@noir-lang/acvm_js 0.42.0 → 0.43.0-053d5e8.nightly

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,89 +1,85 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  /**
4
- * Verifies a ECDSA signature over the secp256r1 curve.
5
- * @param {Uint8Array} hashed_msg
6
- * @param {Uint8Array} public_key_x_bytes
7
- * @param {Uint8Array} public_key_y_bytes
8
- * @param {Uint8Array} signature
9
- * @returns {boolean}
10
- */
11
- export function ecdsa_secp256r1_verify(hashed_msg: Uint8Array, public_key_x_bytes: Uint8Array, public_key_y_bytes: Uint8Array, signature: Uint8Array): boolean;
12
- /**
13
- * Verifies a ECDSA signature over the secp256k1 curve.
14
- * @param {Uint8Array} hashed_msg
15
- * @param {Uint8Array} public_key_x_bytes
16
- * @param {Uint8Array} public_key_y_bytes
17
- * @param {Uint8Array} signature
18
- * @returns {boolean}
4
+ * Compresses a `WitnessMap` into the binary format outputted by Nargo.
5
+ *
6
+ * @param {WitnessMap} witness_map - A witness map.
7
+ * @returns {Uint8Array} A compressed witness map
19
8
  */
20
- export function ecdsa_secp256k1_verify(hashed_msg: Uint8Array, public_key_x_bytes: Uint8Array, public_key_y_bytes: Uint8Array, signature: Uint8Array): boolean;
9
+ export function compressWitness(witness_map: WitnessMap): Uint8Array;
21
10
  /**
22
- * Calculates the Keccak256 hash of the input bytes
23
- * @param {Uint8Array} inputs
24
- * @returns {Uint8Array}
11
+ * Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`.
12
+ * This should be used to only fetch the witness map for the main function.
13
+ *
14
+ * @param {Uint8Array} compressed_witness - A compressed witness.
15
+ * @returns {WitnessMap} The decompressed witness map.
25
16
  */
26
- export function keccak256(inputs: Uint8Array): Uint8Array;
17
+ export function decompressWitness(compressed_witness: Uint8Array): WitnessMap;
27
18
  /**
28
- * Calculates the Blake2s256 hash of the input bytes
29
- * @param {Uint8Array} inputs
30
- * @returns {Uint8Array}
19
+ * Compresses a `WitnessStack` into the binary format outputted by Nargo.
20
+ *
21
+ * @param {WitnessStack} witness_stack - A witness stack.
22
+ * @returns {Uint8Array} A compressed witness stack
31
23
  */
32
- export function blake2s256(inputs: Uint8Array): Uint8Array;
24
+ export function compressWitnessStack(witness_stack: WitnessStack): Uint8Array;
33
25
  /**
34
- * Calculates the SHA256 hash of the input bytes
35
- * @param {Uint8Array} inputs
36
- * @returns {Uint8Array}
26
+ * Decompresses a compressed witness stack as outputted by Nargo into a `WitnessStack`.
27
+ *
28
+ * @param {Uint8Array} compressed_witness - A compressed witness.
29
+ * @returns {WitnessStack} The decompressed witness stack.
37
30
  */
38
- export function sha256(inputs: Uint8Array): Uint8Array;
31
+ export function decompressWitnessStack(compressed_witness: Uint8Array): WitnessStack;
39
32
  /**
40
- * Performs a bitwise XOR operation between `lhs` and `rhs`
41
- * @param {string} lhs
42
- * @param {string} rhs
43
- * @returns {string}
33
+ * @returns {Promise<WasmBlackBoxFunctionSolver>}
44
34
  */
45
- export function xor(lhs: string, rhs: string): string;
35
+ export function createBlackBoxSolver(): Promise<WasmBlackBoxFunctionSolver>;
46
36
  /**
47
- * Performs a bitwise AND operation between `lhs` and `rhs`
48
- * @param {string} lhs
49
- * @param {string} rhs
50
- * @returns {string}
37
+ * Executes an ACIR circuit to generate the solved witness from the initial witness.
38
+ *
39
+ * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
40
+ * @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`..
41
+ * @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit.
42
+ * @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs.
51
43
  */
52
- export function and(lhs: string, rhs: string): string;
44
+ export function executeCircuit(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessMap>;
53
45
  /**
54
46
  * Executes an ACIR circuit to generate the solved witness from the initial witness.
47
+ * This method also extracts the public return values from the solved witness into its own return witness.
55
48
  *
56
49
  * @param {&WasmBlackBoxFunctionSolver} solver - A black box solver.
57
50
  * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
58
51
  * @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`..
59
52
  * @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit.
60
- * @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs.
53
+ * @returns {SolvedAndReturnWitness} The solved witness calculated by executing the circuit on the provided inputs, as well as the return witness indices as specified by the circuit.
61
54
  */
62
- export function executeCircuitWithBlackBoxSolver(solver: WasmBlackBoxFunctionSolver, program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessMap>;
55
+ export function executeCircuitWithReturnWitness(solver: WasmBlackBoxFunctionSolver, program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<SolvedAndReturnWitness>;
63
56
  /**
64
57
  * Executes an ACIR circuit to generate the solved witness from the initial witness.
65
58
  *
59
+ * @param {&WasmBlackBoxFunctionSolver} solver - A black box solver.
66
60
  * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
67
61
  * @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`..
68
62
  * @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit.
69
63
  * @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs.
70
64
  */
71
- export function executeCircuit(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessMap>;
65
+ export function executeCircuitWithBlackBoxSolver(solver: WasmBlackBoxFunctionSolver, program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessMap>;
72
66
  /**
73
- * @returns {Promise<WasmBlackBoxFunctionSolver>}
74
67
  */
75
- export function createBlackBoxSolver(): Promise<WasmBlackBoxFunctionSolver>;
68
+ export function executeProgram(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessStack>;
76
69
  /**
77
- * Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's public inputs.
70
+ */
71
+ export function executeProgramWithBlackBoxSolver(solver: WasmBlackBoxFunctionSolver, program: Uint8Array, initial_witness: WitnessMap, foreign_call_executor: ForeignCallHandler): Promise<WitnessStack>;
72
+ /**
73
+ * Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's return values.
78
74
  *
79
75
  * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
80
76
  * @param {WitnessMap} witness_map - The completed witness map after executing the circuit.
81
- * @returns {WitnessMap} A witness map containing the circuit's public inputs.
77
+ * @returns {WitnessMap} A witness map containing the circuit's return values.
82
78
  * @param {Uint8Array} program
83
- * @param {WitnessMap} solved_witness
79
+ * @param {WitnessMap} witness_map
84
80
  * @returns {WitnessMap}
85
81
  */
86
- export function getPublicWitness(program: Uint8Array, solved_witness: WitnessMap): WitnessMap;
82
+ export function getReturnWitness(program: Uint8Array, witness_map: WitnessMap): WitnessMap;
87
83
  /**
88
84
  * Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's public parameters.
89
85
  *
@@ -96,50 +92,99 @@ export function getPublicWitness(program: Uint8Array, solved_witness: WitnessMap
96
92
  */
97
93
  export function getPublicParametersWitness(program: Uint8Array, solved_witness: WitnessMap): WitnessMap;
98
94
  /**
99
- * Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's return values.
95
+ * Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's public inputs.
100
96
  *
101
97
  * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
102
98
  * @param {WitnessMap} witness_map - The completed witness map after executing the circuit.
103
- * @returns {WitnessMap} A witness map containing the circuit's return values.
99
+ * @returns {WitnessMap} A witness map containing the circuit's public inputs.
104
100
  * @param {Uint8Array} program
105
- * @param {WitnessMap} witness_map
101
+ * @param {WitnessMap} solved_witness
106
102
  * @returns {WitnessMap}
107
103
  */
108
- export function getReturnWitness(program: Uint8Array, witness_map: WitnessMap): WitnessMap;
104
+ export function getPublicWitness(program: Uint8Array, solved_witness: WitnessMap): WitnessMap;
109
105
  /**
110
- * Sets the package's logging level.
111
- *
112
- * @param {LogLevel} level - The maximum level of logging to be emitted.
106
+ * Performs a bitwise AND operation between `lhs` and `rhs`
107
+ * @param {string} lhs
108
+ * @param {string} rhs
109
+ * @returns {string}
113
110
  */
114
- export function initLogLevel(filter: string): void;
111
+ export function and(lhs: string, rhs: string): string;
115
112
  /**
116
- * Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`.
117
- *
118
- * @param {Uint8Array} compressed_witness - A compressed witness.
119
- * @returns {WitnessMap} The decompressed witness map.
113
+ * Performs a bitwise XOR operation between `lhs` and `rhs`
114
+ * @param {string} lhs
115
+ * @param {string} rhs
116
+ * @returns {string}
120
117
  */
121
- export function decompressWitness(compressed_witness: Uint8Array): WitnessMap;
118
+ export function xor(lhs: string, rhs: string): string;
122
119
  /**
123
- * Compresses a `WitnessMap` into the binary format outputted by Nargo.
124
- *
125
- * @param {Uint8Array} compressed_witness - A witness map.
126
- * @returns {WitnessMap} A compressed witness map
120
+ * Calculates the SHA256 hash of the input bytes
121
+ * @param {Uint8Array} inputs
122
+ * @returns {Uint8Array}
127
123
  */
128
- export function compressWitness(witness_map: WitnessMap): Uint8Array;
124
+ export function sha256(inputs: Uint8Array): Uint8Array;
125
+ /**
126
+ * Calculates the Blake2s256 hash of the input bytes
127
+ * @param {Uint8Array} inputs
128
+ * @returns {Uint8Array}
129
+ */
130
+ export function blake2s256(inputs: Uint8Array): Uint8Array;
131
+ /**
132
+ * Calculates the Keccak256 hash of the input bytes
133
+ * @param {Uint8Array} inputs
134
+ * @returns {Uint8Array}
135
+ */
136
+ export function keccak256(inputs: Uint8Array): Uint8Array;
137
+ /**
138
+ * Verifies a ECDSA signature over the secp256k1 curve.
139
+ * @param {Uint8Array} hashed_msg
140
+ * @param {Uint8Array} public_key_x_bytes
141
+ * @param {Uint8Array} public_key_y_bytes
142
+ * @param {Uint8Array} signature
143
+ * @returns {boolean}
144
+ */
145
+ export function ecdsa_secp256k1_verify(hashed_msg: Uint8Array, public_key_x_bytes: Uint8Array, public_key_y_bytes: Uint8Array, signature: Uint8Array): boolean;
146
+ /**
147
+ * Verifies a ECDSA signature over the secp256r1 curve.
148
+ * @param {Uint8Array} hashed_msg
149
+ * @param {Uint8Array} public_key_x_bytes
150
+ * @param {Uint8Array} public_key_y_bytes
151
+ * @param {Uint8Array} signature
152
+ * @returns {boolean}
153
+ */
154
+ export function ecdsa_secp256r1_verify(hashed_msg: Uint8Array, public_key_x_bytes: Uint8Array, public_key_y_bytes: Uint8Array, signature: Uint8Array): boolean;
129
155
  /**
130
156
  * Returns the `BuildInfo` object containing information about how the installed package was built.
131
157
  * @returns {BuildInfo} - Information on how the installed package was built.
132
158
  */
133
159
  export function buildInfo(): BuildInfo;
160
+ /**
161
+ * Sets the package's logging level.
162
+ *
163
+ * @param {LogLevel} level - The maximum level of logging to be emitted.
164
+ */
165
+ export function initLogLevel(filter: string): void;
134
166
 
135
- export type ExecutionError = Error & {
136
- callStack?: string[];
137
- };
167
+ // Map from witness index to hex string value of witness.
168
+ export type WitnessMap = Map<number, string>;
138
169
 
170
+ /**
171
+ * An execution result containing two witnesses.
172
+ * 1. The full solved witness of the execution.
173
+ * 2. The return witness which contains the given public return values within the full witness.
174
+ */
175
+ export type SolvedAndReturnWitness = {
176
+ solvedWitness: WitnessMap;
177
+ returnWitness: WitnessMap;
178
+ }
139
179
 
140
180
 
141
- // Map from witness index to hex string value of witness.
142
- export type WitnessMap = Map<number, string>;
181
+
182
+ export type StackItem = {
183
+ index: number;
184
+ witness: WitnessMap;
185
+ }
186
+
187
+ export type WitnessStack = Array<StackItem>;
143
188
 
144
189
 
145
190
 
@@ -170,6 +215,12 @@ export type BuildInfo = {
170
215
  }
171
216
 
172
217
 
218
+
219
+ export type ExecutionError = Error & {
220
+ callStack?: string[];
221
+ };
222
+
223
+
173
224
  /**
174
225
  */
175
226
  export class WasmBlackBoxFunctionSolver {