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