@kwik-id/sdk-react-native 0.0.0-stage → 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +81 -2
- package/app.plugin.js +40 -0
- package/lib/commonjs/api/api-client.js +213 -0
- package/lib/commonjs/api/api-client.js.map +1 -0
- package/lib/commonjs/api/api-error.js +29 -0
- package/lib/commonjs/api/api-error.js.map +1 -0
- package/lib/commonjs/api/index.js +33 -0
- package/lib/commonjs/api/index.js.map +1 -0
- package/lib/commonjs/api/upload.js +74 -0
- package/lib/commonjs/api/upload.js.map +1 -0
- package/lib/commonjs/camera/camera-view.js +227 -0
- package/lib/commonjs/camera/camera-view.js.map +1 -0
- package/lib/commonjs/camera/index.js +20 -0
- package/lib/commonjs/camera/index.js.map +1 -0
- package/lib/commonjs/camera/photo-capture.js +50 -0
- package/lib/commonjs/camera/photo-capture.js.map +1 -0
- package/lib/commonjs/crypto/fingerprint.js +43 -0
- package/lib/commonjs/crypto/fingerprint.js.map +1 -0
- package/lib/commonjs/crypto/hmac.js +150 -0
- package/lib/commonjs/crypto/hmac.js.map +1 -0
- package/lib/commonjs/crypto/index.js +39 -0
- package/lib/commonjs/crypto/index.js.map +1 -0
- package/lib/commonjs/crypto/session-manager.js +173 -0
- package/lib/commonjs/crypto/session-manager.js.map +1 -0
- package/lib/commonjs/i18n/en.js +297 -0
- package/lib/commonjs/i18n/en.js.map +1 -0
- package/lib/commonjs/i18n/fr.js +294 -0
- package/lib/commonjs/i18n/fr.js.map +1 -0
- package/lib/commonjs/i18n/index.js +34 -0
- package/lib/commonjs/i18n/index.js.map +1 -0
- package/lib/commonjs/i18n/locale.js +20 -0
- package/lib/commonjs/i18n/locale.js.map +1 -0
- package/lib/commonjs/i18n/translator.js +37 -0
- package/lib/commonjs/i18n/translator.js.map +1 -0
- package/lib/commonjs/index.js +187 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/lib/device-detector.js +34 -0
- package/lib/commonjs/lib/device-detector.js.map +1 -0
- package/lib/commonjs/lib/event-emitter.js +85 -0
- package/lib/commonjs/lib/event-emitter.js.map +1 -0
- package/lib/commonjs/lib/index.js +63 -0
- package/lib/commonjs/lib/index.js.map +1 -0
- package/lib/commonjs/lib/kwik-id-rn-sdk.js +156 -0
- package/lib/commonjs/lib/kwik-id-rn-sdk.js.map +1 -0
- package/lib/commonjs/lib/verification-machine.js +276 -0
- package/lib/commonjs/lib/verification-machine.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types/events.js +6 -0
- package/lib/commonjs/types/events.js.map +1 -0
- package/lib/commonjs/types/index.js +2 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/ui/components/KwikIDVerificationModal.js +407 -0
- package/lib/commonjs/ui/components/KwikIDVerificationModal.js.map +1 -0
- package/lib/commonjs/ui/components/screens.js +338 -0
- package/lib/commonjs/ui/components/screens.js.map +1 -0
- package/lib/commonjs/ui/context/kwik-id-provider.js +52 -0
- package/lib/commonjs/ui/context/kwik-id-provider.js.map +1 -0
- package/lib/commonjs/ui/hooks/use-kwik-verification.js +77 -0
- package/lib/commonjs/ui/hooks/use-kwik-verification.js.map +1 -0
- package/lib/commonjs/ui/index.js +33 -0
- package/lib/commonjs/ui/index.js.map +1 -0
- package/lib/module/api/api-client.js +208 -0
- package/lib/module/api/api-client.js.map +1 -0
- package/lib/module/api/api-error.js +24 -0
- package/lib/module/api/api-error.js.map +1 -0
- package/lib/module/api/index.js +6 -0
- package/lib/module/api/index.js.map +1 -0
- package/lib/module/api/upload.js +68 -0
- package/lib/module/api/upload.js.map +1 -0
- package/lib/module/camera/camera-view.js +222 -0
- package/lib/module/camera/camera-view.js.map +1 -0
- package/lib/module/camera/index.js +5 -0
- package/lib/module/camera/index.js.map +1 -0
- package/lib/module/camera/photo-capture.js +45 -0
- package/lib/module/camera/photo-capture.js.map +1 -0
- package/lib/module/crypto/fingerprint.js +37 -0
- package/lib/module/crypto/fingerprint.js.map +1 -0
- package/lib/module/crypto/hmac.js +143 -0
- package/lib/module/crypto/hmac.js.map +1 -0
- package/lib/module/crypto/index.js +6 -0
- package/lib/module/crypto/index.js.map +1 -0
- package/lib/module/crypto/session-manager.js +169 -0
- package/lib/module/crypto/session-manager.js.map +1 -0
- package/lib/module/i18n/en.js +293 -0
- package/lib/module/i18n/en.js.map +1 -0
- package/lib/module/i18n/fr.js +290 -0
- package/lib/module/i18n/fr.js.map +1 -0
- package/lib/module/i18n/index.js +11 -0
- package/lib/module/i18n/index.js.map +1 -0
- package/lib/module/i18n/locale.js +15 -0
- package/lib/module/i18n/locale.js.map +1 -0
- package/lib/module/i18n/translator.js +34 -0
- package/lib/module/i18n/translator.js.map +1 -0
- package/lib/module/index.js +30 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/lib/device-detector.js +26 -0
- package/lib/module/lib/device-detector.js.map +1 -0
- package/lib/module/lib/event-emitter.js +80 -0
- package/lib/module/lib/event-emitter.js.map +1 -0
- package/lib/module/lib/index.js +6 -0
- package/lib/module/lib/index.js.map +1 -0
- package/lib/module/lib/kwik-id-rn-sdk.js +150 -0
- package/lib/module/lib/kwik-id-rn-sdk.js.map +1 -0
- package/lib/module/lib/verification-machine.js +268 -0
- package/lib/module/lib/verification-machine.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types/events.js +4 -0
- package/lib/module/types/events.js.map +1 -0
- package/lib/module/types/index.js +2 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/ui/components/KwikIDVerificationModal.js +402 -0
- package/lib/module/ui/components/KwikIDVerificationModal.js.map +1 -0
- package/lib/module/ui/components/screens.js +328 -0
- package/lib/module/ui/components/screens.js.map +1 -0
- package/lib/module/ui/context/kwik-id-provider.js +46 -0
- package/lib/module/ui/context/kwik-id-provider.js.map +1 -0
- package/lib/module/ui/hooks/use-kwik-verification.js +72 -0
- package/lib/module/ui/hooks/use-kwik-verification.js.map +1 -0
- package/lib/module/ui/index.js +6 -0
- package/lib/module/ui/index.js.map +1 -0
- package/lib/typescript/commonjs/api/api-client.d.ts +82 -0
- package/lib/typescript/commonjs/api/api-client.d.ts.map +1 -0
- package/lib/typescript/commonjs/api/api-error.d.ts +13 -0
- package/lib/typescript/commonjs/api/api-error.d.ts.map +1 -0
- package/lib/typescript/commonjs/api/index.d.ts +6 -0
- package/lib/typescript/commonjs/api/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/api/upload.d.ts +19 -0
- package/lib/typescript/commonjs/api/upload.d.ts.map +1 -0
- package/lib/typescript/commonjs/camera/camera-view.d.ts +25 -0
- package/lib/typescript/commonjs/camera/camera-view.d.ts.map +1 -0
- package/lib/typescript/commonjs/camera/index.d.ts +5 -0
- package/lib/typescript/commonjs/camera/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/camera/photo-capture.d.ts +9 -0
- package/lib/typescript/commonjs/camera/photo-capture.d.ts.map +1 -0
- package/lib/typescript/commonjs/crypto/fingerprint.d.ts +3 -0
- package/lib/typescript/commonjs/crypto/fingerprint.d.ts.map +1 -0
- package/lib/typescript/commonjs/crypto/hmac.d.ts +18 -0
- package/lib/typescript/commonjs/crypto/hmac.d.ts.map +1 -0
- package/lib/typescript/commonjs/crypto/index.d.ts +4 -0
- package/lib/typescript/commonjs/crypto/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/crypto/session-manager.d.ts +27 -0
- package/lib/typescript/commonjs/crypto/session-manager.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n/en.d.ts +291 -0
- package/lib/typescript/commonjs/i18n/en.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n/fr.d.ts +6 -0
- package/lib/typescript/commonjs/i18n/fr.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n/index.d.ts +10 -0
- package/lib/typescript/commonjs/i18n/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n/locale.d.ts +4 -0
- package/lib/typescript/commonjs/i18n/locale.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n/translator.d.ts +15 -0
- package/lib/typescript/commonjs/i18n/translator.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +24 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/lib/device-detector.d.ts +5 -0
- package/lib/typescript/commonjs/lib/device-detector.d.ts.map +1 -0
- package/lib/typescript/commonjs/lib/event-emitter.d.ts +19 -0
- package/lib/typescript/commonjs/lib/event-emitter.d.ts.map +1 -0
- package/lib/typescript/commonjs/lib/index.d.ts +5 -0
- package/lib/typescript/commonjs/lib/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/lib/kwik-id-rn-sdk.d.ts +43 -0
- package/lib/typescript/commonjs/lib/kwik-id-rn-sdk.d.ts.map +1 -0
- package/lib/typescript/commonjs/lib/verification-machine.d.ts +78 -0
- package/lib/typescript/commonjs/lib/verification-machine.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/types/events.d.ts +94 -0
- package/lib/typescript/commonjs/types/events.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/index.d.ts +242 -0
- package/lib/typescript/commonjs/types/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/KwikIDVerificationModal.d.ts +21 -0
- package/lib/typescript/commonjs/ui/components/KwikIDVerificationModal.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/screens.d.ts +46 -0
- package/lib/typescript/commonjs/ui/components/screens.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/context/kwik-id-provider.d.ts +19 -0
- package/lib/typescript/commonjs/ui/context/kwik-id-provider.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hooks/use-kwik-verification.d.ts +29 -0
- package/lib/typescript/commonjs/ui/hooks/use-kwik-verification.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/index.d.ts +7 -0
- package/lib/typescript/commonjs/ui/index.d.ts.map +1 -0
- package/lib/typescript/module/api/api-client.d.ts +82 -0
- package/lib/typescript/module/api/api-client.d.ts.map +1 -0
- package/lib/typescript/module/api/api-error.d.ts +13 -0
- package/lib/typescript/module/api/api-error.d.ts.map +1 -0
- package/lib/typescript/module/api/index.d.ts +6 -0
- package/lib/typescript/module/api/index.d.ts.map +1 -0
- package/lib/typescript/module/api/upload.d.ts +19 -0
- package/lib/typescript/module/api/upload.d.ts.map +1 -0
- package/lib/typescript/module/camera/camera-view.d.ts +25 -0
- package/lib/typescript/module/camera/camera-view.d.ts.map +1 -0
- package/lib/typescript/module/camera/index.d.ts +5 -0
- package/lib/typescript/module/camera/index.d.ts.map +1 -0
- package/lib/typescript/module/camera/photo-capture.d.ts +9 -0
- package/lib/typescript/module/camera/photo-capture.d.ts.map +1 -0
- package/lib/typescript/module/crypto/fingerprint.d.ts +3 -0
- package/lib/typescript/module/crypto/fingerprint.d.ts.map +1 -0
- package/lib/typescript/module/crypto/hmac.d.ts +18 -0
- package/lib/typescript/module/crypto/hmac.d.ts.map +1 -0
- package/lib/typescript/module/crypto/index.d.ts +4 -0
- package/lib/typescript/module/crypto/index.d.ts.map +1 -0
- package/lib/typescript/module/crypto/session-manager.d.ts +27 -0
- package/lib/typescript/module/crypto/session-manager.d.ts.map +1 -0
- package/lib/typescript/module/i18n/en.d.ts +291 -0
- package/lib/typescript/module/i18n/en.d.ts.map +1 -0
- package/lib/typescript/module/i18n/fr.d.ts +6 -0
- package/lib/typescript/module/i18n/fr.d.ts.map +1 -0
- package/lib/typescript/module/i18n/index.d.ts +10 -0
- package/lib/typescript/module/i18n/index.d.ts.map +1 -0
- package/lib/typescript/module/i18n/locale.d.ts +4 -0
- package/lib/typescript/module/i18n/locale.d.ts.map +1 -0
- package/lib/typescript/module/i18n/translator.d.ts +15 -0
- package/lib/typescript/module/i18n/translator.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +24 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/lib/device-detector.d.ts +5 -0
- package/lib/typescript/module/lib/device-detector.d.ts.map +1 -0
- package/lib/typescript/module/lib/event-emitter.d.ts +19 -0
- package/lib/typescript/module/lib/event-emitter.d.ts.map +1 -0
- package/lib/typescript/module/lib/index.d.ts +5 -0
- package/lib/typescript/module/lib/index.d.ts.map +1 -0
- package/lib/typescript/module/lib/kwik-id-rn-sdk.d.ts +43 -0
- package/lib/typescript/module/lib/kwik-id-rn-sdk.d.ts.map +1 -0
- package/lib/typescript/module/lib/verification-machine.d.ts +78 -0
- package/lib/typescript/module/lib/verification-machine.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/types/events.d.ts +94 -0
- package/lib/typescript/module/types/events.d.ts.map +1 -0
- package/lib/typescript/module/types/index.d.ts +242 -0
- package/lib/typescript/module/types/index.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/KwikIDVerificationModal.d.ts +21 -0
- package/lib/typescript/module/ui/components/KwikIDVerificationModal.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/screens.d.ts +46 -0
- package/lib/typescript/module/ui/components/screens.d.ts.map +1 -0
- package/lib/typescript/module/ui/context/kwik-id-provider.d.ts +19 -0
- package/lib/typescript/module/ui/context/kwik-id-provider.d.ts.map +1 -0
- package/lib/typescript/module/ui/hooks/use-kwik-verification.d.ts +29 -0
- package/lib/typescript/module/ui/hooks/use-kwik-verification.d.ts.map +1 -0
- package/lib/typescript/module/ui/index.d.ts +7 -0
- package/lib/typescript/module/ui/index.d.ts.map +1 -0
- package/package.json +121 -3
- package/src/api/api-client.ts +319 -0
- package/src/api/api-error.ts +28 -0
- package/src/api/index.ts +12 -0
- package/src/api/upload.ts +87 -0
- package/src/camera/camera-view.tsx +217 -0
- package/src/camera/index.ts +4 -0
- package/src/camera/photo-capture.ts +58 -0
- package/src/crypto/fingerprint.ts +46 -0
- package/src/crypto/hmac.ts +172 -0
- package/src/crypto/index.ts +3 -0
- package/src/crypto/session-manager.ts +200 -0
- package/src/i18n/en.ts +315 -0
- package/src/i18n/fr.ts +325 -0
- package/src/i18n/index.ts +9 -0
- package/src/i18n/locale.ts +15 -0
- package/src/i18n/translator.ts +37 -0
- package/src/index.ts +102 -0
- package/src/lib/device-detector.ts +32 -0
- package/src/lib/event-emitter.ts +90 -0
- package/src/lib/index.ts +15 -0
- package/src/lib/kwik-id-rn-sdk.ts +160 -0
- package/src/lib/verification-machine.ts +273 -0
- package/src/types/events.ts +75 -0
- package/src/types/index.ts +309 -0
- package/src/ui/components/KwikIDVerificationModal.tsx +450 -0
- package/src/ui/components/screens.tsx +283 -0
- package/src/ui/context/kwik-id-provider.tsx +72 -0
- package/src/ui/hooks/use-kwik-verification.ts +121 -0
- package/src/ui/index.ts +9 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless orchestrator for the RN SDK.
|
|
3
|
+
*
|
|
4
|
+
* Wraps SessionManager + ApiClient + EventEmitter so the UI (and advanced
|
|
5
|
+
* integrators) drive a single object. No camera/UI concerns live here.
|
|
6
|
+
*/
|
|
7
|
+
import { ApiClient, type StatusResponse } from "../api/api-client";
|
|
8
|
+
import { SessionManager } from "../crypto/session-manager";
|
|
9
|
+
import type {
|
|
10
|
+
CaptureAsset,
|
|
11
|
+
CaptureType,
|
|
12
|
+
DocumentType,
|
|
13
|
+
KwikIdConfig,
|
|
14
|
+
KwikIdEventHandler,
|
|
15
|
+
KwikIdEventName,
|
|
16
|
+
LivenessResult,
|
|
17
|
+
QualityResult,
|
|
18
|
+
SessionInfo,
|
|
19
|
+
} from "../types";
|
|
20
|
+
import { assertSupportedRuntime } from "./device-detector";
|
|
21
|
+
import { EventEmitter } from "./event-emitter";
|
|
22
|
+
|
|
23
|
+
export interface KwikIdRNSDKOptions extends KwikIdConfig {
|
|
24
|
+
/** Skip the Expo Go runtime guard (tests only). */
|
|
25
|
+
skipRuntimeCheck?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class KwikIdRNSDK {
|
|
29
|
+
private readonly events = new EventEmitter();
|
|
30
|
+
private readonly sessionManager: SessionManager;
|
|
31
|
+
private readonly api: ApiClient;
|
|
32
|
+
private readonly options: KwikIdRNSDKOptions;
|
|
33
|
+
private sessionInfo: SessionInfo | null = null;
|
|
34
|
+
private initialized = false;
|
|
35
|
+
|
|
36
|
+
constructor(options: KwikIdRNSDKOptions) {
|
|
37
|
+
this.options = options;
|
|
38
|
+
this.sessionManager = new SessionManager();
|
|
39
|
+
this.api = new ApiClient(this.sessionManager, {
|
|
40
|
+
baseUrl: options.baseUrl,
|
|
41
|
+
timeout: options.timeout,
|
|
42
|
+
debug: options.debug,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Validate the runtime + session token. Returns the org/session config. */
|
|
47
|
+
async initialize(): Promise<SessionInfo> {
|
|
48
|
+
if (!this.options.skipRuntimeCheck) {
|
|
49
|
+
assertSupportedRuntime();
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
this.sessionInfo = await this.api.validateSession(this.options.clientSecret);
|
|
53
|
+
this.initialized = true;
|
|
54
|
+
const session = this.sessionManager.getSession();
|
|
55
|
+
if (session) this.events.emit("session:created", session);
|
|
56
|
+
this.events.emit("ready", undefined);
|
|
57
|
+
return this.sessionInfo;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
this.events.emit("error", {
|
|
60
|
+
code: "INIT_FAILED",
|
|
61
|
+
message: (error as Error).message,
|
|
62
|
+
recoverable: false,
|
|
63
|
+
});
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Redeem a desktop→mobile handoff code, swapping in the mobile session token. */
|
|
69
|
+
async redeemHandoff(code: string): Promise<void> {
|
|
70
|
+
try {
|
|
71
|
+
const { sessionToken } = await this.api.redeemHandoff(code);
|
|
72
|
+
this.sessionInfo = await this.api.validateSession(sessionToken);
|
|
73
|
+
this.initialized = true;
|
|
74
|
+
const session = this.sessionManager.getSession();
|
|
75
|
+
this.events.emit("handoff:redeemed", { jobId: session?.jobId ?? "" });
|
|
76
|
+
} catch (error) {
|
|
77
|
+
this.events.emit("handoff:error", { error: error as Error });
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async uploadCapture(
|
|
83
|
+
type: CaptureType,
|
|
84
|
+
asset: CaptureAsset,
|
|
85
|
+
onProgress?: (progress: number) => void
|
|
86
|
+
): Promise<{ uploadId: string }> {
|
|
87
|
+
this.assertReady();
|
|
88
|
+
this.events.emit("upload:starting", { type });
|
|
89
|
+
try {
|
|
90
|
+
const res = await this.api.uploadCapture(type, asset, (p) => {
|
|
91
|
+
this.events.emit("upload:progress", { type, progress: p });
|
|
92
|
+
onProgress?.(p);
|
|
93
|
+
});
|
|
94
|
+
this.events.emit("upload:complete", { type, uploadId: res.uploadId });
|
|
95
|
+
return { uploadId: res.uploadId };
|
|
96
|
+
} catch (error) {
|
|
97
|
+
const retryable =
|
|
98
|
+
typeof (error as { isRetryable?: () => boolean }).isRetryable === "function"
|
|
99
|
+
? (error as { isRetryable: () => boolean }).isRetryable()
|
|
100
|
+
: false;
|
|
101
|
+
this.events.emit("upload:failed", { type, error: error as Error, retryable });
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async submit(
|
|
107
|
+
documentType: DocumentType,
|
|
108
|
+
analysis?: { quality?: QualityResult; liveness?: LivenessResult }
|
|
109
|
+
): Promise<{ jobId: string }> {
|
|
110
|
+
this.assertReady();
|
|
111
|
+
this.events.emit("verification:submitting", undefined);
|
|
112
|
+
try {
|
|
113
|
+
const res = await this.api.submitVerification(documentType, {
|
|
114
|
+
qualityScores: analysis?.quality,
|
|
115
|
+
livenessResult: analysis?.liveness,
|
|
116
|
+
});
|
|
117
|
+
const jobId = res.jobId ?? this.sessionManager.getSession()?.jobId ?? "";
|
|
118
|
+
this.events.emit("verification:submitted", { jobId });
|
|
119
|
+
return { jobId };
|
|
120
|
+
} catch (error) {
|
|
121
|
+
this.events.emit("verification:failed", { error: error as Error });
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
getStatus(): Promise<StatusResponse> {
|
|
127
|
+
this.assertReady();
|
|
128
|
+
return this.api.getStatus();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
getSessionInfo(): SessionInfo | null {
|
|
132
|
+
return this.sessionInfo;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** True when the session token is within ~2 min of expiry. */
|
|
136
|
+
needsRefresh(): boolean {
|
|
137
|
+
return this.sessionManager.needsRefresh();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
on<E extends KwikIdEventName>(event: E, handler: KwikIdEventHandler<E>): () => void {
|
|
141
|
+
return this.events.on(event, handler);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
reset(): void {
|
|
145
|
+
this.sessionManager.clearSession();
|
|
146
|
+
this.sessionInfo = null;
|
|
147
|
+
this.initialized = false;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
destroy(): void {
|
|
151
|
+
this.reset();
|
|
152
|
+
this.events.removeAllListeners();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private assertReady(): void {
|
|
156
|
+
if (!this.initialized) {
|
|
157
|
+
throw new Error("KwikIdRNSDK not initialized — call initialize() first");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure reducer for the RN verification flow.
|
|
3
|
+
*
|
|
4
|
+
* Adapted from the web SDK's KYCModalFlow SubStep machine. No React / no native
|
|
5
|
+
* dependency, so it is fully unit-testable. The selfie branch folds the web's
|
|
6
|
+
* `camera-selfie` into a single `liveness` step (align → passive/active → capture).
|
|
7
|
+
*/
|
|
8
|
+
import type {
|
|
9
|
+
CaptureAsset,
|
|
10
|
+
CaptureSlot,
|
|
11
|
+
CaptureType,
|
|
12
|
+
DocumentType,
|
|
13
|
+
LivenessResult,
|
|
14
|
+
VerificationOutcome,
|
|
15
|
+
VerificationSubStep,
|
|
16
|
+
} from "../types";
|
|
17
|
+
|
|
18
|
+
export interface MachineContext {
|
|
19
|
+
documentType: DocumentType | null;
|
|
20
|
+
front?: CaptureAsset;
|
|
21
|
+
back?: CaptureAsset;
|
|
22
|
+
selfie?: CaptureAsset;
|
|
23
|
+
livenessResult?: LivenessResult;
|
|
24
|
+
/** 0..100 upload/submit progress shown on the processing screen. */
|
|
25
|
+
uploadProgress: number;
|
|
26
|
+
uploadStage: CaptureType | "submitting" | null;
|
|
27
|
+
outcome?: VerificationOutcome;
|
|
28
|
+
error?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface MachineState {
|
|
32
|
+
step: VerificationSubStep;
|
|
33
|
+
context: MachineContext;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface MachineOptions {
|
|
37
|
+
/** When launched as the mobile redeemer of a desktop handoff. */
|
|
38
|
+
hasHandoffCode?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type MachineEvent =
|
|
42
|
+
| { t: "NEXT" }
|
|
43
|
+
| { t: "BACK" }
|
|
44
|
+
| { t: "SELECT_DOC"; doc: DocumentType }
|
|
45
|
+
| { t: "CAPTURED"; slot: CaptureSlot; asset: CaptureAsset }
|
|
46
|
+
| { t: "RETAKE"; slot: CaptureSlot }
|
|
47
|
+
| { t: "HANDOFF_REDEEMED" }
|
|
48
|
+
/** `result` is omitted until on-device liveness ships (Phase 2). */
|
|
49
|
+
| { t: "LIVENESS_DONE"; result?: LivenessResult; selfie: CaptureAsset }
|
|
50
|
+
| { t: "PROGRESS"; stage: MachineContext["uploadStage"]; value: number }
|
|
51
|
+
| { t: "SUBMITTED"; jobId: string }
|
|
52
|
+
| { t: "CANCEL" }
|
|
53
|
+
| { t: "FAILED"; error: string }
|
|
54
|
+
/** Back to a fresh intro, e.g. when the modal closes so the next run starts clean. */
|
|
55
|
+
| { t: "RESET" };
|
|
56
|
+
|
|
57
|
+
export function needsBackImage(doc: DocumentType | null): boolean {
|
|
58
|
+
return doc === "id_card" || doc === "drivers_license" || doc === "voters_card";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function initialState(): MachineState {
|
|
62
|
+
return {
|
|
63
|
+
step: "intro",
|
|
64
|
+
context: {
|
|
65
|
+
documentType: null,
|
|
66
|
+
uploadProgress: 0,
|
|
67
|
+
uploadStage: null,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Steps that contribute to the progress bar, in order (mirrors web getProgress). */
|
|
73
|
+
function progressSteps(ctx: MachineContext): VerificationSubStep[] {
|
|
74
|
+
const steps: VerificationSubStep[] = [
|
|
75
|
+
"document-type",
|
|
76
|
+
"prepare-front",
|
|
77
|
+
"camera-front",
|
|
78
|
+
"confirm-front",
|
|
79
|
+
];
|
|
80
|
+
if (needsBackImage(ctx.documentType)) {
|
|
81
|
+
steps.push("prepare-back", "camera-back", "confirm-back");
|
|
82
|
+
}
|
|
83
|
+
steps.push("prepare-selfie", "liveness", "confirm-selfie");
|
|
84
|
+
return steps;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Progress-bar percentage (0..100) for the current step. */
|
|
88
|
+
export function getStepProgress(state: MachineState): number {
|
|
89
|
+
const hidden: VerificationSubStep[] = ["intro", "handoff-redeem", "processing", "result"];
|
|
90
|
+
if (hidden.includes(state.step)) return 0;
|
|
91
|
+
const steps = progressSteps(state.context);
|
|
92
|
+
const idx = steps.indexOf(state.step);
|
|
93
|
+
if (idx < 0) return 0;
|
|
94
|
+
return ((idx + 1) / steps.length) * 100;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Upload/submit progress banding (matches web performVerification):
|
|
99
|
+
* front 0–30, back 30–45, selfie 45–70 (or 30–55 without back), submit 80, done 100.
|
|
100
|
+
*/
|
|
101
|
+
export function computeUploadProgress(
|
|
102
|
+
stage: MachineContext["uploadStage"],
|
|
103
|
+
pct: number,
|
|
104
|
+
hasBack: boolean
|
|
105
|
+
): number {
|
|
106
|
+
switch (stage) {
|
|
107
|
+
case "document_front":
|
|
108
|
+
return Math.round(pct * 0.3);
|
|
109
|
+
case "document_back":
|
|
110
|
+
return 30 + Math.round(pct * 0.15);
|
|
111
|
+
case "selfie": {
|
|
112
|
+
const base = hasBack ? 45 : 30;
|
|
113
|
+
return base + Math.round(pct * 0.25);
|
|
114
|
+
}
|
|
115
|
+
case "submitting":
|
|
116
|
+
return Math.max(80, Math.round(pct));
|
|
117
|
+
default:
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const FORWARD_TAP: Partial<Record<VerificationSubStep, VerificationSubStep>> = {
|
|
123
|
+
"prepare-front": "camera-front",
|
|
124
|
+
"prepare-back": "camera-back",
|
|
125
|
+
"prepare-selfie": "liveness",
|
|
126
|
+
// 'confirm-front' is resolved dynamically (needs back?) in the reducer.
|
|
127
|
+
"confirm-back": "prepare-selfie",
|
|
128
|
+
"confirm-selfie": "processing",
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const BACK_FLOW: Partial<Record<VerificationSubStep, VerificationSubStep>> = {
|
|
132
|
+
"document-type": "intro",
|
|
133
|
+
"prepare-front": "document-type",
|
|
134
|
+
"camera-front": "prepare-front",
|
|
135
|
+
"confirm-front": "camera-front",
|
|
136
|
+
"prepare-back": "confirm-front",
|
|
137
|
+
"camera-back": "prepare-back",
|
|
138
|
+
"confirm-back": "camera-back",
|
|
139
|
+
"confirm-selfie": "prepare-selfie",
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export function reducer(
|
|
143
|
+
state: MachineState,
|
|
144
|
+
event: MachineEvent,
|
|
145
|
+
options: MachineOptions = {}
|
|
146
|
+
): MachineState {
|
|
147
|
+
const { step, context } = state;
|
|
148
|
+
|
|
149
|
+
switch (event.t) {
|
|
150
|
+
case "NEXT": {
|
|
151
|
+
if (step === "intro") {
|
|
152
|
+
return {
|
|
153
|
+
...state,
|
|
154
|
+
step: options.hasHandoffCode ? "handoff-redeem" : "document-type",
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (step === "confirm-front") {
|
|
158
|
+
return {
|
|
159
|
+
...state,
|
|
160
|
+
step: needsBackImage(context.documentType) ? "prepare-back" : "prepare-selfie",
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const next = FORWARD_TAP[step];
|
|
164
|
+
return next ? { ...state, step: next } : state;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
case "BACK": {
|
|
168
|
+
// Terminal / non-reversible steps.
|
|
169
|
+
if (step === "processing" || step === "result" || step === "liveness") return state;
|
|
170
|
+
if (step === "prepare-selfie") {
|
|
171
|
+
return {
|
|
172
|
+
...state,
|
|
173
|
+
step: needsBackImage(context.documentType) ? "confirm-back" : "confirm-front",
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
const prev = BACK_FLOW[step];
|
|
177
|
+
return prev ? { ...state, step: prev } : state;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
case "SELECT_DOC": {
|
|
181
|
+
if (step !== "document-type") return state;
|
|
182
|
+
return {
|
|
183
|
+
step: "prepare-front",
|
|
184
|
+
context: { ...context, documentType: event.doc },
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
case "HANDOFF_REDEEMED": {
|
|
189
|
+
if (step !== "handoff-redeem") return state;
|
|
190
|
+
return { ...state, step: "document-type" };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
case "CAPTURED": {
|
|
194
|
+
const ctx = { ...context, [event.slot]: event.asset };
|
|
195
|
+
if (event.slot === "front" && step === "camera-front") {
|
|
196
|
+
return { step: "confirm-front", context: ctx };
|
|
197
|
+
}
|
|
198
|
+
if (event.slot === "back" && step === "camera-back") {
|
|
199
|
+
return { step: "confirm-back", context: ctx };
|
|
200
|
+
}
|
|
201
|
+
return { ...state, context: ctx };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
case "RETAKE": {
|
|
205
|
+
if (event.slot === "front") {
|
|
206
|
+
return { step: "camera-front", context: { ...context, front: undefined } };
|
|
207
|
+
}
|
|
208
|
+
if (event.slot === "back") {
|
|
209
|
+
return { step: "camera-back", context: { ...context, back: undefined } };
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
step: "liveness",
|
|
213
|
+
context: { ...context, selfie: undefined, livenessResult: undefined },
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
case "LIVENESS_DONE": {
|
|
218
|
+
if (step !== "liveness") return state;
|
|
219
|
+
return {
|
|
220
|
+
step: "confirm-selfie",
|
|
221
|
+
context: { ...context, selfie: event.selfie, livenessResult: event.result },
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
case "PROGRESS": {
|
|
226
|
+
const hasBack = !!context.back;
|
|
227
|
+
return {
|
|
228
|
+
...state,
|
|
229
|
+
context: {
|
|
230
|
+
...context,
|
|
231
|
+
uploadStage: event.stage,
|
|
232
|
+
uploadProgress: computeUploadProgress(event.stage, event.value, hasBack),
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
case "SUBMITTED": {
|
|
238
|
+
return {
|
|
239
|
+
step: "result",
|
|
240
|
+
context: {
|
|
241
|
+
...context,
|
|
242
|
+
uploadProgress: 100,
|
|
243
|
+
uploadStage: null,
|
|
244
|
+
outcome: { status: "submitted", jobId: event.jobId },
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
case "FAILED": {
|
|
250
|
+
return {
|
|
251
|
+
step: "result",
|
|
252
|
+
context: {
|
|
253
|
+
...context,
|
|
254
|
+
error: event.error,
|
|
255
|
+
outcome: { status: "error", error: new Error(event.error) },
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
case "CANCEL": {
|
|
261
|
+
return {
|
|
262
|
+
...state,
|
|
263
|
+
context: { ...context, outcome: { status: "cancelled" } },
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
case "RESET":
|
|
268
|
+
return initialState();
|
|
269
|
+
|
|
270
|
+
default:
|
|
271
|
+
return state;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event vocabulary for @kwik-id/sdk-react-native.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the portable subset of the web SDK's KwikIdEvents — DOM/Blob/MediaStream
|
|
5
|
+
* payloads are replaced with RN-native equivalents (CaptureAsset, FaceSignals).
|
|
6
|
+
*/
|
|
7
|
+
import type {
|
|
8
|
+
CaptureAsset,
|
|
9
|
+
CaptureType,
|
|
10
|
+
Challenge,
|
|
11
|
+
ChallengeResult,
|
|
12
|
+
FaceSignals,
|
|
13
|
+
LivenessMode,
|
|
14
|
+
LivenessResult,
|
|
15
|
+
PassiveLivenessResult,
|
|
16
|
+
Session,
|
|
17
|
+
VerificationResult,
|
|
18
|
+
} from "./index";
|
|
19
|
+
|
|
20
|
+
export interface KwikIdEvents {
|
|
21
|
+
// Session
|
|
22
|
+
"session:created": Session;
|
|
23
|
+
"session:expired": { sessionId: string };
|
|
24
|
+
"session:refreshed": Session;
|
|
25
|
+
|
|
26
|
+
// Camera
|
|
27
|
+
"camera:ready": void;
|
|
28
|
+
"camera:error": { error: Error; recoverable: boolean };
|
|
29
|
+
"camera:permission_denied": { canAskAgain: boolean };
|
|
30
|
+
|
|
31
|
+
// Face / alignment
|
|
32
|
+
"face:detected": FaceSignals;
|
|
33
|
+
"face:lost": void;
|
|
34
|
+
"face:aligned": void;
|
|
35
|
+
"face:misaligned": { reason: string };
|
|
36
|
+
|
|
37
|
+
// Liveness
|
|
38
|
+
"liveness:starting": { mode: LivenessMode };
|
|
39
|
+
"liveness:challenge": Challenge;
|
|
40
|
+
"liveness:challenge_result": ChallengeResult;
|
|
41
|
+
"liveness:passive_result": PassiveLivenessResult;
|
|
42
|
+
"liveness:complete": LivenessResult;
|
|
43
|
+
"liveness:failed": { reason: string };
|
|
44
|
+
|
|
45
|
+
// Capture
|
|
46
|
+
"capture:starting": { type: CaptureType };
|
|
47
|
+
"capture:complete": { type: CaptureType; asset: CaptureAsset };
|
|
48
|
+
"capture:failed": { type: CaptureType; error: Error };
|
|
49
|
+
|
|
50
|
+
// Upload
|
|
51
|
+
"upload:starting": { type: CaptureType };
|
|
52
|
+
"upload:progress": { type: CaptureType; progress: number };
|
|
53
|
+
"upload:complete": { type: CaptureType; uploadId: string };
|
|
54
|
+
"upload:failed": { type: CaptureType; error: Error; retryable: boolean };
|
|
55
|
+
|
|
56
|
+
// Verification
|
|
57
|
+
"verification:submitting": void;
|
|
58
|
+
"verification:submitted": { jobId: string };
|
|
59
|
+
"verification:processing": { jobId: string; progress?: number };
|
|
60
|
+
"verification:complete": VerificationResult;
|
|
61
|
+
"verification:failed": { error: Error; jobId?: string };
|
|
62
|
+
|
|
63
|
+
// Handoff (mobile is the redeemer)
|
|
64
|
+
"handoff:redeemed": { jobId: string };
|
|
65
|
+
"handoff:error": { error: Error };
|
|
66
|
+
|
|
67
|
+
// General
|
|
68
|
+
ready: void;
|
|
69
|
+
error: { code: string; message: string; recoverable: boolean };
|
|
70
|
+
destroy: void;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type KwikIdEventName = keyof KwikIdEvents;
|
|
74
|
+
|
|
75
|
+
export type KwikIdEventHandler<T extends KwikIdEventName> = (data: KwikIdEvents[T]) => void;
|