@rolly-dev/wasm-signer 1.31.2 → 1.31.3

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.
@@ -0,0 +1,103 @@
1
+ # @rolly-dev/wasm-signer
2
+
3
+ Server-side Poseidon2 hashing and bet authentication for the Rolly ZK-Rollup casino.
4
+
5
+ Built with Rust → WebAssembly (via `wasm-pack`), using the same Poseidon2 hasher
6
+ and Goldilocks field as the plonky2 proving circuit.
7
+
8
+ Node.js only — the backend and orchestrator run this package; the block explorer
9
+ still consumes the published `1.31.x` browser build for payout verification. The
10
+ web dApp uses the pure-TS `@rolly-dev/auth-sign` package for hashing / signing
11
+ instead (WASM does not load reliably under strict CSP / on some devices), and
12
+ `auth-sign` carries no payout math — `games-core` via this crate is the only
13
+ JS-facing source of it.
14
+
15
+ ## Build
16
+
17
+ ```bash
18
+ # requires: cargo, wasm-pack
19
+ npm run build
20
+ # → dist/node/ (Node.js, CJS, sync init, loads .wasm from disk)
21
+ # → dist/node-inline/ (Node.js, self-contained, WASM embedded as base64)
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Node.js (CommonJS)
27
+
28
+ ```javascript
29
+ const {
30
+ poseidon2_hash,
31
+ derive_session_key,
32
+ session_public_key,
33
+ } = require('@rolly-dev/wasm-signer');
34
+
35
+ const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
36
+ // → BigUint64Array(4)
37
+ ```
38
+
39
+ ### Node.js (ESM)
40
+
41
+ ```javascript
42
+ import {
43
+ poseidon2_hash,
44
+ derive_session_key,
45
+ session_public_key,
46
+ } from '@rolly-dev/wasm-signer';
47
+
48
+ const sessionKey = derive_session_key(metamaskSignatureBytes);
49
+ const pkHash = session_public_key(sessionKey, BigInt(expiryTimestamp));
50
+ ```
51
+
52
+ ## API
53
+
54
+ | Function | Input | Output | Description |
55
+ |----------------------------|--------------------------------|-------------------|------------------------------------------------|
56
+ | `poseidon2_hash` | `BigUint64Array` | `BigUint64Array(4)` | Hash N field elements |
57
+ | `poseidon2_two_to_one` | `BigUint64Array(4)` × 2 | `BigUint64Array(4)` | Merkle hash: H(left‖right) |
58
+ | `derive_session_key` | `Uint8Array(32)` | `BigUint64Array(4)` | MetaMask sig → session key |
59
+ | `session_public_key` | `(BigUint64Array(4), bigint)` | `BigUint64Array(4)` | pk_hash = Poseidon2(session_key, expiry) |
60
+ | `compute_server_seed_hash` | `BigUint64Array(8)` | `BigUint64Array(4)` | Full hash of server seed |
61
+ | `seed_hash_truncated` | `BigUint64Array(8)` | `BigUint64Array(3)` | First 3 elements (circuit leaf format, 192-bit commitment) |
62
+ | `goldilocks_modulus` | — | `bigint` | Returns p = 2^64 - 2^32 + 1 |
63
+ | `goldilocks_reduce` | `bigint` | `bigint` | Reduce mod p |
64
+
65
+ ## Dice — range constraints
66
+
67
+ Roll number: `[0, 999]` (TOTAL_RANGE = 1000).
68
+ win_numbers (wn): `[1, 950]` (MIN_RANGE..=MAX_RANGE).
69
+
70
+ ### prediction_range constraints per mode
71
+
72
+ | Mode | wn formula | prediction\[0\] | prediction\[1\] | wn range |
73
+ |-------|-------------------------------------------------|-----------------|-----------------|------------|
74
+ | Under | `prediction[0]` | `[1, 950]` | unused (0) | `[1, 950]` |
75
+ | Over | `999 − prediction[0]` | `[49, 998]` | unused (0) | `[1, 950]` |
76
+ | In | `prediction[1] − prediction[0] + 1` | `[0, 999]` | `[0, 999]` | `[1, 950]` |
77
+ | Out | `1000 − (prediction[1] − prediction[0] + 1)` | `[0, 999]` | `[0, 999]` | `[1, 950]` |
78
+
79
+ **Under** — `prediction[0]` ∈ `[1, 950]` (= wn directly). Win: `roll < prediction[0]`.
80
+
81
+ **Over** — `prediction[0]` ∈ `[49, 998]` (lower: `999 − 950 = 49`, upper: `999 − 1 = 998`). Win: `roll > prediction[0]`.
82
+
83
+ **In** — `prediction[0] <= prediction[1]`, span ∈ `[1, 950]`. Win: `prediction[0] <= roll <= prediction[1]`.
84
+
85
+ **Out** — `prediction[0] <= prediction[1]`, inner span ∈ `[50, 999]` (wn = `1000 − inner` ∈ `[1, 950]`). Win: `roll < prediction[0] || roll > prediction[1]`.
86
+
87
+ ### Multiplier
88
+
89
+ `multiplier = floor(9_900_000 / wn)` (scaled ×10000).
90
+
91
+ | wn | multiplier | display |
92
+ |-----|-----------|-----------|
93
+ | 1 | 9_900_000 | 990.0000x |
94
+ | 500 | 19_800 | 1.9800x |
95
+ | 950 | 10_421 | 1.0421x |
96
+
97
+ ### RTP
98
+
99
+ Theoretical: **98.998%** (floor-division costs ~0.002%). House edge: **~1.002%**. Max win cap: 10,000 USDT (business rule, not formula).
100
+
101
+ ## License
102
+
103
+ MIT