@zkp2p/sdk 0.0.6 → 0.0.7

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 (36) hide show
  1. package/README.md +80 -1
  2. package/dist/{Zkp2pClient-D-eU4dxy.d.mts → Zkp2pClient-w5Pzlea6.d.mts} +102 -36
  3. package/dist/{Zkp2pClient-D-eU4dxy.d.ts → Zkp2pClient-w5Pzlea6.d.ts} +102 -36
  4. package/dist/chunk-3QS3WKRC.mjs +29 -0
  5. package/dist/chunk-3QS3WKRC.mjs.map +1 -0
  6. package/dist/{chunk-ARFGMPYS.mjs → chunk-GYYD6SSA.mjs} +2 -2
  7. package/dist/chunk-GYYD6SSA.mjs.map +1 -0
  8. package/dist/{chunk-CM3RH5VZ.mjs → chunk-NZ53KYLT.mjs} +42 -2
  9. package/dist/chunk-NZ53KYLT.mjs.map +1 -0
  10. package/dist/{chunk-PYEJ4L76.mjs → chunk-W247BDNW.mjs} +3 -3
  11. package/dist/{chunk-PYEJ4L76.mjs.map → chunk-W247BDNW.mjs.map} +1 -1
  12. package/dist/constants-ZICRSYZM.mjs +5 -0
  13. package/dist/{constants-MQB4AQDD.mjs.map → constants-ZICRSYZM.mjs.map} +1 -1
  14. package/dist/{currency-RSSHQOM3.mjs → currency-UVK4OKUR.mjs} +4 -3
  15. package/dist/{currency-RSSHQOM3.mjs.map → currency-UVK4OKUR.mjs.map} +1 -1
  16. package/dist/index.cjs +904 -362
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.mts +68 -4
  19. package/dist/index.d.ts +68 -4
  20. package/dist/index.mjs +633 -345
  21. package/dist/index.mjs.map +1 -1
  22. package/dist/{paymentResolution-4AAJVIIC.mjs → paymentResolution-2FP3NLM3.mjs} +3 -2
  23. package/dist/{paymentResolution-4AAJVIIC.mjs.map → paymentResolution-2FP3NLM3.mjs.map} +1 -1
  24. package/dist/protocolViewerParsers-EH5DGVSU.mjs +6 -0
  25. package/dist/{protocolViewerParsers-3QIR3XMT.mjs.map → protocolViewerParsers-EH5DGVSU.mjs.map} +1 -1
  26. package/dist/react.d.mts +1 -1
  27. package/dist/react.d.ts +1 -1
  28. package/dist/react.mjs +1 -1
  29. package/dist/{timeout-QB7K5SOB.mjs → timeout-7HCFGU6P.mjs} +3 -2
  30. package/dist/timeout-7HCFGU6P.mjs.map +1 -0
  31. package/package.json +4 -3
  32. package/dist/chunk-ARFGMPYS.mjs.map +0 -1
  33. package/dist/chunk-CM3RH5VZ.mjs.map +0 -1
  34. package/dist/constants-MQB4AQDD.mjs +0 -4
  35. package/dist/protocolViewerParsers-3QIR3XMT.mjs +0 -5
  36. package/dist/timeout-QB7K5SOB.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,12 +1,13 @@
1
1
  import { ValidationError, APIError, NetworkError } from './chunk-GHQK65J2.mjs';
2
2
  export { APIError, ContractError, ErrorCode, NetworkError, ValidationError, ZKP2PError } from './chunk-GHQK65J2.mjs';
3
- export { PAYMENT_PLATFORMS, PLATFORM_METADATA, SUPPORTED_CHAIN_IDS, TOKEN_METADATA } from './chunk-ARFGMPYS.mjs';
4
- import { getContracts, getPaymentMethodsCatalog, getGatingServiceAddress } from './chunk-PYEJ4L76.mjs';
5
- export { enrichPvDepositView, enrichPvIntentView, getContracts, getGatingServiceAddress, getPaymentMethodsCatalog, parseDepositView, parseIntentView } from './chunk-PYEJ4L76.mjs';
3
+ export { PAYMENT_PLATFORMS, PLATFORM_METADATA, SUPPORTED_CHAIN_IDS, TOKEN_METADATA } from './chunk-GYYD6SSA.mjs';
4
+ import { getContracts, getPaymentMethodsCatalog, getGatingServiceAddress } from './chunk-W247BDNW.mjs';
5
+ export { enrichPvDepositView, enrichPvIntentView, getContracts, getGatingServiceAddress, getPaymentMethodsCatalog, parseDepositView, parseIntentView } from './chunk-W247BDNW.mjs';
6
6
  import { resolvePaymentMethodHashFromCatalog, resolveFiatCurrencyBytes32 } from './chunk-GDKCACWH.mjs';
7
7
  export { asciiToBytes32, ensureBytes32, resolveFiatCurrencyBytes32, resolvePaymentMethodHash, resolvePaymentMethodHashFromCatalog, resolvePaymentMethodNameFromHash } from './chunk-GDKCACWH.mjs';
8
- import { currencyKeccak256 } from './chunk-CM3RH5VZ.mjs';
9
- export { Currency, currencyInfo, getCurrencyCodeFromHash, getCurrencyInfoFromCountryCode, getCurrencyInfoFromHash, isSupportedCurrencyHash, mapConversionRatesToOnchainMinRate } from './chunk-CM3RH5VZ.mjs';
8
+ import { currencyKeccak256 } from './chunk-NZ53KYLT.mjs';
9
+ export { Currency, currencyInfo, getCurrencyCodeFromHash, getCurrencyInfoFromCountryCode, getCurrencyInfoFromHash, isSupportedCurrencyHash, mapConversionRatesToOnchainMinRate } from './chunk-NZ53KYLT.mjs';
10
+ import './chunk-3QS3WKRC.mjs';
10
11
  import { concatHex, encodeFunctionData, createPublicClient, http } from 'viem';
11
12
  import { hardhat, baseSepolia, base } from 'viem/chains';
12
13
  import { AbiCoder } from 'ethers';
@@ -649,7 +650,7 @@ async function withRetry(fn, maxRetries = 3, delayMs = 1e3, timeoutMs) {
649
650
  for (let i = 0; i < maxRetries; i++) {
650
651
  try {
651
652
  if (timeoutMs) {
652
- const { withTimeout } = await import('./timeout-QB7K5SOB.mjs');
653
+ const { withTimeout } = await import('./timeout-7HCFGU6P.mjs');
653
654
  return await withTimeout(fn(), timeoutMs, `Operation timed out after ${timeoutMs}ms`);
654
655
  }
655
656
  return await fn();
@@ -767,6 +768,17 @@ async function apiFetch({
767
768
  return res.json();
768
769
  }, retryCount, retryDelayMs, timeoutMs);
769
770
  }
771
+ function processApiResponse(data, transformDates = true) {
772
+ if (!transformDates) return data;
773
+ if (data.responseObject) {
774
+ if (Array.isArray(data.responseObject)) {
775
+ data.responseObject = data.responseObject.map((item) => transformDatesToObjects(item));
776
+ } else {
777
+ data.responseObject = transformDatesToObjects(data.responseObject);
778
+ }
779
+ }
780
+ return data;
781
+ }
770
782
  async function apiPostDepositDetails(req, baseApiUrl, timeoutMs) {
771
783
  return apiFetch({
772
784
  url: `${baseApiUrl.replace(/\/$/, "")}/v1/makers/create`,
@@ -826,6 +838,34 @@ async function apiValidatePayeeDetails(req, baseApiUrl, timeoutMs) {
826
838
  }
827
839
  return data;
828
840
  }
841
+ function transformDatesToObjects(obj) {
842
+ const dateFields = ["createdAt", "updatedAt", "signalTimestamp", "fulfillTimestamp", "prunedTimestamp"];
843
+ const transformed = { ...obj };
844
+ for (const key in transformed) {
845
+ const value = transformed[key];
846
+ if (dateFields.includes(key) && typeof value === "string") {
847
+ transformed[key] = new Date(value);
848
+ } else if (Array.isArray(value)) {
849
+ transformed[key] = value.map(
850
+ (item) => typeof item === "object" && item !== null ? transformDatesToObjects(item) : item
851
+ );
852
+ } else if (typeof value === "object" && value !== null) {
853
+ transformed[key] = transformDatesToObjects(value);
854
+ }
855
+ }
856
+ return transformed;
857
+ }
858
+ async function apiGetOwnerDeposits(req, apiKey, baseApiUrl, authToken, timeoutMs) {
859
+ const statusQuery = req.status ? `?status=${encodeURIComponent(req.status)}` : "";
860
+ const data = await apiFetch({
861
+ url: `${withApiBase(baseApiUrl)}/v1/deposits/maker/${req.ownerAddress}${statusQuery}`,
862
+ method: "GET",
863
+ apiKey,
864
+ authToken,
865
+ timeoutMs
866
+ });
867
+ return processApiResponse(data);
868
+ }
829
869
  async function apiGetTakerTier(req, apiKey, baseApiUrl, authToken, timeoutMs) {
830
870
  const normalizedOwner = req.owner.toLowerCase();
831
871
  const query = new URLSearchParams({
@@ -937,6 +977,204 @@ var Zkp2pClient = class {
937
977
  * @throws Error if walletClient is missing an account
938
978
  */
939
979
  constructor(opts) {
980
+ // ╔═══════════════════════════════════════════════════════════════════════════╗
981
+ // ║ CORE: DEPOSIT MANAGEMENT ║
982
+ // ╚═══════════════════════════════════════════════════════════════════════════╝
983
+ /**
984
+ * Enables or disables a deposit from accepting new intents.
985
+ *
986
+ * @param params.depositId - The deposit ID
987
+ * @param params.accepting - Whether to accept new intents
988
+ * @param params.txOverrides - Optional viem transaction overrides
989
+ * @returns Transaction hash
990
+ */
991
+ this.setAcceptingIntents = this.buildEscrowMethod(
992
+ "setAcceptingIntents",
993
+ (params) => [params.depositId, params.accepting]
994
+ );
995
+ /**
996
+ * Updates the min/max intent amount range for a deposit.
997
+ *
998
+ * @param params.depositId - The deposit ID
999
+ * @param params.min - Minimum intent amount
1000
+ * @param params.max - Maximum intent amount
1001
+ * @param params.txOverrides - Optional viem transaction overrides
1002
+ * @returns Transaction hash
1003
+ */
1004
+ this.setIntentRange = this.buildEscrowMethod(
1005
+ "setIntentRange",
1006
+ (params) => [params.depositId, { min: params.min, max: params.max }]
1007
+ );
1008
+ /**
1009
+ * Updates the minimum conversion rate for a specific currency on a payment method.
1010
+ *
1011
+ * @param params.depositId - The deposit ID
1012
+ * @param params.paymentMethod - Payment method hash (bytes32)
1013
+ * @param params.fiatCurrency - Fiat currency hash (bytes32)
1014
+ * @param params.minConversionRate - New minimum conversion rate (18 decimals)
1015
+ * @param params.txOverrides - Optional viem transaction overrides
1016
+ * @returns Transaction hash
1017
+ */
1018
+ this.setCurrencyMinRate = this.buildEscrowMethod("setCurrencyMinRate", (params) => [
1019
+ params.depositId,
1020
+ params.paymentMethod,
1021
+ params.fiatCurrency,
1022
+ params.minConversionRate
1023
+ ]);
1024
+ /**
1025
+ * Adds additional funds to an existing deposit.
1026
+ * Requires prior approval of the token amount.
1027
+ *
1028
+ * @param params.depositId - The deposit ID to add funds to
1029
+ * @param params.amount - Amount to add (in token units)
1030
+ * @param params.txOverrides - Optional viem transaction overrides
1031
+ * @returns Transaction hash
1032
+ */
1033
+ this.addFunds = this.buildEscrowMethod(
1034
+ "addFunds",
1035
+ (params) => [params.depositId, params.amount]
1036
+ );
1037
+ /**
1038
+ * Removes funds from a deposit (partial withdrawal).
1039
+ * Can only withdraw available (non-locked) funds.
1040
+ *
1041
+ * @param params.depositId - The deposit ID
1042
+ * @param params.amount - Amount to remove (in token units)
1043
+ * @param params.txOverrides - Optional viem transaction overrides
1044
+ * @returns Transaction hash
1045
+ */
1046
+ this.removeFunds = this.buildEscrowMethod(
1047
+ "removeFunds",
1048
+ (params) => [params.depositId, params.amount]
1049
+ );
1050
+ /**
1051
+ * Fully withdraws a deposit, returning all available funds to the owner.
1052
+ * The deposit must have no active intents.
1053
+ *
1054
+ * @param params.depositId - The deposit ID to withdraw
1055
+ * @param params.txOverrides - Optional viem transaction overrides
1056
+ * @returns Transaction hash
1057
+ */
1058
+ this.withdrawDeposit = this.buildEscrowMethod(
1059
+ "withdrawDeposit",
1060
+ (params) => [params.depositId]
1061
+ );
1062
+ // ╔═══════════════════════════════════════════════════════════════════════════╗
1063
+ // ║ CORE: ADVANCED DEPOSIT CONFIGURATION ║
1064
+ // ╚═══════════════════════════════════════════════════════════════════════════╝
1065
+ /**
1066
+ * Sets whether a deposit should remain active when its balance reaches zero.
1067
+ *
1068
+ * @param params.depositId - The deposit ID
1069
+ * @param params.retain - If true, deposit stays active when empty
1070
+ * @param params.txOverrides - Optional viem transaction overrides
1071
+ * @returns Transaction hash
1072
+ */
1073
+ this.setRetainOnEmpty = this.buildEscrowMethod(
1074
+ "setRetainOnEmpty",
1075
+ (params) => [params.depositId, params.retain]
1076
+ );
1077
+ /**
1078
+ * Assigns a delegate address that can manage the deposit on behalf of the owner.
1079
+ *
1080
+ * @param params.depositId - The deposit ID
1081
+ * @param params.delegate - Address to delegate management to
1082
+ * @param params.txOverrides - Optional viem transaction overrides
1083
+ * @returns Transaction hash
1084
+ */
1085
+ this.setDelegate = this.buildEscrowMethod(
1086
+ "setDelegate",
1087
+ (params) => [params.depositId, params.delegate]
1088
+ );
1089
+ /**
1090
+ * Removes the delegate from a deposit.
1091
+ *
1092
+ * @param params.depositId - The deposit ID
1093
+ * @param params.txOverrides - Optional viem transaction overrides
1094
+ * @returns Transaction hash
1095
+ */
1096
+ this.removeDelegate = this.buildEscrowMethod(
1097
+ "removeDelegate",
1098
+ (params) => [params.depositId]
1099
+ );
1100
+ /**
1101
+ * Adds new payment methods to an existing deposit.
1102
+ *
1103
+ * @param params.depositId - The deposit ID
1104
+ * @param params.paymentMethods - Array of payment method hashes to add
1105
+ * @param params.paymentMethodData - Corresponding payment method configuration
1106
+ * @param params.txOverrides - Optional viem transaction overrides
1107
+ * @returns Transaction hash
1108
+ */
1109
+ this.addPaymentMethods = this.buildEscrowMethod("addPaymentMethods", (params) => [params.depositId, params.paymentMethods, params.paymentMethodData, params.currencies]);
1110
+ /**
1111
+ * Activates or deactivates a payment method on a deposit.
1112
+ *
1113
+ * @param params.depositId - The deposit ID
1114
+ * @param params.paymentMethod - Payment method hash to modify
1115
+ * @param params.isActive - Whether the payment method should accept intents
1116
+ * @param params.txOverrides - Optional viem transaction overrides
1117
+ * @returns Transaction hash
1118
+ */
1119
+ this.setPaymentMethodActive = this.buildEscrowMethod("setPaymentMethodActive", (params) => [params.depositId, params.paymentMethod, params.isActive]);
1120
+ /**
1121
+ * Deactivates a payment method on a deposit (convenience alias for setPaymentMethodActive).
1122
+ *
1123
+ * @param params.depositId - The deposit ID
1124
+ * @param params.paymentMethod - Payment method hash to deactivate
1125
+ * @param params.txOverrides - Optional viem transaction overrides
1126
+ * @returns Transaction hash
1127
+ */
1128
+ this.removePaymentMethod = this.buildEscrowMethod(
1129
+ "setPaymentMethodActive",
1130
+ (params) => [params.depositId, params.paymentMethod, false]
1131
+ );
1132
+ /**
1133
+ * Adds new currencies to a payment method on a deposit.
1134
+ *
1135
+ * @param params.depositId - The deposit ID
1136
+ * @param params.paymentMethod - Payment method hash to add currencies to
1137
+ * @param params.currencies - Array of currency configurations with code and min rate
1138
+ * @param params.txOverrides - Optional viem transaction overrides
1139
+ * @returns Transaction hash
1140
+ */
1141
+ this.addCurrencies = this.buildEscrowMethod("addCurrencies", (params) => [params.depositId, params.paymentMethod, params.currencies]);
1142
+ /**
1143
+ * Deactivates a currency for a payment method on a deposit.
1144
+ *
1145
+ * @param params.depositId - The deposit ID
1146
+ * @param params.paymentMethod - Payment method hash
1147
+ * @param params.currencyCode - Currency code hash to deactivate
1148
+ * @param params.txOverrides - Optional viem transaction overrides
1149
+ * @returns Transaction hash
1150
+ */
1151
+ this.deactivateCurrency = this.buildEscrowMethod("deactivateCurrency", (params) => [params.depositId, params.paymentMethod, params.currencyCode]);
1152
+ /**
1153
+ * Removes (deactivates) a currency from a payment method.
1154
+ * Alias for deactivateCurrency.
1155
+ *
1156
+ * @param params.depositId - The deposit ID
1157
+ * @param params.paymentMethod - Payment method hash
1158
+ * @param params.currencyCode - Currency code hash to remove
1159
+ * @param params.txOverrides - Optional viem transaction overrides
1160
+ * @returns Transaction hash
1161
+ */
1162
+ this.removeCurrency = this.buildEscrowMethod(
1163
+ "deactivateCurrency",
1164
+ (params) => [params.depositId, params.paymentMethod, params.currencyCode]
1165
+ );
1166
+ /**
1167
+ * Removes expired intents from a deposit, freeing up locked funds.
1168
+ * Can be called by anyone (permissionless cleanup).
1169
+ *
1170
+ * @param params.depositId - The deposit ID to prune
1171
+ * @param params.txOverrides - Optional viem transaction overrides
1172
+ * @returns Transaction hash
1173
+ */
1174
+ this.pruneExpiredIntents = this.buildEscrowMethod(
1175
+ "pruneExpiredIntents",
1176
+ (params) => [params.depositId]
1177
+ );
940
1178
  // ───────────────────────────────────────────────────────────────────────────
941
1179
  // SUPPORTING: INTENT OPERATIONS
942
1180
  // (Used by takers/buyers - not primary SDK functionality)
@@ -1062,6 +1300,20 @@ var Zkp2pClient = class {
1062
1300
  }
1063
1301
  }
1064
1302
  );
1303
+ /**
1304
+ * **Supporting Method** - Releases funds back to the deposit owner.
1305
+ *
1306
+ * Called by the deposit owner when they want to reject an intent
1307
+ * (e.g., payment verification failed or intent expired).
1308
+ *
1309
+ * @param params.intentHash - The intent hash (0x-prefixed, 32 bytes)
1310
+ * @param params.txOverrides - Optional viem transaction overrides
1311
+ * @returns Transaction hash
1312
+ */
1313
+ this.releaseFundsToPayer = this.buildOrchestratorMethod(
1314
+ "releaseFundsToPayer",
1315
+ (params) => [params.intentHash]
1316
+ );
1065
1317
  /**
1066
1318
  * **Supporting Method** - Fulfills an intent by submitting a payment proof.
1067
1319
  *
@@ -1217,6 +1469,106 @@ var Zkp2pClient = class {
1217
1469
  ...overrides
1218
1470
  });
1219
1471
  }
1472
+ prepareEscrowTransaction(opts) {
1473
+ if (!this.escrowAddress || !this.escrowAbi) throw new Error("Escrow not available");
1474
+ const { referrer, value } = opts.txOverrides ?? {};
1475
+ const data = encodeWithAttribution(
1476
+ {
1477
+ abi: this.escrowAbi,
1478
+ functionName: opts.functionName,
1479
+ args: opts.args ?? []
1480
+ },
1481
+ referrer
1482
+ );
1483
+ return {
1484
+ to: this.escrowAddress,
1485
+ data,
1486
+ value: opts.value ?? value ?? 0n,
1487
+ chainId: this.chainId,
1488
+ abi: this.escrowAbi,
1489
+ functionName: opts.functionName,
1490
+ args: opts.args ?? []
1491
+ };
1492
+ }
1493
+ prepareOrchestratorTransaction(opts) {
1494
+ if (!this.orchestratorAddress || !this.orchestratorAbi) throw new Error("Orchestrator not available");
1495
+ const { referrer, value } = opts.txOverrides ?? {};
1496
+ const data = encodeWithAttribution(
1497
+ {
1498
+ abi: this.orchestratorAbi,
1499
+ functionName: opts.functionName,
1500
+ args: opts.args ?? []
1501
+ },
1502
+ referrer
1503
+ );
1504
+ return {
1505
+ to: this.orchestratorAddress,
1506
+ data,
1507
+ value: opts.value ?? value ?? 0n,
1508
+ chainId: this.chainId,
1509
+ abi: this.orchestratorAbi,
1510
+ functionName: opts.functionName,
1511
+ args: opts.args ?? []
1512
+ };
1513
+ }
1514
+ buildEscrowMethod(functionName, buildArgs, buildValue) {
1515
+ return Object.assign(
1516
+ async (params) => {
1517
+ const prepared = this.prepareEscrowTransaction({
1518
+ functionName,
1519
+ args: buildArgs(params),
1520
+ txOverrides: params.txOverrides,
1521
+ value: buildValue?.(params)
1522
+ });
1523
+ return this.executePreparedTransaction(prepared, params.txOverrides);
1524
+ },
1525
+ {
1526
+ prepare: async (params) => {
1527
+ const prepared = this.prepareEscrowTransaction({
1528
+ functionName,
1529
+ args: buildArgs(params),
1530
+ txOverrides: params.txOverrides,
1531
+ value: buildValue?.(params)
1532
+ });
1533
+ return {
1534
+ to: prepared.to,
1535
+ data: prepared.data,
1536
+ value: prepared.value,
1537
+ chainId: prepared.chainId
1538
+ };
1539
+ }
1540
+ }
1541
+ );
1542
+ }
1543
+ buildOrchestratorMethod(functionName, buildArgs, buildValue) {
1544
+ return Object.assign(
1545
+ async (params) => {
1546
+ const prepared = this.prepareOrchestratorTransaction({
1547
+ functionName,
1548
+ args: buildArgs(params),
1549
+ txOverrides: params.txOverrides,
1550
+ value: buildValue?.(params)
1551
+ });
1552
+ return this.executePreparedTransaction(prepared, params.txOverrides);
1553
+ },
1554
+ {
1555
+ prepare: async (params) => {
1556
+ const prepared = this.prepareOrchestratorTransaction({
1557
+ functionName,
1558
+ args: buildArgs(params),
1559
+ txOverrides: params.txOverrides,
1560
+ value: buildValue?.(params)
1561
+ });
1562
+ return {
1563
+ to: prepared.to,
1564
+ data: prepared.data,
1565
+ value: prepared.value,
1566
+ chainId: prepared.chainId
1567
+ };
1568
+ }
1569
+ }
1570
+ );
1571
+ }
1220
1572
  // ╔═══════════════════════════════════════════════════════════════════════════╗
1221
1573
  // ║ CORE: DEPOSIT QUERIES (RPC-first via ProtocolViewer) ║
1222
1574
  // ╚═══════════════════════════════════════════════════════════════════════════╝
@@ -1540,7 +1892,29 @@ var Zkp2pClient = class {
1540
1892
  * ```
1541
1893
  */
1542
1894
  async createDeposit(params) {
1543
- const methods = getPaymentMethodsCatalog(this.chainId, this.runtimeEnv);
1895
+ const { depositDetails, prepared } = await this.prepareCreateDepositInternal(params);
1896
+ const hash = await this.executePreparedTransaction(prepared, params.txOverrides);
1897
+ return { depositDetails, hash };
1898
+ }
1899
+ /**
1900
+ * Prepares a createDeposit transaction without sending it.
1901
+ *
1902
+ * Returns both the prepared transaction calldata and the posted deposit details
1903
+ * (including hashed on-chain IDs) needed for tracking.
1904
+ */
1905
+ async prepareCreateDeposit(params) {
1906
+ const { depositDetails, prepared } = await this.prepareCreateDepositInternal(params);
1907
+ return {
1908
+ depositDetails,
1909
+ prepared: {
1910
+ to: prepared.to,
1911
+ data: prepared.data,
1912
+ value: prepared.value,
1913
+ chainId: prepared.chainId
1914
+ }
1915
+ };
1916
+ }
1917
+ async prepareCreateDepositInternal(params) {
1544
1918
  if (!Array.isArray(params.processorNames) || params.processorNames.length === 0) {
1545
1919
  throw new Error("processorNames must be a non-empty array");
1546
1920
  }
@@ -1550,40 +1924,59 @@ var Zkp2pClient = class {
1550
1924
  if (params.processorNames.length !== params.depositData.length) {
1551
1925
  throw new Error("processorNames and depositData length mismatch");
1552
1926
  }
1553
- const paymentMethods = params.processorNames.map((name) => resolvePaymentMethodHashFromCatalog(name, methods));
1554
- const intentGatingService = getGatingServiceAddress(this.chainId, this.runtimeEnv);
1555
- const baseApiUrl = (this.baseApiUrl ?? "https://api.zkp2p.xyz").replace(/\/$/, "");
1556
- if (!this.apiKey && !this.authorizationToken) {
1557
- throw new Error("createDeposit requires apiKey or authorizationToken to post deposit details");
1558
- }
1559
1927
  const depositDetails = params.processorNames.map((processorName, index) => ({
1560
1928
  processorName,
1561
1929
  depositData: params.depositData[index] || {}
1562
1930
  }));
1563
- const apiResponses = await Promise.all(
1564
- depositDetails.map((req) => apiPostDepositDetails(req, baseApiUrl, this.apiTimeoutMs))
1931
+ const hasOverrides = Boolean(
1932
+ params.paymentMethodsOverride || params.paymentMethodDataOverride || params.currenciesOverride
1565
1933
  );
1566
- if (!apiResponses.every((r) => r?.success)) {
1567
- const failed = apiResponses.find((r) => !r?.success);
1568
- throw new Error(failed?.message || "Failed to create deposit details");
1569
- }
1570
- const hashedOnchainIds = apiResponses.map((r) => r.responseObject?.hashedOnchainId);
1571
- const paymentMethodData = hashedOnchainIds.map((hid) => ({ intentGatingService, payeeDetails: hid, data: "0x" }));
1572
- params.conversionRates.forEach((group, i) => {
1573
- const key = params.processorNames[i]?.toLowerCase();
1574
- const allowed = methods[key]?.currencies?.map((c) => c.toLowerCase());
1575
- if (allowed && allowed.length) {
1576
- for (const { currency } of group) {
1577
- const codeHash = currencyKeccak256(String(currency).toUpperCase()).toLowerCase();
1578
- if (!allowed.includes(codeHash)) {
1579
- throw new Error(`Currency ${currency} not supported by ${params.processorNames[i]}. Allowed: ${allowed.join(", ")}`);
1934
+ let paymentMethods;
1935
+ let paymentMethodData;
1936
+ let currencies;
1937
+ if (hasOverrides) {
1938
+ if (!params.paymentMethodsOverride || !params.paymentMethodDataOverride || !params.currenciesOverride) {
1939
+ throw new Error("paymentMethodsOverride, paymentMethodDataOverride, and currenciesOverride must be provided together");
1940
+ }
1941
+ if (params.paymentMethodsOverride.length !== params.paymentMethodDataOverride.length || params.paymentMethodsOverride.length !== params.currenciesOverride.length) {
1942
+ throw new Error("paymentMethodsOverride, paymentMethodDataOverride, and currenciesOverride length mismatch");
1943
+ }
1944
+ paymentMethods = params.paymentMethodsOverride;
1945
+ paymentMethodData = params.paymentMethodDataOverride;
1946
+ currencies = params.currenciesOverride;
1947
+ } else {
1948
+ const methods = getPaymentMethodsCatalog(this.chainId, this.runtimeEnv);
1949
+ paymentMethods = params.processorNames.map((name) => resolvePaymentMethodHashFromCatalog(name, methods));
1950
+ const intentGatingService = getGatingServiceAddress(this.chainId, this.runtimeEnv);
1951
+ const baseApiUrl = (this.baseApiUrl ?? "https://api.zkp2p.xyz").replace(/\/$/, "");
1952
+ if (!this.apiKey && !this.authorizationToken) {
1953
+ throw new Error("createDeposit requires apiKey or authorizationToken to post deposit details");
1954
+ }
1955
+ const apiResponses = await Promise.all(
1956
+ depositDetails.map((req) => apiPostDepositDetails(req, baseApiUrl, this.apiTimeoutMs))
1957
+ );
1958
+ if (!apiResponses.every((r) => r?.success)) {
1959
+ const failed = apiResponses.find((r) => !r?.success);
1960
+ throw new Error(failed?.message || "Failed to create deposit details");
1961
+ }
1962
+ const hashedOnchainIds = apiResponses.map((r) => r.responseObject?.hashedOnchainId);
1963
+ paymentMethodData = hashedOnchainIds.map((hid) => ({ intentGatingService, payeeDetails: hid, data: "0x" }));
1964
+ params.conversionRates.forEach((group, i) => {
1965
+ const key = params.processorNames[i]?.toLowerCase();
1966
+ const allowed = methods[key]?.currencies?.map((c) => c.toLowerCase());
1967
+ if (allowed && allowed.length) {
1968
+ for (const { currency } of group) {
1969
+ const codeHash = currencyKeccak256(String(currency).toUpperCase()).toLowerCase();
1970
+ if (!allowed.includes(codeHash)) {
1971
+ throw new Error(`Currency ${currency} not supported by ${params.processorNames[i]}. Allowed: ${allowed.join(", ")}`);
1972
+ }
1580
1973
  }
1581
1974
  }
1582
- }
1583
- });
1584
- const { mapConversionRatesToOnchainMinRate: mapConversionRatesToOnchainMinRate2 } = await import('./currency-RSSHQOM3.mjs');
1585
- const normalized = params.conversionRates.map((group) => group.map((r) => ({ currency: r.currency, conversionRate: r.conversionRate })));
1586
- const currencies = mapConversionRatesToOnchainMinRate2(normalized, paymentMethods.length);
1975
+ });
1976
+ const { mapConversionRatesToOnchainMinRate: mapConversionRatesToOnchainMinRate2 } = await import('./currency-UVK4OKUR.mjs');
1977
+ const normalized = params.conversionRates.map((group) => group.map((r) => ({ currency: r.currency, conversionRate: r.conversionRate })));
1978
+ currencies = mapConversionRatesToOnchainMinRate2(normalized, paymentMethods.length);
1979
+ }
1587
1980
  const args = [{
1588
1981
  token: params.token,
1589
1982
  amount: params.amount,
@@ -1595,290 +1988,12 @@ var Zkp2pClient = class {
1595
1988
  intentGuardian: params.intentGuardian ?? "0x0000000000000000000000000000000000000000",
1596
1989
  retainOnEmpty: Boolean(params.retainOnEmpty ?? false)
1597
1990
  }];
1598
- const hash = await this.simulateAndSendWithAttribution({
1599
- address: this.escrowAddress,
1600
- abi: this.escrowAbi,
1991
+ const prepared = this.prepareEscrowTransaction({
1601
1992
  functionName: "createDeposit",
1602
1993
  args,
1603
1994
  txOverrides: params.txOverrides
1604
1995
  });
1605
- return { depositDetails, hash };
1606
- }
1607
- // ╔═══════════════════════════════════════════════════════════════════════════╗
1608
- // ║ CORE: DEPOSIT MANAGEMENT ║
1609
- // ╚═══════════════════════════════════════════════════════════════════════════╝
1610
- /**
1611
- * Enables or disables a deposit from accepting new intents.
1612
- *
1613
- * @param params.depositId - The deposit ID
1614
- * @param params.accepting - Whether to accept new intents
1615
- * @param params.txOverrides - Optional viem transaction overrides
1616
- * @returns Transaction hash
1617
- */
1618
- async setAcceptingIntents(params) {
1619
- return this.simulateAndSendWithAttribution({
1620
- address: this.escrowAddress,
1621
- abi: this.escrowAbi,
1622
- functionName: "setAcceptingIntents",
1623
- args: [params.depositId, params.accepting],
1624
- txOverrides: params.txOverrides
1625
- });
1626
- }
1627
- /**
1628
- * Updates the min/max intent amount range for a deposit.
1629
- *
1630
- * @param params.depositId - The deposit ID
1631
- * @param params.min - Minimum intent amount
1632
- * @param params.max - Maximum intent amount
1633
- * @param params.txOverrides - Optional viem transaction overrides
1634
- * @returns Transaction hash
1635
- */
1636
- async setIntentRange(params) {
1637
- return this.simulateAndSendWithAttribution({
1638
- address: this.escrowAddress,
1639
- abi: this.escrowAbi,
1640
- functionName: "setIntentRange",
1641
- args: [params.depositId, { min: params.min, max: params.max }],
1642
- txOverrides: params.txOverrides
1643
- });
1644
- }
1645
- /**
1646
- * Updates the minimum conversion rate for a specific currency on a payment method.
1647
- *
1648
- * @param params.depositId - The deposit ID
1649
- * @param params.paymentMethod - Payment method hash (bytes32)
1650
- * @param params.fiatCurrency - Fiat currency hash (bytes32)
1651
- * @param params.minConversionRate - New minimum conversion rate (18 decimals)
1652
- * @param params.txOverrides - Optional viem transaction overrides
1653
- * @returns Transaction hash
1654
- */
1655
- async setCurrencyMinRate(params) {
1656
- return this.simulateAndSendWithAttribution({
1657
- address: this.escrowAddress,
1658
- abi: this.escrowAbi,
1659
- functionName: "setCurrencyMinRate",
1660
- args: [params.depositId, params.paymentMethod, params.fiatCurrency, params.minConversionRate],
1661
- txOverrides: params.txOverrides
1662
- });
1663
- }
1664
- /**
1665
- * Adds additional funds to an existing deposit.
1666
- * Requires prior approval of the token amount.
1667
- *
1668
- * @param params.depositId - The deposit ID to add funds to
1669
- * @param params.amount - Amount to add (in token units)
1670
- * @param params.txOverrides - Optional viem transaction overrides
1671
- * @returns Transaction hash
1672
- */
1673
- async addFunds(params) {
1674
- return this.simulateAndSendWithAttribution({
1675
- address: this.escrowAddress,
1676
- abi: this.escrowAbi,
1677
- functionName: "addFunds",
1678
- args: [params.depositId, params.amount],
1679
- txOverrides: params.txOverrides
1680
- });
1681
- }
1682
- /**
1683
- * Removes funds from a deposit (partial withdrawal).
1684
- * Can only withdraw available (non-locked) funds.
1685
- *
1686
- * @param params.depositId - The deposit ID
1687
- * @param params.amount - Amount to remove (in token units)
1688
- * @param params.txOverrides - Optional viem transaction overrides
1689
- * @returns Transaction hash
1690
- */
1691
- async removeFunds(params) {
1692
- return this.simulateAndSendWithAttribution({
1693
- address: this.escrowAddress,
1694
- abi: this.escrowAbi,
1695
- functionName: "removeFunds",
1696
- args: [params.depositId, params.amount],
1697
- txOverrides: params.txOverrides
1698
- });
1699
- }
1700
- /**
1701
- * Fully withdraws a deposit, returning all available funds to the owner.
1702
- * The deposit must have no active intents.
1703
- *
1704
- * @param params.depositId - The deposit ID to withdraw
1705
- * @param params.txOverrides - Optional viem transaction overrides
1706
- * @returns Transaction hash
1707
- */
1708
- async withdrawDeposit(params) {
1709
- return this.simulateAndSendWithAttribution({
1710
- address: this.escrowAddress,
1711
- abi: this.escrowAbi,
1712
- functionName: "withdrawDeposit",
1713
- args: [params.depositId],
1714
- txOverrides: params.txOverrides
1715
- });
1716
- }
1717
- // ╔═══════════════════════════════════════════════════════════════════════════╗
1718
- // ║ CORE: ADVANCED DEPOSIT CONFIGURATION ║
1719
- // ╚═══════════════════════════════════════════════════════════════════════════╝
1720
- /**
1721
- * Sets whether a deposit should remain active when its balance reaches zero.
1722
- *
1723
- * @param params.depositId - The deposit ID
1724
- * @param params.retain - If true, deposit stays active when empty
1725
- * @param params.txOverrides - Optional viem transaction overrides
1726
- * @returns Transaction hash
1727
- */
1728
- async setRetainOnEmpty(params) {
1729
- return this.simulateAndSendWithAttribution({
1730
- address: this.escrowAddress,
1731
- abi: this.escrowAbi,
1732
- functionName: "setRetainOnEmpty",
1733
- args: [params.depositId, params.retain],
1734
- txOverrides: params.txOverrides
1735
- });
1736
- }
1737
- /**
1738
- * Assigns a delegate address that can manage the deposit on behalf of the owner.
1739
- *
1740
- * @param params.depositId - The deposit ID
1741
- * @param params.delegate - Address to delegate management to
1742
- * @param params.txOverrides - Optional viem transaction overrides
1743
- * @returns Transaction hash
1744
- */
1745
- async setDelegate(params) {
1746
- return this.simulateAndSendWithAttribution({
1747
- address: this.escrowAddress,
1748
- abi: this.escrowAbi,
1749
- functionName: "setDelegate",
1750
- args: [params.depositId, params.delegate],
1751
- txOverrides: params.txOverrides
1752
- });
1753
- }
1754
- /**
1755
- * Removes the delegate from a deposit.
1756
- *
1757
- * @param params.depositId - The deposit ID
1758
- * @param params.txOverrides - Optional viem transaction overrides
1759
- * @returns Transaction hash
1760
- */
1761
- async removeDelegate(params) {
1762
- return this.simulateAndSendWithAttribution({
1763
- address: this.escrowAddress,
1764
- abi: this.escrowAbi,
1765
- functionName: "removeDelegate",
1766
- args: [params.depositId],
1767
- txOverrides: params.txOverrides
1768
- });
1769
- }
1770
- /**
1771
- * Adds new payment methods to an existing deposit.
1772
- *
1773
- * @param params.depositId - The deposit ID
1774
- * @param params.paymentMethods - Array of payment method hashes to add
1775
- * @param params.paymentMethodData - Corresponding payment method configuration
1776
- * @param params.txOverrides - Optional viem transaction overrides
1777
- * @returns Transaction hash
1778
- */
1779
- async addPaymentMethods(params) {
1780
- return this.simulateAndSendWithAttribution({
1781
- address: this.escrowAddress,
1782
- abi: this.escrowAbi,
1783
- functionName: "addPaymentMethods",
1784
- args: [params.depositId, params.paymentMethods, params.paymentMethodData],
1785
- txOverrides: params.txOverrides
1786
- });
1787
- }
1788
- /**
1789
- * Activates or deactivates a payment method on a deposit.
1790
- *
1791
- * @param params.depositId - The deposit ID
1792
- * @param params.paymentMethod - Payment method hash to modify
1793
- * @param params.isActive - Whether the payment method should accept intents
1794
- * @param params.txOverrides - Optional viem transaction overrides
1795
- * @returns Transaction hash
1796
- */
1797
- async setPaymentMethodActive(params) {
1798
- return this.simulateAndSendWithAttribution({
1799
- address: this.escrowAddress,
1800
- abi: this.escrowAbi,
1801
- functionName: "setPaymentMethodActive",
1802
- args: [params.depositId, params.paymentMethod, params.isActive],
1803
- txOverrides: params.txOverrides
1804
- });
1805
- }
1806
- /**
1807
- * Deactivates a payment method on a deposit (convenience alias for setPaymentMethodActive).
1808
- *
1809
- * @param params.depositId - The deposit ID
1810
- * @param params.paymentMethod - Payment method hash to deactivate
1811
- * @param params.txOverrides - Optional viem transaction overrides
1812
- * @returns Transaction hash
1813
- */
1814
- async removePaymentMethod(params) {
1815
- return this.setPaymentMethodActive({ depositId: params.depositId, paymentMethod: params.paymentMethod, isActive: false, txOverrides: params.txOverrides });
1816
- }
1817
- /**
1818
- * Adds new currencies to a payment method on a deposit.
1819
- *
1820
- * @param params.depositId - The deposit ID
1821
- * @param params.paymentMethod - Payment method hash to add currencies to
1822
- * @param params.currencies - Array of currency configurations with code and min rate
1823
- * @param params.txOverrides - Optional viem transaction overrides
1824
- * @returns Transaction hash
1825
- */
1826
- async addCurrencies(params) {
1827
- return this.simulateAndSendWithAttribution({
1828
- address: this.escrowAddress,
1829
- abi: this.escrowAbi,
1830
- functionName: "addCurrencies",
1831
- args: [params.depositId, params.paymentMethod, params.currencies],
1832
- txOverrides: params.txOverrides
1833
- });
1834
- }
1835
- /**
1836
- * Deactivates a currency for a payment method on a deposit.
1837
- *
1838
- * @param params.depositId - The deposit ID
1839
- * @param params.paymentMethod - Payment method hash
1840
- * @param params.currencyCode - Currency code hash to deactivate
1841
- * @param params.txOverrides - Optional viem transaction overrides
1842
- * @returns Transaction hash
1843
- */
1844
- async deactivateCurrency(params) {
1845
- return this.simulateAndSendWithAttribution({
1846
- address: this.escrowAddress,
1847
- abi: this.escrowAbi,
1848
- functionName: "deactivateCurrency",
1849
- args: [params.depositId, params.paymentMethod, params.currencyCode],
1850
- txOverrides: params.txOverrides
1851
- });
1852
- }
1853
- /**
1854
- * Removes (deactivates) a currency from a payment method.
1855
- * Alias for deactivateCurrency.
1856
- *
1857
- * @param params.depositId - The deposit ID
1858
- * @param params.paymentMethod - Payment method hash
1859
- * @param params.currencyCode - Currency code hash to remove
1860
- * @param params.txOverrides - Optional viem transaction overrides
1861
- * @returns Transaction hash
1862
- */
1863
- async removeCurrency(params) {
1864
- return this.deactivateCurrency(params);
1865
- }
1866
- /**
1867
- * Removes expired intents from a deposit, freeing up locked funds.
1868
- * Can be called by anyone (permissionless cleanup).
1869
- *
1870
- * @param params.depositId - The deposit ID to prune
1871
- * @param params.txOverrides - Optional viem transaction overrides
1872
- * @returns Transaction hash
1873
- */
1874
- async pruneExpiredIntents(params) {
1875
- return this.simulateAndSendWithAttribution({
1876
- address: this.escrowAddress,
1877
- abi: this.escrowAbi,
1878
- functionName: "pruneExpiredIntents",
1879
- args: [params.depositId],
1880
- txOverrides: params.txOverrides
1881
- });
1996
+ return { depositDetails, prepared };
1882
1997
  }
1883
1998
  /**
1884
1999
  * Prepare signalIntent transaction (all logic except simulation/send).
@@ -1974,26 +2089,6 @@ var Zkp2pClient = class {
1974
2089
  args
1975
2090
  };
1976
2091
  }
1977
- /**
1978
- * **Supporting Method** - Releases funds back to the deposit owner.
1979
- *
1980
- * Called by the deposit owner when they want to reject an intent
1981
- * (e.g., payment verification failed or intent expired).
1982
- *
1983
- * @param params.intentHash - The intent hash (0x-prefixed, 32 bytes)
1984
- * @param params.txOverrides - Optional viem transaction overrides
1985
- * @returns Transaction hash
1986
- */
1987
- async releaseFundsToPayer(params) {
1988
- if (!this.orchestratorAddress || !this.orchestratorAbi) throw new Error("Orchestrator not available");
1989
- return this.simulateAndSendWithAttribution({
1990
- address: this.orchestratorAddress,
1991
- abi: this.orchestratorAbi,
1992
- functionName: "releaseFundsToPayer",
1993
- args: [params.intentHash],
1994
- txOverrides: params.txOverrides
1995
- });
1996
- }
1997
2092
  /**
1998
2093
  * Prepare fulfillIntent transaction (all logic except simulation/send).
1999
2094
  * Includes fetching intent inputs and calling attestation service.
@@ -2012,10 +2107,10 @@ var Zkp2pClient = class {
2012
2107
  const paymentMethodHash = inputs.paymentMethodHash || "0x";
2013
2108
  const timestampBufferMs = params.timestampBufferMs ?? "300000";
2014
2109
  const catalog = getPaymentMethodsCatalog(this.chainId, this.runtimeEnv);
2015
- const { resolvePaymentMethodNameFromHash: resolvePaymentMethodNameFromHash2 } = await import('./paymentResolution-4AAJVIIC.mjs');
2110
+ const { resolvePaymentMethodNameFromHash: resolvePaymentMethodNameFromHash2 } = await import('./paymentResolution-2FP3NLM3.mjs');
2016
2111
  const platformName = resolvePaymentMethodNameFromHash2(paymentMethodHash, catalog);
2017
2112
  if (!platformName) throw new Error("Unknown paymentMethodHash for this network/env; update SDK catalogs.");
2018
- const { resolvePlatformAttestationConfig } = await import('./constants-MQB4AQDD.mjs');
2113
+ const { resolvePlatformAttestationConfig } = await import('./constants-ZICRSYZM.mjs');
2019
2114
  const cfg = resolvePlatformAttestationConfig(platformName);
2020
2115
  const platform = cfg.actionPlatform;
2021
2116
  const actionType = cfg.actionType;
@@ -2177,11 +2272,11 @@ var Zkp2pClient = class {
2177
2272
  try {
2178
2273
  const { address, abi } = this.requireProtocolViewer();
2179
2274
  const raw = await this.publicClient.readContract({ address, abi, functionName: "getDeposit", args: [id] });
2180
- const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-3QIR3XMT.mjs');
2275
+ const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-EH5DGVSU.mjs');
2181
2276
  return parseDepositView2(raw);
2182
2277
  } catch (e) {
2183
2278
  const raw = await this.publicClient.readContract({ address: this.escrowAddress, abi: this.escrowAbi, functionName: "getDeposit", args: [id] });
2184
- const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-3QIR3XMT.mjs');
2279
+ const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-EH5DGVSU.mjs');
2185
2280
  return parseDepositView2(raw);
2186
2281
  }
2187
2282
  }
@@ -2193,7 +2288,7 @@ var Zkp2pClient = class {
2193
2288
  */
2194
2289
  async getPvDepositsFromIds(ids) {
2195
2290
  if (!this.protocolViewerAddress || !this.protocolViewerAbi) {
2196
- const { parseDepositView: parseDepositView3 } = await import('./protocolViewerParsers-3QIR3XMT.mjs');
2291
+ const { parseDepositView: parseDepositView3 } = await import('./protocolViewerParsers-EH5DGVSU.mjs');
2197
2292
  const results = [];
2198
2293
  for (const id of ids) {
2199
2294
  const raw2 = await this.publicClient.readContract({
@@ -2213,7 +2308,7 @@ var Zkp2pClient = class {
2213
2308
  functionName: "getDepositFromIds",
2214
2309
  args: [bn]
2215
2310
  });
2216
- const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-3QIR3XMT.mjs');
2311
+ const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-EH5DGVSU.mjs');
2217
2312
  return raw.map(parseDepositView2);
2218
2313
  }
2219
2314
  /**
@@ -2226,11 +2321,11 @@ var Zkp2pClient = class {
2226
2321
  try {
2227
2322
  const { address, abi } = this.requireProtocolViewer();
2228
2323
  const raw = await this.publicClient.readContract({ address, abi, functionName: "getAccountDeposits", args: [owner] });
2229
- const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-3QIR3XMT.mjs');
2324
+ const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-EH5DGVSU.mjs');
2230
2325
  return raw.map(parseDepositView2);
2231
2326
  } catch (e) {
2232
2327
  const raw = await this.publicClient.readContract({ address: this.escrowAddress, abi: this.escrowAbi, functionName: "getAccountDeposits", args: [owner] });
2233
- const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-3QIR3XMT.mjs');
2328
+ const { parseDepositView: parseDepositView2 } = await import('./protocolViewerParsers-EH5DGVSU.mjs');
2234
2329
  return raw.map(parseDepositView2);
2235
2330
  }
2236
2331
  }
@@ -2249,7 +2344,7 @@ var Zkp2pClient = class {
2249
2344
  functionName: "getAccountIntents",
2250
2345
  args: [owner]
2251
2346
  });
2252
- const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-3QIR3XMT.mjs');
2347
+ const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-EH5DGVSU.mjs');
2253
2348
  return raw.map(parseIntentView2);
2254
2349
  }
2255
2350
  /**
@@ -2266,7 +2361,7 @@ var Zkp2pClient = class {
2266
2361
  functionName: "getIntent",
2267
2362
  args: [intentHash]
2268
2363
  });
2269
- const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-3QIR3XMT.mjs');
2364
+ const { parseIntentView: parseIntentView2 } = await import('./protocolViewerParsers-EH5DGVSU.mjs');
2270
2365
  return parseIntentView2(raw);
2271
2366
  }
2272
2367
  // ╔═══════════════════════════════════════════════════════════════════════════╗
@@ -2368,6 +2463,199 @@ var Zkp2pClient = class {
2368
2463
  }
2369
2464
  };
2370
2465
 
2466
+ // src/extension.ts
2467
+ var PEER_EXTENSION_CHROME_URL = "https://chromewebstore.google.com/detail/peerauth-authenticate-and/ijpgccednehjpeclfcllnjjcmiohdjih";
2468
+ var resolveWindow = (options) => {
2469
+ if (options?.window) {
2470
+ return options.window;
2471
+ }
2472
+ if (typeof window === "undefined") {
2473
+ return void 0;
2474
+ }
2475
+ return window;
2476
+ };
2477
+ var requirePeer = (options) => {
2478
+ const resolvedWindow = resolveWindow(options);
2479
+ if (!resolvedWindow) {
2480
+ throw new Error("Peer extension SDK requires a browser window.");
2481
+ }
2482
+ if (!resolvedWindow.peer) {
2483
+ throw new Error("Peer extension not available. Install or enable the Peer extension.");
2484
+ }
2485
+ return resolvedWindow.peer;
2486
+ };
2487
+ var isPeerExtensionAvailable = (options) => {
2488
+ const resolvedWindow = resolveWindow(options);
2489
+ return Boolean(resolvedWindow?.peer);
2490
+ };
2491
+ var openPeerExtensionInstallPage = (options) => {
2492
+ const resolvedWindow = resolveWindow(options);
2493
+ if (!resolvedWindow) {
2494
+ throw new Error("Peer extension SDK requires a browser window.");
2495
+ }
2496
+ resolvedWindow.open(PEER_EXTENSION_CHROME_URL, "_blank", "noopener,noreferrer");
2497
+ };
2498
+ var getPeerExtensionState = async (options) => {
2499
+ if (!isPeerExtensionAvailable(options)) {
2500
+ return "needs_install";
2501
+ }
2502
+ try {
2503
+ const status = await requirePeer(options).checkConnectionStatus();
2504
+ return status === "connected" ? "ready" : "needs_connection";
2505
+ } catch (error) {
2506
+ return "needs_connection";
2507
+ }
2508
+ };
2509
+ var fiatAmountRegex = /^-?\d*(\.\d{0,6})?$/;
2510
+ var usdcAmountRegex = /^\d+$/;
2511
+ var assertObjectInput = (params) => {
2512
+ if (params === void 0) {
2513
+ return {};
2514
+ }
2515
+ if (params === null || typeof params !== "object" || Array.isArray(params)) {
2516
+ throw new Error("Peer extension onramp expects an object of query params.");
2517
+ }
2518
+ return params;
2519
+ };
2520
+ var normalizeOptionalString = (value, label) => {
2521
+ if (value === void 0) {
2522
+ return void 0;
2523
+ }
2524
+ if (typeof value !== "string") {
2525
+ throw new Error(`Peer extension onramp ${label} must be a non-empty string.`);
2526
+ }
2527
+ const trimmed = value.trim();
2528
+ if (!trimmed) {
2529
+ throw new Error(`Peer extension onramp ${label} must be a non-empty string.`);
2530
+ }
2531
+ return trimmed;
2532
+ };
2533
+ var normalizeOptionalUrl = (value, label) => {
2534
+ const trimmed = normalizeOptionalString(value, label);
2535
+ if (trimmed === void 0) {
2536
+ return void 0;
2537
+ }
2538
+ let parsed;
2539
+ try {
2540
+ parsed = new URL(trimmed);
2541
+ } catch (error) {
2542
+ throw new Error(`Peer extension onramp ${label} must be a valid URL.`);
2543
+ }
2544
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
2545
+ throw new Error(`Peer extension onramp ${label} must use http or https.`);
2546
+ }
2547
+ return trimmed;
2548
+ };
2549
+ var normalizeFiatAmount = (value) => {
2550
+ if (value === void 0) {
2551
+ return void 0;
2552
+ }
2553
+ const normalized = typeof value === "number" ? String(value) : value;
2554
+ if (typeof normalized !== "string") {
2555
+ throw new Error("Peer extension onramp inputAmount must be a string or number.");
2556
+ }
2557
+ const trimmed = normalized.trim();
2558
+ if (!trimmed) {
2559
+ throw new Error("Peer extension onramp inputAmount must be a non-empty value.");
2560
+ }
2561
+ if (!fiatAmountRegex.test(trimmed)) {
2562
+ throw new Error(
2563
+ "Peer extension onramp inputAmount must be a non-negative number with up to 6 decimals."
2564
+ );
2565
+ }
2566
+ if (Number.isNaN(Number(trimmed)) || Number(trimmed) < 0) {
2567
+ throw new Error(
2568
+ "Peer extension onramp inputAmount must be a non-negative number with up to 6 decimals."
2569
+ );
2570
+ }
2571
+ return trimmed;
2572
+ };
2573
+ var normalizeUsdcAmount = (value) => {
2574
+ if (value === void 0) {
2575
+ return void 0;
2576
+ }
2577
+ if (typeof value === "bigint") {
2578
+ if (value < 0n) {
2579
+ throw new Error("Peer extension onramp amountUsdc must be a non-negative integer.");
2580
+ }
2581
+ return value.toString();
2582
+ }
2583
+ if (typeof value === "number") {
2584
+ if (!Number.isFinite(value) || value < 0 || !Number.isInteger(value)) {
2585
+ throw new Error("Peer extension onramp amountUsdc must be a non-negative integer.");
2586
+ }
2587
+ return String(value);
2588
+ }
2589
+ if (typeof value !== "string") {
2590
+ throw new Error("Peer extension onramp amountUsdc must be a string, number, or bigint.");
2591
+ }
2592
+ const trimmed = value.trim();
2593
+ if (!trimmed) {
2594
+ throw new Error("Peer extension onramp amountUsdc must be a non-empty value.");
2595
+ }
2596
+ if (!usdcAmountRegex.test(trimmed)) {
2597
+ throw new Error("Peer extension onramp amountUsdc must be a non-negative integer.");
2598
+ }
2599
+ return trimmed;
2600
+ };
2601
+ var intentHashRegex = /^0x[a-fA-F0-9]{64}$/;
2602
+ var normalizeIntentHash = (value) => {
2603
+ if (value === void 0) {
2604
+ return void 0;
2605
+ }
2606
+ if (typeof value !== "string") {
2607
+ throw new Error("Peer extension onramp intentHash must be a string.");
2608
+ }
2609
+ const trimmed = value.trim();
2610
+ if (!trimmed) {
2611
+ throw new Error("Peer extension onramp intentHash must be a non-empty string.");
2612
+ }
2613
+ if (!intentHashRegex.test(trimmed)) {
2614
+ throw new Error(
2615
+ "Peer extension onramp intentHash must be a valid bytes32 hex string (0x + 64 hex characters)."
2616
+ );
2617
+ }
2618
+ return trimmed.toLowerCase();
2619
+ };
2620
+ var buildOnrampQueryString = (params) => {
2621
+ const validated = assertObjectInput(params);
2622
+ const searchParams = new URLSearchParams();
2623
+ const setParam = (key, value) => {
2624
+ if (value !== void 0) {
2625
+ searchParams.set(key, value);
2626
+ }
2627
+ };
2628
+ setParam("referrer", normalizeOptionalString(validated.referrer, "referrer"));
2629
+ setParam("referrerLogo", normalizeOptionalUrl(validated.referrerLogo, "referrerLogo"));
2630
+ setParam("inputCurrency", normalizeOptionalString(validated.inputCurrency, "inputCurrency"));
2631
+ setParam("inputAmount", normalizeFiatAmount(validated.inputAmount));
2632
+ setParam(
2633
+ "paymentPlatform",
2634
+ normalizeOptionalString(validated.paymentPlatform, "paymentPlatform")
2635
+ );
2636
+ setParam("toToken", normalizeOptionalString(validated.toToken, "toToken"));
2637
+ setParam("amountUsdc", normalizeUsdcAmount(validated.amountUsdc));
2638
+ setParam(
2639
+ "recipientAddress",
2640
+ normalizeOptionalString(validated.recipientAddress, "recipientAddress")
2641
+ );
2642
+ setParam("callbackUrl", normalizeOptionalUrl(validated.callbackUrl, "callbackUrl"));
2643
+ setParam("intentHash", normalizeIntentHash(validated.intentHash));
2644
+ return searchParams.toString();
2645
+ };
2646
+ var createPeerExtensionSdk = (options = {}) => ({
2647
+ isAvailable: () => isPeerExtensionAvailable(options),
2648
+ requestConnection: () => requirePeer(options).requestConnection(),
2649
+ checkConnectionStatus: () => requirePeer(options).checkConnectionStatus(),
2650
+ openSidebar: (route) => requirePeer(options).openSidebar(route),
2651
+ onramp: (params) => requirePeer(options).onramp(buildOnrampQueryString(params)),
2652
+ onProofComplete: (callback) => requirePeer(options).onProofComplete(callback),
2653
+ getVersion: () => requirePeer(options).getVersion(),
2654
+ openInstallPage: () => openPeerExtensionInstallPage(options),
2655
+ getState: () => getPeerExtensionState(options)
2656
+ });
2657
+ var peerExtensionSdk = createPeerExtensionSdk();
2658
+
2371
2659
  // src/utils/logger.ts
2372
2660
  var currentLevel = "info";
2373
2661
  function setLogLevel(level) {
@@ -2406,6 +2694,6 @@ var logger = {
2406
2694
  }
2407
2695
  };
2408
2696
 
2409
- export { BASE_BUILDER_CODE, IndexerClient, IndexerDepositService, Zkp2pClient as OfframpClient, ZKP2P_ANDROID_REFERRER, ZKP2P_IOS_REFERRER, Zkp2pClient, apiGetPayeeDetails, apiGetTakerTier, apiPostDepositDetails, apiValidatePayeeDetails, appendAttributionToCalldata, convertDepositsForLiquidity, convertIndexerDepositToEscrowView, convertIndexerIntentsToEscrowViews, createCompositeDepositId, defaultIndexerEndpoint, encodeWithAttribution, fetchFulfillmentAndPayment as fetchIndexerFulfillmentAndPayment, getAttributionDataSuffix, logger, sendTransactionWithAttribution, setLogLevel };
2697
+ export { BASE_BUILDER_CODE, IndexerClient, IndexerDepositService, Zkp2pClient as OfframpClient, PEER_EXTENSION_CHROME_URL, ZKP2P_ANDROID_REFERRER, ZKP2P_IOS_REFERRER, Zkp2pClient, apiGetOwnerDeposits, apiGetPayeeDetails, apiGetTakerTier, apiPostDepositDetails, apiValidatePayeeDetails, appendAttributionToCalldata, convertDepositsForLiquidity, convertIndexerDepositToEscrowView, convertIndexerIntentsToEscrowViews, createCompositeDepositId, createPeerExtensionSdk, defaultIndexerEndpoint, encodeWithAttribution, fetchFulfillmentAndPayment as fetchIndexerFulfillmentAndPayment, getAttributionDataSuffix, getPeerExtensionState, isPeerExtensionAvailable, logger, openPeerExtensionInstallPage, peerExtensionSdk, sendTransactionWithAttribution, setLogLevel };
2410
2698
  //# sourceMappingURL=index.mjs.map
2411
2699
  //# sourceMappingURL=index.mjs.map