@velion-la/onboarding-sdk-react-native 1.3.0-beta.14 → 1.3.0-beta.15
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/README.md +1 -1
- package/lib/commonjs/utils/deviceIntegrity.js +30 -17
- package/lib/commonjs/utils/deviceIntegrity.js.map +1 -1
- package/lib/module/utils/deviceIntegrity.js +30 -17
- package/lib/module/utils/deviceIntegrity.js.map +1 -1
- package/lib/typescript/utils/deviceIntegrity.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/utils/deviceIntegrity.ts +30 -16
package/README.md
CHANGED
|
@@ -563,7 +563,7 @@ App Attest on iOS, Play Integrity on Android. The proof is tied to the session
|
|
|
563
563
|
with a single-use challenge, and the backend records a verdict. Each workflow's
|
|
564
564
|
integrity policy decides what that verdict does; by default it only records.
|
|
565
565
|
|
|
566
|
-
Attestation never interrupts the flow. It waits at most
|
|
566
|
+
Attestation never interrupts the flow. It waits at most 15 seconds, and a device
|
|
567
567
|
that cannot attest continues as "no attestation": iOS simulators, Android without
|
|
568
568
|
Google Play Services and Huawei devices fall here, so a strict workflow can leave
|
|
569
569
|
those users out.
|
|
@@ -19,6 +19,9 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
19
19
|
|
|
20
20
|
/** The first iOS attestation can take seconds, but it must not hold the user for long. */
|
|
21
21
|
const ATTESTATION_TIMEOUT_MS = 10_000;
|
|
22
|
+
|
|
23
|
+
/** Leaves room for the attestation and the two calls around it. */
|
|
24
|
+
const REPORT_TIMEOUT_MS = 15_000;
|
|
22
25
|
async function attest(challenge, googleCloudProjectNumber) {
|
|
23
26
|
if (_reactNative.Platform.OS === 'ios') {
|
|
24
27
|
if (!AppIntegrity.isSupported) return undefined;
|
|
@@ -30,37 +33,47 @@ async function attest(challenge, googleCloudProjectNumber) {
|
|
|
30
33
|
await AppIntegrity.prepareIntegrityTokenProviderAsync(googleCloudProjectNumber);
|
|
31
34
|
return AppIntegrity.requestIntegrityCheckAsync(challenge);
|
|
32
35
|
}
|
|
33
|
-
|
|
36
|
+
|
|
37
|
+
/** Resolves to `undefined` past the limit, so neither a device nor the network can hold the flow. */
|
|
38
|
+
async function within(work, limitMs) {
|
|
34
39
|
let timer;
|
|
35
40
|
const timeout = new Promise(resolve => {
|
|
36
|
-
timer = setTimeout(() => resolve(undefined),
|
|
41
|
+
timer = setTimeout(() => resolve(undefined), limitMs);
|
|
37
42
|
});
|
|
38
43
|
try {
|
|
39
|
-
return await Promise.race([
|
|
44
|
+
return await Promise.race([work, timeout]);
|
|
45
|
+
} finally {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function attestOrSkip(challenge, googleCloudProjectNumber) {
|
|
50
|
+
try {
|
|
51
|
+
return await within(attest(challenge, googleCloudProjectNumber), ATTESTATION_TIMEOUT_MS);
|
|
40
52
|
} catch (err) {
|
|
41
53
|
_log.log.warn('[Integrity] attestation unavailable', err);
|
|
42
54
|
return undefined;
|
|
43
|
-
} finally {
|
|
44
|
-
clearTimeout(timer);
|
|
45
55
|
}
|
|
46
56
|
}
|
|
57
|
+
async function report(api, sessionId, googleCloudProjectNumber) {
|
|
58
|
+
const {
|
|
59
|
+
challenge
|
|
60
|
+
} = await api.post(`/sessions/${sessionId}/integrity-challenge`, {});
|
|
61
|
+
const token = await attestOrSkip(challenge, googleCloudProjectNumber);
|
|
62
|
+
const payload = {
|
|
63
|
+
challenge,
|
|
64
|
+
platform: _reactNative.Platform.OS === 'ios' ? 'IOS' : 'ANDROID',
|
|
65
|
+
...(token !== undefined && {
|
|
66
|
+
token
|
|
67
|
+
})
|
|
68
|
+
};
|
|
69
|
+
await api.post(`/sessions/${sessionId}/integrity`, payload);
|
|
70
|
+
}
|
|
47
71
|
|
|
48
72
|
/** Reports the attestation of the session; a device that cannot attest reports without a token. */
|
|
49
73
|
async function submitDeviceIntegrity(api, sessionId, googleCloudProjectNumber) {
|
|
50
74
|
if (_reactNative.Platform.OS !== 'ios' && _reactNative.Platform.OS !== 'android') return;
|
|
51
75
|
try {
|
|
52
|
-
|
|
53
|
-
challenge
|
|
54
|
-
} = await api.post(`/sessions/${sessionId}/integrity-challenge`, {});
|
|
55
|
-
const token = await attestWithin(challenge, googleCloudProjectNumber);
|
|
56
|
-
const payload = {
|
|
57
|
-
challenge,
|
|
58
|
-
platform: _reactNative.Platform.OS === 'ios' ? 'IOS' : 'ANDROID',
|
|
59
|
-
...(token !== undefined && {
|
|
60
|
-
token
|
|
61
|
-
})
|
|
62
|
-
};
|
|
63
|
-
await api.post(`/sessions/${sessionId}/integrity`, payload);
|
|
76
|
+
await within(report(api, sessionId, googleCloudProjectNumber), REPORT_TIMEOUT_MS);
|
|
64
77
|
} catch (err) {
|
|
65
78
|
_log.log.warn('[Integrity] could not report the attestation', err);
|
|
66
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AppIntegrity","_interopRequireWildcard","require","_reactNative","_log","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ATTESTATION_TIMEOUT_MS","attest","challenge","googleCloudProjectNumber","Platform","OS","isSupported","undefined","keyId","generateKeyAsync","attestation","attestKeyAsync","prepareIntegrityTokenProviderAsync","requestIntegrityCheckAsync","
|
|
1
|
+
{"version":3,"names":["AppIntegrity","_interopRequireWildcard","require","_reactNative","_log","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ATTESTATION_TIMEOUT_MS","REPORT_TIMEOUT_MS","attest","challenge","googleCloudProjectNumber","Platform","OS","isSupported","undefined","keyId","generateKeyAsync","attestation","attestKeyAsync","prepareIntegrityTokenProviderAsync","requestIntegrityCheckAsync","within","work","limitMs","timer","timeout","Promise","resolve","setTimeout","race","clearTimeout","attestOrSkip","err","log","warn","report","api","sessionId","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B,SAAS;EAClB;AACF;AAEA,eAAeqB,MAAMA,CAACC,GAAc,EAAEC,SAAiB,EAAE3B,wBAAiC,EAAiB;EACzG,MAAM;IAAED;EAAU,CAAC,GAAG,MAAM2B,GAAG,CAACE,IAAI,CAClC,aAAaD,SAAS,sBAAsB,EAC5C,CAAC,CACH,CAAC;EACD,MAAME,KAAK,GAAG,MAAMR,YAAY,CAACtB,SAAS,EAAEC,wBAAwB,CAAC;EACrE,MAAM8B,OAA+B,GAAG;IACtC/B,SAAS;IACTgC,QAAQ,EAAE9B,qBAAQ,CAACC,EAAE,KAAK,KAAK,GAAG,KAAK,GAAG,SAAS;IACnD,IAAI2B,KAAK,KAAKzB,SAAS,IAAI;MAAEyB;IAAM,CAAC;EACtC,CAAC;EACD,MAAMH,GAAG,CAACE,IAAI,CAAC,aAAaD,SAAS,YAAY,EAAEG,OAAO,CAAC;AAC7D;;AAEA;AACO,eAAeE,qBAAqBA,CACzCN,GAAc,EACdC,SAAiB,EACjB3B,wBAAiC,EAClB;EACf,IAAIC,qBAAQ,CAACC,EAAE,KAAK,KAAK,IAAID,qBAAQ,CAACC,EAAE,KAAK,SAAS,EAAE;EACxD,IAAI;IACF,MAAMS,MAAM,CAACc,MAAM,CAACC,GAAG,EAAEC,SAAS,EAAE3B,wBAAwB,CAAC,EAAEH,iBAAiB,CAAC;EACnF,CAAC,CAAC,OAAOyB,GAAG,EAAE;IACZC,QAAG,CAACC,IAAI,CAAC,8CAA8C,EAAEF,GAAG,CAAC;EAC/D;AACF","ignoreList":[]}
|
|
@@ -15,6 +15,9 @@ import { log } from './log';
|
|
|
15
15
|
|
|
16
16
|
/** The first iOS attestation can take seconds, but it must not hold the user for long. */
|
|
17
17
|
const ATTESTATION_TIMEOUT_MS = 10_000;
|
|
18
|
+
|
|
19
|
+
/** Leaves room for the attestation and the two calls around it. */
|
|
20
|
+
const REPORT_TIMEOUT_MS = 15_000;
|
|
18
21
|
async function attest(challenge, googleCloudProjectNumber) {
|
|
19
22
|
if (Platform.OS === 'ios') {
|
|
20
23
|
if (!AppIntegrity.isSupported) return undefined;
|
|
@@ -26,37 +29,47 @@ async function attest(challenge, googleCloudProjectNumber) {
|
|
|
26
29
|
await AppIntegrity.prepareIntegrityTokenProviderAsync(googleCloudProjectNumber);
|
|
27
30
|
return AppIntegrity.requestIntegrityCheckAsync(challenge);
|
|
28
31
|
}
|
|
29
|
-
|
|
32
|
+
|
|
33
|
+
/** Resolves to `undefined` past the limit, so neither a device nor the network can hold the flow. */
|
|
34
|
+
async function within(work, limitMs) {
|
|
30
35
|
let timer;
|
|
31
36
|
const timeout = new Promise(resolve => {
|
|
32
|
-
timer = setTimeout(() => resolve(undefined),
|
|
37
|
+
timer = setTimeout(() => resolve(undefined), limitMs);
|
|
33
38
|
});
|
|
34
39
|
try {
|
|
35
|
-
return await Promise.race([
|
|
40
|
+
return await Promise.race([work, timeout]);
|
|
41
|
+
} finally {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function attestOrSkip(challenge, googleCloudProjectNumber) {
|
|
46
|
+
try {
|
|
47
|
+
return await within(attest(challenge, googleCloudProjectNumber), ATTESTATION_TIMEOUT_MS);
|
|
36
48
|
} catch (err) {
|
|
37
49
|
log.warn('[Integrity] attestation unavailable', err);
|
|
38
50
|
return undefined;
|
|
39
|
-
} finally {
|
|
40
|
-
clearTimeout(timer);
|
|
41
51
|
}
|
|
42
52
|
}
|
|
53
|
+
async function report(api, sessionId, googleCloudProjectNumber) {
|
|
54
|
+
const {
|
|
55
|
+
challenge
|
|
56
|
+
} = await api.post(`/sessions/${sessionId}/integrity-challenge`, {});
|
|
57
|
+
const token = await attestOrSkip(challenge, googleCloudProjectNumber);
|
|
58
|
+
const payload = {
|
|
59
|
+
challenge,
|
|
60
|
+
platform: Platform.OS === 'ios' ? 'IOS' : 'ANDROID',
|
|
61
|
+
...(token !== undefined && {
|
|
62
|
+
token
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
await api.post(`/sessions/${sessionId}/integrity`, payload);
|
|
66
|
+
}
|
|
43
67
|
|
|
44
68
|
/** Reports the attestation of the session; a device that cannot attest reports without a token. */
|
|
45
69
|
export async function submitDeviceIntegrity(api, sessionId, googleCloudProjectNumber) {
|
|
46
70
|
if (Platform.OS !== 'ios' && Platform.OS !== 'android') return;
|
|
47
71
|
try {
|
|
48
|
-
|
|
49
|
-
challenge
|
|
50
|
-
} = await api.post(`/sessions/${sessionId}/integrity-challenge`, {});
|
|
51
|
-
const token = await attestWithin(challenge, googleCloudProjectNumber);
|
|
52
|
-
const payload = {
|
|
53
|
-
challenge,
|
|
54
|
-
platform: Platform.OS === 'ios' ? 'IOS' : 'ANDROID',
|
|
55
|
-
...(token !== undefined && {
|
|
56
|
-
token
|
|
57
|
-
})
|
|
58
|
-
};
|
|
59
|
-
await api.post(`/sessions/${sessionId}/integrity`, payload);
|
|
72
|
+
await within(report(api, sessionId, googleCloudProjectNumber), REPORT_TIMEOUT_MS);
|
|
60
73
|
} catch (err) {
|
|
61
74
|
log.warn('[Integrity] could not report the attestation', err);
|
|
62
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AppIntegrity","Platform","log","ATTESTATION_TIMEOUT_MS","attest","challenge","googleCloudProjectNumber","OS","isSupported","undefined","keyId","generateKeyAsync","attestation","attestKeyAsync","prepareIntegrityTokenProviderAsync","requestIntegrityCheckAsync","
|
|
1
|
+
{"version":3,"names":["AppIntegrity","Platform","log","ATTESTATION_TIMEOUT_MS","REPORT_TIMEOUT_MS","attest","challenge","googleCloudProjectNumber","OS","isSupported","undefined","keyId","generateKeyAsync","attestation","attestKeyAsync","prepareIntegrityTokenProviderAsync","requestIntegrityCheckAsync","within","work","limitMs","timer","timeout","Promise","resolve","setTimeout","race","clearTimeout","attestOrSkip","err","warn","report","api","sessionId","post","token","payload","platform","submitDeviceIntegrity"],"sourceRoot":"../../../src","sources":["utils/deviceIntegrity.ts"],"mappings":";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ils/deviceIntegrity.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"deviceIntegrity.d.ts","sourceRoot":"","sources":["../../../src/utils/deviceIntegrity.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AA0DlD,mGAAmG;AACnG,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,SAAS,EACd,SAAS,EAAE,MAAM,EACjB,wBAAwB,CAAC,EAAE,MAAM,GAChC,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velion-la/onboarding-sdk-react-native",
|
|
3
|
-
"version": "1.3.0-beta.
|
|
3
|
+
"version": "1.3.0-beta.15",
|
|
4
4
|
"description": "Native React Native SDK for the Velion Onboarding (KYC) flow: ID document OCR, passive + active liveness, device fingerprint, OTP verification, address picker, and personal / legal information forms.",
|
|
5
5
|
"main": "./lib/commonjs/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|
|
@@ -16,6 +16,9 @@ import { log } from './log';
|
|
|
16
16
|
/** The first iOS attestation can take seconds, but it must not hold the user for long. */
|
|
17
17
|
const ATTESTATION_TIMEOUT_MS = 10_000;
|
|
18
18
|
|
|
19
|
+
/** Leaves room for the attestation and the two calls around it. */
|
|
20
|
+
const REPORT_TIMEOUT_MS = 15_000;
|
|
21
|
+
|
|
19
22
|
async function attest(challenge: string, googleCloudProjectNumber?: string): Promise<string | undefined> {
|
|
20
23
|
if (Platform.OS === 'ios') {
|
|
21
24
|
if (!AppIntegrity.isSupported) return undefined;
|
|
@@ -28,21 +31,42 @@ async function attest(challenge: string, googleCloudProjectNumber?: string): Pro
|
|
|
28
31
|
return AppIntegrity.requestIntegrityCheckAsync(challenge);
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
/** Resolves to `undefined` past the limit, so neither a device nor the network can hold the flow. */
|
|
35
|
+
async function within<T>(work: Promise<T>, limitMs: number): Promise<T | undefined> {
|
|
32
36
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
33
37
|
const timeout = new Promise<undefined>((resolve) => {
|
|
34
|
-
timer = setTimeout(() => resolve(undefined),
|
|
38
|
+
timer = setTimeout(() => resolve(undefined), limitMs);
|
|
35
39
|
});
|
|
36
40
|
try {
|
|
37
|
-
return await Promise.race([
|
|
41
|
+
return await Promise.race([work, timeout]);
|
|
42
|
+
} finally {
|
|
43
|
+
clearTimeout(timer);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function attestOrSkip(challenge: string, googleCloudProjectNumber?: string): Promise<string | undefined> {
|
|
48
|
+
try {
|
|
49
|
+
return await within(attest(challenge, googleCloudProjectNumber), ATTESTATION_TIMEOUT_MS);
|
|
38
50
|
} catch (err) {
|
|
39
51
|
log.warn('[Integrity] attestation unavailable', err);
|
|
40
52
|
return undefined;
|
|
41
|
-
} finally {
|
|
42
|
-
clearTimeout(timer);
|
|
43
53
|
}
|
|
44
54
|
}
|
|
45
55
|
|
|
56
|
+
async function report(api: ApiCaller, sessionId: string, googleCloudProjectNumber?: string): Promise<void> {
|
|
57
|
+
const { challenge } = await api.post<IntegrityChallengeResponse>(
|
|
58
|
+
`/sessions/${sessionId}/integrity-challenge`,
|
|
59
|
+
{},
|
|
60
|
+
);
|
|
61
|
+
const token = await attestOrSkip(challenge, googleCloudProjectNumber);
|
|
62
|
+
const payload: SubmitIntegrityPayload = {
|
|
63
|
+
challenge,
|
|
64
|
+
platform: Platform.OS === 'ios' ? 'IOS' : 'ANDROID',
|
|
65
|
+
...(token !== undefined && { token }),
|
|
66
|
+
};
|
|
67
|
+
await api.post(`/sessions/${sessionId}/integrity`, payload);
|
|
68
|
+
}
|
|
69
|
+
|
|
46
70
|
/** Reports the attestation of the session; a device that cannot attest reports without a token. */
|
|
47
71
|
export async function submitDeviceIntegrity(
|
|
48
72
|
api: ApiCaller,
|
|
@@ -51,17 +75,7 @@ export async function submitDeviceIntegrity(
|
|
|
51
75
|
): Promise<void> {
|
|
52
76
|
if (Platform.OS !== 'ios' && Platform.OS !== 'android') return;
|
|
53
77
|
try {
|
|
54
|
-
|
|
55
|
-
`/sessions/${sessionId}/integrity-challenge`,
|
|
56
|
-
{},
|
|
57
|
-
);
|
|
58
|
-
const token = await attestWithin(challenge, googleCloudProjectNumber);
|
|
59
|
-
const payload: SubmitIntegrityPayload = {
|
|
60
|
-
challenge,
|
|
61
|
-
platform: Platform.OS === 'ios' ? 'IOS' : 'ANDROID',
|
|
62
|
-
...(token !== undefined && { token }),
|
|
63
|
-
};
|
|
64
|
-
await api.post(`/sessions/${sessionId}/integrity`, payload);
|
|
78
|
+
await within(report(api, sessionId, googleCloudProjectNumber), REPORT_TIMEOUT_MS);
|
|
65
79
|
} catch (err) {
|
|
66
80
|
log.warn('[Integrity] could not report the attestation', err);
|
|
67
81
|
}
|