@rolly-dev/wasm-signer 0.12.0 → 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 +10 -13
- package/dist/node/README.md +10 -13
- package/dist/node/rolly_wasm_signer.d.ts +41 -142
- package/dist/node/rolly_wasm_signer.js +96 -415
- package/dist/node/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/node/rolly_wasm_signer_bg.wasm.d.ts +7 -15
- package/dist/node-inline/README.md +10 -13
- package/dist/node-inline/rolly_wasm_signer.d.ts +41 -142
- package/dist/node-inline/rolly_wasm_signer.js +97 -416
- package/dist/node-inline/rolly_wasm_signer.mjs +94 -405
- package/dist/node-inline/rolly_wasm_signer_bg.wasm.d.ts +7 -15
- package/dist/web/README.md +10 -13
- package/dist/web/rolly_wasm_signer.d.ts +48 -157
- package/dist/web/rolly_wasm_signer.js +92 -403
- package/dist/web/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/web/rolly_wasm_signer_bg.wasm.d.ts +7 -15
- package/js/browser.d.mts +2 -10
- package/js/browser.mjs +2 -10
- package/js/index.d.ts +2 -10
- package/js/node-inline.cjs +2 -10
- package/js/node-inline.mjs +2 -10
- package/js/node.cjs +2 -10
- package/js/node.mjs +2 -10
- package/js/react.d.mts +3 -11
- package/js/react.mjs +4 -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);
|
|
@@ -53,7 +53,7 @@ exports.compute_address_hash = compute_address_hash;
|
|
|
53
53
|
* Full Poseidon2 hash of an 8-element server seed.
|
|
54
54
|
*
|
|
55
55
|
* Returns all 4 hash elements. Note: the circuit stores only the
|
|
56
|
-
* **first
|
|
56
|
+
* **first 3 elements** as the leaf commitment (see `seed_hash_truncated`).
|
|
57
57
|
* This full variant is useful for client-side verification where all
|
|
58
58
|
* 4 elements may be needed.
|
|
59
59
|
*
|
|
@@ -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;
|
|
@@ -278,329 +200,166 @@ function goldilocks_reduce(value) {
|
|
|
278
200
|
exports.goldilocks_reduce = goldilocks_reduce;
|
|
279
201
|
|
|
280
202
|
/**
|
|
281
|
-
*
|
|
203
|
+
* Hash a raw 7-element balance leaf → 4-element Merkle node.
|
|
282
204
|
*
|
|
283
|
-
*
|
|
284
|
-
* the circuit and `Poseidon2Hash::hash_no_pad` in `src/block_builder`.
|
|
205
|
+
* Raw layout: `[balance_lo, balance_hi, seed_hash_0, seed_hash_1, seed_hash_2, credit_lo, credit_hi]`
|
|
285
206
|
*
|
|
286
|
-
*
|
|
207
|
+
* Identical to `hash_balance_leaf` in `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
208
|
+
*
|
|
209
|
+
* **Input** : `BigUint64Array` of exactly 7 elements (each < `GOLDILOCKS_P`).
|
|
287
210
|
* **Output**: `BigUint64Array` of length 4 (one `HashOut`).
|
|
288
211
|
*
|
|
289
212
|
* ```js
|
|
290
|
-
* const
|
|
291
|
-
* //
|
|
213
|
+
* const raw = BigUint64Array.from([balLo, balHi, seed0, seed1, seed2, credLo, credHi]);
|
|
214
|
+
* const balanceHash = hash_balance_leaf(raw); // length 4
|
|
292
215
|
* ```
|
|
293
|
-
* @param {BigUint64Array}
|
|
216
|
+
* @param {BigUint64Array} raw
|
|
294
217
|
* @returns {BigUint64Array}
|
|
295
218
|
*/
|
|
296
|
-
function
|
|
219
|
+
function hash_balance_leaf(raw) {
|
|
297
220
|
try {
|
|
298
221
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
299
|
-
const ptr0 = passArray64ToWasm0(
|
|
222
|
+
const ptr0 = passArray64ToWasm0(raw, wasm.__wbindgen_export3);
|
|
300
223
|
const len0 = WASM_VECTOR_LEN;
|
|
301
|
-
wasm.
|
|
224
|
+
wasm.hash_balance_leaf(retptr, ptr0, len0);
|
|
302
225
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
303
226
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
304
227
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
305
|
-
wasm.
|
|
228
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
306
229
|
return v2;
|
|
307
230
|
} finally {
|
|
308
231
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
309
232
|
}
|
|
310
233
|
}
|
|
311
|
-
exports.
|
|
234
|
+
exports.hash_balance_leaf = hash_balance_leaf;
|
|
312
235
|
|
|
313
236
|
/**
|
|
314
|
-
* Merkle
|
|
237
|
+
* Build a main Merkle tree leaf from balance_hash, pk_hash, and address_hash.
|
|
315
238
|
*
|
|
316
|
-
*
|
|
317
|
-
* Input ordering is critical — `left` concatenated before `right`.
|
|
239
|
+
* `main_leaf = Poseidon2(balance_hash[4] || pk_hash[0..2] || address_hash[0..2])`
|
|
318
240
|
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
* @returns {BigUint64Array}
|
|
323
|
-
*/
|
|
324
|
-
function poseidon2_two_to_one(left, right) {
|
|
325
|
-
try {
|
|
326
|
-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
327
|
-
const ptr0 = passArray64ToWasm0(left, wasm.__wbindgen_export);
|
|
328
|
-
const len0 = WASM_VECTOR_LEN;
|
|
329
|
-
const ptr1 = passArray64ToWasm0(right, wasm.__wbindgen_export);
|
|
330
|
-
const len1 = WASM_VECTOR_LEN;
|
|
331
|
-
wasm.poseidon2_two_to_one(retptr, ptr0, len0, ptr1, len1);
|
|
332
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
333
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
334
|
-
var v3 = getArrayU64FromWasm0(r0, r1).slice();
|
|
335
|
-
wasm.__wbindgen_export4(r0, r1 * 8, 8);
|
|
336
|
-
return v3;
|
|
337
|
-
} finally {
|
|
338
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
exports.poseidon2_two_to_one = poseidon2_two_to_one;
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Derive a Schnorr secret key from entropy bytes (e.g. MetaMask signature).
|
|
241
|
+
* Uses truncated (128-bit) pk/address hashes to keep the preimage at 8 elements
|
|
242
|
+
* (single Poseidon2 permutation round). Identical to `make_main_leaf` in
|
|
243
|
+
* `prover/circuit/src/helpers/leaf_ops.rs`.
|
|
345
244
|
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
245
|
+
* All three inputs must be exactly 4 elements.
|
|
246
|
+
* **Output**: `BigUint64Array` of length 4 (the Merkle leaf hash).
|
|
348
247
|
*
|
|
349
248
|
* ```js
|
|
350
|
-
* const
|
|
249
|
+
* const leaf = make_main_leaf(balanceHash, pkHash, addressHash);
|
|
351
250
|
* ```
|
|
352
|
-
* @param {
|
|
353
|
-
* @
|
|
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
|
|
251
|
+
* @param {BigUint64Array} balance_hash
|
|
252
|
+
* @param {BigUint64Array} pk_hash
|
|
253
|
+
* @param {BigUint64Array} address_hash
|
|
385
254
|
* @returns {BigUint64Array}
|
|
386
255
|
*/
|
|
387
|
-
function
|
|
256
|
+
function make_main_leaf(balance_hash, pk_hash, address_hash) {
|
|
388
257
|
try {
|
|
389
258
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
390
|
-
const ptr0 =
|
|
259
|
+
const ptr0 = passArray64ToWasm0(balance_hash, wasm.__wbindgen_export3);
|
|
391
260
|
const len0 = WASM_VECTOR_LEN;
|
|
392
|
-
|
|
261
|
+
const ptr1 = passArray64ToWasm0(pk_hash, wasm.__wbindgen_export3);
|
|
262
|
+
const len1 = WASM_VECTOR_LEN;
|
|
263
|
+
const ptr2 = passArray64ToWasm0(address_hash, wasm.__wbindgen_export3);
|
|
264
|
+
const len2 = WASM_VECTOR_LEN;
|
|
265
|
+
wasm.make_main_leaf(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
393
266
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
394
267
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
395
|
-
var
|
|
396
|
-
wasm.
|
|
397
|
-
return
|
|
268
|
+
var v4 = getArrayU64FromWasm0(r0, r1).slice();
|
|
269
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
270
|
+
return v4;
|
|
398
271
|
} finally {
|
|
399
272
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
400
273
|
}
|
|
401
274
|
}
|
|
402
|
-
exports.
|
|
275
|
+
exports.make_main_leaf = make_main_leaf;
|
|
403
276
|
|
|
404
277
|
/**
|
|
405
|
-
*
|
|
278
|
+
* Poseidon2 hash of an arbitrary number of Goldilocks field elements.
|
|
406
279
|
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
280
|
+
* Mirrors `builder.hash_n_to_hash_no_pad::<Poseidon2Hash>(...)` inside
|
|
281
|
+
* the circuit and `Poseidon2Hash::hash_no_pad` in `src/block_builder`.
|
|
409
282
|
*
|
|
410
|
-
*
|
|
283
|
+
* **Input** : `BigUint64Array` — each element must be < `GOLDILOCKS_P`.
|
|
284
|
+
* **Output**: `BigUint64Array` of length 4 (one `HashOut`).
|
|
411
285
|
*
|
|
412
286
|
* ```js
|
|
413
|
-
* const
|
|
287
|
+
* const h = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n]));
|
|
288
|
+
* // h.length === 4
|
|
414
289
|
* ```
|
|
415
|
-
* @param {
|
|
290
|
+
* @param {BigUint64Array} input
|
|
416
291
|
* @returns {BigUint64Array}
|
|
417
292
|
*/
|
|
418
|
-
function
|
|
293
|
+
function poseidon2_hash(input) {
|
|
419
294
|
try {
|
|
420
295
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
421
|
-
const ptr0 =
|
|
296
|
+
const ptr0 = passArray64ToWasm0(input, wasm.__wbindgen_export3);
|
|
422
297
|
const len0 = WASM_VECTOR_LEN;
|
|
423
|
-
wasm.
|
|
298
|
+
wasm.poseidon2_hash(retptr, ptr0, len0);
|
|
424
299
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
425
300
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
426
301
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
427
|
-
wasm.
|
|
302
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
428
303
|
return v2;
|
|
429
304
|
} finally {
|
|
430
305
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
431
306
|
}
|
|
432
307
|
}
|
|
433
|
-
exports.
|
|
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;
|
|
308
|
+
exports.poseidon2_hash = poseidon2_hash;
|
|
463
309
|
|
|
464
310
|
/**
|
|
465
|
-
*
|
|
311
|
+
* Merkle-tree hash: Poseidon2(left[4] ‖ right[4]).
|
|
466
312
|
*
|
|
467
|
-
*
|
|
313
|
+
* Identical to `poseidon_hash(left, right)` in `src/merkletree/hash.rs`.
|
|
314
|
+
* Input ordering is critical — `left` concatenated before `right`.
|
|
468
315
|
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
* @
|
|
473
|
-
* @returns {string}
|
|
316
|
+
* Both arrays **must** have exactly 4 elements (one `HashOut` each).
|
|
317
|
+
* @param {BigUint64Array} left
|
|
318
|
+
* @param {BigUint64Array} right
|
|
319
|
+
* @returns {BigUint64Array}
|
|
474
320
|
*/
|
|
475
|
-
function
|
|
476
|
-
let deferred2_0;
|
|
477
|
-
let deferred2_1;
|
|
321
|
+
function poseidon2_two_to_one(left, right) {
|
|
478
322
|
try {
|
|
479
323
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
480
|
-
const ptr0 =
|
|
324
|
+
const ptr0 = passArray64ToWasm0(left, wasm.__wbindgen_export3);
|
|
481
325
|
const len0 = WASM_VECTOR_LEN;
|
|
482
|
-
|
|
326
|
+
const ptr1 = passArray64ToWasm0(right, wasm.__wbindgen_export3);
|
|
327
|
+
const len1 = WASM_VECTOR_LEN;
|
|
328
|
+
wasm.poseidon2_two_to_one(retptr, ptr0, len0, ptr1, len1);
|
|
483
329
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
484
330
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
return
|
|
331
|
+
var v3 = getArrayU64FromWasm0(r0, r1).slice();
|
|
332
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
333
|
+
return v3;
|
|
488
334
|
} finally {
|
|
489
335
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
490
|
-
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
491
336
|
}
|
|
492
337
|
}
|
|
493
|
-
exports.
|
|
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;
|
|
338
|
+
exports.poseidon2_two_to_one = poseidon2_two_to_one;
|
|
582
339
|
|
|
583
340
|
/**
|
|
584
|
-
* Truncated seed hash — first
|
|
341
|
+
* Truncated seed hash — first 3 elements of `Poseidon2(server_seed)`.
|
|
585
342
|
*
|
|
343
|
+
* 192 bits of commitment → ~96-bit collision resistance, which closes the
|
|
344
|
+
* multi-preimage grinding vector that an earlier 128-bit truncation left open.
|
|
586
345
|
* This is the exact format stored in the Merkle-tree leaf and verified
|
|
587
346
|
* by the circuit. Matches `seed_hash_truncated` in
|
|
588
|
-
* `src/block_builder/builder.rs` and `src/circuit/
|
|
347
|
+
* `src/block_builder/builder.rs` and `src/circuit/slot/fairness.rs`.
|
|
589
348
|
*
|
|
590
|
-
* Returns `BigUint64Array` of length
|
|
349
|
+
* Returns `BigUint64Array` of length 3: `[h[0], h[1], h[2]]`.
|
|
591
350
|
* @param {BigUint64Array} server_seed
|
|
592
351
|
* @returns {BigUint64Array}
|
|
593
352
|
*/
|
|
594
353
|
function seed_hash_truncated(server_seed) {
|
|
595
354
|
try {
|
|
596
355
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
597
|
-
const ptr0 = passArray64ToWasm0(server_seed, wasm.
|
|
356
|
+
const ptr0 = passArray64ToWasm0(server_seed, wasm.__wbindgen_export3);
|
|
598
357
|
const len0 = WASM_VECTOR_LEN;
|
|
599
358
|
wasm.seed_hash_truncated(retptr, ptr0, len0);
|
|
600
359
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
601
360
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
602
361
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
603
|
-
wasm.
|
|
362
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
604
363
|
return v2;
|
|
605
364
|
} finally {
|
|
606
365
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -609,25 +368,27 @@ function seed_hash_truncated(server_seed) {
|
|
|
609
368
|
exports.seed_hash_truncated = seed_hash_truncated;
|
|
610
369
|
|
|
611
370
|
/**
|
|
612
|
-
* Compute the public key for a session: `
|
|
371
|
+
* Compute the public key for a session: `pk_hash = Poseidon2(session_key[4], expiry)`.
|
|
613
372
|
*
|
|
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`).
|
|
373
|
+
* The public key hash is stored in the user-asset Merkle leaf and verified
|
|
374
|
+
* inside the circuit (the prover must know the preimage `session_key` + `expiry`).
|
|
616
375
|
*
|
|
617
376
|
* `session_key` must be exactly 4 elements (output of `derive_session_key`).
|
|
377
|
+
* `session_expiry` is the Unix timestamp after which the session is invalid.
|
|
618
378
|
* @param {BigUint64Array} session_key
|
|
379
|
+
* @param {bigint} session_expiry
|
|
619
380
|
* @returns {BigUint64Array}
|
|
620
381
|
*/
|
|
621
|
-
function session_public_key(session_key) {
|
|
382
|
+
function session_public_key(session_key, session_expiry) {
|
|
622
383
|
try {
|
|
623
384
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
624
|
-
const ptr0 = passArray64ToWasm0(session_key, wasm.
|
|
385
|
+
const ptr0 = passArray64ToWasm0(session_key, wasm.__wbindgen_export3);
|
|
625
386
|
const len0 = WASM_VECTOR_LEN;
|
|
626
|
-
wasm.session_public_key(retptr, ptr0, len0);
|
|
387
|
+
wasm.session_public_key(retptr, ptr0, len0, session_expiry);
|
|
627
388
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
628
389
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
629
390
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
630
|
-
wasm.
|
|
391
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
631
392
|
return v2;
|
|
632
393
|
} finally {
|
|
633
394
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -654,13 +415,13 @@ exports.session_public_key = session_public_key;
|
|
|
654
415
|
function string_to_user_seed(input) {
|
|
655
416
|
try {
|
|
656
417
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
657
|
-
const ptr0 = passStringToWasm0(input, wasm.
|
|
418
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
658
419
|
const len0 = WASM_VECTOR_LEN;
|
|
659
420
|
wasm.string_to_user_seed(retptr, ptr0, len0);
|
|
660
421
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
661
422
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
662
423
|
var v2 = getArrayU64FromWasm0(r0, r1).slice();
|
|
663
|
-
wasm.
|
|
424
|
+
wasm.__wbindgen_export2(r0, r1 * 8, 8);
|
|
664
425
|
return v2;
|
|
665
426
|
} finally {
|
|
666
427
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
@@ -686,7 +447,7 @@ function string_to_user_seed_hex(input) {
|
|
|
686
447
|
let deferred2_1;
|
|
687
448
|
try {
|
|
688
449
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
689
|
-
const ptr0 = passStringToWasm0(input, wasm.
|
|
450
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
|
|
690
451
|
const len0 = WASM_VECTOR_LEN;
|
|
691
452
|
wasm.string_to_user_seed_hex(retptr, ptr0, len0);
|
|
692
453
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
@@ -696,7 +457,7 @@ function string_to_user_seed_hex(input) {
|
|
|
696
457
|
return getStringFromWasm0(r0, r1);
|
|
697
458
|
} finally {
|
|
698
459
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
699
|
-
wasm.
|
|
460
|
+
wasm.__wbindgen_export2(deferred2_0, deferred2_1, 1);
|
|
700
461
|
}
|
|
701
462
|
}
|
|
702
463
|
exports.string_to_user_seed_hex = string_to_user_seed_hex;
|
|
@@ -704,13 +465,6 @@ exports.string_to_user_seed_hex = string_to_user_seed_hex;
|
|
|
704
465
|
function __wbg_get_imports() {
|
|
705
466
|
const import0 = {
|
|
706
467
|
__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
468
|
__wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
|
|
715
469
|
const ret = typeof(getObject(arg0)) === 'function';
|
|
716
470
|
return ret;
|
|
@@ -754,10 +508,6 @@ function __wbg_get_imports() {
|
|
|
754
508
|
const ret = getObject(arg0).msCrypto;
|
|
755
509
|
return addHeapObject(ret);
|
|
756
510
|
},
|
|
757
|
-
__wbg_new_361308b2356cecd0: function() {
|
|
758
|
-
const ret = new Object();
|
|
759
|
-
return addHeapObject(ret);
|
|
760
|
-
},
|
|
761
511
|
__wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
|
|
762
512
|
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
763
513
|
return addHeapObject(ret);
|
|
@@ -784,10 +534,6 @@ function __wbg_get_imports() {
|
|
|
784
534
|
const ret = module.require;
|
|
785
535
|
return addHeapObject(ret);
|
|
786
536
|
}, 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
537
|
__wbg_static_accessor_GLOBAL_12837167ad935116: function() {
|
|
792
538
|
const ret = typeof global === 'undefined' ? null : global;
|
|
793
539
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
@@ -845,71 +591,6 @@ function addHeapObject(obj) {
|
|
|
845
591
|
return idx;
|
|
846
592
|
}
|
|
847
593
|
|
|
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
594
|
function dropObject(idx) {
|
|
914
595
|
if (idx < 132) return;
|
|
915
596
|
heap[idx] = heap_next;
|
|
@@ -974,7 +655,7 @@ function handleError(f, args) {
|
|
|
974
655
|
try {
|
|
975
656
|
return f.apply(this, args);
|
|
976
657
|
} catch (e) {
|
|
977
|
-
wasm.
|
|
658
|
+
wasm.__wbindgen_export(addHeapObject(e));
|
|
978
659
|
}
|
|
979
660
|
}
|
|
980
661
|
|