@quantovainc/qcore 0.1.19 → 0.1.21

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 +13 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantovainc/qcore",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
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
@@ -188,13 +188,15 @@ function makeClient(core) {
188
188
  _signingChainId(info) {
189
189
  const name = info && info.chain_id;
190
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));
191
192
  const configured = this.network && this.network.chainId;
192
193
  if (configured && name !== configured) {
193
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`);
194
- } else if (!configured && !this.acknowledgeMainnet && this._isMainnetId(BigInt(core.chainIdFromName(name)))) {
195
- 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`);
196
195
  }
197
- return BigInt(core.chainIdFromName(name));
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;
198
200
  }
199
201
 
200
202
  _isMainnetId(id) {
@@ -219,7 +221,10 @@ function makeClient(core) {
219
221
  const text = await readBounded(res);
220
222
  let data;
221
223
  try { data = JSON.parse(text); } catch { throw new Error('the node returned a non JSON response'); }
222
- if (!res.ok) throw new Error(data.message || data.error || ('status ' + res.status));
224
+ if (!res.ok) {
225
+ const detail = data && typeof data === 'object' ? (data.message || data.error) : null;
226
+ throw new Error(detail || ('status ' + res.status));
227
+ }
223
228
  return data;
224
229
  } finally {
225
230
  clearTimeout(timer);
@@ -320,7 +325,7 @@ function makeClient(core) {
320
325
  if (BigInt(fee) > ceiling) {
321
326
  throw new Error(`the gateway fee ${fee} is above the maximum you allowed ${maxFeeQuon}, refusing to sign`);
322
327
  }
323
- const signer = core.orderSigner(ownerSeedHex, BigInt(ownerIndex));
328
+ const signer = core.orderSigner(ownerSeedHex, accountIndex(ownerIndex));
324
329
  const nonce = await this.contractNonce(contract, signer);
325
330
  const order = JSON.parse(core.buildTypedOrderCall(
326
331
  chainId,
@@ -331,14 +336,14 @@ function makeClient(core) {
331
336
  BigInt(orderSpec.regionOff || 0),
332
337
  JSON.stringify(orderSpec.fields || []),
333
338
  ownerSeedHex,
334
- BigInt(ownerIndex),
339
+ accountIndex(ownerIndex),
335
340
  nonce,
336
341
  ));
337
- const from = core.address(callerSeedHex, BigInt(callerIndex));
342
+ const from = core.address(callerSeedHex, accountIndex(callerIndex));
338
343
  const acct = await this.account(from);
339
344
  if (!acct || acct.nonce == null) throw new Error('the gateway did not report a nonce');
340
345
  const signed = JSON.parse(
341
- core.sign_call(callerSeedHex, BigInt(callerIndex), contract, order.call_args, BigInt(acct.nonce), BigInt(meterLimit), String(fee), chainId)
346
+ core.sign_call(callerSeedHex, accountIndex(callerIndex), contract, order.call_args, BigInt(acct.nonce), BigInt(meterLimit), String(fee), chainId)
342
347
  );
343
348
  const outcome = await this.submit(signed.tx_hex);
344
349
  return { order, signed, outcome };