@izi-noir/sdk 0.1.4 → 0.1.5

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 +0,0 @@
1
- {"version":3,"sources":["../../src/providers/solana.ts"],"sourcesContent":["/**\n * Solana on-chain verification provider for IZI-NOIR.\n *\n * This module provides functionality to verify Groth16 proofs on-chain using\n * the IZI-NOIR Solana program. It's compatible with proofs generated by the\n * Arkworks provider.\n *\n * @example Basic usage\n * ```typescript\n * import { SolanaVerifier } from '@izi-noir/sdk/solana';\n * import { Connection, Keypair } from '@solana/web3.js';\n *\n * const connection = new Connection('https://api.devnet.solana.com');\n * const wallet = Keypair.generate(); // In practice, use a real wallet\n *\n * const verifier = new SolanaVerifier({\n * connection,\n * wallet,\n * programId: 'EYhRED7EuMyyVjx57aDXUD9h6ArnEKng64qtz8999KrS',\n * });\n *\n * // Initialize a VK account from base64-encoded VK\n * const vkAccount = await verifier.initVkFromBase64(vkGnarkBase64, nrPubinputs);\n *\n * // Verify a proof on-chain\n * const txSig = await verifier.verifyProof(\n * vkAccount,\n * proofGnarkBase64,\n * publicInputsHex\n * );\n * ```\n *\n * @module @izi-noir/sdk/solana\n */\n\n// Constants matching the Solana program\nexport const G1_SIZE = 64;\nexport const G2_SIZE = 128;\nexport const FIELD_SIZE = 32;\nexport const PROOF_SIZE = 256;\nexport const MAX_PUBLIC_INPUTS = 16;\n\n// Program ID - deployed on devnet\nexport const IZI_NOIR_PROGRAM_ID = 'EYhRED7EuMyyVjx57aDXUD9h6ArnEKng64qtz8999KrS';\n\n/**\n * Configuration for the SolanaVerifier.\n */\nexport interface SolanaVerifierConfig {\n /**\n * Solana RPC connection.\n * Must be compatible with @solana/web3.js Connection.\n */\n connection: unknown;\n\n /**\n * Wallet for signing transactions.\n * Can be a Keypair or any wallet adapter compatible signer.\n */\n wallet: unknown;\n\n /**\n * Program ID of the deployed IZI-NOIR verifier program.\n * Defaults to the placeholder ID.\n */\n programId?: string;\n}\n\n/**\n * Result from initializing a VK account.\n */\nexport interface InitVkResult {\n /** The public key of the created VK account */\n vkAccount: string;\n /** The transaction signature */\n txSignature: string;\n}\n\n/**\n * Result from verifying a proof on-chain.\n */\nexport interface VerifyResult {\n /** Whether the proof was verified successfully */\n success: boolean;\n /** The transaction signature */\n txSignature: string;\n /** Error message if verification failed */\n error?: string;\n}\n\n/**\n * Parses a base64-encoded verifying key into its components.\n *\n * The VK format from arkworks gnark_compat is:\n * | alpha_g1 (64) | beta_g2 (128) | gamma_g2 (128) | delta_g2 (128) | k[0..n+1] (64 each) |\n *\n * @param vkBase64 - Base64-encoded verifying key\n * @param nrPubinputs - Number of public inputs\n * @returns Parsed VK components\n */\nexport function parseVerifyingKey(vkBase64: string, nrPubinputs: number): {\n alphaG1: Uint8Array;\n betaG2: Uint8Array;\n gammaG2: Uint8Array;\n deltaG2: Uint8Array;\n k: Uint8Array[];\n} {\n const vkBytes = base64ToBytes(vkBase64);\n const expectedLen = G1_SIZE + G2_SIZE * 3 + G1_SIZE * (nrPubinputs + 1);\n\n if (vkBytes.length !== expectedLen) {\n throw new Error(\n `Invalid VK size: expected ${expectedLen} bytes for ${nrPubinputs} public inputs, got ${vkBytes.length}`\n );\n }\n\n let offset = 0;\n\n const alphaG1 = vkBytes.slice(offset, offset + G1_SIZE);\n offset += G1_SIZE;\n\n const betaG2 = vkBytes.slice(offset, offset + G2_SIZE);\n offset += G2_SIZE;\n\n const gammaG2 = vkBytes.slice(offset, offset + G2_SIZE);\n offset += G2_SIZE;\n\n const deltaG2 = vkBytes.slice(offset, offset + G2_SIZE);\n offset += G2_SIZE;\n\n const k: Uint8Array[] = [];\n for (let i = 0; i <= nrPubinputs; i++) {\n k.push(vkBytes.slice(offset, offset + G1_SIZE));\n offset += G1_SIZE;\n }\n\n return { alphaG1, betaG2, gammaG2, deltaG2, k };\n}\n\n/**\n * Parses a base64-encoded proof into its components.\n *\n * The proof format is: A (G1, 64) || B (G2, 128) || C (G1, 64) = 256 bytes\n *\n * @param proofBase64 - Base64-encoded proof\n * @returns Parsed proof components\n */\nexport function parseProof(proofBase64: string): {\n a: Uint8Array;\n b: Uint8Array;\n c: Uint8Array;\n} {\n const proofBytes = base64ToBytes(proofBase64);\n\n if (proofBytes.length !== PROOF_SIZE) {\n throw new Error(`Invalid proof size: expected ${PROOF_SIZE} bytes, got ${proofBytes.length}`);\n }\n\n return {\n a: proofBytes.slice(0, G1_SIZE),\n b: proofBytes.slice(G1_SIZE, G1_SIZE + G2_SIZE),\n c: proofBytes.slice(G1_SIZE + G2_SIZE, PROOF_SIZE),\n };\n}\n\n/**\n * Parses public inputs from hex or decimal string format to 32-byte arrays.\n *\n * @param inputs - Array of public inputs as hex (0x...) or decimal strings\n * @returns Array of 32-byte big-endian field elements\n */\nexport function parsePublicInputs(inputs: string[]): Uint8Array[] {\n return inputs.map((input) => {\n // Handle hex strings\n if (input.startsWith('0x')) {\n const hex = input.slice(2).padStart(64, '0');\n return hexToBytes(hex);\n }\n\n // Handle decimal strings - convert to big-endian bytes\n const num = BigInt(input);\n const hex = num.toString(16).padStart(64, '0');\n return hexToBytes(hex);\n });\n}\n\n/**\n * Calculates the size of a VK account for a given number of public inputs.\n *\n * This matches the Rust `vk_account_size` function.\n *\n * @param nrPubinputs - Number of public inputs\n * @returns Account size in bytes\n */\nexport function calculateVkAccountSize(nrPubinputs: number): number {\n // discriminator (8) + authority (32) + nr_pubinputs (1) + alpha_g1 (64) +\n // beta_g2 (128) + gamma_g2 (128) + delta_g2 (128) + vec_len (4) + k elements\n const fixedSize = 8 + 32 + 1 + G1_SIZE + G2_SIZE * 3 + 4;\n return fixedSize + (nrPubinputs + 1) * G1_SIZE;\n}\n\n/**\n * Calculates the minimum rent for a VK account.\n *\n * @param nrPubinputs - Number of public inputs\n * @param rentExemptionPerByte - Rent per byte (default Solana rate)\n * @returns Rent in lamports\n */\nexport function calculateVkAccountRent(\n nrPubinputs: number,\n rentExemptionPerByte: number = 6960 // approximate lamports per byte\n): number {\n const size = calculateVkAccountSize(nrPubinputs);\n return size * rentExemptionPerByte;\n}\n\n// ========== Helper Functions ==========\n\n/**\n * Converts a base64 string to a Uint8Array.\n */\nfunction base64ToBytes(base64: string): Uint8Array {\n // Browser-compatible base64 decoding\n if (typeof atob === 'function') {\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n }\n // Node.js fallback\n return new Uint8Array(Buffer.from(base64, 'base64'));\n}\n\n/**\n * Converts a Uint8Array to a base64 string.\n */\nexport function bytesToBase64(bytes: Uint8Array): string {\n // Browser-compatible base64 encoding\n if (typeof btoa === 'function') {\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n }\n // Node.js fallback\n return Buffer.from(bytes).toString('base64');\n}\n\n/**\n * Converts a hex string to Uint8Array.\n */\nfunction hexToBytes(hex: string): Uint8Array {\n const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex;\n const bytes = new Uint8Array(cleanHex.length / 2);\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = parseInt(cleanHex.substring(i * 2, i * 2 + 2), 16);\n }\n return bytes;\n}\n\n/**\n * Converts a Uint8Array to hex string.\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n return Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n}\n\n// ========== Instruction Data Builders ==========\n\n/**\n * Builds the instruction data for `init_vk_from_bytes`.\n *\n * Note: This is a simplified version. In practice, you'd use Anchor's IDL\n * and instruction builders from the generated types.\n *\n * @param nrPubinputs - Number of public inputs\n * @param vkBytes - Raw VK bytes\n * @returns Instruction data\n */\nexport function buildInitVkFromBytesData(nrPubinputs: number, vkBytes: Uint8Array): Uint8Array {\n // Anchor instruction discriminator for \"init_vk_from_bytes\"\n // From IDL: [103, 78, 249, 70, 245, 176, 87, 56]\n const discriminator = new Uint8Array([103, 78, 249, 70, 245, 176, 87, 56]);\n\n // Build instruction data: discriminator + nr_pubinputs (u8) + vk_bytes (Vec<u8>)\n const vkLen = new Uint8Array(4);\n new DataView(vkLen.buffer).setUint32(0, vkBytes.length, true); // little-endian\n\n const data = new Uint8Array(discriminator.length + 1 + 4 + vkBytes.length);\n let offset = 0;\n\n data.set(discriminator, offset);\n offset += discriminator.length;\n\n data[offset] = nrPubinputs;\n offset += 1;\n\n data.set(vkLen, offset);\n offset += 4;\n\n data.set(vkBytes, offset);\n\n return data;\n}\n\n/**\n * Builds the instruction data for `verify_proof`.\n *\n * @param proofBytes - 256-byte proof\n * @param publicInputs - Array of 32-byte field elements\n * @returns Instruction data\n */\nexport function buildVerifyProofData(\n proofBytes: Uint8Array,\n publicInputs: Uint8Array[]\n): Uint8Array {\n // Anchor instruction discriminator for \"verify_proof\"\n // From IDL: [217, 211, 191, 110, 144, 13, 186, 98]\n const discriminator = new Uint8Array([217, 211, 191, 110, 144, 13, 186, 98]);\n\n // Validate proof size\n if (proofBytes.length !== PROOF_SIZE) {\n throw new Error(`Invalid proof size: expected ${PROOF_SIZE}, got ${proofBytes.length}`);\n }\n\n // Calculate total size\n const proofVecLen = 4 + proofBytes.length;\n const inputsVecLen = 4 + publicInputs.length * FIELD_SIZE;\n const totalSize = discriminator.length + proofVecLen + inputsVecLen;\n\n const data = new Uint8Array(totalSize);\n let offset = 0;\n\n // Discriminator\n data.set(discriminator, offset);\n offset += discriminator.length;\n\n // proof_bytes as Vec<u8>\n new DataView(data.buffer).setUint32(offset, proofBytes.length, true);\n offset += 4;\n data.set(proofBytes, offset);\n offset += proofBytes.length;\n\n // public_inputs as Vec<[u8; 32]>\n new DataView(data.buffer).setUint32(offset, publicInputs.length, true);\n offset += 4;\n for (const input of publicInputs) {\n if (input.length !== FIELD_SIZE) {\n throw new Error(`Invalid public input size: expected ${FIELD_SIZE}, got ${input.length}`);\n }\n data.set(input, offset);\n offset += FIELD_SIZE;\n }\n\n return data;\n}\n\n/**\n * Type definition for the Anchor IDL accounts structure.\n * This helps with type safety when building transactions.\n */\nexport interface IziNoirAccounts {\n initVk: {\n vkAccount: string;\n authority: string;\n payer: string;\n systemProgram: string;\n };\n verifyProof: {\n vkAccount: string;\n };\n closeVk: {\n vkAccount: string;\n authority: string;\n };\n}\n\n/**\n * Placeholder class for SolanaVerifier.\n *\n * This class provides the interface for on-chain verification but requires\n * @solana/web3.js and @coral-xyz/anchor to be installed as peer dependencies.\n *\n * For full functionality, install the required dependencies:\n * ```bash\n * npm install @solana/web3.js @coral-xyz/anchor\n * ```\n *\n * Then use the generated Anchor client from the solana-contracts package.\n */\nexport class SolanaVerifier {\n private config: SolanaVerifierConfig;\n\n constructor(config: SolanaVerifierConfig) {\n this.config = config;\n }\n\n /**\n * Initializes a VK account from base64-encoded verifying key.\n *\n * Note: This is a placeholder. Use the generated Anchor client for\n * actual transaction building and submission.\n */\n async initVkFromBase64(vkBase64: string, nrPubinputs: number): Promise<InitVkResult> {\n // Parse and validate VK\n const vkBytes = base64ToBytes(vkBase64);\n const expectedLen = G1_SIZE + G2_SIZE * 3 + G1_SIZE * (nrPubinputs + 1);\n\n if (vkBytes.length !== expectedLen) {\n throw new Error(\n `Invalid VK size: expected ${expectedLen} bytes for ${nrPubinputs} public inputs, got ${vkBytes.length}`\n );\n }\n\n // This is a placeholder - actual implementation would use Anchor client\n throw new Error(\n 'SolanaVerifier.initVkFromBase64 requires @solana/web3.js and @coral-xyz/anchor. ' +\n 'Use the generated Anchor client from solana-contracts package.'\n );\n }\n\n /**\n * Verifies a proof on-chain.\n *\n * Note: This is a placeholder. Use the generated Anchor client for\n * actual transaction building and submission.\n */\n async verifyProof(\n vkAccount: string,\n proofBase64: string,\n publicInputs: string[]\n ): Promise<VerifyResult> {\n // Parse and validate proof\n const proofBytes = base64ToBytes(proofBase64);\n if (proofBytes.length !== PROOF_SIZE) {\n throw new Error(`Invalid proof size: expected ${PROOF_SIZE}, got ${proofBytes.length}`);\n }\n\n // This is a placeholder - actual implementation would use Anchor client\n throw new Error(\n 'SolanaVerifier.verifyProof requires @solana/web3.js and @coral-xyz/anchor. ' +\n 'Use the generated Anchor client from solana-contracts package.'\n );\n }\n\n /**\n * Closes a VK account and reclaims rent.\n *\n * Note: This is a placeholder. Use the generated Anchor client for\n * actual transaction building and submission.\n */\n async closeVk(vkAccount: string): Promise<string> {\n throw new Error(\n 'SolanaVerifier.closeVk requires @solana/web3.js and @coral-xyz/anchor. ' +\n 'Use the generated Anchor client from solana-contracts package.'\n );\n }\n}\n\n// Re-export common types\nexport type { CompiledCircuit, InputMap, ProofData } from '../domain/types.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoCO,IAAM,UAAU;AAChB,IAAM,UAAU;AAChB,IAAM,aAAa;AACnB,IAAM,aAAa;AACnB,IAAM,oBAAoB;AAG1B,IAAM,sBAAsB;AAyD5B,SAAS,kBAAkB,UAAkB,aAMlD;AACA,QAAM,UAAU,cAAc,QAAQ;AACtC,QAAM,cAAc,UAAU,UAAU,IAAI,WAAW,cAAc;AAErE,MAAI,QAAQ,WAAW,aAAa;AAClC,UAAM,IAAI;AAAA,MACR,6BAA6B,WAAW,cAAc,WAAW,uBAAuB,QAAQ,MAAM;AAAA,IACxG;AAAA,EACF;AAEA,MAAI,SAAS;AAEb,QAAM,UAAU,QAAQ,MAAM,QAAQ,SAAS,OAAO;AACtD,YAAU;AAEV,QAAM,SAAS,QAAQ,MAAM,QAAQ,SAAS,OAAO;AACrD,YAAU;AAEV,QAAM,UAAU,QAAQ,MAAM,QAAQ,SAAS,OAAO;AACtD,YAAU;AAEV,QAAM,UAAU,QAAQ,MAAM,QAAQ,SAAS,OAAO;AACtD,YAAU;AAEV,QAAM,IAAkB,CAAC;AACzB,WAAS,IAAI,GAAG,KAAK,aA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,aAAa;AAClC,YAAM,IAAI;AAAA,QACR,6BAA6B,WAAW,cAAc,WAAW,uBAAuB,QAAQ,MAAM;AAAA,MACxG;AAAA,IACF;AAGA,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,YACJ,WACA,aACA,cACuB;AAEvB,UAAM,aAAa,cAAc,WAAW;AAC5C,QAAI,WAAW,WAAW,YAAY;AACpC,YAAM,IAAI,MAAM,gCAAgC,UAAU,SAAS,WAAW,MAAM,EAAE;AAAA,IACxF;AAGA,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,QAAQ,WAAoC;AAChD,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACF;","names":["hex"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/providers/solana.ts"],"sourcesContent":["/**\n * Solana on-chain verification provider for IZI-NOIR.\n *\n * This module provides functionality to verify Groth16 proofs on-chain using\n * the IZI-NOIR Solana program. It's compatible with proofs generated by the\n * Arkworks provider.\n *\n * @example Basic usage\n * ```typescript\n * import { SolanaVerifier } from '@izi-noir/sdk/solana';\n * import { Connection, Keypair } from '@solana/web3.js';\n *\n * const connection = new Connection('https://api.devnet.solana.com');\n * const wallet = Keypair.generate(); // In practice, use a real wallet\n *\n * const verifier = new SolanaVerifier({\n * connection,\n * wallet,\n * programId: 'EYhRED7EuMyyVjx57aDXUD9h6ArnEKng64qtz8999KrS',\n * });\n *\n * // Initialize a VK account from base64-encoded VK\n * const vkAccount = await verifier.initVkFromBase64(vkGnarkBase64, nrPubinputs);\n *\n * // Verify a proof on-chain\n * const txSig = await verifier.verifyProof(\n * vkAccount,\n * proofGnarkBase64,\n * publicInputsHex\n * );\n * ```\n *\n * @module @izi-noir/sdk/solana\n */\n\n// Constants matching the Solana program\nexport const G1_SIZE = 64;\nexport const G2_SIZE = 128;\nexport const FIELD_SIZE = 32;\nexport const PROOF_SIZE = 256;\nexport const MAX_PUBLIC_INPUTS = 16;\n\n// Program ID - deployed on devnet\nexport const IZI_NOIR_PROGRAM_ID = 'EYhRED7EuMyyVjx57aDXUD9h6ArnEKng64qtz8999KrS';\n\n/**\n * Configuration for the SolanaVerifier.\n */\nexport interface SolanaVerifierConfig {\n /**\n * Solana RPC connection.\n * Must be compatible with @solana/web3.js Connection.\n */\n connection: unknown;\n\n /**\n * Wallet for signing transactions.\n * Can be a Keypair or any wallet adapter compatible signer.\n */\n wallet: unknown;\n\n /**\n * Program ID of the deployed IZI-NOIR verifier program.\n * Defaults to the placeholder ID.\n */\n programId?: string;\n}\n\n/**\n * Result from initializing a VK account.\n */\nexport interface InitVkResult {\n /** The public key of the created VK account */\n vkAccount: string;\n /** The transaction signature */\n txSignature: string;\n}\n\n/**\n * Result from verifying a proof on-chain.\n */\nexport interface VerifyResult {\n /** Whether the proof was verified successfully */\n success: boolean;\n /** The transaction signature */\n txSignature: string;\n /** Error message if verification failed */\n error?: string;\n}\n\n/**\n * Parses a base64-encoded verifying key into its components.\n *\n * The VK format from arkworks gnark_compat is:\n * | alpha_g1 (64) | beta_g2 (128) | gamma_g2 (128) | delta_g2 (128) | k[0..n+1] (64 each) |\n *\n * @param vkBase64 - Base64-encoded verifying key\n * @param nrPubinputs - Number of public inputs\n * @returns Parsed VK components\n */\nexport function parseVerifyingKey(vkBase64: string, nrPubinputs: number): {\n alphaG1: Uint8Array;\n betaG2: Uint8Array;\n gammaG2: Uint8Array;\n deltaG2: Uint8Array;\n k: Uint8Array[];\n} {\n const vkBytes = base64ToBytes(vkBase64);\n const expectedLen = G1_SIZE + G2_SIZE * 3 + G1_SIZE * (nrPubinputs + 1);\n\n if (vkBytes.length !== expectedLen) {\n throw new Error(\n `Invalid VK size: expected ${expectedLen} bytes for ${nrPubinputs} public inputs, got ${vkBytes.length}`\n );\n }\n\n let offset = 0;\n\n const alphaG1 = vkBytes.slice(offset, offset + G1_SIZE);\n offset += G1_SIZE;\n\n const betaG2 = vkBytes.slice(offset, offset + G2_SIZE);\n offset += G2_SIZE;\n\n const gammaG2 = vkBytes.slice(offset, offset + G2_SIZE);\n offset += G2_SIZE;\n\n const deltaG2 = vkBytes.slice(offset, offset + G2_SIZE);\n offset += G2_SIZE;\n\n const k: Uint8Array[] = [];\n for (let i = 0; i <= nrPubinputs; i++) {\n k.push(vkBytes.slice(offset, offset + G1_SIZE));\n offset += G1_SIZE;\n }\n\n return { alphaG1, betaG2, gammaG2, deltaG2, k };\n}\n\n/**\n * Parses a base64-encoded proof into its components.\n *\n * The proof format is: A (G1, 64) || B (G2, 128) || C (G1, 64) = 256 bytes\n *\n * @param proofBase64 - Base64-encoded proof\n * @returns Parsed proof components\n */\nexport function parseProof(proofBase64: string): {\n a: Uint8Array;\n b: Uint8Array;\n c: Uint8Array;\n} {\n const proofBytes = base64ToBytes(proofBase64);\n\n if (proofBytes.length !== PROOF_SIZE) {\n throw new Error(`Invalid proof size: expected ${PROOF_SIZE} bytes, got ${proofBytes.length}`);\n }\n\n return {\n a: proofBytes.slice(0, G1_SIZE),\n b: proofBytes.slice(G1_SIZE, G1_SIZE + G2_SIZE),\n c: proofBytes.slice(G1_SIZE + G2_SIZE, PROOF_SIZE),\n };\n}\n\n/**\n * Parses public inputs from hex or decimal string format to 32-byte arrays.\n *\n * @param inputs - Array of public inputs as hex (0x...) or decimal strings\n * @returns Array of 32-byte big-endian field elements\n */\nexport function parsePublicInputs(inputs: string[]): Uint8Array[] {\n return inputs.map((input) => {\n // Handle hex strings\n if (input.startsWith('0x')) {\n const hex = input.slice(2).padStart(64, '0');\n return hexToBytes(hex);\n }\n\n // Handle decimal strings - convert to big-endian bytes\n const num = BigInt(input);\n const hex = num.toString(16).padStart(64, '0');\n return hexToBytes(hex);\n });\n}\n\n/**\n * Calculates the size of a VK account for a given number of public inputs.\n *\n * This matches the Rust `vk_account_size` function.\n *\n * @param nrPubinputs - Number of public inputs\n * @returns Account size in bytes\n */\nexport function calculateVkAccountSize(nrPubinputs: number): number {\n // discriminator (8) + authority (32) + nr_pubinputs (1) + alpha_g1 (64) +\n // beta_g2 (128) + gamma_g2 (128) + delta_g2 (128) + vec_len (4) + k elements\n const fixedSize = 8 + 32 + 1 + G1_SIZE + G2_SIZE * 3 + 4;\n return fixedSize + (nrPubinputs + 1) * G1_SIZE;\n}\n\n/**\n * Calculates the minimum rent for a VK account.\n *\n * @param nrPubinputs - Number of public inputs\n * @param rentExemptionPerByte - Rent per byte (default Solana rate)\n * @returns Rent in lamports\n */\nexport function calculateVkAccountRent(\n nrPubinputs: number,\n rentExemptionPerByte: number = 6960 // approximate lamports per byte\n): number {\n const size = calculateVkAccountSize(nrPubinputs);\n return size * rentExemptionPerByte;\n}\n\n// ========== Helper Functions ==========\n\n/**\n * Converts a base64 string to a Uint8Array.\n */\nfunction base64ToBytes(base64: string): Uint8Array {\n // Browser-compatible base64 decoding\n if (typeof atob === 'function') {\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n }\n // Node.js fallback\n return new Uint8Array(Buffer.from(base64, 'base64'));\n}\n\n/**\n * Converts a Uint8Array to a base64 string.\n */\nexport function bytesToBase64(bytes: Uint8Array): string {\n // Browser-compatible base64 encoding\n if (typeof btoa === 'function') {\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n }\n // Node.js fallback\n return Buffer.from(bytes).toString('base64');\n}\n\n/**\n * Converts a hex string to Uint8Array.\n */\nfunction hexToBytes(hex: string): Uint8Array {\n const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex;\n const bytes = new Uint8Array(cleanHex.length / 2);\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = parseInt(cleanHex.substring(i * 2, i * 2 + 2), 16);\n }\n return bytes;\n}\n\n/**\n * Converts a Uint8Array to hex string.\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n return Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n}\n\n// ========== Instruction Data Builders ==========\n\n/**\n * Builds the instruction data for `init_vk_from_bytes`.\n *\n * Note: This is a simplified version. In practice, you'd use Anchor's IDL\n * and instruction builders from the generated types.\n *\n * @param nrPubinputs - Number of public inputs\n * @param vkBytes - Raw VK bytes\n * @returns Instruction data\n */\nexport function buildInitVkFromBytesData(nrPubinputs: number, vkBytes: Uint8Array): Uint8Array {\n // Anchor instruction discriminator for \"init_vk_from_bytes\"\n // From IDL: [103, 78, 249, 70, 245, 176, 87, 56]\n const discriminator = new Uint8Array([103, 78, 249, 70, 245, 176, 87, 56]);\n\n // Build instruction data: discriminator + nr_pubinputs (u8) + vk_bytes (Vec<u8>)\n const vkLen = new Uint8Array(4);\n new DataView(vkLen.buffer).setUint32(0, vkBytes.length, true); // little-endian\n\n const data = new Uint8Array(discriminator.length + 1 + 4 + vkBytes.length);\n let offset = 0;\n\n data.set(discriminator, offset);\n offset += discriminator.length;\n\n data[offset] = nrPubinputs;\n offset += 1;\n\n data.set(vkLen, offset);\n offset += 4;\n\n data.set(vkBytes, offset);\n\n return data;\n}\n\n/**\n * Builds the instruction data for `verify_proof`.\n *\n * @param proofBytes - 256-byte proof\n * @param publicInputs - Array of 32-byte field elements\n * @returns Instruction data\n */\nexport function buildVerifyProofData(\n proofBytes: Uint8Array,\n publicInputs: Uint8Array[]\n): Uint8Array {\n // Anchor instruction discriminator for \"verify_proof\"\n // From IDL: [217, 211, 191, 110, 144, 13, 186, 98]\n const discriminator = new Uint8Array([217, 211, 191, 110, 144, 13, 186, 98]);\n\n // Validate proof size\n if (proofBytes.length !== PROOF_SIZE) {\n throw new Error(`Invalid proof size: expected ${PROOF_SIZE}, got ${proofBytes.length}`);\n }\n\n // Calculate total size\n const proofVecLen = 4 + proofBytes.length;\n const inputsVecLen = 4 + publicInputs.length * FIELD_SIZE;\n const totalSize = discriminator.length + proofVecLen + inputsVecLen;\n\n const data = new Uint8Array(totalSize);\n let offset = 0;\n\n // Discriminator\n data.set(discriminator, offset);\n offset += discriminator.length;\n\n // proof_bytes as Vec<u8>\n new DataView(data.buffer).setUint32(offset, proofBytes.length, true);\n offset += 4;\n data.set(proofBytes, offset);\n offset += proofBytes.length;\n\n // public_inputs as Vec<[u8; 32]>\n new DataView(data.buffer).setUint32(offset, publicInputs.length, true);\n offset += 4;\n for (const input of publicInputs) {\n if (input.length !== FIELD_SIZE) {\n throw new Error(`Invalid public input size: expected ${FIELD_SIZE}, got ${input.length}`);\n }\n data.set(input, offset);\n offset += FIELD_SIZE;\n }\n\n return data;\n}\n\n/**\n * Type definition for the Anchor IDL accounts structure.\n * This helps with type safety when building transactions.\n */\nexport interface IziNoirAccounts {\n initVk: {\n vkAccount: string;\n authority: string;\n payer: string;\n systemProgram: string;\n };\n verifyProof: {\n vkAccount: string;\n };\n closeVk: {\n vkAccount: string;\n authority: string;\n };\n}\n\n/**\n * Placeholder class for SolanaVerifier.\n *\n * This class provides the interface for on-chain verification but requires\n * @solana/web3.js and @coral-xyz/anchor to be installed as peer dependencies.\n *\n * For full functionality, install the required dependencies:\n * ```bash\n * npm install @solana/web3.js @coral-xyz/anchor\n * ```\n *\n * Then use the generated Anchor client from the solana-contracts package.\n */\nexport class SolanaVerifier {\n private config: SolanaVerifierConfig;\n\n constructor(config: SolanaVerifierConfig) {\n this.config = config;\n }\n\n /**\n * Initializes a VK account from base64-encoded verifying key.\n *\n * Note: This is a placeholder. Use the generated Anchor client for\n * actual transaction building and submission.\n */\n async initVkFromBase64(vkBase64: string, nrPubinputs: number): Promise<InitVkResult> {\n // Parse and validate VK\n const vkBytes = base64ToBytes(vkBase64);\n const expectedLen = G1_SIZE + G2_SIZE * 3 + G1_SIZE * (nrPubinputs + 1);\n\n if (vkBytes.length !== expectedLen) {\n throw new Error(\n `Invalid VK size: expected ${expectedLen} bytes for ${nrPubinputs} public inputs, got ${vkBytes.length}`\n );\n }\n\n // This is a placeholder - actual implementation would use Anchor client\n throw new Error(\n 'SolanaVerifier.initVkFromBase64 requires @solana/web3.js and @coral-xyz/anchor. ' +\n 'Use the generated Anchor client from solana-contracts package.'\n );\n }\n\n /**\n * Verifies a proof on-chain.\n *\n * Note: This is a placeholder. Use the generated Anchor client for\n * actual transaction building and submission.\n */\n async verifyProof(\n vkAccount: string,\n proofBase64: string,\n publicInputs: string[]\n ): Promise<VerifyResult> {\n // Parse and validate proof\n const proofBytes = base64ToBytes(proofBase64);\n if (proofBytes.length !== PROOF_SIZE) {\n throw new Error(`Invalid proof size: expected ${PROOF_SIZE}, got ${proofBytes.length}`);\n }\n\n // This is a placeholder - actual implementation would use Anchor client\n throw new Error(\n 'SolanaVerifier.verifyProof requires @solana/web3.js and @coral-xyz/anchor. ' +\n 'Use the generated Anchor client from solana-contracts package.'\n );\n }\n\n /**\n * Closes a VK account and reclaims rent.\n *\n * Note: This is a placeholder. Use the generated Anchor client for\n * actual transaction building and submission.\n */\n async closeVk(vkAccount: string): Promise<string> {\n throw new Error(\n 'SolanaVerifier.closeVk requires @solana/web3.js and @coral-xyz/anchor. ' +\n 'Use the generated Anchor client from solana-contracts package.'\n );\n }\n}\n\n// Re-export common types\nexport type { CompiledCircuit, InputMap, ProofData } from '../domain/types.js';\n"],"mappings":";AAoCO,IAAM,UAAU;AAChB,IAAM,UAAU;AAChB,IAAM,aAAa;AACnB,IAAM,aAAa;AACnB,IAAM,oBAAoB;AAG1B,IAAM,sBAAsB;AAyD5B,SAAS,kBAAkB,UAAkB,aAMlD;AACA,QAAM,UAAU,cAAc,QAAQ;AACtC,QAAM,cAAc,UAAU,UAAU,IAAI,WAAW,cAAc;AAErE,MAAI,QAAQ,WAAW,aAAa;AAClC,UAAM,IAAI;AAAA,MACR,6BAA6B,WAAW,cAAc,WAAW,uBAAuB,QAAQ,MAAM;AAAA,IACxG;AAAA,EACF;AAEA,MAAI,SAAS;AAE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AAAA,EACZ;AAEA,SAAO;AACT;AAmCO,IAAM,iBAAN,MAAqB;AAAA,EAClB;AAAA,EAER,YAAY,QAA8B;AACxC,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,iBAAiB,UAAkB,aAA4C;AAEnF,UAAM,UAAU,cAAc,QAAQ;AACtC,UAAM,cAAc,UAAU,UAAU,IAAI,WAAW,cAAc;AAErE,QAAI,QAAQ,WAAW,aAAa;AAClC,YAAM,IAAI;AAAA,QACR,6BAA6B,WAAW,cAAc,WAAW,uBAAuB,QAAQ,MAAM;AAAA,MACxG;AAAA,IACF;AAGA,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,YACJ,WACA,aACA,cACuB;AAEvB,UAAM,aAAa,cAAc,WAAW;AAC5C,QAAI,WAAW,WAAW,YAAY;AACpC,YAAM,IAAI,MAAM,gCAAgC,UAAU,SAAS,WAAW,MAAM,EAAE;AAAA,IACxF;AAGA,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,QAAQ,WAAoC;AAChD,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACF;","names":["hex"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/providers/sunspot.ts","../../src/infra/provingSystems/Sunspot.ts","../../src/infra/sunspot/types.ts","../../src/infra/sunspot/SunspotCliExecutor.ts","../../src/domain/types/provider.ts"],"sourcesContent":["/**\n * Sunspot entry point for Node.js.\n *\n * This module provides Sunspot support which is NOT available in the main\n * `@izi-noir/sdk` entry point due to Node.js-only dependencies.\n *\n * Note: Sunspot requires nargo and sunspot CLI tools to be installed.\n *\n * @example Using Sunspot directly\n * ```typescript\n * import { Sunspot } from '@izi-noir/sdk/sunspot';\n *\n * // Full compilation mode\n * const sunspot = new Sunspot();\n * const circuit = await sunspot.compile(noirCode);\n * const proof = await sunspot.generateProof(circuit, inputs);\n * const verified = await sunspot.verifyProof(circuit, proof.proof, proof.publicInputs);\n *\n * // Pre-compiled mode\n * const sunspot = new Sunspot({\n * pkPath: './circuit/circuit.pk',\n * vkPath: './circuit/circuit.vk',\n * circuitPath: './circuit/circuit.json',\n * });\n * ```\n *\n * @example Using initSunspotIziNoir helper\n * ```typescript\n * import { initSunspotIziNoir } from '@izi-noir/sdk/sunspot';\n *\n * const izi = await initSunspotIziNoir({\n * pkPath: './circuit/circuit.pk',\n * vkPath: './circuit/circuit.vk',\n * circuitPath: './circuit/circuit.json',\n * });\n *\n * // Use like regular IziNoir (but only prove/verify, not compile)\n * const proof = await izi.prove(inputs);\n * const verified = await izi.verify(proof.proof, proof.publicInputs);\n * ```\n *\n * @module @izi-noir/sdk/sunspot\n */\n\nimport type { IProvingSystem } from '../domain/interfaces/proving/IProvingSystem.js';\nimport type { CompiledCircuit, InputMap, ProofData } from '../domain/types.js';\nimport type { CircuitPaths } from '../domain/types/provider.js';\nimport { Sunspot } from '../infra/provingSystems/Sunspot.js';\n\nexport { Sunspot } from '../infra/provingSystems/Sunspot.js';\nexport type { SunspotInitConfig } from '../infra/provingSystems/Sunspot.js';\nexport type {\n SunspotConfig,\n SunspotCircuitPaths,\n SunspotCompiledCircuit,\n} from '../infra/sunspot/types.js';\nexport { isSunspotCircuit, SunspotCliError } from '../infra/sunspot/types.js';\n\n// Re-export common types\nexport { Provider, type IziNoirConfig, type CircuitPaths } from '../domain/types/provider.js';\nexport type { CompiledCircuit, InputMap, ProofData } from '../domain/types.js';\nexport type { IProvingSystem } from '../domain/interfaces/proving/IProvingSystem.js';\n\n/**\n * IziNoir-like wrapper for Sunspot.\n * Provides a similar API to IziNoir but backed by the Sunspot proving system.\n */\nexport class IziNoirSunspot {\n private provingSystem: IProvingSystem;\n private compiledCircuit: CompiledCircuit | null = null;\n\n private constructor(provingSystem: IProvingSystem) {\n this.provingSystem = provingSystem;\n }\n\n /**\n * Initialize IziNoirSunspot with pre-compiled circuit paths.\n * Note: Sunspot requires pre-compiled circuits for prove/verify operations.\n *\n * @param circuitPaths - Paths to the pre-compiled circuit files\n */\n static async init(circuitPaths: CircuitPaths): Promise<IziNoirSunspot> {\n const sunspot = new Sunspot(circuitPaths);\n return new IziNoirSunspot(sunspot);\n }\n\n /**\n * Initialize IziNoirSunspot for full compilation mode.\n * Requires nargo and sunspot CLI tools to be installed.\n */\n static async initForCompilation(): Promise<IziNoirSunspot> {\n const sunspot = new Sunspot();\n return new IziNoirSunspot(sunspot);\n }\n\n getProvingSystem(): IProvingSystem {\n return this.provingSystem;\n }\n\n getCompiledCircuit(): CompiledCircuit | null {\n return this.compiledCircuit;\n }\n\n async compile(noirCode: string): Promise<CompiledCircuit> {\n this.compiledCircuit = await this.provingSystem.compile(noirCode);\n return this.compiledCircuit;\n }\n\n async prove(inputs: InputMap, circuit?: CompiledCircuit): Promise<ProofData> {\n const circuitToUse = circuit || this.compiledCircuit;\n if (!circuitToUse) {\n throw new Error('No circuit available. Call compile() first or provide a circuit.');\n }\n return this.provingSystem.generateProof(circuitToUse, inputs);\n }\n\n async verify(\n proof: Uint8Array,\n publicInputs: string[],\n circuit?: CompiledCircuit\n ): Promise<boolean> {\n const circuitToUse = circuit || this.compiledCircuit;\n if (!circuitToUse) {\n throw new Error('No circuit available. Call compile() first or provide a circuit.');\n }\n return this.provingSystem.verifyProof(circuitToUse, proof, publicInputs);\n }\n\n async createProof(\n noirCode: string,\n inputs: InputMap\n ): Promise<{ proof: ProofData; verified: boolean }> {\n const circuit = await this.compile(noirCode);\n const proof = await this.prove(inputs, circuit);\n const verified = await this.verify(proof.proof, proof.publicInputs, circuit);\n return { proof, verified };\n }\n}\n\n/**\n * Helper function to create an IziNoirSunspot instance with pre-compiled circuit paths.\n * @deprecated Use `IziNoirSunspot.init(circuitPaths)` instead.\n */\nexport async function initSunspotIziNoir(circuitPaths: CircuitPaths): Promise<IziNoirSunspot> {\n return IziNoirSunspot.init(circuitPaths);\n}\n","import { readFile, writeFile, rm, mkdtemp, mkdir } from 'node:fs/promises';\nimport { join, dirname } from 'node:path';\nimport { tmpdir } from 'node:os';\nimport type { IProvingSystem } from '../../domain/interfaces/proving/IProvingSystem.js';\nimport type { CompiledCircuit, InputMap, ProofData } from '../../domain/types.js';\nimport type { SunspotConfig, SunspotCircuitPaths, SunspotCompiledCircuit } from '../sunspot/types.js';\nimport { DEFAULT_SUNSPOT_CONFIG, isSunspotCircuit, SunspotCliError } from '../sunspot/types.js';\nimport { SunspotCliExecutor } from '../sunspot/SunspotCliExecutor.js';\nimport type { CircuitPaths } from '../../domain/types/provider.js';\n\n/**\n * Configuration for Sunspot constructor\n */\nexport interface SunspotInitConfig extends Partial<SunspotConfig> {\n /** Pre-compiled circuit paths (if provided, compile() is disabled) */\n precompiledPaths?: CircuitPaths;\n}\n\n/**\n * Sunspot proving system using CLI tools.\n * Node.js only (requires nargo and sunspot binaries).\n * Produces Groth16 proofs (~324 bytes) for Solana on-chain verification.\n *\n * Can be used in two modes:\n * 1. Full compilation: Call compile() with Noir code (requires nargo + sunspot CLI)\n * 2. Pre-compiled: Provide circuitPaths in constructor, then only prove/verify\n *\n * @example Full compilation\n * ```typescript\n * const sunspot = new Sunspot();\n * const circuit = await sunspot.compile(noirCode);\n * const proof = await sunspot.generateProof(circuit, inputs);\n * ```\n *\n * @example Pre-compiled (via IziNoir)\n * ```typescript\n * const izi = await IziNoir.init({\n * provider: Provider.Sunspot,\n * circuitPaths: { pkPath: '...', vkPath: '...', circuitPath: '...' }\n * });\n * ```\n */\nexport class Sunspot implements IProvingSystem {\n private readonly config: SunspotConfig;\n private readonly executor: SunspotCliExecutor;\n private readonly precompiledPaths?: CircuitPaths;\n private precompiledCircuit?: SunspotCompiledCircuit;\n\n /**\n * Create a new Sunspot proving system\n * @param config - Configuration options or pre-compiled circuit paths\n */\n constructor(config: SunspotInitConfig | CircuitPaths = {}) {\n // Check if config is CircuitPaths (has pkPath, vkPath, circuitPath)\n if ('pkPath' in config && 'vkPath' in config && 'circuitPath' in config) {\n this.config = { ...DEFAULT_SUNSPOT_CONFIG };\n this.precompiledPaths = config as CircuitPaths;\n } else {\n const initConfig = config as SunspotInitConfig;\n this.config = { ...DEFAULT_SUNSPOT_CONFIG, ...initConfig };\n this.precompiledPaths = initConfig.precompiledPaths;\n }\n\n this.executor = new SunspotCliExecutor(this.config);\n\n // If pre-compiled paths provided, create a dummy circuit object\n if (this.precompiledPaths) {\n this.precompiledCircuit = this.createPrecompiledCircuit(this.precompiledPaths);\n }\n }\n\n /**\n * Create a SunspotCompiledCircuit from pre-compiled paths\n */\n private createPrecompiledCircuit(paths: CircuitPaths): SunspotCompiledCircuit {\n const baseDir = dirname(paths.circuitPath);\n return {\n bytecode: '', // Not needed for prove/verify with pre-compiled\n abi: { parameters: [], return_type: null, error_types: {} },\n debug_symbols: '',\n file_map: {},\n __sunspot: true,\n paths: {\n workDir: baseDir,\n noirProjectDir: baseDir,\n circuitJsonPath: paths.circuitPath,\n witnessPath: join(baseDir, 'circuit.gz'),\n ccsPath: join(baseDir, 'circuit.ccs'),\n pkPath: paths.pkPath,\n vkPath: paths.vkPath,\n proofPath: join(baseDir, 'circuit.proof'),\n publicWitnessPath: join(baseDir, 'circuit.pw'),\n proverTomlPath: join(baseDir, 'Prover.toml'),\n },\n };\n }\n\n /**\n * Create a temporary Noir project for compilation\n */\n private async createNoirProject(noirCode: string, packageName: string): Promise<{ rootDir: string }> {\n const rootDir = await mkdtemp(join(tmpdir(), 'sunspot-circuit-'));\n const srcDir = join(rootDir, 'src');\n await mkdir(srcDir, { recursive: true });\n\n const nargoToml = `[package]\nname = \"${packageName}\"\ntype = \"bin\"\nauthors = [\"\"]\n\n[dependencies]\n`;\n\n await writeFile(join(rootDir, 'Nargo.toml'), nargoToml);\n await writeFile(join(srcDir, 'main.nr'), noirCode);\n\n return { rootDir };\n }\n\n async compile(noirCode: string): Promise<CompiledCircuit> {\n if (this.precompiledPaths) {\n throw new Error(\n 'Sunspot was initialized with pre-compiled circuit paths. ' +\n 'compile() is not available. Use generateProof() and verifyProof() directly.'\n );\n }\n\n // 1. Create temp Noir project\n const project = await this.createNoirProject(noirCode, 'circuit');\n const targetDir = join(project.rootDir, 'target');\n\n // 2. Run nargo compile → circuit.json\n await this.executor.nargoCompile(project.rootDir);\n const circuitJsonPath = join(targetDir, 'circuit.json');\n\n // 3. Run sunspot compile → circuit.ccs\n await this.executor.sunspotCompile(circuitJsonPath);\n const ccsPath = join(dirname(circuitJsonPath), 'circuit.ccs');\n\n // 4. Run sunspot setup → circuit.pk + circuit.vk\n await this.executor.sunspotSetup(ccsPath);\n const pkPath = join(dirname(ccsPath), 'circuit.pk');\n const vkPath = join(dirname(ccsPath), 'circuit.vk');\n\n // 5. Read circuit.json to extract ABI\n const circuitJson = JSON.parse(await readFile(circuitJsonPath, 'utf-8'));\n\n // 6. Build paths object\n const paths: SunspotCircuitPaths = {\n workDir: project.rootDir,\n noirProjectDir: project.rootDir,\n circuitJsonPath,\n witnessPath: join(targetDir, 'circuit.gz'),\n ccsPath,\n pkPath,\n vkPath,\n proofPath: join(dirname(ccsPath), 'circuit.proof'),\n publicWitnessPath: join(dirname(ccsPath), 'circuit.pw'),\n proverTomlPath: join(project.rootDir, 'Prover.toml'),\n };\n\n // 7. Return SunspotCompiledCircuit (don't cleanup - prover needs the files)\n const sunspotCircuit: SunspotCompiledCircuit = {\n bytecode: circuitJson.bytecode || '',\n abi: circuitJson.abi || {\n parameters: [],\n return_type: null,\n error_types: {},\n },\n debug_symbols: circuitJson.debug_symbols || '',\n file_map: circuitJson.file_map || {},\n __sunspot: true,\n paths,\n };\n\n return sunspotCircuit;\n }\n\n async generateProof(circuit: CompiledCircuit, inputs: InputMap): Promise<ProofData> {\n // Use precompiled circuit if available and circuit is empty/default\n const circuitToUse = this.resolveCircuit(circuit);\n\n if (!isSunspotCircuit(circuitToUse)) {\n throw new Error(\n 'Sunspot.generateProof requires a SunspotCompiledCircuit. Use Sunspot.compile() first.'\n );\n }\n\n const paths = circuitToUse.paths;\n\n try {\n // 1. Write Prover.toml with inputs\n const proverToml = this.generateProverToml(inputs);\n await writeFile(paths.proverTomlPath, proverToml);\n\n // 2. Run nargo execute to generate witness\n await this.executor.nargoExecute(paths.noirProjectDir);\n\n // 3. Run sunspot prove to generate proof\n await this.executor.sunspotProve(\n paths.circuitJsonPath,\n paths.witnessPath,\n paths.ccsPath,\n paths.pkPath\n );\n\n // 4. Read proof and public witness files\n const proofBytes = new Uint8Array(await readFile(paths.proofPath));\n const publicWitnessBytes = new Uint8Array(await readFile(paths.publicWitnessPath));\n\n // 5. Parse public inputs from public witness\n const publicInputs = this.parsePublicWitness(publicWitnessBytes);\n\n return {\n proof: proofBytes,\n publicInputs,\n };\n } catch (error) {\n if (!this.config.keepArtifacts) {\n await rm(paths.workDir, { recursive: true, force: true }).catch(() => {});\n }\n throw error;\n }\n }\n\n async verifyProof(\n circuit: CompiledCircuit,\n proof: Uint8Array,\n publicInputs: string[]\n ): Promise<boolean> {\n // Use precompiled circuit if available and circuit is empty/default\n const circuitToUse = this.resolveCircuit(circuit);\n\n if (!isSunspotCircuit(circuitToUse)) {\n throw new Error(\n 'Sunspot.verifyProof requires a SunspotCompiledCircuit. Use Sunspot.compile() first.'\n );\n }\n\n const paths = circuitToUse.paths;\n\n try {\n // Use existing .proof and .pw files from generateProof\n const existingProof = await readFile(paths.proofPath).catch(() => null);\n if (!existingProof || !this.bytesEqual(existingProof, proof)) {\n await writeFile(paths.proofPath, proof);\n }\n\n await this.executor.sunspotVerify(\n paths.vkPath,\n paths.proofPath,\n paths.publicWitnessPath\n );\n\n return true;\n } catch (error) {\n if (error instanceof SunspotCliError) {\n if (error.stderr.toLowerCase().includes('verification failed') ||\n error.stderr.toLowerCase().includes('invalid proof')) {\n return false;\n }\n }\n throw error;\n } finally {\n if (!this.config.keepArtifacts) {\n await rm(paths.workDir, { recursive: true, force: true }).catch(() => {});\n }\n }\n }\n\n /**\n * Resolve which circuit to use - precompiled or provided\n */\n private resolveCircuit(circuit: CompiledCircuit): CompiledCircuit {\n // If circuit is a proper SunspotCompiledCircuit, use it\n if (isSunspotCircuit(circuit)) {\n return circuit;\n }\n\n // If we have precompiled paths, use those\n if (this.precompiledCircuit) {\n return this.precompiledCircuit;\n }\n\n // Otherwise, return the provided circuit (will fail validation)\n return circuit;\n }\n\n private generateProverToml(inputs: InputMap): string {\n const lines: string[] = [];\n for (const [key, value] of Object.entries(inputs)) {\n lines.push(`${key} = ${this.formatTomlValue(value)}`);\n }\n return lines.join('\\n') + '\\n';\n }\n\n private formatTomlValue(value: unknown): string {\n if (typeof value === 'string') {\n if (value.startsWith('0x')) return `\"${value}\"`;\n if (/^\\d+$/.test(value)) return value;\n return `\"${value}\"`;\n }\n if (typeof value === 'number' || typeof value === 'bigint') {\n return value.toString();\n }\n if (Array.isArray(value)) {\n return `[${value.map(v => this.formatTomlValue(v)).join(', ')}]`;\n }\n return String(value);\n }\n\n private parsePublicWitness(bytes: Uint8Array): string[] {\n const publicInputs: string[] = [];\n const FIELD_SIZE = 32;\n\n for (let i = 0; i < bytes.length; i += FIELD_SIZE) {\n const fieldBytes = bytes.slice(i, Math.min(i + FIELD_SIZE, bytes.length));\n if (fieldBytes.length === FIELD_SIZE) {\n const hex = '0x' + Array.from(fieldBytes)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('');\n publicInputs.push(hex);\n }\n }\n\n return publicInputs;\n }\n\n private bytesEqual(a: Buffer | Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n }\n}\n","import type { CompiledCircuit } from '@noir-lang/types';\n\n/**\n * Configuration for Sunspot CLI execution\n */\nexport interface SunspotConfig {\n /** Path to nargo binary (default: 'nargo') */\n nargoBinaryPath: string;\n /** Path to sunspot binary (default: 'sunspot') */\n sunspotBinaryPath: string;\n /** Keep temp artifacts for debugging (default: false) */\n keepArtifacts: boolean;\n /** Timeout for CLI commands in ms (default: 120000) */\n timeoutMs: number;\n}\n\nexport const DEFAULT_SUNSPOT_CONFIG: SunspotConfig = {\n nargoBinaryPath: process.env.NARGO_PATH || 'nargo',\n sunspotBinaryPath: process.env.SUNSPOT_PATH || 'sunspot',\n keepArtifacts: process.env.SUNSPOT_KEEP_ARTIFACTS === 'true',\n timeoutMs: 120000,\n};\n\n/**\n * Paths to all Sunspot artifacts in the temp directory\n */\nexport interface SunspotCircuitPaths {\n /** Base temp directory */\n workDir: string;\n /** Noir project directory with Nargo.toml */\n noirProjectDir: string;\n /** Path to compiled circuit.json (ACIR) */\n circuitJsonPath: string;\n /** Path to witness.gz */\n witnessPath: string;\n /** Path to circuit.ccs */\n ccsPath: string;\n /** Path to proving key */\n pkPath: string;\n /** Path to verification key */\n vkPath: string;\n /** Path to proof file */\n proofPath: string;\n /** Path to public witness file */\n publicWitnessPath: string;\n /** Path to Prover.toml */\n proverTomlPath: string;\n}\n\n/**\n * Extended CompiledCircuit for Sunspot backend\n */\nexport interface SunspotCompiledCircuit extends CompiledCircuit {\n /** Marker to identify Sunspot circuits */\n __sunspot: true;\n /** Paths to all artifacts */\n paths: SunspotCircuitPaths;\n}\n\n/**\n * Type guard to check if a circuit is a Sunspot circuit\n */\nexport function isSunspotCircuit(circuit: CompiledCircuit): circuit is SunspotCompiledCircuit {\n return '__sunspot' in circuit && (circuit as SunspotCompiledCircuit).__sunspot === true;\n}\n\n/**\n * Result of CLI command execution\n */\nexport interface CliResult {\n stdout: string;\n stderr: string;\n exitCode: number;\n}\n\n/**\n * Error thrown when CLI command fails\n */\nexport class SunspotCliError extends Error {\n constructor(\n message: string,\n public readonly command: string,\n public readonly exitCode: number,\n public readonly stderr: string\n ) {\n super(message);\n this.name = 'SunspotCliError';\n }\n}\n","import { spawn } from 'node:child_process';\nimport type { SunspotConfig, CliResult } from './types.js';\nimport { SunspotCliError } from './types.js';\n\n/**\n * Executes Sunspot and Nargo CLI commands\n */\nexport class SunspotCliExecutor {\n constructor(private readonly config: SunspotConfig) {}\n\n /**\n * Execute a CLI command and return the result\n */\n private async execute(command: string, args: string[], cwd?: string): Promise<CliResult> {\n return new Promise((resolve, reject) => {\n const proc = spawn(command, args, {\n cwd,\n timeout: this.config.timeoutMs,\n env: { ...process.env },\n });\n\n let stdout = '';\n let stderr = '';\n\n proc.stdout.on('data', (data) => {\n stdout += data.toString();\n });\n\n proc.stderr.on('data', (data) => {\n stderr += data.toString();\n });\n\n proc.on('close', (exitCode) => {\n const result: CliResult = {\n stdout,\n stderr,\n exitCode: exitCode ?? 1,\n };\n\n if (exitCode !== 0) {\n reject(new SunspotCliError(\n `Command failed: ${command} ${args.join(' ')}\\n${stderr || stdout}`,\n `${command} ${args.join(' ')}`,\n exitCode ?? 1,\n stderr || stdout\n ));\n } else {\n resolve(result);\n }\n });\n\n proc.on('error', (error) => {\n const message = error.message.includes('ENOENT')\n ? `Binary not found: ${command}. Ensure it is installed and in PATH.`\n : `Failed to execute ${command}: ${error.message}`;\n\n reject(new SunspotCliError(\n message,\n `${command} ${args.join(' ')}`,\n 1,\n error.message\n ));\n });\n });\n }\n\n /**\n * Run nargo compile in the project directory\n * Output: target/circuit.json\n */\n async nargoCompile(projectDir: string): Promise<CliResult> {\n return this.execute(this.config.nargoBinaryPath, ['compile'], projectDir);\n }\n\n /**\n * Run nargo execute to generate witness\n * Output: target/circuit.gz\n */\n async nargoExecute(projectDir: string): Promise<CliResult> {\n return this.execute(this.config.nargoBinaryPath, ['execute'], projectDir);\n }\n\n /**\n * Run sunspot compile to generate CCS\n * Input: circuit.json\n * Output: circuit.ccs (in same directory as input)\n */\n async sunspotCompile(circuitJsonPath: string): Promise<CliResult> {\n return this.execute(this.config.sunspotBinaryPath, ['compile', circuitJsonPath]);\n }\n\n /**\n * Run sunspot setup to generate proving and verification keys\n * Input: circuit.ccs\n * Output: circuit.pk, circuit.vk (in same directory as input)\n */\n async sunspotSetup(ccsPath: string): Promise<CliResult> {\n return this.execute(this.config.sunspotBinaryPath, ['setup', ccsPath]);\n }\n\n /**\n * Run sunspot prove to generate proof\n * Inputs: circuit.json, witness.gz, circuit.ccs, circuit.pk\n * Outputs: circuit.proof, circuit.pw (in same directory as ccs)\n */\n async sunspotProve(\n circuitJsonPath: string,\n witnessPath: string,\n ccsPath: string,\n pkPath: string\n ): Promise<CliResult> {\n return this.execute(this.config.sunspotBinaryPath, [\n 'prove',\n circuitJsonPath,\n witnessPath,\n ccsPath,\n pkPath,\n ]);\n }\n\n /**\n * Run sunspot verify to verify a proof\n * Inputs: circuit.vk, circuit.proof, circuit.pw\n * Returns: true if verification succeeds\n */\n async sunspotVerify(\n vkPath: string,\n proofPath: string,\n publicWitnessPath: string\n ): Promise<CliResult> {\n return this.execute(this.config.sunspotBinaryPath, [\n 'verify',\n vkPath,\n proofPath,\n publicWitnessPath,\n ]);\n }\n}\n","import { Chain } from './chain.js';\nimport { Network } from '../../solana/config.js';\n\n/**\n * Available proving system providers\n */\nexport enum Provider {\n /** Barretenberg backend - browser compatible, UltraHonk proofs (~16KB) */\n Barretenberg = 'barretenberg',\n /** Arkworks WASM backend - browser compatible, Groth16 proofs (~256 bytes) */\n Arkworks = 'arkworks',\n /** Sunspot CLI backend - Node.js only, Groth16 proofs (~256 bytes) */\n Sunspot = 'sunspot',\n}\n\n/**\n * Configuration for circuit paths (required for Sunspot)\n */\nexport interface CircuitPaths {\n /** Path to the proving key file */\n pkPath: string;\n /** Path to the verification key file */\n vkPath: string;\n /** Path to the compiled circuit JSON file */\n circuitPath: string;\n}\n\n/**\n * Configuration for IziNoir initialization\n */\nexport interface IziNoirConfig {\n /** The proving system provider to use */\n provider: Provider;\n /**\n * Target blockchain for proof formatting.\n * If omitted, operates in offchain mode (raw proofs, no chain formatting).\n */\n chain?: Chain;\n /**\n * Solana network for deploy/verify operations.\n * Only used when chain is Chain.Solana.\n * Default: Network.Devnet\n */\n network?: Network;\n /** Circuit paths - required for Sunspot provider */\n circuitPaths?: CircuitPaths;\n}\n\n// Re-export Chain and Network for convenience\nexport { Chain };\nexport { Network };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,sBAAwD;AACxD,uBAA8B;AAC9B,qBAAuB;;;ACchB,IAAM,yBAAwC;AAAA,EACnD,iBAAiB,QAAQ,IAAI,cAAc;AAAA,EAC3C,mBAAmB,QAAQ,IAAI,gBAAgB;AAAA,EAC/C,eAAe,QAAQ,IAAI,2BAA2B;AAAA,EACtD,WAAW;AACb;AAyCO,SAAS,iBAAiB,SAA6D;AAC5F,SAAO,eAAe,WAAY,QAAmC,cAAc;AACrF;AAcO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YACE,SACgB,SACA,UACA,QAChB;AACA,UAAM,OAAO;AAJG;AACA;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;ACxFA,gCAAsB;AAOf,IAAM,qBAAN,MAAyB;AAAA,EAC9B,YAA6B,QAAuB;AAAvB;AAAA,EAAwB;AAAA;AAAA;AAAA;AAAA,EAKrD,MAAc,QAAQ,SAAiB,MAAgB,KAAkC;AACvF,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,YAAM,WAAO,iCAAM,SAAS,MAAM;AAAA,QAChC;AAAA,QACA,SAAS,KAAK,OAAO;AAAA,QACrB,KAAK,EAAE,GAAG,QAAQ,IAAI;AAAA,MACxB,CAAC;AAED,UAAI,SAAS;AACb,UAAI,SAAS;AAEb,WAAK,OAAO,GAAG,QAAQ,CAAC,SAAS;AAC/B,kBAAU,KAAK,SAAS;AAAA,MAC1B,CAAC;AAED,WAAK,OAAO,GAAG,QAAQ,CAAC,SAAS;AAC/B,kBAAU,KAAK,SAAS;AAAA,MAC1B,CAAC;AAED,WAAK,GAAG,SAAS,CAAC,aAAa;AAC7B,cAAM,SAAoB;AAAA,UACxB;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ClB,UAAM,eAAe,WAAW,KAAK;AACrC,QAAI,CAAC,cAAc;AACjB,YAAM,IAAI,MAAM,kEAAkE;AAAA,IACpF;AACA,WAAO,KAAK,cAAc,YAAY,cAAc,OAAO,YAAY;AAAA,EACzE;AAAA,EAEA,MAAM,YACJ,UACA,QACkD;AAClD,UAAM,UAAU,MAAM,KAAK,QAAQ,QAAQ;AAC3C,UAAM,QAAQ,MAAM,KAAK,MAAM,QAAQ,OAAO;AAC9C,UAAM,WAAW,MAAM,KAAK,OAAO,MAAM,OAAO,MAAM,cAAc,OAAO;AAC3E,WAAO,EAAE,OAAO,SAAS;AAAA,EAC3B;AACF;AAMA,eAAsB,mBAAmB,cAAqD;AAC5F,SAAO,eAAe,KAAK,YAAY;AACzC;","names":["Provider"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/infra/provingSystems/Sunspot.ts","../../src/infra/sunspot/types.ts","../../src/infra/sunspot/SunspotCliExecutor.ts","../../src/domain/types/provider.ts","../../src/providers/sunspot.ts"],"sourcesContent":["import { readFile, writeFile, rm, mkdtemp, mkdir } from 'node:fs/promises';\nimport { join, dirname } from 'node:path';\nimport { tmpdir } from 'node:os';\nimport type { IProvingSystem } from '../../domain/interfaces/proving/IProvingSystem.js';\nimport type { CompiledCircuit, InputMap, ProofData } from '../../domain/types.js';\nimport type { SunspotConfig, SunspotCircuitPaths, SunspotCompiledCircuit } from '../sunspot/types.js';\nimport { DEFAULT_SUNSPOT_CONFIG, isSunspotCircuit, SunspotCliError } from '../sunspot/types.js';\nimport { SunspotCliExecutor } from '../sunspot/SunspotCliExecutor.js';\nimport type { CircuitPaths } from '../../domain/types/provider.js';\n\n/**\n * Configuration for Sunspot constructor\n */\nexport interface SunspotInitConfig extends Partial<SunspotConfig> {\n /** Pre-compiled circuit paths (if provided, compile() is disabled) */\n precompiledPaths?: CircuitPaths;\n}\n\n/**\n * Sunspot proving system using CLI tools.\n * Node.js only (requires nargo and sunspot binaries).\n * Produces Groth16 proofs (~324 bytes) for Solana on-chain verification.\n *\n * Can be used in two modes:\n * 1. Full compilation: Call compile() with Noir code (requires nargo + sunspot CLI)\n * 2. Pre-compiled: Provide circuitPaths in constructor, then only prove/verify\n *\n * @example Full compilation\n * ```typescript\n * const sunspot = new Sunspot();\n * const circuit = await sunspot.compile(noirCode);\n * const proof = await sunspot.generateProof(circuit, inputs);\n * ```\n *\n * @example Pre-compiled (via IziNoir)\n * ```typescript\n * const izi = await IziNoir.init({\n * provider: Provider.Sunspot,\n * circuitPaths: { pkPath: '...', vkPath: '...', circuitPath: '...' }\n * });\n * ```\n */\nexport class Sunspot implements IProvingSystem {\n private readonly config: SunspotConfig;\n private readonly executor: SunspotCliExecutor;\n private readonly precompiledPaths?: CircuitPaths;\n private precompiledCircuit?: SunspotCompiledCircuit;\n\n /**\n * Create a new Sunspot proving system\n * @param config - Configuration options or pre-compiled circuit paths\n */\n constructor(config: SunspotInitConfig | CircuitPaths = {}) {\n // Check if config is CircuitPaths (has pkPath, vkPath, circuitPath)\n if ('pkPath' in config && 'vkPath' in config && 'circuitPath' in config) {\n this.config = { ...DEFAULT_SUNSPOT_CONFIG };\n this.precompiledPaths = config as CircuitPaths;\n } else {\n const initConfig = config as SunspotInitConfig;\n this.config = { ...DEFAULT_SUNSPOT_CONFIG, ...initConfig };\n this.precompiledPaths = initConfig.precompiledPaths;\n }\n\n this.executor = new SunspotCliExecutor(this.config);\n\n // If pre-compiled paths provided, create a dummy circuit object\n if (this.precompiledPaths) {\n this.precompiledCircuit = this.createPrecompiledCircuit(this.precompiledPaths);\n }\n }\n\n /**\n * Create a SunspotCompiledCircuit from pre-compiled paths\n */\n private createPrecompiledCircuit(paths: CircuitPaths): SunspotCompiledCircuit {\n const baseDir = dirname(paths.circuitPath);\n return {\n bytecode: '', // Not needed for prove/verify with pre-compiled\n abi: { parameters: [], return_type: null, error_types: {} },\n debug_symbols: '',\n file_map: {},\n __sunspot: true,\n paths: {\n workDir: baseDir,\n noirProjectDir: baseDir,\n circuitJsonPath: paths.circuitPath,\n witnessPath: join(baseDir, 'circuit.gz'),\n ccsPath: join(baseDir, 'circuit.ccs'),\n pkPath: paths.pkPath,\n vkPath: paths.vkPath,\n proofPath: join(baseDir, 'circuit.proof'),\n publicWitnessPath: join(baseDir, 'circuit.pw'),\n proverTomlPath: join(baseDir, 'Prover.toml'),\n },\n };\n }\n\n /**\n * Create a temporary Noir project for compilation\n */\n private async createNoirProject(noirCode: string, packageName: string): Promise<{ rootDir: string }> {\n const rootDir = await mkdtemp(join(tmpdir(), 'sunspot-circuit-'));\n const srcDir = join(rootDir, 'src');\n await mkdir(srcDir, { recursive: true });\n\n const nargoToml = `[package]\nname = \"${packageName}\"\ntype = \"bin\"\nauthors = [\"\"]\n\n[dependencies]\n`;\n\n await writeFile(join(rootDir, 'Nargo.toml'), nargoToml);\n await writeFile(join(srcDir, 'main.nr'), noirCode);\n\n return { rootDir };\n }\n\n async compile(noirCode: string): Promise<CompiledCircuit> {\n if (this.precompiledPaths) {\n throw new Error(\n 'Sunspot was initialized with pre-compiled circuit paths. ' +\n 'compile() is not available. Use generateProof() and verifyProof() directly.'\n );\n }\n\n // 1. Create temp Noir project\n const project = await this.createNoirProject(noirCode, 'circuit');\n const targetDir = join(project.rootDir, 'target');\n\n // 2. Run nargo compile → circuit.json\n await this.executor.nargoCompile(project.rootDir);\n const circuitJsonPath = join(targetDir, 'circuit.json');\n\n // 3. Run sunspot compile → circuit.ccs\n await this.executor.sunspotCompile(circuitJsonPath);\n const ccsPath = join(dirname(circuitJsonPath), 'circuit.ccs');\n\n // 4. Run sunspot setup → circuit.pk + circuit.vk\n await this.executor.sunspotSetup(ccsPath);\n const pkPath = join(dirname(ccsPath), 'circuit.pk');\n const vkPath = join(dirname(ccsPath), 'circuit.vk');\n\n // 5. Read circuit.json to extract ABI\n const circuitJson = JSON.parse(await readFile(circuitJsonPath, 'utf-8'));\n\n // 6. Build paths object\n const paths: SunspotCircuitPaths = {\n workDir: project.rootDir,\n noirProjectDir: project.rootDir,\n circuitJsonPath,\n witnessPath: join(targetDir, 'circuit.gz'),\n ccsPath,\n pkPath,\n vkPath,\n proofPath: join(dirname(ccsPath), 'circuit.proof'),\n publicWitnessPath: join(dirname(ccsPath), 'circuit.pw'),\n proverTomlPath: join(project.rootDir, 'Prover.toml'),\n };\n\n // 7. Return SunspotCompiledCircuit (don't cleanup - prover needs the files)\n const sunspotCircuit: SunspotCompiledCircuit = {\n bytecode: circuitJson.bytecode || '',\n abi: circuitJson.abi || {\n parameters: [],\n return_type: null,\n error_types: {},\n },\n debug_symbols: circuitJson.debug_symbols || '',\n file_map: circuitJson.file_map || {},\n __sunspot: true,\n paths,\n };\n\n return sunspotCircuit;\n }\n\n async generateProof(circuit: CompiledCircuit, inputs: InputMap): Promise<ProofData> {\n // Use precompiled circuit if available and circuit is empty/default\n const circuitToUse = this.resolveCircuit(circuit);\n\n if (!isSunspotCircuit(circuitToUse)) {\n throw new Error(\n 'Sunspot.generateProof requires a SunspotCompiledCircuit. Use Sunspot.compile() first.'\n );\n }\n\n const paths = circuitToUse.paths;\n\n try {\n // 1. Write Prover.toml with inputs\n const proverToml = this.generateProverToml(inputs);\n await writeFile(paths.proverTomlPath, proverToml);\n\n // 2. Run nargo execute to generate witness\n await this.executor.nargoExecute(paths.noirProjectDir);\n\n // 3. Run sunspot prove to generate proof\n await this.executor.sunspotProve(\n paths.circuitJsonPath,\n paths.witnessPath,\n paths.ccsPath,\n paths.pkPath\n );\n\n // 4. Read proof and public witness files\n const proofBytes = new Uint8Array(await readFile(paths.proofPath));\n const publicWitnessBytes = new Uint8Array(await readFile(paths.publicWitnessPath));\n\n // 5. Parse public inputs from public witness\n const publicInputs = this.parsePublicWitness(publicWitnessBytes);\n\n return {\n proof: proofBytes,\n publicInputs,\n };\n } catch (error) {\n if (!this.config.keepArtifacts) {\n await rm(paths.workDir, { recursive: true, force: true }).catch(() => {});\n }\n throw error;\n }\n }\n\n async verifyProof(\n circuit: CompiledCircuit,\n proof: Uint8Array,\n publicInputs: string[]\n ): Promise<boolean> {\n // Use precompiled circuit if available and circuit is empty/default\n const circuitToUse = this.resolveCircuit(circuit);\n\n if (!isSunspotCircuit(circuitToUse)) {\n throw new Error(\n 'Sunspot.verifyProof requires a SunspotCompiledCircuit. Use Sunspot.compile() first.'\n );\n }\n\n const paths = circuitToUse.paths;\n\n try {\n // Use existing .proof and .pw files from generateProof\n const existingProof = await readFile(paths.proofPath).catch(() => null);\n if (!existingProof || !this.bytesEqual(existingProof, proof)) {\n await writeFile(paths.proofPath, proof);\n }\n\n await this.executor.sunspotVerify(\n paths.vkPath,\n paths.proofPath,\n paths.publicWitnessPath\n );\n\n return true;\n } catch (error) {\n if (error instanceof SunspotCliError) {\n if (error.stderr.toLowerCase().includes('verification failed') ||\n error.stderr.toLowerCase().includes('invalid proof')) {\n return false;\n }\n }\n throw error;\n } finally {\n if (!this.config.keepArtifacts) {\n await rm(paths.workDir, { recursive: true, force: true }).catch(() => {});\n }\n }\n }\n\n /**\n * Resolve which circuit to use - precompiled or provided\n */\n private resolveCircuit(circuit: CompiledCircuit): CompiledCircuit {\n // If circuit is a proper SunspotCompiledCircuit, use it\n if (isSunspotCircuit(circuit)) {\n return circuit;\n }\n\n // If we have precompiled paths, use those\n if (this.precompiledCircuit) {\n return this.precompiledCircuit;\n }\n\n // Otherwise, return the provided circuit (will fail validation)\n return circuit;\n }\n\n private generateProverToml(inputs: InputMap): string {\n const lines: string[] = [];\n for (const [key, value] of Object.entries(inputs)) {\n lines.push(`${key} = ${this.formatTomlValue(value)}`);\n }\n return lines.join('\\n') + '\\n';\n }\n\n private formatTomlValue(value: unknown): string {\n if (typeof value === 'string') {\n if (value.startsWith('0x')) return `\"${value}\"`;\n if (/^\\d+$/.test(value)) return value;\n return `\"${value}\"`;\n }\n if (typeof value === 'number' || typeof value === 'bigint') {\n return value.toString();\n }\n if (Array.isArray(value)) {\n return `[${value.map(v => this.formatTomlValue(v)).join(', ')}]`;\n }\n return String(value);\n }\n\n private parsePublicWitness(bytes: Uint8Array): string[] {\n const publicInputs: string[] = [];\n const FIELD_SIZE = 32;\n\n for (let i = 0; i < bytes.length; i += FIELD_SIZE) {\n const fieldBytes = bytes.slice(i, Math.min(i + FIELD_SIZE, bytes.length));\n if (fieldBytes.length === FIELD_SIZE) {\n const hex = '0x' + Array.from(fieldBytes)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('');\n publicInputs.push(hex);\n }\n }\n\n return publicInputs;\n }\n\n private bytesEqual(a: Buffer | Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n }\n}\n","import type { CompiledCircuit } from '@noir-lang/types';\n\n/**\n * Configuration for Sunspot CLI execution\n */\nexport interface SunspotConfig {\n /** Path to nargo binary (default: 'nargo') */\n nargoBinaryPath: string;\n /** Path to sunspot binary (default: 'sunspot') */\n sunspotBinaryPath: string;\n /** Keep temp artifacts for debugging (default: false) */\n keepArtifacts: boolean;\n /** Timeout for CLI commands in ms (default: 120000) */\n timeoutMs: number;\n}\n\nexport const DEFAULT_SUNSPOT_CONFIG: SunspotConfig = {\n nargoBinaryPath: process.env.NARGO_PATH || 'nargo',\n sunspotBinaryPath: process.env.SUNSPOT_PATH || 'sunspot',\n keepArtifacts: process.env.SUNSPOT_KEEP_ARTIFACTS === 'true',\n timeoutMs: 120000,\n};\n\n/**\n * Paths to all Sunspot artifacts in the temp directory\n */\nexport interface SunspotCircuitPaths {\n /** Base temp directory */\n workDir: string;\n /** Noir project directory with Nargo.toml */\n noirProjectDir: string;\n /** Path to compiled circuit.json (ACIR) */\n circuitJsonPath: string;\n /** Path to witness.gz */\n witnessPath: string;\n /** Path to circuit.ccs */\n ccsPath: string;\n /** Path to proving key */\n pkPath: string;\n /** Path to verification key */\n vkPath: string;\n /** Path to proof file */\n proofPath: string;\n /** Path to public witness file */\n publicWitnessPath: string;\n /** Path to Prover.toml */\n proverTomlPath: string;\n}\n\n/**\n * Extended CompiledCircuit for Sunspot backend\n */\nexport interface SunspotCompiledCircuit extends CompiledCircuit {\n /** Marker to identify Sunspot circuits */\n __sunspot: true;\n /** Paths to all artifacts */\n paths: SunspotCircuitPaths;\n}\n\n/**\n * Type guard to check if a circuit is a Sunspot circuit\n */\nexport function isSunspotCircuit(circuit: CompiledCircuit): circuit is SunspotCompiledCircuit {\n return '__sunspot' in circuit && (circuit as SunspotCompiledCircuit).__sunspot === true;\n}\n\n/**\n * Result of CLI command execution\n */\nexport interface CliResult {\n stdout: string;\n stderr: string;\n exitCode: number;\n}\n\n/**\n * Error thrown when CLI command fails\n */\nexport class SunspotCliError extends Error {\n constructor(\n message: string,\n public readonly command: string,\n public readonly exitCode: number,\n public readonly stderr: string\n ) {\n super(message);\n this.name = 'SunspotCliError';\n }\n}\n","import { spawn } from 'node:child_process';\nimport type { SunspotConfig, CliResult } from './types.js';\nimport { SunspotCliError } from './types.js';\n\n/**\n * Executes Sunspot and Nargo CLI commands\n */\nexport class SunspotCliExecutor {\n constructor(private readonly config: SunspotConfig) {}\n\n /**\n * Execute a CLI command and return the result\n */\n private async execute(command: string, args: string[], cwd?: string): Promise<CliResult> {\n return new Promise((resolve, reject) => {\n const proc = spawn(command, args, {\n cwd,\n timeout: this.config.timeoutMs,\n env: { ...process.env },\n });\n\n let stdout = '';\n let stderr = '';\n\n proc.stdout.on('data', (data) => {\n stdout += data.toString();\n });\n\n proc.stderr.on('data', (data) => {\n stderr += data.toString();\n });\n\n proc.on('close', (exitCode) => {\n const result: CliResult = {\n stdout,\n stderr,\n exitCode: exitCode ?? 1,\n };\n\n if (exitCode !== 0) {\n reject(new SunspotCliError(\n `Command failed: ${command} ${args.join(' ')}\\n${stderr || stdout}`,\n `${command} ${args.join(' ')}`,\n exitCode ?? 1,\n stderr || stdout\n ));\n } else {\n resolve(result);\n }\n });\n\n proc.on('error', (error) => {\n const message = error.message.includes('ENOENT')\n ? `Binary not found: ${command}. Ensure it is installed and in PATH.`\n : `Failed to execute ${command}: ${error.message}`;\n\n reject(new SunspotCliError(\n message,\n `${command} ${args.join(' ')}`,\n 1,\n error.message\n ));\n });\n });\n }\n\n /**\n * Run nargo compile in the project directory\n * Output: target/circuit.json\n */\n async nargoCompile(projectDir: string): Promise<CliResult> {\n return this.execute(this.config.nargoBinaryPath, ['compile'], projectDir);\n }\n\n /**\n * Run nargo execute to generate witness\n * Output: target/circuit.gz\n */\n async nargoExecute(projectDir: string): Promise<CliResult> {\n return this.execute(this.config.nargoBinaryPath, ['execute'], projectDir);\n }\n\n /**\n * Run sunspot compile to generate CCS\n * Input: circuit.json\n * Output: circuit.ccs (in same directory as input)\n */\n async sunspotCompile(circuitJsonPath: string): Promise<CliResult> {\n return this.execute(this.config.sunspotBinaryPath, ['compile', circuitJsonPath]);\n }\n\n /**\n * Run sunspot setup to generate proving and verification keys\n * Input: circuit.ccs\n * Output: circuit.pk, circuit.vk (in same directory as input)\n */\n async sunspotSetup(ccsPath: string): Promise<CliResult> {\n return this.execute(this.config.sunspotBinaryPath, ['setup', ccsPath]);\n }\n\n /**\n * Run sunspot prove to generate proof\n * Inputs: circuit.json, witness.gz, circuit.ccs, circuit.pk\n * Outputs: circuit.proof, circuit.pw (in same directory as ccs)\n */\n async sunspotProve(\n circuitJsonPath: string,\n witnessPath: string,\n ccsPath: string,\n pkPath: string\n ): Promise<CliResult> {\n return this.execute(this.config.sunspotBinaryPath, [\n 'prove',\n circuitJsonPath,\n witnessPath,\n ccsPath,\n pkPath,\n ]);\n }\n\n /**\n * Run sunspot verify to verify a proof\n * Inputs: circuit.vk, circuit.proof, circuit.pw\n * Returns: true if verification succeeds\n */\n async sunspotVerify(\n vkPath: string,\n proofPath: string,\n publicWitnessPath: string\n ): Promise<CliResult> {\n return this.execute(this.config.sunspotBinaryPath, [\n 'verify',\n vkPath,\n proofPath,\n publicWitnessPath,\n ]);\n }\n}\n","import { Chain } from './chain.js';\nimport { Network } from '../../solana/config.js';\n\n/**\n * Available proving system providers\n */\nexport enum Provider {\n /** Barretenberg backend - browser compatible, UltraHonk proofs (~16KB) */\n Barretenberg = 'barretenberg',\n /** Arkworks WASM backend - browser compatible, Groth16 proofs (~256 bytes) */\n Arkworks = 'arkworks',\n /** Sunspot CLI backend - Node.js only, Groth16 proofs (~256 bytes) */\n Sunspot = 'sunspot',\n}\n\n/**\n * Configuration for circuit paths (required for Sunspot)\n */\nexport interface CircuitPaths {\n /** Path to the proving key file */\n pkPath: string;\n /** Path to the verification key file */\n vkPath: string;\n /** Path to the compiled circuit JSON file */\n circuitPath: string;\n}\n\n/**\n * Configuration for IziNoir initialization\n */\nexport interface IziNoirConfig {\n /** The proving system provider to use */\n provider: Provider;\n /**\n * Target blockchain for proof formatting.\n * If omitted, operates in offchain mode (raw proofs, no chain formatting).\n */\n chain?: Chain;\n /**\n * Solana network for deploy/verify operations.\n * Only used when chain is Chain.Solana.\n * Default: Network.Devnet\n */\n network?: Network;\n /** Circuit paths - required for Sunspot provider */\n circuitPaths?: CircuitPaths;\n}\n\n// Re-export Chain and Network for convenience\nexport { Chain };\nexport { Network };\n","/**\n * Sunspot entry point for Node.js.\n *\n * This module provides Sunspot support which is NOT available in the main\n * `@izi-noir/sdk` entry point due to Node.js-only dependencies.\n *\n * Note: Sunspot requires nargo and sunspot CLI tools to be installed.\n *\n * @example Using Sunspot directly\n * ```typescript\n * import { Sunspot } from '@izi-noir/sdk/sunspot';\n *\n * // Full compilation mode\n * const sunspot = new Sunspot();\n * const circuit = await sunspot.compile(noirCode);\n * const proof = await sunspot.generateProof(circuit, inputs);\n * const verified = await sunspot.verifyProof(circuit, proof.proof, proof.publicInputs);\n *\n * // Pre-compiled mode\n * const sunspot = new Sunspot({\n * pkPath: './circuit/circuit.pk',\n * vkPath: './circuit/circuit.vk',\n * circuitPath: './circuit/circuit.json',\n * });\n * ```\n *\n * @example Using initSunspotIziNoir helper\n * ```typescript\n * import { initSunspotIziNoir } from '@izi-noir/sdk/sunspot';\n *\n * const izi = await initSunspotIziNoir({\n * pkPath: './circuit/circuit.pk',\n * vkPath: './circuit/circuit.vk',\n * circuitPath: './circuit/circuit.json',\n * });\n *\n * // Use like regular IziNoir (but only prove/verify, not compile)\n * const proof = await izi.prove(inputs);\n * const verified = await izi.verify(proof.proof, proof.publicInputs);\n * ```\n *\n * @module @izi-noir/sdk/sunspot\n */\n\nimport type { IProvingSystem } from '../domain/interfaces/proving/IProvingSystem.js';\nimport type { CompiledCircuit, InputMap, ProofData } from '../domain/types.js';\nimport type { CircuitPaths } from '../domain/types/provider.js';\nimport { Sunspot } from '../infra/provingSystems/Sunspot.js';\n\nexport { Sunspot } from '../infra/provingSystems/Sunspot.js';\nexport type { SunspotInitConfig } from '../infra/provingSystems/Sunspot.js';\nexport type {\n SunspotConfig,\n SunspotCircuitPaths,\n SunspotCompiledCircuit,\n} from '../infra/sunspot/types.js';\nexport { isSunspotCircuit, SunspotCliError } from '../infra/sunspot/types.js';\n\n// Re-export common types\nexport { Provider, type IziNoirConfig, type CircuitPaths } from '../domain/types/provider.js';\nexport type { CompiledCircuit, InputMap, ProofData } from '../domain/types.js';\nexport type { IProvingSystem } from '../domain/interfaces/proving/IProvingSystem.js';\n\n/**\n * IziNoir-like wrapper for Sunspot.\n * Provides a similar API to IziNoir but backed by the Sunspot proving system.\n */\nexport class IziNoirSunspot {\n private provingSystem: IProvingSystem;\n private compiledCircuit: CompiledCircuit | null = null;\n\n private constructor(provingSystem: IProvingSystem) {\n this.provingSystem = provingSystem;\n }\n\n /**\n * Initialize IziNoirSunspot with pre-compiled circuit paths.\n * Note: Sunspot requires pre-compiled circuits for prove/verify operations.\n *\n * @param circuitPaths - Paths to the pre-compiled circuit files\n */\n static async init(circuitPaths: CircuitPaths): Promise<IziNoirSunspot> {\n const sunspot = new Sunspot(circuitPaths);\n return new IziNoirSunspot(sunspot);\n }\n\n /**\n * Initialize IziNoirSunspot for full compilation mode.\n * Requires nargo and sunspot CLI tools to be installed.\n */\n static async initForCompilation(): Promise<IziNoirSunspot> {\n const sunspot = new Sunspot();\n return new IziNoirSunspot(sunspot);\n }\n\n getProvingSystem(): IProvingSystem {\n return this.provingSystem;\n }\n\n getCompiledCircuit(): CompiledCircuit | null {\n return this.compiledCircuit;\n }\n\n async compile(noirCode: string): Promise<CompiledCircuit> {\n this.compiledCircuit = await this.provingSystem.compile(noirCode);\n return this.compiledCircuit;\n }\n\n async prove(inputs: InputMap, circuit?: CompiledCircuit): Promise<ProofData> {\n const circuitToUse = circuit || this.compiledCircuit;\n if (!circuitToUse) {\n throw new Error('No circuit available. Call compile() first or provide a circuit.');\n }\n return this.provingSystem.generateProof(circuitToUse, inputs);\n }\n\n async verify(\n proof: Uint8Array,\n publicInputs: string[],\n circuit?: CompiledCircuit\n ): Promise<boolean> {\n const circuitToUse = circuit || this.compiledCircuit;\n if (!circuitToUse) {\n throw new Error('No circuit available. Call compile() first or provide a circuit.');\n }\n return this.provingSystem.verifyProof(circuitToUse, proof, publicInputs);\n }\n\n async createProof(\n noirCode: string,\n inputs: InputMap\n ): Promise<{ proof: ProofData; verified: boolean }> {\n const circuit = await this.compile(noirCode);\n const proof = await this.prove(inputs, circuit);\n const verified = await this.verify(proof.proof, proof.publicInputs, circuit);\n return { proof, verified };\n }\n}\n\n/**\n * Helper function to create an IziNoirSunspot instance with pre-compiled circuit paths.\n * @deprecated Use `IziNoirSunspot.init(circuitPaths)` instead.\n */\nexport async function initSunspotIziNoir(circuitPaths: CircuitPaths): Promise<IziNoirSunspot> {\n return IziNoirSunspot.init(circuitPaths);\n}\n"],"mappings":";AAAA,SAAS,UAAU,WAAW,IAAI,SAAS,aAAa;AACxD,SAAS,MAAM,eAAe;AAC9B,SAAS,cAAc;;;ACchB,IAAM,yBAAwC;AAAA,EACnD,iBAAiB,QAAQ,IAAI,cAAc;AAAA,EAC3C,mBAAmB,QAAQ,IAAI,gBAAgB;AAAA,EAC/C,eAAe,QAAQ,IAAI,2BAA2B;AAAA,EACtD,WAAW;AACb;AAyCO,SAAS,iBAAiB,SAA6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