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:
| Field | Type | Description |
|---|---|---|
initializeSDK() | function | Initializes the eKYC SDK. |
scanNIDOnly() | function | Scans the NID, front and back. |
scanFaceOnly() | function | Scans the face. |
scanComplete() | function | Completes the scan — NID plus face. |
checkStatus() | function | Checks the current scan status. |
terminateSDK() | function | Cleans up and terminates the SDK. |
Module Interface
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
const result = await ekyc.scanStart(['front', 'back', 'face']);| Param | Type | Required | Default | Description |
|---|---|---|---|---|
types | ('face' | 'front' | 'back')[] | Yes | — | Which scans to run. |
opts | ScanOptions | No | — | Optional, mainly for the face type. |
Examples
// 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
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.
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);// 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.
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
}
}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
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()
}| Field | Type | Description |
|---|---|---|
Ekyc.CakeNIDVerifySuccess | event | Verification passed. |
Ekyc.CakeNIDVerifyRuntimeError | event | NID sanity or liveness verification failed. |
Ekyc.CakeNIDVerifyCheckFailed | event | NID comparison failed. |
EkycError.UnexpectedError | 50000 | Runtime exception. |
Upload Image
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
- Web SDK Integration — setup, scanning and error handling
- Web SDK Architecture — the classes behind these calls