@rolly-dev/wasm-signer 1.5.1 → 1.7.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/dist/node/rolly_wasm_signer.d.ts +38 -0
- package/dist/node/rolly_wasm_signer.js +92 -0
- package/dist/node/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/node/rolly_wasm_signer_bg.wasm.d.ts +3 -0
- package/dist/node-inline/rolly_wasm_signer.d.ts +38 -0
- package/dist/node-inline/rolly_wasm_signer.js +93 -1
- package/dist/node-inline/rolly_wasm_signer.mjs +91 -2
- package/dist/node-inline/rolly_wasm_signer_bg.wasm.d.ts +3 -0
- package/dist/web/rolly_wasm_signer.d.ts +41 -0
- package/dist/web/rolly_wasm_signer.js +89 -0
- package/dist/web/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/web/rolly_wasm_signer_bg.wasm.d.ts +3 -0
- package/js/browser.mjs +3 -0
- package/js/index.d.ts +3 -0
- package/js/node-inline.cjs +3 -0
- package/js/node-inline.mjs +3 -0
- package/js/node.cjs +3 -0
- package/js/node.mjs +3 -0
- package/js/react.mjs +6 -0
- package/package.json +1 -1
|
@@ -51,6 +51,18 @@ export function compute_payout_dice(random: BigUint64Array, bet_atomic: bigint,
|
|
|
51
51
|
*/
|
|
52
52
|
export function compute_payout_plinko(random: BigUint64Array, bet_atomic: bigint, sector: number, rows: number, is_extreme: boolean): BigUint64Array;
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Compute prediction hash: `Poseidon2(game_id, p0, p1, p2)` → 4 field elements.
|
|
56
|
+
*
|
|
57
|
+
* Matches `compute_prediction_hash_native` in the circuit (`games/shared.rs`)
|
|
58
|
+
* and the in-circuit `build_prediction_hash`.
|
|
59
|
+
*
|
|
60
|
+
* Semantics of p0–p2 depend on the game:
|
|
61
|
+
* Dice: `(mode, pred_lo, pred_hi)`
|
|
62
|
+
* Plinko: `(sector, rows, is_extreme)`
|
|
63
|
+
*/
|
|
64
|
+
export function compute_prediction_hash(game_id: number, p0: number, p1: number, p2: number): BigUint64Array;
|
|
65
|
+
|
|
54
66
|
/**
|
|
55
67
|
* Extract dice roll number [0, 1000) from Poseidon2 random output.
|
|
56
68
|
*
|
|
@@ -79,6 +91,19 @@ export function compute_roll_plinko(random: BigUint64Array, rows: number): numbe
|
|
|
79
91
|
*/
|
|
80
92
|
export function compute_server_seed_hash(server_seed: BigUint64Array): BigUint64Array;
|
|
81
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Compute user seed with bet-parameter binding:
|
|
96
|
+
* `Poseidon2(game_id, bet, pred_hash[4], secret[4])` → 4 field elements.
|
|
97
|
+
*
|
|
98
|
+
* Matches the circuit constraint in `slot/fairness.rs`.
|
|
99
|
+
* Prevents the operator from swapping bet parameters after the user commits.
|
|
100
|
+
*
|
|
101
|
+
* `bet` is the full bet amount in atomic units (u64).
|
|
102
|
+
* `pred_hash` must be 4 elements (output of `compute_prediction_hash`).
|
|
103
|
+
* `secret` must be 4 elements (output of `generate_user_secret`).
|
|
104
|
+
*/
|
|
105
|
+
export function compute_user_seed_binding(game_id: number, bet: bigint, pred_hash: BigUint64Array, secret: BigUint64Array): BigUint64Array;
|
|
106
|
+
|
|
82
107
|
/**
|
|
83
108
|
* Derive a session key from 32 bytes of entropy (e.g. MetaMask signature).
|
|
84
109
|
*
|
|
@@ -97,6 +122,19 @@ export function compute_server_seed_hash(server_seed: BigUint64Array): BigUint64
|
|
|
97
122
|
*/
|
|
98
123
|
export function derive_session_key(sig_bytes: Uint8Array): BigUint64Array;
|
|
99
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Generate a cryptographically random user secret — 4 Goldilocks field elements.
|
|
127
|
+
*
|
|
128
|
+
* Each element is reduced mod p for canonical representation (safe for circuit use).
|
|
129
|
+
* Uses `getrandom` (`crypto.getRandomValues` in browser, OS entropy in Node.js).
|
|
130
|
+
*
|
|
131
|
+
* ```js
|
|
132
|
+
* const secret = generate_user_secret();
|
|
133
|
+
* // secret.length === 4, each < GOLDILOCKS_P
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export function generate_user_secret(): BigUint64Array;
|
|
137
|
+
|
|
100
138
|
/**
|
|
101
139
|
* Generate a random user seed — 10 alphanumeric characters.
|
|
102
140
|
*
|
|
@@ -130,6 +130,36 @@ function compute_payout_plinko(random, bet_atomic, sector, rows, is_extreme) {
|
|
|
130
130
|
}
|
|
131
131
|
exports.compute_payout_plinko = compute_payout_plinko;
|
|
132
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Compute prediction hash: `Poseidon2(game_id, p0, p1, p2)` → 4 field elements.
|
|
135
|
+
*
|
|
136
|
+
* Matches `compute_prediction_hash_native` in the circuit (`games/shared.rs`)
|
|
137
|
+
* and the in-circuit `build_prediction_hash`.
|
|
138
|
+
*
|
|
139
|
+
* Semantics of p0–p2 depend on the game:
|
|
140
|
+
* Dice: `(mode, pred_lo, pred_hi)`
|
|
141
|
+
* Plinko: `(sector, rows, is_extreme)`
|
|
142
|
+
* @param {number} game_id
|
|
143
|
+
* @param {number} p0
|
|
144
|
+
* @param {number} p1
|
|
145
|
+
* @param {number} p2
|
|
146
|
+
* @returns {BigUint64Array}
|
|
147
|
+
*/
|
|
148
|
+
function compute_prediction_hash(game_id, p0, p1, p2) {
|
|
149
|
+
try {
|
|
150
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
151
|
+
wasm.compute_prediction_hash(retptr, game_id, p0, p1, p2);
|
|
152
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
153
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
154
|
+
var v1 = getArrayU64FromWasm0(r0, r1).slice();
|
|
155
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
156
|
+
return v1;
|
|
157
|
+
} finally {
|
|
158
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.compute_prediction_hash = compute_prediction_hash;
|
|
162
|
+
|
|
133
163
|
/**
|
|
134
164
|
* Extract dice roll number [0, 1000) from Poseidon2 random output.
|
|
135
165
|
*
|
|
@@ -192,6 +222,41 @@ function compute_server_seed_hash(server_seed) {
|
|
|
192
222
|
}
|
|
193
223
|
exports.compute_server_seed_hash = compute_server_seed_hash;
|
|
194
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Compute user seed with bet-parameter binding:
|
|
227
|
+
* `Poseidon2(game_id, bet, pred_hash[4], secret[4])` → 4 field elements.
|
|
228
|
+
*
|
|
229
|
+
* Matches the circuit constraint in `slot/fairness.rs`.
|
|
230
|
+
* Prevents the operator from swapping bet parameters after the user commits.
|
|
231
|
+
*
|
|
232
|
+
* `bet` is the full bet amount in atomic units (u64).
|
|
233
|
+
* `pred_hash` must be 4 elements (output of `compute_prediction_hash`).
|
|
234
|
+
* `secret` must be 4 elements (output of `generate_user_secret`).
|
|
235
|
+
* @param {number} game_id
|
|
236
|
+
* @param {bigint} bet
|
|
237
|
+
* @param {BigUint64Array} pred_hash
|
|
238
|
+
* @param {BigUint64Array} secret
|
|
239
|
+
* @returns {BigUint64Array}
|
|
240
|
+
*/
|
|
241
|
+
function compute_user_seed_binding(game_id, bet, pred_hash, secret) {
|
|
242
|
+
try {
|
|
243
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
244
|
+
const ptr0 = passArray64ToWasm0(pred_hash, wasm.__wbindgen_export3);
|
|
245
|
+
const len0 = WASM_VECTOR_LEN;
|
|
246
|
+
const ptr1 = passArray64ToWasm0(secret, wasm.__wbindgen_export3);
|
|
247
|
+
const len1 = WASM_VECTOR_LEN;
|
|
248
|
+
wasm.compute_user_seed_binding(retptr, game_id, bet, ptr0, len0, ptr1, len1);
|
|
249
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
250
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
251
|
+
var v3 = getArrayU64FromWasm0(r0, r1).slice();
|
|
252
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
253
|
+
return v3;
|
|
254
|
+
} finally {
|
|
255
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
exports.compute_user_seed_binding = compute_user_seed_binding;
|
|
259
|
+
|
|
195
260
|
/**
|
|
196
261
|
* Derive a session key from 32 bytes of entropy (e.g. MetaMask signature).
|
|
197
262
|
*
|
|
@@ -227,6 +292,33 @@ function derive_session_key(sig_bytes) {
|
|
|
227
292
|
}
|
|
228
293
|
exports.derive_session_key = derive_session_key;
|
|
229
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Generate a cryptographically random user secret — 4 Goldilocks field elements.
|
|
297
|
+
*
|
|
298
|
+
* Each element is reduced mod p for canonical representation (safe for circuit use).
|
|
299
|
+
* Uses `getrandom` (`crypto.getRandomValues` in browser, OS entropy in Node.js).
|
|
300
|
+
*
|
|
301
|
+
* ```js
|
|
302
|
+
* const secret = generate_user_secret();
|
|
303
|
+
* // secret.length === 4, each < GOLDILOCKS_P
|
|
304
|
+
* ```
|
|
305
|
+
* @returns {BigUint64Array}
|
|
306
|
+
*/
|
|
307
|
+
function generate_user_secret() {
|
|
308
|
+
try {
|
|
309
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
310
|
+
wasm.generate_user_secret(retptr);
|
|
311
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
312
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
313
|
+
var v1 = getArrayU64FromWasm0(r0, r1).slice();
|
|
314
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
315
|
+
return v1;
|
|
316
|
+
} finally {
|
|
317
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
exports.generate_user_secret = generate_user_secret;
|
|
321
|
+
|
|
230
322
|
/**
|
|
231
323
|
* Generate a random user seed — 10 alphanumeric characters.
|
|
232
324
|
*
|
|
Binary file
|
|
@@ -6,10 +6,13 @@ export const compute_address_hash: (a: number, b: number, c: number) => void;
|
|
|
6
6
|
export const compute_multi_dice: (a: number) => bigint;
|
|
7
7
|
export const compute_payout_dice: (a: number, b: number, c: number, d: bigint, e: number, f: number, g: number) => void;
|
|
8
8
|
export const compute_payout_plinko: (a: number, b: number, c: number, d: bigint, e: number, f: number, g: number) => void;
|
|
9
|
+
export const compute_prediction_hash: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
9
10
|
export const compute_roll_dice: (a: number, b: number) => number;
|
|
10
11
|
export const compute_roll_plinko: (a: number, b: number, c: number) => number;
|
|
11
12
|
export const compute_server_seed_hash: (a: number, b: number, c: number) => void;
|
|
13
|
+
export const compute_user_seed_binding: (a: number, b: number, c: bigint, d: number, e: number, f: number, g: number) => void;
|
|
12
14
|
export const derive_session_key: (a: number, b: number, c: number) => void;
|
|
15
|
+
export const generate_user_secret: (a: number) => void;
|
|
13
16
|
export const generate_user_seed: (a: number) => void;
|
|
14
17
|
export const goldilocks_fields_to_hex: (a: number, b: number, c: number) => void;
|
|
15
18
|
export const goldilocks_reduce: (a: bigint) => bigint;
|
|
@@ -51,6 +51,18 @@ export function compute_payout_dice(random: BigUint64Array, bet_atomic: bigint,
|
|
|
51
51
|
*/
|
|
52
52
|
export function compute_payout_plinko(random: BigUint64Array, bet_atomic: bigint, sector: number, rows: number, is_extreme: boolean): BigUint64Array;
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Compute prediction hash: `Poseidon2(game_id, p0, p1, p2)` → 4 field elements.
|
|
56
|
+
*
|
|
57
|
+
* Matches `compute_prediction_hash_native` in the circuit (`games/shared.rs`)
|
|
58
|
+
* and the in-circuit `build_prediction_hash`.
|
|
59
|
+
*
|
|
60
|
+
* Semantics of p0–p2 depend on the game:
|
|
61
|
+
* Dice: `(mode, pred_lo, pred_hi)`
|
|
62
|
+
* Plinko: `(sector, rows, is_extreme)`
|
|
63
|
+
*/
|
|
64
|
+
export function compute_prediction_hash(game_id: number, p0: number, p1: number, p2: number): BigUint64Array;
|
|
65
|
+
|
|
54
66
|
/**
|
|
55
67
|
* Extract dice roll number [0, 1000) from Poseidon2 random output.
|
|
56
68
|
*
|
|
@@ -79,6 +91,19 @@ export function compute_roll_plinko(random: BigUint64Array, rows: number): numbe
|
|
|
79
91
|
*/
|
|
80
92
|
export function compute_server_seed_hash(server_seed: BigUint64Array): BigUint64Array;
|
|
81
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Compute user seed with bet-parameter binding:
|
|
96
|
+
* `Poseidon2(game_id, bet, pred_hash[4], secret[4])` → 4 field elements.
|
|
97
|
+
*
|
|
98
|
+
* Matches the circuit constraint in `slot/fairness.rs`.
|
|
99
|
+
* Prevents the operator from swapping bet parameters after the user commits.
|
|
100
|
+
*
|
|
101
|
+
* `bet` is the full bet amount in atomic units (u64).
|
|
102
|
+
* `pred_hash` must be 4 elements (output of `compute_prediction_hash`).
|
|
103
|
+
* `secret` must be 4 elements (output of `generate_user_secret`).
|
|
104
|
+
*/
|
|
105
|
+
export function compute_user_seed_binding(game_id: number, bet: bigint, pred_hash: BigUint64Array, secret: BigUint64Array): BigUint64Array;
|
|
106
|
+
|
|
82
107
|
/**
|
|
83
108
|
* Derive a session key from 32 bytes of entropy (e.g. MetaMask signature).
|
|
84
109
|
*
|
|
@@ -97,6 +122,19 @@ export function compute_server_seed_hash(server_seed: BigUint64Array): BigUint64
|
|
|
97
122
|
*/
|
|
98
123
|
export function derive_session_key(sig_bytes: Uint8Array): BigUint64Array;
|
|
99
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Generate a cryptographically random user secret — 4 Goldilocks field elements.
|
|
127
|
+
*
|
|
128
|
+
* Each element is reduced mod p for canonical representation (safe for circuit use).
|
|
129
|
+
* Uses `getrandom` (`crypto.getRandomValues` in browser, OS entropy in Node.js).
|
|
130
|
+
*
|
|
131
|
+
* ```js
|
|
132
|
+
* const secret = generate_user_secret();
|
|
133
|
+
* // secret.length === 4, each < GOLDILOCKS_P
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export function generate_user_secret(): BigUint64Array;
|
|
137
|
+
|
|
100
138
|
/**
|
|
101
139
|
* Generate a random user seed — 10 alphanumeric characters.
|
|
102
140
|
*
|