@rolly-dev/wasm-signer 1.0.0 → 1.1.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.
@@ -47,6 +47,65 @@ export function compute_address_hash(address_hex) {
47
47
  }
48
48
  }
49
49
 
50
+ /**
51
+ * Compute dice multiplier × 10000 from win_numbers count.
52
+ *
53
+ * Formula: `9_900_000 / win_numbers` (integer division = floor).
54
+ * `win_numbers` must be in [1, 950].
55
+ * @param {number} win_numbers
56
+ * @returns {bigint}
57
+ */
58
+ export function compute_multi_dice(win_numbers) {
59
+ const ret = wasm.compute_multi_dice(win_numbers);
60
+ return BigInt.asUintN(64, ret);
61
+ }
62
+
63
+ /**
64
+ * Full dice payout computation — pure integer arithmetic, zero floats.
65
+ *
66
+ * `random`: 4 Goldilocks field elements (Poseidon2 output).
67
+ * `bet_atomic`: bet in atomic units (1 USDT = 1_000_000).
68
+ * `game_mode`: 0=Under, 1=Over, 2=In, 3=Out.
69
+ * `prediction_lo` / `prediction_hi`: prediction range bounds (0..999).
70
+ *
71
+ * Returns `BigUint64Array[4]`: `[win_amount, roll_number, is_win (0|1), multiplier×10000]`.
72
+ * @param {BigUint64Array} random
73
+ * @param {bigint} bet_atomic
74
+ * @param {number} game_mode
75
+ * @param {number} prediction_lo
76
+ * @param {number} prediction_hi
77
+ * @returns {BigUint64Array}
78
+ */
79
+ export function compute_payout_dice(random, bet_atomic, game_mode, prediction_lo, prediction_hi) {
80
+ try {
81
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
82
+ const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export3);
83
+ const len0 = WASM_VECTOR_LEN;
84
+ wasm.compute_payout_dice(retptr, ptr0, len0, bet_atomic, game_mode, prediction_lo, prediction_hi);
85
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
86
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
87
+ var v2 = getArrayU64FromWasm0(r0, r1).slice();
88
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
89
+ return v2;
90
+ } finally {
91
+ wasm.__wbindgen_add_to_stack_pointer(16);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Extract dice roll number [0, 1000) from Poseidon2 random output.
97
+ *
98
+ * `random` must be exactly 4 elements. Returns `random[0] % 1000`.
99
+ * @param {BigUint64Array} random
100
+ * @returns {number}
101
+ */
102
+ export function compute_roll_dice(random) {
103
+ const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export3);
104
+ const len0 = WASM_VECTOR_LEN;
105
+ const ret = wasm.compute_roll_dice(ptr0, len0);
106
+ return ret >>> 0;
107
+ }
108
+
50
109
  /**
51
110
  * Full Poseidon2 hash of an 8-element server seed.
52
111
  *
Binary file
@@ -3,6 +3,9 @@
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const amount_split: (a: number, b: bigint) => void;
5
5
  export const compute_address_hash: (a: number, b: number, c: number) => void;
6
+ export const compute_multi_dice: (a: number) => bigint;
7
+ export const compute_payout_dice: (a: number, b: number, c: number, d: bigint, e: number, f: number, g: number) => void;
8
+ export const compute_roll_dice: (a: number, b: number) => number;
6
9
  export const compute_server_seed_hash: (a: number, b: number, c: number) => void;
7
10
  export const derive_session_key: (a: number, b: number, c: number) => void;
8
11
  export const generate_user_seed: (a: number) => void;
package/js/browser.d.mts CHANGED
@@ -15,6 +15,9 @@ export {
15
15
  compute_address_hash,
16
16
  hash_balance_leaf,
17
17
  make_main_leaf,
18
+ compute_payout_dice,
19
+ compute_roll_dice,
20
+ compute_multi_dice,
18
21
  } from '../dist/web/rolly_wasm_signer.js';
19
22
 
20
23
  export { default as init } from '../dist/web/rolly_wasm_signer.js';
package/js/browser.mjs CHANGED
@@ -17,4 +17,7 @@ export {
17
17
  compute_address_hash,
18
18
  hash_balance_leaf,
19
19
  make_main_leaf,
20
+ compute_payout_dice,
21
+ compute_roll_dice,
22
+ compute_multi_dice,
20
23
  } from '../dist/web/rolly_wasm_signer.js';
package/js/index.d.ts CHANGED
@@ -15,4 +15,7 @@ export {
15
15
  compute_address_hash,
16
16
  hash_balance_leaf,
17
17
  make_main_leaf,
18
+ compute_payout_dice,
19
+ compute_roll_dice,
20
+ compute_multi_dice,
18
21
  } from '../dist/node-inline/rolly_wasm_signer.js';
@@ -19,4 +19,7 @@ module.exports = {
19
19
  compute_address_hash: wasm.compute_address_hash,
20
20
  hash_balance_leaf: wasm.hash_balance_leaf,
21
21
  make_main_leaf: wasm.make_main_leaf,
22
+ compute_payout_dice: wasm.compute_payout_dice,
23
+ compute_roll_dice: wasm.compute_roll_dice,
24
+ compute_multi_dice: wasm.compute_multi_dice,
22
25
  };
@@ -15,4 +15,7 @@ export {
15
15
  compute_address_hash,
16
16
  hash_balance_leaf,
17
17
  make_main_leaf,
18
+ compute_payout_dice,
19
+ compute_roll_dice,
20
+ compute_multi_dice,
18
21
  } from '../dist/node-inline/rolly_wasm_signer.mjs';
package/js/node.cjs CHANGED
@@ -19,4 +19,7 @@ module.exports = {
19
19
  compute_address_hash: wasm.compute_address_hash,
20
20
  hash_balance_leaf: wasm.hash_balance_leaf,
21
21
  make_main_leaf: wasm.make_main_leaf,
22
+ compute_payout_dice: wasm.compute_payout_dice,
23
+ compute_roll_dice: wasm.compute_roll_dice,
24
+ compute_multi_dice: wasm.compute_multi_dice,
22
25
  };
package/js/node.mjs CHANGED
@@ -20,4 +20,7 @@ export const {
20
20
  compute_address_hash,
21
21
  hash_balance_leaf,
22
22
  make_main_leaf,
23
+ compute_payout_dice,
24
+ compute_roll_dice,
25
+ compute_multi_dice,
23
26
  } = wasm;
package/js/react.d.mts CHANGED
@@ -17,6 +17,9 @@ export interface RollyWasmResult {
17
17
  compute_address_hash: (address_hex: string) => BigUint64Array;
18
18
  hash_balance_leaf: (raw: BigUint64Array) => BigUint64Array;
19
19
  make_main_leaf: (balance_hash: BigUint64Array, pk_hash: BigUint64Array, address_hash: BigUint64Array) => BigUint64Array;
20
+ compute_payout_dice: (random: BigUint64Array, bet_atomic: bigint, game_mode: number, prediction_lo: number, prediction_hi: number) => BigUint64Array;
21
+ compute_roll_dice: (random: BigUint64Array) => number;
22
+ compute_multi_dice: (win_numbers: number) => bigint;
20
23
  }
21
24
 
22
25
  export function useRollyWasm(): RollyWasmResult;
package/js/react.mjs CHANGED
@@ -16,6 +16,9 @@ import init, {
16
16
  compute_address_hash,
17
17
  hash_balance_leaf,
18
18
  make_main_leaf,
19
+ compute_payout_dice,
20
+ compute_roll_dice,
21
+ compute_multi_dice,
19
22
  } from '../dist/web/rolly_wasm_signer.js';
20
23
 
21
24
  let _ready = false;
@@ -45,6 +48,9 @@ const fns = {
45
48
  compute_address_hash: guard(compute_address_hash),
46
49
  hash_balance_leaf: guard(hash_balance_leaf),
47
50
  make_main_leaf: guard(make_main_leaf),
51
+ compute_payout_dice: guard(compute_payout_dice),
52
+ compute_roll_dice: guard(compute_roll_dice),
53
+ compute_multi_dice: guard(compute_multi_dice),
48
54
  };
49
55
 
50
56
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolly-dev/wasm-signer",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Poseidon2 hashing & bet signing for Rolly ZK-Rollup (WASM, Goldilocks field)",
5
5
  "type": "module",
6
6
  "exports": {