@rolly-dev/wasm-signer 0.5.1 → 0.6.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.
@@ -1,5 +1,30 @@
1
1
  /* @ts-self-types="./rolly_wasm_signer.d.ts" */
2
2
 
3
+ /**
4
+ * Split a u64 amount into (lo, hi) u32 pair matching the circuit representation.
5
+ *
6
+ * Returns `[amount_lo, amount_hi]` as a `Uint32Array` of length 2.
7
+ *
8
+ * ```js
9
+ * const [lo, hi] = amount_split(123456789n);
10
+ * ```
11
+ * @param {bigint} amount
12
+ * @returns {Uint32Array}
13
+ */
14
+ export function amount_split(amount) {
15
+ try {
16
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
17
+ wasm.amount_split(retptr, amount);
18
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
19
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
20
+ var v1 = getArrayU32FromWasm0(r0, r1).slice();
21
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
22
+ return v1;
23
+ } finally {
24
+ wasm.__wbindgen_add_to_stack_pointer(16);
25
+ }
26
+ }
27
+
3
28
  /**
4
29
  * Full Poseidon2 hash of an 8-element server seed.
5
30
  *
@@ -15,19 +40,48 @@
15
40
  export function compute_server_seed_hash(server_seed) {
16
41
  try {
17
42
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
18
- const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export2);
43
+ const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export);
19
44
  const len0 = WASM_VECTOR_LEN;
20
45
  wasm.compute_server_seed_hash(retptr, ptr0, len0);
21
46
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
22
47
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
23
48
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
24
- wasm.__wbindgen_export3(r0, r1 * 8, 8);
49
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
25
50
  return v2;
26
51
  } finally {
27
52
  wasm.__wbindgen_add_to_stack_pointer(16);
28
53
  }
29
54
  }
30
55
 
56
+ /**
57
+ * Compute the transaction message hash (for debugging / verification).
58
+ *
59
+ * Returns `BigUint64Array` of length 4 — the same hash the circuit computes.
60
+ *
61
+ * ```js
62
+ * const hash = compute_tx_msg_hash(5, userId, 0, amountLo, amountHi);
63
+ * ```
64
+ * @param {number} tx_type
65
+ * @param {number} user_id
66
+ * @param {number} currency_id
67
+ * @param {number} amount_lo
68
+ * @param {number} amount_hi
69
+ * @returns {BigUint64Array}
70
+ */
71
+ export function compute_tx_msg_hash(tx_type, user_id, currency_id, amount_lo, amount_hi) {
72
+ try {
73
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
74
+ wasm.compute_tx_msg_hash(retptr, tx_type, user_id, currency_id, amount_lo, amount_hi);
75
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
76
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
77
+ var v1 = getArrayU64FromWasm0(r0, r1).slice();
78
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
79
+ return v1;
80
+ } finally {
81
+ wasm.__wbindgen_add_to_stack_pointer(16);
82
+ }
83
+ }
84
+
31
85
  /**
32
86
  * Create a `bet_auth` MAC that proves the user authorized this specific bet.
33
87
  *
@@ -61,13 +115,13 @@ export function compute_server_seed_hash(server_seed) {
61
115
  export function create_bet_auth(session_key, bet_amount, nonce) {
62
116
  try {
63
117
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
64
- const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export2);
118
+ const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export);
65
119
  const len0 = WASM_VECTOR_LEN;
66
120
  wasm.create_bet_auth(retptr, ptr0, len0, bet_amount, nonce);
67
121
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
68
122
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
69
123
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
70
- wasm.__wbindgen_export3(r0, r1 * 8, 8);
124
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
71
125
  return v2;
72
126
  } finally {
73
127
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -95,13 +149,13 @@ export function create_bet_auth(session_key, bet_amount, nonce) {
95
149
  export function derive_session_key(sig_bytes) {
96
150
  try {
97
151
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
98
- const ptr0 = passArray8ToWasm0(sig_bytes, wasm.__wbindgen_export2);
152
+ const ptr0 = passArray8ToWasm0(sig_bytes, wasm.__wbindgen_export);
99
153
  const len0 = WASM_VECTOR_LEN;
100
154
  wasm.derive_session_key(retptr, ptr0, len0);
101
155
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
102
156
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
103
157
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
104
- wasm.__wbindgen_export3(r0, r1 * 8, 8);
158
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
105
159
  return v2;
106
160
  } finally {
107
161
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -133,7 +187,7 @@ export function generate_user_seed() {
133
187
  return getStringFromWasm0(r0, r1);
134
188
  } finally {
135
189
  wasm.__wbindgen_add_to_stack_pointer(16);
136
- wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
190
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
137
191
  }
138
192
  }
139
193
 
@@ -154,7 +208,7 @@ export function goldilocks_fields_to_hex(fields) {
154
208
  let deferred2_1;
155
209
  try {
156
210
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
157
- const ptr0 = passArray64ToWasm0(fields, wasm.__wbindgen_export2);
211
+ const ptr0 = passArray64ToWasm0(fields, wasm.__wbindgen_export);
158
212
  const len0 = WASM_VECTOR_LEN;
159
213
  wasm.goldilocks_fields_to_hex(retptr, ptr0, len0);
160
214
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
@@ -164,7 +218,7 @@ export function goldilocks_fields_to_hex(fields) {
164
218
  return getStringFromWasm0(r0, r1);
165
219
  } finally {
166
220
  wasm.__wbindgen_add_to_stack_pointer(16);
167
- wasm.__wbindgen_export3(deferred2_0, deferred2_1, 1);
221
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
168
222
  }
169
223
  }
170
224
 
@@ -209,13 +263,13 @@ export function goldilocks_reduce(value) {
209
263
  export function poseidon2_hash(input) {
210
264
  try {
211
265
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
212
- const ptr0 = passArray64ToWasm0(input, wasm.__wbindgen_export2);
266
+ const ptr0 = passArray64ToWasm0(input, wasm.__wbindgen_export);
213
267
  const len0 = WASM_VECTOR_LEN;
214
268
  wasm.poseidon2_hash(retptr, ptr0, len0);
215
269
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
216
270
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
217
271
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
218
- wasm.__wbindgen_export3(r0, r1 * 8, 8);
272
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
219
273
  return v2;
220
274
  } finally {
221
275
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -236,21 +290,251 @@ export function poseidon2_hash(input) {
236
290
  export function poseidon2_two_to_one(left, right) {
237
291
  try {
238
292
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
239
- const ptr0 = passArray64ToWasm0(left, wasm.__wbindgen_export2);
293
+ const ptr0 = passArray64ToWasm0(left, wasm.__wbindgen_export);
240
294
  const len0 = WASM_VECTOR_LEN;
241
- const ptr1 = passArray64ToWasm0(right, wasm.__wbindgen_export2);
295
+ const ptr1 = passArray64ToWasm0(right, wasm.__wbindgen_export);
242
296
  const len1 = WASM_VECTOR_LEN;
243
297
  wasm.poseidon2_two_to_one(retptr, ptr0, len0, ptr1, len1);
244
298
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
245
299
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
246
300
  var v3 = getArrayU64FromWasm0(r0, r1).slice();
247
- wasm.__wbindgen_export3(r0, r1 * 8, 8);
301
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
248
302
  return v3;
249
303
  } finally {
250
304
  wasm.__wbindgen_add_to_stack_pointer(16);
251
305
  }
252
306
  }
253
307
 
308
+ /**
309
+ * Derive a Schnorr secret key from entropy bytes (e.g. MetaMask signature).
310
+ *
311
+ * Takes at least 32 bytes, uses `Scalar::decode_reduce` to map them into
312
+ * the ECgFp5 scalar field. Returns hex-encoded secret key (80 chars = 40 bytes).
313
+ *
314
+ * ```js
315
+ * const skHex = schnorr_keygen(sigBytes.slice(0, 32));
316
+ * ```
317
+ * @param {Uint8Array} entropy
318
+ * @returns {string}
319
+ */
320
+ export function schnorr_keygen(entropy) {
321
+ let deferred2_0;
322
+ let deferred2_1;
323
+ try {
324
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
325
+ const ptr0 = passArray8ToWasm0(entropy, wasm.__wbindgen_export);
326
+ const len0 = WASM_VECTOR_LEN;
327
+ wasm.schnorr_keygen(retptr, ptr0, len0);
328
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
329
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
330
+ deferred2_0 = r0;
331
+ deferred2_1 = r1;
332
+ return getStringFromWasm0(r0, r1);
333
+ } finally {
334
+ wasm.__wbindgen_add_to_stack_pointer(16);
335
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
336
+ }
337
+ }
338
+
339
+ /**
340
+ * Get the w-encoding of a public key as 5 Goldilocks field elements (for circuit witness).
341
+ *
342
+ * Returns `BigUint64Array` of length 5.
343
+ *
344
+ * ```js
345
+ * const encode = schnorr_pk_encode(pkHex);
346
+ * // encode.length === 5
347
+ * ```
348
+ * @param {string} pk_hex
349
+ * @returns {BigUint64Array}
350
+ */
351
+ export function schnorr_pk_encode(pk_hex) {
352
+ try {
353
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
354
+ const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
355
+ const len0 = WASM_VECTOR_LEN;
356
+ wasm.schnorr_pk_encode(retptr, ptr0, len0);
357
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
358
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
359
+ var v2 = getArrayU64FromWasm0(r0, r1).slice();
360
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
361
+ return v2;
362
+ } finally {
363
+ wasm.__wbindgen_add_to_stack_pointer(16);
364
+ }
365
+ }
366
+
367
+ /**
368
+ * Compute pk_hash = Poseidon2(w_encoding[5]) from a hex-encoded public key.
369
+ *
370
+ * The w-encoding is the 40-byte (80 hex) representation returned by `schnorr_pubkey`.
371
+ * pk_hash is stored in the Merkle tree to bind the Schnorr key to an account.
372
+ *
373
+ * Returns `BigUint64Array` of length 4.
374
+ *
375
+ * ```js
376
+ * const pkHash = schnorr_pk_hash(pkHex);
377
+ * ```
378
+ * @param {string} pk_hex
379
+ * @returns {BigUint64Array}
380
+ */
381
+ export function schnorr_pk_hash(pk_hex) {
382
+ try {
383
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
384
+ const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
385
+ const len0 = WASM_VECTOR_LEN;
386
+ wasm.schnorr_pk_hash(retptr, ptr0, len0);
387
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
388
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
389
+ var v2 = getArrayU64FromWasm0(r0, r1).slice();
390
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
391
+ return v2;
392
+ } finally {
393
+ wasm.__wbindgen_add_to_stack_pointer(16);
394
+ }
395
+ }
396
+
397
+ /**
398
+ * Compute pk_hash as a hex string (for convenience).
399
+ *
400
+ * ```js
401
+ * const pkHashHex = schnorr_pk_hash_hex(pkHex);
402
+ * ```
403
+ * @param {string} pk_hex
404
+ * @returns {string}
405
+ */
406
+ export function schnorr_pk_hash_hex(pk_hex) {
407
+ let deferred2_0;
408
+ let deferred2_1;
409
+ try {
410
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
411
+ const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
412
+ const len0 = WASM_VECTOR_LEN;
413
+ wasm.schnorr_pk_hash_hex(retptr, ptr0, len0);
414
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
415
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
416
+ deferred2_0 = r0;
417
+ deferred2_1 = r1;
418
+ return getStringFromWasm0(r0, r1);
419
+ } finally {
420
+ wasm.__wbindgen_add_to_stack_pointer(16);
421
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
422
+ }
423
+ }
424
+
425
+ /**
426
+ * Compute the Schnorr public key from a hex-encoded secret key.
427
+ *
428
+ * Returns hex-encoded w-encoding of the ECgFp5 point (80 chars = 40 bytes).
429
+ *
430
+ * ```js
431
+ * const pkHex = schnorr_pubkey(skHex);
432
+ * ```
433
+ * @param {string} sk_hex
434
+ * @returns {string}
435
+ */
436
+ export function schnorr_pubkey(sk_hex) {
437
+ let deferred2_0;
438
+ let deferred2_1;
439
+ try {
440
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
441
+ const ptr0 = passStringToWasm0(sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
442
+ const len0 = WASM_VECTOR_LEN;
443
+ wasm.schnorr_pubkey(retptr, ptr0, len0);
444
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
445
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
446
+ deferred2_0 = r0;
447
+ deferred2_1 = r1;
448
+ return getStringFromWasm0(r0, r1);
449
+ } finally {
450
+ wasm.__wbindgen_add_to_stack_pointer(16);
451
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
452
+ }
453
+ }
454
+
455
+ /**
456
+ * Sign a ChangePubKey (tx_type=9) transaction.
457
+ *
458
+ * msg_hash = Poseidon2(9, user_id, new_pk_hash[0..4])
459
+ *
460
+ * The old key signs this message to authorize key rotation.
461
+ *
462
+ * Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
463
+ *
464
+ * ```js
465
+ * const sig = schnorr_sign_cpk(oldSkHex, userId, newPkHashArray);
466
+ * ```
467
+ * @param {string} old_sk_hex
468
+ * @param {number} user_id
469
+ * @param {BigUint64Array} new_pk_hash
470
+ * @returns {any}
471
+ */
472
+ export function schnorr_sign_cpk(old_sk_hex, user_id, new_pk_hash) {
473
+ const ptr0 = passStringToWasm0(old_sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
474
+ const len0 = WASM_VECTOR_LEN;
475
+ const ptr1 = passArray64ToWasm0(new_pk_hash, wasm.__wbindgen_export);
476
+ const len1 = WASM_VECTOR_LEN;
477
+ const ret = wasm.schnorr_sign_cpk(ptr0, len0, user_id, ptr1, len1);
478
+ return takeObject(ret);
479
+ }
480
+
481
+ /**
482
+ * Sign a transaction with Schnorr (ECgFp5).
483
+ *
484
+ * msg_hash = Poseidon2(tx_type, user_id, currency_id, amount_lo, amount_hi)
485
+ *
486
+ * Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
487
+ *
488
+ * ```js
489
+ * const sig = schnorr_sign_tx(skHex, 5, userId, 0, amountBigInt);
490
+ * // sig.pubkey, sig.sig_r, sig.sig_s — all hex strings (80 chars each)
491
+ * ```
492
+ * @param {string} sk_hex
493
+ * @param {number} tx_type
494
+ * @param {number} user_id
495
+ * @param {number} currency_id
496
+ * @param {number} amount_lo
497
+ * @param {number} amount_hi
498
+ * @returns {any}
499
+ */
500
+ export function schnorr_sign_tx(sk_hex, tx_type, user_id, currency_id, amount_lo, amount_hi) {
501
+ const ptr0 = passStringToWasm0(sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
502
+ const len0 = WASM_VECTOR_LEN;
503
+ const ret = wasm.schnorr_sign_tx(ptr0, len0, tx_type, user_id, currency_id, amount_lo, amount_hi);
504
+ return takeObject(ret);
505
+ }
506
+
507
+ /**
508
+ * Verify a Schnorr signature for a transaction on the backend.
509
+ *
510
+ * Checks: s·G == R + H(R‖pk‖msg)·pk
511
+ *
512
+ * Returns `true` if signature is valid, `false` otherwise.
513
+ *
514
+ * ```js
515
+ * const ok = schnorr_verify_tx(pubkeyHex, sigRHex, sigSHex, 5, userId, 0, amountLo, amountHi);
516
+ * ```
517
+ * @param {string} pk_hex
518
+ * @param {string} sig_r_hex
519
+ * @param {string} sig_s_hex
520
+ * @param {number} tx_type
521
+ * @param {number} user_id
522
+ * @param {number} currency_id
523
+ * @param {number} amount_lo
524
+ * @param {number} amount_hi
525
+ * @returns {boolean}
526
+ */
527
+ export function schnorr_verify_tx(pk_hex, sig_r_hex, sig_s_hex, tx_type, user_id, currency_id, amount_lo, amount_hi) {
528
+ const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
529
+ const len0 = WASM_VECTOR_LEN;
530
+ const ptr1 = passStringToWasm0(sig_r_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
531
+ const len1 = WASM_VECTOR_LEN;
532
+ const ptr2 = passStringToWasm0(sig_s_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
533
+ const len2 = WASM_VECTOR_LEN;
534
+ const ret = wasm.schnorr_verify_tx(ptr0, len0, ptr1, len1, ptr2, len2, tx_type, user_id, currency_id, amount_lo, amount_hi);
535
+ return ret !== 0;
536
+ }
537
+
254
538
  /**
255
539
  * Truncated seed hash — first 2 elements of `Poseidon2(server_seed)`.
256
540
  *
@@ -265,13 +549,13 @@ export function poseidon2_two_to_one(left, right) {
265
549
  export function seed_hash_truncated(server_seed) {
266
550
  try {
267
551
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
268
- const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export2);
552
+ const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export);
269
553
  const len0 = WASM_VECTOR_LEN;
270
554
  wasm.seed_hash_truncated(retptr, ptr0, len0);
271
555
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
272
556
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
273
557
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
274
- wasm.__wbindgen_export3(r0, r1 * 8, 8);
558
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
275
559
  return v2;
276
560
  } finally {
277
561
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -291,13 +575,13 @@ export function seed_hash_truncated(server_seed) {
291
575
  export function session_public_key(session_key) {
292
576
  try {
293
577
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
294
- const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export2);
578
+ const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export);
295
579
  const len0 = WASM_VECTOR_LEN;
296
580
  wasm.session_public_key(retptr, ptr0, len0);
297
581
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
298
582
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
299
583
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
300
- wasm.__wbindgen_export3(r0, r1 * 8, 8);
584
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
301
585
  return v2;
302
586
  } finally {
303
587
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -323,13 +607,13 @@ export function session_public_key(session_key) {
323
607
  export function string_to_user_seed(input) {
324
608
  try {
325
609
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
326
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export2, wasm.__wbindgen_export4);
610
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);
327
611
  const len0 = WASM_VECTOR_LEN;
328
612
  wasm.string_to_user_seed(retptr, ptr0, len0);
329
613
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
330
614
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
331
615
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
332
- wasm.__wbindgen_export3(r0, r1 * 8, 8);
616
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
333
617
  return v2;
334
618
  } finally {
335
619
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -354,7 +638,7 @@ export function string_to_user_seed_hex(input) {
354
638
  let deferred2_1;
355
639
  try {
356
640
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
357
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export2, wasm.__wbindgen_export4);
641
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);
358
642
  const len0 = WASM_VECTOR_LEN;
359
643
  wasm.string_to_user_seed_hex(retptr, ptr0, len0);
360
644
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
@@ -364,13 +648,20 @@ export function string_to_user_seed_hex(input) {
364
648
  return getStringFromWasm0(r0, r1);
365
649
  } finally {
366
650
  wasm.__wbindgen_add_to_stack_pointer(16);
367
- wasm.__wbindgen_export3(deferred2_0, deferred2_1, 1);
651
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
368
652
  }
369
653
  }
370
654
 
371
655
  function __wbg_get_imports() {
372
656
  const import0 = {
373
657
  __proto__: null,
658
+ __wbg___wbindgen_debug_string_0bc8482c6e3508ae: function(arg0, arg1) {
659
+ const ret = debugString(getObject(arg1));
660
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
661
+ const len1 = WASM_VECTOR_LEN;
662
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
663
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
664
+ },
374
665
  __wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
375
666
  const ret = typeof(getObject(arg0)) === 'function';
376
667
  return ret;
@@ -414,6 +705,10 @@ function __wbg_get_imports() {
414
705
  const ret = getObject(arg0).msCrypto;
415
706
  return addHeapObject(ret);
416
707
  },
708
+ __wbg_new_361308b2356cecd0: function() {
709
+ const ret = new Object();
710
+ return addHeapObject(ret);
711
+ },
417
712
  __wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
418
713
  const ret = new Function(getStringFromWasm0(arg0, arg1));
419
714
  return addHeapObject(ret);
@@ -440,6 +735,10 @@ function __wbg_get_imports() {
440
735
  const ret = module.require;
441
736
  return addHeapObject(ret);
442
737
  }, arguments); },
738
+ __wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
739
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
740
+ return ret;
741
+ }, arguments); },
443
742
  __wbg_static_accessor_GLOBAL_12837167ad935116: function() {
444
743
  const ret = typeof global === 'undefined' ? null : global;
445
744
  return isLikeNone(ret) ? 0 : addHeapObject(ret);
@@ -497,12 +796,82 @@ function addHeapObject(obj) {
497
796
  return idx;
498
797
  }
499
798
 
799
+ function debugString(val) {
800
+ // primitive types
801
+ const type = typeof val;
802
+ if (type == 'number' || type == 'boolean' || val == null) {
803
+ return `${val}`;
804
+ }
805
+ if (type == 'string') {
806
+ return `"${val}"`;
807
+ }
808
+ if (type == 'symbol') {
809
+ const description = val.description;
810
+ if (description == null) {
811
+ return 'Symbol';
812
+ } else {
813
+ return `Symbol(${description})`;
814
+ }
815
+ }
816
+ if (type == 'function') {
817
+ const name = val.name;
818
+ if (typeof name == 'string' && name.length > 0) {
819
+ return `Function(${name})`;
820
+ } else {
821
+ return 'Function';
822
+ }
823
+ }
824
+ // objects
825
+ if (Array.isArray(val)) {
826
+ const length = val.length;
827
+ let debug = '[';
828
+ if (length > 0) {
829
+ debug += debugString(val[0]);
830
+ }
831
+ for(let i = 1; i < length; i++) {
832
+ debug += ', ' + debugString(val[i]);
833
+ }
834
+ debug += ']';
835
+ return debug;
836
+ }
837
+ // Test for built-in
838
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
839
+ let className;
840
+ if (builtInMatches && builtInMatches.length > 1) {
841
+ className = builtInMatches[1];
842
+ } else {
843
+ // Failed to match the standard '[object ClassName]'
844
+ return toString.call(val);
845
+ }
846
+ if (className == 'Object') {
847
+ // we're a user defined class or Object
848
+ // JSON.stringify avoids problems with cycles, and is generally much
849
+ // easier than looping through ownProperties of `val`.
850
+ try {
851
+ return 'Object(' + JSON.stringify(val) + ')';
852
+ } catch (_) {
853
+ return 'Object';
854
+ }
855
+ }
856
+ // errors
857
+ if (val instanceof Error) {
858
+ return `${val.name}: ${val.message}\n${val.stack}`;
859
+ }
860
+ // TODO we could test for more things here, like `Set`s and `Map`s.
861
+ return className;
862
+ }
863
+
500
864
  function dropObject(idx) {
501
865
  if (idx < 132) return;
502
866
  heap[idx] = heap_next;
503
867
  heap_next = idx;
504
868
  }
505
869
 
870
+ function getArrayU32FromWasm0(ptr, len) {
871
+ ptr = ptr >>> 0;
872
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
873
+ }
874
+
506
875
  function getArrayU64FromWasm0(ptr, len) {
507
876
  ptr = ptr >>> 0;
508
877
  return getBigUint64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
@@ -534,6 +903,14 @@ function getStringFromWasm0(ptr, len) {
534
903
  return decodeText(ptr, len);
535
904
  }
536
905
 
906
+ let cachedUint32ArrayMemory0 = null;
907
+ function getUint32ArrayMemory0() {
908
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
909
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
910
+ }
911
+ return cachedUint32ArrayMemory0;
912
+ }
913
+
537
914
  let cachedUint8ArrayMemory0 = null;
538
915
  function getUint8ArrayMemory0() {
539
916
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
@@ -548,7 +925,7 @@ function handleError(f, args) {
548
925
  try {
549
926
  return f.apply(this, args);
550
927
  } catch (e) {
551
- wasm.__wbindgen_export(addHeapObject(e));
928
+ wasm.__wbindgen_export3(addHeapObject(e));
552
929
  }
553
930
  }
554
931
 
@@ -653,6 +1030,7 @@ function __wbg_finalize_init(instance, module) {
653
1030
  wasmModule = module;
654
1031
  cachedBigUint64ArrayMemory0 = null;
655
1032
  cachedDataViewMemory0 = null;
1033
+ cachedUint32ArrayMemory0 = null;
656
1034
  cachedUint8ArrayMemory0 = null;
657
1035
  return wasm;
658
1036
  }
Binary file
@@ -1,7 +1,9 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
+ export const amount_split: (a: number, b: bigint) => void;
4
5
  export const compute_server_seed_hash: (a: number, b: number, c: number) => void;
6
+ export const compute_tx_msg_hash: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
5
7
  export const create_bet_auth: (a: number, b: number, c: number, d: bigint, e: bigint) => void;
6
8
  export const derive_session_key: (a: number, b: number, c: number) => void;
7
9
  export const generate_user_seed: (a: number) => void;
@@ -9,13 +11,21 @@ export const goldilocks_fields_to_hex: (a: number, b: number, c: number) => void
9
11
  export const goldilocks_reduce: (a: bigint) => bigint;
10
12
  export const poseidon2_hash: (a: number, b: number, c: number) => void;
11
13
  export const poseidon2_two_to_one: (a: number, b: number, c: number, d: number, e: number) => void;
14
+ export const schnorr_keygen: (a: number, b: number, c: number) => void;
15
+ export const schnorr_pk_encode: (a: number, b: number, c: number) => void;
16
+ export const schnorr_pk_hash: (a: number, b: number, c: number) => void;
17
+ export const schnorr_pk_hash_hex: (a: number, b: number, c: number) => void;
18
+ export const schnorr_pubkey: (a: number, b: number, c: number) => void;
19
+ export const schnorr_sign_cpk: (a: number, b: number, c: number, d: number, e: number) => number;
20
+ export const schnorr_sign_tx: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
21
+ export const schnorr_verify_tx: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => number;
12
22
  export const seed_hash_truncated: (a: number, b: number, c: number) => void;
13
23
  export const session_public_key: (a: number, b: number, c: number) => void;
14
24
  export const string_to_user_seed: (a: number, b: number, c: number) => void;
15
25
  export const string_to_user_seed_hex: (a: number, b: number, c: number) => void;
16
26
  export const goldilocks_modulus: () => bigint;
17
- export const __wbindgen_export: (a: number) => void;
27
+ export const __wbindgen_export: (a: number, b: number) => number;
28
+ export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
29
+ export const __wbindgen_export3: (a: number) => void;
18
30
  export const __wbindgen_add_to_stack_pointer: (a: number) => number;
19
- export const __wbindgen_export2: (a: number, b: number) => number;
20
- export const __wbindgen_export3: (a: number, b: number, c: number) => void;
21
- export const __wbindgen_export4: (a: number, b: number, c: number, d: number) => number;
31
+ export const __wbindgen_export4: (a: number, b: number, c: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolly-dev/wasm-signer",
3
- "version": "0.5.1",
3
+ "version": "0.6.1",
4
4
  "description": "Poseidon2 hashing & bet signing for Rolly ZK-Rollup (WASM, Goldilocks field)",
5
5
  "type": "module",
6
6
  "exports": {