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7B,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA;AAAA,IACtB,IAAA,EAAM,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA;AAAA,IACtB,WAAW,IAAA,CAAK,SAAA;AAAA,IAChB,OAAO,IAAA,CAAK,KAAA;AAAA,IACZ,cAAc,IAAA,CAAK,YAAA,CAAa,IAAI,CAAA,CAAA,KAAK,MAAA,CAAO,CAAC,CAAC,CAAA;AAAA,IAClD,aAAa,IAAA,CAAK;AAAA,GACpB;AACF","file":"chunk-7DA2CFRC.cjs","sourcesContent":["/**\n * Plain (non-React) fetch helpers for ASP service STARK endpoints.\n *\n * These return parsed bigint values so callers don't have to convert\n * decimal strings themselves. Thin wrappers over `fetch` + JSON.\n *\n * For React state-managed fetches, see `useStarkASPProof` in the /react\n * subpath. The hook is built on top of these helpers, so the wire shape\n * is normalized in one place.\n *\n * The SNARK-side BLS proof helpers live in `core/asp-list.ts` (taking\n * an `ASPEntry`). The STARK side has no parallel helper there because\n * `ASPEntry` doesn't yet describe a stark proof endpoint URL — when it\n * does, this module's helpers are what `asp-list.ts` should call into.\n */\nimport type {\n  ASPStarkRootResponse,\n  ASPStarkProofResponse,\n} from './api-schema.js'\n\n/**\n * Parsed STARK proof — bigint-typed, ready for AlwaysHashMerkleTree\n * verification or in-circuit witness assembly.\n */\nexport interface ASPStarkProofData {\n  /** STARK tree root */\n  root: bigint\n  /** Leaf value (M31-encoded address) */\n  leaf: bigint\n  /** Index of the leaf in insertion order (0-based) */\n  leafIndex: number\n  /** Tree depth — pinned alongside the proof so verifiers don't guess */\n  depth: number\n  /** Sibling at each level; length === depth */\n  pathElements: bigint[]\n  /** Side bit at each level (0 or 1); length === depth */\n  pathIndices: number[]\n}\n\n/**\n * Fetch the current STARK-side Merkle root from an ASP service.\n *\n * Throws on any non-2xx status — the root endpoint shouldn't return\n * 404, so we don't have a \"not found\" path here. Use `try/catch` to\n * distinguish service-unavailable from connectivity errors.\n */\nexport async function fetchStarkASPRoot(\n  serviceUrl: string,\n  fetchFn: typeof fetch = globalThis.fetch.bind(globalThis)\n): Promise<bigint> {\n  const url = `${serviceUrl.replace(/\\/$/, '')}/stark-root`\n  const res = await fetchFn(url)\n  if (!res.ok) {\n    throw new Error(`fetchStarkASPRoot ${url} → ${res.status} ${res.statusText}`)\n  }\n  const data = (await res.json()) as ASPStarkRootResponse\n  return BigInt(data.root)\n}\n\n/**\n * Fetch a STARK membership proof for `address` from an ASP service.\n *\n * Returns `null` on 404 (address not whitelisted). Throws on any other\n * non-2xx — including 429 (rate limited), which the caller may want to\n * retry with backoff.\n *\n * The returned proof is fixed-depth and always verifies against the\n * value `fetchStarkASPRoot` returns at the same point in time (cross-\n * leaf root agreement, by construction of `AlwaysHashMerkleTree`).\n */\nexport async function fetchStarkASPProof(\n  serviceUrl: string,\n  address: `0x${string}`,\n  fetchFn: typeof fetch = globalThis.fetch.bind(globalThis)\n): Promise<ASPStarkProofData | null> {\n  const url = `${serviceUrl.replace(/\\/$/, '')}/stark-proof/${address}`\n  const res = await fetchFn(url)\n  if (res.status === 404) return null\n  if (!res.ok) {\n    throw new Error(`fetchStarkASPProof ${url} → ${res.status} ${res.statusText}`)\n  }\n  const data = (await res.json()) as ASPStarkProofResponse\n  return {\n    root: BigInt(data.root),\n    leaf: BigInt(data.leaf),\n    leafIndex: data.leafIndex,\n    depth: data.depth,\n    pathElements: data.pathElements.map(e => BigInt(e)),\n    pathIndices: data.pathIndices,\n  }\n}\n"]}