@rolly-dev/wasm-signer 0.6.2 → 0.9.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.
@@ -12,6 +12,12 @@
12
12
  */
13
13
  export function amount_split(amount: bigint): Uint32Array;
14
14
 
15
+ /**
16
+ * Compute address_hash = Poseidon2(addr_byte_0, ..., addr_byte_19).
17
+ * Takes a hex address string (with or without 0x prefix), returns [u64; 4].
18
+ */
19
+ export function compute_address_hash(address_hex: string): BigUint64Array;
20
+
15
21
  /**
16
22
  * Full Poseidon2 hash of an 8-element server seed.
17
23
  *
@@ -33,7 +39,7 @@ export function compute_server_seed_hash(server_seed: BigUint64Array): BigUint64
33
39
  * const hash = compute_tx_msg_hash(5, userId, 0, amountLo, amountHi);
34
40
  * ```
35
41
  */
36
- export function compute_tx_msg_hash(tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number): BigUint64Array;
42
+ export function compute_tx_msg_hash(tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number, session_expiry: bigint): BigUint64Array;
37
43
 
38
44
  /**
39
45
  * Create a `bet_auth` MAC that proves the user authorized this specific bet.
@@ -204,13 +210,13 @@ export function schnorr_pk_hash_hex(pk_hex: string): string;
204
210
  export function schnorr_pubkey(sk_hex: string): string;
205
211
 
206
212
  /**
207
- * Sign a ChangePubKey (tx_type=9) transaction.
213
+ * Sign a ChangePubKey (tx_type=9) transaction in (s, e) format.
208
214
  *
209
215
  * msg_hash = Poseidon2(9, user_id, new_pk_hash[0..4])
210
216
  *
211
217
  * The old key signs this message to authorize key rotation.
212
218
  *
213
- * Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
219
+ * Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
214
220
  *
215
221
  * ```js
216
222
  * const sig = schnorr_sign_cpk(oldSkHex, userId, newPkHashArray);
@@ -219,31 +225,31 @@ export function schnorr_pubkey(sk_hex: string): string;
219
225
  export function schnorr_sign_cpk(old_sk_hex: string, user_id: number, new_pk_hash: BigUint64Array): any;
220
226
 
221
227
  /**
222
- * Sign a transaction with Schnorr (ECgFp5).
228
+ * Sign a transaction with Schnorr (ECgFp5) in (s, e) format.
223
229
  *
224
230
  * msg_hash = Poseidon2(tx_type, user_id, currency_id, amount_lo, amount_hi)
225
231
  *
226
- * Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
232
+ * Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
227
233
  *
228
234
  * ```js
229
- * const sig = schnorr_sign_tx(skHex, 5, userId, 0, amountBigInt);
230
- * // sig.pubkey, sig.sig_r, sig.sig_s all hex strings (80 chars each)
235
+ * const sig = schnorr_sign_tx(skHex, 5, userId, 0, amountLo, amountHi);
236
+ * // sig.pubkey (80 hex), sig.sig_s (80 hex), sig.sig_e (80 hex)
231
237
  * ```
232
238
  */
233
- export function schnorr_sign_tx(sk_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number): any;
239
+ export function schnorr_sign_tx(sk_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number, session_expiry: bigint): any;
234
240
 
235
241
  /**
236
- * Verify a Schnorr signature for a transaction on the backend.
242
+ * Verify a Schnorr signature (s, e) for a transaction.
237
243
  *
238
- * Checks: s·G == R + H(R‖pk‖msg)·pk
244
+ * Algorithm: R_v = s·G + e·pk, e_v = H(R_v‖pk‖msg), check e == e_v.
239
245
  *
240
246
  * Returns `true` if signature is valid, `false` otherwise.
241
247
  *
242
248
  * ```js
243
- * const ok = schnorr_verify_tx(pubkeyHex, sigRHex, sigSHex, 5, userId, 0, amountLo, amountHi);
249
+ * const ok = schnorr_verify_tx(pubkeyHex, sigSHex, sigEHex, 5, userId, 0, amountLo, amountHi);
244
250
  * ```
245
251
  */
246
- export function schnorr_verify_tx(pk_hex: string, sig_r_hex: string, sig_s_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number): boolean;
252
+ export function schnorr_verify_tx(pk_hex: string, sig_s_hex: string, sig_e_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number, session_expiry: bigint): boolean;
247
253
 
248
254
  /**
249
255
  * Truncated seed hash — first 2 elements of `Poseidon2(server_seed)`.
@@ -26,6 +26,29 @@ function amount_split(amount) {
26
26
  }
27
27
  exports.amount_split = amount_split;
28
28
 
29
+ /**
30
+ * Compute address_hash = Poseidon2(addr_byte_0, ..., addr_byte_19).
31
+ * Takes a hex address string (with or without 0x prefix), returns [u64; 4].
32
+ * @param {string} address_hex
33
+ * @returns {BigUint64Array}
34
+ */
35
+ function compute_address_hash(address_hex) {
36
+ try {
37
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
38
+ const ptr0 = passStringToWasm0(address_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
39
+ const len0 = WASM_VECTOR_LEN;
40
+ wasm.compute_address_hash(retptr, ptr0, len0);
41
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
42
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
43
+ var v2 = getArrayU64FromWasm0(r0, r1).slice();
44
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
45
+ return v2;
46
+ } finally {
47
+ wasm.__wbindgen_add_to_stack_pointer(16);
48
+ }
49
+ }
50
+ exports.compute_address_hash = compute_address_hash;
51
+
29
52
  /**
30
53
  * Full Poseidon2 hash of an 8-element server seed.
31
54
  *
@@ -68,12 +91,13 @@ exports.compute_server_seed_hash = compute_server_seed_hash;
68
91
  * @param {number} currency_id
69
92
  * @param {number} amount_lo
70
93
  * @param {number} amount_hi
94
+ * @param {bigint} session_expiry
71
95
  * @returns {BigUint64Array}
72
96
  */
73
- function compute_tx_msg_hash(tx_type, user_id, currency_id, amount_lo, amount_hi) {
97
+ function compute_tx_msg_hash(tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry) {
74
98
  try {
75
99
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
76
- wasm.compute_tx_msg_hash(retptr, tx_type, user_id, currency_id, amount_lo, amount_hi);
100
+ wasm.compute_tx_msg_hash(retptr, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry);
77
101
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
78
102
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
79
103
  var v1 = getArrayU64FromWasm0(r0, r1).slice();
@@ -469,13 +493,13 @@ function schnorr_pubkey(sk_hex) {
469
493
  exports.schnorr_pubkey = schnorr_pubkey;
470
494
 
471
495
  /**
472
- * Sign a ChangePubKey (tx_type=9) transaction.
496
+ * Sign a ChangePubKey (tx_type=9) transaction in (s, e) format.
473
497
  *
474
498
  * msg_hash = Poseidon2(9, user_id, new_pk_hash[0..4])
475
499
  *
476
500
  * The old key signs this message to authorize key rotation.
477
501
  *
478
- * Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
502
+ * Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
479
503
  *
480
504
  * ```js
481
505
  * const sig = schnorr_sign_cpk(oldSkHex, userId, newPkHashArray);
@@ -496,15 +520,15 @@ function schnorr_sign_cpk(old_sk_hex, user_id, new_pk_hash) {
496
520
  exports.schnorr_sign_cpk = schnorr_sign_cpk;
497
521
 
498
522
  /**
499
- * Sign a transaction with Schnorr (ECgFp5).
523
+ * Sign a transaction with Schnorr (ECgFp5) in (s, e) format.
500
524
  *
501
525
  * msg_hash = Poseidon2(tx_type, user_id, currency_id, amount_lo, amount_hi)
502
526
  *
503
- * Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
527
+ * Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
504
528
  *
505
529
  * ```js
506
- * const sig = schnorr_sign_tx(skHex, 5, userId, 0, amountBigInt);
507
- * // sig.pubkey, sig.sig_r, sig.sig_s all hex strings (80 chars each)
530
+ * const sig = schnorr_sign_tx(skHex, 5, userId, 0, amountLo, amountHi);
531
+ * // sig.pubkey (80 hex), sig.sig_s (80 hex), sig.sig_e (80 hex)
508
532
  * ```
509
533
  * @param {string} sk_hex
510
534
  * @param {number} tx_type
@@ -512,44 +536,46 @@ exports.schnorr_sign_cpk = schnorr_sign_cpk;
512
536
  * @param {number} currency_id
513
537
  * @param {number} amount_lo
514
538
  * @param {number} amount_hi
539
+ * @param {bigint} session_expiry
515
540
  * @returns {any}
516
541
  */
517
- function schnorr_sign_tx(sk_hex, tx_type, user_id, currency_id, amount_lo, amount_hi) {
542
+ function schnorr_sign_tx(sk_hex, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry) {
518
543
  const ptr0 = passStringToWasm0(sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
519
544
  const len0 = WASM_VECTOR_LEN;
520
- const ret = wasm.schnorr_sign_tx(ptr0, len0, tx_type, user_id, currency_id, amount_lo, amount_hi);
545
+ const ret = wasm.schnorr_sign_tx(ptr0, len0, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry);
521
546
  return takeObject(ret);
522
547
  }
523
548
  exports.schnorr_sign_tx = schnorr_sign_tx;
524
549
 
525
550
  /**
526
- * Verify a Schnorr signature for a transaction on the backend.
551
+ * Verify a Schnorr signature (s, e) for a transaction.
527
552
  *
528
- * Checks: s·G == R + H(R‖pk‖msg)·pk
553
+ * Algorithm: R_v = s·G + e·pk, e_v = H(R_v‖pk‖msg), check e == e_v.
529
554
  *
530
555
  * Returns `true` if signature is valid, `false` otherwise.
531
556
  *
532
557
  * ```js
533
- * const ok = schnorr_verify_tx(pubkeyHex, sigRHex, sigSHex, 5, userId, 0, amountLo, amountHi);
558
+ * const ok = schnorr_verify_tx(pubkeyHex, sigSHex, sigEHex, 5, userId, 0, amountLo, amountHi);
534
559
  * ```
535
560
  * @param {string} pk_hex
536
- * @param {string} sig_r_hex
537
561
  * @param {string} sig_s_hex
562
+ * @param {string} sig_e_hex
538
563
  * @param {number} tx_type
539
564
  * @param {number} user_id
540
565
  * @param {number} currency_id
541
566
  * @param {number} amount_lo
542
567
  * @param {number} amount_hi
568
+ * @param {bigint} session_expiry
543
569
  * @returns {boolean}
544
570
  */
545
- function schnorr_verify_tx(pk_hex, sig_r_hex, sig_s_hex, tx_type, user_id, currency_id, amount_lo, amount_hi) {
571
+ function schnorr_verify_tx(pk_hex, sig_s_hex, sig_e_hex, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry) {
546
572
  const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
547
573
  const len0 = WASM_VECTOR_LEN;
548
- const ptr1 = passStringToWasm0(sig_r_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
574
+ const ptr1 = passStringToWasm0(sig_s_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
549
575
  const len1 = WASM_VECTOR_LEN;
550
- const ptr2 = passStringToWasm0(sig_s_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
576
+ const ptr2 = passStringToWasm0(sig_e_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
551
577
  const len2 = WASM_VECTOR_LEN;
552
- const ret = wasm.schnorr_verify_tx(ptr0, len0, ptr1, len1, ptr2, len2, tx_type, user_id, currency_id, amount_lo, amount_hi);
578
+ const ret = wasm.schnorr_verify_tx(ptr0, len0, ptr1, len1, ptr2, len2, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry);
553
579
  return ret !== 0;
554
580
  }
555
581
  exports.schnorr_verify_tx = schnorr_verify_tx;
Binary file
@@ -2,8 +2,9 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const amount_split: (a: number, b: bigint) => void;
5
+ export const compute_address_hash: (a: number, b: number, c: number) => void;
5
6
  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;
7
+ export const compute_tx_msg_hash: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint) => void;
7
8
  export const create_bet_auth: (a: number, b: number, c: number, d: bigint, e: bigint) => void;
8
9
  export const derive_session_key: (a: number, b: number, c: number) => void;
9
10
  export const generate_user_seed: (a: number) => void;
@@ -17,8 +18,8 @@ export const schnorr_pk_hash: (a: number, b: number, c: number) => void;
17
18
  export const schnorr_pk_hash_hex: (a: number, b: number, c: number) => void;
18
19
  export const schnorr_pubkey: (a: number, b: number, c: number) => void;
19
20
  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;
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;
22
23
  export const seed_hash_truncated: (a: number, b: number, c: number) => void;
23
24
  export const session_public_key: (a: number, b: number, c: number) => void;
24
25
  export const string_to_user_seed: (a: number, b: number, c: number) => void;
@@ -12,6 +12,12 @@
12
12
  */
13
13
  export function amount_split(amount: bigint): Uint32Array;
14
14
 
15
+ /**
16
+ * Compute address_hash = Poseidon2(addr_byte_0, ..., addr_byte_19).
17
+ * Takes a hex address string (with or without 0x prefix), returns [u64; 4].
18
+ */
19
+ export function compute_address_hash(address_hex: string): BigUint64Array;
20
+
15
21
  /**
16
22
  * Full Poseidon2 hash of an 8-element server seed.
17
23
  *
@@ -33,7 +39,7 @@ export function compute_server_seed_hash(server_seed: BigUint64Array): BigUint64
33
39
  * const hash = compute_tx_msg_hash(5, userId, 0, amountLo, amountHi);
34
40
  * ```
35
41
  */
36
- export function compute_tx_msg_hash(tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number): BigUint64Array;
42
+ export function compute_tx_msg_hash(tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number, session_expiry: bigint): BigUint64Array;
37
43
 
38
44
  /**
39
45
  * Create a `bet_auth` MAC that proves the user authorized this specific bet.
@@ -204,13 +210,13 @@ export function schnorr_pk_hash_hex(pk_hex: string): string;
204
210
  export function schnorr_pubkey(sk_hex: string): string;
205
211
 
206
212
  /**
207
- * Sign a ChangePubKey (tx_type=9) transaction.
213
+ * Sign a ChangePubKey (tx_type=9) transaction in (s, e) format.
208
214
  *
209
215
  * msg_hash = Poseidon2(9, user_id, new_pk_hash[0..4])
210
216
  *
211
217
  * The old key signs this message to authorize key rotation.
212
218
  *
213
- * Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
219
+ * Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
214
220
  *
215
221
  * ```js
216
222
  * const sig = schnorr_sign_cpk(oldSkHex, userId, newPkHashArray);
@@ -219,31 +225,31 @@ export function schnorr_pubkey(sk_hex: string): string;
219
225
  export function schnorr_sign_cpk(old_sk_hex: string, user_id: number, new_pk_hash: BigUint64Array): any;
220
226
 
221
227
  /**
222
- * Sign a transaction with Schnorr (ECgFp5).
228
+ * Sign a transaction with Schnorr (ECgFp5) in (s, e) format.
223
229
  *
224
230
  * msg_hash = Poseidon2(tx_type, user_id, currency_id, amount_lo, amount_hi)
225
231
  *
226
- * Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
232
+ * Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
227
233
  *
228
234
  * ```js
229
- * const sig = schnorr_sign_tx(skHex, 5, userId, 0, amountBigInt);
230
- * // sig.pubkey, sig.sig_r, sig.sig_s all hex strings (80 chars each)
235
+ * const sig = schnorr_sign_tx(skHex, 5, userId, 0, amountLo, amountHi);
236
+ * // sig.pubkey (80 hex), sig.sig_s (80 hex), sig.sig_e (80 hex)
231
237
  * ```
232
238
  */
233
- export function schnorr_sign_tx(sk_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number): any;
239
+ export function schnorr_sign_tx(sk_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number, session_expiry: bigint): any;
234
240
 
235
241
  /**
236
- * Verify a Schnorr signature for a transaction on the backend.
242
+ * Verify a Schnorr signature (s, e) for a transaction.
237
243
  *
238
- * Checks: s·G == R + H(R‖pk‖msg)·pk
244
+ * Algorithm: R_v = s·G + e·pk, e_v = H(R_v‖pk‖msg), check e == e_v.
239
245
  *
240
246
  * Returns `true` if signature is valid, `false` otherwise.
241
247
  *
242
248
  * ```js
243
- * const ok = schnorr_verify_tx(pubkeyHex, sigRHex, sigSHex, 5, userId, 0, amountLo, amountHi);
249
+ * const ok = schnorr_verify_tx(pubkeyHex, sigSHex, sigEHex, 5, userId, 0, amountLo, amountHi);
244
250
  * ```
245
251
  */
246
- export function schnorr_verify_tx(pk_hex: string, sig_r_hex: string, sig_s_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number): boolean;
252
+ export function schnorr_verify_tx(pk_hex: string, sig_s_hex: string, sig_e_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number, session_expiry: bigint): boolean;
247
253
 
248
254
  /**
249
255
  * Truncated seed hash — first 2 elements of `Poseidon2(server_seed)`.
@@ -300,8 +306,9 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
300
306
  export interface InitOutput {
301
307
  readonly memory: WebAssembly.Memory;
302
308
  readonly amount_split: (a: number, b: bigint) => void;
309
+ readonly compute_address_hash: (a: number, b: number, c: number) => void;
303
310
  readonly compute_server_seed_hash: (a: number, b: number, c: number) => void;
304
- readonly compute_tx_msg_hash: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
311
+ readonly compute_tx_msg_hash: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint) => void;
305
312
  readonly create_bet_auth: (a: number, b: number, c: number, d: bigint, e: bigint) => void;
306
313
  readonly derive_session_key: (a: number, b: number, c: number) => void;
307
314
  readonly generate_user_seed: (a: number) => void;
@@ -315,8 +322,8 @@ export interface InitOutput {
315
322
  readonly schnorr_pk_hash_hex: (a: number, b: number, c: number) => void;
316
323
  readonly schnorr_pubkey: (a: number, b: number, c: number) => void;
317
324
  readonly schnorr_sign_cpk: (a: number, b: number, c: number, d: number, e: number) => number;
318
- readonly schnorr_sign_tx: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
319
- readonly 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;
325
+ readonly schnorr_sign_tx: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint) => number;
326
+ readonly 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;
320
327
  readonly seed_hash_truncated: (a: number, b: number, c: number) => void;
321
328
  readonly session_public_key: (a: number, b: number, c: number) => void;
322
329
  readonly string_to_user_seed: (a: number, b: number, c: number) => void;
@@ -25,6 +25,28 @@ export function amount_split(amount) {
25
25
  }
26
26
  }
27
27
 
28
+ /**
29
+ * Compute address_hash = Poseidon2(addr_byte_0, ..., addr_byte_19).
30
+ * Takes a hex address string (with or without 0x prefix), returns [u64; 4].
31
+ * @param {string} address_hex
32
+ * @returns {BigUint64Array}
33
+ */
34
+ export function compute_address_hash(address_hex) {
35
+ try {
36
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
37
+ const ptr0 = passStringToWasm0(address_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
38
+ const len0 = WASM_VECTOR_LEN;
39
+ wasm.compute_address_hash(retptr, ptr0, len0);
40
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
41
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
42
+ var v2 = getArrayU64FromWasm0(r0, r1).slice();
43
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
44
+ return v2;
45
+ } finally {
46
+ wasm.__wbindgen_add_to_stack_pointer(16);
47
+ }
48
+ }
49
+
28
50
  /**
29
51
  * Full Poseidon2 hash of an 8-element server seed.
30
52
  *
@@ -66,12 +88,13 @@ export function compute_server_seed_hash(server_seed) {
66
88
  * @param {number} currency_id
67
89
  * @param {number} amount_lo
68
90
  * @param {number} amount_hi
91
+ * @param {bigint} session_expiry
69
92
  * @returns {BigUint64Array}
70
93
  */
71
- export function compute_tx_msg_hash(tx_type, user_id, currency_id, amount_lo, amount_hi) {
94
+ export function compute_tx_msg_hash(tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry) {
72
95
  try {
73
96
  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);
97
+ wasm.compute_tx_msg_hash(retptr, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry);
75
98
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
76
99
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
77
100
  var v1 = getArrayU64FromWasm0(r0, r1).slice();
@@ -453,13 +476,13 @@ export function schnorr_pubkey(sk_hex) {
453
476
  }
454
477
 
455
478
  /**
456
- * Sign a ChangePubKey (tx_type=9) transaction.
479
+ * Sign a ChangePubKey (tx_type=9) transaction in (s, e) format.
457
480
  *
458
481
  * msg_hash = Poseidon2(9, user_id, new_pk_hash[0..4])
459
482
  *
460
483
  * The old key signs this message to authorize key rotation.
461
484
  *
462
- * Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
485
+ * Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
463
486
  *
464
487
  * ```js
465
488
  * const sig = schnorr_sign_cpk(oldSkHex, userId, newPkHashArray);
@@ -479,15 +502,15 @@ export function schnorr_sign_cpk(old_sk_hex, user_id, new_pk_hash) {
479
502
  }
480
503
 
481
504
  /**
482
- * Sign a transaction with Schnorr (ECgFp5).
505
+ * Sign a transaction with Schnorr (ECgFp5) in (s, e) format.
483
506
  *
484
507
  * msg_hash = Poseidon2(tx_type, user_id, currency_id, amount_lo, amount_hi)
485
508
  *
486
- * Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
509
+ * Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
487
510
  *
488
511
  * ```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)
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)
491
514
  * ```
492
515
  * @param {string} sk_hex
493
516
  * @param {number} tx_type
@@ -495,43 +518,45 @@ export function schnorr_sign_cpk(old_sk_hex, user_id, new_pk_hash) {
495
518
  * @param {number} currency_id
496
519
  * @param {number} amount_lo
497
520
  * @param {number} amount_hi
521
+ * @param {bigint} session_expiry
498
522
  * @returns {any}
499
523
  */
500
- export function schnorr_sign_tx(sk_hex, tx_type, user_id, currency_id, amount_lo, amount_hi) {
524
+ export function schnorr_sign_tx(sk_hex, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry) {
501
525
  const ptr0 = passStringToWasm0(sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
502
526
  const len0 = WASM_VECTOR_LEN;
503
- const ret = wasm.schnorr_sign_tx(ptr0, len0, tx_type, user_id, currency_id, amount_lo, amount_hi);
527
+ const ret = wasm.schnorr_sign_tx(ptr0, len0, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry);
504
528
  return takeObject(ret);
505
529
  }
506
530
 
507
531
  /**
508
- * Verify a Schnorr signature for a transaction on the backend.
532
+ * Verify a Schnorr signature (s, e) for a transaction.
509
533
  *
510
- * Checks: s·G == R + H(R‖pk‖msg)·pk
534
+ * Algorithm: R_v = s·G + e·pk, e_v = H(R_v‖pk‖msg), check e == e_v.
511
535
  *
512
536
  * Returns `true` if signature is valid, `false` otherwise.
513
537
  *
514
538
  * ```js
515
- * const ok = schnorr_verify_tx(pubkeyHex, sigRHex, sigSHex, 5, userId, 0, amountLo, amountHi);
539
+ * const ok = schnorr_verify_tx(pubkeyHex, sigSHex, sigEHex, 5, userId, 0, amountLo, amountHi);
516
540
  * ```
517
541
  * @param {string} pk_hex
518
- * @param {string} sig_r_hex
519
542
  * @param {string} sig_s_hex
543
+ * @param {string} sig_e_hex
520
544
  * @param {number} tx_type
521
545
  * @param {number} user_id
522
546
  * @param {number} currency_id
523
547
  * @param {number} amount_lo
524
548
  * @param {number} amount_hi
549
+ * @param {bigint} session_expiry
525
550
  * @returns {boolean}
526
551
  */
527
- export function schnorr_verify_tx(pk_hex, sig_r_hex, sig_s_hex, tx_type, user_id, currency_id, amount_lo, amount_hi) {
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) {
528
553
  const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
529
554
  const len0 = WASM_VECTOR_LEN;
530
- const ptr1 = passStringToWasm0(sig_r_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
555
+ const ptr1 = passStringToWasm0(sig_s_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
531
556
  const len1 = WASM_VECTOR_LEN;
532
- const ptr2 = passStringToWasm0(sig_s_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
557
+ const ptr2 = passStringToWasm0(sig_e_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
533
558
  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);
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);
535
560
  return ret !== 0;
536
561
  }
537
562
 
Binary file
@@ -2,8 +2,9 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const amount_split: (a: number, b: bigint) => void;
5
+ export const compute_address_hash: (a: number, b: number, c: number) => void;
5
6
  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;
7
+ export const compute_tx_msg_hash: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint) => void;
7
8
  export const create_bet_auth: (a: number, b: number, c: number, d: bigint, e: bigint) => void;
8
9
  export const derive_session_key: (a: number, b: number, c: number) => void;
9
10
  export const generate_user_seed: (a: number) => void;
@@ -17,8 +18,8 @@ export const schnorr_pk_hash: (a: number, b: number, c: number) => void;
17
18
  export const schnorr_pk_hash_hex: (a: number, b: number, c: number) => void;
18
19
  export const schnorr_pubkey: (a: number, b: number, c: number) => void;
19
20
  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;
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;
22
23
  export const seed_hash_truncated: (a: number, b: number, c: number) => void;
23
24
  export const session_public_key: (a: number, b: number, c: number) => void;
24
25
  export const string_to_user_seed: (a: number, b: number, c: number) => void;
package/js/browser.d.mts CHANGED
@@ -12,6 +12,17 @@ export {
12
12
  goldilocks_fields_to_hex,
13
13
  goldilocks_modulus,
14
14
  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
+ amount_split,
25
+ compute_address_hash,
15
26
  } from '../dist/web/rolly_wasm_signer.js';
16
27
 
17
28
  export { default as init } from '../dist/web/rolly_wasm_signer.js';
package/js/browser.mjs CHANGED
@@ -24,4 +24,5 @@ export {
24
24
  schnorr_sign_cpk,
25
25
  compute_tx_msg_hash,
26
26
  amount_split,
27
+ compute_address_hash,
27
28
  } from '../dist/web/rolly_wasm_signer.js';
package/js/index.d.ts CHANGED
@@ -22,4 +22,5 @@ export {
22
22
  schnorr_sign_cpk,
23
23
  compute_tx_msg_hash,
24
24
  amount_split,
25
+ compute_address_hash,
25
26
  } from '../dist/node/rolly_wasm_signer.js';
package/js/node.cjs CHANGED
@@ -26,4 +26,5 @@ module.exports = {
26
26
  schnorr_sign_cpk: wasm.schnorr_sign_cpk,
27
27
  compute_tx_msg_hash: wasm.compute_tx_msg_hash,
28
28
  amount_split: wasm.amount_split,
29
+ compute_address_hash: wasm.compute_address_hash,
29
30
  };
package/js/node.mjs CHANGED
@@ -27,4 +27,5 @@ export const {
27
27
  schnorr_sign_cpk,
28
28
  compute_tx_msg_hash,
29
29
  amount_split,
30
+ compute_address_hash,
30
31
  } = wasm;
package/js/react.d.mts CHANGED
@@ -14,6 +14,17 @@ export interface RollyWasmResult {
14
14
  goldilocks_fields_to_hex: (fields: BigUint64Array) => string;
15
15
  goldilocks_modulus: () => bigint;
16
16
  goldilocks_reduce: (value: bigint) => bigint;
17
+ schnorr_keygen: (entropy: Uint8Array) => string;
18
+ schnorr_pubkey: (sk_hex: string) => string;
19
+ schnorr_sign_tx: (sk_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number, session_expiry: bigint) => any;
20
+ schnorr_verify_tx: (pk_hex: string, sig_s_hex: string, sig_e_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number, session_expiry: bigint) => boolean;
21
+ schnorr_pk_hash: (pk_hex: string) => BigUint64Array;
22
+ schnorr_pk_hash_hex: (pk_hex: string) => string;
23
+ schnorr_pk_encode: (pk_hex: string) => BigUint64Array;
24
+ schnorr_sign_cpk: (old_sk_hex: string, user_id: number, new_pk_hash: BigUint64Array) => any;
25
+ compute_tx_msg_hash: (tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number, session_expiry: bigint) => BigUint64Array;
26
+ amount_split: (amount: bigint) => Uint32Array;
27
+ compute_address_hash: (address_hex: string) => BigUint64Array;
17
28
  }
18
29
 
19
30
  export function useRollyWasm(): RollyWasmResult;
package/js/react.mjs CHANGED
@@ -13,6 +13,17 @@ import init, {
13
13
  goldilocks_fields_to_hex,
14
14
  goldilocks_modulus,
15
15
  goldilocks_reduce,
16
+ schnorr_keygen,
17
+ schnorr_pubkey,
18
+ schnorr_sign_tx,
19
+ schnorr_verify_tx,
20
+ schnorr_pk_hash,
21
+ schnorr_pk_hash_hex,
22
+ schnorr_pk_encode,
23
+ schnorr_sign_cpk,
24
+ compute_tx_msg_hash,
25
+ amount_split,
26
+ compute_address_hash,
16
27
  } from '../dist/web/rolly_wasm_signer.js';
17
28
 
18
29
  let _ready = false;
@@ -39,6 +50,17 @@ const fns = {
39
50
  goldilocks_fields_to_hex: guard(goldilocks_fields_to_hex),
40
51
  goldilocks_modulus: guard(goldilocks_modulus),
41
52
  goldilocks_reduce: guard(goldilocks_reduce),
53
+ schnorr_keygen: guard(schnorr_keygen),
54
+ schnorr_pubkey: guard(schnorr_pubkey),
55
+ schnorr_sign_tx: guard(schnorr_sign_tx),
56
+ schnorr_verify_tx: guard(schnorr_verify_tx),
57
+ schnorr_pk_hash: guard(schnorr_pk_hash),
58
+ schnorr_pk_hash_hex: guard(schnorr_pk_hash_hex),
59
+ schnorr_pk_encode: guard(schnorr_pk_encode),
60
+ schnorr_sign_cpk: guard(schnorr_sign_cpk),
61
+ compute_tx_msg_hash: guard(compute_tx_msg_hash),
62
+ amount_split: guard(amount_split),
63
+ compute_address_hash: guard(compute_address_hash),
42
64
  };
43
65
 
44
66
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolly-dev/wasm-signer",
3
- "version": "0.6.2",
3
+ "version": "0.9.0",
4
4
  "description": "Poseidon2 hashing & bet signing for Rolly ZK-Rollup (WASM, Goldilocks field)",
5
5
  "type": "module",
6
6
  "exports": {