@rolly-dev/wasm-signer 1.31.1 → 1.31.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1913 +0,0 @@
1
- /* @ts-self-types="./rolly_wasm_signer.d.ts" */
2
-
3
- /**
4
- * Split a u64 amount into (lo, hi) u32 pair matching the circuit representation.
5
- *
6
- * Returns `[amount_lo, amount_hi]` as a `Uint32Array` of length 2.
7
- *
8
- * ```js
9
- * const [lo, hi] = amount_split(123456789n);
10
- * ```
11
- * @param {bigint} amount
12
- * @returns {Uint32Array}
13
- */
14
- export function amount_split(amount) {
15
- try {
16
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
17
- wasm.amount_split(retptr, amount);
18
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
19
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
20
- var v1 = getArrayU32FromWasm0(r0, r1).slice();
21
- wasm.__wbindgen_export4(r0, r1 * 4, 4);
22
- return v1;
23
- } finally {
24
- wasm.__wbindgen_add_to_stack_pointer(16);
25
- }
26
- }
27
-
28
- /**
29
- * Backward-compatible alias for `crash_rtp_percent`.
30
- * @returns {number}
31
- */
32
- export function aviato_rtp_percent() {
33
- const ret = wasm.aviato_rtp_percent();
34
- return ret >>> 0;
35
- }
36
-
37
- /**
38
- * Reconstruct the 30 dealt Blackjack rank codes from the fairness seeds.
39
- *
40
- * This is the SINGLE client/backend-side mirror of the native shoe unfold in
41
- * `tx_validator::blackjack::unfold_shoe` and the in-circuit shuffle: it computes
42
- * `mix = Poseidon2(server_seed ‖ user_secret_random)` and the per-step swap
43
- * randomness `low32(Poseidon2(mix ‖ k))`, then defers the deterministic
44
- * 30-swap partial Fisher–Yates over the fixed 416-card layout to the pure
45
- * `rolly_game_core::blackjack::deal_shoe`. Mixing the player-chosen
46
- * `user_secret_random` into the seed makes the shuffle a mutual commit–reveal,
47
- * so neither the operator nor the player can pre-grind a shoe.
48
- *
49
- * `server_seed` must be 8 elements (the full fairness preimage); `user_secret_random`
50
- * must be 4 elements (`string_to_user_seed(user_seed_source)`).
51
- *
52
- * **Output**: `Uint8Array` of length 30 — rank codes `0..=12` (Ace=0, 2..9=1..8,
53
- * 10/J/Q/K=9..12). Suits are cosmetic and restored off-engine.
54
- *
55
- * ```js
56
- * const shoe = blackjack_deal_shoe(serverSeed8, userSecret4); // length 30
57
- * ```
58
- * @param {BigUint64Array} server_seed
59
- * @param {BigUint64Array} user_secret_random
60
- * @returns {Uint8Array}
61
- */
62
- export function blackjack_deal_shoe(server_seed, user_secret_random) {
63
- try {
64
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
65
- const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export);
66
- const len0 = WASM_VECTOR_LEN;
67
- const ptr1 = passArray64ToWasm0(user_secret_random, wasm.__wbindgen_export);
68
- const len1 = WASM_VECTOR_LEN;
69
- wasm.blackjack_deal_shoe(retptr, ptr0, len0, ptr1, len1);
70
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
71
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
72
- var v3 = getArrayU8FromWasm0(r0, r1).slice();
73
- wasm.__wbindgen_export4(r0, r1 * 1, 1);
74
- return v3;
75
- } finally {
76
- wasm.__wbindgen_add_to_stack_pointer(16);
77
- }
78
- }
79
-
80
- /**
81
- * Pack a Blackjack action sequence into the two base-8 halves the rollup records
82
- * as `prediction_lo` / `prediction_hi` (`actions[0..10]` → lo, `actions[10..20]`
83
- * → hi). Single-sources `rolly_game_core::blackjack::pack_actions` so the
84
- * backend feeds the WitnessEngine exactly what the circuit re-derives.
85
- *
86
- * `actions` are the `ACTION_*` codes (1..=6). **Output**: `Uint32Array` of
87
- * length 2 = `[prediction_lo, prediction_hi]`.
88
- * @param {Uint8Array} actions
89
- * @returns {Uint32Array}
90
- */
91
- export function blackjack_pack_actions(actions) {
92
- try {
93
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
94
- const ptr0 = passArray8ToWasm0(actions, wasm.__wbindgen_export);
95
- const len0 = WASM_VECTOR_LEN;
96
- wasm.blackjack_pack_actions(retptr, ptr0, len0);
97
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
98
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
99
- var v2 = getArrayU32FromWasm0(r0, r1).slice();
100
- wasm.__wbindgen_export4(r0, r1 * 4, 4);
101
- return v2;
102
- } finally {
103
- wasm.__wbindgen_add_to_stack_pointer(16);
104
- }
105
- }
106
-
107
- /**
108
- * CoinFlip multiplier × 10000 (19800 = 1.98×). Canonical source for backend/frontend.
109
- * @returns {number}
110
- */
111
- export function coinflip_multiplier_x10000() {
112
- const ret = wasm.coinflip_multiplier_x10000();
113
- return ret >>> 0;
114
- }
115
-
116
- /**
117
- * CoinFlip RTP percent (99). Canonical source for backend/frontend.
118
- * @returns {number}
119
- */
120
- export function coinflip_rtp_percent() {
121
- const ret = wasm.aviato_rtp_percent();
122
- return ret >>> 0;
123
- }
124
-
125
- /**
126
- * Compute address_hash = Poseidon2(addr_byte_0, ..., addr_byte_19).
127
- * Takes a hex address string (with or without 0x prefix), returns [u64; 4].
128
- * @param {string} address_hex
129
- * @returns {BigUint64Array}
130
- */
131
- export function compute_address_hash(address_hex) {
132
- try {
133
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
134
- const ptr0 = passStringToWasm0(address_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
135
- const len0 = WASM_VECTOR_LEN;
136
- wasm.compute_address_hash(retptr, ptr0, len0);
137
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
138
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
139
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
140
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
141
- return v2;
142
- } finally {
143
- wasm.__wbindgen_add_to_stack_pointer(16);
144
- }
145
- }
146
-
147
- /**
148
- * Backward-compatible alias for `compute_crash_point`.
149
- * @param {BigUint64Array} random
150
- * @returns {number}
151
- */
152
- export function compute_aviato_point(random) {
153
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
154
- const len0 = WASM_VECTOR_LEN;
155
- const ret = wasm.compute_aviato_point(ptr0, len0);
156
- return ret >>> 0;
157
- }
158
-
159
- /**
160
- * Extract crash point (×100) from raw server seed fields.
161
- *
162
- * `random` must be exactly 4 elements (first 4 fields of server_seed).
163
- * Returns the clamped crash multiplier ×100 (100..=1_000_000, i.e. 1.00x..10000.00x).
164
- * @param {BigUint64Array} random
165
- * @returns {number}
166
- */
167
- export function compute_crash_point(random) {
168
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
169
- const len0 = WASM_VECTOR_LEN;
170
- const ret = wasm.compute_crash_point(ptr0, len0);
171
- return ret >>> 0;
172
- }
173
-
174
- /**
175
- * Extract the 10 drawn numbers from Poseidon2 random output using
176
- * the combinatorial number system: `combo_index = random[0] % C(40,10)`.
177
- *
178
- * `random` must be exactly 4 elements.
179
- * Returns `Uint8Array` of length 10 (sorted ascending, each in [0, 39]).
180
- * @param {BigUint64Array} random
181
- * @returns {Uint8Array}
182
- */
183
- export function compute_drawn_keno(random) {
184
- try {
185
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
186
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
187
- const len0 = WASM_VECTOR_LEN;
188
- wasm.compute_drawn_keno(retptr, ptr0, len0);
189
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
190
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
191
- var v2 = getArrayU8FromWasm0(r0, r1).slice();
192
- wasm.__wbindgen_export4(r0, r1 * 1, 1);
193
- return v2;
194
- } finally {
195
- wasm.__wbindgen_add_to_stack_pointer(16);
196
- }
197
- }
198
-
199
- /**
200
- * Compute dice multiplier × 10000 from win_numbers count.
201
- *
202
- * Formula: `9_900_000 / win_numbers` (integer division = floor).
203
- * `win_numbers` must be in [1, 950].
204
- * @param {number} win_numbers
205
- * @returns {bigint}
206
- */
207
- export function compute_multi_dice(win_numbers) {
208
- const ret = wasm.compute_multi_dice(win_numbers);
209
- return BigInt.asUintN(64, ret);
210
- }
211
-
212
- /**
213
- * Backward-compatible alias for `compute_payout_crash`.
214
- * @param {BigUint64Array} random
215
- * @param {bigint} bet_atomic
216
- * @param {number} cashout_x100
217
- * @returns {BigUint64Array}
218
- */
219
- export function compute_payout_aviato(random, bet_atomic, cashout_x100) {
220
- try {
221
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
222
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
223
- const len0 = WASM_VECTOR_LEN;
224
- wasm.compute_payout_aviato(retptr, ptr0, len0, bet_atomic, cashout_x100);
225
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
226
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
227
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
228
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
229
- return v2;
230
- } finally {
231
- wasm.__wbindgen_add_to_stack_pointer(16);
232
- }
233
- }
234
-
235
- /**
236
- * Client-side provably-fair verification of a full Blackjack round.
237
- *
238
- * Reconstructs the fair shoe from `(server_seed ‖ user_secret_random)` (see
239
- * [`blackjack_deal_shoe`]), decodes the base-8 `prediction_lo` / `prediction_hi`
240
- * action halves, and replays the exact same state machine the circuit and the
241
- * tx-validator run (`rolly_game_core::blackjack::replay_full`). This lets a
242
- * player independently confirm the settled `win`/`bet` off-chain; it is NOT on
243
- * the tx/settlement path.
244
- *
245
- * `server_seed` must be 8 elements (the revealed fairness preimage);
246
- * `user_secret_random` must be 4 elements (`string_to_user_seed(...)`).
247
- * `base_bet` is the base stake in atomic units. The returned `total_staked`
248
- * grows with double/split/insurance exactly as the engine books them.
249
- *
250
- * **Output**: a JS object matching [`BlackjackVerifyResult`].
251
- *
252
- * Returns an error if the decoded action list contains an invalid code
253
- * (outside `1..=6`), mirroring the tx-validator's typed rejection.
254
- *
255
- * ```js
256
- * const res = compute_payout_blackjack(serverSeed8, userSecret4, lo, hi, betAtomic);
257
- * // res.win_amount, res.total_staked, res.shoe (length 30),
258
- * // res.first_cards / res.second_cards / res.dealer_cards (rank codes),
259
- * // res.first_kind / res.second_kind (per-hand type: 0=bet,1=hit,2=stand,
260
- * // 3=double,4=split,5=insurance; a closed hand reports 2),
261
- * // res.first_amount / res.second_amount (per-hand staked, atomic),
262
- * // res.first_win / res.second_win (per-hand win, atomic, pre-cap), ...
263
- * ```
264
- * @param {BigUint64Array} server_seed
265
- * @param {BigUint64Array} user_secret_random
266
- * @param {number} prediction_lo
267
- * @param {number} prediction_hi
268
- * @param {bigint} base_bet
269
- * @returns {any}
270
- */
271
- export function compute_payout_blackjack(server_seed, user_secret_random, prediction_lo, prediction_hi, base_bet) {
272
- try {
273
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
274
- const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export);
275
- const len0 = WASM_VECTOR_LEN;
276
- const ptr1 = passArray64ToWasm0(user_secret_random, wasm.__wbindgen_export);
277
- const len1 = WASM_VECTOR_LEN;
278
- wasm.compute_payout_blackjack(retptr, ptr0, len0, ptr1, len1, prediction_lo, prediction_hi, base_bet);
279
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
280
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
281
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
282
- if (r2) {
283
- throw takeObject(r1);
284
- }
285
- return takeObject(r0);
286
- } finally {
287
- wasm.__wbindgen_add_to_stack_pointer(16);
288
- }
289
- }
290
-
291
- /**
292
- * Full coinflip payout computation — pure integer arithmetic, zero floats.
293
- *
294
- * `random`: 4 Goldilocks field elements (Poseidon2 output).
295
- * `bet_atomic`: bet in atomic units (1 USDT = 1_000_000).
296
- * `prediction`: 0 or 1.
297
- *
298
- * Returns `BigUint64Array[4]`: `[win_amount, roll (0|1), is_win (0|1), multiplier×10000]`.
299
- * @param {BigUint64Array} random
300
- * @param {bigint} bet_atomic
301
- * @param {number} prediction
302
- * @returns {BigUint64Array}
303
- */
304
- export function compute_payout_coinflip(random, bet_atomic, prediction) {
305
- try {
306
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
307
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
308
- const len0 = WASM_VECTOR_LEN;
309
- wasm.compute_payout_coinflip(retptr, ptr0, len0, bet_atomic, prediction);
310
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
311
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
312
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
313
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
314
- return v2;
315
- } finally {
316
- wasm.__wbindgen_add_to_stack_pointer(16);
317
- }
318
- }
319
-
320
- /**
321
- * Full crash payout computation — pure integer arithmetic, zero floats.
322
- *
323
- * `random`: 4 Goldilocks field elements (first 4 fields of raw server_seed).
324
- * `bet_atomic`: bet in atomic units (1 USDT = 1_000_000).
325
- * `cashout_x100`: multiplier at which the user cashed out (×100).
326
- * - 0 = user did NOT cash out (loss).
327
- * - 100..=1_000_000 = user stopped at this multiplier.
328
- *
329
- * Returns `BigUint64Array[4]`: `[win_amount, crash_x100, is_win (0|1), multiplier×10000]`.
330
- * @param {BigUint64Array} random
331
- * @param {bigint} bet_atomic
332
- * @param {number} cashout_x100
333
- * @returns {BigUint64Array}
334
- */
335
- export function compute_payout_crash(random, bet_atomic, cashout_x100) {
336
- try {
337
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
338
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
339
- const len0 = WASM_VECTOR_LEN;
340
- wasm.compute_payout_crash(retptr, ptr0, len0, bet_atomic, cashout_x100);
341
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
342
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
343
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
344
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
345
- return v2;
346
- } finally {
347
- wasm.__wbindgen_add_to_stack_pointer(16);
348
- }
349
- }
350
-
351
- /**
352
- * Full dice payout computation — pure integer arithmetic, zero floats.
353
- *
354
- * `random`: 4 Goldilocks field elements (Poseidon2 output).
355
- * `bet_atomic`: bet in atomic units (1 USDT = 1_000_000).
356
- * `game_mode`: 0=Under, 1=Over, 2=In, 3=Out.
357
- * `prediction_lo` / `prediction_hi`: prediction range bounds (0..999).
358
- *
359
- * Returns `BigUint64Array[4]`: `[win_amount, roll_number, is_win (0|1), multiplier×10000]`.
360
- * @param {BigUint64Array} random
361
- * @param {bigint} bet_atomic
362
- * @param {number} game_mode
363
- * @param {number} prediction_lo
364
- * @param {number} prediction_hi
365
- * @returns {BigUint64Array}
366
- */
367
- export function compute_payout_dice(random, bet_atomic, game_mode, prediction_lo, prediction_hi) {
368
- try {
369
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
370
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
371
- const len0 = WASM_VECTOR_LEN;
372
- wasm.compute_payout_dice(retptr, ptr0, len0, bet_atomic, game_mode, prediction_lo, prediction_hi);
373
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
374
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
375
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
376
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
377
- return v2;
378
- } finally {
379
- wasm.__wbindgen_add_to_stack_pointer(16);
380
- }
381
- }
382
-
383
- /**
384
- * Full keno payout computation — pure integer arithmetic, zero floats.
385
- *
386
- * `random`: 4 Goldilocks field elements (Poseidon2 output).
387
- * `bet_atomic`: bet in atomic units (1 USDT = 1_000_000).
388
- * `risk`: 0=low, 1=medium, 2=high.
389
- * `selected`: player-chosen numbers (0-indexed, each in [0, 39]).
390
- *
391
- * Returns `BigUint64Array[4]`: `[win_amount, match_count, is_win (0|1), multiplier×10000]`.
392
- * @param {BigUint64Array} random
393
- * @param {bigint} bet_atomic
394
- * @param {number} risk
395
- * @param {Uint8Array} selected
396
- * @returns {BigUint64Array}
397
- */
398
- export function compute_payout_keno(random, bet_atomic, risk, selected) {
399
- try {
400
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
401
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
402
- const len0 = WASM_VECTOR_LEN;
403
- const ptr1 = passArray8ToWasm0(selected, wasm.__wbindgen_export);
404
- const len1 = WASM_VECTOR_LEN;
405
- wasm.compute_payout_keno(retptr, ptr0, len0, bet_atomic, risk, ptr1, len1);
406
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
407
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
408
- var v3 = getArrayU64FromWasm0(r0, r1).slice();
409
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
410
- return v3;
411
- } finally {
412
- wasm.__wbindgen_add_to_stack_pointer(16);
413
- }
414
- }
415
-
416
- /**
417
- * Full limbo payout computation — pure integer arithmetic, zero floats.
418
- *
419
- * `random`: 4 Goldilocks field elements (Poseidon2 output).
420
- * `bet_atomic`: bet in atomic units (1 USDT = 1_000_000).
421
- * `prediction_x100`: target multiplier x 100 (101..999999, i.e. 1.01x-9999.99x).
422
- *
423
- * Returns `BigUint64Array[4]`: `[win_amount, multiplier_x100, is_win (0|1), payout_multiplier x10000]`.
424
- * @param {BigUint64Array} random
425
- * @param {bigint} bet_atomic
426
- * @param {number} prediction_x100
427
- * @returns {BigUint64Array}
428
- */
429
- export function compute_payout_limbo(random, bet_atomic, prediction_x100) {
430
- try {
431
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
432
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
433
- const len0 = WASM_VECTOR_LEN;
434
- wasm.compute_payout_limbo(retptr, ptr0, len0, bet_atomic, prediction_x100);
435
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
436
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
437
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
438
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
439
- return v2;
440
- } finally {
441
- wasm.__wbindgen_add_to_stack_pointer(16);
442
- }
443
- }
444
-
445
- /**
446
- * Full plinko payout computation — pure integer arithmetic, zero floats.
447
- *
448
- * `random`: 4 Goldilocks field elements (Poseidon2 output).
449
- * `bet_atomic`: bet in atomic units (1 USDT = 1_000_000).
450
- * `sector`: risk profile (0=low, 1=medium, 2=high).
451
- * `rows`: number of pin rows (8..16).
452
- * `is_extreme`: whether extreme mode is active.
453
- *
454
- * Returns `BigUint64Array[4]`: `[win_amount, bucket_index, is_win (0|1), multiplier×10000]`.
455
- * @param {BigUint64Array} random
456
- * @param {bigint} bet_atomic
457
- * @param {number} sector
458
- * @param {number} rows
459
- * @param {boolean} is_extreme
460
- * @returns {BigUint64Array}
461
- */
462
- export function compute_payout_plinko(random, bet_atomic, sector, rows, is_extreme) {
463
- try {
464
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
465
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
466
- const len0 = WASM_VECTOR_LEN;
467
- wasm.compute_payout_plinko(retptr, ptr0, len0, bet_atomic, sector, rows, is_extreme);
468
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
469
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
470
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
471
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
472
- return v2;
473
- } finally {
474
- wasm.__wbindgen_add_to_stack_pointer(16);
475
- }
476
- }
477
-
478
- /**
479
- * Compute prediction hash: `Poseidon2(game_id, p0, p1, p2)` → 4 field elements.
480
- *
481
- * Matches `compute_prediction_hash_native` in the circuit (`games/shared.rs`)
482
- * and the in-circuit `build_prediction_hash`.
483
- *
484
- * Semantics of p0–p2 depend on the game:
485
- * Limbo: `(98, prediction_x100, 0)` — RTP hardcoded at 98
486
- * Dice: `(mode, pred_lo, pred_hi)`
487
- * Plinko: `(sector, rows, is_extreme)`
488
- * CoinFlip: `(prediction, 0, 0)`
489
- * @param {number} game_id
490
- * @param {number} p0
491
- * @param {number} p1
492
- * @param {number} p2
493
- * @returns {BigUint64Array}
494
- */
495
- export function compute_prediction_hash(game_id, p0, p1, p2) {
496
- try {
497
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
498
- wasm.compute_prediction_hash(retptr, game_id, p0, p1, p2);
499
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
500
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
501
- var v1 = getArrayU64FromWasm0(r0, r1).slice();
502
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
503
- return v1;
504
- } finally {
505
- wasm.__wbindgen_add_to_stack_pointer(16);
506
- }
507
- }
508
-
509
- /**
510
- * Compute Keno prediction hash with extended 13-input format:
511
- * `Poseidon2(game_id, risk, pick_count, selected[0], …, selected[9])`.
512
- *
513
- * Selected numbers are sorted internally for deterministic output.
514
- * Unused slots (when pick_count < 10) are filled with 0.
515
- *
516
- * Returns `BigUint64Array` of length 4 (one `HashOut`).
517
- * @param {number} game_id
518
- * @param {number} risk
519
- * @param {number} pick_count
520
- * @param {Uint8Array} selected
521
- * @returns {BigUint64Array}
522
- */
523
- export function compute_prediction_hash_keno(game_id, risk, pick_count, selected) {
524
- try {
525
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
526
- const ptr0 = passArray8ToWasm0(selected, wasm.__wbindgen_export);
527
- const len0 = WASM_VECTOR_LEN;
528
- wasm.compute_prediction_hash_keno(retptr, game_id, risk, pick_count, ptr0, len0);
529
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
530
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
531
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
532
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
533
- return v2;
534
- } finally {
535
- wasm.__wbindgen_add_to_stack_pointer(16);
536
- }
537
- }
538
-
539
- /**
540
- * Extract coinflip roll (0 or 1) from Poseidon2 random output.
541
- *
542
- * `random` must be exactly 4 elements. Returns `random[0] % 2`.
543
- * @param {BigUint64Array} random
544
- * @returns {number}
545
- */
546
- export function compute_roll_coinflip(random) {
547
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
548
- const len0 = WASM_VECTOR_LEN;
549
- const ret = wasm.compute_roll_coinflip(ptr0, len0);
550
- return ret >>> 0;
551
- }
552
-
553
- /**
554
- * Extract dice roll number [0, 1000) from Poseidon2 random output.
555
- *
556
- * `random` must be exactly 4 elements. Returns `random[0] % 1000`.
557
- * @param {BigUint64Array} random
558
- * @returns {number}
559
- */
560
- export function compute_roll_dice(random) {
561
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
562
- const len0 = WASM_VECTOR_LEN;
563
- const ret = wasm.compute_roll_dice(ptr0, len0);
564
- return ret >>> 0;
565
- }
566
-
567
- /**
568
- * Extract limbo result multiplier x 100 from Poseidon2 random output.
569
- *
570
- * `random` must be exactly 4 elements.
571
- * Returns the clamped multiplier x 100 (101..999999).
572
- * @param {BigUint64Array} random
573
- * @returns {number}
574
- */
575
- export function compute_roll_limbo(random) {
576
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
577
- const len0 = WASM_VECTOR_LEN;
578
- const ret = wasm.compute_roll_limbo(ptr0, len0);
579
- return ret >>> 0;
580
- }
581
-
582
- /**
583
- * Extract plinko bucket index from Poseidon2 random output.
584
- *
585
- * `random` must be exactly 4 elements.
586
- * `rows` must be in [8, 16].
587
- * Returns the bucket index (0..=rows) = popcount of first `rows` bits of random[0].
588
- * @param {BigUint64Array} random
589
- * @param {number} rows
590
- * @returns {number}
591
- */
592
- export function compute_roll_plinko(random, rows) {
593
- const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export);
594
- const len0 = WASM_VECTOR_LEN;
595
- const ret = wasm.compute_roll_plinko(ptr0, len0, rows);
596
- return ret >>> 0;
597
- }
598
-
599
- /**
600
- * Full Poseidon2 hash of an 8-element server seed.
601
- *
602
- * Returns all 4 hash elements. Note: the circuit stores only the
603
- * **first 3 elements** as the leaf commitment (see `seed_hash_truncated`).
604
- * This full variant is useful for client-side verification where all
605
- * 4 elements may be needed.
606
- *
607
- * `server_seed` must be exactly 8 elements.
608
- * @param {BigUint64Array} server_seed
609
- * @returns {BigUint64Array}
610
- */
611
- export function compute_server_seed_hash(server_seed) {
612
- try {
613
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
614
- const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export);
615
- const len0 = WASM_VECTOR_LEN;
616
- wasm.compute_server_seed_hash(retptr, ptr0, len0);
617
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
618
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
619
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
620
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
621
- return v2;
622
- } finally {
623
- wasm.__wbindgen_add_to_stack_pointer(16);
624
- }
625
- }
626
-
627
- /**
628
- * Compute user seed with bet-parameter binding:
629
- * `Poseidon2(game_id, bet, pred_hash[4], secret[4])` → 4 field elements.
630
- *
631
- * Matches the circuit constraint in `slot/fairness.rs`.
632
- * Prevents the operator from swapping bet parameters after the user commits.
633
- *
634
- * `bet` is the full bet amount in atomic units (u64).
635
- * `pred_hash` must be 4 elements (output of `compute_prediction_hash`).
636
- * `secret` must be 4 elements (output of `generate_user_secret`).
637
- * @param {number} game_id
638
- * @param {bigint} bet
639
- * @param {BigUint64Array} pred_hash
640
- * @param {BigUint64Array} secret
641
- * @returns {BigUint64Array}
642
- */
643
- export function compute_user_seed_binding(game_id, bet, pred_hash, secret) {
644
- try {
645
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
646
- const ptr0 = passArray64ToWasm0(pred_hash, wasm.__wbindgen_export);
647
- const len0 = WASM_VECTOR_LEN;
648
- const ptr1 = passArray64ToWasm0(secret, wasm.__wbindgen_export);
649
- const len1 = WASM_VECTOR_LEN;
650
- wasm.compute_user_seed_binding(retptr, game_id, bet, ptr0, len0, ptr1, len1);
651
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
652
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
653
- var v3 = getArrayU64FromWasm0(r0, r1).slice();
654
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
655
- return v3;
656
- } finally {
657
- wasm.__wbindgen_add_to_stack_pointer(16);
658
- }
659
- }
660
-
661
- /**
662
- * Crash RTP percent (99). Canonical source for backend/frontend.
663
- * @returns {number}
664
- */
665
- export function crash_rtp_percent() {
666
- const ret = wasm.aviato_rtp_percent();
667
- return ret >>> 0;
668
- }
669
-
670
- /**
671
- * Derive a session key from 32 bytes of entropy (e.g. MetaMask signature).
672
- *
673
- * **Algorithm**: split 32 bytes into 4 × 8 bytes, interpret each chunk as
674
- * little-endian u64, reduce mod p, then hash:
675
- * `session_key = Poseidon2(reduced_chunks)`
676
- *
677
- * The reduction via `from_noncanonical_u64` is necessary because raw
678
- * signature bytes can produce values >= p.
679
- *
680
- * ```js
681
- * const sig = ethers.getBytes(metaMaskSignature).slice(0, 32);
682
- * const sk = derive_session_key(new Uint8Array(sig));
683
- * // sk.length === 4
684
- * ```
685
- * @param {Uint8Array} sig_bytes
686
- * @returns {BigUint64Array}
687
- */
688
- export function derive_session_key(sig_bytes) {
689
- try {
690
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
691
- const ptr0 = passArray8ToWasm0(sig_bytes, wasm.__wbindgen_export);
692
- const len0 = WASM_VECTOR_LEN;
693
- wasm.derive_session_key(retptr, ptr0, len0);
694
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
695
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
696
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
697
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
698
- return v2;
699
- } finally {
700
- wasm.__wbindgen_add_to_stack_pointer(16);
701
- }
702
- }
703
-
704
- /**
705
- * Dice RTP percent (99). Canonical source for backend/frontend.
706
- * @returns {number}
707
- */
708
- export function dice_rtp_percent() {
709
- const ret = wasm.aviato_rtp_percent();
710
- return ret >>> 0;
711
- }
712
-
713
- /**
714
- * Encode 1-indexed Keno selected numbers into a bitmask pair `[lo, hi]`.
715
- *
716
- * `selected_1indexed`: player-chosen numbers as they come from the frontend (1..40).
717
- * Returns `Uint32Array[2]`: `[lo, hi]` where `lo` covers numbers 0..29 and `hi` covers 30..39
718
- * (0-indexed bit positions).
719
- * @param {Uint8Array} selected_1indexed
720
- * @returns {Uint32Array}
721
- */
722
- export function encode_keno_selected(selected_1indexed) {
723
- try {
724
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
725
- const ptr0 = passArray8ToWasm0(selected_1indexed, wasm.__wbindgen_export);
726
- const len0 = WASM_VECTOR_LEN;
727
- wasm.encode_keno_selected(retptr, ptr0, len0);
728
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
729
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
730
- var v2 = getArrayU32FromWasm0(r0, r1).slice();
731
- wasm.__wbindgen_export4(r0, r1 * 4, 4);
732
- return v2;
733
- } finally {
734
- wasm.__wbindgen_add_to_stack_pointer(16);
735
- }
736
- }
737
-
738
- /**
739
- * Generate a cryptographically random user secret — 4 Goldilocks field elements.
740
- *
741
- * Each element is reduced mod p for canonical representation (safe for circuit use).
742
- * Uses `getrandom` (`crypto.getRandomValues` in browser, OS entropy in Node.js).
743
- *
744
- * ```js
745
- * const secret = generate_user_secret();
746
- * // secret.length === 4, each < GOLDILOCKS_P
747
- * ```
748
- * @returns {BigUint64Array}
749
- */
750
- export function generate_user_secret() {
751
- try {
752
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
753
- wasm.generate_user_secret(retptr);
754
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
755
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
756
- var v1 = getArrayU64FromWasm0(r0, r1).slice();
757
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
758
- return v1;
759
- } finally {
760
- wasm.__wbindgen_add_to_stack_pointer(16);
761
- }
762
- }
763
-
764
- /**
765
- * Generate a random user seed — 10 alphanumeric characters.
766
- *
767
- * Uses `getrandom` (backed by `crypto.getRandomValues` in the browser
768
- * and OS entropy on Node.js) for cryptographically secure randomness.
769
- *
770
- * ```js
771
- * const seed = generate_user_seed();
772
- * // e.g. "k7Qm2xW9aB"
773
- * ```
774
- * @returns {string}
775
- */
776
- export function generate_user_seed() {
777
- let deferred1_0;
778
- let deferred1_1;
779
- try {
780
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
781
- wasm.generate_user_seed(retptr);
782
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
783
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
784
- deferred1_0 = r0;
785
- deferred1_1 = r1;
786
- return getStringFromWasm0(r0, r1);
787
- } finally {
788
- wasm.__wbindgen_add_to_stack_pointer(16);
789
- wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
790
- }
791
- }
792
-
793
- /**
794
- * Convert any Goldilocks field elements to a hex string.
795
- *
796
- * Each u64 is encoded as 8 little-endian bytes → 16 hex chars.
797
- * For 4 elements: 64 hex chars (32 bytes).
798
- *
799
- * ```js
800
- * const hex = goldilocks_fields_to_hex(BigUint64Array.from([1n, 2n, 3n, 4n]));
801
- * ```
802
- * @param {BigUint64Array} fields
803
- * @returns {string}
804
- */
805
- export function goldilocks_fields_to_hex(fields) {
806
- let deferred2_0;
807
- let deferred2_1;
808
- try {
809
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
810
- const ptr0 = passArray64ToWasm0(fields, wasm.__wbindgen_export);
811
- const len0 = WASM_VECTOR_LEN;
812
- wasm.goldilocks_fields_to_hex(retptr, ptr0, len0);
813
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
814
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
815
- deferred2_0 = r0;
816
- deferred2_1 = r1;
817
- return getStringFromWasm0(r0, r1);
818
- } finally {
819
- wasm.__wbindgen_add_to_stack_pointer(16);
820
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
821
- }
822
- }
823
-
824
- /**
825
- * Returns the Goldilocks prime: p = 2^64 - 2^32 + 1.
826
- * @returns {bigint}
827
- */
828
- export function goldilocks_modulus() {
829
- const ret = wasm.goldilocks_modulus();
830
- return BigInt.asUintN(64, ret);
831
- }
832
-
833
- /**
834
- * Reduce an arbitrary u64 to its canonical representative mod p.
835
- *
836
- * Values already < p are returned unchanged. Values >= p are reduced.
837
- * This uses `from_noncanonical_u64` internally (no panic on large values).
838
- * @param {bigint} value
839
- * @returns {bigint}
840
- */
841
- export function goldilocks_reduce(value) {
842
- const ret = wasm.goldilocks_reduce(value);
843
- return BigInt.asUintN(64, ret);
844
- }
845
-
846
- /**
847
- * Hash a raw 7-element balance leaf → 4-element Merkle node.
848
- *
849
- * Raw layout: `[balance_lo, balance_hi, seed_hash_0, seed_hash_1, seed_hash_2, credit_lo, credit_hi]`
850
- *
851
- * Identical to `hash_balance_leaf` in `prover/circuit/src/helpers/leaf_ops.rs`.
852
- *
853
- * **Input** : `BigUint64Array` of exactly 7 elements (each < `GOLDILOCKS_P`).
854
- * **Output**: `BigUint64Array` of length 4 (one `HashOut`).
855
- *
856
- * ```js
857
- * const raw = BigUint64Array.from([balLo, balHi, seed0, seed1, seed2, credLo, credHi]);
858
- * const balanceHash = hash_balance_leaf(raw); // length 4
859
- * ```
860
- * @param {BigUint64Array} raw
861
- * @returns {BigUint64Array}
862
- */
863
- export function hash_balance_leaf(raw) {
864
- try {
865
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
866
- const ptr0 = passArray64ToWasm0(raw, wasm.__wbindgen_export);
867
- const len0 = WASM_VECTOR_LEN;
868
- wasm.hash_balance_leaf(retptr, ptr0, len0);
869
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
870
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
871
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
872
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
873
- return v2;
874
- } finally {
875
- wasm.__wbindgen_add_to_stack_pointer(16);
876
- }
877
- }
878
-
879
- /**
880
- * RTP × 100 for ALL valid Keno configs.
881
- * Returns JS object: `{ "0_1": 9450, "0_2": 9712, ..., "2_10": 9580 }`
882
- * Keys: `"{risk}_{pick_count}"`.
883
- * @returns {any}
884
- */
885
- export function keno_all_rtp_x100() {
886
- const ret = wasm.keno_all_rtp_x100();
887
- return takeObject(ret);
888
- }
889
-
890
- /**
891
- * @returns {number}
892
- */
893
- export function keno_draw_count() {
894
- const ret = wasm.keno_draw_count();
895
- return ret >>> 0;
896
- }
897
-
898
- /**
899
- * Whether a (risk, pick_count) pair is a valid Keno config.
900
- * @param {number} risk
901
- * @param {number} pick_count
902
- * @returns {boolean}
903
- */
904
- export function keno_is_valid_config(risk, pick_count) {
905
- const ret = wasm.keno_is_valid_config(risk, pick_count);
906
- return ret !== 0;
907
- }
908
-
909
- /**
910
- * @returns {number}
911
- */
912
- export function keno_max_picks() {
913
- const ret = wasm.keno_draw_count();
914
- return ret >>> 0;
915
- }
916
-
917
- /**
918
- * Returns the multiplier table (×10000) for the given Keno config.
919
- * `risk`: 0=low, 1=medium, 2=high. `pick_count`: 1..10.
920
- * Length = pick_count + 1. Returns empty vec for invalid combos.
921
- * @param {number} risk
922
- * @param {number} pick_count
923
- * @returns {BigUint64Array}
924
- */
925
- export function keno_multiplier_table(risk, pick_count) {
926
- try {
927
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
928
- wasm.keno_multiplier_table(retptr, risk, pick_count);
929
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
930
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
931
- var v1 = getArrayU64FromWasm0(r0, r1).slice();
932
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
933
- return v1;
934
- } finally {
935
- wasm.__wbindgen_add_to_stack_pointer(16);
936
- }
937
- }
938
-
939
- /**
940
- * @returns {number}
941
- */
942
- export function keno_numbers_range() {
943
- const ret = wasm.keno_numbers_range();
944
- return ret >>> 0;
945
- }
946
-
947
- /**
948
- * RTP × 100 for a Keno config (e.g. 9800 = 98.00%). Returns 0 for invalid combos.
949
- * @param {number} risk
950
- * @param {number} pick_count
951
- * @returns {bigint}
952
- */
953
- export function keno_rtp_x100(risk, pick_count) {
954
- const ret = wasm.keno_rtp_x100(risk, pick_count);
955
- return BigInt.asUintN(64, ret);
956
- }
957
-
958
- /**
959
- * Limbo RTP percent (98). Canonical source for backend/frontend.
960
- * @returns {number}
961
- */
962
- export function limbo_rtp_percent() {
963
- const ret = wasm.limbo_rtp_percent();
964
- return ret >>> 0;
965
- }
966
-
967
- /**
968
- * Build a main Merkle tree leaf from balance_hash, pk_hash, and address_hash.
969
- *
970
- * `main_leaf = Poseidon2(balance_hash[4] || pk_hash[0..2] || address_hash[0..2])`
971
- *
972
- * Uses truncated (128-bit) pk/address hashes to keep the preimage at 8 elements
973
- * (single Poseidon2 permutation round). Identical to `make_main_leaf` in
974
- * `prover/circuit/src/helpers/leaf_ops.rs`.
975
- *
976
- * All three inputs must be exactly 4 elements.
977
- * **Output**: `BigUint64Array` of length 4 (the Merkle leaf hash).
978
- *
979
- * ```js
980
- * const leaf = make_main_leaf(balanceHash, pkHash, addressHash);
981
- * ```
982
- * @param {BigUint64Array} balance_hash
983
- * @param {BigUint64Array} pk_hash
984
- * @param {BigUint64Array} address_hash
985
- * @returns {BigUint64Array}
986
- */
987
- export function make_main_leaf(balance_hash, pk_hash, address_hash) {
988
- try {
989
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
990
- const ptr0 = passArray64ToWasm0(balance_hash, wasm.__wbindgen_export);
991
- const len0 = WASM_VECTOR_LEN;
992
- const ptr1 = passArray64ToWasm0(pk_hash, wasm.__wbindgen_export);
993
- const len1 = WASM_VECTOR_LEN;
994
- const ptr2 = passArray64ToWasm0(address_hash, wasm.__wbindgen_export);
995
- const len2 = WASM_VECTOR_LEN;
996
- wasm.make_main_leaf(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
997
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
998
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
999
- var v4 = getArrayU64FromWasm0(r0, r1).slice();
1000
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
1001
- return v4;
1002
- } finally {
1003
- wasm.__wbindgen_add_to_stack_pointer(16);
1004
- }
1005
- }
1006
-
1007
- /**
1008
- * RTP × 100 for ALL valid Plinko configs.
1009
- * Returns JS object: `{ "0_8_normal": 9799, "1_12_extreme": 9881, ... }`
1010
- * @returns {any}
1011
- */
1012
- export function plinko_all_rtp_x100() {
1013
- const ret = wasm.plinko_all_rtp_x100();
1014
- return takeObject(ret);
1015
- }
1016
-
1017
- /**
1018
- * Whether a (sector, rows, is_extreme) triple is a valid Plinko config.
1019
- * @param {number} sector
1020
- * @param {number} rows
1021
- * @param {boolean} is_extreme
1022
- * @returns {boolean}
1023
- */
1024
- export function plinko_is_valid_config(sector, rows, is_extreme) {
1025
- const ret = wasm.plinko_is_valid_config(sector, rows, is_extreme);
1026
- return ret !== 0;
1027
- }
1028
-
1029
- /**
1030
- * Whether rows is within the valid Plinko range [8, 16].
1031
- * @param {number} rows
1032
- * @returns {boolean}
1033
- */
1034
- export function plinko_is_valid_rows(rows) {
1035
- const ret = wasm.plinko_is_valid_rows(rows);
1036
- return ret !== 0;
1037
- }
1038
-
1039
- /**
1040
- * @returns {number}
1041
- */
1042
- export function plinko_max_rows() {
1043
- const ret = wasm.plinko_max_rows();
1044
- return ret >>> 0;
1045
- }
1046
-
1047
- /**
1048
- * @returns {number}
1049
- */
1050
- export function plinko_min_rows() {
1051
- const ret = wasm.plinko_min_rows();
1052
- return ret >>> 0;
1053
- }
1054
-
1055
- /**
1056
- * Returns the multiplier table (×10000) for the given Plinko config.
1057
- * Length = rows + 1. Returns empty vec for invalid combos.
1058
- * @param {number} sector
1059
- * @param {number} rows
1060
- * @param {boolean} is_extreme
1061
- * @returns {BigUint64Array}
1062
- */
1063
- export function plinko_multiplier_table(sector, rows, is_extreme) {
1064
- try {
1065
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1066
- wasm.plinko_multiplier_table(retptr, sector, rows, is_extreme);
1067
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1068
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1069
- var v1 = getArrayU64FromWasm0(r0, r1).slice();
1070
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
1071
- return v1;
1072
- } finally {
1073
- wasm.__wbindgen_add_to_stack_pointer(16);
1074
- }
1075
- }
1076
-
1077
- /**
1078
- * @returns {number}
1079
- */
1080
- export function plinko_num_sectors() {
1081
- const ret = wasm.plinko_num_sectors();
1082
- return ret;
1083
- }
1084
-
1085
- /**
1086
- * RTP × 100 for a Plinko config (e.g. 9799 = 97.99%). Returns 0 for invalid combos.
1087
- * @param {number} sector
1088
- * @param {number} rows
1089
- * @param {boolean} is_extreme
1090
- * @returns {bigint}
1091
- */
1092
- export function plinko_rtp_x100(sector, rows, is_extreme) {
1093
- const ret = wasm.plinko_rtp_x100(sector, rows, is_extreme);
1094
- return BigInt.asUintN(64, ret);
1095
- }
1096
-
1097
- /**
1098
- * Poseidon2 hash of an arbitrary number of Goldilocks field elements.
1099
- *
1100
- * Mirrors `builder.hash_n_to_hash_no_pad::<Poseidon2Hash>(...)` inside
1101
- * the circuit and `Poseidon2Hash::hash_no_pad` in `src/block_builder`.
1102
- *
1103
- * **Input** : `BigUint64Array` — each element must be < `GOLDILOCKS_P`.
1104
- * **Output**: `BigUint64Array` of length 4 (one `HashOut`).
1105
- *
1106
- * ```js
1107
- * const h = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
1108
- * // h.length === 4
1109
- * ```
1110
- * @param {BigUint64Array} input
1111
- * @returns {BigUint64Array}
1112
- */
1113
- export function poseidon2_hash(input) {
1114
- try {
1115
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1116
- const ptr0 = passArray64ToWasm0(input, wasm.__wbindgen_export);
1117
- const len0 = WASM_VECTOR_LEN;
1118
- wasm.poseidon2_hash(retptr, ptr0, len0);
1119
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1120
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1121
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
1122
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
1123
- return v2;
1124
- } finally {
1125
- wasm.__wbindgen_add_to_stack_pointer(16);
1126
- }
1127
- }
1128
-
1129
- /**
1130
- * Merkle-tree hash: Poseidon2(left[4] ‖ right[4]).
1131
- *
1132
- * Identical to `poseidon_hash(left, right)` in `src/merkletree/hash.rs`.
1133
- * Input ordering is critical — `left` concatenated before `right`.
1134
- *
1135
- * Both arrays **must** have exactly 4 elements (one `HashOut` each).
1136
- * @param {BigUint64Array} left
1137
- * @param {BigUint64Array} right
1138
- * @returns {BigUint64Array}
1139
- */
1140
- export function poseidon2_two_to_one(left, right) {
1141
- try {
1142
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1143
- const ptr0 = passArray64ToWasm0(left, wasm.__wbindgen_export);
1144
- const len0 = WASM_VECTOR_LEN;
1145
- const ptr1 = passArray64ToWasm0(right, wasm.__wbindgen_export);
1146
- const len1 = WASM_VECTOR_LEN;
1147
- wasm.poseidon2_two_to_one(retptr, ptr0, len0, ptr1, len1);
1148
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1149
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1150
- var v3 = getArrayU64FromWasm0(r0, r1).slice();
1151
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
1152
- return v3;
1153
- } finally {
1154
- wasm.__wbindgen_add_to_stack_pointer(16);
1155
- }
1156
- }
1157
-
1158
- /**
1159
- * Truncated seed hash — first 3 elements of `Poseidon2(server_seed)`.
1160
- *
1161
- * 192 bits of commitment → ~96-bit collision resistance, which closes the
1162
- * multi-preimage grinding vector that an earlier 128-bit truncation left open.
1163
- * This is the exact format stored in the Merkle-tree leaf and verified
1164
- * by the circuit. Matches `seed_hash_truncated` in
1165
- * `src/block_builder/builder.rs` and `src/circuit/slot/fairness.rs`.
1166
- *
1167
- * Returns `BigUint64Array` of length 3: `[h[0], h[1], h[2]]`.
1168
- * @param {BigUint64Array} server_seed
1169
- * @returns {BigUint64Array}
1170
- */
1171
- export function seed_hash_truncated(server_seed) {
1172
- try {
1173
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1174
- const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export);
1175
- const len0 = WASM_VECTOR_LEN;
1176
- wasm.seed_hash_truncated(retptr, ptr0, len0);
1177
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1178
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1179
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
1180
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
1181
- return v2;
1182
- } finally {
1183
- wasm.__wbindgen_add_to_stack_pointer(16);
1184
- }
1185
- }
1186
-
1187
- /**
1188
- * Compute the public key for a session: `pk_hash = Poseidon2(session_key[4], expiry)`.
1189
- *
1190
- * The public key hash is stored in the user-asset Merkle leaf and verified
1191
- * inside the circuit (the prover must know the preimage `session_key` + `expiry`).
1192
- *
1193
- * `session_key` must be exactly 4 elements (output of `derive_session_key`).
1194
- * `session_expiry` is the Unix timestamp after which the session is invalid.
1195
- * @param {BigUint64Array} session_key
1196
- * @param {bigint} session_expiry
1197
- * @returns {BigUint64Array}
1198
- */
1199
- export function session_public_key(session_key, session_expiry) {
1200
- try {
1201
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1202
- const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export);
1203
- const len0 = WASM_VECTOR_LEN;
1204
- wasm.session_public_key(retptr, ptr0, len0, session_expiry);
1205
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1206
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1207
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
1208
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
1209
- return v2;
1210
- } finally {
1211
- wasm.__wbindgen_add_to_stack_pointer(16);
1212
- }
1213
- }
1214
-
1215
- /**
1216
- * Convert a user seed string to 4 Goldilocks field elements.
1217
- *
1218
- * `SHA-256(str)` → split into 4 × 8 LE bytes → reduce each mod p.
1219
- *
1220
- * This matches the backend's `stringToUserSeed` and produces the exact
1221
- * field elements used in the provably-fair random computation:
1222
- * `random = Poseidon2(server_seed ‖ user_seed)`
1223
- *
1224
- * ```js
1225
- * const fields = string_to_user_seed("my-seed-123");
1226
- * // fields.length === 4, each < GOLDILOCKS_P
1227
- * ```
1228
- * @param {string} input
1229
- * @returns {BigUint64Array}
1230
- */
1231
- export function string_to_user_seed(input) {
1232
- try {
1233
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1234
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1235
- const len0 = WASM_VECTOR_LEN;
1236
- wasm.string_to_user_seed(retptr, ptr0, len0);
1237
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1238
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1239
- var v2 = getArrayU64FromWasm0(r0, r1).slice();
1240
- wasm.__wbindgen_export4(r0, r1 * 8, 8);
1241
- return v2;
1242
- } finally {
1243
- wasm.__wbindgen_add_to_stack_pointer(16);
1244
- }
1245
- }
1246
-
1247
- /**
1248
- * Convert a user seed string directly to a hex representation.
1249
- *
1250
- * Equivalent to `goldiLocksFieldsToHex(stringToUserSeed(str))`.
1251
- * Returns a 64-character lowercase hex string (32 bytes).
1252
- *
1253
- * ```js
1254
- * const hex = string_to_user_seed_hex("my-seed-123");
1255
- * // hex === "a1b2c3..." (64 chars)
1256
- * ```
1257
- * @param {string} input
1258
- * @returns {string}
1259
- */
1260
- export function string_to_user_seed_hex(input) {
1261
- let deferred2_0;
1262
- let deferred2_1;
1263
- try {
1264
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1265
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1266
- const len0 = WASM_VECTOR_LEN;
1267
- wasm.string_to_user_seed_hex(retptr, ptr0, len0);
1268
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1269
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1270
- deferred2_0 = r0;
1271
- deferred2_1 = r1;
1272
- return getStringFromWasm0(r0, r1);
1273
- } finally {
1274
- wasm.__wbindgen_add_to_stack_pointer(16);
1275
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
1276
- }
1277
- }
1278
-
1279
- /**
1280
- * Re-check every per-slot circuit constraint on a candidate witness, returning
1281
- * the post-tx effects on success or a typed rejection reason on failure.
1282
- *
1283
- * Input: a JS object matching `tx_validator::SlotInput` (serde-compatible).
1284
- * Output on success: `{ ok: true, effects: SlotEffects }`.
1285
- * Output on failure: `{ ok: false, reason: string }`.
1286
- * @param {any} input
1287
- * @returns {any}
1288
- */
1289
- export function validate_slot(input) {
1290
- try {
1291
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1292
- wasm.validate_slot(retptr, addHeapObject(input));
1293
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1294
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1295
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1296
- if (r2) {
1297
- throw takeObject(r1);
1298
- }
1299
- return takeObject(r0);
1300
- } finally {
1301
- wasm.__wbindgen_add_to_stack_pointer(16);
1302
- }
1303
- }
1304
-
1305
- function __wbg_get_imports() {
1306
- const import0 = {
1307
- __proto__: null,
1308
- __wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
1309
- const ret = Error(getStringFromWasm0(arg0, arg1));
1310
- return addHeapObject(ret);
1311
- },
1312
- __wbg_Number_04624de7d0e8332d: function(arg0) {
1313
- const ret = Number(getObject(arg0));
1314
- return ret;
1315
- },
1316
- __wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
1317
- const ret = String(getObject(arg1));
1318
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1319
- const len1 = WASM_VECTOR_LEN;
1320
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1321
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1322
- },
1323
- __wbg___wbindgen_bigint_get_as_i64_8fcf4ce7f1ca72a2: function(arg0, arg1) {
1324
- const v = getObject(arg1);
1325
- const ret = typeof(v) === 'bigint' ? v : undefined;
1326
- getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
1327
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
1328
- },
1329
- __wbg___wbindgen_boolean_get_bbbb1c18aa2f5e25: function(arg0) {
1330
- const v = getObject(arg0);
1331
- const ret = typeof(v) === 'boolean' ? v : undefined;
1332
- return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
1333
- },
1334
- __wbg___wbindgen_debug_string_0bc8482c6e3508ae: function(arg0, arg1) {
1335
- const ret = debugString(getObject(arg1));
1336
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1337
- const len1 = WASM_VECTOR_LEN;
1338
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1339
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1340
- },
1341
- __wbg___wbindgen_in_47fa6863be6f2f25: function(arg0, arg1) {
1342
- const ret = getObject(arg0) in getObject(arg1);
1343
- return ret;
1344
- },
1345
- __wbg___wbindgen_is_bigint_31b12575b56f32fc: function(arg0) {
1346
- const ret = typeof(getObject(arg0)) === 'bigint';
1347
- return ret;
1348
- },
1349
- __wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
1350
- const ret = typeof(getObject(arg0)) === 'function';
1351
- return ret;
1352
- },
1353
- __wbg___wbindgen_is_object_5ae8e5880f2c1fbd: function(arg0) {
1354
- const val = getObject(arg0);
1355
- const ret = typeof(val) === 'object' && val !== null;
1356
- return ret;
1357
- },
1358
- __wbg___wbindgen_is_string_cd444516edc5b180: function(arg0) {
1359
- const ret = typeof(getObject(arg0)) === 'string';
1360
- return ret;
1361
- },
1362
- __wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
1363
- const ret = getObject(arg0) === undefined;
1364
- return ret;
1365
- },
1366
- __wbg___wbindgen_jsval_eq_11888390b0186270: function(arg0, arg1) {
1367
- const ret = getObject(arg0) === getObject(arg1);
1368
- return ret;
1369
- },
1370
- __wbg___wbindgen_jsval_loose_eq_9dd77d8cd6671811: function(arg0, arg1) {
1371
- const ret = getObject(arg0) == getObject(arg1);
1372
- return ret;
1373
- },
1374
- __wbg___wbindgen_number_get_8ff4255516ccad3e: function(arg0, arg1) {
1375
- const obj = getObject(arg1);
1376
- const ret = typeof(obj) === 'number' ? obj : undefined;
1377
- getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
1378
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
1379
- },
1380
- __wbg___wbindgen_string_get_72fb696202c56729: function(arg0, arg1) {
1381
- const obj = getObject(arg1);
1382
- const ret = typeof(obj) === 'string' ? obj : undefined;
1383
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1384
- var len1 = WASM_VECTOR_LEN;
1385
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1386
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1387
- },
1388
- __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
1389
- throw new Error(getStringFromWasm0(arg0, arg1));
1390
- },
1391
- __wbg_call_389efe28435a9388: function() { return handleError(function (arg0, arg1) {
1392
- const ret = getObject(arg0).call(getObject(arg1));
1393
- return addHeapObject(ret);
1394
- }, arguments); },
1395
- __wbg_call_4708e0c13bdc8e95: function() { return handleError(function (arg0, arg1, arg2) {
1396
- const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
1397
- return addHeapObject(ret);
1398
- }, arguments); },
1399
- __wbg_crypto_86f2631e91b51511: function(arg0) {
1400
- const ret = getObject(arg0).crypto;
1401
- return addHeapObject(ret);
1402
- },
1403
- __wbg_done_57b39ecd9addfe81: function(arg0) {
1404
- const ret = getObject(arg0).done;
1405
- return ret;
1406
- },
1407
- __wbg_getRandomValues_b3f15fcbfabb0f8b: function() { return handleError(function (arg0, arg1) {
1408
- getObject(arg0).getRandomValues(getObject(arg1));
1409
- }, arguments); },
1410
- __wbg_get_9b94d73e6221f75c: function(arg0, arg1) {
1411
- const ret = getObject(arg0)[arg1 >>> 0];
1412
- return addHeapObject(ret);
1413
- },
1414
- __wbg_get_b3ed3ad4be2bc8ac: function() { return handleError(function (arg0, arg1) {
1415
- const ret = Reflect.get(getObject(arg0), getObject(arg1));
1416
- return addHeapObject(ret);
1417
- }, arguments); },
1418
- __wbg_get_with_ref_key_1dc361bd10053bfe: function(arg0, arg1) {
1419
- const ret = getObject(arg0)[getObject(arg1)];
1420
- return addHeapObject(ret);
1421
- },
1422
- __wbg_instanceof_ArrayBuffer_c367199e2fa2aa04: function(arg0) {
1423
- let result;
1424
- try {
1425
- result = getObject(arg0) instanceof ArrayBuffer;
1426
- } catch (_) {
1427
- result = false;
1428
- }
1429
- const ret = result;
1430
- return ret;
1431
- },
1432
- __wbg_instanceof_Uint8Array_9b9075935c74707c: function(arg0) {
1433
- let result;
1434
- try {
1435
- result = getObject(arg0) instanceof Uint8Array;
1436
- } catch (_) {
1437
- result = false;
1438
- }
1439
- const ret = result;
1440
- return ret;
1441
- },
1442
- __wbg_isArray_d314bb98fcf08331: function(arg0) {
1443
- const ret = Array.isArray(getObject(arg0));
1444
- return ret;
1445
- },
1446
- __wbg_isSafeInteger_bfbc7332a9768d2a: function(arg0) {
1447
- const ret = Number.isSafeInteger(getObject(arg0));
1448
- return ret;
1449
- },
1450
- __wbg_iterator_6ff6560ca1568e55: function() {
1451
- const ret = Symbol.iterator;
1452
- return addHeapObject(ret);
1453
- },
1454
- __wbg_length_32ed9a279acd054c: function(arg0) {
1455
- const ret = getObject(arg0).length;
1456
- return ret;
1457
- },
1458
- __wbg_length_35a7bace40f36eac: function(arg0) {
1459
- const ret = getObject(arg0).length;
1460
- return ret;
1461
- },
1462
- __wbg_msCrypto_d562bbe83e0d4b91: function(arg0) {
1463
- const ret = getObject(arg0).msCrypto;
1464
- return addHeapObject(ret);
1465
- },
1466
- __wbg_new_361308b2356cecd0: function() {
1467
- const ret = new Object();
1468
- return addHeapObject(ret);
1469
- },
1470
- __wbg_new_3eb36ae241fe6f44: function() {
1471
- const ret = new Array();
1472
- return addHeapObject(ret);
1473
- },
1474
- __wbg_new_dd2b680c8bf6ae29: function(arg0) {
1475
- const ret = new Uint8Array(getObject(arg0));
1476
- return addHeapObject(ret);
1477
- },
1478
- __wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
1479
- const ret = new Function(getStringFromWasm0(arg0, arg1));
1480
- return addHeapObject(ret);
1481
- },
1482
- __wbg_new_with_length_a2c39cbe88fd8ff1: function(arg0) {
1483
- const ret = new Uint8Array(arg0 >>> 0);
1484
- return addHeapObject(ret);
1485
- },
1486
- __wbg_next_3482f54c49e8af19: function() { return handleError(function (arg0) {
1487
- const ret = getObject(arg0).next();
1488
- return addHeapObject(ret);
1489
- }, arguments); },
1490
- __wbg_next_418f80d8f5303233: function(arg0) {
1491
- const ret = getObject(arg0).next;
1492
- return addHeapObject(ret);
1493
- },
1494
- __wbg_node_e1f24f89a7336c2e: function(arg0) {
1495
- const ret = getObject(arg0).node;
1496
- return addHeapObject(ret);
1497
- },
1498
- __wbg_process_3975fd6c72f520aa: function(arg0) {
1499
- const ret = getObject(arg0).process;
1500
- return addHeapObject(ret);
1501
- },
1502
- __wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
1503
- Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
1504
- },
1505
- __wbg_randomFillSync_f8c153b79f285817: function() { return handleError(function (arg0, arg1) {
1506
- getObject(arg0).randomFillSync(takeObject(arg1));
1507
- }, arguments); },
1508
- __wbg_require_b74f47fc2d022fd6: function() { return handleError(function () {
1509
- const ret = module.require;
1510
- return addHeapObject(ret);
1511
- }, arguments); },
1512
- __wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
1513
- getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
1514
- },
1515
- __wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
1516
- const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
1517
- return ret;
1518
- }, arguments); },
1519
- __wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
1520
- getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
1521
- },
1522
- __wbg_static_accessor_GLOBAL_12837167ad935116: function() {
1523
- const ret = typeof global === 'undefined' ? null : global;
1524
- return isLikeNone(ret) ? 0 : addHeapObject(ret);
1525
- },
1526
- __wbg_static_accessor_GLOBAL_THIS_e628e89ab3b1c95f: function() {
1527
- const ret = typeof globalThis === 'undefined' ? null : globalThis;
1528
- return isLikeNone(ret) ? 0 : addHeapObject(ret);
1529
- },
1530
- __wbg_static_accessor_SELF_a621d3dfbb60d0ce: function() {
1531
- const ret = typeof self === 'undefined' ? null : self;
1532
- return isLikeNone(ret) ? 0 : addHeapObject(ret);
1533
- },
1534
- __wbg_static_accessor_WINDOW_f8727f0cf888e0bd: function() {
1535
- const ret = typeof window === 'undefined' ? null : window;
1536
- return isLikeNone(ret) ? 0 : addHeapObject(ret);
1537
- },
1538
- __wbg_subarray_a96e1fef17ed23cb: function(arg0, arg1, arg2) {
1539
- const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
1540
- return addHeapObject(ret);
1541
- },
1542
- __wbg_value_0546255b415e96c1: function(arg0) {
1543
- const ret = getObject(arg0).value;
1544
- return addHeapObject(ret);
1545
- },
1546
- __wbg_versions_4e31226f5e8dc909: function(arg0) {
1547
- const ret = getObject(arg0).versions;
1548
- return addHeapObject(ret);
1549
- },
1550
- __wbindgen_cast_0000000000000001: function(arg0) {
1551
- // Cast intrinsic for `F64 -> Externref`.
1552
- const ret = arg0;
1553
- return addHeapObject(ret);
1554
- },
1555
- __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1556
- // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
1557
- const ret = getArrayU8FromWasm0(arg0, arg1);
1558
- return addHeapObject(ret);
1559
- },
1560
- __wbindgen_cast_0000000000000003: function(arg0, arg1) {
1561
- // Cast intrinsic for `Ref(String) -> Externref`.
1562
- const ret = getStringFromWasm0(arg0, arg1);
1563
- return addHeapObject(ret);
1564
- },
1565
- __wbindgen_cast_0000000000000004: function(arg0) {
1566
- // Cast intrinsic for `U64 -> Externref`.
1567
- const ret = BigInt.asUintN(64, arg0);
1568
- return addHeapObject(ret);
1569
- },
1570
- __wbindgen_object_clone_ref: function(arg0) {
1571
- const ret = getObject(arg0);
1572
- return addHeapObject(ret);
1573
- },
1574
- __wbindgen_object_drop_ref: function(arg0) {
1575
- takeObject(arg0);
1576
- },
1577
- };
1578
- return {
1579
- __proto__: null,
1580
- "./rolly_wasm_signer_bg.js": import0,
1581
- };
1582
- }
1583
-
1584
- function addHeapObject(obj) {
1585
- if (heap_next === heap.length) heap.push(heap.length + 1);
1586
- const idx = heap_next;
1587
- heap_next = heap[idx];
1588
-
1589
- heap[idx] = obj;
1590
- return idx;
1591
- }
1592
-
1593
- function debugString(val) {
1594
- // primitive types
1595
- const type = typeof val;
1596
- if (type == 'number' || type == 'boolean' || val == null) {
1597
- return `${val}`;
1598
- }
1599
- if (type == 'string') {
1600
- return `"${val}"`;
1601
- }
1602
- if (type == 'symbol') {
1603
- const description = val.description;
1604
- if (description == null) {
1605
- return 'Symbol';
1606
- } else {
1607
- return `Symbol(${description})`;
1608
- }
1609
- }
1610
- if (type == 'function') {
1611
- const name = val.name;
1612
- if (typeof name == 'string' && name.length > 0) {
1613
- return `Function(${name})`;
1614
- } else {
1615
- return 'Function';
1616
- }
1617
- }
1618
- // objects
1619
- if (Array.isArray(val)) {
1620
- const length = val.length;
1621
- let debug = '[';
1622
- if (length > 0) {
1623
- debug += debugString(val[0]);
1624
- }
1625
- for(let i = 1; i < length; i++) {
1626
- debug += ', ' + debugString(val[i]);
1627
- }
1628
- debug += ']';
1629
- return debug;
1630
- }
1631
- // Test for built-in
1632
- const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
1633
- let className;
1634
- if (builtInMatches && builtInMatches.length > 1) {
1635
- className = builtInMatches[1];
1636
- } else {
1637
- // Failed to match the standard '[object ClassName]'
1638
- return toString.call(val);
1639
- }
1640
- if (className == 'Object') {
1641
- // we're a user defined class or Object
1642
- // JSON.stringify avoids problems with cycles, and is generally much
1643
- // easier than looping through ownProperties of `val`.
1644
- try {
1645
- return 'Object(' + JSON.stringify(val) + ')';
1646
- } catch (_) {
1647
- return 'Object';
1648
- }
1649
- }
1650
- // errors
1651
- if (val instanceof Error) {
1652
- return `${val.name}: ${val.message}\n${val.stack}`;
1653
- }
1654
- // TODO we could test for more things here, like `Set`s and `Map`s.
1655
- return className;
1656
- }
1657
-
1658
- function dropObject(idx) {
1659
- if (idx < 132) return;
1660
- heap[idx] = heap_next;
1661
- heap_next = idx;
1662
- }
1663
-
1664
- function getArrayU32FromWasm0(ptr, len) {
1665
- ptr = ptr >>> 0;
1666
- return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
1667
- }
1668
-
1669
- function getArrayU64FromWasm0(ptr, len) {
1670
- ptr = ptr >>> 0;
1671
- return getBigUint64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
1672
- }
1673
-
1674
- function getArrayU8FromWasm0(ptr, len) {
1675
- ptr = ptr >>> 0;
1676
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
1677
- }
1678
-
1679
- let cachedBigUint64ArrayMemory0 = null;
1680
- function getBigUint64ArrayMemory0() {
1681
- if (cachedBigUint64ArrayMemory0 === null || cachedBigUint64ArrayMemory0.byteLength === 0) {
1682
- cachedBigUint64ArrayMemory0 = new BigUint64Array(wasm.memory.buffer);
1683
- }
1684
- return cachedBigUint64ArrayMemory0;
1685
- }
1686
-
1687
- let cachedDataViewMemory0 = null;
1688
- function getDataViewMemory0() {
1689
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
1690
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
1691
- }
1692
- return cachedDataViewMemory0;
1693
- }
1694
-
1695
- function getStringFromWasm0(ptr, len) {
1696
- ptr = ptr >>> 0;
1697
- return decodeText(ptr, len);
1698
- }
1699
-
1700
- let cachedUint32ArrayMemory0 = null;
1701
- function getUint32ArrayMemory0() {
1702
- if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
1703
- cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
1704
- }
1705
- return cachedUint32ArrayMemory0;
1706
- }
1707
-
1708
- let cachedUint8ArrayMemory0 = null;
1709
- function getUint8ArrayMemory0() {
1710
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
1711
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
1712
- }
1713
- return cachedUint8ArrayMemory0;
1714
- }
1715
-
1716
- function getObject(idx) { return heap[idx]; }
1717
-
1718
- function handleError(f, args) {
1719
- try {
1720
- return f.apply(this, args);
1721
- } catch (e) {
1722
- wasm.__wbindgen_export3(addHeapObject(e));
1723
- }
1724
- }
1725
-
1726
- let heap = new Array(128).fill(undefined);
1727
- heap.push(undefined, null, true, false);
1728
-
1729
- let heap_next = heap.length;
1730
-
1731
- function isLikeNone(x) {
1732
- return x === undefined || x === null;
1733
- }
1734
-
1735
- function passArray64ToWasm0(arg, malloc) {
1736
- const ptr = malloc(arg.length * 8, 8) >>> 0;
1737
- getBigUint64ArrayMemory0().set(arg, ptr / 8);
1738
- WASM_VECTOR_LEN = arg.length;
1739
- return ptr;
1740
- }
1741
-
1742
- function passArray8ToWasm0(arg, malloc) {
1743
- const ptr = malloc(arg.length * 1, 1) >>> 0;
1744
- getUint8ArrayMemory0().set(arg, ptr / 1);
1745
- WASM_VECTOR_LEN = arg.length;
1746
- return ptr;
1747
- }
1748
-
1749
- function passStringToWasm0(arg, malloc, realloc) {
1750
- if (realloc === undefined) {
1751
- const buf = cachedTextEncoder.encode(arg);
1752
- const ptr = malloc(buf.length, 1) >>> 0;
1753
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
1754
- WASM_VECTOR_LEN = buf.length;
1755
- return ptr;
1756
- }
1757
-
1758
- let len = arg.length;
1759
- let ptr = malloc(len, 1) >>> 0;
1760
-
1761
- const mem = getUint8ArrayMemory0();
1762
-
1763
- let offset = 0;
1764
-
1765
- for (; offset < len; offset++) {
1766
- const code = arg.charCodeAt(offset);
1767
- if (code > 0x7F) break;
1768
- mem[ptr + offset] = code;
1769
- }
1770
- if (offset !== len) {
1771
- if (offset !== 0) {
1772
- arg = arg.slice(offset);
1773
- }
1774
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
1775
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
1776
- const ret = cachedTextEncoder.encodeInto(arg, view);
1777
-
1778
- offset += ret.written;
1779
- ptr = realloc(ptr, len, offset, 1) >>> 0;
1780
- }
1781
-
1782
- WASM_VECTOR_LEN = offset;
1783
- return ptr;
1784
- }
1785
-
1786
- function takeObject(idx) {
1787
- const ret = getObject(idx);
1788
- dropObject(idx);
1789
- return ret;
1790
- }
1791
-
1792
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1793
- cachedTextDecoder.decode();
1794
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
1795
- let numBytesDecoded = 0;
1796
- function decodeText(ptr, len) {
1797
- numBytesDecoded += len;
1798
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
1799
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1800
- cachedTextDecoder.decode();
1801
- numBytesDecoded = len;
1802
- }
1803
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
1804
- }
1805
-
1806
- const cachedTextEncoder = new TextEncoder();
1807
-
1808
- if (!('encodeInto' in cachedTextEncoder)) {
1809
- cachedTextEncoder.encodeInto = function (arg, view) {
1810
- const buf = cachedTextEncoder.encode(arg);
1811
- view.set(buf);
1812
- return {
1813
- read: arg.length,
1814
- written: buf.length
1815
- };
1816
- };
1817
- }
1818
-
1819
- let WASM_VECTOR_LEN = 0;
1820
-
1821
- let wasmModule, wasm;
1822
- function __wbg_finalize_init(instance, module) {
1823
- wasm = instance.exports;
1824
- wasmModule = module;
1825
- cachedBigUint64ArrayMemory0 = null;
1826
- cachedDataViewMemory0 = null;
1827
- cachedUint32ArrayMemory0 = null;
1828
- cachedUint8ArrayMemory0 = null;
1829
- return wasm;
1830
- }
1831
-
1832
- async function __wbg_load(module, imports) {
1833
- if (typeof Response === 'function' && module instanceof Response) {
1834
- if (typeof WebAssembly.instantiateStreaming === 'function') {
1835
- try {
1836
- return await WebAssembly.instantiateStreaming(module, imports);
1837
- } catch (e) {
1838
- const validResponse = module.ok && expectedResponseType(module.type);
1839
-
1840
- if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
1841
- console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
1842
-
1843
- } else { throw e; }
1844
- }
1845
- }
1846
-
1847
- const bytes = await module.arrayBuffer();
1848
- return await WebAssembly.instantiate(bytes, imports);
1849
- } else {
1850
- const instance = await WebAssembly.instantiate(module, imports);
1851
-
1852
- if (instance instanceof WebAssembly.Instance) {
1853
- return { instance, module };
1854
- } else {
1855
- return instance;
1856
- }
1857
- }
1858
-
1859
- function expectedResponseType(type) {
1860
- switch (type) {
1861
- case 'basic': case 'cors': case 'default': return true;
1862
- }
1863
- return false;
1864
- }
1865
- }
1866
-
1867
- function initSync(module) {
1868
- if (wasm !== undefined) return wasm;
1869
-
1870
-
1871
- if (module !== undefined) {
1872
- if (Object.getPrototypeOf(module) === Object.prototype) {
1873
- ({module} = module)
1874
- } else {
1875
- console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1876
- }
1877
- }
1878
-
1879
- const imports = __wbg_get_imports();
1880
- if (!(module instanceof WebAssembly.Module)) {
1881
- module = new WebAssembly.Module(module);
1882
- }
1883
- const instance = new WebAssembly.Instance(module, imports);
1884
- return __wbg_finalize_init(instance, module);
1885
- }
1886
-
1887
- async function __wbg_init(module_or_path) {
1888
- if (wasm !== undefined) return wasm;
1889
-
1890
-
1891
- if (module_or_path !== undefined) {
1892
- if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1893
- ({module_or_path} = module_or_path)
1894
- } else {
1895
- console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1896
- }
1897
- }
1898
-
1899
- if (module_or_path === undefined) {
1900
- module_or_path = new URL('rolly_wasm_signer_bg.wasm', import.meta.url);
1901
- }
1902
- const imports = __wbg_get_imports();
1903
-
1904
- if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1905
- module_or_path = fetch(module_or_path);
1906
- }
1907
-
1908
- const { instance, module } = await __wbg_load(await module_or_path, imports);
1909
-
1910
- return __wbg_finalize_init(instance, module);
1911
- }
1912
-
1913
- export { initSync, __wbg_init as default };