@privateid/cryptonets-web-sdk-alpha
TypeScript icon, indicating that this package has built-in type declarations

2.0.84 • Public • Published

CryptoNets WebAssembly SDK

Powered by Private Identity®
https://private.id

CryptoNets™ Wasm Module Implementation is an npm package that uses the W3C WebAssembly to perform 1:N fully homomorphically encrypted (FHE) face recognition.

BENEFITS

  • Face biometric capture
  • Encrypted face recognition every 200ms
  • 1:n biometric match in 60ms constant time
  • Human age estimation
  • Unlimited users (unlimited gallery size)
  • Fair, accurate and unbiased
  • Preserves user privacy with neural network cryptography + fully homomorphic encryption (CryptoNets)
  • IEEE 2410 Standard for Biometric Privacy, ISO 27001, ISO 9001 compliant
  • Exempt from GDPR, CCPA, BIPA, and HIPAA privacy law obligations
  • Predicts in 50ms with or without network using local storage

BUILD

  • Verified Identity
  • Web Sign-in
  • Payments
  • Phone Unlock
  • Ticketless Access Control
  • Account Recovery
  • Face CAPTCHA

Prerequisite

Sign up on the waitlist on https://private.id to obtain your apiKey.

Installation

npm install @privateid/cryptonets-web-sdk

Copy the necessary dependencies to the public folder of your app

"prestart": "cp -R ./node_modules/@privateid/cryptonets-web-sdk/wasm public/&& cp -R ./node_modules/@privateid/cryptonets-web-sdk/workers public/",
"prebuild": "cp -R ./node_modules/@privateid/cryptonets-web-sdk/wasm public/ && cp -R ./node_modules/@privateid/cryptonets-web-sdk/workers public/"

Add the necessary environment variables on the .env file in the root of your project

SKIP_PREFLIGHT_CHECK=true
REACT_APP_API_URL= 
REACT_APP_API_KEY=
REACT_APP_WASM_MODULE= face_mask | face | voice

Load the WASM Module

The first step is to load and initialize the wasm module and clear the content of the local database.

import { loadPrivIdModule, clearDB } from '@privateid/cryptonets-web-sdk';

await loadPrivIdModule();
clearDB();

In case of .env file (evironment variable) does not work for you we have added a support to set the variables on load.

import { loadPrivIdModule } from '@privateid/cryptonets-web-sdk';

await loadPrivIdModule(
  api_url, 
  api_key,
  api_orchestration_url,
  wasm_url,
  wasm_module,
);
Status Description
api_url Equivalent to env variable REACT_APP_API_URL
api_key Equivalent to env variable REACT_APP_API_KEY
api_orchestration_url Equivalent to env variable REACT_APP_API_ORCHESTRATION_URL
wasm_url Please set it the same with api_url or REACT_APP_API_URL
wasm_module face_mask , face , voice

Open or switch camera

The first step is to load and initialize the wasm module.

Open the camera

To open user camera use the openCamera function with element id of the video tag in the DOM

import { openCamera } from '@privateid/cryptonets-web-sdk';

const { devices, faceMode } = await openCamera(element);

it returns list of the available video devices.

Switch to another camera

To switch to another media device use the switchCamera function with the ID of the device to be used

import { switchCamera } from '@privateid/cryptonets-web-sdk';

switchCamera(deviceID);

for the mobile phone we can select whether it's front or back camera for this we pass 'front' or 'back' to the switch function

import { switchCamera } from '@privateid/cryptonets-web-sdk';

switchCamera('front');

isValid

Live demo: [https://age.devel.private.id]

isValid only exercises the is_valid() call and does not find identity. The function detects if there is a valid face in the camera view or in an ImageData Array.

isValid accepts two parameters.

  • action: false for prediction (less restrictive), and true for enrollment (more restrictive). We recommend using false as your default.
  • ImageData: array of an image data to perform the face captcha on (optional)
import { isValid } from '@privateid/cryptonets-web-sdk';

const {result, imageData} = isValid (false);

Face CAPTCHA returns 17 possible coded results, as follows.

Property Description
-1 No Face
0 Valid Biometric
1 Image Spoof
2 Video Spoof
3 Too close
4 Too far away
5 Too far to right
6 Too far to left
7 Too far up
8 Too far down
9 Too blurry
10 Glasses on
11 Mask on
12 Chin too far left
13 Chin too far right
14 Chin too far up
15 Chin too far down

Enroll or predict

Perform a new enrollment (register a new user) or predict (authenticate a user) using the enroll1FA or predict1FA function

import { enroll1FA, predict1FA } from '@privateid/cryptonets-web-sdk';

enroll1FA(callback, {input_image_format: "rgba"}, "userVideo")
predict1FA(callback, {input_image_format: "rgba"}, "userVideo")

The function takes 3 parameters

Property Description
callback The callback to be executed on each status
config The image format to be used for processing. Recommended: { input_image_format: "rgba" }
videoRef Video tag

Callback

The enroll1FA and predict1FA function provides 5 status updates to allow the developer to take action at different steps of the identification process.

Status Description
VALID_FACE A face is detected
INVALID_FACE A valid face is not detected
ENROLLING Enrollment (registration) starts of a valid face
PREDICTING Prediction (authentication) starts of a valid face
WASM_RESPONSE The prediction or enrollment process is complete

Continuous enroll predict

Live demo: https://c.priv.id

Perform continuous user enrollment or prediction (registration or authentication) using the continuousEnrollPredict function. This provides the same status updates as Enroll or Predict.

import { continuousEnrollPredict } from '@privateid/cryptonets-web-sdk';

continuousEnrollPredict(false, callback)

The continousEnrollPredict function takes 2 parameters

Property Description
action True (enroll) / false (predict)
callback The callback to be executed on each status

isValidPhotoID

This function finds, crops, align and validate, front and back of the photoID, and returns back a valid cropped and aligned image of the photoID

import { isValidPhotoID } from '@privateid/cryptonets-web-sdk';

//Front of DL scan with predict
const { imageData } = isValidPhotoID("PHOTO_ID_FRONT", documentCallback);

//Front of DL scan without predict
const { imageData } = isValidPhotoID("PHOTO_ID_FRONT", documentCallback, false);

// Back of DL barcode scan
const { croppedBarcode } = isValidPhotoID("PHOTO_ID_BACK", callback)

The isValidPhotoID function takes 3 parameters

Property Description
docType it can be either PHOTO_ID_BACK (back of the photo ID) or PHOTO_ID_FRONT (front of the photo ID)
callback returns the uuid of the portrait on the Front of the Photo ID
doPredict it is a boolean field wheter we are gonna do a predict on the image of front dl or not. Default value is true

The function returns:

Front Document Scan (PHOTO_ID_FRONT)
result: status of the validation of the document

Status Description
0 valid document
-1 validation failed

imageData: ImageData datatype of the input image (Note: please use utilty function below for converting.)

Front DL Callback Data returns:

{
    payload_type: string,
    conf_level: number,
    uuid: string,
    guid: string,
    predict_message: string,
    face_validity_message: string,
    op_message: string,
    predict_status: number,
    enroll_level: number,
    face_valid: number,
    op_status: number
}

Back Document Scan (PHOTO_ID_BACK)
result: status of the validation of the document
croppedBarcode:: a Uint8ClampedArray convertable to base64String (Note: please use utilty function below for converting.)

Back DL Callback sample return value: Note: Variables might change depending on the barcode data.

{
    "op_status": number,
    "op_message": string,
    "payload_type": string,
    "barcode_conf_score": number,
    "crop_doc_width": number,
    "crop_doc_height": number,
    "type": string,
    "format": string,
    "firstName": string,
    "lastName": string,
    "middleName": string,
    "expirationDate": string,
    "issueDate": string,
    "dateOfBirth": string,
    "gender": string,
    "eyeColor": string,
    "hairColor": string,
    "height": string,
    "streetAddress1": string,
    "streetAddress2": string,
    "RestStreetAddress1": string,
    "RestStreetAddress2": string,
    "city": string,
    "state": string,
    "postCode": string,
    "issuingCountry": string,
    "firstNameTruncation": string,
    "placeOfBirth": string,
    "auditInformation": string,
    "inventoryControlNumber": string,
    "lastNameAlias": string,
    "firstNameAlias": string,
    "suffixAlias": string,
    "nameSuffix": string,
    "namePrefix": string,
    "barcode_key_string": string,
    "barcodeHash64_string": string,
    "barcodeHash128_string": string,
}

Utility function for convertion of image returned by front and back dl scan

convertCroppedImage()

This is a utility function that helps for converting returned image from FRONT DL SCAN and BACK DL SCAN

// FRONT DL SCAM
// For converting imageData returned data from FRONT DL SCAN.
const ConvertedBase64String = convertCroppedImage(imageData.data, imageData.width, imageData.height);

// BACK DL SCAN
// For converting croppedBarcode returned data from BACK DL SCAN.
// (Note: We would need other variables that is returned in the callback data. crop_doc_width and crop_doc_height)
const ConvertedBase64String = convertCroppedImage(croppedBarcode, crop_doc_width, crop_doc_height);

Licensing Restriction: This product is not licensed for use in regulated gaming. To license in this market, please contact CentralAMS.

deleteUser

This function is used for deleting user with the uuid

import { deleteUser } from "@privateid/cryptonets-web-sdk";

deleteUser(uuid, callback)

Note: Please use Predict to get the user UUID you want to delete and pass it in

The function returns:
result: status of the validation of the document

Status Description
0 deletion is successful
-1 deletion is unsuccessful

messege: deletion messege

checkPackageSupport

This function checks if the web browser supports WASM based on: https://www.lambdatest.com/web-technologies/wasm

import { checkPackageSupport } from "@privateid/cryptonets-web-sdk";

checkPackageSupport();

The function returns:
status: status is a boolean when "True" the browser supports WASM and "False" browser does not support WASM
messege: Messege of the checking of package support.

API Utils

createUser

This function accepts { token (CID or GAN Unique ID/PlayerID), phone, email, ... } and creates user.

import { createUser } from '@privateid/cryptonets-web-sdk';

createUser(parmas)

params = {
    id?: string; // (CID or GAN Unique ID/PlayerID)
    guid?: string;
    phone: string;
    phoneVerified?: boolean;
    email?: string;
    emailVerified?: boolean;
    ssn4?: string;
    ssn9?: string;
    userConsent: boolean;
    userConsentDate: string;
    userFaceEnrollConsent?: boolean;
    consentVersion: string;
    portrait?: string;
};

sendEnrollSms

This function sends SMS to user's phone with a link to acquire front & back of Driver License from mobile. (also enroll face if faceEnrollConsent is true).
From the redirect link in SMS, you can find query string code. You can pass it through verifyToken function as a verification code to get user information.
You can use it if the webcam is lower than 2MP.

import { sendEnrollSms } from '@privateid/cryptonets-web-sdk';

sendEnrollSms({ id })

{
    id: string; // (CID or GAN Unique ID/PlayerID)
}

verifyToken

This function gets the verification code as parameter and return the user information if it's valid code.

import { verifyToken } from '@privateid/cryptonets-web-sdk';

verifyToken({ code, type })

{
    code: string; // verification code
    type: ['phone', 'email']; 
}

uploadPortrait

This function uploads user portrait image.

import { uploadPortrait } from '@privateid/cryptonets-web-sdk';

uploadPortrait({ id, portrait })

{
    id: string; // (CID or GAN Unique ID/PlayerID)
    portrait: string // Base64 
}

uploadDL

This function uploads front & back of Driver Licence image.

import { uploadDL } from '@privateid/cryptonets-web-sdk';

// Upload front of driver licence
uploadDL({ id, type: 'front', image })

// Upload back of driver license and barcde data
uploadDL({ id, type: 'back', image, barcode })

{
    id: string; // (CID or GAN Unique ID/PlayerID)
    type: ['front', 'back'];
    image: string // Base64 
    barcode: string
}

updateUser

This function update user preferred data.
i.e. address, city, state, country, postalCode, etc.
This information will be stored in preferred field of User object in DB.

import { updateUser } from '@privateid/cryptonets-web-sdk';

updateUser({ id, attributes })

{
    id: string; // (CID or GAN Unique ID/PlayerID)
    attributes: {...}; // 
}

getUserStatus

This function will return the status of user.

import { getUserStatus } from '@privateid/cryptonets-web-sdk';

getUserStatus({ id  })

{
    id: string; // (CID or GAN Unique ID/PlayerID)
}

Response

Name Value Description
userRegistered true, false true if all user information provided for createUser function
emailVerified true, false Email verified for user
phoneVerified true, false Phone number verified for user
manualPIIEntry true, false true for manual data entry (no Scan ID)
userScanID true, false true Approved Scan ID

validateSecurityToken

This function will validate the returned securityToken.

Note: Token are only valid for 5 minutes starting from the creation of token. After 5 minutes the token will be invalid.

import { validateSecurityToken } from '@privateid/cryptonets-web-sdk';

validateSecurityToken({ uuid, token })

{
    uuid: string; // UUID of the user
    token: string; // Token from the api call i.e. enroll1Fa/predict1Fa
}

Response

Name Value Description
securityToken string The securityToken passed in the API call.
securityTokenStatus '1','0' '1' being TRUE means securityToken is valid. '0' being FALSE means securityToken is invalid.

Package Sidebar

Install

npm i @privateid/cryptonets-web-sdk-alpha@2.0.84

Version

2.0.84

License

See AWS EULA Template (2020.11.20)(Private ID) at this link: https://github.com/openinfer/PrivateIdentity/blob/e19cb4870048f14e04a6be99d3cab78f4d8c6360/images/AWS%20EULA%20Template%20(2020.11.20)%20(Private%20Identity).pdf

Unpacked Size

43.7 MB

Total Files

47

Last publish

Collaborators

  • xcjames29
  • mikepoll
  • shivenj
  • na6im93
  • nathandent
  • haroonpid