@auditable/privacy-pool-zk-sdk 0.0.2-rc.8 → 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.
@@ -0,0 +1,708 @@
1
+ /* @ts-self-types="./client_sdk_wasm.d.ts" */
2
+
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
+ }
37
+
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
+ }
70
+
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
+ }
94
+
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
+ }
116
+ }
117
+
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) {
126
+ try {
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);
144
+ }
145
+ }
146
+
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
+ }
158
+
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);
186
+ }
187
+ }
188
+
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
+ }
212
+
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);
237
+ }
238
+ }
239
+
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
+ }
262
+ }
263
+
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
+ }
286
+ }
287
+
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
+ };
419
+ }
420
+
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;
428
+ }
429
+
430
+ function debugString(val) {
431
+ // primitive types
432
+ const type = typeof val;
433
+ if (type == 'number' || type == 'boolean' || val == null) {
434
+ return `${val}`;
435
+ }
436
+ if (type == 'string') {
437
+ return `"${val}"`;
438
+ }
439
+ if (type == 'symbol') {
440
+ const description = val.description;
441
+ if (description == null) {
442
+ return 'Symbol';
443
+ } else {
444
+ return `Symbol(${description})`;
445
+ }
446
+ }
447
+ if (type == 'function') {
448
+ const name = val.name;
449
+ if (typeof name == 'string' && name.length > 0) {
450
+ return `Function(${name})`;
451
+ } else {
452
+ return 'Function';
453
+ }
454
+ }
455
+ // objects
456
+ if (Array.isArray(val)) {
457
+ const length = val.length;
458
+ let debug = '[';
459
+ if (length > 0) {
460
+ debug += debugString(val[0]);
461
+ }
462
+ for(let i = 1; i < length; i++) {
463
+ debug += ', ' + debugString(val[i]);
464
+ }
465
+ debug += ']';
466
+ return debug;
467
+ }
468
+ // Test for built-in
469
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
470
+ let className;
471
+ if (builtInMatches && builtInMatches.length > 1) {
472
+ className = builtInMatches[1];
473
+ } else {
474
+ // Failed to match the standard '[object ClassName]'
475
+ return toString.call(val);
476
+ }
477
+ if (className == 'Object') {
478
+ // we're a user defined class or Object
479
+ // JSON.stringify avoids problems with cycles, and is generally much
480
+ // easier than looping through ownProperties of `val`.
481
+ try {
482
+ return 'Object(' + JSON.stringify(val) + ')';
483
+ } catch (_) {
484
+ return 'Object';
485
+ }
486
+ }
487
+ // errors
488
+ if (val instanceof Error) {
489
+ return `${val.name}: ${val.message}\n${val.stack}`;
490
+ }
491
+ // TODO we could test for more things here, like `Set`s and `Map`s.
492
+ return className;
493
+ }
494
+
495
+ function dropObject(idx) {
496
+ if (idx < 1028) return;
497
+ heap[idx] = heap_next;
498
+ heap_next = idx;
499
+ }
500
+
501
+ function getArrayU8FromWasm0(ptr, len) {
502
+ ptr = ptr >>> 0;
503
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
504
+ }
505
+
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;
512
+ }
513
+
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]; }
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) {
547
+ if (realloc === undefined) {
548
+ const buf = cachedTextEncoder.encode(arg);
549
+ const ptr = malloc(buf.length, 1) >>> 0;
550
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
551
+ WASM_VECTOR_LEN = buf.length;
552
+ return ptr;
553
+ }
554
+
555
+ let len = arg.length;
556
+ let ptr = malloc(len, 1) >>> 0;
557
+
558
+ const mem = getUint8ArrayMemory0();
559
+
560
+ let offset = 0;
561
+
562
+ for (; offset < len; offset++) {
563
+ const code = arg.charCodeAt(offset);
564
+ if (code > 0x7F) break;
565
+ mem[ptr + offset] = code;
566
+ }
567
+ if (offset !== len) {
568
+ if (offset !== 0) {
569
+ arg = arg.slice(offset);
570
+ }
571
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
572
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
573
+ const ret = cachedTextEncoder.encodeInto(arg, view);
574
+
575
+ offset += ret.written;
576
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
577
+ }
578
+
579
+ WASM_VECTOR_LEN = offset;
580
+ return ptr;
581
+ }
582
+
583
+ function takeObject(idx) {
584
+ const ret = getObject(idx);
585
+ dropObject(idx);
586
+ return ret;
587
+ }
588
+
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;
599
+ }
600
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
601
+ }
602
+
603
+ const cachedTextEncoder = new TextEncoder();
604
+
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
+ };
614
+ }
615
+
616
+ let WASM_VECTOR_LEN = 0;
617
+
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
+ }
626
+
627
+ async function __wbg_load(module, imports) {
628
+ if (typeof Response === 'function' && module instanceof Response) {
629
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
630
+ try {
631
+ return await WebAssembly.instantiateStreaming(module, imports);
632
+ } catch (e) {
633
+ const validResponse = module.ok && expectedResponseType(module.type);
634
+
635
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
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);
637
+
638
+ } else { throw e; }
639
+ }
640
+ }
641
+
642
+ const bytes = await module.arrayBuffer();
643
+ return await WebAssembly.instantiate(bytes, imports);
644
+ } else {
645
+ const instance = await WebAssembly.instantiate(module, imports);
646
+
647
+ if (instance instanceof WebAssembly.Instance) {
648
+ return { instance, module };
649
+ } else {
650
+ return instance;
651
+ }
652
+ }
653
+
654
+ function expectedResponseType(type) {
655
+ switch (type) {
656
+ case 'basic': case 'cors': case 'default': return true;
657
+ }
658
+ return false;
659
+ }
660
+ }
661
+
662
+ function initSync(module) {
663
+ if (wasm !== undefined) return wasm;
664
+
665
+
666
+ if (module !== undefined) {
667
+ if (Object.getPrototypeOf(module) === Object.prototype) {
668
+ ({module} = module)
669
+ } else {
670
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
671
+ }
672
+ }
673
+
674
+ const imports = __wbg_get_imports();
675
+ if (!(module instanceof WebAssembly.Module)) {
676
+ module = new WebAssembly.Module(module);
677
+ }
678
+ const instance = new WebAssembly.Instance(module, imports);
679
+ return __wbg_finalize_init(instance, module);
680
+ }
681
+
682
+ async function __wbg_init(module_or_path) {
683
+ if (wasm !== undefined) return wasm;
684
+
685
+
686
+ if (module_or_path !== undefined) {
687
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
688
+ ({module_or_path} = module_or_path)
689
+ } else {
690
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
691
+ }
692
+ }
693
+
694
+ if (module_or_path === undefined) {
695
+ module_or_path = new URL('client_sdk_wasm_bg.wasm', import.meta.url);
696
+ }
697
+ const imports = __wbg_get_imports();
698
+
699
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
700
+ module_or_path = fetch(module_or_path);
701
+ }
702
+
703
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
704
+
705
+ return __wbg_finalize_init(instance, module);
706
+ }
707
+
708
+ export { initSync, __wbg_init as default };
Binary file