@permissionless-technologies/upp-sdk 0.1.0 → 0.2.1

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.
@@ -0,0 +1,79 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Generate a proof and also verify it locally before returning.
6
+ *
7
+ * This is useful during development to catch issues early.
8
+ * In production, you'd skip local verification to save time.
9
+ */
10
+ export function prove_and_verify_withdraw_wasm(inputs_json: string): Uint8Array;
11
+
12
+ /**
13
+ * Compute all derived values (hashes, roots, nullifier) from the private witness,
14
+ * then generate a proof.
15
+ *
16
+ * This is the main entry point for the browser — the JS side only needs
17
+ * to provide the raw witness values, not pre-compute any hashes.
18
+ *
19
+ * Returns seed (32 bytes) || serialized proof bytes as `Uint8Array`.
20
+ */
21
+ export function prove_from_witness_wasm(witness_json: string): Uint8Array;
22
+
23
+ /**
24
+ * Generate a Circle STARK proof for a 1-in-2-out transfer.
25
+ *
26
+ * The WASM prover computes all derived values (hashes, roots, nullifier,
27
+ * output commitments) internally from the raw witness.
28
+ *
29
+ * Returns seed (32 bytes) || serialized proof bytes as `Uint8Array`.
30
+ */
31
+ export function prove_transfer_from_witness_wasm(witness_json: string): Uint8Array;
32
+
33
+ /**
34
+ * Generate a Circle STARK proof for a withdraw operation.
35
+ *
36
+ * Takes a JSON string with all public and private inputs.
37
+ * Returns seed (32 bytes) || serialized proof as a `Uint8Array`.
38
+ *
39
+ * Throws a JS error string on failure.
40
+ */
41
+ export function prove_withdraw_wasm(inputs_json: string): Uint8Array;
42
+
43
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
44
+
45
+ export interface InitOutput {
46
+ readonly memory: WebAssembly.Memory;
47
+ readonly prove_withdraw_wasm: (a: number, b: number) => [number, number, number, number];
48
+ readonly prove_and_verify_withdraw_wasm: (a: number, b: number) => [number, number, number, number];
49
+ readonly prove_from_witness_wasm: (a: number, b: number) => [number, number, number, number];
50
+ readonly prove_transfer_from_witness_wasm: (a: number, b: number) => [number, number, number, number];
51
+ readonly __wbindgen_externrefs: WebAssembly.Table;
52
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
53
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
54
+ readonly __externref_table_dealloc: (a: number) => void;
55
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
56
+ readonly __wbindgen_start: () => void;
57
+ }
58
+
59
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
60
+
61
+ /**
62
+ * Instantiates the given `module`, which can either be bytes or
63
+ * a precompiled `WebAssembly.Module`.
64
+ *
65
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
66
+ *
67
+ * @returns {InitOutput}
68
+ */
69
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
70
+
71
+ /**
72
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
73
+ * for everything else, calls `WebAssembly.instantiate` directly.
74
+ *
75
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
76
+ *
77
+ * @returns {Promise<InitOutput>}
78
+ */
79
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,293 @@
1
+ /* @ts-self-types="./upp_stwo_prover.d.ts" */
2
+
3
+ /**
4
+ * Generate a proof and also verify it locally before returning.
5
+ *
6
+ * This is useful during development to catch issues early.
7
+ * In production, you'd skip local verification to save time.
8
+ * @param {string} inputs_json
9
+ * @returns {Uint8Array}
10
+ */
11
+ export function prove_and_verify_withdraw_wasm(inputs_json) {
12
+ const ptr0 = passStringToWasm0(inputs_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
13
+ const len0 = WASM_VECTOR_LEN;
14
+ const ret = wasm.prove_and_verify_withdraw_wasm(ptr0, len0);
15
+ if (ret[3]) {
16
+ throw takeFromExternrefTable0(ret[2]);
17
+ }
18
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
19
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
20
+ return v2;
21
+ }
22
+
23
+ /**
24
+ * Compute all derived values (hashes, roots, nullifier) from the private witness,
25
+ * then generate a proof.
26
+ *
27
+ * This is the main entry point for the browser — the JS side only needs
28
+ * to provide the raw witness values, not pre-compute any hashes.
29
+ *
30
+ * Returns seed (32 bytes) || serialized proof bytes as `Uint8Array`.
31
+ * @param {string} witness_json
32
+ * @returns {Uint8Array}
33
+ */
34
+ export function prove_from_witness_wasm(witness_json) {
35
+ const ptr0 = passStringToWasm0(witness_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
36
+ const len0 = WASM_VECTOR_LEN;
37
+ const ret = wasm.prove_from_witness_wasm(ptr0, len0);
38
+ if (ret[3]) {
39
+ throw takeFromExternrefTable0(ret[2]);
40
+ }
41
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
42
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
43
+ return v2;
44
+ }
45
+
46
+ /**
47
+ * Generate a Circle STARK proof for a 1-in-2-out transfer.
48
+ *
49
+ * The WASM prover computes all derived values (hashes, roots, nullifier,
50
+ * output commitments) internally from the raw witness.
51
+ *
52
+ * Returns seed (32 bytes) || serialized proof bytes as `Uint8Array`.
53
+ * @param {string} witness_json
54
+ * @returns {Uint8Array}
55
+ */
56
+ export function prove_transfer_from_witness_wasm(witness_json) {
57
+ const ptr0 = passStringToWasm0(witness_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
58
+ const len0 = WASM_VECTOR_LEN;
59
+ const ret = wasm.prove_transfer_from_witness_wasm(ptr0, len0);
60
+ if (ret[3]) {
61
+ throw takeFromExternrefTable0(ret[2]);
62
+ }
63
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
64
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
65
+ return v2;
66
+ }
67
+
68
+ /**
69
+ * Generate a Circle STARK proof for a withdraw operation.
70
+ *
71
+ * Takes a JSON string with all public and private inputs.
72
+ * Returns seed (32 bytes) || serialized proof as a `Uint8Array`.
73
+ *
74
+ * Throws a JS error string on failure.
75
+ * @param {string} inputs_json
76
+ * @returns {Uint8Array}
77
+ */
78
+ export function prove_withdraw_wasm(inputs_json) {
79
+ const ptr0 = passStringToWasm0(inputs_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
80
+ const len0 = WASM_VECTOR_LEN;
81
+ const ret = wasm.prove_withdraw_wasm(ptr0, len0);
82
+ if (ret[3]) {
83
+ throw takeFromExternrefTable0(ret[2]);
84
+ }
85
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
86
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
87
+ return v2;
88
+ }
89
+
90
+ function __wbg_get_imports() {
91
+ const import0 = {
92
+ __proto__: null,
93
+ __wbg_Error_83742b46f01ce22d: function(arg0, arg1) {
94
+ const ret = Error(getStringFromWasm0(arg0, arg1));
95
+ return ret;
96
+ },
97
+ __wbindgen_init_externref_table: function() {
98
+ const table = wasm.__wbindgen_externrefs;
99
+ const offset = table.grow(4);
100
+ table.set(0, undefined);
101
+ table.set(offset + 0, undefined);
102
+ table.set(offset + 1, null);
103
+ table.set(offset + 2, true);
104
+ table.set(offset + 3, false);
105
+ },
106
+ };
107
+ return {
108
+ __proto__: null,
109
+ "./upp_stwo_prover_bg.js": import0,
110
+ };
111
+ }
112
+
113
+ function getArrayU8FromWasm0(ptr, len) {
114
+ ptr = ptr >>> 0;
115
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
116
+ }
117
+
118
+ function getStringFromWasm0(ptr, len) {
119
+ ptr = ptr >>> 0;
120
+ return decodeText(ptr, len);
121
+ }
122
+
123
+ let cachedUint8ArrayMemory0 = null;
124
+ function getUint8ArrayMemory0() {
125
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
126
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
127
+ }
128
+ return cachedUint8ArrayMemory0;
129
+ }
130
+
131
+ function passStringToWasm0(arg, malloc, realloc) {
132
+ if (realloc === undefined) {
133
+ const buf = cachedTextEncoder.encode(arg);
134
+ const ptr = malloc(buf.length, 1) >>> 0;
135
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
136
+ WASM_VECTOR_LEN = buf.length;
137
+ return ptr;
138
+ }
139
+
140
+ let len = arg.length;
141
+ let ptr = malloc(len, 1) >>> 0;
142
+
143
+ const mem = getUint8ArrayMemory0();
144
+
145
+ let offset = 0;
146
+
147
+ for (; offset < len; offset++) {
148
+ const code = arg.charCodeAt(offset);
149
+ if (code > 0x7F) break;
150
+ mem[ptr + offset] = code;
151
+ }
152
+ if (offset !== len) {
153
+ if (offset !== 0) {
154
+ arg = arg.slice(offset);
155
+ }
156
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
157
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
158
+ const ret = cachedTextEncoder.encodeInto(arg, view);
159
+
160
+ offset += ret.written;
161
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
162
+ }
163
+
164
+ WASM_VECTOR_LEN = offset;
165
+ return ptr;
166
+ }
167
+
168
+ function takeFromExternrefTable0(idx) {
169
+ const value = wasm.__wbindgen_externrefs.get(idx);
170
+ wasm.__externref_table_dealloc(idx);
171
+ return value;
172
+ }
173
+
174
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
175
+ cachedTextDecoder.decode();
176
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
177
+ let numBytesDecoded = 0;
178
+ function decodeText(ptr, len) {
179
+ numBytesDecoded += len;
180
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
181
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
182
+ cachedTextDecoder.decode();
183
+ numBytesDecoded = len;
184
+ }
185
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
186
+ }
187
+
188
+ const cachedTextEncoder = new TextEncoder();
189
+
190
+ if (!('encodeInto' in cachedTextEncoder)) {
191
+ cachedTextEncoder.encodeInto = function (arg, view) {
192
+ const buf = cachedTextEncoder.encode(arg);
193
+ view.set(buf);
194
+ return {
195
+ read: arg.length,
196
+ written: buf.length
197
+ };
198
+ };
199
+ }
200
+
201
+ let WASM_VECTOR_LEN = 0;
202
+
203
+ let wasmModule, wasm;
204
+ function __wbg_finalize_init(instance, module) {
205
+ wasm = instance.exports;
206
+ wasmModule = module;
207
+ cachedUint8ArrayMemory0 = null;
208
+ wasm.__wbindgen_start();
209
+ return wasm;
210
+ }
211
+
212
+ async function __wbg_load(module, imports) {
213
+ if (typeof Response === 'function' && module instanceof Response) {
214
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
215
+ try {
216
+ return await WebAssembly.instantiateStreaming(module, imports);
217
+ } catch (e) {
218
+ const validResponse = module.ok && expectedResponseType(module.type);
219
+
220
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
221
+ 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);
222
+
223
+ } else { throw e; }
224
+ }
225
+ }
226
+
227
+ const bytes = await module.arrayBuffer();
228
+ return await WebAssembly.instantiate(bytes, imports);
229
+ } else {
230
+ const instance = await WebAssembly.instantiate(module, imports);
231
+
232
+ if (instance instanceof WebAssembly.Instance) {
233
+ return { instance, module };
234
+ } else {
235
+ return instance;
236
+ }
237
+ }
238
+
239
+ function expectedResponseType(type) {
240
+ switch (type) {
241
+ case 'basic': case 'cors': case 'default': return true;
242
+ }
243
+ return false;
244
+ }
245
+ }
246
+
247
+ function initSync(module) {
248
+ if (wasm !== undefined) return wasm;
249
+
250
+
251
+ if (module !== undefined) {
252
+ if (Object.getPrototypeOf(module) === Object.prototype) {
253
+ ({module} = module)
254
+ } else {
255
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
256
+ }
257
+ }
258
+
259
+ const imports = __wbg_get_imports();
260
+ if (!(module instanceof WebAssembly.Module)) {
261
+ module = new WebAssembly.Module(module);
262
+ }
263
+ const instance = new WebAssembly.Instance(module, imports);
264
+ return __wbg_finalize_init(instance, module);
265
+ }
266
+
267
+ async function __wbg_init(module_or_path) {
268
+ if (wasm !== undefined) return wasm;
269
+
270
+
271
+ if (module_or_path !== undefined) {
272
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
273
+ ({module_or_path} = module_or_path)
274
+ } else {
275
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
276
+ }
277
+ }
278
+
279
+ if (module_or_path === undefined) {
280
+ module_or_path = new URL('upp_stwo_prover_bg.wasm', import.meta.url);
281
+ }
282
+ const imports = __wbg_get_imports();
283
+
284
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
285
+ module_or_path = fetch(module_or_path);
286
+ }
287
+
288
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
289
+
290
+ return __wbg_finalize_init(instance, module);
291
+ }
292
+
293
+ export { initSync, __wbg_init as default };
@@ -0,0 +1,13 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const prove_withdraw_wasm: (a: number, b: number) => [number, number, number, number];
5
+ export const prove_and_verify_withdraw_wasm: (a: number, b: number) => [number, number, number, number];
6
+ export const prove_from_witness_wasm: (a: number, b: number) => [number, number, number, number];
7
+ export const prove_transfer_from_witness_wasm: (a: number, b: number) => [number, number, number, number];
8
+ export const __wbindgen_externrefs: WebAssembly.Table;
9
+ export const __wbindgen_malloc: (a: number, b: number) => number;
10
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
11
+ export const __externref_table_dealloc: (a: number) => void;
12
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
13
+ export const __wbindgen_start: () => void;