@quantovainc/qcore 0.1.18 → 0.1.19

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/shared.js +15 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantovainc/qcore",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
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');
@@ -228,7 +236,7 @@ function makeClient(core) {
228
236
  storage(address) { return this._call('get_storage', JSON.stringify({ address })); }
229
237
  events(height) { return this._call('get_events', core.eventsBody(BigInt(height))); }
230
238
 
231
- address(seedHex, index) { return core.address(seedHex, BigInt(index)); }
239
+ address(seedHex, index) { return core.address(seedHex, accountIndex(index)); }
232
240
 
233
241
  async transfer(seedHex, index, to, amount, maxFeeQuon) {
234
242
  if (!core.valid_address(to)) throw new Error('the recipient is not a q1 address');
@@ -242,11 +250,11 @@ function makeClient(core) {
242
250
  if (BigInt(fee) > ceiling) {
243
251
  throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
244
252
  }
245
- const from = core.address(seedHex, BigInt(index));
253
+ const from = core.address(seedHex, accountIndex(index));
246
254
  const acct = await this.account(from);
247
255
  if (!acct || acct.nonce == null) throw new Error('the gateway did not report a nonce');
248
256
  const signed = JSON.parse(
249
- core.sign_transfer(seedHex, BigInt(index), to, String(amount), BigInt(acct.nonce), String(fee), chainId)
257
+ core.sign_transfer(seedHex, accountIndex(index), to, String(amount), BigInt(acct.nonce), String(fee), chainId)
250
258
  );
251
259
  const outcome = await this.submit(signed.tx_hex);
252
260
  return { signed, outcome };
@@ -262,10 +270,10 @@ function makeClient(core) {
262
270
  if (BigInt(fee) > ceiling) {
263
271
  throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
264
272
  }
265
- const from = core.address(seedHex, BigInt(index));
273
+ const from = core.address(seedHex, accountIndex(index));
266
274
  const acct = await this.account(from);
267
275
  if (!acct || acct.nonce == null) throw new Error('the gateway did not report a nonce');
268
- const signed = JSON.parse(core.signRegister(seedHex, BigInt(index), BigInt(acct.nonce), String(fee), chainId));
276
+ const signed = JSON.parse(core.signRegister(seedHex, accountIndex(index), BigInt(acct.nonce), String(fee), chainId));
269
277
  const outcome = await this.submit(signed.tx_hex);
270
278
  return { signed, outcome };
271
279
  }
@@ -281,11 +289,11 @@ function makeClient(core) {
281
289
  if (BigInt(fee) > ceiling) {
282
290
  throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
283
291
  }
284
- const from = core.address(seedHex, BigInt(index));
292
+ const from = core.address(seedHex, accountIndex(index));
285
293
  const acct = await this.account(from);
286
294
  if (!acct || acct.nonce == null) throw new Error('the gateway did not report a nonce');
287
295
  const signed = JSON.parse(
288
- core.sign_call(seedHex, BigInt(index), target, argsHex, BigInt(acct.nonce), BigInt(meterLimit), String(fee), chainId)
296
+ core.sign_call(seedHex, accountIndex(index), target, argsHex, BigInt(acct.nonce), BigInt(meterLimit), String(fee), chainId)
289
297
  );
290
298
  const outcome = await this.submit(signed.tx_hex);
291
299
  return { signed, outcome };
@@ -314,8 +322,6 @@ function makeClient(core) {
314
322
  }
315
323
  const signer = core.orderSigner(ownerSeedHex, BigInt(ownerIndex));
316
324
  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
325
  const order = JSON.parse(core.buildTypedOrderCall(
320
326
  chainId,
321
327
  contract,