@metamask/transaction-controller 55.0.2 → 56.1.0

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 (62) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/dist/TransactionController.cjs +57 -18
  3. package/dist/TransactionController.cjs.map +1 -1
  4. package/dist/TransactionController.d.cts +10 -2
  5. package/dist/TransactionController.d.cts.map +1 -1
  6. package/dist/TransactionController.d.mts +10 -2
  7. package/dist/TransactionController.d.mts.map +1 -1
  8. package/dist/TransactionController.mjs +59 -20
  9. package/dist/TransactionController.mjs.map +1 -1
  10. package/dist/api/accounts-api.cjs +3 -2
  11. package/dist/api/accounts-api.cjs.map +1 -1
  12. package/dist/api/accounts-api.d.cts +1 -0
  13. package/dist/api/accounts-api.d.cts.map +1 -1
  14. package/dist/api/accounts-api.d.mts +1 -0
  15. package/dist/api/accounts-api.d.mts.map +1 -1
  16. package/dist/api/accounts-api.mjs +3 -2
  17. package/dist/api/accounts-api.mjs.map +1 -1
  18. package/dist/helpers/AccountsApiRemoteTransactionSource.cjs +2 -1
  19. package/dist/helpers/AccountsApiRemoteTransactionSource.cjs.map +1 -1
  20. package/dist/helpers/AccountsApiRemoteTransactionSource.d.cts.map +1 -1
  21. package/dist/helpers/AccountsApiRemoteTransactionSource.d.mts.map +1 -1
  22. package/dist/helpers/AccountsApiRemoteTransactionSource.mjs +2 -1
  23. package/dist/helpers/AccountsApiRemoteTransactionSource.mjs.map +1 -1
  24. package/dist/helpers/GasFeePoller.cjs +76 -48
  25. package/dist/helpers/GasFeePoller.cjs.map +1 -1
  26. package/dist/helpers/GasFeePoller.d.cts +15 -3
  27. package/dist/helpers/GasFeePoller.d.cts.map +1 -1
  28. package/dist/helpers/GasFeePoller.d.mts +15 -3
  29. package/dist/helpers/GasFeePoller.d.mts.map +1 -1
  30. package/dist/helpers/GasFeePoller.mjs +73 -46
  31. package/dist/helpers/GasFeePoller.mjs.map +1 -1
  32. package/dist/helpers/IncomingTransactionHelper.cjs +32 -8
  33. package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -1
  34. package/dist/helpers/IncomingTransactionHelper.d.cts +7 -2
  35. package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -1
  36. package/dist/helpers/IncomingTransactionHelper.d.mts +7 -2
  37. package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -1
  38. package/dist/helpers/IncomingTransactionHelper.mjs +32 -8
  39. package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
  40. package/dist/types.cjs.map +1 -1
  41. package/dist/types.d.cts +4 -0
  42. package/dist/types.d.cts.map +1 -1
  43. package/dist/types.d.mts +4 -0
  44. package/dist/types.d.mts.map +1 -1
  45. package/dist/types.mjs.map +1 -1
  46. package/dist/utils/feature-flags.cjs +16 -1
  47. package/dist/utils/feature-flags.cjs.map +1 -1
  48. package/dist/utils/feature-flags.d.cts +14 -0
  49. package/dist/utils/feature-flags.d.cts.map +1 -1
  50. package/dist/utils/feature-flags.d.mts +14 -0
  51. package/dist/utils/feature-flags.d.mts.map +1 -1
  52. package/dist/utils/feature-flags.mjs +14 -0
  53. package/dist/utils/feature-flags.mjs.map +1 -1
  54. package/dist/utils/validation.cjs +1 -0
  55. package/dist/utils/validation.cjs.map +1 -1
  56. package/dist/utils/validation.d.cts +2 -1
  57. package/dist/utils/validation.d.cts.map +1 -1
  58. package/dist/utils/validation.d.mts +2 -1
  59. package/dist/utils/validation.d.mts.map +1 -1
  60. package/dist/utils/validation.mjs +1 -0
  61. package/dist/utils/validation.mjs.map +1 -1
  62. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"feature-flags.d.cts","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,GAAG,EAAE,wBAAwB;AAK/D,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAQ/E;;GAEG;AACH,oBAAY,WAAW;IACrB,OAAO,2BAA2B;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AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,8BAA8B,GACxC;IACD,sBAAsB,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC5C,uBAAuB,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7C,CAUA;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,GAAG,EACZ,SAAS,EAAE,8BAA8B,GACxC;IACD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAgBA;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,WAAW,EACX,uBAAuB,EACvB,SAAS,GACV,EAAE;IACD,OAAO,EAAE,GAAG,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,uBAAuB,EAAE,OAAO,CAAC;IACjC,SAAS,EAAE,8BAA8B,CAAC;CAC3C,GAAG,MAAM,CAsBT"}
1
+ {"version":3,"file":"feature-flags.d.cts","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,GAAG,EAAE,wBAAwB;AAK/D,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAS/E;;GAEG;AACH,oBAAY,WAAW;IACrB,OAAO,2BAA2B;IAClC,SAAS,6BAA6B;IACtC,oBAAoB,wCAAwC;IAC5D,YAAY,+BAA+B;CAC5C;AAED,KAAK,mBAAmB,GAAG;IACzB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,+DAA+D;IAC/D,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,EAAE;QACtB;;;;WAIG;QACH,SAAS,CAAC,EAAE,MAAM,CAChB,GAAG,EACH;YACE,qCAAqC;YACrC,O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,CACpC,OAAO,EAAE,GAAG,EACZ,SAAS,EAAE,8BAA8B,GACxC;IACD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAgBA;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,WAAW,EACX,uBAAuB,EACvB,SAAS,GACV,EAAE;IACD,OAAO,EAAE,GAAG,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,uBAAuB,EAAE,OAAO,CAAC;IACjC,SAAS,EAAE,8BAA8B,CAAC;CAC3C,GAAG,MAAM,CAsBT;AAED;;;;;;GAMG;AACH,wBAAgB,sCAAsC,CACpD,SAAS,EAAE,8BAA8B,GACxC,MAAM,CAOR"}
@@ -6,6 +6,7 @@ import type { TransactionControllerMessenger } from "../TransactionController.mj
6
6
  export declare enum FeatureFlag {
7
7
  EIP7702 = "confirmations_eip_7702",
8
8
  GasBuffer = "confirmations_gas_buffer",
9
+ IncomingTransactions = "confirmations_incoming_transactions",
9
10
  Transactions = "confirmations_transactions"
10
11
  }
11
12
  type GasEstimateFallback = {
@@ -69,6 +70,11 @@ export type TransactionControllerFeatureFlags = {
69
70
  };
70
71
  };
71
72
  };
73
+ /** Incoming transaction configuration. */
74
+ [FeatureFlag.IncomingTransactions]?: {
75
+ /** Interval between requests to accounts API to retrieve incoming transactions. */
76
+ pollingIntervalMs?: number;
77
+ };
72
78
  /** Miscellaneous feature flags to support the transaction controller. */
73
79
  [FeatureFlag.Transactions]?: {
74
80
  /** Maximum number of transactions that can be in an external batch. */
@@ -197,5 +203,13 @@ export declare function getGasEstimateBuffer({ chainId, isCustomRPC, isUpgradeWi
197
203
  isUpgradeWithDataToSelf: boolean;
198
204
  messenger: TransactionControllerMessenger;
199
205
  }): number;
206
+ /**
207
+ * Retrieves the incoming transactions polling interval.
208
+ * Defaults to 4 minutes if not set.
209
+ *
210
+ * @param messenger - The controller messenger instance.
211
+ * @returns The incoming transactions polling interval in milliseconds.
212
+ */
213
+ export declare function getIncomingTransactionsPollingInterval(messenger: TransactionControllerMessenger): number;
200
214
  export {};
201
215
  //# sourceMappingURL=feature-flags.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"feature-flags.d.mts","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,GAAG,EAAE,wBAAwB;AAK/D,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAQ/E;;GAEG;AACH,oBAAY,WAAW;IACrB,OAAO,2BAA2B;IAClC,SAAS,6BAA6B;IACtC,YAAY,+BAA+B;CAC5C;AAED,KAAK,mBAAmB,GAAG;IACzB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,+DAA+D;IAC/D,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,EAAE;QACtB;;;;WAIG;QACH,SAAS,CAAC,EAAE,MAAM,CAChB,GAAG,EACH;YACE,qCAAqC;YACrC,OAAO,EAAE,GAAG,CAAC;YAEb,qDAAqD;YACrD,SAAS,EAAE,GAAG,CAAC;SAChB,EAAE,CACJ,CAAC;QAEF,sDAAsD;QACtD,eAAe,CAAC,EAAE,GAAG,EAAE,CAAC;KACzB,CAAC;IAEF;;;OAGG;IACH,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE;QACxB,uDAAuD;QACvD,OAAO,CAAC,EAAE,MAAM,CAAC;QAEjB;;;WAGG;QACH,QAAQ,CAAC,EAAE,MAAM,CAAC;QAElB,mCAAmC;QACnC,cAAc,CAAC,EAAE;YACf,CAAC,OAAO,EAAE,GAAG,GAAG;gBACd;;;mBAGG;gBACH,IAAI,CAAC,EAAE,MAAM,CAAC;gBAEd;;;mBAGG;gBACH,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAElB;;;;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C,OAAO,EAAE,GAAG,EACZ,SAAS,EAAE,8BAA8B,GACxC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAiB1C;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,8BAA8B,GACxC;IACD,sBAAsB,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC5C,uBAAuB,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7C,CAUA;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,GAAG,EACZ,SAAS,EAAE,8BAA8B,GACxC;IACD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAgBA;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,WAAW,EACX,uBAAuB,EACvB,SAAS,GACV,EAAE;IACD,OAAO,EAAE,GAAG,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,uBAAuB,EAAE,OAAO,CAAC;IACjC,SAAS,EAAE,8BAA8B,CAAC;CAC3C,GAAG,MAAM,CAsBT;AAED;;;;;;GAMG;AACH,wBAAgB,sCAAsC,CACpD,SAAS,EAAE,8BAA8B,GACxC,MAAM,CAOR"}
@@ -7,6 +7,7 @@ const DEFAULT_ACCELERATED_POLLING_COUNT_MAX = 10;
7
7
  const DEFAULT_ACCELERATED_POLLING_INTERVAL_MS = 3 * 1000;
8
8
  const DEFAULT_GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;
9
9
  const DEFAULT_GAS_ESTIMATE_BUFFER = 1;
10
+ const DEFAULT_INCOMING_TRANSACTIONS_POLLING_INTERVAL_MS = 1000 * 60 * 4; // 4 Minutes
10
11
  /**
11
12
  * Feature flags supporting the transaction controller.
12
13
  */
@@ -14,6 +15,7 @@ export var FeatureFlag;
14
15
  (function (FeatureFlag) {
15
16
  FeatureFlag["EIP7702"] = "confirmations_eip_7702";
16
17
  FeatureFlag["GasBuffer"] = "confirmations_gas_buffer";
18
+ FeatureFlag["IncomingTransactions"] = "confirmations_incoming_transactions";
17
19
  FeatureFlag["Transactions"] = "confirmations_transactions";
18
20
  })(FeatureFlag || (FeatureFlag = {}));
19
21
  const log = createModuleLogger(projectLogger, 'feature-flags');
@@ -143,6 +145,18 @@ export function getGasEstimateBuffer({ chainId, isCustomRPC, isUpgradeWithDataTo
143
145
  gasBufferFlags?.default ??
144
146
  DEFAULT_GAS_ESTIMATE_BUFFER);
145
147
  }
148
+ /**
149
+ * Retrieves the incoming transactions polling interval.
150
+ * Defaults to 4 minutes if not set.
151
+ *
152
+ * @param messenger - The controller messenger instance.
153
+ * @returns The incoming transactions polling interval in milliseconds.
154
+ */
155
+ export function getIncomingTransactionsPollingInterval(messenger) {
156
+ const featureFlags = getFeatureFlags(messenger);
157
+ return (featureFlags?.[FeatureFlag.IncomingTransactions]?.pollingIntervalMs ??
158
+ DEFAULT_INCOMING_TRANSACTIONS_POLLING_INTERVAL_MS);
159
+ }
146
160
  /**
147
161
  * Retrieves the relevant feature flags from the remote feature flag controller.
148
162
  *
@@ -1 +1 @@
1
- {"version":3,"file":"feature-flags.mjs","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAY,wBAAwB;AAE/D,OAAO,EAAE,gBAAgB,EAAE,wBAAoB;AAC/C,OAAO,EAAE,kBAAkB,EAAE,oBAAgB;AAC7C,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAG1C,MAAM,wBAAwB,GAAG,EAAE,CAAC;AACpC,MAAM,qCAAqC,GAAG,EAAE,CAAC;AACjD,MAAM,uCAAuC,GAAG,CAAC,GAAG,IAAI,CAAC;AACzD,MAAM,2CAA2C,GAAG,EAAE,CAAC;AACvD,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAEtC;;GAEG;AACH,MAAM,CAAN,IAAY,W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AAyB,EAAE,YAAY,CAAC,CAAC;IAE7C,OAAO,YAAiD,CAAC;AAC3D,CAAC","sourcesContent":["import { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { isValidSignature } from './signature';\nimport { padHexToEvenLength } from './utils';\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\n\nconst DEFAULT_BATCH_SIZE_LIMIT = 10;\nconst DEFAULT_ACCELERATED_POLLING_COUNT_MAX = 10;\nconst DEFAULT_ACCELERATED_POLLING_INTERVAL_MS = 3 * 1000;\nconst DEFAULT_GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;\nconst DEFAULT_GAS_ESTIMATE_BUFFER = 1;\n\n/**\n * Feature flags supporting the transaction controller.\n */\nexport enum FeatureFlag {\n EIP7702 = 'confirmations_eip_7702',\n GasBuffer = 'confirmations_gas_buffer',\n Transactions = 'confirmations_transactions',\n}\n\ntype GasEstimateFallback = {\n /**\n * The fixed gas estimate fallback for a transaction.\n */\n fixed?: number;\n\n /**\n * The percentage multiplier gas estimate fallback for a transaction.\n */\n percentage?: number;\n};\n\nexport type TransactionControllerFeatureFlags = {\n /** Feature flags to support EIP-7702 / type-4 transactions. */\n [FeatureFlag.EIP7702]?: {\n /**\n * All contracts that support EIP-7702 batch transactions.\n * Keyed by chain ID.\n * First entry in each array is the contract that standard EOAs will be upgraded to.\n */\n contracts?: Record<\n Hex,\n {\n /** Address of the smart contract. */\n address: Hex;\n\n /** Signature to verify the contract is authentic. */\n signature: Hex;\n }[]\n >;\n\n /** Chains enabled for EIP-7702 batch transactions. */\n supportedChains?: Hex[];\n };\n\n /**\n * Buffers added to gas limit estimations.\n * Values are multipliers such as `1.5` meaning 150% of the original gas limit.\n */\n [FeatureFlag.GasBuffer]?: {\n /** Fallback buffer for all chains and transactions. */\n default?: number;\n\n /**\n * Buffer for included network RPCs only and not those added by user.\n * Takes priority over `default`.\n */\n included?: number;\n\n /** Buffers for specific chains. */\n perChainConfig?: {\n [chainId: Hex]: {\n /**\n * Buffer for the chain for all transactions.\n * Takes priority over non-chain `included`.\n */\n base?: number;\n\n /**\n * Buffer if network RPC is included and not added by user.\n * Takes priority over `base`.\n */\n included?: number;\n\n /**\n * Buffer for the chain for EIP-7702 / type 4 transactions only.\n * Only if `data` included and `to` matches `from`.\n * Takes priority over `included` and `base`.\n */\n eip7702?: number;\n };\n };\n };\n\n /** Miscellaneous feature flags to support the transaction controller. */\n [FeatureFlag.Transactions]?: {\n /** Maximum number of transactions that can be in an external batch. */\n batchSizeLimit?: number;\n\n /**\n * Accelerated polling is used to speed up the polling process for\n * transactions that are not yet confirmed.\n */\n acceleratedPolling?: {\n /** Accelerated polling parameters on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: {\n /**\n * Maximum number of polling requests that can be made in a row, before\n * the normal polling resumes.\n */\n countMax?: number;\n\n /** Interval between polling requests in milliseconds. */\n intervalMs?: number;\n };\n };\n\n /** Default `countMax` in case no chain-specific parameter is set. */\n defaultCountMax?: number;\n\n /** Default `intervalMs` in case no chain-specific parameter is set. */\n defaultIntervalMs?: number;\n };\n\n gasFeeRandomisation?: {\n /** Randomised gas fee digits per chainId. */\n randomisedGasFeeDigits?: Record<Hex, number>;\n\n /** Number of digits to preserve for randomised gas fee digits. */\n preservedNumberOfDigits?: number;\n };\n\n /** Gas estimate fallback is used as a fallback in case of failure to obtain the gas estimate values. */\n gasEstimateFallback?: {\n /** Gas estimate fallback per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: GasEstimateFallback;\n };\n\n /**\n * Default gas estimate fallback.\n * This value is used when no specific gas estimate fallback is found for a chain ID.\n */\n default?: GasEstimateFallback;\n };\n };\n};\n\nconst log = createModuleLogger(projectLogger, 'feature-flags');\n\n/**\n * Retrieves the supported EIP-7702 chains.\n *\n * @param messenger - The controller messenger instance.\n * @returns The supported chains.\n */\nexport function getEIP7702SupportedChains(\n messenger: TransactionControllerMessenger,\n): Hex[] {\n const featureFlags = getFeatureFlags(messenger);\n return featureFlags?.[FeatureFlag.EIP7702]?.supportedChains ?? [];\n}\n\n/**\n * Retrieves the supported EIP-7702 contract addresses for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @param publicKey - The public key used to validate the contract authenticity.\n * @returns The supported contract addresses.\n */\nexport function getEIP7702ContractAddresses(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n publicKey: Hex,\n): Hex[] {\n const featureFlags = getFeatureFlags(messenger);\n\n const contracts =\n featureFlags?.[FeatureFlag.EIP7702]?.contracts?.[\n chainId.toLowerCase() as Hex\n ] ?? [];\n\n return contracts\n .filter((contract) =>\n isValidSignature(\n [contract.address, padHexToEvenLength(chainId) as Hex],\n contract.signature,\n publicKey,\n ),\n )\n .map((contract) => contract.address);\n}\n\n/**\n * Retrieves the EIP-7702 upgrade contract address.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @param publicKey - The public key used to validate the contract authenticity.\n * @returns The upgrade contract address.\n */\nexport function getEIP7702UpgradeContractAddress(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n publicKey: Hex,\n): Hex | undefined {\n return getEIP7702ContractAddresses(chainId, messenger, publicKey)?.[0];\n}\n\n/**\n * Retrieves the batch size limit.\n * Defaults to 10 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The batch size limit.\n */\nexport function getBatchSizeLimit(\n messenger: TransactionControllerMessenger,\n): number {\n const featureFlags = getFeatureFlags(messenger);\n return (\n featureFlags?.[FeatureFlag.Transactions]?.batchSizeLimit ??\n DEFAULT_BATCH_SIZE_LIMIT\n );\n}\n\n/**\n * Retrieves the accelerated polling parameters for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The accelerated polling parameters: `countMax` and `intervalMs`.\n */\nexport function getAcceleratedPollingParams(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): { countMax: number; intervalMs: number } {\n const featureFlags = getFeatureFlags(messenger);\n\n const acceleratedPollingParams =\n featureFlags?.[FeatureFlag.Transactions]?.acceleratedPolling;\n\n const countMax =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.countMax ||\n acceleratedPollingParams?.defaultCountMax ||\n DEFAULT_ACCELERATED_POLLING_COUNT_MAX;\n\n const intervalMs =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.intervalMs ||\n acceleratedPollingParams?.defaultIntervalMs ||\n DEFAULT_ACCELERATED_POLLING_INTERVAL_MS;\n\n return { countMax, intervalMs };\n}\n\n/**\n * Retrieves the gas fee randomisation parameters.\n *\n * @param messenger - The controller messenger instance.\n * @returns The gas fee randomisation parameters.\n */\nexport function getGasFeeRandomisation(\n messenger: TransactionControllerMessenger,\n): {\n randomisedGasFeeDigits: Record<Hex, number>;\n preservedNumberOfDigits: number | undefined;\n} {\n const featureFlags = getFeatureFlags(messenger);\n\n const gasFeeRandomisation =\n featureFlags?.[FeatureFlag.Transactions]?.gasFeeRandomisation || {};\n\n return {\n randomisedGasFeeDigits: gasFeeRandomisation.randomisedGasFeeDigits || {},\n preservedNumberOfDigits: gasFeeRandomisation.preservedNumberOfDigits,\n };\n}\n\n/**\n * Retrieves the gas estimate fallback for a given chain ID.\n * Defaults to the default gas estimate fallback if not set.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The gas estimate fallback.\n */\nexport function getGasEstimateFallback(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): {\n fixed?: number;\n percentage: number;\n} {\n const featureFlags = getFeatureFlags(messenger);\n\n const gasEstimateFallbackFlags =\n featureFlags?.[FeatureFlag.Transactions]?.gasEstimateFallback;\n\n const chainFlags = gasEstimateFallbackFlags?.perChainConfig?.[chainId];\n\n const percentage =\n chainFlags?.percentage ??\n gasEstimateFallbackFlags?.default?.percentage ??\n DEFAULT_GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT;\n\n const fixed = chainFlags?.fixed ?? gasEstimateFallbackFlags?.default?.fixed;\n\n return { fixed, percentage };\n}\n\n/**\n * Retrieves the gas buffers for a given chain ID.\n *\n * @param request - The request object.\n * @param request.chainId - The chain ID.\n * @param request.isCustomRPC - Whether the network RPC is added by the user.\n * @param request.isUpgradeWithDataToSelf - Whether the transaction is an EIP-7702 upgrade with data to self.\n * @param request.messenger - The controller messenger instance.\n * @returns The gas buffers.\n */\nexport function getGasEstimateBuffer({\n chainId,\n isCustomRPC,\n isUpgradeWithDataToSelf,\n messenger,\n}: {\n chainId: Hex;\n isCustomRPC: boolean;\n isUpgradeWithDataToSelf: boolean;\n messenger: TransactionControllerMessenger;\n}): number {\n const featureFlags = getFeatureFlags(messenger);\n const gasBufferFlags = featureFlags?.[FeatureFlag.GasBuffer];\n const chainFlags = gasBufferFlags?.perChainConfig?.[chainId];\n const chainIncludedRPCBuffer = isCustomRPC ? undefined : chainFlags?.included;\n\n const defaultIncludedRPCBuffer = isCustomRPC\n ? undefined\n : gasBufferFlags?.included;\n\n const upgradeBuffer = isUpgradeWithDataToSelf\n ? chainFlags?.eip7702\n : undefined;\n\n return (\n upgradeBuffer ??\n chainIncludedRPCBuffer ??\n chainFlags?.base ??\n defaultIncludedRPCBuffer ??\n gasBufferFlags?.default ??\n DEFAULT_GAS_ESTIMATE_BUFFER\n );\n}\n\n/**\n * Retrieves the relevant feature flags from the remote feature flag controller.\n *\n * @param messenger - The messenger instance.\n * @returns The feature flags.\n */\nfunction getFeatureFlags(\n messenger: TransactionControllerMessenger,\n): TransactionControllerFeatureFlags {\n const featureFlags = messenger.call(\n 'RemoteFeatureFlagController:getState',\n ).remoteFeatureFlags;\n\n log('Retrieved feature flags', featureFlags);\n\n return featureFlags as TransactionControllerFeatureFlags;\n}\n"]}
1
+ {"version":3,"file":"feature-flags.mjs","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAY,wBAAwB;AAE/D,OAAO,EAAE,gBAAgB,EAAE,wBAAoB;AAC/C,OAAO,EAAE,kBAAkB,E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;IAE7B,MAAM,aAAa,GAAG,uBAAuB;QAC3C,CAAC,CAAC,UAAU,EAAE,OAAO;QACrB,CAAC,CAAC,SAAS,CAAC;IAEd,OAAO,CACL,aAAa;QACb,sBAAsB;QACtB,UAAU,EAAE,IAAI;QAChB,wBAAwB;QACxB,cAAc,EAAE,OAAO;QACvB,2BAA2B,CAC5B,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,sCAAsC,CACpD,SAAyC;IAEzC,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IAEhD,OAAO,CACL,YAAY,EAAE,CAAC,WAAW,CAAC,oBAAoB,CAAC,EAAE,iBAAiB;QACnE,iDAAiD,CAClD,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CACtB,SAAyC;IAEzC,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CACjC,sCAAsC,CACvC,CAAC,kBAAkB,CAAC;IAErB,GAAG,CAAC,yBAAyB,EAAE,YAAY,CAAC,CAAC;IAE7C,OAAO,YAAiD,CAAC;AAC3D,CAAC","sourcesContent":["import { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { isValidSignature } from './signature';\nimport { padHexToEvenLength } from './utils';\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\n\nconst DEFAULT_BATCH_SIZE_LIMIT = 10;\nconst DEFAULT_ACCELERATED_POLLING_COUNT_MAX = 10;\nconst DEFAULT_ACCELERATED_POLLING_INTERVAL_MS = 3 * 1000;\nconst DEFAULT_GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT = 35;\nconst DEFAULT_GAS_ESTIMATE_BUFFER = 1;\nconst DEFAULT_INCOMING_TRANSACTIONS_POLLING_INTERVAL_MS = 1000 * 60 * 4; // 4 Minutes\n\n/**\n * Feature flags supporting the transaction controller.\n */\nexport enum FeatureFlag {\n EIP7702 = 'confirmations_eip_7702',\n GasBuffer = 'confirmations_gas_buffer',\n IncomingTransactions = 'confirmations_incoming_transactions',\n Transactions = 'confirmations_transactions',\n}\n\ntype GasEstimateFallback = {\n /**\n * The fixed gas estimate fallback for a transaction.\n */\n fixed?: number;\n\n /**\n * The percentage multiplier gas estimate fallback for a transaction.\n */\n percentage?: number;\n};\n\nexport type TransactionControllerFeatureFlags = {\n /** Feature flags to support EIP-7702 / type-4 transactions. */\n [FeatureFlag.EIP7702]?: {\n /**\n * All contracts that support EIP-7702 batch transactions.\n * Keyed by chain ID.\n * First entry in each array is the contract that standard EOAs will be upgraded to.\n */\n contracts?: Record<\n Hex,\n {\n /** Address of the smart contract. */\n address: Hex;\n\n /** Signature to verify the contract is authentic. */\n signature: Hex;\n }[]\n >;\n\n /** Chains enabled for EIP-7702 batch transactions. */\n supportedChains?: Hex[];\n };\n\n /**\n * Buffers added to gas limit estimations.\n * Values are multipliers such as `1.5` meaning 150% of the original gas limit.\n */\n [FeatureFlag.GasBuffer]?: {\n /** Fallback buffer for all chains and transactions. */\n default?: number;\n\n /**\n * Buffer for included network RPCs only and not those added by user.\n * Takes priority over `default`.\n */\n included?: number;\n\n /** Buffers for specific chains. */\n perChainConfig?: {\n [chainId: Hex]: {\n /**\n * Buffer for the chain for all transactions.\n * Takes priority over non-chain `included`.\n */\n base?: number;\n\n /**\n * Buffer if network RPC is included and not added by user.\n * Takes priority over `base`.\n */\n included?: number;\n\n /**\n * Buffer for the chain for EIP-7702 / type 4 transactions only.\n * Only if `data` included and `to` matches `from`.\n * Takes priority over `included` and `base`.\n */\n eip7702?: number;\n };\n };\n };\n\n /** Incoming transaction configuration. */\n [FeatureFlag.IncomingTransactions]?: {\n /** Interval between requests to accounts API to retrieve incoming transactions. */\n pollingIntervalMs?: number;\n };\n\n /** Miscellaneous feature flags to support the transaction controller. */\n [FeatureFlag.Transactions]?: {\n /** Maximum number of transactions that can be in an external batch. */\n batchSizeLimit?: number;\n\n /**\n * Accelerated polling is used to speed up the polling process for\n * transactions that are not yet confirmed.\n */\n acceleratedPolling?: {\n /** Accelerated polling parameters on a per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: {\n /**\n * Maximum number of polling requests that can be made in a row, before\n * the normal polling resumes.\n */\n countMax?: number;\n\n /** Interval between polling requests in milliseconds. */\n intervalMs?: number;\n };\n };\n\n /** Default `countMax` in case no chain-specific parameter is set. */\n defaultCountMax?: number;\n\n /** Default `intervalMs` in case no chain-specific parameter is set. */\n defaultIntervalMs?: number;\n };\n\n gasFeeRandomisation?: {\n /** Randomised gas fee digits per chainId. */\n randomisedGasFeeDigits?: Record<Hex, number>;\n\n /** Number of digits to preserve for randomised gas fee digits. */\n preservedNumberOfDigits?: number;\n };\n\n /** Gas estimate fallback is used as a fallback in case of failure to obtain the gas estimate values. */\n gasEstimateFallback?: {\n /** Gas estimate fallback per-chain basis. */\n perChainConfig?: {\n [chainId: Hex]: GasEstimateFallback;\n };\n\n /**\n * Default gas estimate fallback.\n * This value is used when no specific gas estimate fallback is found for a chain ID.\n */\n default?: GasEstimateFallback;\n };\n };\n};\n\nconst log = createModuleLogger(projectLogger, 'feature-flags');\n\n/**\n * Retrieves the supported EIP-7702 chains.\n *\n * @param messenger - The controller messenger instance.\n * @returns The supported chains.\n */\nexport function getEIP7702SupportedChains(\n messenger: TransactionControllerMessenger,\n): Hex[] {\n const featureFlags = getFeatureFlags(messenger);\n return featureFlags?.[FeatureFlag.EIP7702]?.supportedChains ?? [];\n}\n\n/**\n * Retrieves the supported EIP-7702 contract addresses for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @param publicKey - The public key used to validate the contract authenticity.\n * @returns The supported contract addresses.\n */\nexport function getEIP7702ContractAddresses(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n publicKey: Hex,\n): Hex[] {\n const featureFlags = getFeatureFlags(messenger);\n\n const contracts =\n featureFlags?.[FeatureFlag.EIP7702]?.contracts?.[\n chainId.toLowerCase() as Hex\n ] ?? [];\n\n return contracts\n .filter((contract) =>\n isValidSignature(\n [contract.address, padHexToEvenLength(chainId) as Hex],\n contract.signature,\n publicKey,\n ),\n )\n .map((contract) => contract.address);\n}\n\n/**\n * Retrieves the EIP-7702 upgrade contract address.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @param publicKey - The public key used to validate the contract authenticity.\n * @returns The upgrade contract address.\n */\nexport function getEIP7702UpgradeContractAddress(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n publicKey: Hex,\n): Hex | undefined {\n return getEIP7702ContractAddresses(chainId, messenger, publicKey)?.[0];\n}\n\n/**\n * Retrieves the batch size limit.\n * Defaults to 10 if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The batch size limit.\n */\nexport function getBatchSizeLimit(\n messenger: TransactionControllerMessenger,\n): number {\n const featureFlags = getFeatureFlags(messenger);\n return (\n featureFlags?.[FeatureFlag.Transactions]?.batchSizeLimit ??\n DEFAULT_BATCH_SIZE_LIMIT\n );\n}\n\n/**\n * Retrieves the accelerated polling parameters for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The accelerated polling parameters: `countMax` and `intervalMs`.\n */\nexport function getAcceleratedPollingParams(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): { countMax: number; intervalMs: number } {\n const featureFlags = getFeatureFlags(messenger);\n\n const acceleratedPollingParams =\n featureFlags?.[FeatureFlag.Transactions]?.acceleratedPolling;\n\n const countMax =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.countMax ||\n acceleratedPollingParams?.defaultCountMax ||\n DEFAULT_ACCELERATED_POLLING_COUNT_MAX;\n\n const intervalMs =\n acceleratedPollingParams?.perChainConfig?.[chainId]?.intervalMs ||\n acceleratedPollingParams?.defaultIntervalMs ||\n DEFAULT_ACCELERATED_POLLING_INTERVAL_MS;\n\n return { countMax, intervalMs };\n}\n\n/**\n * Retrieves the gas fee randomisation parameters.\n *\n * @param messenger - The controller messenger instance.\n * @returns The gas fee randomisation parameters.\n */\nexport function getGasFeeRandomisation(\n messenger: TransactionControllerMessenger,\n): {\n randomisedGasFeeDigits: Record<Hex, number>;\n preservedNumberOfDigits: number | undefined;\n} {\n const featureFlags = getFeatureFlags(messenger);\n\n const gasFeeRandomisation =\n featureFlags?.[FeatureFlag.Transactions]?.gasFeeRandomisation || {};\n\n return {\n randomisedGasFeeDigits: gasFeeRandomisation.randomisedGasFeeDigits || {},\n preservedNumberOfDigits: gasFeeRandomisation.preservedNumberOfDigits,\n };\n}\n\n/**\n * Retrieves the gas estimate fallback for a given chain ID.\n * Defaults to the default gas estimate fallback if not set.\n *\n * @param chainId - The chain ID.\n * @param messenger - The controller messenger instance.\n * @returns The gas estimate fallback.\n */\nexport function getGasEstimateFallback(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): {\n fixed?: number;\n percentage: number;\n} {\n const featureFlags = getFeatureFlags(messenger);\n\n const gasEstimateFallbackFlags =\n featureFlags?.[FeatureFlag.Transactions]?.gasEstimateFallback;\n\n const chainFlags = gasEstimateFallbackFlags?.perChainConfig?.[chainId];\n\n const percentage =\n chainFlags?.percentage ??\n gasEstimateFallbackFlags?.default?.percentage ??\n DEFAULT_GAS_ESTIMATE_FALLBACK_BLOCK_PERCENT;\n\n const fixed = chainFlags?.fixed ?? gasEstimateFallbackFlags?.default?.fixed;\n\n return { fixed, percentage };\n}\n\n/**\n * Retrieves the gas buffers for a given chain ID.\n *\n * @param request - The request object.\n * @param request.chainId - The chain ID.\n * @param request.isCustomRPC - Whether the network RPC is added by the user.\n * @param request.isUpgradeWithDataToSelf - Whether the transaction is an EIP-7702 upgrade with data to self.\n * @param request.messenger - The controller messenger instance.\n * @returns The gas buffers.\n */\nexport function getGasEstimateBuffer({\n chainId,\n isCustomRPC,\n isUpgradeWithDataToSelf,\n messenger,\n}: {\n chainId: Hex;\n isCustomRPC: boolean;\n isUpgradeWithDataToSelf: boolean;\n messenger: TransactionControllerMessenger;\n}): number {\n const featureFlags = getFeatureFlags(messenger);\n const gasBufferFlags = featureFlags?.[FeatureFlag.GasBuffer];\n const chainFlags = gasBufferFlags?.perChainConfig?.[chainId];\n const chainIncludedRPCBuffer = isCustomRPC ? undefined : chainFlags?.included;\n\n const defaultIncludedRPCBuffer = isCustomRPC\n ? undefined\n : gasBufferFlags?.included;\n\n const upgradeBuffer = isUpgradeWithDataToSelf\n ? chainFlags?.eip7702\n : undefined;\n\n return (\n upgradeBuffer ??\n chainIncludedRPCBuffer ??\n chainFlags?.base ??\n defaultIncludedRPCBuffer ??\n gasBufferFlags?.default ??\n DEFAULT_GAS_ESTIMATE_BUFFER\n );\n}\n\n/**\n * Retrieves the incoming transactions polling interval.\n * Defaults to 4 minutes if not set.\n *\n * @param messenger - The controller messenger instance.\n * @returns The incoming transactions polling interval in milliseconds.\n */\nexport function getIncomingTransactionsPollingInterval(\n messenger: TransactionControllerMessenger,\n): number {\n const featureFlags = getFeatureFlags(messenger);\n\n return (\n featureFlags?.[FeatureFlag.IncomingTransactions]?.pollingIntervalMs ??\n DEFAULT_INCOMING_TRANSACTIONS_POLLING_INTERVAL_MS\n );\n}\n\n/**\n * Retrieves the relevant feature flags from the remote feature flag controller.\n *\n * @param messenger - The messenger instance.\n * @returns The feature flags.\n */\nfunction getFeatureFlags(\n messenger: TransactionControllerMessenger,\n): TransactionControllerFeatureFlags {\n const featureFlags = messenger.call(\n 'RemoteFeatureFlagController:getState',\n ).remoteFeatureFlags;\n\n log('Retrieved feature flags', featureFlags);\n\n return featureFlags as TransactionControllerFeatureFlags;\n}\n"]}
@@ -12,6 +12,7 @@ var ErrorCode;
12
12
  (function (ErrorCode) {
13
13
  ErrorCode[ErrorCode["DuplicateBundleId"] = 5720] = "DuplicateBundleId";
14
14
  ErrorCode[ErrorCode["BundleTooLarge"] = 5740] = "BundleTooLarge";
15
+ ErrorCode[ErrorCode["RejectedUpgrade"] = 5750] = "RejectedUpgrade";
15
16
  })(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
16
17
  const TRANSACTION_ENVELOPE_TYPES_FEE_MARKET = [
17
18
  types_1.TransactionEnvelopeType.feeMarket,
@@ -1 +1 @@
1
- {"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAC/C,iEAAgF;AAChF,mEAAuD;AACvD,qDAA+E;AAE/E,2CAA8D;AAE9D,uCAA+C;AAE/C,wCAIkB;AAElB,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,sEAAwB,CAAA;IACxB,gEAAqB,CAAA;AACvB,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAED,MAAM,qCAAqC,GAAG;IAC5C,+BAAuB,CAAC,SAAS;IACjC,+BAAuB,CAAC,OAAO;CAChC,CAAC;AASF;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,yBAAyB,CAAC,EAC9C,IAAI,EACJ,IAAI,EACJ,gBAAgB,EAChB,MAAM,EACN,kBAAkB,EAClB,QAAQ,EACR,IAAI,GAUL;IACC,MAAM,UAAU,GAAG,CAAC,MAAM,IAAI,MAAM,KAAK,kCAAe,CAAC;IAEzD,IAAI,UAAU,EAAE;QACd,OAAO;KACR;IAED,MAAM,EAAE,iBAAiB,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC;IAE/D,IAAI,kBAAkB,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QAC5D,MAAM,2BAAc,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;KACzD;IAED,IAAI,IAAI,KAAK,uBAAe,CAAC,KAAK,EAAE;QAClC,OAAO;KACR;IAED,IAAI,iBAAiB,IAAI,YAAY,KAAK,+BAAuB,CAAC,OAAO,EAAE;QACzE,MAAM,sBAAS,CAAC,aAAa,CAC3B,kDAAkD,CACnD,CAAC;KACH;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,KAAK,IA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AE3E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE;QACrC,MAAM,sBAAS,CAAC,aAAa,CAC3B,gEAAgE,CACjE,CAAC;KACH;IAED,KAAK,MAAM,aAAa,IAAI,iBAAiB,EAAE;QAC7C,qBAAqB,CAAC,aAAa,CAAC,CAAC;KACtC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,qBAAqB,CAAC,aAA4B;IACzD,qBAAqB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAChD,iBAAiB,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;IAExD,KAAK,MAAM,KAAK,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAU,EAAE;QAC3D,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE;YACxB,qBAAqB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;SAC7C;KACF;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC;IAElC,IAAI,OAAO,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QAC/C,MAAM,sBAAS,CAAC,aAAa,CAC3B,mEAAmE,OAAO,EAAE,CAC7E,CAAC;KACH;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,iBAAiB,CACxB,KAAa,EACb,WAAmB,EACnB,SAAiB;IAEjB,MAAM,iBAAiB,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAErD,IAAI,iBAAiB,KAAK,WAAW,EAAE;QACrC,MAAM,sBAAS,CAAC,aAAa,CAC3B,+BAA+B,SAAS,YAAY,WAAW,gBAAgB,iBAAiB,QAAQ,CACzG,CAAC;KACH;AACH,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport { ORIGIN_METAMASK, isValidHexAddress } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { JsonRpcError, providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Hex } from '@metamask/utils';\nimport { isStrictHexString, remove0x } from '@metamask/utils';\n\nimport { isEIP1559Transaction } from './utils';\nimport type { Authorization, TransactionBatchRequest } from '../types';\nimport {\n TransactionEnvelopeType,\n TransactionType,\n type TransactionParams,\n} from '../types';\n\nexport enum ErrorCode {\n DuplicateBundleId = 5720,\n BundleTooLarge = 5740,\n}\n\nconst TRANSACTION_ENVELOPE_TYPES_FEE_MARKET = [\n TransactionEnvelopeType.feeMarket,\n TransactionEnvelopeType.setCode,\n];\n\ntype GasFieldsToValidate =\n | 'gasPrice'\n | 'maxFeePerGas'\n | 'maxPriorityFeePerGas'\n | 'gas'\n | 'gasLimit';\n\n/**\n * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.\n *\n * @param options - Options bag.\n * @param options.data - The data included in the transaction.\n * @param options.from - The address from which the transaction is initiated.\n * @param options.internalAccounts - The internal accounts added to the wallet.\n * @param options.origin - The origin or source of the transaction.\n * @param options.permittedAddresses - The permitted accounts for the given origin.\n * @param options.selectedAddress - The currently selected Ethereum address in the wallet.\n * @param options.txParams - The transaction parameters.\n * @param options.type - The transaction type.\n * @throws Throws an error if the transaction is not permitted.\n */\nexport async function validateTransactionOrigin({\n data,\n from,\n internalAccounts,\n origin,\n permittedAddresses,\n txParams,\n type,\n}: {\n data?: string;\n from: string;\n internalAccounts?: string[];\n origin?: string;\n permittedAddresses?: string[];\n selectedAddress?: string;\n txParams: TransactionParams;\n type?: TransactionType;\n}) {\n const isInternal = !origin || origin === ORIGIN_METAMASK;\n\n if (isInternal) {\n return;\n }\n\n const { authorizationList, to, type: envelopeType } = txParams;\n\n if (permittedAddresses && !permittedAddresses.includes(from)) {\n throw providerErrors.unauthorized({ data: { origin } });\n }\n\n if (type === TransactionType.batch) {\n return;\n }\n\n if (authorizationList || envelopeType === TransactionEnvelopeType.setCode) {\n throw rpcErrors.invalidParams(\n 'External EIP-7702 transactions are not supported',\n );\n }\n\n const hasData = Boolean(data && data !== '0x');\n\n if (\n hasData &&\n internalAccounts?.some(\n (account) => account.toLowerCase() === to?.toLowerCase(),\n )\n ) {\n throw rpcErrors.invalidParams(\n 'External transactions to internal accounts cannot include data',\n );\n }\n}\n\n/**\n * Validates the transaction params for required properties and throws in\n * the event of any validation error.\n *\n * @param txParams - Transaction params object to validate.\n * @param isEIP1559Compatible - whether or not the current network supports EIP-1559 transactions.\n * @param chainId - The chain ID of the transaction.\n */\nexport function validateTxParams(\n txParams: TransactionParams,\n isEIP1559Compatible = true,\n chainId?: Hex,\n) {\n validateEnvelopeType(txParams.type);\n validateEIP1559Compatibility(txParams, isEIP1559Compatible);\n validateParamFrom(txParams.from);\n validateParamRecipient(txParams);\n validateParamValue(txParams.value);\n validateParamData(txParams.data);\n validateParamChainId(txParams.chainId, chainId);\n validateGasFeeParams(txParams);\n validateAuthorizationList(txParams);\n}\n\n/**\n * Validates the `type` property, ensuring that if it is specified, it is a valid transaction envelope type.\n *\n * @param type - The transaction envelope type to validate.\n * @throws Throws invalid params if the type is not a valid transaction envelope type.\n */\nfunction validateEnvelopeType(type: string | undefined) {\n if (\n type &&\n !Object.values(TransactionEnvelopeType).includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: \"${type}\". Must be one of: ${Object.values(\n TransactionEnvelopeType,\n ).join(', ')}`,\n );\n }\n}\n\n/**\n * Validates EIP-1559 compatibility for transaction creation.\n *\n * @param txParams - The transaction parameters to validate.\n * @param isEIP1559Compatible - Indicates if the current network supports EIP-1559.\n * @throws Throws invalid params if the transaction specifies EIP-1559 but the network does not support it.\n */\nfunction validateEIP1559Compatibility(\n txParams: TransactionParams,\n isEIP1559Compatible: boolean,\n) {\n if (isEIP1559Transaction(txParams) && !isEIP1559Compatible) {\n throw rpcErrors.invalidParams(\n 'Invalid transaction params: params specify an EIP-1559 transaction but the current network does not support EIP-1559',\n );\n }\n}\n\n/**\n * Validates value property, ensuring it is a valid positive integer number\n * denominated in wei.\n *\n * @param value - The value to validate, expressed as a string.\n * @throws Throws an error if the value is not a valid positive integer\n * number denominated in wei.\n * - If the value contains a hyphen (-), it is considered invalid.\n * - If the value contains a decimal point (.), it is considered invalid.\n * - If the value is not a finite number, is NaN, or is not a safe integer, it is considered invalid.\n */\nfunction validateParamValue(value?: string) {\n if (value !== undefined) {\n if (value.includes('-')) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value \"${value}\": not a positive number.`,\n );\n }\n\n if (value.includes('.')) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value \"${value}\": number must be in wei.`,\n );\n }\n const intValue = parseInt(value, 10);\n const isValid =\n Number.isFinite(intValue) &&\n !Number.isNaN(intValue) &&\n !isNaN(Number(value)) &&\n Number.isSafeInteger(intValue);\n if (!isValid) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value ${value}: number must be a valid number.`,\n );\n }\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param txParams - The transaction parameters object to validate.\n * @throws Throws an error if the recipient address is invalid:\n * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,\n * the \"to\" field is removed from the transaction parameters.\n * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.\n */\nfunction validateParamRecipient(txParams: TransactionParams) {\n if (txParams.to === '0x' || txParams.to === undefined) {\n if (txParams.data) {\n delete txParams.to;\n } else {\n throw rpcErrors.invalidParams(`Invalid \"to\" address.`);\n }\n } else if (txParams.to !== undefined && !isValidHexAddress(txParams.to)) {\n throw rpcErrors.invalidParams(`Invalid \"to\" address.`);\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param from - The from property to validate.\n * @throws Throws an error if the recipient address is invalid:\n * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,\n * the \"to\" field is removed from the transaction parameters.\n * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.\n */\nfunction validateParamFrom(from: string) {\n if (!from || typeof from !== 'string') {\n throw rpcErrors.invalidParams(\n `Invalid \"from\" address ${from}: not a string.`,\n );\n }\n if (!isValidHexAddress(from)) {\n throw rpcErrors.invalidParams('Invalid \"from\" address.');\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param to - The to property to validate.\n * @throws Throws an error if the recipient address is invalid.\n */\nexport function validateParamTo(to?: string) {\n if (!to || typeof to !== 'string') {\n throw rpcErrors.invalidParams(`Invalid \"to\" address`);\n }\n}\n\n/**\n * Validates a transaction batch request.\n *\n * @param options - Options bag.\n * @param options.internalAccounts - The internal accounts added to the wallet.\n * @param options.request - The batch request object.\n * @param options.sizeLimit - The maximum number of calls allowed in a batch request.\n */\nexport function validateBatchRequest({\n internalAccounts,\n request,\n sizeLimit,\n}: {\n internalAccounts: string[];\n request: TransactionBatchRequest;\n sizeLimit: number;\n}) {\n const { origin } = request;\n const isExternal = origin && origin !== ORIGIN_METAMASK;\n\n const internalAccountsNormalized = internalAccounts.map((account) =>\n account.toLowerCase(),\n );\n\n if (\n isExternal &&\n request.transactions.some((nestedTransaction) => {\n const normalizedCallTo =\n nestedTransaction.params.to?.toLowerCase() as string;\n\n const callData = nestedTransaction.params.data;\n\n const isInternalAccount =\n internalAccountsNormalized.includes(normalizedCallTo);\n\n const hasData = Boolean(callData && callData !== '0x');\n\n return isInternalAccount && hasData;\n })\n ) {\n throw rpcErrors.invalidParams(\n 'External calls to internal accounts cannot include data',\n );\n }\n\n if (isExternal && request.transactions.length > sizeLimit) {\n throw new JsonRpcError(\n ErrorCode.BundleTooLarge,\n `Batch size cannot exceed ${sizeLimit}. got: ${request.transactions.length}`,\n );\n }\n}\n\n/**\n * Validates input data for transactions.\n *\n * @param value - The input data to validate.\n * @throws Throws invalid params if the input data is invalid.\n */\nfunction validateParamData(value?: string) {\n if (value) {\n const ERC20Interface = new Interface(abiERC20);\n try {\n ERC20Interface.parseTransaction({ data: value });\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n if (error.message.match(/BUFFER_OVERRUN/u)) {\n throw rpcErrors.invalidParams(\n 'Invalid transaction params: data out-of-bounds, BUFFER_OVERRUN.',\n );\n }\n }\n }\n}\n\n/**\n * Validates chainId type.\n *\n * @param chainIdParams - The chain ID to validate.\n * @param chainIdNetworkClient - The chain ID of the network client.\n */\nfunction validateParamChainId(chainIdParams?: Hex, chainIdNetworkClient?: Hex) {\n if (\n chainIdParams &&\n chainIdNetworkClient &&\n chainIdParams.toLowerCase?.() !== chainIdNetworkClient.toLowerCase()\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: chainId must match the network client, got: ${chainIdParams}, expected: ${chainIdNetworkClient}`,\n );\n }\n}\n\n/**\n * Validates gas values.\n *\n * @param txParams - The transaction parameters to validate.\n */\nfunction validateGasFeeParams(txParams: TransactionParams) {\n if (txParams.gasPrice) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'gasPrice');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'gasPrice',\n 'maxFeePerGas',\n );\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'gasPrice',\n 'maxPriorityFeePerGas',\n );\n ensureFieldIsValidHex(txParams, 'gasPrice');\n }\n\n if (txParams.maxFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'maxFeePerGas');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsValidHex(txParams, 'maxFeePerGas');\n }\n\n if (txParams.maxPriorityFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(\n txParams,\n 'maxPriorityFeePerGas',\n );\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxPriorityFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsValidHex(txParams, 'maxPriorityFeePerGas');\n }\n\n if (txParams.gasLimit) {\n ensureFieldIsValidHex(txParams, 'gasLimit');\n }\n\n if (txParams.gas) {\n ensureFieldIsValidHex(txParams, 'gas');\n }\n}\n\n/**\n * Ensures that the provided txParams has the proper 'type' specified for the\n * given field, if it is provided. If types do not match throws an\n * invalidParams error.\n *\n * @param txParams - The transaction parameters object\n * @param field - The current field being validated\n * @throws {ethErrors.rpc.invalidParams} Throws if type does not match the\n * expectations for provided field.\n */\nfunction ensureProperTransactionEnvelopeTypeProvided(\n txParams: TransactionParams,\n field: keyof TransactionParams,\n) {\n const type = txParams.type as TransactionEnvelopeType | undefined;\n\n switch (field) {\n case 'authorizationList':\n if (type && type !== TransactionEnvelopeType.setCode) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${type}\" but including authorizationList requires type: \"${TransactionEnvelopeType.setCode}\"`,\n );\n }\n break;\n case 'maxFeePerGas':\n case 'maxPriorityFeePerGas':\n if (\n type &&\n !TRANSACTION_ENVELOPE_TYPES_FEE_MARKET.includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${type}\" but including maxFeePerGas and maxPriorityFeePerGas requires type: \"${TRANSACTION_ENVELOPE_TYPES_FEE_MARKET.join(', ')}\"`,\n );\n }\n break;\n case 'gasPrice':\n default:\n if (\n type &&\n TRANSACTION_ENVELOPE_TYPES_FEE_MARKET.includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${type}\" but included a gasPrice instead of maxFeePerGas and maxPriorityFeePerGas`,\n );\n }\n }\n}\n\n/**\n * Given two fields, ensure that the second field is not included in txParams,\n * and if it is throw an invalidParams error.\n *\n * @param txParams - The transaction parameters object\n * @param fieldBeingValidated - The current field being validated\n * @param mutuallyExclusiveField - The field to ensure is not provided\n * @throws {ethErrors.rpc.invalidParams} Throws if mutuallyExclusiveField is\n * present in txParams.\n */\nfunction ensureMutuallyExclusiveFieldsNotProvided(\n txParams: TransactionParams,\n fieldBeingValidated: GasFieldsToValidate,\n mutuallyExclusiveField: GasFieldsToValidate,\n) {\n if (typeof txParams[mutuallyExclusiveField] !== 'undefined') {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: specified ${fieldBeingValidated} but also included ${mutuallyExclusiveField}, these cannot be mixed`,\n );\n }\n}\n\n/**\n * Ensures that the provided value for field is a valid hexadecimal.\n * Throws an invalidParams error if field is not a valid hexadecimal.\n *\n * @param data - The object containing the field\n * @param field - The current field being validated\n * @throws {rpcErrors.invalidParams} Throws if field is not a valid hexadecimal\n */\nfunction ensureFieldIsValidHex<T>(data: T, field: keyof T) {\n const value = data[field];\n if (typeof value !== 'string' || !isStrictHexString(value)) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: ${String(field)} is not a valid hexadecimal string. got: (${String(\n value,\n )})`,\n );\n }\n}\n\n/**\n * Validate the authorization list property in the transaction parameters.\n *\n * @param txParams - The transaction parameters containing the authorization list to validate.\n */\nfunction validateAuthorizationList(txParams: TransactionParams) {\n const { authorizationList } = txParams;\n\n if (!authorizationList) {\n return;\n }\n\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'authorizationList');\n\n if (!Array.isArray(authorizationList)) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: authorizationList must be an array`,\n );\n }\n\n for (const authorization of authorizationList) {\n validateAuthorization(authorization);\n }\n}\n\n/**\n * Validate an authorization object.\n *\n * @param authorization - The authorization object to validate.\n */\nfunction validateAuthorization(authorization: Authorization) {\n ensureFieldIsValidHex(authorization, 'address');\n validateHexLength(authorization.address, 20, 'address');\n\n for (const field of ['chainId', 'nonce', 'r', 's'] as const) {\n if (authorization[field]) {\n ensureFieldIsValidHex(authorization, field);\n }\n }\n\n const { yParity } = authorization;\n\n if (yParity && !['0x', '0x1'].includes(yParity)) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: yParity must be '0x' or '0x1'. got: ${yParity}`,\n );\n }\n}\n\n/**\n * Validate the number of bytes in a hex string.\n *\n * @param value - The hex string to validate.\n * @param lengthBytes - The expected length in bytes.\n * @param fieldName - The name of the field being validated.\n */\nfunction validateHexLength(\n value: string,\n lengthBytes: number,\n fieldName: string,\n) {\n const actualLengthBytes = remove0x(value).length / 2;\n\n if (actualLengthBytes !== lengthBytes) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: ${fieldName} must be ${lengthBytes} bytes. got: ${actualLengthBytes} bytes`,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAC/C,iEAAgF;AAChF,mEAAuD;AACvD,qDAA+E;AAE/E,2CAA8D;AAE9D,uCAA+C;AAE/C,wCAIkB;AAElB,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,sEAAwB,CAAA;IACxB,gEAAqB,CAAA;IACrB,kEAAsB,CAAA;AACxB,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB;AAED,MAAM,qCAAqC,GAAG;IAC5C,+BAAuB,CAAC,SAAS;IACjC,+BAAuB,CAAC,OAAO;CAChC,CAAC;AASF;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,yBAAyB,CAAC,EAC9C,IAAI,EACJ,IAAI,EACJ,gBAAgB,EAChB,MAAM,EACN,kBAAkB,EAClB,QAAQ,EACR,IAAI,GAUL;IACC,MAAM,UAAU,GAAG,CAAC,MAAM,IAAI,MAAM,KAAK,kCAAe,CAAC;IAEzD,IAAI,UAAU,EAAE;QACd,OAAO;KACR;IAED,MAAM,EAAE,iBAAiB,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC;IAE/D,IAAI,kBAAkB,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QAC5D,MAAM,2BAAc,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;KACzD;IAED,IAAI,IAAI,KAAK,uBAAe,CAA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KAAK,WAAW,EAAE;QACrC,MAAM,sBAAS,CAAC,aAAa,CAC3B,+BAA+B,SAAS,YAAY,WAAW,gBAAgB,iBAAiB,QAAQ,CACzG,CAAC;KACH;AACH,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport { ORIGIN_METAMASK, isValidHexAddress } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { JsonRpcError, providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Hex } from '@metamask/utils';\nimport { isStrictHexString, remove0x } from '@metamask/utils';\n\nimport { isEIP1559Transaction } from './utils';\nimport type { Authorization, TransactionBatchRequest } from '../types';\nimport {\n TransactionEnvelopeType,\n TransactionType,\n type TransactionParams,\n} from '../types';\n\nexport enum ErrorCode {\n DuplicateBundleId = 5720,\n BundleTooLarge = 5740,\n RejectedUpgrade = 5750,\n}\n\nconst TRANSACTION_ENVELOPE_TYPES_FEE_MARKET = [\n TransactionEnvelopeType.feeMarket,\n TransactionEnvelopeType.setCode,\n];\n\ntype GasFieldsToValidate =\n | 'gasPrice'\n | 'maxFeePerGas'\n | 'maxPriorityFeePerGas'\n | 'gas'\n | 'gasLimit';\n\n/**\n * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.\n *\n * @param options - Options bag.\n * @param options.data - The data included in the transaction.\n * @param options.from - The address from which the transaction is initiated.\n * @param options.internalAccounts - The internal accounts added to the wallet.\n * @param options.origin - The origin or source of the transaction.\n * @param options.permittedAddresses - The permitted accounts for the given origin.\n * @param options.selectedAddress - The currently selected Ethereum address in the wallet.\n * @param options.txParams - The transaction parameters.\n * @param options.type - The transaction type.\n * @throws Throws an error if the transaction is not permitted.\n */\nexport async function validateTransactionOrigin({\n data,\n from,\n internalAccounts,\n origin,\n permittedAddresses,\n txParams,\n type,\n}: {\n data?: string;\n from: string;\n internalAccounts?: string[];\n origin?: string;\n permittedAddresses?: string[];\n selectedAddress?: string;\n txParams: TransactionParams;\n type?: TransactionType;\n}) {\n const isInternal = !origin || origin === ORIGIN_METAMASK;\n\n if (isInternal) {\n return;\n }\n\n const { authorizationList, to, type: envelopeType } = txParams;\n\n if (permittedAddresses && !permittedAddresses.includes(from)) {\n throw providerErrors.unauthorized({ data: { origin } });\n }\n\n if (type === TransactionType.batch) {\n return;\n }\n\n if (authorizationList || envelopeType === TransactionEnvelopeType.setCode) {\n throw rpcErrors.invalidParams(\n 'External EIP-7702 transactions are not supported',\n );\n }\n\n const hasData = Boolean(data && data !== '0x');\n\n if (\n hasData &&\n internalAccounts?.some(\n (account) => account.toLowerCase() === to?.toLowerCase(),\n )\n ) {\n throw rpcErrors.invalidParams(\n 'External transactions to internal accounts cannot include data',\n );\n }\n}\n\n/**\n * Validates the transaction params for required properties and throws in\n * the event of any validation error.\n *\n * @param txParams - Transaction params object to validate.\n * @param isEIP1559Compatible - whether or not the current network supports EIP-1559 transactions.\n * @param chainId - The chain ID of the transaction.\n */\nexport function validateTxParams(\n txParams: TransactionParams,\n isEIP1559Compatible = true,\n chainId?: Hex,\n) {\n validateEnvelopeType(txParams.type);\n validateEIP1559Compatibility(txParams, isEIP1559Compatible);\n validateParamFrom(txParams.from);\n validateParamRecipient(txParams);\n validateParamValue(txParams.value);\n validateParamData(txParams.data);\n validateParamChainId(txParams.chainId, chainId);\n validateGasFeeParams(txParams);\n validateAuthorizationList(txParams);\n}\n\n/**\n * Validates the `type` property, ensuring that if it is specified, it is a valid transaction envelope type.\n *\n * @param type - The transaction envelope type to validate.\n * @throws Throws invalid params if the type is not a valid transaction envelope type.\n */\nfunction validateEnvelopeType(type: string | undefined) {\n if (\n type &&\n !Object.values(TransactionEnvelopeType).includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: \"${type}\". Must be one of: ${Object.values(\n TransactionEnvelopeType,\n ).join(', ')}`,\n );\n }\n}\n\n/**\n * Validates EIP-1559 compatibility for transaction creation.\n *\n * @param txParams - The transaction parameters to validate.\n * @param isEIP1559Compatible - Indicates if the current network supports EIP-1559.\n * @throws Throws invalid params if the transaction specifies EIP-1559 but the network does not support it.\n */\nfunction validateEIP1559Compatibility(\n txParams: TransactionParams,\n isEIP1559Compatible: boolean,\n) {\n if (isEIP1559Transaction(txParams) && !isEIP1559Compatible) {\n throw rpcErrors.invalidParams(\n 'Invalid transaction params: params specify an EIP-1559 transaction but the current network does not support EIP-1559',\n );\n }\n}\n\n/**\n * Validates value property, ensuring it is a valid positive integer number\n * denominated in wei.\n *\n * @param value - The value to validate, expressed as a string.\n * @throws Throws an error if the value is not a valid positive integer\n * number denominated in wei.\n * - If the value contains a hyphen (-), it is considered invalid.\n * - If the value contains a decimal point (.), it is considered invalid.\n * - If the value is not a finite number, is NaN, or is not a safe integer, it is considered invalid.\n */\nfunction validateParamValue(value?: string) {\n if (value !== undefined) {\n if (value.includes('-')) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value \"${value}\": not a positive number.`,\n );\n }\n\n if (value.includes('.')) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value \"${value}\": number must be in wei.`,\n );\n }\n const intValue = parseInt(value, 10);\n const isValid =\n Number.isFinite(intValue) &&\n !Number.isNaN(intValue) &&\n !isNaN(Number(value)) &&\n Number.isSafeInteger(intValue);\n if (!isValid) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value ${value}: number must be a valid number.`,\n );\n }\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param txParams - The transaction parameters object to validate.\n * @throws Throws an error if the recipient address is invalid:\n * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,\n * the \"to\" field is removed from the transaction parameters.\n * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.\n */\nfunction validateParamRecipient(txParams: TransactionParams) {\n if (txParams.to === '0x' || txParams.to === undefined) {\n if (txParams.data) {\n delete txParams.to;\n } else {\n throw rpcErrors.invalidParams(`Invalid \"to\" address.`);\n }\n } else if (txParams.to !== undefined && !isValidHexAddress(txParams.to)) {\n throw rpcErrors.invalidParams(`Invalid \"to\" address.`);\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param from - The from property to validate.\n * @throws Throws an error if the recipient address is invalid:\n * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,\n * the \"to\" field is removed from the transaction parameters.\n * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.\n */\nfunction validateParamFrom(from: string) {\n if (!from || typeof from !== 'string') {\n throw rpcErrors.invalidParams(\n `Invalid \"from\" address ${from}: not a string.`,\n );\n }\n if (!isValidHexAddress(from)) {\n throw rpcErrors.invalidParams('Invalid \"from\" address.');\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param to - The to property to validate.\n * @throws Throws an error if the recipient address is invalid.\n */\nexport function validateParamTo(to?: string) {\n if (!to || typeof to !== 'string') {\n throw rpcErrors.invalidParams(`Invalid \"to\" address`);\n }\n}\n\n/**\n * Validates a transaction batch request.\n *\n * @param options - Options bag.\n * @param options.internalAccounts - The internal accounts added to the wallet.\n * @param options.request - The batch request object.\n * @param options.sizeLimit - The maximum number of calls allowed in a batch request.\n */\nexport function validateBatchRequest({\n internalAccounts,\n request,\n sizeLimit,\n}: {\n internalAccounts: string[];\n request: TransactionBatchRequest;\n sizeLimit: number;\n}) {\n const { origin } = request;\n const isExternal = origin && origin !== ORIGIN_METAMASK;\n\n const internalAccountsNormalized = internalAccounts.map((account) =>\n account.toLowerCase(),\n );\n\n if (\n isExternal &&\n request.transactions.some((nestedTransaction) => {\n const normalizedCallTo =\n nestedTransaction.params.to?.toLowerCase() as string;\n\n const callData = nestedTransaction.params.data;\n\n const isInternalAccount =\n internalAccountsNormalized.includes(normalizedCallTo);\n\n const hasData = Boolean(callData && callData !== '0x');\n\n return isInternalAccount && hasData;\n })\n ) {\n throw rpcErrors.invalidParams(\n 'External calls to internal accounts cannot include data',\n );\n }\n\n if (isExternal && request.transactions.length > sizeLimit) {\n throw new JsonRpcError(\n ErrorCode.BundleTooLarge,\n `Batch size cannot exceed ${sizeLimit}. got: ${request.transactions.length}`,\n );\n }\n}\n\n/**\n * Validates input data for transactions.\n *\n * @param value - The input data to validate.\n * @throws Throws invalid params if the input data is invalid.\n */\nfunction validateParamData(value?: string) {\n if (value) {\n const ERC20Interface = new Interface(abiERC20);\n try {\n ERC20Interface.parseTransaction({ data: value });\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n if (error.message.match(/BUFFER_OVERRUN/u)) {\n throw rpcErrors.invalidParams(\n 'Invalid transaction params: data out-of-bounds, BUFFER_OVERRUN.',\n );\n }\n }\n }\n}\n\n/**\n * Validates chainId type.\n *\n * @param chainIdParams - The chain ID to validate.\n * @param chainIdNetworkClient - The chain ID of the network client.\n */\nfunction validateParamChainId(chainIdParams?: Hex, chainIdNetworkClient?: Hex) {\n if (\n chainIdParams &&\n chainIdNetworkClient &&\n chainIdParams.toLowerCase?.() !== chainIdNetworkClient.toLowerCase()\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: chainId must match the network client, got: ${chainIdParams}, expected: ${chainIdNetworkClient}`,\n );\n }\n}\n\n/**\n * Validates gas values.\n *\n * @param txParams - The transaction parameters to validate.\n */\nfunction validateGasFeeParams(txParams: TransactionParams) {\n if (txParams.gasPrice) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'gasPrice');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'gasPrice',\n 'maxFeePerGas',\n );\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'gasPrice',\n 'maxPriorityFeePerGas',\n );\n ensureFieldIsValidHex(txParams, 'gasPrice');\n }\n\n if (txParams.maxFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'maxFeePerGas');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsValidHex(txParams, 'maxFeePerGas');\n }\n\n if (txParams.maxPriorityFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(\n txParams,\n 'maxPriorityFeePerGas',\n );\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxPriorityFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsValidHex(txParams, 'maxPriorityFeePerGas');\n }\n\n if (txParams.gasLimit) {\n ensureFieldIsValidHex(txParams, 'gasLimit');\n }\n\n if (txParams.gas) {\n ensureFieldIsValidHex(txParams, 'gas');\n }\n}\n\n/**\n * Ensures that the provided txParams has the proper 'type' specified for the\n * given field, if it is provided. If types do not match throws an\n * invalidParams error.\n *\n * @param txParams - The transaction parameters object\n * @param field - The current field being validated\n * @throws {ethErrors.rpc.invalidParams} Throws if type does not match the\n * expectations for provided field.\n */\nfunction ensureProperTransactionEnvelopeTypeProvided(\n txParams: TransactionParams,\n field: keyof TransactionParams,\n) {\n const type = txParams.type as TransactionEnvelopeType | undefined;\n\n switch (field) {\n case 'authorizationList':\n if (type && type !== TransactionEnvelopeType.setCode) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${type}\" but including authorizationList requires type: \"${TransactionEnvelopeType.setCode}\"`,\n );\n }\n break;\n case 'maxFeePerGas':\n case 'maxPriorityFeePerGas':\n if (\n type &&\n !TRANSACTION_ENVELOPE_TYPES_FEE_MARKET.includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${type}\" but including maxFeePerGas and maxPriorityFeePerGas requires type: \"${TRANSACTION_ENVELOPE_TYPES_FEE_MARKET.join(', ')}\"`,\n );\n }\n break;\n case 'gasPrice':\n default:\n if (\n type &&\n TRANSACTION_ENVELOPE_TYPES_FEE_MARKET.includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${type}\" but included a gasPrice instead of maxFeePerGas and maxPriorityFeePerGas`,\n );\n }\n }\n}\n\n/**\n * Given two fields, ensure that the second field is not included in txParams,\n * and if it is throw an invalidParams error.\n *\n * @param txParams - The transaction parameters object\n * @param fieldBeingValidated - The current field being validated\n * @param mutuallyExclusiveField - The field to ensure is not provided\n * @throws {ethErrors.rpc.invalidParams} Throws if mutuallyExclusiveField is\n * present in txParams.\n */\nfunction ensureMutuallyExclusiveFieldsNotProvided(\n txParams: TransactionParams,\n fieldBeingValidated: GasFieldsToValidate,\n mutuallyExclusiveField: GasFieldsToValidate,\n) {\n if (typeof txParams[mutuallyExclusiveField] !== 'undefined') {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: specified ${fieldBeingValidated} but also included ${mutuallyExclusiveField}, these cannot be mixed`,\n );\n }\n}\n\n/**\n * Ensures that the provided value for field is a valid hexadecimal.\n * Throws an invalidParams error if field is not a valid hexadecimal.\n *\n * @param data - The object containing the field\n * @param field - The current field being validated\n * @throws {rpcErrors.invalidParams} Throws if field is not a valid hexadecimal\n */\nfunction ensureFieldIsValidHex<T>(data: T, field: keyof T) {\n const value = data[field];\n if (typeof value !== 'string' || !isStrictHexString(value)) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: ${String(field)} is not a valid hexadecimal string. got: (${String(\n value,\n )})`,\n );\n }\n}\n\n/**\n * Validate the authorization list property in the transaction parameters.\n *\n * @param txParams - The transaction parameters containing the authorization list to validate.\n */\nfunction validateAuthorizationList(txParams: TransactionParams) {\n const { authorizationList } = txParams;\n\n if (!authorizationList) {\n return;\n }\n\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'authorizationList');\n\n if (!Array.isArray(authorizationList)) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: authorizationList must be an array`,\n );\n }\n\n for (const authorization of authorizationList) {\n validateAuthorization(authorization);\n }\n}\n\n/**\n * Validate an authorization object.\n *\n * @param authorization - The authorization object to validate.\n */\nfunction validateAuthorization(authorization: Authorization) {\n ensureFieldIsValidHex(authorization, 'address');\n validateHexLength(authorization.address, 20, 'address');\n\n for (const field of ['chainId', 'nonce', 'r', 's'] as const) {\n if (authorization[field]) {\n ensureFieldIsValidHex(authorization, field);\n }\n }\n\n const { yParity } = authorization;\n\n if (yParity && !['0x', '0x1'].includes(yParity)) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: yParity must be '0x' or '0x1'. got: ${yParity}`,\n );\n }\n}\n\n/**\n * Validate the number of bytes in a hex string.\n *\n * @param value - The hex string to validate.\n * @param lengthBytes - The expected length in bytes.\n * @param fieldName - The name of the field being validated.\n */\nfunction validateHexLength(\n value: string,\n lengthBytes: number,\n fieldName: string,\n) {\n const actualLengthBytes = remove0x(value).length / 2;\n\n if (actualLengthBytes !== lengthBytes) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: ${fieldName} must be ${lengthBytes} bytes. got: ${actualLengthBytes} bytes`,\n );\n }\n}\n"]}
@@ -3,7 +3,8 @@ import type { TransactionBatchRequest } from "../types.cjs";
3
3
  import { TransactionType, type TransactionParams } from "../types.cjs";
4
4
  export declare enum ErrorCode {
5
5
  DuplicateBundleId = 5720,
6
- BundleTooLarge = 5740
6
+ BundleTooLarge = 5740,
7
+ RejectedUpgrade = 5750
7
8
  }
8
9
  /**
9
10
  * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.cts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EAAiB,uBAAuB,EAAE,qBAAiB;AACvE,OAAO,EAEL,eAAe,EACf,KAAK,iBAAiB,EACvB,qBAAiB;AAElB,oBAAY,SAAS;IACnB,iBAAiB,OAAO;IACxB,cAAc,OAAO;CACtB;AAcD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,yBAAyB,CAAC,EAC9C,IAAI,EACJ,IAAI,EACJ,gBAAgB,EAChB,MAAM,EACN,kBAAkB,EAClB,QAAQ,EACR,IAAI,GACL,EAAE;IACD,IAAI,CAAC,EA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,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB,iBAmCA;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,iBAAiB,EAC3B,mBAAmB,UAAO,EAC1B,OAAO,CAAC,EAAE,GAAG,QAWd;AAwHD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,EAAE,CAAC,EAAE,MAAM,QAI1C;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,gBAAgB,EAChB,OAAO,EACP,SAAS,GACV,EAAE;IACD,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,OAAO,EAAE,uBAAuB,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;CACnB,QAmCA"}
@@ -3,7 +3,8 @@ import type { TransactionBatchRequest } from "../types.mjs";
3
3
  import { TransactionType, type TransactionParams } from "../types.mjs";
4
4
  export declare enum ErrorCode {
5
5
  DuplicateBundleId = 5720,
6
- BundleTooLarge = 5740
6
+ BundleTooLarge = 5740,
7
+ RejectedUpgrade = 5750
7
8
  }
8
9
  /**
9
10
  * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.mts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EAAiB,uBAAuB,EAAE,qBAAiB;AACvE,OAAO,EAEL,eAAe,EACf,KAAK,iBAAiB,EACvB,qBAAiB;AAElB,oBAAY,SAAS;IACnB,iBAAiB,OAAO;IACxB,cAAc,OAAO;CACtB;AAcD;;;;;;;;;;;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,EACJ,IAAI,EACJ,gBAAgB,EAChB,MAAM,EACN,kBAAkB,EAClB,QAAQ,EACR,IAAI,GACL,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB,iBAmCA;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,iBAAiB,EAC3B,mBAAmB,UAAO,EAC1B,OAAO,CAAC,EAAE,GAAG,QAWd;AAwHD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,EAAE,CAAC,EAAE,MAAM,QAI1C;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,gBAAgB,EAChB,OAAO,EACP,SAAS,GACV,EAAE;IACD,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,OAAO,EAAE,uBAAuB,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;CACnB,QAmCA"}
@@ -9,6 +9,7 @@ export var ErrorCode;
9
9
  (function (ErrorCode) {
10
10
  ErrorCode[ErrorCode["DuplicateBundleId"] = 5720] = "DuplicateBundleId";
11
11
  ErrorCode[ErrorCode["BundleTooLarge"] = 5740] = "BundleTooLarge";
12
+ ErrorCode[ErrorCode["RejectedUpgrade"] = 5750] = "RejectedUpgrade";
12
13
  })(ErrorCode || (ErrorCode = {}));
13
14
  const TRANSACTION_ENVELOPE_TYPES_FEE_MARKET = [
14
15
  TransactionEnvelopeType.feeMarket,
@@ -1 +1 @@
1
- {"version":3,"file":"validation.mjs","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OA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mBAAmB,CAAC,CAAC;IAE3E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE;QACrC,MAAM,SAAS,CAAC,aAAa,CAC3B,gEAAgE,CACjE,CAAC;KACH;IAED,KAAK,MAAM,aAAa,IAAI,iBAAiB,EAAE;QAC7C,qBAAqB,CAAC,aAAa,CAAC,CAAC;KACtC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,qBAAqB,CAAC,aAA4B;IACzD,qBAAqB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAChD,iBAAiB,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;IAExD,KAAK,MAAM,KAAK,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAU,EAAE;QAC3D,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE;YACxB,qBAAqB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;SAC7C;KACF;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC;IAElC,IAAI,OAAO,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QAC/C,MAAM,SAAS,CAAC,aAAa,CAC3B,mEAAmE,OAAO,EAAE,CAC7E,CAAC;KACH;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,iBAAiB,CACxB,KAAa,EACb,WAAmB,EACnB,SAAiB;IAEjB,MAAM,iBAAiB,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAErD,IAAI,iBAAiB,KAAK,WAAW,EAAE;QACrC,MAAM,SAAS,CAAC,aAAa,CAC3B,+BAA+B,SAAS,YAAY,WAAW,gBAAgB,iBAAiB,QAAQ,CACzG,CAAC;KACH;AACH,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport { ORIGIN_METAMASK, isValidHexAddress } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { JsonRpcError, providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Hex } from '@metamask/utils';\nimport { isStrictHexString, remove0x } from '@metamask/utils';\n\nimport { isEIP1559Transaction } from './utils';\nimport type { Authorization, TransactionBatchRequest } from '../types';\nimport {\n TransactionEnvelopeType,\n TransactionType,\n type TransactionParams,\n} from '../types';\n\nexport enum ErrorCode {\n DuplicateBundleId = 5720,\n BundleTooLarge = 5740,\n}\n\nconst TRANSACTION_ENVELOPE_TYPES_FEE_MARKET = [\n TransactionEnvelopeType.feeMarket,\n TransactionEnvelopeType.setCode,\n];\n\ntype GasFieldsToValidate =\n | 'gasPrice'\n | 'maxFeePerGas'\n | 'maxPriorityFeePerGas'\n | 'gas'\n | 'gasLimit';\n\n/**\n * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.\n *\n * @param options - Options bag.\n * @param options.data - The data included in the transaction.\n * @param options.from - The address from which the transaction is initiated.\n * @param options.internalAccounts - The internal accounts added to the wallet.\n * @param options.origin - The origin or source of the transaction.\n * @param options.permittedAddresses - The permitted accounts for the given origin.\n * @param options.selectedAddress - The currently selected Ethereum address in the wallet.\n * @param options.txParams - The transaction parameters.\n * @param options.type - The transaction type.\n * @throws Throws an error if the transaction is not permitted.\n */\nexport async function validateTransactionOrigin({\n data,\n from,\n internalAccounts,\n origin,\n permittedAddresses,\n txParams,\n type,\n}: {\n data?: string;\n from: string;\n internalAccounts?: string[];\n origin?: string;\n permittedAddresses?: string[];\n selectedAddress?: string;\n txParams: TransactionParams;\n type?: TransactionType;\n}) {\n const isInternal = !origin || origin === ORIGIN_METAMASK;\n\n if (isInternal) {\n return;\n }\n\n const { authorizationList, to, type: envelopeType } = txParams;\n\n if (permittedAddresses && !permittedAddresses.includes(from)) {\n throw providerErrors.unauthorized({ data: { origin } });\n }\n\n if (type === TransactionType.batch) {\n return;\n }\n\n if (authorizationList || envelopeType === TransactionEnvelopeType.setCode) {\n throw rpcErrors.invalidParams(\n 'External EIP-7702 transactions are not supported',\n );\n }\n\n const hasData = Boolean(data && data !== '0x');\n\n if (\n hasData &&\n internalAccounts?.some(\n (account) => account.toLowerCase() === to?.toLowerCase(),\n )\n ) {\n throw rpcErrors.invalidParams(\n 'External transactions to internal accounts cannot include data',\n );\n }\n}\n\n/**\n * Validates the transaction params for required properties and throws in\n * the event of any validation error.\n *\n * @param txParams - Transaction params object to validate.\n * @param isEIP1559Compatible - whether or not the current network supports EIP-1559 transactions.\n * @param chainId - The chain ID of the transaction.\n */\nexport function validateTxParams(\n txParams: TransactionParams,\n isEIP1559Compatible = true,\n chainId?: Hex,\n) {\n validateEnvelopeType(txParams.type);\n validateEIP1559Compatibility(txParams, isEIP1559Compatible);\n validateParamFrom(txParams.from);\n validateParamRecipient(txParams);\n validateParamValue(txParams.value);\n validateParamData(txParams.data);\n validateParamChainId(txParams.chainId, chainId);\n validateGasFeeParams(txParams);\n validateAuthorizationList(txParams);\n}\n\n/**\n * Validates the `type` property, ensuring that if it is specified, it is a valid transaction envelope type.\n *\n * @param type - The transaction envelope type to validate.\n * @throws Throws invalid params if the type is not a valid transaction envelope type.\n */\nfunction validateEnvelopeType(type: string | undefined) {\n if (\n type &&\n !Object.values(TransactionEnvelopeType).includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: \"${type}\". Must be one of: ${Object.values(\n TransactionEnvelopeType,\n ).join(', ')}`,\n );\n }\n}\n\n/**\n * Validates EIP-1559 compatibility for transaction creation.\n *\n * @param txParams - The transaction parameters to validate.\n * @param isEIP1559Compatible - Indicates if the current network supports EIP-1559.\n * @throws Throws invalid params if the transaction specifies EIP-1559 but the network does not support it.\n */\nfunction validateEIP1559Compatibility(\n txParams: TransactionParams,\n isEIP1559Compatible: boolean,\n) {\n if (isEIP1559Transaction(txParams) && !isEIP1559Compatible) {\n throw rpcErrors.invalidParams(\n 'Invalid transaction params: params specify an EIP-1559 transaction but the current network does not support EIP-1559',\n );\n }\n}\n\n/**\n * Validates value property, ensuring it is a valid positive integer number\n * denominated in wei.\n *\n * @param value - The value to validate, expressed as a string.\n * @throws Throws an error if the value is not a valid positive integer\n * number denominated in wei.\n * - If the value contains a hyphen (-), it is considered invalid.\n * - If the value contains a decimal point (.), it is considered invalid.\n * - If the value is not a finite number, is NaN, or is not a safe integer, it is considered invalid.\n */\nfunction validateParamValue(value?: string) {\n if (value !== undefined) {\n if (value.includes('-')) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value \"${value}\": not a positive number.`,\n );\n }\n\n if (value.includes('.')) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value \"${value}\": number must be in wei.`,\n );\n }\n const intValue = parseInt(value, 10);\n const isValid =\n Number.isFinite(intValue) &&\n !Number.isNaN(intValue) &&\n !isNaN(Number(value)) &&\n Number.isSafeInteger(intValue);\n if (!isValid) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value ${value}: number must be a valid number.`,\n );\n }\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param txParams - The transaction parameters object to validate.\n * @throws Throws an error if the recipient address is invalid:\n * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,\n * the \"to\" field is removed from the transaction parameters.\n * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.\n */\nfunction validateParamRecipient(txParams: TransactionParams) {\n if (txParams.to === '0x' || txParams.to === undefined) {\n if (txParams.data) {\n delete txParams.to;\n } else {\n throw rpcErrors.invalidParams(`Invalid \"to\" address.`);\n }\n } else if (txParams.to !== undefined && !isValidHexAddress(txParams.to)) {\n throw rpcErrors.invalidParams(`Invalid \"to\" address.`);\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param from - The from property to validate.\n * @throws Throws an error if the recipient address is invalid:\n * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,\n * the \"to\" field is removed from the transaction parameters.\n * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.\n */\nfunction validateParamFrom(from: string) {\n if (!from || typeof from !== 'string') {\n throw rpcErrors.invalidParams(\n `Invalid \"from\" address ${from}: not a string.`,\n );\n }\n if (!isValidHexAddress(from)) {\n throw rpcErrors.invalidParams('Invalid \"from\" address.');\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param to - The to property to validate.\n * @throws Throws an error if the recipient address is invalid.\n */\nexport function validateParamTo(to?: string) {\n if (!to || typeof to !== 'string') {\n throw rpcErrors.invalidParams(`Invalid \"to\" address`);\n }\n}\n\n/**\n * Validates a transaction batch request.\n *\n * @param options - Options bag.\n * @param options.internalAccounts - The internal accounts added to the wallet.\n * @param options.request - The batch request object.\n * @param options.sizeLimit - The maximum number of calls allowed in a batch request.\n */\nexport function validateBatchRequest({\n internalAccounts,\n request,\n sizeLimit,\n}: {\n internalAccounts: string[];\n request: TransactionBatchRequest;\n sizeLimit: number;\n}) {\n const { origin } = request;\n const isExternal = origin && origin !== ORIGIN_METAMASK;\n\n const internalAccountsNormalized = internalAccounts.map((account) =>\n account.toLowerCase(),\n );\n\n if (\n isExternal &&\n request.transactions.some((nestedTransaction) => {\n const normalizedCallTo =\n nestedTransaction.params.to?.toLowerCase() as string;\n\n const callData = nestedTransaction.params.data;\n\n const isInternalAccount =\n internalAccountsNormalized.includes(normalizedCallTo);\n\n const hasData = Boolean(callData && callData !== '0x');\n\n return isInternalAccount && hasData;\n })\n ) {\n throw rpcErrors.invalidParams(\n 'External calls to internal accounts cannot include data',\n );\n }\n\n if (isExternal && request.transactions.length > sizeLimit) {\n throw new JsonRpcError(\n ErrorCode.BundleTooLarge,\n `Batch size cannot exceed ${sizeLimit}. got: ${request.transactions.length}`,\n );\n }\n}\n\n/**\n * Validates input data for transactions.\n *\n * @param value - The input data to validate.\n * @throws Throws invalid params if the input data is invalid.\n */\nfunction validateParamData(value?: string) {\n if (value) {\n const ERC20Interface = new Interface(abiERC20);\n try {\n ERC20Interface.parseTransaction({ data: value });\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n if (error.message.match(/BUFFER_OVERRUN/u)) {\n throw rpcErrors.invalidParams(\n 'Invalid transaction params: data out-of-bounds, BUFFER_OVERRUN.',\n );\n }\n }\n }\n}\n\n/**\n * Validates chainId type.\n *\n * @param chainIdParams - The chain ID to validate.\n * @param chainIdNetworkClient - The chain ID of the network client.\n */\nfunction validateParamChainId(chainIdParams?: Hex, chainIdNetworkClient?: Hex) {\n if (\n chainIdParams &&\n chainIdNetworkClient &&\n chainIdParams.toLowerCase?.() !== chainIdNetworkClient.toLowerCase()\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: chainId must match the network client, got: ${chainIdParams}, expected: ${chainIdNetworkClient}`,\n );\n }\n}\n\n/**\n * Validates gas values.\n *\n * @param txParams - The transaction parameters to validate.\n */\nfunction validateGasFeeParams(txParams: TransactionParams) {\n if (txParams.gasPrice) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'gasPrice');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'gasPrice',\n 'maxFeePerGas',\n );\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'gasPrice',\n 'maxPriorityFeePerGas',\n );\n ensureFieldIsValidHex(txParams, 'gasPrice');\n }\n\n if (txParams.maxFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'maxFeePerGas');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsValidHex(txParams, 'maxFeePerGas');\n }\n\n if (txParams.maxPriorityFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(\n txParams,\n 'maxPriorityFeePerGas',\n );\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxPriorityFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsValidHex(txParams, 'maxPriorityFeePerGas');\n }\n\n if (txParams.gasLimit) {\n ensureFieldIsValidHex(txParams, 'gasLimit');\n }\n\n if (txParams.gas) {\n ensureFieldIsValidHex(txParams, 'gas');\n }\n}\n\n/**\n * Ensures that the provided txParams has the proper 'type' specified for the\n * given field, if it is provided. If types do not match throws an\n * invalidParams error.\n *\n * @param txParams - The transaction parameters object\n * @param field - The current field being validated\n * @throws {ethErrors.rpc.invalidParams} Throws if type does not match the\n * expectations for provided field.\n */\nfunction ensureProperTransactionEnvelopeTypeProvided(\n txParams: TransactionParams,\n field: keyof TransactionParams,\n) {\n const type = txParams.type as TransactionEnvelopeType | undefined;\n\n switch (field) {\n case 'authorizationList':\n if (type && type !== TransactionEnvelopeType.setCode) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${type}\" but including authorizationList requires type: \"${TransactionEnvelopeType.setCode}\"`,\n );\n }\n break;\n case 'maxFeePerGas':\n case 'maxPriorityFeePerGas':\n if (\n type &&\n !TRANSACTION_ENVELOPE_TYPES_FEE_MARKET.includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${type}\" but including maxFeePerGas and maxPriorityFeePerGas requires type: \"${TRANSACTION_ENVELOPE_TYPES_FEE_MARKET.join(', ')}\"`,\n );\n }\n break;\n case 'gasPrice':\n default:\n if (\n type &&\n TRANSACTION_ENVELOPE_TYPES_FEE_MARKET.includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${type}\" but included a gasPrice instead of maxFeePerGas and maxPriorityFeePerGas`,\n );\n }\n }\n}\n\n/**\n * Given two fields, ensure that the second field is not included in txParams,\n * and if it is throw an invalidParams error.\n *\n * @param txParams - The transaction parameters object\n * @param fieldBeingValidated - The current field being validated\n * @param mutuallyExclusiveField - The field to ensure is not provided\n * @throws {ethErrors.rpc.invalidParams} Throws if mutuallyExclusiveField is\n * present in txParams.\n */\nfunction ensureMutuallyExclusiveFieldsNotProvided(\n txParams: TransactionParams,\n fieldBeingValidated: GasFieldsToValidate,\n mutuallyExclusiveField: GasFieldsToValidate,\n) {\n if (typeof txParams[mutuallyExclusiveField] !== 'undefined') {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: specified ${fieldBeingValidated} but also included ${mutuallyExclusiveField}, these cannot be mixed`,\n );\n }\n}\n\n/**\n * Ensures that the provided value for field is a valid hexadecimal.\n * Throws an invalidParams error if field is not a valid hexadecimal.\n *\n * @param data - The object containing the field\n * @param field - The current field being validated\n * @throws {rpcErrors.invalidParams} Throws if field is not a valid hexadecimal\n */\nfunction ensureFieldIsValidHex<T>(data: T, field: keyof T) {\n const value = data[field];\n if (typeof value !== 'string' || !isStrictHexString(value)) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: ${String(field)} is not a valid hexadecimal string. got: (${String(\n value,\n )})`,\n );\n }\n}\n\n/**\n * Validate the authorization list property in the transaction parameters.\n *\n * @param txParams - The transaction parameters containing the authorization list to validate.\n */\nfunction validateAuthorizationList(txParams: TransactionParams) {\n const { authorizationList } = txParams;\n\n if (!authorizationList) {\n return;\n }\n\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'authorizationList');\n\n if (!Array.isArray(authorizationList)) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: authorizationList must be an array`,\n );\n }\n\n for (const authorization of authorizationList) {\n validateAuthorization(authorization);\n }\n}\n\n/**\n * Validate an authorization object.\n *\n * @param authorization - The authorization object to validate.\n */\nfunction validateAuthorization(authorization: Authorization) {\n ensureFieldIsValidHex(authorization, 'address');\n validateHexLength(authorization.address, 20, 'address');\n\n for (const field of ['chainId', 'nonce', 'r', 's'] as const) {\n if (authorization[field]) {\n ensureFieldIsValidHex(authorization, field);\n }\n }\n\n const { yParity } = authorization;\n\n if (yParity && !['0x', '0x1'].includes(yParity)) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: yParity must be '0x' or '0x1'. got: ${yParity}`,\n );\n }\n}\n\n/**\n * Validate the number of bytes in a hex string.\n *\n * @param value - The hex string to validate.\n * @param lengthBytes - The expected length in bytes.\n * @param fieldName - The name of the field being validated.\n */\nfunction validateHexLength(\n value: string,\n lengthBytes: number,\n fieldName: string,\n) {\n const actualLengthBytes = remove0x(value).length / 2;\n\n if (actualLengthBytes !== lengthBytes) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: ${fieldName} must be ${lengthBytes} bytes. got: ${actualLengthBytes} bytes`,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"validation.mjs","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,2BAA2B;AAC/C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,mCAAmC;AAChF,OAAO,EAAE,QAAQ,EAAE,oCAAoC;AACvD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAE/E,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,wBAAwB;AAE9D,OAAO,EAAE,oBAAoB,EAAE,oBAAgB;AAE/C,OAAO,EACL,uBAAuB,EACvB,eAAe,EAEhB,qBAAiB;AAElB,MAAM,CAAN,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,sEAAwB,CAAA;IACxB,gEAAqB,CAAA;IACrB,kEAAsB,CAAA;AACxB,CAAC,EAJW,SAAS,KAAT,SAAS,QAIpB;AAED,MAAM,qCAAqC,GAAG;IAC5C,uBAAuB,CAAC,SAAS;IACjC,uBAAuB,CAAC,OAAO;CAChC,CAAC;AASF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,EAC9C,IAAI,EACJ,IAAI,EACJ,gBAAgB,EAChB,MAAM,EACN,kBAAkB,EAClB,QAAQ,EACR,IAAI,GAUL;IACC,MAAM,UAAU,GAAG,CAAC,MAAM,IAAI,MAAM,KAAK,eAAe,CAAC;IAEzD,IAAI,UAAU,EAAE;QACd,OAAO;KACR;IAED,MAAM,EAAE,iBAAiB,EA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AMG;AACH,SAAS,iBAAiB,CACxB,KAAa,EACb,WAAmB,EACnB,SAAiB;IAEjB,MAAM,iBAAiB,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAErD,IAAI,iBAAiB,KAAK,WAAW,EAAE;QACrC,MAAM,SAAS,CAAC,aAAa,CAC3B,+BAA+B,SAAS,YAAY,WAAW,gBAAgB,iBAAiB,QAAQ,CACzG,CAAC;KACH;AACH,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport { ORIGIN_METAMASK, isValidHexAddress } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { JsonRpcError, providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Hex } from '@metamask/utils';\nimport { isStrictHexString, remove0x } from '@metamask/utils';\n\nimport { isEIP1559Transaction } from './utils';\nimport type { Authorization, TransactionBatchRequest } from '../types';\nimport {\n TransactionEnvelopeType,\n TransactionType,\n type TransactionParams,\n} from '../types';\n\nexport enum ErrorCode {\n DuplicateBundleId = 5720,\n BundleTooLarge = 5740,\n RejectedUpgrade = 5750,\n}\n\nconst TRANSACTION_ENVELOPE_TYPES_FEE_MARKET = [\n TransactionEnvelopeType.feeMarket,\n TransactionEnvelopeType.setCode,\n];\n\ntype GasFieldsToValidate =\n | 'gasPrice'\n | 'maxFeePerGas'\n | 'maxPriorityFeePerGas'\n | 'gas'\n | 'gasLimit';\n\n/**\n * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.\n *\n * @param options - Options bag.\n * @param options.data - The data included in the transaction.\n * @param options.from - The address from which the transaction is initiated.\n * @param options.internalAccounts - The internal accounts added to the wallet.\n * @param options.origin - The origin or source of the transaction.\n * @param options.permittedAddresses - The permitted accounts for the given origin.\n * @param options.selectedAddress - The currently selected Ethereum address in the wallet.\n * @param options.txParams - The transaction parameters.\n * @param options.type - The transaction type.\n * @throws Throws an error if the transaction is not permitted.\n */\nexport async function validateTransactionOrigin({\n data,\n from,\n internalAccounts,\n origin,\n permittedAddresses,\n txParams,\n type,\n}: {\n data?: string;\n from: string;\n internalAccounts?: string[];\n origin?: string;\n permittedAddresses?: string[];\n selectedAddress?: string;\n txParams: TransactionParams;\n type?: TransactionType;\n}) {\n const isInternal = !origin || origin === ORIGIN_METAMASK;\n\n if (isInternal) {\n return;\n }\n\n const { authorizationList, to, type: envelopeType } = txParams;\n\n if (permittedAddresses && !permittedAddresses.includes(from)) {\n throw providerErrors.unauthorized({ data: { origin } });\n }\n\n if (type === TransactionType.batch) {\n return;\n }\n\n if (authorizationList || envelopeType === TransactionEnvelopeType.setCode) {\n throw rpcErrors.invalidParams(\n 'External EIP-7702 transactions are not supported',\n );\n }\n\n const hasData = Boolean(data && data !== '0x');\n\n if (\n hasData &&\n internalAccounts?.some(\n (account) => account.toLowerCase() === to?.toLowerCase(),\n )\n ) {\n throw rpcErrors.invalidParams(\n 'External transactions to internal accounts cannot include data',\n );\n }\n}\n\n/**\n * Validates the transaction params for required properties and throws in\n * the event of any validation error.\n *\n * @param txParams - Transaction params object to validate.\n * @param isEIP1559Compatible - whether or not the current network supports EIP-1559 transactions.\n * @param chainId - The chain ID of the transaction.\n */\nexport function validateTxParams(\n txParams: TransactionParams,\n isEIP1559Compatible = true,\n chainId?: Hex,\n) {\n validateEnvelopeType(txParams.type);\n validateEIP1559Compatibility(txParams, isEIP1559Compatible);\n validateParamFrom(txParams.from);\n validateParamRecipient(txParams);\n validateParamValue(txParams.value);\n validateParamData(txParams.data);\n validateParamChainId(txParams.chainId, chainId);\n validateGasFeeParams(txParams);\n validateAuthorizationList(txParams);\n}\n\n/**\n * Validates the `type` property, ensuring that if it is specified, it is a valid transaction envelope type.\n *\n * @param type - The transaction envelope type to validate.\n * @throws Throws invalid params if the type is not a valid transaction envelope type.\n */\nfunction validateEnvelopeType(type: string | undefined) {\n if (\n type &&\n !Object.values(TransactionEnvelopeType).includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: \"${type}\". Must be one of: ${Object.values(\n TransactionEnvelopeType,\n ).join(', ')}`,\n );\n }\n}\n\n/**\n * Validates EIP-1559 compatibility for transaction creation.\n *\n * @param txParams - The transaction parameters to validate.\n * @param isEIP1559Compatible - Indicates if the current network supports EIP-1559.\n * @throws Throws invalid params if the transaction specifies EIP-1559 but the network does not support it.\n */\nfunction validateEIP1559Compatibility(\n txParams: TransactionParams,\n isEIP1559Compatible: boolean,\n) {\n if (isEIP1559Transaction(txParams) && !isEIP1559Compatible) {\n throw rpcErrors.invalidParams(\n 'Invalid transaction params: params specify an EIP-1559 transaction but the current network does not support EIP-1559',\n );\n }\n}\n\n/**\n * Validates value property, ensuring it is a valid positive integer number\n * denominated in wei.\n *\n * @param value - The value to validate, expressed as a string.\n * @throws Throws an error if the value is not a valid positive integer\n * number denominated in wei.\n * - If the value contains a hyphen (-), it is considered invalid.\n * - If the value contains a decimal point (.), it is considered invalid.\n * - If the value is not a finite number, is NaN, or is not a safe integer, it is considered invalid.\n */\nfunction validateParamValue(value?: string) {\n if (value !== undefined) {\n if (value.includes('-')) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value \"${value}\": not a positive number.`,\n );\n }\n\n if (value.includes('.')) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value \"${value}\": number must be in wei.`,\n );\n }\n const intValue = parseInt(value, 10);\n const isValid =\n Number.isFinite(intValue) &&\n !Number.isNaN(intValue) &&\n !isNaN(Number(value)) &&\n Number.isSafeInteger(intValue);\n if (!isValid) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value ${value}: number must be a valid number.`,\n );\n }\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param txParams - The transaction parameters object to validate.\n * @throws Throws an error if the recipient address is invalid:\n * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,\n * the \"to\" field is removed from the transaction parameters.\n * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.\n */\nfunction validateParamRecipient(txParams: TransactionParams) {\n if (txParams.to === '0x' || txParams.to === undefined) {\n if (txParams.data) {\n delete txParams.to;\n } else {\n throw rpcErrors.invalidParams(`Invalid \"to\" address.`);\n }\n } else if (txParams.to !== undefined && !isValidHexAddress(txParams.to)) {\n throw rpcErrors.invalidParams(`Invalid \"to\" address.`);\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param from - The from property to validate.\n * @throws Throws an error if the recipient address is invalid:\n * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,\n * the \"to\" field is removed from the transaction parameters.\n * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.\n */\nfunction validateParamFrom(from: string) {\n if (!from || typeof from !== 'string') {\n throw rpcErrors.invalidParams(\n `Invalid \"from\" address ${from}: not a string.`,\n );\n }\n if (!isValidHexAddress(from)) {\n throw rpcErrors.invalidParams('Invalid \"from\" address.');\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param to - The to property to validate.\n * @throws Throws an error if the recipient address is invalid.\n */\nexport function validateParamTo(to?: string) {\n if (!to || typeof to !== 'string') {\n throw rpcErrors.invalidParams(`Invalid \"to\" address`);\n }\n}\n\n/**\n * Validates a transaction batch request.\n *\n * @param options - Options bag.\n * @param options.internalAccounts - The internal accounts added to the wallet.\n * @param options.request - The batch request object.\n * @param options.sizeLimit - The maximum number of calls allowed in a batch request.\n */\nexport function validateBatchRequest({\n internalAccounts,\n request,\n sizeLimit,\n}: {\n internalAccounts: string[];\n request: TransactionBatchRequest;\n sizeLimit: number;\n}) {\n const { origin } = request;\n const isExternal = origin && origin !== ORIGIN_METAMASK;\n\n const internalAccountsNormalized = internalAccounts.map((account) =>\n account.toLowerCase(),\n );\n\n if (\n isExternal &&\n request.transactions.some((nestedTransaction) => {\n const normalizedCallTo =\n nestedTransaction.params.to?.toLowerCase() as string;\n\n const callData = nestedTransaction.params.data;\n\n const isInternalAccount =\n internalAccountsNormalized.includes(normalizedCallTo);\n\n const hasData = Boolean(callData && callData !== '0x');\n\n return isInternalAccount && hasData;\n })\n ) {\n throw rpcErrors.invalidParams(\n 'External calls to internal accounts cannot include data',\n );\n }\n\n if (isExternal && request.transactions.length > sizeLimit) {\n throw new JsonRpcError(\n ErrorCode.BundleTooLarge,\n `Batch size cannot exceed ${sizeLimit}. got: ${request.transactions.length}`,\n );\n }\n}\n\n/**\n * Validates input data for transactions.\n *\n * @param value - The input data to validate.\n * @throws Throws invalid params if the input data is invalid.\n */\nfunction validateParamData(value?: string) {\n if (value) {\n const ERC20Interface = new Interface(abiERC20);\n try {\n ERC20Interface.parseTransaction({ data: value });\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n if (error.message.match(/BUFFER_OVERRUN/u)) {\n throw rpcErrors.invalidParams(\n 'Invalid transaction params: data out-of-bounds, BUFFER_OVERRUN.',\n );\n }\n }\n }\n}\n\n/**\n * Validates chainId type.\n *\n * @param chainIdParams - The chain ID to validate.\n * @param chainIdNetworkClient - The chain ID of the network client.\n */\nfunction validateParamChainId(chainIdParams?: Hex, chainIdNetworkClient?: Hex) {\n if (\n chainIdParams &&\n chainIdNetworkClient &&\n chainIdParams.toLowerCase?.() !== chainIdNetworkClient.toLowerCase()\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: chainId must match the network client, got: ${chainIdParams}, expected: ${chainIdNetworkClient}`,\n );\n }\n}\n\n/**\n * Validates gas values.\n *\n * @param txParams - The transaction parameters to validate.\n */\nfunction validateGasFeeParams(txParams: TransactionParams) {\n if (txParams.gasPrice) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'gasPrice');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'gasPrice',\n 'maxFeePerGas',\n );\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'gasPrice',\n 'maxPriorityFeePerGas',\n );\n ensureFieldIsValidHex(txParams, 'gasPrice');\n }\n\n if (txParams.maxFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'maxFeePerGas');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsValidHex(txParams, 'maxFeePerGas');\n }\n\n if (txParams.maxPriorityFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(\n txParams,\n 'maxPriorityFeePerGas',\n );\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxPriorityFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsValidHex(txParams, 'maxPriorityFeePerGas');\n }\n\n if (txParams.gasLimit) {\n ensureFieldIsValidHex(txParams, 'gasLimit');\n }\n\n if (txParams.gas) {\n ensureFieldIsValidHex(txParams, 'gas');\n }\n}\n\n/**\n * Ensures that the provided txParams has the proper 'type' specified for the\n * given field, if it is provided. If types do not match throws an\n * invalidParams error.\n *\n * @param txParams - The transaction parameters object\n * @param field - The current field being validated\n * @throws {ethErrors.rpc.invalidParams} Throws if type does not match the\n * expectations for provided field.\n */\nfunction ensureProperTransactionEnvelopeTypeProvided(\n txParams: TransactionParams,\n field: keyof TransactionParams,\n) {\n const type = txParams.type as TransactionEnvelopeType | undefined;\n\n switch (field) {\n case 'authorizationList':\n if (type && type !== TransactionEnvelopeType.setCode) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${type}\" but including authorizationList requires type: \"${TransactionEnvelopeType.setCode}\"`,\n );\n }\n break;\n case 'maxFeePerGas':\n case 'maxPriorityFeePerGas':\n if (\n type &&\n !TRANSACTION_ENVELOPE_TYPES_FEE_MARKET.includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${type}\" but including maxFeePerGas and maxPriorityFeePerGas requires type: \"${TRANSACTION_ENVELOPE_TYPES_FEE_MARKET.join(', ')}\"`,\n );\n }\n break;\n case 'gasPrice':\n default:\n if (\n type &&\n TRANSACTION_ENVELOPE_TYPES_FEE_MARKET.includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${type}\" but included a gasPrice instead of maxFeePerGas and maxPriorityFeePerGas`,\n );\n }\n }\n}\n\n/**\n * Given two fields, ensure that the second field is not included in txParams,\n * and if it is throw an invalidParams error.\n *\n * @param txParams - The transaction parameters object\n * @param fieldBeingValidated - The current field being validated\n * @param mutuallyExclusiveField - The field to ensure is not provided\n * @throws {ethErrors.rpc.invalidParams} Throws if mutuallyExclusiveField is\n * present in txParams.\n */\nfunction ensureMutuallyExclusiveFieldsNotProvided(\n txParams: TransactionParams,\n fieldBeingValidated: GasFieldsToValidate,\n mutuallyExclusiveField: GasFieldsToValidate,\n) {\n if (typeof txParams[mutuallyExclusiveField] !== 'undefined') {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: specified ${fieldBeingValidated} but also included ${mutuallyExclusiveField}, these cannot be mixed`,\n );\n }\n}\n\n/**\n * Ensures that the provided value for field is a valid hexadecimal.\n * Throws an invalidParams error if field is not a valid hexadecimal.\n *\n * @param data - The object containing the field\n * @param field - The current field being validated\n * @throws {rpcErrors.invalidParams} Throws if field is not a valid hexadecimal\n */\nfunction ensureFieldIsValidHex<T>(data: T, field: keyof T) {\n const value = data[field];\n if (typeof value !== 'string' || !isStrictHexString(value)) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: ${String(field)} is not a valid hexadecimal string. got: (${String(\n value,\n )})`,\n );\n }\n}\n\n/**\n * Validate the authorization list property in the transaction parameters.\n *\n * @param txParams - The transaction parameters containing the authorization list to validate.\n */\nfunction validateAuthorizationList(txParams: TransactionParams) {\n const { authorizationList } = txParams;\n\n if (!authorizationList) {\n return;\n }\n\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'authorizationList');\n\n if (!Array.isArray(authorizationList)) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: authorizationList must be an array`,\n );\n }\n\n for (const authorization of authorizationList) {\n validateAuthorization(authorization);\n }\n}\n\n/**\n * Validate an authorization object.\n *\n * @param authorization - The authorization object to validate.\n */\nfunction validateAuthorization(authorization: Authorization) {\n ensureFieldIsValidHex(authorization, 'address');\n validateHexLength(authorization.address, 20, 'address');\n\n for (const field of ['chainId', 'nonce', 'r', 's'] as const) {\n if (authorization[field]) {\n ensureFieldIsValidHex(authorization, field);\n }\n }\n\n const { yParity } = authorization;\n\n if (yParity && !['0x', '0x1'].includes(yParity)) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: yParity must be '0x' or '0x1'. got: ${yParity}`,\n );\n }\n}\n\n/**\n * Validate the number of bytes in a hex string.\n *\n * @param value - The hex string to validate.\n * @param lengthBytes - The expected length in bytes.\n * @param fieldName - The name of the field being validated.\n */\nfunction validateHexLength(\n value: string,\n lengthBytes: number,\n fieldName: string,\n) {\n const actualLengthBytes = remove0x(value).length / 2;\n\n if (actualLengthBytes !== lengthBytes) {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: ${fieldName} must be ${lengthBytes} bytes. got: ${actualLengthBytes} bytes`,\n );\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/transaction-controller",
3
- "version": "55.0.2",
3
+ "version": "56.1.0",
4
4
  "description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -55,7 +55,7 @@
55
55
  "@ethersproject/providers": "^5.7.0",
56
56
  "@ethersproject/wallet": "^5.7.0",
57
57
  "@metamask/base-controller": "^8.0.1",
58
- "@metamask/controller-utils": "^11.8.0",
58
+ "@metamask/controller-utils": "^11.9.0",
59
59
  "@metamask/eth-query": "^4.0.0",
60
60
  "@metamask/metamask-eth-abis": "^3.1.1",
61
61
  "@metamask/nonce-tracker": "^6.0.0",
@@ -70,14 +70,14 @@
70
70
  },
71
71
  "devDependencies": {
72
72
  "@babel/runtime": "^7.23.9",
73
- "@metamask/accounts-controller": "^28.0.0",
73
+ "@metamask/accounts-controller": "^29.0.0",
74
74
  "@metamask/approval-controller": "^7.1.3",
75
75
  "@metamask/auto-changelog": "^3.4.4",
76
76
  "@metamask/eth-block-tracker": "^11.0.3",
77
77
  "@metamask/eth-json-rpc-provider": "^4.1.8",
78
78
  "@metamask/ethjs-provider-http": "^0.3.0",
79
79
  "@metamask/gas-fee-controller": "^23.0.0",
80
- "@metamask/network-controller": "^23.4.0",
80
+ "@metamask/network-controller": "^23.5.0",
81
81
  "@metamask/remote-feature-flag-controller": "^1.6.0",
82
82
  "@types/bn.js": "^5.1.5",
83
83
  "@types/jest": "^27.4.1",
@@ -94,7 +94,7 @@
94
94
  },
95
95
  "peerDependencies": {
96
96
  "@babel/runtime": "^7.0.0",
97
- "@metamask/accounts-controller": "^28.0.0",
97
+ "@metamask/accounts-controller": "^29.0.0",
98
98
  "@metamask/approval-controller": "^7.0.0",
99
99
  "@metamask/eth-block-tracker": ">=9",
100
100
  "@metamask/gas-fee-controller": "^23.0.0",