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
package/dist/index.mjs CHANGED
@@ -240,7 +240,7 @@ var noopLogger = {
240
240
  };
241
241
 
242
242
  // src/core/version.ts
243
- var SDK_VERSION = "1.5.2";
243
+ var SDK_VERSION = "1.6.0";
244
244
 
245
245
  // src/shared/browser-utils.ts
246
246
  function generateUUID() {
@@ -1523,17 +1523,34 @@ var ComplianceClient = class {
1523
1523
  const startTime = Date.now();
1524
1524
  this.validateRegistrationRequest(request);
1525
1525
  let geoVerification = null;
1526
+ let cipherTextResult;
1526
1527
  try {
1527
1528
  if (this.config.debug) {
1528
1529
  this.logger.debug("Starting registration verification", { customerId: request.customerId });
1529
1530
  }
1530
- geoVerification = await this.geoClient.verifyIP({
1531
- ip_address: request.ipAddress,
1532
- user_id: request.customerId,
1533
- event_type: "registration",
1534
- device_fingerprint: request.deviceFingerprint
1535
- }, requestOptions);
1536
- const blockReasons = this.evaluateRegistrationBlock(geoVerification);
1531
+ const customerData = request.cipherText ? {
1532
+ full_name: request.fullName,
1533
+ email: request.emailAddress,
1534
+ phone: request.phoneNumber,
1535
+ date_of_birth: request.dateOfBirth
1536
+ } : void 0;
1537
+ [cipherTextResult, geoVerification] = await Promise.all([
1538
+ this.executeCipherTextValidation(
1539
+ request.cipherText,
1540
+ request.customerId,
1541
+ "registration",
1542
+ request.ipAddress,
1543
+ customerData,
1544
+ requestOptions
1545
+ ),
1546
+ this.geoClient.verifyIP({
1547
+ ip_address: request.ipAddress,
1548
+ user_id: request.customerId,
1549
+ event_type: "registration",
1550
+ device_fingerprint: request.deviceFingerprint
1551
+ }, requestOptions)
1552
+ ]);
1553
+ const blockReasons = this.evaluateRegistrationBlock(geoVerification, cipherTextResult);
1537
1554
  if (blockReasons.length > 0) {
1538
1555
  if (this.config.debug) {
1539
1556
  this.logger.debug("Registration blocked at geo stage", { blockReasons });
@@ -1545,7 +1562,8 @@ var ComplianceClient = class {
1545
1562
  requiresKYC: false,
1546
1563
  requiresEDD: false,
1547
1564
  blockReasons,
1548
- processingTime: Date.now() - startTime
1565
+ processingTime: Date.now() - startTime,
1566
+ cipherTextValidation: cipherTextResult
1549
1567
  };
1550
1568
  }
1551
1569
  const profile = await this.riskClient.createProfile({
@@ -1580,7 +1598,8 @@ var ComplianceClient = class {
1580
1598
  requiresKYC,
1581
1599
  requiresEDD,
1582
1600
  blockReasons: [],
1583
- processingTime: Date.now() - startTime
1601
+ processingTime: Date.now() - startTime,
1602
+ cipherTextValidation: cipherTextResult
1584
1603
  };
1585
1604
  } catch (error) {
1586
1605
  if (this.config.debug) {
@@ -1608,7 +1627,7 @@ var ComplianceClient = class {
1608
1627
  * @param geoVerification - Geolocation verification result
1609
1628
  * @returns Array of block reasons (empty if allowed)
1610
1629
  */
1611
- evaluateRegistrationBlock(geoVerification) {
1630
+ evaluateRegistrationBlock(geoVerification, cipherTextResult) {
1612
1631
  const blockReasons = [];
1613
1632
  if (geoVerification.is_blocked) {
1614
1633
  blockReasons.push(...geoVerification.risk_reasons);
@@ -1642,6 +1661,20 @@ var ComplianceClient = class {
1642
1661
  blockReasons.push("critical_risk_level");
1643
1662
  }
1644
1663
  }
1664
+ if (cipherTextResult) {
1665
+ if (!cipherTextResult.valid) {
1666
+ blockReasons.push("ciphertext_validation_failed");
1667
+ }
1668
+ if (cipherTextResult.risk?.is_blocked) {
1669
+ blockReasons.push(...cipherTextResult.risk.block_reasons || []);
1670
+ }
1671
+ if (cipherTextResult.risk?.location_mismatch) {
1672
+ blockReasons.push("gps_ip_location_mismatch");
1673
+ }
1674
+ }
1675
+ if (geoVerification.gps_required && !cipherTextResult) {
1676
+ blockReasons.push("gps_verification_required");
1677
+ }
1645
1678
  return [...new Set(blockReasons)];
1646
1679
  }
1647
1680
  /**
@@ -1772,7 +1805,15 @@ var ComplianceClient = class {
1772
1805
  if (this.config.debug) {
1773
1806
  this.logger.debug("Starting login verification", { customerId: request.customerId });
1774
1807
  }
1775
- const [geoVerification, profileResult] = await Promise.all([
1808
+ const [cipherTextResult, geoVerification, profileResult] = await Promise.all([
1809
+ this.executeCipherTextValidation(
1810
+ request.cipherText,
1811
+ request.customerId,
1812
+ "login",
1813
+ request.ipAddress,
1814
+ void 0,
1815
+ requestOptions
1816
+ ),
1776
1817
  this.geoClient.verifyIP({
1777
1818
  ip_address: request.ipAddress,
1778
1819
  user_id: request.customerId,
@@ -1781,10 +1822,23 @@ var ComplianceClient = class {
1781
1822
  }, requestOptions),
1782
1823
  this.riskClient.getProfile(request.customerId, requestOptions).catch(() => null)
1783
1824
  ]);
1825
+ const loginBlockReasons = this.getBlockReasons(geoVerification, profileResult || {}, cipherTextResult);
1826
+ const isBlocked = !geoVerification.is_compliant || geoVerification.is_blocked || !!cipherTextResult?.risk?.is_blocked || cipherTextResult?.valid === false || geoVerification.gps_required && !cipherTextResult;
1827
+ if (isBlocked && !profileResult) {
1828
+ return {
1829
+ allowed: false,
1830
+ geolocation: geoVerification,
1831
+ profile: null,
1832
+ requiresStepUp: false,
1833
+ blockReasons: loginBlockReasons,
1834
+ processingTime: Date.now() - startTime,
1835
+ cipherTextValidation: cipherTextResult
1836
+ };
1837
+ }
1784
1838
  let profile;
1785
1839
  if (profileResult) {
1786
1840
  profile = profileResult;
1787
- if (this.shouldUpdateProfile(profile, geoVerification.location.city)) {
1841
+ if (!isBlocked && this.shouldUpdateProfile(profile, geoVerification.location.city)) {
1788
1842
  profile = await this.riskClient.updateProfile(profile.id, {
1789
1843
  last_recorded_activity: (/* @__PURE__ */ new Date()).toISOString(),
1790
1844
  location: `${geoVerification.location.city}, ${geoVerification.location.country}`,
@@ -1797,15 +1851,15 @@ var ComplianceClient = class {
1797
1851
  }
1798
1852
  profile = await this.createProfileFromGeo(request.customerId, geoVerification);
1799
1853
  }
1800
- const isAllowed = geoVerification.is_compliant && !geoVerification.is_blocked && profile.customer_status !== "suspended";
1801
- const requiresStepUp = geoVerification.risk_level === "high" || geoVerification.risk_level === "critical";
1854
+ const requiresStepUp = geoVerification.risk_level === "high" || geoVerification.risk_level === "critical" || cipherTextResult?.risk?.location_mismatch === true;
1802
1855
  return {
1803
- allowed: isAllowed,
1856
+ allowed: !isBlocked && profile.customer_status !== "suspended",
1804
1857
  geolocation: geoVerification,
1805
1858
  profile,
1806
1859
  requiresStepUp,
1807
- blockReasons: this.getBlockReasons(geoVerification, profile),
1808
- processingTime: Date.now() - startTime
1860
+ blockReasons: isBlocked || profile.customer_status === "suspended" ? this.getBlockReasons(geoVerification, profile, cipherTextResult) : [],
1861
+ processingTime: Date.now() - startTime,
1862
+ cipherTextValidation: cipherTextResult
1809
1863
  };
1810
1864
  } catch (error) {
1811
1865
  throw new ComplianceError("Login verification failed", error instanceof Error ? error.message : void 0);
@@ -1852,27 +1906,55 @@ var ComplianceClient = class {
1852
1906
  currency: request.currency
1853
1907
  });
1854
1908
  }
1855
- const [geoVerification, profile] = await Promise.all([
1909
+ const [cipherTextResult, geoVerification, profileResult] = await Promise.all([
1910
+ this.executeCipherTextValidation(
1911
+ request.cipherText,
1912
+ request.customerId,
1913
+ "transaction",
1914
+ request.ipAddress,
1915
+ void 0,
1916
+ requestOptions
1917
+ ),
1856
1918
  this.geoClient.verifyIP({
1857
1919
  ip_address: request.ipAddress,
1858
1920
  user_id: request.customerId,
1859
1921
  event_type: "transaction",
1860
1922
  device_fingerprint: request.deviceFingerprint
1861
1923
  }, requestOptions),
1862
- this.riskClient.getProfile(request.customerId, requestOptions)
1924
+ this.riskClient.getProfile(request.customerId, requestOptions).catch(() => null)
1863
1925
  ]);
1926
+ const geoBlocked = !geoVerification.is_compliant || geoVerification.is_blocked || !!cipherTextResult?.risk?.is_blocked || cipherTextResult?.valid === false || geoVerification.gps_required && !cipherTextResult;
1927
+ if (geoBlocked && !profileResult) {
1928
+ return {
1929
+ allowed: false,
1930
+ geolocation: geoVerification,
1931
+ profile: null,
1932
+ transactionRisk: { score: 0, level: "low", factors: [], allowed: false, requiresManualReview: false },
1933
+ requiresApproval: false,
1934
+ blockReasons: this.getTransactionBlockReasons(
1935
+ geoVerification,
1936
+ { score: 0, level: "low", factors: [], allowed: false, requiresManualReview: false },
1937
+ true,
1938
+ cipherTextResult
1939
+ ),
1940
+ processingTime: Date.now() - startTime,
1941
+ cipherTextValidation: cipherTextResult
1942
+ };
1943
+ }
1944
+ const profile = profileResult;
1864
1945
  const transactionRisk = this.calculateTransactionRisk(
1865
1946
  request.amount,
1866
1947
  request.currency,
1867
1948
  geoVerification,
1868
- profile
1949
+ profile,
1950
+ cipherTextResult
1869
1951
  );
1870
1952
  const jurisdictionAllowed = this.checkJurisdictionLimits(
1871
1953
  request.amount,
1872
1954
  request.currency,
1873
1955
  geoVerification.jurisdiction
1874
1956
  );
1875
- const isAllowed = geoVerification.is_compliant && !geoVerification.is_blocked && jurisdictionAllowed && transactionRisk.allowed;
1957
+ const isAllowed = !geoBlocked && jurisdictionAllowed && transactionRisk.allowed && profile.customer_status !== "suspended";
1876
1958
  return {
1877
1959
  allowed: isAllowed,
1878
1960
  geolocation: geoVerification,
@@ -1882,9 +1964,11 @@ var ComplianceClient = class {
1882
1964
  blockReasons: this.getTransactionBlockReasons(
1883
1965
  geoVerification,
1884
1966
  transactionRisk,
1885
- jurisdictionAllowed
1967
+ jurisdictionAllowed,
1968
+ cipherTextResult
1886
1969
  ),
1887
- processingTime: Date.now() - startTime
1970
+ processingTime: Date.now() - startTime,
1971
+ cipherTextValidation: cipherTextResult
1888
1972
  };
1889
1973
  } catch (error) {
1890
1974
  throw new ComplianceError("Transaction verification failed", error instanceof Error ? error.message : void 0);
@@ -1899,12 +1983,22 @@ var ComplianceClient = class {
1899
1983
  async verifyEvent(request, requestOptions) {
1900
1984
  const startTime = Date.now();
1901
1985
  this.validateEventRequest(request);
1902
- const geoVerification = await this.geoClient.verifyIP({
1903
- ip_address: request.ipAddress,
1904
- user_id: request.customerId,
1905
- event_type: request.eventType,
1906
- device_fingerprint: request.deviceFingerprint
1907
- }, requestOptions);
1986
+ const [cipherTextResult, geoVerification] = await Promise.all([
1987
+ this.executeCipherTextValidation(
1988
+ request.cipherText,
1989
+ request.customerId,
1990
+ request.eventType,
1991
+ request.ipAddress,
1992
+ void 0,
1993
+ requestOptions
1994
+ ),
1995
+ this.geoClient.verifyIP({
1996
+ ip_address: request.ipAddress,
1997
+ user_id: request.customerId,
1998
+ event_type: request.eventType,
1999
+ device_fingerprint: request.deviceFingerprint
2000
+ }, requestOptions)
2001
+ ]);
1908
2002
  if (this.config.autoCreateProfiles) {
1909
2003
  try {
1910
2004
  const profile = await this.riskClient.getProfile(request.customerId, requestOptions);
@@ -1917,11 +2011,26 @@ var ComplianceClient = class {
1917
2011
  }
1918
2012
  }
1919
2013
  }
2014
+ const cipherTextBlocked = cipherTextResult ? !cipherTextResult.valid || cipherTextResult.risk?.is_blocked === true : false;
2015
+ const blockReasons = [...geoVerification.risk_reasons];
2016
+ if (cipherTextResult) {
2017
+ if (!cipherTextResult.valid) {
2018
+ blockReasons.push("ciphertext_validation_failed");
2019
+ }
2020
+ if (cipherTextResult.risk?.is_blocked) {
2021
+ blockReasons.push(...cipherTextResult.risk.block_reasons || []);
2022
+ }
2023
+ }
2024
+ const gpsBlocked = geoVerification.gps_required && !cipherTextResult;
2025
+ if (gpsBlocked) {
2026
+ blockReasons.push("gps_verification_required");
2027
+ }
1920
2028
  return {
1921
- allowed: geoVerification.is_compliant && !geoVerification.is_blocked,
2029
+ allowed: geoVerification.is_compliant && !geoVerification.is_blocked && !cipherTextBlocked && !gpsBlocked,
1922
2030
  geolocation: geoVerification,
1923
- blockReasons: geoVerification.risk_reasons,
1924
- processingTime: Date.now() - startTime
2031
+ blockReasons: [...new Set(blockReasons)],
2032
+ processingTime: Date.now() - startTime,
2033
+ cipherTextValidation: cipherTextResult
1925
2034
  };
1926
2035
  }
1927
2036
  // ============================================================================
@@ -1950,7 +2059,29 @@ var ComplianceClient = class {
1950
2059
  kyc_status: "pending"
1951
2060
  });
1952
2061
  }
1953
- calculateTransactionRisk(amount, currency, geoVerification, profile) {
2062
+ /**
2063
+ * Execute cipherText validation with graceful degradation.
2064
+ * Returns undefined if cipherText is not provided or validation fails.
2065
+ */
2066
+ async executeCipherTextValidation(cipherText, userId, eventType, ipAddress, customerData, requestOptions) {
2067
+ if (!cipherText) return void 0;
2068
+ try {
2069
+ return await this.geoClient.validateCipherText(
2070
+ cipherText,
2071
+ userId,
2072
+ eventType,
2073
+ ipAddress,
2074
+ customerData,
2075
+ requestOptions
2076
+ );
2077
+ } catch (err) {
2078
+ this.logger.warn("CipherText validation failed, proceeding with IP-only", {
2079
+ error: err instanceof Error ? err.message : "Unknown error"
2080
+ });
2081
+ return void 0;
2082
+ }
2083
+ }
2084
+ calculateTransactionRisk(amount, currency, geoVerification, profile, cipherTextResult) {
1954
2085
  if (!this._currencyRatesCustomized && !this._currencyRatesWarned) {
1955
2086
  this._currencyRatesWarned = true;
1956
2087
  this.logger.warn(
@@ -1983,6 +2114,15 @@ var ComplianceClient = class {
1983
2114
  riskScore += 50;
1984
2115
  factors.push("account_suspended");
1985
2116
  }
2117
+ if (cipherTextResult) {
2118
+ if (cipherTextResult.risk?.location_mismatch) {
2119
+ riskScore += 20;
2120
+ factors.push("gps_ip_location_mismatch");
2121
+ }
2122
+ if (cipherTextResult.risk?.score) {
2123
+ riskScore += cipherTextResult.risk.score * 0.2;
2124
+ }
2125
+ }
1986
2126
  return {
1987
2127
  score: Math.min(riskScore, 100),
1988
2128
  level: this.getRiskLevel(riskScore),
@@ -2008,7 +2148,7 @@ var ComplianceClient = class {
2008
2148
  if (score >= 40) return "medium";
2009
2149
  return "low";
2010
2150
  }
2011
- getBlockReasons(geoVerification, profile) {
2151
+ getBlockReasons(geoVerification, profile, cipherTextResult) {
2012
2152
  const reasons = [];
2013
2153
  if (geoVerification.is_blocked) {
2014
2154
  reasons.push(...geoVerification.risk_reasons);
@@ -2019,9 +2159,20 @@ var ComplianceClient = class {
2019
2159
  if (profile.has_sanctions) {
2020
2160
  reasons.push("sanctions_match");
2021
2161
  }
2022
- return reasons;
2162
+ if (cipherTextResult) {
2163
+ if (!cipherTextResult.valid) {
2164
+ reasons.push("ciphertext_validation_failed");
2165
+ }
2166
+ if (cipherTextResult.risk?.is_blocked) {
2167
+ reasons.push(...cipherTextResult.risk.block_reasons || []);
2168
+ }
2169
+ }
2170
+ if (geoVerification.gps_required && !cipherTextResult) {
2171
+ reasons.push("gps_verification_required");
2172
+ }
2173
+ return [...new Set(reasons)];
2023
2174
  }
2024
- getTransactionBlockReasons(geoVerification, transactionRisk, jurisdictionAllowed) {
2175
+ getTransactionBlockReasons(geoVerification, transactionRisk, jurisdictionAllowed, cipherTextResult) {
2025
2176
  const reasons = [];
2026
2177
  if (!geoVerification.is_compliant) {
2027
2178
  reasons.push("non_compliant_jurisdiction");
@@ -2032,7 +2183,18 @@ var ComplianceClient = class {
2032
2183
  if (!transactionRisk.allowed) {
2033
2184
  reasons.push(...transactionRisk.factors);
2034
2185
  }
2035
- return reasons;
2186
+ if (cipherTextResult) {
2187
+ if (!cipherTextResult.valid) {
2188
+ reasons.push("ciphertext_validation_failed");
2189
+ }
2190
+ if (cipherTextResult.risk?.is_blocked) {
2191
+ reasons.push(...cipherTextResult.risk.block_reasons || []);
2192
+ }
2193
+ }
2194
+ if (geoVerification.gps_required && !cipherTextResult) {
2195
+ reasons.push("gps_verification_required");
2196
+ }
2197
+ return [...new Set(reasons)];
2036
2198
  }
2037
2199
  // ============================================================================
2038
2200
  // Location Request Methods