@rolly-dev/wasm-signer 0.13.1 → 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.
- package/README.md +37 -1
- package/dist/node/README.md +37 -1
- package/dist/node/rolly_wasm_signer.d.ts +68 -4
- package/dist/node/rolly_wasm_signer.js +143 -4
- package/dist/node/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/node/rolly_wasm_signer_bg.wasm.d.ts +5 -0
- package/dist/node-inline/README.md +37 -1
- package/dist/node-inline/rolly_wasm_signer.d.ts +68 -4
- package/dist/node-inline/rolly_wasm_signer.js +144 -5
- package/dist/node-inline/rolly_wasm_signer.mjs +140 -6
- package/dist/node-inline/rolly_wasm_signer_bg.wasm.d.ts +5 -0
- package/dist/web/README.md +37 -1
- package/dist/web/rolly_wasm_signer.d.ts +73 -4
- package/dist/web/rolly_wasm_signer.js +138 -4
- package/dist/web/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/web/rolly_wasm_signer_bg.wasm.d.ts +5 -0
- package/js/browser.d.mts +5 -0
- package/js/browser.mjs +5 -0
- package/js/index.d.ts +5 -0
- package/js/node-inline.cjs +5 -0
- package/js/node-inline.mjs +5 -0
- package/js/node.cjs +5 -0
- package/js/node.mjs +5 -0
- package/js/react.d.mts +5 -0
- package/js/react.mjs +10 -0
- package/package.json +1 -1
package/dist/web/README.md
CHANGED
|
@@ -89,7 +89,7 @@ poseidon2_hash(BigUint64Array.from([1n]));
|
|
|
89
89
|
| `derive_session_key` | `Uint8Array(32)` | `BigUint64Array(4)` | MetaMask sig → session key |
|
|
90
90
|
| `session_public_key` | `(BigUint64Array(4), bigint)` | `BigUint64Array(4)` | pk_hash = Poseidon2(session_key, expiry) |
|
|
91
91
|
| `compute_server_seed_hash` | `BigUint64Array(8)` | `BigUint64Array(4)` | Full hash of server seed |
|
|
92
|
-
| `seed_hash_truncated` | `BigUint64Array(8)` | `BigUint64Array(
|
|
92
|
+
| `seed_hash_truncated` | `BigUint64Array(8)` | `BigUint64Array(3)` | First 3 elements (circuit leaf format, 192-bit commitment) |
|
|
93
93
|
| `goldilocks_modulus` | — | `bigint` | Returns p = 2^64 - 2^32 + 1 |
|
|
94
94
|
| `goldilocks_reduce` | `bigint` | `bigint` | Reduce mod p |
|
|
95
95
|
|
|
@@ -107,6 +107,42 @@ module.exports = { experiments: { asyncWebAssembly: true } };
|
|
|
107
107
|
|
|
108
108
|
**Next.js** — conditional exports auto-resolve: Node.js entry on server, browser entry on client.
|
|
109
109
|
|
|
110
|
+
## Dice — range constraints
|
|
111
|
+
|
|
112
|
+
Roll number: `[0, 999]` (TOTAL_RANGE = 1000).
|
|
113
|
+
win_numbers (wn): `[1, 950]` (MIN_RANGE..=MAX_RANGE).
|
|
114
|
+
|
|
115
|
+
### prediction_range constraints per mode
|
|
116
|
+
|
|
117
|
+
| Mode | wn formula | prediction\[0\] | prediction\[1\] | wn range |
|
|
118
|
+
|-------|-------------------------------------------------|-----------------|-----------------|------------|
|
|
119
|
+
| Under | `prediction[0]` | `[1, 950]` | unused (0) | `[1, 950]` |
|
|
120
|
+
| Over | `999 − prediction[0]` | `[49, 998]` | unused (0) | `[1, 950]` |
|
|
121
|
+
| In | `prediction[1] − prediction[0] + 1` | `[0, 999]` | `[0, 999]` | `[1, 950]` |
|
|
122
|
+
| Out | `1000 − (prediction[1] − prediction[0] + 1)` | `[0, 999]` | `[0, 999]` | `[1, 950]` |
|
|
123
|
+
|
|
124
|
+
**Under** — `prediction[0]` ∈ `[1, 950]` (= wn directly). Win: `roll < prediction[0]`.
|
|
125
|
+
|
|
126
|
+
**Over** — `prediction[0]` ∈ `[49, 998]` (lower: `999 − 950 = 49`, upper: `999 − 1 = 998`). Win: `roll > prediction[0]`.
|
|
127
|
+
|
|
128
|
+
**In** — `prediction[0] <= prediction[1]`, span ∈ `[1, 950]`. Win: `prediction[0] <= roll <= prediction[1]`.
|
|
129
|
+
|
|
130
|
+
**Out** — `prediction[0] <= prediction[1]`, inner span ∈ `[50, 999]` (wn = `1000 − inner` ∈ `[1, 950]`). Win: `roll < prediction[0] || roll > prediction[1]`.
|
|
131
|
+
|
|
132
|
+
### Multiplier
|
|
133
|
+
|
|
134
|
+
`multiplier = floor(9_900_000 / wn)` (scaled ×10000).
|
|
135
|
+
|
|
136
|
+
| wn | multiplier | display |
|
|
137
|
+
|-----|-----------|-----------|
|
|
138
|
+
| 1 | 9_900_000 | 990.0000x |
|
|
139
|
+
| 500 | 19_800 | 1.9800x |
|
|
140
|
+
| 950 | 10_421 | 1.0421x |
|
|
141
|
+
|
|
142
|
+
### RTP
|
|
143
|
+
|
|
144
|
+
Theoretical: **98.998%** (floor-division costs ~0.002%). House edge: **~1.002%**. Max win cap: 10,000 USDT (business rule, not formula).
|
|
145
|
+
|
|
110
146
|
## License
|
|
111
147
|
|
|
112
148
|
MIT
|
|
@@ -18,11 +18,38 @@ export function amount_split(amount: bigint): Uint32Array;
|
|
|
18
18
|
*/
|
|
19
19
|
export function compute_address_hash(address_hex: string): BigUint64Array;
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Compute dice multiplier × 10000 from win_numbers count.
|
|
23
|
+
*
|
|
24
|
+
* Formula: `9_900_000 / win_numbers` (integer division = floor).
|
|
25
|
+
* `win_numbers` must be in [1, 950].
|
|
26
|
+
*/
|
|
27
|
+
export function compute_multi_dice(win_numbers: number): bigint;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Full dice payout computation — pure integer arithmetic, zero floats.
|
|
31
|
+
*
|
|
32
|
+
* `random`: 4 Goldilocks field elements (Poseidon2 output).
|
|
33
|
+
* `bet_atomic`: bet in atomic units (1 USDT = 1_000_000).
|
|
34
|
+
* `game_mode`: 0=Under, 1=Over, 2=In, 3=Out.
|
|
35
|
+
* `prediction_lo` / `prediction_hi`: prediction range bounds (0..999).
|
|
36
|
+
*
|
|
37
|
+
* Returns `BigUint64Array[4]`: `[win_amount, roll_number, is_win (0|1), multiplier×10000]`.
|
|
38
|
+
*/
|
|
39
|
+
export function compute_payout_dice(random: BigUint64Array, bet_atomic: bigint, game_mode: number, prediction_lo: number, prediction_hi: number): BigUint64Array;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Extract dice roll number [0, 1000) from Poseidon2 random output.
|
|
43
|
+
*
|
|
44
|
+
* `random` must be exactly 4 elements. Returns `random[0] % 1000`.
|
|
45
|
+
*/
|
|
46
|
+
export function compute_roll_dice(random: BigUint64Array): number;
|
|
47
|
+
|
|
21
48
|
/**
|
|
22
49
|
* Full Poseidon2 hash of an 8-element server seed.
|
|
23
50
|
*
|
|
24
51
|
* Returns all 4 hash elements. Note: the circuit stores only the
|
|
25
|
-
* **first
|
|
52
|
+
* **first 3 elements** as the leaf commitment (see `seed_hash_truncated`).
|
|
26
53
|
* This full variant is useful for client-side verification where all
|
|
27
54
|
* 4 elements may be needed.
|
|
28
55
|
*
|
|
@@ -86,6 +113,41 @@ export function goldilocks_modulus(): bigint;
|
|
|
86
113
|
*/
|
|
87
114
|
export function goldilocks_reduce(value: bigint): bigint;
|
|
88
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Hash a raw 7-element balance leaf → 4-element Merkle node.
|
|
118
|
+
*
|
|
119
|
+
* Raw layout: `[balance_lo, balance_hi, seed_hash_0, seed_hash_1, seed_hash_2, credit_lo, credit_hi]`
|
|
120
|
+
*
|
|
121
|
+
* Identical to `hash_balance_leaf` in `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
122
|
+
*
|
|
123
|
+
* **Input** : `BigUint64Array` of exactly 7 elements (each < `GOLDILOCKS_P`).
|
|
124
|
+
* **Output**: `BigUint64Array` of length 4 (one `HashOut`).
|
|
125
|
+
*
|
|
126
|
+
* ```js
|
|
127
|
+
* const raw = BigUint64Array.from([balLo, balHi, seed0, seed1, seed2, credLo, credHi]);
|
|
128
|
+
* const balanceHash = hash_balance_leaf(raw); // length 4
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export function hash_balance_leaf(raw: BigUint64Array): BigUint64Array;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Build a main Merkle tree leaf from balance_hash, pk_hash, and address_hash.
|
|
135
|
+
*
|
|
136
|
+
* `main_leaf = Poseidon2(balance_hash[4] || pk_hash[0..2] || address_hash[0..2])`
|
|
137
|
+
*
|
|
138
|
+
* Uses truncated (128-bit) pk/address hashes to keep the preimage at 8 elements
|
|
139
|
+
* (single Poseidon2 permutation round). Identical to `make_main_leaf` in
|
|
140
|
+
* `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
141
|
+
*
|
|
142
|
+
* All three inputs must be exactly 4 elements.
|
|
143
|
+
* **Output**: `BigUint64Array` of length 4 (the Merkle leaf hash).
|
|
144
|
+
*
|
|
145
|
+
* ```js
|
|
146
|
+
* const leaf = make_main_leaf(balanceHash, pkHash, addressHash);
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export function make_main_leaf(balance_hash: BigUint64Array, pk_hash: BigUint64Array, address_hash: BigUint64Array): BigUint64Array;
|
|
150
|
+
|
|
89
151
|
/**
|
|
90
152
|
* Poseidon2 hash of an arbitrary number of Goldilocks field elements.
|
|
91
153
|
*
|
|
@@ -113,13 +175,15 @@ export function poseidon2_hash(input: BigUint64Array): BigUint64Array;
|
|
|
113
175
|
export function poseidon2_two_to_one(left: BigUint64Array, right: BigUint64Array): BigUint64Array;
|
|
114
176
|
|
|
115
177
|
/**
|
|
116
|
-
* Truncated seed hash — first
|
|
178
|
+
* Truncated seed hash — first 3 elements of `Poseidon2(server_seed)`.
|
|
117
179
|
*
|
|
180
|
+
* 192 bits of commitment → ~96-bit collision resistance, which closes the
|
|
181
|
+
* multi-preimage grinding vector that an earlier 128-bit truncation left open.
|
|
118
182
|
* This is the exact format stored in the Merkle-tree leaf and verified
|
|
119
183
|
* by the circuit. Matches `seed_hash_truncated` in
|
|
120
|
-
* `src/block_builder/builder.rs` and `src/circuit/
|
|
184
|
+
* `src/block_builder/builder.rs` and `src/circuit/slot/fairness.rs`.
|
|
121
185
|
*
|
|
122
|
-
* Returns `BigUint64Array` of length
|
|
186
|
+
* Returns `BigUint64Array` of length 3: `[h[0], h[1], h[2]]`.
|
|
123
187
|
*/
|
|
124
188
|
export function seed_hash_truncated(server_seed: BigUint64Array): BigUint64Array;
|
|
125
189
|
|
|
@@ -169,11 +233,16 @@ export interface InitOutput {
|
|
|
169
233
|
readonly memory: WebAssembly.Memory;
|
|
170
234
|
readonly amount_split: (a: number, b: bigint) => void;
|
|
171
235
|
readonly compute_address_hash: (a: number, b: number, c: number) => void;
|
|
236
|
+
readonly compute_multi_dice: (a: number) => bigint;
|
|
237
|
+
readonly compute_payout_dice: (a: number, b: number, c: number, d: bigint, e: number, f: number, g: number) => void;
|
|
238
|
+
readonly compute_roll_dice: (a: number, b: number) => number;
|
|
172
239
|
readonly compute_server_seed_hash: (a: number, b: number, c: number) => void;
|
|
173
240
|
readonly derive_session_key: (a: number, b: number, c: number) => void;
|
|
174
241
|
readonly generate_user_seed: (a: number) => void;
|
|
175
242
|
readonly goldilocks_fields_to_hex: (a: number, b: number, c: number) => void;
|
|
176
243
|
readonly goldilocks_reduce: (a: bigint) => bigint;
|
|
244
|
+
readonly hash_balance_leaf: (a: number, b: number, c: number) => void;
|
|
245
|
+
readonly make_main_leaf: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
177
246
|
readonly poseidon2_hash: (a: number, b: number, c: number) => void;
|
|
178
247
|
readonly poseidon2_two_to_one: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
179
248
|
readonly seed_hash_truncated: (a: number, b: number, c: number) => void;
|
|
@@ -47,11 +47,70 @@ 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
|
*
|
|
53
112
|
* Returns all 4 hash elements. Note: the circuit stores only the
|
|
54
|
-
* **first
|
|
113
|
+
* **first 3 elements** as the leaf commitment (see `seed_hash_truncated`).
|
|
55
114
|
* This full variant is useful for client-side verification where all
|
|
56
115
|
* 4 elements may be needed.
|
|
57
116
|
*
|
|
@@ -191,6 +250,79 @@ export function goldilocks_reduce(value) {
|
|
|
191
250
|
return BigInt.asUintN(64, ret);
|
|
192
251
|
}
|
|
193
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Hash a raw 7-element balance leaf → 4-element Merkle node.
|
|
255
|
+
*
|
|
256
|
+
* Raw layout: `[balance_lo, balance_hi, seed_hash_0, seed_hash_1, seed_hash_2, credit_lo, credit_hi]`
|
|
257
|
+
*
|
|
258
|
+
* Identical to `hash_balance_leaf` in `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
259
|
+
*
|
|
260
|
+
* **Input** : `BigUint64Array` of exactly 7 elements (each < `GOLDILOCKS_P`).
|
|
261
|
+
* **Output**: `BigUint64Array` of length 4 (one `HashOut`).
|
|
262
|
+
*
|
|
263
|
+
* ```js
|
|
264
|
+
* const raw = BigUint64Array.from([balLo, balHi, seed0, seed1, seed2, credLo, credHi]);
|
|
265
|
+
* const balanceHash = hash_balance_leaf(raw); // length 4
|
|
266
|
+
* ```
|
|
267
|
+
* @param {BigUint64Array} raw
|
|
268
|
+
* @returns {BigUint64Array}
|
|
269
|
+
*/
|
|
270
|
+
export function hash_balance_leaf(raw) {
|
|
271
|
+
try {
|
|
272
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
273
|
+
const ptr0 = passArray64ToWasm0(raw, wasm.__wbindgen_export3);
|
|
274
|
+
const len0 = WASM_VECTOR_LEN;
|
|
275
|
+
wasm.hash_balance_leaf(retptr, ptr0, len0);
|
|
276
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
277
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
278
|
+
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
279
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
280
|
+
return v2;
|
|
281
|
+
} finally {
|
|
282
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Build a main Merkle tree leaf from balance_hash, pk_hash, and address_hash.
|
|
288
|
+
*
|
|
289
|
+
* `main_leaf = Poseidon2(balance_hash[4] || pk_hash[0..2] || address_hash[0..2])`
|
|
290
|
+
*
|
|
291
|
+
* Uses truncated (128-bit) pk/address hashes to keep the preimage at 8 elements
|
|
292
|
+
* (single Poseidon2 permutation round). Identical to `make_main_leaf` in
|
|
293
|
+
* `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
294
|
+
*
|
|
295
|
+
* All three inputs must be exactly 4 elements.
|
|
296
|
+
* **Output**: `BigUint64Array` of length 4 (the Merkle leaf hash).
|
|
297
|
+
*
|
|
298
|
+
* ```js
|
|
299
|
+
* const leaf = make_main_leaf(balanceHash, pkHash, addressHash);
|
|
300
|
+
* ```
|
|
301
|
+
* @param {BigUint64Array} balance_hash
|
|
302
|
+
* @param {BigUint64Array} pk_hash
|
|
303
|
+
* @param {BigUint64Array} address_hash
|
|
304
|
+
* @returns {BigUint64Array}
|
|
305
|
+
*/
|
|
306
|
+
export function make_main_leaf(balance_hash, pk_hash, address_hash) {
|
|
307
|
+
try {
|
|
308
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
309
|
+
const ptr0 = passArray64ToWasm0(balance_hash, wasm.__wbindgen_export3);
|
|
310
|
+
const len0 = WASM_VECTOR_LEN;
|
|
311
|
+
const ptr1 = passArray64ToWasm0(pk_hash, wasm.__wbindgen_export3);
|
|
312
|
+
const len1 = WASM_VECTOR_LEN;
|
|
313
|
+
const ptr2 = passArray64ToWasm0(address_hash, wasm.__wbindgen_export3);
|
|
314
|
+
const len2 = WASM_VECTOR_LEN;
|
|
315
|
+
wasm.make_main_leaf(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
316
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
317
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
318
|
+
var v4 = getArrayU64FromWasm0(r0, r1).slice();
|
|
319
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
320
|
+
return v4;
|
|
321
|
+
} finally {
|
|
322
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
194
326
|
/**
|
|
195
327
|
* Poseidon2 hash of an arbitrary number of Goldilocks field elements.
|
|
196
328
|
*
|
|
@@ -253,13 +385,15 @@ export function poseidon2_two_to_one(left, right) {
|
|
|
253
385
|
}
|
|
254
386
|
|
|
255
387
|
/**
|
|
256
|
-
* Truncated seed hash — first
|
|
388
|
+
* Truncated seed hash — first 3 elements of `Poseidon2(server_seed)`.
|
|
257
389
|
*
|
|
390
|
+
* 192 bits of commitment → ~96-bit collision resistance, which closes the
|
|
391
|
+
* multi-preimage grinding vector that an earlier 128-bit truncation left open.
|
|
258
392
|
* This is the exact format stored in the Merkle-tree leaf and verified
|
|
259
393
|
* by the circuit. Matches `seed_hash_truncated` in
|
|
260
|
-
* `src/block_builder/builder.rs` and `src/circuit/
|
|
394
|
+
* `src/block_builder/builder.rs` and `src/circuit/slot/fairness.rs`.
|
|
261
395
|
*
|
|
262
|
-
* Returns `BigUint64Array` of length
|
|
396
|
+
* Returns `BigUint64Array` of length 3: `[h[0], h[1], h[2]]`.
|
|
263
397
|
* @param {BigUint64Array} server_seed
|
|
264
398
|
* @returns {BigUint64Array}
|
|
265
399
|
*/
|
|
Binary file
|
|
@@ -3,11 +3,16 @@
|
|
|
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;
|
|
9
12
|
export const goldilocks_fields_to_hex: (a: number, b: number, c: number) => void;
|
|
10
13
|
export const goldilocks_reduce: (a: bigint) => bigint;
|
|
14
|
+
export const hash_balance_leaf: (a: number, b: number, c: number) => void;
|
|
15
|
+
export const make_main_leaf: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
11
16
|
export const poseidon2_hash: (a: number, b: number, c: number) => void;
|
|
12
17
|
export const poseidon2_two_to_one: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
13
18
|
export const seed_hash_truncated: (a: number, b: number, c: number) => void;
|
package/js/browser.d.mts
CHANGED
|
@@ -13,6 +13,11 @@ export {
|
|
|
13
13
|
goldilocks_reduce,
|
|
14
14
|
amount_split,
|
|
15
15
|
compute_address_hash,
|
|
16
|
+
hash_balance_leaf,
|
|
17
|
+
make_main_leaf,
|
|
18
|
+
compute_payout_dice,
|
|
19
|
+
compute_roll_dice,
|
|
20
|
+
compute_multi_dice,
|
|
16
21
|
} from '../dist/web/rolly_wasm_signer.js';
|
|
17
22
|
|
|
18
23
|
export { default as init } from '../dist/web/rolly_wasm_signer.js';
|
package/js/browser.mjs
CHANGED
package/js/index.d.ts
CHANGED
package/js/node-inline.cjs
CHANGED
|
@@ -17,4 +17,9 @@ module.exports = {
|
|
|
17
17
|
goldilocks_reduce: wasm.goldilocks_reduce,
|
|
18
18
|
amount_split: wasm.amount_split,
|
|
19
19
|
compute_address_hash: wasm.compute_address_hash,
|
|
20
|
+
hash_balance_leaf: wasm.hash_balance_leaf,
|
|
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,
|
|
20
25
|
};
|
package/js/node-inline.mjs
CHANGED
package/js/node.cjs
CHANGED
|
@@ -17,4 +17,9 @@ module.exports = {
|
|
|
17
17
|
goldilocks_reduce: wasm.goldilocks_reduce,
|
|
18
18
|
amount_split: wasm.amount_split,
|
|
19
19
|
compute_address_hash: wasm.compute_address_hash,
|
|
20
|
+
hash_balance_leaf: wasm.hash_balance_leaf,
|
|
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,
|
|
20
25
|
};
|
package/js/node.mjs
CHANGED
package/js/react.d.mts
CHANGED
|
@@ -15,6 +15,11 @@ export interface RollyWasmResult {
|
|
|
15
15
|
goldilocks_reduce: (value: bigint) => bigint;
|
|
16
16
|
amount_split: (amount: bigint) => Uint32Array;
|
|
17
17
|
compute_address_hash: (address_hex: string) => BigUint64Array;
|
|
18
|
+
hash_balance_leaf: (raw: BigUint64Array) => BigUint64Array;
|
|
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;
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
export function useRollyWasm(): RollyWasmResult;
|
package/js/react.mjs
CHANGED
|
@@ -14,6 +14,11 @@ import init, {
|
|
|
14
14
|
goldilocks_reduce,
|
|
15
15
|
amount_split,
|
|
16
16
|
compute_address_hash,
|
|
17
|
+
hash_balance_leaf,
|
|
18
|
+
make_main_leaf,
|
|
19
|
+
compute_payout_dice,
|
|
20
|
+
compute_roll_dice,
|
|
21
|
+
compute_multi_dice,
|
|
17
22
|
} from '../dist/web/rolly_wasm_signer.js';
|
|
18
23
|
|
|
19
24
|
let _ready = false;
|
|
@@ -41,6 +46,11 @@ const fns = {
|
|
|
41
46
|
goldilocks_reduce: guard(goldilocks_reduce),
|
|
42
47
|
amount_split: guard(amount_split),
|
|
43
48
|
compute_address_hash: guard(compute_address_hash),
|
|
49
|
+
hash_balance_leaf: guard(hash_balance_leaf),
|
|
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),
|
|
44
54
|
};
|
|
45
55
|
|
|
46
56
|
/**
|