@matterlabs/ethproofs-airbender-verifier 0.1.0 → 0.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matterlabs/ethproofs-airbender-verifier",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Airbender ZK Proof Verifier for EthProofs",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "repository": {
@@ -25,7 +25,7 @@
25
25
  }
26
26
  },
27
27
  "scripts": {
28
- "build:wasm": "cd ../wasm && RUST_MIN_STACK=267108864 wasm-pack build --target web --out-dir ../ts/wasm/pkg",
28
+ "build:wasm": "cd ../wasm && ./build_for_ts.sh",
29
29
  "build:ts": "tsup",
30
30
  "build": "yarn build:wasm && yarn build:ts",
31
31
  "prepack": "yarn build"
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "proof_verifier_wasm",
3
+ "type": "module",
4
+ "version": "0.1.2",
5
+ "license": "MIT OR Apache-2.0",
6
+ "files": [
7
+ "proof_verifier_wasm_bg.wasm",
8
+ "proof_verifier_wasm.js",
9
+ "proof_verifier_wasm.d.ts"
10
+ ],
11
+ "main": "proof_verifier_wasm.js",
12
+ "types": "proof_verifier_wasm.d.ts",
13
+ "sideEffects": [
14
+ "./snippets/*"
15
+ ]
16
+ }
@@ -0,0 +1,66 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class ProofHandle {
5
+ private constructor();
6
+ free(): void;
7
+ [Symbol.dispose](): void;
8
+ }
9
+
10
+ export class VerifyResult {
11
+ private constructor();
12
+ free(): void;
13
+ [Symbol.dispose](): void;
14
+ error(): any | undefined;
15
+ readonly success: boolean;
16
+ }
17
+
18
+ export function deserialize_proof_bytes(proof_bytes: Uint8Array): ProofHandle;
19
+
20
+ export function init_defaults(): void;
21
+
22
+ export function init_with(setup_bin: Uint8Array, layout_bin: Uint8Array): void;
23
+
24
+ export function verify_proof(handle: ProofHandle): VerifyResult;
25
+
26
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
27
+
28
+ export interface InitOutput {
29
+ readonly memory: WebAssembly.Memory;
30
+ readonly __wbg_proofhandle_free: (a: number, b: number) => void;
31
+ readonly __wbg_verifyresult_free: (a: number, b: number) => void;
32
+ readonly deserialize_proof_bytes: (a: number, b: number) => [number, number, number];
33
+ readonly init_defaults: () => [number, number];
34
+ readonly init_with: (a: number, b: number, c: number, d: number) => [number, number];
35
+ readonly verify_proof: (a: number) => number;
36
+ readonly verifyresult_error: (a: number) => any;
37
+ readonly verifyresult_success: (a: number) => number;
38
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
39
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
40
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
41
+ readonly __wbindgen_externrefs: WebAssembly.Table;
42
+ readonly __externref_table_dealloc: (a: number) => void;
43
+ readonly __wbindgen_start: () => void;
44
+ }
45
+
46
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
47
+
48
+ /**
49
+ * Instantiates the given `module`, which can either be bytes or
50
+ * a precompiled `WebAssembly.Module`.
51
+ *
52
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
53
+ *
54
+ * @returns {InitOutput}
55
+ */
56
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
57
+
58
+ /**
59
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
60
+ * for everything else, calls `WebAssembly.instantiate` directly.
61
+ *
62
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
63
+ *
64
+ * @returns {Promise<InitOutput>}
65
+ */
66
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,358 @@
1
+ /* @ts-self-types="./proof_verifier_wasm.d.ts" */
2
+
3
+ export class ProofHandle {
4
+ static __wrap(ptr) {
5
+ ptr = ptr >>> 0;
6
+ const obj = Object.create(ProofHandle.prototype);
7
+ obj.__wbg_ptr = ptr;
8
+ ProofHandleFinalization.register(obj, obj.__wbg_ptr, obj);
9
+ return obj;
10
+ }
11
+ __destroy_into_raw() {
12
+ const ptr = this.__wbg_ptr;
13
+ this.__wbg_ptr = 0;
14
+ ProofHandleFinalization.unregister(this);
15
+ return ptr;
16
+ }
17
+ free() {
18
+ const ptr = this.__destroy_into_raw();
19
+ wasm.__wbg_proofhandle_free(ptr, 0);
20
+ }
21
+ }
22
+ if (Symbol.dispose) ProofHandle.prototype[Symbol.dispose] = ProofHandle.prototype.free;
23
+
24
+ export class VerifyResult {
25
+ static __wrap(ptr) {
26
+ ptr = ptr >>> 0;
27
+ const obj = Object.create(VerifyResult.prototype);
28
+ obj.__wbg_ptr = ptr;
29
+ VerifyResultFinalization.register(obj, obj.__wbg_ptr, obj);
30
+ return obj;
31
+ }
32
+ __destroy_into_raw() {
33
+ const ptr = this.__wbg_ptr;
34
+ this.__wbg_ptr = 0;
35
+ VerifyResultFinalization.unregister(this);
36
+ return ptr;
37
+ }
38
+ free() {
39
+ const ptr = this.__destroy_into_raw();
40
+ wasm.__wbg_verifyresult_free(ptr, 0);
41
+ }
42
+ /**
43
+ * @returns {any | undefined}
44
+ */
45
+ error() {
46
+ const ret = wasm.verifyresult_error(this.__wbg_ptr);
47
+ return ret;
48
+ }
49
+ /**
50
+ * @returns {boolean}
51
+ */
52
+ get success() {
53
+ const ret = wasm.verifyresult_success(this.__wbg_ptr);
54
+ return ret !== 0;
55
+ }
56
+ }
57
+ if (Symbol.dispose) VerifyResult.prototype[Symbol.dispose] = VerifyResult.prototype.free;
58
+
59
+ /**
60
+ * @param {Uint8Array} proof_bytes
61
+ * @returns {ProofHandle}
62
+ */
63
+ export function deserialize_proof_bytes(proof_bytes) {
64
+ const ptr0 = passArray8ToWasm0(proof_bytes, wasm.__wbindgen_malloc);
65
+ const len0 = WASM_VECTOR_LEN;
66
+ const ret = wasm.deserialize_proof_bytes(ptr0, len0);
67
+ if (ret[2]) {
68
+ throw takeFromExternrefTable0(ret[1]);
69
+ }
70
+ return ProofHandle.__wrap(ret[0]);
71
+ }
72
+
73
+ export function init_defaults() {
74
+ const ret = wasm.init_defaults();
75
+ if (ret[1]) {
76
+ throw takeFromExternrefTable0(ret[0]);
77
+ }
78
+ }
79
+
80
+ /**
81
+ * @param {Uint8Array} setup_bin
82
+ * @param {Uint8Array} layout_bin
83
+ */
84
+ export function init_with(setup_bin, layout_bin) {
85
+ const ptr0 = passArray8ToWasm0(setup_bin, wasm.__wbindgen_malloc);
86
+ const len0 = WASM_VECTOR_LEN;
87
+ const ptr1 = passArray8ToWasm0(layout_bin, wasm.__wbindgen_malloc);
88
+ const len1 = WASM_VECTOR_LEN;
89
+ const ret = wasm.init_with(ptr0, len0, ptr1, len1);
90
+ if (ret[1]) {
91
+ throw takeFromExternrefTable0(ret[0]);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * @param {ProofHandle} handle
97
+ * @returns {VerifyResult}
98
+ */
99
+ export function verify_proof(handle) {
100
+ _assertClass(handle, ProofHandle);
101
+ const ret = wasm.verify_proof(handle.__wbg_ptr);
102
+ return VerifyResult.__wrap(ret);
103
+ }
104
+
105
+ function __wbg_get_imports() {
106
+ const import0 = {
107
+ __proto__: null,
108
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
109
+ throw new Error(getStringFromWasm0(arg0, arg1));
110
+ },
111
+ __wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
112
+ let deferred0_0;
113
+ let deferred0_1;
114
+ try {
115
+ deferred0_0 = arg0;
116
+ deferred0_1 = arg1;
117
+ console.error(getStringFromWasm0(arg0, arg1));
118
+ } finally {
119
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
120
+ }
121
+ },
122
+ __wbg_new_8a6f238a6ece86ea: function() {
123
+ const ret = new Error();
124
+ return ret;
125
+ },
126
+ __wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
127
+ const ret = arg1.stack;
128
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
129
+ const len1 = WASM_VECTOR_LEN;
130
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
131
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
132
+ },
133
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
134
+ // Cast intrinsic for `Ref(String) -> Externref`.
135
+ const ret = getStringFromWasm0(arg0, arg1);
136
+ return ret;
137
+ },
138
+ __wbindgen_init_externref_table: function() {
139
+ const table = wasm.__wbindgen_externrefs;
140
+ const offset = table.grow(4);
141
+ table.set(0, undefined);
142
+ table.set(offset + 0, undefined);
143
+ table.set(offset + 1, null);
144
+ table.set(offset + 2, true);
145
+ table.set(offset + 3, false);
146
+ },
147
+ };
148
+ return {
149
+ __proto__: null,
150
+ "./proof_verifier_wasm_bg.js": import0,
151
+ };
152
+ }
153
+
154
+ const ProofHandleFinalization = (typeof FinalizationRegistry === 'undefined')
155
+ ? { register: () => {}, unregister: () => {} }
156
+ : new FinalizationRegistry(ptr => wasm.__wbg_proofhandle_free(ptr >>> 0, 1));
157
+ const VerifyResultFinalization = (typeof FinalizationRegistry === 'undefined')
158
+ ? { register: () => {}, unregister: () => {} }
159
+ : new FinalizationRegistry(ptr => wasm.__wbg_verifyresult_free(ptr >>> 0, 1));
160
+
161
+ function _assertClass(instance, klass) {
162
+ if (!(instance instanceof klass)) {
163
+ throw new Error(`expected instance of ${klass.name}`);
164
+ }
165
+ }
166
+
167
+ let cachedDataViewMemory0 = null;
168
+ function getDataViewMemory0() {
169
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
170
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
171
+ }
172
+ return cachedDataViewMemory0;
173
+ }
174
+
175
+ function getStringFromWasm0(ptr, len) {
176
+ ptr = ptr >>> 0;
177
+ return decodeText(ptr, len);
178
+ }
179
+
180
+ let cachedUint8ArrayMemory0 = null;
181
+ function getUint8ArrayMemory0() {
182
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
183
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
184
+ }
185
+ return cachedUint8ArrayMemory0;
186
+ }
187
+
188
+ function passArray8ToWasm0(arg, malloc) {
189
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
190
+ getUint8ArrayMemory0().set(arg, ptr / 1);
191
+ WASM_VECTOR_LEN = arg.length;
192
+ return ptr;
193
+ }
194
+
195
+ function passStringToWasm0(arg, malloc, realloc) {
196
+ if (realloc === undefined) {
197
+ const buf = cachedTextEncoder.encode(arg);
198
+ const ptr = malloc(buf.length, 1) >>> 0;
199
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
200
+ WASM_VECTOR_LEN = buf.length;
201
+ return ptr;
202
+ }
203
+
204
+ let len = arg.length;
205
+ let ptr = malloc(len, 1) >>> 0;
206
+
207
+ const mem = getUint8ArrayMemory0();
208
+
209
+ let offset = 0;
210
+
211
+ for (; offset < len; offset++) {
212
+ const code = arg.charCodeAt(offset);
213
+ if (code > 0x7F) break;
214
+ mem[ptr + offset] = code;
215
+ }
216
+ if (offset !== len) {
217
+ if (offset !== 0) {
218
+ arg = arg.slice(offset);
219
+ }
220
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
221
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
222
+ const ret = cachedTextEncoder.encodeInto(arg, view);
223
+
224
+ offset += ret.written;
225
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
226
+ }
227
+
228
+ WASM_VECTOR_LEN = offset;
229
+ return ptr;
230
+ }
231
+
232
+ function takeFromExternrefTable0(idx) {
233
+ const value = wasm.__wbindgen_externrefs.get(idx);
234
+ wasm.__externref_table_dealloc(idx);
235
+ return value;
236
+ }
237
+
238
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
239
+ cachedTextDecoder.decode();
240
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
241
+ let numBytesDecoded = 0;
242
+ function decodeText(ptr, len) {
243
+ numBytesDecoded += len;
244
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
245
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
246
+ cachedTextDecoder.decode();
247
+ numBytesDecoded = len;
248
+ }
249
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
250
+ }
251
+
252
+ const cachedTextEncoder = new TextEncoder();
253
+
254
+ if (!('encodeInto' in cachedTextEncoder)) {
255
+ cachedTextEncoder.encodeInto = function (arg, view) {
256
+ const buf = cachedTextEncoder.encode(arg);
257
+ view.set(buf);
258
+ return {
259
+ read: arg.length,
260
+ written: buf.length
261
+ };
262
+ };
263
+ }
264
+
265
+ let WASM_VECTOR_LEN = 0;
266
+
267
+ let wasmModule, wasm;
268
+ function __wbg_finalize_init(instance, module) {
269
+ wasm = instance.exports;
270
+ wasmModule = module;
271
+ cachedDataViewMemory0 = null;
272
+ cachedUint8ArrayMemory0 = null;
273
+ wasm.__wbindgen_start();
274
+ return wasm;
275
+ }
276
+
277
+ async function __wbg_load(module, imports) {
278
+ if (typeof Response === 'function' && module instanceof Response) {
279
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
280
+ try {
281
+ return await WebAssembly.instantiateStreaming(module, imports);
282
+ } catch (e) {
283
+ const validResponse = module.ok && expectedResponseType(module.type);
284
+
285
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
286
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
287
+
288
+ } else { throw e; }
289
+ }
290
+ }
291
+
292
+ const bytes = await module.arrayBuffer();
293
+ return await WebAssembly.instantiate(bytes, imports);
294
+ } else {
295
+ const instance = await WebAssembly.instantiate(module, imports);
296
+
297
+ if (instance instanceof WebAssembly.Instance) {
298
+ return { instance, module };
299
+ } else {
300
+ return instance;
301
+ }
302
+ }
303
+
304
+ function expectedResponseType(type) {
305
+ switch (type) {
306
+ case 'basic': case 'cors': case 'default': return true;
307
+ }
308
+ return false;
309
+ }
310
+ }
311
+
312
+ function initSync(module) {
313
+ if (wasm !== undefined) return wasm;
314
+
315
+
316
+ if (module !== undefined) {
317
+ if (Object.getPrototypeOf(module) === Object.prototype) {
318
+ ({module} = module)
319
+ } else {
320
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
321
+ }
322
+ }
323
+
324
+ const imports = __wbg_get_imports();
325
+ if (!(module instanceof WebAssembly.Module)) {
326
+ module = new WebAssembly.Module(module);
327
+ }
328
+ const instance = new WebAssembly.Instance(module, imports);
329
+ return __wbg_finalize_init(instance, module);
330
+ }
331
+
332
+ async function __wbg_init(module_or_path) {
333
+ if (wasm !== undefined) return wasm;
334
+
335
+
336
+ if (module_or_path !== undefined) {
337
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
338
+ ({module_or_path} = module_or_path)
339
+ } else {
340
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
341
+ }
342
+ }
343
+
344
+ if (module_or_path === undefined) {
345
+ module_or_path = new URL('proof_verifier_wasm_bg.wasm', import.meta.url);
346
+ }
347
+ const imports = __wbg_get_imports();
348
+
349
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
350
+ module_or_path = fetch(module_or_path);
351
+ }
352
+
353
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
354
+
355
+ return __wbg_finalize_init(instance, module);
356
+ }
357
+
358
+ export { initSync, __wbg_init as default };
@@ -0,0 +1,17 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_proofhandle_free: (a: number, b: number) => void;
5
+ export const __wbg_verifyresult_free: (a: number, b: number) => void;
6
+ export const deserialize_proof_bytes: (a: number, b: number) => [number, number, number];
7
+ export const init_defaults: () => [number, number];
8
+ export const init_with: (a: number, b: number, c: number, d: number) => [number, number];
9
+ export const verify_proof: (a: number) => number;
10
+ export const verifyresult_error: (a: number) => any;
11
+ export const verifyresult_success: (a: number) => number;
12
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
13
+ export const __wbindgen_malloc: (a: number, b: number) => number;
14
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
15
+ export const __wbindgen_externrefs: WebAssembly.Table;
16
+ export const __externref_table_dealloc: (a: number) => void;
17
+ export const __wbindgen_start: () => void;