@quantovainc/qcore 0.1.17 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantovainc/qcore",
3
- "version": "0.1.17",
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",
Binary file
Binary file
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');
@@ -189,10 +197,8 @@ function makeClient(core) {
189
197
  return BigInt(core.chainIdFromName(name));
190
198
  }
191
199
 
192
- // The canonical mainnet name is still an open convention (the chain crate's id vs the "Q-main-net-1"
193
- // preset), so until it is settled the gate prompts for either candidate rather than miss the real one.
194
200
  _isMainnetId(id) {
195
- return id === BigInt(core.mainnetChainId()) || id === BigInt(core.chainIdFromName('Q-main-net-1'));
201
+ return id === BigInt(core.mainnetChainId());
196
202
  }
197
203
 
198
204
  async _call(method, body) {
@@ -230,7 +236,7 @@ function makeClient(core) {
230
236
  storage(address) { return this._call('get_storage', JSON.stringify({ address })); }
231
237
  events(height) { return this._call('get_events', core.eventsBody(BigInt(height))); }
232
238
 
233
- address(seedHex, index) { return core.address(seedHex, BigInt(index)); }
239
+ address(seedHex, index) { return core.address(seedHex, accountIndex(index)); }
234
240
 
235
241
  async transfer(seedHex, index, to, amount, maxFeeQuon) {
236
242
  if (!core.valid_address(to)) throw new Error('the recipient is not a q1 address');
@@ -244,11 +250,11 @@ function makeClient(core) {
244
250
  if (BigInt(fee) > ceiling) {
245
251
  throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
246
252
  }
247
- const from = core.address(seedHex, BigInt(index));
253
+ const from = core.address(seedHex, accountIndex(index));
248
254
  const acct = await this.account(from);
249
255
  if (!acct || acct.nonce == null) throw new Error('the gateway did not report a nonce');
250
256
  const signed = JSON.parse(
251
- 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)
252
258
  );
253
259
  const outcome = await this.submit(signed.tx_hex);
254
260
  return { signed, outcome };
@@ -264,10 +270,10 @@ function makeClient(core) {
264
270
  if (BigInt(fee) > ceiling) {
265
271
  throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
266
272
  }
267
- const from = core.address(seedHex, BigInt(index));
273
+ const from = core.address(seedHex, accountIndex(index));
268
274
  const acct = await this.account(from);
269
275
  if (!acct || acct.nonce == null) throw new Error('the gateway did not report a nonce');
270
- 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));
271
277
  const outcome = await this.submit(signed.tx_hex);
272
278
  return { signed, outcome };
273
279
  }
@@ -283,11 +289,11 @@ function makeClient(core) {
283
289
  if (BigInt(fee) > ceiling) {
284
290
  throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
285
291
  }
286
- const from = core.address(seedHex, BigInt(index));
292
+ const from = core.address(seedHex, accountIndex(index));
287
293
  const acct = await this.account(from);
288
294
  if (!acct || acct.nonce == null) throw new Error('the gateway did not report a nonce');
289
295
  const signed = JSON.parse(
290
- 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)
291
297
  );
292
298
  const outcome = await this.submit(signed.tx_hex);
293
299
  return { signed, outcome };
@@ -316,8 +322,6 @@ function makeClient(core) {
316
322
  }
317
323
  const signer = core.orderSigner(ownerSeedHex, BigInt(ownerIndex));
318
324
  const nonce = await this.contractNonce(contract, signer);
319
- // orderSpec.fields are the signed fields in message order, each { offset, width, value } read
320
- // from the interface descriptor, so a wide amount or an address is signed at its true width.
321
325
  const order = JSON.parse(core.buildTypedOrderCall(
322
326
  chainId,
323
327
  contract,