@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.
- package/LICENSE +21 -0
- package/README.md +458 -0
- package/dist/IProvingSystem-D9TnEig0.d.ts +140 -0
- package/dist/IProvingSystem-TKNofoo8.d.cts +140 -0
- package/dist/index.cjs +2793 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1196 -0
- package/dist/index.d.ts +1196 -0
- package/dist/index.js +2730 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/arkworks.cjs +824 -0
- package/dist/providers/arkworks.cjs.map +1 -0
- package/dist/providers/arkworks.d.cts +121 -0
- package/dist/providers/arkworks.d.ts +121 -0
- package/dist/providers/arkworks.js +791 -0
- package/dist/providers/arkworks.js.map +1 -0
- package/dist/providers/barretenberg.cjs +822 -0
- package/dist/providers/barretenberg.cjs.map +1 -0
- package/dist/providers/barretenberg.d.cts +18 -0
- package/dist/providers/barretenberg.d.ts +18 -0
- package/dist/providers/barretenberg.js +790 -0
- package/dist/providers/barretenberg.js.map +1 -0
- package/dist/providers/solana.cjs +262 -0
- package/dist/providers/solana.cjs.map +1 -0
- package/dist/providers/solana.d.cts +223 -0
- package/dist/providers/solana.d.ts +223 -0
- package/dist/providers/solana.js +222 -0
- package/dist/providers/solana.js.map +1 -0
- package/dist/providers/sunspot.cjs +475 -0
- package/dist/providers/sunspot.cjs.map +1 -0
- package/dist/providers/sunspot.d.cts +210 -0
- package/dist/providers/sunspot.d.ts +210 -0
- package/dist/providers/sunspot.js +443 -0
- package/dist/providers/sunspot.js.map +1 -0
- package/dist/types-CaaigonG.d.cts +93 -0
- package/dist/types-CaaigonG.d.ts +93 -0
- package/dist/wasm/nodejs/arkworks_groth16_wasm.js +448 -0
- package/dist/wasm/nodejs/arkworks_groth16_wasm_bg.wasm +0 -0
- package/dist/wasm/web/arkworks_groth16_wasm.js +536 -0
- package/dist/wasm/web/arkworks_groth16_wasm_bg.wasm +0 -0
- package/dist/wasmInit-KV6DTj4J.d.ts +282 -0
- package/dist/wasmInit-iEYiiB8M.d.cts +282 -0
- package/package.json +87 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { C as ChainId, a as CircuitMetadata, b as ChainMetadataFor, c as Chain, I as IziNoirConfig, d as IProvingSystem } from './IProvingSystem-D9TnEig0.js';
|
|
2
|
+
import { P as ProofData, S as SolanaProofData, V as VerifyingKeyData } from './types-CaaigonG.js';
|
|
3
|
+
import { CompiledCircuit, InputMap } from '@noir-lang/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Interface for chain-specific proof formatters.
|
|
7
|
+
*
|
|
8
|
+
* Chain formatters convert generic ProofData into chain-specific formats
|
|
9
|
+
* suitable for on-chain verification on different blockchains.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* class SolanaFormatter implements IChainFormatter<'solana'> {
|
|
14
|
+
* readonly chainId = 'solana';
|
|
15
|
+
* async formatProof(proofData, circuit, metadata) {
|
|
16
|
+
* // Convert to gnark format for Solana
|
|
17
|
+
* return solanaProofData;
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
interface IChainFormatter<TChain extends ChainId = ChainId> {
|
|
23
|
+
/**
|
|
24
|
+
* Unique identifier for this chain
|
|
25
|
+
*/
|
|
26
|
+
readonly chainId: TChain;
|
|
27
|
+
/**
|
|
28
|
+
* Format a generic proof for this chain's verification system
|
|
29
|
+
*
|
|
30
|
+
* @param proofData - Generic proof data from the proving system
|
|
31
|
+
* @param circuit - The compiled circuit used for proving
|
|
32
|
+
* @param metadata - Circuit metadata (public input count, etc.)
|
|
33
|
+
* @returns Chain-specific proof data ready for on-chain verification
|
|
34
|
+
*/
|
|
35
|
+
formatProof(proofData: ProofData, circuit: CompiledCircuit, metadata: CircuitMetadata): Promise<ChainProofDataFor<TChain>>;
|
|
36
|
+
/**
|
|
37
|
+
* Get chain-specific metadata for a circuit
|
|
38
|
+
*
|
|
39
|
+
* @param publicInputCount - Number of public inputs in the circuit
|
|
40
|
+
* @returns Chain-specific metadata (account size, gas estimates, etc.)
|
|
41
|
+
*/
|
|
42
|
+
getChainMetadata(publicInputCount: number): ChainMetadataFor<TChain>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Type helper to get chain-specific proof data type
|
|
46
|
+
*/
|
|
47
|
+
type ChainProofDataFor<T extends ChainId> = T extends 'solana' ? SolanaProofData : ProofData;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Data needed to deploy a verifying key to Solana.
|
|
51
|
+
* Use with SolanaTransactionBuilder or your own transaction logic.
|
|
52
|
+
*/
|
|
53
|
+
interface SolanaDeployData {
|
|
54
|
+
/** The proof data with VK and public inputs */
|
|
55
|
+
proofData: SolanaProofData;
|
|
56
|
+
/** Program ID to use */
|
|
57
|
+
programId: string;
|
|
58
|
+
/** Compute units for the transaction */
|
|
59
|
+
computeUnits: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Main class for ZK proof generation with multiple backend providers.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* import { IziNoir, Provider, Chain } from '@izi-noir/sdk';
|
|
67
|
+
*
|
|
68
|
+
* // On-chain mode: Initialize with chain for blockchain-specific formatting
|
|
69
|
+
* const izi = await IziNoir.init({
|
|
70
|
+
* provider: Provider.Arkworks,
|
|
71
|
+
* chain: Chain.Solana
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* await izi.compile(noirCode);
|
|
75
|
+
* const proof = await izi.prove(inputs); // Returns SolanaProofData
|
|
76
|
+
* console.log(izi.vk); // Verifying key available
|
|
77
|
+
*
|
|
78
|
+
* // Offchain mode: No chain specified
|
|
79
|
+
* const iziOffchain = await IziNoir.init({ provider: Provider.Arkworks });
|
|
80
|
+
* const rawProof = await iziOffchain.prove(inputs); // Returns ProofData
|
|
81
|
+
* const verified = await iziOffchain.verify(rawProof.proof, rawProof.publicInputs);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare class IziNoir {
|
|
85
|
+
private provingSystem;
|
|
86
|
+
private compiledCircuit;
|
|
87
|
+
private chainFormatters;
|
|
88
|
+
private readonly chain?;
|
|
89
|
+
private _verifyingKey?;
|
|
90
|
+
private _lastProof?;
|
|
91
|
+
private constructor();
|
|
92
|
+
/**
|
|
93
|
+
* Get the verifying key from the last proof generation.
|
|
94
|
+
* Only available after calling prove() with a chain configured.
|
|
95
|
+
*/
|
|
96
|
+
get vk(): VerifyingKeyData | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Get the configured chain, if any.
|
|
99
|
+
*/
|
|
100
|
+
get targetChain(): Chain | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Check if operating in offchain mode (no chain configured).
|
|
103
|
+
*/
|
|
104
|
+
get isOffchain(): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Register a chain formatter for chain-specific proof formatting.
|
|
107
|
+
*
|
|
108
|
+
* @param formatter - The chain formatter to register
|
|
109
|
+
*/
|
|
110
|
+
registerChainFormatter<T extends ChainId>(formatter: IChainFormatter<T>): void;
|
|
111
|
+
/**
|
|
112
|
+
* Get a registered chain formatter.
|
|
113
|
+
*
|
|
114
|
+
* @param chainId - The chain ID to get the formatter for
|
|
115
|
+
* @returns The formatter or undefined if not registered
|
|
116
|
+
*/
|
|
117
|
+
getChainFormatter<T extends ChainId>(chainId: T): IChainFormatter<T> | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Initialize IziNoir with the specified provider and optional chain.
|
|
120
|
+
*
|
|
121
|
+
* @param config - Configuration specifying the provider, chain, and optional circuit paths
|
|
122
|
+
* @returns Initialized IziNoir instance
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* // On-chain mode (Solana)
|
|
127
|
+
* const izi = await IziNoir.init({
|
|
128
|
+
* provider: Provider.Arkworks,
|
|
129
|
+
* chain: Chain.Solana
|
|
130
|
+
* });
|
|
131
|
+
*
|
|
132
|
+
* // Offchain mode (no chain formatting)
|
|
133
|
+
* const iziOffchain = await IziNoir.init({
|
|
134
|
+
* provider: Provider.Arkworks
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* // Barretenberg (browser-compatible, ~16KB proofs, offchain only)
|
|
138
|
+
* const bb = await IziNoir.init({ provider: Provider.Barretenberg });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
static init(config: IziNoirConfig): Promise<IziNoir>;
|
|
142
|
+
/**
|
|
143
|
+
* Get the underlying proving system instance.
|
|
144
|
+
* Useful for advanced use cases.
|
|
145
|
+
*/
|
|
146
|
+
getProvingSystem(): IProvingSystem;
|
|
147
|
+
/**
|
|
148
|
+
* Get the currently compiled circuit, if any.
|
|
149
|
+
*/
|
|
150
|
+
getCompiledCircuit(): CompiledCircuit | null;
|
|
151
|
+
/**
|
|
152
|
+
* Compile Noir code into a circuit.
|
|
153
|
+
*
|
|
154
|
+
* @param noirCode - The Noir source code to compile
|
|
155
|
+
* @returns The compiled circuit
|
|
156
|
+
*/
|
|
157
|
+
compile(noirCode: string): Promise<CompiledCircuit>;
|
|
158
|
+
/**
|
|
159
|
+
* Generate a proof for the given inputs.
|
|
160
|
+
*
|
|
161
|
+
* If a chain is configured, returns chain-formatted proof data and stores
|
|
162
|
+
* the verifying key in `this.vk`. Otherwise, returns raw proof data.
|
|
163
|
+
*
|
|
164
|
+
* @param inputs - The inputs (both public and private) for the circuit
|
|
165
|
+
* @param circuit - Optional circuit to use (defaults to last compiled circuit)
|
|
166
|
+
* @returns The proof data - type depends on configured chain
|
|
167
|
+
* @throws Error if no circuit is available
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* // With chain configured - returns SolanaProofData
|
|
172
|
+
* const izi = await IziNoir.init({ provider: Provider.Arkworks, chain: Chain.Solana });
|
|
173
|
+
* await izi.compile(noirCode);
|
|
174
|
+
* const proof = await izi.prove({ expected: '100', secret: '10' });
|
|
175
|
+
* // proof is SolanaProofData, izi.vk is available
|
|
176
|
+
*
|
|
177
|
+
* // Offchain mode - returns ProofData
|
|
178
|
+
* const iziOffchain = await IziNoir.init({ provider: Provider.Arkworks });
|
|
179
|
+
* await iziOffchain.compile(noirCode);
|
|
180
|
+
* const rawProof = await iziOffchain.prove({ expected: '100', secret: '10' });
|
|
181
|
+
* // rawProof is ProofData, iziOffchain.vk is undefined
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
prove(inputs: InputMap, circuit?: CompiledCircuit): Promise<ProofData | SolanaProofData>;
|
|
185
|
+
/**
|
|
186
|
+
* Verify a proof.
|
|
187
|
+
* Available in both on-chain and offchain modes.
|
|
188
|
+
*
|
|
189
|
+
* @param proof - The proof bytes to verify
|
|
190
|
+
* @param publicInputs - The public inputs that were used
|
|
191
|
+
* @param circuit - Optional circuit to use (defaults to last compiled circuit)
|
|
192
|
+
* @returns true if the proof is valid, false otherwise
|
|
193
|
+
* @throws Error if no circuit is available
|
|
194
|
+
*/
|
|
195
|
+
verify(proof: Uint8Array, publicInputs: string[], circuit?: CompiledCircuit): Promise<boolean>;
|
|
196
|
+
/**
|
|
197
|
+
* Convenience method: compile, prove, and verify in one call.
|
|
198
|
+
*
|
|
199
|
+
* @param noirCode - The Noir source code to compile
|
|
200
|
+
* @param inputs - The inputs (both public and private) for the circuit
|
|
201
|
+
* @returns Object containing proof data and verification result
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const { proof, verified } = await izi.createProof(noirCode, {
|
|
206
|
+
* x: '100',
|
|
207
|
+
* y: '10',
|
|
208
|
+
* });
|
|
209
|
+
* console.log(`Verified: ${verified}`);
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
createProof(noirCode: string, inputs: InputMap): Promise<{
|
|
213
|
+
proof: ProofData | SolanaProofData;
|
|
214
|
+
verified: boolean;
|
|
215
|
+
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Get deployment data for the verifying key.
|
|
218
|
+
* Returns the data needed to deploy to the configured blockchain.
|
|
219
|
+
* Use with SolanaTransactionBuilder to build and send the transaction.
|
|
220
|
+
*
|
|
221
|
+
* @param options - Optional configuration
|
|
222
|
+
* @returns Deployment data that can be used with SolanaTransactionBuilder
|
|
223
|
+
* @throws Error if no chain is configured (offchain mode)
|
|
224
|
+
* @throws Error if prove() hasn't been called yet
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* const izi = await IziNoir.init({ provider: Provider.Arkworks, chain: Chain.Solana });
|
|
229
|
+
* await izi.compile(noirCode);
|
|
230
|
+
* await izi.prove(inputs);
|
|
231
|
+
*
|
|
232
|
+
* // Get deployment data
|
|
233
|
+
* const deployData = izi.getDeployData();
|
|
234
|
+
*
|
|
235
|
+
* // Use with SolanaTransactionBuilder in your frontend
|
|
236
|
+
* const builder = new SolanaTransactionBuilder({ programId: deployData.programId });
|
|
237
|
+
* const { initVk, rentLamports, accountSize } = builder.buildInitAndVerifyInstructions(
|
|
238
|
+
* deployData.proofData,
|
|
239
|
+
* vkAccountPubkey,
|
|
240
|
+
* authority,
|
|
241
|
+
* payer
|
|
242
|
+
* );
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
getDeployData(options?: {
|
|
246
|
+
programId?: string;
|
|
247
|
+
computeUnits?: number;
|
|
248
|
+
}): SolanaDeployData;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Initialize WASM modules for Noir compilation and execution.
|
|
253
|
+
* Automatically detects Node.js vs browser and uses the appropriate WASM target.
|
|
254
|
+
*
|
|
255
|
+
* Uses lazy loading with singleton pattern - safe to call multiple times.
|
|
256
|
+
* Only initializes once, subsequent calls return immediately.
|
|
257
|
+
*/
|
|
258
|
+
declare function initNoirWasm(): Promise<void>;
|
|
259
|
+
/**
|
|
260
|
+
* Check if WASM modules are already initialized
|
|
261
|
+
*/
|
|
262
|
+
declare function isWasmInitialized(): boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Mark WASM as already initialized externally.
|
|
265
|
+
* Use this when WASM has been initialized outside the SDK (e.g., with Vite URL imports).
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* // In Vite/browser environment
|
|
270
|
+
* import initNoirC from "@noir-lang/noirc_abi";
|
|
271
|
+
* import initACVM from "@noir-lang/acvm_js";
|
|
272
|
+
* import acvm from "@noir-lang/acvm_js/web/acvm_js_bg.wasm?url";
|
|
273
|
+
* import noirc from "@noir-lang/noirc_abi/web/noirc_abi_wasm_bg.wasm?url";
|
|
274
|
+
* import { markWasmInitialized } from "@izi-noir/sdk";
|
|
275
|
+
*
|
|
276
|
+
* await Promise.all([initACVM(fetch(acvm)), initNoirC(fetch(noirc))]);
|
|
277
|
+
* markWasmInitialized();
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
declare function markWasmInitialized(): void;
|
|
281
|
+
|
|
282
|
+
export { type ChainProofDataFor as C, type IChainFormatter as I, type SolanaDeployData as S, IziNoir as a, isWasmInitialized as b, initNoirWasm as i, markWasmInitialized as m };
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { C as ChainId, a as CircuitMetadata, b as ChainMetadataFor, c as Chain, I as IziNoirConfig, d as IProvingSystem } from './IProvingSystem-TKNofoo8.cjs';
|
|
2
|
+
import { P as ProofData, S as SolanaProofData, V as VerifyingKeyData } from './types-CaaigonG.cjs';
|
|
3
|
+
import { CompiledCircuit, InputMap } from '@noir-lang/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Interface for chain-specific proof formatters.
|
|
7
|
+
*
|
|
8
|
+
* Chain formatters convert generic ProofData into chain-specific formats
|
|
9
|
+
* suitable for on-chain verification on different blockchains.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* class SolanaFormatter implements IChainFormatter<'solana'> {
|
|
14
|
+
* readonly chainId = 'solana';
|
|
15
|
+
* async formatProof(proofData, circuit, metadata) {
|
|
16
|
+
* // Convert to gnark format for Solana
|
|
17
|
+
* return solanaProofData;
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
interface IChainFormatter<TChain extends ChainId = ChainId> {
|
|
23
|
+
/**
|
|
24
|
+
* Unique identifier for this chain
|
|
25
|
+
*/
|
|
26
|
+
readonly chainId: TChain;
|
|
27
|
+
/**
|
|
28
|
+
* Format a generic proof for this chain's verification system
|
|
29
|
+
*
|
|
30
|
+
* @param proofData - Generic proof data from the proving system
|
|
31
|
+
* @param circuit - The compiled circuit used for proving
|
|
32
|
+
* @param metadata - Circuit metadata (public input count, etc.)
|
|
33
|
+
* @returns Chain-specific proof data ready for on-chain verification
|
|
34
|
+
*/
|
|
35
|
+
formatProof(proofData: ProofData, circuit: CompiledCircuit, metadata: CircuitMetadata): Promise<ChainProofDataFor<TChain>>;
|
|
36
|
+
/**
|
|
37
|
+
* Get chain-specific metadata for a circuit
|
|
38
|
+
*
|
|
39
|
+
* @param publicInputCount - Number of public inputs in the circuit
|
|
40
|
+
* @returns Chain-specific metadata (account size, gas estimates, etc.)
|
|
41
|
+
*/
|
|
42
|
+
getChainMetadata(publicInputCount: number): ChainMetadataFor<TChain>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Type helper to get chain-specific proof data type
|
|
46
|
+
*/
|
|
47
|
+
type ChainProofDataFor<T extends ChainId> = T extends 'solana' ? SolanaProofData : ProofData;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Data needed to deploy a verifying key to Solana.
|
|
51
|
+
* Use with SolanaTransactionBuilder or your own transaction logic.
|
|
52
|
+
*/
|
|
53
|
+
interface SolanaDeployData {
|
|
54
|
+
/** The proof data with VK and public inputs */
|
|
55
|
+
proofData: SolanaProofData;
|
|
56
|
+
/** Program ID to use */
|
|
57
|
+
programId: string;
|
|
58
|
+
/** Compute units for the transaction */
|
|
59
|
+
computeUnits: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Main class for ZK proof generation with multiple backend providers.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* import { IziNoir, Provider, Chain } from '@izi-noir/sdk';
|
|
67
|
+
*
|
|
68
|
+
* // On-chain mode: Initialize with chain for blockchain-specific formatting
|
|
69
|
+
* const izi = await IziNoir.init({
|
|
70
|
+
* provider: Provider.Arkworks,
|
|
71
|
+
* chain: Chain.Solana
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* await izi.compile(noirCode);
|
|
75
|
+
* const proof = await izi.prove(inputs); // Returns SolanaProofData
|
|
76
|
+
* console.log(izi.vk); // Verifying key available
|
|
77
|
+
*
|
|
78
|
+
* // Offchain mode: No chain specified
|
|
79
|
+
* const iziOffchain = await IziNoir.init({ provider: Provider.Arkworks });
|
|
80
|
+
* const rawProof = await iziOffchain.prove(inputs); // Returns ProofData
|
|
81
|
+
* const verified = await iziOffchain.verify(rawProof.proof, rawProof.publicInputs);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare class IziNoir {
|
|
85
|
+
private provingSystem;
|
|
86
|
+
private compiledCircuit;
|
|
87
|
+
private chainFormatters;
|
|
88
|
+
private readonly chain?;
|
|
89
|
+
private _verifyingKey?;
|
|
90
|
+
private _lastProof?;
|
|
91
|
+
private constructor();
|
|
92
|
+
/**
|
|
93
|
+
* Get the verifying key from the last proof generation.
|
|
94
|
+
* Only available after calling prove() with a chain configured.
|
|
95
|
+
*/
|
|
96
|
+
get vk(): VerifyingKeyData | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Get the configured chain, if any.
|
|
99
|
+
*/
|
|
100
|
+
get targetChain(): Chain | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Check if operating in offchain mode (no chain configured).
|
|
103
|
+
*/
|
|
104
|
+
get isOffchain(): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Register a chain formatter for chain-specific proof formatting.
|
|
107
|
+
*
|
|
108
|
+
* @param formatter - The chain formatter to register
|
|
109
|
+
*/
|
|
110
|
+
registerChainFormatter<T extends ChainId>(formatter: IChainFormatter<T>): void;
|
|
111
|
+
/**
|
|
112
|
+
* Get a registered chain formatter.
|
|
113
|
+
*
|
|
114
|
+
* @param chainId - The chain ID to get the formatter for
|
|
115
|
+
* @returns The formatter or undefined if not registered
|
|
116
|
+
*/
|
|
117
|
+
getChainFormatter<T extends ChainId>(chainId: T): IChainFormatter<T> | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Initialize IziNoir with the specified provider and optional chain.
|
|
120
|
+
*
|
|
121
|
+
* @param config - Configuration specifying the provider, chain, and optional circuit paths
|
|
122
|
+
* @returns Initialized IziNoir instance
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* // On-chain mode (Solana)
|
|
127
|
+
* const izi = await IziNoir.init({
|
|
128
|
+
* provider: Provider.Arkworks,
|
|
129
|
+
* chain: Chain.Solana
|
|
130
|
+
* });
|
|
131
|
+
*
|
|
132
|
+
* // Offchain mode (no chain formatting)
|
|
133
|
+
* const iziOffchain = await IziNoir.init({
|
|
134
|
+
* provider: Provider.Arkworks
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* // Barretenberg (browser-compatible, ~16KB proofs, offchain only)
|
|
138
|
+
* const bb = await IziNoir.init({ provider: Provider.Barretenberg });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
static init(config: IziNoirConfig): Promise<IziNoir>;
|
|
142
|
+
/**
|
|
143
|
+
* Get the underlying proving system instance.
|
|
144
|
+
* Useful for advanced use cases.
|
|
145
|
+
*/
|
|
146
|
+
getProvingSystem(): IProvingSystem;
|
|
147
|
+
/**
|
|
148
|
+
* Get the currently compiled circuit, if any.
|
|
149
|
+
*/
|
|
150
|
+
getCompiledCircuit(): CompiledCircuit | null;
|
|
151
|
+
/**
|
|
152
|
+
* Compile Noir code into a circuit.
|
|
153
|
+
*
|
|
154
|
+
* @param noirCode - The Noir source code to compile
|
|
155
|
+
* @returns The compiled circuit
|
|
156
|
+
*/
|
|
157
|
+
compile(noirCode: string): Promise<CompiledCircuit>;
|
|
158
|
+
/**
|
|
159
|
+
* Generate a proof for the given inputs.
|
|
160
|
+
*
|
|
161
|
+
* If a chain is configured, returns chain-formatted proof data and stores
|
|
162
|
+
* the verifying key in `this.vk`. Otherwise, returns raw proof data.
|
|
163
|
+
*
|
|
164
|
+
* @param inputs - The inputs (both public and private) for the circuit
|
|
165
|
+
* @param circuit - Optional circuit to use (defaults to last compiled circuit)
|
|
166
|
+
* @returns The proof data - type depends on configured chain
|
|
167
|
+
* @throws Error if no circuit is available
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* // With chain configured - returns SolanaProofData
|
|
172
|
+
* const izi = await IziNoir.init({ provider: Provider.Arkworks, chain: Chain.Solana });
|
|
173
|
+
* await izi.compile(noirCode);
|
|
174
|
+
* const proof = await izi.prove({ expected: '100', secret: '10' });
|
|
175
|
+
* // proof is SolanaProofData, izi.vk is available
|
|
176
|
+
*
|
|
177
|
+
* // Offchain mode - returns ProofData
|
|
178
|
+
* const iziOffchain = await IziNoir.init({ provider: Provider.Arkworks });
|
|
179
|
+
* await iziOffchain.compile(noirCode);
|
|
180
|
+
* const rawProof = await iziOffchain.prove({ expected: '100', secret: '10' });
|
|
181
|
+
* // rawProof is ProofData, iziOffchain.vk is undefined
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
prove(inputs: InputMap, circuit?: CompiledCircuit): Promise<ProofData | SolanaProofData>;
|
|
185
|
+
/**
|
|
186
|
+
* Verify a proof.
|
|
187
|
+
* Available in both on-chain and offchain modes.
|
|
188
|
+
*
|
|
189
|
+
* @param proof - The proof bytes to verify
|
|
190
|
+
* @param publicInputs - The public inputs that were used
|
|
191
|
+
* @param circuit - Optional circuit to use (defaults to last compiled circuit)
|
|
192
|
+
* @returns true if the proof is valid, false otherwise
|
|
193
|
+
* @throws Error if no circuit is available
|
|
194
|
+
*/
|
|
195
|
+
verify(proof: Uint8Array, publicInputs: string[], circuit?: CompiledCircuit): Promise<boolean>;
|
|
196
|
+
/**
|
|
197
|
+
* Convenience method: compile, prove, and verify in one call.
|
|
198
|
+
*
|
|
199
|
+
* @param noirCode - The Noir source code to compile
|
|
200
|
+
* @param inputs - The inputs (both public and private) for the circuit
|
|
201
|
+
* @returns Object containing proof data and verification result
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const { proof, verified } = await izi.createProof(noirCode, {
|
|
206
|
+
* x: '100',
|
|
207
|
+
* y: '10',
|
|
208
|
+
* });
|
|
209
|
+
* console.log(`Verified: ${verified}`);
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
createProof(noirCode: string, inputs: InputMap): Promise<{
|
|
213
|
+
proof: ProofData | SolanaProofData;
|
|
214
|
+
verified: boolean;
|
|
215
|
+
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Get deployment data for the verifying key.
|
|
218
|
+
* Returns the data needed to deploy to the configured blockchain.
|
|
219
|
+
* Use with SolanaTransactionBuilder to build and send the transaction.
|
|
220
|
+
*
|
|
221
|
+
* @param options - Optional configuration
|
|
222
|
+
* @returns Deployment data that can be used with SolanaTransactionBuilder
|
|
223
|
+
* @throws Error if no chain is configured (offchain mode)
|
|
224
|
+
* @throws Error if prove() hasn't been called yet
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* const izi = await IziNoir.init({ provider: Provider.Arkworks, chain: Chain.Solana });
|
|
229
|
+
* await izi.compile(noirCode);
|
|
230
|
+
* await izi.prove(inputs);
|
|
231
|
+
*
|
|
232
|
+
* // Get deployment data
|
|
233
|
+
* const deployData = izi.getDeployData();
|
|
234
|
+
*
|
|
235
|
+
* // Use with SolanaTransactionBuilder in your frontend
|
|
236
|
+
* const builder = new SolanaTransactionBuilder({ programId: deployData.programId });
|
|
237
|
+
* const { initVk, rentLamports, accountSize } = builder.buildInitAndVerifyInstructions(
|
|
238
|
+
* deployData.proofData,
|
|
239
|
+
* vkAccountPubkey,
|
|
240
|
+
* authority,
|
|
241
|
+
* payer
|
|
242
|
+
* );
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
getDeployData(options?: {
|
|
246
|
+
programId?: string;
|
|
247
|
+
computeUnits?: number;
|
|
248
|
+
}): SolanaDeployData;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Initialize WASM modules for Noir compilation and execution.
|
|
253
|
+
* Automatically detects Node.js vs browser and uses the appropriate WASM target.
|
|
254
|
+
*
|
|
255
|
+
* Uses lazy loading with singleton pattern - safe to call multiple times.
|
|
256
|
+
* Only initializes once, subsequent calls return immediately.
|
|
257
|
+
*/
|
|
258
|
+
declare function initNoirWasm(): Promise<void>;
|
|
259
|
+
/**
|
|
260
|
+
* Check if WASM modules are already initialized
|
|
261
|
+
*/
|
|
262
|
+
declare function isWasmInitialized(): boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Mark WASM as already initialized externally.
|
|
265
|
+
* Use this when WASM has been initialized outside the SDK (e.g., with Vite URL imports).
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* // In Vite/browser environment
|
|
270
|
+
* import initNoirC from "@noir-lang/noirc_abi";
|
|
271
|
+
* import initACVM from "@noir-lang/acvm_js";
|
|
272
|
+
* import acvm from "@noir-lang/acvm_js/web/acvm_js_bg.wasm?url";
|
|
273
|
+
* import noirc from "@noir-lang/noirc_abi/web/noirc_abi_wasm_bg.wasm?url";
|
|
274
|
+
* import { markWasmInitialized } from "@izi-noir/sdk";
|
|
275
|
+
*
|
|
276
|
+
* await Promise.all([initACVM(fetch(acvm)), initNoirC(fetch(noirc))]);
|
|
277
|
+
* markWasmInitialized();
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
declare function markWasmInitialized(): void;
|
|
281
|
+
|
|
282
|
+
export { type ChainProofDataFor as C, type IChainFormatter as I, type SolanaDeployData as S, IziNoir as a, isWasmInitialized as b, initNoirWasm as i, markWasmInitialized as m };
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@izi-noir/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Write ZK circuits in JavaScript/TypeScript, generate Noir code and proofs automatically",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./barretenberg": {
|
|
16
|
+
"types": "./dist/providers/barretenberg.d.ts",
|
|
17
|
+
"import": "./dist/providers/barretenberg.js"
|
|
18
|
+
},
|
|
19
|
+
"./arkworks": {
|
|
20
|
+
"types": "./dist/providers/arkworks.d.ts",
|
|
21
|
+
"import": "./dist/providers/arkworks.js"
|
|
22
|
+
},
|
|
23
|
+
"./sunspot": {
|
|
24
|
+
"types": "./dist/providers/sunspot.d.ts",
|
|
25
|
+
"import": "./dist/providers/sunspot.js"
|
|
26
|
+
},
|
|
27
|
+
"./solana": {
|
|
28
|
+
"types": "./dist/providers/solana.d.ts",
|
|
29
|
+
"import": "./dist/providers/solana.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsup",
|
|
35
|
+
"dev": "tsup --watch",
|
|
36
|
+
"test": "tsx test/example.ts",
|
|
37
|
+
"test:vitest": "vitest run",
|
|
38
|
+
"lint": "eslint src/",
|
|
39
|
+
"lint:fix": "eslint src/ --fix",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"clean": "rimraf dist",
|
|
42
|
+
"copy:wasm": "mkdir -p src/wasm/nodejs src/wasm/web && cp ../arkworks-groth16-wasm/pkg-nodejs/*.js ../arkworks-groth16-wasm/pkg-nodejs/*.d.ts ../arkworks-groth16-wasm/pkg-nodejs/*.wasm src/wasm/nodejs/ && cp ../arkworks-groth16-wasm/pkg/*.js ../arkworks-groth16-wasm/pkg/*.d.ts ../arkworks-groth16-wasm/pkg/*.wasm src/wasm/web/",
|
|
43
|
+
"prebuild": "npm run copy:wasm",
|
|
44
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@aztec/bb.js": "3.0.0-devnet.20251212",
|
|
48
|
+
"@noir-lang/noir_js": "1.0.0-beta.13-1d260df.nightly",
|
|
49
|
+
"@noir-lang/noir_wasm": "1.0.0-beta.13-1d260df.nightly",
|
|
50
|
+
"@noir-lang/types": "1.0.0-beta.13-1d260df.nightly",
|
|
51
|
+
"acorn": "^8.14.0",
|
|
52
|
+
"acorn-walk": "^8.3.4"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@izi-noir/eslint-config": "*",
|
|
56
|
+
"@izi-noir/tsconfig": "*",
|
|
57
|
+
"@types/node": "^22.0.0",
|
|
58
|
+
"rimraf": "^5.0.0",
|
|
59
|
+
"tsup": "^8.0.0",
|
|
60
|
+
"tsx": "^4.0.0",
|
|
61
|
+
"typescript": "^5.4.0",
|
|
62
|
+
"vitest": "^1.6.0"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@aztec/bb.js": ">=3.0.0-devnet.0"
|
|
66
|
+
},
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public"
|
|
69
|
+
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=22.12.0"
|
|
72
|
+
},
|
|
73
|
+
"keywords": [
|
|
74
|
+
"noir",
|
|
75
|
+
"zero-knowledge",
|
|
76
|
+
"zk",
|
|
77
|
+
"zkp",
|
|
78
|
+
"proof",
|
|
79
|
+
"circuit",
|
|
80
|
+
"transpiler",
|
|
81
|
+
"barretenberg",
|
|
82
|
+
"aztec",
|
|
83
|
+
"solana"
|
|
84
|
+
],
|
|
85
|
+
"author": "Franco Perez",
|
|
86
|
+
"license": "MIT"
|
|
87
|
+
}
|