@didit-protocol/sdk-web 0.5.3 → 0.7.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/README.md +8 -1
- package/dist/didit-sdk.cjs +221 -42
- package/dist/didit-sdk.cjs.js +221 -42
- package/dist/didit-sdk.cjs.js.map +1 -1
- package/dist/didit-sdk.cjs.map +1 -1
- package/dist/didit-sdk.esm.js +699 -266
- package/dist/didit-sdk.esm.js.map +1 -1
- package/dist/didit-sdk.module.js +222 -43
- package/dist/didit-sdk.module.js.map +1 -1
- package/dist/didit-sdk.umd.js +700 -265
- package/dist/didit-sdk.umd.js.map +1 -1
- package/dist/didit-sdk.umd.min.js +2 -2
- package/dist/didit-sdk.umd.min.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +7 -2
package/dist/didit-sdk.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Didit SDK for Web v0.
|
|
2
|
+
* Didit SDK for Web v0.7.0
|
|
3
3
|
* (c) 2026 Didit
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -10,24 +10,32 @@
|
|
|
10
10
|
})(this, (function (exports) { 'use strict';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* Didit verification frontend. It collects stable browser signals, hashes them
|
|
15
|
-
* with WebCrypto SHA-256 and persists a random device id in localStorage with a
|
|
16
|
-
* cookie fallback. The payload shape matches the didit-fp-v2 schema so the Didit
|
|
17
|
-
* backend middleware parses it identically to the verification flow:
|
|
13
|
+
* What the navigator alone says about automation.
|
|
18
14
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
15
|
+
* The score is the strongest flag found, not a count: one conclusive signal is not diluted because
|
|
16
|
+
* the other checks came back clean. Only what a browser never shows to a person (a driver's
|
|
17
|
+
* `navigator.webdriver`, a headless or automation user agent) weighs 0.8 or more.
|
|
21
18
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
function detectBotFromNavigator(signals) {
|
|
20
|
+
const flags = [];
|
|
21
|
+
const userAgent = signals.userAgent;
|
|
22
|
+
let score = 0;
|
|
23
|
+
if (typeof navigator !== "undefined" && navigator.webdriver) {
|
|
24
|
+
flags.push("webdriver");
|
|
25
|
+
score = 0.9;
|
|
26
|
+
}
|
|
27
|
+
if (/HeadlessChrome|PhantomJS|Selenium|puppeteer|playwright/i.test(userAgent)) {
|
|
28
|
+
flags.push("headless-ua");
|
|
29
|
+
score = 0.9;
|
|
30
|
+
}
|
|
31
|
+
if (signals.uaDataMobile === false && /Android|iPhone|iPad/i.test(userAgent)) {
|
|
32
|
+
flags.push("ua-mobile-mismatch");
|
|
33
|
+
score = score || 0.3;
|
|
34
|
+
}
|
|
35
|
+
return { score, flags };
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
const BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
27
|
-
let memoryPersistentId = null;
|
|
28
|
-
let cachedPayload = null;
|
|
29
|
-
let pendingPayload = null;
|
|
30
|
-
let cachedPayloadPromise = null;
|
|
31
39
|
function bytesToBase64Url(bytes) {
|
|
32
40
|
let output = "";
|
|
33
41
|
let i = 0;
|
|
@@ -51,12 +59,40 @@
|
|
|
51
59
|
}
|
|
52
60
|
return output;
|
|
53
61
|
}
|
|
62
|
+
function toBytes(input) {
|
|
63
|
+
if (typeof input === "string") {
|
|
64
|
+
return new TextEncoder().encode(input);
|
|
65
|
+
}
|
|
66
|
+
return input;
|
|
67
|
+
}
|
|
68
|
+
async function sha256Bytes(input) {
|
|
69
|
+
if (typeof crypto === "undefined" || !crypto.subtle) {
|
|
70
|
+
throw new Error("WebCrypto SubtleCrypto is not available");
|
|
71
|
+
}
|
|
72
|
+
const bytes = toBytes(input);
|
|
73
|
+
// crypto.subtle.digest needs a BufferSource; copy into a fresh ArrayBuffer-backed view
|
|
74
|
+
// so we are not handing over a SharedArrayBuffer-typed slice. The view itself is passed, not
|
|
75
|
+
// its buffer: a bare ArrayBuffer made in another realm (a test runner's sandbox on Node 20) is
|
|
76
|
+
// refused as "not an ArrayBuffer", and the hash would be left out; a view is accepted everywhere.
|
|
77
|
+
const view = new Uint8Array(bytes.byteLength);
|
|
78
|
+
view.set(bytes);
|
|
79
|
+
const digest = await crypto.subtle.digest("SHA-256", view);
|
|
80
|
+
return new Uint8Array(digest);
|
|
81
|
+
}
|
|
82
|
+
// SHA-256 truncated to the leading 128 bits, base64url-encoded (22 chars).
|
|
83
|
+
// Used as the composite fingerprint hash. 128 bits keeps the birthday boundary
|
|
84
|
+
// at 2^64 — collision-safe at any conceivable session volume.
|
|
85
|
+
async function sha256_128(input) {
|
|
86
|
+
const bytes = await sha256Bytes(input);
|
|
87
|
+
return bytesToBase64Url(bytes.slice(0, 16));
|
|
88
|
+
}
|
|
54
89
|
function randomBytes(length) {
|
|
55
90
|
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
56
91
|
const buffer = new Uint8Array(length);
|
|
57
92
|
crypto.getRandomValues(buffer);
|
|
58
93
|
return buffer;
|
|
59
94
|
}
|
|
95
|
+
// Math.random fallback — only reached in environments without WebCrypto.
|
|
60
96
|
const fallback = new Uint8Array(length);
|
|
61
97
|
for (let i = 0; i < length; i++) {
|
|
62
98
|
fallback[i] = Math.floor(Math.random() * 256);
|
|
@@ -66,27 +102,13 @@
|
|
|
66
102
|
function randomBase64Url(byteLength) {
|
|
67
103
|
return bytesToBase64Url(randomBytes(byteLength));
|
|
68
104
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const view = new Uint8Array(bytes.byteLength);
|
|
77
|
-
view.set(bytes);
|
|
78
|
-
const digest = await crypto.subtle.digest("SHA-256", view.buffer);
|
|
79
|
-
return bytesToBase64Url(new Uint8Array(digest).slice(0, 16));
|
|
80
|
-
}
|
|
81
|
-
// FNV-1a 32-bit fallback hash, only used when WebCrypto is unavailable.
|
|
82
|
-
function fnv1a32(value) {
|
|
83
|
-
let hash = 0x811c9dc5;
|
|
84
|
-
for (let i = 0; i < value.length; i++) {
|
|
85
|
-
hash ^= value.charCodeAt(i);
|
|
86
|
-
hash = Math.imul(hash, 0x01000193);
|
|
87
|
-
}
|
|
88
|
-
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
89
|
-
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Which fields the composite hash reads. It travels inside `signals`, the part of the payload
|
|
108
|
+
* Didit stores, so a stored hash can be told apart from one of an earlier version. A change to
|
|
109
|
+
* `canonicalNavigator` or to the full canonical form changes every device's hash once: raise it.
|
|
110
|
+
*/
|
|
111
|
+
const COMPOSITE_HASH_VERSION = 4;
|
|
90
112
|
function stableStringify(value) {
|
|
91
113
|
if (value === null || value === undefined)
|
|
92
114
|
return JSON.stringify(value ?? null);
|
|
@@ -99,200 +121,391 @@
|
|
|
99
121
|
}
|
|
100
122
|
return JSON.stringify(value);
|
|
101
123
|
}
|
|
102
|
-
|
|
103
|
-
|
|
124
|
+
/**
|
|
125
|
+
* The user agent without its version numbers: `Chrome/147.0.0.0`, `Version/17.5`,
|
|
126
|
+
* `Build/UP1A.231005.007`, `iPhone OS 17_5_1`, `Android 14`. They change with every browser and
|
|
127
|
+
* system update while the device stays the same; what is left names the browser, the system and,
|
|
128
|
+
* where the browser still gives it, the device model (`SM-S918B`, `2312DRA50G`).
|
|
129
|
+
*/
|
|
130
|
+
function userAgentWithoutVersions(userAgent) {
|
|
131
|
+
return userAgent
|
|
132
|
+
.replace(/\/[\w.]+/g, "")
|
|
133
|
+
.replace(/\d+(?:[._]\d+)+/g, "")
|
|
134
|
+
.replace(/\bAndroid \d+/g, "Android");
|
|
104
135
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
136
|
+
/**
|
|
137
|
+
* The browser's brand names without their versions. The placeholder brand Chromium adds
|
|
138
|
+
* ("Not_A Brand", "Not;A=Brand", ...) is left out: its spelling changes from one version to the next.
|
|
139
|
+
*/
|
|
140
|
+
function brandNames(brands) {
|
|
141
|
+
return brands
|
|
142
|
+
.map(brandName)
|
|
143
|
+
.filter((name) => !isPlaceholderBrand(name))
|
|
144
|
+
.sort();
|
|
115
145
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
146
|
+
/**
|
|
147
|
+
* `Google Chrome:147` is `Google Chrome`. The version follows the last colon, not the first: the
|
|
148
|
+
* placeholder has a colon of its own in two Chromium versions out of eleven (`Not:A-Brand:99`,
|
|
149
|
+
* `Not(A:Brand:8`). Cut at the first one it left `Not` or `Not(A` in the list as a brand of its
|
|
150
|
+
* own, and the hash changed with the browser's next update (version 3 did that).
|
|
151
|
+
*/
|
|
152
|
+
function brandName(brand) {
|
|
153
|
+
const colon = brand.lastIndexOf(":");
|
|
154
|
+
return colon < 0 ? brand : brand.slice(0, colon);
|
|
155
|
+
}
|
|
156
|
+
/** "not" with "brand" somewhere after it, in any case. Two searches, so a long name costs its length once. */
|
|
157
|
+
function isPlaceholderBrand(name) {
|
|
158
|
+
const lower = name.toLowerCase();
|
|
159
|
+
const not = lower.indexOf("not");
|
|
160
|
+
return not >= 0 && lower.indexOf("brand", not + 3) >= 0;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The navigator part of the canonical form: what describes the device and its browser and reads
|
|
164
|
+
* the same on every visit. No version numbers (a browser update is not another device) and the
|
|
165
|
+
* screen shorter side first (a phone turned on its side is not another device).
|
|
166
|
+
*
|
|
167
|
+
* The light fingerprint hashes this and the webview kind; the full one adds the graphics, font,
|
|
168
|
+
* math and API families (`canonicalize` in compose.ts). Both go through this one function.
|
|
169
|
+
*/
|
|
170
|
+
function canonicalNavigator(navigator) {
|
|
171
|
+
const screen = [navigator.screenWidth, navigator.screenHeight].sort((a, b) => (a ?? 0) - (b ?? 0));
|
|
172
|
+
return {
|
|
173
|
+
ua: userAgentWithoutVersions(navigator.userAgent),
|
|
174
|
+
platform: navigator.platform,
|
|
175
|
+
lang: navigator.language.split("-")[0],
|
|
176
|
+
languages: [...navigator.languages].sort(),
|
|
177
|
+
concurrency: navigator.hardwareConcurrencyQuantized,
|
|
178
|
+
memory: navigator.deviceMemory,
|
|
179
|
+
maxTouch: navigator.maxTouchPoints,
|
|
180
|
+
dpr: navigator.devicePixelRatio,
|
|
181
|
+
screen,
|
|
182
|
+
colorDepth: navigator.colorDepth,
|
|
183
|
+
timeZone: navigator.timeZone,
|
|
184
|
+
uaDataPlatform: navigator.uaDataPlatform,
|
|
185
|
+
uaDataBrands: brandNames(navigator.uaDataBrands),
|
|
186
|
+
};
|
|
125
187
|
}
|
|
126
|
-
|
|
188
|
+
/**
|
|
189
|
+
* The composite hash of a canonical form: SHA-256, first 128 bits, base64url. Empty where the
|
|
190
|
+
* browser has no WebCrypto (a page served without TLS): the hash is then left out, never replaced
|
|
191
|
+
* by a weaker one that would read as another device.
|
|
192
|
+
*/
|
|
193
|
+
async function compositeHashOf(canonical) {
|
|
127
194
|
try {
|
|
128
|
-
|
|
129
|
-
return null;
|
|
130
|
-
const prefix = `${PERSISTENT_ID_COOKIE_NAME}=`;
|
|
131
|
-
for (const part of document.cookie.split(";")) {
|
|
132
|
-
const trimmed = part.trim();
|
|
133
|
-
if (trimmed.startsWith(prefix)) {
|
|
134
|
-
const value = decodeURIComponent(trimmed.substring(prefix.length));
|
|
135
|
-
return isValidPersistentId(value) ? value : null;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return null;
|
|
195
|
+
return await sha256_128(stableStringify(canonical));
|
|
139
196
|
}
|
|
140
197
|
catch {
|
|
141
|
-
return
|
|
198
|
+
return "";
|
|
142
199
|
}
|
|
143
200
|
}
|
|
144
|
-
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The device headers a Didit API reads. They carry the identifiers only; the signals themselves
|
|
204
|
+
* travel in the request body (`fingerprint_v2`), which has no size limit a proxy would enforce.
|
|
205
|
+
*/
|
|
206
|
+
function payloadToHeaders(payload) {
|
|
207
|
+
if (!payload)
|
|
208
|
+
return {};
|
|
209
|
+
const headers = { "X-Didit-FP-V2": "1" };
|
|
210
|
+
if (payload.persistentId)
|
|
211
|
+
headers["X-Didit-PID"] = payload.persistentId;
|
|
212
|
+
if (payload.compositeHash)
|
|
213
|
+
headers["X-Didit-FP-Hash"] = payload.compositeHash;
|
|
214
|
+
if (payload.legacyCompatibilityHash)
|
|
215
|
+
headers["X-Didit-FP-Legacy"] = payload.legacyCompatibilityHash;
|
|
216
|
+
if (payload.signals?.webview?.kind)
|
|
217
|
+
headers["X-Didit-FP-Webview"] = payload.signals.webview.kind;
|
|
218
|
+
if (payload.bot?.score)
|
|
219
|
+
headers["X-Didit-FP-Bot-Score"] = payload.bot.score.toFixed(2);
|
|
220
|
+
return headers;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function safe(read, fallback) {
|
|
145
224
|
try {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const isSecure = typeof location !== "undefined" && location.protocol === "https:";
|
|
149
|
-
const attributes = [
|
|
150
|
-
`${PERSISTENT_ID_COOKIE_NAME}=${encodeURIComponent(id)}`,
|
|
151
|
-
"Path=/",
|
|
152
|
-
`Max-Age=${PERSISTENT_ID_COOKIE_MAX_AGE_SECONDS}`,
|
|
153
|
-
"SameSite=Lax"
|
|
154
|
-
];
|
|
155
|
-
if (isSecure)
|
|
156
|
-
attributes.push("Secure");
|
|
157
|
-
document.cookie = attributes.join("; ");
|
|
225
|
+
const value = read();
|
|
226
|
+
return value === undefined ? fallback : value;
|
|
158
227
|
}
|
|
159
228
|
catch {
|
|
160
|
-
|
|
229
|
+
return fallback;
|
|
161
230
|
}
|
|
162
231
|
}
|
|
163
|
-
function
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
memoryPersistentId = id;
|
|
187
|
-
// Self-heal any layer that was missing or mismatched.
|
|
188
|
-
if (fromLocalStorage !== id)
|
|
189
|
-
writeLocalStorageId(id);
|
|
190
|
-
if (fromCookie !== id)
|
|
191
|
-
writeCookieId(id);
|
|
192
|
-
return { id, sources, wasCreated };
|
|
232
|
+
function quantizeConcurrency(value) {
|
|
233
|
+
if (value === null)
|
|
234
|
+
return null;
|
|
235
|
+
if (value <= 1)
|
|
236
|
+
return 1;
|
|
237
|
+
if (value <= 2)
|
|
238
|
+
return 2;
|
|
239
|
+
if (value <= 4)
|
|
240
|
+
return 4;
|
|
241
|
+
if (value <= 6)
|
|
242
|
+
return 6;
|
|
243
|
+
if (value <= 8)
|
|
244
|
+
return 8;
|
|
245
|
+
if (value <= 12)
|
|
246
|
+
return 12;
|
|
247
|
+
if (value <= 16)
|
|
248
|
+
return 16;
|
|
249
|
+
return 20;
|
|
250
|
+
}
|
|
251
|
+
function normalizeUserAgent(ua) {
|
|
252
|
+
// Collapse fine-grained version numbers (147.0.7727.137 → 147) so two installs of the same major version match.
|
|
253
|
+
return ua.replace(/(\d+)(\.\d+)+/g, "$1");
|
|
193
254
|
}
|
|
194
255
|
function collectNavigatorSignals() {
|
|
195
|
-
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
const uaData = nav
|
|
205
|
-
? nav
|
|
206
|
-
.userAgentData
|
|
207
|
-
: undefined;
|
|
256
|
+
// Outside a browser there is no navigator: every read below then falls back to its empty value.
|
|
257
|
+
const present = typeof navigator !== "undefined";
|
|
258
|
+
const nav = (present ? navigator : {});
|
|
259
|
+
const userAgent = safe(() => nav.userAgent || "", "");
|
|
260
|
+
const concurrency = safe(() => nav.hardwareConcurrency ?? null, null);
|
|
261
|
+
const connection = safe(() => nav.connection || nav.mozConnection || nav.webkitConnection || null, null);
|
|
262
|
+
const screenObj = present && typeof screen !== "undefined" ? screen : null;
|
|
263
|
+
const uaData = safe(() => nav.userAgentData, undefined);
|
|
208
264
|
return {
|
|
209
|
-
userAgent
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
265
|
+
userAgent,
|
|
266
|
+
userAgentNormalized: normalizeUserAgent(userAgent),
|
|
267
|
+
platform: safe(() => nav.platform || "", ""),
|
|
268
|
+
language: safe(() => nav.language || "", ""),
|
|
269
|
+
languages: safe(() => (nav.languages ? [...nav.languages] : []), []),
|
|
270
|
+
hardwareConcurrency: concurrency,
|
|
271
|
+
hardwareConcurrencyQuantized: quantizeConcurrency(concurrency),
|
|
272
|
+
deviceMemory: safe(() => nav.deviceMemory ?? null, null),
|
|
273
|
+
maxTouchPoints: safe(() => nav.maxTouchPoints ?? null, null),
|
|
274
|
+
devicePixelRatio: safe(() => (present && typeof window !== "undefined" ? (window.devicePixelRatio ?? null) : null), null),
|
|
275
|
+
screenWidth: screenObj?.width ?? null,
|
|
276
|
+
screenHeight: screenObj?.height ?? null,
|
|
277
|
+
availWidth: screenObj?.availWidth ?? null,
|
|
278
|
+
availHeight: screenObj?.availHeight ?? null,
|
|
279
|
+
colorDepth: screenObj?.colorDepth ?? null,
|
|
280
|
+
pixelDepth: screenObj?.pixelDepth ?? null,
|
|
281
|
+
orientation: screenObj && "orientation" in screenObj ? (screenObj.orientation?.type ?? null) : null,
|
|
282
|
+
timeZone: safe(() => (present && typeof Intl !== "undefined" && Intl.DateTimeFormat ? Intl.DateTimeFormat().resolvedOptions().timeZone || "" : ""), ""),
|
|
283
|
+
connectionEffectiveType: connection?.effectiveType ?? null,
|
|
284
|
+
connectionDownlink: connection?.downlink ?? null,
|
|
285
|
+
uaDataMobile: uaData?.mobile ?? null,
|
|
224
286
|
uaDataPlatform: uaData?.platform ?? null,
|
|
225
|
-
|
|
226
|
-
|
|
287
|
+
uaDataBrands: uaData?.brands ? uaData.brands.map((b) => `${b.brand}:${b.version}`).sort() : [],
|
|
288
|
+
cookieEnabled: safe(() => nav.cookieEnabled ?? null, null),
|
|
289
|
+
doNotTrack: safe(() => nav.doNotTrack ?? null, null),
|
|
227
290
|
};
|
|
228
291
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
292
|
+
|
|
293
|
+
function detectWebViewContext(userAgent) {
|
|
294
|
+
if (!userAgent) {
|
|
295
|
+
return { kind: "browser", hostAppVersion: null, isStandaloneBrowser: true };
|
|
296
|
+
}
|
|
297
|
+
const ua = userAgent;
|
|
298
|
+
const waMatch = ua.match(/WA(?:4[A]|4iOS)\/([\d.]+)/);
|
|
299
|
+
if (waMatch)
|
|
300
|
+
return { kind: "whatsapp", hostAppVersion: waMatch[1], isStandaloneBrowser: false };
|
|
301
|
+
// Google app (iOS/Android) in-app browser. On iOS its WKWebView exposes no
|
|
302
|
+
// navigator.mediaDevices at all, so no capture is ever possible there.
|
|
303
|
+
const gsaMatch = ua.match(/GSA\/([\d.]+)/);
|
|
304
|
+
if (gsaMatch)
|
|
305
|
+
return { kind: "gsa", hostAppVersion: gsaMatch[1], isStandaloneBrowser: false };
|
|
306
|
+
const igMatch = ua.match(/Instagram\s+([\d.]+)/);
|
|
307
|
+
if (igMatch)
|
|
308
|
+
return { kind: "instagram", hostAppVersion: igMatch[1], isStandaloneBrowser: false };
|
|
309
|
+
if (/FBAN|FBAV/.test(ua)) {
|
|
310
|
+
const fbVer = ua.match(/FBAV\/([\d.]+)/);
|
|
311
|
+
return { kind: "facebook", hostAppVersion: fbVer?.[1] ?? null, isStandaloneBrowser: false };
|
|
312
|
+
}
|
|
313
|
+
if (/MessengerLiteForiOS|MessengerForiOS|FB_IAB\/Messenger/.test(ua)) {
|
|
314
|
+
return { kind: "messenger", hostAppVersion: null, isStandaloneBrowser: false };
|
|
315
|
+
}
|
|
316
|
+
const ttMatch = ua.match(/(?:musical_ly|TikTok|trill)_(\d+)/i);
|
|
317
|
+
if (ttMatch)
|
|
318
|
+
return { kind: "tiktok", hostAppVersion: ttMatch[1], isStandaloneBrowser: false };
|
|
319
|
+
const lineMatch = ua.match(/Line\/([\d.]+)/);
|
|
320
|
+
if (lineMatch)
|
|
321
|
+
return { kind: "line", hostAppVersion: lineMatch[1], isStandaloneBrowser: false };
|
|
322
|
+
if (/MicroMessenger/.test(ua)) {
|
|
323
|
+
const wcVer = ua.match(/MicroMessenger\/([\d.]+)/);
|
|
324
|
+
return { kind: "wechat", hostAppVersion: wcVer?.[1] ?? null, isStandaloneBrowser: false };
|
|
325
|
+
}
|
|
326
|
+
if (/Telegram/i.test(ua)) {
|
|
327
|
+
return { kind: "telegram", hostAppVersion: null, isStandaloneBrowser: false };
|
|
328
|
+
}
|
|
329
|
+
if (/Twitter|TwitterAndroid/i.test(ua)) {
|
|
330
|
+
return { kind: "twitter", hostAppVersion: null, isStandaloneBrowser: false };
|
|
331
|
+
}
|
|
332
|
+
if (/LinkedInApp/i.test(ua)) {
|
|
333
|
+
return { kind: "linkedin", hostAppVersion: null, isStandaloneBrowser: false };
|
|
334
|
+
}
|
|
335
|
+
if (/Snapchat/i.test(ua)) {
|
|
336
|
+
return { kind: "snapchat", hostAppVersion: null, isStandaloneBrowser: false };
|
|
337
|
+
}
|
|
338
|
+
if (/\bwv\)|\bWebView\b/i.test(ua)) {
|
|
339
|
+
return { kind: "generic-wv", hostAppVersion: null, isStandaloneBrowser: false };
|
|
340
|
+
}
|
|
341
|
+
return { kind: "browser", hostAppVersion: null, isStandaloneBrowser: true };
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const STORAGE_KEY = "didit-pid-v1";
|
|
345
|
+
const COOKIE_NAME = "didit_pid";
|
|
346
|
+
const COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 365 * 2;
|
|
347
|
+
const PERSISTENT_ID_BYTE_LENGTH = 16;
|
|
348
|
+
let memoryFallback = null;
|
|
349
|
+
function isValidPersistentId(value) {
|
|
350
|
+
return typeof value === "string" && /^[A-Za-z0-9_-]{20,32}$/.test(value);
|
|
351
|
+
}
|
|
352
|
+
const localStorageLayer = {
|
|
353
|
+
source: "localStorage",
|
|
354
|
+
read() {
|
|
355
|
+
try {
|
|
356
|
+
if (typeof localStorage === "undefined")
|
|
357
|
+
return null;
|
|
358
|
+
const value = localStorage.getItem(STORAGE_KEY);
|
|
359
|
+
return isValidPersistentId(value) ? value : null;
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
// Storage may be blocked (private mode, storage policies): the other layers still apply.
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
write(id) {
|
|
367
|
+
try {
|
|
368
|
+
if (typeof localStorage === "undefined")
|
|
369
|
+
return false;
|
|
370
|
+
localStorage.setItem(STORAGE_KEY, id);
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
};
|
|
378
|
+
const cookieLayer = {
|
|
379
|
+
source: "cookie",
|
|
380
|
+
read() {
|
|
381
|
+
try {
|
|
382
|
+
if (typeof document === "undefined" || !document.cookie)
|
|
383
|
+
return null;
|
|
384
|
+
const prefix = `${COOKIE_NAME}=`;
|
|
385
|
+
for (const part of document.cookie.split(";")) {
|
|
386
|
+
const trimmed = part.trim();
|
|
387
|
+
if (trimmed.startsWith(prefix)) {
|
|
388
|
+
const value = decodeURIComponent(trimmed.substring(prefix.length));
|
|
389
|
+
return isValidPersistentId(value) ? value : null;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
catch {
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
write(id) {
|
|
399
|
+
try {
|
|
400
|
+
if (typeof document === "undefined")
|
|
401
|
+
return false;
|
|
402
|
+
const isSecure = typeof location !== "undefined" && location.protocol === "https:";
|
|
403
|
+
const attributes = [
|
|
404
|
+
`${COOKIE_NAME}=${encodeURIComponent(id)}`,
|
|
405
|
+
"Path=/",
|
|
406
|
+
`Max-Age=${COOKIE_MAX_AGE_SECONDS}`,
|
|
407
|
+
"SameSite=Lax",
|
|
408
|
+
];
|
|
409
|
+
if (isSecure)
|
|
410
|
+
attributes.push("Secure");
|
|
411
|
+
document.cookie = attributes.join("; ");
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
414
|
+
catch {
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
/** The layers every browser answers at once. `storage-layers.ts` adds the ones that have to wait. */
|
|
420
|
+
const SYNC_STORAGE_LAYERS = [localStorageLayer, cookieLayer];
|
|
421
|
+
/** The value most layers agree on; on a tie, the layer listed first. */
|
|
422
|
+
function pickWinner(candidates) {
|
|
423
|
+
const tally = new Map();
|
|
424
|
+
for (const { id, source } of candidates) {
|
|
425
|
+
const existing = tally.get(id);
|
|
426
|
+
if (existing) {
|
|
427
|
+
existing.push(source);
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
tally.set(id, [source]);
|
|
431
|
+
}
|
|
235
432
|
}
|
|
236
|
-
|
|
237
|
-
|
|
433
|
+
let winner = candidates[0].id;
|
|
434
|
+
let winnerCount = 0;
|
|
435
|
+
for (const [id, sources] of tally) {
|
|
436
|
+
if (sources.length > winnerCount) {
|
|
437
|
+
winnerCount = sources.length;
|
|
438
|
+
winner = id;
|
|
439
|
+
}
|
|
238
440
|
}
|
|
239
|
-
return
|
|
441
|
+
return { id: winner, sources: tally.get(winner) || [] };
|
|
240
442
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
443
|
+
/**
|
|
444
|
+
* From what each layer answered: the id this browser profile is known by (the value most layers
|
|
445
|
+
* agree on, the one kept in memory when storage is blocked, or a new random one), and the layers
|
|
446
|
+
* that did not have it, for the caller to write it back to.
|
|
447
|
+
*/
|
|
448
|
+
function choosePersistentId(layers, values, embedderId) {
|
|
449
|
+
const candidates = [];
|
|
450
|
+
values.forEach((value, index) => {
|
|
451
|
+
if (value)
|
|
452
|
+
candidates.push({ id: value, source: layers[index].source });
|
|
453
|
+
});
|
|
454
|
+
// No layer has an id, and the page that embeds this one passed its own: this visit goes by it.
|
|
455
|
+
// It is not written to any layer and not kept in memory: the embedding page is where it lives,
|
|
456
|
+
// and a value another page supplies never becomes this origin's stored id.
|
|
457
|
+
if (!candidates.length && isValidPersistentId(embedderId)) {
|
|
458
|
+
return { result: { id: embedderId, sources: ["embedder"], wasCreated: false }, stale: [] };
|
|
246
459
|
}
|
|
247
|
-
if (
|
|
248
|
-
|
|
460
|
+
if (!candidates.length && memoryFallback && isValidPersistentId(memoryFallback)) {
|
|
461
|
+
candidates.push({ id: memoryFallback, source: "memory" });
|
|
249
462
|
}
|
|
250
|
-
|
|
251
|
-
|
|
463
|
+
let result;
|
|
464
|
+
if (candidates.length) {
|
|
465
|
+
const winner = pickWinner(candidates);
|
|
466
|
+
result = { id: winner.id, sources: winner.sources, wasCreated: false };
|
|
252
467
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
function canonicalizeSignals(signals) {
|
|
256
|
-
// Only drift-resistant fields, serialized with stable key order so the same
|
|
257
|
-
// device always produces the same composite hash.
|
|
258
|
-
const stable = {
|
|
259
|
-
platform: signals.platform,
|
|
260
|
-
navigator: {
|
|
261
|
-
ua: signals.navigator.userAgent,
|
|
262
|
-
platform: signals.navigator.platform,
|
|
263
|
-
lang: signals.navigator.language.split("-")[0],
|
|
264
|
-
languages: [...signals.navigator.languages].sort(),
|
|
265
|
-
concurrency: signals.navigator.hardwareConcurrency,
|
|
266
|
-
memory: signals.navigator.deviceMemory,
|
|
267
|
-
maxTouch: signals.navigator.maxTouchPoints,
|
|
268
|
-
dpr: signals.navigator.devicePixelRatio,
|
|
269
|
-
screen: [signals.navigator.screenWidth, signals.navigator.screenHeight],
|
|
270
|
-
colorDepth: signals.navigator.colorDepth,
|
|
271
|
-
timeZone: signals.navigator.timeZone,
|
|
272
|
-
uaDataPlatform: signals.navigator.uaDataPlatform,
|
|
273
|
-
uaDataBrands: signals.navigator.uaDataBrands
|
|
274
|
-
},
|
|
275
|
-
webview: signals.webview.kind
|
|
276
|
-
};
|
|
277
|
-
return stableStringify(stable);
|
|
278
|
-
}
|
|
279
|
-
async function computeCompositeHash(canonical) {
|
|
280
|
-
try {
|
|
281
|
-
return await sha256_128(canonical);
|
|
468
|
+
else {
|
|
469
|
+
result = { id: randomBase64Url(PERSISTENT_ID_BYTE_LENGTH), sources: ["fresh"], wasCreated: true };
|
|
282
470
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
471
|
+
memoryFallback = result.id;
|
|
472
|
+
return { result, stale: layers.filter((_, index) => values[index] !== result.id) };
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* The stored id from the layers that answer at once (localStorage and a cookie), written back to
|
|
476
|
+
* the one that missed it. `loadOrCreatePersistentIdFromBrowserStorage` (storage-layers.ts) reads
|
|
477
|
+
* the slow layers too.
|
|
478
|
+
*/
|
|
479
|
+
function loadOrCreatePersistentId() {
|
|
480
|
+
const layers = SYNC_STORAGE_LAYERS;
|
|
481
|
+
const { result, stale } = choosePersistentId(layers, layers.map((layer) => layer.read()));
|
|
482
|
+
stale.forEach((layer) => layer.write(result.id));
|
|
483
|
+
return result;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* The id this page already keeps, or null. It only reads: nothing is created and nothing is
|
|
487
|
+
* written, so asking never adds a cookie or a storage entry to a site that had none.
|
|
488
|
+
*/
|
|
489
|
+
function readStoredPersistentId() {
|
|
490
|
+
for (const layer of SYNC_STORAGE_LAYERS) {
|
|
491
|
+
const value = layer.read();
|
|
492
|
+
if (value)
|
|
493
|
+
return value;
|
|
286
494
|
}
|
|
495
|
+
return null;
|
|
287
496
|
}
|
|
497
|
+
|
|
498
|
+
let provider = null;
|
|
499
|
+
let cachedPayload = null;
|
|
500
|
+
let pendingPayload = null;
|
|
501
|
+
let cachedPayloadPromise = null;
|
|
502
|
+
/** Raised when the source of the payload changes, so a collection started before it is recognised. */
|
|
503
|
+
let generation = 0;
|
|
288
504
|
async function buildPayload() {
|
|
505
|
+
// These layers answer at once, so the id is in the payload before anything is awaited.
|
|
289
506
|
const persistent = loadOrCreatePersistentId();
|
|
290
507
|
const navigatorSignals = collectNavigatorSignals();
|
|
291
|
-
const
|
|
292
|
-
platform: "web",
|
|
293
|
-
navigator: navigatorSignals,
|
|
294
|
-
webview: { kind: detectWebViewKind(navigatorSignals.userAgent) }
|
|
295
|
-
};
|
|
508
|
+
const webview = detectWebViewContext(navigatorSignals.userAgent);
|
|
296
509
|
const payload = {
|
|
297
510
|
version: 2,
|
|
298
511
|
schema: "didit-fp-v2",
|
|
@@ -301,14 +514,24 @@
|
|
|
301
514
|
persistentId: persistent.id,
|
|
302
515
|
persistentIdSources: persistent.sources,
|
|
303
516
|
persistentIdWasCreated: persistent.wasCreated,
|
|
304
|
-
signals
|
|
305
|
-
|
|
306
|
-
|
|
517
|
+
signals: {
|
|
518
|
+
platform: "web",
|
|
519
|
+
tier: "lite",
|
|
520
|
+
compositeHashVersion: COMPOSITE_HASH_VERSION,
|
|
521
|
+
navigator: navigatorSignals,
|
|
522
|
+
webview,
|
|
523
|
+
},
|
|
524
|
+
bot: detectBotFromNavigator(navigatorSignals),
|
|
525
|
+
compositeHash: "",
|
|
307
526
|
};
|
|
308
527
|
// Keep all synchronously collected context available during the native hash.
|
|
309
528
|
// An empty hash is omitted from headers, never replaced with a different identity.
|
|
310
529
|
pendingPayload = payload;
|
|
311
|
-
|
|
530
|
+
const compositeHash = await compositeHashOf({
|
|
531
|
+
navigator: canonicalNavigator(navigatorSignals),
|
|
532
|
+
webview: webview.kind,
|
|
533
|
+
});
|
|
534
|
+
return { ...payload, compositeHash };
|
|
312
535
|
}
|
|
313
536
|
function isBrowserEnvironment() {
|
|
314
537
|
return typeof window !== "undefined" && typeof navigator !== "undefined" && typeof document !== "undefined";
|
|
@@ -325,10 +548,18 @@
|
|
|
325
548
|
if (cachedPayload)
|
|
326
549
|
return cachedPayload;
|
|
327
550
|
if (!cachedPayloadPromise) {
|
|
328
|
-
|
|
551
|
+
const started = generation;
|
|
552
|
+
cachedPayloadPromise = (provider ? provider.get() : buildPayload()).then((payload) => {
|
|
553
|
+
// The source changed while this was being collected (`enableDeviceIntelligence()` called
|
|
554
|
+
// with the lite collection still running): its result must not become the cached payload,
|
|
555
|
+
// and whoever waited for it gets the payload of the source that replaced it.
|
|
556
|
+
if (started !== generation)
|
|
557
|
+
return getDeviceFingerprintPayload();
|
|
329
558
|
cachedPayload = payload;
|
|
330
559
|
return payload;
|
|
331
560
|
}, (error) => {
|
|
561
|
+
if (started !== generation)
|
|
562
|
+
return getDeviceFingerprintPayload();
|
|
332
563
|
// Do not cache failures; a later call may succeed.
|
|
333
564
|
cachedPayloadPromise = null;
|
|
334
565
|
throw error;
|
|
@@ -338,22 +569,27 @@
|
|
|
338
569
|
}
|
|
339
570
|
/** Internal exit snapshot: never waits for WebCrypto or changes the cached payload. */
|
|
340
571
|
function getAvailableDeviceFingerprintPayload() {
|
|
341
|
-
return cachedPayload ?? pendingPayload;
|
|
342
|
-
}
|
|
343
|
-
function buildFingerprintHeaders(payload) {
|
|
344
|
-
if (!payload)
|
|
345
|
-
return {};
|
|
346
|
-
const headers = { "X-Didit-FP-V2": "1" };
|
|
347
|
-
if (payload.persistentId)
|
|
348
|
-
headers["X-Didit-PID"] = payload.persistentId;
|
|
349
|
-
if (payload.compositeHash)
|
|
350
|
-
headers["X-Didit-FP-Hash"] = payload.compositeHash;
|
|
351
|
-
if (payload.signals.webview.kind)
|
|
352
|
-
headers["X-Didit-FP-Webview"] = payload.signals.webview.kind;
|
|
353
|
-
if (payload.bot.score)
|
|
354
|
-
headers["X-Didit-FP-Bot-Score"] = payload.bot.score.toFixed(2);
|
|
355
|
-
return headers;
|
|
572
|
+
return cachedPayload ?? (provider ? provider.peek() : pendingPayload);
|
|
356
573
|
}
|
|
574
|
+
/**
|
|
575
|
+
* Makes another collector the source of the fingerprint this entry sends (null: back to the lite
|
|
576
|
+
* one). `enableDeviceIntelligence()` of `@didit-protocol/signals/device` calls it; nothing else should.
|
|
577
|
+
*/
|
|
578
|
+
function setDeviceSignalsProvider(next) {
|
|
579
|
+
provider = next;
|
|
580
|
+
generation += 1;
|
|
581
|
+
cachedPayload = null;
|
|
582
|
+
pendingPayload = null;
|
|
583
|
+
cachedPayloadPromise = null;
|
|
584
|
+
}
|
|
585
|
+
/** The device headers a Didit API reads from the payload. */
|
|
586
|
+
const buildFingerprintHeaders = payloadToHeaders;
|
|
587
|
+
/**
|
|
588
|
+
* The device id this page already keeps for Didit, or null when it keeps none. It never creates
|
|
589
|
+
* one: `@didit-protocol/sdk-web` hands it to the verification it opens, so a site that sends no
|
|
590
|
+
* events, transactions or sign-ins gets no cookie and no storage entry from being asked.
|
|
591
|
+
*/
|
|
592
|
+
const getStoredDeviceId = readStoredPersistentId;
|
|
357
593
|
|
|
358
594
|
const DEFAULT_EVENTS_BASE_URL = "https://verification.didit.me";
|
|
359
595
|
const BATCH_PATH = "/v1/events/batch/";
|
|
@@ -367,6 +603,8 @@
|
|
|
367
603
|
const NEVER_DROPPED = /^(security|payment|dispute|responsible_gambling)\.|^gameplay\.(bet_placed|bet_settled|p2p_settlement)$/;
|
|
368
604
|
const LOW_VALUE = /^session\.(page_view|sdk_heartbeat|sdk_loaded|device_seen|bot_signal_observed)$|^bonus\.promotion_viewed$|^affiliate\.referral_clicked$/;
|
|
369
605
|
const PRIORITY_NEVER_DROPPED = 2;
|
|
606
|
+
/** What `fetch` accepts as a header value: no control character but the tab, nothing above U+00FF. */
|
|
607
|
+
const HEADER_VALUE = /^[\t\x20-\x7e\x80-\xff]+$/;
|
|
370
608
|
/**
|
|
371
609
|
* Typed error for events Didit refused or the SDK had to drop. Thrown by
|
|
372
610
|
* submitEvent for a missing token or event, otherwise delivered to the
|
|
@@ -397,6 +635,16 @@
|
|
|
397
635
|
let listening = false;
|
|
398
636
|
let exiting = false;
|
|
399
637
|
let keepaliveBytes = 0;
|
|
638
|
+
/**
|
|
639
|
+
* `value` without the slashes it ends with. A loop, not a regular expression: `/\/+$/` rescans a
|
|
640
|
+
* long run of slashes from every one of them.
|
|
641
|
+
*/
|
|
642
|
+
function withoutTrailingSlashes(value) {
|
|
643
|
+
let end = value.length;
|
|
644
|
+
while (end > 0 && value.charCodeAt(end - 1) === 47)
|
|
645
|
+
end -= 1;
|
|
646
|
+
return value.slice(0, end);
|
|
647
|
+
}
|
|
400
648
|
function isRecord(value) {
|
|
401
649
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
402
650
|
}
|
|
@@ -704,7 +952,7 @@
|
|
|
704
952
|
*/
|
|
705
953
|
function configureEvents(configuration) {
|
|
706
954
|
const next = { ...settings, ...compact$1({ ...configuration }) };
|
|
707
|
-
next.baseUrl = next.baseUrl
|
|
955
|
+
next.baseUrl = withoutTrailingSlashes(next.baseUrl);
|
|
708
956
|
next.batchSize = Math.min(Math.max(1, Math.floor(next.batchSize)), MAX_BATCH_EVENTS);
|
|
709
957
|
next.flushIntervalMs = Math.max(0, next.flushIntervalMs);
|
|
710
958
|
next.maxQueueSize = Math.max(1, Math.floor(next.maxQueueSize));
|
|
@@ -724,11 +972,17 @@
|
|
|
724
972
|
* environment has no fetch.
|
|
725
973
|
*/
|
|
726
974
|
function submitEvent(options) {
|
|
727
|
-
|
|
975
|
+
// Without the white space around it, as `fetch` sends a header value.
|
|
976
|
+
const token = typeof options?.monitoringToken === "string" ? options.monitoringToken.trim() : "";
|
|
728
977
|
const event = options?.event;
|
|
729
|
-
if (!token
|
|
978
|
+
if (!token) {
|
|
730
979
|
throw new DiditEventError("invalid_token", "monitoringToken is required.");
|
|
731
980
|
}
|
|
981
|
+
// A line break or a NUL inside it, or a character above U+00FF, makes `fetch` throw before any
|
|
982
|
+
// request is made. Queued, such an event looked like a network failure and was retried forever.
|
|
983
|
+
if (!HEADER_VALUE.test(token)) {
|
|
984
|
+
throw new DiditEventError("invalid_token", "monitoringToken is not a value a header can carry.");
|
|
985
|
+
}
|
|
732
986
|
if (!isRecord(event) || !event.category || typeof event.actionType !== "string" || !event.actionType.trim()) {
|
|
733
987
|
throw new DiditEventError("validation", "event.category and event.actionType are required.");
|
|
734
988
|
}
|
|
@@ -747,7 +1001,7 @@
|
|
|
747
1001
|
// UTF-8 length; JSON.stringify never leaves a lone surrogate for encodeURIComponent to reject.
|
|
748
1002
|
bytes: byteLength(json),
|
|
749
1003
|
token,
|
|
750
|
-
url: `${(options.baseUrl ?? settings.baseUrl)
|
|
1004
|
+
url: `${withoutTrailingSlashes(options.baseUrl ?? settings.baseUrl)}${BATCH_PATH}`,
|
|
751
1005
|
priority: NEVER_DROPPED.test(kind) ? PRIORITY_NEVER_DROPPED : LOW_VALUE.test(kind) ? 0 : 1,
|
|
752
1006
|
sending: false
|
|
753
1007
|
});
|
|
@@ -797,9 +1051,10 @@
|
|
|
797
1051
|
loading: "didit-loading",
|
|
798
1052
|
confirmOverlay: "didit-confirm-overlay",
|
|
799
1053
|
confirmBox: "didit-confirm-box",
|
|
800
|
-
embedded: "didit-embedded"
|
|
1054
|
+
embedded: "didit-embedded",
|
|
1055
|
+
curtain: "didit-modal-curtain"
|
|
801
1056
|
};
|
|
802
|
-
const SDK_VERSION = "0.
|
|
1057
|
+
const SDK_VERSION = "0.7.0";
|
|
803
1058
|
/**
|
|
804
1059
|
* The permissions the verification iframe gets, in a modal and embedded:
|
|
805
1060
|
* camera and microphone for capture, clipboard-write for the flow's copy
|
|
@@ -825,6 +1080,13 @@
|
|
|
825
1080
|
presentation: "sdk_presentation",
|
|
826
1081
|
closeButton: "sdk_close_button"
|
|
827
1082
|
};
|
|
1083
|
+
/**
|
|
1084
|
+
* The verification-URL query parameter that carries the device id this page
|
|
1085
|
+
* already keeps for Didit, when it keeps one. A browser gives the flow in the
|
|
1086
|
+
* frame storage of its own, apart from this page's, so without it a
|
|
1087
|
+
* verification and this site's events never share a device id.
|
|
1088
|
+
*/
|
|
1089
|
+
const DEVICE_ID_QUERY_PARAM = "sdk_device_id";
|
|
828
1090
|
/**
|
|
829
1091
|
* Posted by the hosted flow when it lays itself out for the modal, with
|
|
830
1092
|
* `data: { contentHeight, colorScheme?, dir?, kind? }` (`kind` is `handoff` or `step`, `step` when missing). The modal then grows to the
|
|
@@ -951,15 +1213,21 @@
|
|
|
951
1213
|
* `showDocumentCameraSwitchButton` -> `document_camera_switch=true|false`,
|
|
952
1214
|
* `showLivenessCameraSwitchButton` -> `liveness_camera_switch=true|false`.
|
|
953
1215
|
* How the SDK presents the flow is always added: `sdk_presentation=modal|embedded`
|
|
954
|
-
* and, in a modal, `sdk_close_button=true|false`.
|
|
1216
|
+
* and, in a modal, `sdk_close_button=true|false`. `storedDeviceId`, when the
|
|
1217
|
+
* page has one, is added as `sdk_device_id`.
|
|
955
1218
|
* Each parameter is set (not appended) so the configuration wins over a value
|
|
956
1219
|
* already on the URL; existing query parameters and the hash are kept. A
|
|
957
1220
|
* value of the wrong shape is ignored with a warning rather than forwarded,
|
|
958
1221
|
* and a URL the browser cannot parse is returned as it came (the modal
|
|
959
1222
|
* reports it when it loads).
|
|
960
1223
|
*/
|
|
961
|
-
function buildVerificationUrl(url, configuration = {}) {
|
|
1224
|
+
function buildVerificationUrl(url, configuration = {}, storedDeviceId = null) {
|
|
962
1225
|
const params = presentationParams(configuration);
|
|
1226
|
+
// The id this page already keeps for Didit (see getStoredDeviceId): the flow in the frame, whose
|
|
1227
|
+
// own storage the browser keeps apart from this page's, can then be told apart as the same
|
|
1228
|
+
// device as this site's events. Absent when the page keeps none; nothing is created for it.
|
|
1229
|
+
if (storedDeviceId)
|
|
1230
|
+
params.push([DEVICE_ID_QUERY_PARAM, storedDeviceId]);
|
|
963
1231
|
for (const option of CAMERA_LENS_OPTIONS) {
|
|
964
1232
|
const value = configuration[option];
|
|
965
1233
|
if (value === undefined)
|
|
@@ -1465,6 +1733,10 @@
|
|
|
1465
1733
|
const SIZE_ANIMATION_MS = 300;
|
|
1466
1734
|
/** How long the modal waits for the first layout before it shows at step size, so it can never hang. */
|
|
1467
1735
|
const FIRST_LAYOUT_TIMEOUT_MS = 3000;
|
|
1736
|
+
/** A strip is a line or two of text: a taller value is not one, and would push the close button out of reach. */
|
|
1737
|
+
const MAX_TOP_INSET = 160;
|
|
1738
|
+
/** The flow's ground (site-ground in the design system), which a full-screen modal paints the page with. */
|
|
1739
|
+
const FLOW_GROUND = { light: "#ffffff", dark: "#0b0b0d" };
|
|
1468
1740
|
class VerificationModal {
|
|
1469
1741
|
constructor(configuration, callbacks) {
|
|
1470
1742
|
this.state = {
|
|
@@ -1487,10 +1759,9 @@
|
|
|
1487
1759
|
this.embedded = false;
|
|
1488
1760
|
this.embeddedContainer = null;
|
|
1489
1761
|
this.language = "en";
|
|
1490
|
-
/** The
|
|
1491
|
-
this.
|
|
1492
|
-
|
|
1493
|
-
this.previousBodyOverflow = null;
|
|
1762
|
+
/** The ground below the layout viewport (see showCurtain), while this modal is open. */
|
|
1763
|
+
this.curtain = null;
|
|
1764
|
+
this.boundPlaceCurtain = null;
|
|
1494
1765
|
this.modalId = generateModalId();
|
|
1495
1766
|
this.config = {
|
|
1496
1767
|
zIndex: configuration?.zIndex ?? DEFAULT_CONFIG.zIndex,
|
|
@@ -1584,13 +1855,14 @@
|
|
|
1584
1855
|
display: flex;
|
|
1585
1856
|
align-items: center;
|
|
1586
1857
|
justify-content: center;
|
|
1587
|
-
|
|
1858
|
+
/* The flow's ground, so a phone's loader meets the ground below the viewport without a seam. */
|
|
1859
|
+
background: ${FLOW_GROUND.light};
|
|
1588
1860
|
z-index: 5;
|
|
1589
1861
|
}
|
|
1590
1862
|
|
|
1591
1863
|
@media (prefers-color-scheme: dark) {
|
|
1592
1864
|
.${CSS_CLASSES.loading} {
|
|
1593
|
-
background:
|
|
1865
|
+
background: ${FLOW_GROUND.dark};
|
|
1594
1866
|
}
|
|
1595
1867
|
}
|
|
1596
1868
|
|
|
@@ -1780,6 +2052,40 @@
|
|
|
1780
2052
|
}
|
|
1781
2053
|
}
|
|
1782
2054
|
|
|
2055
|
+
/*
|
|
2056
|
+
* The flow's ground right below the layout viewport, in the page itself (see showCurtain):
|
|
2057
|
+
* on a phone, iOS browsers with their toolbars collapsed show a band of the page there,
|
|
2058
|
+
* below every fixed element, the full-screen modal included.
|
|
2059
|
+
*/
|
|
2060
|
+
.${CSS_CLASSES.curtain} {
|
|
2061
|
+
display: none;
|
|
2062
|
+
position: absolute;
|
|
2063
|
+
top: 0;
|
|
2064
|
+
left: 0;
|
|
2065
|
+
width: 100vw;
|
|
2066
|
+
height: 100vh;
|
|
2067
|
+
margin: 0;
|
|
2068
|
+
pointer-events: none;
|
|
2069
|
+
/* Under the modal where they meet for a frame while the toolbars move, above the page. */
|
|
2070
|
+
z-index: ${this.config.zIndex - 1};
|
|
2071
|
+
background: ${FLOW_GROUND.light};
|
|
2072
|
+
}
|
|
2073
|
+
|
|
2074
|
+
.${CSS_CLASSES.curtain}[data-didit-theme="dark"] {
|
|
2075
|
+
background: ${FLOW_GROUND.dark};
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
/* The exit confirmation's dimming continues over the ground below the viewport. */
|
|
2079
|
+
.${CSS_CLASSES.curtain}[data-didit-dimmed] {
|
|
2080
|
+
background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5));
|
|
2081
|
+
}
|
|
2082
|
+
|
|
2083
|
+
@media (max-width: 540px) {
|
|
2084
|
+
.${CSS_CLASSES.curtain} {
|
|
2085
|
+
display: block;
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
|
|
1783
2089
|
/*
|
|
1784
2090
|
* The hosted flow's layout message (didit:layout) brings the modal's size
|
|
1785
2091
|
* (see above), theme and direction. Colours are the design system tokens
|
|
@@ -1812,7 +2118,7 @@
|
|
|
1812
2118
|
}
|
|
1813
2119
|
|
|
1814
2120
|
.${CSS_CLASSES.flowSized} .${CSS_CLASSES.closeButton} {
|
|
1815
|
-
top: 8px;
|
|
2121
|
+
top: calc(8px + var(--didit-top-inset, 0px));
|
|
1816
2122
|
right: 8px;
|
|
1817
2123
|
width: 44px;
|
|
1818
2124
|
height: 44px;
|
|
@@ -2113,11 +2419,12 @@
|
|
|
2113
2419
|
/**
|
|
2114
2420
|
* Reads a didit:layout message's data. Without a positive contentHeight the
|
|
2115
2421
|
* message is ignored; a missing or unknown colorScheme follows the device,
|
|
2116
|
-
*
|
|
2422
|
+
* a missing or unknown dir follows the verification URL's language, and the
|
|
2423
|
+
* close button keeps its place without a plausible topInset.
|
|
2117
2424
|
*/
|
|
2118
2425
|
readFlowLayout(data) {
|
|
2119
2426
|
const fields = typeof data === "object" && data !== null ? data : {};
|
|
2120
|
-
const { contentHeight, colorScheme, dir, kind } = fields;
|
|
2427
|
+
const { contentHeight, colorScheme, dir, kind, topInset } = fields;
|
|
2121
2428
|
if (typeof contentHeight !== "number" || !Number.isFinite(contentHeight) || contentHeight <= 0) {
|
|
2122
2429
|
return null;
|
|
2123
2430
|
}
|
|
@@ -2126,7 +2433,8 @@
|
|
|
2126
2433
|
kind: kind === "handoff" ? "handoff" : "step",
|
|
2127
2434
|
contentHeight: Math.ceil(contentHeight),
|
|
2128
2435
|
colorScheme: colorScheme === "light" || colorScheme === "dark" ? colorScheme : prefersDark ? "dark" : "light",
|
|
2129
|
-
dir: dir === "ltr" || dir === "rtl" ? dir : isRtlLanguage(this.language) ? "rtl" : "ltr"
|
|
2436
|
+
dir: dir === "ltr" || dir === "rtl" ? dir : isRtlLanguage(this.language) ? "rtl" : "ltr",
|
|
2437
|
+
topInset: typeof topInset === "number" && topInset > 0 && topInset <= MAX_TOP_INSET ? Math.ceil(topInset) : 0
|
|
2130
2438
|
};
|
|
2131
2439
|
}
|
|
2132
2440
|
/** Embedded mode keeps filling the integrator's host element, whatever the flow reports. */
|
|
@@ -2140,7 +2448,11 @@
|
|
|
2140
2448
|
// The height the person sees now, before the reported content height can change it.
|
|
2141
2449
|
const shownHeight = this.container.offsetHeight;
|
|
2142
2450
|
this.container.style.setProperty("--didit-content-height", `${layout.contentHeight}px`);
|
|
2451
|
+
// The close button sits under the flow's strip, over its top bar.
|
|
2452
|
+
this.container.style.setProperty("--didit-top-inset", `${layout.topInset}px`);
|
|
2143
2453
|
this.matchPageBackground(layout.colorScheme);
|
|
2454
|
+
if (this.curtain)
|
|
2455
|
+
this.curtain.dataset.diditTheme = layout.colorScheme;
|
|
2144
2456
|
this.setModalKind(layout.kind, layout.kind === "handoff" && this.handoffHeight(layout) === shownHeight);
|
|
2145
2457
|
}
|
|
2146
2458
|
/** Whether the window is a computer-sized one: a phone is full screen and never waits for a layout. */
|
|
@@ -2211,18 +2523,125 @@
|
|
|
2211
2523
|
matchPageBackground(colorScheme) {
|
|
2212
2524
|
if (!window.matchMedia?.("(max-width: 540px)").matches)
|
|
2213
2525
|
return;
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2526
|
+
VerificationModal.pageBackground ?? (VerificationModal.pageBackground = {
|
|
2527
|
+
saved: { root: document.documentElement.style.backgroundColor, body: document.body.style.backgroundColor },
|
|
2528
|
+
grounds: new Map()
|
|
2529
|
+
});
|
|
2530
|
+
VerificationModal.pageBackground.grounds.set(this, colorScheme);
|
|
2531
|
+
VerificationModal.paintPageBackground();
|
|
2219
2532
|
}
|
|
2220
2533
|
restorePageBackground() {
|
|
2221
|
-
|
|
2534
|
+
const background = VerificationModal.pageBackground;
|
|
2535
|
+
if (!background?.grounds.delete(this))
|
|
2536
|
+
return;
|
|
2537
|
+
if (background.grounds.size > 0) {
|
|
2538
|
+
VerificationModal.paintPageBackground();
|
|
2222
2539
|
return;
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2540
|
+
}
|
|
2541
|
+
VerificationModal.pageBackground = null;
|
|
2542
|
+
document.documentElement.style.backgroundColor = background.saved.root;
|
|
2543
|
+
document.body.style.backgroundColor = background.saved.body;
|
|
2544
|
+
}
|
|
2545
|
+
/** The page shows the ground of the topmost open modal that lends one. */
|
|
2546
|
+
static paintPageBackground() {
|
|
2547
|
+
const background = VerificationModal.pageBackground;
|
|
2548
|
+
if (!background)
|
|
2549
|
+
return;
|
|
2550
|
+
const lender = [...VerificationModal.openModals].reverse().find((modal) => background.grounds.has(modal));
|
|
2551
|
+
const colorScheme = lender ? background.grounds.get(lender) : [...background.grounds.values()].pop();
|
|
2552
|
+
if (!colorScheme)
|
|
2553
|
+
return;
|
|
2554
|
+
document.documentElement.style.backgroundColor = FLOW_GROUND[colorScheme];
|
|
2555
|
+
document.body.style.backgroundColor = FLOW_GROUND[colorScheme];
|
|
2556
|
+
}
|
|
2557
|
+
/**
|
|
2558
|
+
* Stops the page scrolling under the modal. The lock is on the root element: Chrome for iOS keeps
|
|
2559
|
+
* scrolling a page whose body alone is `overflow: hidden` (a swipe over the modal scrolls the page
|
|
2560
|
+
* and toggles the browser's toolbars), and stops only when the root element is. A page that
|
|
2561
|
+
* scrolls its body instead of the window has its body locked too. The first modal to open keeps
|
|
2562
|
+
* the page's own values and the last one to close gives them back.
|
|
2563
|
+
*/
|
|
2564
|
+
lockPageScroll() {
|
|
2565
|
+
const lock = VerificationModal.pageScrollLock;
|
|
2566
|
+
if (lock) {
|
|
2567
|
+
lock.holders.add(this);
|
|
2568
|
+
return;
|
|
2569
|
+
}
|
|
2570
|
+
const root = document.documentElement;
|
|
2571
|
+
const body = document.body;
|
|
2572
|
+
// The body's overflow is the viewport's only while the root's is visible; otherwise a body with
|
|
2573
|
+
// an overflow of its own is a scroll container. Locking a body that is not one would clip the page
|
|
2574
|
+
// to the body's box.
|
|
2575
|
+
const clips = (overflow) => overflow !== "" && overflow !== "visible";
|
|
2576
|
+
const bodyScrollsItself = clips(window.getComputedStyle(root).overflowY) && clips(window.getComputedStyle(body).overflowY);
|
|
2577
|
+
VerificationModal.pageScrollLock = {
|
|
2578
|
+
holders: new Set([this]),
|
|
2579
|
+
root: { overflow: root.style.overflow, overscrollBehavior: root.style.overscrollBehavior },
|
|
2580
|
+
body: bodyScrollsItself ? { overflow: body.style.overflow } : null
|
|
2581
|
+
};
|
|
2582
|
+
root.style.overflow = "hidden";
|
|
2583
|
+
root.style.overscrollBehavior = "none";
|
|
2584
|
+
if (bodyScrollsItself)
|
|
2585
|
+
body.style.overflow = "hidden";
|
|
2586
|
+
}
|
|
2587
|
+
unlockPageScroll() {
|
|
2588
|
+
const lock = VerificationModal.pageScrollLock;
|
|
2589
|
+
if (!lock || !lock.holders.delete(this) || lock.holders.size > 0)
|
|
2590
|
+
return;
|
|
2591
|
+
VerificationModal.pageScrollLock = null;
|
|
2592
|
+
const root = document.documentElement;
|
|
2593
|
+
root.style.overflow = lock.root.overflow;
|
|
2594
|
+
root.style.overscrollBehavior = lock.root.overscrollBehavior;
|
|
2595
|
+
if (lock.body)
|
|
2596
|
+
document.body.style.overflow = lock.body.overflow;
|
|
2597
|
+
}
|
|
2598
|
+
/**
|
|
2599
|
+
* On a phone, Chrome for iOS (and the other iOS browsers built on WebKit's web view) shows a band
|
|
2600
|
+
* of the page below the layout viewport while its toolbars are collapsed: the home indicator's
|
|
2601
|
+
* area, and more while the toolbars move. Fixed elements end at the layout viewport, so the
|
|
2602
|
+
* full-screen modal cannot cover it and the host page's own content showed under the flow. The
|
|
2603
|
+
* curtain is part of the page instead: right below the viewport, in the flow's ground, so that band
|
|
2604
|
+
* shows the modal's ground. The page cannot scroll while the modal is open (lockPageScroll), and the
|
|
2605
|
+
* curtain follows the viewport when it resizes. Only phone-sized windows draw it (see the styles).
|
|
2606
|
+
*/
|
|
2607
|
+
showCurtain() {
|
|
2608
|
+
if (!this.curtain) {
|
|
2609
|
+
const curtain = document.createElement("div");
|
|
2610
|
+
curtain.className = CSS_CLASSES.curtain;
|
|
2611
|
+
curtain.setAttribute("aria-hidden", "true");
|
|
2612
|
+
document.body.appendChild(curtain);
|
|
2613
|
+
this.curtain = curtain;
|
|
2614
|
+
this.boundPlaceCurtain = () => this.placeCurtain();
|
|
2615
|
+
window.addEventListener("resize", this.boundPlaceCurtain);
|
|
2616
|
+
window.addEventListener("scroll", this.boundPlaceCurtain);
|
|
2617
|
+
window.visualViewport?.addEventListener("resize", this.boundPlaceCurtain);
|
|
2618
|
+
}
|
|
2619
|
+
// The device's theme until the newly loaded flow reports its own (applyFlowLayout).
|
|
2620
|
+
this.curtain.dataset.diditTheme = window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
2621
|
+
this.placeCurtain();
|
|
2622
|
+
}
|
|
2623
|
+
/** Puts the curtain's top at the bottom of the layout viewport, whatever its containing block is. */
|
|
2624
|
+
placeCurtain() {
|
|
2625
|
+
const curtain = this.curtain;
|
|
2626
|
+
if (!curtain)
|
|
2627
|
+
return;
|
|
2628
|
+
curtain.style.top = "0px";
|
|
2629
|
+
curtain.style.left = "0px";
|
|
2630
|
+
// At 0, 0 the curtain's box starts at its containing block's corner (the page's, or a positioned
|
|
2631
|
+
// body's), in viewport coordinates: the offset that brings its top to the viewport's bottom edge.
|
|
2632
|
+
const origin = curtain.getBoundingClientRect();
|
|
2633
|
+
curtain.style.top = `${window.innerHeight - origin.top}px`;
|
|
2634
|
+
curtain.style.left = `${-origin.left}px`;
|
|
2635
|
+
}
|
|
2636
|
+
removeCurtain() {
|
|
2637
|
+
if (this.boundPlaceCurtain) {
|
|
2638
|
+
window.removeEventListener("resize", this.boundPlaceCurtain);
|
|
2639
|
+
window.removeEventListener("scroll", this.boundPlaceCurtain);
|
|
2640
|
+
window.visualViewport?.removeEventListener("resize", this.boundPlaceCurtain);
|
|
2641
|
+
this.boundPlaceCurtain = null;
|
|
2642
|
+
}
|
|
2643
|
+
this.curtain?.remove();
|
|
2644
|
+
this.curtain = null;
|
|
2226
2645
|
}
|
|
2227
2646
|
/** Back to the neutral look until the newly loaded flow reports its theme and direction. */
|
|
2228
2647
|
resetFlowLayout() {
|
|
@@ -2234,6 +2653,7 @@
|
|
|
2234
2653
|
delete this.container.dataset.diditDir;
|
|
2235
2654
|
delete this.container.dataset.diditKind;
|
|
2236
2655
|
this.container.style.removeProperty("--didit-content-height");
|
|
2656
|
+
this.container.style.removeProperty("--didit-top-inset");
|
|
2237
2657
|
if (this.firstLayoutTimeout !== null) {
|
|
2238
2658
|
window.clearTimeout(this.firstLayoutTimeout);
|
|
2239
2659
|
this.firstLayoutTimeout = null;
|
|
@@ -2300,6 +2720,7 @@
|
|
|
2300
2720
|
: this.container?.querySelector(`.${CSS_CLASSES.closeButton}`) ?? this.iframe);
|
|
2301
2721
|
this.state.showConfirmation = true;
|
|
2302
2722
|
this.confirmOverlay.classList.add("active");
|
|
2723
|
+
this.curtain?.setAttribute("data-didit-dimmed", "");
|
|
2303
2724
|
if (this.iframe)
|
|
2304
2725
|
this.iframe.inert = true;
|
|
2305
2726
|
const close = this.container?.querySelector(`.${CSS_CLASSES.closeButton}`);
|
|
@@ -2323,6 +2744,7 @@
|
|
|
2323
2744
|
return;
|
|
2324
2745
|
this.state.showConfirmation = false;
|
|
2325
2746
|
this.confirmOverlay?.classList.remove("active");
|
|
2747
|
+
this.curtain?.removeAttribute("data-didit-dimmed");
|
|
2326
2748
|
if (this.iframe)
|
|
2327
2749
|
this.iframe.inert = false;
|
|
2328
2750
|
const close = this.container?.querySelector(`.${CSS_CLASSES.closeButton}`);
|
|
@@ -2350,11 +2772,6 @@
|
|
|
2350
2772
|
this.callbacks.onCloseConfirmed();
|
|
2351
2773
|
}
|
|
2352
2774
|
open(verificationUrl) {
|
|
2353
|
-
// Whether this modal already held its scroll lock before this call. Re-opening
|
|
2354
|
-
// an already-open instance must not re-capture previousBodyOverflow, or it
|
|
2355
|
-
// would record this modal's own "hidden" lock and close() could never restore
|
|
2356
|
-
// the real pre-lock value.
|
|
2357
|
-
const wasAlreadyOpen = this.state.isOpen;
|
|
2358
2775
|
this.language = detectLanguageFromUrl(verificationUrl);
|
|
2359
2776
|
if (!this.overlay && !this.container) {
|
|
2360
2777
|
this.createDOM();
|
|
@@ -2379,16 +2796,10 @@
|
|
|
2379
2796
|
return;
|
|
2380
2797
|
}
|
|
2381
2798
|
this.overlay?.classList.add("active");
|
|
2382
|
-
//
|
|
2383
|
-
//
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
// in effect is this modal's own lock, and previousBodyOverflow already
|
|
2387
|
-
// holds the correct pre-lock value.
|
|
2388
|
-
if (!wasAlreadyOpen) {
|
|
2389
|
-
this.previousBodyOverflow = document.body.style.overflow;
|
|
2390
|
-
}
|
|
2391
|
-
document.body.style.overflow = "hidden";
|
|
2799
|
+
// Idempotent: a re-open of a modal that is still open keeps its one hold on the lock, so
|
|
2800
|
+
// close() still gives the page back the values it had before any modal opened.
|
|
2801
|
+
this.lockPageScroll();
|
|
2802
|
+
this.showCurtain();
|
|
2392
2803
|
}
|
|
2393
2804
|
close() {
|
|
2394
2805
|
SDKLogger.log("Closing");
|
|
@@ -2406,8 +2817,8 @@
|
|
|
2406
2817
|
return;
|
|
2407
2818
|
}
|
|
2408
2819
|
this.overlay?.classList.remove("active");
|
|
2409
|
-
|
|
2410
|
-
this.
|
|
2820
|
+
this.removeCurtain();
|
|
2821
|
+
this.unlockPageScroll();
|
|
2411
2822
|
}
|
|
2412
2823
|
destroy() {
|
|
2413
2824
|
SDKLogger.log("Destroying");
|
|
@@ -2439,6 +2850,16 @@
|
|
|
2439
2850
|
* a transaction action modal stacked over the verification modal).
|
|
2440
2851
|
*/
|
|
2441
2852
|
VerificationModal.openModals = [];
|
|
2853
|
+
/**
|
|
2854
|
+
* The page's own background colours, kept while full-screen modals lend it their ground, shared by
|
|
2855
|
+
* every open modal: the topmost one's ground shows and the last one to give it back restores them.
|
|
2856
|
+
*/
|
|
2857
|
+
VerificationModal.pageBackground = null;
|
|
2858
|
+
/**
|
|
2859
|
+
* The page's scroll styles from before the first open modal locked them, shared by every open
|
|
2860
|
+
* modal: the last one to close gives them back.
|
|
2861
|
+
*/
|
|
2862
|
+
VerificationModal.pageScrollLock = null;
|
|
2442
2863
|
|
|
2443
2864
|
const DEFAULT_TRANSACTION_BASE_URL = "https://verification.didit.me";
|
|
2444
2865
|
const ACTION_POLL_INTERVAL_MS = 1500;
|
|
@@ -2758,6 +3179,18 @@
|
|
|
2758
3179
|
throw new Error(`Embedded container "#${containerId}" was not found in the page.`);
|
|
2759
3180
|
}
|
|
2760
3181
|
}
|
|
3182
|
+
/**
|
|
3183
|
+
* The device id this page already keeps for Didit (it has sent events, transactions or sign-ins),
|
|
3184
|
+
* or null. Reading it never creates one, and a browser that refuses the read is not an error.
|
|
3185
|
+
*/
|
|
3186
|
+
function storedDeviceId() {
|
|
3187
|
+
try {
|
|
3188
|
+
return getStoredDeviceId();
|
|
3189
|
+
}
|
|
3190
|
+
catch {
|
|
3191
|
+
return null;
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
2761
3194
|
class DiditSdk {
|
|
2762
3195
|
static get shared() {
|
|
2763
3196
|
if (!DiditSdk._instance) {
|
|
@@ -2831,7 +3264,7 @@
|
|
|
2831
3264
|
onMessage: (event) => this.handleVerificationEvent(event),
|
|
2832
3265
|
onIframeLoad: () => this.handleIframeLoad()
|
|
2833
3266
|
});
|
|
2834
|
-
this._url = buildVerificationUrl(url, config);
|
|
3267
|
+
this._url = buildVerificationUrl(url, config, storedDeviceId());
|
|
2835
3268
|
this.setState("loading");
|
|
2836
3269
|
this.emitInternalEvent("didit:started", {});
|
|
2837
3270
|
this._modal?.open(this._url);
|
|
@@ -3228,6 +3661,8 @@
|
|
|
3228
3661
|
exports.default = DiditSdk;
|
|
3229
3662
|
exports.flush = flush;
|
|
3230
3663
|
exports.getDeviceFingerprintPayload = getDeviceFingerprintPayload;
|
|
3664
|
+
exports.getStoredDeviceId = getStoredDeviceId;
|
|
3665
|
+
exports.setDeviceSignalsProvider = setDeviceSignalsProvider;
|
|
3231
3666
|
exports.submitEvent = submitEvent;
|
|
3232
3667
|
|
|
3233
3668
|
Object.defineProperty(exports, '__esModule', { value: true });
|