@rolly-dev/wasm-signer 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,6 +60,35 @@ export function compute_multi_dice(win_numbers) {
60
60
  return BigInt.asUintN(64, ret);
61
61
  }
62
62
 
63
+ /**
64
+ * Full coinflip 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
+ * `prediction`: 0 or 1.
69
+ *
70
+ * Returns `BigUint64Array[4]`: `[win_amount, roll (0|1), is_win (0|1), multiplier×10000]`.
71
+ * @param {BigUint64Array} random
72
+ * @param {bigint} bet_atomic
73
+ * @param {number} prediction
74
+ * @returns {BigUint64Array}
75
+ */
76
+ export function compute_payout_coinflip(random, bet_atomic, prediction) {
77
+ try {
78
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
79
+ const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export3);
80
+ const len0 = WASM_VECTOR_LEN;
81
+ wasm.compute_payout_coinflip(retptr, ptr0, len0, bet_atomic, prediction);
82
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
83
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
84
+ var v2 = getArrayU64FromWasm0(r0, r1).slice();
85
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
86
+ return v2;
87
+ } finally {
88
+ wasm.__wbindgen_add_to_stack_pointer(16);
89
+ }
90
+ }
91
+
63
92
  /**
64
93
  * Full dice payout computation — pure integer arithmetic, zero floats.
65
94
  *
@@ -132,8 +161,9 @@ export function compute_payout_plinko(random, bet_atomic, sector, rows, is_extre
132
161
  * and the in-circuit `build_prediction_hash`.
133
162
  *
134
163
  * Semantics of p0–p2 depend on the game:
135
- * Dice: `(mode, pred_lo, pred_hi)`
136
- * Plinko: `(sector, rows, is_extreme)`
164
+ * Dice: `(mode, pred_lo, pred_hi)`
165
+ * Plinko: `(sector, rows, is_extreme)`
166
+ * CoinFlip: `(prediction, 0, 0)`
137
167
  * @param {number} game_id
138
168
  * @param {number} p0
139
169
  * @param {number} p1
@@ -154,6 +184,20 @@ export function compute_prediction_hash(game_id, p0, p1, p2) {
154
184
  }
155
185
  }
156
186
 
187
+ /**
188
+ * Extract coinflip roll (0 or 1) from Poseidon2 random output.
189
+ *
190
+ * `random` must be exactly 4 elements. Returns `random[0] % 2`.
191
+ * @param {BigUint64Array} random
192
+ * @returns {number}
193
+ */
194
+ export function compute_roll_coinflip(random) {
195
+ const ptr0 = passArray64ToWasm0(random, wasm.__wbindgen_export3);
196
+ const len0 = WASM_VECTOR_LEN;
197
+ const ret = wasm.compute_roll_coinflip(ptr0, len0);
198
+ return ret >>> 0;
199
+ }
200
+
157
201
  /**
158
202
  * Extract dice roll number [0, 1000) from Poseidon2 random output.
159
203
  *
Binary file
@@ -4,9 +4,11 @@ export const memory: WebAssembly.Memory;
4
4
  export const amount_split: (a: number, b: bigint) => void;
5
5
  export const compute_address_hash: (a: number, b: number, c: number) => void;
6
6
  export const compute_multi_dice: (a: number) => bigint;
7
+ export const compute_payout_coinflip: (a: number, b: number, c: number, d: bigint, e: number) => void;
7
8
  export const compute_payout_dice: (a: number, b: number, c: number, d: bigint, e: number, f: number, g: number) => void;
8
9
  export const compute_payout_plinko: (a: number, b: number, c: number, d: bigint, e: number, f: number, g: number) => void;
9
10
  export const compute_prediction_hash: (a: number, b: number, c: number, d: number, e: number) => void;
11
+ export const compute_roll_coinflip: (a: number, b: number) => number;
10
12
  export const compute_roll_dice: (a: number, b: number) => number;
11
13
  export const compute_roll_plinko: (a: number, b: number, c: number) => number;
12
14
  export const compute_server_seed_hash: (a: number, b: number, c: number) => void;
package/js/browser.mjs CHANGED
@@ -4,9 +4,11 @@ export {
4
4
  amount_split,
5
5
  compute_address_hash,
6
6
  compute_multi_dice,
7
+ compute_payout_coinflip,
7
8
  compute_payout_dice,
8
9
  compute_payout_plinko,
9
10
  compute_prediction_hash,
11
+ compute_roll_coinflip,
10
12
  compute_roll_dice,
11
13
  compute_roll_plinko,
12
14
  compute_server_seed_hash,
package/js/index.d.ts CHANGED
@@ -2,9 +2,11 @@ export {
2
2
  amount_split,
3
3
  compute_address_hash,
4
4
  compute_multi_dice,
5
+ compute_payout_coinflip,
5
6
  compute_payout_dice,
6
7
  compute_payout_plinko,
7
8
  compute_prediction_hash,
9
+ compute_roll_coinflip,
8
10
  compute_roll_dice,
9
11
  compute_roll_plinko,
10
12
  compute_server_seed_hash,
@@ -6,9 +6,11 @@ module.exports = {
6
6
  amount_split: wasm.amount_split,
7
7
  compute_address_hash: wasm.compute_address_hash,
8
8
  compute_multi_dice: wasm.compute_multi_dice,
9
+ compute_payout_coinflip: wasm.compute_payout_coinflip,
9
10
  compute_payout_dice: wasm.compute_payout_dice,
10
11
  compute_payout_plinko: wasm.compute_payout_plinko,
11
12
  compute_prediction_hash: wasm.compute_prediction_hash,
13
+ compute_roll_coinflip: wasm.compute_roll_coinflip,
12
14
  compute_roll_dice: wasm.compute_roll_dice,
13
15
  compute_roll_plinko: wasm.compute_roll_plinko,
14
16
  compute_server_seed_hash: wasm.compute_server_seed_hash,
@@ -2,9 +2,11 @@ export {
2
2
  amount_split,
3
3
  compute_address_hash,
4
4
  compute_multi_dice,
5
+ compute_payout_coinflip,
5
6
  compute_payout_dice,
6
7
  compute_payout_plinko,
7
8
  compute_prediction_hash,
9
+ compute_roll_coinflip,
8
10
  compute_roll_dice,
9
11
  compute_roll_plinko,
10
12
  compute_server_seed_hash,
package/js/node.cjs CHANGED
@@ -6,9 +6,11 @@ module.exports = {
6
6
  amount_split: wasm.amount_split,
7
7
  compute_address_hash: wasm.compute_address_hash,
8
8
  compute_multi_dice: wasm.compute_multi_dice,
9
+ compute_payout_coinflip: wasm.compute_payout_coinflip,
9
10
  compute_payout_dice: wasm.compute_payout_dice,
10
11
  compute_payout_plinko: wasm.compute_payout_plinko,
11
12
  compute_prediction_hash: wasm.compute_prediction_hash,
13
+ compute_roll_coinflip: wasm.compute_roll_coinflip,
12
14
  compute_roll_dice: wasm.compute_roll_dice,
13
15
  compute_roll_plinko: wasm.compute_roll_plinko,
14
16
  compute_server_seed_hash: wasm.compute_server_seed_hash,
package/js/node.mjs CHANGED
@@ -7,9 +7,11 @@ export const {
7
7
  amount_split,
8
8
  compute_address_hash,
9
9
  compute_multi_dice,
10
+ compute_payout_coinflip,
10
11
  compute_payout_dice,
11
12
  compute_payout_plinko,
12
13
  compute_prediction_hash,
14
+ compute_roll_coinflip,
13
15
  compute_roll_dice,
14
16
  compute_roll_plinko,
15
17
  compute_server_seed_hash,
package/js/react.mjs CHANGED
@@ -3,9 +3,11 @@ import init, {
3
3
  amount_split,
4
4
  compute_address_hash,
5
5
  compute_multi_dice,
6
+ compute_payout_coinflip,
6
7
  compute_payout_dice,
7
8
  compute_payout_plinko,
8
9
  compute_prediction_hash,
10
+ compute_roll_coinflip,
9
11
  compute_roll_dice,
10
12
  compute_roll_plinko,
11
13
  compute_server_seed_hash,
@@ -40,9 +42,11 @@ const fns = {
40
42
  amount_split: guard(amount_split),
41
43
  compute_address_hash: guard(compute_address_hash),
42
44
  compute_multi_dice: guard(compute_multi_dice),
45
+ compute_payout_coinflip: guard(compute_payout_coinflip),
43
46
  compute_payout_dice: guard(compute_payout_dice),
44
47
  compute_payout_plinko: guard(compute_payout_plinko),
45
48
  compute_prediction_hash: guard(compute_prediction_hash),
49
+ compute_roll_coinflip: guard(compute_roll_coinflip),
46
50
  compute_roll_dice: guard(compute_roll_dice),
47
51
  compute_roll_plinko: guard(compute_roll_plinko),
48
52
  compute_server_seed_hash: guard(compute_server_seed_hash),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolly-dev/wasm-signer",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "Poseidon2 hashing & bet signing for Rolly ZK-Rollup (WASM, Goldilocks field)",
5
5
  "type": "module",
6
6
  "exports": {