@rolly-dev/wasm-signer 0.12.0 → 1.0.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.
@@ -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);
@@ -51,7 +51,7 @@ export function compute_address_hash(address_hex) {
51
51
  * Full Poseidon2 hash of an 8-element server seed.
52
52
  *
53
53
  * Returns all 4 hash elements. Note: the circuit stores only the
54
- * **first 2 elements** as the leaf commitment (see `seed_hash_truncated`).
54
+ * **first 3 elements** as the leaf commitment (see `seed_hash_truncated`).
55
55
  * This full variant is useful for client-side verification where all
56
56
  * 4 elements may be needed.
57
57
  *
@@ -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
 
@@ -268,31 +192,32 @@ export function goldilocks_reduce(value) {
268
192
  }
269
193
 
270
194
  /**
271
- * Poseidon2 hash of an arbitrary number of Goldilocks field elements.
195
+ * Hash a raw 7-element balance leaf 4-element Merkle node.
272
196
  *
273
- * Mirrors `builder.hash_n_to_hash_no_pad::<Poseidon2Hash>(...)` inside
274
- * the circuit and `Poseidon2Hash::hash_no_pad` in `src/block_builder`.
197
+ * Raw layout: `[balance_lo, balance_hi, seed_hash_0, seed_hash_1, seed_hash_2, credit_lo, credit_hi]`
275
198
  *
276
- * **Input** : `BigUint64Array` each element must be < `GOLDILOCKS_P`.
199
+ * Identical to `hash_balance_leaf` in `prover/circuit/src/helpers/leaf_ops.rs`.
200
+ *
201
+ * **Input** : `BigUint64Array` of exactly 7 elements (each < `GOLDILOCKS_P`).
277
202
  * **Output**: `BigUint64Array` of length 4 (one `HashOut`).
278
203
  *
279
204
  * ```js
280
- * const h = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
281
- * // h.length === 4
205
+ * const raw = BigUint64Array.from([balLo, balHi, seed0, seed1, seed2, credLo, credHi]);
206
+ * const balanceHash = hash_balance_leaf(raw); // length 4
282
207
  * ```
283
- * @param {BigUint64Array} input
208
+ * @param {BigUint64Array} raw
284
209
  * @returns {BigUint64Array}
285
210
  */
286
- export function poseidon2_hash(input) {
211
+ export function hash_balance_leaf(raw) {
287
212
  try {
288
213
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
289
- const ptr0 = passArray64ToWasm0(input, wasm.__wbindgen_export);
214
+ const ptr0 = passArray64ToWasm0(raw, wasm.__wbindgen_export3);
290
215
  const len0 = WASM_VECTOR_LEN;
291
- wasm.poseidon2_hash(retptr, ptr0, len0);
216
+ wasm.hash_balance_leaf(retptr, ptr0, len0);
292
217
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
293
218
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
294
219
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
295
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
220
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
296
221
  return v2;
297
222
  } finally {
298
223
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -300,117 +225,71 @@ export function poseidon2_hash(input) {
300
225
  }
301
226
 
302
227
  /**
303
- * Merkle-tree hash: Poseidon2(left[4] right[4]).
304
- *
305
- * Identical to `poseidon_hash(left, right)` in `src/merkletree/hash.rs`.
306
- * Input ordering is critical — `left` concatenated before `right`.
307
- *
308
- * Both arrays **must** have exactly 4 elements (one `HashOut` each).
309
- * @param {BigUint64Array} left
310
- * @param {BigUint64Array} right
311
- * @returns {BigUint64Array}
312
- */
313
- export function poseidon2_two_to_one(left, right) {
314
- try {
315
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
316
- const ptr0 = passArray64ToWasm0(left, wasm.__wbindgen_export);
317
- const len0 = WASM_VECTOR_LEN;
318
- const ptr1 = passArray64ToWasm0(right, wasm.__wbindgen_export);
319
- const len1 = WASM_VECTOR_LEN;
320
- wasm.poseidon2_two_to_one(retptr, ptr0, len0, ptr1, len1);
321
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
322
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
323
- var v3 = getArrayU64FromWasm0(r0, r1).slice();
324
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
325
- return v3;
326
- } finally {
327
- wasm.__wbindgen_add_to_stack_pointer(16);
328
- }
329
- }
330
-
331
- /**
332
- * Derive a Schnorr secret key from entropy bytes (e.g. MetaMask signature).
228
+ * Build a main Merkle tree leaf from balance_hash, pk_hash, and address_hash.
333
229
  *
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).
230
+ * `main_leaf = Poseidon2(balance_hash[4] || pk_hash[0..2] || address_hash[0..2])`
336
231
  *
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).
232
+ * Uses truncated (128-bit) pk/address hashes to keep the preimage at 8 elements
233
+ * (single Poseidon2 permutation round). Identical to `make_main_leaf` in
234
+ * `prover/circuit/src/helpers/leaf_ops.rs`.
364
235
  *
365
- * Returns `BigUint64Array` of length 5.
236
+ * All three inputs must be exactly 4 elements.
237
+ * **Output**: `BigUint64Array` of length 4 (the Merkle leaf hash).
366
238
  *
367
239
  * ```js
368
- * const encode = schnorr_pk_encode(pkHex);
369
- * // encode.length === 5
240
+ * const leaf = make_main_leaf(balanceHash, pkHash, addressHash);
370
241
  * ```
371
- * @param {string} pk_hex
242
+ * @param {BigUint64Array} balance_hash
243
+ * @param {BigUint64Array} pk_hash
244
+ * @param {BigUint64Array} address_hash
372
245
  * @returns {BigUint64Array}
373
246
  */
374
- export function schnorr_pk_encode(pk_hex) {
247
+ export function make_main_leaf(balance_hash, pk_hash, address_hash) {
375
248
  try {
376
249
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
377
- const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
250
+ const ptr0 = passArray64ToWasm0(balance_hash, wasm.__wbindgen_export3);
378
251
  const len0 = WASM_VECTOR_LEN;
379
- wasm.schnorr_pk_encode(retptr, ptr0, len0);
252
+ const ptr1 = passArray64ToWasm0(pk_hash, wasm.__wbindgen_export3);
253
+ const len1 = WASM_VECTOR_LEN;
254
+ const ptr2 = passArray64ToWasm0(address_hash, wasm.__wbindgen_export3);
255
+ const len2 = WASM_VECTOR_LEN;
256
+ wasm.make_main_leaf(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
380
257
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
381
258
  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;
259
+ var v4 = getArrayU64FromWasm0(r0, r1).slice();
260
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
261
+ return v4;
385
262
  } finally {
386
263
  wasm.__wbindgen_add_to_stack_pointer(16);
387
264
  }
388
265
  }
389
266
 
390
267
  /**
391
- * Compute pk_hash = Poseidon2(w_encoding[5]) from a hex-encoded public key.
268
+ * Poseidon2 hash of an arbitrary number of Goldilocks field elements.
392
269
  *
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.
270
+ * Mirrors `builder.hash_n_to_hash_no_pad::<Poseidon2Hash>(...)` inside
271
+ * the circuit and `Poseidon2Hash::hash_no_pad` in `src/block_builder`.
395
272
  *
396
- * Returns `BigUint64Array` of length 4.
273
+ * **Input** : `BigUint64Array` each element must be < `GOLDILOCKS_P`.
274
+ * **Output**: `BigUint64Array` of length 4 (one `HashOut`).
397
275
  *
398
276
  * ```js
399
- * const pkHash = schnorr_pk_hash(pkHex);
277
+ * const h = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
278
+ * // h.length === 4
400
279
  * ```
401
- * @param {string} pk_hex
280
+ * @param {BigUint64Array} input
402
281
  * @returns {BigUint64Array}
403
282
  */
404
- export function schnorr_pk_hash(pk_hex) {
283
+ export function poseidon2_hash(input) {
405
284
  try {
406
285
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
407
- const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
286
+ const ptr0 = passArray64ToWasm0(input, wasm.__wbindgen_export3);
408
287
  const len0 = WASM_VECTOR_LEN;
409
- wasm.schnorr_pk_hash(retptr, ptr0, len0);
288
+ wasm.poseidon2_hash(retptr, ptr0, len0);
410
289
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
411
290
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
412
291
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
413
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
292
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
414
293
  return v2;
415
294
  } finally {
416
295
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -418,169 +297,57 @@ export function schnorr_pk_hash(pk_hex) {
418
297
  }
419
298
 
420
299
  /**
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.
300
+ * Merkle-tree hash: Poseidon2(left[4] right[4]).
450
301
  *
451
- * Returns hex-encoded w-encoding of the ECgFp5 point (80 chars = 40 bytes).
302
+ * Identical to `poseidon_hash(left, right)` in `src/merkletree/hash.rs`.
303
+ * Input ordering is critical — `left` concatenated before `right`.
452
304
  *
453
- * ```js
454
- * const pkHex = schnorr_pubkey(skHex);
455
- * ```
456
- * @param {string} sk_hex
457
- * @returns {string}
305
+ * Both arrays **must** have exactly 4 elements (one `HashOut` each).
306
+ * @param {BigUint64Array} left
307
+ * @param {BigUint64Array} right
308
+ * @returns {BigUint64Array}
458
309
  */
459
- export function schnorr_pubkey(sk_hex) {
460
- let deferred2_0;
461
- let deferred2_1;
310
+ export function poseidon2_two_to_one(left, right) {
462
311
  try {
463
312
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
464
- const ptr0 = passStringToWasm0(sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
313
+ const ptr0 = passArray64ToWasm0(left, wasm.__wbindgen_export3);
465
314
  const len0 = WASM_VECTOR_LEN;
466
- wasm.schnorr_pubkey(retptr, ptr0, len0);
315
+ const ptr1 = passArray64ToWasm0(right, wasm.__wbindgen_export3);
316
+ const len1 = WASM_VECTOR_LEN;
317
+ wasm.poseidon2_two_to_one(retptr, ptr0, len0, ptr1, len1);
467
318
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
468
319
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
469
- deferred2_0 = r0;
470
- deferred2_1 = r1;
471
- return getStringFromWasm0(r0, r1);
320
+ var v3 = getArrayU64FromWasm0(r0, r1).slice();
321
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
322
+ return v3;
472
323
  } finally {
473
324
  wasm.__wbindgen_add_to_stack_pointer(16);
474
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
475
325
  }
476
326
  }
477
327
 
478
328
  /**
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
- /**
564
- * Truncated seed hash — first 2 elements of `Poseidon2(server_seed)`.
329
+ * Truncated seed hash first 3 elements of `Poseidon2(server_seed)`.
565
330
  *
331
+ * 192 bits of commitment → ~96-bit collision resistance, which closes the
332
+ * multi-preimage grinding vector that an earlier 128-bit truncation left open.
566
333
  * This is the exact format stored in the Merkle-tree leaf and verified
567
334
  * by the circuit. Matches `seed_hash_truncated` in
568
- * `src/block_builder/builder.rs` and `src/circuit/main_circuit.rs`.
335
+ * `src/block_builder/builder.rs` and `src/circuit/slot/fairness.rs`.
569
336
  *
570
- * Returns `BigUint64Array` of length 2: `[h[0], h[1]]`.
337
+ * Returns `BigUint64Array` of length 3: `[h[0], h[1], h[2]]`.
571
338
  * @param {BigUint64Array} server_seed
572
339
  * @returns {BigUint64Array}
573
340
  */
574
341
  export function seed_hash_truncated(server_seed) {
575
342
  try {
576
343
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
577
- const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export);
344
+ const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export3);
578
345
  const len0 = WASM_VECTOR_LEN;
579
346
  wasm.seed_hash_truncated(retptr, ptr0, len0);
580
347
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
581
348
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
582
349
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
583
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
350
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
584
351
  return v2;
585
352
  } finally {
586
353
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -588,25 +355,27 @@ export function seed_hash_truncated(server_seed) {
588
355
  }
589
356
 
590
357
  /**
591
- * Compute the public key for a session: `session_pk = Poseidon2(session_key)`.
358
+ * Compute the public key for a session: `pk_hash = Poseidon2(session_key[4], expiry)`.
592
359
  *
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`).
360
+ * The public key hash is stored in the user-asset Merkle leaf and verified
361
+ * inside the circuit (the prover must know the preimage `session_key` + `expiry`).
595
362
  *
596
363
  * `session_key` must be exactly 4 elements (output of `derive_session_key`).
364
+ * `session_expiry` is the Unix timestamp after which the session is invalid.
597
365
  * @param {BigUint64Array} session_key
366
+ * @param {bigint} session_expiry
598
367
  * @returns {BigUint64Array}
599
368
  */
600
- export function session_public_key(session_key) {
369
+ export function session_public_key(session_key, session_expiry) {
601
370
  try {
602
371
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
603
- const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export);
372
+ const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export3);
604
373
  const len0 = WASM_VECTOR_LEN;
605
- wasm.session_public_key(retptr, ptr0, len0);
374
+ wasm.session_public_key(retptr, ptr0, len0, session_expiry);
606
375
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
607
376
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
608
377
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
609
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
378
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
610
379
  return v2;
611
380
  } finally {
612
381
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -632,13 +401,13 @@ export function session_public_key(session_key) {
632
401
  export function string_to_user_seed(input) {
633
402
  try {
634
403
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
635
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);
404
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
636
405
  const len0 = WASM_VECTOR_LEN;
637
406
  wasm.string_to_user_seed(retptr, ptr0, len0);
638
407
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
639
408
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
640
409
  var v2 = getArrayU64FromWasm0(r0, r1).slice();
641
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
410
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
642
411
  return v2;
643
412
  } finally {
644
413
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -663,7 +432,7 @@ export function string_to_user_seed_hex(input) {
663
432
  let deferred2_1;
664
433
  try {
665
434
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
666
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);
435
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
667
436
  const len0 = WASM_VECTOR_LEN;
668
437
  wasm.string_to_user_seed_hex(retptr, ptr0, len0);
669
438
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
@@ -673,20 +442,13 @@ export function string_to_user_seed_hex(input) {
673
442
  return getStringFromWasm0(r0, r1);
674
443
  } finally {
675
444
  wasm.__wbindgen_add_to_stack_pointer(16);
676
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
445
+ wasm.__wbindgen_export2(deferred2_0, deferred2_1, 1);
677
446
  }
678
447
  }
679
448
 
680
449
  function __wbg_get_imports() {
681
450
  const import0 = {
682
451
  __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
452
  __wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
691
453
  const ret = typeof(getObject(arg0)) === 'function';
692
454
  return ret;
@@ -730,10 +492,6 @@ function __wbg_get_imports() {
730
492
  const ret = getObject(arg0).msCrypto;
731
493
  return addHeapObject(ret);
732
494
  },
733
- __wbg_new_361308b2356cecd0: function() {
734
- const ret = new Object();
735
- return addHeapObject(ret);
736
- },
737
495
  __wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
738
496
  const ret = new Function(getStringFromWasm0(arg0, arg1));
739
497
  return addHeapObject(ret);
@@ -760,10 +518,6 @@ function __wbg_get_imports() {
760
518
  const ret = module.require;
761
519
  return addHeapObject(ret);
762
520
  }, 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
521
  __wbg_static_accessor_GLOBAL_12837167ad935116: function() {
768
522
  const ret = typeof global === 'undefined' ? null : global;
769
523
  return isLikeNone(ret) ? 0 : addHeapObject(ret);
@@ -821,71 +575,6 @@ function addHeapObject(obj) {
821
575
  return idx;
822
576
  }
823
577
 
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
578
  function dropObject(idx) {
890
579
  if (idx < 132) return;
891
580
  heap[idx] = heap_next;
@@ -950,7 +639,7 @@ function handleError(f, args) {
950
639
  try {
951
640
  return f.apply(this, args);
952
641
  } catch (e) {
953
- wasm.__wbindgen_export3(addHeapObject(e));
642
+ wasm.__wbindgen_export(addHeapObject(e));
954
643
  }
955
644
  }
956
645