@rolly-dev/wasm-signer 0.12.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 +33 -419
- 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 +0 -10
- 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
|
@@ -18,7 +18,7 @@ function amount_split(amount) {
|
|
|
18
18
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
19
19
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
20
20
|
var v1 = getArrayU32FromWasm0(r0, r1).slice();
|
|
21
|
-
wasm.
|
|
21
|
+
wasm.__wbindgen_export2(r0, r1 * 4, 4);
|
|
22
22
|
return v1;
|
|
23
23
|
} finally {
|
|
24
24
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -35,13 +35,13 @@ exports.amount_split = amount_split;
|
|
|
35
35
|
function compute_address_hash(address_hex) {
|
|
36
36
|
try {
|
|
37
37
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
38
|
-
const ptr0 = passStringToWasm0(address_hex, wasm.
|
|
38
|
+
const ptr0 = passStringToWasm0(address_hex, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
39
39
|
const len0 = WASM_VECTOR_LEN;
|
|
40
40
|
wasm.compute_address_hash(retptr, ptr0, len0);
|
|
41
41
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
42
42
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
43
43
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
44
|
-
wasm.
|
|
44
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
45
45
|
return v2;
|
|
46
46
|
} finally {
|
|
47
47
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -64,13 +64,13 @@ exports.compute_address_hash = compute_address_hash;
|
|
|
64
64
|
function compute_server_seed_hash(server_seed) {
|
|
65
65
|
try {
|
|
66
66
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
67
|
-
const ptr0 = passArray64ToWasm0(server_seed, wasm.
|
|
67
|
+
const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export3);
|
|
68
68
|
const len0 = WASM_VECTOR_LEN;
|
|
69
69
|
wasm.compute_server_seed_hash(retptr, ptr0, len0);
|
|
70
70
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
71
71
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
72
72
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
73
|
-
wasm.
|
|
73
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
74
74
|
return v2;
|
|
75
75
|
} finally {
|
|
76
76
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -78,84 +78,6 @@ function compute_server_seed_hash(server_seed) {
|
|
|
78
78
|
}
|
|
79
79
|
exports.compute_server_seed_hash = compute_server_seed_hash;
|
|
80
80
|
|
|
81
|
-
/**
|
|
82
|
-
* Compute the transaction message hash (for debugging / verification).
|
|
83
|
-
*
|
|
84
|
-
* Returns `BigUint64Array` of length 4 — the same hash the circuit computes.
|
|
85
|
-
*
|
|
86
|
-
* ```js
|
|
87
|
-
* const hash = compute_tx_msg_hash(5, userId, 0, amountLo, amountHi);
|
|
88
|
-
* ```
|
|
89
|
-
* @param {number} tx_type
|
|
90
|
-
* @param {number} user_id
|
|
91
|
-
* @param {number} currency_id
|
|
92
|
-
* @param {number} amount_lo
|
|
93
|
-
* @param {number} amount_hi
|
|
94
|
-
* @param {bigint} session_expiry
|
|
95
|
-
* @returns {BigUint64Array}
|
|
96
|
-
*/
|
|
97
|
-
function compute_tx_msg_hash(tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry) {
|
|
98
|
-
try {
|
|
99
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
100
|
-
wasm.compute_tx_msg_hash(retptr, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry);
|
|
101
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
102
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
103
|
-
var v1 = getArrayU64FromWasm0(r0, r1).slice();
|
|
104
|
-
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
105
|
-
return v1;
|
|
106
|
-
} finally {
|
|
107
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
exports.compute_tx_msg_hash = compute_tx_msg_hash;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Create a `bet_auth` MAC that proves the user authorized this specific bet.
|
|
114
|
-
*
|
|
115
|
-
* ```text
|
|
116
|
-
* bet_auth = Poseidon2(
|
|
117
|
-
* session_key[0..4], // 4 field elements (private)
|
|
118
|
-
* amount_lo, // lower 32 bits of bet_amount
|
|
119
|
-
* amount_hi, // upper 32 bits of bet_amount
|
|
120
|
-
* nonce, // monotonic counter, prevents replay
|
|
121
|
-
* )
|
|
122
|
-
* ```
|
|
123
|
-
*
|
|
124
|
-
* The circuit verifies two things:
|
|
125
|
-
* 1. `session_pk == Poseidon2(session_key)` — knowledge of key
|
|
126
|
-
* 2. `bet_auth == Poseidon2(session_key ‖ amount_lo ‖ amount_hi ‖ nonce)`
|
|
127
|
-
*
|
|
128
|
-
* The lo/hi split matches `src/circuit/main_circuit.rs` witness assignment:
|
|
129
|
-
* `amount as u32` / `(amount >> 32) as u32`, both via `from_canonical_u32`.
|
|
130
|
-
*
|
|
131
|
-
* **Parameters**
|
|
132
|
-
* - `session_key` : 4 × u64 (private, from `derive_session_key`)
|
|
133
|
-
* - `bet_amount` : u64 (in smallest currency units)
|
|
134
|
-
* - `nonce` : u64 (incrementing per-session counter)
|
|
135
|
-
*
|
|
136
|
-
* **Returns**: 4 × u64 (`bet_auth` hash)
|
|
137
|
-
* @param {BigUint64Array} session_key
|
|
138
|
-
* @param {bigint} bet_amount
|
|
139
|
-
* @param {bigint} nonce
|
|
140
|
-
* @returns {BigUint64Array}
|
|
141
|
-
*/
|
|
142
|
-
function create_bet_auth(session_key, bet_amount, nonce) {
|
|
143
|
-
try {
|
|
144
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
145
|
-
const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export);
|
|
146
|
-
const len0 = WASM_VECTOR_LEN;
|
|
147
|
-
wasm.create_bet_auth(retptr, ptr0, len0, bet_amount, nonce);
|
|
148
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
149
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
150
|
-
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
151
|
-
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
152
|
-
return v2;
|
|
153
|
-
} finally {
|
|
154
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports.create_bet_auth = create_bet_auth;
|
|
158
|
-
|
|
159
81
|
/**
|
|
160
82
|
* Derive a session key from 32 bytes of entropy (e.g. MetaMask signature).
|
|
161
83
|
*
|
|
@@ -177,13 +99,13 @@ exports.create_bet_auth = create_bet_auth;
|
|
|
177
99
|
function derive_session_key(sig_bytes) {
|
|
178
100
|
try {
|
|
179
101
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
180
|
-
const ptr0 = passArray8ToWasm0(sig_bytes, wasm.
|
|
102
|
+
const ptr0 = passArray8ToWasm0(sig_bytes, wasm.__wbindgen_export3);
|
|
181
103
|
const len0 = WASM_VECTOR_LEN;
|
|
182
104
|
wasm.derive_session_key(retptr, ptr0, len0);
|
|
183
105
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
184
106
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
185
107
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
186
|
-
wasm.
|
|
108
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
187
109
|
return v2;
|
|
188
110
|
} finally {
|
|
189
111
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -216,7 +138,7 @@ function generate_user_seed() {
|
|
|
216
138
|
return getStringFromWasm0(r0, r1);
|
|
217
139
|
} finally {
|
|
218
140
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
219
|
-
wasm.
|
|
141
|
+
wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
|
|
220
142
|
}
|
|
221
143
|
}
|
|
222
144
|
exports.generate_user_seed = generate_user_seed;
|
|
@@ -238,7 +160,7 @@ function goldilocks_fields_to_hex(fields) {
|
|
|
238
160
|
let deferred2_1;
|
|
239
161
|
try {
|
|
240
162
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
241
|
-
const ptr0 = passArray64ToWasm0(fields, wasm.
|
|
163
|
+
const ptr0 = passArray64ToWasm0(fields, wasm.__wbindgen_export3);
|
|
242
164
|
const len0 = WASM_VECTOR_LEN;
|
|
243
165
|
wasm.goldilocks_fields_to_hex(retptr, ptr0, len0);
|
|
244
166
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
@@ -248,7 +170,7 @@ function goldilocks_fields_to_hex(fields) {
|
|
|
248
170
|
return getStringFromWasm0(r0, r1);
|
|
249
171
|
} finally {
|
|
250
172
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
251
|
-
wasm.
|
|
173
|
+
wasm.__wbindgen_export2(deferred2_0, deferred2_1, 1);
|
|
252
174
|
}
|
|
253
175
|
}
|
|
254
176
|
exports.goldilocks_fields_to_hex = goldilocks_fields_to_hex;
|
|
@@ -296,13 +218,13 @@ exports.goldilocks_reduce = goldilocks_reduce;
|
|
|
296
218
|
function poseidon2_hash(input) {
|
|
297
219
|
try {
|
|
298
220
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
299
|
-
const ptr0 = passArray64ToWasm0(input, wasm.
|
|
221
|
+
const ptr0 = passArray64ToWasm0(input, wasm.__wbindgen_export3);
|
|
300
222
|
const len0 = WASM_VECTOR_LEN;
|
|
301
223
|
wasm.poseidon2_hash(retptr, ptr0, len0);
|
|
302
224
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
303
225
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
304
226
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
305
|
-
wasm.
|
|
227
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
306
228
|
return v2;
|
|
307
229
|
} finally {
|
|
308
230
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -324,15 +246,15 @@ exports.poseidon2_hash = poseidon2_hash;
|
|
|
324
246
|
function poseidon2_two_to_one(left, right) {
|
|
325
247
|
try {
|
|
326
248
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
327
|
-
const ptr0 = passArray64ToWasm0(left, wasm.
|
|
249
|
+
const ptr0 = passArray64ToWasm0(left, wasm.__wbindgen_export3);
|
|
328
250
|
const len0 = WASM_VECTOR_LEN;
|
|
329
|
-
const ptr1 = passArray64ToWasm0(right, wasm.
|
|
251
|
+
const ptr1 = passArray64ToWasm0(right, wasm.__wbindgen_export3);
|
|
330
252
|
const len1 = WASM_VECTOR_LEN;
|
|
331
253
|
wasm.poseidon2_two_to_one(retptr, ptr0, len0, ptr1, len1);
|
|
332
254
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
333
255
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
334
256
|
var v3 = getArrayU64FromWasm0(r0, r1).slice();
|
|
335
|
-
wasm.
|
|
257
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
336
258
|
return v3;
|
|
337
259
|
} finally {
|
|
338
260
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -340,246 +262,6 @@ function poseidon2_two_to_one(left, right) {
|
|
|
340
262
|
}
|
|
341
263
|
exports.poseidon2_two_to_one = poseidon2_two_to_one;
|
|
342
264
|
|
|
343
|
-
/**
|
|
344
|
-
* Derive a Schnorr secret key from entropy bytes (e.g. MetaMask signature).
|
|
345
|
-
*
|
|
346
|
-
* Takes at least 32 bytes, uses `Scalar::decode_reduce` to map them into
|
|
347
|
-
* the ECgFp5 scalar field. Returns hex-encoded secret key (80 chars = 40 bytes).
|
|
348
|
-
*
|
|
349
|
-
* ```js
|
|
350
|
-
* const skHex = schnorr_keygen(sigBytes.slice(0, 32));
|
|
351
|
-
* ```
|
|
352
|
-
* @param {Uint8Array} entropy
|
|
353
|
-
* @returns {string}
|
|
354
|
-
*/
|
|
355
|
-
function schnorr_keygen(entropy) {
|
|
356
|
-
let deferred2_0;
|
|
357
|
-
let deferred2_1;
|
|
358
|
-
try {
|
|
359
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
360
|
-
const ptr0 = passArray8ToWasm0(entropy, wasm.__wbindgen_export);
|
|
361
|
-
const len0 = WASM_VECTOR_LEN;
|
|
362
|
-
wasm.schnorr_keygen(retptr, ptr0, len0);
|
|
363
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
364
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
365
|
-
deferred2_0 = r0;
|
|
366
|
-
deferred2_1 = r1;
|
|
367
|
-
return getStringFromWasm0(r0, r1);
|
|
368
|
-
} finally {
|
|
369
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
370
|
-
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
exports.schnorr_keygen = schnorr_keygen;
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Get the w-encoding of a public key as 5 Goldilocks field elements (for circuit witness).
|
|
377
|
-
*
|
|
378
|
-
* Returns `BigUint64Array` of length 5.
|
|
379
|
-
*
|
|
380
|
-
* ```js
|
|
381
|
-
* const encode = schnorr_pk_encode(pkHex);
|
|
382
|
-
* // encode.length === 5
|
|
383
|
-
* ```
|
|
384
|
-
* @param {string} pk_hex
|
|
385
|
-
* @returns {BigUint64Array}
|
|
386
|
-
*/
|
|
387
|
-
function schnorr_pk_encode(pk_hex) {
|
|
388
|
-
try {
|
|
389
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
390
|
-
const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
391
|
-
const len0 = WASM_VECTOR_LEN;
|
|
392
|
-
wasm.schnorr_pk_encode(retptr, ptr0, len0);
|
|
393
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
394
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
395
|
-
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
396
|
-
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
397
|
-
return v2;
|
|
398
|
-
} finally {
|
|
399
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
exports.schnorr_pk_encode = schnorr_pk_encode;
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Compute pk_hash = Poseidon2(w_encoding[5]) from a hex-encoded public key.
|
|
406
|
-
*
|
|
407
|
-
* The w-encoding is the 40-byte (80 hex) representation returned by `schnorr_pubkey`.
|
|
408
|
-
* pk_hash is stored in the Merkle tree to bind the Schnorr key to an account.
|
|
409
|
-
*
|
|
410
|
-
* Returns `BigUint64Array` of length 4.
|
|
411
|
-
*
|
|
412
|
-
* ```js
|
|
413
|
-
* const pkHash = schnorr_pk_hash(pkHex);
|
|
414
|
-
* ```
|
|
415
|
-
* @param {string} pk_hex
|
|
416
|
-
* @returns {BigUint64Array}
|
|
417
|
-
*/
|
|
418
|
-
function schnorr_pk_hash(pk_hex) {
|
|
419
|
-
try {
|
|
420
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
421
|
-
const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
422
|
-
const len0 = WASM_VECTOR_LEN;
|
|
423
|
-
wasm.schnorr_pk_hash(retptr, ptr0, len0);
|
|
424
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
425
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
426
|
-
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
427
|
-
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
428
|
-
return v2;
|
|
429
|
-
} finally {
|
|
430
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
exports.schnorr_pk_hash = schnorr_pk_hash;
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* Compute pk_hash as a hex string (for convenience).
|
|
437
|
-
*
|
|
438
|
-
* ```js
|
|
439
|
-
* const pkHashHex = schnorr_pk_hash_hex(pkHex);
|
|
440
|
-
* ```
|
|
441
|
-
* @param {string} pk_hex
|
|
442
|
-
* @returns {string}
|
|
443
|
-
*/
|
|
444
|
-
function schnorr_pk_hash_hex(pk_hex) {
|
|
445
|
-
let deferred2_0;
|
|
446
|
-
let deferred2_1;
|
|
447
|
-
try {
|
|
448
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
449
|
-
const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
450
|
-
const len0 = WASM_VECTOR_LEN;
|
|
451
|
-
wasm.schnorr_pk_hash_hex(retptr, ptr0, len0);
|
|
452
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
453
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
454
|
-
deferred2_0 = r0;
|
|
455
|
-
deferred2_1 = r1;
|
|
456
|
-
return getStringFromWasm0(r0, r1);
|
|
457
|
-
} finally {
|
|
458
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
459
|
-
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
exports.schnorr_pk_hash_hex = schnorr_pk_hash_hex;
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* Compute the Schnorr public key from a hex-encoded secret key.
|
|
466
|
-
*
|
|
467
|
-
* Returns hex-encoded w-encoding of the ECgFp5 point (80 chars = 40 bytes).
|
|
468
|
-
*
|
|
469
|
-
* ```js
|
|
470
|
-
* const pkHex = schnorr_pubkey(skHex);
|
|
471
|
-
* ```
|
|
472
|
-
* @param {string} sk_hex
|
|
473
|
-
* @returns {string}
|
|
474
|
-
*/
|
|
475
|
-
function schnorr_pubkey(sk_hex) {
|
|
476
|
-
let deferred2_0;
|
|
477
|
-
let deferred2_1;
|
|
478
|
-
try {
|
|
479
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
480
|
-
const ptr0 = passStringToWasm0(sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
481
|
-
const len0 = WASM_VECTOR_LEN;
|
|
482
|
-
wasm.schnorr_pubkey(retptr, ptr0, len0);
|
|
483
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
484
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
485
|
-
deferred2_0 = r0;
|
|
486
|
-
deferred2_1 = r1;
|
|
487
|
-
return getStringFromWasm0(r0, r1);
|
|
488
|
-
} finally {
|
|
489
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
490
|
-
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
exports.schnorr_pubkey = schnorr_pubkey;
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* Sign a ChangePubKey (tx_type=9) transaction in (s, e) format.
|
|
497
|
-
*
|
|
498
|
-
* msg_hash = Poseidon2(9, user_id, new_pk_hash[0..4])
|
|
499
|
-
*
|
|
500
|
-
* The old key signs this message to authorize key rotation.
|
|
501
|
-
*
|
|
502
|
-
* Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
|
|
503
|
-
*
|
|
504
|
-
* ```js
|
|
505
|
-
* const sig = schnorr_sign_cpk(oldSkHex, userId, newPkHashArray);
|
|
506
|
-
* ```
|
|
507
|
-
* @param {string} old_sk_hex
|
|
508
|
-
* @param {number} user_id
|
|
509
|
-
* @param {BigUint64Array} new_pk_hash
|
|
510
|
-
* @returns {any}
|
|
511
|
-
*/
|
|
512
|
-
function schnorr_sign_cpk(old_sk_hex, user_id, new_pk_hash) {
|
|
513
|
-
const ptr0 = passStringToWasm0(old_sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
514
|
-
const len0 = WASM_VECTOR_LEN;
|
|
515
|
-
const ptr1 = passArray64ToWasm0(new_pk_hash, wasm.__wbindgen_export);
|
|
516
|
-
const len1 = WASM_VECTOR_LEN;
|
|
517
|
-
const ret = wasm.schnorr_sign_cpk(ptr0, len0, user_id, ptr1, len1);
|
|
518
|
-
return takeObject(ret);
|
|
519
|
-
}
|
|
520
|
-
exports.schnorr_sign_cpk = schnorr_sign_cpk;
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* Sign a transaction with Schnorr (ECgFp5) in (s, e) format.
|
|
524
|
-
*
|
|
525
|
-
* msg_hash = Poseidon2(tx_type, user_id, currency_id, amount_lo, amount_hi)
|
|
526
|
-
*
|
|
527
|
-
* Returns a JS object: `{ pubkey: "hex", sig_s: "hex", sig_e: "hex" }`
|
|
528
|
-
*
|
|
529
|
-
* ```js
|
|
530
|
-
* const sig = schnorr_sign_tx(skHex, 5, userId, 0, amountLo, amountHi);
|
|
531
|
-
* // sig.pubkey (80 hex), sig.sig_s (80 hex), sig.sig_e (80 hex)
|
|
532
|
-
* ```
|
|
533
|
-
* @param {string} sk_hex
|
|
534
|
-
* @param {number} tx_type
|
|
535
|
-
* @param {number} user_id
|
|
536
|
-
* @param {number} currency_id
|
|
537
|
-
* @param {number} amount_lo
|
|
538
|
-
* @param {number} amount_hi
|
|
539
|
-
* @param {bigint} session_expiry
|
|
540
|
-
* @returns {any}
|
|
541
|
-
*/
|
|
542
|
-
function schnorr_sign_tx(sk_hex, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry) {
|
|
543
|
-
const ptr0 = passStringToWasm0(sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
544
|
-
const len0 = WASM_VECTOR_LEN;
|
|
545
|
-
const ret = wasm.schnorr_sign_tx(ptr0, len0, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry);
|
|
546
|
-
return takeObject(ret);
|
|
547
|
-
}
|
|
548
|
-
exports.schnorr_sign_tx = schnorr_sign_tx;
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* Verify a Schnorr signature (s, e) for a transaction.
|
|
552
|
-
*
|
|
553
|
-
* Algorithm: R_v = s·G + e·pk, e_v = H(R_v‖pk‖msg), check e == e_v.
|
|
554
|
-
*
|
|
555
|
-
* Returns `true` if signature is valid, `false` otherwise.
|
|
556
|
-
*
|
|
557
|
-
* ```js
|
|
558
|
-
* const ok = schnorr_verify_tx(pubkeyHex, sigSHex, sigEHex, 5, userId, 0, amountLo, amountHi);
|
|
559
|
-
* ```
|
|
560
|
-
* @param {string} pk_hex
|
|
561
|
-
* @param {string} sig_s_hex
|
|
562
|
-
* @param {string} sig_e_hex
|
|
563
|
-
* @param {number} tx_type
|
|
564
|
-
* @param {number} user_id
|
|
565
|
-
* @param {number} currency_id
|
|
566
|
-
* @param {number} amount_lo
|
|
567
|
-
* @param {number} amount_hi
|
|
568
|
-
* @param {bigint} session_expiry
|
|
569
|
-
* @returns {boolean}
|
|
570
|
-
*/
|
|
571
|
-
function schnorr_verify_tx(pk_hex, sig_s_hex, sig_e_hex, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry) {
|
|
572
|
-
const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
573
|
-
const len0 = WASM_VECTOR_LEN;
|
|
574
|
-
const ptr1 = passStringToWasm0(sig_s_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
575
|
-
const len1 = WASM_VECTOR_LEN;
|
|
576
|
-
const ptr2 = passStringToWasm0(sig_e_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
577
|
-
const len2 = WASM_VECTOR_LEN;
|
|
578
|
-
const ret = wasm.schnorr_verify_tx(ptr0, len0, ptr1, len1, ptr2, len2, tx_type, user_id, currency_id, amount_lo, amount_hi, session_expiry);
|
|
579
|
-
return ret !== 0;
|
|
580
|
-
}
|
|
581
|
-
exports.schnorr_verify_tx = schnorr_verify_tx;
|
|
582
|
-
|
|
583
265
|
/**
|
|
584
266
|
* Truncated seed hash — first 2 elements of `Poseidon2(server_seed)`.
|
|
585
267
|
*
|
|
@@ -594,13 +276,13 @@ exports.schnorr_verify_tx = schnorr_verify_tx;
|
|
|
594
276
|
function seed_hash_truncated(server_seed) {
|
|
595
277
|
try {
|
|
596
278
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
597
|
-
const ptr0 = passArray64ToWasm0(server_seed, wasm.
|
|
279
|
+
const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export3);
|
|
598
280
|
const len0 = WASM_VECTOR_LEN;
|
|
599
281
|
wasm.seed_hash_truncated(retptr, ptr0, len0);
|
|
600
282
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
601
283
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
602
284
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
603
|
-
wasm.
|
|
285
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
604
286
|
return v2;
|
|
605
287
|
} finally {
|
|
606
288
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -609,25 +291,27 @@ function seed_hash_truncated(server_seed) {
|
|
|
609
291
|
exports.seed_hash_truncated = seed_hash_truncated;
|
|
610
292
|
|
|
611
293
|
/**
|
|
612
|
-
* Compute the public key for a session: `
|
|
294
|
+
* Compute the public key for a session: `pk_hash = Poseidon2(session_key[4], expiry)`.
|
|
613
295
|
*
|
|
614
|
-
* The public key is stored in the user-asset Merkle leaf and verified
|
|
615
|
-
* inside the circuit (the prover must know the preimage `session_key`).
|
|
296
|
+
* The public key hash is stored in the user-asset Merkle leaf and verified
|
|
297
|
+
* inside the circuit (the prover must know the preimage `session_key` + `expiry`).
|
|
616
298
|
*
|
|
617
299
|
* `session_key` must be exactly 4 elements (output of `derive_session_key`).
|
|
300
|
+
* `session_expiry` is the Unix timestamp after which the session is invalid.
|
|
618
301
|
* @param {BigUint64Array} session_key
|
|
302
|
+
* @param {bigint} session_expiry
|
|
619
303
|
* @returns {BigUint64Array}
|
|
620
304
|
*/
|
|
621
|
-
function session_public_key(session_key) {
|
|
305
|
+
function session_public_key(session_key, session_expiry) {
|
|
622
306
|
try {
|
|
623
307
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
624
|
-
const ptr0 = passArray64ToWasm0(session_key, wasm.
|
|
308
|
+
const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export3);
|
|
625
309
|
const len0 = WASM_VECTOR_LEN;
|
|
626
|
-
wasm.session_public_key(retptr, ptr0, len0);
|
|
310
|
+
wasm.session_public_key(retptr, ptr0, len0, session_expiry);
|
|
627
311
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
628
312
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
629
313
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
630
|
-
wasm.
|
|
314
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
631
315
|
return v2;
|
|
632
316
|
} finally {
|
|
633
317
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -654,13 +338,13 @@ exports.session_public_key = session_public_key;
|
|
|
654
338
|
function string_to_user_seed(input) {
|
|
655
339
|
try {
|
|
656
340
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
657
|
-
const ptr0 = passStringToWasm0(input, wasm.
|
|
341
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
658
342
|
const len0 = WASM_VECTOR_LEN;
|
|
659
343
|
wasm.string_to_user_seed(retptr, ptr0, len0);
|
|
660
344
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
661
345
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
662
346
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
663
|
-
wasm.
|
|
347
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
664
348
|
return v2;
|
|
665
349
|
} finally {
|
|
666
350
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -686,7 +370,7 @@ function string_to_user_seed_hex(input) {
|
|
|
686
370
|
let deferred2_1;
|
|
687
371
|
try {
|
|
688
372
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
689
|
-
const ptr0 = passStringToWasm0(input, wasm.
|
|
373
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
690
374
|
const len0 = WASM_VECTOR_LEN;
|
|
691
375
|
wasm.string_to_user_seed_hex(retptr, ptr0, len0);
|
|
692
376
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
@@ -696,7 +380,7 @@ function string_to_user_seed_hex(input) {
|
|
|
696
380
|
return getStringFromWasm0(r0, r1);
|
|
697
381
|
} finally {
|
|
698
382
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
699
|
-
wasm.
|
|
383
|
+
wasm.__wbindgen_export2(deferred2_0, deferred2_1, 1);
|
|
700
384
|
}
|
|
701
385
|
}
|
|
702
386
|
exports.string_to_user_seed_hex = string_to_user_seed_hex;
|
|
@@ -704,13 +388,6 @@ exports.string_to_user_seed_hex = string_to_user_seed_hex;
|
|
|
704
388
|
function __wbg_get_imports() {
|
|
705
389
|
const import0 = {
|
|
706
390
|
__proto__: null,
|
|
707
|
-
__wbg___wbindgen_debug_string_0bc8482c6e3508ae: function(arg0, arg1) {
|
|
708
|
-
const ret = debugString(getObject(arg1));
|
|
709
|
-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
710
|
-
const len1 = WASM_VECTOR_LEN;
|
|
711
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
712
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
713
|
-
},
|
|
714
391
|
__wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
|
|
715
392
|
const ret = typeof(getObject(arg0)) === 'function';
|
|
716
393
|
return ret;
|
|
@@ -754,10 +431,6 @@ function __wbg_get_imports() {
|
|
|
754
431
|
const ret = getObject(arg0).msCrypto;
|
|
755
432
|
return addHeapObject(ret);
|
|
756
433
|
},
|
|
757
|
-
__wbg_new_361308b2356cecd0: function() {
|
|
758
|
-
const ret = new Object();
|
|
759
|
-
return addHeapObject(ret);
|
|
760
|
-
},
|
|
761
434
|
__wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
|
|
762
435
|
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
763
436
|
return addHeapObject(ret);
|
|
@@ -784,10 +457,6 @@ function __wbg_get_imports() {
|
|
|
784
457
|
const ret = module.require;
|
|
785
458
|
return addHeapObject(ret);
|
|
786
459
|
}, arguments); },
|
|
787
|
-
__wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
|
|
788
|
-
const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
|
|
789
|
-
return ret;
|
|
790
|
-
}, arguments); },
|
|
791
460
|
__wbg_static_accessor_GLOBAL_12837167ad935116: function() {
|
|
792
461
|
const ret = typeof global === 'undefined' ? null : global;
|
|
793
462
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
@@ -845,71 +514,6 @@ function addHeapObject(obj) {
|
|
|
845
514
|
return idx;
|
|
846
515
|
}
|
|
847
516
|
|
|
848
|
-
function debugString(val) {
|
|
849
|
-
// primitive types
|
|
850
|
-
const type = typeof val;
|
|
851
|
-
if (type == 'number' || type == 'boolean' || val == null) {
|
|
852
|
-
return `${val}`;
|
|
853
|
-
}
|
|
854
|
-
if (type == 'string') {
|
|
855
|
-
return `"${val}"`;
|
|
856
|
-
}
|
|
857
|
-
if (type == 'symbol') {
|
|
858
|
-
const description = val.description;
|
|
859
|
-
if (description == null) {
|
|
860
|
-
return 'Symbol';
|
|
861
|
-
} else {
|
|
862
|
-
return `Symbol(${description})`;
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
if (type == 'function') {
|
|
866
|
-
const name = val.name;
|
|
867
|
-
if (typeof name == 'string' && name.length > 0) {
|
|
868
|
-
return `Function(${name})`;
|
|
869
|
-
} else {
|
|
870
|
-
return 'Function';
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
// objects
|
|
874
|
-
if (Array.isArray(val)) {
|
|
875
|
-
const length = val.length;
|
|
876
|
-
let debug = '[';
|
|
877
|
-
if (length > 0) {
|
|
878
|
-
debug += debugString(val[0]);
|
|
879
|
-
}
|
|
880
|
-
for(let i = 1; i < length; i++) {
|
|
881
|
-
debug += ', ' + debugString(val[i]);
|
|
882
|
-
}
|
|
883
|
-
debug += ']';
|
|
884
|
-
return debug;
|
|
885
|
-
}
|
|
886
|
-
// Test for built-in
|
|
887
|
-
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
888
|
-
let className;
|
|
889
|
-
if (builtInMatches && builtInMatches.length > 1) {
|
|
890
|
-
className = builtInMatches[1];
|
|
891
|
-
} else {
|
|
892
|
-
// Failed to match the standard '[object ClassName]'
|
|
893
|
-
return toString.call(val);
|
|
894
|
-
}
|
|
895
|
-
if (className == 'Object') {
|
|
896
|
-
// we're a user defined class or Object
|
|
897
|
-
// JSON.stringify avoids problems with cycles, and is generally much
|
|
898
|
-
// easier than looping through ownProperties of `val`.
|
|
899
|
-
try {
|
|
900
|
-
return 'Object(' + JSON.stringify(val) + ')';
|
|
901
|
-
} catch (_) {
|
|
902
|
-
return 'Object';
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
// errors
|
|
906
|
-
if (val instanceof Error) {
|
|
907
|
-
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
908
|
-
}
|
|
909
|
-
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
910
|
-
return className;
|
|
911
|
-
}
|
|
912
|
-
|
|
913
517
|
function dropObject(idx) {
|
|
914
518
|
if (idx < 132) return;
|
|
915
519
|
heap[idx] = heap_next;
|
|
@@ -974,7 +578,7 @@ function handleError(f, args) {
|
|
|
974
578
|
try {
|
|
975
579
|
return f.apply(this, args);
|
|
976
580
|
} catch (e) {
|
|
977
|
-
wasm.
|
|
581
|
+
wasm.__wbindgen_export(addHeapObject(e));
|
|
978
582
|
}
|
|
979
583
|
}
|
|
980
584
|
|
|
Binary file
|
|
@@ -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;
|