veilix-sdk 0.0.9 → 0.2.0

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 +1 @@
1
- {"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 `veilix-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: \"68b712068a25e5b027a755ec96c35f176dfdc988f437b98587d572d6f3a26c03\",\n zkey: \"fd177812fb178896c08de7efd7bcc9e6b17d5ac1e5de512459ba0a9a92161a5e\",\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 = \"veilix-sdk\";\nexport const CIRCUIT_CDN_VERSION = \"0.0.4\";\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 VeilixSdkInitOptions.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\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport {\n WITHDRAW_CIRCUIT_WASM,\n WITHDRAW_CIRCUIT_ZKEY,\n} from \"../circuits/constants\";\n\nconst pluginDir = dirname(fileURLToPath(import.meta.url));\nconst circuitsSrc = join(pluginDir, \"..\", \"circuits\");\n\nexport type VeilixCircuitsPluginOptions = {\n /** Directory under `public/` (default: `\"circuits\"`). */\n dest?: string;\n};\n\ntype VitePlugin = {\n name: string;\n apply?: \"build\" | \"serve\";\n buildStart?: (this: {\n error: (msg: string) => void;\n info: (msg: string) => void;\n }) => void;\n};\n\n/**\n * Vite plugin: copies withdraw.wasm and withdraw.zkey into `public/circuits/`\n * before production build so browser proof generation works on static hosts (Vercel, etc.).\n *\n * @example\n * ```ts\n * import { veilixCircuitsPlugin } from \"veilix-sdk/vite\";\n *\n * export default defineConfig({\n * plugins: [react(), veilixCircuitsPlugin()],\n * });\n * ```\n */\nexport function veilixCircuitsPlugin(\n options: VeilixCircuitsPluginOptions = {}\n): VitePlugin {\n const destDir = options.dest ?? \"circuits\";\n\n return {\n name: \"veilix-circuits\",\n apply: \"build\",\n buildStart() {\n const target = join(process.cwd(), \"public\", destDir);\n mkdirSync(target, { recursive: true });\n\n for (const file of [WITHDRAW_CIRCUIT_WASM, WITHDRAW_CIRCUIT_ZKEY]) {\n const from = join(circuitsSrc, file);\n if (!existsSync(from)) {\n this.error(`Missing circuit artifact: ${from}`);\n return;\n }\n cpSync(from, join(target, file));\n }\n\n this.info(`Copied withdraw circuits to public/${destDir}/`);\n },\n };\n}\n"]}
1
+ {"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 `veilix-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: \"5f9eb88bcbc1b3dd5669dad6fdd3b91d59dd2d617ad0b34827af8a498d13fa60\",\n zkey: \"73e0d2328eca8f48024b69b42d659b68d7dd2f067d762079e859ffff34360a1a\",\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 = \"veilix-sdk-test\";\nexport const CIRCUIT_CDN_VERSION = \"0.1.0\";\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 VeilixSdkInitOptions.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\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport {\n WITHDRAW_CIRCUIT_WASM,\n WITHDRAW_CIRCUIT_ZKEY,\n} from \"../circuits/constants\";\n\nconst pluginDir = dirname(fileURLToPath(import.meta.url));\nconst circuitsSrc = join(pluginDir, \"..\", \"circuits\");\n\nexport type VeilixCircuitsPluginOptions = {\n /** Directory under `public/` (default: `\"circuits\"`). */\n dest?: string;\n};\n\ntype VitePlugin = {\n name: string;\n apply?: \"build\" | \"serve\";\n buildStart?: (this: {\n error: (msg: string) => void;\n info: (msg: string) => void;\n }) => void;\n};\n\n/**\n * Vite plugin: copies withdraw.wasm and withdraw.zkey into `public/circuits/`\n * before production build so browser proof generation works on static hosts (Vercel, etc.).\n *\n * @example\n * ```ts\n * import { veilixCircuitsPlugin } from \"veilix-sdk/vite\";\n *\n * export default defineConfig({\n * plugins: [react(), veilixCircuitsPlugin()],\n * });\n * ```\n */\nexport function veilixCircuitsPlugin(\n options: VeilixCircuitsPluginOptions = {}\n): VitePlugin {\n const destDir = options.dest ?? \"circuits\";\n\n return {\n name: \"veilix-circuits\",\n apply: \"build\",\n buildStart() {\n const target = join(process.cwd(), \"public\", destDir);\n mkdirSync(target, { recursive: true });\n\n for (const file of [WITHDRAW_CIRCUIT_WASM, WITHDRAW_CIRCUIT_ZKEY]) {\n const from = join(circuitsSrc, file);\n if (!existsSync(from)) {\n this.error(`Missing circuit artifact: ${from}`);\n return;\n }\n cpSync(from, join(target, file));\n }\n\n this.info(`Copied withdraw circuits to public/${destDir}/`);\n },\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/circuits/constants.ts","../../src/vite/copyCircuitsPlugin.ts"],"names":[],"mappings":";;;;;AASO,IAAM,qBAAA,GAAwB,eAAA;AAC9B,IAAM,qBAAA,GAAwB,eAAA;;;ACDrC,IAAM,SAAA,GAAY,OAAA,CAAQ,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAC,CAAA;AACxD,IAAM,WAAA,GAAc,IAAA,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,SAAS,IAAA,CAAK,OAAA,CAAQ,GAAA,EAAI,EAAG,UAAU,OAAO,CAAA;AACpD,MAAA,SAAA,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,GAAO,IAAA,CAAK,WAAA,EAAa,IAAI,CAAA;AACnC,QAAA,IAAI,CAAC,UAAA,CAAW,IAAI,CAAA,EAAG;AACrB,UAAA,IAAA,CAAK,KAAA,CAAM,CAAA,0BAAA,EAA6B,IAAI,CAAA,CAAE,CAAA;AAC9C,UAAA;AAAA,QACF;AACA,QAAA,MAAA,CAAO,IAAA,EAAM,IAAA,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.js","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 `veilix-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: \"68b712068a25e5b027a755ec96c35f176dfdc988f437b98587d572d6f3a26c03\",\n zkey: \"fd177812fb178896c08de7efd7bcc9e6b17d5ac1e5de512459ba0a9a92161a5e\",\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 = \"veilix-sdk\";\nexport const CIRCUIT_CDN_VERSION = \"0.0.4\";\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 VeilixSdkInitOptions.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\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport {\n WITHDRAW_CIRCUIT_WASM,\n WITHDRAW_CIRCUIT_ZKEY,\n} from \"../circuits/constants\";\n\nconst pluginDir = dirname(fileURLToPath(import.meta.url));\nconst circuitsSrc = join(pluginDir, \"..\", \"circuits\");\n\nexport type VeilixCircuitsPluginOptions = {\n /** Directory under `public/` (default: `\"circuits\"`). */\n dest?: string;\n};\n\ntype VitePlugin = {\n name: string;\n apply?: \"build\" | \"serve\";\n buildStart?: (this: {\n error: (msg: string) => void;\n info: (msg: string) => void;\n }) => void;\n};\n\n/**\n * Vite plugin: copies withdraw.wasm and withdraw.zkey into `public/circuits/`\n * before production build so browser proof generation works on static hosts (Vercel, etc.).\n *\n * @example\n * ```ts\n * import { veilixCircuitsPlugin } from \"veilix-sdk/vite\";\n *\n * export default defineConfig({\n * plugins: [react(), veilixCircuitsPlugin()],\n * });\n * ```\n */\nexport function veilixCircuitsPlugin(\n options: VeilixCircuitsPluginOptions = {}\n): VitePlugin {\n const destDir = options.dest ?? \"circuits\";\n\n return {\n name: \"veilix-circuits\",\n apply: \"build\",\n buildStart() {\n const target = join(process.cwd(), \"public\", destDir);\n mkdirSync(target, { recursive: true });\n\n for (const file of [WITHDRAW_CIRCUIT_WASM, WITHDRAW_CIRCUIT_ZKEY]) {\n const from = join(circuitsSrc, file);\n if (!existsSync(from)) {\n this.error(`Missing circuit artifact: ${from}`);\n return;\n }\n cpSync(from, join(target, file));\n }\n\n this.info(`Copied withdraw circuits to public/${destDir}/`);\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/circuits/constants.ts","../../src/vite/copyCircuitsPlugin.ts"],"names":[],"mappings":";;;;;AASO,IAAM,qBAAA,GAAwB,eAAA;AAC9B,IAAM,qBAAA,GAAwB,eAAA;;;ACDrC,IAAM,SAAA,GAAY,OAAA,CAAQ,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAC,CAAA;AACxD,IAAM,WAAA,GAAc,IAAA,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,SAAS,IAAA,CAAK,OAAA,CAAQ,GAAA,EAAI,EAAG,UAAU,OAAO,CAAA;AACpD,MAAA,SAAA,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,GAAO,IAAA,CAAK,WAAA,EAAa,IAAI,CAAA;AACnC,QAAA,IAAI,CAAC,UAAA,CAAW,IAAI,CAAA,EAAG;AACrB,UAAA,IAAA,CAAK,KAAA,CAAM,CAAA,0BAAA,EAA6B,IAAI,CAAA,CAAE,CAAA;AAC9C,UAAA;AAAA,QACF;AACA,QAAA,MAAA,CAAO,IAAA,EAAM,IAAA,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.js","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 `veilix-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: \"5f9eb88bcbc1b3dd5669dad6fdd3b91d59dd2d617ad0b34827af8a498d13fa60\",\n zkey: \"73e0d2328eca8f48024b69b42d659b68d7dd2f067d762079e859ffff34360a1a\",\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 = \"veilix-sdk-test\";\nexport const CIRCUIT_CDN_VERSION = \"0.1.0\";\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 VeilixSdkInitOptions.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\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport {\n WITHDRAW_CIRCUIT_WASM,\n WITHDRAW_CIRCUIT_ZKEY,\n} from \"../circuits/constants\";\n\nconst pluginDir = dirname(fileURLToPath(import.meta.url));\nconst circuitsSrc = join(pluginDir, \"..\", \"circuits\");\n\nexport type VeilixCircuitsPluginOptions = {\n /** Directory under `public/` (default: `\"circuits\"`). */\n dest?: string;\n};\n\ntype VitePlugin = {\n name: string;\n apply?: \"build\" | \"serve\";\n buildStart?: (this: {\n error: (msg: string) => void;\n info: (msg: string) => void;\n }) => void;\n};\n\n/**\n * Vite plugin: copies withdraw.wasm and withdraw.zkey into `public/circuits/`\n * before production build so browser proof generation works on static hosts (Vercel, etc.).\n *\n * @example\n * ```ts\n * import { veilixCircuitsPlugin } from \"veilix-sdk/vite\";\n *\n * export default defineConfig({\n * plugins: [react(), veilixCircuitsPlugin()],\n * });\n * ```\n */\nexport function veilixCircuitsPlugin(\n options: VeilixCircuitsPluginOptions = {}\n): VitePlugin {\n const destDir = options.dest ?? \"circuits\";\n\n return {\n name: \"veilix-circuits\",\n apply: \"build\",\n buildStart() {\n const target = join(process.cwd(), \"public\", destDir);\n mkdirSync(target, { recursive: true });\n\n for (const file of [WITHDRAW_CIRCUIT_WASM, WITHDRAW_CIRCUIT_ZKEY]) {\n const from = join(circuitsSrc, file);\n if (!existsSync(from)) {\n this.error(`Missing circuit artifact: ${from}`);\n return;\n }\n cpSync(from, join(target, file));\n }\n\n this.info(`Copied withdraw circuits to public/${destDir}/`);\n },\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veilix-sdk",
3
- "version": "0.0.9",
3
+ "version": "0.2.0",
4
4
  "description": "Veilix Privacy SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -75,6 +75,7 @@
75
75
  "license": "MIT",
76
76
  "devDependencies": {
77
77
  "@solana/wallet-adapter-react": "^0.15.39",
78
+ "@types/bn.js": "^5.2.0",
78
79
  "@types/node": "^26.0.0",
79
80
  "@types/react": "^19.1.8",
80
81
  "react": "^19.1.0",
@@ -90,6 +91,7 @@
90
91
  "@solana/web3.js": "^1.98.4",
91
92
  "@switchboard-xyz/common": "^5.8.1",
92
93
  "@switchboard-xyz/on-demand": "^3.10.1",
94
+ "bn.js": "^5.2.5",
93
95
  "buffer": "^6.0.3",
94
96
  "ffjavascript": "^0.3.1",
95
97
  "fixed-merkle-tree": "^0.7.3",
@@ -1,386 +0,0 @@
1
- import { PublicKey, Keypair, Connection, TransactionInstruction, Transaction } from '@solana/web3.js';
2
- import { OracleJob } from '@switchboard-xyz/common';
3
- import { Program } from '@coral-xyz/anchor';
4
- import { Wallet } from '@coral-xyz/anchor/dist/cjs/provider';
5
- import { C as CircuitPaths } from './constants-sO9UKB9l.js';
6
-
7
- type IndexerAsset = string | {
8
- mint?: string;
9
- asset?: string;
10
- } | null;
11
-
12
- /** Frontend wallet adapter or backend {@link Keypair}. */
13
- type EncryptKeyWallet = Keypair | {
14
- signMessage: (message: Uint8Array) => Promise<Uint8Array> | Uint8Array;
15
- };
16
- type BuildDepositTxParams = {
17
- senderPublicKey: PublicKey | string;
18
- /** Pre-generated secret note from {@link generateDepositParams}. */
19
- note: string;
20
- onChainBackup?: boolean;
21
- computeUnitPrice?: number;
22
- tempSigner?: PublicKey | string;
23
- };
24
- type FetchWalletBalanceOptions = {
25
- includeDeposits?: boolean;
26
- indexerAsset?: IndexerAsset;
27
- };
28
- type BuildRelayPayloadParams = {
29
- args: unknown[];
30
- proofHex: string;
31
- denomination: number | bigint | string;
32
- withdrawAddress: unknown;
33
- relayerPubkey: unknown;
34
- mint?: unknown;
35
- };
36
- type RelayPayload = Record<string, unknown>;
37
-
38
- type DepositParams = {
39
- nullifier: string;
40
- secret: string;
41
- amount: string;
42
- commitment: string;
43
- nullifierHash: string;
44
- mint: string | null;
45
- };
46
- type GenerateDepositParamsResult = {
47
- params: DepositParams;
48
- note: string;
49
- };
50
- type PreparedCircuitArtifacts = {
51
- wasmPath: string;
52
- zkeyPath: string;
53
- /** Revokes the browser object URLs. `null` outside the browser. */
54
- cleanup: (() => void) | null;
55
- };
56
- type GenerateWithdrawProofOptions = {
57
- /** Override WASM path/URL (for bundled frontends, use a Vite `?url` import). */
58
- circuitWasmPath?: string;
59
- /** Override zkey path/URL (for bundled frontends, use a Vite `?url` import). */
60
- circuitZkeyPath?: string;
61
- /**
62
- * Artifacts already fetched and verified by {@link prepareCircuitArtifacts}.
63
- * Skips the download and takes precedence over the path overrides; the caller
64
- * stays responsible for calling `cleanup`.
65
- */
66
- circuitArtifacts?: PreparedCircuitArtifacts;
67
- };
68
- /**
69
- * Fetch and integrity-check the withdraw circuit artifacts once so that several
70
- * proofs can share them. Call `cleanup` after the last proof has settled.
71
- */
72
- declare const prepareCircuitArtifacts: (circuitWasmPath?: string, circuitZkeyPath?: string) => Promise<PreparedCircuitArtifacts>;
73
-
74
- type Network = "mainnet" | "devnet";
75
- declare const MAINNET_TOKEN_MINTS: {
76
- readonly Veilix: "GAFN64LvtCBoc5BHncVn3JEJGpq42rUzQjPmvMK2UhZH";
77
- readonly Bitcoin: "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh";
78
- readonly Ethereum: "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs";
79
- readonly USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
80
- };
81
- type TokenSymbol = keyof typeof MAINNET_TOKEN_MINTS;
82
- declare const TOKEN_DECIMALS: {
83
- readonly Solana: 9;
84
- readonly Veilix: 9;
85
- readonly Ethereum: 8;
86
- readonly Bitcoin: 8;
87
- readonly USDC: 6;
88
- };
89
- type TokenDecimalsSymbol = keyof typeof TOKEN_DECIMALS;
90
- /** Supported deposit denominations per token (same on mainnet and devnet). */
91
- declare const DEPOSIT_AMOUNTS: {
92
- readonly Solana: readonly [0.1, 1, 5, 10, 50, 100, 500];
93
- readonly Veilix: readonly [10000, 50000, 100000, 500000, 1000000, 10000000];
94
- readonly Bitcoin: readonly [0.01, 0.05, 0.1, 0.5, 1, 5];
95
- readonly Ethereum: readonly [0.1, 1, 10, 50, 100, 500];
96
- readonly USDC: readonly [1, 10, 50, 100, 1000, 10000, 100000, 1000000];
97
- };
98
- type DepositTokenSymbol = keyof typeof DEPOSIT_AMOUNTS;
99
-
100
- type Relayer = {
101
- isValid: true;
102
- label: string;
103
- url: string;
104
- key: number;
105
- value: string;
106
- fee: unknown;
107
- recentActivities: unknown;
108
- userPubkey: unknown;
109
- workers: unknown;
110
- totalFeeEarningsSol: unknown;
111
- totalWithdrawCount: unknown;
112
- stakedAmount: unknown;
113
- volume24hSol: unknown;
114
- volume7dSol: unknown;
115
- };
116
-
117
- interface VeilixSdkInitOptions {
118
- /** Wallet for Anchor provider transactions. */
119
- wallet: Wallet;
120
- /**
121
- * Solana JSON-RPC endpoint (Node/scripts). Omit when passing {@link connection}
122
- * from `@solana/wallet-adapter-react` (`useConnection()`).
123
- */
124
- rpcEndpoint?: string;
125
- /** Existing connection (e.g. `useConnection()` in React). */
126
- connection?: Connection;
127
- /**
128
- * Cluster override when the RPC URL does not contain `devnet` / `mainnet` hints
129
- * (common with private RPC providers).
130
- */
131
- network: Network;
132
- /**
133
- * Base URL/path for withdraw circuit artifacts in the browser.
134
- * Defaults to `/node_modules/<pkg>/dist/circuits/` on localhost and the
135
- * pinned, SHA-256-verified jsDelivr CDN in production (domain-independent).
136
- * Set this to self-host instead, e.g. `"/circuits/"` (verified, with CDN fallback)
137
- * or `"https://cdn.example.com/veilix/circuits/"`.
138
- */
139
- circuitPathsBase?: string;
140
- }
141
- interface VeilixSdkRuntimeConfig {
142
- rpcEndpoint: string;
143
- /** Cluster inferred from {@link rpcEndpoint}. */
144
- network: Network;
145
- programId: string;
146
- /** Active relayers for {@link network}, loaded at SDK initialization. */
147
- relayers: Relayer[];
148
- connection: Connection;
149
- wallet: Wallet;
150
- program: Program;
151
- /** Set by {@link VeilixSDK.getEncryptionKey}; required for on-chain note backup. */
152
- encryptKey?: Uint8Array;
153
- /** Resolved withdraw circuit wasm/zkey URLs for browser proof generation. */
154
- circuitPaths?: CircuitPaths;
155
- }
156
-
157
- type WithdrawParams = {
158
- /** Secret note from the original deposit. */
159
- note: string;
160
- /** Withdrawal recipient public key. */
161
- recipient: PublicKey | string;
162
- /** Mode for normal withdraw or veilix transfer. */
163
- veilixTransferMode?: boolean;
164
- };
165
- type WithdrawStatus = "success" | "failed";
166
- type WithdrawResult = {
167
- txHash: string;
168
- status: WithdrawStatus;
169
- };
170
-
171
- type QuoteRelayer = {
172
- url: string;
173
- [key: string]: unknown;
174
- };
175
- type QuoteTransaction = Record<string, unknown>;
176
- type QuoteSplit = {
177
- denomination: number;
178
- totalRelayerFee: number;
179
- relayer: QuoteRelayer;
180
- transaction: QuoteTransaction;
181
- };
182
- type Quote = {
183
- amount: number;
184
- transactionCount: number;
185
- recipientAmount: number;
186
- totalRelayerFee: number;
187
- etaSeconds: number;
188
- splits: QuoteSplit[];
189
- platformFee?: number;
190
- };
191
- type GetQuoteResponse = {
192
- success: boolean;
193
- quote: Quote;
194
- };
195
- type GetQuoteParams = {
196
- amount: number | string;
197
- amountLamports: number | string | bigint;
198
- recipient: PublicKey | string;
199
- /** Indexer asset label (default `SOL`). */
200
- asset?: string;
201
- /** Cluster for the quote (default active SDK network). */
202
- network?: Network;
203
- };
204
- /** Fetch a withdraw quote from the indexer. Requires SDK init or an active instance context. */
205
- declare function getQuote(params: GetQuoteParams): Promise<GetQuoteResponse>;
206
-
207
- type ResolvedNoteAsset = {
208
- key: string;
209
- tokenName: TokenDecimalsSymbol;
210
- unit: string;
211
- multiplier: bigint;
212
- mint: string | null;
213
- poolAmounts: readonly number[];
214
- decimals: number;
215
- };
216
-
217
- type VeilixTransferItem = {
218
- mint: PublicKey;
219
- /** Human-readable token amount (e.g. `"1.5"` SOL). */
220
- amount: string;
221
- recipient: PublicKey;
222
- };
223
- type VeilixTransferDepositFailure = {
224
- amount: string;
225
- mint: string;
226
- recipient: string;
227
- };
228
- type VeilixTransferWithdrawFailure = {
229
- note: string;
230
- recipient: string;
231
- };
232
- type VeilixTransferResult = {
233
- error: boolean;
234
- depositFailed: VeilixTransferDepositFailure[];
235
- withdrawFailed: VeilixTransferWithdrawFailure[];
236
- depositSuccess: string[];
237
- };
238
- type VeilixTransferOptions = {
239
- /** When true, all withdraws use the same randomly selected relayer. */
240
- uniqueRelayer?: boolean;
241
- };
242
-
243
- /**
244
- * Veilix SDK client. Create one instance per configuration (network, RPC, wallet).
245
- *
246
- * @example
247
- * ```js
248
- * const { VeilixSDK } = require('veilix-sdk');
249
- * const sdk = await VeilixSDK.create({
250
- * rpcEndpoint: 'https://api.devnet.solana.com',
251
- * wallet,
252
- * network: 'devnet',
253
- * });
254
- * console.log(sdk.config.relayers);
255
- * ```
256
- *
257
- * @example React (wallet-adapter)
258
- * ```tsx
259
- * import { useVeilixSdk } from 'veilix-sdk/react';
260
- *
261
- * function MyComponent() {
262
- * const sdk = useVeilixSdk({ network: 'mainnet' });
263
- * if (!sdk) return null;
264
- * // ...
265
- * }
266
- * ```
267
- *
268
- * @example
269
- * ```ts
270
- * import { VeilixSDK } from 'veilix-sdk';
271
- * const sdk = await VeilixSDK.create({ rpcEndpoint, wallet, network: 'mainnet' });
272
- * await sdk.getEncryptionKey(wallet);
273
- * const { note } = sdk.generateDepositParams(1_000_000_000n, null);
274
- * await sdk.buildDepositTx({ senderPublicKey: wallet.publicKey, note, onChainBackup: true });
275
- * ```
276
- */
277
- declare class VeilixSDK {
278
- static readonly VERSION = "0.0.1";
279
- readonly config: VeilixSdkRuntimeConfig;
280
- private constructor();
281
- /** Create an SDK instance (loads relayers for the inferred network). */
282
- static create(options: VeilixSdkInitOptions): Promise<VeilixSDK>;
283
- private run;
284
- private runAsync;
285
- getConfig(): VeilixSdkRuntimeConfig;
286
- getRpcEndpoint(): string;
287
- getNetwork(): Network;
288
- getProgramIdString(): string;
289
- /** Encryption key derived by {@link getEncryptionKey}; undefined until set. */
290
- get encryptKey(): Uint8Array | undefined;
291
- /** Relayers loaded at initialization; use {@link fetchRelayers} to refresh. */
292
- get relayers(): Relayer[];
293
- getIndexerUrl(): string;
294
- getRiskApiUrl(): string;
295
- getTokenMints(): {
296
- Solana: string;
297
- Veilix: "GAFN64LvtCBoc5BHncVn3JEJGpq42rUzQjPmvMK2UhZH";
298
- Bitcoin: "" | "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh";
299
- Ethereum: "" | "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs";
300
- USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" | "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
301
- };
302
- getVeilixTokenMint(): string;
303
- getTokenMint(symbol: TokenSymbol): string;
304
- getDepositAmounts(symbol: DepositTokenSymbol): readonly number[];
305
- getTokenDecimals(symbol: TokenDecimalsSymbol): number;
306
- resolveCircuitPaths(base?: string): Promise<CircuitPaths>;
307
- getRangeRiskScoreJob(address: string): OracleJob;
308
- getOracleQuote(payer: Keypair | PublicKey, addressToCheck: string): Promise<{
309
- queueAccount: PublicKey;
310
- sigVerifyIx: TransactionInstruction;
311
- }>;
312
- getProgramId(): PublicKey;
313
- getPoolPDA(denominationLamports: number | bigint): [PublicKey, number];
314
- getTokenPoolPDA(mint: PublicKey | string, denominationSmallestUnits: number | bigint): [PublicKey, number];
315
- getTreasuryPDA(): [PublicKey, number];
316
- getCommitmentPDA(commitmentBigInt: bigint | number | string): [PublicKey, number];
317
- getNullifierPDA(nullifierHashBigInt: bigint | number | string): [PublicKey, number];
318
- getNetworkStatePDA(): [PublicKey, number];
319
- buildDepositTx(params: BuildDepositTxParams): Promise<{
320
- tx: Transaction;
321
- note: string;
322
- }>;
323
- /**
324
- * Withdraw to `recipient` using a secret `note`.
325
- * Relayer is chosen at random from {@link config.relayers}, or by {@link WithdrawParams.relayerIdx}.
326
- */
327
- withdraw(params: WithdrawParams, relayerIdx?: number): Promise<WithdrawResult>;
328
- /**
329
- * Private transfer: deposit into the pool (split by supported denominations),
330
- * then withdraw each successful note to the recipient.
331
- *
332
- * Requires {@link getEncryptionKey} before calling (deposits use on-chain backup).
333
- *
334
- * @param tempKeypair Ephemeral keypair co-signed on deposit instructions.
335
- */
336
- veilixTransfer(items: VeilixTransferItem[], tempKeypair: Keypair): Promise<VeilixTransferResult>;
337
- /** Validate a withdraw recipient against the risk API. */
338
- assertWithdrawRecipientAllowed(address: string): Promise<void>;
339
- /** Resolve the token asset encoded in a secret note. */
340
- resolveNoteAsset(amount: string, mint?: string | null, tokenNameHint?: TokenDecimalsSymbol): ResolvedNoteAsset;
341
- fetchPlatformFee(): Promise<string>;
342
- /** Fetch a withdraw quote from the indexer. */
343
- getQuote(params: GetQuoteParams): Promise<GetQuoteResponse>;
344
- fetchCommitments(denomination: number | bigint | string, indexerAsset?: IndexerAsset): Promise<unknown>;
345
- validateNullifier(nullifierHash: string, indexerAsset?: IndexerAsset): Promise<unknown>;
346
- fetchTxStatus(commitmentHex: string, nullifierHashHex: string, indexerAsset?: IndexerAsset): Promise<unknown>;
347
- fetchDepositCountByCommitment(commitment: string, denomination: number | bigint | string, indexerAsset?: IndexerAsset): Promise<unknown>;
348
- fetchWalletBalance(wallet: string, options?: FetchWalletBalanceOptions): Promise<unknown>;
349
- /** Re-fetch relayers from the indexer and update {@link config.relayers}. */
350
- fetchRelayers(): Promise<Relayer[]>;
351
- fetchLatestTransactions(type?: string, indexerAsset?: IndexerAsset): Promise<unknown>;
352
- fetchTxCounts(type?: string, indexerAsset?: IndexerAsset): Promise<unknown>;
353
- normalizePubkeyString(value: unknown): string;
354
- buildRelayPayload(params: BuildRelayPayloadParams): RelayPayload;
355
- submitToRelayer(relayerUrl: string, payload: RelayPayload): Promise<unknown>;
356
- pollRelayerJob(relayerUrl: string, jobId: string, maxWaitMs?: number): Promise<unknown>;
357
- /**
358
- * Derives the note encryption key from a wallet signature and stores it on
359
- * {@link config.encryptKey}. Required before {@link buildDepositTx} with
360
- * `onChainBackup: true`.
361
- *
362
- * Accepts a frontend wallet adapter (`signMessage`) or a backend {@link Keypair}.
363
- */
364
- getEncryptionKey(wallet: EncryptKeyWallet): Promise<Uint8Array>;
365
- encryptData(key: Uint8Array, plaintext: string): Uint8Array<ArrayBufferLike>;
366
- decryptData(key: Uint8Array, combined: Uint8Array): string;
367
- generateRandomFieldElement(): bigint;
368
- createCommitment(nullifier: bigint | number | string, secret: bigint | number | string): bigint;
369
- createNullifierHash(nullifier: bigint | number | string): bigint;
370
- generateDepositParams(amountLamports: bigint | number | string, mint?: string | null): GenerateDepositParamsResult;
371
- parseSecretNote(note: string): Record<string, string>;
372
- publicKeyToFieldElement(publicKeyBytes: Uint8Array | number[]): bigint;
373
- amountToFieldElement(amount: bigint | number | string): bigint;
374
- generateMerkleProof(depositParams: Record<string, unknown>, leaves: unknown[]): unknown;
375
- generateWithdrawProof(depositParams: Record<string, unknown>, leaves: unknown[], recipient: PublicKey | string, relayer: PublicKey | string, fee: bigint | number | string, refund: bigint | number | string, options?: GenerateWithdrawProofOptions): Promise<unknown>;
376
- convertProofToBytes(proof: unknown): Promise<number[] | Uint8Array<ArrayBufferLike>>;
377
- to32ByteBuffer(bigInt: bigint | number | string): Uint8Array<ArrayBufferLike>;
378
- toFixedHex(value: bigint | number | string, length?: number): string;
379
- toFieldElementHex(value: bigint | number | string): string;
380
- formatNoteForDisplay(note: string, segmentLen?: number): string;
381
- appendIndexerAsset(params: URLSearchParams, indexerAsset?: IndexerAsset): void;
382
- /** Program ID for a cluster without an SDK instance. */
383
- static getProgramIdForNetwork(network: Network): string;
384
- }
385
-
386
- export { type BuildDepositTxParams as B, type DepositTokenSymbol as D, type EncryptKeyWallet as E, type FetchWalletBalanceOptions as F, type GenerateDepositParamsResult as G, type IndexerAsset as I, type Network as N, type PreparedCircuitArtifacts as P, type Quote as Q, type RelayPayload as R, type TokenDecimalsSymbol as T, VeilixSDK as V, type WithdrawParams as W, type BuildRelayPayloadParams as a, type GenerateWithdrawProofOptions as b, type GetQuoteParams as c, type GetQuoteResponse as d, type QuoteRelayer as e, type QuoteSplit as f, type QuoteTransaction as g, type Relayer as h, type ResolvedNoteAsset as i, type TokenSymbol as j, type VeilixSdkInitOptions as k, type VeilixSdkRuntimeConfig as l, type VeilixTransferDepositFailure as m, type VeilixTransferItem as n, type VeilixTransferOptions as o, type VeilixTransferResult as p, type VeilixTransferWithdrawFailure as q, type WithdrawResult as r, type WithdrawStatus as s, getQuote as t, prepareCircuitArtifacts as u };