@interest-protocol/vortex-sdk 0.0.1-alpha.0 → 1.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.
Files changed (121) hide show
  1. package/.eslingignore +1 -0
  2. package/dist/__tests__/entities/keypair.spec.d.ts +2 -0
  3. package/dist/__tests__/entities/keypair.spec.d.ts.map +1 -0
  4. package/dist/__tests__/test-utils.d.ts +25 -0
  5. package/dist/__tests__/test-utils.d.ts.map +1 -0
  6. package/dist/__tests__/types.d.ts +3 -0
  7. package/dist/__tests__/types.d.ts.map +1 -0
  8. package/dist/__tests__/vortex.test.d.ts +2 -0
  9. package/dist/__tests__/vortex.test.d.ts.map +1 -0
  10. package/dist/constants.d.ts +44 -0
  11. package/dist/constants.d.ts.map +1 -0
  12. package/dist/crypto/ff/f1field.d.ts +76 -0
  13. package/dist/crypto/ff/f1field.d.ts.map +1 -0
  14. package/dist/crypto/ff/index.d.ts +6 -0
  15. package/dist/crypto/ff/index.d.ts.map +1 -0
  16. package/dist/crypto/ff/random.d.ts +2 -0
  17. package/dist/crypto/ff/random.d.ts.map +1 -0
  18. package/dist/crypto/ff/scalar.d.ts +45 -0
  19. package/dist/crypto/ff/scalar.d.ts.map +1 -0
  20. package/dist/crypto/ff/utils.d.ts +6 -0
  21. package/dist/crypto/ff/utils.d.ts.map +1 -0
  22. package/dist/crypto/index.d.ts +6 -0
  23. package/dist/crypto/index.d.ts.map +1 -0
  24. package/dist/crypto/poseidon/index.d.ts +2 -0
  25. package/dist/crypto/poseidon/index.d.ts.map +1 -0
  26. package/dist/crypto/poseidon/poseidon-constants-opt.d.ts +7 -0
  27. package/dist/crypto/poseidon/poseidon-constants-opt.d.ts.map +1 -0
  28. package/dist/crypto/poseidon/poseidon-opt.d.ts +16 -0
  29. package/dist/crypto/poseidon/poseidon-opt.d.ts.map +1 -0
  30. package/dist/deposit.d.ts +4 -0
  31. package/dist/deposit.d.ts.map +1 -0
  32. package/dist/entities/index.d.ts +4 -0
  33. package/dist/entities/index.d.ts.map +1 -0
  34. package/dist/entities/keypair.d.ts +29 -0
  35. package/dist/entities/keypair.d.ts.map +1 -0
  36. package/dist/entities/merkle-tree.d.ts +81 -0
  37. package/dist/entities/merkle-tree.d.ts.map +1 -0
  38. package/dist/entities/utxo.d.ts +24 -0
  39. package/dist/entities/utxo.d.ts.map +1 -0
  40. package/dist/index.d.ts +6 -2
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +38280 -4459
  43. package/dist/index.js.map +1 -1
  44. package/dist/index.mjs +38244 -4453
  45. package/dist/index.mjs.map +1 -1
  46. package/dist/jest-setup.d.ts +2 -0
  47. package/dist/jest-setup.d.ts.map +1 -0
  48. package/dist/keys/index.d.ts +3 -0
  49. package/dist/keys/index.d.ts.map +1 -0
  50. package/dist/pkg/nodejs/vortex.d.ts +11 -0
  51. package/dist/pkg/nodejs/vortex.d.ts.map +1 -0
  52. package/dist/pkg/web/vortex.d.ts +44 -0
  53. package/dist/pkg/web/vortex.d.ts.map +1 -0
  54. package/dist/utils/decrypt.d.ts +12 -0
  55. package/dist/utils/decrypt.d.ts.map +1 -0
  56. package/dist/utils/env.d.ts +2 -0
  57. package/dist/utils/env.d.ts.map +1 -0
  58. package/dist/utils/events.d.ts +7 -0
  59. package/dist/utils/events.d.ts.map +1 -0
  60. package/dist/utils/ext-data.d.ts +3 -0
  61. package/dist/utils/ext-data.d.ts.map +1 -0
  62. package/dist/utils/index.d.ts +50 -0
  63. package/dist/utils/index.d.ts.map +1 -0
  64. package/dist/utils/prove.d.ts +3 -0
  65. package/dist/utils/prove.d.ts.map +1 -0
  66. package/dist/vortex.d.ts +51 -21
  67. package/dist/vortex.d.ts.map +1 -1
  68. package/dist/vortex.types.d.ts +74 -50
  69. package/dist/vortex.types.d.ts.map +1 -1
  70. package/dist/vortex_bg.wasm +0 -0
  71. package/dist/withdraw.d.ts +4 -0
  72. package/dist/withdraw.d.ts.map +1 -0
  73. package/jest.config.js +31 -0
  74. package/package.json +22 -7
  75. package/src/__tests__/entities/keypair.spec.ts +191 -0
  76. package/src/__tests__/test-utils.ts +76 -0
  77. package/src/__tests__/types.ts +3 -0
  78. package/src/__tests__/vortex.test.ts +25 -0
  79. package/src/constants.ts +104 -0
  80. package/src/crypto/ff/f1field.ts +464 -0
  81. package/src/crypto/ff/index.ts +6 -0
  82. package/src/crypto/ff/random.ts +32 -0
  83. package/src/crypto/ff/readme.md +8 -0
  84. package/src/crypto/ff/scalar.ts +264 -0
  85. package/src/crypto/ff/utils.ts +121 -0
  86. package/src/crypto/index.ts +8 -0
  87. package/src/crypto/poseidon/index.ts +1 -0
  88. package/src/crypto/poseidon/poseidon-constants-opt.ts +24806 -0
  89. package/src/crypto/poseidon/poseidon-opt.ts +184 -0
  90. package/src/deposit.ts +168 -0
  91. package/src/entities/index.ts +3 -0
  92. package/src/entities/keypair.ts +262 -0
  93. package/src/entities/merkle-tree.ts +256 -0
  94. package/src/entities/utxo.ts +52 -0
  95. package/src/index.ts +6 -2
  96. package/src/jest-setup.ts +2 -0
  97. package/src/keys/index.ts +5 -0
  98. package/src/pkg/nodejs/vortex.d.ts +36 -0
  99. package/src/pkg/nodejs/vortex.js +332 -0
  100. package/src/pkg/nodejs/vortex_bg.wasm +0 -0
  101. package/src/pkg/nodejs/vortex_bg.wasm.d.ts +12 -0
  102. package/src/pkg/web/vortex.d.ts +72 -0
  103. package/src/pkg/web/vortex.js +442 -0
  104. package/src/pkg/web/vortex_bg.wasm +0 -0
  105. package/src/pkg/web/vortex_bg.wasm.d.ts +12 -0
  106. package/src/utils/decrypt.ts +46 -0
  107. package/src/utils/env.ts +18 -0
  108. package/src/utils/events.ts +16 -0
  109. package/src/utils/ext-data.ts +43 -0
  110. package/src/utils/index.ts +152 -0
  111. package/src/utils/prove.ts +18 -0
  112. package/src/vortex.ts +235 -111
  113. package/src/vortex.types.ts +74 -54
  114. package/src/withdraw.ts +159 -0
  115. package/tsconfig.json +4 -2
  116. package/dist/admin.d.ts +0 -17
  117. package/dist/admin.d.ts.map +0 -1
  118. package/dist/utils.d.ts +0 -11
  119. package/dist/utils.d.ts.map +0 -1
  120. package/src/admin.ts +0 -124
  121. package/src/utils.ts +0 -66
@@ -0,0 +1,442 @@
1
+ let wasm;
2
+
3
+ /* eslint-disable */
4
+ function debugString(val) {
5
+ // primitive types
6
+ const type = typeof val;
7
+ if (type == 'number' || type == 'boolean' || val == null) {
8
+ return `${val}`;
9
+ }
10
+ if (type == 'string') {
11
+ return `"${val}"`;
12
+ }
13
+ if (type == 'symbol') {
14
+ const description = val.description;
15
+ if (description == null) {
16
+ return 'Symbol';
17
+ } else {
18
+ return `Symbol(${description})`;
19
+ }
20
+ }
21
+ if (type == 'function') {
22
+ const name = val.name;
23
+ if (typeof name == 'string' && name.length > 0) {
24
+ return `Function(${name})`;
25
+ } else {
26
+ return 'Function';
27
+ }
28
+ }
29
+ // objects
30
+ if (Array.isArray(val)) {
31
+ const length = val.length;
32
+ let debug = '[';
33
+ if (length > 0) {
34
+ debug += debugString(val[0]);
35
+ }
36
+ for (let i = 1; i < length; i++) {
37
+ debug += ', ' + debugString(val[i]);
38
+ }
39
+ debug += ']';
40
+ return debug;
41
+ }
42
+ // Test for built-in
43
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
44
+ let className;
45
+ if (builtInMatches && builtInMatches.length > 1) {
46
+ className = builtInMatches[1];
47
+ } else {
48
+ // Failed to match the standard '[object ClassName]'
49
+ return toString.call(val);
50
+ }
51
+ if (className == 'Object') {
52
+ // we're a user defined class or Object
53
+ // JSON.stringify avoids problems with cycles, and is generally much
54
+ // easier than looping through ownProperties of `val`.
55
+ try {
56
+ return 'Object(' + JSON.stringify(val) + ')';
57
+ } catch (_) {
58
+ return 'Object';
59
+ }
60
+ }
61
+ // errors
62
+ if (val instanceof Error) {
63
+ return `${val.name}: ${val.message}\n${val.stack}`;
64
+ }
65
+ // TODO we could test for more things here, like `Set`s and `Map`s.
66
+ return className;
67
+ }
68
+
69
+ let WASM_VECTOR_LEN = 0;
70
+
71
+ let cachedUint8ArrayMemory0 = null;
72
+
73
+ function getUint8ArrayMemory0() {
74
+ if (
75
+ cachedUint8ArrayMemory0 === null ||
76
+ cachedUint8ArrayMemory0.byteLength === 0
77
+ ) {
78
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
79
+ }
80
+ return cachedUint8ArrayMemory0;
81
+ }
82
+
83
+ const cachedTextEncoder = new TextEncoder();
84
+
85
+ if (!('encodeInto' in cachedTextEncoder)) {
86
+ cachedTextEncoder.encodeInto = function (arg, view) {
87
+ const buf = cachedTextEncoder.encode(arg);
88
+ view.set(buf);
89
+ return {
90
+ read: arg.length,
91
+ written: buf.length,
92
+ };
93
+ };
94
+ }
95
+
96
+ function passStringToWasm0(arg, malloc, realloc) {
97
+ if (realloc === undefined) {
98
+ const buf = cachedTextEncoder.encode(arg);
99
+ const ptr = malloc(buf.length, 1) >>> 0;
100
+ getUint8ArrayMemory0()
101
+ .subarray(ptr, ptr + buf.length)
102
+ .set(buf);
103
+ WASM_VECTOR_LEN = buf.length;
104
+ return ptr;
105
+ }
106
+
107
+ let len = arg.length;
108
+ let ptr = malloc(len, 1) >>> 0;
109
+
110
+ const mem = getUint8ArrayMemory0();
111
+
112
+ let offset = 0;
113
+
114
+ for (; offset < len; offset++) {
115
+ const code = arg.charCodeAt(offset);
116
+ if (code > 0x7f) break;
117
+ mem[ptr + offset] = code;
118
+ }
119
+
120
+ if (offset !== len) {
121
+ if (offset !== 0) {
122
+ arg = arg.slice(offset);
123
+ }
124
+ ptr = realloc(ptr, len, (len = offset + arg.length * 3), 1) >>> 0;
125
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
126
+ const ret = cachedTextEncoder.encodeInto(arg, view);
127
+
128
+ offset += ret.written;
129
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
130
+ }
131
+
132
+ WASM_VECTOR_LEN = offset;
133
+ return ptr;
134
+ }
135
+
136
+ let cachedDataViewMemory0 = null;
137
+
138
+ function getDataViewMemory0() {
139
+ if (
140
+ cachedDataViewMemory0 === null ||
141
+ cachedDataViewMemory0.buffer.detached === true ||
142
+ (cachedDataViewMemory0.buffer.detached === undefined &&
143
+ cachedDataViewMemory0.buffer !== wasm.memory.buffer)
144
+ ) {
145
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
146
+ }
147
+ return cachedDataViewMemory0;
148
+ }
149
+
150
+ let cachedTextDecoder = new TextDecoder('utf-8', {
151
+ ignoreBOM: true,
152
+ fatal: true,
153
+ });
154
+
155
+ cachedTextDecoder.decode();
156
+
157
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
158
+ let numBytesDecoded = 0;
159
+ function decodeText(ptr, len) {
160
+ numBytesDecoded += len;
161
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
162
+ cachedTextDecoder = new TextDecoder('utf-8', {
163
+ ignoreBOM: true,
164
+ fatal: true,
165
+ });
166
+ cachedTextDecoder.decode();
167
+ numBytesDecoded = len;
168
+ }
169
+ return cachedTextDecoder.decode(
170
+ getUint8ArrayMemory0().subarray(ptr, ptr + len)
171
+ );
172
+ }
173
+
174
+ function getStringFromWasm0(ptr, len) {
175
+ ptr = ptr >>> 0;
176
+ return decodeText(ptr, len);
177
+ }
178
+
179
+ export function main() {
180
+ wasm.main();
181
+ }
182
+
183
+ function takeFromExternrefTable0(idx) {
184
+ const value = wasm.__wbindgen_externrefs.get(idx);
185
+ wasm.__externref_table_dealloc(idx);
186
+ return value;
187
+ }
188
+ /**
189
+ * Generates a zero-knowledge proof for a privacy-preserving transaction
190
+ *
191
+ * # Arguments
192
+ * * `input_json` - JSON string containing all circuit inputs
193
+ * * `proving_key_hex` - Hex-encoded proving key (generated during setup)
194
+ *
195
+ * # Returns
196
+ * JSON string containing the proof and public inputs
197
+ *
198
+ * # Example
199
+ * ```javascript
200
+ * const input = {
201
+ * root: "12345...",
202
+ * publicAmount: "1000",
203
+ * // ... other inputs
204
+ * };
205
+ * const proof = prove(JSON.stringify(input), provingKeyHex);
206
+ * const { proofA, proofB, proofC, publicInputs } = JSON.parse(proof);
207
+ * ```
208
+ * @param {string} input_json
209
+ * @param {string} proving_key_hex
210
+ * @returns {string}
211
+ */
212
+ export function prove(input_json, proving_key_hex) {
213
+ let deferred4_0;
214
+ let deferred4_1;
215
+ try {
216
+ const ptr0 = passStringToWasm0(
217
+ input_json,
218
+ wasm.__wbindgen_malloc,
219
+ wasm.__wbindgen_realloc
220
+ );
221
+ const len0 = WASM_VECTOR_LEN;
222
+ const ptr1 = passStringToWasm0(
223
+ proving_key_hex,
224
+ wasm.__wbindgen_malloc,
225
+ wasm.__wbindgen_realloc
226
+ );
227
+ const len1 = WASM_VECTOR_LEN;
228
+ const ret = wasm.prove(ptr0, len0, ptr1, len1);
229
+ var ptr3 = ret[0];
230
+ var len3 = ret[1];
231
+ if (ret[3]) {
232
+ ptr3 = 0;
233
+ len3 = 0;
234
+ throw takeFromExternrefTable0(ret[2]);
235
+ }
236
+ deferred4_0 = ptr3;
237
+ deferred4_1 = len3;
238
+ return getStringFromWasm0(ptr3, len3);
239
+ } finally {
240
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Verifies a proof (useful for testing before submitting to chain)
246
+ *
247
+ * # Arguments
248
+ * * `proof_json` - JSON string containing proof output from `prove()`
249
+ * * `verifying_key_hex` - Hex-encoded verifying key
250
+ *
251
+ * # Returns
252
+ * "true" if proof is valid, "false" otherwise
253
+ * @param {string} proof_json
254
+ * @param {string} verifying_key_hex
255
+ * @returns {boolean}
256
+ */
257
+ export function verify(proof_json, verifying_key_hex) {
258
+ const ptr0 = passStringToWasm0(
259
+ proof_json,
260
+ wasm.__wbindgen_malloc,
261
+ wasm.__wbindgen_realloc
262
+ );
263
+ const len0 = WASM_VECTOR_LEN;
264
+ const ptr1 = passStringToWasm0(
265
+ verifying_key_hex,
266
+ wasm.__wbindgen_malloc,
267
+ wasm.__wbindgen_realloc
268
+ );
269
+ const len1 = WASM_VECTOR_LEN;
270
+ const ret = wasm.verify(ptr0, len0, ptr1, len1);
271
+ if (ret[2]) {
272
+ throw takeFromExternrefTable0(ret[1]);
273
+ }
274
+ return ret[0] !== 0;
275
+ }
276
+
277
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
278
+
279
+ async function __wbg_load(module, imports) {
280
+ if (typeof Response === 'function' && module instanceof Response) {
281
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
282
+ try {
283
+ return await WebAssembly.instantiateStreaming(module, imports);
284
+ } catch (e) {
285
+ const validResponse =
286
+ module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
287
+
288
+ if (
289
+ validResponse &&
290
+ module.headers.get('Content-Type') !== 'application/wasm'
291
+ ) {
292
+ console.warn(
293
+ '`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',
294
+ e
295
+ );
296
+ } else {
297
+ throw e;
298
+ }
299
+ }
300
+ }
301
+
302
+ const bytes = await module.arrayBuffer();
303
+ return await WebAssembly.instantiate(bytes, imports);
304
+ } else {
305
+ const instance = await WebAssembly.instantiate(module, imports);
306
+
307
+ if (instance instanceof WebAssembly.Instance) {
308
+ return { instance, module };
309
+ } else {
310
+ return instance;
311
+ }
312
+ }
313
+ }
314
+
315
+ function __wbg_get_imports() {
316
+ const imports = {};
317
+ imports.wbg = {};
318
+ imports.wbg.__wbg___wbindgen_debug_string_df47ffb5e35e6763 = function (
319
+ arg0,
320
+ arg1
321
+ ) {
322
+ const ret = debugString(arg1);
323
+ const ptr1 = passStringToWasm0(
324
+ ret,
325
+ wasm.__wbindgen_malloc,
326
+ wasm.__wbindgen_realloc
327
+ );
328
+ const len1 = WASM_VECTOR_LEN;
329
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
330
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
331
+ };
332
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function (arg0, arg1) {
333
+ let deferred0_0;
334
+ let deferred0_1;
335
+ try {
336
+ deferred0_0 = arg0;
337
+ deferred0_1 = arg1;
338
+ console.error(getStringFromWasm0(arg0, arg1));
339
+ } finally {
340
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
341
+ }
342
+ };
343
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function () {
344
+ const ret = new Error();
345
+ return ret;
346
+ };
347
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function (arg0, arg1) {
348
+ const ret = arg1.stack;
349
+ const ptr1 = passStringToWasm0(
350
+ ret,
351
+ wasm.__wbindgen_malloc,
352
+ wasm.__wbindgen_realloc
353
+ );
354
+ const len1 = WASM_VECTOR_LEN;
355
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
356
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
357
+ };
358
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function (arg0, arg1) {
359
+ // Cast intrinsic for `Ref(String) -> Externref`.
360
+ const ret = getStringFromWasm0(arg0, arg1);
361
+ return ret;
362
+ };
363
+ imports.wbg.__wbindgen_init_externref_table = function () {
364
+ const table = wasm.__wbindgen_externrefs;
365
+ const offset = table.grow(4);
366
+ table.set(0, undefined);
367
+ table.set(offset + 0, undefined);
368
+ table.set(offset + 1, null);
369
+ table.set(offset + 2, true);
370
+ table.set(offset + 3, false);
371
+ };
372
+
373
+ return imports;
374
+ }
375
+
376
+ function __wbg_finalize_init(instance, module) {
377
+ wasm = instance.exports;
378
+ __wbg_init.__wbindgen_wasm_module = module;
379
+ cachedDataViewMemory0 = null;
380
+ cachedUint8ArrayMemory0 = null;
381
+
382
+ wasm.__wbindgen_start();
383
+ return wasm;
384
+ }
385
+
386
+ function initSync(module) {
387
+ if (wasm !== undefined) return wasm;
388
+
389
+ if (typeof module !== 'undefined') {
390
+ if (Object.getPrototypeOf(module) === Object.prototype) {
391
+ ({ module } = module);
392
+ } else {
393
+ console.warn(
394
+ 'using deprecated parameters for `initSync()`; pass a single object instead'
395
+ );
396
+ }
397
+ }
398
+
399
+ const imports = __wbg_get_imports();
400
+
401
+ if (!(module instanceof WebAssembly.Module)) {
402
+ module = new WebAssembly.Module(module);
403
+ }
404
+
405
+ const instance = new WebAssembly.Instance(module, imports);
406
+
407
+ return __wbg_finalize_init(instance, module);
408
+ }
409
+
410
+ async function __wbg_init(module_or_path) {
411
+ if (wasm !== undefined) return wasm;
412
+
413
+ if (typeof module_or_path !== 'undefined') {
414
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
415
+ ({ module_or_path } = module_or_path);
416
+ } else {
417
+ console.warn(
418
+ 'using deprecated parameters for the initialization function; pass a single object instead'
419
+ );
420
+ }
421
+ }
422
+
423
+ if (typeof module_or_path === 'undefined') {
424
+ module_or_path = new URL('vortex_bg.wasm', import.meta.url);
425
+ }
426
+ const imports = __wbg_get_imports();
427
+
428
+ if (
429
+ typeof module_or_path === 'string' ||
430
+ (typeof Request === 'function' && module_or_path instanceof Request) ||
431
+ (typeof URL === 'function' && module_or_path instanceof URL)
432
+ ) {
433
+ module_or_path = fetch(module_or_path);
434
+ }
435
+
436
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
437
+
438
+ return __wbg_finalize_init(instance, module);
439
+ }
440
+
441
+ export { initSync };
442
+ export default __wbg_init;
Binary file
@@ -0,0 +1,12 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const prove: (a: number, b: number, c: number, d: number) => [number, number, number, number];
5
+ export const verify: (a: number, b: number, c: number, d: number) => [number, number, number];
6
+ export const main: () => void;
7
+ export const __wbindgen_malloc: (a: number, b: number) => number;
8
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
9
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
10
+ export const __wbindgen_externrefs: WebAssembly.Table;
11
+ export const __externref_table_dealloc: (a: number) => void;
12
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,46 @@
1
+ import { PaginatedEvents } from '@mysten/sui/client';
2
+ import { parseNewCommitmentEvent } from './events';
3
+ import { UtxoPayload } from '../entities/keypair';
4
+ import { VortexKeypair } from '../entities/keypair';
5
+ import { Utxo } from '../entities/utxo';
6
+
7
+ import { Vortex } from '../vortex';
8
+
9
+ interface GetUnspentUtxosArgs {
10
+ commitmentEvents: PaginatedEvents;
11
+ vortexKeypair: VortexKeypair;
12
+ vortex: Vortex;
13
+ }
14
+
15
+ export const getUnspentUtxos = async ({
16
+ commitmentEvents,
17
+ vortexKeypair,
18
+ vortex,
19
+ }: GetUnspentUtxosArgs) => {
20
+ const commitments = parseNewCommitmentEvent(commitmentEvents);
21
+
22
+ const allUtxos = [] as UtxoPayload[];
23
+
24
+ commitments.forEach((commitment) => {
25
+ try {
26
+ const utxo = vortexKeypair.decryptUtxo(commitment.encryptedOutput);
27
+ allUtxos.push(utxo);
28
+ } catch {
29
+ // Do nothing
30
+ }
31
+ });
32
+
33
+ const utxos = allUtxos.map(
34
+ (utxo) => new Utxo({ ...utxo, keypair: vortexKeypair })
35
+ );
36
+
37
+ const nullifiers = utxos.map((utxo) => utxo.nullifier());
38
+
39
+ const isNullifierSpentArray = await vortex.areNullifiersSpent(nullifiers);
40
+
41
+ const unspentUtxos = utxos.filter(
42
+ (_, index) => !isNullifierSpentArray[index]
43
+ );
44
+
45
+ return unspentUtxos;
46
+ };
@@ -0,0 +1,18 @@
1
+ const isBrowser =
2
+ typeof window !== 'undefined' &&
3
+ typeof window.document !== 'undefined' &&
4
+ typeof navigator !== 'undefined';
5
+
6
+ const isNode =
7
+ typeof process !== 'undefined' &&
8
+ process.versions != null &&
9
+ process.versions.node != null &&
10
+ typeof window === 'undefined';
11
+
12
+ export const getEnv = () => {
13
+ if (isBrowser) return 'web';
14
+
15
+ if (isNode) return 'node';
16
+
17
+ throw new Error('Unsupported environment');
18
+ };
@@ -0,0 +1,16 @@
1
+ import { PaginatedEvents } from '@mysten/sui/client';
2
+ import { toHex } from '@mysten/sui/utils';
3
+ import { pathOr } from 'ramda';
4
+
5
+ export const parseNewCommitmentEvent = (events: PaginatedEvents) =>
6
+ events.data.map((event) => {
7
+ return {
8
+ commitment: BigInt(pathOr('0', ['commitment'], event.parsedJson)),
9
+ index: BigInt(pathOr('0', ['index'], event.parsedJson)),
10
+ encryptedOutput: toHex(
11
+ Uint8Array.from(
12
+ pathOr([], ['encrypted_output'], event.parsedJson) as number[]
13
+ )
14
+ ),
15
+ };
16
+ });
@@ -0,0 +1,43 @@
1
+ import { bcs } from '@mysten/sui/bcs';
2
+ import { blake2b } from '@noble/hashes/blake2.js';
3
+ import { normalizeSuiAddress } from '@mysten/sui/utils';
4
+
5
+ import { ExtDataHashArgs } from '../vortex.types';
6
+
7
+ export function computeExtDataHash({
8
+ recipient,
9
+ value,
10
+ valueSign,
11
+ relayer,
12
+ relayerFee,
13
+ encryptedOutput0,
14
+ encryptedOutput1,
15
+ }: ExtDataHashArgs): Uint8Array {
16
+ // Serialize each field using BCS encoding (matching Move's to_bytes())
17
+
18
+ const extDataHashBytesArray = [
19
+ bcs.Address.serialize(normalizeSuiAddress(recipient)).toBytes(),
20
+ bcs.u64().serialize(value).toBytes(),
21
+ bcs.bool().serialize(valueSign).toBytes(),
22
+ bcs.Address.serialize(normalizeSuiAddress(relayer)).toBytes(),
23
+ bcs.u64().serialize(relayerFee).toBytes(),
24
+ bcs.vector(bcs.u8()).serialize(encryptedOutput0).toBytes(),
25
+ bcs.vector(bcs.u8()).serialize(encryptedOutput1).toBytes(),
26
+ ];
27
+
28
+ const totalLength = extDataHashBytesArray.reduce(
29
+ (acc, curr) => acc + curr.length,
30
+ 0
31
+ );
32
+
33
+ const extDataHashBytes = new Uint8Array(totalLength);
34
+ let offset = 0;
35
+
36
+ for (const byte of extDataHashBytesArray) {
37
+ extDataHashBytes.set(byte, offset);
38
+ offset += byte.length;
39
+ }
40
+
41
+ // Concatenate all bytes in the same order as Move
42
+ return blake2b(extDataHashBytes, { dkLen: 32 });
43
+ }