@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.
- package/README.md +10 -55
- package/dist/node/README.md +10 -55
- package/dist/node/rolly_wasm_signer.d.ts +5 -1
- package/dist/node/rolly_wasm_signer.js +5 -1
- package/dist/node/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/node-inline/README.md +10 -55
- package/dist/node-inline/rolly_wasm_signer.d.ts +5 -1
- package/dist/node-inline/rolly_wasm_signer.js +6 -2
- package/dist/node-inline/rolly_wasm_signer.mjs +6 -2
- package/package.json +6 -25
- package/dist/web/README.md +0 -148
- package/dist/web/rolly_wasm_signer.d.ts +0 -663
- package/dist/web/rolly_wasm_signer.js +0 -1913
- package/dist/web/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/web/rolly_wasm_signer_bg.wasm.d.ts +0 -69
- package/js/browser.d.mts +0 -38
- package/js/browser.mjs +0 -65
- package/js/react.d.mts +0 -56
- package/js/react.mjs +0 -162
package/package.json
CHANGED
|
@@ -1,32 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rolly-dev/wasm-signer",
|
|
3
|
-
"version": "1.31.
|
|
3
|
+
"version": "1.31.2",
|
|
4
4
|
"description": "Poseidon2 hashing & bet signing for Rolly ZK-Rollup (WASM, Goldilocks field)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./js/index.d.ts",
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"import": "./js/node-inline.mjs"
|
|
12
|
-
},
|
|
13
|
-
"browser": "./js/browser.mjs",
|
|
14
|
-
"default": "./js/browser.mjs"
|
|
15
|
-
},
|
|
16
|
-
"./react": {
|
|
17
|
-
"types": "./js/react.d.mts",
|
|
18
|
-
"default": "./js/react.mjs"
|
|
19
|
-
},
|
|
20
|
-
"./init": {
|
|
21
|
-
"types": "./dist/web/rolly_wasm_signer.d.ts",
|
|
22
|
-
"default": "./dist/web/rolly_wasm_signer.js"
|
|
9
|
+
"require": "./js/node-inline.cjs",
|
|
10
|
+
"import": "./js/node-inline.mjs"
|
|
23
11
|
}
|
|
24
12
|
},
|
|
25
13
|
"main": "./js/node-inline.cjs",
|
|
26
|
-
"module": "./js/
|
|
14
|
+
"module": "./js/node-inline.mjs",
|
|
27
15
|
"types": "./js/index.d.ts",
|
|
28
16
|
"files": [
|
|
29
|
-
"dist/",
|
|
17
|
+
"dist/node/",
|
|
18
|
+
"dist/node-inline/",
|
|
30
19
|
"js/"
|
|
31
20
|
],
|
|
32
21
|
"scripts": {
|
|
@@ -35,14 +24,6 @@
|
|
|
35
24
|
"test": "node test.js"
|
|
36
25
|
},
|
|
37
26
|
"sideEffects": false,
|
|
38
|
-
"peerDependencies": {
|
|
39
|
-
"react": ">=17.0.0"
|
|
40
|
-
},
|
|
41
|
-
"peerDependenciesMeta": {
|
|
42
|
-
"react": {
|
|
43
|
-
"optional": true
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
27
|
"keywords": [
|
|
47
28
|
"wasm",
|
|
48
29
|
"poseidon2",
|
package/dist/web/README.md
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
# @rolly-dev/wasm-signer
|
|
2
|
-
|
|
3
|
-
Client-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
|
-
## Build
|
|
9
|
-
|
|
10
|
-
```bash
|
|
11
|
-
# requires: cargo, wasm-pack
|
|
12
|
-
npm run build
|
|
13
|
-
# → dist/node/ (Node.js, CJS, sync init)
|
|
14
|
-
# → dist/web/ (Browser, ESM, async init)
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Usage
|
|
18
|
-
|
|
19
|
-
### Node.js (CommonJS)
|
|
20
|
-
|
|
21
|
-
```javascript
|
|
22
|
-
const {
|
|
23
|
-
poseidon2_hash,
|
|
24
|
-
derive_session_key,
|
|
25
|
-
session_public_key,
|
|
26
|
-
} = require('@rolly-dev/wasm-signer');
|
|
27
|
-
|
|
28
|
-
const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
|
|
29
|
-
// → BigUint64Array(4)
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### Node.js (ESM)
|
|
33
|
-
|
|
34
|
-
```javascript
|
|
35
|
-
import {
|
|
36
|
-
poseidon2_hash,
|
|
37
|
-
derive_session_key,
|
|
38
|
-
session_public_key,
|
|
39
|
-
} from '@rolly-dev/wasm-signer';
|
|
40
|
-
|
|
41
|
-
const sessionKey = derive_session_key(metamaskSignatureBytes);
|
|
42
|
-
const pkHash = session_public_key(sessionKey, BigInt(expiryTimestamp));
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### React
|
|
46
|
-
|
|
47
|
-
```jsx
|
|
48
|
-
import { useRollyWasm } from '@rolly-dev/wasm-signer/react';
|
|
49
|
-
|
|
50
|
-
function SessionInfo({ sessionKey, expiry }) {
|
|
51
|
-
const { ready, session_public_key } = useRollyWasm();
|
|
52
|
-
|
|
53
|
-
if (!ready) return <span>Loading...</span>;
|
|
54
|
-
|
|
55
|
-
const pkHash = session_public_key(sessionKey, BigInt(expiry));
|
|
56
|
-
// register pkHash on-chain via key_register tx...
|
|
57
|
-
|
|
58
|
-
return <div>Session active until {new Date(Number(expiry) * 1000).toLocaleString()}</div>;
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### Browser (vanilla ESM)
|
|
63
|
-
|
|
64
|
-
```html
|
|
65
|
-
<script type="module">
|
|
66
|
-
import { init, poseidon2_hash } from '@rolly-dev/wasm-signer';
|
|
67
|
-
|
|
68
|
-
await init(); // loads .wasm, must be called once
|
|
69
|
-
const h = poseidon2_hash(BigUint64Array.from([1n, 2n]));
|
|
70
|
-
</script>
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### Manual init (advanced)
|
|
74
|
-
|
|
75
|
-
```javascript
|
|
76
|
-
import init, { poseidon2_hash } from '@rolly-dev/wasm-signer/init';
|
|
77
|
-
|
|
78
|
-
// custom wasm URL or ArrayBuffer
|
|
79
|
-
await init('/assets/rolly_wasm_signer_bg.wasm');
|
|
80
|
-
poseidon2_hash(BigUint64Array.from([1n]));
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## API
|
|
84
|
-
|
|
85
|
-
| Function | Input | Output | Description |
|
|
86
|
-
|----------------------------|--------------------------------|-------------------|------------------------------------------------|
|
|
87
|
-
| `poseidon2_hash` | `BigUint64Array` | `BigUint64Array(4)` | Hash N field elements |
|
|
88
|
-
| `poseidon2_two_to_one` | `BigUint64Array(4)` × 2 | `BigUint64Array(4)` | Merkle hash: H(left‖right) |
|
|
89
|
-
| `derive_session_key` | `Uint8Array(32)` | `BigUint64Array(4)` | MetaMask sig → session key |
|
|
90
|
-
| `session_public_key` | `(BigUint64Array(4), bigint)` | `BigUint64Array(4)` | pk_hash = Poseidon2(session_key, expiry) |
|
|
91
|
-
| `compute_server_seed_hash` | `BigUint64Array(8)` | `BigUint64Array(4)` | Full hash of server seed |
|
|
92
|
-
| `seed_hash_truncated` | `BigUint64Array(8)` | `BigUint64Array(3)` | First 3 elements (circuit leaf format, 192-bit commitment) |
|
|
93
|
-
| `goldilocks_modulus` | — | `bigint` | Returns p = 2^64 - 2^32 + 1 |
|
|
94
|
-
| `goldilocks_reduce` | `bigint` | `bigint` | Reduce mod p |
|
|
95
|
-
|
|
96
|
-
## Bundler notes
|
|
97
|
-
|
|
98
|
-
**Vite** — add to `optimizeDeps.exclude`:
|
|
99
|
-
```js
|
|
100
|
-
optimizeDeps: { exclude: ['@rolly-dev/wasm-signer'] }
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
**Webpack 5** — enable WASM experiments:
|
|
104
|
-
```js
|
|
105
|
-
module.exports = { experiments: { asyncWebAssembly: true } };
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
**Next.js** — conditional exports auto-resolve: Node.js entry on server, browser entry on client.
|
|
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
|
-
|
|
146
|
-
## License
|
|
147
|
-
|
|
148
|
-
MIT
|