@quantovainc/qcore 0.5.1 → 0.5.3
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 +3 -1
- package/index.d.ts +15 -0
- package/package.json +1 -1
- package/pkg/README.md +3 -1
- package/pkg/package.json +1 -1
- package/pkg/qcore_js.d.ts +12 -2
- package/pkg/qcore_js.js +1 -1
- package/pkg/qcore_js_bg.js +149 -27
- package/pkg/qcore_js_bg.wasm +0 -0
- package/pkg/qcore_js_bg.wasm.d.ts +7 -2
- package/pkg-node/README.md +3 -1
- package/pkg-node/package.json +1 -1
- package/pkg-node/qcore_js.d.ts +12 -2
- package/pkg-node/qcore_js.js +154 -27
- package/pkg-node/qcore_js_bg.wasm +0 -0
- package/shared.js +48 -3
- package/shared.mjs +48 -3
package/README.md
CHANGED
|
@@ -231,7 +231,9 @@ the fee cap and the amount guard and never the bare signing functions.
|
|
|
231
231
|
The raw builds are still reachable on their own subpaths, `@quantovainc/qcore/pkg` for the bundler build
|
|
232
232
|
and `@quantovainc/qcore/pkg-node` for the nodejs build. Those export only the core.* functions, with no
|
|
233
233
|
Client, no fee cap, and no amount guard, and are for an advanced caller who assembles the fee comparison
|
|
234
|
-
alone.
|
|
234
|
+
alone. A whole number argument above the u64 range wraps modulo 2^64 in a raw build, so such a caller
|
|
235
|
+
must range check every amount, fee, nonce, and expiry before the call. The default browser, import,
|
|
236
|
+
node, and require resolutions never reach them.
|
|
235
237
|
|
|
236
238
|
To build both from source, run `npm run build`, which produces the bundler build in `pkg` and the node
|
|
237
239
|
build in `pkg-node`.
|
package/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export interface SignedOrder {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export interface OrderLayout {
|
|
21
|
+
layoutHash: string;
|
|
21
22
|
schemeOff: number | bigint;
|
|
22
23
|
ptrOff: number | bigint;
|
|
23
24
|
expiryOff: number | bigint;
|
|
@@ -32,7 +33,14 @@ export interface SignedOrderField {
|
|
|
32
33
|
value: string;
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
export interface OrderLayoutField {
|
|
37
|
+
name: string;
|
|
38
|
+
type: string;
|
|
39
|
+
width: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
35
42
|
export interface SignedOrderSpec {
|
|
43
|
+
layoutHash: string;
|
|
36
44
|
schemeOff: number | bigint;
|
|
37
45
|
ptrOff: number | bigint;
|
|
38
46
|
expiryOff: number | bigint;
|
|
@@ -62,6 +70,7 @@ export interface QCore {
|
|
|
62
70
|
chain_id: WholeNumber,
|
|
63
71
|
contract: string,
|
|
64
72
|
selector_hex: string,
|
|
73
|
+
layout_hash_hex: string,
|
|
65
74
|
scheme_off: WholeNumber,
|
|
66
75
|
ptr_off: WholeNumber,
|
|
67
76
|
expiry_off: WholeNumber,
|
|
@@ -77,6 +86,7 @@ export interface QCore {
|
|
|
77
86
|
chain_id: WholeNumber,
|
|
78
87
|
contract: string,
|
|
79
88
|
selector_hex: string,
|
|
89
|
+
layout_hash_hex: string,
|
|
80
90
|
scheme_off: WholeNumber,
|
|
81
91
|
ptr_off: WholeNumber,
|
|
82
92
|
expiry_off: WholeNumber,
|
|
@@ -98,6 +108,11 @@ export interface QCore {
|
|
|
98
108
|
mnemonicFromSeed(seed: Uint8Array): Uint8Array;
|
|
99
109
|
mnemonicFromSeedText(seed: Uint8Array): string;
|
|
100
110
|
nonceSlotKey(signer_hex: string): string;
|
|
111
|
+
orderLayoutHash(selector_hex: string, fields_json: string): string;
|
|
112
|
+
checkOrderExpiry(expiry: WholeNumber, now_secs: WholeNumber): void;
|
|
113
|
+
verifyFinality(chain_id: WholeNumber, header_hex: string, certificate_hex: string, roster_json: string): string;
|
|
114
|
+
verifyEvent(event_root_hex: string, leaf_hex: string, steps_json: string): boolean;
|
|
115
|
+
decodeEvent(leaf_hex: string): string;
|
|
101
116
|
orderSigner(seed: Uint8Array, index: WholeNumber): string;
|
|
102
117
|
parseEvents(response: string): string;
|
|
103
118
|
scalarSlotKey(slot: WholeNumber): string;
|
package/package.json
CHANGED
package/pkg/README.md
CHANGED
|
@@ -231,7 +231,9 @@ the fee cap and the amount guard and never the bare signing functions.
|
|
|
231
231
|
The raw builds are still reachable on their own subpaths, `@quantovainc/qcore/pkg` for the bundler build
|
|
232
232
|
and `@quantovainc/qcore/pkg-node` for the nodejs build. Those export only the core.* functions, with no
|
|
233
233
|
Client, no fee cap, and no amount guard, and are for an advanced caller who assembles the fee comparison
|
|
234
|
-
alone.
|
|
234
|
+
alone. A whole number argument above the u64 range wraps modulo 2^64 in a raw build, so such a caller
|
|
235
|
+
must range check every amount, fee, nonce, and expiry before the call. The default browser, import,
|
|
236
|
+
node, and require resolutions never reach them.
|
|
235
237
|
|
|
236
238
|
To build both from source, run `npm run build`, which produces the bundler build in `pkg` and the node
|
|
237
239
|
build in `pkg-node`.
|
package/pkg/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "qcore-js",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "The JavaScript binding for the Quantova client core, generated over QCore with wasm-bindgen. The core does the key derivation, the post quantum signing, and the wire, the page does the fetch.",
|
|
5
|
-
"version": "0.5.
|
|
5
|
+
"version": "0.5.3",
|
|
6
6
|
"license": "Apache-2.0 OR MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
package/pkg/qcore_js.d.ts
CHANGED
|
@@ -26,18 +26,22 @@ export function block_by_height_body(height: bigint): string;
|
|
|
26
26
|
|
|
27
27
|
export function boundedValidUntil(chain_name: string, head: bigint, wall_secs: bigint, floor: bigint | null | undefined, floor_age_secs: bigint): bigint;
|
|
28
28
|
|
|
29
|
-
export function buildSignedOrderCall(chain_id: bigint, contract: string, selector_hex: string, scheme_off: bigint, ptr_off: bigint, expiry_off: bigint, field_offs_csv: string, fields_csv: string, region_off: bigint, owner_seed_bytes: Uint8Array, owner_index: bigint, nonce: bigint, expiry: bigint): string;
|
|
29
|
+
export function buildSignedOrderCall(chain_id: bigint, contract: string, selector_hex: string, layout_hash_hex: string, scheme_off: bigint, ptr_off: bigint, expiry_off: bigint, field_offs_csv: string, fields_csv: string, region_off: bigint, owner_seed_bytes: Uint8Array, owner_index: bigint, nonce: bigint, expiry: bigint): string;
|
|
30
30
|
|
|
31
|
-
export function buildTypedOrderCall(chain_id: bigint, contract: string, selector_hex: string, scheme_off: bigint, ptr_off: bigint, expiry_off: bigint, region_off: bigint, fields_json: string, owner_seed_bytes: Uint8Array, owner_index: bigint, nonce: bigint, expiry: bigint): string;
|
|
31
|
+
export function buildTypedOrderCall(chain_id: bigint, contract: string, selector_hex: string, layout_hash_hex: string, scheme_off: bigint, ptr_off: bigint, expiry_off: bigint, region_off: bigint, fields_json: string, owner_seed_bytes: Uint8Array, owner_index: bigint, nonce: bigint, expiry: bigint): string;
|
|
32
32
|
|
|
33
33
|
export function chainIdFromName(name: string): bigint;
|
|
34
34
|
|
|
35
35
|
export function checkGatewayJson(response: string): void;
|
|
36
36
|
|
|
37
|
+
export function checkOrderExpiry(expiry: bigint, now_secs: bigint): void;
|
|
38
|
+
|
|
37
39
|
export function checkValidUntil(valid_until: bigint, head: bigint): void;
|
|
38
40
|
|
|
39
41
|
export function contractAddress(deployer: string, nonce: bigint): string | undefined;
|
|
40
42
|
|
|
43
|
+
export function decodeEvent(leaf_hex: string): string;
|
|
44
|
+
|
|
41
45
|
export function eventsBody(height: bigint): string;
|
|
42
46
|
|
|
43
47
|
export function genesisSecs(chain_name: string): bigint;
|
|
@@ -62,6 +66,8 @@ export function nameKey(label: string): string;
|
|
|
62
66
|
|
|
63
67
|
export function nonceSlotKey(signer_hex: string): string;
|
|
64
68
|
|
|
69
|
+
export function orderLayoutHash(selector_hex: string, fields_json: string): string;
|
|
70
|
+
|
|
65
71
|
export function orderSigner(seed_bytes: Uint8Array, index: bigint): string;
|
|
66
72
|
|
|
67
73
|
export function packSymbol(symbol: string): bigint;
|
|
@@ -110,6 +116,10 @@ export function valid_address(address: string): boolean;
|
|
|
110
116
|
|
|
111
117
|
export function validityBlocks(): bigint;
|
|
112
118
|
|
|
119
|
+
export function verifyEvent(event_root_hex: string, leaf_hex: string, steps_json: string): boolean;
|
|
120
|
+
|
|
121
|
+
export function verifyFinality(chain_id: bigint, header_hex: string, certificate_hex: string, roster_json: string): string;
|
|
122
|
+
|
|
113
123
|
export function vmCallFee(transfer_fee: string, meter_limit: bigint): string;
|
|
114
124
|
|
|
115
125
|
export function vmDeployAddress(): string;
|
package/pkg/qcore_js.js
CHANGED
|
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./qcore_js_bg.js";
|
|
|
5
5
|
__wbg_set_wasm(wasm);
|
|
6
6
|
wasm.__wbindgen_start();
|
|
7
7
|
export {
|
|
8
|
-
SigningSession, account_body, address, assetBalanceBody, assetSupplyBody, block_by_height_body, boundedValidUntil, buildSignedOrderCall, buildTypedOrderCall, chainIdFromName, checkGatewayJson, checkValidUntil, contractAddress, eventsBody, genesisSecs, headCeiling, localChainId, lookalikeOf, mainnetChainId, mapAddrWordKey, mapSlotKey, mnemonicFromSeed, mnemonicFromSeedText, nameKey, nonceSlotKey, orderSigner, packSymbol, parseEvents, sameAddress, scalarSlotKey, seedFromMnemonic, seedFromMnemonicBytes, signAssetCall, signPayableCall, signRegister, sign_call, sign_transfer, storageBody, storageValue, submit_body, testnetChainId, testnetChainName, testnetRpcUrl, tokenDecimalsSlot, tokenSymbolSlot, transaction_body, unpackSymbol, valid_address, validityBlocks, vmCallFee, vmDeployAddress
|
|
8
|
+
SigningSession, account_body, address, assetBalanceBody, assetSupplyBody, block_by_height_body, boundedValidUntil, buildSignedOrderCall, buildTypedOrderCall, chainIdFromName, checkGatewayJson, checkOrderExpiry, checkValidUntil, contractAddress, decodeEvent, eventsBody, genesisSecs, headCeiling, localChainId, lookalikeOf, mainnetChainId, mapAddrWordKey, mapSlotKey, mnemonicFromSeed, mnemonicFromSeedText, nameKey, nonceSlotKey, orderLayoutHash, orderSigner, packSymbol, parseEvents, sameAddress, scalarSlotKey, seedFromMnemonic, seedFromMnemonicBytes, signAssetCall, signPayableCall, signRegister, sign_call, sign_transfer, storageBody, storageValue, submit_body, testnetChainId, testnetChainName, testnetRpcUrl, tokenDecimalsSlot, tokenSymbolSlot, transaction_body, unpackSymbol, valid_address, validityBlocks, verifyEvent, verifyFinality, vmCallFee, vmDeployAddress
|
|
9
9
|
} from "./qcore_js_bg.js";
|
package/pkg/qcore_js_bg.js
CHANGED
|
@@ -226,6 +226,7 @@ export function boundedValidUntil(chain_name, head, wall_secs, floor, floor_age_
|
|
|
226
226
|
* @param {bigint} chain_id
|
|
227
227
|
* @param {string} contract
|
|
228
228
|
* @param {string} selector_hex
|
|
229
|
+
* @param {string} layout_hash_hex
|
|
229
230
|
* @param {bigint} scheme_off
|
|
230
231
|
* @param {bigint} ptr_off
|
|
231
232
|
* @param {bigint} expiry_off
|
|
@@ -238,32 +239,34 @@ export function boundedValidUntil(chain_name, head, wall_secs, floor, floor_age_
|
|
|
238
239
|
* @param {bigint} expiry
|
|
239
240
|
* @returns {string}
|
|
240
241
|
*/
|
|
241
|
-
export function buildSignedOrderCall(chain_id, contract, selector_hex, scheme_off, ptr_off, expiry_off, field_offs_csv, fields_csv, region_off, owner_seed_bytes, owner_index, nonce, expiry) {
|
|
242
|
-
let
|
|
243
|
-
let
|
|
242
|
+
export function buildSignedOrderCall(chain_id, contract, selector_hex, layout_hash_hex, scheme_off, ptr_off, expiry_off, field_offs_csv, fields_csv, region_off, owner_seed_bytes, owner_index, nonce, expiry) {
|
|
243
|
+
let deferred8_0;
|
|
244
|
+
let deferred8_1;
|
|
244
245
|
try {
|
|
245
246
|
const ptr0 = passStringToWasm0(contract, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
246
247
|
const len0 = WASM_VECTOR_LEN;
|
|
247
248
|
const ptr1 = passStringToWasm0(selector_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
248
249
|
const len1 = WASM_VECTOR_LEN;
|
|
249
|
-
const ptr2 = passStringToWasm0(
|
|
250
|
+
const ptr2 = passStringToWasm0(layout_hash_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
250
251
|
const len2 = WASM_VECTOR_LEN;
|
|
251
|
-
const ptr3 = passStringToWasm0(
|
|
252
|
+
const ptr3 = passStringToWasm0(field_offs_csv, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
252
253
|
const len3 = WASM_VECTOR_LEN;
|
|
253
|
-
const ptr4 =
|
|
254
|
+
const ptr4 = passStringToWasm0(fields_csv, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
254
255
|
const len4 = WASM_VECTOR_LEN;
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
256
|
+
const ptr5 = passArray8ToWasm0(owner_seed_bytes, wasm.__wbindgen_malloc);
|
|
257
|
+
const len5 = WASM_VECTOR_LEN;
|
|
258
|
+
const ret = wasm.buildSignedOrderCall(chain_id, ptr0, len0, ptr1, len1, ptr2, len2, scheme_off, ptr_off, expiry_off, ptr3, len3, ptr4, len4, region_off, ptr5, len5, owner_index, nonce, expiry);
|
|
259
|
+
var ptr7 = ret[0];
|
|
260
|
+
var len7 = ret[1];
|
|
258
261
|
if (ret[3]) {
|
|
259
|
-
|
|
262
|
+
ptr7 = 0; len7 = 0;
|
|
260
263
|
throw takeFromExternrefTable0(ret[2]);
|
|
261
264
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return getStringFromWasm0(
|
|
265
|
+
deferred8_0 = ptr7;
|
|
266
|
+
deferred8_1 = len7;
|
|
267
|
+
return getStringFromWasm0(ptr7, len7);
|
|
265
268
|
} finally {
|
|
266
|
-
wasm.__wbindgen_free(
|
|
269
|
+
wasm.__wbindgen_free(deferred8_0, deferred8_1, 1);
|
|
267
270
|
}
|
|
268
271
|
}
|
|
269
272
|
|
|
@@ -271,6 +274,7 @@ export function buildSignedOrderCall(chain_id, contract, selector_hex, scheme_of
|
|
|
271
274
|
* @param {bigint} chain_id
|
|
272
275
|
* @param {string} contract
|
|
273
276
|
* @param {string} selector_hex
|
|
277
|
+
* @param {string} layout_hash_hex
|
|
274
278
|
* @param {bigint} scheme_off
|
|
275
279
|
* @param {bigint} ptr_off
|
|
276
280
|
* @param {bigint} expiry_off
|
|
@@ -282,30 +286,32 @@ export function buildSignedOrderCall(chain_id, contract, selector_hex, scheme_of
|
|
|
282
286
|
* @param {bigint} expiry
|
|
283
287
|
* @returns {string}
|
|
284
288
|
*/
|
|
285
|
-
export function buildTypedOrderCall(chain_id, contract, selector_hex, scheme_off, ptr_off, expiry_off, region_off, fields_json, owner_seed_bytes, owner_index, nonce, expiry) {
|
|
286
|
-
let
|
|
287
|
-
let
|
|
289
|
+
export function buildTypedOrderCall(chain_id, contract, selector_hex, layout_hash_hex, scheme_off, ptr_off, expiry_off, region_off, fields_json, owner_seed_bytes, owner_index, nonce, expiry) {
|
|
290
|
+
let deferred7_0;
|
|
291
|
+
let deferred7_1;
|
|
288
292
|
try {
|
|
289
293
|
const ptr0 = passStringToWasm0(contract, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
290
294
|
const len0 = WASM_VECTOR_LEN;
|
|
291
295
|
const ptr1 = passStringToWasm0(selector_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
292
296
|
const len1 = WASM_VECTOR_LEN;
|
|
293
|
-
const ptr2 = passStringToWasm0(
|
|
297
|
+
const ptr2 = passStringToWasm0(layout_hash_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
294
298
|
const len2 = WASM_VECTOR_LEN;
|
|
295
|
-
const ptr3 =
|
|
299
|
+
const ptr3 = passStringToWasm0(fields_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
296
300
|
const len3 = WASM_VECTOR_LEN;
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
301
|
+
const ptr4 = passArray8ToWasm0(owner_seed_bytes, wasm.__wbindgen_malloc);
|
|
302
|
+
const len4 = WASM_VECTOR_LEN;
|
|
303
|
+
const ret = wasm.buildTypedOrderCall(chain_id, ptr0, len0, ptr1, len1, ptr2, len2, scheme_off, ptr_off, expiry_off, region_off, ptr3, len3, ptr4, len4, owner_index, nonce, expiry);
|
|
304
|
+
var ptr6 = ret[0];
|
|
305
|
+
var len6 = ret[1];
|
|
300
306
|
if (ret[3]) {
|
|
301
|
-
|
|
307
|
+
ptr6 = 0; len6 = 0;
|
|
302
308
|
throw takeFromExternrefTable0(ret[2]);
|
|
303
309
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
return getStringFromWasm0(
|
|
310
|
+
deferred7_0 = ptr6;
|
|
311
|
+
deferred7_1 = len6;
|
|
312
|
+
return getStringFromWasm0(ptr6, len6);
|
|
307
313
|
} finally {
|
|
308
|
-
wasm.__wbindgen_free(
|
|
314
|
+
wasm.__wbindgen_free(deferred7_0, deferred7_1, 1);
|
|
309
315
|
}
|
|
310
316
|
}
|
|
311
317
|
|
|
@@ -332,6 +338,17 @@ export function checkGatewayJson(response) {
|
|
|
332
338
|
}
|
|
333
339
|
}
|
|
334
340
|
|
|
341
|
+
/**
|
|
342
|
+
* @param {bigint} expiry
|
|
343
|
+
* @param {bigint} now_secs
|
|
344
|
+
*/
|
|
345
|
+
export function checkOrderExpiry(expiry, now_secs) {
|
|
346
|
+
const ret = wasm.checkOrderExpiry(expiry, now_secs);
|
|
347
|
+
if (ret[1]) {
|
|
348
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
335
352
|
/**
|
|
336
353
|
* @param {bigint} valid_until
|
|
337
354
|
* @param {bigint} head
|
|
@@ -360,6 +377,31 @@ export function contractAddress(deployer, nonce) {
|
|
|
360
377
|
return v2;
|
|
361
378
|
}
|
|
362
379
|
|
|
380
|
+
/**
|
|
381
|
+
* @param {string} leaf_hex
|
|
382
|
+
* @returns {string}
|
|
383
|
+
*/
|
|
384
|
+
export function decodeEvent(leaf_hex) {
|
|
385
|
+
let deferred3_0;
|
|
386
|
+
let deferred3_1;
|
|
387
|
+
try {
|
|
388
|
+
const ptr0 = passStringToWasm0(leaf_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
389
|
+
const len0 = WASM_VECTOR_LEN;
|
|
390
|
+
const ret = wasm.decodeEvent(ptr0, len0);
|
|
391
|
+
var ptr2 = ret[0];
|
|
392
|
+
var len2 = ret[1];
|
|
393
|
+
if (ret[3]) {
|
|
394
|
+
ptr2 = 0; len2 = 0;
|
|
395
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
396
|
+
}
|
|
397
|
+
deferred3_0 = ptr2;
|
|
398
|
+
deferred3_1 = len2;
|
|
399
|
+
return getStringFromWasm0(ptr2, len2);
|
|
400
|
+
} finally {
|
|
401
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
363
405
|
/**
|
|
364
406
|
* @param {bigint} height
|
|
365
407
|
* @returns {string}
|
|
@@ -562,6 +604,34 @@ export function nonceSlotKey(signer_hex) {
|
|
|
562
604
|
}
|
|
563
605
|
}
|
|
564
606
|
|
|
607
|
+
/**
|
|
608
|
+
* @param {string} selector_hex
|
|
609
|
+
* @param {string} fields_json
|
|
610
|
+
* @returns {string}
|
|
611
|
+
*/
|
|
612
|
+
export function orderLayoutHash(selector_hex, fields_json) {
|
|
613
|
+
let deferred4_0;
|
|
614
|
+
let deferred4_1;
|
|
615
|
+
try {
|
|
616
|
+
const ptr0 = passStringToWasm0(selector_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
617
|
+
const len0 = WASM_VECTOR_LEN;
|
|
618
|
+
const ptr1 = passStringToWasm0(fields_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
619
|
+
const len1 = WASM_VECTOR_LEN;
|
|
620
|
+
const ret = wasm.orderLayoutHash(ptr0, len0, ptr1, len1);
|
|
621
|
+
var ptr3 = ret[0];
|
|
622
|
+
var len3 = ret[1];
|
|
623
|
+
if (ret[3]) {
|
|
624
|
+
ptr3 = 0; len3 = 0;
|
|
625
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
626
|
+
}
|
|
627
|
+
deferred4_0 = ptr3;
|
|
628
|
+
deferred4_1 = len3;
|
|
629
|
+
return getStringFromWasm0(ptr3, len3);
|
|
630
|
+
} finally {
|
|
631
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
565
635
|
/**
|
|
566
636
|
* @param {Uint8Array} seed_bytes
|
|
567
637
|
* @param {bigint} index
|
|
@@ -1075,6 +1145,58 @@ export function validityBlocks() {
|
|
|
1075
1145
|
return BigInt.asUintN(64, ret);
|
|
1076
1146
|
}
|
|
1077
1147
|
|
|
1148
|
+
/**
|
|
1149
|
+
* @param {string} event_root_hex
|
|
1150
|
+
* @param {string} leaf_hex
|
|
1151
|
+
* @param {string} steps_json
|
|
1152
|
+
* @returns {boolean}
|
|
1153
|
+
*/
|
|
1154
|
+
export function verifyEvent(event_root_hex, leaf_hex, steps_json) {
|
|
1155
|
+
const ptr0 = passStringToWasm0(event_root_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1156
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1157
|
+
const ptr1 = passStringToWasm0(leaf_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1158
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1159
|
+
const ptr2 = passStringToWasm0(steps_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1160
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1161
|
+
const ret = wasm.verifyEvent(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
1162
|
+
if (ret[2]) {
|
|
1163
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
1164
|
+
}
|
|
1165
|
+
return ret[0] !== 0;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
/**
|
|
1169
|
+
* @param {bigint} chain_id
|
|
1170
|
+
* @param {string} header_hex
|
|
1171
|
+
* @param {string} certificate_hex
|
|
1172
|
+
* @param {string} roster_json
|
|
1173
|
+
* @returns {string}
|
|
1174
|
+
*/
|
|
1175
|
+
export function verifyFinality(chain_id, header_hex, certificate_hex, roster_json) {
|
|
1176
|
+
let deferred5_0;
|
|
1177
|
+
let deferred5_1;
|
|
1178
|
+
try {
|
|
1179
|
+
const ptr0 = passStringToWasm0(header_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1180
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1181
|
+
const ptr1 = passStringToWasm0(certificate_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1182
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1183
|
+
const ptr2 = passStringToWasm0(roster_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1184
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1185
|
+
const ret = wasm.verifyFinality(chain_id, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
1186
|
+
var ptr4 = ret[0];
|
|
1187
|
+
var len4 = ret[1];
|
|
1188
|
+
if (ret[3]) {
|
|
1189
|
+
ptr4 = 0; len4 = 0;
|
|
1190
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1191
|
+
}
|
|
1192
|
+
deferred5_0 = ptr4;
|
|
1193
|
+
deferred5_1 = len4;
|
|
1194
|
+
return getStringFromWasm0(ptr4, len4);
|
|
1195
|
+
} finally {
|
|
1196
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1078
1200
|
/**
|
|
1079
1201
|
* @param {string} transfer_fee
|
|
1080
1202
|
* @param {bigint} meter_limit
|
package/pkg/qcore_js_bg.wasm
CHANGED
|
Binary file
|
|
@@ -8,12 +8,14 @@ export const assetBalanceBody: (a: number, b: number, c: number, d: number) => [
|
|
|
8
8
|
export const assetSupplyBody: (a: number, b: number) => [number, number];
|
|
9
9
|
export const block_by_height_body: (a: bigint) => [number, number];
|
|
10
10
|
export const boundedValidUntil: (a: number, b: number, c: bigint, d: bigint, e: number, f: bigint, g: bigint) => [bigint, number, number];
|
|
11
|
-
export const buildSignedOrderCall: (a: bigint, b: number, c: number, d: number, e: number, f:
|
|
12
|
-
export const buildTypedOrderCall: (a: bigint, b: number, c: number, d: number, e: number, f:
|
|
11
|
+
export const buildSignedOrderCall: (a: bigint, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint, i: bigint, j: bigint, k: number, l: number, m: number, n: number, o: bigint, p: number, q: number, r: bigint, s: bigint, t: bigint) => [number, number, number, number];
|
|
12
|
+
export const buildTypedOrderCall: (a: bigint, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint, i: bigint, j: bigint, k: bigint, l: number, m: number, n: number, o: number, p: bigint, q: bigint, r: bigint) => [number, number, number, number];
|
|
13
13
|
export const chainIdFromName: (a: number, b: number) => bigint;
|
|
14
14
|
export const checkGatewayJson: (a: number, b: number) => [number, number];
|
|
15
|
+
export const checkOrderExpiry: (a: bigint, b: bigint) => [number, number];
|
|
15
16
|
export const checkValidUntil: (a: bigint, b: bigint) => [number, number];
|
|
16
17
|
export const contractAddress: (a: number, b: number, c: bigint) => [number, number];
|
|
18
|
+
export const decodeEvent: (a: number, b: number) => [number, number, number, number];
|
|
17
19
|
export const eventsBody: (a: bigint) => [number, number];
|
|
18
20
|
export const genesisSecs: (a: number, b: number) => bigint;
|
|
19
21
|
export const headCeiling: (a: number, b: number, c: bigint) => bigint;
|
|
@@ -26,6 +28,7 @@ export const mnemonicFromSeed: (a: number, b: number) => [number, number, number
|
|
|
26
28
|
export const mnemonicFromSeedText: (a: number, b: number) => [number, number, number];
|
|
27
29
|
export const nameKey: (a: number, b: number) => [number, number];
|
|
28
30
|
export const nonceSlotKey: (a: number, b: number) => [number, number, number, number];
|
|
31
|
+
export const orderLayoutHash: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
29
32
|
export const orderSigner: (a: number, b: number, c: bigint) => [number, number, number, number];
|
|
30
33
|
export const packSymbol: (a: number, b: number) => bigint;
|
|
31
34
|
export const parseEvents: (a: number, b: number) => [number, number, number, number];
|
|
@@ -58,6 +61,8 @@ export const transaction_body: (a: number, b: number) => [number, number];
|
|
|
58
61
|
export const unpackSymbol: (a: bigint) => [number, number];
|
|
59
62
|
export const valid_address: (a: number, b: number) => number;
|
|
60
63
|
export const validityBlocks: () => bigint;
|
|
64
|
+
export const verifyEvent: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
65
|
+
export const verifyFinality: (a: bigint, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
|
|
61
66
|
export const vmCallFee: (a: number, b: number, c: bigint) => [number, number, number, number];
|
|
62
67
|
export const vmDeployAddress: () => [number, number];
|
|
63
68
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
package/pkg-node/README.md
CHANGED
|
@@ -231,7 +231,9 @@ the fee cap and the amount guard and never the bare signing functions.
|
|
|
231
231
|
The raw builds are still reachable on their own subpaths, `@quantovainc/qcore/pkg` for the bundler build
|
|
232
232
|
and `@quantovainc/qcore/pkg-node` for the nodejs build. Those export only the core.* functions, with no
|
|
233
233
|
Client, no fee cap, and no amount guard, and are for an advanced caller who assembles the fee comparison
|
|
234
|
-
alone.
|
|
234
|
+
alone. A whole number argument above the u64 range wraps modulo 2^64 in a raw build, so such a caller
|
|
235
|
+
must range check every amount, fee, nonce, and expiry before the call. The default browser, import,
|
|
236
|
+
node, and require resolutions never reach them.
|
|
235
237
|
|
|
236
238
|
To build both from source, run `npm run build`, which produces the bundler build in `pkg` and the node
|
|
237
239
|
build in `pkg-node`.
|
package/pkg-node/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qcore-js",
|
|
3
3
|
"description": "The JavaScript binding for the Quantova client core, generated over QCore with wasm-bindgen. The core does the key derivation, the post quantum signing, and the wire, the page does the fetch.",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.3",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
package/pkg-node/qcore_js.d.ts
CHANGED
|
@@ -26,18 +26,22 @@ export function block_by_height_body(height: bigint): string;
|
|
|
26
26
|
|
|
27
27
|
export function boundedValidUntil(chain_name: string, head: bigint, wall_secs: bigint, floor: bigint | null | undefined, floor_age_secs: bigint): bigint;
|
|
28
28
|
|
|
29
|
-
export function buildSignedOrderCall(chain_id: bigint, contract: string, selector_hex: string, scheme_off: bigint, ptr_off: bigint, expiry_off: bigint, field_offs_csv: string, fields_csv: string, region_off: bigint, owner_seed_bytes: Uint8Array, owner_index: bigint, nonce: bigint, expiry: bigint): string;
|
|
29
|
+
export function buildSignedOrderCall(chain_id: bigint, contract: string, selector_hex: string, layout_hash_hex: string, scheme_off: bigint, ptr_off: bigint, expiry_off: bigint, field_offs_csv: string, fields_csv: string, region_off: bigint, owner_seed_bytes: Uint8Array, owner_index: bigint, nonce: bigint, expiry: bigint): string;
|
|
30
30
|
|
|
31
|
-
export function buildTypedOrderCall(chain_id: bigint, contract: string, selector_hex: string, scheme_off: bigint, ptr_off: bigint, expiry_off: bigint, region_off: bigint, fields_json: string, owner_seed_bytes: Uint8Array, owner_index: bigint, nonce: bigint, expiry: bigint): string;
|
|
31
|
+
export function buildTypedOrderCall(chain_id: bigint, contract: string, selector_hex: string, layout_hash_hex: string, scheme_off: bigint, ptr_off: bigint, expiry_off: bigint, region_off: bigint, fields_json: string, owner_seed_bytes: Uint8Array, owner_index: bigint, nonce: bigint, expiry: bigint): string;
|
|
32
32
|
|
|
33
33
|
export function chainIdFromName(name: string): bigint;
|
|
34
34
|
|
|
35
35
|
export function checkGatewayJson(response: string): void;
|
|
36
36
|
|
|
37
|
+
export function checkOrderExpiry(expiry: bigint, now_secs: bigint): void;
|
|
38
|
+
|
|
37
39
|
export function checkValidUntil(valid_until: bigint, head: bigint): void;
|
|
38
40
|
|
|
39
41
|
export function contractAddress(deployer: string, nonce: bigint): string | undefined;
|
|
40
42
|
|
|
43
|
+
export function decodeEvent(leaf_hex: string): string;
|
|
44
|
+
|
|
41
45
|
export function eventsBody(height: bigint): string;
|
|
42
46
|
|
|
43
47
|
export function genesisSecs(chain_name: string): bigint;
|
|
@@ -62,6 +66,8 @@ export function nameKey(label: string): string;
|
|
|
62
66
|
|
|
63
67
|
export function nonceSlotKey(signer_hex: string): string;
|
|
64
68
|
|
|
69
|
+
export function orderLayoutHash(selector_hex: string, fields_json: string): string;
|
|
70
|
+
|
|
65
71
|
export function orderSigner(seed_bytes: Uint8Array, index: bigint): string;
|
|
66
72
|
|
|
67
73
|
export function packSymbol(symbol: string): bigint;
|
|
@@ -110,6 +116,10 @@ export function valid_address(address: string): boolean;
|
|
|
110
116
|
|
|
111
117
|
export function validityBlocks(): bigint;
|
|
112
118
|
|
|
119
|
+
export function verifyEvent(event_root_hex: string, leaf_hex: string, steps_json: string): boolean;
|
|
120
|
+
|
|
121
|
+
export function verifyFinality(chain_id: bigint, header_hex: string, certificate_hex: string, roster_json: string): string;
|
|
122
|
+
|
|
113
123
|
export function vmCallFee(transfer_fee: string, meter_limit: bigint): string;
|
|
114
124
|
|
|
115
125
|
export function vmDeployAddress(): string;
|
package/pkg-node/qcore_js.js
CHANGED
|
@@ -235,6 +235,7 @@ exports.boundedValidUntil = boundedValidUntil;
|
|
|
235
235
|
* @param {bigint} chain_id
|
|
236
236
|
* @param {string} contract
|
|
237
237
|
* @param {string} selector_hex
|
|
238
|
+
* @param {string} layout_hash_hex
|
|
238
239
|
* @param {bigint} scheme_off
|
|
239
240
|
* @param {bigint} ptr_off
|
|
240
241
|
* @param {bigint} expiry_off
|
|
@@ -247,32 +248,34 @@ exports.boundedValidUntil = boundedValidUntil;
|
|
|
247
248
|
* @param {bigint} expiry
|
|
248
249
|
* @returns {string}
|
|
249
250
|
*/
|
|
250
|
-
function buildSignedOrderCall(chain_id, contract, selector_hex, scheme_off, ptr_off, expiry_off, field_offs_csv, fields_csv, region_off, owner_seed_bytes, owner_index, nonce, expiry) {
|
|
251
|
-
let
|
|
252
|
-
let
|
|
251
|
+
function buildSignedOrderCall(chain_id, contract, selector_hex, layout_hash_hex, scheme_off, ptr_off, expiry_off, field_offs_csv, fields_csv, region_off, owner_seed_bytes, owner_index, nonce, expiry) {
|
|
252
|
+
let deferred8_0;
|
|
253
|
+
let deferred8_1;
|
|
253
254
|
try {
|
|
254
255
|
const ptr0 = passStringToWasm0(contract, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
255
256
|
const len0 = WASM_VECTOR_LEN;
|
|
256
257
|
const ptr1 = passStringToWasm0(selector_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
257
258
|
const len1 = WASM_VECTOR_LEN;
|
|
258
|
-
const ptr2 = passStringToWasm0(
|
|
259
|
+
const ptr2 = passStringToWasm0(layout_hash_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
259
260
|
const len2 = WASM_VECTOR_LEN;
|
|
260
|
-
const ptr3 = passStringToWasm0(
|
|
261
|
+
const ptr3 = passStringToWasm0(field_offs_csv, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
261
262
|
const len3 = WASM_VECTOR_LEN;
|
|
262
|
-
const ptr4 =
|
|
263
|
+
const ptr4 = passStringToWasm0(fields_csv, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
263
264
|
const len4 = WASM_VECTOR_LEN;
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
const ptr5 = passArray8ToWasm0(owner_seed_bytes, wasm.__wbindgen_malloc);
|
|
266
|
+
const len5 = WASM_VECTOR_LEN;
|
|
267
|
+
const ret = wasm.buildSignedOrderCall(chain_id, ptr0, len0, ptr1, len1, ptr2, len2, scheme_off, ptr_off, expiry_off, ptr3, len3, ptr4, len4, region_off, ptr5, len5, owner_index, nonce, expiry);
|
|
268
|
+
var ptr7 = ret[0];
|
|
269
|
+
var len7 = ret[1];
|
|
267
270
|
if (ret[3]) {
|
|
268
|
-
|
|
271
|
+
ptr7 = 0; len7 = 0;
|
|
269
272
|
throw takeFromExternrefTable0(ret[2]);
|
|
270
273
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
return getStringFromWasm0(
|
|
274
|
+
deferred8_0 = ptr7;
|
|
275
|
+
deferred8_1 = len7;
|
|
276
|
+
return getStringFromWasm0(ptr7, len7);
|
|
274
277
|
} finally {
|
|
275
|
-
wasm.__wbindgen_free(
|
|
278
|
+
wasm.__wbindgen_free(deferred8_0, deferred8_1, 1);
|
|
276
279
|
}
|
|
277
280
|
}
|
|
278
281
|
exports.buildSignedOrderCall = buildSignedOrderCall;
|
|
@@ -281,6 +284,7 @@ exports.buildSignedOrderCall = buildSignedOrderCall;
|
|
|
281
284
|
* @param {bigint} chain_id
|
|
282
285
|
* @param {string} contract
|
|
283
286
|
* @param {string} selector_hex
|
|
287
|
+
* @param {string} layout_hash_hex
|
|
284
288
|
* @param {bigint} scheme_off
|
|
285
289
|
* @param {bigint} ptr_off
|
|
286
290
|
* @param {bigint} expiry_off
|
|
@@ -292,30 +296,32 @@ exports.buildSignedOrderCall = buildSignedOrderCall;
|
|
|
292
296
|
* @param {bigint} expiry
|
|
293
297
|
* @returns {string}
|
|
294
298
|
*/
|
|
295
|
-
function buildTypedOrderCall(chain_id, contract, selector_hex, scheme_off, ptr_off, expiry_off, region_off, fields_json, owner_seed_bytes, owner_index, nonce, expiry) {
|
|
296
|
-
let
|
|
297
|
-
let
|
|
299
|
+
function buildTypedOrderCall(chain_id, contract, selector_hex, layout_hash_hex, scheme_off, ptr_off, expiry_off, region_off, fields_json, owner_seed_bytes, owner_index, nonce, expiry) {
|
|
300
|
+
let deferred7_0;
|
|
301
|
+
let deferred7_1;
|
|
298
302
|
try {
|
|
299
303
|
const ptr0 = passStringToWasm0(contract, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
300
304
|
const len0 = WASM_VECTOR_LEN;
|
|
301
305
|
const ptr1 = passStringToWasm0(selector_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
302
306
|
const len1 = WASM_VECTOR_LEN;
|
|
303
|
-
const ptr2 = passStringToWasm0(
|
|
307
|
+
const ptr2 = passStringToWasm0(layout_hash_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
304
308
|
const len2 = WASM_VECTOR_LEN;
|
|
305
|
-
const ptr3 =
|
|
309
|
+
const ptr3 = passStringToWasm0(fields_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
306
310
|
const len3 = WASM_VECTOR_LEN;
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
311
|
+
const ptr4 = passArray8ToWasm0(owner_seed_bytes, wasm.__wbindgen_malloc);
|
|
312
|
+
const len4 = WASM_VECTOR_LEN;
|
|
313
|
+
const ret = wasm.buildTypedOrderCall(chain_id, ptr0, len0, ptr1, len1, ptr2, len2, scheme_off, ptr_off, expiry_off, region_off, ptr3, len3, ptr4, len4, owner_index, nonce, expiry);
|
|
314
|
+
var ptr6 = ret[0];
|
|
315
|
+
var len6 = ret[1];
|
|
310
316
|
if (ret[3]) {
|
|
311
|
-
|
|
317
|
+
ptr6 = 0; len6 = 0;
|
|
312
318
|
throw takeFromExternrefTable0(ret[2]);
|
|
313
319
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
return getStringFromWasm0(
|
|
320
|
+
deferred7_0 = ptr6;
|
|
321
|
+
deferred7_1 = len6;
|
|
322
|
+
return getStringFromWasm0(ptr6, len6);
|
|
317
323
|
} finally {
|
|
318
|
-
wasm.__wbindgen_free(
|
|
324
|
+
wasm.__wbindgen_free(deferred7_0, deferred7_1, 1);
|
|
319
325
|
}
|
|
320
326
|
}
|
|
321
327
|
exports.buildTypedOrderCall = buildTypedOrderCall;
|
|
@@ -345,6 +351,18 @@ function checkGatewayJson(response) {
|
|
|
345
351
|
}
|
|
346
352
|
exports.checkGatewayJson = checkGatewayJson;
|
|
347
353
|
|
|
354
|
+
/**
|
|
355
|
+
* @param {bigint} expiry
|
|
356
|
+
* @param {bigint} now_secs
|
|
357
|
+
*/
|
|
358
|
+
function checkOrderExpiry(expiry, now_secs) {
|
|
359
|
+
const ret = wasm.checkOrderExpiry(expiry, now_secs);
|
|
360
|
+
if (ret[1]) {
|
|
361
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
exports.checkOrderExpiry = checkOrderExpiry;
|
|
365
|
+
|
|
348
366
|
/**
|
|
349
367
|
* @param {bigint} valid_until
|
|
350
368
|
* @param {bigint} head
|
|
@@ -375,6 +393,32 @@ function contractAddress(deployer, nonce) {
|
|
|
375
393
|
}
|
|
376
394
|
exports.contractAddress = contractAddress;
|
|
377
395
|
|
|
396
|
+
/**
|
|
397
|
+
* @param {string} leaf_hex
|
|
398
|
+
* @returns {string}
|
|
399
|
+
*/
|
|
400
|
+
function decodeEvent(leaf_hex) {
|
|
401
|
+
let deferred3_0;
|
|
402
|
+
let deferred3_1;
|
|
403
|
+
try {
|
|
404
|
+
const ptr0 = passStringToWasm0(leaf_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
405
|
+
const len0 = WASM_VECTOR_LEN;
|
|
406
|
+
const ret = wasm.decodeEvent(ptr0, len0);
|
|
407
|
+
var ptr2 = ret[0];
|
|
408
|
+
var len2 = ret[1];
|
|
409
|
+
if (ret[3]) {
|
|
410
|
+
ptr2 = 0; len2 = 0;
|
|
411
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
412
|
+
}
|
|
413
|
+
deferred3_0 = ptr2;
|
|
414
|
+
deferred3_1 = len2;
|
|
415
|
+
return getStringFromWasm0(ptr2, len2);
|
|
416
|
+
} finally {
|
|
417
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
exports.decodeEvent = decodeEvent;
|
|
421
|
+
|
|
378
422
|
/**
|
|
379
423
|
* @param {bigint} height
|
|
380
424
|
* @returns {string}
|
|
@@ -589,6 +633,35 @@ function nonceSlotKey(signer_hex) {
|
|
|
589
633
|
}
|
|
590
634
|
exports.nonceSlotKey = nonceSlotKey;
|
|
591
635
|
|
|
636
|
+
/**
|
|
637
|
+
* @param {string} selector_hex
|
|
638
|
+
* @param {string} fields_json
|
|
639
|
+
* @returns {string}
|
|
640
|
+
*/
|
|
641
|
+
function orderLayoutHash(selector_hex, fields_json) {
|
|
642
|
+
let deferred4_0;
|
|
643
|
+
let deferred4_1;
|
|
644
|
+
try {
|
|
645
|
+
const ptr0 = passStringToWasm0(selector_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
646
|
+
const len0 = WASM_VECTOR_LEN;
|
|
647
|
+
const ptr1 = passStringToWasm0(fields_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
648
|
+
const len1 = WASM_VECTOR_LEN;
|
|
649
|
+
const ret = wasm.orderLayoutHash(ptr0, len0, ptr1, len1);
|
|
650
|
+
var ptr3 = ret[0];
|
|
651
|
+
var len3 = ret[1];
|
|
652
|
+
if (ret[3]) {
|
|
653
|
+
ptr3 = 0; len3 = 0;
|
|
654
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
655
|
+
}
|
|
656
|
+
deferred4_0 = ptr3;
|
|
657
|
+
deferred4_1 = len3;
|
|
658
|
+
return getStringFromWasm0(ptr3, len3);
|
|
659
|
+
} finally {
|
|
660
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
exports.orderLayoutHash = orderLayoutHash;
|
|
664
|
+
|
|
592
665
|
/**
|
|
593
666
|
* @param {Uint8Array} seed_bytes
|
|
594
667
|
* @param {bigint} index
|
|
@@ -1126,6 +1199,60 @@ function validityBlocks() {
|
|
|
1126
1199
|
}
|
|
1127
1200
|
exports.validityBlocks = validityBlocks;
|
|
1128
1201
|
|
|
1202
|
+
/**
|
|
1203
|
+
* @param {string} event_root_hex
|
|
1204
|
+
* @param {string} leaf_hex
|
|
1205
|
+
* @param {string} steps_json
|
|
1206
|
+
* @returns {boolean}
|
|
1207
|
+
*/
|
|
1208
|
+
function verifyEvent(event_root_hex, leaf_hex, steps_json) {
|
|
1209
|
+
const ptr0 = passStringToWasm0(event_root_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1210
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1211
|
+
const ptr1 = passStringToWasm0(leaf_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1212
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1213
|
+
const ptr2 = passStringToWasm0(steps_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1214
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1215
|
+
const ret = wasm.verifyEvent(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
1216
|
+
if (ret[2]) {
|
|
1217
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
1218
|
+
}
|
|
1219
|
+
return ret[0] !== 0;
|
|
1220
|
+
}
|
|
1221
|
+
exports.verifyEvent = verifyEvent;
|
|
1222
|
+
|
|
1223
|
+
/**
|
|
1224
|
+
* @param {bigint} chain_id
|
|
1225
|
+
* @param {string} header_hex
|
|
1226
|
+
* @param {string} certificate_hex
|
|
1227
|
+
* @param {string} roster_json
|
|
1228
|
+
* @returns {string}
|
|
1229
|
+
*/
|
|
1230
|
+
function verifyFinality(chain_id, header_hex, certificate_hex, roster_json) {
|
|
1231
|
+
let deferred5_0;
|
|
1232
|
+
let deferred5_1;
|
|
1233
|
+
try {
|
|
1234
|
+
const ptr0 = passStringToWasm0(header_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1235
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1236
|
+
const ptr1 = passStringToWasm0(certificate_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1237
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1238
|
+
const ptr2 = passStringToWasm0(roster_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1239
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1240
|
+
const ret = wasm.verifyFinality(chain_id, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
1241
|
+
var ptr4 = ret[0];
|
|
1242
|
+
var len4 = ret[1];
|
|
1243
|
+
if (ret[3]) {
|
|
1244
|
+
ptr4 = 0; len4 = 0;
|
|
1245
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1246
|
+
}
|
|
1247
|
+
deferred5_0 = ptr4;
|
|
1248
|
+
deferred5_1 = len4;
|
|
1249
|
+
return getStringFromWasm0(ptr4, len4);
|
|
1250
|
+
} finally {
|
|
1251
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
exports.verifyFinality = verifyFinality;
|
|
1255
|
+
|
|
1129
1256
|
/**
|
|
1130
1257
|
* @param {string} transfer_fee
|
|
1131
1258
|
* @param {bigint} meter_limit
|
|
Binary file
|
package/shared.js
CHANGED
|
@@ -96,8 +96,13 @@ const CORE_ARGS = {
|
|
|
96
96
|
sign_call: [['seed', 'seed'], ['u64', 'account index'], ['text', 'target'], ['text', 'call arguments'], ['u64', 'nonce'], ['u64', 'meter limit'], ['u128s', 'fee'], ['u64', 'chain id'], ['u64', 'validity deadline'], ['u128s', 'transfer fee']],
|
|
97
97
|
signPayableCall: [['seed', 'seed'], ['u64', 'account index'], ['text', 'target'], ['text', 'call arguments'], ['u64', 'nonce'], ['u64', 'meter limit'], ['u128s', 'fee'], ['u64s', 'value'], ['u64', 'chain id'], ['u64', 'validity deadline'], ['u128s', 'transfer fee']],
|
|
98
98
|
signAssetCall: [['seed', 'seed'], ['u64', 'account index'], ['text', 'target'], ['text', 'call arguments'], ['text', 'asset issuer'], ['u64s', 'amount'], ['u64', 'nonce'], ['u64', 'meter limit'], ['u128s', 'fee'], ['u64', 'chain id'], ['u64', 'validity deadline'], ['u128s', 'transfer fee']],
|
|
99
|
-
buildSignedOrderCall: [['u64', 'chain id'], ['text', 'contract'], ['text', 'selector'], ['u64', 'scheme offset'], ['u64', 'pointer offset'], ['u64', 'expiry offset'], ['text', 'field offsets'], ['text', 'fields'], ['u64', 'region offset'], ['seed', 'owner seed'], ['u64', 'owner index'], ['u64', 'order nonce'], ['u64', 'order expiry']],
|
|
100
|
-
buildTypedOrderCall: [['u64', 'chain id'], ['text', 'contract'], ['text', 'selector'], ['u64', 'scheme offset'], ['u64', 'pointer offset'], ['u64', 'expiry offset'], ['u64', 'region offset'], ['text', 'fields'], ['seed', 'owner seed'], ['u64', 'owner index'], ['u64', 'order nonce'], ['u64', 'order expiry']],
|
|
99
|
+
buildSignedOrderCall: [['u64', 'chain id'], ['text', 'contract'], ['text', 'selector'], ['text', 'layout hash'], ['u64', 'scheme offset'], ['u64', 'pointer offset'], ['u64', 'expiry offset'], ['text', 'field offsets'], ['text', 'fields'], ['u64', 'region offset'], ['seed', 'owner seed'], ['u64', 'owner index'], ['u64', 'order nonce'], ['u64', 'order expiry']],
|
|
100
|
+
buildTypedOrderCall: [['u64', 'chain id'], ['text', 'contract'], ['text', 'selector'], ['text', 'layout hash'], ['u64', 'scheme offset'], ['u64', 'pointer offset'], ['u64', 'expiry offset'], ['u64', 'region offset'], ['text', 'fields'], ['seed', 'owner seed'], ['u64', 'owner index'], ['u64', 'order nonce'], ['u64', 'order expiry']],
|
|
101
|
+
orderLayoutHash: [['text', 'selector'], ['text', 'order layout']],
|
|
102
|
+
checkOrderExpiry: [['u64', 'order expiry'], ['u64', 'wall clock seconds']],
|
|
103
|
+
verifyFinality: [['u64', 'chain id'], ['text', 'header'], ['text', 'certificate'], ['text', 'validator roster']],
|
|
104
|
+
verifyEvent: [['text', 'event root'], ['text', 'event leaf'], ['text', 'proof steps']],
|
|
105
|
+
decodeEvent: [['text', 'event leaf']],
|
|
101
106
|
contractAddress: [['text', 'deployer'], ['u64', 'nonce']],
|
|
102
107
|
scalarSlotKey: [['u64', 'slot']],
|
|
103
108
|
mapSlotKey: [['u64', 'map domain tag'], ['text', 'key address']],
|
|
@@ -337,6 +342,37 @@ function makeClient(core) {
|
|
|
337
342
|
this._session = new core.SigningSession(book);
|
|
338
343
|
this._pinnedChainName = null;
|
|
339
344
|
this._headFloor = null;
|
|
345
|
+
this._locks = new Map();
|
|
346
|
+
for (const name of ['transfer', 'register', 'call', 'assetCall', 'payableCall']) {
|
|
347
|
+
const inner = this[name].bind(this);
|
|
348
|
+
this[name] = (seed, index, ...rest) => {
|
|
349
|
+
let key;
|
|
350
|
+
try { key = core.address(seed, index); } catch (e) { return inner(seed, index, ...rest); }
|
|
351
|
+
return this._exclusive([key], () => inner(seed, index, ...rest));
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
const order = this.callSignedOrder.bind(this);
|
|
355
|
+
this.callSignedOrder = (callerSeed, callerIndex, contract, selectorHex, orderSpec, ownerSeed, ownerIndex, ...rest) => {
|
|
356
|
+
const run = () => order(callerSeed, callerIndex, contract, selectorHex, orderSpec, ownerSeed, ownerIndex, ...rest);
|
|
357
|
+
let keys;
|
|
358
|
+
try {
|
|
359
|
+
keys = [core.address(callerSeed, callerIndex), String(contract) + '/' + core.orderSigner(ownerSeed, ownerIndex)];
|
|
360
|
+
} catch (e) {
|
|
361
|
+
return run();
|
|
362
|
+
}
|
|
363
|
+
return this._exclusive(keys, run);
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
_exclusive(keys, fn) {
|
|
368
|
+
const prior = keys.map((key) => this._locks.get(key) || Promise.resolve());
|
|
369
|
+
let release;
|
|
370
|
+
const gate = new Promise((resolve) => { release = resolve; });
|
|
371
|
+
for (const key of keys) this._locks.set(key, gate);
|
|
372
|
+
return Promise.all(prior).then(fn).finally(() => {
|
|
373
|
+
release();
|
|
374
|
+
for (const key of keys) if (this._locks.get(key) === gate) this._locks.delete(key);
|
|
375
|
+
});
|
|
340
376
|
}
|
|
341
377
|
|
|
342
378
|
_guardMainnet() {
|
|
@@ -383,7 +419,7 @@ function makeClient(core) {
|
|
|
383
419
|
redirect: 'error',
|
|
384
420
|
});
|
|
385
421
|
const text = await readBounded(res);
|
|
386
|
-
if (
|
|
422
|
+
if (res.status === 200) core.checkGatewayJson(text);
|
|
387
423
|
let data;
|
|
388
424
|
try { data = JSON.parse(text); } catch { throw new Error('the node returned a non JSON response'); }
|
|
389
425
|
if (res.status !== 200) {
|
|
@@ -574,6 +610,10 @@ function makeClient(core) {
|
|
|
574
610
|
|
|
575
611
|
async _slotValue(contract, key) {
|
|
576
612
|
const resp = await this._call('get_storage_at', JSON.stringify({ address: contract, keys: [key] }), true);
|
|
613
|
+
const slots = resp && Array.isArray(resp.slots) ? resp.slots : [];
|
|
614
|
+
if (!slots.some((s) => s && typeof s.slot === 'string' && s.slot.toLowerCase() === String(key).toLowerCase())) {
|
|
615
|
+
throw new Error('the gateway did not report the requested storage slot');
|
|
616
|
+
}
|
|
577
617
|
return BigInt(core.storageValue(JSON.stringify(resp), key));
|
|
578
618
|
}
|
|
579
619
|
|
|
@@ -611,10 +651,15 @@ function makeClient(core) {
|
|
|
611
651
|
const orderKey = contract + '/' + signer;
|
|
612
652
|
const reportedOrder = await this.contractNonce(contract, signer);
|
|
613
653
|
const nonce = BigInt(this._session.slot(orderKey, reportedOrder, this._expected(expectedOrderNonce, 'expected order nonce'), true));
|
|
654
|
+
if (typeof orderSpec.layoutHash !== 'string') throw new Error('the order spec needs the layout hash the compiler emits for this entry');
|
|
655
|
+
const orderExpiry = wholeNumber(orderSpec.expiry, 'order expiry', U64_MAX);
|
|
656
|
+
const nowSecs = BigInt(Math.floor(Date.now() / 1000));
|
|
657
|
+
core.checkOrderExpiry(orderExpiry, nowSecs);
|
|
614
658
|
const order = JSON.parse(core.buildTypedOrderCall(
|
|
615
659
|
chainId,
|
|
616
660
|
contract,
|
|
617
661
|
selectorHex,
|
|
662
|
+
orderSpec.layoutHash,
|
|
618
663
|
wholeNumber(orderSpec.schemeOff, 'scheme offset', U64_MAX),
|
|
619
664
|
wholeNumber(orderSpec.ptrOff, 'pointer offset', U64_MAX),
|
|
620
665
|
wholeNumber(orderSpec.expiryOff, 'expiry offset', U64_MAX),
|
package/shared.mjs
CHANGED
|
@@ -96,8 +96,13 @@ const CORE_ARGS = {
|
|
|
96
96
|
sign_call: [['seed', 'seed'], ['u64', 'account index'], ['text', 'target'], ['text', 'call arguments'], ['u64', 'nonce'], ['u64', 'meter limit'], ['u128s', 'fee'], ['u64', 'chain id'], ['u64', 'validity deadline'], ['u128s', 'transfer fee']],
|
|
97
97
|
signPayableCall: [['seed', 'seed'], ['u64', 'account index'], ['text', 'target'], ['text', 'call arguments'], ['u64', 'nonce'], ['u64', 'meter limit'], ['u128s', 'fee'], ['u64s', 'value'], ['u64', 'chain id'], ['u64', 'validity deadline'], ['u128s', 'transfer fee']],
|
|
98
98
|
signAssetCall: [['seed', 'seed'], ['u64', 'account index'], ['text', 'target'], ['text', 'call arguments'], ['text', 'asset issuer'], ['u64s', 'amount'], ['u64', 'nonce'], ['u64', 'meter limit'], ['u128s', 'fee'], ['u64', 'chain id'], ['u64', 'validity deadline'], ['u128s', 'transfer fee']],
|
|
99
|
-
buildSignedOrderCall: [['u64', 'chain id'], ['text', 'contract'], ['text', 'selector'], ['u64', 'scheme offset'], ['u64', 'pointer offset'], ['u64', 'expiry offset'], ['text', 'field offsets'], ['text', 'fields'], ['u64', 'region offset'], ['seed', 'owner seed'], ['u64', 'owner index'], ['u64', 'order nonce'], ['u64', 'order expiry']],
|
|
100
|
-
buildTypedOrderCall: [['u64', 'chain id'], ['text', 'contract'], ['text', 'selector'], ['u64', 'scheme offset'], ['u64', 'pointer offset'], ['u64', 'expiry offset'], ['u64', 'region offset'], ['text', 'fields'], ['seed', 'owner seed'], ['u64', 'owner index'], ['u64', 'order nonce'], ['u64', 'order expiry']],
|
|
99
|
+
buildSignedOrderCall: [['u64', 'chain id'], ['text', 'contract'], ['text', 'selector'], ['text', 'layout hash'], ['u64', 'scheme offset'], ['u64', 'pointer offset'], ['u64', 'expiry offset'], ['text', 'field offsets'], ['text', 'fields'], ['u64', 'region offset'], ['seed', 'owner seed'], ['u64', 'owner index'], ['u64', 'order nonce'], ['u64', 'order expiry']],
|
|
100
|
+
buildTypedOrderCall: [['u64', 'chain id'], ['text', 'contract'], ['text', 'selector'], ['text', 'layout hash'], ['u64', 'scheme offset'], ['u64', 'pointer offset'], ['u64', 'expiry offset'], ['u64', 'region offset'], ['text', 'fields'], ['seed', 'owner seed'], ['u64', 'owner index'], ['u64', 'order nonce'], ['u64', 'order expiry']],
|
|
101
|
+
orderLayoutHash: [['text', 'selector'], ['text', 'order layout']],
|
|
102
|
+
checkOrderExpiry: [['u64', 'order expiry'], ['u64', 'wall clock seconds']],
|
|
103
|
+
verifyFinality: [['u64', 'chain id'], ['text', 'header'], ['text', 'certificate'], ['text', 'validator roster']],
|
|
104
|
+
verifyEvent: [['text', 'event root'], ['text', 'event leaf'], ['text', 'proof steps']],
|
|
105
|
+
decodeEvent: [['text', 'event leaf']],
|
|
101
106
|
contractAddress: [['text', 'deployer'], ['u64', 'nonce']],
|
|
102
107
|
scalarSlotKey: [['u64', 'slot']],
|
|
103
108
|
mapSlotKey: [['u64', 'map domain tag'], ['text', 'key address']],
|
|
@@ -337,6 +342,37 @@ function makeClient(core) {
|
|
|
337
342
|
this._session = new core.SigningSession(book);
|
|
338
343
|
this._pinnedChainName = null;
|
|
339
344
|
this._headFloor = null;
|
|
345
|
+
this._locks = new Map();
|
|
346
|
+
for (const name of ['transfer', 'register', 'call', 'assetCall', 'payableCall']) {
|
|
347
|
+
const inner = this[name].bind(this);
|
|
348
|
+
this[name] = (seed, index, ...rest) => {
|
|
349
|
+
let key;
|
|
350
|
+
try { key = core.address(seed, index); } catch (e) { return inner(seed, index, ...rest); }
|
|
351
|
+
return this._exclusive([key], () => inner(seed, index, ...rest));
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
const order = this.callSignedOrder.bind(this);
|
|
355
|
+
this.callSignedOrder = (callerSeed, callerIndex, contract, selectorHex, orderSpec, ownerSeed, ownerIndex, ...rest) => {
|
|
356
|
+
const run = () => order(callerSeed, callerIndex, contract, selectorHex, orderSpec, ownerSeed, ownerIndex, ...rest);
|
|
357
|
+
let keys;
|
|
358
|
+
try {
|
|
359
|
+
keys = [core.address(callerSeed, callerIndex), String(contract) + '/' + core.orderSigner(ownerSeed, ownerIndex)];
|
|
360
|
+
} catch (e) {
|
|
361
|
+
return run();
|
|
362
|
+
}
|
|
363
|
+
return this._exclusive(keys, run);
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
_exclusive(keys, fn) {
|
|
368
|
+
const prior = keys.map((key) => this._locks.get(key) || Promise.resolve());
|
|
369
|
+
let release;
|
|
370
|
+
const gate = new Promise((resolve) => { release = resolve; });
|
|
371
|
+
for (const key of keys) this._locks.set(key, gate);
|
|
372
|
+
return Promise.all(prior).then(fn).finally(() => {
|
|
373
|
+
release();
|
|
374
|
+
for (const key of keys) if (this._locks.get(key) === gate) this._locks.delete(key);
|
|
375
|
+
});
|
|
340
376
|
}
|
|
341
377
|
|
|
342
378
|
_guardMainnet() {
|
|
@@ -383,7 +419,7 @@ function makeClient(core) {
|
|
|
383
419
|
redirect: 'error',
|
|
384
420
|
});
|
|
385
421
|
const text = await readBounded(res);
|
|
386
|
-
if (
|
|
422
|
+
if (res.status === 200) core.checkGatewayJson(text);
|
|
387
423
|
let data;
|
|
388
424
|
try { data = JSON.parse(text); } catch { throw new Error('the node returned a non JSON response'); }
|
|
389
425
|
if (res.status !== 200) {
|
|
@@ -574,6 +610,10 @@ function makeClient(core) {
|
|
|
574
610
|
|
|
575
611
|
async _slotValue(contract, key) {
|
|
576
612
|
const resp = await this._call('get_storage_at', JSON.stringify({ address: contract, keys: [key] }), true);
|
|
613
|
+
const slots = resp && Array.isArray(resp.slots) ? resp.slots : [];
|
|
614
|
+
if (!slots.some((s) => s && typeof s.slot === 'string' && s.slot.toLowerCase() === String(key).toLowerCase())) {
|
|
615
|
+
throw new Error('the gateway did not report the requested storage slot');
|
|
616
|
+
}
|
|
577
617
|
return BigInt(core.storageValue(JSON.stringify(resp), key));
|
|
578
618
|
}
|
|
579
619
|
|
|
@@ -611,10 +651,15 @@ function makeClient(core) {
|
|
|
611
651
|
const orderKey = contract + '/' + signer;
|
|
612
652
|
const reportedOrder = await this.contractNonce(contract, signer);
|
|
613
653
|
const nonce = BigInt(this._session.slot(orderKey, reportedOrder, this._expected(expectedOrderNonce, 'expected order nonce'), true));
|
|
654
|
+
if (typeof orderSpec.layoutHash !== 'string') throw new Error('the order spec needs the layout hash the compiler emits for this entry');
|
|
655
|
+
const orderExpiry = wholeNumber(orderSpec.expiry, 'order expiry', U64_MAX);
|
|
656
|
+
const nowSecs = BigInt(Math.floor(Date.now() / 1000));
|
|
657
|
+
core.checkOrderExpiry(orderExpiry, nowSecs);
|
|
614
658
|
const order = JSON.parse(core.buildTypedOrderCall(
|
|
615
659
|
chainId,
|
|
616
660
|
contract,
|
|
617
661
|
selectorHex,
|
|
662
|
+
orderSpec.layoutHash,
|
|
618
663
|
wholeNumber(orderSpec.schemeOff, 'scheme offset', U64_MAX),
|
|
619
664
|
wholeNumber(orderSpec.ptrOff, 'pointer offset', U64_MAX),
|
|
620
665
|
wholeNumber(orderSpec.expiryOff, 'expiry offset', U64_MAX),
|