@quantovainc/qcore 0.1.32 → 0.1.33

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 CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@quantovainc/qcore",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
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": "bash scripts/build.sh",
7
- "test": "node test-types.js && node test-conformance.js && node test-order-nonce.js && node test-chain-binding.js && node test-sign-validate.js && node test-transport.js && node test-fee-cap.js && node test-network.js && node test-typed-order.js && node test-asset-guards.js"
7
+ "test": "node test-types.js && node test-conformance.js && node test-order-nonce.js && node test-chain-binding.js && node test-sign-validate.js && node test-transport.js && node test-fee-cap.js && node test-network.js && node test-typed-order.js && node test-asset-guards.js && node test-account-index.js"
8
8
  },
9
9
  "keywords": [
10
10
  "post-quantum",
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.1.31",
5
+ "version": "0.1.33",
6
6
  "license": "Apache-2.0 OR MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -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.1.31",
4
+ "version": "0.1.33",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "repository": {
7
7
  "type": "git",
package/shared.js CHANGED
@@ -28,7 +28,15 @@ function checkAmount(amount) {
28
28
  }
29
29
 
30
30
  function accountIndex(index) {
31
- const i = BigInt(index);
31
+ if (typeof index === 'number' && !Number.isSafeInteger(index)) {
32
+ throw new Error('the account index must be a whole number in the safe integer range, a number that large silently rounds and would sign with a different account key');
33
+ }
34
+ let i;
35
+ try {
36
+ i = BigInt(index);
37
+ } catch {
38
+ throw new Error('the account index must be a whole number');
39
+ }
32
40
  if (i < 0n || i > 0xffffffffffffffffn) {
33
41
  throw new Error('the account index must fit in an unsigned 64 bit integer');
34
42
  }
@@ -342,7 +350,8 @@ function makeClient(core) {
342
350
  if (this._headFloor) {
343
351
  const { height, at } = this._headFloor;
344
352
  if (head < height) throw new Error(`the gateway reports head ${head} below the ${height} it reported earlier, refusing to sign`);
345
- const allowed = (now - at + HEAD_SLACK_SECS) * HEAD_BLOCKS_PER_SEC;
353
+ const elapsed = now > at ? now - at : 0n;
354
+ const allowed = (elapsed + HEAD_SLACK_SECS) * HEAD_BLOCKS_PER_SEC;
346
355
  if (head > height + allowed) throw new Error(`the gateway head leapt from ${height} to ${head} faster than blocks are made, refusing to sign`);
347
356
  } else {
348
357
  this._headFloor = { height: head, at: now };
@@ -365,9 +374,10 @@ function makeClient(core) {
365
374
  const info = await this.nodeInfo();
366
375
  this._guardMainnet();
367
376
  const chainId = this._signingChainId(info);
368
- const fee = info && info.fee && info.fee.transfer_quon;
369
- if (fee == null) throw new Error('the gateway did not report a transfer fee');
370
- if (gatewayFee(fee) > ceiling) {
377
+ const reported = info && info.fee && info.fee.transfer_quon;
378
+ if (reported == null) throw new Error('the gateway did not report a transfer fee');
379
+ const fee = gatewayFee(reported);
380
+ if (fee > ceiling) {
371
381
  throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
372
382
  }
373
383
  const from = core.address(seedHex, accountIndex(index));
@@ -387,9 +397,10 @@ function makeClient(core) {
387
397
  const info = await this.nodeInfo();
388
398
  this._guardMainnet();
389
399
  const chainId = this._signingChainId(info);
390
- const fee = info && info.fee && info.fee.transfer_quon;
391
- if (fee == null) throw new Error('the gateway did not report a transfer fee');
392
- if (gatewayFee(fee) > ceiling) {
400
+ const reported = info && info.fee && info.fee.transfer_quon;
401
+ if (reported == null) throw new Error('the gateway did not report a transfer fee');
402
+ const fee = gatewayFee(reported);
403
+ if (fee > ceiling) {
393
404
  throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
394
405
  }
395
406
  const from = core.address(seedHex, accountIndex(index));
package/shared.mjs CHANGED
@@ -28,7 +28,15 @@ function checkAmount(amount) {
28
28
  }
29
29
 
30
30
  function accountIndex(index) {
31
- const i = BigInt(index);
31
+ if (typeof index === 'number' && !Number.isSafeInteger(index)) {
32
+ throw new Error('the account index must be a whole number in the safe integer range, a number that large silently rounds and would sign with a different account key');
33
+ }
34
+ let i;
35
+ try {
36
+ i = BigInt(index);
37
+ } catch {
38
+ throw new Error('the account index must be a whole number');
39
+ }
32
40
  if (i < 0n || i > 0xffffffffffffffffn) {
33
41
  throw new Error('the account index must fit in an unsigned 64 bit integer');
34
42
  }
@@ -342,7 +350,8 @@ function makeClient(core) {
342
350
  if (this._headFloor) {
343
351
  const { height, at } = this._headFloor;
344
352
  if (head < height) throw new Error(`the gateway reports head ${head} below the ${height} it reported earlier, refusing to sign`);
345
- const allowed = (now - at + HEAD_SLACK_SECS) * HEAD_BLOCKS_PER_SEC;
353
+ const elapsed = now > at ? now - at : 0n;
354
+ const allowed = (elapsed + HEAD_SLACK_SECS) * HEAD_BLOCKS_PER_SEC;
346
355
  if (head > height + allowed) throw new Error(`the gateway head leapt from ${height} to ${head} faster than blocks are made, refusing to sign`);
347
356
  } else {
348
357
  this._headFloor = { height: head, at: now };
@@ -365,9 +374,10 @@ function makeClient(core) {
365
374
  const info = await this.nodeInfo();
366
375
  this._guardMainnet();
367
376
  const chainId = this._signingChainId(info);
368
- const fee = info && info.fee && info.fee.transfer_quon;
369
- if (fee == null) throw new Error('the gateway did not report a transfer fee');
370
- if (gatewayFee(fee) > ceiling) {
377
+ const reported = info && info.fee && info.fee.transfer_quon;
378
+ if (reported == null) throw new Error('the gateway did not report a transfer fee');
379
+ const fee = gatewayFee(reported);
380
+ if (fee > ceiling) {
371
381
  throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
372
382
  }
373
383
  const from = core.address(seedHex, accountIndex(index));
@@ -387,9 +397,10 @@ function makeClient(core) {
387
397
  const info = await this.nodeInfo();
388
398
  this._guardMainnet();
389
399
  const chainId = this._signingChainId(info);
390
- const fee = info && info.fee && info.fee.transfer_quon;
391
- if (fee == null) throw new Error('the gateway did not report a transfer fee');
392
- if (gatewayFee(fee) > ceiling) {
400
+ const reported = info && info.fee && info.fee.transfer_quon;
401
+ if (reported == null) throw new Error('the gateway did not report a transfer fee');
402
+ const fee = gatewayFee(reported);
403
+ if (fee > ceiling) {
393
404
  throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
394
405
  }
395
406
  const from = core.address(seedHex, accountIndex(index));