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