@zkp2p/sdk 0.5.8 → 0.6.1

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.
@@ -1,10 +1,10 @@
1
1
  // src/takerTiers.ts
2
2
  var TAKER_TIER_SCHEDULE = [
3
- { tier: "PLATINUM", perIntentCapUsd: 5e3, minVolumeUsd: 25e3, maxVolumeUsd: Infinity },
4
- { tier: "PRO", perIntentCapUsd: 2500, minVolumeUsd: 1e4, maxVolumeUsd: 24999 },
5
- { tier: "PLUS", perIntentCapUsd: 1e3, minVolumeUsd: 2e3, maxVolumeUsd: 9999 },
6
- { tier: "PEER", perIntentCapUsd: 250, minVolumeUsd: 500, maxVolumeUsd: 1999 },
7
- { tier: "PEASANT", perIntentCapUsd: 100, minVolumeUsd: 0, maxVolumeUsd: 499 }
3
+ { tier: "PLATINUM", perIntentCapUsd: 5e3, minVolumeUsd: 1e5, maxVolumeUsd: Infinity },
4
+ { tier: "PRO", perIntentCapUsd: 2500, minVolumeUsd: 5e4, maxVolumeUsd: 99999 },
5
+ { tier: "PLUS", perIntentCapUsd: 1e3, minVolumeUsd: 1e4, maxVolumeUsd: 49999 },
6
+ { tier: "PEER", perIntentCapUsd: 250, minVolumeUsd: 1e3, maxVolumeUsd: 9999 },
7
+ { tier: "PEASANT", perIntentCapUsd: 100, minVolumeUsd: 0, maxVolumeUsd: 999 }
8
8
  ];
9
9
  var TAKER_TIER_ORDER = [
10
10
  "PEASANT",
@@ -16,6 +16,18 @@ var TAKER_TIER_ORDER = [
16
16
  var TAKER_TIER_CAPS = Object.fromEntries(
17
17
  TAKER_TIER_SCHEDULE.map((entry) => [entry.tier, entry.perIntentCapUsd])
18
18
  );
19
+ var TAKER_TIER_FEE_DISCOUNT_BPS = {
20
+ PEASANT: 0,
21
+ PEER: 5,
22
+ PLUS: 10,
23
+ PRO: 20,
24
+ PLATINUM: 30,
25
+ PEER_PRESIDENT: 30
26
+ };
27
+ function getTakerTierFeeDiscountBps(tier) {
28
+ if (!tier) return 0;
29
+ return TAKER_TIER_FEE_DISCOUNT_BPS[tier] ?? 0;
30
+ }
19
31
  function getNextTakerTier(currentTier) {
20
32
  if (!currentTier) return null;
21
33
  const index = TAKER_TIER_ORDER.indexOf(currentTier);
@@ -95,6 +107,6 @@ var prepareSetDelegationTx = async (client, params, referrer) => {
95
107
  });
96
108
  };
97
109
 
98
- export { TAKER_TIER_CAPS, TAKER_TIER_ORDER, TAKER_TIER_SCHEDULE, ZERO_ADDRESS, ZERO_RATE_MANAGER_ID, asErrorMessage, assertAtomicDelegationSwitchSupport, assertDelegationMethodSupport, classifyDelegationState, getDelegationRoute, getNextTakerTier, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry, prepareClearDelegationTx, prepareSetDelegationTx };
99
- //# sourceMappingURL=chunk-TGMRXUP2.mjs.map
100
- //# sourceMappingURL=chunk-TGMRXUP2.mjs.map
110
+ export { TAKER_TIER_CAPS, TAKER_TIER_FEE_DISCOUNT_BPS, TAKER_TIER_ORDER, TAKER_TIER_SCHEDULE, ZERO_ADDRESS, ZERO_RATE_MANAGER_ID, asErrorMessage, assertAtomicDelegationSwitchSupport, assertDelegationMethodSupport, classifyDelegationState, getDelegationRoute, getNextTakerTier, getTakerTierFeeDiscountBps, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry, prepareClearDelegationTx, prepareSetDelegationTx };
111
+ //# sourceMappingURL=chunk-6WAMIVRB.mjs.map
112
+ //# sourceMappingURL=chunk-6WAMIVRB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/takerTiers.ts","../src/react/hooks/vaultUtils.ts"],"names":[],"mappings":";AA2CO,IAAM,mBAAA,GAAyD;AAAA,EACpE,EAAE,MAAM,UAAA,EAAY,eAAA,EAAiB,KAAM,YAAA,EAAc,GAAA,EAAQ,cAAc,QAAA,EAAS;AAAA,EACxF,EAAE,MAAM,KAAA,EAAO,eAAA,EAAiB,MAAM,YAAA,EAAc,GAAA,EAA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,MAAA,CAAO,MAAA;AAAA,IACtB,WAAW,MAAA,CAAO,SAAA;AAAA,IAClB,GAAI,WAAW,EAAE,WAAA,EAAa,EAAE,QAAA,EAAS,KAAM;AAAC,GACjD,CAAA;AACH;AAEO,IAAM,sBAAA,GAAyB,OAEpC,MAAA,EACA,MAAA,EAMA,QAAA,KACiC;AACjC,EAAA,MAAM,KAAA,GAAQ,kBAAA,CAAmB,MAAA,EAAQ,MAAA,CAAO,MAAM,CAAA;AACtD,EAAA,6BAAA,CAA8B,MAAA,EAAQ,OAAO,KAAK,CAAA;AAClD,EAAA,OAAO,MAAA,CAAO,eAAe,OAAA,CAAQ;AAAA,IACnC,eAAe,MAAA,CAAO,MAAA;AAAA,IACtB,WAAW,MAAA,CAAO,SAAA;AAAA,IAClB,oBAAoB,MAAA,CAAO,QAAA;AAAA,IAC3B,eAAe,MAAA,CAAO,aAAA;AAAA,IACtB,GAAI,WAAW,EAAE,WAAA,EAAa,EAAE,QAAA,EAAS,KAAM;AAAC,GACjD,CAAA;AACH","file":"chunk-6WAMIVRB.mjs","sourcesContent":["import type { TakerTierLevel } from './types';\n\n/**\n * Canonical taker tier schedule — the single client-side source of truth for\n * per-intent caps and volume thresholds. Mirrors the curator's authoritative\n * tier engine (curator `src/common/services/tier/tierConstants.ts`), which is\n * what the backend actually enforces.\n *\n * The signal is now **lifetime Peer-Pay-consumed maker volume**, not raw taker\n * fulfilled volume (curator PR #463 removed SAR weighting).\n *\n * A user's *live* tier, cap, and progression always come from the taker-tier\n * API payload (`TakerTier.perIntentCapBaseUnits`, `minVolumeForTier`,\n * `volumeToNextTier`, `peerPayVolume`). Those values are DB-backed and\n * server-authoritative — they vary per environment (e.g. preprod runs\n * different thresholds than these). This static schedule is ONLY a\n * documented-default reference for displays that must show every tier at once\n * (the Fees & Tiers ladder) when no live payload is available; never gate or\n * compute a user's real cap from it.\n *\n * Volume bands track the live (pre-prod) tuned qualification thresholds, which\n * were re-anchored to the real maker distribution — PEER $1k, PLUS $10k,\n * PRO $50k, PLATINUM $100k (the earlier $2.5k/$20k/$75k/$300k placeholders left\n * PLATINUM literally unreachable; the top band sits in the $99k–$167k gap so the\n * same 3 whales qualify, on a round number). Caps ($100/$250/$1k/$2.5k/$5k) are\n * unchanged.\n * Production still runs the old placeholder bands until the tuned config is\n * promoted, so even this reference can disagree with a given environment — read\n * the live per-user values from the API.\n *\n * Ordered highest tier → lowest (PLATINUM first) to match UI display order.\n * PEER_PRESIDENT is invite-only and excluded from the volume ladder.\n */\nexport interface TakerTierScheduleEntry {\n tier: TakerTierLevel;\n /** Per-intent order cap in whole USD (base, before platform risk multipliers). */\n perIntentCapUsd: number;\n /** Inclusive lower bound of lifetime Peer-Pay volume (USD) that qualifies for this tier. */\n minVolumeUsd: number;\n /** Inclusive upper bound of lifetime Peer-Pay volume (USD); `Infinity` for the top tier. */\n maxVolumeUsd: number;\n}\n\nexport const TAKER_TIER_SCHEDULE: readonly TakerTierScheduleEntry[] = [\n { tier: 'PLATINUM', perIntentCapUsd: 5000, minVolumeUsd: 100000, maxVolumeUsd: Infinity },\n { tier: 'PRO', perIntentCapUsd: 2500, minVolumeUsd: 50000, maxVolumeUsd: 99999 },\n { tier: 'PLUS', perIntentCapUsd: 1000, minVolumeUsd: 10000, maxVolumeUsd: 49999 },\n { tier: 'PEER', perIntentCapUsd: 250, minVolumeUsd: 1000, maxVolumeUsd: 9999 },\n { tier: 'PEASANT', perIntentCapUsd: 100, minVolumeUsd: 0, maxVolumeUsd: 999 },\n];\n\n/** Volume-based tier order, lowest → highest, for next-tier progression. */\nexport const TAKER_TIER_ORDER: readonly TakerTierLevel[] = [\n 'PEASANT',\n 'PEER',\n 'PLUS',\n 'PRO',\n 'PLATINUM',\n];\n\n/** Per-intent caps (whole USD) keyed by tier, derived from the schedule. */\nexport const TAKER_TIER_CAPS: Readonly<Record<string, number>> = Object.fromEntries(\n TAKER_TIER_SCHEDULE.map((entry) => [entry.tier, entry.perIntentCapUsd]),\n);\n\n/**\n * Default take-fee discount (in basis points) applied per tier, mirroring\n * curator `TIER_FEE_DISCOUNT_BPS`. The discount is subtracted from the base\n * service fee server-side at quote and sign time — it is NOT returned by the\n * tier endpoint. These are documented defaults for reference fee displays only;\n * the curator DB control-plane can override them, so prefer the fee shown on a\n * live quote when one is available.\n */\nexport const TAKER_TIER_FEE_DISCOUNT_BPS: Readonly<Record<TakerTierLevel, number>> = {\n PEASANT: 0,\n PEER: 5,\n PLUS: 10,\n PRO: 20,\n PLATINUM: 30,\n PEER_PRESIDENT: 30,\n};\n\n/** The default fee-discount (bps) for a tier, or 0 for unknown tiers. */\nexport function getTakerTierFeeDiscountBps(tier: string | undefined): number {\n if (!tier) return 0;\n return TAKER_TIER_FEE_DISCOUNT_BPS[tier as TakerTierLevel] ?? 0;\n}\n\n/** The next tier up from `currentTier`, or `null` at the top / for unknown tiers. */\nexport function getNextTakerTier(currentTier: string | undefined): TakerTierLevel | null {\n if (!currentTier) return null;\n const index = TAKER_TIER_ORDER.indexOf(currentTier as TakerTierLevel);\n if (index === -1 || index >= TAKER_TIER_ORDER.length - 1) return null;\n return TAKER_TIER_ORDER[index + 1];\n}\n","import type { Address, Hex } from 'viem';\nimport type { PreparedTransaction } from '../../types/prepared';\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nexport const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' as const;\nexport const ZERO_RATE_MANAGER_ID =\n '0x0000000000000000000000000000000000000000000000000000000000000000' as const;\n\n// ---------------------------------------------------------------------------\n// Normalizers\n// ---------------------------------------------------------------------------\n\nexport const normalizeRateManagerId = (value?: string | null): string =>\n (value ?? ZERO_RATE_MANAGER_ID).toLowerCase();\n\nexport const normalizeRegistry = (value?: string | null): string =>\n (value ?? ZERO_ADDRESS).toLowerCase();\n\nexport const isZeroRateManagerId = (value?: string | null): boolean => {\n if (!value) return true;\n const normalized = value.toLowerCase();\n return normalized === ZERO_ADDRESS || normalized === ZERO_RATE_MANAGER_ID;\n};\n\n// ---------------------------------------------------------------------------\n// Error helper\n// ---------------------------------------------------------------------------\n\nexport const asErrorMessage = (error: unknown): string => {\n if (!error) return 'Unknown error';\n if (error instanceof Error) return error.message;\n if (typeof error === 'string') return error;\n\n const anyErr = error as Record<string, unknown>;\n if (typeof anyErr.shortMessage === 'string') return anyErr.shortMessage;\n if (typeof anyErr.details === 'string') return anyErr.details;\n if (typeof anyErr.message === 'string') return anyErr.message;\n\n try {\n return JSON.stringify(error);\n } catch {\n return String(error);\n }\n};\n\n// ---------------------------------------------------------------------------\n// Delegation state classification\n// ---------------------------------------------------------------------------\n\nexport type DelegationState = 'delegated_here' | 'delegated_elsewhere' | 'not_delegated';\n\n/**\n * Classify whether a deposit is delegated to the target vault, delegated\n * elsewhere, or not delegated at all.\n *\n * @param currentRateManagerId The deposit's current rateManagerId (from indexer)\n * @param currentRegistry The deposit's current rateManagerAddress / registry (from indexer)\n * @param targetRateManagerId The vault's rateManagerId we're comparing against\n * @param targetRegistry The vault's registry address we're comparing against\n */\nexport const classifyDelegationState = (\n currentRateManagerId: string | null | undefined,\n currentRegistry: string | null | undefined,\n targetRateManagerId: string,\n targetRegistry: string | null | undefined,\n): DelegationState => {\n if (isZeroRateManagerId(currentRateManagerId)) {\n return 'not_delegated';\n }\n\n const normalizedCurrent = normalizeRateManagerId(currentRateManagerId);\n const normalizedTarget = targetRateManagerId.toLowerCase();\n const normalizedCurrentRegistry = normalizeRegistry(currentRegistry);\n const normalizedTargetRegistry = targetRegistry ? targetRegistry.toLowerCase() : '';\n\n const idsMatch = normalizedCurrent === normalizedTarget;\n const registryMatches = normalizedTargetRegistry\n ? normalizedCurrentRegistry === normalizedTargetRegistry\n : true;\n\n if (idsMatch && registryMatches) {\n return 'delegated_here';\n }\n\n return 'delegated_elsewhere';\n};\n\nexport const assertAtomicDelegationSwitchSupport = (\n requiresSwitch: boolean,\n canBatch: boolean,\n): void => {\n if (!requiresSwitch || canBatch) return;\n throw new Error(\n 'Switching delegation targets requires smart-account batching. Clear the existing delegation first.',\n );\n};\n\n// ---------------------------------------------------------------------------\n// Contract routing\n// ---------------------------------------------------------------------------\n\nexport type DelegationRoute = 'v2';\n\nexport const getDelegationRoute = (_client: unknown, _escrow: Address): DelegationRoute => 'v2';\n\ntype DelegationMethodSupportClient = Partial<\n Record<'setRateManager' | 'clearRateManager', { prepare?: unknown }>\n>;\n\nexport const assertDelegationMethodSupport = (\n client: DelegationMethodSupportClient,\n _route: DelegationRoute,\n action: 'set' | 'clear',\n): void => {\n const method = action === 'set' ? 'setRateManager' : 'clearRateManager';\n if (client?.[method]?.prepare) return;\n throw new Error(`Delegation requires SDK ${method} support`);\n};\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface DelegationDepositTarget {\n compositeDepositId: string;\n escrow: Address;\n depositId: bigint;\n currentRateManagerId?: string | null;\n currentRateManagerRegistry?: string | null;\n}\n\nexport interface BatchResult {\n hashes: string[];\n failed: Array<{ compositeDepositId: string; error: string }>;\n}\n\n/**\n * Callback the consumer provides for sending a single prepared transaction.\n * Returns the transaction hash.\n */\nexport type SendTransactionFn = (tx: { to: Address; data: Hex; value?: bigint }) => Promise<string>;\n\n/**\n * Optional callback for batching multiple calls in a single user operation\n * (e.g. via a smart account). If not provided, transactions are sent\n * sequentially via sendTransaction.\n */\nexport type SendBatchFn = (\n txs: Array<{ to: Address; data: Hex; value?: bigint }>,\n) => Promise<string>;\n\n// ---------------------------------------------------------------------------\n// Prepare helpers (used internally by hooks)\n// ---------------------------------------------------------------------------\n\nexport const prepareClearDelegationTx = async (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n client: any,\n params: { escrow: Address; depositId: bigint },\n referrer?: string | string[],\n): Promise<PreparedTransaction> => {\n const route = getDelegationRoute(client, params.escrow);\n assertDelegationMethodSupport(client, route, 'clear');\n return client.clearRateManager.prepare({\n escrowAddress: params.escrow,\n depositId: params.depositId,\n ...(referrer ? { txOverrides: { referrer } } : {}),\n });\n};\n\nexport const prepareSetDelegationTx = async (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n client: any,\n params: {\n escrow: Address;\n depositId: bigint;\n registry: Address;\n rateManagerId: Hex;\n },\n referrer?: string | string[],\n): Promise<PreparedTransaction> => {\n const route = getDelegationRoute(client, params.escrow);\n assertDelegationMethodSupport(client, route, 'set');\n return client.setRateManager.prepare({\n escrowAddress: params.escrow,\n depositId: params.depositId,\n rateManagerAddress: params.registry,\n rateManagerId: params.rateManagerId,\n ...(referrer ? { txOverrides: { referrer } } : {}),\n });\n};\n"]}
package/dist/index.cjs CHANGED
@@ -42352,9 +42352,9 @@ async function apiSignIntentV3(request, opts) {
42352
42352
 
42353
42353
  // src/adapters/attestation.ts
42354
42354
  init_errors();
42355
- function headers() {
42356
- return { "Content-Type": "application/json" };
42357
- }
42355
+
42356
+ // src/adapters/attestationTransport.ts
42357
+ var DEFAULT_ATTESTATION_PROXY_URL = "https://attestation-service-proxy.up.railway.app";
42358
42358
  function normalizeOptionalString(value) {
42359
42359
  if (typeof value !== "string") {
42360
42360
  return null;
@@ -42362,13 +42362,92 @@ function normalizeOptionalString(value) {
42362
42362
  const normalized = value.trim();
42363
42363
  return normalized.length > 0 ? normalized : null;
42364
42364
  }
42365
- function normalizeBaseUrl(value, label) {
42365
+ function normalizeAttestationBaseUrl(value, label) {
42366
42366
  const normalized = normalizeOptionalString(value)?.replace(/\/+$/u, "");
42367
42367
  if (!normalized) {
42368
42368
  throw new Error(`${label} is required.`);
42369
42369
  }
42370
42370
  return normalized;
42371
42371
  }
42372
+ function resolveFallbackUrls(primaryBaseUrl, fallbackUrls) {
42373
+ const rawFallbackUrls = fallbackUrls == null ? [DEFAULT_ATTESTATION_PROXY_URL] : fallbackUrls;
42374
+ const normalized = rawFallbackUrls.map((url) => normalizeOptionalString(url)?.replace(/\/+$/u, "") ?? null).filter((url) => Boolean(url));
42375
+ return Array.from(new Set(normalized)).filter((url) => url !== primaryBaseUrl);
42376
+ }
42377
+ function resolveFetch(requestFetch) {
42378
+ if (requestFetch) {
42379
+ return requestFetch;
42380
+ }
42381
+ if (typeof globalThis.fetch !== "function") {
42382
+ throw new Error("fetch is not available in this runtime.");
42383
+ }
42384
+ return globalThis.fetch.bind(globalThis);
42385
+ }
42386
+ function inputUrl(input) {
42387
+ try {
42388
+ if (typeof input === "string" || input instanceof URL) {
42389
+ return new URL(input);
42390
+ }
42391
+ if (typeof Request !== "undefined" && input instanceof Request) {
42392
+ return new URL(input.url);
42393
+ }
42394
+ } catch {
42395
+ return null;
42396
+ }
42397
+ return null;
42398
+ }
42399
+ function rewriteInputBaseUrl(input, primaryBaseUrl, targetBaseUrl) {
42400
+ const url = inputUrl(input);
42401
+ if (!url) {
42402
+ return input;
42403
+ }
42404
+ const primaryUrl = new URL(primaryBaseUrl);
42405
+ const targetUrl = new URL(targetBaseUrl);
42406
+ if (url.origin === primaryUrl.origin) {
42407
+ url.protocol = targetUrl.protocol;
42408
+ url.host = targetUrl.host;
42409
+ }
42410
+ if (typeof Request !== "undefined" && input instanceof Request) {
42411
+ return new Request(url.toString(), input.clone());
42412
+ }
42413
+ return url.toString();
42414
+ }
42415
+ function createAttestationTransport(primaryBaseUrl, options = {}) {
42416
+ const requestFetch = resolveFetch(options.fetch);
42417
+ const fallbackUrls = resolveFallbackUrls(primaryBaseUrl, options.fallbackUrls);
42418
+ let activeBaseUrl = primaryBaseUrl;
42419
+ const transportFetch = async (input, init) => {
42420
+ const attemptInput = activeBaseUrl === primaryBaseUrl ? input : rewriteInputBaseUrl(input, primaryBaseUrl, activeBaseUrl);
42421
+ try {
42422
+ return await requestFetch(attemptInput, init);
42423
+ } catch (primaryError) {
42424
+ if (activeBaseUrl !== primaryBaseUrl || fallbackUrls.length === 0) {
42425
+ throw primaryError;
42426
+ }
42427
+ let fallbackError = primaryError;
42428
+ for (const fallbackUrl of fallbackUrls) {
42429
+ try {
42430
+ const fallbackInput = rewriteInputBaseUrl(input, primaryBaseUrl, fallbackUrl);
42431
+ const response = await requestFetch(fallbackInput, init);
42432
+ activeBaseUrl = fallbackUrl;
42433
+ return response;
42434
+ } catch (error) {
42435
+ fallbackError = error;
42436
+ }
42437
+ }
42438
+ throw fallbackError;
42439
+ }
42440
+ };
42441
+ return {
42442
+ fetch: transportFetch,
42443
+ getActiveBaseUrl: () => activeBaseUrl
42444
+ };
42445
+ }
42446
+
42447
+ // src/adapters/attestation.ts
42448
+ function headers() {
42449
+ return { "Content-Type": "application/json" };
42450
+ }
42372
42451
  function isPayeeBoundSellerCredentialUploadInput(payload) {
42373
42452
  return typeof payload.payeeId === "string";
42374
42453
  }
@@ -42377,7 +42456,8 @@ function isWiseCredentialUploadInput(payload) {
42377
42456
  }
42378
42457
  async function createEncryptedSellerCredentialUploadForPlatform({
42379
42458
  attestationServiceUrl,
42380
- attestationRuntime,
42459
+ attestationTransport,
42460
+ cryptoRuntime,
42381
42461
  payload,
42382
42462
  platform,
42383
42463
  timeoutMs
@@ -42391,9 +42471,9 @@ async function createEncryptedSellerCredentialUploadForPlatform({
42391
42471
  platform: "wise",
42392
42472
  sessionMaterial: payload.sessionMaterial,
42393
42473
  ...typeof timeoutMs === "number" ? { timeoutMs } : {},
42394
- ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
42395
- ...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
42396
- ...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
42474
+ fetch: attestationTransport.fetch,
42475
+ ...cryptoRuntime?.subtle ? { subtle: cryptoRuntime.subtle } : {},
42476
+ ...cryptoRuntime?.getRandomValues ? { getRandomValues: cryptoRuntime.getRandomValues } : {}
42397
42477
  });
42398
42478
  }
42399
42479
  if (!isPayeeBoundSellerCredentialUploadInput(payload)) {
@@ -42405,19 +42485,23 @@ async function createEncryptedSellerCredentialUploadForPlatform({
42405
42485
  payeeId: payload.payeeId,
42406
42486
  sessionMaterial: payload.sessionMaterial,
42407
42487
  ...typeof timeoutMs === "number" ? { timeoutMs } : {},
42408
- ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
42409
- ...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
42410
- ...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
42488
+ fetch: attestationTransport.fetch,
42489
+ ...cryptoRuntime?.subtle ? { subtle: cryptoRuntime.subtle } : {},
42490
+ ...cryptoRuntime?.getRandomValues ? { getRandomValues: cryptoRuntime.getRandomValues } : {}
42411
42491
  });
42412
42492
  }
42413
- async function apiVerifyBuyerTeePayment(payload, attestationServiceUrl, platform, actionType) {
42493
+ async function apiVerifyBuyerTeePayment(payload, attestationServiceUrl, platform, actionType, options = {}) {
42414
42494
  return withRetry(async () => {
42415
42495
  let res;
42416
42496
  try {
42417
42497
  const endpoint = `/buyer/verify/${encodeURIComponent(platform)}/${encodeURIComponent(
42418
42498
  actionType
42419
42499
  )}`;
42420
- res = await fetch(`${attestationServiceUrl}${endpoint}`, {
42500
+ const baseUrl = normalizeAttestationBaseUrl(attestationServiceUrl, "Attestation Service URL");
42501
+ const attestationTransport = createAttestationTransport(baseUrl, {
42502
+ fallbackUrls: options.fallbackUrls
42503
+ });
42504
+ res = await attestationTransport.fetch(`${baseUrl}${endpoint}`, {
42421
42505
  method: "POST",
42422
42506
  headers: headers(),
42423
42507
  body: JSON.stringify(payload)
@@ -42435,13 +42519,16 @@ async function apiVerifyBuyerTeePayment(payload, attestationServiceUrl, platform
42435
42519
  return res.json();
42436
42520
  });
42437
42521
  }
42438
- async function apiRequestIdentityAttestation(payload, attestationServiceUrl, platform, actionType) {
42522
+ async function apiRequestIdentityAttestation(payload, attestationServiceUrl, platform, actionType, options = {}) {
42439
42523
  return withRetry(async () => {
42440
42524
  let res;
42441
42525
  try {
42442
42526
  const endpoint = "/identity";
42443
- const baseUrl = normalizeBaseUrl(attestationServiceUrl, "Attestation Service URL");
42444
- res = await fetch(`${baseUrl}${endpoint}`, {
42527
+ const baseUrl = normalizeAttestationBaseUrl(attestationServiceUrl, "Attestation Service URL");
42528
+ const attestationTransport = createAttestationTransport(baseUrl, {
42529
+ fallbackUrls: options.fallbackUrls
42530
+ });
42531
+ res = await attestationTransport.fetch(`${baseUrl}${endpoint}`, {
42445
42532
  method: "POST",
42446
42533
  headers: headers(),
42447
42534
  body: JSON.stringify({
@@ -42467,31 +42554,51 @@ async function apiRequestIdentityAttestation(payload, attestationServiceUrl, pla
42467
42554
  }
42468
42555
  async function createEncryptedBuyerTeeSessionMaterial({
42469
42556
  actionType,
42557
+ attestationServiceFallbackUrls,
42470
42558
  attestationRuntime,
42471
42559
  attestationServiceUrl,
42472
42560
  platform,
42473
42561
  sessionMaterial,
42474
42562
  timeoutMs
42475
42563
  }) {
42564
+ const normalizedAttestationServiceUrl = normalizeAttestationBaseUrl(
42565
+ attestationServiceUrl,
42566
+ "Attestation Service URL"
42567
+ );
42568
+ const attestationTransport = createAttestationTransport(normalizedAttestationServiceUrl, {
42569
+ fallbackUrls: attestationServiceFallbackUrls,
42570
+ ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {}
42571
+ });
42476
42572
  const params = {
42477
42573
  actionType,
42478
- attestationServiceUrl: normalizeBaseUrl(attestationServiceUrl, "Attestation Service URL"),
42574
+ attestationServiceUrl: normalizedAttestationServiceUrl,
42479
42575
  platform,
42480
42576
  sessionMaterial,
42481
42577
  ...timeoutMs == null ? {} : { timeoutMs },
42482
- ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
42578
+ fetch: attestationTransport.fetch,
42483
42579
  ...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
42484
42580
  ...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
42485
42581
  };
42486
42582
  return zkp2pAttestation.createEncryptedBuyerTeeSessionMaterial(params);
42487
42583
  }
42488
- async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, platform, timeoutMs, attestationRuntime) {
42584
+ async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, platform, timeoutMs, attestationRuntime, options = {}) {
42489
42585
  return withRetry(
42490
42586
  async () => {
42491
- const requestFetch = attestationRuntime?.fetch ?? fetch;
42492
- const encryptedUpload = await createEncryptedSellerCredentialUploadForPlatform({
42587
+ const normalizedAttestationServiceUrl = normalizeAttestationBaseUrl(
42493
42588
  attestationServiceUrl,
42494
- attestationRuntime,
42589
+ "Attestation Service URL"
42590
+ );
42591
+ const attestationTransport = createAttestationTransport(normalizedAttestationServiceUrl, {
42592
+ fallbackUrls: options.fallbackUrls,
42593
+ ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {}
42594
+ });
42595
+ const encryptedUpload = await createEncryptedSellerCredentialUploadForPlatform({
42596
+ attestationServiceUrl: normalizedAttestationServiceUrl,
42597
+ attestationTransport,
42598
+ cryptoRuntime: {
42599
+ subtle: attestationRuntime?.subtle,
42600
+ getRandomValues: attestationRuntime?.getRandomValues
42601
+ },
42495
42602
  payload,
42496
42603
  platform,
42497
42604
  timeoutMs
@@ -42499,7 +42606,8 @@ async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, p
42499
42606
  let res;
42500
42607
  try {
42501
42608
  const endpoint = `/seller/credentials/${encodeURIComponent(platform)}`;
42502
- res = await requestFetch(`${attestationServiceUrl}${endpoint}`, {
42609
+ const activeBaseUrl = attestationTransport.getActiveBaseUrl();
42610
+ res = await attestationTransport.fetch(`${activeBaseUrl}${endpoint}`, {
42503
42611
  method: "POST",
42504
42612
  headers: headers(),
42505
42613
  body: JSON.stringify({ encryptedUpload })
@@ -43333,7 +43441,8 @@ var IntentOperations = class {
43333
43441
  },
43334
43442
  attestationServiceUrl,
43335
43443
  attestationRoute.actionPlatform,
43336
- attestationRoute.actionType
43444
+ attestationRoute.actionType,
43445
+ { fallbackUrls: params.attestationServiceFallbackUrls }
43337
43446
  );
43338
43447
  assertReleaseAmountMeetsMinimum(attestation, inputs.minimumReleaseAmount);
43339
43448
  paymentProof = encodePaymentAttestation(attestation);
@@ -50060,18 +50169,44 @@ var Zkp2pClient = class {
50060
50169
  const attestationServiceUrl = this.stripTrailingSlash(
50061
50170
  opts?.attestationServiceUrl ?? this.defaultAttestationServiceForBaseApiUrl(baseApiUrl)
50062
50171
  );
50063
- const createBundle = (uploadPayload) => opts?.attestationRuntime ? apiCreateSellerCredentialBundle(
50064
- uploadPayload,
50065
- attestationServiceUrl,
50066
- params.platform,
50067
- timeoutMs,
50068
- opts.attestationRuntime
50069
- ) : apiCreateSellerCredentialBundle(
50070
- uploadPayload,
50071
- attestationServiceUrl,
50072
- params.platform,
50073
- timeoutMs
50074
- );
50172
+ const createBundle = (uploadPayload) => {
50173
+ const requestOptions = opts?.attestationServiceFallbackUrls ? { fallbackUrls: opts.attestationServiceFallbackUrls } : void 0;
50174
+ if (opts?.attestationRuntime && requestOptions) {
50175
+ return apiCreateSellerCredentialBundle(
50176
+ uploadPayload,
50177
+ attestationServiceUrl,
50178
+ params.platform,
50179
+ timeoutMs,
50180
+ opts.attestationRuntime,
50181
+ requestOptions
50182
+ );
50183
+ }
50184
+ if (opts?.attestationRuntime) {
50185
+ return apiCreateSellerCredentialBundle(
50186
+ uploadPayload,
50187
+ attestationServiceUrl,
50188
+ params.platform,
50189
+ timeoutMs,
50190
+ opts.attestationRuntime
50191
+ );
50192
+ }
50193
+ if (requestOptions) {
50194
+ return apiCreateSellerCredentialBundle(
50195
+ uploadPayload,
50196
+ attestationServiceUrl,
50197
+ params.platform,
50198
+ timeoutMs,
50199
+ void 0,
50200
+ requestOptions
50201
+ );
50202
+ }
50203
+ return apiCreateSellerCredentialBundle(
50204
+ uploadPayload,
50205
+ attestationServiceUrl,
50206
+ params.platform,
50207
+ timeoutMs
50208
+ );
50209
+ };
50075
50210
  if (params.platform === "wise") {
50076
50211
  const bundleResponse2 = await createBundle({
50077
50212
  sessionMaterial: params.sessionMaterial
@@ -50142,6 +50277,21 @@ var Zkp2pClient = class {
50142
50277
  }
50143
50278
  );
50144
50279
  }
50280
+ if (params.platform === "zelle") {
50281
+ return apiUploadGoogleOAuthSellerCredential(
50282
+ "zelle",
50283
+ params.payeeDetails,
50284
+ {
50285
+ payeeId: params.payeeId,
50286
+ authorizationCode: params.authorizationCode,
50287
+ redirectUri: params.redirectUri
50288
+ },
50289
+ baseApiUrl,
50290
+ {
50291
+ timeoutMs
50292
+ }
50293
+ );
50294
+ }
50145
50295
  return apiUploadGoogleOAuthSellerCredential(
50146
50296
  "venmo",
50147
50297
  params.payeeDetails,
@@ -50396,11 +50546,11 @@ var peerExtensionSdk = createPeerExtensionSdk();
50396
50546
 
50397
50547
  // src/takerTiers.ts
50398
50548
  var TAKER_TIER_SCHEDULE = [
50399
- { tier: "PLATINUM", perIntentCapUsd: 5e3, minVolumeUsd: 25e3, maxVolumeUsd: Infinity },
50400
- { tier: "PRO", perIntentCapUsd: 2500, minVolumeUsd: 1e4, maxVolumeUsd: 24999 },
50401
- { tier: "PLUS", perIntentCapUsd: 1e3, minVolumeUsd: 2e3, maxVolumeUsd: 9999 },
50402
- { tier: "PEER", perIntentCapUsd: 250, minVolumeUsd: 500, maxVolumeUsd: 1999 },
50403
- { tier: "PEASANT", perIntentCapUsd: 100, minVolumeUsd: 0, maxVolumeUsd: 499 }
50549
+ { tier: "PLATINUM", perIntentCapUsd: 5e3, minVolumeUsd: 1e5, maxVolumeUsd: Infinity },
50550
+ { tier: "PRO", perIntentCapUsd: 2500, minVolumeUsd: 5e4, maxVolumeUsd: 99999 },
50551
+ { tier: "PLUS", perIntentCapUsd: 1e3, minVolumeUsd: 1e4, maxVolumeUsd: 49999 },
50552
+ { tier: "PEER", perIntentCapUsd: 250, minVolumeUsd: 1e3, maxVolumeUsd: 9999 },
50553
+ { tier: "PEASANT", perIntentCapUsd: 100, minVolumeUsd: 0, maxVolumeUsd: 999 }
50404
50554
  ];
50405
50555
  var TAKER_TIER_ORDER = [
50406
50556
  "PEASANT",
@@ -50412,6 +50562,18 @@ var TAKER_TIER_ORDER = [
50412
50562
  var TAKER_TIER_CAPS = Object.fromEntries(
50413
50563
  TAKER_TIER_SCHEDULE.map((entry) => [entry.tier, entry.perIntentCapUsd])
50414
50564
  );
50565
+ var TAKER_TIER_FEE_DISCOUNT_BPS = {
50566
+ PEASANT: 0,
50567
+ PEER: 5,
50568
+ PLUS: 10,
50569
+ PRO: 20,
50570
+ PLATINUM: 30,
50571
+ PEER_PRESIDENT: 30
50572
+ };
50573
+ function getTakerTierFeeDiscountBps(tier) {
50574
+ if (!tier) return 0;
50575
+ return TAKER_TIER_FEE_DISCOUNT_BPS[tier] ?? 0;
50576
+ }
50415
50577
  function getNextTakerTier(currentTier) {
50416
50578
  if (!currentTier) return null;
50417
50579
  const index = TAKER_TIER_ORDER.indexOf(currentTier);
@@ -50476,6 +50638,7 @@ exports.PYTH_ORACLE_FEEDS = PYTH_ORACLE_FEEDS;
50476
50638
  exports.SPREAD_ORACLE_FEEDS = SPREAD_ORACLE_FEEDS;
50477
50639
  exports.SUPPORTED_CHAIN_IDS = SUPPORTED_CHAIN_IDS;
50478
50640
  exports.TAKER_TIER_CAPS = TAKER_TIER_CAPS;
50641
+ exports.TAKER_TIER_FEE_DISCOUNT_BPS = TAKER_TIER_FEE_DISCOUNT_BPS;
50479
50642
  exports.TAKER_TIER_ORDER = TAKER_TIER_ORDER;
50480
50643
  exports.TAKER_TIER_SCHEDULE = TAKER_TIER_SCHEDULE;
50481
50644
  exports.TOKEN_METADATA = TOKEN_METADATA;
@@ -50526,6 +50689,7 @@ exports.getPaymentMethodsCatalog = getPaymentMethodsCatalog;
50526
50689
  exports.getPeerExtensionState = getPeerExtensionState;
50527
50690
  exports.getRateManagerContracts = getRateManagerContracts;
50528
50691
  exports.getSpreadOracleConfig = getSpreadOracleConfig;
50692
+ exports.getTakerTierFeeDiscountBps = getTakerTierFeeDiscountBps;
50529
50693
  exports.isPeerExtensionAvailable = isPeerExtensionAvailable;
50530
50694
  exports.isSupportedCurrencyHash = isSupportedCurrencyHash;
50531
50695
  exports.isValidReferrerFeeBps = isValidReferrerFeeBps;