@rolly-dev/wasm-signer 0.11.0 → 0.13.1
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 +9 -12
- package/dist/node/README.md +9 -12
- package/dist/node/rolly_wasm_signer.d.ts +5 -143
- package/dist/node/rolly_wasm_signer.js +31 -427
- package/dist/node/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/node/rolly_wasm_signer_bg.wasm.d.ts +5 -15
- package/dist/node-inline/README.md +9 -12
- package/dist/node-inline/rolly_wasm_signer.d.ts +5 -143
- package/dist/node-inline/rolly_wasm_signer.js +32 -428
- package/dist/node-inline/rolly_wasm_signer.mjs +662 -0
- package/dist/node-inline/rolly_wasm_signer_bg.wasm.d.ts +5 -15
- package/dist/web/README.md +9 -12
- package/dist/web/rolly_wasm_signer.d.ts +10 -158
- package/dist/web/rolly_wasm_signer.js +31 -417
- package/dist/web/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/web/rolly_wasm_signer_bg.wasm.d.ts +5 -15
- package/js/browser.d.mts +0 -10
- package/js/browser.mjs +0 -10
- package/js/index.d.ts +0 -10
- package/js/node-inline.cjs +0 -10
- package/js/node-inline.mjs +2 -17
- package/js/node.cjs +0 -10
- package/js/node.mjs +0 -10
- package/js/react.d.mts +1 -11
- package/js/react.mjs +0 -20
- package/package.json +1 -1
|
@@ -4,29 +4,19 @@ export const memory: WebAssembly.Memory;
|
|
|
4
4
|
export const amount_split: (a: number, b: bigint) => void;
|
|
5
5
|
export const compute_address_hash: (a: number, b: number, c: number) => void;
|
|
6
6
|
export const compute_server_seed_hash: (a: number, b: number, c: number) => void;
|
|
7
|
-
export const compute_tx_msg_hash: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint) => void;
|
|
8
|
-
export const create_bet_auth: (a: number, b: number, c: number, d: bigint, e: bigint) => void;
|
|
9
7
|
export const derive_session_key: (a: number, b: number, c: number) => void;
|
|
10
8
|
export const generate_user_seed: (a: number) => void;
|
|
11
9
|
export const goldilocks_fields_to_hex: (a: number, b: number, c: number) => void;
|
|
12
10
|
export const goldilocks_reduce: (a: bigint) => bigint;
|
|
13
11
|
export const poseidon2_hash: (a: number, b: number, c: number) => void;
|
|
14
12
|
export const poseidon2_two_to_one: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
15
|
-
export const schnorr_keygen: (a: number, b: number, c: number) => void;
|
|
16
|
-
export const schnorr_pk_encode: (a: number, b: number, c: number) => void;
|
|
17
|
-
export const schnorr_pk_hash: (a: number, b: number, c: number) => void;
|
|
18
|
-
export const schnorr_pk_hash_hex: (a: number, b: number, c: number) => void;
|
|
19
|
-
export const schnorr_pubkey: (a: number, b: number, c: number) => void;
|
|
20
|
-
export const schnorr_sign_cpk: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
21
|
-
export const schnorr_sign_tx: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint) => number;
|
|
22
|
-
export const schnorr_verify_tx: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: bigint) => number;
|
|
23
13
|
export const seed_hash_truncated: (a: number, b: number, c: number) => void;
|
|
24
|
-
export const session_public_key: (a: number, b: number, c: number) => void;
|
|
14
|
+
export const session_public_key: (a: number, b: number, c: number, d: bigint) => void;
|
|
25
15
|
export const string_to_user_seed: (a: number, b: number, c: number) => void;
|
|
26
16
|
export const string_to_user_seed_hex: (a: number, b: number, c: number) => void;
|
|
27
17
|
export const goldilocks_modulus: () => bigint;
|
|
28
|
-
export const __wbindgen_export: (a: number
|
|
29
|
-
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
30
|
-
export const __wbindgen_export3: (a: number) => void;
|
|
18
|
+
export const __wbindgen_export: (a: number) => void;
|
|
31
19
|
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
32
|
-
export const
|
|
20
|
+
export const __wbindgen_export2: (a: number, b: number, c: number) => void;
|
|
21
|
+
export const __wbindgen_export3: (a: number, b: number) => number;
|
|
22
|
+
export const __wbindgen_export4: (a: number, b: number, c: number, d: number) => number;
|
package/dist/web/README.md
CHANGED
|
@@ -23,7 +23,6 @@ const {
|
|
|
23
23
|
poseidon2_hash,
|
|
24
24
|
derive_session_key,
|
|
25
25
|
session_public_key,
|
|
26
|
-
create_bet_auth,
|
|
27
26
|
} = require('@rolly-dev/wasm-signer');
|
|
28
27
|
|
|
29
28
|
const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
|
|
@@ -36,10 +35,11 @@ const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
|
|
|
36
35
|
import {
|
|
37
36
|
poseidon2_hash,
|
|
38
37
|
derive_session_key,
|
|
39
|
-
|
|
38
|
+
session_public_key,
|
|
40
39
|
} from '@rolly-dev/wasm-signer';
|
|
41
40
|
|
|
42
|
-
const
|
|
41
|
+
const sessionKey = derive_session_key(metamaskSignatureBytes);
|
|
42
|
+
const pkHash = session_public_key(sessionKey, BigInt(expiryTimestamp));
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
### React
|
|
@@ -47,17 +47,15 @@ const hash = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
|
|
|
47
47
|
```jsx
|
|
48
48
|
import { useRollyWasm } from '@rolly-dev/wasm-signer/react';
|
|
49
49
|
|
|
50
|
-
function
|
|
51
|
-
const { ready,
|
|
50
|
+
function SessionInfo({ sessionKey, expiry }) {
|
|
51
|
+
const { ready, session_public_key } = useRollyWasm();
|
|
52
52
|
|
|
53
53
|
if (!ready) return <span>Loading...</span>;
|
|
54
54
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
// send auth to server...
|
|
58
|
-
};
|
|
55
|
+
const pkHash = session_public_key(sessionKey, BigInt(expiry));
|
|
56
|
+
// register pkHash on-chain via key_register tx...
|
|
59
57
|
|
|
60
|
-
return <
|
|
58
|
+
return <div>Session active until {new Date(Number(expiry) * 1000).toLocaleString()}</div>;
|
|
61
59
|
}
|
|
62
60
|
```
|
|
63
61
|
|
|
@@ -89,8 +87,7 @@ poseidon2_hash(BigUint64Array.from([1n]));
|
|
|
89
87
|
| `poseidon2_hash` | `BigUint64Array` | `BigUint64Array(4)` | Hash N field elements |
|
|
90
88
|
| `poseidon2_two_to_one` | `BigUint64Array(4)` × 2 | `BigUint64Array(4)` | Merkle hash: H(left‖right) |
|
|
91
89
|
| `derive_session_key` | `Uint8Array(32)` | `BigUint64Array(4)` | MetaMask sig → session key |
|
|
92
|
-
| `session_public_key` | `BigUint64Array(4)`
|
|
93
|
-
| `create_bet_auth` | `(BigUint64Array(4), bigint, bigint)` | `BigUint64Array(4)` | MAC = H(sk‖amount_lo‖amount_hi‖nonce) |
|
|
90
|
+
| `session_public_key` | `(BigUint64Array(4), bigint)` | `BigUint64Array(4)` | pk_hash = Poseidon2(session_key, expiry) |
|
|
94
91
|
| `compute_server_seed_hash` | `BigUint64Array(8)` | `BigUint64Array(4)` | Full hash of server seed |
|
|
95
92
|
| `seed_hash_truncated` | `BigUint64Array(8)` | `BigUint64Array(2)` | First 2 elements (circuit leaf format) |
|
|
96
93
|
| `goldilocks_modulus` | — | `bigint` | Returns p = 2^64 - 2^32 + 1 |
|
|
@@ -30,45 +30,6 @@ export function compute_address_hash(address_hex: string): BigUint64Array;
|
|
|
30
30
|
*/
|
|
31
31
|
export function compute_server_seed_hash(server_seed: BigUint64Array): BigUint64Array;
|
|
32
32
|
|
|
33
|
-
/**
|
|
34
|
-
* Compute the transaction message hash (for debugging / verification).
|
|
35
|
-
*
|
|
36
|
-
* Returns `BigUint64Array` of length 4 — the same hash the circuit computes.
|
|
37
|
-
*
|
|
38
|
-
* ```js
|
|
39
|
-
* const hash = compute_tx_msg_hash(5, userId, 0, amountLo, amountHi);
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export function compute_tx_msg_hash(tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number, session_expiry: bigint): BigUint64Array;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Create a `bet_auth` MAC that proves the user authorized this specific bet.
|
|
46
|
-
*
|
|
47
|
-
* ```text
|
|
48
|
-
* bet_auth = Poseidon2(
|
|
49
|
-
* session_key[0..4], // 4 field elements (private)
|
|
50
|
-
* amount_lo, // lower 32 bits of bet_amount
|
|
51
|
-
* amount_hi, // upper 32 bits of bet_amount
|
|
52
|
-
* nonce, // monotonic counter, prevents replay
|
|
53
|
-
* )
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* The circuit verifies two things:
|
|
57
|
-
* 1. `session_pk == Poseidon2(session_key)` — knowledge of key
|
|
58
|
-
* 2. `bet_auth == Poseidon2(session_key ‖ amount_lo ‖ amount_hi ‖ nonce)`
|
|
59
|
-
*
|
|
60
|
-
* The lo/hi split matches `src/circuit/main_circuit.rs` witness assignment:
|
|
61
|
-
* `amount as u32` / `(amount >> 32) as u32`, both via `from_canonical_u32`.
|
|
62
|
-
*
|
|
63
|
-
* **Parameters**
|
|
64
|
-
* - `session_key` : 4 × u64 (private, from `derive_session_key`)
|
|
65
|
-
* - `bet_amount` : u64 (in smallest currency units)
|
|
66
|
-
* - `nonce` : u64 (incrementing per-session counter)
|
|
67
|
-
*
|
|
68
|
-
* **Returns**: 4 × u64 (`bet_auth` hash)
|
|
69
|
-
*/
|
|
70
|
-
export function create_bet_auth(session_key: BigUint64Array, bet_amount: bigint, nonce: bigint): BigUint64Array;
|
|
71
|
-
|
|
72
33
|
/**
|
|
73
34
|
* Derive a session key from 32 bytes of entropy (e.g. MetaMask signature).
|
|
74
35
|
*
|
|
@@ -151,106 +112,6 @@ export function poseidon2_hash(input: BigUint64Array): BigUint64Array;
|
|
|
151
112
|
*/
|
|
152
113
|
export function poseidon2_two_to_one(left: BigUint64Array, right: BigUint64Array): BigUint64Array;
|
|
153
114
|
|
|
154
|
-
/**
|
|
155
|
-
* Derive a Schnorr secret key from entropy bytes (e.g. MetaMask signature).
|
|
156
|
-
*
|
|
157
|
-
* Takes at least 32 bytes, uses `Scalar::decode_reduce` to map them into
|
|
158
|
-
* the ECgFp5 scalar field. Returns hex-encoded secret key (80 chars = 40 bytes).
|
|
159
|
-
*
|
|
160
|
-
* ```js
|
|
161
|
-
* const skHex = schnorr_keygen(sigBytes.slice(0, 32));
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
export function schnorr_keygen(entropy: Uint8Array): string;
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Get the w-encoding of a public key as 5 Goldilocks field elements (for circuit witness).
|
|
168
|
-
*
|
|
169
|
-
* Returns `BigUint64Array` of length 5.
|
|
170
|
-
*
|
|
171
|
-
* ```js
|
|
172
|
-
* const encode = schnorr_pk_encode(pkHex);
|
|
173
|
-
* // encode.length === 5
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
export function schnorr_pk_encode(pk_hex: string): BigUint64Array;
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Compute pk_hash = Poseidon2(w_encoding[5]) from a hex-encoded public key.
|
|
180
|
-
*
|
|
181
|
-
* The w-encoding is the 40-byte (80 hex) representation returned by `schnorr_pubkey`.
|
|
182
|
-
* pk_hash is stored in the Merkle tree to bind the Schnorr key to an account.
|
|
183
|
-
*
|
|
184
|
-
* Returns `BigUint64Array` of length 4.
|
|
185
|
-
*
|
|
186
|
-
* ```js
|
|
187
|
-
* const pkHash = schnorr_pk_hash(pkHex);
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
export function schnorr_pk_hash(pk_hex: string): BigUint64Array;
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Compute pk_hash as a hex string (for convenience).
|
|
194
|
-
*
|
|
195
|
-
* ```js
|
|
196
|
-
* const pkHashHex = schnorr_pk_hash_hex(pkHex);
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
export function schnorr_pk_hash_hex(pk_hex: string): string;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Compute the Schnorr public key from a hex-encoded secret key.
|
|
203
|
-
*
|
|
204
|
-
* Returns hex-encoded w-encoding of the ECgFp5 point (80 chars = 40 bytes).
|
|
205
|
-
*
|
|
206
|
-
* ```js
|
|
207
|
-
* const pkHex = schnorr_pubkey(skHex);
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
export function schnorr_pubkey(sk_hex: string): string;
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Sign a ChangePubKey (tx_type=9) transaction in (s, e) format.
|
|
214
|
-
*
|
|
215
|
-
* msg_hash = Poseidon2(9, user_id, new_pk_hash[0..4])
|
|
216
|
-
*
|
|
217
|
-
* The old key signs this message to authorize key rotation.
|
|
218
|
-
*
|
|
219
|
-
* Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
|
|
220
|
-
*
|
|
221
|
-
* ```js
|
|
222
|
-
* const sig = schnorr_sign_cpk(oldSkHex, userId, newPkHashArray);
|
|
223
|
-
* ```
|
|
224
|
-
*/
|
|
225
|
-
export function schnorr_sign_cpk(old_sk_hex: string, user_id: number, new_pk_hash: BigUint64Array): any;
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Sign a transaction with Schnorr (ECgFp5) in (s, e) format.
|
|
229
|
-
*
|
|
230
|
-
* msg_hash = Poseidon2(tx_type, user_id, currency_id, amount_lo, amount_hi)
|
|
231
|
-
*
|
|
232
|
-
* Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
|
|
233
|
-
*
|
|
234
|
-
* ```js
|
|
235
|
-
* const sig = schnorr_sign_tx(skHex, 5, userId, 0, amountLo, amountHi);
|
|
236
|
-
* // sig.pubkey (80 hex), sig.sig_s (80 hex), sig.sig_e (80 hex)
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
|
-
export function schnorr_sign_tx(sk_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number, session_expiry: bigint): any;
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Verify a Schnorr signature (s, e) for a transaction.
|
|
243
|
-
*
|
|
244
|
-
* Algorithm: R_v = s·G + e·pk, e_v = H(R_v‖pk‖msg), check e == e_v.
|
|
245
|
-
*
|
|
246
|
-
* Returns `true` if signature is valid, `false` otherwise.
|
|
247
|
-
*
|
|
248
|
-
* ```js
|
|
249
|
-
* const ok = schnorr_verify_tx(pubkeyHex, sigSHex, sigEHex, 5, userId, 0, amountLo, amountHi);
|
|
250
|
-
* ```
|
|
251
|
-
*/
|
|
252
|
-
export function schnorr_verify_tx(pk_hex: string, sig_s_hex: string, sig_e_hex: string, tx_type: number, user_id: number, currency_id: number, amount_lo: number, amount_hi: number, session_expiry: bigint): boolean;
|
|
253
|
-
|
|
254
115
|
/**
|
|
255
116
|
* Truncated seed hash — first 2 elements of `Poseidon2(server_seed)`.
|
|
256
117
|
*
|
|
@@ -263,14 +124,15 @@ export function schnorr_verify_tx(pk_hex: string, sig_s_hex: string, sig_e_hex:
|
|
|
263
124
|
export function seed_hash_truncated(server_seed: BigUint64Array): BigUint64Array;
|
|
264
125
|
|
|
265
126
|
/**
|
|
266
|
-
* Compute the public key for a session: `
|
|
127
|
+
* Compute the public key for a session: `pk_hash = Poseidon2(session_key[4], expiry)`.
|
|
267
128
|
*
|
|
268
|
-
* The public key is stored in the user-asset Merkle leaf and verified
|
|
269
|
-
* inside the circuit (the prover must know the preimage `session_key`).
|
|
129
|
+
* The public key hash is stored in the user-asset Merkle leaf and verified
|
|
130
|
+
* inside the circuit (the prover must know the preimage `session_key` + `expiry`).
|
|
270
131
|
*
|
|
271
132
|
* `session_key` must be exactly 4 elements (output of `derive_session_key`).
|
|
133
|
+
* `session_expiry` is the Unix timestamp after which the session is invalid.
|
|
272
134
|
*/
|
|
273
|
-
export function session_public_key(session_key: BigUint64Array): BigUint64Array;
|
|
135
|
+
export function session_public_key(session_key: BigUint64Array, session_expiry: bigint): BigUint64Array;
|
|
274
136
|
|
|
275
137
|
/**
|
|
276
138
|
* Convert a user seed string to 4 Goldilocks field elements.
|
|
@@ -308,32 +170,22 @@ export interface InitOutput {
|
|
|
308
170
|
readonly amount_split: (a: number, b: bigint) => void;
|
|
309
171
|
readonly compute_address_hash: (a: number, b: number, c: number) => void;
|
|
310
172
|
readonly compute_server_seed_hash: (a: number, b: number, c: number) => void;
|
|
311
|
-
readonly compute_tx_msg_hash: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint) => void;
|
|
312
|
-
readonly create_bet_auth: (a: number, b: number, c: number, d: bigint, e: bigint) => void;
|
|
313
173
|
readonly derive_session_key: (a: number, b: number, c: number) => void;
|
|
314
174
|
readonly generate_user_seed: (a: number) => void;
|
|
315
175
|
readonly goldilocks_fields_to_hex: (a: number, b: number, c: number) => void;
|
|
316
176
|
readonly goldilocks_reduce: (a: bigint) => bigint;
|
|
317
177
|
readonly poseidon2_hash: (a: number, b: number, c: number) => void;
|
|
318
178
|
readonly poseidon2_two_to_one: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
319
|
-
readonly schnorr_keygen: (a: number, b: number, c: number) => void;
|
|
320
|
-
readonly schnorr_pk_encode: (a: number, b: number, c: number) => void;
|
|
321
|
-
readonly schnorr_pk_hash: (a: number, b: number, c: number) => void;
|
|
322
|
-
readonly schnorr_pk_hash_hex: (a: number, b: number, c: number) => void;
|
|
323
|
-
readonly schnorr_pubkey: (a: number, b: number, c: number) => void;
|
|
324
|
-
readonly schnorr_sign_cpk: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
325
|
-
readonly schnorr_sign_tx: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint) => number;
|
|
326
|
-
readonly schnorr_verify_tx: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: bigint) => number;
|
|
327
179
|
readonly seed_hash_truncated: (a: number, b: number, c: number) => void;
|
|
328
|
-
readonly session_public_key: (a: number, b: number, c: number) => void;
|
|
180
|
+
readonly session_public_key: (a: number, b: number, c: number, d: bigint) => void;
|
|
329
181
|
readonly string_to_user_seed: (a: number, b: number, c: number) => void;
|
|
330
182
|
readonly string_to_user_seed_hex: (a: number, b: number, c: number) => void;
|
|
331
183
|
readonly goldilocks_modulus: () => bigint;
|
|
332
|
-
readonly __wbindgen_export: (a: number
|
|
333
|
-
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
334
|
-
readonly __wbindgen_export3: (a: number) => void;
|
|
184
|
+
readonly __wbindgen_export: (a: number) => void;
|
|
335
185
|
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
336
|
-
readonly
|
|
186
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number) => void;
|
|
187
|
+
readonly __wbindgen_export3: (a: number, b: number) => number;
|
|
188
|
+
readonly __wbindgen_export4: (a: number, b: number, c: number, d: number) => number;
|
|
337
189
|
}
|
|
338
190
|
|
|
339
191
|
export type SyncInitInput = BufferSource | WebAssembly.Module;
|