vesant-sdk 1.1.0 → 1.2.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/dist/{types-DgNbBnEH.d.ts → client-BIfLMfuC.d.mts} +274 -2
- package/dist/{types-DGbuL8c0.d.mts → client-BWp5FI3x.d.ts} +274 -2
- package/dist/compliance/index.d.mts +9 -4
- package/dist/compliance/index.d.ts +9 -4
- package/dist/compliance/index.js +297 -2
- package/dist/compliance/index.js.map +1 -1
- package/dist/compliance/index.mjs +297 -2
- package/dist/compliance/index.mjs.map +1 -1
- package/dist/geolocation/index.d.mts +3 -5
- package/dist/geolocation/index.d.ts +3 -5
- package/dist/geolocation/index.js +310 -250
- package/dist/geolocation/index.js.map +1 -1
- package/dist/geolocation/index.mjs +310 -250
- package/dist/geolocation/index.mjs.map +1 -1
- package/dist/index.d.mts +5 -7
- package/dist/index.d.ts +5 -7
- package/dist/index.js +322 -251
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +322 -251
- package/dist/index.mjs.map +1 -1
- package/dist/kyc/core.d.mts +2 -3
- package/dist/kyc/core.d.ts +2 -3
- package/dist/kyc/core.js +1 -1
- package/dist/kyc/core.js.map +1 -1
- package/dist/kyc/core.mjs +1 -1
- package/dist/kyc/core.mjs.map +1 -1
- package/dist/kyc/index.d.mts +2 -3
- package/dist/kyc/index.d.ts +2 -3
- package/dist/kyc/index.js +1 -1
- package/dist/kyc/index.js.map +1 -1
- package/dist/kyc/index.mjs +1 -1
- package/dist/kyc/index.mjs.map +1 -1
- package/dist/react.d.mts +3 -5
- package/dist/react.d.ts +3 -5
- package/dist/react.js +29 -3
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +29 -3
- package/dist/react.mjs.map +1 -1
- package/dist/risk-profile/index.d.mts +4 -5
- package/dist/risk-profile/index.d.ts +4 -5
- package/dist/risk-profile/index.js +1 -1
- package/dist/risk-profile/index.js.map +1 -1
- package/dist/risk-profile/index.mjs +1 -1
- package/dist/risk-profile/index.mjs.map +1 -1
- package/dist/{types-DBGM-bFB.d.mts → types-BpKxSXGF.d.mts} +50 -1
- package/dist/{types-DBGM-bFB.d.ts → types-BpKxSXGF.d.ts} +50 -1
- package/dist/{types-BQTkTvNp.d.mts → types-DKCQN4C5.d.mts} +1 -1
- package/dist/{types-BF8mYH2W.d.ts → types-DfHLp_tz.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/client-B7YzKVEm.d.mts +0 -52
- package/dist/client-BaNLT2Df.d.ts +0 -52
- package/dist/client-VKJg2GGT.d.mts +0 -253
- package/dist/client-hXdrPhA4.d.ts +0 -253
|
@@ -74,7 +74,7 @@ function createConsoleLogger() {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// src/core/version.ts
|
|
77
|
-
var SDK_VERSION = "1.
|
|
77
|
+
var SDK_VERSION = "1.2.0";
|
|
78
78
|
|
|
79
79
|
// src/core/client.ts
|
|
80
80
|
var BaseClient = class {
|
|
@@ -299,6 +299,281 @@ var BaseClient = class {
|
|
|
299
299
|
}
|
|
300
300
|
};
|
|
301
301
|
|
|
302
|
+
// src/shared/browser-utils.ts
|
|
303
|
+
function generateUUID() {
|
|
304
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
305
|
+
return crypto.randomUUID();
|
|
306
|
+
}
|
|
307
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
308
|
+
const r = Math.random() * 16 | 0;
|
|
309
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
310
|
+
return v.toString(16);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
function generateDeviceId() {
|
|
314
|
+
if (typeof window === "undefined" || typeof localStorage === "undefined") {
|
|
315
|
+
return generateUUID();
|
|
316
|
+
}
|
|
317
|
+
const storageKey = "cgs_device_id";
|
|
318
|
+
let deviceId = localStorage.getItem(storageKey);
|
|
319
|
+
if (!deviceId) {
|
|
320
|
+
deviceId = generateUUID();
|
|
321
|
+
localStorage.setItem(storageKey, deviceId);
|
|
322
|
+
}
|
|
323
|
+
return deviceId;
|
|
324
|
+
}
|
|
325
|
+
function getBrowserInfo() {
|
|
326
|
+
if (typeof navigator === "undefined") {
|
|
327
|
+
return { browser: "unknown", browser_version: "", os: "unknown", os_version: "" };
|
|
328
|
+
}
|
|
329
|
+
const ua = navigator.userAgent;
|
|
330
|
+
let browser = "unknown";
|
|
331
|
+
let browserVersion = "";
|
|
332
|
+
let os = "unknown";
|
|
333
|
+
let osVersion = "";
|
|
334
|
+
if (ua.includes("Firefox/")) {
|
|
335
|
+
browser = "Firefox";
|
|
336
|
+
browserVersion = ua.match(/Firefox\/([\d.]+)/)?.[1] || "";
|
|
337
|
+
} else if (ua.includes("Edg/")) {
|
|
338
|
+
browser = "Edge";
|
|
339
|
+
browserVersion = ua.match(/Edg\/([\d.]+)/)?.[1] || "";
|
|
340
|
+
} else if (ua.includes("Chrome/")) {
|
|
341
|
+
browser = "Chrome";
|
|
342
|
+
browserVersion = ua.match(/Chrome\/([\d.]+)/)?.[1] || "";
|
|
343
|
+
} else if (ua.includes("Safari/") && !ua.includes("Chrome")) {
|
|
344
|
+
browser = "Safari";
|
|
345
|
+
browserVersion = ua.match(/Version\/([\d.]+)/)?.[1] || "";
|
|
346
|
+
} else if (ua.includes("Opera") || ua.includes("OPR/")) {
|
|
347
|
+
browser = "Opera";
|
|
348
|
+
browserVersion = ua.match(/(?:Opera|OPR)\/([\d.]+)/)?.[1] || "";
|
|
349
|
+
}
|
|
350
|
+
if (ua.includes("Windows")) {
|
|
351
|
+
os = "Windows";
|
|
352
|
+
if (ua.includes("Windows NT 10.0")) osVersion = "10";
|
|
353
|
+
else if (ua.includes("Windows NT 6.3")) osVersion = "8.1";
|
|
354
|
+
else if (ua.includes("Windows NT 6.2")) osVersion = "8";
|
|
355
|
+
else if (ua.includes("Windows NT 6.1")) osVersion = "7";
|
|
356
|
+
} else if (ua.includes("Mac OS X")) {
|
|
357
|
+
os = "macOS";
|
|
358
|
+
osVersion = ua.match(/Mac OS X ([\d_]+)/)?.[1]?.replace(/_/g, ".") || "";
|
|
359
|
+
} else if (ua.includes("Linux")) {
|
|
360
|
+
os = "Linux";
|
|
361
|
+
} else if (ua.includes("Android")) {
|
|
362
|
+
os = "Android";
|
|
363
|
+
osVersion = ua.match(/Android ([\d.]+)/)?.[1] || "";
|
|
364
|
+
} else if (ua.includes("iOS") || ua.includes("iPhone") || ua.includes("iPad")) {
|
|
365
|
+
os = "iOS";
|
|
366
|
+
osVersion = ua.match(/OS ([\d_]+)/)?.[1]?.replace(/_/g, ".") || "";
|
|
367
|
+
}
|
|
368
|
+
return { browser, browser_version: browserVersion, os, os_version: osVersion };
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// src/geolocation/ciphertext.ts
|
|
372
|
+
var CIPHER_TEXT_EXPIRY_MINUTES = 5;
|
|
373
|
+
async function computeHMAC(key, message) {
|
|
374
|
+
if (typeof globalThis.crypto !== "undefined" && globalThis.crypto.subtle) {
|
|
375
|
+
const encoder = new TextEncoder();
|
|
376
|
+
const keyData = encoder.encode(key);
|
|
377
|
+
const msgData = encoder.encode(message);
|
|
378
|
+
const cryptoKey = await globalThis.crypto.subtle.importKey(
|
|
379
|
+
"raw",
|
|
380
|
+
keyData,
|
|
381
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
382
|
+
false,
|
|
383
|
+
["sign"]
|
|
384
|
+
);
|
|
385
|
+
const signature = await globalThis.crypto.subtle.sign("HMAC", cryptoKey, msgData);
|
|
386
|
+
const bytes = new Uint8Array(signature);
|
|
387
|
+
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
388
|
+
}
|
|
389
|
+
const { createHmac } = await import('crypto');
|
|
390
|
+
return createHmac("sha256", key).update(message).digest("hex");
|
|
391
|
+
}
|
|
392
|
+
function getWebGLInfo() {
|
|
393
|
+
if (typeof document === "undefined") return null;
|
|
394
|
+
try {
|
|
395
|
+
const canvas = document.createElement("canvas");
|
|
396
|
+
const gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
|
|
397
|
+
if (!gl) return null;
|
|
398
|
+
const debugInfo = gl.getExtension("WEBGL_debug_renderer_info");
|
|
399
|
+
if (!debugInfo) return null;
|
|
400
|
+
return {
|
|
401
|
+
vendor: gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL) || "",
|
|
402
|
+
renderer: gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) || ""
|
|
403
|
+
};
|
|
404
|
+
} catch {
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function getNetworkInfo() {
|
|
409
|
+
if (typeof navigator === "undefined") return void 0;
|
|
410
|
+
const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
|
|
411
|
+
if (!connection) return void 0;
|
|
412
|
+
return {
|
|
413
|
+
effective_type: connection.effectiveType,
|
|
414
|
+
downlink: connection.downlink,
|
|
415
|
+
rtt: connection.rtt,
|
|
416
|
+
save_data: connection.saveData
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
async function requestGPSLocation(timeout = 1e4, highAccuracy = true) {
|
|
420
|
+
if (typeof navigator === "undefined" || !navigator.geolocation) {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
return new Promise((resolve) => {
|
|
424
|
+
navigator.geolocation.getCurrentPosition(
|
|
425
|
+
(position) => {
|
|
426
|
+
const { latitude, longitude, accuracy } = position.coords;
|
|
427
|
+
if (latitude < -90 || latitude > 90) {
|
|
428
|
+
resolve(null);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
if (longitude < -180 || longitude > 180) {
|
|
432
|
+
resolve(null);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if (accuracy !== null && accuracy !== void 0 && accuracy <= 0) {
|
|
436
|
+
resolve(null);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
resolve({
|
|
440
|
+
latitude,
|
|
441
|
+
longitude,
|
|
442
|
+
accuracy,
|
|
443
|
+
altitude: position.coords.altitude ?? void 0,
|
|
444
|
+
altitude_accuracy: position.coords.altitudeAccuracy ?? void 0,
|
|
445
|
+
heading: position.coords.heading ?? void 0,
|
|
446
|
+
speed: position.coords.speed ?? void 0,
|
|
447
|
+
timestamp: position.timestamp
|
|
448
|
+
});
|
|
449
|
+
},
|
|
450
|
+
() => {
|
|
451
|
+
resolve(null);
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
enableHighAccuracy: highAccuracy,
|
|
455
|
+
timeout,
|
|
456
|
+
maximumAge: 0
|
|
457
|
+
}
|
|
458
|
+
);
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
function collectDeviceData(includeWebGL) {
|
|
462
|
+
const browserInfo = getBrowserInfo();
|
|
463
|
+
const webglInfo = includeWebGL ? getWebGLInfo() : null;
|
|
464
|
+
return {
|
|
465
|
+
device_id: generateDeviceId(),
|
|
466
|
+
user_agent: typeof navigator !== "undefined" ? navigator.userAgent : "",
|
|
467
|
+
platform: typeof navigator !== "undefined" ? navigator.platform : "",
|
|
468
|
+
browser: browserInfo.browser,
|
|
469
|
+
browser_version: browserInfo.browser_version,
|
|
470
|
+
os: browserInfo.os,
|
|
471
|
+
os_version: browserInfo.os_version,
|
|
472
|
+
screen_resolution: typeof screen !== "undefined" ? `${screen.width}x${screen.height}` : void 0,
|
|
473
|
+
language: typeof navigator !== "undefined" ? navigator.language : void 0,
|
|
474
|
+
timezone: Intl?.DateTimeFormat?.()?.resolvedOptions?.()?.timeZone,
|
|
475
|
+
color_depth: typeof screen !== "undefined" ? screen.colorDepth : void 0,
|
|
476
|
+
hardware_concurrency: typeof navigator !== "undefined" ? navigator.hardwareConcurrency : void 0,
|
|
477
|
+
device_memory: typeof navigator !== "undefined" ? navigator.deviceMemory : void 0,
|
|
478
|
+
touch_support: typeof navigator !== "undefined" ? navigator.maxTouchPoints > 0 : void 0,
|
|
479
|
+
webgl_vendor: webglInfo?.vendor,
|
|
480
|
+
webgl_renderer: webglInfo?.renderer
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
function encodePayload(payload) {
|
|
484
|
+
const json = JSON.stringify(payload);
|
|
485
|
+
if (typeof btoa !== "undefined") {
|
|
486
|
+
return btoa(unescape(encodeURIComponent(json)));
|
|
487
|
+
} else if (typeof Buffer !== "undefined") {
|
|
488
|
+
return Buffer.from(json, "utf-8").toString("base64");
|
|
489
|
+
}
|
|
490
|
+
throw new Error("No base64 encoding method available");
|
|
491
|
+
}
|
|
492
|
+
async function generateCipherText(options, config) {
|
|
493
|
+
const warnings = [];
|
|
494
|
+
let requestLocation = options.requestLocation ?? false;
|
|
495
|
+
if (config?.require_gps) {
|
|
496
|
+
const reason = options.reason;
|
|
497
|
+
if (reason === "login" && config.require_gps.login || reason === "registration" && config.require_gps.registration || reason === "transaction" && config.require_gps.transaction) {
|
|
498
|
+
requestLocation = true;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
const deviceData = collectDeviceData(options.includeWebGL !== false);
|
|
502
|
+
let locationData;
|
|
503
|
+
if (requestLocation) {
|
|
504
|
+
const location = await requestGPSLocation(
|
|
505
|
+
options.locationTimeout || 1e4,
|
|
506
|
+
options.highAccuracy !== false
|
|
507
|
+
);
|
|
508
|
+
if (location) {
|
|
509
|
+
locationData = location;
|
|
510
|
+
} else {
|
|
511
|
+
warnings.push("GPS location not available or permission denied");
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
let networkData;
|
|
515
|
+
if (options.includeNetworkInfo !== false) {
|
|
516
|
+
networkData = getNetworkInfo();
|
|
517
|
+
}
|
|
518
|
+
const now = /* @__PURE__ */ new Date();
|
|
519
|
+
const expiry = new Date(now.getTime() + CIPHER_TEXT_EXPIRY_MINUTES * 60 * 1e3);
|
|
520
|
+
const payload = {
|
|
521
|
+
device: deviceData,
|
|
522
|
+
location: locationData,
|
|
523
|
+
network: networkData,
|
|
524
|
+
metadata: {
|
|
525
|
+
collected_at: now.toISOString(),
|
|
526
|
+
sdk_version: SDK_VERSION,
|
|
527
|
+
collection_reason: options.reason,
|
|
528
|
+
page_url: typeof window !== "undefined" ? window.location.href : void 0,
|
|
529
|
+
referrer: typeof document !== "undefined" ? document.referrer || void 0 : void 0
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
const encoded = encodePayload(payload);
|
|
533
|
+
const timestamp = now.getTime().toString(36);
|
|
534
|
+
let cipherText;
|
|
535
|
+
const hmacKey = options.signingKey || options.apiKey;
|
|
536
|
+
if (hmacKey) {
|
|
537
|
+
const message = `02.${timestamp}.${encoded}`;
|
|
538
|
+
const hmac = await computeHMAC(hmacKey, message);
|
|
539
|
+
cipherText = `${message}.${hmac}`;
|
|
540
|
+
} else {
|
|
541
|
+
cipherText = `01.${timestamp}.${encoded}`;
|
|
542
|
+
}
|
|
543
|
+
return {
|
|
544
|
+
cipherText,
|
|
545
|
+
locationCaptured: !!locationData,
|
|
546
|
+
warnings: warnings.length > 0 ? warnings : void 0,
|
|
547
|
+
generatedAt: now.toISOString(),
|
|
548
|
+
expiresAt: expiry.toISOString()
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
function decodeCipherText(cipherText) {
|
|
552
|
+
try {
|
|
553
|
+
const parts = cipherText.split(".");
|
|
554
|
+
if (parts.length !== 3 && parts.length !== 4) return null;
|
|
555
|
+
const [version, , encodedB64] = parts;
|
|
556
|
+
if (version !== "01" && version !== "02") return null;
|
|
557
|
+
const json = decodeURIComponent(escape(atob(encodedB64)));
|
|
558
|
+
return JSON.parse(json);
|
|
559
|
+
} catch {
|
|
560
|
+
return null;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
function isCipherTextExpired(cipherText) {
|
|
564
|
+
try {
|
|
565
|
+
const parts = cipherText.split(".");
|
|
566
|
+
if (parts.length !== 3 && parts.length !== 4) return true;
|
|
567
|
+
const timestampB36 = parts[1];
|
|
568
|
+
const timestamp = parseInt(timestampB36, 36);
|
|
569
|
+
const now = Date.now();
|
|
570
|
+
const expiryMs = CIPHER_TEXT_EXPIRY_MINUTES * 60 * 1e3;
|
|
571
|
+
return now - timestamp > expiryMs;
|
|
572
|
+
} catch {
|
|
573
|
+
return true;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
302
577
|
// src/geolocation/client.ts
|
|
303
578
|
var GeolocationClient = class extends BaseClient {
|
|
304
579
|
constructor(config) {
|
|
@@ -399,7 +674,11 @@ var GeolocationClient = class extends BaseClient {
|
|
|
399
674
|
* ```
|
|
400
675
|
*/
|
|
401
676
|
async getGPSConfig(requestOptions) {
|
|
402
|
-
|
|
677
|
+
const config = await this.requestWithRetry("/api/v1/geo/config", void 0, void 0, void 0, requestOptions);
|
|
678
|
+
if (config.signing_key) {
|
|
679
|
+
this.cachedSigningKey = config.signing_key;
|
|
680
|
+
}
|
|
681
|
+
return config;
|
|
403
682
|
}
|
|
404
683
|
// ============================================================================
|
|
405
684
|
// CipherText Validation
|
|
@@ -659,258 +938,39 @@ var GeolocationClient = class extends BaseClient {
|
|
|
659
938
|
}, void 0, requestOptions);
|
|
660
939
|
}
|
|
661
940
|
// ============================================================================
|
|
662
|
-
//
|
|
941
|
+
// CipherText Generation
|
|
663
942
|
// ============================================================================
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
localStorage.setItem(storageKey, deviceId);
|
|
686
|
-
}
|
|
687
|
-
return deviceId;
|
|
688
|
-
}
|
|
689
|
-
function getBrowserInfo() {
|
|
690
|
-
if (typeof navigator === "undefined") {
|
|
691
|
-
return { browser: "unknown", browser_version: "", os: "unknown", os_version: "" };
|
|
692
|
-
}
|
|
693
|
-
const ua = navigator.userAgent;
|
|
694
|
-
let browser = "unknown";
|
|
695
|
-
let browserVersion = "";
|
|
696
|
-
let os = "unknown";
|
|
697
|
-
let osVersion = "";
|
|
698
|
-
if (ua.includes("Firefox/")) {
|
|
699
|
-
browser = "Firefox";
|
|
700
|
-
browserVersion = ua.match(/Firefox\/([\d.]+)/)?.[1] || "";
|
|
701
|
-
} else if (ua.includes("Edg/")) {
|
|
702
|
-
browser = "Edge";
|
|
703
|
-
browserVersion = ua.match(/Edg\/([\d.]+)/)?.[1] || "";
|
|
704
|
-
} else if (ua.includes("Chrome/")) {
|
|
705
|
-
browser = "Chrome";
|
|
706
|
-
browserVersion = ua.match(/Chrome\/([\d.]+)/)?.[1] || "";
|
|
707
|
-
} else if (ua.includes("Safari/") && !ua.includes("Chrome")) {
|
|
708
|
-
browser = "Safari";
|
|
709
|
-
browserVersion = ua.match(/Version\/([\d.]+)/)?.[1] || "";
|
|
710
|
-
} else if (ua.includes("Opera") || ua.includes("OPR/")) {
|
|
711
|
-
browser = "Opera";
|
|
712
|
-
browserVersion = ua.match(/(?:Opera|OPR)\/([\d.]+)/)?.[1] || "";
|
|
713
|
-
}
|
|
714
|
-
if (ua.includes("Windows")) {
|
|
715
|
-
os = "Windows";
|
|
716
|
-
if (ua.includes("Windows NT 10.0")) osVersion = "10";
|
|
717
|
-
else if (ua.includes("Windows NT 6.3")) osVersion = "8.1";
|
|
718
|
-
else if (ua.includes("Windows NT 6.2")) osVersion = "8";
|
|
719
|
-
else if (ua.includes("Windows NT 6.1")) osVersion = "7";
|
|
720
|
-
} else if (ua.includes("Mac OS X")) {
|
|
721
|
-
os = "macOS";
|
|
722
|
-
osVersion = ua.match(/Mac OS X ([\d_]+)/)?.[1]?.replace(/_/g, ".") || "";
|
|
723
|
-
} else if (ua.includes("Linux")) {
|
|
724
|
-
os = "Linux";
|
|
725
|
-
} else if (ua.includes("Android")) {
|
|
726
|
-
os = "Android";
|
|
727
|
-
osVersion = ua.match(/Android ([\d.]+)/)?.[1] || "";
|
|
728
|
-
} else if (ua.includes("iOS") || ua.includes("iPhone") || ua.includes("iPad")) {
|
|
729
|
-
os = "iOS";
|
|
730
|
-
osVersion = ua.match(/OS ([\d_]+)/)?.[1]?.replace(/_/g, ".") || "";
|
|
731
|
-
}
|
|
732
|
-
return { browser, browser_version: browserVersion, os, os_version: osVersion };
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
// src/geolocation/ciphertext.ts
|
|
736
|
-
var CIPHER_TEXT_EXPIRY_MINUTES = 5;
|
|
737
|
-
function getWebGLInfo() {
|
|
738
|
-
if (typeof document === "undefined") return null;
|
|
739
|
-
try {
|
|
740
|
-
const canvas = document.createElement("canvas");
|
|
741
|
-
const gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
|
|
742
|
-
if (!gl) return null;
|
|
743
|
-
const debugInfo = gl.getExtension("WEBGL_debug_renderer_info");
|
|
744
|
-
if (!debugInfo) return null;
|
|
745
|
-
return {
|
|
746
|
-
vendor: gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL) || "",
|
|
747
|
-
renderer: gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) || ""
|
|
748
|
-
};
|
|
749
|
-
} catch {
|
|
750
|
-
return null;
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
function getNetworkInfo() {
|
|
754
|
-
if (typeof navigator === "undefined") return void 0;
|
|
755
|
-
const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
|
|
756
|
-
if (!connection) return void 0;
|
|
757
|
-
return {
|
|
758
|
-
effective_type: connection.effectiveType,
|
|
759
|
-
downlink: connection.downlink,
|
|
760
|
-
rtt: connection.rtt,
|
|
761
|
-
save_data: connection.saveData
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
async function requestGPSLocation(timeout = 1e4, highAccuracy = true) {
|
|
765
|
-
if (typeof navigator === "undefined" || !navigator.geolocation) {
|
|
766
|
-
return null;
|
|
767
|
-
}
|
|
768
|
-
return new Promise((resolve) => {
|
|
769
|
-
navigator.geolocation.getCurrentPosition(
|
|
770
|
-
(position) => {
|
|
771
|
-
const { latitude, longitude, accuracy } = position.coords;
|
|
772
|
-
if (latitude < -90 || latitude > 90) {
|
|
773
|
-
resolve(null);
|
|
774
|
-
return;
|
|
775
|
-
}
|
|
776
|
-
if (longitude < -180 || longitude > 180) {
|
|
777
|
-
resolve(null);
|
|
778
|
-
return;
|
|
779
|
-
}
|
|
780
|
-
if (accuracy !== null && accuracy !== void 0 && accuracy <= 0) {
|
|
781
|
-
resolve(null);
|
|
782
|
-
return;
|
|
783
|
-
}
|
|
784
|
-
resolve({
|
|
785
|
-
latitude,
|
|
786
|
-
longitude,
|
|
787
|
-
accuracy,
|
|
788
|
-
altitude: position.coords.altitude ?? void 0,
|
|
789
|
-
altitude_accuracy: position.coords.altitudeAccuracy ?? void 0,
|
|
790
|
-
heading: position.coords.heading ?? void 0,
|
|
791
|
-
speed: position.coords.speed ?? void 0,
|
|
792
|
-
timestamp: position.timestamp
|
|
793
|
-
});
|
|
794
|
-
},
|
|
795
|
-
() => {
|
|
796
|
-
resolve(null);
|
|
797
|
-
},
|
|
798
|
-
{
|
|
799
|
-
enableHighAccuracy: highAccuracy,
|
|
800
|
-
timeout,
|
|
801
|
-
maximumAge: 0
|
|
802
|
-
}
|
|
803
|
-
);
|
|
804
|
-
});
|
|
805
|
-
}
|
|
806
|
-
function collectDeviceData(includeWebGL) {
|
|
807
|
-
const browserInfo = getBrowserInfo();
|
|
808
|
-
const webglInfo = includeWebGL ? getWebGLInfo() : null;
|
|
809
|
-
return {
|
|
810
|
-
device_id: generateDeviceId(),
|
|
811
|
-
user_agent: typeof navigator !== "undefined" ? navigator.userAgent : "",
|
|
812
|
-
platform: typeof navigator !== "undefined" ? navigator.platform : "",
|
|
813
|
-
browser: browserInfo.browser,
|
|
814
|
-
browser_version: browserInfo.browser_version,
|
|
815
|
-
os: browserInfo.os,
|
|
816
|
-
os_version: browserInfo.os_version,
|
|
817
|
-
screen_resolution: typeof screen !== "undefined" ? `${screen.width}x${screen.height}` : void 0,
|
|
818
|
-
language: typeof navigator !== "undefined" ? navigator.language : void 0,
|
|
819
|
-
timezone: Intl?.DateTimeFormat?.()?.resolvedOptions?.()?.timeZone,
|
|
820
|
-
color_depth: typeof screen !== "undefined" ? screen.colorDepth : void 0,
|
|
821
|
-
hardware_concurrency: typeof navigator !== "undefined" ? navigator.hardwareConcurrency : void 0,
|
|
822
|
-
device_memory: typeof navigator !== "undefined" ? navigator.deviceMemory : void 0,
|
|
823
|
-
touch_support: typeof navigator !== "undefined" ? navigator.maxTouchPoints > 0 : void 0,
|
|
824
|
-
webgl_vendor: webglInfo?.vendor,
|
|
825
|
-
webgl_renderer: webglInfo?.renderer
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
|
-
function encodePayload(payload) {
|
|
829
|
-
const json = JSON.stringify(payload);
|
|
830
|
-
if (typeof btoa !== "undefined") {
|
|
831
|
-
return btoa(unescape(encodeURIComponent(json)));
|
|
832
|
-
} else if (typeof Buffer !== "undefined") {
|
|
833
|
-
return Buffer.from(json, "utf-8").toString("base64");
|
|
834
|
-
}
|
|
835
|
-
throw new Error("No base64 encoding method available");
|
|
836
|
-
}
|
|
837
|
-
async function generateCipherText(options, config) {
|
|
838
|
-
const warnings = [];
|
|
839
|
-
let requestLocation = options.requestLocation ?? false;
|
|
840
|
-
if (config?.require_gps) {
|
|
841
|
-
const reason = options.reason;
|
|
842
|
-
if (reason === "login" && config.require_gps.login || reason === "registration" && config.require_gps.registration || reason === "transaction" && config.require_gps.transaction) {
|
|
843
|
-
requestLocation = true;
|
|
943
|
+
/**
|
|
944
|
+
* Generate a signed cipherText containing device and location data.
|
|
945
|
+
*
|
|
946
|
+
* Automatically passes the client's API key for HMAC signing (v02 format).
|
|
947
|
+
* If no API key is configured, falls back to unsigned v01 format.
|
|
948
|
+
*
|
|
949
|
+
* @param options - Options for cipherText generation
|
|
950
|
+
* @param gpsConfig - Optional GPS config (from getGPSConfig)
|
|
951
|
+
* @returns CipherText result with the signed string
|
|
952
|
+
*
|
|
953
|
+
* @example
|
|
954
|
+
* ```typescript
|
|
955
|
+
* const result = await client.generateCipherText({ reason: 'login' });
|
|
956
|
+
* console.log(result.cipherText); // v02 signed cipherText
|
|
957
|
+
* ```
|
|
958
|
+
*/
|
|
959
|
+
async generateCipherText(options, gpsConfig) {
|
|
960
|
+
let signingKey = this.cachedSigningKey;
|
|
961
|
+
if (!signingKey) {
|
|
962
|
+
const config = await this.getGPSConfig();
|
|
963
|
+
signingKey = config.signing_key;
|
|
844
964
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
if (requestLocation) {
|
|
849
|
-
const location = await requestGPSLocation(
|
|
850
|
-
options.locationTimeout || 1e4,
|
|
851
|
-
options.highAccuracy !== false
|
|
965
|
+
return generateCipherText(
|
|
966
|
+
{ ...options, signingKey: signingKey || void 0 },
|
|
967
|
+
gpsConfig
|
|
852
968
|
);
|
|
853
|
-
if (location) {
|
|
854
|
-
locationData = location;
|
|
855
|
-
} else {
|
|
856
|
-
warnings.push("GPS location not available or permission denied");
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
let networkData;
|
|
860
|
-
if (options.includeNetworkInfo !== false) {
|
|
861
|
-
networkData = getNetworkInfo();
|
|
862
969
|
}
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
location: locationData,
|
|
868
|
-
network: networkData,
|
|
869
|
-
metadata: {
|
|
870
|
-
collected_at: now.toISOString(),
|
|
871
|
-
sdk_version: SDK_VERSION,
|
|
872
|
-
collection_reason: options.reason,
|
|
873
|
-
page_url: typeof window !== "undefined" ? window.location.href : void 0,
|
|
874
|
-
referrer: typeof document !== "undefined" ? document.referrer || void 0 : void 0
|
|
875
|
-
}
|
|
876
|
-
};
|
|
877
|
-
const encoded = encodePayload(payload);
|
|
878
|
-
const version = "01";
|
|
879
|
-
const timestamp = now.getTime().toString(36);
|
|
880
|
-
const cipherText = `${version}.${timestamp}.${encoded}`;
|
|
881
|
-
return {
|
|
882
|
-
cipherText,
|
|
883
|
-
locationCaptured: !!locationData,
|
|
884
|
-
warnings: warnings.length > 0 ? warnings : void 0,
|
|
885
|
-
generatedAt: now.toISOString(),
|
|
886
|
-
expiresAt: expiry.toISOString()
|
|
887
|
-
};
|
|
888
|
-
}
|
|
889
|
-
function decodeCipherText(cipherText) {
|
|
890
|
-
try {
|
|
891
|
-
const parts = cipherText.split(".");
|
|
892
|
-
if (parts.length !== 3) return null;
|
|
893
|
-
const [version, , encodedB64] = parts;
|
|
894
|
-
if (version !== "01") return null;
|
|
895
|
-
const json = decodeURIComponent(escape(atob(encodedB64)));
|
|
896
|
-
return JSON.parse(json);
|
|
897
|
-
} catch {
|
|
898
|
-
return null;
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
function isCipherTextExpired(cipherText) {
|
|
902
|
-
try {
|
|
903
|
-
const parts = cipherText.split(".");
|
|
904
|
-
if (parts.length !== 3) return true;
|
|
905
|
-
const timestampB36 = parts[1];
|
|
906
|
-
const timestamp = parseInt(timestampB36, 36);
|
|
907
|
-
const now = Date.now();
|
|
908
|
-
const expiryMs = CIPHER_TEXT_EXPIRY_MINUTES * 60 * 1e3;
|
|
909
|
-
return now - timestamp > expiryMs;
|
|
910
|
-
} catch {
|
|
911
|
-
return true;
|
|
912
|
-
}
|
|
913
|
-
}
|
|
970
|
+
// ============================================================================
|
|
971
|
+
// Utility Methods (inherited from BaseClient: healthCheck, updateConfig, getConfig, buildQueryString)
|
|
972
|
+
// ============================================================================
|
|
973
|
+
};
|
|
914
974
|
|
|
915
975
|
export { GeolocationClient, decodeCipherText, generateCipherText, isCipherTextExpired };
|
|
916
976
|
//# sourceMappingURL=index.mjs.map
|