Skip to content

Web SDK Reference ​

The global window.ekyc object and its TypeScript interfaces. This page supplements Web SDK Integration — read that first.

Global Object ​

After bundle.js executes, window.ekyc exposes:

FieldTypeDescription
initializeSDK()functionInitializes the eKYC SDK.
scanNIDOnly()functionScans the NID, front and back.
scanFaceOnly()functionScans the face.
scanComplete()functionCompletes the scan — NID plus face.
checkStatus()functionChecks the current scan status.
terminateSDK()functionCleans up and terminates the SDK.

Module Interface ​

typescript
type SDKConfigParams = {
    resourcePath?: string;
    baseUrl: string;
    token: string;
};

interface ScanOptions {
    frontImageId?: string;
    faceauthClientId?: string;
    faceauthRefId?: string;
    isNTB?: boolean;
}

interface NIDScanResult {
    front: Front;
    back: Back;
    status: Status;
}

interface Status {
    frontCompleted: boolean;
    backCompleted: boolean;
    timestamp?: string;
}

declare const _default: {
    readonly initialize: (elementID: string, opts: SDKConfigParams) => Promise<SDK>;
    readonly scanStart: (types: ("face" | "front" | "back")[], opts?: ScanOptions) => Promise<{
        nid?: NIDScanResult;
        face?: FaceScanResult;
    }>;
    readonly getScanStatus: () => Status;
    readonly terminate: () => void;
    readonly CakeEkycSDK: typeof CakeEkycSDK;
};

INFO

This module interface omits qrcode from the scanStart types and from Status, while Web SDK Integration documents it as supported. The integration page is the newer source — treat qrcode as available and confirm with the CAKE team if your bundle rejects it.

Scan ​

javascript
const result = await ekyc.scanStart(['front', 'back', 'face']);
ParamTypeRequiredDefaultDescription
types('face' | 'front' | 'back')[]Yes—Which scans to run.
optsScanOptionsNo—Optional, mainly for the face type.

Examples ​

javascript
// NID only
const nidResult = await ekyc.scanStart(['front', 'back']);

// Face only
const faceResult = await ekyc.scanStart(['face']);

// Complete scan
const completeResult = await ekyc.scanStart(['front', 'back', 'face']);

// Custom order
const customResult = await ekyc.scanStart(['back', 'front', 'face']);

Terminate ​

javascript
await ekyc.terminateScanner();

INFO

The method may be exposed as terminate or terminateScanner depending on the bundle. Check which your bundle exposes before relying on either name.

Class-Based API ​

CakeEkycSDK is also exported for direct use, giving finer control than scanStart.

typescript
import { CakeEkycSDK, SDKConfigParams } from './CakeEkycSDK';

const container = document.getElementById('ekyc-container');
const sdkConfig: SDKConfigParams = {
  baseUrl: '<BASE_URL>',
  token: '<SDK_TOKEN>',
  resourcePath: '/path/to/resources',
};
const ekycSDK = await CakeEkycSDK.initialize(container, sdkConfig);
typescript
// Scan a face
const faceScanner = ekycSDK.scanFace();
faceScanner.start();

// Scan an NID side
const cardSide = 'front'; // or 'back'
const nidScanner = ekycSDK.scanNID(cardSide);
nidScanner?.start();

// Verify an NID
const verifyStep = ekycSDK.verifyNID(input);
verifyStep.start();

// Verify faces
const faceVerifyStep = ekycSDK.verifyFaces(faceImages);
faceVerifyStep.start();

// Face authentication
const authResponse = await ekycSDK.verifyFaceAuthentication(authParams);

Event-driven scanning ​

Scanners report through onEvent rather than resolving a promise.

typescript
const nidScanner = sdk.scanNID(cardSide) as CakeNIDScanner
if (!nidScanner) return reject('Error: Can not start scanNID')
nidScanner.start()

terminate = nidScanner.terminate

nidScanner.onEvent = async (event: any) => {
  if (event instanceof Ekyc.NIDScanOutput) {
    // success
  } else {
    // error
  }
}
typescript
const scanner = sdk.scanFace() as CakeFaceScanner
if (!scanner) return reject('Error: Can not start scanFace')

scanner.start()

terminate = scanner.terminate

scanner.onEvent = async (event) => {
  if (event instanceof Ekyc.FaceScanOutput) {
    // success
  } else {
    // error
  }
}

Verify step events ​

typescript
stepVerify = sdk.verifyNID({
   front: { id: String(opts?.frontImageId) },
   back:  { image: (await event.blob()) as Blob },
})

if (!stepVerify) throw Error('Instance Verify not found!')

stepVerify.start()

stepVerify.onEvent = (
  verifyEvent:
    | Ekyc.CakeNIDVerifySuccess
    | Ekyc.CakeNIDVerifyRuntimeError
    | Ekyc.CakeNIDVerifyCheckFailed
) => {
  if (verifyEvent instanceof Ekyc.CakeNIDVerifySuccess) {
    // success
  }
  if (verifyEvent instanceof Ekyc.CakeNIDVerifyRuntimeError) {
    // sanity or liveness failed
  }
  if (verifyEvent instanceof Ekyc.CakeNIDVerifyCheckFailed) {
    // comparison failed
  }

  nidScanner.terminate()
}
FieldTypeDescription
Ekyc.CakeNIDVerifySuccesseventVerification passed.
Ekyc.CakeNIDVerifyRuntimeErroreventNID sanity or liveness verification failed.
Ekyc.CakeNIDVerifyCheckFailedeventNID comparison failed.
EkycError.UnexpectedError50000Runtime exception.

Upload Image ​

typescript
function uploadImage(params: CESUploadRequest): Promise<HttpResponse<CESUploadResponse>> {
  const formdata = new FormData()
  formdata.append('file', params.file, 'file.jpeg')
  formdata.append('label', params.label)

  return this.client.request({
    method: 'POST',
    url: `${this.params.baseUrl}/v1/images`,
    body: formdata,
    headers: this.getHeader(),
  })
}

uploadImage({ file: file, label })

This calls Upload Image directly.

Next Steps ​

Developers