@metamask/transaction-controller 36.1.0 → 37.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 (480) hide show
  1. package/CHANGELOG.md +47 -1
  2. package/dist/TransactionController.cjs +2071 -0
  3. package/dist/TransactionController.cjs.map +1 -0
  4. package/dist/{types/TransactionController.d.ts → TransactionController.d.cts} +19 -26
  5. package/dist/TransactionController.d.cts.map +1 -0
  6. package/dist/TransactionController.d.mts +828 -0
  7. package/dist/TransactionController.d.mts.map +1 -0
  8. package/dist/TransactionController.mjs +2072 -44
  9. package/dist/TransactionController.mjs.map +1 -1
  10. package/dist/constants.cjs +170 -0
  11. package/dist/constants.cjs.map +1 -0
  12. package/dist/{types/constants.d.ts → constants.d.cts} +1 -1
  13. package/dist/constants.d.cts.map +1 -0
  14. package/dist/constants.d.mts +143 -0
  15. package/dist/constants.d.mts.map +1 -0
  16. package/dist/constants.mjs +165 -18
  17. package/dist/constants.mjs.map +1 -1
  18. package/dist/errors.cjs +30 -0
  19. package/dist/{chunk-HMOSP33F.js.map → errors.cjs.map} +1 -1
  20. package/dist/{types/errors.d.ts → errors.d.cts} +2 -2
  21. package/dist/errors.d.cts.map +1 -0
  22. package/dist/errors.d.mts +15 -0
  23. package/dist/errors.d.mts.map +1 -0
  24. package/dist/errors.mjs +22 -14
  25. package/dist/errors.mjs.map +1 -1
  26. package/dist/gas-flows/DefaultGasFeeFlow.cjs +87 -0
  27. package/dist/gas-flows/DefaultGasFeeFlow.cjs.map +1 -0
  28. package/dist/{types/gas-flows/DefaultGasFeeFlow.d.ts → gas-flows/DefaultGasFeeFlow.d.cts} +2 -2
  29. package/dist/gas-flows/DefaultGasFeeFlow.d.cts.map +1 -0
  30. package/dist/gas-flows/DefaultGasFeeFlow.d.mts +10 -0
  31. package/dist/gas-flows/DefaultGasFeeFlow.d.mts.map +1 -0
  32. package/dist/gas-flows/DefaultGasFeeFlow.mjs +81 -13
  33. package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -1
  34. package/dist/gas-flows/LineaGasFeeFlow.cjs +102 -0
  35. package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -0
  36. package/dist/{types/gas-flows/LineaGasFeeFlow.d.ts → gas-flows/LineaGasFeeFlow.d.cts} +2 -2
  37. package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -0
  38. package/dist/gas-flows/LineaGasFeeFlow.d.mts +12 -0
  39. package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -0
  40. package/dist/gas-flows/LineaGasFeeFlow.mjs +96 -14
  41. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
  42. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +29 -0
  43. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -0
  44. package/dist/{types/gas-flows/OptimismLayer1GasFeeFlow.d.ts → gas-flows/OptimismLayer1GasFeeFlow.d.cts} +3 -3
  45. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -0
  46. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts +10 -0
  47. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -0
  48. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs +24 -10
  49. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -1
  50. package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs +92 -0
  51. package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs.map +1 -0
  52. package/dist/{types/gas-flows/OracleLayer1GasFeeFlow.d.ts → gas-flows/OracleLayer1GasFeeFlow.d.cts} +3 -3
  53. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts.map +1 -0
  54. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts +12 -0
  55. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts.map +1 -0
  56. package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs +88 -7
  57. package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs.map +1 -1
  58. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +21 -0
  59. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -0
  60. package/dist/{types/gas-flows/ScrollLayer1GasFeeFlow.d.ts → gas-flows/ScrollLayer1GasFeeFlow.d.cts} +3 -3
  61. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -0
  62. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts +10 -0
  63. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -0
  64. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs +16 -10
  65. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -1
  66. package/dist/gas-flows/TestGasFeeFlow.cjs +73 -0
  67. package/dist/{chunk-FMRLPVFZ.mjs.map → gas-flows/TestGasFeeFlow.cjs.map} +1 -1
  68. package/dist/{types/gas-flows/TestGasFeeFlow.d.ts → gas-flows/TestGasFeeFlow.d.cts} +2 -2
  69. package/dist/gas-flows/TestGasFeeFlow.d.cts.map +1 -0
  70. package/dist/gas-flows/TestGasFeeFlow.d.mts +12 -0
  71. package/dist/gas-flows/TestGasFeeFlow.d.mts.map +1 -0
  72. package/dist/gas-flows/TestGasFeeFlow.mjs +67 -7
  73. package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -1
  74. package/dist/helpers/EtherscanRemoteTransactionSource.cjs +149 -0
  75. package/dist/helpers/EtherscanRemoteTransactionSource.cjs.map +1 -0
  76. package/dist/{types/helpers/EtherscanRemoteTransactionSource.d.ts → helpers/EtherscanRemoteTransactionSource.d.cts} +3 -3
  77. package/dist/helpers/EtherscanRemoteTransactionSource.d.cts.map +1 -0
  78. package/dist/helpers/EtherscanRemoteTransactionSource.d.mts +15 -0
  79. package/dist/helpers/EtherscanRemoteTransactionSource.d.mts.map +1 -0
  80. package/dist/helpers/EtherscanRemoteTransactionSource.mjs +147 -10
  81. package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -1
  82. package/dist/helpers/GasFeePoller.cjs +185 -0
  83. package/dist/helpers/GasFeePoller.cjs.map +1 -0
  84. package/dist/{types/helpers/GasFeePoller.d.ts → helpers/GasFeePoller.d.cts} +7 -7
  85. package/dist/helpers/GasFeePoller.d.cts.map +1 -0
  86. package/dist/helpers/GasFeePoller.d.mts +35 -0
  87. package/dist/helpers/GasFeePoller.d.mts.map +1 -0
  88. package/dist/helpers/GasFeePoller.mjs +183 -10
  89. package/dist/helpers/GasFeePoller.mjs.map +1 -1
  90. package/dist/helpers/IncomingTransactionHelper.cjs +199 -0
  91. package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -0
  92. package/dist/{types/helpers/IncomingTransactionHelper.d.ts → helpers/IncomingTransactionHelper.d.cts} +6 -6
  93. package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -0
  94. package/dist/helpers/IncomingTransactionHelper.d.mts +40 -0
  95. package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -0
  96. package/dist/helpers/IncomingTransactionHelper.mjs +190 -7
  97. package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
  98. package/dist/helpers/MultichainTrackingHelper.cjs +284 -0
  99. package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -0
  100. package/dist/{types/helpers/MultichainTrackingHelper.d.ts → helpers/MultichainTrackingHelper.d.cts} +8 -8
  101. package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -0
  102. package/dist/helpers/MultichainTrackingHelper.d.mts +76 -0
  103. package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -0
  104. package/dist/helpers/MultichainTrackingHelper.mjs +282 -11
  105. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
  106. package/dist/helpers/PendingTransactionTracker.cjs +327 -0
  107. package/dist/helpers/PendingTransactionTracker.cjs.map +1 -0
  108. package/dist/{types/helpers/PendingTransactionTracker.d.ts → helpers/PendingTransactionTracker.d.cts} +7 -8
  109. package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -0
  110. package/dist/helpers/PendingTransactionTracker.d.mts +42 -0
  111. package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -0
  112. package/dist/helpers/PendingTransactionTracker.mjs +319 -8
  113. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
  114. package/dist/index.cjs +32 -0
  115. package/dist/index.cjs.map +1 -0
  116. package/dist/{types/index.d.ts → index.d.cts} +11 -10
  117. package/dist/index.d.cts.map +1 -0
  118. package/dist/index.d.mts +11 -0
  119. package/dist/index.d.mts.map +1 -0
  120. package/dist/index.mjs +7 -76
  121. package/dist/index.mjs.map +1 -1
  122. package/dist/logger.cjs +9 -0
  123. package/dist/logger.cjs.map +1 -0
  124. package/dist/{types/logger.d.ts → logger.d.cts} +2 -2
  125. package/dist/logger.d.cts.map +1 -0
  126. package/dist/logger.d.mts +6 -0
  127. package/dist/logger.d.mts.map +1 -0
  128. package/dist/logger.mjs +5 -11
  129. package/dist/logger.mjs.map +1 -1
  130. package/dist/types.cjs +308 -0
  131. package/dist/types.cjs.map +1 -0
  132. package/dist/{types/types.d.ts → types.d.cts} +35 -35
  133. package/dist/types.d.cts.map +1 -0
  134. package/dist/types.d.mts +1027 -0
  135. package/dist/types.d.mts.map +1 -0
  136. package/dist/types.mjs +304 -23
  137. package/dist/types.mjs.map +1 -1
  138. package/dist/utils/etherscan.cjs +111 -0
  139. package/dist/utils/etherscan.cjs.map +1 -0
  140. package/dist/{types/utils/etherscan.d.ts → utils/etherscan.d.cts} +2 -2
  141. package/dist/utils/etherscan.d.cts.map +1 -0
  142. package/dist/utils/etherscan.d.mts +71 -0
  143. package/dist/utils/etherscan.d.mts.map +1 -0
  144. package/dist/utils/etherscan.mjs +104 -13
  145. package/dist/utils/etherscan.mjs.map +1 -1
  146. package/dist/utils/external-transactions.cjs +36 -0
  147. package/dist/utils/external-transactions.cjs.map +1 -0
  148. package/dist/{types/utils/external-transactions.d.ts → utils/external-transactions.d.cts} +2 -2
  149. package/dist/utils/external-transactions.d.cts.map +1 -0
  150. package/dist/utils/external-transactions.d.mts +10 -0
  151. package/dist/utils/external-transactions.d.mts.map +1 -0
  152. package/dist/utils/external-transactions.mjs +31 -8
  153. package/dist/utils/external-transactions.mjs.map +1 -1
  154. package/dist/utils/gas-fees.cjs +208 -0
  155. package/dist/utils/gas-fees.cjs.map +1 -0
  156. package/dist/{types/utils/gas-fees.d.ts → utils/gas-fees.d.cts} +5 -5
  157. package/dist/utils/gas-fees.d.cts.map +1 -0
  158. package/dist/utils/gas-fees.d.mts +26 -0
  159. package/dist/utils/gas-fees.d.mts.map +1 -0
  160. package/dist/utils/gas-fees.mjs +202 -15
  161. package/dist/utils/gas-fees.mjs.map +1 -1
  162. package/dist/utils/gas-flow.cjs +76 -0
  163. package/dist/utils/gas-flow.cjs.map +1 -0
  164. package/dist/{types/utils/gas-flow.d.ts → utils/gas-flow.d.cts} +5 -5
  165. package/dist/utils/gas-flow.d.cts.map +1 -0
  166. package/dist/utils/gas-flow.d.mts +26 -0
  167. package/dist/utils/gas-flow.d.mts.map +1 -0
  168. package/dist/utils/gas-flow.mjs +70 -10
  169. package/dist/utils/gas-flow.mjs.map +1 -1
  170. package/dist/utils/gas.cjs +112 -0
  171. package/dist/utils/gas.cjs.map +1 -0
  172. package/dist/{types/utils/gas.d.ts → utils/gas.d.cts} +4 -4
  173. package/dist/utils/gas.d.cts.map +1 -0
  174. package/dist/utils/gas.d.mts +28 -0
  175. package/dist/utils/gas.d.mts.map +1 -0
  176. package/dist/utils/gas.mjs +105 -19
  177. package/dist/utils/gas.mjs.map +1 -1
  178. package/dist/utils/history.cjs +164 -0
  179. package/dist/utils/history.cjs.map +1 -0
  180. package/dist/{types/utils/history.d.ts → utils/history.d.cts} +2 -2
  181. package/dist/utils/history.d.cts.map +1 -0
  182. package/dist/utils/history.d.mts +29 -0
  183. package/dist/utils/history.d.mts.map +1 -0
  184. package/dist/utils/history.mjs +163 -13
  185. package/dist/utils/history.mjs.map +1 -1
  186. package/dist/utils/layer1-gas-fee-flow.cjs +59 -0
  187. package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -0
  188. package/dist/{types/utils/layer1-gas-fee-flow.d.ts → utils/layer1-gas-fee-flow.d.cts} +4 -4
  189. package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -0
  190. package/dist/utils/layer1-gas-fee-flow.d.mts +25 -0
  191. package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -0
  192. package/dist/utils/layer1-gas-fee-flow.mjs +53 -10
  193. package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
  194. package/dist/utils/nonce.cjs +66 -0
  195. package/dist/utils/nonce.cjs.map +1 -0
  196. package/dist/{types/utils/nonce.d.ts → utils/nonce.d.cts} +3 -3
  197. package/dist/utils/nonce.d.cts.map +1 -0
  198. package/dist/utils/nonce.d.mts +21 -0
  199. package/dist/utils/nonce.d.mts.map +1 -0
  200. package/dist/utils/nonce.mjs +60 -10
  201. package/dist/utils/nonce.mjs.map +1 -1
  202. package/dist/utils/retry.cjs +89 -0
  203. package/dist/utils/retry.cjs.map +1 -0
  204. package/dist/{types/utils/retry.d.ts → utils/retry.d.cts} +3 -3
  205. package/dist/utils/retry.d.cts.map +1 -0
  206. package/dist/utils/retry.d.mts +11 -0
  207. package/dist/utils/retry.d.mts.map +1 -0
  208. package/dist/utils/retry.mjs +84 -7
  209. package/dist/utils/retry.mjs.map +1 -1
  210. package/dist/utils/simulation-api.cjs +72 -0
  211. package/dist/utils/simulation-api.cjs.map +1 -0
  212. package/dist/{types/utils/simulation-api.d.ts → utils/simulation-api.d.cts} +2 -2
  213. package/dist/utils/simulation-api.d.cts.map +1 -0
  214. package/dist/utils/simulation-api.d.mts +107 -0
  215. package/dist/utils/simulation-api.d.mts.map +1 -0
  216. package/dist/utils/simulation-api.mjs +67 -10
  217. package/dist/utils/simulation-api.mjs.map +1 -1
  218. package/dist/utils/simulation.cjs +443 -0
  219. package/dist/utils/simulation.cjs.map +1 -0
  220. package/dist/{types/utils/simulation.d.ts → utils/simulation.d.cts} +6 -6
  221. package/dist/utils/simulation.d.cts.map +1 -0
  222. package/dist/utils/simulation.d.mts +46 -0
  223. package/dist/utils/simulation.d.mts.map +1 -0
  224. package/dist/utils/simulation.mjs +436 -15
  225. package/dist/utils/simulation.mjs.map +1 -1
  226. package/dist/utils/swaps.cjs +309 -0
  227. package/dist/utils/swaps.cjs.map +1 -0
  228. package/dist/{types/utils/swaps.d.ts → utils/swaps.d.cts} +5 -5
  229. package/dist/utils/swaps.d.cts.map +1 -0
  230. package/dist/utils/swaps.d.mts +84 -0
  231. package/dist/utils/swaps.d.mts.map +1 -0
  232. package/dist/utils/swaps.mjs +303 -22
  233. package/dist/utils/swaps.mjs.map +1 -1
  234. package/dist/utils/transaction-type.cjs +115 -0
  235. package/dist/utils/transaction-type.cjs.map +1 -0
  236. package/dist/{types/utils/transaction-type.d.ts → utils/transaction-type.d.cts} +3 -3
  237. package/dist/utils/transaction-type.d.cts.map +1 -0
  238. package/dist/utils/transaction-type.d.mts +14 -0
  239. package/dist/utils/transaction-type.d.mts.map +1 -0
  240. package/dist/utils/transaction-type.mjs +110 -10
  241. package/dist/utils/transaction-type.mjs.map +1 -1
  242. package/dist/utils/utils.cjs +151 -0
  243. package/dist/utils/utils.cjs.map +1 -0
  244. package/dist/{types/utils/utils.d.ts → utils/utils.d.cts} +2 -2
  245. package/dist/utils/utils.d.cts.map +1 -0
  246. package/dist/utils/utils.d.mts +52 -0
  247. package/dist/utils/utils.d.mts.map +1 -0
  248. package/dist/utils/utils.mjs +139 -21
  249. package/dist/utils/utils.mjs.map +1 -1
  250. package/dist/utils/validation.cjs +267 -0
  251. package/dist/{chunk-4OYPDGHO.js.map → utils/validation.cjs.map} +1 -1
  252. package/dist/{types/utils/validation.d.ts → utils/validation.d.cts} +2 -2
  253. package/dist/utils/validation.d.cts.map +1 -0
  254. package/dist/utils/validation.d.mts +20 -0
  255. package/dist/utils/validation.d.mts.map +1 -0
  256. package/dist/utils/validation.mjs +261 -11
  257. package/dist/utils/validation.mjs.map +1 -1
  258. package/package.json +20 -15
  259. package/dist/TransactionController.js +0 -46
  260. package/dist/TransactionController.js.map +0 -1
  261. package/dist/chunk-2XKEAKQG.js +0 -55
  262. package/dist/chunk-2XKEAKQG.js.map +0 -1
  263. package/dist/chunk-3AVRGHUO.mjs +0 -360
  264. package/dist/chunk-3AVRGHUO.mjs.map +0 -1
  265. package/dist/chunk-3ZV5YEUV.mjs +0 -239
  266. package/dist/chunk-3ZV5YEUV.mjs.map +0 -1
  267. package/dist/chunk-4OYPDGHO.js +0 -201
  268. package/dist/chunk-4V4XIPCI.mjs +0 -338
  269. package/dist/chunk-4V4XIPCI.mjs.map +0 -1
  270. package/dist/chunk-5G6OHAXI.mjs +0 -137
  271. package/dist/chunk-5G6OHAXI.mjs.map +0 -1
  272. package/dist/chunk-5HYWLTVQ.js +0 -228
  273. package/dist/chunk-5HYWLTVQ.js.map +0 -1
  274. package/dist/chunk-5QVDIVJH.js +0 -68
  275. package/dist/chunk-5QVDIVJH.js.map +0 -1
  276. package/dist/chunk-6B5BEO3R.mjs +0 -399
  277. package/dist/chunk-6B5BEO3R.mjs.map +0 -1
  278. package/dist/chunk-6DDVVUJC.mjs +0 -50
  279. package/dist/chunk-6DDVVUJC.mjs.map +0 -1
  280. package/dist/chunk-6OLJWLKK.js +0 -338
  281. package/dist/chunk-6OLJWLKK.js.map +0 -1
  282. package/dist/chunk-7LXE4KHV.js +0 -40
  283. package/dist/chunk-7LXE4KHV.js.map +0 -1
  284. package/dist/chunk-7NMV2NPM.js +0 -172
  285. package/dist/chunk-7NMV2NPM.js.map +0 -1
  286. package/dist/chunk-AWIJZAW3.mjs +0 -112
  287. package/dist/chunk-AWIJZAW3.mjs.map +0 -1
  288. package/dist/chunk-BZV72SCF.js +0 -226
  289. package/dist/chunk-BZV72SCF.js.map +0 -1
  290. package/dist/chunk-EGQCE3FK.mjs +0 -85
  291. package/dist/chunk-EGQCE3FK.mjs.map +0 -1
  292. package/dist/chunk-EHWAY6XU.js +0 -112
  293. package/dist/chunk-EHWAY6XU.js.map +0 -1
  294. package/dist/chunk-EKJXGERC.mjs +0 -172
  295. package/dist/chunk-EKJXGERC.mjs.map +0 -1
  296. package/dist/chunk-FG74Z3F5.mjs +0 -102
  297. package/dist/chunk-FG74Z3F5.mjs.map +0 -1
  298. package/dist/chunk-FMRLPVFZ.mjs +0 -66
  299. package/dist/chunk-FRKQ3Z2L.mjs +0 -40
  300. package/dist/chunk-FRKQ3Z2L.mjs.map +0 -1
  301. package/dist/chunk-HMOSP33F.js +0 -36
  302. package/dist/chunk-HQSNKCXI.mjs +0 -36
  303. package/dist/chunk-HQSNKCXI.mjs.map +0 -1
  304. package/dist/chunk-JIFPK37W.mjs +0 -257
  305. package/dist/chunk-JIFPK37W.mjs.map +0 -1
  306. package/dist/chunk-JOQK7A5G.mjs +0 -68
  307. package/dist/chunk-JOQK7A5G.mjs.map +0 -1
  308. package/dist/chunk-K4KOSAGM.mjs +0 -61
  309. package/dist/chunk-K4KOSAGM.mjs.map +0 -1
  310. package/dist/chunk-KG4UW4K4.mjs +0 -88
  311. package/dist/chunk-KG4UW4K4.mjs.map +0 -1
  312. package/dist/chunk-KT6UAKBB.js +0 -61
  313. package/dist/chunk-KT6UAKBB.js.map +0 -1
  314. package/dist/chunk-KTGMNUTQ.js +0 -106
  315. package/dist/chunk-KTGMNUTQ.js.map +0 -1
  316. package/dist/chunk-KYRW4BLA.mjs +0 -121
  317. package/dist/chunk-KYRW4BLA.mjs.map +0 -1
  318. package/dist/chunk-LFFYCDHB.mjs +0 -92
  319. package/dist/chunk-LFFYCDHB.mjs.map +0 -1
  320. package/dist/chunk-NNCUD3QF.js +0 -360
  321. package/dist/chunk-NNCUD3QF.js.map +0 -1
  322. package/dist/chunk-NNHSNPT2.mjs +0 -67
  323. package/dist/chunk-NNHSNPT2.mjs.map +0 -1
  324. package/dist/chunk-NOHEXQ7Y.mjs +0 -55
  325. package/dist/chunk-NOHEXQ7Y.mjs.map +0 -1
  326. package/dist/chunk-NYKRCWBG.js +0 -31
  327. package/dist/chunk-NYKRCWBG.js.map +0 -1
  328. package/dist/chunk-O6ZZVIFH.mjs +0 -176
  329. package/dist/chunk-O6ZZVIFH.mjs.map +0 -1
  330. package/dist/chunk-PRUNMTRD.js +0 -50
  331. package/dist/chunk-PRUNMTRD.js.map +0 -1
  332. package/dist/chunk-PSZ34BI5.js +0 -92
  333. package/dist/chunk-PSZ34BI5.js.map +0 -1
  334. package/dist/chunk-QKV7E5BO.js +0 -257
  335. package/dist/chunk-QKV7E5BO.js.map +0 -1
  336. package/dist/chunk-RHDPOIS4.js +0 -239
  337. package/dist/chunk-RHDPOIS4.js.map +0 -1
  338. package/dist/chunk-S6VGOPUY.js +0 -14
  339. package/dist/chunk-S6VGOPUY.js.map +0 -1
  340. package/dist/chunk-SD6CWFDF.js +0 -88
  341. package/dist/chunk-SD6CWFDF.js.map +0 -1
  342. package/dist/chunk-SFFOC25Q.mjs +0 -226
  343. package/dist/chunk-SFFOC25Q.mjs.map +0 -1
  344. package/dist/chunk-SMC5Q6ZH.mjs +0 -120
  345. package/dist/chunk-SMC5Q6ZH.mjs.map +0 -1
  346. package/dist/chunk-TIE3CPF7.js +0 -120
  347. package/dist/chunk-TIE3CPF7.js.map +0 -1
  348. package/dist/chunk-TJMQEH57.js +0 -66
  349. package/dist/chunk-TJMQEH57.js.map +0 -1
  350. package/dist/chunk-UGN7PBON.js +0 -176
  351. package/dist/chunk-UGN7PBON.js.map +0 -1
  352. package/dist/chunk-UHAFIPSL.js +0 -121
  353. package/dist/chunk-UHAFIPSL.js.map +0 -1
  354. package/dist/chunk-UHSRHP55.mjs +0 -106
  355. package/dist/chunk-UHSRHP55.mjs.map +0 -1
  356. package/dist/chunk-ULD4JC3Q.js +0 -399
  357. package/dist/chunk-ULD4JC3Q.js.map +0 -1
  358. package/dist/chunk-UQQWZT6C.mjs +0 -14
  359. package/dist/chunk-UQQWZT6C.mjs.map +0 -1
  360. package/dist/chunk-V72C4MCR.js +0 -137
  361. package/dist/chunk-V72C4MCR.js.map +0 -1
  362. package/dist/chunk-VEVVBHP3.mjs +0 -31
  363. package/dist/chunk-VEVVBHP3.mjs.map +0 -1
  364. package/dist/chunk-VGFPVAKX.mjs +0 -228
  365. package/dist/chunk-VGFPVAKX.mjs.map +0 -1
  366. package/dist/chunk-VKWOHNDO.js +0 -2509
  367. package/dist/chunk-VKWOHNDO.js.map +0 -1
  368. package/dist/chunk-WR5F34OW.js +0 -23
  369. package/dist/chunk-WR5F34OW.js.map +0 -1
  370. package/dist/chunk-X4XSEYPL.mjs +0 -201
  371. package/dist/chunk-X4XSEYPL.mjs.map +0 -1
  372. package/dist/chunk-XTMJ25EF.mjs +0 -2509
  373. package/dist/chunk-XTMJ25EF.mjs.map +0 -1
  374. package/dist/chunk-XUI43LEZ.mjs +0 -30
  375. package/dist/chunk-XUI43LEZ.mjs.map +0 -1
  376. package/dist/chunk-XVYXRCRL.js +0 -85
  377. package/dist/chunk-XVYXRCRL.js.map +0 -1
  378. package/dist/chunk-YVCX6Z75.js +0 -102
  379. package/dist/chunk-YVCX6Z75.js.map +0 -1
  380. package/dist/chunk-YWLMT7XH.js +0 -67
  381. package/dist/chunk-YWLMT7XH.js.map +0 -1
  382. package/dist/chunk-Z4BLTVTB.js +0 -30
  383. package/dist/chunk-Z4BLTVTB.js.map +0 -1
  384. package/dist/chunk-Z4GV3YQQ.mjs +0 -23
  385. package/dist/chunk-Z4GV3YQQ.mjs.map +0 -1
  386. package/dist/constants.js +0 -20
  387. package/dist/constants.js.map +0 -1
  388. package/dist/errors.js +0 -15
  389. package/dist/errors.js.map +0 -1
  390. package/dist/gas-flows/DefaultGasFeeFlow.js +0 -15
  391. package/dist/gas-flows/DefaultGasFeeFlow.js.map +0 -1
  392. package/dist/gas-flows/LineaGasFeeFlow.js +0 -16
  393. package/dist/gas-flows/LineaGasFeeFlow.js.map +0 -1
  394. package/dist/gas-flows/OptimismLayer1GasFeeFlow.js +0 -11
  395. package/dist/gas-flows/OptimismLayer1GasFeeFlow.js.map +0 -1
  396. package/dist/gas-flows/OracleLayer1GasFeeFlow.js +0 -9
  397. package/dist/gas-flows/OracleLayer1GasFeeFlow.js.map +0 -1
  398. package/dist/gas-flows/ScrollLayer1GasFeeFlow.js +0 -11
  399. package/dist/gas-flows/ScrollLayer1GasFeeFlow.js.map +0 -1
  400. package/dist/gas-flows/TestGasFeeFlow.js +0 -9
  401. package/dist/gas-flows/TestGasFeeFlow.js.map +0 -1
  402. package/dist/helpers/EtherscanRemoteTransactionSource.js +0 -12
  403. package/dist/helpers/EtherscanRemoteTransactionSource.js.map +0 -1
  404. package/dist/helpers/GasFeePoller.js +0 -12
  405. package/dist/helpers/GasFeePoller.js.map +0 -1
  406. package/dist/helpers/IncomingTransactionHelper.js +0 -9
  407. package/dist/helpers/IncomingTransactionHelper.js.map +0 -1
  408. package/dist/helpers/MultichainTrackingHelper.js +0 -13
  409. package/dist/helpers/MultichainTrackingHelper.js.map +0 -1
  410. package/dist/helpers/PendingTransactionTracker.js +0 -10
  411. package/dist/helpers/PendingTransactionTracker.js.map +0 -1
  412. package/dist/index.js +0 -77
  413. package/dist/index.js.map +0 -1
  414. package/dist/logger.js +0 -12
  415. package/dist/logger.js.map +0 -1
  416. package/dist/tsconfig.build.tsbuildinfo +0 -1
  417. package/dist/types/TransactionController.d.ts.map +0 -1
  418. package/dist/types/constants.d.ts.map +0 -1
  419. package/dist/types/errors.d.ts.map +0 -1
  420. package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
  421. package/dist/types/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
  422. package/dist/types/gas-flows/OptimismLayer1GasFeeFlow.d.ts.map +0 -1
  423. package/dist/types/gas-flows/OracleLayer1GasFeeFlow.d.ts.map +0 -1
  424. package/dist/types/gas-flows/ScrollLayer1GasFeeFlow.d.ts.map +0 -1
  425. package/dist/types/gas-flows/TestGasFeeFlow.d.ts.map +0 -1
  426. package/dist/types/helpers/EtherscanRemoteTransactionSource.d.ts.map +0 -1
  427. package/dist/types/helpers/GasFeePoller.d.ts.map +0 -1
  428. package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +0 -1
  429. package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +0 -1
  430. package/dist/types/helpers/PendingTransactionTracker.d.ts.map +0 -1
  431. package/dist/types/index.d.ts.map +0 -1
  432. package/dist/types/logger.d.ts.map +0 -1
  433. package/dist/types/types.d.ts.map +0 -1
  434. package/dist/types/utils/etherscan.d.ts.map +0 -1
  435. package/dist/types/utils/external-transactions.d.ts.map +0 -1
  436. package/dist/types/utils/gas-fees.d.ts.map +0 -1
  437. package/dist/types/utils/gas-flow.d.ts.map +0 -1
  438. package/dist/types/utils/gas.d.ts.map +0 -1
  439. package/dist/types/utils/history.d.ts.map +0 -1
  440. package/dist/types/utils/layer1-gas-fee-flow.d.ts.map +0 -1
  441. package/dist/types/utils/nonce.d.ts.map +0 -1
  442. package/dist/types/utils/retry.d.ts.map +0 -1
  443. package/dist/types/utils/simulation-api.d.ts.map +0 -1
  444. package/dist/types/utils/simulation.d.ts.map +0 -1
  445. package/dist/types/utils/swaps.d.ts.map +0 -1
  446. package/dist/types/utils/transaction-type.d.ts.map +0 -1
  447. package/dist/types/utils/utils.d.ts.map +0 -1
  448. package/dist/types/utils/validation.d.ts.map +0 -1
  449. package/dist/types.js +0 -24
  450. package/dist/types.js.map +0 -1
  451. package/dist/utils/etherscan.js +0 -14
  452. package/dist/utils/etherscan.js.map +0 -1
  453. package/dist/utils/external-transactions.js +0 -9
  454. package/dist/utils/external-transactions.js.map +0 -1
  455. package/dist/utils/gas-fees.js +0 -16
  456. package/dist/utils/gas-fees.js.map +0 -1
  457. package/dist/utils/gas-flow.js +0 -11
  458. package/dist/utils/gas-flow.js.map +0 -1
  459. package/dist/utils/gas.js +0 -20
  460. package/dist/utils/gas.js.map +0 -1
  461. package/dist/utils/history.js +0 -14
  462. package/dist/utils/history.js.map +0 -1
  463. package/dist/utils/layer1-gas-fee-flow.js +0 -11
  464. package/dist/utils/layer1-gas-fee-flow.js.map +0 -1
  465. package/dist/utils/nonce.js +0 -11
  466. package/dist/utils/nonce.js.map +0 -1
  467. package/dist/utils/retry.js +0 -8
  468. package/dist/utils/retry.js.map +0 -1
  469. package/dist/utils/simulation-api.js +0 -11
  470. package/dist/utils/simulation-api.js.map +0 -1
  471. package/dist/utils/simulation.js +0 -17
  472. package/dist/utils/simulation.js.map +0 -1
  473. package/dist/utils/swaps.js +0 -24
  474. package/dist/utils/swaps.js.map +0 -1
  475. package/dist/utils/transaction-type.js +0 -11
  476. package/dist/utils/transaction-type.js.map +0 -1
  477. package/dist/utils/utils.js +0 -23
  478. package/dist/utils/utils.js.map +0 -1
  479. package/dist/utils/validation.js +0 -12
  480. package/dist/utils/validation.js.map +0 -1
@@ -0,0 +1,267 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateTxParams = exports.validateTransactionOrigin = void 0;
4
+ const abi_1 = require("@ethersproject/abi");
5
+ const controller_utils_1 = require("@metamask/controller-utils");
6
+ const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
7
+ const rpc_errors_1 = require("@metamask/rpc-errors");
8
+ const types_1 = require("../types.cjs");
9
+ const utils_1 = require("./utils.cjs");
10
+ /**
11
+ * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.
12
+ *
13
+ * @param permittedAddresses - The permitted accounts for the given origin.
14
+ * @param selectedAddress - The currently selected Ethereum address in the wallet.
15
+ * @param from - The address from which the transaction is initiated.
16
+ * @param origin - The origin or source of the transaction.
17
+ * @throws Throws an error if the transaction is not permitted.
18
+ */
19
+ async function validateTransactionOrigin(permittedAddresses, selectedAddress, from, origin) {
20
+ if (origin === controller_utils_1.ORIGIN_METAMASK) {
21
+ // Ensure the 'from' address matches the currently selected address
22
+ if (from !== selectedAddress) {
23
+ throw rpc_errors_1.rpcErrors.internal({
24
+ message: `Internally initiated transaction is using invalid account.`,
25
+ data: {
26
+ origin,
27
+ fromAddress: from,
28
+ selectedAddress,
29
+ },
30
+ });
31
+ }
32
+ return;
33
+ }
34
+ // Check if the origin has permissions to initiate transactions from the specified address
35
+ if (!permittedAddresses.includes(from)) {
36
+ throw rpc_errors_1.providerErrors.unauthorized({ data: { origin } });
37
+ }
38
+ }
39
+ exports.validateTransactionOrigin = validateTransactionOrigin;
40
+ /**
41
+ * Validates the transaction params for required properties and throws in
42
+ * the event of any validation error.
43
+ *
44
+ * @param txParams - Transaction params object to validate.
45
+ * @param isEIP1559Compatible - whether or not the current network supports EIP-1559 transactions.
46
+ */
47
+ function validateTxParams(txParams, isEIP1559Compatible = true) {
48
+ validateEnvelopeType(txParams.type);
49
+ validateEIP1559Compatibility(txParams, isEIP1559Compatible);
50
+ validateParamFrom(txParams.from);
51
+ validateParamRecipient(txParams);
52
+ validateParamValue(txParams.value);
53
+ validateParamData(txParams.data);
54
+ validateParamChainId(txParams.chainId);
55
+ validateGasFeeParams(txParams);
56
+ }
57
+ exports.validateTxParams = validateTxParams;
58
+ /**
59
+ * Validates the `type` property, ensuring that if it is specified, it is a valid transaction envelope type.
60
+ *
61
+ * @param type - The transaction envelope type to validate.
62
+ * @throws Throws invalid params if the type is not a valid transaction envelope type.
63
+ */
64
+ function validateEnvelopeType(type) {
65
+ if (type &&
66
+ !Object.values(types_1.TransactionEnvelopeType).includes(type)) {
67
+ throw rpc_errors_1.rpcErrors.invalidParams(`Invalid transaction envelope type: "${type}". Must be one of: ${Object.values(types_1.TransactionEnvelopeType).join(', ')}`);
68
+ }
69
+ }
70
+ /**
71
+ * Validates EIP-1559 compatibility for transaction creation.
72
+ *
73
+ * @param txParams - The transaction parameters to validate.
74
+ * @param isEIP1559Compatible - Indicates if the current network supports EIP-1559.
75
+ * @throws Throws invalid params if the transaction specifies EIP-1559 but the network does not support it.
76
+ */
77
+ function validateEIP1559Compatibility(txParams, isEIP1559Compatible) {
78
+ if ((0, utils_1.isEIP1559Transaction)(txParams) && !isEIP1559Compatible) {
79
+ throw rpc_errors_1.rpcErrors.invalidParams('Invalid transaction params: params specify an EIP-1559 transaction but the current network does not support EIP-1559');
80
+ }
81
+ }
82
+ /**
83
+ * Validates value property, ensuring it is a valid positive integer number
84
+ * denominated in wei.
85
+ *
86
+ * @param value - The value to validate, expressed as a string.
87
+ * @throws Throws an error if the value is not a valid positive integer
88
+ * number denominated in wei.
89
+ * - If the value contains a hyphen (-), it is considered invalid.
90
+ * - If the value contains a decimal point (.), it is considered invalid.
91
+ * - If the value is not a finite number, is NaN, or is not a safe integer, it is considered invalid.
92
+ */
93
+ function validateParamValue(value) {
94
+ if (value !== undefined) {
95
+ if (value.includes('-')) {
96
+ throw rpc_errors_1.rpcErrors.invalidParams(`Invalid transaction value "${value}": not a positive number.`);
97
+ }
98
+ if (value.includes('.')) {
99
+ throw rpc_errors_1.rpcErrors.invalidParams(`Invalid transaction value "${value}": number must be in wei.`);
100
+ }
101
+ const intValue = parseInt(value, 10);
102
+ const isValid = Number.isFinite(intValue) &&
103
+ !Number.isNaN(intValue) &&
104
+ !isNaN(Number(value)) &&
105
+ Number.isSafeInteger(intValue);
106
+ if (!isValid) {
107
+ throw rpc_errors_1.rpcErrors.invalidParams(`Invalid transaction value ${value}: number must be a valid number.`);
108
+ }
109
+ }
110
+ }
111
+ /**
112
+ * Validates the recipient address in a transaction's parameters.
113
+ *
114
+ * @param txParams - The transaction parameters object to validate.
115
+ * @throws Throws an error if the recipient address is invalid:
116
+ * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,
117
+ * the "to" field is removed from the transaction parameters.
118
+ * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.
119
+ */
120
+ function validateParamRecipient(txParams) {
121
+ if (txParams.to === '0x' || txParams.to === undefined) {
122
+ if (txParams.data) {
123
+ delete txParams.to;
124
+ }
125
+ else {
126
+ throw rpc_errors_1.rpcErrors.invalidParams(`Invalid "to" address.`);
127
+ }
128
+ }
129
+ else if (txParams.to !== undefined && !(0, controller_utils_1.isValidHexAddress)(txParams.to)) {
130
+ throw rpc_errors_1.rpcErrors.invalidParams(`Invalid "to" address.`);
131
+ }
132
+ }
133
+ /**
134
+ * Validates the recipient address in a transaction's parameters.
135
+ *
136
+ * @param from - The from property to validate.
137
+ * @throws Throws an error if the recipient address is invalid:
138
+ * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,
139
+ * the "to" field is removed from the transaction parameters.
140
+ * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.
141
+ */
142
+ function validateParamFrom(from) {
143
+ if (!from || typeof from !== 'string') {
144
+ throw rpc_errors_1.rpcErrors.invalidParams(`Invalid "from" address ${from}: not a string.`);
145
+ }
146
+ if (!(0, controller_utils_1.isValidHexAddress)(from)) {
147
+ throw rpc_errors_1.rpcErrors.invalidParams('Invalid "from" address.');
148
+ }
149
+ }
150
+ /**
151
+ * Validates input data for transactions.
152
+ *
153
+ * @param value - The input data to validate.
154
+ * @throws Throws invalid params if the input data is invalid.
155
+ */
156
+ function validateParamData(value) {
157
+ if (value) {
158
+ const ERC20Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC20);
159
+ try {
160
+ ERC20Interface.parseTransaction({ data: value });
161
+ // TODO: Replace `any` with type
162
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
163
+ }
164
+ catch (error) {
165
+ if (error.message.match(/BUFFER_OVERRUN/u)) {
166
+ throw rpc_errors_1.rpcErrors.invalidParams('Invalid transaction params: data out-of-bounds, BUFFER_OVERRUN.');
167
+ }
168
+ }
169
+ }
170
+ }
171
+ /**
172
+ * Validates chainId type.
173
+ *
174
+ * @param chainId - The chainId to validate.
175
+ */
176
+ function validateParamChainId(chainId) {
177
+ if (chainId !== undefined &&
178
+ typeof chainId !== 'number' &&
179
+ typeof chainId !== 'string') {
180
+ throw rpc_errors_1.rpcErrors.invalidParams(
181
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
182
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
183
+ `Invalid transaction params: chainId is not a Number or hex string. got: (${chainId})`);
184
+ }
185
+ }
186
+ /**
187
+ * Validates gas values.
188
+ *
189
+ * @param txParams - The transaction parameters to validate.
190
+ */
191
+ function validateGasFeeParams(txParams) {
192
+ if (txParams.gasPrice) {
193
+ ensureProperTransactionEnvelopeTypeProvided(txParams, 'gasPrice');
194
+ ensureMutuallyExclusiveFieldsNotProvided(txParams, 'gasPrice', 'maxFeePerGas');
195
+ ensureMutuallyExclusiveFieldsNotProvided(txParams, 'gasPrice', 'maxPriorityFeePerGas');
196
+ ensureFieldIsString(txParams, 'gasPrice');
197
+ }
198
+ if (txParams.maxFeePerGas) {
199
+ ensureProperTransactionEnvelopeTypeProvided(txParams, 'maxFeePerGas');
200
+ ensureMutuallyExclusiveFieldsNotProvided(txParams, 'maxFeePerGas', 'gasPrice');
201
+ ensureFieldIsString(txParams, 'maxFeePerGas');
202
+ }
203
+ if (txParams.maxPriorityFeePerGas) {
204
+ ensureProperTransactionEnvelopeTypeProvided(txParams, 'maxPriorityFeePerGas');
205
+ ensureMutuallyExclusiveFieldsNotProvided(txParams, 'maxPriorityFeePerGas', 'gasPrice');
206
+ ensureFieldIsString(txParams, 'maxPriorityFeePerGas');
207
+ }
208
+ }
209
+ /**
210
+ * Ensures that the provided txParams has the proper 'type' specified for the
211
+ * given field, if it is provided. If types do not match throws an
212
+ * invalidParams error.
213
+ *
214
+ * @param txParams - The transaction parameters object
215
+ * @param field - The current field being validated
216
+ * @throws {ethErrors.rpc.invalidParams} Throws if type does not match the
217
+ * expectations for provided field.
218
+ */
219
+ function ensureProperTransactionEnvelopeTypeProvided(txParams, field) {
220
+ switch (field) {
221
+ case 'maxFeePerGas':
222
+ case 'maxPriorityFeePerGas':
223
+ if (txParams.type &&
224
+ txParams.type !== types_1.TransactionEnvelopeType.feeMarket) {
225
+ throw rpc_errors_1.rpcErrors.invalidParams(`Invalid transaction envelope type: specified type "${txParams.type}" but including maxFeePerGas and maxPriorityFeePerGas requires type: "${types_1.TransactionEnvelopeType.feeMarket}"`);
226
+ }
227
+ break;
228
+ case 'gasPrice':
229
+ default:
230
+ if (txParams.type &&
231
+ txParams.type === types_1.TransactionEnvelopeType.feeMarket) {
232
+ throw rpc_errors_1.rpcErrors.invalidParams(`Invalid transaction envelope type: specified type "${txParams.type}" but included a gasPrice instead of maxFeePerGas and maxPriorityFeePerGas`);
233
+ }
234
+ }
235
+ }
236
+ /**
237
+ * Given two fields, ensure that the second field is not included in txParams,
238
+ * and if it is throw an invalidParams error.
239
+ *
240
+ * @param txParams - The transaction parameters object
241
+ * @param fieldBeingValidated - The current field being validated
242
+ * @param mutuallyExclusiveField - The field to ensure is not provided
243
+ * @throws {ethErrors.rpc.invalidParams} Throws if mutuallyExclusiveField is
244
+ * present in txParams.
245
+ */
246
+ function ensureMutuallyExclusiveFieldsNotProvided(txParams, fieldBeingValidated, mutuallyExclusiveField) {
247
+ if (typeof txParams[mutuallyExclusiveField] !== 'undefined') {
248
+ throw rpc_errors_1.rpcErrors.invalidParams(`Invalid transaction params: specified ${fieldBeingValidated} but also included ${mutuallyExclusiveField}, these cannot be mixed`);
249
+ }
250
+ }
251
+ /**
252
+ * Ensures that the provided value for field is a string, throws an
253
+ * invalidParams error if field is not a string.
254
+ *
255
+ * @param txParams - The transaction parameters object
256
+ * @param field - The current field being validated
257
+ * @throws {rpcErrors.invalidParams} Throws if field is not a string
258
+ */
259
+ function ensureFieldIsString(txParams, field) {
260
+ if (typeof txParams[field] !== 'string') {
261
+ throw rpc_errors_1.rpcErrors.invalidParams(
262
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
263
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
264
+ `Invalid transaction params: ${field} is not a string. got: (${txParams[field]})`);
265
+ }
266
+ }
267
+ //# sourceMappingURL=validation.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/validation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AO,SAAS,KAAK,MAAM,UAAU;AACvC,UAAM,UAAU;AAAA;AAAA;AAAA,MAGd,+BAA+B,KAAK,2BAA2B,SAAS,KAAK,CAAC;AAAA,IAChF;AAAA,EACF;AACF","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"]}
1
+ {"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/utils/validation.ts"],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AS,EACnD;gBACA,MAAM,sBAAS,CAAC,aAAa,CAC3B,sDAAsD,QAAQ,CAAC,IAAI,yEAAyE,+BAAuB,CAAC,SAAS,GAAG,CACjL,CAAC;aACH;YACD,MAAM;QACR,KAAK,UAAU,CAAC;QAChB;YACE,IACE,QAAQ,CAAC,IAAI;gBACb,QAAQ,CAAC,IAAI,KAAK,+BAAuB,CAAC,SAAS,EACnD;gBACA,MAAM,sBAAS,CAAC,aAAa,CAC3B,sDAAsD,QAAQ,CAAC,IAAI,4EAA4E,CAChJ,CAAC;aACH;KACJ;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,wCAAwC,CAC/C,QAA2B,EAC3B,mBAAwC,EACxC,sBAA2C;IAE3C,IAAI,OAAO,QAAQ,CAAC,sBAAsB,CAAC,KAAK,WAAW,EAAE;QAC3D,MAAM,sBAAS,CAAC,aAAa,CAC3B,yCAAyC,mBAAmB,sBAAsB,sBAAsB,yBAAyB,CAClI,CAAC;KACH;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,mBAAmB,CAC1B,QAA2B,EAC3B,KAA0B;IAE1B,IAAI,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE;QACvC,MAAM,sBAAS,CAAC,aAAa;QAC3B,gFAAgF;QAChF,4EAA4E;QAC5E,+BAA+B,KAAK,2BAA2B,QAAQ,CAAC,KAAK,CAAC,GAAG,CAClF,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 { 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,4 +1,4 @@
1
- import { type TransactionParams } from '../types';
1
+ import { type TransactionParams } from "../types.cjs";
2
2
  /**
3
3
  * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.
4
4
  *
@@ -17,4 +17,4 @@ export declare function validateTransactionOrigin(permittedAddresses: string[],
17
17
  * @param isEIP1559Compatible - whether or not the current network supports EIP-1559 transactions.
18
18
  */
19
19
  export declare function validateTxParams(txParams: TransactionParams, isEIP1559Compatible?: boolean): void;
20
- //# sourceMappingURL=validation.d.ts.map
20
+ //# sourceMappingURL=validation.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.cts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAKA,OAAO,EAA2B,KAAK,iBAAiB,EAAE,qBAAiB;AAK3E;;;;;;;;GAQG;AACH,wBAAsB,yBAAyB,CAC7C,kBAAkB,EAAE,MAAM,EAAE,EAC5B,eAAe,EAAE,MAAM,EACvB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,iBAqBf;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,iBAAiB,EAC3B,mBAAmB,UAAO,QAU3B"}
@@ -0,0 +1,20 @@
1
+ import { type TransactionParams } from "../types.mjs";
2
+ /**
3
+ * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.
4
+ *
5
+ * @param permittedAddresses - The permitted accounts for the given origin.
6
+ * @param selectedAddress - The currently selected Ethereum address in the wallet.
7
+ * @param from - The address from which the transaction is initiated.
8
+ * @param origin - The origin or source of the transaction.
9
+ * @throws Throws an error if the transaction is not permitted.
10
+ */
11
+ export declare function validateTransactionOrigin(permittedAddresses: string[], selectedAddress: string, from: string, origin: string): Promise<void>;
12
+ /**
13
+ * Validates the transaction params for required properties and throws in
14
+ * the event of any validation error.
15
+ *
16
+ * @param txParams - Transaction params object to validate.
17
+ * @param isEIP1559Compatible - whether or not the current network supports EIP-1559 transactions.
18
+ */
19
+ export declare function validateTxParams(txParams: TransactionParams, isEIP1559Compatible?: boolean): void;
20
+ //# sourceMappingURL=validation.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.mts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAKA,OAAO,EAA2B,KAAK,iBAAiB,EAAE,qBAAiB;AAK3E;;;;;;;;GAQG;AACH,wBAAsB,yBAAyB,CAC7C,kBAAkB,EAAE,MAAM,EAAE,EAC5B,eAAe,EAAE,MAAM,EACvB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,iBAqBf;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,iBAAiB,EAC3B,mBAAmB,UAAO,QAU3B"}
@@ -1,12 +1,262 @@
1
- import {
2
- validateTransactionOrigin,
3
- validateTxParams
4
- } from "../chunk-X4XSEYPL.mjs";
5
- import "../chunk-UHSRHP55.mjs";
6
- import "../chunk-LFFYCDHB.mjs";
7
- import "../chunk-XUI43LEZ.mjs";
8
- export {
9
- validateTransactionOrigin,
10
- validateTxParams
11
- };
1
+ import { Interface } from "@ethersproject/abi";
2
+ import { ORIGIN_METAMASK, isValidHexAddress } from "@metamask/controller-utils";
3
+ import { abiERC20 } from "@metamask/metamask-eth-abis";
4
+ import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
5
+ import { TransactionEnvelopeType } from "../types.mjs";
6
+ import { isEIP1559Transaction } from "./utils.mjs";
7
+ /**
8
+ * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.
9
+ *
10
+ * @param permittedAddresses - The permitted accounts for the given origin.
11
+ * @param selectedAddress - The currently selected Ethereum address in the wallet.
12
+ * @param from - The address from which the transaction is initiated.
13
+ * @param origin - The origin or source of the transaction.
14
+ * @throws Throws an error if the transaction is not permitted.
15
+ */
16
+ export async function validateTransactionOrigin(permittedAddresses, selectedAddress, from, origin) {
17
+ if (origin === ORIGIN_METAMASK) {
18
+ // Ensure the 'from' address matches the currently selected address
19
+ if (from !== selectedAddress) {
20
+ throw rpcErrors.internal({
21
+ message: `Internally initiated transaction is using invalid account.`,
22
+ data: {
23
+ origin,
24
+ fromAddress: from,
25
+ selectedAddress,
26
+ },
27
+ });
28
+ }
29
+ return;
30
+ }
31
+ // Check if the origin has permissions to initiate transactions from the specified address
32
+ if (!permittedAddresses.includes(from)) {
33
+ throw providerErrors.unauthorized({ data: { origin } });
34
+ }
35
+ }
36
+ /**
37
+ * Validates the transaction params for required properties and throws in
38
+ * the event of any validation error.
39
+ *
40
+ * @param txParams - Transaction params object to validate.
41
+ * @param isEIP1559Compatible - whether or not the current network supports EIP-1559 transactions.
42
+ */
43
+ export function validateTxParams(txParams, isEIP1559Compatible = true) {
44
+ validateEnvelopeType(txParams.type);
45
+ validateEIP1559Compatibility(txParams, isEIP1559Compatible);
46
+ validateParamFrom(txParams.from);
47
+ validateParamRecipient(txParams);
48
+ validateParamValue(txParams.value);
49
+ validateParamData(txParams.data);
50
+ validateParamChainId(txParams.chainId);
51
+ validateGasFeeParams(txParams);
52
+ }
53
+ /**
54
+ * Validates the `type` property, ensuring that if it is specified, it is a valid transaction envelope type.
55
+ *
56
+ * @param type - The transaction envelope type to validate.
57
+ * @throws Throws invalid params if the type is not a valid transaction envelope type.
58
+ */
59
+ function validateEnvelopeType(type) {
60
+ if (type &&
61
+ !Object.values(TransactionEnvelopeType).includes(type)) {
62
+ throw rpcErrors.invalidParams(`Invalid transaction envelope type: "${type}". Must be one of: ${Object.values(TransactionEnvelopeType).join(', ')}`);
63
+ }
64
+ }
65
+ /**
66
+ * Validates EIP-1559 compatibility for transaction creation.
67
+ *
68
+ * @param txParams - The transaction parameters to validate.
69
+ * @param isEIP1559Compatible - Indicates if the current network supports EIP-1559.
70
+ * @throws Throws invalid params if the transaction specifies EIP-1559 but the network does not support it.
71
+ */
72
+ function validateEIP1559Compatibility(txParams, isEIP1559Compatible) {
73
+ if (isEIP1559Transaction(txParams) && !isEIP1559Compatible) {
74
+ throw rpcErrors.invalidParams('Invalid transaction params: params specify an EIP-1559 transaction but the current network does not support EIP-1559');
75
+ }
76
+ }
77
+ /**
78
+ * Validates value property, ensuring it is a valid positive integer number
79
+ * denominated in wei.
80
+ *
81
+ * @param value - The value to validate, expressed as a string.
82
+ * @throws Throws an error if the value is not a valid positive integer
83
+ * number denominated in wei.
84
+ * - If the value contains a hyphen (-), it is considered invalid.
85
+ * - If the value contains a decimal point (.), it is considered invalid.
86
+ * - If the value is not a finite number, is NaN, or is not a safe integer, it is considered invalid.
87
+ */
88
+ function validateParamValue(value) {
89
+ if (value !== undefined) {
90
+ if (value.includes('-')) {
91
+ throw rpcErrors.invalidParams(`Invalid transaction value "${value}": not a positive number.`);
92
+ }
93
+ if (value.includes('.')) {
94
+ throw rpcErrors.invalidParams(`Invalid transaction value "${value}": number must be in wei.`);
95
+ }
96
+ const intValue = parseInt(value, 10);
97
+ const isValid = Number.isFinite(intValue) &&
98
+ !Number.isNaN(intValue) &&
99
+ !isNaN(Number(value)) &&
100
+ Number.isSafeInteger(intValue);
101
+ if (!isValid) {
102
+ throw rpcErrors.invalidParams(`Invalid transaction value ${value}: number must be a valid number.`);
103
+ }
104
+ }
105
+ }
106
+ /**
107
+ * Validates the recipient address in a transaction's parameters.
108
+ *
109
+ * @param txParams - The transaction parameters object to validate.
110
+ * @throws Throws an error if the recipient address is invalid:
111
+ * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,
112
+ * the "to" field is removed from the transaction parameters.
113
+ * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.
114
+ */
115
+ function validateParamRecipient(txParams) {
116
+ if (txParams.to === '0x' || txParams.to === undefined) {
117
+ if (txParams.data) {
118
+ delete txParams.to;
119
+ }
120
+ else {
121
+ throw rpcErrors.invalidParams(`Invalid "to" address.`);
122
+ }
123
+ }
124
+ else if (txParams.to !== undefined && !isValidHexAddress(txParams.to)) {
125
+ throw rpcErrors.invalidParams(`Invalid "to" address.`);
126
+ }
127
+ }
128
+ /**
129
+ * Validates the recipient address in a transaction's parameters.
130
+ *
131
+ * @param from - The from property to validate.
132
+ * @throws Throws an error if the recipient address is invalid:
133
+ * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,
134
+ * the "to" field is removed from the transaction parameters.
135
+ * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.
136
+ */
137
+ function validateParamFrom(from) {
138
+ if (!from || typeof from !== 'string') {
139
+ throw rpcErrors.invalidParams(`Invalid "from" address ${from}: not a string.`);
140
+ }
141
+ if (!isValidHexAddress(from)) {
142
+ throw rpcErrors.invalidParams('Invalid "from" address.');
143
+ }
144
+ }
145
+ /**
146
+ * Validates input data for transactions.
147
+ *
148
+ * @param value - The input data to validate.
149
+ * @throws Throws invalid params if the input data is invalid.
150
+ */
151
+ function validateParamData(value) {
152
+ if (value) {
153
+ const ERC20Interface = new Interface(abiERC20);
154
+ try {
155
+ ERC20Interface.parseTransaction({ data: value });
156
+ // TODO: Replace `any` with type
157
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
158
+ }
159
+ catch (error) {
160
+ if (error.message.match(/BUFFER_OVERRUN/u)) {
161
+ throw rpcErrors.invalidParams('Invalid transaction params: data out-of-bounds, BUFFER_OVERRUN.');
162
+ }
163
+ }
164
+ }
165
+ }
166
+ /**
167
+ * Validates chainId type.
168
+ *
169
+ * @param chainId - The chainId to validate.
170
+ */
171
+ function validateParamChainId(chainId) {
172
+ if (chainId !== undefined &&
173
+ typeof chainId !== 'number' &&
174
+ typeof chainId !== 'string') {
175
+ throw rpcErrors.invalidParams(
176
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
177
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
178
+ `Invalid transaction params: chainId is not a Number or hex string. got: (${chainId})`);
179
+ }
180
+ }
181
+ /**
182
+ * Validates gas values.
183
+ *
184
+ * @param txParams - The transaction parameters to validate.
185
+ */
186
+ function validateGasFeeParams(txParams) {
187
+ if (txParams.gasPrice) {
188
+ ensureProperTransactionEnvelopeTypeProvided(txParams, 'gasPrice');
189
+ ensureMutuallyExclusiveFieldsNotProvided(txParams, 'gasPrice', 'maxFeePerGas');
190
+ ensureMutuallyExclusiveFieldsNotProvided(txParams, 'gasPrice', 'maxPriorityFeePerGas');
191
+ ensureFieldIsString(txParams, 'gasPrice');
192
+ }
193
+ if (txParams.maxFeePerGas) {
194
+ ensureProperTransactionEnvelopeTypeProvided(txParams, 'maxFeePerGas');
195
+ ensureMutuallyExclusiveFieldsNotProvided(txParams, 'maxFeePerGas', 'gasPrice');
196
+ ensureFieldIsString(txParams, 'maxFeePerGas');
197
+ }
198
+ if (txParams.maxPriorityFeePerGas) {
199
+ ensureProperTransactionEnvelopeTypeProvided(txParams, 'maxPriorityFeePerGas');
200
+ ensureMutuallyExclusiveFieldsNotProvided(txParams, 'maxPriorityFeePerGas', 'gasPrice');
201
+ ensureFieldIsString(txParams, 'maxPriorityFeePerGas');
202
+ }
203
+ }
204
+ /**
205
+ * Ensures that the provided txParams has the proper 'type' specified for the
206
+ * given field, if it is provided. If types do not match throws an
207
+ * invalidParams error.
208
+ *
209
+ * @param txParams - The transaction parameters object
210
+ * @param field - The current field being validated
211
+ * @throws {ethErrors.rpc.invalidParams} Throws if type does not match the
212
+ * expectations for provided field.
213
+ */
214
+ function ensureProperTransactionEnvelopeTypeProvided(txParams, field) {
215
+ switch (field) {
216
+ case 'maxFeePerGas':
217
+ case 'maxPriorityFeePerGas':
218
+ if (txParams.type &&
219
+ txParams.type !== TransactionEnvelopeType.feeMarket) {
220
+ throw rpcErrors.invalidParams(`Invalid transaction envelope type: specified type "${txParams.type}" but including maxFeePerGas and maxPriorityFeePerGas requires type: "${TransactionEnvelopeType.feeMarket}"`);
221
+ }
222
+ break;
223
+ case 'gasPrice':
224
+ default:
225
+ if (txParams.type &&
226
+ txParams.type === TransactionEnvelopeType.feeMarket) {
227
+ throw rpcErrors.invalidParams(`Invalid transaction envelope type: specified type "${txParams.type}" but included a gasPrice instead of maxFeePerGas and maxPriorityFeePerGas`);
228
+ }
229
+ }
230
+ }
231
+ /**
232
+ * Given two fields, ensure that the second field is not included in txParams,
233
+ * and if it is throw an invalidParams error.
234
+ *
235
+ * @param txParams - The transaction parameters object
236
+ * @param fieldBeingValidated - The current field being validated
237
+ * @param mutuallyExclusiveField - The field to ensure is not provided
238
+ * @throws {ethErrors.rpc.invalidParams} Throws if mutuallyExclusiveField is
239
+ * present in txParams.
240
+ */
241
+ function ensureMutuallyExclusiveFieldsNotProvided(txParams, fieldBeingValidated, mutuallyExclusiveField) {
242
+ if (typeof txParams[mutuallyExclusiveField] !== 'undefined') {
243
+ throw rpcErrors.invalidParams(`Invalid transaction params: specified ${fieldBeingValidated} but also included ${mutuallyExclusiveField}, these cannot be mixed`);
244
+ }
245
+ }
246
+ /**
247
+ * Ensures that the provided value for field is a string, throws an
248
+ * invalidParams error if field is not a string.
249
+ *
250
+ * @param txParams - The transaction parameters object
251
+ * @param field - The current field being validated
252
+ * @throws {rpcErrors.invalidParams} Throws if field is not a string
253
+ */
254
+ function ensureFieldIsString(txParams, field) {
255
+ if (typeof txParams[field] !== 'string') {
256
+ throw rpcErrors.invalidParams(
257
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
258
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
259
+ `Invalid transaction params: ${field} is not a string. got: (${txParams[field]})`);
260
+ }
261
+ }
12
262
  //# sourceMappingURL=validation.mjs.map