@rolly-dev/wasm-signer 0.13.1 → 1.0.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 +1 -1
- package/dist/node/README.md +1 -1
- package/dist/node/rolly_wasm_signer.d.ts +41 -4
- package/dist/node/rolly_wasm_signer.js +81 -4
- package/dist/node/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/node/rolly_wasm_signer_bg.wasm.d.ts +2 -0
- package/dist/node-inline/README.md +1 -1
- package/dist/node-inline/rolly_wasm_signer.d.ts +41 -4
- package/dist/node-inline/rolly_wasm_signer.js +82 -5
- package/dist/node-inline/rolly_wasm_signer.mjs +81 -6
- package/dist/node-inline/rolly_wasm_signer_bg.wasm.d.ts +2 -0
- package/dist/web/README.md +1 -1
- package/dist/web/rolly_wasm_signer.d.ts +43 -4
- package/dist/web/rolly_wasm_signer.js +79 -4
- package/dist/web/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/web/rolly_wasm_signer_bg.wasm.d.ts +2 -0
- package/js/browser.d.mts +2 -0
- package/js/browser.mjs +2 -0
- package/js/index.d.ts +2 -0
- package/js/node-inline.cjs +2 -0
- package/js/node-inline.mjs +2 -0
- package/js/node.cjs +2 -0
- package/js/node.mjs +2 -0
- package/js/react.d.mts +2 -0
- package/js/react.mjs +4 -0
- package/package.json +1 -1
package/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
|
|
package/dist/node/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
|
|
|
@@ -22,7 +22,7 @@ export function compute_address_hash(address_hex: string): BigUint64Array;
|
|
|
22
22
|
* Full Poseidon2 hash of an 8-element server seed.
|
|
23
23
|
*
|
|
24
24
|
* Returns all 4 hash elements. Note: the circuit stores only the
|
|
25
|
-
* **first
|
|
25
|
+
* **first 3 elements** as the leaf commitment (see `seed_hash_truncated`).
|
|
26
26
|
* This full variant is useful for client-side verification where all
|
|
27
27
|
* 4 elements may be needed.
|
|
28
28
|
*
|
|
@@ -86,6 +86,41 @@ export function goldilocks_modulus(): bigint;
|
|
|
86
86
|
*/
|
|
87
87
|
export function goldilocks_reduce(value: bigint): bigint;
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Hash a raw 7-element balance leaf → 4-element Merkle node.
|
|
91
|
+
*
|
|
92
|
+
* Raw layout: `[balance_lo, balance_hi, seed_hash_0, seed_hash_1, seed_hash_2, credit_lo, credit_hi]`
|
|
93
|
+
*
|
|
94
|
+
* Identical to `hash_balance_leaf` in `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
95
|
+
*
|
|
96
|
+
* **Input** : `BigUint64Array` of exactly 7 elements (each < `GOLDILOCKS_P`).
|
|
97
|
+
* **Output**: `BigUint64Array` of length 4 (one `HashOut`).
|
|
98
|
+
*
|
|
99
|
+
* ```js
|
|
100
|
+
* const raw = BigUint64Array.from([balLo, balHi, seed0, seed1, seed2, credLo, credHi]);
|
|
101
|
+
* const balanceHash = hash_balance_leaf(raw); // length 4
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export function hash_balance_leaf(raw: BigUint64Array): BigUint64Array;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Build a main Merkle tree leaf from balance_hash, pk_hash, and address_hash.
|
|
108
|
+
*
|
|
109
|
+
* `main_leaf = Poseidon2(balance_hash[4] || pk_hash[0..2] || address_hash[0..2])`
|
|
110
|
+
*
|
|
111
|
+
* Uses truncated (128-bit) pk/address hashes to keep the preimage at 8 elements
|
|
112
|
+
* (single Poseidon2 permutation round). Identical to `make_main_leaf` in
|
|
113
|
+
* `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
114
|
+
*
|
|
115
|
+
* All three inputs must be exactly 4 elements.
|
|
116
|
+
* **Output**: `BigUint64Array` of length 4 (the Merkle leaf hash).
|
|
117
|
+
*
|
|
118
|
+
* ```js
|
|
119
|
+
* const leaf = make_main_leaf(balanceHash, pkHash, addressHash);
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export function make_main_leaf(balance_hash: BigUint64Array, pk_hash: BigUint64Array, address_hash: BigUint64Array): BigUint64Array;
|
|
123
|
+
|
|
89
124
|
/**
|
|
90
125
|
* Poseidon2 hash of an arbitrary number of Goldilocks field elements.
|
|
91
126
|
*
|
|
@@ -113,13 +148,15 @@ export function poseidon2_hash(input: BigUint64Array): BigUint64Array;
|
|
|
113
148
|
export function poseidon2_two_to_one(left: BigUint64Array, right: BigUint64Array): BigUint64Array;
|
|
114
149
|
|
|
115
150
|
/**
|
|
116
|
-
* Truncated seed hash — first
|
|
151
|
+
* Truncated seed hash — first 3 elements of `Poseidon2(server_seed)`.
|
|
117
152
|
*
|
|
153
|
+
* 192 bits of commitment → ~96-bit collision resistance, which closes the
|
|
154
|
+
* multi-preimage grinding vector that an earlier 128-bit truncation left open.
|
|
118
155
|
* This is the exact format stored in the Merkle-tree leaf and verified
|
|
119
156
|
* by the circuit. Matches `seed_hash_truncated` in
|
|
120
|
-
* `src/block_builder/builder.rs` and `src/circuit/
|
|
157
|
+
* `src/block_builder/builder.rs` and `src/circuit/slot/fairness.rs`.
|
|
121
158
|
*
|
|
122
|
-
* Returns `BigUint64Array` of length
|
|
159
|
+
* Returns `BigUint64Array` of length 3: `[h[0], h[1], h[2]]`.
|
|
123
160
|
*/
|
|
124
161
|
export function seed_hash_truncated(server_seed: BigUint64Array): BigUint64Array;
|
|
125
162
|
|
|
@@ -53,7 +53,7 @@ exports.compute_address_hash = compute_address_hash;
|
|
|
53
53
|
* Full Poseidon2 hash of an 8-element server seed.
|
|
54
54
|
*
|
|
55
55
|
* Returns all 4 hash elements. Note: the circuit stores only the
|
|
56
|
-
* **first
|
|
56
|
+
* **first 3 elements** as the leaf commitment (see `seed_hash_truncated`).
|
|
57
57
|
* This full variant is useful for client-side verification where all
|
|
58
58
|
* 4 elements may be needed.
|
|
59
59
|
*
|
|
@@ -199,6 +199,81 @@ function goldilocks_reduce(value) {
|
|
|
199
199
|
}
|
|
200
200
|
exports.goldilocks_reduce = goldilocks_reduce;
|
|
201
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Hash a raw 7-element balance leaf → 4-element Merkle node.
|
|
204
|
+
*
|
|
205
|
+
* Raw layout: `[balance_lo, balance_hi, seed_hash_0, seed_hash_1, seed_hash_2, credit_lo, credit_hi]`
|
|
206
|
+
*
|
|
207
|
+
* Identical to `hash_balance_leaf` in `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
208
|
+
*
|
|
209
|
+
* **Input** : `BigUint64Array` of exactly 7 elements (each < `GOLDILOCKS_P`).
|
|
210
|
+
* **Output**: `BigUint64Array` of length 4 (one `HashOut`).
|
|
211
|
+
*
|
|
212
|
+
* ```js
|
|
213
|
+
* const raw = BigUint64Array.from([balLo, balHi, seed0, seed1, seed2, credLo, credHi]);
|
|
214
|
+
* const balanceHash = hash_balance_leaf(raw); // length 4
|
|
215
|
+
* ```
|
|
216
|
+
* @param {BigUint64Array} raw
|
|
217
|
+
* @returns {BigUint64Array}
|
|
218
|
+
*/
|
|
219
|
+
function hash_balance_leaf(raw) {
|
|
220
|
+
try {
|
|
221
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
222
|
+
const ptr0 = passArray64ToWasm0(raw, wasm.__wbindgen_export3);
|
|
223
|
+
const len0 = WASM_VECTOR_LEN;
|
|
224
|
+
wasm.hash_balance_leaf(retptr, ptr0, len0);
|
|
225
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
226
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
227
|
+
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
228
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
229
|
+
return v2;
|
|
230
|
+
} finally {
|
|
231
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
exports.hash_balance_leaf = hash_balance_leaf;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Build a main Merkle tree leaf from balance_hash, pk_hash, and address_hash.
|
|
238
|
+
*
|
|
239
|
+
* `main_leaf = Poseidon2(balance_hash[4] || pk_hash[0..2] || address_hash[0..2])`
|
|
240
|
+
*
|
|
241
|
+
* Uses truncated (128-bit) pk/address hashes to keep the preimage at 8 elements
|
|
242
|
+
* (single Poseidon2 permutation round). Identical to `make_main_leaf` in
|
|
243
|
+
* `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
244
|
+
*
|
|
245
|
+
* All three inputs must be exactly 4 elements.
|
|
246
|
+
* **Output**: `BigUint64Array` of length 4 (the Merkle leaf hash).
|
|
247
|
+
*
|
|
248
|
+
* ```js
|
|
249
|
+
* const leaf = make_main_leaf(balanceHash, pkHash, addressHash);
|
|
250
|
+
* ```
|
|
251
|
+
* @param {BigUint64Array} balance_hash
|
|
252
|
+
* @param {BigUint64Array} pk_hash
|
|
253
|
+
* @param {BigUint64Array} address_hash
|
|
254
|
+
* @returns {BigUint64Array}
|
|
255
|
+
*/
|
|
256
|
+
function make_main_leaf(balance_hash, pk_hash, address_hash) {
|
|
257
|
+
try {
|
|
258
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
259
|
+
const ptr0 = passArray64ToWasm0(balance_hash, wasm.__wbindgen_export3);
|
|
260
|
+
const len0 = WASM_VECTOR_LEN;
|
|
261
|
+
const ptr1 = passArray64ToWasm0(pk_hash, wasm.__wbindgen_export3);
|
|
262
|
+
const len1 = WASM_VECTOR_LEN;
|
|
263
|
+
const ptr2 = passArray64ToWasm0(address_hash, wasm.__wbindgen_export3);
|
|
264
|
+
const len2 = WASM_VECTOR_LEN;
|
|
265
|
+
wasm.make_main_leaf(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
266
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
267
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
268
|
+
var v4 = getArrayU64FromWasm0(r0, r1).slice();
|
|
269
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
270
|
+
return v4;
|
|
271
|
+
} finally {
|
|
272
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.make_main_leaf = make_main_leaf;
|
|
276
|
+
|
|
202
277
|
/**
|
|
203
278
|
* Poseidon2 hash of an arbitrary number of Goldilocks field elements.
|
|
204
279
|
*
|
|
@@ -263,13 +338,15 @@ function poseidon2_two_to_one(left, right) {
|
|
|
263
338
|
exports.poseidon2_two_to_one = poseidon2_two_to_one;
|
|
264
339
|
|
|
265
340
|
/**
|
|
266
|
-
* Truncated seed hash — first
|
|
341
|
+
* Truncated seed hash — first 3 elements of `Poseidon2(server_seed)`.
|
|
267
342
|
*
|
|
343
|
+
* 192 bits of commitment → ~96-bit collision resistance, which closes the
|
|
344
|
+
* multi-preimage grinding vector that an earlier 128-bit truncation left open.
|
|
268
345
|
* This is the exact format stored in the Merkle-tree leaf and verified
|
|
269
346
|
* by the circuit. Matches `seed_hash_truncated` in
|
|
270
|
-
* `src/block_builder/builder.rs` and `src/circuit/
|
|
347
|
+
* `src/block_builder/builder.rs` and `src/circuit/slot/fairness.rs`.
|
|
271
348
|
*
|
|
272
|
-
* Returns `BigUint64Array` of length
|
|
349
|
+
* Returns `BigUint64Array` of length 3: `[h[0], h[1], h[2]]`.
|
|
273
350
|
* @param {BigUint64Array} server_seed
|
|
274
351
|
* @returns {BigUint64Array}
|
|
275
352
|
*/
|
|
Binary file
|
|
@@ -8,6 +8,8 @@ export const derive_session_key: (a: number, b: number, c: number) => void;
|
|
|
8
8
|
export const generate_user_seed: (a: number) => void;
|
|
9
9
|
export const goldilocks_fields_to_hex: (a: number, b: number, c: number) => void;
|
|
10
10
|
export const goldilocks_reduce: (a: bigint) => bigint;
|
|
11
|
+
export const hash_balance_leaf: (a: number, b: number, c: number) => void;
|
|
12
|
+
export const make_main_leaf: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
11
13
|
export const poseidon2_hash: (a: number, b: number, c: number) => void;
|
|
12
14
|
export const poseidon2_two_to_one: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
13
15
|
export const seed_hash_truncated: (a: number, b: number, c: number) => void;
|
|
@@ -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
|
|
|
@@ -22,7 +22,7 @@ export function compute_address_hash(address_hex: string): BigUint64Array;
|
|
|
22
22
|
* Full Poseidon2 hash of an 8-element server seed.
|
|
23
23
|
*
|
|
24
24
|
* Returns all 4 hash elements. Note: the circuit stores only the
|
|
25
|
-
* **first
|
|
25
|
+
* **first 3 elements** as the leaf commitment (see `seed_hash_truncated`).
|
|
26
26
|
* This full variant is useful for client-side verification where all
|
|
27
27
|
* 4 elements may be needed.
|
|
28
28
|
*
|
|
@@ -86,6 +86,41 @@ export function goldilocks_modulus(): bigint;
|
|
|
86
86
|
*/
|
|
87
87
|
export function goldilocks_reduce(value: bigint): bigint;
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Hash a raw 7-element balance leaf → 4-element Merkle node.
|
|
91
|
+
*
|
|
92
|
+
* Raw layout: `[balance_lo, balance_hi, seed_hash_0, seed_hash_1, seed_hash_2, credit_lo, credit_hi]`
|
|
93
|
+
*
|
|
94
|
+
* Identical to `hash_balance_leaf` in `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
95
|
+
*
|
|
96
|
+
* **Input** : `BigUint64Array` of exactly 7 elements (each < `GOLDILOCKS_P`).
|
|
97
|
+
* **Output**: `BigUint64Array` of length 4 (one `HashOut`).
|
|
98
|
+
*
|
|
99
|
+
* ```js
|
|
100
|
+
* const raw = BigUint64Array.from([balLo, balHi, seed0, seed1, seed2, credLo, credHi]);
|
|
101
|
+
* const balanceHash = hash_balance_leaf(raw); // length 4
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export function hash_balance_leaf(raw: BigUint64Array): BigUint64Array;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Build a main Merkle tree leaf from balance_hash, pk_hash, and address_hash.
|
|
108
|
+
*
|
|
109
|
+
* `main_leaf = Poseidon2(balance_hash[4] || pk_hash[0..2] || address_hash[0..2])`
|
|
110
|
+
*
|
|
111
|
+
* Uses truncated (128-bit) pk/address hashes to keep the preimage at 8 elements
|
|
112
|
+
* (single Poseidon2 permutation round). Identical to `make_main_leaf` in
|
|
113
|
+
* `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
114
|
+
*
|
|
115
|
+
* All three inputs must be exactly 4 elements.
|
|
116
|
+
* **Output**: `BigUint64Array` of length 4 (the Merkle leaf hash).
|
|
117
|
+
*
|
|
118
|
+
* ```js
|
|
119
|
+
* const leaf = make_main_leaf(balanceHash, pkHash, addressHash);
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export function make_main_leaf(balance_hash: BigUint64Array, pk_hash: BigUint64Array, address_hash: BigUint64Array): BigUint64Array;
|
|
123
|
+
|
|
89
124
|
/**
|
|
90
125
|
* Poseidon2 hash of an arbitrary number of Goldilocks field elements.
|
|
91
126
|
*
|
|
@@ -113,13 +148,15 @@ export function poseidon2_hash(input: BigUint64Array): BigUint64Array;
|
|
|
113
148
|
export function poseidon2_two_to_one(left: BigUint64Array, right: BigUint64Array): BigUint64Array;
|
|
114
149
|
|
|
115
150
|
/**
|
|
116
|
-
* Truncated seed hash — first
|
|
151
|
+
* Truncated seed hash — first 3 elements of `Poseidon2(server_seed)`.
|
|
117
152
|
*
|
|
153
|
+
* 192 bits of commitment → ~96-bit collision resistance, which closes the
|
|
154
|
+
* multi-preimage grinding vector that an earlier 128-bit truncation left open.
|
|
118
155
|
* This is the exact format stored in the Merkle-tree leaf and verified
|
|
119
156
|
* by the circuit. Matches `seed_hash_truncated` in
|
|
120
|
-
* `src/block_builder/builder.rs` and `src/circuit/
|
|
157
|
+
* `src/block_builder/builder.rs` and `src/circuit/slot/fairness.rs`.
|
|
121
158
|
*
|
|
122
|
-
* Returns `BigUint64Array` of length
|
|
159
|
+
* Returns `BigUint64Array` of length 3: `[h[0], h[1], h[2]]`.
|
|
123
160
|
*/
|
|
124
161
|
export function seed_hash_truncated(server_seed: BigUint64Array): BigUint64Array;
|
|
125
162
|
|