11.3.0 • Published 6 months ago

@raytio/core v11.3.0

Weekly downloads
324
License
MIT
Repository
-
Last release
6 months ago

@raytio/core

@raytio/core is a collection of low-level functions for using the Raytio API. It works in both the browser and a nodejs environment, although nodejs requires several polyfills (see below).

For a high-level and easy-to-use API, consider using @raytio/decrypt-helper.

Usage in nodejs

Nodejs does not support fetch, WebCrypto, or atob/btoa, so these will need to be polyfilled. Older versions of nodejs (<14.0.0) also do not support TextEncoder or Intl.DateTimeFormat.

If you use the high-level @raytio/decrypt-helper module, you don't need to worry about this.

If you wish to use @raytio/core directly, an example of configuring polyfills for nodejs is availble here

API

Table of contents

Type Aliases

Functions

Type Aliases

SafeHarbourObj

Ƭ SafeHarbourObj: Partial<Record<SafeHarbourCode, string[]>>

an object listing the xIds for each SafeHarbourCode


SafeHarbourResult

Ƭ SafeHarbourResult: Object

the response from calcSafeHarbourScore

Type declaration

NameType
flagsSafeHarbourObj
isSafeboolean

ServerRelationship

Ƭ ServerRelationship: Omit<Relationship, "p_id" | "start" | "end"> & { from_id: NId ; id: PId } & { to_id: NId } | { to_i_id: IId }

This type represents the relationship format returned by the Postgres API


VerDetails

Ƭ VerDetails: Object

Type declaration

NameTypeDescription
expiryDate?Datefield only present for expired verifications
sourceNId?NId-
verifiersVerificationProvider[]-

Functions

calcSafeHarbourScore

calcSafeHarbourScore(data): Promise<SafeHarbourResult>

The Safe Harbour Score indidicates whether a person's identity has been verified to the extent requried for Safe Harbour Compliance. This requires multiple verifications from different sources. For information, refer to the Raytio Documentation.

Parameters

NameType
dataObject
data.personProfileObject
data.profileObjectsProfileObject[]
data.realVersRealVer[]
data.getSchema(schemaName: SchemaName) => Promise<Schema>

Returns

Promise<SafeHarbourResult>


calculateScore

calculateScore(ruleConfig, ruleInput): Promise<ScoreResult>

the main function to calculate a score and category. Might throw an error.

Parameters

NameType
ruleConfigScoreConfig
ruleInputRuleData

Returns

Promise<ScoreResult>


checkJsonSignature

checkJsonSignature(data, signature, keyId): Promise<boolean>

checks that a json object was signed by the provided signature. Unless you're dealing with bundled verifications, you should use getOwnRealVerifications or getSomeoneElsesRealVerifications instead.

Parameters

NameType
dataunknown
signaturestring
keyIdundefined | string

Returns

Promise<boolean>


convertInstanceToRuleInput

convertInstanceToRuleInput(POs, realVers, getSchema): Promise<RuleData>

Parameters

NameType
POsProfileObject[]
realVersRealVer[]
getSchema(schemaName: SchemaName) => Promise<Schema>

Returns

Promise<RuleData>


convertServerRelationship

convertServerRelationship(serverRelationship): Relationship

Converts relationship type used by the server into the (Urn format) type used by the client

Parameters

NameTypeDescription
serverRelationshipServerRelationshiprelationship type used in the server

Returns

Relationship

a Relationship (client-side type) that is equivalent to the inputted serverRelationship value


createAA

createAA(«destructured»): Promise<AA>

Creates an Access Application and associated public+private keys.

The user must be part of an organization, and you need to include the orgId.

You must also supply an apiToken and an instance of the maxcryptor for that user, as well as the userDoc data which is stored in the user's cognito attributes.

Parameters

NameType
«destructured»Object
› apiTokenstring
› apiUrlstring
› applicationOmit<AA, "a_id">
› maxcryptorDataEncryptorI
› userDocUserDoc

Returns

Promise<AA>


createHashedNId

createHashedNId(nId, aId): NId

the API returns hashed NIds in a separate field, which breaks the whole app. So, we move the hashed ID into the normal n_id field, and use a different format.

This was first introduced in #1048

Parameters

NameType
nIdNId
aIdAId

Returns

NId


decryptSharedData

decryptSharedData(«destructured»): Promise<{ applicationDecryptor: ApplicationDataEncryptorI ; instance: Instance }>

Decrypts any encrypted properties included in the supplied instanceData. If nothing is encrypted the supplied instanceData is returned.

It will reject if there are keys missing for any encrypted properties, or if the encrypted data is invalid. If you don't want it to reject, you can supply a onCorruptedData function which returns a value to use instead.

Parameters

NameType
«destructured»Object
› apiTokenstring
› apiUrlstring
› instanceDataInstance
› maxcryptorDataEncryptorI
› onCorruptedData?(fieldName: string, fieldValue: Encrypted, error: Error) => any

Returns

Promise<{ applicationDecryptor: ApplicationDataEncryptorI ; instance: Instance }>

a copy of instanceData with all properties decrypted.


evaluateRule

evaluateRule(rule, data): Object

evaluates an individual rule, normally you should use calculateScore

Parameters

NameType
ruleScoreRule
dataRuleData

Returns

Object

NameType
passedboolean
scorenumber

expandSchema

expandSchema(wrappedSchema, allUnexpandedSchemas, userLocales): Schema

❣️ This is the main function to transform a schema from the JSON that the API returns, into a Schema object that's useful to the client.

Parameters

NameType
wrappedSchemaWrappedSchema
allUnexpandedSchemasWrappedSchema[]
userLocalesreadonly string[]

Returns

Schema


findSchemaLabel

findSchemaLabel(labels): undefined | SchemaName

Finds the label (on a profile object) which is the schema name

Parameters

NameType
labelsundefined | string[]

Returns

undefined | SchemaName


findSuitableLocale

findSuitableLocale(options, langs): undefined | string

Selects the most suitable locale to use from a list of options. Returns undefined if there is no language that the user speaks

Parameters

NameType
optionsstring[]
langsreadonly string[]

Returns

undefined | string


fromCognitoAttributes

fromCognitoAttributes(attributes): UserDoc

This function converts Cognito's userAttributes into a maxcryptor UserDoc. The userAttributes come from const attributes = await Auth.userAttributes(user)

Parameters

NameType
attributesICognitoUserAttributeData[]

Returns

UserDoc


getAADecryptor

getAADecryptor(«destructured»): Promise<{ decryptor: ApplicationEncryptor ; publicKeyId: KId }>

Fetchs the public and private keys for an Access Application, then initializes the https://npm.im/@raytio/maxcryptor|Maxcryptor's ApplicationEncryptor.

Parameters

NameType
«destructured»Object
› aIdAId
› apiTokenstring
› apiUrlstring
› maxcryptorDataEncryptorI

Returns

Promise<{ decryptor: ApplicationEncryptor ; publicKeyId: KId }>

an ApplicationEncryptor and the public key of the Access Application


getAAPublicKey

getAAPublicKey(«destructured»): Promise<PublicKeyNode>

Fetches the Public Key Information for an Access Application

Parameters

NameType
«destructured»Object
› aIdAId
› apiTokenstring
› apiUrlstring

Returns

Promise<PublicKeyNode>

the id and Key information of the Applications Public Key


getMissingDataForInstance

getMissingDataForInstance(«destructured»): Promise<Instance>

the new API doesn't return the whole instance at once, so we have to make several additional API requests.

Parameters

NameType
«destructured»Object
› apiTokenstring
› apiUrlstring
› instanceWithoutDataInstanceWithoutData

Returns

Promise<Instance>


getNidFromUrn

getNidFromUrn<IDType>(urn): IDType

two overloads - if you provide undefined, you might get undefined back

Type parameters

NameType
IDTypeNId

Parameters

NameType
urnUrn

Returns

IDType

getNidFromUrn<IDType>(urn): undefined | IDType

two overloads - if you provide undefined, you might get undefined back

Type parameters

NameType
IDTypeNId

Parameters

NameType
urnundefined | Urn

Returns

undefined | IDType


getOwnRealVerifications

getOwnRealVerifications(«destructured»): Promise<RealVer[]>

Given a list of verifications and decrypted profile objects, this function locally verifies the credibility of the signatures in the verifications.

This function does NOT call the API, except to fetch the public key.

Parameters

NameType
«destructured»Object
› profileObjectsProfileObject[]
› userIdUId
› verificationsVerification[]

Returns

Promise<RealVer[]>

a list of authentic RealVer


getPOVerification

getPOVerification(«destructured»): Object

Determines the verification status of a profile object, and its individual fields.

Parameters

NameType
«destructured»Object
› POProfileObject | ProfileObjectForUpload
› realVersRealVer[]
› schemaSchema

Returns

Object

NameType
detailsVerDetails
fieldVerificationsRecord<string, FieldVerification>
statusPOVerification

getSomeoneElsesRealVerifications

getSomeoneElsesRealVerifications(«destructured»): Promise<RealVer[]>

Given a list of verifications and decrypted profile objects, this function calls the Raytio API to verify the credibility of these verifications, returning only valid verifications.

❗ prefer getOwnRealVerifications if the data to be verified belongs to the current user.

Parameters

NameType
«destructured»Props

Returns

Promise<RealVer[]>

a list of fileNames/values that are verified.


hashPassword

hashPassword(password): Promise<string>

Deprecated

legacy feature, see #1252

AWS Cognito never gets the raw password. We send them a hashed verison using PBKDF2 with SHA-256 and 10,000 iterations.

Parameters

NameTypeDescription
passwordstringThe raw password

Returns

Promise<string>

Promise resolving to the hashed password


isConditionMet

isConditionMet(condition, formValues): boolean

Checks all other form values in case any have a trigger value that makes this field required.

Example

[
  { "if": { "age": [17, 18], "city": ["Taupō"] } },
  { "if": { "age": [19, 20] } }
]

This means [(age=17 OR age=18) AND (city=Taupō)] OR [(age=19 OR age=20)]

Parameters

NameType
conditionRecord<string, ConditionValue[]>
formValuesRecord<string, unknown>

Returns

boolean


isEncrypted

isEncrypted(value): value is Encrypted

Determines where the input is an encrypted Raytio object

Parameters

NameTypeDescription
valueunknownanything

Returns

value is Encrypted

true or false depending on whether the input is an encrypted Raytio object


isEncryptedFile

isEncryptedFile(value): value is Encrypted

Determines where the input is an encrypted Raytio file

Parameters

NameTypeDescription
valueunknownanything

Returns

value is Encrypted

true or false depending on whether the input is an encrypted Raytio file


isScoreConfigValid

isScoreConfigValid(x): x is ScoreConfig

determines whether a ScoreConfig object is valid

Parameters

NameType
xunknown

Returns

x is ScoreConfig


isScoreResultValid

isScoreResultValid(x): x is ScoreResult

determines whether a ScoreResult object is valid

Parameters

NameType
xunknown

Returns

x is ScoreResult


repairDate

repairDate(date): Date

repairs broken ISO dates into valid JS date objects

Parameters

NameType
datestring | Date

Returns

Date


someEncrypted

someEncrypted<T>(...args): number

Given a profile object's properties, returns the number of properties that are encryted.

Type parameters

NameType
Textends object

Parameters

NameType
...argsobj: T

Returns

number


sortSchemaProperties

sortSchemaProperties(properties): Section[]

Schema properties are an object, so they need to be converted into an array, grouped by the group tag, and then sorted based on the priority attribute within their group.

Parameters

NameType
propertiesRecord<string, SchemaField>

Returns

Section[]


toCognitoAttributes

toCognitoAttributes(userDoc): Object

Given a UserDoc from the maxcryptor, this returns an object which you can provide to Auth.updateUserAttributes(). It is an object of stringified Json.

Parameters

NameType
userDocUserDoc

Returns

Object

11.3.0

6 months ago

11.2.0

10 months ago

11.0.0

1 year ago

11.1.0

1 year ago

10.1.0

2 years ago

10.0.1

2 years ago

10.0.0

2 years ago

9.0.3

2 years ago

9.0.2

2 years ago

9.0.1

2 years ago

9.0.0

2 years ago

8.1.3

3 years ago

8.1.2

3 years ago

8.1.1

3 years ago

8.1.0

3 years ago

8.0.0

3 years ago

7.0.0

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

5.0.0

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.2.2

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

1.0.4

3 years ago

2.0.0

3 years ago

1.0.3

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.3.2

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.0.1

4 years ago