vesant-sdk 1.5.2 → 1.6.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 (47) hide show
  1. package/dist/{client-B8pFrXx_.d.ts → client-Bd9a5o0C.d.ts} +2 -0
  2. package/dist/{client-BZxzOidG.d.mts → client-C4g596fI.d.mts} +2 -0
  3. package/dist/compliance/index.d.mts +15 -2
  4. package/dist/compliance/index.d.ts +15 -2
  5. package/dist/compliance/index.js +200 -38
  6. package/dist/compliance/index.js.map +1 -1
  7. package/dist/compliance/index.mjs +200 -38
  8. package/dist/compliance/index.mjs.map +1 -1
  9. package/dist/decisions/index.js +1 -1
  10. package/dist/decisions/index.js.map +1 -1
  11. package/dist/decisions/index.mjs +1 -1
  12. package/dist/decisions/index.mjs.map +1 -1
  13. package/dist/geolocation/index.d.mts +2 -2
  14. package/dist/geolocation/index.d.ts +2 -2
  15. package/dist/geolocation/index.js +1 -1
  16. package/dist/geolocation/index.js.map +1 -1
  17. package/dist/geolocation/index.mjs +1 -1
  18. package/dist/geolocation/index.mjs.map +1 -1
  19. package/dist/index.d.mts +2 -2
  20. package/dist/index.d.ts +2 -2
  21. package/dist/index.js +200 -38
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +200 -38
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/kyc/core.js +1 -1
  26. package/dist/kyc/core.js.map +1 -1
  27. package/dist/kyc/core.mjs +1 -1
  28. package/dist/kyc/core.mjs.map +1 -1
  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 +1 -1
  34. package/dist/react.d.ts +1 -1
  35. package/dist/react.js +1 -1
  36. package/dist/react.js.map +1 -1
  37. package/dist/react.mjs +1 -1
  38. package/dist/react.mjs.map +1 -1
  39. package/dist/risk-profile/index.js +1 -1
  40. package/dist/risk-profile/index.js.map +1 -1
  41. package/dist/risk-profile/index.mjs +1 -1
  42. package/dist/risk-profile/index.mjs.map +1 -1
  43. package/dist/scores/index.js +1 -1
  44. package/dist/scores/index.js.map +1 -1
  45. package/dist/scores/index.mjs +1 -1
  46. package/dist/scores/index.mjs.map +1 -1
  47. package/package.json +1 -1
@@ -222,7 +222,7 @@ function createConsoleLogger() {
222
222
  }
223
223
 
224
224
  // src/core/version.ts
225
- var SDK_VERSION = "1.5.2";
225
+ var SDK_VERSION = "1.6.0";
226
226
 
227
227
  // src/shared/browser-utils.ts
228
228
  function generateUUID() {
@@ -1438,17 +1438,34 @@ var ComplianceClient = class {
1438
1438
  const startTime = Date.now();
1439
1439
  this.validateRegistrationRequest(request);
1440
1440
  let geoVerification = null;
1441
+ let cipherTextResult;
1441
1442
  try {
1442
1443
  if (this.config.debug) {
1443
1444
  this.logger.debug("Starting registration verification", { customerId: request.customerId });
1444
1445
  }
1445
- geoVerification = await this.geoClient.verifyIP({
1446
- ip_address: request.ipAddress,
1447
- user_id: request.customerId,
1448
- event_type: "registration",
1449
- device_fingerprint: request.deviceFingerprint
1450
- }, requestOptions);
1451
- const blockReasons = this.evaluateRegistrationBlock(geoVerification);
1446
+ const customerData = request.cipherText ? {
1447
+ full_name: request.fullName,
1448
+ email: request.emailAddress,
1449
+ phone: request.phoneNumber,
1450
+ date_of_birth: request.dateOfBirth
1451
+ } : void 0;
1452
+ [cipherTextResult, geoVerification] = await Promise.all([
1453
+ this.executeCipherTextValidation(
1454
+ request.cipherText,
1455
+ request.customerId,
1456
+ "registration",
1457
+ request.ipAddress,
1458
+ customerData,
1459
+ requestOptions
1460
+ ),
1461
+ this.geoClient.verifyIP({
1462
+ ip_address: request.ipAddress,
1463
+ user_id: request.customerId,
1464
+ event_type: "registration",
1465
+ device_fingerprint: request.deviceFingerprint
1466
+ }, requestOptions)
1467
+ ]);
1468
+ const blockReasons = this.evaluateRegistrationBlock(geoVerification, cipherTextResult);
1452
1469
  if (blockReasons.length > 0) {
1453
1470
  if (this.config.debug) {
1454
1471
  this.logger.debug("Registration blocked at geo stage", { blockReasons });
@@ -1460,7 +1477,8 @@ var ComplianceClient = class {
1460
1477
  requiresKYC: false,
1461
1478
  requiresEDD: false,
1462
1479
  blockReasons,
1463
- processingTime: Date.now() - startTime
1480
+ processingTime: Date.now() - startTime,
1481
+ cipherTextValidation: cipherTextResult
1464
1482
  };
1465
1483
  }
1466
1484
  const profile = await this.riskClient.createProfile({
@@ -1495,7 +1513,8 @@ var ComplianceClient = class {
1495
1513
  requiresKYC,
1496
1514
  requiresEDD,
1497
1515
  blockReasons: [],
1498
- processingTime: Date.now() - startTime
1516
+ processingTime: Date.now() - startTime,
1517
+ cipherTextValidation: cipherTextResult
1499
1518
  };
1500
1519
  } catch (error) {
1501
1520
  if (this.config.debug) {
@@ -1523,7 +1542,7 @@ var ComplianceClient = class {
1523
1542
  * @param geoVerification - Geolocation verification result
1524
1543
  * @returns Array of block reasons (empty if allowed)
1525
1544
  */
1526
- evaluateRegistrationBlock(geoVerification) {
1545
+ evaluateRegistrationBlock(geoVerification, cipherTextResult) {
1527
1546
  const blockReasons = [];
1528
1547
  if (geoVerification.is_blocked) {
1529
1548
  blockReasons.push(...geoVerification.risk_reasons);
@@ -1557,6 +1576,20 @@ var ComplianceClient = class {
1557
1576
  blockReasons.push("critical_risk_level");
1558
1577
  }
1559
1578
  }
1579
+ if (cipherTextResult) {
1580
+ if (!cipherTextResult.valid) {
1581
+ blockReasons.push("ciphertext_validation_failed");
1582
+ }
1583
+ if (cipherTextResult.risk?.is_blocked) {
1584
+ blockReasons.push(...cipherTextResult.risk.block_reasons || []);
1585
+ }
1586
+ if (cipherTextResult.risk?.location_mismatch) {
1587
+ blockReasons.push("gps_ip_location_mismatch");
1588
+ }
1589
+ }
1590
+ if (geoVerification.gps_required && !cipherTextResult) {
1591
+ blockReasons.push("gps_verification_required");
1592
+ }
1560
1593
  return [...new Set(blockReasons)];
1561
1594
  }
1562
1595
  /**
@@ -1687,7 +1720,15 @@ var ComplianceClient = class {
1687
1720
  if (this.config.debug) {
1688
1721
  this.logger.debug("Starting login verification", { customerId: request.customerId });
1689
1722
  }
1690
- const [geoVerification, profileResult] = await Promise.all([
1723
+ const [cipherTextResult, geoVerification, profileResult] = await Promise.all([
1724
+ this.executeCipherTextValidation(
1725
+ request.cipherText,
1726
+ request.customerId,
1727
+ "login",
1728
+ request.ipAddress,
1729
+ void 0,
1730
+ requestOptions
1731
+ ),
1691
1732
  this.geoClient.verifyIP({
1692
1733
  ip_address: request.ipAddress,
1693
1734
  user_id: request.customerId,
@@ -1696,10 +1737,23 @@ var ComplianceClient = class {
1696
1737
  }, requestOptions),
1697
1738
  this.riskClient.getProfile(request.customerId, requestOptions).catch(() => null)
1698
1739
  ]);
1740
+ const loginBlockReasons = this.getBlockReasons(geoVerification, profileResult || {}, cipherTextResult);
1741
+ const isBlocked = !geoVerification.is_compliant || geoVerification.is_blocked || !!cipherTextResult?.risk?.is_blocked || cipherTextResult?.valid === false || geoVerification.gps_required && !cipherTextResult;
1742
+ if (isBlocked && !profileResult) {
1743
+ return {
1744
+ allowed: false,
1745
+ geolocation: geoVerification,
1746
+ profile: null,
1747
+ requiresStepUp: false,
1748
+ blockReasons: loginBlockReasons,
1749
+ processingTime: Date.now() - startTime,
1750
+ cipherTextValidation: cipherTextResult
1751
+ };
1752
+ }
1699
1753
  let profile;
1700
1754
  if (profileResult) {
1701
1755
  profile = profileResult;
1702
- if (this.shouldUpdateProfile(profile, geoVerification.location.city)) {
1756
+ if (!isBlocked && this.shouldUpdateProfile(profile, geoVerification.location.city)) {
1703
1757
  profile = await this.riskClient.updateProfile(profile.id, {
1704
1758
  last_recorded_activity: (/* @__PURE__ */ new Date()).toISOString(),
1705
1759
  location: `${geoVerification.location.city}, ${geoVerification.location.country}`,
@@ -1712,15 +1766,15 @@ var ComplianceClient = class {
1712
1766
  }
1713
1767
  profile = await this.createProfileFromGeo(request.customerId, geoVerification);
1714
1768
  }
1715
- const isAllowed = geoVerification.is_compliant && !geoVerification.is_blocked && profile.customer_status !== "suspended";
1716
- const requiresStepUp = geoVerification.risk_level === "high" || geoVerification.risk_level === "critical";
1769
+ const requiresStepUp = geoVerification.risk_level === "high" || geoVerification.risk_level === "critical" || cipherTextResult?.risk?.location_mismatch === true;
1717
1770
  return {
1718
- allowed: isAllowed,
1771
+ allowed: !isBlocked && profile.customer_status !== "suspended",
1719
1772
  geolocation: geoVerification,
1720
1773
  profile,
1721
1774
  requiresStepUp,
1722
- blockReasons: this.getBlockReasons(geoVerification, profile),
1723
- processingTime: Date.now() - startTime
1775
+ blockReasons: isBlocked || profile.customer_status === "suspended" ? this.getBlockReasons(geoVerification, profile, cipherTextResult) : [],
1776
+ processingTime: Date.now() - startTime,
1777
+ cipherTextValidation: cipherTextResult
1724
1778
  };
1725
1779
  } catch (error) {
1726
1780
  throw new ComplianceError("Login verification failed", error instanceof Error ? error.message : void 0);
@@ -1767,27 +1821,55 @@ var ComplianceClient = class {
1767
1821
  currency: request.currency
1768
1822
  });
1769
1823
  }
1770
- const [geoVerification, profile] = await Promise.all([
1824
+ const [cipherTextResult, geoVerification, profileResult] = await Promise.all([
1825
+ this.executeCipherTextValidation(
1826
+ request.cipherText,
1827
+ request.customerId,
1828
+ "transaction",
1829
+ request.ipAddress,
1830
+ void 0,
1831
+ requestOptions
1832
+ ),
1771
1833
  this.geoClient.verifyIP({
1772
1834
  ip_address: request.ipAddress,
1773
1835
  user_id: request.customerId,
1774
1836
  event_type: "transaction",
1775
1837
  device_fingerprint: request.deviceFingerprint
1776
1838
  }, requestOptions),
1777
- this.riskClient.getProfile(request.customerId, requestOptions)
1839
+ this.riskClient.getProfile(request.customerId, requestOptions).catch(() => null)
1778
1840
  ]);
1841
+ const geoBlocked = !geoVerification.is_compliant || geoVerification.is_blocked || !!cipherTextResult?.risk?.is_blocked || cipherTextResult?.valid === false || geoVerification.gps_required && !cipherTextResult;
1842
+ if (geoBlocked && !profileResult) {
1843
+ return {
1844
+ allowed: false,
1845
+ geolocation: geoVerification,
1846
+ profile: null,
1847
+ transactionRisk: { score: 0, level: "low", factors: [], allowed: false, requiresManualReview: false },
1848
+ requiresApproval: false,
1849
+ blockReasons: this.getTransactionBlockReasons(
1850
+ geoVerification,
1851
+ { score: 0, level: "low", factors: [], allowed: false, requiresManualReview: false },
1852
+ true,
1853
+ cipherTextResult
1854
+ ),
1855
+ processingTime: Date.now() - startTime,
1856
+ cipherTextValidation: cipherTextResult
1857
+ };
1858
+ }
1859
+ const profile = profileResult;
1779
1860
  const transactionRisk = this.calculateTransactionRisk(
1780
1861
  request.amount,
1781
1862
  request.currency,
1782
1863
  geoVerification,
1783
- profile
1864
+ profile,
1865
+ cipherTextResult
1784
1866
  );
1785
1867
  const jurisdictionAllowed = this.checkJurisdictionLimits(
1786
1868
  request.amount,
1787
1869
  request.currency,
1788
1870
  geoVerification.jurisdiction
1789
1871
  );
1790
- const isAllowed = geoVerification.is_compliant && !geoVerification.is_blocked && jurisdictionAllowed && transactionRisk.allowed;
1872
+ const isAllowed = !geoBlocked && jurisdictionAllowed && transactionRisk.allowed && profile.customer_status !== "suspended";
1791
1873
  return {
1792
1874
  allowed: isAllowed,
1793
1875
  geolocation: geoVerification,
@@ -1797,9 +1879,11 @@ var ComplianceClient = class {
1797
1879
  blockReasons: this.getTransactionBlockReasons(
1798
1880
  geoVerification,
1799
1881
  transactionRisk,
1800
- jurisdictionAllowed
1882
+ jurisdictionAllowed,
1883
+ cipherTextResult
1801
1884
  ),
1802
- processingTime: Date.now() - startTime
1885
+ processingTime: Date.now() - startTime,
1886
+ cipherTextValidation: cipherTextResult
1803
1887
  };
1804
1888
  } catch (error) {
1805
1889
  throw new ComplianceError("Transaction verification failed", error instanceof Error ? error.message : void 0);
@@ -1814,12 +1898,22 @@ var ComplianceClient = class {
1814
1898
  async verifyEvent(request, requestOptions) {
1815
1899
  const startTime = Date.now();
1816
1900
  this.validateEventRequest(request);
1817
- const geoVerification = await this.geoClient.verifyIP({
1818
- ip_address: request.ipAddress,
1819
- user_id: request.customerId,
1820
- event_type: request.eventType,
1821
- device_fingerprint: request.deviceFingerprint
1822
- }, requestOptions);
1901
+ const [cipherTextResult, geoVerification] = await Promise.all([
1902
+ this.executeCipherTextValidation(
1903
+ request.cipherText,
1904
+ request.customerId,
1905
+ request.eventType,
1906
+ request.ipAddress,
1907
+ void 0,
1908
+ requestOptions
1909
+ ),
1910
+ this.geoClient.verifyIP({
1911
+ ip_address: request.ipAddress,
1912
+ user_id: request.customerId,
1913
+ event_type: request.eventType,
1914
+ device_fingerprint: request.deviceFingerprint
1915
+ }, requestOptions)
1916
+ ]);
1823
1917
  if (this.config.autoCreateProfiles) {
1824
1918
  try {
1825
1919
  const profile = await this.riskClient.getProfile(request.customerId, requestOptions);
@@ -1832,11 +1926,26 @@ var ComplianceClient = class {
1832
1926
  }
1833
1927
  }
1834
1928
  }
1929
+ const cipherTextBlocked = cipherTextResult ? !cipherTextResult.valid || cipherTextResult.risk?.is_blocked === true : false;
1930
+ const blockReasons = [...geoVerification.risk_reasons];
1931
+ if (cipherTextResult) {
1932
+ if (!cipherTextResult.valid) {
1933
+ blockReasons.push("ciphertext_validation_failed");
1934
+ }
1935
+ if (cipherTextResult.risk?.is_blocked) {
1936
+ blockReasons.push(...cipherTextResult.risk.block_reasons || []);
1937
+ }
1938
+ }
1939
+ const gpsBlocked = geoVerification.gps_required && !cipherTextResult;
1940
+ if (gpsBlocked) {
1941
+ blockReasons.push("gps_verification_required");
1942
+ }
1835
1943
  return {
1836
- allowed: geoVerification.is_compliant && !geoVerification.is_blocked,
1944
+ allowed: geoVerification.is_compliant && !geoVerification.is_blocked && !cipherTextBlocked && !gpsBlocked,
1837
1945
  geolocation: geoVerification,
1838
- blockReasons: geoVerification.risk_reasons,
1839
- processingTime: Date.now() - startTime
1946
+ blockReasons: [...new Set(blockReasons)],
1947
+ processingTime: Date.now() - startTime,
1948
+ cipherTextValidation: cipherTextResult
1840
1949
  };
1841
1950
  }
1842
1951
  // ============================================================================
@@ -1865,7 +1974,29 @@ var ComplianceClient = class {
1865
1974
  kyc_status: "pending"
1866
1975
  });
1867
1976
  }
1868
- calculateTransactionRisk(amount, currency, geoVerification, profile) {
1977
+ /**
1978
+ * Execute cipherText validation with graceful degradation.
1979
+ * Returns undefined if cipherText is not provided or validation fails.
1980
+ */
1981
+ async executeCipherTextValidation(cipherText, userId, eventType, ipAddress, customerData, requestOptions) {
1982
+ if (!cipherText) return void 0;
1983
+ try {
1984
+ return await this.geoClient.validateCipherText(
1985
+ cipherText,
1986
+ userId,
1987
+ eventType,
1988
+ ipAddress,
1989
+ customerData,
1990
+ requestOptions
1991
+ );
1992
+ } catch (err) {
1993
+ this.logger.warn("CipherText validation failed, proceeding with IP-only", {
1994
+ error: err instanceof Error ? err.message : "Unknown error"
1995
+ });
1996
+ return void 0;
1997
+ }
1998
+ }
1999
+ calculateTransactionRisk(amount, currency, geoVerification, profile, cipherTextResult) {
1869
2000
  if (!this._currencyRatesCustomized && !this._currencyRatesWarned) {
1870
2001
  this._currencyRatesWarned = true;
1871
2002
  this.logger.warn(
@@ -1898,6 +2029,15 @@ var ComplianceClient = class {
1898
2029
  riskScore += 50;
1899
2030
  factors.push("account_suspended");
1900
2031
  }
2032
+ if (cipherTextResult) {
2033
+ if (cipherTextResult.risk?.location_mismatch) {
2034
+ riskScore += 20;
2035
+ factors.push("gps_ip_location_mismatch");
2036
+ }
2037
+ if (cipherTextResult.risk?.score) {
2038
+ riskScore += cipherTextResult.risk.score * 0.2;
2039
+ }
2040
+ }
1901
2041
  return {
1902
2042
  score: Math.min(riskScore, 100),
1903
2043
  level: this.getRiskLevel(riskScore),
@@ -1923,7 +2063,7 @@ var ComplianceClient = class {
1923
2063
  if (score >= 40) return "medium";
1924
2064
  return "low";
1925
2065
  }
1926
- getBlockReasons(geoVerification, profile) {
2066
+ getBlockReasons(geoVerification, profile, cipherTextResult) {
1927
2067
  const reasons = [];
1928
2068
  if (geoVerification.is_blocked) {
1929
2069
  reasons.push(...geoVerification.risk_reasons);
@@ -1934,9 +2074,20 @@ var ComplianceClient = class {
1934
2074
  if (profile.has_sanctions) {
1935
2075
  reasons.push("sanctions_match");
1936
2076
  }
1937
- return reasons;
2077
+ if (cipherTextResult) {
2078
+ if (!cipherTextResult.valid) {
2079
+ reasons.push("ciphertext_validation_failed");
2080
+ }
2081
+ if (cipherTextResult.risk?.is_blocked) {
2082
+ reasons.push(...cipherTextResult.risk.block_reasons || []);
2083
+ }
2084
+ }
2085
+ if (geoVerification.gps_required && !cipherTextResult) {
2086
+ reasons.push("gps_verification_required");
2087
+ }
2088
+ return [...new Set(reasons)];
1938
2089
  }
1939
- getTransactionBlockReasons(geoVerification, transactionRisk, jurisdictionAllowed) {
2090
+ getTransactionBlockReasons(geoVerification, transactionRisk, jurisdictionAllowed, cipherTextResult) {
1940
2091
  const reasons = [];
1941
2092
  if (!geoVerification.is_compliant) {
1942
2093
  reasons.push("non_compliant_jurisdiction");
@@ -1947,7 +2098,18 @@ var ComplianceClient = class {
1947
2098
  if (!transactionRisk.allowed) {
1948
2099
  reasons.push(...transactionRisk.factors);
1949
2100
  }
1950
- return reasons;
2101
+ if (cipherTextResult) {
2102
+ if (!cipherTextResult.valid) {
2103
+ reasons.push("ciphertext_validation_failed");
2104
+ }
2105
+ if (cipherTextResult.risk?.is_blocked) {
2106
+ reasons.push(...cipherTextResult.risk.block_reasons || []);
2107
+ }
2108
+ }
2109
+ if (geoVerification.gps_required && !cipherTextResult) {
2110
+ reasons.push("gps_verification_required");
2111
+ }
2112
+ return [...new Set(reasons)];
1951
2113
  }
1952
2114
  // ============================================================================
1953
2115
  // Location Request Methods