@zkp2p/sdk 0.5.8 → 0.6.2

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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { TAKER_TIER_CAPS, TAKER_TIER_ORDER, TAKER_TIER_SCHEDULE, ZERO_RATE_MANAGER_ID, classifyDelegationState, getDelegationRoute, getNextTakerTier, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry } from './chunk-TGMRXUP2.mjs';
1
+ export { TAKER_TIER_CAPS, TAKER_TIER_FEE_DISCOUNT_BPS, TAKER_TIER_ORDER, TAKER_TIER_SCHEDULE, ZERO_RATE_MANAGER_ID, classifyDelegationState, getDelegationRoute, getNextTakerTier, getTakerTierFeeDiscountBps, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry } from './chunk-6WAMIVRB.mjs';
2
2
  import { APIError, NetworkError, ValidationError } from './chunk-GHQK65J2.mjs';
3
3
  export { APIError, ContractError, ErrorCode, NetworkError, ValidationError, ZKP2PError } from './chunk-GHQK65J2.mjs';
4
4
  import { getContracts, getRateManagerContracts, getPaymentMethodsCatalog, resolvePaymentMethodHashFromCatalog, getGatingServiceAddress, parseBigIntLike, resolveFiatCurrencyBytes32, resolvePaymentMethodNameFromHash } from './chunk-NMIFJSZ3.mjs';
@@ -406,9 +406,9 @@ async function apiSignIntentV3(request, opts) {
406
406
  referralFees
407
407
  };
408
408
  }
409
- function headers() {
410
- return { "Content-Type": "application/json" };
411
- }
409
+
410
+ // src/adapters/attestationTransport.ts
411
+ var DEFAULT_ATTESTATION_PROXY_URL = "https://attestation-service-proxy.up.railway.app";
412
412
  function normalizeOptionalString(value) {
413
413
  if (typeof value !== "string") {
414
414
  return null;
@@ -416,13 +416,92 @@ function normalizeOptionalString(value) {
416
416
  const normalized = value.trim();
417
417
  return normalized.length > 0 ? normalized : null;
418
418
  }
419
- function normalizeBaseUrl(value, label) {
419
+ function normalizeAttestationBaseUrl(value, label) {
420
420
  const normalized = normalizeOptionalString(value)?.replace(/\/+$/u, "");
421
421
  if (!normalized) {
422
422
  throw new Error(`${label} is required.`);
423
423
  }
424
424
  return normalized;
425
425
  }
426
+ function resolveFallbackUrls(primaryBaseUrl, fallbackUrls) {
427
+ const rawFallbackUrls = fallbackUrls == null ? [DEFAULT_ATTESTATION_PROXY_URL] : fallbackUrls;
428
+ const normalized = rawFallbackUrls.map((url) => normalizeOptionalString(url)?.replace(/\/+$/u, "") ?? null).filter((url) => Boolean(url));
429
+ return Array.from(new Set(normalized)).filter((url) => url !== primaryBaseUrl);
430
+ }
431
+ function resolveFetch(requestFetch) {
432
+ if (requestFetch) {
433
+ return requestFetch;
434
+ }
435
+ if (typeof globalThis.fetch !== "function") {
436
+ throw new Error("fetch is not available in this runtime.");
437
+ }
438
+ return globalThis.fetch.bind(globalThis);
439
+ }
440
+ function inputUrl(input) {
441
+ try {
442
+ if (typeof input === "string" || input instanceof URL) {
443
+ return new URL(input);
444
+ }
445
+ if (typeof Request !== "undefined" && input instanceof Request) {
446
+ return new URL(input.url);
447
+ }
448
+ } catch {
449
+ return null;
450
+ }
451
+ return null;
452
+ }
453
+ function rewriteInputBaseUrl(input, primaryBaseUrl, targetBaseUrl) {
454
+ const url = inputUrl(input);
455
+ if (!url) {
456
+ return input;
457
+ }
458
+ const primaryUrl = new URL(primaryBaseUrl);
459
+ const targetUrl = new URL(targetBaseUrl);
460
+ if (url.origin === primaryUrl.origin) {
461
+ url.protocol = targetUrl.protocol;
462
+ url.host = targetUrl.host;
463
+ }
464
+ if (typeof Request !== "undefined" && input instanceof Request) {
465
+ return new Request(url.toString(), input.clone());
466
+ }
467
+ return url.toString();
468
+ }
469
+ function createAttestationTransport(primaryBaseUrl, options = {}) {
470
+ const requestFetch = resolveFetch(options.fetch);
471
+ const fallbackUrls = resolveFallbackUrls(primaryBaseUrl, options.fallbackUrls);
472
+ let activeBaseUrl = primaryBaseUrl;
473
+ const transportFetch = async (input, init) => {
474
+ const attemptInput = activeBaseUrl === primaryBaseUrl ? input : rewriteInputBaseUrl(input, primaryBaseUrl, activeBaseUrl);
475
+ try {
476
+ return await requestFetch(attemptInput, init);
477
+ } catch (primaryError) {
478
+ if (activeBaseUrl !== primaryBaseUrl || fallbackUrls.length === 0) {
479
+ throw primaryError;
480
+ }
481
+ let fallbackError = primaryError;
482
+ for (const fallbackUrl of fallbackUrls) {
483
+ try {
484
+ const fallbackInput = rewriteInputBaseUrl(input, primaryBaseUrl, fallbackUrl);
485
+ const response = await requestFetch(fallbackInput, init);
486
+ activeBaseUrl = fallbackUrl;
487
+ return response;
488
+ } catch (error) {
489
+ fallbackError = error;
490
+ }
491
+ }
492
+ throw fallbackError;
493
+ }
494
+ };
495
+ return {
496
+ fetch: transportFetch,
497
+ getActiveBaseUrl: () => activeBaseUrl
498
+ };
499
+ }
500
+
501
+ // src/adapters/attestation.ts
502
+ function headers() {
503
+ return { "Content-Type": "application/json" };
504
+ }
426
505
  function isPayeeBoundSellerCredentialUploadInput(payload) {
427
506
  return typeof payload.payeeId === "string";
428
507
  }
@@ -431,7 +510,8 @@ function isWiseCredentialUploadInput(payload) {
431
510
  }
432
511
  async function createEncryptedSellerCredentialUploadForPlatform({
433
512
  attestationServiceUrl,
434
- attestationRuntime,
513
+ attestationTransport,
514
+ cryptoRuntime,
435
515
  payload,
436
516
  platform,
437
517
  timeoutMs
@@ -445,9 +525,9 @@ async function createEncryptedSellerCredentialUploadForPlatform({
445
525
  platform: "wise",
446
526
  sessionMaterial: payload.sessionMaterial,
447
527
  ...typeof timeoutMs === "number" ? { timeoutMs } : {},
448
- ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
449
- ...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
450
- ...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
528
+ fetch: attestationTransport.fetch,
529
+ ...cryptoRuntime?.subtle ? { subtle: cryptoRuntime.subtle } : {},
530
+ ...cryptoRuntime?.getRandomValues ? { getRandomValues: cryptoRuntime.getRandomValues } : {}
451
531
  });
452
532
  }
453
533
  if (!isPayeeBoundSellerCredentialUploadInput(payload)) {
@@ -459,19 +539,23 @@ async function createEncryptedSellerCredentialUploadForPlatform({
459
539
  payeeId: payload.payeeId,
460
540
  sessionMaterial: payload.sessionMaterial,
461
541
  ...typeof timeoutMs === "number" ? { timeoutMs } : {},
462
- ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
463
- ...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
464
- ...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
542
+ fetch: attestationTransport.fetch,
543
+ ...cryptoRuntime?.subtle ? { subtle: cryptoRuntime.subtle } : {},
544
+ ...cryptoRuntime?.getRandomValues ? { getRandomValues: cryptoRuntime.getRandomValues } : {}
465
545
  });
466
546
  }
467
- async function apiVerifyBuyerTeePayment(payload, attestationServiceUrl, platform, actionType) {
547
+ async function apiVerifyBuyerTeePayment(payload, attestationServiceUrl, platform, actionType, options = {}) {
468
548
  return withRetry(async () => {
469
549
  let res;
470
550
  try {
471
551
  const endpoint = `/buyer/verify/${encodeURIComponent(platform)}/${encodeURIComponent(
472
552
  actionType
473
553
  )}`;
474
- res = await fetch(`${attestationServiceUrl}${endpoint}`, {
554
+ const baseUrl = normalizeAttestationBaseUrl(attestationServiceUrl, "Attestation Service URL");
555
+ const attestationTransport = createAttestationTransport(baseUrl, {
556
+ fallbackUrls: options.fallbackUrls
557
+ });
558
+ res = await attestationTransport.fetch(`${baseUrl}${endpoint}`, {
475
559
  method: "POST",
476
560
  headers: headers(),
477
561
  body: JSON.stringify(payload)
@@ -489,13 +573,16 @@ async function apiVerifyBuyerTeePayment(payload, attestationServiceUrl, platform
489
573
  return res.json();
490
574
  });
491
575
  }
492
- async function apiRequestIdentityAttestation(payload, attestationServiceUrl, platform, actionType) {
576
+ async function apiRequestIdentityAttestation(payload, attestationServiceUrl, platform, actionType, options = {}) {
493
577
  return withRetry(async () => {
494
578
  let res;
495
579
  try {
496
580
  const endpoint = "/identity";
497
- const baseUrl = normalizeBaseUrl(attestationServiceUrl, "Attestation Service URL");
498
- res = await fetch(`${baseUrl}${endpoint}`, {
581
+ const baseUrl = normalizeAttestationBaseUrl(attestationServiceUrl, "Attestation Service URL");
582
+ const attestationTransport = createAttestationTransport(baseUrl, {
583
+ fallbackUrls: options.fallbackUrls
584
+ });
585
+ res = await attestationTransport.fetch(`${baseUrl}${endpoint}`, {
499
586
  method: "POST",
500
587
  headers: headers(),
501
588
  body: JSON.stringify({
@@ -521,31 +608,51 @@ async function apiRequestIdentityAttestation(payload, attestationServiceUrl, pla
521
608
  }
522
609
  async function createEncryptedBuyerTeeSessionMaterial({
523
610
  actionType,
611
+ attestationServiceFallbackUrls,
524
612
  attestationRuntime,
525
613
  attestationServiceUrl,
526
614
  platform,
527
615
  sessionMaterial,
528
616
  timeoutMs
529
617
  }) {
618
+ const normalizedAttestationServiceUrl = normalizeAttestationBaseUrl(
619
+ attestationServiceUrl,
620
+ "Attestation Service URL"
621
+ );
622
+ const attestationTransport = createAttestationTransport(normalizedAttestationServiceUrl, {
623
+ fallbackUrls: attestationServiceFallbackUrls,
624
+ ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {}
625
+ });
530
626
  const params = {
531
627
  actionType,
532
- attestationServiceUrl: normalizeBaseUrl(attestationServiceUrl, "Attestation Service URL"),
628
+ attestationServiceUrl: normalizedAttestationServiceUrl,
533
629
  platform,
534
630
  sessionMaterial,
535
631
  ...timeoutMs == null ? {} : { timeoutMs },
536
- ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
632
+ fetch: attestationTransport.fetch,
537
633
  ...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
538
634
  ...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
539
635
  };
540
636
  return createEncryptedBuyerTeeSessionMaterial$1(params);
541
637
  }
542
- async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, platform, timeoutMs, attestationRuntime) {
638
+ async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, platform, timeoutMs, attestationRuntime, options = {}) {
543
639
  return withRetry(
544
640
  async () => {
545
- const requestFetch = attestationRuntime?.fetch ?? fetch;
546
- const encryptedUpload = await createEncryptedSellerCredentialUploadForPlatform({
641
+ const normalizedAttestationServiceUrl = normalizeAttestationBaseUrl(
547
642
  attestationServiceUrl,
548
- attestationRuntime,
643
+ "Attestation Service URL"
644
+ );
645
+ const attestationTransport = createAttestationTransport(normalizedAttestationServiceUrl, {
646
+ fallbackUrls: options.fallbackUrls,
647
+ ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {}
648
+ });
649
+ const encryptedUpload = await createEncryptedSellerCredentialUploadForPlatform({
650
+ attestationServiceUrl: normalizedAttestationServiceUrl,
651
+ attestationTransport,
652
+ cryptoRuntime: {
653
+ subtle: attestationRuntime?.subtle,
654
+ getRandomValues: attestationRuntime?.getRandomValues
655
+ },
549
656
  payload,
550
657
  platform,
551
658
  timeoutMs
@@ -553,7 +660,8 @@ async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, p
553
660
  let res;
554
661
  try {
555
662
  const endpoint = `/seller/credentials/${encodeURIComponent(platform)}`;
556
- res = await requestFetch(`${attestationServiceUrl}${endpoint}`, {
663
+ const activeBaseUrl = attestationTransport.getActiveBaseUrl();
664
+ res = await attestationTransport.fetch(`${activeBaseUrl}${endpoint}`, {
557
665
  method: "POST",
558
666
  headers: headers(),
559
667
  body: JSON.stringify({ encryptedUpload })
@@ -1377,7 +1485,8 @@ var IntentOperations = class {
1377
1485
  },
1378
1486
  attestationServiceUrl,
1379
1487
  attestationRoute.actionPlatform,
1380
- attestationRoute.actionType
1488
+ attestationRoute.actionType,
1489
+ { fallbackUrls: params.attestationServiceFallbackUrls }
1381
1490
  );
1382
1491
  assertReleaseAmountMeetsMinimum(attestation, inputs.minimumReleaseAmount);
1383
1492
  paymentProof = encodePaymentAttestation(attestation);
@@ -8090,18 +8199,44 @@ var Zkp2pClient = class {
8090
8199
  const attestationServiceUrl = this.stripTrailingSlash(
8091
8200
  opts?.attestationServiceUrl ?? this.defaultAttestationServiceForBaseApiUrl(baseApiUrl)
8092
8201
  );
8093
- const createBundle = (uploadPayload) => opts?.attestationRuntime ? apiCreateSellerCredentialBundle(
8094
- uploadPayload,
8095
- attestationServiceUrl,
8096
- params.platform,
8097
- timeoutMs,
8098
- opts.attestationRuntime
8099
- ) : apiCreateSellerCredentialBundle(
8100
- uploadPayload,
8101
- attestationServiceUrl,
8102
- params.platform,
8103
- timeoutMs
8104
- );
8202
+ const createBundle = (uploadPayload) => {
8203
+ const requestOptions = opts?.attestationServiceFallbackUrls ? { fallbackUrls: opts.attestationServiceFallbackUrls } : void 0;
8204
+ if (opts?.attestationRuntime && requestOptions) {
8205
+ return apiCreateSellerCredentialBundle(
8206
+ uploadPayload,
8207
+ attestationServiceUrl,
8208
+ params.platform,
8209
+ timeoutMs,
8210
+ opts.attestationRuntime,
8211
+ requestOptions
8212
+ );
8213
+ }
8214
+ if (opts?.attestationRuntime) {
8215
+ return apiCreateSellerCredentialBundle(
8216
+ uploadPayload,
8217
+ attestationServiceUrl,
8218
+ params.platform,
8219
+ timeoutMs,
8220
+ opts.attestationRuntime
8221
+ );
8222
+ }
8223
+ if (requestOptions) {
8224
+ return apiCreateSellerCredentialBundle(
8225
+ uploadPayload,
8226
+ attestationServiceUrl,
8227
+ params.platform,
8228
+ timeoutMs,
8229
+ void 0,
8230
+ requestOptions
8231
+ );
8232
+ }
8233
+ return apiCreateSellerCredentialBundle(
8234
+ uploadPayload,
8235
+ attestationServiceUrl,
8236
+ params.platform,
8237
+ timeoutMs
8238
+ );
8239
+ };
8105
8240
  if (params.platform === "wise") {
8106
8241
  const bundleResponse2 = await createBundle({
8107
8242
  sessionMaterial: params.sessionMaterial
@@ -8172,6 +8307,21 @@ var Zkp2pClient = class {
8172
8307
  }
8173
8308
  );
8174
8309
  }
8310
+ if (params.platform === "zelle") {
8311
+ return apiUploadGoogleOAuthSellerCredential(
8312
+ "zelle",
8313
+ params.payeeDetails,
8314
+ {
8315
+ payeeId: params.payeeId,
8316
+ authorizationCode: params.authorizationCode,
8317
+ redirectUri: params.redirectUri
8318
+ },
8319
+ baseApiUrl,
8320
+ {
8321
+ timeoutMs
8322
+ }
8323
+ );
8324
+ }
8175
8325
  return apiUploadGoogleOAuthSellerCredential(
8176
8326
  "venmo",
8177
8327
  params.payeeDetails,
@@ -8424,6 +8574,6 @@ var createPeerExtensionSdk = (options = {}) => ({
8424
8574
  });
8425
8575
  var peerExtensionSdk = createPeerExtensionSdk();
8426
8576
 
8427
- export { BASE_BUILDER_CODE, CHAINLINK_ORACLE_ADAPTER, CHAINLINK_ORACLE_FEEDS, ContractRouter, DEFAULT_ORACLE_MAX_STALENESS_SECONDS, IndexerClient, IndexerDepositService, IndexerRateManagerService, Zkp2pClient as OfframpClient, PAYMENT_PLATFORMS, PEER_EXTENSION_CHROME_URL, PLATFORM_METADATA, PYTH_CONTRACT_BASE, PYTH_ORACLE_ADAPTER, PYTH_ORACLE_FEEDS, SPREAD_ORACLE_FEEDS, SUPPORTED_CHAIN_IDS, TOKEN_METADATA, ZKP2P_ANDROID_REFERRER, ZKP2P_IOS_REFERRER, Zkp2pClient, apiCreateSellerCredentialBundle, apiGetDepositBundle, apiGetOrderbook, apiGetOwnerDeposits, apiGetPayeeDetails, apiGetQuotesBestByPlatform, apiGetTakerTier, apiPostDepositDetails, apiRequestIdentityAttestation, apiUploadGoogleOAuthSellerCredential, apiUploadSellerCredentialBundle, apiValidatePayeeDetails, appendAttributionToCalldata, assertValidReferrerFeeConfig, compareEventCursorIdsByRecency, convertDepositsForLiquidity, convertIndexerDepositToEscrowView, convertIndexerIntentsToEscrowViews, createCompositeDepositId, createEncryptedBuyerTeeSessionMaterial, createPeerExtensionSdk, defaultIndexerEndpoint, encodePythAdapterConfig, encodeSpreadOracleAdapterConfig, encodeWithAttribution, fetchFulfillmentAndPayment as fetchIndexerFulfillmentAndPayment, getAttributionDataSuffix, getPeerExtensionState, getSpreadOracleConfig, isPeerExtensionAvailable, isValidReferrerFeeBps, isValidReferrerFeeRecipient, logger, openPeerExtensionInstallPage, parseReferrerFeeConfig, peerExtensionSdk, referrerFeeConfigToPreciseUnits, sendTransactionWithAttribution, setLogLevel, validateOracleFeedsOnChain };
8577
+ export { BASE_BUILDER_CODE, CHAINLINK_ORACLE_ADAPTER, CHAINLINK_ORACLE_FEEDS, ContractRouter, DEFAULT_ORACLE_MAX_STALENESS_SECONDS, IndexerClient, IndexerDepositService, IndexerRateManagerService, Zkp2pClient as OfframpClient, PAYMENT_PLATFORMS, PEER_EXTENSION_CHROME_URL, PLATFORM_METADATA, PYTH_CONTRACT_BASE, PYTH_ORACLE_ADAPTER, PYTH_ORACLE_FEEDS, SPREAD_ORACLE_FEEDS, SUPPORTED_CHAIN_IDS, TOKEN_METADATA, ZKP2P_ANDROID_REFERRER, ZKP2P_IOS_REFERRER, Zkp2pClient, apiCreateSellerCredentialBundle, apiGetDepositBundle, apiGetOrderbook, apiGetOwnerDeposits, apiGetPayeeDetails, apiGetQuotesBestByPlatform, apiGetTakerTier, apiPostDepositDetails, apiRequestIdentityAttestation, apiUploadGoogleOAuthSellerCredential, apiUploadSellerCredentialBundle, apiValidatePayeeDetails, apiVerifyBuyerTeePayment, appendAttributionToCalldata, assertValidReferrerFeeConfig, compareEventCursorIdsByRecency, convertDepositsForLiquidity, convertIndexerDepositToEscrowView, convertIndexerIntentsToEscrowViews, createCompositeDepositId, createEncryptedBuyerTeeSessionMaterial, createPeerExtensionSdk, defaultIndexerEndpoint, encodePythAdapterConfig, encodeSpreadOracleAdapterConfig, encodeWithAttribution, fetchFulfillmentAndPayment as fetchIndexerFulfillmentAndPayment, getAttributionDataSuffix, getPeerExtensionState, getSpreadOracleConfig, isPeerExtensionAvailable, isValidReferrerFeeBps, isValidReferrerFeeRecipient, logger, openPeerExtensionInstallPage, parseReferrerFeeConfig, peerExtensionSdk, referrerFeeConfigToPreciseUnits, sendTransactionWithAttribution, setLogLevel, validateOracleFeedsOnChain };
8428
8578
  //# sourceMappingURL=index.mjs.map
8429
8579
  //# sourceMappingURL=index.mjs.map