@quantovainc/qcore 0.2.3 → 0.2.4

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantovainc/qcore",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
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",
Binary file
Binary file
package/shared.js CHANGED
@@ -8,14 +8,7 @@ function feeCeiling(maxFeeQuon) {
8
8
  if (typeof maxFeeQuon === 'number') {
9
9
  throw new Error('pass the maximum fee as a decimal string or a BigInt, never a JavaScript number, because a number silently rounds above 2^53 and could set the ceiling higher than you intended');
10
10
  }
11
- let ceiling;
12
- try {
13
- ceiling = BigInt(maxFeeQuon);
14
- } catch {
15
- throw new Error('the maximum fee must be an integer number of Quon');
16
- }
17
- if (ceiling < 0n) throw new Error('the maximum fee cannot be negative');
18
- return ceiling;
11
+ return wholeNumber(maxFeeQuon, 'maximum fee', U128_MAX);
19
12
  }
20
13
 
21
14
  function checkAmount(amount) {
@@ -28,35 +21,11 @@ function checkAmount(amount) {
28
21
  }
29
22
 
30
23
  function accountIndex(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
- }
40
- if (i < 0n || i > 0xffffffffffffffffn) {
41
- throw new Error('the account index must fit in an unsigned 64 bit integer');
42
- }
43
- return i;
24
+ return wholeNumber(index, 'account index', U64_MAX);
44
25
  }
45
26
 
46
27
  function accountNonce(nonce) {
47
- if (typeof nonce === 'number' && !Number.isSafeInteger(nonce)) {
48
- throw new Error('the gateway reported a nonce outside the safe integer range, a number that large silently rounds and would sign a different nonce');
49
- }
50
- let n;
51
- try {
52
- n = BigInt(nonce);
53
- } catch {
54
- throw new Error('the gateway reported a nonce that is not a whole number');
55
- }
56
- if (n < 0n || n > 0xffffffffffffffffn) {
57
- throw new Error('the gateway reported a nonce outside the unsigned 64 bit range');
58
- }
59
- return n;
28
+ return wholeNumber(nonce, 'nonce', U64_MAX);
60
29
  }
61
30
 
62
31
  const VALIDITY_BLOCKS = 300n;
@@ -142,19 +111,7 @@ function isPublicChain(name) {
142
111
  }
143
112
 
144
113
  function meterLimitOf(meterLimit) {
145
- if (typeof meterLimit === 'number' && !Number.isSafeInteger(meterLimit)) {
146
- throw new Error('the meter limit must be a whole number in the safe integer range');
147
- }
148
- let meter;
149
- try {
150
- meter = BigInt(meterLimit);
151
- } catch {
152
- throw new Error('the meter limit must be a whole number');
153
- }
154
- if (meter < 0n || meter > 0xffffffffffffffffn) {
155
- throw new Error('the meter limit must fit in an unsigned 64 bit integer');
156
- }
157
- return meter;
114
+ return wholeNumber(meterLimit, 'meter limit', U64_MAX);
158
115
  }
159
116
 
160
117
  function validUntil(info) {
@@ -176,17 +133,7 @@ function validUntil(info) {
176
133
  }
177
134
 
178
135
  function gatewayFee(fee) {
179
- if (typeof fee === 'number' && !Number.isSafeInteger(fee)) {
180
- throw new Error('the gateway reported a fee outside the safe integer range, a number that large silently rounds and would sign a different fee');
181
- }
182
- let f;
183
- try {
184
- f = BigInt(fee);
185
- } catch {
186
- throw new Error('the gateway reported a fee that is not a whole number');
187
- }
188
- if (f < 0n) throw new Error('the gateway reported a negative fee');
189
- return f;
136
+ return wholeNumber(fee, 'fee', U128_MAX);
190
137
  }
191
138
 
192
139
  async function readBounded(res) {
package/shared.mjs CHANGED
@@ -8,14 +8,7 @@ function feeCeiling(maxFeeQuon) {
8
8
  if (typeof maxFeeQuon === 'number') {
9
9
  throw new Error('pass the maximum fee as a decimal string or a BigInt, never a JavaScript number, because a number silently rounds above 2^53 and could set the ceiling higher than you intended');
10
10
  }
11
- let ceiling;
12
- try {
13
- ceiling = BigInt(maxFeeQuon);
14
- } catch {
15
- throw new Error('the maximum fee must be an integer number of Quon');
16
- }
17
- if (ceiling < 0n) throw new Error('the maximum fee cannot be negative');
18
- return ceiling;
11
+ return wholeNumber(maxFeeQuon, 'maximum fee', U128_MAX);
19
12
  }
20
13
 
21
14
  function checkAmount(amount) {
@@ -28,35 +21,11 @@ function checkAmount(amount) {
28
21
  }
29
22
 
30
23
  function accountIndex(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
- }
40
- if (i < 0n || i > 0xffffffffffffffffn) {
41
- throw new Error('the account index must fit in an unsigned 64 bit integer');
42
- }
43
- return i;
24
+ return wholeNumber(index, 'account index', U64_MAX);
44
25
  }
45
26
 
46
27
  function accountNonce(nonce) {
47
- if (typeof nonce === 'number' && !Number.isSafeInteger(nonce)) {
48
- throw new Error('the gateway reported a nonce outside the safe integer range, a number that large silently rounds and would sign a different nonce');
49
- }
50
- let n;
51
- try {
52
- n = BigInt(nonce);
53
- } catch {
54
- throw new Error('the gateway reported a nonce that is not a whole number');
55
- }
56
- if (n < 0n || n > 0xffffffffffffffffn) {
57
- throw new Error('the gateway reported a nonce outside the unsigned 64 bit range');
58
- }
59
- return n;
28
+ return wholeNumber(nonce, 'nonce', U64_MAX);
60
29
  }
61
30
 
62
31
  const VALIDITY_BLOCKS = 300n;
@@ -142,19 +111,7 @@ function isPublicChain(name) {
142
111
  }
143
112
 
144
113
  function meterLimitOf(meterLimit) {
145
- if (typeof meterLimit === 'number' && !Number.isSafeInteger(meterLimit)) {
146
- throw new Error('the meter limit must be a whole number in the safe integer range');
147
- }
148
- let meter;
149
- try {
150
- meter = BigInt(meterLimit);
151
- } catch {
152
- throw new Error('the meter limit must be a whole number');
153
- }
154
- if (meter < 0n || meter > 0xffffffffffffffffn) {
155
- throw new Error('the meter limit must fit in an unsigned 64 bit integer');
156
- }
157
- return meter;
114
+ return wholeNumber(meterLimit, 'meter limit', U64_MAX);
158
115
  }
159
116
 
160
117
  function validUntil(info) {
@@ -176,17 +133,7 @@ function validUntil(info) {
176
133
  }
177
134
 
178
135
  function gatewayFee(fee) {
179
- if (typeof fee === 'number' && !Number.isSafeInteger(fee)) {
180
- throw new Error('the gateway reported a fee outside the safe integer range, a number that large silently rounds and would sign a different fee');
181
- }
182
- let f;
183
- try {
184
- f = BigInt(fee);
185
- } catch {
186
- throw new Error('the gateway reported a fee that is not a whole number');
187
- }
188
- if (f < 0n) throw new Error('the gateway reported a negative fee');
189
- return f;
136
+ return wholeNumber(fee, 'fee', U128_MAX);
190
137
  }
191
138
 
192
139
  async function readBounded(res) {