@zkp2p/sdk 0.3.1 → 0.3.2-rc.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.
package/dist/index.cjs CHANGED
@@ -254,9 +254,6 @@ function uniqueAddresses(...values) {
254
254
  }
255
255
  return addresses;
256
256
  }
257
- function addressesEqual(left, right) {
258
- return Boolean(left && right && left.toLowerCase() === right.toLowerCase());
259
- }
260
257
  function readRuntimeEnv(key) {
261
258
  try {
262
259
  const meta = ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) });
@@ -288,26 +285,19 @@ function getContracts(chainId, env = "production") {
288
285
  "ProtocolViewerV2"
289
286
  ]);
290
287
  const baseV2ProtocolViewerAddress = pickAddress(baseContracts, ["ProtocolViewerV2"]);
291
- const baseV1ProtocolViewerAddress = pickAddress(baseContracts, ["ProtocolViewer"]);
292
288
  const baseProtocolViewerEntries = (() => {
293
289
  const entries = [];
294
290
  if (baseV2ProtocolViewerAddress && baseV2ProtocolViewerAbi) {
295
291
  entries.push({ address: baseV2ProtocolViewerAddress, abi: baseV2ProtocolViewerAbi });
296
292
  }
297
- if (baseV1ProtocolViewerAddress && !addressesEqual(baseV1ProtocolViewerAddress, baseV2ProtocolViewerAddress)) {
298
- entries.push({ address: baseV1ProtocolViewerAddress, abi: ProtocolViewerBase__default.default });
299
- }
300
293
  return entries.length > 0 ? entries : void 0;
301
294
  })();
302
295
  const addressesByKey = {
303
296
  base: {
304
- escrow: pickAddress(baseContracts, ["EscrowV2", "Escrow_V2"]) ?? pickAddress(baseContracts, ["Escrow"]) ?? "",
297
+ escrow: pickAddress(baseContracts, ["EscrowV2", "Escrow_V2"]) ?? "",
305
298
  escrowV2: pickAddress(baseContracts, ["EscrowV2", "Escrow_V2"]),
306
- escrowAddresses: uniqueAddresses(
307
- pickAddress(baseContracts, ["EscrowV2", "Escrow_V2"]),
308
- pickAddress(baseContracts, ["Escrow"])
309
- ),
310
- orchestrator: pickAddress(baseContracts, ["OrchestratorV2", "Orchestrator_V2"]) ?? pickAddress(baseContracts, ["Orchestrator"]),
299
+ escrowAddresses: uniqueAddresses(pickAddress(baseContracts, ["EscrowV2", "Escrow_V2"])),
300
+ orchestrator: pickAddress(baseContracts, ["OrchestratorV2", "Orchestrator_V2"]),
311
301
  orchestratorV2: pickAddress(baseContracts, ["OrchestratorV2", "Orchestrator_V2"]),
312
302
  orchestratorAddresses: uniqueAddresses(
313
303
  pickAddress(baseContracts, ["OrchestratorV2", "Orchestrator_V2"])
@@ -317,7 +307,7 @@ function getContracts(chainId, env = "production") {
317
307
  "UnifiedPaymentVerifier"
318
308
  ]),
319
309
  unifiedPaymentVerifierV2: pickAddress(baseContracts, ["UnifiedPaymentVerifierV2"]),
320
- protocolViewer: baseProtocolViewerEntries?.[0]?.address ?? baseV1ProtocolViewerAddress ?? baseV2ProtocolViewerAddress,
310
+ protocolViewer: baseProtocolViewerEntries?.[0]?.address ?? baseV2ProtocolViewerAddress,
321
311
  protocolViewerEntries: baseProtocolViewerEntries,
322
312
  usdc: baseConstants.USDC,
323
313
  rateManagerV1: pickAddress(baseContracts, ["RateManagerV1", "DepositRateManagerRegistryV1"]),
@@ -368,13 +358,13 @@ function getContracts(chainId, env = "production") {
368
358
  "VITE_BASE_STAGING_ESCROW_V2_ADDRESS",
369
359
  "VITE_ESCROW_V2_ADDRESS"
370
360
  ]);
371
- const stagingEscrowCurrent = stagingEscrowV2Override ?? pickAddress(sc, ["EscrowV2", "Escrow_V2"]) ?? pickAddress(sc, ["Escrow"]);
361
+ const stagingEscrowCurrent = stagingEscrowV2Override ?? pickAddress(sc, ["EscrowV2", "Escrow_V2"]);
372
362
  const stagingOrchestratorV2Override = resolveRuntimeAddressOverride([
373
363
  "VITE_BASE_STAGING_ORCHESTRATOR_V2_ADDRESS",
374
364
  "VITE_ORCHESTRATOR_V2_ADDRESS",
375
365
  "VITE_ORCHESTRATORV2_ADDRESS"
376
366
  ]);
377
- const stagingOrchestratorCurrent = stagingOrchestratorV2Override ?? pickAddress(sc, ["OrchestratorV2", "Orchestrator_V2"]) ?? pickAddress(sc, ["Orchestrator"]);
367
+ const stagingOrchestratorCurrent = stagingOrchestratorV2Override ?? pickAddress(sc, ["OrchestratorV2", "Orchestrator_V2"]);
378
368
  const stagingRateManagerV1 = pickAddress(sc, ["RateManagerV1", "DepositRateManagerRegistryV1"]);
379
369
  return {
380
370
  addresses: {
@@ -389,7 +379,7 @@ function getContracts(chainId, env = "production") {
389
379
  "UnifiedPaymentVerifier"
390
380
  ]),
391
381
  unifiedPaymentVerifierV2: pickAddress(sc, ["UnifiedPaymentVerifierV2"]),
392
- protocolViewer: pickAddress(sc, ["ProtocolViewerV2", "ProtocolViewer"]),
382
+ protocolViewer: pickAddress(sc, ["ProtocolViewerV2"]),
393
383
  protocolViewerEntries: (() => {
394
384
  const entries = [];
395
385
  const pvV2Address = pickAddress(sc, ["ProtocolViewerV2"]);
@@ -399,11 +389,6 @@ function getContracts(chainId, env = "production") {
399
389
  if (pvV2Address && pvV2Abi) {
400
390
  entries.push({ address: pvV2Address, abi: pvV2Abi });
401
391
  }
402
- const pvV1Address = pickAddress(sc, ["ProtocolViewer"]);
403
- const pvV1Abi = ProtocolViewerBaseStaging__default.default;
404
- if (pvV1Address && !addressesEqual(pvV1Address, pvV2Address) && pvV1Abi) {
405
- entries.push({ address: pvV1Address, abi: pvV1Abi });
406
- }
407
392
  return entries.length > 0 ? entries : void 0;
408
393
  })(),
409
394
  usdc: baseStagingConstants.USDC,
@@ -416,12 +401,11 @@ function getContracts(chainId, env = "production") {
416
401
  },
417
402
  abis: {
418
403
  escrow: EscrowBaseStaging__default.default,
419
- escrowV2: addressesEqual(stagingEscrowCurrent, pickAddress(sc, ["Escrow"])) ? EscrowBaseStaging__default.default : pickAbi(baseStagingAbisRaw__namespace, ["EscrowV2"]) ?? EscrowBaseStaging__default.default,
404
+ escrowV2: pickAbi(baseStagingAbisRaw__namespace, [
405
+ "EscrowV2"
406
+ ]) ?? EscrowBaseStaging__default.default,
420
407
  orchestrator: OrchestratorBaseStaging__default.default,
421
- orchestratorV2: addressesEqual(
422
- stagingOrchestratorCurrent,
423
- pickAddress(sc, ["Orchestrator"])
424
- ) ? OrchestratorBaseStaging__default.default : pickAbi(baseStagingAbisRaw__namespace, [
408
+ orchestratorV2: pickAbi(baseStagingAbisRaw__namespace, [
425
409
  "OrchestratorV2"
426
410
  ]) ?? OrchestratorBaseStaging__default.default,
427
411
  unifiedPaymentVerifier: pickAbi(baseStagingAbisRaw__namespace, [
@@ -1527,6 +1511,34 @@ async function apiCreatePaymentAttestation(payload, attestationServiceUrl, platf
1527
1511
  return res.json();
1528
1512
  });
1529
1513
  }
1514
+ async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, platform, timeoutMs) {
1515
+ return withRetry(
1516
+ async () => {
1517
+ let res;
1518
+ try {
1519
+ const endpoint = `/seller/credentials/${encodeURIComponent(platform)}`;
1520
+ res = await fetch(`${attestationServiceUrl}${endpoint}`, {
1521
+ method: "POST",
1522
+ headers: headers(),
1523
+ body: JSON.stringify(payload)
1524
+ });
1525
+ } catch (error) {
1526
+ throw new exports.NetworkError("Failed to connect to Attestation Service", {
1527
+ endpoint: `/seller/credentials/${platform}`,
1528
+ error
1529
+ });
1530
+ }
1531
+ if (!res.ok) {
1532
+ const errorText = await res.text();
1533
+ throw parseAPIError(res, errorText);
1534
+ }
1535
+ return res.json();
1536
+ },
1537
+ 3,
1538
+ 1e3,
1539
+ timeoutMs
1540
+ );
1541
+ }
1530
1542
  var abiCoder = ethers.AbiCoder.defaultAbiCoder();
1531
1543
  function encodeVerifyPaymentData(params) {
1532
1544
  return abiCoder.encode(
@@ -1670,6 +1682,9 @@ var PAYMENT_PLATFORMS = [
1670
1682
  "n26"
1671
1683
  ];
1672
1684
 
1685
+ // src/utils/constants.ts
1686
+ var DEFAULT_BASE_API_URL = "https://api.zkp2p.xyz";
1687
+
1673
1688
  // src/utils/oracles.ts
1674
1689
  init_currency();
1675
1690
  var ZERO_ADDRESS3 = "0x0000000000000000000000000000000000000000";
@@ -1916,6 +1931,13 @@ var IntentOperations = class {
1916
1931
  orchestratorAddress: params.orchestratorAddress,
1917
1932
  escrowAddress: escrowContext.address
1918
1933
  });
1934
+ const currentEscrow = this.config.getEscrowV2Address();
1935
+ const currentOrchestrator = this.config.getOrchestratorV2Address();
1936
+ if (currentEscrow && escrowContext.address.toLowerCase() !== currentEscrow.toLowerCase() || currentOrchestrator && orchestratorContext.address.toLowerCase() !== currentOrchestrator.toLowerCase()) {
1937
+ throw new Error(
1938
+ "signalIntent is only supported on the current EscrowV2 / OrchestratorV2 deployment"
1939
+ );
1940
+ }
1919
1941
  const catalog = getPaymentMethodsCatalog(this.config.getChainId(), this.config.getRuntimeEnv());
1920
1942
  const paymentMethod = resolvePaymentMethodHashFromCatalog(params.processorName, catalog);
1921
1943
  const fiatCurrency = resolveFiatCurrencyBytes32(params.fiatCurrencyCode);
@@ -6088,6 +6110,78 @@ async function apiGetTakerTier(req, apiKey, baseApiUrl, timeoutMs) {
6088
6110
  timeoutMs
6089
6111
  });
6090
6112
  }
6113
+ async function apiUploadSellerCredential(makerId, bundle, baseApiUrl, timeoutMs, apiKey, authToken) {
6114
+ return apiFetch({
6115
+ url: `${withApiBase(baseApiUrl)}/v2/makers/${makerId}/seller-credential`,
6116
+ method: "POST",
6117
+ body: bundle,
6118
+ apiKey,
6119
+ authToken,
6120
+ timeoutMs
6121
+ });
6122
+ }
6123
+ async function apiGetSellerCredentialStatus(makerId, baseApiUrl, timeoutMs, apiKey, authToken) {
6124
+ return apiFetch({
6125
+ url: `${withApiBase(baseApiUrl)}/v2/makers/${makerId}/seller-credential/status`,
6126
+ method: "GET",
6127
+ apiKey,
6128
+ authToken,
6129
+ timeoutMs
6130
+ });
6131
+ }
6132
+ async function apiVerifySellerPayment(platform, req, baseApiUrl, timeoutMs, apiKey, authToken) {
6133
+ return apiFetch({
6134
+ url: `${withApiBase(baseApiUrl)}/v2/verify/seller/${encodeURIComponent(platform)}`,
6135
+ method: "POST",
6136
+ body: req,
6137
+ apiKey,
6138
+ authToken,
6139
+ timeoutMs
6140
+ });
6141
+ }
6142
+ async function apiGetOrderbook(params, optsOrBaseApiUrl, timeoutMs, apiKey) {
6143
+ const opts = typeof optsOrBaseApiUrl === "string" ? {
6144
+ baseApiUrl: optsOrBaseApiUrl,
6145
+ timeoutMs,
6146
+ apiKey
6147
+ } : optsOrBaseApiUrl;
6148
+ const query = new URLSearchParams();
6149
+ Object.entries(params).forEach(([key, value]) => {
6150
+ if (value === void 0 || value === null) return;
6151
+ query.set(key, String(value));
6152
+ });
6153
+ const response = await apiFetch({
6154
+ url: `${withApiBase(opts.baseApiUrl)}/v2/orderbook?${query.toString()}`,
6155
+ method: "GET",
6156
+ apiKey: opts.apiKey,
6157
+ authToken: opts.authToken,
6158
+ timeoutMs: opts.timeoutMs
6159
+ });
6160
+ return response.responseObject;
6161
+ }
6162
+ async function apiGetDepositBundle(params, optsOrBaseApiUrl, timeoutMs, apiKey) {
6163
+ const opts = typeof optsOrBaseApiUrl === "string" ? {
6164
+ baseApiUrl: optsOrBaseApiUrl,
6165
+ timeoutMs,
6166
+ apiKey
6167
+ } : optsOrBaseApiUrl;
6168
+ const escrowAddress = requireEscrowAddress(
6169
+ params.escrowAddress,
6170
+ "apiGetDepositBundle requires escrowAddress"
6171
+ );
6172
+ const query = new URLSearchParams({ escrowAddress });
6173
+ if (params.dailySnapshotLimit !== void 0) {
6174
+ query.set("dailySnapshotLimit", String(params.dailySnapshotLimit));
6175
+ }
6176
+ const response = await apiFetch({
6177
+ url: `${withApiBase(opts.baseApiUrl)}/v2/deposits/${params.depositId}/bundle?${query.toString()}`,
6178
+ method: "GET",
6179
+ apiKey: opts.apiKey,
6180
+ authToken: opts.authToken,
6181
+ timeoutMs: opts.timeoutMs
6182
+ });
6183
+ return response.responseObject;
6184
+ }
6091
6185
 
6092
6186
  // src/client/Zkp2pClient.ts
6093
6187
  init_contracts();
@@ -7303,6 +7397,7 @@ var Zkp2pClient = class {
7303
7397
  getProtocolViewerAbi: () => this.protocolViewerAbi,
7304
7398
  getIndexerClient: () => this._indexerClient,
7305
7399
  getIndexerService: () => this._indexerService,
7400
+ getEscrowV2Address: () => this.escrowV2Address,
7306
7401
  getOrchestratorV2Address: () => this.orchestratorV2Address,
7307
7402
  host: {
7308
7403
  resolveEscrowContext: (options) => this.resolveEscrowContext(options),
@@ -7326,6 +7421,30 @@ var Zkp2pClient = class {
7326
7421
  parseRawDepositId(depositId) {
7327
7422
  return parseRawDepositId(depositId);
7328
7423
  }
7424
+ stripTrailingSlash(url) {
7425
+ return url.replace(/\/$/, "");
7426
+ }
7427
+ defaultAttestationServiceForBaseApiUrl(baseApiUrl) {
7428
+ try {
7429
+ const { hostname } = new URL(baseApiUrl);
7430
+ if (hostname === "api-staging.zkp2p.xyz") {
7431
+ return "https://attestation-service-staging.zkp2p.xyz";
7432
+ }
7433
+ if (hostname === "api-preprod.zkp2p.xyz") {
7434
+ return "https://attestation-service.zkp2p.xyz";
7435
+ }
7436
+ if (hostname === "api.zkp2p.xyz") {
7437
+ return "https://attestation-service.zkp2p.xyz";
7438
+ }
7439
+ } catch {
7440
+ }
7441
+ if (baseApiUrl === DEFAULT_BASE_API_URL) {
7442
+ return "https://attestation-service.zkp2p.xyz";
7443
+ }
7444
+ throw new Error(
7445
+ `attestationServiceUrl is required when baseApiUrl is not a supported zkp2p API host: ${baseApiUrl}`
7446
+ );
7447
+ }
7329
7448
  normalizeOracleRateConfig(config) {
7330
7449
  return normalizeOracleRateConfig(config);
7331
7450
  }
@@ -8519,7 +8638,7 @@ var Zkp2pClient = class {
8519
8638
  const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
8520
8639
  const reqWithEscrow = { ...req };
8521
8640
  if (!reqWithEscrow.escrowAddresses || reqWithEscrow.escrowAddresses.length === 0) {
8522
- const configuredEscrows = this.escrowAddresses.length > 0 ? this.escrowAddresses.map((address) => address) : this.escrowAddress ? [this.escrowAddress] : [];
8641
+ const configuredEscrows = this.escrowV2Address ? [this.escrowV2Address] : this.escrowAddress ? [this.escrowAddress] : [];
8523
8642
  if (configuredEscrows.length > 0) {
8524
8643
  reqWithEscrow.escrowAddresses = configuredEscrows;
8525
8644
  }
@@ -8563,7 +8682,7 @@ var Zkp2pClient = class {
8563
8682
  const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
8564
8683
  const reqWithEscrow = { ...req };
8565
8684
  if (!reqWithEscrow.escrowAddresses || reqWithEscrow.escrowAddresses.length === 0) {
8566
- const configuredEscrows = this.escrowAddresses.length > 0 ? [...this.escrowAddresses] : this.escrowAddress ? [this.escrowAddress] : [];
8685
+ const configuredEscrows = this.escrowV2Address ? [this.escrowV2Address] : this.escrowAddress ? [this.escrowAddress] : [];
8567
8686
  if (configuredEscrows.length > 0) {
8568
8687
  reqWithEscrow.escrowAddresses = configuredEscrows;
8569
8688
  }
@@ -8613,6 +8732,92 @@ var Zkp2pClient = class {
8613
8732
  const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
8614
8733
  return apiGetTakerTier(req, void 0, baseApiUrl, timeoutMs);
8615
8734
  }
8735
+ /**
8736
+ * The signed `expiresAtMs` field is an upload-time freshness token minted by attestation-service.
8737
+ * Once curator persists the bundle, seller-automated-release availability is governed by curator's
8738
+ * probe/revalidation state rather than this timestamp.
8739
+ *
8740
+ * Curator accepts either a configured API key or bearer token for this endpoint.
8741
+ *
8742
+ * Create a signed seller credential bundle with attestation-service and store it on the maker via curator.
8743
+ */
8744
+ async uploadSellerCredential(params, opts) {
8745
+ const baseApiUrl = this.stripTrailingSlash(
8746
+ opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL
8747
+ );
8748
+ const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
8749
+ const attestationServiceUrl = this.stripTrailingSlash(
8750
+ opts?.attestationServiceUrl ?? this.defaultAttestationServiceForBaseApiUrl(baseApiUrl)
8751
+ );
8752
+ const uploadPayload = {
8753
+ payeeId: params.payeeId,
8754
+ sessionMaterial: params.sessionMaterial
8755
+ };
8756
+ const bundleResponse = await apiCreateSellerCredentialBundle(
8757
+ uploadPayload,
8758
+ attestationServiceUrl,
8759
+ params.platform,
8760
+ timeoutMs
8761
+ );
8762
+ if (!bundleResponse.success || !bundleResponse.responseObject) {
8763
+ throw new Error(bundleResponse.message || "Failed to create seller credential bundle");
8764
+ }
8765
+ return apiUploadSellerCredential(
8766
+ params.makerId,
8767
+ bundleResponse.responseObject,
8768
+ baseApiUrl,
8769
+ timeoutMs,
8770
+ this.apiKey,
8771
+ this.authorizationToken
8772
+ );
8773
+ }
8774
+ /**
8775
+ * Status is a coarse curator-owned signal (`active` / `inactive` / `missing`) and intentionally
8776
+ * omits low-level diagnostics. Curator may still re-probe stale credentials during verify, so callers
8777
+ * should continue to handle a 410 from `verifySellerPayment`.
8778
+ *
8779
+ * Curator accepts either a configured API key or bearer token for this endpoint.
8780
+ *
8781
+ * Fetch seller credential status for a maker from curator.
8782
+ */
8783
+ async getSellerCredentialStatus(params, opts) {
8784
+ const baseApiUrl = this.stripTrailingSlash(
8785
+ opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL
8786
+ );
8787
+ const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
8788
+ return apiGetSellerCredentialStatus(
8789
+ params.makerId,
8790
+ baseApiUrl,
8791
+ timeoutMs,
8792
+ this.apiKey,
8793
+ this.authorizationToken
8794
+ );
8795
+ }
8796
+ /**
8797
+ * Internal-use endpoint. The curator route requires an internal `x-api-key`; standard SDK consumer
8798
+ * API keys will be rejected with 401. Returns 410 GONE when curator has marked the credential inactive
8799
+ * or a stale credential fails its synchronous re-probe.
8800
+ *
8801
+ * Verify a seller payment via curator's seller-credential proxy.
8802
+ */
8803
+ async verifySellerPayment(params, opts) {
8804
+ const baseApiUrl = this.stripTrailingSlash(
8805
+ opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL
8806
+ );
8807
+ const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
8808
+ return apiVerifySellerPayment(
8809
+ params.platform,
8810
+ {
8811
+ txId: params.txId,
8812
+ chainId: params.chainId,
8813
+ intent: params.intent
8814
+ },
8815
+ baseApiUrl,
8816
+ timeoutMs,
8817
+ this.apiKey,
8818
+ this.authorizationToken
8819
+ );
8820
+ }
8616
8821
  // ╔═══════════════════════════════════════════════════════════════════════════╗
8617
8822
  // ║ CORE: ON-CHAIN DEPOSIT VIEWS ║
8618
8823
  // ╚═══════════════════════════════════════════════════════════════════════════╝
@@ -9039,6 +9244,8 @@ exports.ZERO_RATE_MANAGER_ID = ZERO_RATE_MANAGER_ID;
9039
9244
  exports.ZKP2P_ANDROID_REFERRER = ZKP2P_ANDROID_REFERRER;
9040
9245
  exports.ZKP2P_IOS_REFERRER = ZKP2P_IOS_REFERRER;
9041
9246
  exports.Zkp2pClient = Zkp2pClient;
9247
+ exports.apiGetDepositBundle = apiGetDepositBundle;
9248
+ exports.apiGetOrderbook = apiGetOrderbook;
9042
9249
  exports.apiGetOwnerDeposits = apiGetOwnerDeposits;
9043
9250
  exports.apiGetPayeeDetails = apiGetPayeeDetails;
9044
9251
  exports.apiGetQuotesBestByPlatform = apiGetQuotesBestByPlatform;