@quantovainc/qcore 0.1.18 → 0.1.20
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/package.json +1 -1
- package/shared.js +24 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quantovainc/qcore",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "Quantova's post quantum client core for JavaScript. Signs with ML-DSA-65 and builds Q1 addresses.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "RUSTFLAGS=\"--remap-path-prefix=$HOME/quantova-stack=/qcore --remap-path-prefix=$HOME/.cargo=/cargo --remap-path-prefix=$HOME/.rustup=/rustup\" wasm-pack build --target bundler --out-dir pkg && RUSTFLAGS=\"--remap-path-prefix=$HOME/quantova-stack=/qcore --remap-path-prefix=$HOME/.cargo=/cargo --remap-path-prefix=$HOME/.rustup=/rustup\" wasm-pack build --target nodejs --out-dir pkg-node",
|
package/shared.js
CHANGED
|
@@ -27,6 +27,14 @@ function checkAmount(amount) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
function accountIndex(index) {
|
|
31
|
+
const i = BigInt(index);
|
|
32
|
+
if (i < 0n || i > 0xffffffffffffffffn) {
|
|
33
|
+
throw new Error('the account index must fit in an unsigned 64 bit integer');
|
|
34
|
+
}
|
|
35
|
+
return i;
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
async function readBounded(res) {
|
|
31
39
|
if (!res.body || typeof res.body.getReader !== 'function') {
|
|
32
40
|
const header = res.headers.get('content-length');
|
|
@@ -180,13 +188,15 @@ function makeClient(core) {
|
|
|
180
188
|
_signingChainId(info) {
|
|
181
189
|
const name = info && info.chain_id;
|
|
182
190
|
if (!name) throw new Error('the gateway did not report a chain id to bind the signature to');
|
|
191
|
+
const id = BigInt(core.chainIdFromName(name));
|
|
183
192
|
const configured = this.network && this.network.chainId;
|
|
184
193
|
if (configured && name !== configured) {
|
|
185
194
|
throw new Error(`the gateway reports chain ${name} but this client is configured for ${configured}; refusing to sign a transaction that would be valid on a network you did not choose`);
|
|
186
|
-
} else if (!configured && !this.acknowledgeMainnet && this._isMainnetId(BigInt(core.chainIdFromName(name)))) {
|
|
187
|
-
throw new Error(`the gateway reports the mainnet chain ${name} but this client did not choose a network; refusing to sign a mainnet transaction without acknowledgeMainnet`);
|
|
188
195
|
}
|
|
189
|
-
|
|
196
|
+
if (!this.acknowledgeMainnet && this._isMainnetId(id)) {
|
|
197
|
+
throw new Error(`the gateway reports the mainnet chain ${name}; refusing to sign a mainnet transaction without acknowledgeMainnet`);
|
|
198
|
+
}
|
|
199
|
+
return id;
|
|
190
200
|
}
|
|
191
201
|
|
|
192
202
|
_isMainnetId(id) {
|
|
@@ -228,7 +238,7 @@ function makeClient(core) {
|
|
|
228
238
|
storage(address) { return this._call('get_storage', JSON.stringify({ address })); }
|
|
229
239
|
events(height) { return this._call('get_events', core.eventsBody(BigInt(height))); }
|
|
230
240
|
|
|
231
|
-
address(seedHex, index) { return core.address(seedHex,
|
|
241
|
+
address(seedHex, index) { return core.address(seedHex, accountIndex(index)); }
|
|
232
242
|
|
|
233
243
|
async transfer(seedHex, index, to, amount, maxFeeQuon) {
|
|
234
244
|
if (!core.valid_address(to)) throw new Error('the recipient is not a q1 address');
|
|
@@ -242,11 +252,11 @@ function makeClient(core) {
|
|
|
242
252
|
if (BigInt(fee) > ceiling) {
|
|
243
253
|
throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
|
|
244
254
|
}
|
|
245
|
-
const from = core.address(seedHex,
|
|
255
|
+
const from = core.address(seedHex, accountIndex(index));
|
|
246
256
|
const acct = await this.account(from);
|
|
247
257
|
if (!acct || acct.nonce == null) throw new Error('the gateway did not report a nonce');
|
|
248
258
|
const signed = JSON.parse(
|
|
249
|
-
core.sign_transfer(seedHex,
|
|
259
|
+
core.sign_transfer(seedHex, accountIndex(index), to, String(amount), BigInt(acct.nonce), String(fee), chainId)
|
|
250
260
|
);
|
|
251
261
|
const outcome = await this.submit(signed.tx_hex);
|
|
252
262
|
return { signed, outcome };
|
|
@@ -262,10 +272,10 @@ function makeClient(core) {
|
|
|
262
272
|
if (BigInt(fee) > ceiling) {
|
|
263
273
|
throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
|
|
264
274
|
}
|
|
265
|
-
const from = core.address(seedHex,
|
|
275
|
+
const from = core.address(seedHex, accountIndex(index));
|
|
266
276
|
const acct = await this.account(from);
|
|
267
277
|
if (!acct || acct.nonce == null) throw new Error('the gateway did not report a nonce');
|
|
268
|
-
const signed = JSON.parse(core.signRegister(seedHex,
|
|
278
|
+
const signed = JSON.parse(core.signRegister(seedHex, accountIndex(index), BigInt(acct.nonce), String(fee), chainId));
|
|
269
279
|
const outcome = await this.submit(signed.tx_hex);
|
|
270
280
|
return { signed, outcome };
|
|
271
281
|
}
|
|
@@ -281,11 +291,11 @@ function makeClient(core) {
|
|
|
281
291
|
if (BigInt(fee) > ceiling) {
|
|
282
292
|
throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
|
|
283
293
|
}
|
|
284
|
-
const from = core.address(seedHex,
|
|
294
|
+
const from = core.address(seedHex, accountIndex(index));
|
|
285
295
|
const acct = await this.account(from);
|
|
286
296
|
if (!acct || acct.nonce == null) throw new Error('the gateway did not report a nonce');
|
|
287
297
|
const signed = JSON.parse(
|
|
288
|
-
core.sign_call(seedHex,
|
|
298
|
+
core.sign_call(seedHex, accountIndex(index), target, argsHex, BigInt(acct.nonce), BigInt(meterLimit), String(fee), chainId)
|
|
289
299
|
);
|
|
290
300
|
const outcome = await this.submit(signed.tx_hex);
|
|
291
301
|
return { signed, outcome };
|
|
@@ -312,10 +322,8 @@ function makeClient(core) {
|
|
|
312
322
|
if (BigInt(fee) > ceiling) {
|
|
313
323
|
throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
|
|
314
324
|
}
|
|
315
|
-
const signer = core.orderSigner(ownerSeedHex,
|
|
325
|
+
const signer = core.orderSigner(ownerSeedHex, accountIndex(ownerIndex));
|
|
316
326
|
const nonce = await this.contractNonce(contract, signer);
|
|
317
|
-
// orderSpec.fields are the signed fields in message order, each { offset, width, value } read
|
|
318
|
-
// from the interface descriptor, so a wide amount or an address is signed at its true width.
|
|
319
327
|
const order = JSON.parse(core.buildTypedOrderCall(
|
|
320
328
|
chainId,
|
|
321
329
|
contract,
|
|
@@ -325,14 +333,14 @@ function makeClient(core) {
|
|
|
325
333
|
BigInt(orderSpec.regionOff || 0),
|
|
326
334
|
JSON.stringify(orderSpec.fields || []),
|
|
327
335
|
ownerSeedHex,
|
|
328
|
-
|
|
336
|
+
accountIndex(ownerIndex),
|
|
329
337
|
nonce,
|
|
330
338
|
));
|
|
331
|
-
const from = core.address(callerSeedHex,
|
|
339
|
+
const from = core.address(callerSeedHex, accountIndex(callerIndex));
|
|
332
340
|
const acct = await this.account(from);
|
|
333
341
|
if (!acct || acct.nonce == null) throw new Error('the gateway did not report a nonce');
|
|
334
342
|
const signed = JSON.parse(
|
|
335
|
-
core.sign_call(callerSeedHex,
|
|
343
|
+
core.sign_call(callerSeedHex, accountIndex(callerIndex), contract, order.call_args, BigInt(acct.nonce), BigInt(meterLimit), String(fee), chainId)
|
|
336
344
|
);
|
|
337
345
|
const outcome = await this.submit(signed.tx_hex);
|
|
338
346
|
return { order, signed, outcome };
|