@metamask/transaction-controller 35.1.0 → 35.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -1
- package/dist/TransactionController.js +3 -3
- package/dist/TransactionController.mjs +2 -2
- package/dist/{chunk-RXIUMVA5.js → chunk-GPS6RX64.js} +16 -1
- package/dist/chunk-GPS6RX64.js.map +1 -0
- package/dist/{chunk-5ZEJT5SN.mjs → chunk-LTPS73D7.mjs} +16 -1
- package/dist/chunk-LTPS73D7.mjs.map +1 -0
- package/dist/{chunk-QKS2F7VG.js → chunk-S3RZBMF7.js} +24 -11
- package/dist/chunk-S3RZBMF7.js.map +1 -0
- package/dist/{chunk-5JWPMHSZ.mjs → chunk-T3GOPPVF.mjs} +21 -8
- package/dist/chunk-T3GOPPVF.mjs.map +1 -0
- package/dist/index.js +3 -3
- package/dist/index.mjs +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/TransactionController.d.ts.map +1 -1
- package/dist/types/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +2 -2
- package/dist/utils/validation.mjs +1 -1
- package/package.json +4 -4
- package/dist/chunk-5JWPMHSZ.mjs.map +0 -1
- package/dist/chunk-5ZEJT5SN.mjs.map +0 -1
- package/dist/chunk-QKS2F7VG.js.map +0 -1
- package/dist/chunk-RXIUMVA5.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [35.1.1]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Upgrade TypeScript version from `~5.0.4` to `~5.2.2` ([#4576](https://github.com/MetaMask/core/pull/4576), [#4584](https://github.com/MetaMask/core/pull/4584))
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Fix gaps in transaction validation and async error logging ([#4596](https://github.com/MetaMask/core/pull/4596))
|
|
19
|
+
- Upgrade `@metamask/nonce-tracker` from v5 to v6 ([#4591](https://github.com/MetaMask/core/pull/4591))
|
|
20
|
+
|
|
10
21
|
## [35.1.0]
|
|
11
22
|
|
|
12
23
|
### Added
|
|
@@ -948,7 +959,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
948
959
|
|
|
949
960
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
950
961
|
|
|
951
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.1.
|
|
962
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.1.1...HEAD
|
|
963
|
+
[35.1.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.1.0...@metamask/transaction-controller@35.1.1
|
|
952
964
|
[35.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.0.1...@metamask/transaction-controller@35.1.0
|
|
953
965
|
[35.0.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.0.0...@metamask/transaction-controller@35.0.1
|
|
954
966
|
[35.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@34.0.0...@metamask/transaction-controller@35.0.0
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkS3RZBMF7js = require('./chunk-S3RZBMF7.js');
|
|
8
8
|
require('./chunk-PRUNMTRD.js');
|
|
9
9
|
require('./chunk-NNCUD3QF.js');
|
|
10
10
|
require('./chunk-KT6UAKBB.js');
|
|
11
11
|
require('./chunk-SD6CWFDF.js');
|
|
12
|
-
require('./chunk-
|
|
12
|
+
require('./chunk-GPS6RX64.js');
|
|
13
13
|
require('./chunk-ULD4JC3Q.js');
|
|
14
14
|
require('./chunk-7LXE4KHV.js');
|
|
15
15
|
require('./chunk-V72C4MCR.js');
|
|
@@ -41,5 +41,5 @@ require('./chunk-Z4BLTVTB.js');
|
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
exports.ApprovalState =
|
|
44
|
+
exports.ApprovalState = _chunkS3RZBMF7js.ApprovalState; exports.CANCEL_RATE = _chunkS3RZBMF7js.CANCEL_RATE; exports.HARDFORK = _chunkS3RZBMF7js.HARDFORK; exports.SPEED_UP_RATE = _chunkS3RZBMF7js.SPEED_UP_RATE; exports.TransactionController = _chunkS3RZBMF7js.TransactionController;
|
|
45
45
|
//# sourceMappingURL=TransactionController.js.map
|
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
HARDFORK,
|
|
5
5
|
SPEED_UP_RATE,
|
|
6
6
|
TransactionController
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-T3GOPPVF.mjs";
|
|
8
8
|
import "./chunk-6DDVVUJC.mjs";
|
|
9
9
|
import "./chunk-3AVRGHUO.mjs";
|
|
10
10
|
import "./chunk-K4KOSAGM.mjs";
|
|
11
11
|
import "./chunk-KG4UW4K4.mjs";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-LTPS73D7.mjs";
|
|
13
13
|
import "./chunk-6B5BEO3R.mjs";
|
|
14
14
|
import "./chunk-FRKQ3Z2L.mjs";
|
|
15
15
|
import "./chunk-5G6OHAXI.mjs";
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var _chunkOZ6UB42Cjs = require('./chunk-OZ6UB42C.js');
|
|
4
4
|
|
|
5
|
+
|
|
6
|
+
var _chunkAYTU4HU5js = require('./chunk-AYTU4HU5.js');
|
|
7
|
+
|
|
5
8
|
// src/utils/validation.ts
|
|
6
9
|
var _abi = require('@ethersproject/abi');
|
|
7
10
|
var _controllerutils = require('@metamask/controller-utils');
|
|
@@ -26,6 +29,7 @@ async function validateTransactionOrigin(permittedAddresses, selectedAddress, fr
|
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
function validateTxParams(txParams, isEIP1559Compatible = true) {
|
|
32
|
+
validateEnvelopeType(txParams.type);
|
|
29
33
|
validateEIP1559Compatibility(txParams, isEIP1559Compatible);
|
|
30
34
|
validateParamFrom(txParams.from);
|
|
31
35
|
validateParamRecipient(txParams);
|
|
@@ -34,6 +38,17 @@ function validateTxParams(txParams, isEIP1559Compatible = true) {
|
|
|
34
38
|
validateParamChainId(txParams.chainId);
|
|
35
39
|
validateGasFeeParams(txParams);
|
|
36
40
|
}
|
|
41
|
+
function validateEnvelopeType(type) {
|
|
42
|
+
if (type && !Object.values(_chunkAYTU4HU5js.TransactionEnvelopeType).includes(
|
|
43
|
+
type
|
|
44
|
+
)) {
|
|
45
|
+
throw _rpcerrors.rpcErrors.invalidParams(
|
|
46
|
+
`Invalid transaction envelope type: "${type}". Must be one of: ${Object.values(
|
|
47
|
+
_chunkAYTU4HU5js.TransactionEnvelopeType
|
|
48
|
+
).join(", ")}`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
37
52
|
function validateEIP1559Compatibility(txParams, isEIP1559Compatible) {
|
|
38
53
|
if (_chunkOZ6UB42Cjs.isEIP1559Transaction.call(void 0, txParams) && !isEIP1559Compatible) {
|
|
39
54
|
throw _rpcerrors.rpcErrors.invalidParams(
|
|
@@ -183,4 +198,4 @@ function ensureFieldIsString(txParams, field) {
|
|
|
183
198
|
|
|
184
199
|
|
|
185
200
|
exports.validateTransactionOrigin = validateTransactionOrigin; exports.validateTxParams = validateTxParams;
|
|
186
|
-
//# sourceMappingURL=chunk-
|
|
201
|
+
//# sourceMappingURL=chunk-GPS6RX64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/validation.ts"],"names":[],"mappings":";;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB,yBAAyB;AACnD,SAAS,gBAAgB;AACzB,SAAS,gBAAgB,iBAAiB;AAgB1C,eAAsB,0BACpB,o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interface } from '@ethersproject/abi';\nimport { ORIGIN_METAMASK, isValidHexAddress } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\n\nimport { TransactionEnvelopeType, type TransactionParams } from '../types';\nimport { isEIP1559Transaction } from './utils';\n\ntype GasFieldsToValidate = 'gasPrice' | 'maxFeePerGas' | 'maxPriorityFeePerGas';\n\n/**\n * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.\n *\n * @param permittedAddresses - The permitted accounts for the given origin.\n * @param selectedAddress - The currently selected Ethereum address in the wallet.\n * @param from - The address from which the transaction is initiated.\n * @param origin - The origin or source of the transaction.\n * @throws Throws an error if the transaction is not permitted.\n */\nexport async function validateTransactionOrigin(\n permittedAddresses: string[],\n selectedAddress: string,\n from: string,\n origin: string,\n) {\n if (origin === ORIGIN_METAMASK) {\n // Ensure the 'from' address matches the currently selected address\n if (from !== selectedAddress) {\n throw rpcErrors.internal({\n message: `Internally initiated transaction is using invalid account.`,\n data: {\n origin,\n fromAddress: from,\n selectedAddress,\n },\n });\n }\n return;\n }\n\n // Check if the origin has permissions to initiate transactions from the specified address\n if (!permittedAddresses.includes(from)) {\n throw providerErrors.unauthorized({ data: { origin } });\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 */\nexport function validateTxParams(\n txParams: TransactionParams,\n isEIP1559Compatible = true,\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);\n validateGasFeeParams(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 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 chainId - The chainId to validate.\n */\nfunction validateParamChainId(chainId: number | string | undefined) {\n if (\n chainId !== undefined &&\n typeof chainId !== 'number' &&\n typeof chainId !== 'string'\n ) {\n throw rpcErrors.invalidParams(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Invalid transaction params: chainId is not a Number or hex string. got: (${chainId})`,\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 ensureFieldIsString(txParams, 'gasPrice');\n }\n\n if (txParams.maxFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'maxFeePerGas');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsString(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 ensureFieldIsString(txParams, 'maxPriorityFeePerGas');\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: GasFieldsToValidate,\n) {\n switch (field) {\n case 'maxFeePerGas':\n case 'maxPriorityFeePerGas':\n if (\n txParams.type &&\n txParams.type !== TransactionEnvelopeType.feeMarket\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${txParams.type}\" but including maxFeePerGas and maxPriorityFeePerGas requires type: \"${TransactionEnvelopeType.feeMarket}\"`,\n );\n }\n break;\n case 'gasPrice':\n default:\n if (\n txParams.type &&\n txParams.type === TransactionEnvelopeType.feeMarket\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${txParams.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 string, throws an\n * invalidParams error if field is not a string.\n *\n * @param txParams - The transaction parameters object\n * @param field - The current field being validated\n * @throws {rpcErrors.invalidParams} Throws if field is not a string\n */\nfunction ensureFieldIsString(\n txParams: TransactionParams,\n field: GasFieldsToValidate,\n) {\n if (typeof txParams[field] !== 'string') {\n throw rpcErrors.invalidParams(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Invalid transaction params: ${field} is not a string. got: (${txParams[field]})`,\n );\n }\n}\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isEIP1559Transaction
|
|
3
3
|
} from "./chunk-Q56I5ONX.mjs";
|
|
4
|
+
import {
|
|
5
|
+
TransactionEnvelopeType
|
|
6
|
+
} from "./chunk-6SJYXSF3.mjs";
|
|
4
7
|
|
|
5
8
|
// src/utils/validation.ts
|
|
6
9
|
import { Interface } from "@ethersproject/abi";
|
|
@@ -26,6 +29,7 @@ async function validateTransactionOrigin(permittedAddresses, selectedAddress, fr
|
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
function validateTxParams(txParams, isEIP1559Compatible = true) {
|
|
32
|
+
validateEnvelopeType(txParams.type);
|
|
29
33
|
validateEIP1559Compatibility(txParams, isEIP1559Compatible);
|
|
30
34
|
validateParamFrom(txParams.from);
|
|
31
35
|
validateParamRecipient(txParams);
|
|
@@ -34,6 +38,17 @@ function validateTxParams(txParams, isEIP1559Compatible = true) {
|
|
|
34
38
|
validateParamChainId(txParams.chainId);
|
|
35
39
|
validateGasFeeParams(txParams);
|
|
36
40
|
}
|
|
41
|
+
function validateEnvelopeType(type) {
|
|
42
|
+
if (type && !Object.values(TransactionEnvelopeType).includes(
|
|
43
|
+
type
|
|
44
|
+
)) {
|
|
45
|
+
throw rpcErrors.invalidParams(
|
|
46
|
+
`Invalid transaction envelope type: "${type}". Must be one of: ${Object.values(
|
|
47
|
+
TransactionEnvelopeType
|
|
48
|
+
).join(", ")}`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
37
52
|
function validateEIP1559Compatibility(txParams, isEIP1559Compatible) {
|
|
38
53
|
if (isEIP1559Transaction(txParams) && !isEIP1559Compatible) {
|
|
39
54
|
throw rpcErrors.invalidParams(
|
|
@@ -183,4 +198,4 @@ export {
|
|
|
183
198
|
validateTransactionOrigin,
|
|
184
199
|
validateTxParams
|
|
185
200
|
};
|
|
186
|
-
//# sourceMappingURL=chunk-
|
|
201
|
+
//# sourceMappingURL=chunk-LTPS73D7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/validation.ts"],"sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport { ORIGIN_METAMASK, isValidHexAddress } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\n\nimport { TransactionEnvelopeType, type TransactionParams } from '../types';\nimport { isEIP1559Transaction } from './utils';\n\ntype GasFieldsToValidate = 'gasPrice' | 'maxFeePerGas' | 'maxPriorityFeePerGas';\n\n/**\n * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.\n *\n * @param permittedAddresses - The permitted accounts for the given origin.\n * @param selectedAddress - The currently selected Ethereum address in the wallet.\n * @param from - The address from which the transaction is initiated.\n * @param origin - The origin or source of the transaction.\n * @throws Throws an error if the transaction is not permitted.\n */\nexport async function validateTransactionOrigin(\n permittedAddresses: string[],\n selectedAddress: string,\n from: string,\n origin: string,\n) {\n if (origin === ORIGIN_METAMASK) {\n // Ensure the 'from' address matches the currently selected address\n if (from !== selectedAddress) {\n throw rpcErrors.internal({\n message: `Internally initiated transaction is using invalid account.`,\n data: {\n origin,\n fromAddress: from,\n selectedAddress,\n },\n });\n }\n return;\n }\n\n // Check if the origin has permissions to initiate transactions from the specified address\n if (!permittedAddresses.includes(from)) {\n throw providerErrors.unauthorized({ data: { origin } });\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 */\nexport function validateTxParams(\n txParams: TransactionParams,\n isEIP1559Compatible = true,\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);\n validateGasFeeParams(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 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 chainId - The chainId to validate.\n */\nfunction validateParamChainId(chainId: number | string | undefined) {\n if (\n chainId !== undefined &&\n typeof chainId !== 'number' &&\n typeof chainId !== 'string'\n ) {\n throw rpcErrors.invalidParams(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Invalid transaction params: chainId is not a Number or hex string. got: (${chainId})`,\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 ensureFieldIsString(txParams, 'gasPrice');\n }\n\n if (txParams.maxFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'maxFeePerGas');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsString(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 ensureFieldIsString(txParams, 'maxPriorityFeePerGas');\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: GasFieldsToValidate,\n) {\n switch (field) {\n case 'maxFeePerGas':\n case 'maxPriorityFeePerGas':\n if (\n txParams.type &&\n txParams.type !== TransactionEnvelopeType.feeMarket\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${txParams.type}\" but including maxFeePerGas and maxPriorityFeePerGas requires type: \"${TransactionEnvelopeType.feeMarket}\"`,\n );\n }\n break;\n case 'gasPrice':\n default:\n if (\n txParams.type &&\n txParams.type === TransactionEnvelopeType.feeMarket\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${txParams.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 string, throws an\n * invalidParams error if field is not a string.\n *\n * @param txParams - The transaction parameters object\n * @param field - The current field being validated\n * @throws {rpcErrors.invalidParams} Throws if field is not a string\n */\nfunction ensureFieldIsString(\n txParams: TransactionParams,\n field: GasFieldsToValidate,\n) {\n if (typeof txParams[field] !== 'string') {\n throw rpcErrors.invalidParams(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Invalid transaction params: ${field} is not a string. got: (${txParams[field]})`,\n );\n }\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB,yBAAyB;AACnD,SAAS,gBAAgB;AACzB,SAAS,gBAAgB,iBAAiB;AAgB1C,eAAsB,0BACpB,oBACA,iBACA,MACA,QACA;AACA,MAAI,WAAW,iBAAiB;AAE9B,QAAI,SAAS,iBAAiB;AAC5B,YAAM,UAAU,SAAS;AAAA,QACvB,SAAS;AAAA,QACT,MAAM;AAAA,UACJ;AAAA,UACA,aAAa;AAAA,UACb;AAAA,QACF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,IACF;AACA,wBAAoB,UAAU,UAAU;AAAA,EAC1C;AAEA,MAAI,SAAS,cAAc;AACzB,gDAA4C,UAAU,cAAc;AACpE;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,wBAAoB,UAAU,cAAc;AAAA,EAC9C;AAEA,MAAI,SAAS,sBAAsB;AACjC;AAAA,MACE;AAAA,MACA;AAAA,IACF;AACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,wBAAoB,UAAU,sBAAsB;AAAA,EACtD;AACF;AAYA,SAAS,4CACP,UACA,OACA;AACA,UAAQ,OAAO;AAAA,IACb,KAAK;AAAA,IACL,KAAK;AACH,UACE,SAAS,QACT,SAAS,gCACT;AACA,cAAM,UAAU;AAAA,UACd,sDAAsD,SAAS,IAAI,8FAA0G;AAAA,QAC/K;AAAA,MACF;AACA;AAAA,IACF,KAAK;AAAA,IACL;AACE,UACE,SAAS,QACT,SAAS,gCACT;AACA,cAAM,UAAU;AAAA,UACd,sDAAsD,SAAS,IAAI;AAAA,QACrE;AAAA,MACF;AAAA,EACJ;AACF;AAYA,SAAS,yCACP,UACA,qBACA,wBACA;AACA,MAAI,OAAO,SAAS,sBAAsB,MAAM,aAAa;AAC3D,UAAM,UAAU;AAAA,MACd,yCAAyC,mBAAmB,sBAAsB,sBAAsB;AAAA,IAC1G;AAAA,EACF;AACF;AAUA,SAAS,oBACP,UACA,OACA;AACA,MAAI,OAAO,SAAS,KAAK,MAAM,UAAU;AACvC,UAAM,UAAU;AAAA;AAAA;AAAA,MAGd,+BAA+B,KAAK,2BAA2B,SAAS,KAAK,CAAC;AAAA,IAChF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -11,7 +11,7 @@ var _chunkSD6CWFDFjs = require('./chunk-SD6CWFDF.js');
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunkGPS6RX64js = require('./chunk-GPS6RX64.js');
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
var _chunkULD4JC3Qjs = require('./chunk-ULD4JC3Q.js');
|
|
@@ -464,9 +464,9 @@ var TransactionController = class extends _basecontroller.BaseController {
|
|
|
464
464
|
const isEIP1559Compatible = await this.getEIP1559Compatibility(
|
|
465
465
|
networkClientId
|
|
466
466
|
);
|
|
467
|
-
|
|
467
|
+
_chunkGPS6RX64js.validateTxParams.call(void 0, txParams, isEIP1559Compatible);
|
|
468
468
|
if (origin) {
|
|
469
|
-
await
|
|
469
|
+
await _chunkGPS6RX64js.validateTransactionOrigin.call(void 0,
|
|
470
470
|
await this.getPermittedAccounts(origin),
|
|
471
471
|
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getSelectedAccount, getSelectedAccount_fn).call(this).address,
|
|
472
472
|
txParams.from,
|
|
@@ -528,7 +528,10 @@ var TransactionController = class extends _basecontroller.BaseController {
|
|
|
528
528
|
);
|
|
529
529
|
this.addMetadata(addedTransactionMeta);
|
|
530
530
|
if (requireApproval !== false) {
|
|
531
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateSimulationData, updateSimulationData_fn).call(this, addedTransactionMeta)
|
|
531
|
+
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateSimulationData, updateSimulationData_fn).call(this, addedTransactionMeta).catch((error) => {
|
|
532
|
+
_chunkS6VGOPUYjs.projectLogger.call(void 0, "Error while updating simulation data", error);
|
|
533
|
+
throw error;
|
|
534
|
+
});
|
|
532
535
|
} else {
|
|
533
536
|
_chunkS6VGOPUYjs.projectLogger.call(void 0, "Skipping simulation as approval not required");
|
|
534
537
|
}
|
|
@@ -960,7 +963,10 @@ var TransactionController = class extends _basecontroller.BaseController {
|
|
|
960
963
|
`${controllerName}:confirmExternalTransaction - Add external transaction`
|
|
961
964
|
);
|
|
962
965
|
this.onTransactionStatusChange(updatedTransactionMeta);
|
|
963
|
-
this.updatePostBalance(updatedTransactionMeta)
|
|
966
|
+
this.updatePostBalance(updatedTransactionMeta).catch((error) => {
|
|
967
|
+
_chunkS6VGOPUYjs.projectLogger.call(void 0, "Error while updating post balance", error);
|
|
968
|
+
throw error;
|
|
969
|
+
});
|
|
964
970
|
this.messagingSystem.publish(
|
|
965
971
|
`${controllerName}:transactionConfirmed`,
|
|
966
972
|
updatedTransactionMeta
|
|
@@ -1492,6 +1498,7 @@ var TransactionController = class extends _basecontroller.BaseController {
|
|
|
1492
1498
|
this.signAbortCallbacks.delete(transactionId);
|
|
1493
1499
|
}
|
|
1494
1500
|
addMetadata(transactionMeta) {
|
|
1501
|
+
_chunkGPS6RX64js.validateTxParams.call(void 0, transactionMeta.txParams);
|
|
1495
1502
|
this.update((state) => {
|
|
1496
1503
|
state.transactions = this.trimTransactionsForState([
|
|
1497
1504
|
...state.transactions,
|
|
@@ -1500,7 +1507,7 @@ var TransactionController = class extends _basecontroller.BaseController {
|
|
|
1500
1507
|
});
|
|
1501
1508
|
}
|
|
1502
1509
|
async updateGasProperties(transactionMeta) {
|
|
1503
|
-
const isEIP1559Compatible =
|
|
1510
|
+
const isEIP1559Compatible = transactionMeta.txParams.type !== "0x0" /* legacy */ && await this.getEIP1559Compatibility(transactionMeta.networkClientId);
|
|
1504
1511
|
const { networkClientId, chainId } = transactionMeta;
|
|
1505
1512
|
const isCustomNetwork = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _isCustomNetwork, isCustomNetwork_fn).call(this, networkClientId);
|
|
1506
1513
|
const ethQuery = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _multichainTrackingHelper).getEthQuery({
|
|
@@ -2177,7 +2184,10 @@ var TransactionController = class extends _basecontroller.BaseController {
|
|
|
2177
2184
|
transactionMeta
|
|
2178
2185
|
);
|
|
2179
2186
|
this.onTransactionStatusChange(transactionMeta);
|
|
2180
|
-
this.updatePostBalance(transactionMeta)
|
|
2187
|
+
this.updatePostBalance(transactionMeta).catch((error) => {
|
|
2188
|
+
_chunkS6VGOPUYjs.projectLogger.call(void 0, "Error while updating post balance", error);
|
|
2189
|
+
throw error;
|
|
2190
|
+
});
|
|
2181
2191
|
}
|
|
2182
2192
|
async updatePostBalance(transactionMeta) {
|
|
2183
2193
|
try {
|
|
@@ -2248,7 +2258,7 @@ createNonceTracker_fn = function({
|
|
|
2248
2258
|
// TODO: Fix types
|
|
2249
2259
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2250
2260
|
provider,
|
|
2251
|
-
//
|
|
2261
|
+
// TODO: Fix types
|
|
2252
2262
|
blockTracker,
|
|
2253
2263
|
getPendingTransactions: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getNonceTrackerPendingTransactions, getNonceTrackerPendingTransactions_fn).bind(
|
|
2254
2264
|
this,
|
|
@@ -2402,7 +2412,7 @@ updateTransactionInternal_fn = function({
|
|
|
2402
2412
|
transactionMeta2.txParams = _chunkOZ6UB42Cjs.normalizeTransactionParams.call(void 0,
|
|
2403
2413
|
transactionMeta2.txParams
|
|
2404
2414
|
);
|
|
2405
|
-
|
|
2415
|
+
_chunkGPS6RX64js.validateTxParams.call(void 0, transactionMeta2.txParams);
|
|
2406
2416
|
updatedTransactionParams = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _checkIfTransactionParamsUpdated, checkIfTransactionParamsUpdated_fn).call(this, transactionMeta2);
|
|
2407
2417
|
const shouldSkipHistory = this.isHistoryDisabled || skipHistory;
|
|
2408
2418
|
if (!shouldSkipHistory) {
|
|
@@ -2447,7 +2457,10 @@ onTransactionParamsUpdated_fn = function(transactionMeta, updatedParams) {
|
|
|
2447
2457
|
(param) => updatedParams.includes(param)
|
|
2448
2458
|
)) {
|
|
2449
2459
|
_chunkS6VGOPUYjs.projectLogger.call(void 0, "Updating simulation data due to transaction parameter update");
|
|
2450
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateSimulationData, updateSimulationData_fn).call(this, transactionMeta)
|
|
2460
|
+
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateSimulationData, updateSimulationData_fn).call(this, transactionMeta).catch((error) => {
|
|
2461
|
+
_chunkS6VGOPUYjs.projectLogger.call(void 0, "Error updating simulation data", error);
|
|
2462
|
+
throw error;
|
|
2463
|
+
});
|
|
2451
2464
|
}
|
|
2452
2465
|
};
|
|
2453
2466
|
_updateSimulationData = new WeakSet();
|
|
@@ -2563,4 +2576,4 @@ getSelectedAccount_fn = function() {
|
|
|
2563
2576
|
|
|
2564
2577
|
|
|
2565
2578
|
exports.HARDFORK = HARDFORK; exports.CANCEL_RATE = CANCEL_RATE; exports.SPEED_UP_RATE = SPEED_UP_RATE; exports.ApprovalState = ApprovalState; exports.TransactionController = TransactionController;
|
|
2566
|
-
//# sourceMappingURL=chunk-
|
|
2579
|
+
//# sourceMappingURL=chunk-S3RZBMF7.js.map
|