@rolly-dev/wasm-signer 0.11.0 → 0.13.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.
@@ -18,7 +18,7 @@ export function amount_split(amount) {
18
18
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
19
19
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
20
20
  var v1 = getArrayU32FromWasm0(r0, r1).slice();
21
- wasm.__wbindgen_export4(r0, r1 * 4, 4);
21
+ wasm.__wbindgen_export2(r0, r1 * 4, 4);
22
22
  return v1;
23
23
  } finally {
24
24
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -34,13 +34,13 @@ export function amount_split(amount) {
34
34
  export function compute_address_hash(address_hex) {
35
35
  try {
36
36
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
37
- const ptr0 = passStringToWasm0(address_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
37
+ const ptr0 = passStringToWasm0(address_hex, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
38
38
  const len0 = WASM_VECTOR_LEN;
39
39
  wasm.compute_address_hash(retptr, ptr0, len0);
40
40
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
41
41
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
42
42
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
43
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
43
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
44
44
  return v2;
45
45
  } finally {
46
46
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -62,89 +62,13 @@ export function compute_address_hash(address_hex) {
62
62
  export function compute_server_seed_hash(server_seed) {
63
63
  try {
64
64
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
65
- const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export);
65
+ const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export3);
66
66
  const len0 = WASM_VECTOR_LEN;
67
67
  wasm.compute_server_seed_hash(retptr, ptr0, len0);
68
68
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
69
69
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
70
70
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
71
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
72
- return v2;
73
- } finally {
74
- wasm.__wbindgen_add_to_stack_pointer(16);
75
- }
76
- }
77
-
78
- /**
79
- * Compute the transaction message hash (for debugging / verification).
80
- *
81
- * Returns `BigUint64Array` of length 4 — the same hash the circuit computes.
82
- *
83
- * ```js
84
- * const hash = compute_tx_msg_hash(5, userId, 0, amountLo, amountHi);
85
- * ```
86
- * @param {number} tx_type
87
- * @param {number} user_id
88
- * @param {number} currency_id
89
- * @param {number} amount_lo
90
- * @param {number} amount_hi
91
- * @param {bigint} session_expiry
92
- * @returns {BigUint64Array}
93
- */
94
- export function compute_tx_msg_hash(tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry) {
95
- try {
96
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
97
- wasm.compute_tx_msg_hash(retptr, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry);
98
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
99
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
100
- var v1 = getArrayU64FromWasm0(r0, r1).slice();
101
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
102
- return v1;
103
- } finally {
104
- wasm.__wbindgen_add_to_stack_pointer(16);
105
- }
106
- }
107
-
108
- /**
109
- * Create a `bet_auth` MAC that proves the user authorized this specific bet.
110
- *
111
- * ```text
112
- * bet_auth = Poseidon2(
113
- * session_key[0..4], // 4 field elements (private)
114
- * amount_lo, // lower 32 bits of bet_amount
115
- * amount_hi, // upper 32 bits of bet_amount
116
- * nonce, // monotonic counter, prevents replay
117
- * )
118
- * ```
119
- *
120
- * The circuit verifies two things:
121
- * 1. `session_pk == Poseidon2(session_key)` — knowledge of key
122
- * 2. `bet_auth == Poseidon2(session_key ‖ amount_lo ‖ amount_hi ‖ nonce)`
123
- *
124
- * The lo/hi split matches `src/circuit/main_circuit.rs` witness assignment:
125
- * `amount as u32` / `(amount >> 32) as u32`, both via `from_canonical_u32`.
126
- *
127
- * **Parameters**
128
- * - `session_key` : 4 × u64 (private, from `derive_session_key`)
129
- * - `bet_amount` : u64 (in smallest currency units)
130
- * - `nonce` : u64 (incrementing per-session counter)
131
- *
132
- * **Returns**: 4 × u64 (`bet_auth` hash)
133
- * @param {BigUint64Array} session_key
134
- * @param {bigint} bet_amount
135
- * @param {bigint} nonce
136
- * @returns {BigUint64Array}
137
- */
138
- export function create_bet_auth(session_key, bet_amount, nonce) {
139
- try {
140
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
141
- const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export);
142
- const len0 = WASM_VECTOR_LEN;
143
- wasm.create_bet_auth(retptr, ptr0, len0, bet_amount, nonce);
144
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
145
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
146
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
147
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
71
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
148
72
  return v2;
149
73
  } finally {
150
74
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -172,13 +96,13 @@ export function create_bet_auth(session_key, bet_amount, nonce) {
172
96
  export function derive_session_key(sig_bytes) {
173
97
  try {
174
98
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
175
- const ptr0 = passArray8ToWasm0(sig_bytes, wasm.__wbindgen_export);
99
+ const ptr0 = passArray8ToWasm0(sig_bytes, wasm.__wbindgen_export3);
176
100
  const len0 = WASM_VECTOR_LEN;
177
101
  wasm.derive_session_key(retptr, ptr0, len0);
178
102
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
179
103
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
180
104
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
181
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
105
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
182
106
  return v2;
183
107
  } finally {
184
108
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -210,7 +134,7 @@ export function generate_user_seed() {
210
134
  return getStringFromWasm0(r0, r1);
211
135
  } finally {
212
136
  wasm.__wbindgen_add_to_stack_pointer(16);
213
- wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
137
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
214
138
  }
215
139
  }
216
140
 
@@ -231,7 +155,7 @@ export function goldilocks_fields_to_hex(fields) {
231
155
  let deferred2_1;
232
156
  try {
233
157
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
234
- const ptr0 = passArray64ToWasm0(fields, wasm.__wbindgen_export);
158
+ const ptr0 = passArray64ToWasm0(fields, wasm.__wbindgen_export3);
235
159
  const len0 = WASM_VECTOR_LEN;
236
160
  wasm.goldilocks_fields_to_hex(retptr, ptr0, len0);
237
161
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
@@ -241,7 +165,7 @@ export function goldilocks_fields_to_hex(fields) {
241
165
  return getStringFromWasm0(r0, r1);
242
166
  } finally {
243
167
  wasm.__wbindgen_add_to_stack_pointer(16);
244
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
168
+ wasm.__wbindgen_export2(deferred2_0, deferred2_1, 1);
245
169
  }
246
170
  }
247
171
 
@@ -286,13 +210,13 @@ export function goldilocks_reduce(value) {
286
210
  export function poseidon2_hash(input) {
287
211
  try {
288
212
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
289
- const ptr0 = passArray64ToWasm0(input, wasm.__wbindgen_export);
213
+ const ptr0 = passArray64ToWasm0(input, wasm.__wbindgen_export3);
290
214
  const len0 = WASM_VECTOR_LEN;
291
215
  wasm.poseidon2_hash(retptr, ptr0, len0);
292
216
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
293
217
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
294
218
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
295
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
219
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
296
220
  return v2;
297
221
  } finally {
298
222
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -313,253 +237,21 @@ export function poseidon2_hash(input) {
313
237
  export function poseidon2_two_to_one(left, right) {
314
238
  try {
315
239
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
316
- const ptr0 = passArray64ToWasm0(left, wasm.__wbindgen_export);
240
+ const ptr0 = passArray64ToWasm0(left, wasm.__wbindgen_export3);
317
241
  const len0 = WASM_VECTOR_LEN;
318
- const ptr1 = passArray64ToWasm0(right, wasm.__wbindgen_export);
242
+ const ptr1 = passArray64ToWasm0(right, wasm.__wbindgen_export3);
319
243
  const len1 = WASM_VECTOR_LEN;
320
244
  wasm.poseidon2_two_to_one(retptr, ptr0, len0, ptr1, len1);
321
245
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
322
246
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
323
247
  var v3 = getArrayU64FromWasm0(r0, r1).slice();
324
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
248
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
325
249
  return v3;
326
250
  } finally {
327
251
  wasm.__wbindgen_add_to_stack_pointer(16);
328
252
  }
329
253
  }
330
254
 
331
- /**
332
- * Derive a Schnorr secret key from entropy bytes (e.g. MetaMask signature).
333
- *
334
- * Takes at least 32 bytes, uses `Scalar::decode_reduce` to map them into
335
- * the ECgFp5 scalar field. Returns hex-encoded secret key (80 chars = 40 bytes).
336
- *
337
- * ```js
338
- * const skHex = schnorr_keygen(sigBytes.slice(0, 32));
339
- * ```
340
- * @param {Uint8Array} entropy
341
- * @returns {string}
342
- */
343
- export function schnorr_keygen(entropy) {
344
- let deferred2_0;
345
- let deferred2_1;
346
- try {
347
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
348
- const ptr0 = passArray8ToWasm0(entropy, wasm.__wbindgen_export);
349
- const len0 = WASM_VECTOR_LEN;
350
- wasm.schnorr_keygen(retptr, ptr0, len0);
351
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
352
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
353
- deferred2_0 = r0;
354
- deferred2_1 = r1;
355
- return getStringFromWasm0(r0, r1);
356
- } finally {
357
- wasm.__wbindgen_add_to_stack_pointer(16);
358
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
359
- }
360
- }
361
-
362
- /**
363
- * Get the w-encoding of a public key as 5 Goldilocks field elements (for circuit witness).
364
- *
365
- * Returns `BigUint64Array` of length 5.
366
- *
367
- * ```js
368
- * const encode = schnorr_pk_encode(pkHex);
369
- * // encode.length === 5
370
- * ```
371
- * @param {string} pk_hex
372
- * @returns {BigUint64Array}
373
- */
374
- export function schnorr_pk_encode(pk_hex) {
375
- try {
376
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
377
- const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
378
- const len0 = WASM_VECTOR_LEN;
379
- wasm.schnorr_pk_encode(retptr, ptr0, len0);
380
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
381
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
382
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
383
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
384
- return v2;
385
- } finally {
386
- wasm.__wbindgen_add_to_stack_pointer(16);
387
- }
388
- }
389
-
390
- /**
391
- * Compute pk_hash = Poseidon2(w_encoding[5]) from a hex-encoded public key.
392
- *
393
- * The w-encoding is the 40-byte (80 hex) representation returned by `schnorr_pubkey`.
394
- * pk_hash is stored in the Merkle tree to bind the Schnorr key to an account.
395
- *
396
- * Returns `BigUint64Array` of length 4.
397
- *
398
- * ```js
399
- * const pkHash = schnorr_pk_hash(pkHex);
400
- * ```
401
- * @param {string} pk_hex
402
- * @returns {BigUint64Array}
403
- */
404
- export function schnorr_pk_hash(pk_hex) {
405
- try {
406
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
407
- const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
408
- const len0 = WASM_VECTOR_LEN;
409
- wasm.schnorr_pk_hash(retptr, ptr0, len0);
410
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
411
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
412
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
413
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
414
- return v2;
415
- } finally {
416
- wasm.__wbindgen_add_to_stack_pointer(16);
417
- }
418
- }
419
-
420
- /**
421
- * Compute pk_hash as a hex string (for convenience).
422
- *
423
- * ```js
424
- * const pkHashHex = schnorr_pk_hash_hex(pkHex);
425
- * ```
426
- * @param {string} pk_hex
427
- * @returns {string}
428
- */
429
- export function schnorr_pk_hash_hex(pk_hex) {
430
- let deferred2_0;
431
- let deferred2_1;
432
- try {
433
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
434
- const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
435
- const len0 = WASM_VECTOR_LEN;
436
- wasm.schnorr_pk_hash_hex(retptr, ptr0, len0);
437
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
438
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
439
- deferred2_0 = r0;
440
- deferred2_1 = r1;
441
- return getStringFromWasm0(r0, r1);
442
- } finally {
443
- wasm.__wbindgen_add_to_stack_pointer(16);
444
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
445
- }
446
- }
447
-
448
- /**
449
- * Compute the Schnorr public key from a hex-encoded secret key.
450
- *
451
- * Returns hex-encoded w-encoding of the ECgFp5 point (80 chars = 40 bytes).
452
- *
453
- * ```js
454
- * const pkHex = schnorr_pubkey(skHex);
455
- * ```
456
- * @param {string} sk_hex
457
- * @returns {string}
458
- */
459
- export function schnorr_pubkey(sk_hex) {
460
- let deferred2_0;
461
- let deferred2_1;
462
- try {
463
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
464
- const ptr0 = passStringToWasm0(sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
465
- const len0 = WASM_VECTOR_LEN;
466
- wasm.schnorr_pubkey(retptr, ptr0, len0);
467
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
468
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
469
- deferred2_0 = r0;
470
- deferred2_1 = r1;
471
- return getStringFromWasm0(r0, r1);
472
- } finally {
473
- wasm.__wbindgen_add_to_stack_pointer(16);
474
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
475
- }
476
- }
477
-
478
- /**
479
- * Sign a ChangePubKey (tx_type=9) transaction in (s, e) format.
480
- *
481
- * msg_hash = Poseidon2(9, user_id, new_pk_hash[0..4])
482
- *
483
- * The old key signs this message to authorize key rotation.
484
- *
485
- * Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
486
- *
487
- * ```js
488
- * const sig = schnorr_sign_cpk(oldSkHex, userId, newPkHashArray);
489
- * ```
490
- * @param {string} old_sk_hex
491
- * @param {number} user_id
492
- * @param {BigUint64Array} new_pk_hash
493
- * @returns {any}
494
- */
495
- export function schnorr_sign_cpk(old_sk_hex, user_id, new_pk_hash) {
496
- const ptr0 = passStringToWasm0(old_sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
497
- const len0 = WASM_VECTOR_LEN;
498
- const ptr1 = passArray64ToWasm0(new_pk_hash, wasm.__wbindgen_export);
499
- const len1 = WASM_VECTOR_LEN;
500
- const ret = wasm.schnorr_sign_cpk(ptr0, len0, user_id, ptr1, len1);
501
- return takeObject(ret);
502
- }
503
-
504
- /**
505
- * Sign a transaction with Schnorr (ECgFp5) in (s, e) format.
506
- *
507
- * msg_hash = Poseidon2(tx_type, user_id, currency_id, amount_lo, amount_hi)
508
- *
509
- * Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
510
- *
511
- * ```js
512
- * const sig = schnorr_sign_tx(skHex, 5, userId, 0, amountLo, amountHi);
513
- * // sig.pubkey (80 hex), sig.sig_s (80 hex), sig.sig_e (80 hex)
514
- * ```
515
- * @param {string} sk_hex
516
- * @param {number} tx_type
517
- * @param {number} user_id
518
- * @param {number} currency_id
519
- * @param {number} amount_lo
520
- * @param {number} amount_hi
521
- * @param {bigint} session_expiry
522
- * @returns {any}
523
- */
524
- export function schnorr_sign_tx(sk_hex, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry) {
525
- const ptr0 = passStringToWasm0(sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
526
- const len0 = WASM_VECTOR_LEN;
527
- const ret = wasm.schnorr_sign_tx(ptr0, len0, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry);
528
- return takeObject(ret);
529
- }
530
-
531
- /**
532
- * Verify a Schnorr signature (s, e) for a transaction.
533
- *
534
- * Algorithm: R_v = s·G + e·pk, e_v = H(R_v‖pk‖msg), check e == e_v.
535
- *
536
- * Returns `true` if signature is valid, `false` otherwise.
537
- *
538
- * ```js
539
- * const ok = schnorr_verify_tx(pubkeyHex, sigSHex, sigEHex, 5, userId, 0, amountLo, amountHi);
540
- * ```
541
- * @param {string} pk_hex
542
- * @param {string} sig_s_hex
543
- * @param {string} sig_e_hex
544
- * @param {number} tx_type
545
- * @param {number} user_id
546
- * @param {number} currency_id
547
- * @param {number} amount_lo
548
- * @param {number} amount_hi
549
- * @param {bigint} session_expiry
550
- * @returns {boolean}
551
- */
552
- export function schnorr_verify_tx(pk_hex, sig_s_hex, sig_e_hex, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry) {
553
- const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
554
- const len0 = WASM_VECTOR_LEN;
555
- const ptr1 = passStringToWasm0(sig_s_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
556
- const len1 = WASM_VECTOR_LEN;
557
- const ptr2 = passStringToWasm0(sig_e_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
558
- const len2 = WASM_VECTOR_LEN;
559
- const ret = wasm.schnorr_verify_tx(ptr0, len0, ptr1, len1, ptr2, len2, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry);
560
- return ret !== 0;
561
- }
562
-
563
255
  /**
564
256
  * Truncated seed hash — first 2 elements of `Poseidon2(server_seed)`.
565
257
  *
@@ -574,13 +266,13 @@ export function schnorr_verify_tx(pk_hex, sig_s_hex, sig_e_hex, tx_type, user_id
574
266
  export function seed_hash_truncated(server_seed) {
575
267
  try {
576
268
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
577
- const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export);
269
+ const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export3);
578
270
  const len0 = WASM_VECTOR_LEN;
579
271
  wasm.seed_hash_truncated(retptr, ptr0, len0);
580
272
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
581
273
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
582
274
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
583
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
275
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
584
276
  return v2;
585
277
  } finally {
586
278
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -588,25 +280,27 @@ export function seed_hash_truncated(server_seed) {
588
280
  }
589
281
 
590
282
  /**
591
- * Compute the public key for a session: `session_pk = Poseidon2(session_key)`.
283
+ * Compute the public key for a session: `pk_hash = Poseidon2(session_key[4], expiry)`.
592
284
  *
593
- * The public key is stored in the user-asset Merkle leaf and verified
594
- * inside the circuit (the prover must know the preimage `session_key`).
285
+ * The public key hash is stored in the user-asset Merkle leaf and verified
286
+ * inside the circuit (the prover must know the preimage `session_key` + `expiry`).
595
287
  *
596
288
  * `session_key` must be exactly 4 elements (output of `derive_session_key`).
289
+ * `session_expiry` is the Unix timestamp after which the session is invalid.
597
290
  * @param {BigUint64Array} session_key
291
+ * @param {bigint} session_expiry
598
292
  * @returns {BigUint64Array}
599
293
  */
600
- export function session_public_key(session_key) {
294
+ export function session_public_key(session_key, session_expiry) {
601
295
  try {
602
296
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
603
- const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export);
297
+ const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export3);
604
298
  const len0 = WASM_VECTOR_LEN;
605
- wasm.session_public_key(retptr, ptr0, len0);
299
+ wasm.session_public_key(retptr, ptr0, len0, session_expiry);
606
300
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
607
301
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
608
302
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
609
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
303
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
610
304
  return v2;
611
305
  } finally {
612
306
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -632,13 +326,13 @@ export function session_public_key(session_key) {
632
326
  export function string_to_user_seed(input) {
633
327
  try {
634
328
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
635
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);
329
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
636
330
  const len0 = WASM_VECTOR_LEN;
637
331
  wasm.string_to_user_seed(retptr, ptr0, len0);
638
332
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
639
333
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
640
334
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
641
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
335
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
642
336
  return v2;
643
337
  } finally {
644
338
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -663,7 +357,7 @@ export function string_to_user_seed_hex(input) {
663
357
  let deferred2_1;
664
358
  try {
665
359
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
666
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);
360
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
667
361
  const len0 = WASM_VECTOR_LEN;
668
362
  wasm.string_to_user_seed_hex(retptr, ptr0, len0);
669
363
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
@@ -673,20 +367,13 @@ export function string_to_user_seed_hex(input) {
673
367
  return getStringFromWasm0(r0, r1);
674
368
  } finally {
675
369
  wasm.__wbindgen_add_to_stack_pointer(16);
676
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
370
+ wasm.__wbindgen_export2(deferred2_0, deferred2_1, 1);
677
371
  }
678
372
  }
679
373
 
680
374
  function __wbg_get_imports() {
681
375
  const import0 = {
682
376
  __proto__: null,
683
- __wbg___wbindgen_debug_string_0bc8482c6e3508ae: function(arg0, arg1) {
684
- const ret = debugString(getObject(arg1));
685
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
686
- const len1 = WASM_VECTOR_LEN;
687
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
688
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
689
- },
690
377
  __wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
691
378
  const ret = typeof(getObject(arg0)) === 'function';
692
379
  return ret;
@@ -730,10 +417,6 @@ function __wbg_get_imports() {
730
417
  const ret = getObject(arg0).msCrypto;
731
418
  return addHeapObject(ret);
732
419
  },
733
- __wbg_new_361308b2356cecd0: function() {
734
- const ret = new Object();
735
- return addHeapObject(ret);
736
- },
737
420
  __wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
738
421
  const ret = new Function(getStringFromWasm0(arg0, arg1));
739
422
  return addHeapObject(ret);
@@ -760,10 +443,6 @@ function __wbg_get_imports() {
760
443
  const ret = module.require;
761
444
  return addHeapObject(ret);
762
445
  }, arguments); },
763
- __wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
764
- const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
765
- return ret;
766
- }, arguments); },
767
446
  __wbg_static_accessor_GLOBAL_12837167ad935116: function() {
768
447
  const ret = typeof global === 'undefined' ? null : global;
769
448
  return isLikeNone(ret) ? 0 : addHeapObject(ret);
@@ -821,71 +500,6 @@ function addHeapObject(obj) {
821
500
  return idx;
822
501
  }
823
502
 
824
- function debugString(val) {
825
- // primitive types
826
- const type = typeof val;
827
- if (type == 'number' || type == 'boolean' || val == null) {
828
- return `${val}`;
829
- }
830
- if (type == 'string') {
831
- return `"${val}"`;
832
- }
833
- if (type == 'symbol') {
834
- const description = val.description;
835
- if (description == null) {
836
- return 'Symbol';
837
- } else {
838
- return `Symbol(${description})`;
839
- }
840
- }
841
- if (type == 'function') {
842
- const name = val.name;
843
- if (typeof name == 'string' && name.length > 0) {
844
- return `Function(${name})`;
845
- } else {
846
- return 'Function';
847
- }
848
- }
849
- // objects
850
- if (Array.isArray(val)) {
851
- const length = val.length;
852
- let debug = '[';
853
- if (length > 0) {
854
- debug += debugString(val[0]);
855
- }
856
- for(let i = 1; i < length; i++) {
857
- debug += ', ' + debugString(val[i]);
858
- }
859
- debug += ']';
860
- return debug;
861
- }
862
- // Test for built-in
863
- const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
864
- let className;
865
- if (builtInMatches && builtInMatches.length > 1) {
866
- className = builtInMatches[1];
867
- } else {
868
- // Failed to match the standard '[object ClassName]'
869
- return toString.call(val);
870
- }
871
- if (className == 'Object') {
872
- // we're a user defined class or Object
873
- // JSON.stringify avoids problems with cycles, and is generally much
874
- // easier than looping through ownProperties of `val`.
875
- try {
876
- return 'Object(' + JSON.stringify(val) + ')';
877
- } catch (_) {
878
- return 'Object';
879
- }
880
- }
881
- // errors
882
- if (val instanceof Error) {
883
- return `${val.name}: ${val.message}\n${val.stack}`;
884
- }
885
- // TODO we could test for more things here, like `Set`s and `Map`s.
886
- return className;
887
- }
888
-
889
503
  function dropObject(idx) {
890
504
  if (idx < 132) return;
891
505
  heap[idx] = heap_next;
@@ -950,7 +564,7 @@ function handleError(f, args) {
950
564
  try {
951
565
  return f.apply(this, args);
952
566
  } catch (e) {
953
- wasm.__wbindgen_export3(addHeapObject(e));
567
+ wasm.__wbindgen_export(addHeapObject(e));
954
568
  }
955
569
  }
956
570
 
Binary file
@@ -4,29 +4,19 @@ export const memory: WebAssembly.Memory;
4
4
  export const amount_split: (a: number, b: bigint) => void;
5
5
  export const compute_address_hash: (a: number, b: number, c: number) => void;
6
6
  export const compute_server_seed_hash: (a: number, b: number, c: number) => void;
7
- export const compute_tx_msg_hash: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint) => void;
8
- export const create_bet_auth: (a: number, b: number, c: number, d: bigint, e: bigint) => void;
9
7
  export const derive_session_key: (a: number, b: number, c: number) => void;
10
8
  export const generate_user_seed: (a: number) => void;
11
9
  export const goldilocks_fields_to_hex: (a: number, b: number, c: number) => void;
12
10
  export const goldilocks_reduce: (a: bigint) => bigint;
13
11
  export const poseidon2_hash: (a: number, b: number, c: number) => void;
14
12
  export const poseidon2_two_to_one: (a: number, b: number, c: number, d: number, e: number) => void;
15
- export const schnorr_keygen: (a: number, b: number, c: number) => void;
16
- export const schnorr_pk_encode: (a: number, b: number, c: number) => void;
17
- export const schnorr_pk_hash: (a: number, b: number, c: number) => void;
18
- export const schnorr_pk_hash_hex: (a: number, b: number, c: number) => void;
19
- export const schnorr_pubkey: (a: number, b: number, c: number) => void;
20
- export const schnorr_sign_cpk: (a: number, b: number, c: number, d: number, e: number) => number;
21
- export const schnorr_sign_tx: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint) => number;
22
- 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, l: bigint) => number;
23
13
  export const seed_hash_truncated: (a: number, b: number, c: number) => void;
24
- export const session_public_key: (a: number, b: number, c: number) => void;
14
+ export const session_public_key: (a: number, b: number, c: number, d: bigint) => void;
25
15
  export const string_to_user_seed: (a: number, b: number, c: number) => void;
26
16
  export const string_to_user_seed_hex: (a: number, b: number, c: number) => void;
27
17
  export const goldilocks_modulus: () => bigint;
28
- export const __wbindgen_export: (a: number, b: number) => number;
29
- export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
30
- export const __wbindgen_export3: (a: number) => void;
18
+ export const __wbindgen_export: (a: number) => void;
31
19
  export const __wbindgen_add_to_stack_pointer: (a: number) => number;
32
- export const __wbindgen_export4: (a: number, b: number, c: number) => void;
20
+ export const __wbindgen_export2: (a: number, b: number, c: number) => void;
21
+ export const __wbindgen_export3: (a: number, b: number) => number;
22
+ export const __wbindgen_export4: (a: number, b: number, c: number, d: number) => number;
package/js/browser.d.mts CHANGED
@@ -3,7 +3,6 @@ export {
3
3
  poseidon2_two_to_one,
4
4
  derive_session_key,
5
5
  session_public_key,
6
- create_bet_auth,
7
6
  compute_server_seed_hash,
8
7
  seed_hash_truncated,
9
8
  string_to_user_seed,
@@ -12,15 +11,6 @@ export {
12
11
  goldilocks_fields_to_hex,
13
12
  goldilocks_modulus,
14
13
  goldilocks_reduce,
15
- schnorr_keygen,
16
- schnorr_pubkey,
17
- schnorr_sign_tx,
18
- schnorr_verify_tx,
19
- schnorr_pk_hash,
20
- schnorr_pk_hash_hex,
21
- schnorr_pk_encode,
22
- schnorr_sign_cpk,
23
- compute_tx_msg_hash,
24
14
  amount_split,
25
15
  compute_address_hash,
26
16
  } from '../dist/web/rolly_wasm_signer.js';