@zkp2p/sdk 0.5.7 → 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
@@ -42314,9 +42314,11 @@ async function apiSignIntentV3(request, opts) {
42314
42314
  async () => {
42315
42315
  let res;
42316
42316
  try {
42317
+ const headers2 = { "Content-Type": "application/json" };
42318
+ if (opts.apiKey) headers2["x-api-key"] = opts.apiKey;
42317
42319
  res = await fetch(url, {
42318
42320
  method: "POST",
42319
- headers: { "Content-Type": "application/json" },
42321
+ headers: headers2,
42320
42322
  body: JSON.stringify(request)
42321
42323
  });
42322
42324
  } catch (error) {
@@ -42350,9 +42352,9 @@ async function apiSignIntentV3(request, opts) {
42350
42352
 
42351
42353
  // src/adapters/attestation.ts
42352
42354
  init_errors();
42353
- function headers() {
42354
- return { "Content-Type": "application/json" };
42355
- }
42355
+
42356
+ // src/adapters/attestationTransport.ts
42357
+ var DEFAULT_ATTESTATION_PROXY_URL = "https://attestation-service-proxy.up.railway.app";
42356
42358
  function normalizeOptionalString(value) {
42357
42359
  if (typeof value !== "string") {
42358
42360
  return null;
@@ -42360,13 +42362,92 @@ function normalizeOptionalString(value) {
42360
42362
  const normalized = value.trim();
42361
42363
  return normalized.length > 0 ? normalized : null;
42362
42364
  }
42363
- function normalizeBaseUrl(value, label) {
42365
+ function normalizeAttestationBaseUrl(value, label) {
42364
42366
  const normalized = normalizeOptionalString(value)?.replace(/\/+$/u, "");
42365
42367
  if (!normalized) {
42366
42368
  throw new Error(`${label} is required.`);
42367
42369
  }
42368
42370
  return normalized;
42369
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
+ }
42370
42451
  function isPayeeBoundSellerCredentialUploadInput(payload) {
42371
42452
  return typeof payload.payeeId === "string";
42372
42453
  }
@@ -42375,7 +42456,8 @@ function isWiseCredentialUploadInput(payload) {
42375
42456
  }
42376
42457
  async function createEncryptedSellerCredentialUploadForPlatform({
42377
42458
  attestationServiceUrl,
42378
- attestationRuntime,
42459
+ attestationTransport,
42460
+ cryptoRuntime,
42379
42461
  payload,
42380
42462
  platform,
42381
42463
  timeoutMs
@@ -42389,9 +42471,9 @@ async function createEncryptedSellerCredentialUploadForPlatform({
42389
42471
  platform: "wise",
42390
42472
  sessionMaterial: payload.sessionMaterial,
42391
42473
  ...typeof timeoutMs === "number" ? { timeoutMs } : {},
42392
- ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
42393
- ...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
42394
- ...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
42474
+ fetch: attestationTransport.fetch,
42475
+ ...cryptoRuntime?.subtle ? { subtle: cryptoRuntime.subtle } : {},
42476
+ ...cryptoRuntime?.getRandomValues ? { getRandomValues: cryptoRuntime.getRandomValues } : {}
42395
42477
  });
42396
42478
  }
42397
42479
  if (!isPayeeBoundSellerCredentialUploadInput(payload)) {
@@ -42403,19 +42485,23 @@ async function createEncryptedSellerCredentialUploadForPlatform({
42403
42485
  payeeId: payload.payeeId,
42404
42486
  sessionMaterial: payload.sessionMaterial,
42405
42487
  ...typeof timeoutMs === "number" ? { timeoutMs } : {},
42406
- ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
42407
- ...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
42408
- ...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
42488
+ fetch: attestationTransport.fetch,
42489
+ ...cryptoRuntime?.subtle ? { subtle: cryptoRuntime.subtle } : {},
42490
+ ...cryptoRuntime?.getRandomValues ? { getRandomValues: cryptoRuntime.getRandomValues } : {}
42409
42491
  });
42410
42492
  }
42411
- async function apiVerifyBuyerTeePayment(payload, attestationServiceUrl, platform, actionType) {
42493
+ async function apiVerifyBuyerTeePayment(payload, attestationServiceUrl, platform, actionType, options = {}) {
42412
42494
  return withRetry(async () => {
42413
42495
  let res;
42414
42496
  try {
42415
42497
  const endpoint = `/buyer/verify/${encodeURIComponent(platform)}/${encodeURIComponent(
42416
42498
  actionType
42417
42499
  )}`;
42418
- 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}`, {
42419
42505
  method: "POST",
42420
42506
  headers: headers(),
42421
42507
  body: JSON.stringify(payload)
@@ -42433,13 +42519,16 @@ async function apiVerifyBuyerTeePayment(payload, attestationServiceUrl, platform
42433
42519
  return res.json();
42434
42520
  });
42435
42521
  }
42436
- async function apiRequestIdentityAttestation(payload, attestationServiceUrl, platform, actionType) {
42522
+ async function apiRequestIdentityAttestation(payload, attestationServiceUrl, platform, actionType, options = {}) {
42437
42523
  return withRetry(async () => {
42438
42524
  let res;
42439
42525
  try {
42440
42526
  const endpoint = "/identity";
42441
- const baseUrl = normalizeBaseUrl(attestationServiceUrl, "Attestation Service URL");
42442
- 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}`, {
42443
42532
  method: "POST",
42444
42533
  headers: headers(),
42445
42534
  body: JSON.stringify({
@@ -42465,31 +42554,51 @@ async function apiRequestIdentityAttestation(payload, attestationServiceUrl, pla
42465
42554
  }
42466
42555
  async function createEncryptedBuyerTeeSessionMaterial({
42467
42556
  actionType,
42557
+ attestationServiceFallbackUrls,
42468
42558
  attestationRuntime,
42469
42559
  attestationServiceUrl,
42470
42560
  platform,
42471
42561
  sessionMaterial,
42472
42562
  timeoutMs
42473
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
+ });
42474
42572
  const params = {
42475
42573
  actionType,
42476
- attestationServiceUrl: normalizeBaseUrl(attestationServiceUrl, "Attestation Service URL"),
42574
+ attestationServiceUrl: normalizedAttestationServiceUrl,
42477
42575
  platform,
42478
42576
  sessionMaterial,
42479
42577
  ...timeoutMs == null ? {} : { timeoutMs },
42480
- ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
42578
+ fetch: attestationTransport.fetch,
42481
42579
  ...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
42482
42580
  ...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
42483
42581
  };
42484
42582
  return zkp2pAttestation.createEncryptedBuyerTeeSessionMaterial(params);
42485
42583
  }
42486
- async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, platform, timeoutMs, attestationRuntime) {
42584
+ async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, platform, timeoutMs, attestationRuntime, options = {}) {
42487
42585
  return withRetry(
42488
42586
  async () => {
42489
- const requestFetch = attestationRuntime?.fetch ?? fetch;
42490
- const encryptedUpload = await createEncryptedSellerCredentialUploadForPlatform({
42587
+ const normalizedAttestationServiceUrl = normalizeAttestationBaseUrl(
42491
42588
  attestationServiceUrl,
42492
- 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
+ },
42493
42602
  payload,
42494
42603
  platform,
42495
42604
  timeoutMs
@@ -42497,7 +42606,8 @@ async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, p
42497
42606
  let res;
42498
42607
  try {
42499
42608
  const endpoint = `/seller/credentials/${encodeURIComponent(platform)}`;
42500
- res = await requestFetch(`${attestationServiceUrl}${endpoint}`, {
42609
+ const activeBaseUrl = attestationTransport.getActiveBaseUrl();
42610
+ res = await attestationTransport.fetch(`${activeBaseUrl}${endpoint}`, {
42501
42611
  method: "POST",
42502
42612
  headers: headers(),
42503
42613
  body: JSON.stringify({ encryptedUpload })
@@ -43061,6 +43171,7 @@ var IntentOperations = class {
43061
43171
  if ((!gatingServiceSignature || !signatureExpiration) && baseApiUrl) {
43062
43172
  const apiOpts = {
43063
43173
  baseApiUrl,
43174
+ apiKey: this.config.getApiKey(),
43064
43175
  timeoutMs: this.config.getApiTimeoutMs()
43065
43176
  };
43066
43177
  const response = await apiSignIntentV3(
@@ -43330,7 +43441,8 @@ var IntentOperations = class {
43330
43441
  },
43331
43442
  attestationServiceUrl,
43332
43443
  attestationRoute.actionPlatform,
43333
- attestationRoute.actionType
43444
+ attestationRoute.actionType,
43445
+ { fallbackUrls: params.attestationServiceFallbackUrls }
43334
43446
  );
43335
43447
  assertReleaseAmountMeetsMinimum(attestation, inputs.minimumReleaseAmount);
43336
43448
  paymentProof = encodePaymentAttestation(attestation);
@@ -48699,6 +48811,7 @@ var Zkp2pClient = class {
48699
48811
  getChainId: () => this.chainId,
48700
48812
  getRuntimeEnv: () => this.runtimeEnv,
48701
48813
  getBaseApiUrl: () => this.baseApiUrl,
48814
+ getApiKey: () => this.apiKey,
48702
48815
  getApiTimeoutMs: () => this.apiTimeoutMs,
48703
48816
  getProtocolViewerAddress: () => this.protocolViewerAddress,
48704
48817
  getProtocolViewerAbi: () => this.protocolViewerAbi,
@@ -50056,18 +50169,44 @@ var Zkp2pClient = class {
50056
50169
  const attestationServiceUrl = this.stripTrailingSlash(
50057
50170
  opts?.attestationServiceUrl ?? this.defaultAttestationServiceForBaseApiUrl(baseApiUrl)
50058
50171
  );
50059
- const createBundle = (uploadPayload) => opts?.attestationRuntime ? apiCreateSellerCredentialBundle(
50060
- uploadPayload,
50061
- attestationServiceUrl,
50062
- params.platform,
50063
- timeoutMs,
50064
- opts.attestationRuntime
50065
- ) : apiCreateSellerCredentialBundle(
50066
- uploadPayload,
50067
- attestationServiceUrl,
50068
- params.platform,
50069
- timeoutMs
50070
- );
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
+ };
50071
50210
  if (params.platform === "wise") {
50072
50211
  const bundleResponse2 = await createBundle({
50073
50212
  sessionMaterial: params.sessionMaterial
@@ -50138,6 +50277,21 @@ var Zkp2pClient = class {
50138
50277
  }
50139
50278
  );
50140
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
+ }
50141
50295
  return apiUploadGoogleOAuthSellerCredential(
50142
50296
  "venmo",
50143
50297
  params.payeeDetails,
@@ -50392,11 +50546,11 @@ var peerExtensionSdk = createPeerExtensionSdk();
50392
50546
 
50393
50547
  // src/takerTiers.ts
50394
50548
  var TAKER_TIER_SCHEDULE = [
50395
- { tier: "PLATINUM", perIntentCapUsd: 5e3, minVolumeUsd: 25e3, maxVolumeUsd: Infinity },
50396
- { tier: "PRO", perIntentCapUsd: 2500, minVolumeUsd: 1e4, maxVolumeUsd: 24999 },
50397
- { tier: "PLUS", perIntentCapUsd: 1e3, minVolumeUsd: 2e3, maxVolumeUsd: 9999 },
50398
- { tier: "PEER", perIntentCapUsd: 250, minVolumeUsd: 500, maxVolumeUsd: 1999 },
50399
- { 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 }
50400
50554
  ];
50401
50555
  var TAKER_TIER_ORDER = [
50402
50556
  "PEASANT",
@@ -50408,6 +50562,18 @@ var TAKER_TIER_ORDER = [
50408
50562
  var TAKER_TIER_CAPS = Object.fromEntries(
50409
50563
  TAKER_TIER_SCHEDULE.map((entry) => [entry.tier, entry.perIntentCapUsd])
50410
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
+ }
50411
50577
  function getNextTakerTier(currentTier) {
50412
50578
  if (!currentTier) return null;
50413
50579
  const index = TAKER_TIER_ORDER.indexOf(currentTier);
@@ -50472,6 +50638,7 @@ exports.PYTH_ORACLE_FEEDS = PYTH_ORACLE_FEEDS;
50472
50638
  exports.SPREAD_ORACLE_FEEDS = SPREAD_ORACLE_FEEDS;
50473
50639
  exports.SUPPORTED_CHAIN_IDS = SUPPORTED_CHAIN_IDS;
50474
50640
  exports.TAKER_TIER_CAPS = TAKER_TIER_CAPS;
50641
+ exports.TAKER_TIER_FEE_DISCOUNT_BPS = TAKER_TIER_FEE_DISCOUNT_BPS;
50475
50642
  exports.TAKER_TIER_ORDER = TAKER_TIER_ORDER;
50476
50643
  exports.TAKER_TIER_SCHEDULE = TAKER_TIER_SCHEDULE;
50477
50644
  exports.TOKEN_METADATA = TOKEN_METADATA;
@@ -50522,6 +50689,7 @@ exports.getPaymentMethodsCatalog = getPaymentMethodsCatalog;
50522
50689
  exports.getPeerExtensionState = getPeerExtensionState;
50523
50690
  exports.getRateManagerContracts = getRateManagerContracts;
50524
50691
  exports.getSpreadOracleConfig = getSpreadOracleConfig;
50692
+ exports.getTakerTierFeeDiscountBps = getTakerTierFeeDiscountBps;
50525
50693
  exports.isPeerExtensionAvailable = isPeerExtensionAvailable;
50526
50694
  exports.isSupportedCurrencyHash = isSupportedCurrencyHash;
50527
50695
  exports.isValidReferrerFeeBps = isValidReferrerFeeBps;