@aztec/noir-acvm_js 0.0.0-test.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/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # acvm_js
2
+
3
+ The `acvm_js` package enables users to execute an ACIR program, i.e. generating an initial witness from a set of inputs and calculating a partial witness. This partial witness can then be used to create a proof of execution using an ACVM backend.
4
+
5
+ ## Dependencies
6
+
7
+ In order to build the wasm package, the following must be installed:
8
+
9
+ - [jq](https://github.com/stedolan/jq)
10
+
11
+ ## Build
12
+
13
+ The wasm package can be built using the command below:
14
+
15
+ ```bash
16
+ ./build.sh
17
+ ```
@@ -0,0 +1,183 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Executes an ACIR circuit to generate the solved witness from the initial witness.
5
+ *
6
+ * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
7
+ * @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`..
8
+ * @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit.
9
+ * @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs.
10
+ */
11
+ export function executeCircuit(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessMap>;
12
+ /**
13
+ * Executes an ACIR circuit to generate the solved witness from the initial witness.
14
+ * This method also extracts the public return values from the solved witness into its own return witness.
15
+ *
16
+ * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
17
+ * @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`..
18
+ * @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit.
19
+ * @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.
20
+ */
21
+ export function executeCircuitWithReturnWitness(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<SolvedAndReturnWitness>;
22
+ /**
23
+ * Executes an ACIR circuit to generate the solved witness from the initial witness.
24
+ *
25
+ * @param {Uint8Array} program - A serialized representation of an ACIR program
26
+ * @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `program`.
27
+ * @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the program.
28
+ * @returns {WitnessStack} The solved witness calculated by executing the program on the provided inputs.
29
+ */
30
+ export function executeProgram(program: Uint8Array, initial_witness: WitnessMap, foreign_call_handler: ForeignCallHandler): Promise<WitnessStack>;
31
+ /**
32
+ * Compresses a `WitnessMap` into the binary format outputted by Nargo.
33
+ *
34
+ * @param {WitnessMap} witness_map - A witness map.
35
+ * @returns {Uint8Array} A compressed witness map
36
+ */
37
+ export function compressWitness(witness_map: WitnessMap): Uint8Array;
38
+ /**
39
+ * Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`.
40
+ * This should be used to only fetch the witness map for the main function.
41
+ *
42
+ * @param {Uint8Array} compressed_witness - A compressed witness.
43
+ * @returns {WitnessMap} The decompressed witness map.
44
+ */
45
+ export function decompressWitness(compressed_witness: Uint8Array): WitnessMap;
46
+ /**
47
+ * Compresses a `WitnessStack` into the binary format outputted by Nargo.
48
+ *
49
+ * @param {WitnessStack} witness_stack - A witness stack.
50
+ * @returns {Uint8Array} A compressed witness stack
51
+ */
52
+ export function compressWitnessStack(witness_stack: WitnessStack): Uint8Array;
53
+ /**
54
+ * Decompresses a compressed witness stack as outputted by Nargo into a `WitnessStack`.
55
+ *
56
+ * @param {Uint8Array} compressed_witness - A compressed witness.
57
+ * @returns {WitnessStack} The decompressed witness stack.
58
+ */
59
+ export function decompressWitnessStack(compressed_witness: Uint8Array): WitnessStack;
60
+ /**
61
+ * Sets the package's logging level.
62
+ *
63
+ * @param {LogLevel} level - The maximum level of logging to be emitted.
64
+ */
65
+ export function initLogLevel(filter: string): void;
66
+ /**
67
+ * Performs a bitwise AND operation between `lhs` and `rhs`
68
+ */
69
+ export function and(lhs: string, rhs: string): string;
70
+ /**
71
+ * Performs a bitwise XOR operation between `lhs` and `rhs`
72
+ */
73
+ export function xor(lhs: string, rhs: string): string;
74
+ /**
75
+ * Sha256 compression function
76
+ */
77
+ export function sha256_compression(inputs: Uint32Array, state: Uint32Array): Uint32Array;
78
+ /**
79
+ * Calculates the Blake2s256 hash of the input bytes
80
+ */
81
+ export function blake2s256(inputs: Uint8Array): Uint8Array;
82
+ /**
83
+ * Verifies a ECDSA signature over the secp256k1 curve.
84
+ */
85
+ export function ecdsa_secp256k1_verify(hashed_msg: Uint8Array, public_key_x_bytes: Uint8Array, public_key_y_bytes: Uint8Array, signature: Uint8Array): boolean;
86
+ /**
87
+ * Verifies a ECDSA signature over the secp256r1 curve.
88
+ */
89
+ export function ecdsa_secp256r1_verify(hashed_msg: Uint8Array, public_key_x_bytes: Uint8Array, public_key_y_bytes: Uint8Array, signature: Uint8Array): boolean;
90
+ /**
91
+ * Returns the `BuildInfo` object containing information about how the installed package was built.
92
+ * @returns {BuildInfo} - Information on how the installed package was built.
93
+ */
94
+ export function buildInfo(): BuildInfo;
95
+ /**
96
+ * Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's return values.
97
+ *
98
+ * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
99
+ * @param {WitnessMap} witness_map - The completed witness map after executing the circuit.
100
+ * @returns {WitnessMap} A witness map containing the circuit's return values.
101
+ */
102
+ export function getReturnWitness(program: Uint8Array, witness_map: WitnessMap): WitnessMap;
103
+ /**
104
+ * Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's public parameters.
105
+ *
106
+ * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
107
+ * @param {WitnessMap} witness_map - The completed witness map after executing the circuit.
108
+ * @returns {WitnessMap} A witness map containing the circuit's public parameters.
109
+ */
110
+ export function getPublicParametersWitness(program: Uint8Array, solved_witness: WitnessMap): WitnessMap;
111
+ /**
112
+ * Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's public inputs.
113
+ *
114
+ * @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
115
+ * @param {WitnessMap} witness_map - The completed witness map after executing the circuit.
116
+ * @returns {WitnessMap} A witness map containing the circuit's public inputs.
117
+ */
118
+ export function getPublicWitness(program: Uint8Array, solved_witness: WitnessMap): WitnessMap;
119
+
120
+ export type RawAssertionPayload = {
121
+ selector: string;
122
+ data: string[];
123
+ };
124
+
125
+ export type ExecutionError = Error & {
126
+ callStack?: string[];
127
+ rawAssertionPayload?: RawAssertionPayload;
128
+ brilligFunctionId?: number;
129
+ };
130
+
131
+
132
+
133
+ export type StackItem = {
134
+ index: number;
135
+ witness: WitnessMap;
136
+ }
137
+
138
+ export type WitnessStack = Array<StackItem>;
139
+
140
+
141
+
142
+ /**
143
+ * @typedef {Object} BuildInfo - Information about how the installed package was built
144
+ * @property {string} gitHash - The hash of the git commit from which the package was built.
145
+ * @property {string} version - The version of the package at the built git commit.
146
+ * @property {boolean} dirty - Whether the package contained uncommitted changes when built.
147
+ */
148
+ export type BuildInfo = {
149
+ gitHash: string;
150
+ version: string;
151
+ dirty: string;
152
+ }
153
+
154
+
155
+
156
+ export type ForeignCallInput = string[]
157
+ export type ForeignCallOutput = string | string[]
158
+
159
+ /**
160
+ * A callback which performs an foreign call and returns the response.
161
+ * @callback ForeignCallHandler
162
+ * @param {string} name - The identifier for the type of foreign call being performed.
163
+ * @param {string[][]} inputs - An array of hex encoded inputs to the foreign call.
164
+ * @returns {Promise<string[]>} outputs - An array of hex encoded outputs containing the results of the foreign call.
165
+ */
166
+ export type ForeignCallHandler = (name: string, inputs: ForeignCallInput[]) => Promise<ForeignCallOutput[]>;
167
+
168
+
169
+
170
+ // Map from witness index to hex string value of witness.
171
+ export type WitnessMap = Map<number, string>;
172
+
173
+ /**
174
+ * An execution result containing two witnesses.
175
+ * 1. The full solved witness of the execution.
176
+ * 2. The return witness which contains the given public return values within the full witness.
177
+ */
178
+ export type SolvedAndReturnWitness = {
179
+ solvedWitness: WitnessMap;
180
+ returnWitness: WitnessMap;
181
+ }
182
+
183
+