@izi-noir/sdk 0.1.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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +458 -0
  3. package/dist/IProvingSystem-D9TnEig0.d.ts +140 -0
  4. package/dist/IProvingSystem-TKNofoo8.d.cts +140 -0
  5. package/dist/index.cjs +2793 -0
  6. package/dist/index.cjs.map +1 -0
  7. package/dist/index.d.cts +1196 -0
  8. package/dist/index.d.ts +1196 -0
  9. package/dist/index.js +2730 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/providers/arkworks.cjs +824 -0
  12. package/dist/providers/arkworks.cjs.map +1 -0
  13. package/dist/providers/arkworks.d.cts +121 -0
  14. package/dist/providers/arkworks.d.ts +121 -0
  15. package/dist/providers/arkworks.js +791 -0
  16. package/dist/providers/arkworks.js.map +1 -0
  17. package/dist/providers/barretenberg.cjs +822 -0
  18. package/dist/providers/barretenberg.cjs.map +1 -0
  19. package/dist/providers/barretenberg.d.cts +18 -0
  20. package/dist/providers/barretenberg.d.ts +18 -0
  21. package/dist/providers/barretenberg.js +790 -0
  22. package/dist/providers/barretenberg.js.map +1 -0
  23. package/dist/providers/solana.cjs +262 -0
  24. package/dist/providers/solana.cjs.map +1 -0
  25. package/dist/providers/solana.d.cts +223 -0
  26. package/dist/providers/solana.d.ts +223 -0
  27. package/dist/providers/solana.js +222 -0
  28. package/dist/providers/solana.js.map +1 -0
  29. package/dist/providers/sunspot.cjs +475 -0
  30. package/dist/providers/sunspot.cjs.map +1 -0
  31. package/dist/providers/sunspot.d.cts +210 -0
  32. package/dist/providers/sunspot.d.ts +210 -0
  33. package/dist/providers/sunspot.js +443 -0
  34. package/dist/providers/sunspot.js.map +1 -0
  35. package/dist/types-CaaigonG.d.cts +93 -0
  36. package/dist/types-CaaigonG.d.ts +93 -0
  37. package/dist/wasm/nodejs/arkworks_groth16_wasm.js +448 -0
  38. package/dist/wasm/nodejs/arkworks_groth16_wasm_bg.wasm +0 -0
  39. package/dist/wasm/web/arkworks_groth16_wasm.js +536 -0
  40. package/dist/wasm/web/arkworks_groth16_wasm_bg.wasm +0 -0
  41. package/dist/wasmInit-KV6DTj4J.d.ts +282 -0
  42. package/dist/wasmInit-iEYiiB8M.d.cts +282 -0
  43. package/package.json +87 -0
@@ -0,0 +1,1196 @@
1
+ import { I as IChainFormatter } from './wasmInit-iEYiiB8M.cjs';
2
+ export { C as ChainProofDataFor, a as IziNoir, S as SolanaDeployData, i as initNoirWasm, b as isWasmInitialized, m as markWasmInitialized } from './wasmInit-iEYiiB8M.cjs';
3
+ import { P as ProofData, S as SolanaProofData, C as CircuitFunction, I as InputValue, a as ProofResult } from './types-CaaigonG.cjs';
4
+ export { b as ProofTimings, c as ProverOptions, d as VerifierOptions, V as VerifyingKeyData } from './types-CaaigonG.cjs';
5
+ import { a as CircuitMetadata, S as SolanaChainMetadata, d as IProvingSystem } from './IProvingSystem-TKNofoo8.cjs';
6
+ export { c as Chain, C as ChainId, f as ChainMetadata, b as ChainMetadataFor, e as CircuitPaths, E as EthereumChainMetadata, g as ICompiler, h as IProver, i as IVerifier, I as IziNoirConfig, P as Provider } from './IProvingSystem-TKNofoo8.cjs';
7
+ import { ArkworksWasm, ArkworksWasmConfig } from './providers/arkworks.cjs';
8
+ export { ArkworksCompiledCircuit, ArkworksProofResult, ArkworksSetupResult, ArkworksWasmModule, isArkworksCircuit } from './providers/arkworks.cjs';
9
+ import { CompiledCircuit } from '@noir-lang/types';
10
+ export { CompiledCircuit, InputMap } from '@noir-lang/types';
11
+ export { Barretenberg } from './providers/barretenberg.cjs';
12
+ export { IZI_NOIR_PROGRAM_ID, buildInitVkFromBytesData, buildVerifyProofData, calculateVkAccountRent, calculateVkAccountSize, parseProof, parsePublicInputs, parseVerifyingKey } from './providers/solana.cjs';
13
+
14
+ /**
15
+ * Formatter for Solana-compatible proof data.
16
+ *
17
+ * Converts generic ProofData into SolanaProofData format with:
18
+ * - Verifying key in gnark format (compatible with gnark-verifier-solana)
19
+ * - Proof bytes (256 bytes Groth16)
20
+ * - Public inputs as 32-byte arrays
21
+ * - VK account size and rent estimates
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const formatter = new SolanaFormatter(arkworksProvider);
26
+ * const solanaProof = await formatter.formatProof(proofData, circuit, metadata);
27
+ * ```
28
+ */
29
+ declare class SolanaFormatter implements IChainFormatter<'solana'> {
30
+ private arkworksProvider;
31
+ readonly chainId: "solana";
32
+ constructor(arkworksProvider: ArkworksWasm);
33
+ /**
34
+ * Format a generic proof for Solana on-chain verification.
35
+ *
36
+ * @param proofData - Generic proof data from Arkworks
37
+ * @param circuit - The compiled circuit (must be Arkworks circuit)
38
+ * @param metadata - Circuit metadata with public input count
39
+ * @returns SolanaProofData ready for on-chain verification
40
+ */
41
+ formatProof(proofData: ProofData, circuit: CompiledCircuit, metadata: CircuitMetadata): Promise<SolanaProofData>;
42
+ /**
43
+ * Get Solana-specific metadata for a circuit.
44
+ *
45
+ * @param publicInputCount - Number of public inputs in the circuit
46
+ * @returns Solana metadata with account size and rent estimates
47
+ */
48
+ getChainMetadata(publicInputCount: number): SolanaChainMetadata;
49
+ /**
50
+ * Calculate the size of a VK account for a given number of public inputs.
51
+ * Matches the Rust `vk_account_size` function in the Solana program.
52
+ */
53
+ private calculateVkAccountSize;
54
+ /**
55
+ * Calculate the minimum rent for a VK account.
56
+ */
57
+ private calculateVkAccountRent;
58
+ /**
59
+ * Convert Uint8Array to base64 string.
60
+ */
61
+ private uint8ArrayToBase64;
62
+ /**
63
+ * Convert hex string to Uint8Array.
64
+ */
65
+ private hexToBytes;
66
+ }
67
+
68
+ interface CircuitParam {
69
+ name: string;
70
+ index: number;
71
+ }
72
+ interface BinaryExpr {
73
+ kind: 'binary';
74
+ left: Expr;
75
+ operator: BinaryOperator;
76
+ right: Expr;
77
+ }
78
+ interface IdentifierExpr {
79
+ kind: 'identifier';
80
+ name: string;
81
+ }
82
+ interface LiteralExpr {
83
+ kind: 'literal';
84
+ value: number | string | bigint;
85
+ }
86
+ interface MemberExpr {
87
+ kind: 'member';
88
+ object: Expr;
89
+ index: Expr;
90
+ }
91
+ interface ArrayLiteralExpr {
92
+ kind: 'array_literal';
93
+ elements: Expr[];
94
+ }
95
+ interface CallExpr {
96
+ kind: 'call';
97
+ callee: Expr;
98
+ method?: string;
99
+ args: Expr[];
100
+ }
101
+ type BinaryOperator = '==' | '!=' | '+' | '-' | '*' | '/' | '%' | '<' | '>' | '<=' | '>=' | '&' | '|';
102
+ type UnaryOperator = '!' | '-';
103
+ interface UnaryExpr {
104
+ kind: 'unary';
105
+ operator: UnaryOperator;
106
+ operand: Expr;
107
+ }
108
+ interface IfExpr {
109
+ kind: 'if_expr';
110
+ condition: Expr;
111
+ consequent: Expr;
112
+ alternate: Expr;
113
+ }
114
+ type Expr = BinaryExpr | UnaryExpr | IdentifierExpr | LiteralExpr | MemberExpr | ArrayLiteralExpr | CallExpr | IfExpr;
115
+ interface AssertStatement {
116
+ kind: 'assert';
117
+ condition: Expr;
118
+ message?: string;
119
+ }
120
+ interface VariableDeclaration {
121
+ kind: 'variable_declaration';
122
+ name: string;
123
+ mutable: boolean;
124
+ initializer: Expr;
125
+ }
126
+ interface AssignmentStatement {
127
+ kind: 'assignment';
128
+ target: string;
129
+ value: Expr;
130
+ }
131
+ interface IfStatement {
132
+ kind: 'if_statement';
133
+ condition: Expr;
134
+ consequent: Statement[];
135
+ alternate?: Statement[];
136
+ }
137
+ interface ForStatement {
138
+ kind: 'for_statement';
139
+ variable: string;
140
+ start: Expr;
141
+ end: Expr;
142
+ inclusive: boolean;
143
+ body: Statement[];
144
+ }
145
+ type Statement = AssertStatement | VariableDeclaration | AssignmentStatement | IfStatement | ForStatement;
146
+ interface ParsedCircuit {
147
+ publicParams: CircuitParam[];
148
+ privateParams: CircuitParam[];
149
+ statements: Statement[];
150
+ }
151
+
152
+ interface IParser {
153
+ parse(fn: CircuitFunction, publicInputs: InputValue[], privateInputs: InputValue[]): ParsedCircuit;
154
+ }
155
+
156
+ interface CreateProofDependencies {
157
+ parser: IParser;
158
+ provingSystem: IProvingSystem;
159
+ }
160
+ declare class CreateProofUseCase {
161
+ private readonly deps;
162
+ constructor(deps: CreateProofDependencies);
163
+ execute(publicInputs: InputValue[], privateInputs: InputValue[], circuitFn: CircuitFunction): Promise<ProofResult>;
164
+ }
165
+
166
+ /**
167
+ * Create default container with Barretenberg backend
168
+ *
169
+ * @deprecated Use IziNoir.init({ provider: Provider.Barretenberg }) instead
170
+ */
171
+ declare function createDefaultContainer(): CreateProofDependencies;
172
+ /**
173
+ * Create container with ArkworksWasm backend (Groth16 for Solana, 100% browser)
174
+ *
175
+ * @deprecated Use IziNoir.init({ provider: Provider.Arkworks }) instead
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * // Preferred:
180
+ * const izi = await IziNoir.init({ provider: Provider.Arkworks });
181
+ * await izi.compile(noirCode);
182
+ * const proof = await izi.proveForChain('solana', inputs);
183
+ * ```
184
+ */
185
+ declare function createArkworksWasmContainer(config?: ArkworksWasmConfig): CreateProofDependencies;
186
+
187
+ /**
188
+ * Parses JavaScript circuit functions into a structured representation.
189
+ *
190
+ * The AcornParser is the main orchestrator that:
191
+ * 1. Parses JS source using Acorn
192
+ * 2. Extracts parameters from ([public], [private]) => {} pattern
193
+ * 3. Delegates statement/expression parsing to specialized parsers
194
+ *
195
+ * Architecture:
196
+ * - ExpressionParser: Handles all expression types
197
+ * - StatementParser: Handles statements (vars, if, assert, assignments)
198
+ * - ForLoopParser: Handles for loop validation and parsing
199
+ */
200
+ declare class AcornParser implements IParser {
201
+ private exprParser;
202
+ private forLoopParser;
203
+ private stmtParser;
204
+ /**
205
+ * Parses a circuit function into public/private parameters and statements.
206
+ *
207
+ * @param fn The circuit function with signature ([public], [private]) => { ... }
208
+ * @param _publicInputs Public input values (used for validation, not parsing)
209
+ * @param _privateInputs Private input values (used for validation, not parsing)
210
+ */
211
+ parse(fn: CircuitFunction, _publicInputs: InputValue[], _privateInputs: InputValue[]): ParsedCircuit;
212
+ /**
213
+ * Finds the arrow function or function expression in the AST.
214
+ */
215
+ private findFunctionNode;
216
+ /**
217
+ * Extracts public and private parameters from the function signature.
218
+ * Expects pattern: ([pub1, pub2], [priv1, priv2]) => { ... }
219
+ */
220
+ private extractParameters;
221
+ /**
222
+ * Parses the function body into statements.
223
+ */
224
+ private parseBody;
225
+ }
226
+
227
+ declare function generateNoir(circuit: ParsedCircuit): string;
228
+
229
+ /**
230
+ * Transaction builder for IZI-NOIR Solana program.
231
+ *
232
+ * Provides a high-level API for building Solana transactions without
233
+ * requiring Anchor or deep knowledge of instruction formats.
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * import { SolanaTransactionBuilder } from '@izi-noir/sdk';
238
+ *
239
+ * const builder = new SolanaTransactionBuilder({
240
+ * computeUnits: 400_000,
241
+ * programId: 'EYhRED7EuMyyVjx57aDXUD9h6ArnEKng64qtz8999KrS',
242
+ * });
243
+ *
244
+ * // Build init VK transaction
245
+ * const initData = builder.buildInitVkInstructionData(solanaProofData);
246
+ *
247
+ * // Build verify proof transaction
248
+ * const verifyData = builder.buildVerifyProofInstructionData(
249
+ * solanaProofData.proof.bytes,
250
+ * solanaProofData.publicInputs.bytes
251
+ * );
252
+ * ```
253
+ *
254
+ * @module @izi-noir/sdk/solana
255
+ */
256
+
257
+ /**
258
+ * Configuration for the transaction builder.
259
+ */
260
+ interface TransactionBuilderConfig {
261
+ /**
262
+ * Program ID of the IZI-NOIR verifier program.
263
+ * Defaults to the deployed devnet program.
264
+ */
265
+ programId?: string;
266
+ /**
267
+ * Compute units to request for transactions.
268
+ * Default: 400,000 (sufficient for most proof verifications)
269
+ */
270
+ computeUnits?: number;
271
+ /**
272
+ * Priority fee in microLamports per compute unit.
273
+ * Default: 0 (no priority fee)
274
+ */
275
+ priorityFee?: number;
276
+ }
277
+ /**
278
+ * Account configuration for init_vk instruction.
279
+ */
280
+ interface InitVkAccounts {
281
+ /** Public key of the VK account (as base58 string) */
282
+ vkAccount: string;
283
+ /** Public key of the authority (as base58 string) */
284
+ authority: string;
285
+ /** Public key of the payer (as base58 string) */
286
+ payer: string;
287
+ }
288
+ /**
289
+ * Account configuration for verify_proof instruction.
290
+ */
291
+ interface VerifyProofAccounts {
292
+ /** Public key of the VK account (as base58 string) */
293
+ vkAccount: string;
294
+ }
295
+ /**
296
+ * Account configuration for close_vk instruction.
297
+ */
298
+ interface CloseVkAccounts {
299
+ /** Public key of the VK account (as base58 string) */
300
+ vkAccount: string;
301
+ /** Public key of the authority (as base58 string) */
302
+ authority: string;
303
+ }
304
+ /**
305
+ * Instruction data and accounts for a Solana instruction.
306
+ */
307
+ interface InstructionData {
308
+ /** Raw instruction data bytes */
309
+ data: Uint8Array;
310
+ /** Program ID (base58) */
311
+ programId: string;
312
+ /** Account keys with metadata */
313
+ keys: Array<{
314
+ pubkey: string;
315
+ isSigner: boolean;
316
+ isWritable: boolean;
317
+ }>;
318
+ }
319
+ /**
320
+ * Result of building init and verify transactions together.
321
+ */
322
+ interface InitAndVerifyInstructions {
323
+ /** Init VK instruction */
324
+ initVk: InstructionData;
325
+ /** Verify proof instruction */
326
+ verifyProof: InstructionData;
327
+ /** Compute budget instruction (set compute units) */
328
+ computeBudget?: InstructionData;
329
+ /** Priority fee instruction (if configured) */
330
+ priorityFee?: InstructionData;
331
+ /** Required rent for VK account in lamports */
332
+ rentLamports: number;
333
+ /** Size of VK account in bytes */
334
+ accountSize: number;
335
+ }
336
+ /**
337
+ * Transaction builder for IZI-NOIR Solana program.
338
+ *
339
+ * This class provides methods to build instruction data for the IZI-NOIR
340
+ * Solana program without requiring Anchor or @solana/web3.js dependencies.
341
+ *
342
+ * The returned instruction data can be used with any Solana library:
343
+ * - @solana/web3.js
344
+ * - @solana/kit (new)
345
+ * - Anchor
346
+ * - Mobile wallet adapters
347
+ */
348
+ declare class SolanaTransactionBuilder {
349
+ private programId;
350
+ private computeUnits;
351
+ private priorityFee;
352
+ constructor(config?: TransactionBuilderConfig);
353
+ /**
354
+ * Builds the instruction data for initializing a VK account.
355
+ *
356
+ * @param solanaProofData - Proof data from `izi.proveForSolana()`
357
+ * @param accounts - Account public keys
358
+ * @returns Instruction data ready for transaction building
359
+ *
360
+ * @example
361
+ * ```typescript
362
+ * const initInstruction = builder.buildInitVkInstruction(solanaProofData, {
363
+ * vkAccount: vkKeypair.publicKey.toBase58(),
364
+ * authority: wallet.publicKey.toBase58(),
365
+ * payer: wallet.publicKey.toBase58(),
366
+ * });
367
+ * ```
368
+ */
369
+ buildInitVkInstruction(solanaProofData: SolanaProofData, accounts: InitVkAccounts): InstructionData;
370
+ /**
371
+ * Builds the instruction data for verifying a proof.
372
+ *
373
+ * @param proofBytes - 256-byte Groth16 proof
374
+ * @param publicInputs - Array of 32-byte public inputs
375
+ * @param accounts - Account public keys
376
+ * @returns Instruction data ready for transaction building
377
+ *
378
+ * @example
379
+ * ```typescript
380
+ * const verifyInstruction = builder.buildVerifyProofInstruction(
381
+ * solanaProofData.proof.bytes,
382
+ * solanaProofData.publicInputs.bytes,
383
+ * { vkAccount: vkAccountPubkey.toBase58() }
384
+ * );
385
+ * ```
386
+ */
387
+ buildVerifyProofInstruction(proofBytes: Uint8Array, publicInputs: Uint8Array[], accounts: VerifyProofAccounts): InstructionData;
388
+ /**
389
+ * Builds the instruction data for closing a VK account.
390
+ *
391
+ * @param accounts - Account public keys
392
+ * @returns Instruction data ready for transaction building
393
+ */
394
+ buildCloseVkInstruction(accounts: CloseVkAccounts): InstructionData;
395
+ /**
396
+ * Builds a compute budget instruction to set compute unit limit.
397
+ *
398
+ * @param units - Number of compute units (default: configured value)
399
+ * @returns Instruction data
400
+ */
401
+ buildSetComputeUnitLimitInstruction(units?: number): InstructionData;
402
+ /**
403
+ * Builds a compute budget instruction to set priority fee.
404
+ *
405
+ * @param microLamports - Priority fee in microLamports per CU
406
+ * @returns Instruction data
407
+ */
408
+ buildSetComputeUnitPriceInstruction(microLamports?: number): InstructionData;
409
+ /**
410
+ * Builds all instructions needed to initialize a VK and verify a proof.
411
+ *
412
+ * This is a convenience method that combines:
413
+ * - Compute budget instructions (if configured)
414
+ * - Init VK instruction
415
+ * - Verify proof instruction
416
+ *
417
+ * @param solanaProofData - Proof data from `izi.proveForSolana()`
418
+ * @param vkAccountPubkey - Public key for the new VK account
419
+ * @param authorityPubkey - Authority for the VK account
420
+ * @param payerPubkey - Payer for the transaction
421
+ * @returns All instruction data and metadata
422
+ *
423
+ * @example
424
+ * ```typescript
425
+ * const result = builder.buildInitAndVerifyInstructions(
426
+ * solanaProofData,
427
+ * vkKeypair.publicKey.toBase58(),
428
+ * wallet.publicKey.toBase58(),
429
+ * wallet.publicKey.toBase58()
430
+ * );
431
+ *
432
+ * // Use with @solana/web3.js:
433
+ * const transaction = new Transaction();
434
+ * if (result.computeBudget) {
435
+ * transaction.add(toTransactionInstruction(result.computeBudget));
436
+ * }
437
+ * transaction.add(toTransactionInstruction(result.initVk));
438
+ * // ... sign and send
439
+ * ```
440
+ */
441
+ buildInitAndVerifyInstructions(solanaProofData: SolanaProofData, vkAccountPubkey: string, authorityPubkey: string, payerPubkey: string): InitAndVerifyInstructions;
442
+ /**
443
+ * Validates that SolanaProofData has the correct format.
444
+ *
445
+ * @param data - Proof data to validate
446
+ * @throws Error if validation fails
447
+ */
448
+ validateSolanaProofData(data: SolanaProofData): void;
449
+ /**
450
+ * Gets the program ID being used.
451
+ */
452
+ getProgramId(): string;
453
+ /**
454
+ * Gets the configured compute units.
455
+ */
456
+ getComputeUnits(): number;
457
+ /**
458
+ * Gets the configured priority fee.
459
+ */
460
+ getPriorityFee(): number;
461
+ }
462
+
463
+ /**
464
+ * VK Deployment Manager for IZI-NOIR.
465
+ *
466
+ * Provides idempotent deployment of verifying keys to Solana with
467
+ * local persistence for tracking deployed circuits.
468
+ *
469
+ * @example
470
+ * ```typescript
471
+ * import { VkDeploymentManager } from '@izi-noir/sdk';
472
+ *
473
+ * const manager = new VkDeploymentManager({
474
+ * network: 'devnet',
475
+ * configDir: './.izi-noir', // optional, defaults to .izi-noir
476
+ * });
477
+ *
478
+ * // Deploy (idempotent - won't redeploy if already deployed)
479
+ * const deployment = await manager.ensureDeployed({
480
+ * circuitName: 'balance-check',
481
+ * solanaProofData,
482
+ * sendTransaction: async (tx) => {
483
+ * // Sign and send using your wallet adapter
484
+ * return await wallet.sendTransaction(tx, connection);
485
+ * },
486
+ * });
487
+ *
488
+ * console.log(`VK at: ${deployment.vkAccount}`);
489
+ *
490
+ * // Save deployment state
491
+ * await manager.save();
492
+ * ```
493
+ *
494
+ * @module @izi-noir/sdk/deployment
495
+ */
496
+
497
+ /**
498
+ * Supported Solana networks.
499
+ */
500
+ type SolanaNetwork = 'mainnet-beta' | 'devnet' | 'testnet' | 'localnet';
501
+ /**
502
+ * Network RPC endpoints.
503
+ */
504
+ declare const NETWORK_ENDPOINTS: Record<SolanaNetwork, string>;
505
+ /**
506
+ * Configuration for VK Deployment Manager.
507
+ */
508
+ interface VkDeploymentManagerConfig {
509
+ /**
510
+ * Solana network to deploy to.
511
+ */
512
+ network: SolanaNetwork;
513
+ /**
514
+ * Custom RPC endpoint. Overrides network default.
515
+ */
516
+ rpcEndpoint?: string;
517
+ /**
518
+ * Directory to store deployment config. Default: '.izi-noir'
519
+ */
520
+ configDir?: string;
521
+ /**
522
+ * Program ID override.
523
+ */
524
+ programId?: string;
525
+ /**
526
+ * Compute units for transactions. Default: 400,000
527
+ */
528
+ computeUnits?: number;
529
+ }
530
+ /**
531
+ * Record of a deployed VK.
532
+ */
533
+ interface VkDeployment {
534
+ /** Circuit identifier (name or hash) */
535
+ circuitId: string;
536
+ /** VK account public key (base58) */
537
+ vkAccount: string;
538
+ /** Authority public key (base58) */
539
+ authority: string;
540
+ /** Deployment timestamp */
541
+ deployedAt: string;
542
+ /** Transaction signature */
543
+ txSignature: string;
544
+ /** Network deployed to */
545
+ network: SolanaNetwork;
546
+ /** Hash of the VK bytes for deduplication */
547
+ vkHash: string;
548
+ /** Number of public inputs */
549
+ nrPublicInputs: number;
550
+ }
551
+ /**
552
+ * Options for ensureDeployed method.
553
+ */
554
+ interface EnsureDeployedOptions {
555
+ /**
556
+ * Identifier for the circuit (used for lookup).
557
+ */
558
+ circuitName: string;
559
+ /**
560
+ * Proof data containing VK bytes.
561
+ */
562
+ solanaProofData: SolanaProofData;
563
+ /**
564
+ * Function to send a transaction.
565
+ * Should return the transaction signature.
566
+ */
567
+ sendTransaction: (instructions: InstructionData[], signers: SignerInfo[]) => Promise<string>;
568
+ /**
569
+ * Authority public key (base58).
570
+ */
571
+ authority: string;
572
+ /**
573
+ * Payer public key (base58).
574
+ */
575
+ payer: string;
576
+ /**
577
+ * Force redeploy even if already exists.
578
+ */
579
+ forceRedeploy?: boolean;
580
+ }
581
+ /**
582
+ * Information about required signers.
583
+ */
584
+ interface SignerInfo {
585
+ /** Public key of the signer (base58) */
586
+ pubkey: string;
587
+ /** Whether this is a new keypair that needs to be generated */
588
+ isNewKeypair: boolean;
589
+ /** Description of the signer role */
590
+ role: 'vkAccount' | 'authority' | 'payer';
591
+ }
592
+ /**
593
+ * Result of deployment operation.
594
+ */
595
+ interface DeploymentResult {
596
+ /** Whether deployment was performed (false if already deployed) */
597
+ deployed: boolean;
598
+ /** VK account address */
599
+ vkAccount: string;
600
+ /** Transaction signature (if deployed) */
601
+ txSignature?: string;
602
+ /** Full deployment record */
603
+ deployment: VkDeployment;
604
+ }
605
+ /**
606
+ * Deployments state file structure.
607
+ */
608
+ interface DeploymentsState {
609
+ version: '1.0';
610
+ deployments: VkDeployment[];
611
+ }
612
+ /**
613
+ * VK Deployment Manager.
614
+ *
615
+ * Manages deployment of verifying keys to Solana with:
616
+ * - Idempotent deployments (skip if already deployed)
617
+ * - Local persistence of deployment records
618
+ * - Network-aware configuration
619
+ */
620
+ declare class VkDeploymentManager {
621
+ private config;
622
+ private deployments;
623
+ private builder;
624
+ private dirty;
625
+ constructor(config: VkDeploymentManagerConfig);
626
+ /**
627
+ * Loads deployment state from disk.
628
+ *
629
+ * In browser environments, this is a no-op.
630
+ * In Node.js, reads from {configDir}/deployments.json
631
+ */
632
+ load(): Promise<void>;
633
+ /**
634
+ * Loads deployment state from a JSON object.
635
+ */
636
+ loadFromJson(state: DeploymentsState): void;
637
+ /**
638
+ * Saves deployment state.
639
+ *
640
+ * Returns the state object for custom persistence.
641
+ */
642
+ save(): Promise<DeploymentsState>;
643
+ /**
644
+ * Exports deployment state to JSON.
645
+ */
646
+ toJson(): DeploymentsState;
647
+ /**
648
+ * Ensures a VK is deployed, skipping if already exists.
649
+ *
650
+ * @returns Deployment result with VK account address
651
+ */
652
+ ensureDeployed(options: EnsureDeployedOptions): Promise<DeploymentResult>;
653
+ /**
654
+ * Gets deployment by circuit name.
655
+ */
656
+ getDeployment(circuitName: string): VkDeployment | undefined;
657
+ /**
658
+ * Gets deployment by VK hash.
659
+ */
660
+ getDeploymentByVkHash(vkHash: string): VkDeployment | undefined;
661
+ /**
662
+ * Gets all deployments.
663
+ */
664
+ getAllDeployments(): VkDeployment[];
665
+ /**
666
+ * Checks if there are unsaved changes.
667
+ */
668
+ isDirty(): boolean;
669
+ /**
670
+ * Gets the RPC endpoint.
671
+ */
672
+ getRpcEndpoint(): string;
673
+ /**
674
+ * Gets the network.
675
+ */
676
+ getNetwork(): SolanaNetwork;
677
+ /**
678
+ * Prepares instructions for deployment without sending.
679
+ *
680
+ * Useful when you need to combine with other instructions
681
+ * or use a specific signing flow.
682
+ */
683
+ prepareDeployment(solanaProofData: SolanaProofData, accounts: {
684
+ vkAccount: string;
685
+ authority: string;
686
+ payer: string;
687
+ }): {
688
+ instructions: InstructionData[];
689
+ signers: SignerInfo[];
690
+ rentLamports: number;
691
+ };
692
+ /**
693
+ * Records an external deployment (made outside this manager).
694
+ */
695
+ recordDeployment(deployment: VkDeployment): void;
696
+ /**
697
+ * Removes a deployment record.
698
+ */
699
+ removeDeployment(circuitName: string): boolean;
700
+ private makeDeploymentKey;
701
+ private hashVkBytes;
702
+ private generateVkAccountPlaceholder;
703
+ }
704
+ /**
705
+ * Creates a VK Deployment Manager with Node.js file persistence.
706
+ *
707
+ * @example
708
+ * ```typescript
709
+ * const manager = await createNodeVkDeploymentManager({
710
+ * network: 'devnet',
711
+ * configDir: './.izi-noir',
712
+ * });
713
+ *
714
+ * // Automatically loads existing deployments
715
+ * // and saves on manager.save()
716
+ * ```
717
+ */
718
+ declare function createNodeVkDeploymentManager(config: VkDeploymentManagerConfig): Promise<VkDeploymentManager>;
719
+
720
+ /**
721
+ * Circuit Registry for IZI-NOIR.
722
+ *
723
+ * Provides naming, versioning, and metadata management for JS circuits.
724
+ * Enables circuit reuse and documentation generation.
725
+ *
726
+ * @example
727
+ * ```typescript
728
+ * import { CircuitRegistry } from '@izi-noir/sdk';
729
+ *
730
+ * const registry = new CircuitRegistry();
731
+ *
732
+ * // Register a circuit
733
+ * registry.register({
734
+ * name: 'balance-check',
735
+ * version: '1.0.0',
736
+ * description: 'Proves balance >= minimum without revealing actual balance',
737
+ * jsCircuit: ([minimum], [balance]) => {
738
+ * assert(balance >= minimum);
739
+ * },
740
+ * publicInputs: [{ name: 'minimum', type: 'Field', description: 'Minimum required balance' }],
741
+ * privateInputs: [{ name: 'balance', type: 'Field', description: 'Actual balance (kept private)' }],
742
+ * tags: ['finance', 'privacy'],
743
+ * });
744
+ *
745
+ * // Use the circuit
746
+ * const circuit = registry.get('balance-check');
747
+ * const result = await izi.createProof(circuit.jsCircuit, [100], [250]);
748
+ * ```
749
+ *
750
+ * @module @izi-noir/sdk/registry
751
+ */
752
+
753
+ /**
754
+ * Input field definition with metadata.
755
+ */
756
+ interface CircuitInputDef {
757
+ /** Name of the input */
758
+ name: string;
759
+ /** Type in Noir (Field, u8, u32, etc.) */
760
+ type: 'Field' | 'u8' | 'u16' | 'u32' | 'u64' | 'bool' | string;
761
+ /** Human-readable description */
762
+ description?: string;
763
+ /** Optional constraint or validation info */
764
+ constraints?: string;
765
+ }
766
+ /**
767
+ * Circuit definition with metadata.
768
+ */
769
+ interface CircuitDefinition {
770
+ /** Unique identifier for the circuit */
771
+ name: string;
772
+ /** Semantic version (e.g., '1.0.0') */
773
+ version: string;
774
+ /** Human-readable description */
775
+ description?: string;
776
+ /** The JavaScript circuit function */
777
+ jsCircuit: CircuitFunction;
778
+ /** Public inputs metadata */
779
+ publicInputs: CircuitInputDef[];
780
+ /** Private inputs metadata */
781
+ privateInputs: CircuitInputDef[];
782
+ /** Optional tags for categorization */
783
+ tags?: string[];
784
+ /** Optional author information */
785
+ author?: string;
786
+ /** Optional license */
787
+ license?: string;
788
+ }
789
+ /**
790
+ * Registered circuit with computed metadata.
791
+ */
792
+ interface RegisteredCircuit extends CircuitDefinition {
793
+ /** When the circuit was registered */
794
+ registeredAt: Date;
795
+ /** Unique identifier combining name and version */
796
+ id: string;
797
+ /** Hash of the circuit function for change detection */
798
+ functionHash: string;
799
+ }
800
+ /**
801
+ * Options for circuit lookup.
802
+ */
803
+ interface GetCircuitOptions {
804
+ /** Specific version to get (default: latest) */
805
+ version?: string;
806
+ }
807
+ /**
808
+ * Circuit Registry.
809
+ *
810
+ * A registry for managing named, versioned circuits with rich metadata.
811
+ * Provides features for:
812
+ * - Semantic versioning
813
+ * - Input/output documentation
814
+ * - Tag-based categorization
815
+ * - Change detection
816
+ */
817
+ declare class CircuitRegistry {
818
+ private circuits;
819
+ /**
820
+ * Registers a new circuit.
821
+ *
822
+ * @param definition - Circuit definition with metadata
823
+ * @returns The registered circuit with computed fields
824
+ * @throws Error if circuit with same name and version exists
825
+ */
826
+ register(definition: CircuitDefinition): RegisteredCircuit;
827
+ /**
828
+ * Gets a circuit by name.
829
+ *
830
+ * @param name - Circuit name
831
+ * @param options - Lookup options (version, etc.)
832
+ * @returns The circuit or undefined if not found
833
+ */
834
+ get(name: string, options?: GetCircuitOptions): RegisteredCircuit | undefined;
835
+ /**
836
+ * Gets all versions of a circuit.
837
+ *
838
+ * @param name - Circuit name
839
+ * @returns Array of all registered versions
840
+ */
841
+ getVersions(name: string): RegisteredCircuit[];
842
+ /**
843
+ * Checks if a circuit exists.
844
+ *
845
+ * @param name - Circuit name
846
+ * @param version - Optional specific version
847
+ */
848
+ has(name: string, version?: string): boolean;
849
+ /**
850
+ * Gets all registered circuit names.
851
+ */
852
+ names(): string[];
853
+ /**
854
+ * Gets all registered circuits.
855
+ */
856
+ all(): RegisteredCircuit[];
857
+ /**
858
+ * Searches circuits by tag.
859
+ *
860
+ * @param tag - Tag to search for
861
+ * @returns Circuits with matching tag
862
+ */
863
+ findByTag(tag: string): RegisteredCircuit[];
864
+ /**
865
+ * Removes a circuit from the registry.
866
+ *
867
+ * @param name - Circuit name
868
+ * @param version - Optional specific version (removes all if not specified)
869
+ * @returns true if circuit was removed
870
+ */
871
+ remove(name: string, version?: string): boolean;
872
+ /**
873
+ * Exports the registry to a serializable format.
874
+ */
875
+ export(): CircuitRegistryExport;
876
+ /**
877
+ * Generates documentation for a circuit.
878
+ *
879
+ * @param name - Circuit name
880
+ * @returns Markdown documentation
881
+ */
882
+ generateDocs(name: string): string;
883
+ /**
884
+ * Validates circuit inputs against the definition.
885
+ *
886
+ * @param name - Circuit name
887
+ * @param publicInputs - Public inputs to validate
888
+ * @param privateInputs - Private inputs to validate
889
+ * @throws Error if validation fails
890
+ */
891
+ validateInputs(name: string, publicInputs: unknown[], privateInputs: unknown[]): void;
892
+ private hashFunction;
893
+ private compareVersions;
894
+ private validateInput;
895
+ }
896
+ /**
897
+ * Serializable circuit entry (without the function).
898
+ */
899
+ interface CircuitExportEntry {
900
+ name: string;
901
+ version: string;
902
+ description?: string;
903
+ publicInputs: CircuitInputDef[];
904
+ privateInputs: CircuitInputDef[];
905
+ tags?: string[];
906
+ author?: string;
907
+ license?: string;
908
+ registeredAt: string;
909
+ functionHash: string;
910
+ }
911
+ /**
912
+ * Serializable registry export.
913
+ */
914
+ interface CircuitRegistryExport {
915
+ version: '1.0';
916
+ exportedAt: string;
917
+ circuits: CircuitExportEntry[];
918
+ }
919
+ declare function getGlobalRegistry(): CircuitRegistry;
920
+ /**
921
+ * Decorator-style function to register a circuit with minimal boilerplate.
922
+ *
923
+ * @example
924
+ * ```typescript
925
+ * const balanceCheck = defineCircuit({
926
+ * name: 'balance-check',
927
+ * version: '1.0.0',
928
+ * publicInputs: [{ name: 'minimum', type: 'Field' }],
929
+ * privateInputs: [{ name: 'balance', type: 'Field' }],
930
+ * }, ([minimum], [balance]) => {
931
+ * assert(balance >= minimum);
932
+ * });
933
+ *
934
+ * // balanceCheck is now registered and contains the full definition
935
+ * ```
936
+ */
937
+ declare function defineCircuit(metadata: Omit<CircuitDefinition, 'jsCircuit'>, jsCircuit: CircuitFunction): RegisteredCircuit;
938
+
939
+ /**
940
+ * Off-Chain Verifier for IZI-NOIR.
941
+ *
942
+ * Provides ZK proof verification without on-chain transactions.
943
+ * Useful for API authentication, backend validation, and testing.
944
+ *
945
+ * @example
946
+ * ```typescript
947
+ * import { OffchainVerifier, createVerifierMiddleware } from '@izi-noir/sdk';
948
+ * import express from 'express';
949
+ *
950
+ * // Create verifier with compiled circuits
951
+ * const verifier = new OffchainVerifier();
952
+ *
953
+ * // Register circuits for verification
954
+ * await verifier.registerCircuit('age-check', {
955
+ * jsCircuit: ([minAge], [birthYear]) => {
956
+ * assert(2024 - birthYear >= minAge);
957
+ * }
958
+ * });
959
+ *
960
+ * // Use as Express middleware
961
+ * const app = express();
962
+ * app.post('/api/verify', createVerifierMiddleware(verifier));
963
+ *
964
+ * // Or verify directly
965
+ * const result = await verifier.verify({
966
+ * circuitName: 'age-check',
967
+ * proof: proofBytes,
968
+ * publicInputs: [18],
969
+ * });
970
+ *
971
+ * if (result.verified) {
972
+ * console.log('Proof valid!');
973
+ * }
974
+ * ```
975
+ *
976
+ * @module @izi-noir/sdk/server
977
+ */
978
+
979
+ /**
980
+ * Circuit configuration for offchain verification.
981
+ */
982
+ interface OffchainCircuitConfig {
983
+ /** JavaScript circuit function */
984
+ jsCircuit: CircuitFunction;
985
+ /** Pre-compiled circuit (optional, will compile if not provided) */
986
+ compiledCircuit?: CompiledCircuit;
987
+ /** Expected number of public inputs */
988
+ publicInputCount?: number;
989
+ }
990
+ /**
991
+ * Verification request.
992
+ */
993
+ interface VerifyRequest {
994
+ /** Circuit name to verify against */
995
+ circuitName: string;
996
+ /** Proof bytes (hex string or Uint8Array) */
997
+ proof: string | Uint8Array;
998
+ /** Public inputs (numbers or hex strings) */
999
+ publicInputs: Array<number | bigint | string>;
1000
+ }
1001
+ /**
1002
+ * Verification result.
1003
+ */
1004
+ interface VerifyResult {
1005
+ /** Whether the proof is valid */
1006
+ verified: boolean;
1007
+ /** Circuit name */
1008
+ circuitName: string;
1009
+ /** Verification time in milliseconds */
1010
+ verificationTimeMs: number;
1011
+ /** Error message if verification failed */
1012
+ error?: string;
1013
+ /** Public inputs that were verified */
1014
+ publicInputs: Array<number | bigint | string>;
1015
+ }
1016
+ /**
1017
+ * Configuration for OffchainVerifier.
1018
+ */
1019
+ interface OffchainVerifierConfig {
1020
+ /**
1021
+ * Callback to compile a circuit.
1022
+ * Required if registering circuits by jsCircuit without pre-compiled circuit.
1023
+ */
1024
+ compiler?: (jsCircuit: CircuitFunction) => Promise<CompiledCircuit>;
1025
+ /**
1026
+ * Callback to verify a proof against a compiled circuit.
1027
+ */
1028
+ verifier?: (circuit: CompiledCircuit, proof: Uint8Array, publicInputs: Uint8Array[]) => Promise<boolean>;
1029
+ }
1030
+ /**
1031
+ * Express-like request interface.
1032
+ */
1033
+ interface ExpressRequest {
1034
+ body: {
1035
+ circuitName?: string;
1036
+ proof?: string | Uint8Array;
1037
+ publicInputs?: Array<number | bigint | string>;
1038
+ };
1039
+ }
1040
+ /**
1041
+ * Express-like response interface.
1042
+ */
1043
+ interface ExpressResponse {
1044
+ status(code: number): ExpressResponse;
1045
+ json(body: unknown): ExpressResponse;
1046
+ }
1047
+ /**
1048
+ * Express-like next function.
1049
+ */
1050
+ type ExpressNext = (err?: Error) => void;
1051
+ /**
1052
+ * Off-chain ZK proof verifier.
1053
+ *
1054
+ * Manages registered circuits and provides proof verification
1055
+ * without requiring blockchain transactions.
1056
+ */
1057
+ declare class OffchainVerifier {
1058
+ private circuits;
1059
+ private compiledCircuits;
1060
+ private config;
1061
+ constructor(config?: OffchainVerifierConfig);
1062
+ /**
1063
+ * Registers a circuit for verification.
1064
+ *
1065
+ * @param name - Unique name for the circuit
1066
+ * @param config - Circuit configuration
1067
+ */
1068
+ registerCircuit(name: string, config: OffchainCircuitConfig): Promise<void>;
1069
+ /**
1070
+ * Registers a pre-compiled circuit.
1071
+ *
1072
+ * @param name - Unique name for the circuit
1073
+ * @param compiled - Pre-compiled circuit
1074
+ */
1075
+ registerCompiledCircuit(name: string, compiled: CompiledCircuit): void;
1076
+ /**
1077
+ * Verifies a ZK proof.
1078
+ *
1079
+ * @param request - Verification request with circuit name, proof, and public inputs
1080
+ * @returns Verification result
1081
+ */
1082
+ verify(request: VerifyRequest): Promise<VerifyResult>;
1083
+ /**
1084
+ * Checks if a circuit is registered.
1085
+ *
1086
+ * @param name - Circuit name
1087
+ */
1088
+ hasCircuit(name: string): boolean;
1089
+ /**
1090
+ * Gets all registered circuit names.
1091
+ */
1092
+ getCircuitNames(): string[];
1093
+ /**
1094
+ * Removes a circuit from the verifier.
1095
+ *
1096
+ * @param name - Circuit name to remove
1097
+ */
1098
+ removeCircuit(name: string): boolean;
1099
+ private toUint8Array;
1100
+ private publicInputToBytes;
1101
+ }
1102
+ /**
1103
+ * Creates an Express middleware for proof verification.
1104
+ *
1105
+ * @param verifier - The OffchainVerifier instance
1106
+ * @returns Express middleware function
1107
+ *
1108
+ * @example
1109
+ * ```typescript
1110
+ * import express from 'express';
1111
+ * import { OffchainVerifier, createVerifierMiddleware } from '@izi-noir/sdk';
1112
+ *
1113
+ * const app = express();
1114
+ * const verifier = new OffchainVerifier({ ... });
1115
+ *
1116
+ * // Register your circuits
1117
+ * await verifier.registerCircuit('my-circuit', { ... });
1118
+ *
1119
+ * // Add middleware
1120
+ * app.use(express.json());
1121
+ * app.post('/verify', createVerifierMiddleware(verifier));
1122
+ *
1123
+ * // Client sends:
1124
+ * // POST /verify
1125
+ * // { "circuitName": "my-circuit", "proof": "0x...", "publicInputs": [123, 456] }
1126
+ *
1127
+ * // Server responds:
1128
+ * // { "verified": true, "circuitName": "my-circuit", "verificationTimeMs": 42 }
1129
+ * ```
1130
+ */
1131
+ declare function createVerifierMiddleware(verifier: OffchainVerifier): (req: ExpressRequest, res: ExpressResponse, next: ExpressNext) => Promise<void>;
1132
+ /**
1133
+ * Options for verification endpoint.
1134
+ */
1135
+ interface VerificationEndpointOptions {
1136
+ /** Custom path for the endpoint (default: '/verify') */
1137
+ path?: string;
1138
+ /** Rate limiting (requests per minute, 0 = unlimited) */
1139
+ rateLimit?: number;
1140
+ /** Required API key header */
1141
+ apiKeyHeader?: string;
1142
+ /** Allowed circuit names (empty = all) */
1143
+ allowedCircuits?: string[];
1144
+ }
1145
+ /**
1146
+ * Creates a verification endpoint configuration.
1147
+ *
1148
+ * This is a helper for setting up verification endpoints with
1149
+ * common options like rate limiting and API key authentication.
1150
+ *
1151
+ * @example
1152
+ * ```typescript
1153
+ * const config = createVerificationEndpoint(verifier, {
1154
+ * path: '/api/v1/verify',
1155
+ * rateLimit: 100,
1156
+ * apiKeyHeader: 'X-API-Key',
1157
+ * allowedCircuits: ['balance-check', 'age-verify'],
1158
+ * });
1159
+ *
1160
+ * // Use with Express
1161
+ * app.post(config.path, config.middleware);
1162
+ * ```
1163
+ */
1164
+ declare function createVerificationEndpoint(verifier: OffchainVerifier, options?: VerificationEndpointOptions): {
1165
+ path: string;
1166
+ middleware: (req: ExpressRequest, res: ExpressResponse, next: ExpressNext) => Promise<void>;
1167
+ };
1168
+ /**
1169
+ * Verification result for batch operations.
1170
+ */
1171
+ interface BatchVerifyResult {
1172
+ /** Results for each verification */
1173
+ results: VerifyResult[];
1174
+ /** Total time for all verifications */
1175
+ totalTimeMs: number;
1176
+ /** Number of verified proofs */
1177
+ verifiedCount: number;
1178
+ /** Number of failed verifications */
1179
+ failedCount: number;
1180
+ }
1181
+ /**
1182
+ * Batch verification extension for OffchainVerifier.
1183
+ *
1184
+ * @example
1185
+ * ```typescript
1186
+ * const results = await batchVerify(verifier, [
1187
+ * { circuitName: 'age-check', proof: proof1, publicInputs: [18] },
1188
+ * { circuitName: 'balance-check', proof: proof2, publicInputs: [100] },
1189
+ * ]);
1190
+ *
1191
+ * console.log(`Verified: ${results.verifiedCount}/${results.results.length}`);
1192
+ * ```
1193
+ */
1194
+ declare function batchVerify(verifier: OffchainVerifier, requests: VerifyRequest[]): Promise<BatchVerifyResult>;
1195
+
1196
+ export { AcornParser, ArkworksWasm, ArkworksWasmConfig, type AssertStatement, type BatchVerifyResult, type BinaryExpr, type BinaryOperator, type CircuitDefinition, type CircuitExportEntry, CircuitFunction, type CircuitInputDef, CircuitMetadata, type CircuitParam, CircuitRegistry, type CircuitRegistryExport, type CloseVkAccounts, type CreateProofDependencies, CreateProofUseCase, type DeploymentResult, type DeploymentsState, type EnsureDeployedOptions, type Expr, type GetCircuitOptions, IChainFormatter, type IParser, IProvingSystem, type IdentifierExpr, type InitAndVerifyInstructions, type InitVkAccounts, InputValue, type InstructionData, type LiteralExpr, type MemberExpr, NETWORK_ENDPOINTS, type OffchainCircuitConfig, OffchainVerifier, type OffchainVerifierConfig, type ParsedCircuit, ProofData, ProofResult, type RegisteredCircuit, type SignerInfo, SolanaChainMetadata, SolanaFormatter, type SolanaNetwork, SolanaProofData, SolanaTransactionBuilder, type Statement, type TransactionBuilderConfig, type VerificationEndpointOptions, type VerifyProofAccounts, type VerifyRequest, type VerifyResult, type VkDeployment, VkDeploymentManager, type VkDeploymentManagerConfig, batchVerify, createArkworksWasmContainer, createDefaultContainer, createNodeVkDeploymentManager, createVerificationEndpoint, createVerifierMiddleware, defineCircuit, generateNoir, getGlobalRegistry };