@velion-la/onboarding-sdk-react-native 1.3.0-beta.2 → 1.3.0-beta.20
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/CHANGELOG.md +16 -0
- package/README.md +66 -1
- package/android/build.gradle +15 -0
- package/android/src/main/java/la/velion/onboarding/sdk/devicekey/VelionDeviceKeyModule.kt +94 -0
- package/app.plugin.js +19 -2
- package/expo-module.config.json +9 -0
- package/ios/VelionDeviceKey.podspec +25 -0
- package/ios/VelionDeviceKeyModule.swift +76 -0
- package/lib/commonjs/core/VelionOnboarding.js +4 -1
- package/lib/commonjs/core/VelionOnboarding.js.map +1 -1
- package/lib/commonjs/steps/FingerprintStep.js +1 -0
- package/lib/commonjs/steps/FingerprintStep.js.map +1 -1
- package/lib/commonjs/steps/LivenessMatchStep.js +53 -8
- package/lib/commonjs/steps/LivenessMatchStep.js.map +1 -1
- package/lib/commonjs/steps/livenessRestart.js +32 -0
- package/lib/commonjs/steps/livenessRestart.js.map +1 -0
- package/lib/commonjs/transport/api.js +17 -1
- package/lib/commonjs/transport/api.js.map +1 -1
- package/lib/commonjs/types/index.js +12 -0
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/utils/appId.js +22 -0
- package/lib/commonjs/utils/appId.js.map +1 -0
- package/lib/commonjs/utils/deviceFingerprint.js +1 -1
- package/lib/commonjs/utils/deviceFingerprint.js.map +1 -1
- package/lib/commonjs/utils/deviceIntegrity.js +103 -0
- package/lib/commonjs/utils/deviceIntegrity.js.map +1 -0
- package/lib/commonjs/utils/deviceKey.js +53 -0
- package/lib/commonjs/utils/deviceKey.js.map +1 -0
- package/lib/commonjs/utils/frameChain.js +55 -0
- package/lib/commonjs/utils/frameChain.js.map +1 -0
- package/lib/commonjs/utils/hmac.js +6 -4
- package/lib/commonjs/utils/hmac.js.map +1 -1
- package/lib/commonjs/utils/jpegFromUri.js.map +1 -1
- package/lib/module/core/VelionOnboarding.js +4 -1
- package/lib/module/core/VelionOnboarding.js.map +1 -1
- package/lib/module/steps/FingerprintStep.js +1 -0
- package/lib/module/steps/FingerprintStep.js.map +1 -1
- package/lib/module/steps/LivenessMatchStep.js +53 -8
- package/lib/module/steps/LivenessMatchStep.js.map +1 -1
- package/lib/module/steps/livenessRestart.js +28 -0
- package/lib/module/steps/livenessRestart.js.map +1 -0
- package/lib/module/transport/api.js +17 -1
- package/lib/module/transport/api.js.map +1 -1
- package/lib/module/types/index.js +13 -0
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/utils/appId.js +18 -0
- package/lib/module/utils/appId.js.map +1 -0
- package/lib/module/utils/deviceFingerprint.js +1 -1
- package/lib/module/utils/deviceFingerprint.js.map +1 -1
- package/lib/module/utils/deviceIntegrity.js +99 -0
- package/lib/module/utils/deviceIntegrity.js.map +1 -0
- package/lib/module/utils/deviceKey.js +46 -0
- package/lib/module/utils/deviceKey.js.map +1 -0
- package/lib/module/utils/frameChain.js +52 -0
- package/lib/module/utils/frameChain.js.map +1 -0
- package/lib/module/utils/hmac.js +6 -4
- package/lib/module/utils/hmac.js.map +1 -1
- package/lib/module/utils/jpegFromUri.js.map +1 -1
- package/lib/typescript/core/VelionOnboarding.d.ts.map +1 -1
- package/lib/typescript/steps/FingerprintStep.d.ts.map +1 -1
- package/lib/typescript/steps/LivenessMatchStep.d.ts.map +1 -1
- package/lib/typescript/steps/livenessRestart.d.ts +25 -0
- package/lib/typescript/steps/livenessRestart.d.ts.map +1 -0
- package/lib/typescript/steps/types.d.ts +2 -0
- package/lib/typescript/steps/types.d.ts.map +1 -1
- package/lib/typescript/transport/api.d.ts.map +1 -1
- package/lib/typescript/types/index.d.ts +34 -0
- package/lib/typescript/types/index.d.ts.map +1 -1
- package/lib/typescript/utils/appId.d.ts +8 -0
- package/lib/typescript/utils/appId.d.ts.map +1 -0
- package/lib/typescript/utils/deviceFingerprint.d.ts +2 -0
- package/lib/typescript/utils/deviceFingerprint.d.ts.map +1 -1
- package/lib/typescript/utils/deviceIntegrity.d.ts +20 -0
- package/lib/typescript/utils/deviceIntegrity.d.ts.map +1 -0
- package/lib/typescript/utils/deviceKey.d.ts +13 -0
- package/lib/typescript/utils/deviceKey.d.ts.map +1 -0
- package/lib/typescript/utils/frameChain.d.ts +15 -0
- package/lib/typescript/utils/frameChain.d.ts.map +1 -0
- package/lib/typescript/utils/hmac.d.ts +3 -1
- package/lib/typescript/utils/hmac.d.ts.map +1 -1
- package/lib/typescript/utils/jpegFromUri.d.ts +1 -1
- package/lib/typescript/utils/jpegFromUri.d.ts.map +1 -1
- package/package.json +14 -9
- package/src/core/VelionOnboarding.ts +4 -1
- package/src/steps/FingerprintStep.tsx +1 -0
- package/src/steps/LivenessMatchStep.tsx +57 -8
- package/src/steps/livenessRestart.ts +32 -0
- package/src/steps/types.ts +2 -0
- package/src/transport/api.ts +17 -0
- package/src/types/index.ts +37 -0
- package/src/utils/appId.ts +15 -0
- package/src/utils/deviceFingerprint.ts +3 -1
- package/src/utils/deviceIntegrity.ts +102 -0
- package/src/utils/deviceKey.ts +52 -0
- package/src/utils/frameChain.ts +56 -0
- package/src/utils/hmac.ts +8 -5
- package/src/utils/jpegFromUri.ts +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Hash chain of the frames sent to Iris, signed by batches with
|
|
3
|
+
* the hardware key (ADR-061): a frame added, dropped or reordered breaks it, and
|
|
4
|
+
* capture never waits for the hardware. Must match `DeviceSignatures` in Iris:
|
|
5
|
+
*
|
|
6
|
+
* link(0) = sha256_hex("iris-frame-chain-v1\n" + sessionId)
|
|
7
|
+
* link(n) = sha256_hex(link(n-1) + "\n" + canonical frame line)
|
|
8
|
+
* signed = "iris-frame-batch-v1\n" + sessionId + "\n" + frameId + "\n" + link(frameId)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
12
|
+
import { bytesToHexLower } from './base64';
|
|
13
|
+
import { log } from './log';
|
|
14
|
+
|
|
15
|
+
/** A placeholder until signing is measured on real devices, as ADR-061 asks. */
|
|
16
|
+
const BATCH_INTERVAL_MS = 1_000;
|
|
17
|
+
|
|
18
|
+
function sha256Hex(text: string): string {
|
|
19
|
+
return bytesToHexLower(sha256(new TextEncoder().encode(text)));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createFrameChain(
|
|
23
|
+
sessionId: string,
|
|
24
|
+
sign: (message: string) => Promise<string>,
|
|
25
|
+
send: (json: string) => void,
|
|
26
|
+
now: () => number = Date.now,
|
|
27
|
+
) {
|
|
28
|
+
let link = sha256Hex(`iris-frame-chain-v1\n${sessionId}`);
|
|
29
|
+
let lastBatchAt = Number.NEGATIVE_INFINITY;
|
|
30
|
+
let signing = false;
|
|
31
|
+
|
|
32
|
+
async function signBatch(frameId: number, frameLink: string): Promise<void> {
|
|
33
|
+
signing = true;
|
|
34
|
+
lastBatchAt = now();
|
|
35
|
+
try {
|
|
36
|
+
const signature = await sign(`iris-frame-batch-v1\n${sessionId}\n${frameId}\n${frameLink}`);
|
|
37
|
+
send(JSON.stringify({ type: 'FRAME_BATCH', lastFrameId: frameId, signature }));
|
|
38
|
+
} catch (err) {
|
|
39
|
+
log.warn('[FrameChain] could not sign the batch', err);
|
|
40
|
+
} finally {
|
|
41
|
+
signing = false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
/** Links a frame just sent. Signing runs on its own, so capture never waits for it. */
|
|
47
|
+
addFrame(frameId: number, canonicalLine: string): void {
|
|
48
|
+
link = sha256Hex(`${link}\n${canonicalLine}`);
|
|
49
|
+
if (!signing && now() - lastBatchAt >= BATCH_INTERVAL_MS) {
|
|
50
|
+
void signBatch(frameId, link);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type FrameChain = ReturnType<typeof createFrameChain>;
|
package/src/utils/hmac.ts
CHANGED
|
@@ -34,28 +34,31 @@ export function importHmacKey(base64: string): HmacKey {
|
|
|
34
34
|
* Returns the JSON string ready to `ws.send`.
|
|
35
35
|
*/
|
|
36
36
|
export function buildSignedFrameEnvelope(args: {
|
|
37
|
-
key
|
|
37
|
+
/** `null` builds the same envelope without `mac`, for a session Iris gave no key. */
|
|
38
|
+
key: HmacKey | null;
|
|
38
39
|
sessionId: string;
|
|
39
40
|
frameId: number;
|
|
40
41
|
jpegBytes: Uint8Array;
|
|
41
42
|
jpegBase64: string;
|
|
42
43
|
/** Defaults to `Date.now()`. */
|
|
43
44
|
timestamp?: number;
|
|
44
|
-
}): { json: string; timestamp: number } {
|
|
45
|
+
}): { json: string; timestamp: number; canonical: string } {
|
|
45
46
|
const ts = args.timestamp ?? Date.now();
|
|
46
47
|
const digest = sha256(args.jpegBytes);
|
|
47
48
|
const digestHex = bytesToHexLower(digest);
|
|
48
49
|
const canonical = `${args.sessionId}\n${args.frameId}\n${ts}\n${digestHex}`;
|
|
49
|
-
const
|
|
50
|
-
|
|
50
|
+
const macHex = args.key
|
|
51
|
+
? bytesToHexLower(hmac(sha256, args.key.raw, new TextEncoder().encode(canonical)))
|
|
52
|
+
: undefined;
|
|
51
53
|
return {
|
|
52
54
|
json: JSON.stringify({
|
|
53
55
|
type: 'FRAME',
|
|
54
56
|
frameId: args.frameId,
|
|
55
57
|
timestamp: ts,
|
|
56
58
|
image: args.jpegBase64,
|
|
57
|
-
mac: macHex,
|
|
59
|
+
...(macHex !== undefined && { mac: macHex }),
|
|
58
60
|
}),
|
|
59
61
|
timestamp: ts,
|
|
62
|
+
canonical,
|
|
60
63
|
};
|
|
61
64
|
}
|
package/src/utils/jpegFromUri.ts
CHANGED
|
@@ -50,7 +50,7 @@ function normalise(uri: string): string {
|
|
|
50
50
|
* uploads, for instance. It skips the base64 encoding, which is pure waste for
|
|
51
51
|
* a multi-megabyte video.
|
|
52
52
|
*/
|
|
53
|
-
export async function readBytesFromUri(uri: string): Promise<Uint8Array
|
|
53
|
+
export async function readBytesFromUri(uri: string): Promise<Uint8Array<ArrayBuffer>> {
|
|
54
54
|
const buf = await new File(normalise(uri)).arrayBuffer();
|
|
55
55
|
return new Uint8Array(buf);
|
|
56
56
|
}
|