vesant-sdk 1.1.1 → 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/{client-BfeDYmrZ.d.mts → client-BIfLMfuC.d.mts} +24 -0
- package/dist/{client-i5QtnFIa.d.ts → client-BWp5FI3x.d.ts} +24 -0
- package/dist/compliance/index.d.mts +2 -2
- package/dist/compliance/index.d.ts +2 -2
- package/dist/compliance/index.js +286 -2
- package/dist/compliance/index.js.map +1 -1
- package/dist/compliance/index.mjs +286 -2
- package/dist/compliance/index.mjs.map +1 -1
- package/dist/geolocation/index.d.mts +2 -2
- package/dist/geolocation/index.d.ts +2 -2
- 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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +311 -251
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +311 -251
- package/dist/index.mjs.map +1 -1
- 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.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 +1 -1
- package/dist/react.d.ts +1 -1
- 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.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/package.json +1 -1
|
@@ -82,7 +82,7 @@ function createConsoleLogger() {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
// src/core/version.ts
|
|
85
|
-
var SDK_VERSION = "1.
|
|
85
|
+
var SDK_VERSION = "1.2.0";
|
|
86
86
|
|
|
87
87
|
// src/core/client.ts
|
|
88
88
|
var BaseClient = class {
|
|
@@ -307,6 +307,256 @@ var BaseClient = class {
|
|
|
307
307
|
}
|
|
308
308
|
};
|
|
309
309
|
|
|
310
|
+
// src/shared/browser-utils.ts
|
|
311
|
+
function generateUUID() {
|
|
312
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
313
|
+
return crypto.randomUUID();
|
|
314
|
+
}
|
|
315
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
316
|
+
const r = Math.random() * 16 | 0;
|
|
317
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
318
|
+
return v.toString(16);
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
function generateDeviceId() {
|
|
322
|
+
if (typeof window === "undefined" || typeof localStorage === "undefined") {
|
|
323
|
+
return generateUUID();
|
|
324
|
+
}
|
|
325
|
+
const storageKey = "cgs_device_id";
|
|
326
|
+
let deviceId = localStorage.getItem(storageKey);
|
|
327
|
+
if (!deviceId) {
|
|
328
|
+
deviceId = generateUUID();
|
|
329
|
+
localStorage.setItem(storageKey, deviceId);
|
|
330
|
+
}
|
|
331
|
+
return deviceId;
|
|
332
|
+
}
|
|
333
|
+
function getBrowserInfo() {
|
|
334
|
+
if (typeof navigator === "undefined") {
|
|
335
|
+
return { browser: "unknown", browser_version: "", os: "unknown", os_version: "" };
|
|
336
|
+
}
|
|
337
|
+
const ua = navigator.userAgent;
|
|
338
|
+
let browser = "unknown";
|
|
339
|
+
let browserVersion = "";
|
|
340
|
+
let os = "unknown";
|
|
341
|
+
let osVersion = "";
|
|
342
|
+
if (ua.includes("Firefox/")) {
|
|
343
|
+
browser = "Firefox";
|
|
344
|
+
browserVersion = ua.match(/Firefox\/([\d.]+)/)?.[1] || "";
|
|
345
|
+
} else if (ua.includes("Edg/")) {
|
|
346
|
+
browser = "Edge";
|
|
347
|
+
browserVersion = ua.match(/Edg\/([\d.]+)/)?.[1] || "";
|
|
348
|
+
} else if (ua.includes("Chrome/")) {
|
|
349
|
+
browser = "Chrome";
|
|
350
|
+
browserVersion = ua.match(/Chrome\/([\d.]+)/)?.[1] || "";
|
|
351
|
+
} else if (ua.includes("Safari/") && !ua.includes("Chrome")) {
|
|
352
|
+
browser = "Safari";
|
|
353
|
+
browserVersion = ua.match(/Version\/([\d.]+)/)?.[1] || "";
|
|
354
|
+
} else if (ua.includes("Opera") || ua.includes("OPR/")) {
|
|
355
|
+
browser = "Opera";
|
|
356
|
+
browserVersion = ua.match(/(?:Opera|OPR)\/([\d.]+)/)?.[1] || "";
|
|
357
|
+
}
|
|
358
|
+
if (ua.includes("Windows")) {
|
|
359
|
+
os = "Windows";
|
|
360
|
+
if (ua.includes("Windows NT 10.0")) osVersion = "10";
|
|
361
|
+
else if (ua.includes("Windows NT 6.3")) osVersion = "8.1";
|
|
362
|
+
else if (ua.includes("Windows NT 6.2")) osVersion = "8";
|
|
363
|
+
else if (ua.includes("Windows NT 6.1")) osVersion = "7";
|
|
364
|
+
} else if (ua.includes("Mac OS X")) {
|
|
365
|
+
os = "macOS";
|
|
366
|
+
osVersion = ua.match(/Mac OS X ([\d_]+)/)?.[1]?.replace(/_/g, ".") || "";
|
|
367
|
+
} else if (ua.includes("Linux")) {
|
|
368
|
+
os = "Linux";
|
|
369
|
+
} else if (ua.includes("Android")) {
|
|
370
|
+
os = "Android";
|
|
371
|
+
osVersion = ua.match(/Android ([\d.]+)/)?.[1] || "";
|
|
372
|
+
} else if (ua.includes("iOS") || ua.includes("iPhone") || ua.includes("iPad")) {
|
|
373
|
+
os = "iOS";
|
|
374
|
+
osVersion = ua.match(/OS ([\d_]+)/)?.[1]?.replace(/_/g, ".") || "";
|
|
375
|
+
}
|
|
376
|
+
return { browser, browser_version: browserVersion, os, os_version: osVersion };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// src/geolocation/ciphertext.ts
|
|
380
|
+
var CIPHER_TEXT_EXPIRY_MINUTES = 5;
|
|
381
|
+
async function computeHMAC(key, message) {
|
|
382
|
+
if (typeof globalThis.crypto !== "undefined" && globalThis.crypto.subtle) {
|
|
383
|
+
const encoder = new TextEncoder();
|
|
384
|
+
const keyData = encoder.encode(key);
|
|
385
|
+
const msgData = encoder.encode(message);
|
|
386
|
+
const cryptoKey = await globalThis.crypto.subtle.importKey(
|
|
387
|
+
"raw",
|
|
388
|
+
keyData,
|
|
389
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
390
|
+
false,
|
|
391
|
+
["sign"]
|
|
392
|
+
);
|
|
393
|
+
const signature = await globalThis.crypto.subtle.sign("HMAC", cryptoKey, msgData);
|
|
394
|
+
const bytes = new Uint8Array(signature);
|
|
395
|
+
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
396
|
+
}
|
|
397
|
+
const { createHmac } = await import('crypto');
|
|
398
|
+
return createHmac("sha256", key).update(message).digest("hex");
|
|
399
|
+
}
|
|
400
|
+
function getWebGLInfo() {
|
|
401
|
+
if (typeof document === "undefined") return null;
|
|
402
|
+
try {
|
|
403
|
+
const canvas = document.createElement("canvas");
|
|
404
|
+
const gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
|
|
405
|
+
if (!gl) return null;
|
|
406
|
+
const debugInfo = gl.getExtension("WEBGL_debug_renderer_info");
|
|
407
|
+
if (!debugInfo) return null;
|
|
408
|
+
return {
|
|
409
|
+
vendor: gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL) || "",
|
|
410
|
+
renderer: gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) || ""
|
|
411
|
+
};
|
|
412
|
+
} catch {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function getNetworkInfo() {
|
|
417
|
+
if (typeof navigator === "undefined") return void 0;
|
|
418
|
+
const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
|
|
419
|
+
if (!connection) return void 0;
|
|
420
|
+
return {
|
|
421
|
+
effective_type: connection.effectiveType,
|
|
422
|
+
downlink: connection.downlink,
|
|
423
|
+
rtt: connection.rtt,
|
|
424
|
+
save_data: connection.saveData
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
async function requestGPSLocation(timeout = 1e4, highAccuracy = true) {
|
|
428
|
+
if (typeof navigator === "undefined" || !navigator.geolocation) {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
return new Promise((resolve) => {
|
|
432
|
+
navigator.geolocation.getCurrentPosition(
|
|
433
|
+
(position) => {
|
|
434
|
+
const { latitude, longitude, accuracy } = position.coords;
|
|
435
|
+
if (latitude < -90 || latitude > 90) {
|
|
436
|
+
resolve(null);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
if (longitude < -180 || longitude > 180) {
|
|
440
|
+
resolve(null);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (accuracy !== null && accuracy !== void 0 && accuracy <= 0) {
|
|
444
|
+
resolve(null);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
resolve({
|
|
448
|
+
latitude,
|
|
449
|
+
longitude,
|
|
450
|
+
accuracy,
|
|
451
|
+
altitude: position.coords.altitude ?? void 0,
|
|
452
|
+
altitude_accuracy: position.coords.altitudeAccuracy ?? void 0,
|
|
453
|
+
heading: position.coords.heading ?? void 0,
|
|
454
|
+
speed: position.coords.speed ?? void 0,
|
|
455
|
+
timestamp: position.timestamp
|
|
456
|
+
});
|
|
457
|
+
},
|
|
458
|
+
() => {
|
|
459
|
+
resolve(null);
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
enableHighAccuracy: highAccuracy,
|
|
463
|
+
timeout,
|
|
464
|
+
maximumAge: 0
|
|
465
|
+
}
|
|
466
|
+
);
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
function collectDeviceData(includeWebGL) {
|
|
470
|
+
const browserInfo = getBrowserInfo();
|
|
471
|
+
const webglInfo = includeWebGL ? getWebGLInfo() : null;
|
|
472
|
+
return {
|
|
473
|
+
device_id: generateDeviceId(),
|
|
474
|
+
user_agent: typeof navigator !== "undefined" ? navigator.userAgent : "",
|
|
475
|
+
platform: typeof navigator !== "undefined" ? navigator.platform : "",
|
|
476
|
+
browser: browserInfo.browser,
|
|
477
|
+
browser_version: browserInfo.browser_version,
|
|
478
|
+
os: browserInfo.os,
|
|
479
|
+
os_version: browserInfo.os_version,
|
|
480
|
+
screen_resolution: typeof screen !== "undefined" ? `${screen.width}x${screen.height}` : void 0,
|
|
481
|
+
language: typeof navigator !== "undefined" ? navigator.language : void 0,
|
|
482
|
+
timezone: Intl?.DateTimeFormat?.()?.resolvedOptions?.()?.timeZone,
|
|
483
|
+
color_depth: typeof screen !== "undefined" ? screen.colorDepth : void 0,
|
|
484
|
+
hardware_concurrency: typeof navigator !== "undefined" ? navigator.hardwareConcurrency : void 0,
|
|
485
|
+
device_memory: typeof navigator !== "undefined" ? navigator.deviceMemory : void 0,
|
|
486
|
+
touch_support: typeof navigator !== "undefined" ? navigator.maxTouchPoints > 0 : void 0,
|
|
487
|
+
webgl_vendor: webglInfo?.vendor,
|
|
488
|
+
webgl_renderer: webglInfo?.renderer
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
function encodePayload(payload) {
|
|
492
|
+
const json = JSON.stringify(payload);
|
|
493
|
+
if (typeof btoa !== "undefined") {
|
|
494
|
+
return btoa(unescape(encodeURIComponent(json)));
|
|
495
|
+
} else if (typeof Buffer !== "undefined") {
|
|
496
|
+
return Buffer.from(json, "utf-8").toString("base64");
|
|
497
|
+
}
|
|
498
|
+
throw new Error("No base64 encoding method available");
|
|
499
|
+
}
|
|
500
|
+
async function generateCipherText(options, config) {
|
|
501
|
+
const warnings = [];
|
|
502
|
+
let requestLocation = options.requestLocation ?? false;
|
|
503
|
+
if (config?.require_gps) {
|
|
504
|
+
const reason = options.reason;
|
|
505
|
+
if (reason === "login" && config.require_gps.login || reason === "registration" && config.require_gps.registration || reason === "transaction" && config.require_gps.transaction) {
|
|
506
|
+
requestLocation = true;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
const deviceData = collectDeviceData(options.includeWebGL !== false);
|
|
510
|
+
let locationData;
|
|
511
|
+
if (requestLocation) {
|
|
512
|
+
const location = await requestGPSLocation(
|
|
513
|
+
options.locationTimeout || 1e4,
|
|
514
|
+
options.highAccuracy !== false
|
|
515
|
+
);
|
|
516
|
+
if (location) {
|
|
517
|
+
locationData = location;
|
|
518
|
+
} else {
|
|
519
|
+
warnings.push("GPS location not available or permission denied");
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
let networkData;
|
|
523
|
+
if (options.includeNetworkInfo !== false) {
|
|
524
|
+
networkData = getNetworkInfo();
|
|
525
|
+
}
|
|
526
|
+
const now = /* @__PURE__ */ new Date();
|
|
527
|
+
const expiry = new Date(now.getTime() + CIPHER_TEXT_EXPIRY_MINUTES * 60 * 1e3);
|
|
528
|
+
const payload = {
|
|
529
|
+
device: deviceData,
|
|
530
|
+
location: locationData,
|
|
531
|
+
network: networkData,
|
|
532
|
+
metadata: {
|
|
533
|
+
collected_at: now.toISOString(),
|
|
534
|
+
sdk_version: SDK_VERSION,
|
|
535
|
+
collection_reason: options.reason,
|
|
536
|
+
page_url: typeof window !== "undefined" ? window.location.href : void 0,
|
|
537
|
+
referrer: typeof document !== "undefined" ? document.referrer || void 0 : void 0
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
const encoded = encodePayload(payload);
|
|
541
|
+
const timestamp = now.getTime().toString(36);
|
|
542
|
+
let cipherText;
|
|
543
|
+
const hmacKey = options.signingKey || options.apiKey;
|
|
544
|
+
if (hmacKey) {
|
|
545
|
+
const message = `02.${timestamp}.${encoded}`;
|
|
546
|
+
const hmac = await computeHMAC(hmacKey, message);
|
|
547
|
+
cipherText = `${message}.${hmac}`;
|
|
548
|
+
} else {
|
|
549
|
+
cipherText = `01.${timestamp}.${encoded}`;
|
|
550
|
+
}
|
|
551
|
+
return {
|
|
552
|
+
cipherText,
|
|
553
|
+
locationCaptured: !!locationData,
|
|
554
|
+
warnings: warnings.length > 0 ? warnings : void 0,
|
|
555
|
+
generatedAt: now.toISOString(),
|
|
556
|
+
expiresAt: expiry.toISOString()
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
|
|
310
560
|
// src/geolocation/client.ts
|
|
311
561
|
var GeolocationClient = class extends BaseClient {
|
|
312
562
|
constructor(config) {
|
|
@@ -407,7 +657,11 @@ var GeolocationClient = class extends BaseClient {
|
|
|
407
657
|
* ```
|
|
408
658
|
*/
|
|
409
659
|
async getGPSConfig(requestOptions) {
|
|
410
|
-
|
|
660
|
+
const config = await this.requestWithRetry("/api/v1/geo/config", void 0, void 0, void 0, requestOptions);
|
|
661
|
+
if (config.signing_key) {
|
|
662
|
+
this.cachedSigningKey = config.signing_key;
|
|
663
|
+
}
|
|
664
|
+
return config;
|
|
411
665
|
}
|
|
412
666
|
// ============================================================================
|
|
413
667
|
// CipherText Validation
|
|
@@ -667,6 +921,36 @@ var GeolocationClient = class extends BaseClient {
|
|
|
667
921
|
}, void 0, requestOptions);
|
|
668
922
|
}
|
|
669
923
|
// ============================================================================
|
|
924
|
+
// CipherText Generation
|
|
925
|
+
// ============================================================================
|
|
926
|
+
/**
|
|
927
|
+
* Generate a signed cipherText containing device and location data.
|
|
928
|
+
*
|
|
929
|
+
* Automatically passes the client's API key for HMAC signing (v02 format).
|
|
930
|
+
* If no API key is configured, falls back to unsigned v01 format.
|
|
931
|
+
*
|
|
932
|
+
* @param options - Options for cipherText generation
|
|
933
|
+
* @param gpsConfig - Optional GPS config (from getGPSConfig)
|
|
934
|
+
* @returns CipherText result with the signed string
|
|
935
|
+
*
|
|
936
|
+
* @example
|
|
937
|
+
* ```typescript
|
|
938
|
+
* const result = await client.generateCipherText({ reason: 'login' });
|
|
939
|
+
* console.log(result.cipherText); // v02 signed cipherText
|
|
940
|
+
* ```
|
|
941
|
+
*/
|
|
942
|
+
async generateCipherText(options, gpsConfig) {
|
|
943
|
+
let signingKey = this.cachedSigningKey;
|
|
944
|
+
if (!signingKey) {
|
|
945
|
+
const config = await this.getGPSConfig();
|
|
946
|
+
signingKey = config.signing_key;
|
|
947
|
+
}
|
|
948
|
+
return generateCipherText(
|
|
949
|
+
{ ...options, signingKey: signingKey || void 0 },
|
|
950
|
+
gpsConfig
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
// ============================================================================
|
|
670
954
|
// Utility Methods (inherited from BaseClient: healthCheck, updateConfig, getConfig, buildQueryString)
|
|
671
955
|
// ============================================================================
|
|
672
956
|
};
|