@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
|
@@ -51,7 +51,7 @@ export function compute_address_hash(address_hex) {
|
|
|
51
51
|
* Full Poseidon2 hash of an 8-element server seed.
|
|
52
52
|
*
|
|
53
53
|
* Returns all 4 hash elements. Note: the circuit stores only the
|
|
54
|
-
* **first
|
|
54
|
+
* **first 3 elements** as the leaf commitment (see `seed_hash_truncated`).
|
|
55
55
|
* This full variant is useful for client-side verification where all
|
|
56
56
|
* 4 elements may be needed.
|
|
57
57
|
*
|
|
@@ -191,6 +191,79 @@ export function goldilocks_reduce(value) {
|
|
|
191
191
|
return BigInt.asUintN(64, ret);
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Hash a raw 7-element balance leaf → 4-element Merkle node.
|
|
196
|
+
*
|
|
197
|
+
* Raw layout: `[balance_lo, balance_hi, seed_hash_0, seed_hash_1, seed_hash_2, credit_lo, credit_hi]`
|
|
198
|
+
*
|
|
199
|
+
* Identical to `hash_balance_leaf` in `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
200
|
+
*
|
|
201
|
+
* **Input** : `BigUint64Array` of exactly 7 elements (each < `GOLDILOCKS_P`).
|
|
202
|
+
* **Output**: `BigUint64Array` of length 4 (one `HashOut`).
|
|
203
|
+
*
|
|
204
|
+
* ```js
|
|
205
|
+
* const raw = BigUint64Array.from([balLo, balHi, seed0, seed1, seed2, credLo, credHi]);
|
|
206
|
+
* const balanceHash = hash_balance_leaf(raw); // length 4
|
|
207
|
+
* ```
|
|
208
|
+
* @param {BigUint64Array} raw
|
|
209
|
+
* @returns {BigUint64Array}
|
|
210
|
+
*/
|
|
211
|
+
export function hash_balance_leaf(raw) {
|
|
212
|
+
try {
|
|
213
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
214
|
+
const ptr0 = passArray64ToWasm0(raw, wasm.__wbindgen_export3);
|
|
215
|
+
const len0 = WASM_VECTOR_LEN;
|
|
216
|
+
wasm.hash_balance_leaf(retptr, ptr0, len0);
|
|
217
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
218
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
219
|
+
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
220
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
221
|
+
return v2;
|
|
222
|
+
} finally {
|
|
223
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Build a main Merkle tree leaf from balance_hash, pk_hash, and address_hash.
|
|
229
|
+
*
|
|
230
|
+
* `main_leaf = Poseidon2(balance_hash[4] || pk_hash[0..2] || address_hash[0..2])`
|
|
231
|
+
*
|
|
232
|
+
* Uses truncated (128-bit) pk/address hashes to keep the preimage at 8 elements
|
|
233
|
+
* (single Poseidon2 permutation round). Identical to `make_main_leaf` in
|
|
234
|
+
* `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
235
|
+
*
|
|
236
|
+
* All three inputs must be exactly 4 elements.
|
|
237
|
+
* **Output**: `BigUint64Array` of length 4 (the Merkle leaf hash).
|
|
238
|
+
*
|
|
239
|
+
* ```js
|
|
240
|
+
* const leaf = make_main_leaf(balanceHash, pkHash, addressHash);
|
|
241
|
+
* ```
|
|
242
|
+
* @param {BigUint64Array} balance_hash
|
|
243
|
+
* @param {BigUint64Array} pk_hash
|
|
244
|
+
* @param {BigUint64Array} address_hash
|
|
245
|
+
* @returns {BigUint64Array}
|
|
246
|
+
*/
|
|
247
|
+
export function make_main_leaf(balance_hash, pk_hash, address_hash) {
|
|
248
|
+
try {
|
|
249
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
250
|
+
const ptr0 = passArray64ToWasm0(balance_hash, wasm.__wbindgen_export3);
|
|
251
|
+
const len0 = WASM_VECTOR_LEN;
|
|
252
|
+
const ptr1 = passArray64ToWasm0(pk_hash, wasm.__wbindgen_export3);
|
|
253
|
+
const len1 = WASM_VECTOR_LEN;
|
|
254
|
+
const ptr2 = passArray64ToWasm0(address_hash, wasm.__wbindgen_export3);
|
|
255
|
+
const len2 = WASM_VECTOR_LEN;
|
|
256
|
+
wasm.make_main_leaf(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
257
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
258
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
259
|
+
var v4 = getArrayU64FromWasm0(r0, r1).slice();
|
|
260
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
261
|
+
return v4;
|
|
262
|
+
} finally {
|
|
263
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
194
267
|
/**
|
|
195
268
|
* Poseidon2 hash of an arbitrary number of Goldilocks field elements.
|
|
196
269
|
*
|
|
@@ -253,13 +326,15 @@ export function poseidon2_two_to_one(left, right) {
|
|
|
253
326
|
}
|
|
254
327
|
|
|
255
328
|
/**
|
|
256
|
-
* Truncated seed hash — first
|
|
329
|
+
* Truncated seed hash — first 3 elements of `Poseidon2(server_seed)`.
|
|
257
330
|
*
|
|
331
|
+
* 192 bits of commitment → ~96-bit collision resistance, which closes the
|
|
332
|
+
* multi-preimage grinding vector that an earlier 128-bit truncation left open.
|
|
258
333
|
* This is the exact format stored in the Merkle-tree leaf and verified
|
|
259
334
|
* by the circuit. Matches `seed_hash_truncated` in
|
|
260
|
-
* `src/block_builder/builder.rs` and `src/circuit/
|
|
335
|
+
* `src/block_builder/builder.rs` and `src/circuit/slot/fairness.rs`.
|
|
261
336
|
*
|
|
262
|
-
* Returns `BigUint64Array` of length
|
|
337
|
+
* Returns `BigUint64Array` of length 3: `[h[0], h[1], h[2]]`.
|
|
263
338
|
* @param {BigUint64Array} server_seed
|
|
264
339
|
* @returns {BigUint64Array}
|
|
265
340
|
*/
|
|
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;
|
package/js/browser.d.mts
CHANGED
package/js/browser.mjs
CHANGED
package/js/index.d.ts
CHANGED
package/js/node-inline.cjs
CHANGED
package/js/node-inline.mjs
CHANGED
package/js/node.cjs
CHANGED
package/js/node.mjs
CHANGED
package/js/react.d.mts
CHANGED
|
@@ -15,6 +15,8 @@ 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;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
export function useRollyWasm(): RollyWasmResult;
|
package/js/react.mjs
CHANGED
|
@@ -14,6 +14,8 @@ import init, {
|
|
|
14
14
|
goldilocks_reduce,
|
|
15
15
|
amount_split,
|
|
16
16
|
compute_address_hash,
|
|
17
|
+
hash_balance_leaf,
|
|
18
|
+
make_main_leaf,
|
|
17
19
|
} from '../dist/web/rolly_wasm_signer.js';
|
|
18
20
|
|
|
19
21
|
let _ready = false;
|
|
@@ -41,6 +43,8 @@ const fns = {
|
|
|
41
43
|
goldilocks_reduce: guard(goldilocks_reduce),
|
|
42
44
|
amount_split: guard(amount_split),
|
|
43
45
|
compute_address_hash: guard(compute_address_hash),
|
|
46
|
+
hash_balance_leaf: guard(hash_balance_leaf),
|
|
47
|
+
make_main_leaf: guard(make_main_leaf),
|
|
44
48
|
};
|
|
45
49
|
|
|
46
50
|
/**
|