@auditable/privacy-pool-zk-sdk 0.0.2-rc.9 → 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.
@@ -1,74 +1,430 @@
1
- let wasm;
1
+ /* @ts-self-types="./client_sdk_wasm.d.ts" */
2
2
 
3
- const heap = new Array(128).fill(undefined);
4
-
5
- heap.push(undefined, null, true, false);
6
-
7
- function getObject(idx) { return heap[idx]; }
3
+ /**
4
+ * Merkle root, path, and coin field strings for the first withdraw leg (JSON → JSON).
5
+ * @param {string} coin_json
6
+ * @param {string} state_json
7
+ * @returns {string}
8
+ */
9
+ export function buildWithdrawMerkleWitness(coin_json, state_json) {
10
+ let deferred4_0;
11
+ let deferred4_1;
12
+ try {
13
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
14
+ const ptr0 = passStringToWasm0(coin_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
15
+ const len0 = WASM_VECTOR_LEN;
16
+ const ptr1 = passStringToWasm0(state_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
17
+ const len1 = WASM_VECTOR_LEN;
18
+ wasm.buildWithdrawMerkleWitness(retptr, ptr0, len0, ptr1, len1);
19
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
20
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
21
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
22
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
23
+ var ptr3 = r0;
24
+ var len3 = r1;
25
+ if (r3) {
26
+ ptr3 = 0; len3 = 0;
27
+ throw takeObject(r2);
28
+ }
29
+ deferred4_0 = ptr3;
30
+ deferred4_1 = len3;
31
+ return getStringFromWasm0(ptr3, len3);
32
+ } finally {
33
+ wasm.__wbindgen_add_to_stack_pointer(16);
34
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
35
+ }
36
+ }
8
37
 
9
- let heap_next = heap.length;
38
+ /**
39
+ * Calculate nullifier hash from nullifier decimal string.
40
+ * Returns hex string (0x...)
41
+ * @param {string} nullifier_decimal
42
+ * @returns {string}
43
+ */
44
+ export function calculateNullifierHash(nullifier_decimal) {
45
+ let deferred3_0;
46
+ let deferred3_1;
47
+ try {
48
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
49
+ const ptr0 = passStringToWasm0(nullifier_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
50
+ const len0 = WASM_VECTOR_LEN;
51
+ wasm.calculateNullifierHash(retptr, ptr0, len0);
52
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
53
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
54
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
55
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
56
+ var ptr2 = r0;
57
+ var len2 = r1;
58
+ if (r3) {
59
+ ptr2 = 0; len2 = 0;
60
+ throw takeObject(r2);
61
+ }
62
+ deferred3_0 = ptr2;
63
+ deferred3_1 = len2;
64
+ return getStringFromWasm0(ptr2, len2);
65
+ } finally {
66
+ wasm.__wbindgen_add_to_stack_pointer(16);
67
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
68
+ }
69
+ }
10
70
 
11
- function addHeapObject(obj) {
12
- if (heap_next === heap.length) heap.push(heap.length + 1);
13
- const idx = heap_next;
14
- heap_next = heap[idx];
71
+ /**
72
+ * UTF-8 seed → `SHA256` → scalar → BabyJubJub `BASE8 * r` (circom `ECDHEphemeralKey`).
73
+ * `x` and `y` are lowercase hex (no `0x`). Bech32 / stealth string: TypeScript `encodeStealthAddress`.
74
+ * @param {string} seed
75
+ * @returns {any}
76
+ */
77
+ export function ecdhEphemeralPublicKey(seed) {
78
+ try {
79
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
80
+ const ptr0 = passStringToWasm0(seed, wasm.__wbindgen_export, wasm.__wbindgen_export2);
81
+ const len0 = WASM_VECTOR_LEN;
82
+ wasm.ecdhEphemeralPublicKey(retptr, ptr0, len0);
83
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
84
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
85
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
86
+ if (r2) {
87
+ throw takeObject(r1);
88
+ }
89
+ return takeObject(r0);
90
+ } finally {
91
+ wasm.__wbindgen_add_to_stack_pointer(16);
92
+ }
93
+ }
15
94
 
16
- heap[idx] = obj;
17
- return idx;
95
+ /**
96
+ * 32-byte scalar as 64 hex chars (optional `0x`) → `ecdh_ephemeral_public_key` (no UTF-8 seed hash).
97
+ * @param {string} scalar_hex
98
+ * @returns {any}
99
+ */
100
+ export function ecdhEphemeralPublicKeyFromScalarHex(scalar_hex) {
101
+ try {
102
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
103
+ const ptr0 = passStringToWasm0(scalar_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
104
+ const len0 = WASM_VECTOR_LEN;
105
+ wasm.ecdhEphemeralPublicKeyFromScalarHex(retptr, ptr0, len0);
106
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
107
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
108
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
109
+ if (r2) {
110
+ throw takeObject(r1);
111
+ }
112
+ return takeObject(r0);
113
+ } finally {
114
+ wasm.__wbindgen_add_to_stack_pointer(16);
115
+ }
18
116
  }
19
117
 
20
- function handleError(f, args) {
118
+ /**
119
+ * Circuit `ECDH`: `priv * (pub_x, pub_y)` → shared key (`key[0], key[1]` hex).
120
+ * @param {string} priv_hex
121
+ * @param {string} pub_x_hex
122
+ * @param {string} pub_y_hex
123
+ * @returns {any}
124
+ */
125
+ export function ecdhSharedKey(priv_hex, pub_x_hex, pub_y_hex) {
21
126
  try {
22
- return f.apply(this, args);
23
- } catch (e) {
24
- wasm.__wbindgen_export_0(addHeapObject(e));
127
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
128
+ const ptr0 = passStringToWasm0(priv_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
129
+ const len0 = WASM_VECTOR_LEN;
130
+ const ptr1 = passStringToWasm0(pub_x_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
131
+ const len1 = WASM_VECTOR_LEN;
132
+ const ptr2 = passStringToWasm0(pub_y_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
133
+ const len2 = WASM_VECTOR_LEN;
134
+ wasm.ecdhSharedKey(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
135
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
136
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
137
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
138
+ if (r2) {
139
+ throw takeObject(r1);
140
+ }
141
+ return takeObject(r0);
142
+ } finally {
143
+ wasm.__wbindgen_add_to_stack_pointer(16);
25
144
  }
26
145
  }
27
146
 
28
- let cachedUint8ArrayMemory0 = null;
147
+ /**
148
+ * Generate a new coin with random nullifier, secret, and shared-secret field elements.
149
+ * `amount` is stroops (u64); JS passes `bigint`.
150
+ * Returns JSON: { coin: { value, nullifier, secret, commitment }, commitment_hex }
151
+ * @param {bigint} amount
152
+ * @returns {any}
153
+ */
154
+ export function generateCoin(amount) {
155
+ const ret = wasm.generateCoin(amount);
156
+ return takeObject(ret);
157
+ }
29
158
 
30
- function getUint8ArrayMemory0() {
31
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
32
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
159
+ /**
160
+ * `Poseidon₁(scalar)` secret + fixed ECDH shared coords (hex), matching an aligned deposit witness.
161
+ * @param {string} scalar_hex
162
+ * @param {string} shared_x_hex
163
+ * @param {string} shared_y_hex
164
+ * @param {bigint} amount
165
+ * @returns {any}
166
+ */
167
+ export function generateCoinForDepositWithSharedHex(scalar_hex, shared_x_hex, shared_y_hex, amount) {
168
+ try {
169
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
170
+ const ptr0 = passStringToWasm0(scalar_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
171
+ const len0 = WASM_VECTOR_LEN;
172
+ const ptr1 = passStringToWasm0(shared_x_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
173
+ const len1 = WASM_VECTOR_LEN;
174
+ const ptr2 = passStringToWasm0(shared_y_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
175
+ const len2 = WASM_VECTOR_LEN;
176
+ wasm.generateCoinForDepositWithSharedHex(retptr, ptr0, len0, ptr1, len1, ptr2, len2, amount);
177
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
178
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
179
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
180
+ if (r2) {
181
+ throw takeObject(r1);
182
+ }
183
+ return takeObject(r0);
184
+ } finally {
185
+ wasm.__wbindgen_add_to_stack_pointer(16);
33
186
  }
34
- return cachedUint8ArrayMemory0;
35
187
  }
36
188
 
37
- let cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
38
-
39
- if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
189
+ /**
190
+ * `secret` in coin = `Poseidon255(1)(scalar)` per `deposit.circom`; scalar is 32-byte hex (64 chars, optional `0x`).
191
+ * @param {string} scalar_hex
192
+ * @param {bigint} amount
193
+ * @returns {any}
194
+ */
195
+ export function generateCoinFromDepositEphemeralScalarHex(scalar_hex, amount) {
196
+ try {
197
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
198
+ const ptr0 = passStringToWasm0(scalar_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
199
+ const len0 = WASM_VECTOR_LEN;
200
+ wasm.generateCoinFromDepositEphemeralScalarHex(retptr, ptr0, len0, amount);
201
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
202
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
203
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
204
+ if (r2) {
205
+ throw takeObject(r1);
206
+ }
207
+ return takeObject(r0);
208
+ } finally {
209
+ wasm.__wbindgen_add_to_stack_pointer(16);
210
+ }
211
+ }
40
212
 
41
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
42
- let numBytesDecoded = 0;
43
- function decodeText(ptr, len) {
44
- numBytesDecoded += len;
45
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
46
- cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
47
- cachedTextDecoder.decode();
48
- numBytesDecoded = len;
213
+ /**
214
+ * Same as `generateCoin`, but commitment uses the given ECDH shared key (64-char hex coords from `ecdhSharedKey`); shared coords are not stored in `coin` JSON.
215
+ * @param {string} shared_x_hex
216
+ * @param {string} shared_y_hex
217
+ * @param {bigint} amount
218
+ * @returns {any}
219
+ */
220
+ export function generateCoinWithSharedSecretHex(shared_x_hex, shared_y_hex, amount) {
221
+ try {
222
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
223
+ const ptr0 = passStringToWasm0(shared_x_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
224
+ const len0 = WASM_VECTOR_LEN;
225
+ const ptr1 = passStringToWasm0(shared_y_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
226
+ const len1 = WASM_VECTOR_LEN;
227
+ wasm.generateCoinWithSharedSecretHex(retptr, ptr0, len0, ptr1, len1, amount);
228
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
229
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
230
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
231
+ if (r2) {
232
+ throw takeObject(r1);
233
+ }
234
+ return takeObject(r0);
235
+ } finally {
236
+ wasm.__wbindgen_add_to_stack_pointer(16);
49
237
  }
50
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
51
238
  }
52
239
 
53
- function getStringFromWasm0(ptr, len) {
54
- ptr = ptr >>> 0;
55
- return decodeText(ptr, len);
240
+ /**
241
+ * Convert snarkjs proof JSON to hex bytes for Soroban contract.
242
+ * @param {string} proof_json
243
+ * @returns {string}
244
+ */
245
+ export function proofToHex(proof_json) {
246
+ let deferred2_0;
247
+ let deferred2_1;
248
+ try {
249
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
250
+ const ptr0 = passStringToWasm0(proof_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
251
+ const len0 = WASM_VECTOR_LEN;
252
+ wasm.proofToHex(retptr, ptr0, len0);
253
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
254
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
255
+ deferred2_0 = r0;
256
+ deferred2_1 = r1;
257
+ return getStringFromWasm0(r0, r1);
258
+ } finally {
259
+ wasm.__wbindgen_add_to_stack_pointer(16);
260
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
261
+ }
56
262
  }
57
263
 
58
- function dropObject(idx) {
59
- if (idx < 132) return;
60
- heap[idx] = heap_next;
61
- heap_next = idx;
264
+ /**
265
+ * Convert snarkjs public signals JSON to hex bytes for Soroban contract.
266
+ * @param {string} public_json
267
+ * @returns {string}
268
+ */
269
+ export function publicToHex(public_json) {
270
+ let deferred2_0;
271
+ let deferred2_1;
272
+ try {
273
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
274
+ const ptr0 = passStringToWasm0(public_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
275
+ const len0 = WASM_VECTOR_LEN;
276
+ wasm.publicToHex(retptr, ptr0, len0);
277
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
278
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
279
+ deferred2_0 = r0;
280
+ deferred2_1 = r1;
281
+ return getStringFromWasm0(r0, r1);
282
+ } finally {
283
+ wasm.__wbindgen_add_to_stack_pointer(16);
284
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
285
+ }
62
286
  }
63
287
 
64
- function takeObject(idx) {
65
- const ret = getObject(idx);
66
- dropObject(idx);
67
- return ret;
288
+ function __wbg_get_imports() {
289
+ const import0 = {
290
+ __proto__: null,
291
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
292
+ const ret = String(getObject(arg1));
293
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
294
+ const len1 = WASM_VECTOR_LEN;
295
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
296
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
297
+ },
298
+ __wbg___wbindgen_debug_string_5398f5bb970e0daa: function(arg0, arg1) {
299
+ const ret = debugString(getObject(arg1));
300
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
301
+ const len1 = WASM_VECTOR_LEN;
302
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
303
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
304
+ },
305
+ __wbg___wbindgen_is_function_3c846841762788c1: function(arg0) {
306
+ const ret = typeof(getObject(arg0)) === 'function';
307
+ return ret;
308
+ },
309
+ __wbg___wbindgen_is_object_781bc9f159099513: function(arg0) {
310
+ const val = getObject(arg0);
311
+ const ret = typeof(val) === 'object' && val !== null;
312
+ return ret;
313
+ },
314
+ __wbg___wbindgen_is_string_7ef6b97b02428fae: function(arg0) {
315
+ const ret = typeof(getObject(arg0)) === 'string';
316
+ return ret;
317
+ },
318
+ __wbg___wbindgen_is_undefined_52709e72fb9f179c: function(arg0) {
319
+ const ret = getObject(arg0) === undefined;
320
+ return ret;
321
+ },
322
+ __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
323
+ throw new Error(getStringFromWasm0(arg0, arg1));
324
+ },
325
+ __wbg_call_2d781c1f4d5c0ef8: function() { return handleError(function (arg0, arg1, arg2) {
326
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
327
+ return addHeapObject(ret);
328
+ }, arguments); },
329
+ __wbg_crypto_38df2bab126b63dc: function(arg0) {
330
+ const ret = getObject(arg0).crypto;
331
+ return addHeapObject(ret);
332
+ },
333
+ __wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
334
+ getObject(arg0).getRandomValues(getObject(arg1));
335
+ }, arguments); },
336
+ __wbg_length_ea16607d7b61445b: function(arg0) {
337
+ const ret = getObject(arg0).length;
338
+ return ret;
339
+ },
340
+ __wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
341
+ const ret = getObject(arg0).msCrypto;
342
+ return addHeapObject(ret);
343
+ },
344
+ __wbg_new_ab79df5bd7c26067: function() {
345
+ const ret = new Object();
346
+ return addHeapObject(ret);
347
+ },
348
+ __wbg_new_with_length_825018a1616e9e55: function(arg0) {
349
+ const ret = new Uint8Array(arg0 >>> 0);
350
+ return addHeapObject(ret);
351
+ },
352
+ __wbg_node_84ea875411254db1: function(arg0) {
353
+ const ret = getObject(arg0).node;
354
+ return addHeapObject(ret);
355
+ },
356
+ __wbg_process_44c7a14e11e9f69e: function(arg0) {
357
+ const ret = getObject(arg0).process;
358
+ return addHeapObject(ret);
359
+ },
360
+ __wbg_prototypesetcall_d62e5099504357e6: function(arg0, arg1, arg2) {
361
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
362
+ },
363
+ __wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) {
364
+ getObject(arg0).randomFillSync(takeObject(arg1));
365
+ }, arguments); },
366
+ __wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () {
367
+ const ret = module.require;
368
+ return addHeapObject(ret);
369
+ }, arguments); },
370
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
371
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
372
+ },
373
+ __wbg_static_accessor_GLOBAL_8adb955bd33fac2f: function() {
374
+ const ret = typeof global === 'undefined' ? null : global;
375
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
376
+ },
377
+ __wbg_static_accessor_GLOBAL_THIS_ad356e0db91c7913: function() {
378
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
379
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
380
+ },
381
+ __wbg_static_accessor_SELF_f207c857566db248: function() {
382
+ const ret = typeof self === 'undefined' ? null : self;
383
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
384
+ },
385
+ __wbg_static_accessor_WINDOW_bb9f1ba69d61b386: function() {
386
+ const ret = typeof window === 'undefined' ? null : window;
387
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
388
+ },
389
+ __wbg_subarray_a068d24e39478a8a: function(arg0, arg1, arg2) {
390
+ const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
391
+ return addHeapObject(ret);
392
+ },
393
+ __wbg_versions_276b2795b1c6a219: function(arg0) {
394
+ const ret = getObject(arg0).versions;
395
+ return addHeapObject(ret);
396
+ },
397
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
398
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
399
+ const ret = getArrayU8FromWasm0(arg0, arg1);
400
+ return addHeapObject(ret);
401
+ },
402
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
403
+ // Cast intrinsic for `Ref(String) -> Externref`.
404
+ const ret = getStringFromWasm0(arg0, arg1);
405
+ return addHeapObject(ret);
406
+ },
407
+ __wbindgen_object_clone_ref: function(arg0) {
408
+ const ret = getObject(arg0);
409
+ return addHeapObject(ret);
410
+ },
411
+ __wbindgen_object_drop_ref: function(arg0) {
412
+ takeObject(arg0);
413
+ },
414
+ };
415
+ return {
416
+ __proto__: null,
417
+ "./client_sdk_wasm_bg.js": import0,
418
+ };
68
419
  }
69
420
 
70
- function isLikeNone(x) {
71
- return x === undefined || x === null;
421
+ function addHeapObject(obj) {
422
+ if (heap_next === heap.length) heap.push(heap.length + 1);
423
+ const idx = heap_next;
424
+ heap_next = heap[idx];
425
+
426
+ heap[idx] = obj;
427
+ return idx;
72
428
  }
73
429
 
74
430
  function debugString(val) {
@@ -136,25 +492,58 @@ function debugString(val) {
136
492
  return className;
137
493
  }
138
494
 
139
- let WASM_VECTOR_LEN = 0;
495
+ function dropObject(idx) {
496
+ if (idx < 1028) return;
497
+ heap[idx] = heap_next;
498
+ heap_next = idx;
499
+ }
140
500
 
141
- const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
501
+ function getArrayU8FromWasm0(ptr, len) {
502
+ ptr = ptr >>> 0;
503
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
504
+ }
142
505
 
143
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
144
- ? function (arg, view) {
145
- return cachedTextEncoder.encodeInto(arg, view);
506
+ let cachedDataViewMemory0 = null;
507
+ function getDataViewMemory0() {
508
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
509
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
510
+ }
511
+ return cachedDataViewMemory0;
146
512
  }
147
- : function (arg, view) {
148
- const buf = cachedTextEncoder.encode(arg);
149
- view.set(buf);
150
- return {
151
- read: arg.length,
152
- written: buf.length
153
- };
154
- });
155
513
 
156
- function passStringToWasm0(arg, malloc, realloc) {
514
+ function getStringFromWasm0(ptr, len) {
515
+ ptr = ptr >>> 0;
516
+ return decodeText(ptr, len);
517
+ }
518
+
519
+ let cachedUint8ArrayMemory0 = null;
520
+ function getUint8ArrayMemory0() {
521
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
522
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
523
+ }
524
+ return cachedUint8ArrayMemory0;
525
+ }
526
+
527
+ function getObject(idx) { return heap[idx]; }
157
528
 
529
+ function handleError(f, args) {
530
+ try {
531
+ return f.apply(this, args);
532
+ } catch (e) {
533
+ wasm.__wbindgen_export3(addHeapObject(e));
534
+ }
535
+ }
536
+
537
+ let heap = new Array(1024).fill(undefined);
538
+ heap.push(undefined, null, true, false);
539
+
540
+ let heap_next = heap.length;
541
+
542
+ function isLikeNone(x) {
543
+ return x === undefined || x === null;
544
+ }
545
+
546
+ function passStringToWasm0(arg, malloc, realloc) {
158
547
  if (realloc === undefined) {
159
548
  const buf = cachedTextEncoder.encode(arg);
160
549
  const ptr = malloc(buf.length, 1) >>> 0;
@@ -175,14 +564,13 @@ function passStringToWasm0(arg, malloc, realloc) {
175
564
  if (code > 0x7F) break;
176
565
  mem[ptr + offset] = code;
177
566
  }
178
-
179
567
  if (offset !== len) {
180
568
  if (offset !== 0) {
181
569
  arg = arg.slice(offset);
182
570
  }
183
571
  ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
184
572
  const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
185
- const ret = encodeString(arg, view);
573
+ const ret = cachedTextEncoder.encodeInto(arg, view);
186
574
 
187
575
  offset += ret.written;
188
576
  ptr = realloc(ptr, len, offset, 1) >>> 0;
@@ -192,333 +580,90 @@ function passStringToWasm0(arg, malloc, realloc) {
192
580
  return ptr;
193
581
  }
194
582
 
195
- let cachedDataViewMemory0 = null;
196
-
197
- function getDataViewMemory0() {
198
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
199
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
200
- }
201
- return cachedDataViewMemory0;
202
- }
203
- /**
204
- * Convert snarkjs public signals JSON to hex bytes for Soroban contract.
205
- * @param {string} public_json
206
- * @returns {string}
207
- */
208
- export function publicToHex(public_json) {
209
- let deferred2_0;
210
- let deferred2_1;
211
- try {
212
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
213
- const ptr0 = passStringToWasm0(public_json, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
214
- const len0 = WASM_VECTOR_LEN;
215
- wasm.publicToHex(retptr, ptr0, len0);
216
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
217
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
218
- deferred2_0 = r0;
219
- deferred2_1 = r1;
220
- return getStringFromWasm0(r0, r1);
221
- } finally {
222
- wasm.__wbindgen_add_to_stack_pointer(16);
223
- wasm.__wbindgen_export_3(deferred2_0, deferred2_1, 1);
224
- }
583
+ function takeObject(idx) {
584
+ const ret = getObject(idx);
585
+ dropObject(idx);
586
+ return ret;
225
587
  }
226
588
 
227
- /**
228
- * Calculate nullifier hash from nullifier decimal string.
229
- * Returns hex string (0x...)
230
- * @param {string} nullifier_decimal
231
- * @returns {string}
232
- */
233
- export function calculateNullifierHash(nullifier_decimal) {
234
- let deferred3_0;
235
- let deferred3_1;
236
- try {
237
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
238
- const ptr0 = passStringToWasm0(nullifier_decimal, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
239
- const len0 = WASM_VECTOR_LEN;
240
- wasm.calculateNullifierHash(retptr, ptr0, len0);
241
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
242
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
243
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
244
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
245
- var ptr2 = r0;
246
- var len2 = r1;
247
- if (r3) {
248
- ptr2 = 0; len2 = 0;
249
- throw takeObject(r2);
250
- }
251
- deferred3_0 = ptr2;
252
- deferred3_1 = len2;
253
- return getStringFromWasm0(ptr2, len2);
254
- } finally {
255
- wasm.__wbindgen_add_to_stack_pointer(16);
256
- wasm.__wbindgen_export_3(deferred3_0, deferred3_1, 1);
589
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
590
+ cachedTextDecoder.decode();
591
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
592
+ let numBytesDecoded = 0;
593
+ function decodeText(ptr, len) {
594
+ numBytesDecoded += len;
595
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
596
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
597
+ cachedTextDecoder.decode();
598
+ numBytesDecoded = len;
257
599
  }
600
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
258
601
  }
259
602
 
260
- /**
261
- * Generate withdrawal SNARK input from coin and state JSON strings.
262
- * Returns JSON string of SnarkInput.
263
- * @param {string} coin_json
264
- * @param {string} state_json
265
- * @returns {string}
266
- */
267
- export function generateWithdrawalInput(coin_json, state_json) {
268
- let deferred4_0;
269
- let deferred4_1;
270
- try {
271
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
272
- const ptr0 = passStringToWasm0(coin_json, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
273
- const len0 = WASM_VECTOR_LEN;
274
- const ptr1 = passStringToWasm0(state_json, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
275
- const len1 = WASM_VECTOR_LEN;
276
- wasm.generateWithdrawalInput(retptr, ptr0, len0, ptr1, len1);
277
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
278
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
279
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
280
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
281
- var ptr3 = r0;
282
- var len3 = r1;
283
- if (r3) {
284
- ptr3 = 0; len3 = 0;
285
- throw takeObject(r2);
286
- }
287
- deferred4_0 = ptr3;
288
- deferred4_1 = len3;
289
- return getStringFromWasm0(ptr3, len3);
290
- } finally {
291
- wasm.__wbindgen_add_to_stack_pointer(16);
292
- wasm.__wbindgen_export_3(deferred4_0, deferred4_1, 1);
293
- }
294
- }
603
+ const cachedTextEncoder = new TextEncoder();
295
604
 
296
- /**
297
- * Generate a new coin with random nullifier and secret.
298
- * Returns JSON: { coin: { value, nullifier, secret, commitment }, commitment_hex }
299
- * @returns {any}
300
- */
301
- export function generateCoin() {
302
- const ret = wasm.generateCoin();
303
- return takeObject(ret);
605
+ if (!('encodeInto' in cachedTextEncoder)) {
606
+ cachedTextEncoder.encodeInto = function (arg, view) {
607
+ const buf = cachedTextEncoder.encode(arg);
608
+ view.set(buf);
609
+ return {
610
+ read: arg.length,
611
+ written: buf.length
612
+ };
613
+ };
304
614
  }
305
615
 
306
- /**
307
- * Convert snarkjs proof JSON to hex bytes for Soroban contract.
308
- * @param {string} proof_json
309
- * @returns {string}
310
- */
311
- export function proofToHex(proof_json) {
312
- let deferred2_0;
313
- let deferred2_1;
314
- try {
315
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
316
- const ptr0 = passStringToWasm0(proof_json, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
317
- const len0 = WASM_VECTOR_LEN;
318
- wasm.proofToHex(retptr, ptr0, len0);
319
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
320
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
321
- deferred2_0 = r0;
322
- deferred2_1 = r1;
323
- return getStringFromWasm0(r0, r1);
324
- } finally {
325
- wasm.__wbindgen_add_to_stack_pointer(16);
326
- wasm.__wbindgen_export_3(deferred2_0, deferred2_1, 1);
327
- }
328
- }
616
+ let WASM_VECTOR_LEN = 0;
329
617
 
330
- const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
618
+ let wasmModule, wasm;
619
+ function __wbg_finalize_init(instance, module) {
620
+ wasm = instance.exports;
621
+ wasmModule = module;
622
+ cachedDataViewMemory0 = null;
623
+ cachedUint8ArrayMemory0 = null;
624
+ return wasm;
625
+ }
331
626
 
332
627
  async function __wbg_load(module, imports) {
333
628
  if (typeof Response === 'function' && module instanceof Response) {
334
629
  if (typeof WebAssembly.instantiateStreaming === 'function') {
335
630
  try {
336
631
  return await WebAssembly.instantiateStreaming(module, imports);
337
-
338
632
  } catch (e) {
339
- const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
633
+ const validResponse = module.ok && expectedResponseType(module.type);
340
634
 
341
635
  if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
342
636
  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);
343
637
 
344
- } else {
345
- throw e;
346
- }
638
+ } else { throw e; }
347
639
  }
348
640
  }
349
641
 
350
642
  const bytes = await module.arrayBuffer();
351
643
  return await WebAssembly.instantiate(bytes, imports);
352
-
353
644
  } else {
354
645
  const instance = await WebAssembly.instantiate(module, imports);
355
646
 
356
647
  if (instance instanceof WebAssembly.Instance) {
357
648
  return { instance, module };
358
-
359
649
  } else {
360
650
  return instance;
361
651
  }
362
652
  }
363
- }
364
-
365
- function __wbg_get_imports() {
366
- const imports = {};
367
- imports.wbg = {};
368
- imports.wbg.__wbg_buffer_a1a27a0dfa70165d = function(arg0) {
369
- const ret = getObject(arg0).buffer;
370
- return addHeapObject(ret);
371
- };
372
- imports.wbg.__wbg_call_f2db6205e5c51dc8 = function() { return handleError(function (arg0, arg1, arg2) {
373
- const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
374
- return addHeapObject(ret);
375
- }, arguments) };
376
- imports.wbg.__wbg_call_fbe8be8bf6436ce5 = function() { return handleError(function (arg0, arg1) {
377
- const ret = getObject(arg0).call(getObject(arg1));
378
- return addHeapObject(ret);
379
- }, arguments) };
380
- imports.wbg.__wbg_crypto_574e78ad8b13b65f = function(arg0) {
381
- const ret = getObject(arg0).crypto;
382
- return addHeapObject(ret);
383
- };
384
- imports.wbg.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
385
- getObject(arg0).getRandomValues(getObject(arg1));
386
- }, arguments) };
387
- imports.wbg.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
388
- const ret = getObject(arg0).msCrypto;
389
- return addHeapObject(ret);
390
- };
391
- imports.wbg.__wbg_new_07b483f72211fd66 = function() {
392
- const ret = new Object();
393
- return addHeapObject(ret);
394
- };
395
- imports.wbg.__wbg_new_e52b3efaaa774f96 = function(arg0) {
396
- const ret = new Uint8Array(getObject(arg0));
397
- return addHeapObject(ret);
398
- };
399
- imports.wbg.__wbg_newnoargs_ff528e72d35de39a = function(arg0, arg1) {
400
- const ret = new Function(getStringFromWasm0(arg0, arg1));
401
- return addHeapObject(ret);
402
- };
403
- imports.wbg.__wbg_newwithbyteoffsetandlength_3b01ecda099177e8 = function(arg0, arg1, arg2) {
404
- const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
405
- return addHeapObject(ret);
406
- };
407
- imports.wbg.__wbg_newwithlength_08f872dc1e3ada2e = function(arg0) {
408
- const ret = new Uint8Array(arg0 >>> 0);
409
- return addHeapObject(ret);
410
- };
411
- imports.wbg.__wbg_node_905d3e251edff8a2 = function(arg0) {
412
- const ret = getObject(arg0).node;
413
- return addHeapObject(ret);
414
- };
415
- imports.wbg.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
416
- const ret = getObject(arg0).process;
417
- return addHeapObject(ret);
418
- };
419
- imports.wbg.__wbg_randomFillSync_ac0988aba3254290 = function() { return handleError(function (arg0, arg1) {
420
- getObject(arg0).randomFillSync(takeObject(arg1));
421
- }, arguments) };
422
- imports.wbg.__wbg_require_60cc747a6bc5215a = function() { return handleError(function () {
423
- const ret = module.require;
424
- return addHeapObject(ret);
425
- }, arguments) };
426
- imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
427
- getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
428
- };
429
- imports.wbg.__wbg_set_fe4e79d1ed3b0e9b = function(arg0, arg1, arg2) {
430
- getObject(arg0).set(getObject(arg1), arg2 >>> 0);
431
- };
432
- imports.wbg.__wbg_static_accessor_GLOBAL_487c52c58d65314d = function() {
433
- const ret = typeof global === 'undefined' ? null : global;
434
- return isLikeNone(ret) ? 0 : addHeapObject(ret);
435
- };
436
- imports.wbg.__wbg_static_accessor_GLOBAL_THIS_ee9704f328b6b291 = function() {
437
- const ret = typeof globalThis === 'undefined' ? null : globalThis;
438
- return isLikeNone(ret) ? 0 : addHeapObject(ret);
439
- };
440
- imports.wbg.__wbg_static_accessor_SELF_78c9e3071b912620 = function() {
441
- const ret = typeof self === 'undefined' ? null : self;
442
- return isLikeNone(ret) ? 0 : addHeapObject(ret);
443
- };
444
- imports.wbg.__wbg_static_accessor_WINDOW_a093d21393777366 = function() {
445
- const ret = typeof window === 'undefined' ? null : window;
446
- return isLikeNone(ret) ? 0 : addHeapObject(ret);
447
- };
448
- imports.wbg.__wbg_subarray_dd4ade7d53bd8e26 = function(arg0, arg1, arg2) {
449
- const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
450
- return addHeapObject(ret);
451
- };
452
- imports.wbg.__wbg_versions_c01dfd4722a88165 = function(arg0) {
453
- const ret = getObject(arg0).versions;
454
- return addHeapObject(ret);
455
- };
456
- imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
457
- const ret = debugString(getObject(arg1));
458
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
459
- const len1 = WASM_VECTOR_LEN;
460
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
461
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
462
- };
463
- imports.wbg.__wbindgen_is_function = function(arg0) {
464
- const ret = typeof(getObject(arg0)) === 'function';
465
- return ret;
466
- };
467
- imports.wbg.__wbindgen_is_object = function(arg0) {
468
- const val = getObject(arg0);
469
- const ret = typeof(val) === 'object' && val !== null;
470
- return ret;
471
- };
472
- imports.wbg.__wbindgen_is_string = function(arg0) {
473
- const ret = typeof(getObject(arg0)) === 'string';
474
- return ret;
475
- };
476
- imports.wbg.__wbindgen_is_undefined = function(arg0) {
477
- const ret = getObject(arg0) === undefined;
478
- return ret;
479
- };
480
- imports.wbg.__wbindgen_memory = function() {
481
- const ret = wasm.memory;
482
- return addHeapObject(ret);
483
- };
484
- imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
485
- const ret = getObject(arg0);
486
- return addHeapObject(ret);
487
- };
488
- imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
489
- takeObject(arg0);
490
- };
491
- imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
492
- const ret = getStringFromWasm0(arg0, arg1);
493
- return addHeapObject(ret);
494
- };
495
- imports.wbg.__wbindgen_throw = function(arg0, arg1) {
496
- throw new Error(getStringFromWasm0(arg0, arg1));
497
- };
498
-
499
- return imports;
500
- }
501
-
502
- function __wbg_init_memory(imports, memory) {
503
653
 
504
- }
505
-
506
- function __wbg_finalize_init(instance, module) {
507
- wasm = instance.exports;
508
- __wbg_init.__wbindgen_wasm_module = module;
509
- cachedDataViewMemory0 = null;
510
- cachedUint8ArrayMemory0 = null;
511
-
512
-
513
-
514
- return wasm;
654
+ function expectedResponseType(type) {
655
+ switch (type) {
656
+ case 'basic': case 'cors': case 'default': return true;
657
+ }
658
+ return false;
659
+ }
515
660
  }
516
661
 
517
662
  function initSync(module) {
518
663
  if (wasm !== undefined) return wasm;
519
664
 
520
665
 
521
- if (typeof module !== 'undefined') {
666
+ if (module !== undefined) {
522
667
  if (Object.getPrototypeOf(module) === Object.prototype) {
523
668
  ({module} = module)
524
669
  } else {
@@ -527,15 +672,10 @@ function initSync(module) {
527
672
  }
528
673
 
529
674
  const imports = __wbg_get_imports();
530
-
531
- __wbg_init_memory(imports);
532
-
533
675
  if (!(module instanceof WebAssembly.Module)) {
534
676
  module = new WebAssembly.Module(module);
535
677
  }
536
-
537
678
  const instance = new WebAssembly.Instance(module, imports);
538
-
539
679
  return __wbg_finalize_init(instance, module);
540
680
  }
541
681
 
@@ -543,7 +683,7 @@ async function __wbg_init(module_or_path) {
543
683
  if (wasm !== undefined) return wasm;
544
684
 
545
685
 
546
- if (typeof module_or_path !== 'undefined') {
686
+ if (module_or_path !== undefined) {
547
687
  if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
548
688
  ({module_or_path} = module_or_path)
549
689
  } else {
@@ -551,7 +691,7 @@ async function __wbg_init(module_or_path) {
551
691
  }
552
692
  }
553
693
 
554
- if (typeof module_or_path === 'undefined') {
694
+ if (module_or_path === undefined) {
555
695
  module_or_path = new URL('client_sdk_wasm_bg.wasm', import.meta.url);
556
696
  }
557
697
  const imports = __wbg_get_imports();
@@ -560,12 +700,9 @@ async function __wbg_init(module_or_path) {
560
700
  module_or_path = fetch(module_or_path);
561
701
  }
562
702
 
563
- __wbg_init_memory(imports);
564
-
565
703
  const { instance, module } = await __wbg_load(await module_or_path, imports);
566
704
 
567
705
  return __wbg_finalize_init(instance, module);
568
706
  }
569
707
 
570
- export { initSync };
571
- export default __wbg_init;
708
+ export { initSync, __wbg_init as default };