@rolly-dev/wasm-signer 0.5.1 → 0.6.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/dist/node/rolly_wasm_signer.d.ts +122 -0
- package/dist/node/rolly_wasm_signer.js +410 -23
- package/dist/node/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/node/rolly_wasm_signer_bg.wasm.d.ts +14 -4
- package/dist/web/rolly_wasm_signer.d.ts +136 -4
- package/dist/web/rolly_wasm_signer.js +401 -23
- package/dist/web/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/web/rolly_wasm_signer_bg.wasm.d.ts +14 -4
- package/package.json +1 -1
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
/* @ts-self-types="./rolly_wasm_signer.d.ts" */
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Split a u64 amount into (lo, hi) u32 pair matching the circuit representation.
|
|
5
|
+
*
|
|
6
|
+
* Returns `[amount_lo, amount_hi]` as a `Uint32Array` of length 2.
|
|
7
|
+
*
|
|
8
|
+
* ```js
|
|
9
|
+
* const [lo, hi] = amount_split(123456789n);
|
|
10
|
+
* ```
|
|
11
|
+
* @param {bigint} amount
|
|
12
|
+
* @returns {Uint32Array}
|
|
13
|
+
*/
|
|
14
|
+
function amount_split(amount) {
|
|
15
|
+
try {
|
|
16
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
17
|
+
wasm.amount_split(retptr, amount);
|
|
18
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
19
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
20
|
+
var v1 = getArrayU32FromWasm0(r0, r1).slice();
|
|
21
|
+
wasm.__wbindgen_export4(r0, r1 * 4, 4);
|
|
22
|
+
return v1;
|
|
23
|
+
} finally {
|
|
24
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.amount_split = amount_split;
|
|
28
|
+
|
|
3
29
|
/**
|
|
4
30
|
* Full Poseidon2 hash of an 8-element server seed.
|
|
5
31
|
*
|
|
@@ -15,13 +41,13 @@
|
|
|
15
41
|
function compute_server_seed_hash(server_seed) {
|
|
16
42
|
try {
|
|
17
43
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
18
|
-
const ptr0 = passArray64ToWasm0(server_seed, wasm.
|
|
44
|
+
const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export);
|
|
19
45
|
const len0 = WASM_VECTOR_LEN;
|
|
20
46
|
wasm.compute_server_seed_hash(retptr, ptr0, len0);
|
|
21
47
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
22
48
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
23
49
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
24
|
-
wasm.
|
|
50
|
+
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
25
51
|
return v2;
|
|
26
52
|
} finally {
|
|
27
53
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -29,6 +55,36 @@ function compute_server_seed_hash(server_seed) {
|
|
|
29
55
|
}
|
|
30
56
|
exports.compute_server_seed_hash = compute_server_seed_hash;
|
|
31
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Compute the transaction message hash (for debugging / verification).
|
|
60
|
+
*
|
|
61
|
+
* Returns `BigUint64Array` of length 4 — the same hash the circuit computes.
|
|
62
|
+
*
|
|
63
|
+
* ```js
|
|
64
|
+
* const hash = compute_tx_msg_hash(5, userId, 0, amountLo, amountHi);
|
|
65
|
+
* ```
|
|
66
|
+
* @param {number} tx_type
|
|
67
|
+
* @param {number} user_id
|
|
68
|
+
* @param {number} currency_id
|
|
69
|
+
* @param {number} amount_lo
|
|
70
|
+
* @param {number} amount_hi
|
|
71
|
+
* @returns {BigUint64Array}
|
|
72
|
+
*/
|
|
73
|
+
function compute_tx_msg_hash(tx_type, user_id, currency_id, amount_lo, amount_hi) {
|
|
74
|
+
try {
|
|
75
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
76
|
+
wasm.compute_tx_msg_hash(retptr, tx_type, user_id, currency_id, amount_lo, amount_hi);
|
|
77
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
78
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
79
|
+
var v1 = getArrayU64FromWasm0(r0, r1).slice();
|
|
80
|
+
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
81
|
+
return v1;
|
|
82
|
+
} finally {
|
|
83
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.compute_tx_msg_hash = compute_tx_msg_hash;
|
|
87
|
+
|
|
32
88
|
/**
|
|
33
89
|
* Create a `bet_auth` MAC that proves the user authorized this specific bet.
|
|
34
90
|
*
|
|
@@ -62,13 +118,13 @@ exports.compute_server_seed_hash = compute_server_seed_hash;
|
|
|
62
118
|
function create_bet_auth(session_key, bet_amount, nonce) {
|
|
63
119
|
try {
|
|
64
120
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
65
|
-
const ptr0 = passArray64ToWasm0(session_key, wasm.
|
|
121
|
+
const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export);
|
|
66
122
|
const len0 = WASM_VECTOR_LEN;
|
|
67
123
|
wasm.create_bet_auth(retptr, ptr0, len0, bet_amount, nonce);
|
|
68
124
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
69
125
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
70
126
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
71
|
-
wasm.
|
|
127
|
+
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
72
128
|
return v2;
|
|
73
129
|
} finally {
|
|
74
130
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -97,13 +153,13 @@ exports.create_bet_auth = create_bet_auth;
|
|
|
97
153
|
function derive_session_key(sig_bytes) {
|
|
98
154
|
try {
|
|
99
155
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
100
|
-
const ptr0 = passArray8ToWasm0(sig_bytes, wasm.
|
|
156
|
+
const ptr0 = passArray8ToWasm0(sig_bytes, wasm.__wbindgen_export);
|
|
101
157
|
const len0 = WASM_VECTOR_LEN;
|
|
102
158
|
wasm.derive_session_key(retptr, ptr0, len0);
|
|
103
159
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
104
160
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
105
161
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
106
|
-
wasm.
|
|
162
|
+
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
107
163
|
return v2;
|
|
108
164
|
} finally {
|
|
109
165
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -136,7 +192,7 @@ function generate_user_seed() {
|
|
|
136
192
|
return getStringFromWasm0(r0, r1);
|
|
137
193
|
} finally {
|
|
138
194
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
139
|
-
wasm.
|
|
195
|
+
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
140
196
|
}
|
|
141
197
|
}
|
|
142
198
|
exports.generate_user_seed = generate_user_seed;
|
|
@@ -158,7 +214,7 @@ function goldilocks_fields_to_hex(fields) {
|
|
|
158
214
|
let deferred2_1;
|
|
159
215
|
try {
|
|
160
216
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
161
|
-
const ptr0 = passArray64ToWasm0(fields, wasm.
|
|
217
|
+
const ptr0 = passArray64ToWasm0(fields, wasm.__wbindgen_export);
|
|
162
218
|
const len0 = WASM_VECTOR_LEN;
|
|
163
219
|
wasm.goldilocks_fields_to_hex(retptr, ptr0, len0);
|
|
164
220
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
@@ -168,7 +224,7 @@ function goldilocks_fields_to_hex(fields) {
|
|
|
168
224
|
return getStringFromWasm0(r0, r1);
|
|
169
225
|
} finally {
|
|
170
226
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
171
|
-
wasm.
|
|
227
|
+
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
172
228
|
}
|
|
173
229
|
}
|
|
174
230
|
exports.goldilocks_fields_to_hex = goldilocks_fields_to_hex;
|
|
@@ -216,13 +272,13 @@ exports.goldilocks_reduce = goldilocks_reduce;
|
|
|
216
272
|
function poseidon2_hash(input) {
|
|
217
273
|
try {
|
|
218
274
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
219
|
-
const ptr0 = passArray64ToWasm0(input, wasm.
|
|
275
|
+
const ptr0 = passArray64ToWasm0(input, wasm.__wbindgen_export);
|
|
220
276
|
const len0 = WASM_VECTOR_LEN;
|
|
221
277
|
wasm.poseidon2_hash(retptr, ptr0, len0);
|
|
222
278
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
223
279
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
224
280
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
225
|
-
wasm.
|
|
281
|
+
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
226
282
|
return v2;
|
|
227
283
|
} finally {
|
|
228
284
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -244,15 +300,15 @@ exports.poseidon2_hash = poseidon2_hash;
|
|
|
244
300
|
function poseidon2_two_to_one(left, right) {
|
|
245
301
|
try {
|
|
246
302
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
247
|
-
const ptr0 = passArray64ToWasm0(left, wasm.
|
|
303
|
+
const ptr0 = passArray64ToWasm0(left, wasm.__wbindgen_export);
|
|
248
304
|
const len0 = WASM_VECTOR_LEN;
|
|
249
|
-
const ptr1 = passArray64ToWasm0(right, wasm.
|
|
305
|
+
const ptr1 = passArray64ToWasm0(right, wasm.__wbindgen_export);
|
|
250
306
|
const len1 = WASM_VECTOR_LEN;
|
|
251
307
|
wasm.poseidon2_two_to_one(retptr, ptr0, len0, ptr1, len1);
|
|
252
308
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
253
309
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
254
310
|
var v3 = getArrayU64FromWasm0(r0, r1).slice();
|
|
255
|
-
wasm.
|
|
311
|
+
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
256
312
|
return v3;
|
|
257
313
|
} finally {
|
|
258
314
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -260,6 +316,244 @@ function poseidon2_two_to_one(left, right) {
|
|
|
260
316
|
}
|
|
261
317
|
exports.poseidon2_two_to_one = poseidon2_two_to_one;
|
|
262
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Derive a Schnorr secret key from entropy bytes (e.g. MetaMask signature).
|
|
321
|
+
*
|
|
322
|
+
* Takes at least 32 bytes, uses `Scalar::decode_reduce` to map them into
|
|
323
|
+
* the ECgFp5 scalar field. Returns hex-encoded secret key (80 chars = 40 bytes).
|
|
324
|
+
*
|
|
325
|
+
* ```js
|
|
326
|
+
* const skHex = schnorr_keygen(sigBytes.slice(0, 32));
|
|
327
|
+
* ```
|
|
328
|
+
* @param {Uint8Array} entropy
|
|
329
|
+
* @returns {string}
|
|
330
|
+
*/
|
|
331
|
+
function schnorr_keygen(entropy) {
|
|
332
|
+
let deferred2_0;
|
|
333
|
+
let deferred2_1;
|
|
334
|
+
try {
|
|
335
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
336
|
+
const ptr0 = passArray8ToWasm0(entropy, wasm.__wbindgen_export);
|
|
337
|
+
const len0 = WASM_VECTOR_LEN;
|
|
338
|
+
wasm.schnorr_keygen(retptr, ptr0, len0);
|
|
339
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
340
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
341
|
+
deferred2_0 = r0;
|
|
342
|
+
deferred2_1 = r1;
|
|
343
|
+
return getStringFromWasm0(r0, r1);
|
|
344
|
+
} finally {
|
|
345
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
346
|
+
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
exports.schnorr_keygen = schnorr_keygen;
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Get the w-encoding of a public key as 5 Goldilocks field elements (for circuit witness).
|
|
353
|
+
*
|
|
354
|
+
* Returns `BigUint64Array` of length 5.
|
|
355
|
+
*
|
|
356
|
+
* ```js
|
|
357
|
+
* const encode = schnorr_pk_encode(pkHex);
|
|
358
|
+
* // encode.length === 5
|
|
359
|
+
* ```
|
|
360
|
+
* @param {string} pk_hex
|
|
361
|
+
* @returns {BigUint64Array}
|
|
362
|
+
*/
|
|
363
|
+
function schnorr_pk_encode(pk_hex) {
|
|
364
|
+
try {
|
|
365
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
366
|
+
const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
367
|
+
const len0 = WASM_VECTOR_LEN;
|
|
368
|
+
wasm.schnorr_pk_encode(retptr, ptr0, len0);
|
|
369
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
370
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
371
|
+
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
372
|
+
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
373
|
+
return v2;
|
|
374
|
+
} finally {
|
|
375
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
exports.schnorr_pk_encode = schnorr_pk_encode;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Compute pk_hash = Poseidon2(w_encoding[5]) from a hex-encoded public key.
|
|
382
|
+
*
|
|
383
|
+
* The w-encoding is the 40-byte (80 hex) representation returned by `schnorr_pubkey`.
|
|
384
|
+
* pk_hash is stored in the Merkle tree to bind the Schnorr key to an account.
|
|
385
|
+
*
|
|
386
|
+
* Returns `BigUint64Array` of length 4.
|
|
387
|
+
*
|
|
388
|
+
* ```js
|
|
389
|
+
* const pkHash = schnorr_pk_hash(pkHex);
|
|
390
|
+
* ```
|
|
391
|
+
* @param {string} pk_hex
|
|
392
|
+
* @returns {BigUint64Array}
|
|
393
|
+
*/
|
|
394
|
+
function schnorr_pk_hash(pk_hex) {
|
|
395
|
+
try {
|
|
396
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
397
|
+
const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
398
|
+
const len0 = WASM_VECTOR_LEN;
|
|
399
|
+
wasm.schnorr_pk_hash(retptr, ptr0, len0);
|
|
400
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
401
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
402
|
+
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
403
|
+
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
404
|
+
return v2;
|
|
405
|
+
} finally {
|
|
406
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
exports.schnorr_pk_hash = schnorr_pk_hash;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Compute pk_hash as a hex string (for convenience).
|
|
413
|
+
*
|
|
414
|
+
* ```js
|
|
415
|
+
* const pkHashHex = schnorr_pk_hash_hex(pkHex);
|
|
416
|
+
* ```
|
|
417
|
+
* @param {string} pk_hex
|
|
418
|
+
* @returns {string}
|
|
419
|
+
*/
|
|
420
|
+
function schnorr_pk_hash_hex(pk_hex) {
|
|
421
|
+
let deferred2_0;
|
|
422
|
+
let deferred2_1;
|
|
423
|
+
try {
|
|
424
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
425
|
+
const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
426
|
+
const len0 = WASM_VECTOR_LEN;
|
|
427
|
+
wasm.schnorr_pk_hash_hex(retptr, ptr0, len0);
|
|
428
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
429
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
430
|
+
deferred2_0 = r0;
|
|
431
|
+
deferred2_1 = r1;
|
|
432
|
+
return getStringFromWasm0(r0, r1);
|
|
433
|
+
} finally {
|
|
434
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
435
|
+
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
exports.schnorr_pk_hash_hex = schnorr_pk_hash_hex;
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Compute the Schnorr public key from a hex-encoded secret key.
|
|
442
|
+
*
|
|
443
|
+
* Returns hex-encoded w-encoding of the ECgFp5 point (80 chars = 40 bytes).
|
|
444
|
+
*
|
|
445
|
+
* ```js
|
|
446
|
+
* const pkHex = schnorr_pubkey(skHex);
|
|
447
|
+
* ```
|
|
448
|
+
* @param {string} sk_hex
|
|
449
|
+
* @returns {string}
|
|
450
|
+
*/
|
|
451
|
+
function schnorr_pubkey(sk_hex) {
|
|
452
|
+
let deferred2_0;
|
|
453
|
+
let deferred2_1;
|
|
454
|
+
try {
|
|
455
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
456
|
+
const ptr0 = passStringToWasm0(sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
457
|
+
const len0 = WASM_VECTOR_LEN;
|
|
458
|
+
wasm.schnorr_pubkey(retptr, ptr0, len0);
|
|
459
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
460
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
461
|
+
deferred2_0 = r0;
|
|
462
|
+
deferred2_1 = r1;
|
|
463
|
+
return getStringFromWasm0(r0, r1);
|
|
464
|
+
} finally {
|
|
465
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
466
|
+
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
exports.schnorr_pubkey = schnorr_pubkey;
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Sign a ChangePubKey (tx_type=9) transaction.
|
|
473
|
+
*
|
|
474
|
+
* msg_hash = Poseidon2(9, user_id, new_pk_hash[0..4])
|
|
475
|
+
*
|
|
476
|
+
* The old key signs this message to authorize key rotation.
|
|
477
|
+
*
|
|
478
|
+
* Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
|
|
479
|
+
*
|
|
480
|
+
* ```js
|
|
481
|
+
* const sig = schnorr_sign_cpk(oldSkHex, userId, newPkHashArray);
|
|
482
|
+
* ```
|
|
483
|
+
* @param {string} old_sk_hex
|
|
484
|
+
* @param {number} user_id
|
|
485
|
+
* @param {BigUint64Array} new_pk_hash
|
|
486
|
+
* @returns {any}
|
|
487
|
+
*/
|
|
488
|
+
function schnorr_sign_cpk(old_sk_hex, user_id, new_pk_hash) {
|
|
489
|
+
const ptr0 = passStringToWasm0(old_sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
490
|
+
const len0 = WASM_VECTOR_LEN;
|
|
491
|
+
const ptr1 = passArray64ToWasm0(new_pk_hash, wasm.__wbindgen_export);
|
|
492
|
+
const len1 = WASM_VECTOR_LEN;
|
|
493
|
+
const ret = wasm.schnorr_sign_cpk(ptr0, len0, user_id, ptr1, len1);
|
|
494
|
+
return takeObject(ret);
|
|
495
|
+
}
|
|
496
|
+
exports.schnorr_sign_cpk = schnorr_sign_cpk;
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Sign a transaction with Schnorr (ECgFp5).
|
|
500
|
+
*
|
|
501
|
+
* msg_hash = Poseidon2(tx_type, user_id, currency_id, amount_lo, amount_hi)
|
|
502
|
+
*
|
|
503
|
+
* Returns a JS object: `{ pubkey: "hex", sig_r: "hex", sig_s: "hex" }`
|
|
504
|
+
*
|
|
505
|
+
* ```js
|
|
506
|
+
* const sig = schnorr_sign_tx(skHex, 5, userId, 0, amountBigInt);
|
|
507
|
+
* // sig.pubkey, sig.sig_r, sig.sig_s — all hex strings (80 chars each)
|
|
508
|
+
* ```
|
|
509
|
+
* @param {string} sk_hex
|
|
510
|
+
* @param {number} tx_type
|
|
511
|
+
* @param {number} user_id
|
|
512
|
+
* @param {number} currency_id
|
|
513
|
+
* @param {number} amount_lo
|
|
514
|
+
* @param {number} amount_hi
|
|
515
|
+
* @returns {any}
|
|
516
|
+
*/
|
|
517
|
+
function schnorr_sign_tx(sk_hex, tx_type, user_id, currency_id, amount_lo, amount_hi) {
|
|
518
|
+
const ptr0 = passStringToWasm0(sk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
519
|
+
const len0 = WASM_VECTOR_LEN;
|
|
520
|
+
const ret = wasm.schnorr_sign_tx(ptr0, len0, tx_type, user_id, currency_id, amount_lo, amount_hi);
|
|
521
|
+
return takeObject(ret);
|
|
522
|
+
}
|
|
523
|
+
exports.schnorr_sign_tx = schnorr_sign_tx;
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Verify a Schnorr signature for a transaction on the backend.
|
|
527
|
+
*
|
|
528
|
+
* Checks: s·G == R + H(R‖pk‖msg)·pk
|
|
529
|
+
*
|
|
530
|
+
* Returns `true` if signature is valid, `false` otherwise.
|
|
531
|
+
*
|
|
532
|
+
* ```js
|
|
533
|
+
* const ok = schnorr_verify_tx(pubkeyHex, sigRHex, sigSHex, 5, userId, 0, amountLo, amountHi);
|
|
534
|
+
* ```
|
|
535
|
+
* @param {string} pk_hex
|
|
536
|
+
* @param {string} sig_r_hex
|
|
537
|
+
* @param {string} sig_s_hex
|
|
538
|
+
* @param {number} tx_type
|
|
539
|
+
* @param {number} user_id
|
|
540
|
+
* @param {number} currency_id
|
|
541
|
+
* @param {number} amount_lo
|
|
542
|
+
* @param {number} amount_hi
|
|
543
|
+
* @returns {boolean}
|
|
544
|
+
*/
|
|
545
|
+
function schnorr_verify_tx(pk_hex, sig_r_hex, sig_s_hex, tx_type, user_id, currency_id, amount_lo, amount_hi) {
|
|
546
|
+
const ptr0 = passStringToWasm0(pk_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
547
|
+
const len0 = WASM_VECTOR_LEN;
|
|
548
|
+
const ptr1 = passStringToWasm0(sig_r_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
549
|
+
const len1 = WASM_VECTOR_LEN;
|
|
550
|
+
const ptr2 = passStringToWasm0(sig_s_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
551
|
+
const len2 = WASM_VECTOR_LEN;
|
|
552
|
+
const ret = wasm.schnorr_verify_tx(ptr0, len0, ptr1, len1, ptr2, len2, tx_type, user_id, currency_id, amount_lo, amount_hi);
|
|
553
|
+
return ret !== 0;
|
|
554
|
+
}
|
|
555
|
+
exports.schnorr_verify_tx = schnorr_verify_tx;
|
|
556
|
+
|
|
263
557
|
/**
|
|
264
558
|
* Truncated seed hash — first 2 elements of `Poseidon2(server_seed)`.
|
|
265
559
|
*
|
|
@@ -274,13 +568,13 @@ exports.poseidon2_two_to_one = poseidon2_two_to_one;
|
|
|
274
568
|
function seed_hash_truncated(server_seed) {
|
|
275
569
|
try {
|
|
276
570
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
277
|
-
const ptr0 = passArray64ToWasm0(server_seed, wasm.
|
|
571
|
+
const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export);
|
|
278
572
|
const len0 = WASM_VECTOR_LEN;
|
|
279
573
|
wasm.seed_hash_truncated(retptr, ptr0, len0);
|
|
280
574
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
281
575
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
282
576
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
283
|
-
wasm.
|
|
577
|
+
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
284
578
|
return v2;
|
|
285
579
|
} finally {
|
|
286
580
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -301,13 +595,13 @@ exports.seed_hash_truncated = seed_hash_truncated;
|
|
|
301
595
|
function session_public_key(session_key) {
|
|
302
596
|
try {
|
|
303
597
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
304
|
-
const ptr0 = passArray64ToWasm0(session_key, wasm.
|
|
598
|
+
const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export);
|
|
305
599
|
const len0 = WASM_VECTOR_LEN;
|
|
306
600
|
wasm.session_public_key(retptr, ptr0, len0);
|
|
307
601
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
308
602
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
309
603
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
310
|
-
wasm.
|
|
604
|
+
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
311
605
|
return v2;
|
|
312
606
|
} finally {
|
|
313
607
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -334,13 +628,13 @@ exports.session_public_key = session_public_key;
|
|
|
334
628
|
function string_to_user_seed(input) {
|
|
335
629
|
try {
|
|
336
630
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
337
|
-
const ptr0 = passStringToWasm0(input, wasm.
|
|
631
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
338
632
|
const len0 = WASM_VECTOR_LEN;
|
|
339
633
|
wasm.string_to_user_seed(retptr, ptr0, len0);
|
|
340
634
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
341
635
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
342
636
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
343
|
-
wasm.
|
|
637
|
+
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
344
638
|
return v2;
|
|
345
639
|
} finally {
|
|
346
640
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -366,7 +660,7 @@ function string_to_user_seed_hex(input) {
|
|
|
366
660
|
let deferred2_1;
|
|
367
661
|
try {
|
|
368
662
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
369
|
-
const ptr0 = passStringToWasm0(input, wasm.
|
|
663
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
370
664
|
const len0 = WASM_VECTOR_LEN;
|
|
371
665
|
wasm.string_to_user_seed_hex(retptr, ptr0, len0);
|
|
372
666
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
@@ -376,7 +670,7 @@ function string_to_user_seed_hex(input) {
|
|
|
376
670
|
return getStringFromWasm0(r0, r1);
|
|
377
671
|
} finally {
|
|
378
672
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
379
|
-
wasm.
|
|
673
|
+
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
380
674
|
}
|
|
381
675
|
}
|
|
382
676
|
exports.string_to_user_seed_hex = string_to_user_seed_hex;
|
|
@@ -384,6 +678,13 @@ exports.string_to_user_seed_hex = string_to_user_seed_hex;
|
|
|
384
678
|
function __wbg_get_imports() {
|
|
385
679
|
const import0 = {
|
|
386
680
|
__proto__: null,
|
|
681
|
+
__wbg___wbindgen_debug_string_0bc8482c6e3508ae: function(arg0, arg1) {
|
|
682
|
+
const ret = debugString(getObject(arg1));
|
|
683
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
684
|
+
const len1 = WASM_VECTOR_LEN;
|
|
685
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
686
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
687
|
+
},
|
|
387
688
|
__wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
|
|
388
689
|
const ret = typeof(getObject(arg0)) === 'function';
|
|
389
690
|
return ret;
|
|
@@ -427,6 +728,10 @@ function __wbg_get_imports() {
|
|
|
427
728
|
const ret = getObject(arg0).msCrypto;
|
|
428
729
|
return addHeapObject(ret);
|
|
429
730
|
},
|
|
731
|
+
__wbg_new_361308b2356cecd0: function() {
|
|
732
|
+
const ret = new Object();
|
|
733
|
+
return addHeapObject(ret);
|
|
734
|
+
},
|
|
430
735
|
__wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
|
|
431
736
|
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
432
737
|
return addHeapObject(ret);
|
|
@@ -453,6 +758,10 @@ function __wbg_get_imports() {
|
|
|
453
758
|
const ret = module.require;
|
|
454
759
|
return addHeapObject(ret);
|
|
455
760
|
}, arguments); },
|
|
761
|
+
__wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
|
|
762
|
+
const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
|
|
763
|
+
return ret;
|
|
764
|
+
}, arguments); },
|
|
456
765
|
__wbg_static_accessor_GLOBAL_12837167ad935116: function() {
|
|
457
766
|
const ret = typeof global === 'undefined' ? null : global;
|
|
458
767
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
@@ -510,12 +819,82 @@ function addHeapObject(obj) {
|
|
|
510
819
|
return idx;
|
|
511
820
|
}
|
|
512
821
|
|
|
822
|
+
function debugString(val) {
|
|
823
|
+
// primitive types
|
|
824
|
+
const type = typeof val;
|
|
825
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
826
|
+
return `${val}`;
|
|
827
|
+
}
|
|
828
|
+
if (type == 'string') {
|
|
829
|
+
return `"${val}"`;
|
|
830
|
+
}
|
|
831
|
+
if (type == 'symbol') {
|
|
832
|
+
const description = val.description;
|
|
833
|
+
if (description == null) {
|
|
834
|
+
return 'Symbol';
|
|
835
|
+
} else {
|
|
836
|
+
return `Symbol(${description})`;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
if (type == 'function') {
|
|
840
|
+
const name = val.name;
|
|
841
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
842
|
+
return `Function(${name})`;
|
|
843
|
+
} else {
|
|
844
|
+
return 'Function';
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
// objects
|
|
848
|
+
if (Array.isArray(val)) {
|
|
849
|
+
const length = val.length;
|
|
850
|
+
let debug = '[';
|
|
851
|
+
if (length > 0) {
|
|
852
|
+
debug += debugString(val[0]);
|
|
853
|
+
}
|
|
854
|
+
for(let i = 1; i < length; i++) {
|
|
855
|
+
debug += ', ' + debugString(val[i]);
|
|
856
|
+
}
|
|
857
|
+
debug += ']';
|
|
858
|
+
return debug;
|
|
859
|
+
}
|
|
860
|
+
// Test for built-in
|
|
861
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
862
|
+
let className;
|
|
863
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
864
|
+
className = builtInMatches[1];
|
|
865
|
+
} else {
|
|
866
|
+
// Failed to match the standard '[object ClassName]'
|
|
867
|
+
return toString.call(val);
|
|
868
|
+
}
|
|
869
|
+
if (className == 'Object') {
|
|
870
|
+
// we're a user defined class or Object
|
|
871
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
872
|
+
// easier than looping through ownProperties of `val`.
|
|
873
|
+
try {
|
|
874
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
875
|
+
} catch (_) {
|
|
876
|
+
return 'Object';
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
// errors
|
|
880
|
+
if (val instanceof Error) {
|
|
881
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
882
|
+
}
|
|
883
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
884
|
+
return className;
|
|
885
|
+
}
|
|
886
|
+
|
|
513
887
|
function dropObject(idx) {
|
|
514
888
|
if (idx < 132) return;
|
|
515
889
|
heap[idx] = heap_next;
|
|
516
890
|
heap_next = idx;
|
|
517
891
|
}
|
|
518
892
|
|
|
893
|
+
function getArrayU32FromWasm0(ptr, len) {
|
|
894
|
+
ptr = ptr >>> 0;
|
|
895
|
+
return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
896
|
+
}
|
|
897
|
+
|
|
519
898
|
function getArrayU64FromWasm0(ptr, len) {
|
|
520
899
|
ptr = ptr >>> 0;
|
|
521
900
|
return getBigUint64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
|
|
@@ -547,6 +926,14 @@ function getStringFromWasm0(ptr, len) {
|
|
|
547
926
|
return decodeText(ptr, len);
|
|
548
927
|
}
|
|
549
928
|
|
|
929
|
+
let cachedUint32ArrayMemory0 = null;
|
|
930
|
+
function getUint32ArrayMemory0() {
|
|
931
|
+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
932
|
+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
933
|
+
}
|
|
934
|
+
return cachedUint32ArrayMemory0;
|
|
935
|
+
}
|
|
936
|
+
|
|
550
937
|
let cachedUint8ArrayMemory0 = null;
|
|
551
938
|
function getUint8ArrayMemory0() {
|
|
552
939
|
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
@@ -561,7 +948,7 @@ function handleError(f, args) {
|
|
|
561
948
|
try {
|
|
562
949
|
return f.apply(this, args);
|
|
563
950
|
} catch (e) {
|
|
564
|
-
wasm.
|
|
951
|
+
wasm.__wbindgen_export3(addHeapObject(e));
|
|
565
952
|
}
|
|
566
953
|
}
|
|
567
954
|
|
|
Binary file
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const amount_split: (a: number, b: bigint) => void;
|
|
4
5
|
export const compute_server_seed_hash: (a: number, b: number, c: number) => void;
|
|
6
|
+
export const compute_tx_msg_hash: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
5
7
|
export const create_bet_auth: (a: number, b: number, c: number, d: bigint, e: bigint) => void;
|
|
6
8
|
export const derive_session_key: (a: number, b: number, c: number) => void;
|
|
7
9
|
export const generate_user_seed: (a: number) => void;
|
|
@@ -9,13 +11,21 @@ export const goldilocks_fields_to_hex: (a: number, b: number, c: number) => void
|
|
|
9
11
|
export const goldilocks_reduce: (a: bigint) => bigint;
|
|
10
12
|
export const poseidon2_hash: (a: number, b: number, c: number) => void;
|
|
11
13
|
export const poseidon2_two_to_one: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
14
|
+
export const schnorr_keygen: (a: number, b: number, c: number) => void;
|
|
15
|
+
export const schnorr_pk_encode: (a: number, b: number, c: number) => void;
|
|
16
|
+
export const schnorr_pk_hash: (a: number, b: number, c: number) => void;
|
|
17
|
+
export const schnorr_pk_hash_hex: (a: number, b: number, c: number) => void;
|
|
18
|
+
export const schnorr_pubkey: (a: number, b: number, c: number) => void;
|
|
19
|
+
export const schnorr_sign_cpk: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
20
|
+
export const schnorr_sign_tx: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
|
|
21
|
+
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) => number;
|
|
12
22
|
export const seed_hash_truncated: (a: number, b: number, c: number) => void;
|
|
13
23
|
export const session_public_key: (a: number, b: number, c: number) => void;
|
|
14
24
|
export const string_to_user_seed: (a: number, b: number, c: number) => void;
|
|
15
25
|
export const string_to_user_seed_hex: (a: number, b: number, c: number) => void;
|
|
16
26
|
export const goldilocks_modulus: () => bigint;
|
|
17
|
-
export const __wbindgen_export: (a: number) =>
|
|
27
|
+
export const __wbindgen_export: (a: number, b: number) => number;
|
|
28
|
+
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
29
|
+
export const __wbindgen_export3: (a: number) => void;
|
|
18
30
|
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
19
|
-
export const
|
|
20
|
-
export const __wbindgen_export3: (a: number, b: number, c: number) => void;
|
|
21
|
-
export const __wbindgen_export4: (a: number, b: number, c: number, d: number) => number;
|
|
31
|
+
export const __wbindgen_export4: (a: number, b: number, c: number) => void;
|