{"version":3,"sources":["../../src/circuits/constants.ts","../../src/vite/copyCircuitsPlugin.ts"],"names":["dirname","fileURLToPath","join","mkdirSync","existsSync","cpSync"],"mappings":";;;;;;;;AASO,IAAM,qBAAA,GAAwB,eAAA;AAC9B,IAAM,qBAAA,GAAwB,eAAA;;;ACDrC,IAAM,SAAA,GAAYA,YAAA,CAAQC,iBAAA,CAAc,2PAAe,CAAC,CAAA;AACxD,IAAM,WAAA,GAAcC,SAAA,CAAK,SAAA,EAAW,IAAA,EAAM,UAAU,CAAA;AA6B7C,SAAS,oBAAA,CACd,OAAA,GAAuC,EAAC,EAC5B;AACZ,EAAA,MAAM,OAAA,GAAU,QAAQ,IAAA,IAAQ,UAAA;AAEhC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,iBAAA;AAAA,IACN,KAAA,EAAO,OAAA;AAAA,IACP,UAAA,GAAa;AACX,MAAA,MAAM,SAASA,SAAA,CAAK,OAAA,CAAQ,GAAA,EAAI,EAAG,UAAU,OAAO,CAAA;AACpD,MAAAC,YAAA,CAAU,MAAA,EAAQ,EAAE,SAAA,EAAW,IAAA,EAAM,CAAA;AAErC,MAAA,KAAA,MAAW,IAAA,IAAQ,CAAC,qBAAA,EAAuB,qBAAqB,CAAA,EAAG;AACjE,QAAA,MAAM,IAAA,GAAOD,SAAA,CAAK,WAAA,EAAa,IAAI,CAAA;AACnC,QAAA,IAAI,CAACE,aAAA,CAAW,IAAI,CAAA,EAAG;AACrB,UAAA,IAAA,CAAK,KAAA,CAAM,CAAA,0BAAA,EAA6B,IAAI,CAAA,CAAE,CAAA;AAC9C,UAAA;AAAA,QACF;AACA,QAAAC,SAAA,CAAO,IAAA,EAAMH,SAAA,CAAK,MAAA,EAAQ,IAAI,CAAC,CAAA;AAAA,MACjC;AAEA,MAAA,IAAA,CAAK,IAAA,CAAK,CAAA,mCAAA,EAAsC,OAAO,CAAA,CAAA,CAAG,CAAA;AAAA,IAC5D;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import packageJson from \"../../package.json\";\n\n/** npm package name (used to load the standalone circuits module). */\nexport const PACKAGE_NAME = packageJson.name;\n\n/** Published npm version (pins CDN circuit URLs in production). */\nexport const PACKAGE_VERSION = packageJson.version;\n\n/** Withdraw circuit artifact filenames (published under `arcane-sdk/circuits/`). */\nexport const WITHDRAW_CIRCUIT_WASM = \"withdraw.wasm\";\nexport const WITHDRAW_CIRCUIT_ZKEY = \"withdraw.zkey\";\n/**\n * Pinned SHA-256 hashes for the published withdraw circuit artifacts.\n * These are verified in-browser before passing artifacts to snarkjs.\n */\nexport const WITHDRAW_CIRCUIT_SHA256 = {\n  wasm: \"2565a8dd94b0b3cb9ec6d415933ab05ed5d32ac07165b71be6bcf31615fc0330\",\n  zkey: \"64a4d915099f6fe6bfa06e151c254843be8773c7991c742260019dc5184e5d82\",\n} as const;\n\n/** Optional self-hosted path convention (opt-in via `circuitPathsBase`). */\nexport const SELF_HOSTED_CIRCUIT_BASE = \"/circuits/\";\n\n/**\n * Stable published source for the pinned circuit artifacts.\n *\n * Decoupled from {@link PACKAGE_VERSION} on purpose: the withdraw circuit is a\n * fixed cryptographic artifact, so SDK code releases must not change where the\n * verified circuits are fetched from. Bump these together with\n * {@link WITHDRAW_CIRCUIT_SHA256} only when the circuit itself changes.\n */\nexport const CIRCUIT_CDN_PACKAGE = \"arcane-privacy-sdk\";\nexport const CIRCUIT_CDN_VERSION = \"0.0.2\";\n\nexport type CircuitPaths = {\n  wasm: string;\n  zkey: string;\n};\n\n/** Resolve circuit URLs when the caller knows the package `dist/` root. */\nexport function resolveCircuitPathsFromBase(base: string): CircuitPaths {\n  const root = base.endsWith(\"/\") ? base : `${base}/`;\n  return {\n    wasm: `${root}circuits/${WITHDRAW_CIRCUIT_WASM}`,\n    zkey: `${root}circuits/${WITHDRAW_CIRCUIT_ZKEY}`,\n  };\n}\n\n/**\n * Base URL for circuit files on jsDelivr.\n *\n * Pinned to {@link CIRCUIT_CDN_PACKAGE}@{@link CIRCUIT_CDN_VERSION} (not the\n * current SDK version) so the bytes always match {@link WITHDRAW_CIRCUIT_SHA256}.\n * This URL is independent of the consuming app's origin/domain.\n */\nexport function resolveNpmCdnCircuitBase(): string {\n  return `https://cdn.jsdelivr.net/npm/${CIRCUIT_CDN_PACKAGE}@${CIRCUIT_CDN_VERSION}/dist/circuits/`;\n}\n\n/** Trusted jsDelivr fallback paths for pinned withdraw circuit artifacts. */\nexport function resolveNpmCdnCircuitPaths(): CircuitPaths {\n  const base = resolveNpmCdnCircuitBase();\n  return {\n    wasm: `${base}${WITHDRAW_CIRCUIT_WASM}`,\n    zkey: `${base}${WITHDRAW_CIRCUIT_ZKEY}`,\n  };\n}\n\nfunction isLocalDevHost(hostname: string): boolean {\n  return (\n    hostname === \"localhost\" ||\n    hostname === \"127.0.0.1\" ||\n    hostname === \"[::1]\"\n  );\n}\n\n/**\n * Browser circuit URLs.\n *\n * - Local dev (Vite): `/node_modules/<pkg>/dist/circuits/` — Vite serves node_modules.\n * - Production: pinned, domain-independent jsDelivr CDN (verified by SHA-256 before use).\n *\n * The production default does not depend on the app's own origin/domain, so it\n * works on any deployed host with no copy step. Artifacts are always integrity\n * checked before proving (see {@link WITHDRAW_CIRCUIT_SHA256}). To self-host\n * instead, pass {@link ArcaneSdkInitOptions.circuitPathsBase} (e.g. `\"/circuits/\"`);\n * it is verified too and falls back to the CDN if unavailable.\n */\nexport function resolveBrowserCircuitPaths(\n  baseOverride?: string\n): CircuitPaths | null {\n  if (typeof window === \"undefined\") {\n    return null;\n  }\n\n  if (baseOverride !== undefined) {\n    return resolveCircuitPathsFromBase(baseOverride);\n  }\n\n  if (isLocalDevHost(window.location.hostname)) {\n    const base = `/node_modules/${PACKAGE_NAME}/dist/circuits/`;\n    return {\n      wasm: `${base}${WITHDRAW_CIRCUIT_WASM}`,\n      zkey: `${base}${WITHDRAW_CIRCUIT_ZKEY}`,\n    };\n  }\n\n  return resolveNpmCdnCircuitPaths();\n}\n","import { cpSync, existsSync, mkdirSync } from \"node:fs\";\r\nimport { dirname, join } from \"node:path\";\r\nimport { fileURLToPath } from \"node:url\";\r\n\r\nimport {\r\n  WITHDRAW_CIRCUIT_WASM,\r\n  WITHDRAW_CIRCUIT_ZKEY,\r\n} from \"../circuits/constants\";\r\n\r\nconst pluginDir = dirname(fileURLToPath(import.meta.url));\r\nconst circuitsSrc = join(pluginDir, \"..\", \"circuits\");\r\n\r\nexport type ArcaneCircuitsPluginOptions = {\r\n  /** Directory under `public/` (default: `\"circuits\"`). */\r\n  dest?: string;\r\n};\r\n\r\ntype VitePlugin = {\r\n  name: string;\r\n  apply?: \"build\" | \"serve\";\r\n  buildStart?: (this: {\r\n    error: (msg: string) => void;\r\n    info: (msg: string) => void;\r\n  }) => void;\r\n};\r\n\r\n/**\r\n * Vite plugin: copies withdraw.wasm and withdraw.zkey into `public/circuits/`\r\n * before production build so browser proof generation works on static hosts (Vercel, etc.).\r\n *\r\n * @example\r\n * ```ts\r\n * import { arcaneCircuitsPlugin } from \"arcane-privacy-sdk/vite\";\r\n *\r\n * export default defineConfig({\r\n *   plugins: [react(), arcaneCircuitsPlugin()],\r\n * });\r\n * ```\r\n */\r\nexport function arcaneCircuitsPlugin(\r\n  options: ArcaneCircuitsPluginOptions = {}\r\n): VitePlugin {\r\n  const destDir = options.dest ?? \"circuits\";\r\n\r\n  return {\r\n    name: \"arcane-circuits\",\r\n    apply: \"build\",\r\n    buildStart() {\r\n      const target = join(process.cwd(), \"public\", destDir);\r\n      mkdirSync(target, { recursive: true });\r\n\r\n      for (const file of [WITHDRAW_CIRCUIT_WASM, WITHDRAW_CIRCUIT_ZKEY]) {\r\n        const from = join(circuitsSrc, file);\r\n        if (!existsSync(from)) {\r\n          this.error(`Missing circuit artifact: ${from}`);\r\n          return;\r\n        }\r\n        cpSync(from, join(target, file));\r\n      }\r\n\r\n      this.info(`Copied withdraw circuits to public/${destDir}/`);\r\n    },\r\n  };\r\n}\r\n"]}