@qrlwallet/connect 5.0.0 → 5.0.1

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/dist/index.js CHANGED
@@ -3645,7 +3645,7 @@ function requestedSwitchChainId(params) {
3645
3645
  }
3646
3646
  return canonicalChainId2(request.chainId);
3647
3647
  }
3648
- var TRANSACTION_FIELDS = /* @__PURE__ */ new Set(["from", "to", "value", "gas", "data"]);
3648
+ var TRANSACTION_FIELDS = /* @__PURE__ */ new Set(["from", "to", "value", "gas", "data", "chainId"]);
3649
3649
  var QRL_TRANSACTION_MAX_DATA_BYTES = 128 * 1024;
3650
3650
  var QRL_TRANSACTION_MAX_QUANTITY_HEX_DIGITS = 64;
3651
3651
  var RPC_QUANTITY_RE = /^0x(?:0|[1-9a-fA-F][0-9a-fA-F]*)$/;
@@ -3660,8 +3660,11 @@ function validateRpcQuantity(value, field) {
3660
3660
  if (field === "gas" && BigInt(value) > BigInt(Number.MAX_SAFE_INTEGER)) {
3661
3661
  throw new Error("transaction gas exceeds the wallet safe-integer limit");
3662
3662
  }
3663
+ if (field === "chainId" && BigInt(value) === 0n) {
3664
+ throw new Error("transaction chainId must be positive");
3665
+ }
3663
3666
  }
3664
- function validateTransactionRequest(method, params, authorizedAccount) {
3667
+ function validateTransactionRequest(method, params, authorizedAccount, currentChainId) {
3665
3668
  if (params?.length !== 1 || !isRecordObj(params[0])) {
3666
3669
  throw new Error(`${method} requires exactly one transaction object`);
3667
3670
  }
@@ -3679,6 +3682,12 @@ function validateTransactionRequest(method, params, authorizedAccount) {
3679
3682
  }
3680
3683
  if ("value" in tx) validateRpcQuantity(tx.value, "value");
3681
3684
  if ("gas" in tx) validateRpcQuantity(tx.gas, "gas");
3685
+ if ("chainId" in tx) {
3686
+ validateRpcQuantity(tx.chainId, "chainId");
3687
+ if (canonicalChainId2(tx.chainId) !== canonicalChainId2(currentChainId)) {
3688
+ throw new Error("transaction chainId does not match the connected wallet");
3689
+ }
3690
+ }
3682
3691
  if ("data" in tx && (typeof tx.data !== "string" || tx.data.length > QRL_TRANSACTION_MAX_DATA_BYTES * 2 + 2 || !/^0x(?:[0-9a-fA-F]{2})*$/.test(tx.data))) {
3683
3692
  throw new Error("transaction data must be bounded 0x-prefixed bytes");
3684
3693
  }
@@ -3696,7 +3705,7 @@ function snapshotRequestParams(params) {
3696
3705
  throw new Error(`Request params must be JSON-serializable: ${detail}`);
3697
3706
  }
3698
3707
  }
3699
- function validateRestrictedRequest(method, params, authorizedAccounts) {
3708
+ function validateRestrictedRequest(method, params, authorizedAccounts, currentChainId) {
3700
3709
  if (method === "qrl_requestAccounts") {
3701
3710
  if (params !== void 0 && params.length !== 0) {
3702
3711
  throw new Error("qrl_requestAccounts does not accept parameters");
@@ -3711,7 +3720,7 @@ function validateRestrictedRequest(method, params, authorizedAccounts) {
3711
3720
  throw new Error("No authorized account: call qrl_requestAccounts first");
3712
3721
  }
3713
3722
  if (method === "qrl_sendTransaction" || method === "qrl_signTransaction") {
3714
- validateTransactionRequest(method, params, authorizedAccount);
3723
+ validateTransactionRequest(method, params, authorizedAccount, currentChainId);
3715
3724
  return void 0;
3716
3725
  }
3717
3726
  if (method === "qrl_signMessage") {
@@ -4059,7 +4068,8 @@ var QRLConnectProvider = class extends import_eventemitter34.default {
4059
4068
  const expectedChainId = validateRestrictedRequest(
4060
4069
  method,
4061
4070
  stableParams,
4062
- this.connectionManager.getAccounts()
4071
+ this.connectionManager.getAccounts(),
4072
+ this.connectionManager.getChainId()
4063
4073
  );
4064
4074
  return this.enqueueRestrictedRequest(method, stableParams, expectedChainId, generation);
4065
4075
  }
@@ -4124,6 +4134,14 @@ var QRLConnectProvider = class extends import_eventemitter34.default {
4124
4134
  throw new Error("Not connected to QRL Wallet");
4125
4135
  }
4126
4136
  }
4137
+ if (restricted) {
4138
+ validateRestrictedRequest(
4139
+ method,
4140
+ params,
4141
+ this.connectionManager.getAccounts(),
4142
+ this.connectionManager.getChainId()
4143
+ );
4144
+ }
4127
4145
  if (this.requestCounter >= Number.MAX_SAFE_INTEGER) {
4128
4146
  throw new Error("JSON-RPC request id counter exhausted");
4129
4147
  }
package/dist/index.mjs CHANGED
@@ -3540,7 +3540,7 @@ function requestedSwitchChainId(params) {
3540
3540
  }
3541
3541
  return canonicalChainId2(request.chainId);
3542
3542
  }
3543
- var TRANSACTION_FIELDS = /* @__PURE__ */ new Set(["from", "to", "value", "gas", "data"]);
3543
+ var TRANSACTION_FIELDS = /* @__PURE__ */ new Set(["from", "to", "value", "gas", "data", "chainId"]);
3544
3544
  var QRL_TRANSACTION_MAX_DATA_BYTES = 128 * 1024;
3545
3545
  var QRL_TRANSACTION_MAX_QUANTITY_HEX_DIGITS = 64;
3546
3546
  var RPC_QUANTITY_RE = /^0x(?:0|[1-9a-fA-F][0-9a-fA-F]*)$/;
@@ -3555,8 +3555,11 @@ function validateRpcQuantity(value, field) {
3555
3555
  if (field === "gas" && BigInt(value) > BigInt(Number.MAX_SAFE_INTEGER)) {
3556
3556
  throw new Error("transaction gas exceeds the wallet safe-integer limit");
3557
3557
  }
3558
+ if (field === "chainId" && BigInt(value) === 0n) {
3559
+ throw new Error("transaction chainId must be positive");
3560
+ }
3558
3561
  }
3559
- function validateTransactionRequest(method, params, authorizedAccount) {
3562
+ function validateTransactionRequest(method, params, authorizedAccount, currentChainId) {
3560
3563
  if (params?.length !== 1 || !isRecordObj(params[0])) {
3561
3564
  throw new Error(`${method} requires exactly one transaction object`);
3562
3565
  }
@@ -3574,6 +3577,12 @@ function validateTransactionRequest(method, params, authorizedAccount) {
3574
3577
  }
3575
3578
  if ("value" in tx) validateRpcQuantity(tx.value, "value");
3576
3579
  if ("gas" in tx) validateRpcQuantity(tx.gas, "gas");
3580
+ if ("chainId" in tx) {
3581
+ validateRpcQuantity(tx.chainId, "chainId");
3582
+ if (canonicalChainId2(tx.chainId) !== canonicalChainId2(currentChainId)) {
3583
+ throw new Error("transaction chainId does not match the connected wallet");
3584
+ }
3585
+ }
3577
3586
  if ("data" in tx && (typeof tx.data !== "string" || tx.data.length > QRL_TRANSACTION_MAX_DATA_BYTES * 2 + 2 || !/^0x(?:[0-9a-fA-F]{2})*$/.test(tx.data))) {
3578
3587
  throw new Error("transaction data must be bounded 0x-prefixed bytes");
3579
3588
  }
@@ -3591,7 +3600,7 @@ function snapshotRequestParams(params) {
3591
3600
  throw new Error(`Request params must be JSON-serializable: ${detail}`);
3592
3601
  }
3593
3602
  }
3594
- function validateRestrictedRequest(method, params, authorizedAccounts) {
3603
+ function validateRestrictedRequest(method, params, authorizedAccounts, currentChainId) {
3595
3604
  if (method === "qrl_requestAccounts") {
3596
3605
  if (params !== void 0 && params.length !== 0) {
3597
3606
  throw new Error("qrl_requestAccounts does not accept parameters");
@@ -3606,7 +3615,7 @@ function validateRestrictedRequest(method, params, authorizedAccounts) {
3606
3615
  throw new Error("No authorized account: call qrl_requestAccounts first");
3607
3616
  }
3608
3617
  if (method === "qrl_sendTransaction" || method === "qrl_signTransaction") {
3609
- validateTransactionRequest(method, params, authorizedAccount);
3618
+ validateTransactionRequest(method, params, authorizedAccount, currentChainId);
3610
3619
  return void 0;
3611
3620
  }
3612
3621
  if (method === "qrl_signMessage") {
@@ -3954,7 +3963,8 @@ var QRLConnectProvider = class extends EventEmitter4 {
3954
3963
  const expectedChainId = validateRestrictedRequest(
3955
3964
  method,
3956
3965
  stableParams,
3957
- this.connectionManager.getAccounts()
3966
+ this.connectionManager.getAccounts(),
3967
+ this.connectionManager.getChainId()
3958
3968
  );
3959
3969
  return this.enqueueRestrictedRequest(method, stableParams, expectedChainId, generation);
3960
3970
  }
@@ -4019,6 +4029,14 @@ var QRLConnectProvider = class extends EventEmitter4 {
4019
4029
  throw new Error("Not connected to QRL Wallet");
4020
4030
  }
4021
4031
  }
4032
+ if (restricted) {
4033
+ validateRestrictedRequest(
4034
+ method,
4035
+ params,
4036
+ this.connectionManager.getAccounts(),
4037
+ this.connectionManager.getChainId()
4038
+ );
4039
+ }
4022
4040
  if (this.requestCounter >= Number.MAX_SAFE_INTEGER) {
4023
4041
  throw new Error("JSON-RPC request id counter exhausted");
4024
4042
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrlwallet/connect",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "packageManager": "npm@10.9.8",
5
5
  "description": "Connect your dApp to QRL Wallet via QR code or deep link",
6
6
  "main": "dist/index.js",