@metamask/snaps-rpc-methods 6.0.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (559) hide show
  1. package/CHANGELOG.md +13 -2
  2. package/dist/chunk-23XDKQW2.mjs +73 -0
  3. package/dist/chunk-23XDKQW2.mjs.map +1 -0
  4. package/dist/chunk-2KTJCF3C.js +68 -0
  5. package/dist/chunk-2KTJCF3C.js.map +1 -0
  6. package/dist/chunk-3DHVA2FY.js +21 -0
  7. package/dist/chunk-3DHVA2FY.js.map +1 -0
  8. package/dist/chunk-3LPBU737.js +43 -0
  9. package/dist/chunk-3LPBU737.js.map +1 -0
  10. package/dist/chunk-3S7DJI4I.mjs +49 -0
  11. package/dist/chunk-3S7DJI4I.mjs.map +1 -0
  12. package/dist/chunk-3UAWEHMF.js +18 -0
  13. package/dist/chunk-3UAWEHMF.js.map +1 -0
  14. package/dist/chunk-4D2B2UQ6.mjs +23 -0
  15. package/dist/chunk-4D2B2UQ6.mjs.map +1 -0
  16. package/dist/chunk-4LSOS7SM.js +23 -0
  17. package/dist/chunk-4LSOS7SM.js.map +1 -0
  18. package/dist/chunk-4SQWLI2S.mjs +151 -0
  19. package/dist/chunk-4SQWLI2S.mjs.map +1 -0
  20. package/dist/chunk-4W7U4OH6.js +42 -0
  21. package/dist/chunk-4W7U4OH6.js.map +1 -0
  22. package/dist/chunk-62URQ5VS.mjs +18 -0
  23. package/dist/chunk-62URQ5VS.mjs.map +1 -0
  24. package/dist/chunk-6TKD32TS.js +78 -0
  25. package/dist/chunk-6TKD32TS.js.map +1 -0
  26. package/dist/chunk-6UY23OOZ.js +39 -0
  27. package/dist/chunk-6UY23OOZ.js.map +1 -0
  28. package/dist/chunk-6WUIFFMQ.mjs +78 -0
  29. package/dist/chunk-6WUIFFMQ.mjs.map +1 -0
  30. package/dist/chunk-7NBRKDKJ.mjs +188 -0
  31. package/dist/chunk-7NBRKDKJ.mjs.map +1 -0
  32. package/dist/chunk-7OMVZR5X.mjs +39 -0
  33. package/dist/chunk-7OMVZR5X.mjs.map +1 -0
  34. package/dist/chunk-7TVJV425.js +1 -0
  35. package/dist/chunk-7TVJV425.js.map +1 -0
  36. package/dist/chunk-ADXH5C3U.mjs +119 -0
  37. package/dist/chunk-ADXH5C3U.mjs.map +1 -0
  38. package/dist/chunk-AKRFLGOS.mjs +59 -0
  39. package/dist/chunk-AKRFLGOS.mjs.map +1 -0
  40. package/dist/chunk-AOWUGDER.js +78 -0
  41. package/dist/chunk-AOWUGDER.js.map +1 -0
  42. package/dist/chunk-AWQ6HTAL.mjs +75 -0
  43. package/dist/chunk-AWQ6HTAL.mjs.map +1 -0
  44. package/dist/chunk-AYJK7MSH.js +43 -0
  45. package/dist/chunk-AYJK7MSH.js.map +1 -0
  46. package/dist/chunk-B3NIHNXW.js +23 -0
  47. package/dist/{cjs/endowments/ethereum-provider.js.map → chunk-B3NIHNXW.js.map} +1 -1
  48. package/dist/chunk-C6E6DI4I.mjs +115 -0
  49. package/dist/chunk-C6E6DI4I.mjs.map +1 -0
  50. package/dist/chunk-CD4OUHO5.mjs +20 -0
  51. package/dist/chunk-CD4OUHO5.mjs.map +1 -0
  52. package/dist/chunk-CH5O2YCX.mjs +18 -0
  53. package/dist/chunk-CH5O2YCX.mjs.map +1 -0
  54. package/dist/chunk-CVK2TYJX.mjs +54 -0
  55. package/dist/chunk-CVK2TYJX.mjs.map +1 -0
  56. package/dist/chunk-D6MUXDVI.js +51 -0
  57. package/dist/chunk-D6MUXDVI.js.map +1 -0
  58. package/dist/chunk-E6WUMFQT.mjs +54 -0
  59. package/dist/chunk-E6WUMFQT.mjs.map +1 -0
  60. package/dist/chunk-EEVEVBK6.mjs +78 -0
  61. package/dist/chunk-EEVEVBK6.mjs.map +1 -0
  62. package/dist/chunk-EKXDFYIX.mjs +68 -0
  63. package/dist/chunk-EKXDFYIX.mjs.map +1 -0
  64. package/dist/chunk-FBOZCV3C.js +59 -0
  65. package/dist/chunk-FBOZCV3C.js.map +1 -0
  66. package/dist/chunk-FCVWU5XH.js +73 -0
  67. package/dist/chunk-FCVWU5XH.js.map +1 -0
  68. package/dist/chunk-FFHVA6PP.js +82 -0
  69. package/dist/chunk-FFHVA6PP.js.map +1 -0
  70. package/dist/chunk-FMDV3RFT.js +21 -0
  71. package/dist/chunk-FMDV3RFT.js.map +1 -0
  72. package/dist/chunk-GP5KW5FU.js +45 -0
  73. package/dist/chunk-GP5KW5FU.js.map +1 -0
  74. package/dist/chunk-GYZV5UBD.js +151 -0
  75. package/dist/chunk-GYZV5UBD.js.map +1 -0
  76. package/dist/chunk-I6FU5MGE.mjs +47 -0
  77. package/dist/chunk-I6FU5MGE.mjs.map +1 -0
  78. package/dist/chunk-IBV23QOX.mjs +67 -0
  79. package/dist/chunk-IBV23QOX.mjs.map +1 -0
  80. package/dist/chunk-IDZGMGIB.js +45 -0
  81. package/dist/chunk-IDZGMGIB.js.map +1 -0
  82. package/dist/chunk-IEUCBULU.js +119 -0
  83. package/dist/chunk-IEUCBULU.js.map +1 -0
  84. package/dist/chunk-IZYMBIBD.mjs +32 -0
  85. package/dist/chunk-IZYMBIBD.mjs.map +1 -0
  86. package/dist/chunk-JQ456NCC.mjs +51 -0
  87. package/dist/chunk-JQ456NCC.mjs.map +1 -0
  88. package/dist/chunk-JRSPKOFG.js +115 -0
  89. package/dist/chunk-JRSPKOFG.js.map +1 -0
  90. package/dist/chunk-JWDQUKKU.mjs +80 -0
  91. package/dist/chunk-JWDQUKKU.mjs.map +1 -0
  92. package/dist/chunk-KO4MKRYZ.js +188 -0
  93. package/dist/chunk-KO4MKRYZ.js.map +1 -0
  94. package/dist/chunk-KSTF5JYB.mjs +23 -0
  95. package/dist/chunk-KSTF5JYB.mjs.map +1 -0
  96. package/dist/chunk-LGUJMQC7.js +78 -0
  97. package/dist/{cjs/restricted/getBip32PublicKey.js.map → chunk-LGUJMQC7.js.map} +1 -1
  98. package/dist/chunk-LIWV3FMY.js +69 -0
  99. package/dist/chunk-LIWV3FMY.js.map +1 -0
  100. package/dist/chunk-LR7UR4YU.mjs +52 -0
  101. package/dist/chunk-LR7UR4YU.mjs.map +1 -0
  102. package/dist/chunk-LVTN25J2.js +49 -0
  103. package/dist/chunk-LVTN25J2.js.map +1 -0
  104. package/dist/chunk-MVG4B2HM.mjs +21 -0
  105. package/dist/chunk-MVG4B2HM.mjs.map +1 -0
  106. package/dist/chunk-MXCJWR45.mjs +45 -0
  107. package/dist/chunk-MXCJWR45.mjs.map +1 -0
  108. package/dist/chunk-MXPVC2XP.mjs +105 -0
  109. package/dist/chunk-MXPVC2XP.mjs.map +1 -0
  110. package/dist/chunk-NP3KGMVC.js +47 -0
  111. package/dist/chunk-NP3KGMVC.js.map +1 -0
  112. package/dist/chunk-NU4NAAFG.js +1 -0
  113. package/dist/chunk-NU4NAAFG.js.map +1 -0
  114. package/dist/chunk-NWT2EXFD.js +18 -0
  115. package/dist/chunk-NWT2EXFD.js.map +1 -0
  116. package/dist/chunk-O66NZFSD.mjs +23 -0
  117. package/dist/chunk-O66NZFSD.mjs.map +1 -0
  118. package/dist/chunk-OQOTJFFV.js +74 -0
  119. package/dist/chunk-OQOTJFFV.js.map +1 -0
  120. package/dist/chunk-P74WXDY4.js +54 -0
  121. package/dist/chunk-P74WXDY4.js.map +1 -0
  122. package/dist/chunk-PCB6QOHL.mjs +21 -0
  123. package/dist/chunk-PCB6QOHL.mjs.map +1 -0
  124. package/dist/chunk-PS6OEQXL.js +105 -0
  125. package/dist/chunk-PS6OEQXL.js.map +1 -0
  126. package/dist/chunk-PWUEAR4H.js +70 -0
  127. package/dist/chunk-PWUEAR4H.js.map +1 -0
  128. package/dist/chunk-Q27K2I6Z.js +23 -0
  129. package/dist/{cjs/endowments/web-assembly.js.map → chunk-Q27K2I6Z.js.map} +1 -1
  130. package/dist/chunk-Q5W3YGEB.js +67 -0
  131. package/dist/chunk-Q5W3YGEB.js.map +1 -0
  132. package/dist/chunk-QDZAWH6F.js +80 -0
  133. package/dist/chunk-QDZAWH6F.js.map +1 -0
  134. package/dist/chunk-QMULJEYN.js +35 -0
  135. package/dist/chunk-QMULJEYN.js.map +1 -0
  136. package/dist/chunk-S7AR3ROH.js +57 -0
  137. package/dist/chunk-S7AR3ROH.js.map +1 -0
  138. package/dist/chunk-SGQXD5K7.mjs +83 -0
  139. package/dist/chunk-SGQXD5K7.mjs.map +1 -0
  140. package/dist/chunk-SYUGPLEP.js +32 -0
  141. package/dist/chunk-SYUGPLEP.js.map +1 -0
  142. package/dist/chunk-TEXEQGNZ.js +75 -0
  143. package/dist/chunk-TEXEQGNZ.js.map +1 -0
  144. package/dist/chunk-TG63GBK3.mjs +1 -0
  145. package/dist/chunk-TG63GBK3.mjs.map +1 -0
  146. package/dist/chunk-TJYMYQAB.mjs +42 -0
  147. package/dist/chunk-TJYMYQAB.mjs.map +1 -0
  148. package/dist/chunk-TKXU7ZXP.mjs +78 -0
  149. package/dist/chunk-TKXU7ZXP.mjs.map +1 -0
  150. package/dist/chunk-TNENASGX.mjs +1 -0
  151. package/dist/chunk-TNENASGX.mjs.map +1 -0
  152. package/dist/chunk-TNRH2LRU.mjs +57 -0
  153. package/dist/chunk-TNRH2LRU.mjs.map +1 -0
  154. package/dist/chunk-TOYWHUAS.mjs +70 -0
  155. package/dist/chunk-TOYWHUAS.mjs.map +1 -0
  156. package/dist/chunk-TT4DP2YW.mjs +35 -0
  157. package/dist/chunk-TT4DP2YW.mjs.map +1 -0
  158. package/dist/chunk-UB3733UY.mjs +23 -0
  159. package/dist/chunk-UB3733UY.mjs.map +1 -0
  160. package/dist/chunk-UBPHGXCO.mjs +74 -0
  161. package/dist/chunk-UBPHGXCO.mjs.map +1 -0
  162. package/dist/chunk-VCGZNL35.mjs +69 -0
  163. package/dist/chunk-VCGZNL35.mjs.map +1 -0
  164. package/dist/chunk-VHY3NATP.js +67 -0
  165. package/dist/chunk-VHY3NATP.js.map +1 -0
  166. package/dist/chunk-VUA6ICJO.js +52 -0
  167. package/dist/chunk-VUA6ICJO.js.map +1 -0
  168. package/dist/chunk-VVBTXSID.mjs +82 -0
  169. package/dist/chunk-VVBTXSID.mjs.map +1 -0
  170. package/dist/chunk-WFAY5FPP.mjs +67 -0
  171. package/dist/chunk-WFAY5FPP.mjs.map +1 -0
  172. package/dist/chunk-WLDEPJGG.mjs +43 -0
  173. package/dist/chunk-WLDEPJGG.mjs.map +1 -0
  174. package/dist/chunk-Y4LNTDZ2.mjs +43 -0
  175. package/dist/chunk-Y4LNTDZ2.mjs.map +1 -0
  176. package/dist/chunk-YG7W4CDT.js +83 -0
  177. package/dist/{cjs/utils.js.map → chunk-YG7W4CDT.js.map} +1 -1
  178. package/dist/chunk-YGKFOOWI.js +20 -0
  179. package/dist/chunk-YGKFOOWI.js.map +1 -0
  180. package/dist/chunk-YOHE52XB.js +23 -0
  181. package/dist/chunk-YOHE52XB.js.map +1 -0
  182. package/dist/chunk-YS6TYXCP.mjs +45 -0
  183. package/dist/chunk-YS6TYXCP.mjs.map +1 -0
  184. package/dist/chunk-ZPK4THX4.js +54 -0
  185. package/dist/chunk-ZPK4THX4.js.map +1 -0
  186. package/dist/endowments/caveats/generic.js +7 -0
  187. package/dist/endowments/caveats/generic.js.map +1 -0
  188. package/dist/endowments/caveats/generic.mjs +7 -0
  189. package/dist/endowments/caveats/generic.mjs.map +1 -0
  190. package/dist/endowments/caveats/index.js +18 -0
  191. package/dist/endowments/caveats/index.js.map +1 -0
  192. package/dist/endowments/caveats/index.mjs +18 -0
  193. package/dist/endowments/caveats/index.mjs.map +1 -0
  194. package/dist/endowments/caveats/requestTime.js +13 -0
  195. package/dist/endowments/caveats/requestTime.js.map +1 -0
  196. package/dist/endowments/caveats/requestTime.mjs +13 -0
  197. package/dist/endowments/caveats/requestTime.mjs.map +1 -0
  198. package/dist/endowments/cronjob.js +16 -0
  199. package/dist/endowments/cronjob.js.map +1 -0
  200. package/dist/endowments/cronjob.mjs +16 -0
  201. package/dist/endowments/cronjob.mjs.map +1 -0
  202. package/dist/endowments/enum.js +7 -0
  203. package/dist/endowments/enum.js.map +1 -0
  204. package/dist/endowments/enum.mjs +7 -0
  205. package/dist/endowments/enum.mjs.map +1 -0
  206. package/dist/endowments/ethereum-provider.js +8 -0
  207. package/dist/endowments/ethereum-provider.js.map +1 -0
  208. package/dist/endowments/ethereum-provider.mjs +8 -0
  209. package/dist/endowments/ethereum-provider.mjs.map +1 -0
  210. package/dist/endowments/home-page.js +8 -0
  211. package/dist/endowments/home-page.js.map +1 -0
  212. package/dist/endowments/home-page.mjs +8 -0
  213. package/dist/endowments/home-page.mjs.map +1 -0
  214. package/dist/endowments/index.js +54 -0
  215. package/dist/endowments/index.js.map +1 -0
  216. package/dist/endowments/index.mjs +54 -0
  217. package/dist/endowments/index.mjs.map +1 -0
  218. package/dist/endowments/keyring.js +17 -0
  219. package/dist/endowments/keyring.js.map +1 -0
  220. package/dist/endowments/keyring.mjs +17 -0
  221. package/dist/endowments/keyring.mjs.map +1 -0
  222. package/dist/endowments/lifecycle-hooks.js +8 -0
  223. package/dist/endowments/lifecycle-hooks.js.map +1 -0
  224. package/dist/endowments/lifecycle-hooks.mjs +8 -0
  225. package/dist/endowments/lifecycle-hooks.mjs.map +1 -0
  226. package/dist/endowments/name-lookup.js +19 -0
  227. package/dist/endowments/name-lookup.js.map +1 -0
  228. package/dist/endowments/name-lookup.mjs +19 -0
  229. package/dist/endowments/name-lookup.mjs.map +1 -0
  230. package/dist/endowments/network-access.js +8 -0
  231. package/dist/endowments/network-access.js.map +1 -0
  232. package/dist/endowments/network-access.mjs +8 -0
  233. package/dist/endowments/network-access.mjs.map +1 -0
  234. package/dist/endowments/rpc.js +17 -0
  235. package/dist/endowments/rpc.js.map +1 -0
  236. package/dist/endowments/rpc.mjs +17 -0
  237. package/dist/endowments/rpc.mjs.map +1 -0
  238. package/dist/endowments/signature-insight.js +17 -0
  239. package/dist/endowments/signature-insight.js.map +1 -0
  240. package/dist/endowments/signature-insight.mjs +17 -0
  241. package/dist/endowments/signature-insight.mjs.map +1 -0
  242. package/dist/endowments/transaction-insight.js +17 -0
  243. package/dist/endowments/transaction-insight.js.map +1 -0
  244. package/dist/endowments/transaction-insight.mjs +17 -0
  245. package/dist/endowments/transaction-insight.mjs.map +1 -0
  246. package/dist/endowments/web-assembly.js +8 -0
  247. package/dist/endowments/web-assembly.js.map +1 -0
  248. package/dist/endowments/web-assembly.mjs +8 -0
  249. package/dist/endowments/web-assembly.mjs.map +1 -0
  250. package/dist/index.js +118 -0
  251. package/dist/index.js.map +1 -0
  252. package/dist/index.mjs +118 -0
  253. package/dist/index.mjs.map +1 -0
  254. package/dist/permissions.js +43 -0
  255. package/dist/permissions.js.map +1 -0
  256. package/dist/permissions.mjs +43 -0
  257. package/dist/permissions.mjs.map +1 -0
  258. package/dist/permitted/createInterface.js +7 -0
  259. package/dist/permitted/createInterface.js.map +1 -0
  260. package/dist/permitted/createInterface.mjs +7 -0
  261. package/dist/permitted/createInterface.mjs.map +1 -0
  262. package/dist/permitted/getAllSnaps.js +7 -0
  263. package/dist/permitted/getAllSnaps.js.map +1 -0
  264. package/dist/permitted/getAllSnaps.mjs +7 -0
  265. package/dist/permitted/getAllSnaps.mjs.map +1 -0
  266. package/dist/permitted/getClientStatus.js +7 -0
  267. package/dist/permitted/getClientStatus.js.map +1 -0
  268. package/dist/permitted/getClientStatus.mjs +7 -0
  269. package/dist/permitted/getClientStatus.mjs.map +1 -0
  270. package/dist/permitted/getFile.js +9 -0
  271. package/dist/permitted/getFile.js.map +1 -0
  272. package/dist/permitted/getFile.mjs +9 -0
  273. package/dist/permitted/getFile.mjs.map +1 -0
  274. package/dist/permitted/getInterfaceState.js +7 -0
  275. package/dist/permitted/getInterfaceState.js.map +1 -0
  276. package/dist/permitted/getInterfaceState.mjs +7 -0
  277. package/dist/permitted/getInterfaceState.mjs.map +1 -0
  278. package/dist/permitted/getSnaps.js +7 -0
  279. package/dist/permitted/getSnaps.js.map +1 -0
  280. package/dist/permitted/getSnaps.mjs +7 -0
  281. package/dist/permitted/getSnaps.mjs.map +1 -0
  282. package/dist/permitted/handlers.js +20 -0
  283. package/dist/permitted/handlers.js.map +1 -0
  284. package/dist/permitted/handlers.mjs +20 -0
  285. package/dist/permitted/handlers.mjs.map +1 -0
  286. package/dist/permitted/index.js +26 -0
  287. package/dist/permitted/index.js.map +1 -0
  288. package/dist/permitted/index.mjs +26 -0
  289. package/dist/permitted/index.mjs.map +1 -0
  290. package/dist/permitted/invokeKeyring.js +8 -0
  291. package/dist/permitted/invokeKeyring.js.map +1 -0
  292. package/dist/permitted/invokeKeyring.mjs +8 -0
  293. package/dist/permitted/invokeKeyring.mjs.map +1 -0
  294. package/dist/permitted/invokeSnapSugar.js +11 -0
  295. package/dist/permitted/invokeSnapSugar.js.map +1 -0
  296. package/dist/permitted/invokeSnapSugar.mjs +11 -0
  297. package/dist/permitted/invokeSnapSugar.mjs.map +1 -0
  298. package/dist/permitted/middleware.js +20 -0
  299. package/dist/permitted/middleware.js.map +1 -0
  300. package/dist/permitted/middleware.mjs +20 -0
  301. package/dist/permitted/middleware.mjs.map +1 -0
  302. package/dist/permitted/requestSnaps.js +12 -0
  303. package/dist/permitted/requestSnaps.js.map +1 -0
  304. package/dist/permitted/requestSnaps.mjs +12 -0
  305. package/dist/permitted/requestSnaps.mjs.map +1 -0
  306. package/dist/permitted/updateInterface.js +7 -0
  307. package/dist/permitted/updateInterface.js.map +1 -0
  308. package/dist/permitted/updateInterface.mjs +7 -0
  309. package/dist/permitted/updateInterface.mjs.map +1 -0
  310. package/dist/restricted/caveats/index.js +17 -0
  311. package/dist/restricted/caveats/index.js.map +1 -0
  312. package/dist/restricted/caveats/index.mjs +17 -0
  313. package/dist/restricted/caveats/index.mjs.map +1 -0
  314. package/dist/restricted/caveats/permittedCoinTypes.js +13 -0
  315. package/dist/restricted/caveats/permittedCoinTypes.js.map +1 -0
  316. package/dist/restricted/caveats/permittedCoinTypes.mjs +13 -0
  317. package/dist/restricted/caveats/permittedCoinTypes.mjs.map +1 -0
  318. package/dist/restricted/caveats/permittedDerivationPaths.js +13 -0
  319. package/dist/restricted/caveats/permittedDerivationPaths.js.map +1 -0
  320. package/dist/restricted/caveats/permittedDerivationPaths.mjs +13 -0
  321. package/dist/restricted/caveats/permittedDerivationPaths.mjs.map +1 -0
  322. package/dist/restricted/caveats/snapIds.js +11 -0
  323. package/dist/restricted/caveats/snapIds.js.map +1 -0
  324. package/dist/restricted/caveats/snapIds.mjs +11 -0
  325. package/dist/restricted/caveats/snapIds.mjs.map +1 -0
  326. package/dist/restricted/dialog.js +9 -0
  327. package/dist/restricted/dialog.js.map +1 -0
  328. package/dist/restricted/dialog.mjs +9 -0
  329. package/dist/restricted/dialog.mjs.map +1 -0
  330. package/dist/restricted/getBip32Entropy.js +10 -0
  331. package/dist/restricted/getBip32Entropy.js.map +1 -0
  332. package/dist/restricted/getBip32Entropy.mjs +10 -0
  333. package/dist/restricted/getBip32Entropy.mjs.map +1 -0
  334. package/dist/restricted/getBip32PublicKey.js +12 -0
  335. package/dist/restricted/getBip32PublicKey.js.map +1 -0
  336. package/dist/restricted/getBip32PublicKey.mjs +12 -0
  337. package/dist/restricted/getBip32PublicKey.mjs.map +1 -0
  338. package/dist/restricted/getBip44Entropy.js +9 -0
  339. package/dist/restricted/getBip44Entropy.js.map +1 -0
  340. package/dist/restricted/getBip44Entropy.mjs +9 -0
  341. package/dist/restricted/getBip44Entropy.mjs.map +1 -0
  342. package/dist/restricted/getEntropy.js +10 -0
  343. package/dist/restricted/getEntropy.js.map +1 -0
  344. package/dist/restricted/getEntropy.mjs +10 -0
  345. package/dist/restricted/getEntropy.mjs.map +1 -0
  346. package/dist/restricted/getLocale.js +11 -0
  347. package/dist/restricted/getLocale.js.map +1 -0
  348. package/dist/restricted/getLocale.mjs +11 -0
  349. package/dist/restricted/getLocale.mjs.map +1 -0
  350. package/dist/restricted/index.js +33 -0
  351. package/dist/restricted/index.js.map +1 -0
  352. package/dist/restricted/index.mjs +33 -0
  353. package/dist/restricted/index.mjs.map +1 -0
  354. package/dist/restricted/invokeSnap.js +13 -0
  355. package/dist/restricted/invokeSnap.js.map +1 -0
  356. package/dist/restricted/invokeSnap.mjs +13 -0
  357. package/dist/restricted/invokeSnap.mjs.map +1 -0
  358. package/dist/restricted/manageAccounts.js +13 -0
  359. package/dist/restricted/manageAccounts.js.map +1 -0
  360. package/dist/restricted/manageAccounts.mjs +13 -0
  361. package/dist/restricted/manageAccounts.mjs.map +1 -0
  362. package/dist/restricted/manageState.js +20 -0
  363. package/dist/restricted/manageState.js.map +1 -0
  364. package/dist/restricted/manageState.mjs +20 -0
  365. package/dist/restricted/manageState.mjs.map +1 -0
  366. package/dist/restricted/notify.js +13 -0
  367. package/dist/restricted/notify.js.map +1 -0
  368. package/dist/restricted/notify.mjs +13 -0
  369. package/dist/restricted/notify.mjs.map +1 -0
  370. package/dist/tsconfig.build.tsbuildinfo +1 -0
  371. package/dist/utils.js +13 -0
  372. package/dist/utils.js.map +1 -0
  373. package/dist/utils.mjs +13 -0
  374. package/dist/utils.mjs.map +1 -0
  375. package/package.json +21 -18
  376. package/dist/cjs/endowments/caveats/generic.js +0 -40
  377. package/dist/cjs/endowments/caveats/generic.js.map +0 -1
  378. package/dist/cjs/endowments/caveats/index.js +0 -21
  379. package/dist/cjs/endowments/caveats/index.js.map +0 -1
  380. package/dist/cjs/endowments/caveats/requestTime.js +0 -99
  381. package/dist/cjs/endowments/caveats/requestTime.js.map +0 -1
  382. package/dist/cjs/endowments/cronjob.js +0 -100
  383. package/dist/cjs/endowments/cronjob.js.map +0 -1
  384. package/dist/cjs/endowments/enum.js +0 -26
  385. package/dist/cjs/endowments/enum.js.map +0 -1
  386. package/dist/cjs/endowments/ethereum-provider.js +0 -43
  387. package/dist/cjs/endowments/home-page.js +0 -37
  388. package/dist/cjs/endowments/home-page.js.map +0 -1
  389. package/dist/cjs/endowments/index.js +0 -121
  390. package/dist/cjs/endowments/index.js.map +0 -1
  391. package/dist/cjs/endowments/keyring.js +0 -104
  392. package/dist/cjs/endowments/keyring.js.map +0 -1
  393. package/dist/cjs/endowments/lifecycle-hooks.js +0 -37
  394. package/dist/cjs/endowments/lifecycle-hooks.js.map +0 -1
  395. package/dist/cjs/endowments/name-lookup.js +0 -148
  396. package/dist/cjs/endowments/name-lookup.js.map +0 -1
  397. package/dist/cjs/endowments/network-access.js +0 -44
  398. package/dist/cjs/endowments/network-access.js.map +0 -1
  399. package/dist/cjs/endowments/rpc.js +0 -103
  400. package/dist/cjs/endowments/rpc.js.map +0 -1
  401. package/dist/cjs/endowments/signature-insight.js +0 -110
  402. package/dist/cjs/endowments/signature-insight.js.map +0 -1
  403. package/dist/cjs/endowments/transaction-insight.js +0 -111
  404. package/dist/cjs/endowments/transaction-insight.js.map +0 -1
  405. package/dist/cjs/endowments/web-assembly.js +0 -42
  406. package/dist/cjs/index.js +0 -45
  407. package/dist/cjs/index.js.map +0 -1
  408. package/dist/cjs/permissions.js +0 -62
  409. package/dist/cjs/permissions.js.map +0 -1
  410. package/dist/cjs/permitted/createInterface.js +0 -68
  411. package/dist/cjs/permitted/createInterface.js.map +0 -1
  412. package/dist/cjs/permitted/getAllSnaps.js +0 -44
  413. package/dist/cjs/permitted/getAllSnaps.js.map +0 -1
  414. package/dist/cjs/permitted/getClientStatus.js +0 -40
  415. package/dist/cjs/permitted/getClientStatus.js.map +0 -1
  416. package/dist/cjs/permitted/getFile.js +0 -63
  417. package/dist/cjs/permitted/getFile.js.map +0 -1
  418. package/dist/cjs/permitted/getInterfaceState.js +0 -67
  419. package/dist/cjs/permitted/getInterfaceState.js.map +0 -1
  420. package/dist/cjs/permitted/getSnaps.js +0 -39
  421. package/dist/cjs/permitted/getSnaps.js.map +0 -1
  422. package/dist/cjs/permitted/handlers.js +0 -43
  423. package/dist/cjs/permitted/handlers.js.map +0 -1
  424. package/dist/cjs/permitted/index.js +0 -21
  425. package/dist/cjs/permitted/index.js.map +0 -1
  426. package/dist/cjs/permitted/invokeKeyring.js +0 -87
  427. package/dist/cjs/permitted/invokeKeyring.js.map +0 -1
  428. package/dist/cjs/permitted/invokeSnapSugar.js +0 -62
  429. package/dist/cjs/permitted/invokeSnapSugar.js.map +0 -1
  430. package/dist/cjs/permitted/middleware.js +0 -38
  431. package/dist/cjs/permitted/middleware.js.map +0 -1
  432. package/dist/cjs/permitted/requestSnaps.js +0 -123
  433. package/dist/cjs/permitted/requestSnaps.js.map +0 -1
  434. package/dist/cjs/permitted/updateInterface.js +0 -70
  435. package/dist/cjs/permitted/updateInterface.js.map +0 -1
  436. package/dist/cjs/restricted/caveats/index.js +0 -38
  437. package/dist/cjs/restricted/caveats/index.js.map +0 -1
  438. package/dist/cjs/restricted/caveats/permittedCoinTypes.js +0 -83
  439. package/dist/cjs/restricted/caveats/permittedCoinTypes.js.map +0 -1
  440. package/dist/cjs/restricted/caveats/permittedDerivationPaths.js +0 -67
  441. package/dist/cjs/restricted/caveats/permittedDerivationPaths.js.map +0 -1
  442. package/dist/cjs/restricted/caveats/snapIds.js +0 -59
  443. package/dist/cjs/restricted/caveats/snapIds.js.map +0 -1
  444. package/dist/cjs/restricted/dialog.js +0 -172
  445. package/dist/cjs/restricted/dialog.js.map +0 -1
  446. package/dist/cjs/restricted/getBip32Entropy.js +0 -76
  447. package/dist/cjs/restricted/getBip32Entropy.js.map +0 -1
  448. package/dist/cjs/restricted/getBip32PublicKey.js +0 -91
  449. package/dist/cjs/restricted/getBip44Entropy.js +0 -76
  450. package/dist/cjs/restricted/getBip44Entropy.js.map +0 -1
  451. package/dist/cjs/restricted/getEntropy.js +0 -76
  452. package/dist/cjs/restricted/getEntropy.js.map +0 -1
  453. package/dist/cjs/restricted/getLocale.js +0 -49
  454. package/dist/cjs/restricted/getLocale.js.map +0 -1
  455. package/dist/cjs/restricted/index.js +0 -59
  456. package/dist/cjs/restricted/index.js.map +0 -1
  457. package/dist/cjs/restricted/invokeSnap.js +0 -99
  458. package/dist/cjs/restricted/invokeSnap.js.map +0 -1
  459. package/dist/cjs/restricted/manageAccounts.js +0 -68
  460. package/dist/cjs/restricted/manageAccounts.js.map +0 -1
  461. package/dist/cjs/restricted/manageState.js +0 -208
  462. package/dist/cjs/restricted/manageState.js.map +0 -1
  463. package/dist/cjs/restricted/notify.js +0 -92
  464. package/dist/cjs/restricted/notify.js.map +0 -1
  465. package/dist/cjs/utils.js +0 -98
  466. package/dist/esm/endowments/caveats/generic.js +0 -40
  467. package/dist/esm/endowments/caveats/generic.js.map +0 -1
  468. package/dist/esm/endowments/caveats/index.js +0 -4
  469. package/dist/esm/endowments/caveats/index.js.map +0 -1
  470. package/dist/esm/endowments/caveats/requestTime.js +0 -93
  471. package/dist/esm/endowments/caveats/requestTime.js.map +0 -1
  472. package/dist/esm/endowments/cronjob.js +0 -99
  473. package/dist/esm/endowments/cronjob.js.map +0 -1
  474. package/dist/esm/endowments/enum.js +0 -16
  475. package/dist/esm/endowments/enum.js.map +0 -1
  476. package/dist/esm/endowments/ethereum-provider.js +0 -33
  477. package/dist/esm/endowments/ethereum-provider.js.map +0 -1
  478. package/dist/esm/endowments/home-page.js +0 -27
  479. package/dist/esm/endowments/home-page.js.map +0 -1
  480. package/dist/esm/endowments/index.js +0 -68
  481. package/dist/esm/endowments/index.js.map +0 -1
  482. package/dist/esm/endowments/keyring.js +0 -95
  483. package/dist/esm/endowments/keyring.js.map +0 -1
  484. package/dist/esm/endowments/lifecycle-hooks.js +0 -27
  485. package/dist/esm/endowments/lifecycle-hooks.js.map +0 -1
  486. package/dist/esm/endowments/name-lookup.js +0 -146
  487. package/dist/esm/endowments/name-lookup.js.map +0 -1
  488. package/dist/esm/endowments/network-access.js +0 -34
  489. package/dist/esm/endowments/network-access.js.map +0 -1
  490. package/dist/esm/endowments/rpc.js +0 -92
  491. package/dist/esm/endowments/rpc.js.map +0 -1
  492. package/dist/esm/endowments/signature-insight.js +0 -103
  493. package/dist/esm/endowments/signature-insight.js.map +0 -1
  494. package/dist/esm/endowments/transaction-insight.js +0 -104
  495. package/dist/esm/endowments/transaction-insight.js.map +0 -1
  496. package/dist/esm/endowments/web-assembly.js +0 -32
  497. package/dist/esm/endowments/web-assembly.js.map +0 -1
  498. package/dist/esm/index.js +0 -8
  499. package/dist/esm/index.js.map +0 -1
  500. package/dist/esm/permissions.js +0 -51
  501. package/dist/esm/permissions.js.map +0 -1
  502. package/dist/esm/permitted/createInterface.js +0 -58
  503. package/dist/esm/permitted/createInterface.js.map +0 -1
  504. package/dist/esm/permitted/getAllSnaps.js +0 -37
  505. package/dist/esm/permitted/getAllSnaps.js.map +0 -1
  506. package/dist/esm/permitted/getClientStatus.js +0 -32
  507. package/dist/esm/permitted/getClientStatus.js.map +0 -1
  508. package/dist/esm/permitted/getFile.js +0 -45
  509. package/dist/esm/permitted/getFile.js.map +0 -1
  510. package/dist/esm/permitted/getInterfaceState.js +0 -57
  511. package/dist/esm/permitted/getInterfaceState.js.map +0 -1
  512. package/dist/esm/permitted/getSnaps.js +0 -31
  513. package/dist/esm/permitted/getSnaps.js.map +0 -1
  514. package/dist/esm/permitted/handlers.js +0 -25
  515. package/dist/esm/permitted/handlers.js.map +0 -1
  516. package/dist/esm/permitted/index.js +0 -4
  517. package/dist/esm/permitted/index.js.map +0 -1
  518. package/dist/esm/permitted/invokeKeyring.js +0 -79
  519. package/dist/esm/permitted/invokeKeyring.js.map +0 -1
  520. package/dist/esm/permitted/invokeSnapSugar.js +0 -60
  521. package/dist/esm/permitted/invokeSnapSugar.js.map +0 -1
  522. package/dist/esm/permitted/middleware.js +0 -34
  523. package/dist/esm/permitted/middleware.js.map +0 -1
  524. package/dist/esm/permitted/requestSnaps.js +0 -118
  525. package/dist/esm/permitted/requestSnaps.js.map +0 -1
  526. package/dist/esm/permitted/updateInterface.js +0 -60
  527. package/dist/esm/permitted/updateInterface.js.map +0 -1
  528. package/dist/esm/restricted/caveats/index.js +0 -20
  529. package/dist/esm/restricted/caveats/index.js.map +0 -1
  530. package/dist/esm/restricted/caveats/permittedCoinTypes.js +0 -77
  531. package/dist/esm/restricted/caveats/permittedCoinTypes.js.map +0 -1
  532. package/dist/esm/restricted/caveats/permittedDerivationPaths.js +0 -64
  533. package/dist/esm/restricted/caveats/permittedDerivationPaths.js.map +0 -1
  534. package/dist/esm/restricted/caveats/snapIds.js +0 -50
  535. package/dist/esm/restricted/caveats/snapIds.js.map +0 -1
  536. package/dist/esm/restricted/dialog.js +0 -164
  537. package/dist/esm/restricted/dialog.js.map +0 -1
  538. package/dist/esm/restricted/getBip32Entropy.js +0 -67
  539. package/dist/esm/restricted/getBip32Entropy.js.map +0 -1
  540. package/dist/esm/restricted/getBip32PublicKey.js +0 -79
  541. package/dist/esm/restricted/getBip32PublicKey.js.map +0 -1
  542. package/dist/esm/restricted/getBip44Entropy.js +0 -69
  543. package/dist/esm/restricted/getBip44Entropy.js.map +0 -1
  544. package/dist/esm/restricted/getEntropy.js +0 -58
  545. package/dist/esm/restricted/getEntropy.js.map +0 -1
  546. package/dist/esm/restricted/getLocale.js +0 -42
  547. package/dist/esm/restricted/getLocale.js.map +0 -1
  548. package/dist/esm/restricted/index.js +0 -27
  549. package/dist/esm/restricted/index.js.map +0 -1
  550. package/dist/esm/restricted/invokeSnap.js +0 -89
  551. package/dist/esm/restricted/invokeSnap.js.map +0 -1
  552. package/dist/esm/restricted/manageAccounts.js +0 -60
  553. package/dist/esm/restricted/manageAccounts.js.map +0 -1
  554. package/dist/esm/restricted/manageState.js +0 -225
  555. package/dist/esm/restricted/manageState.js.map +0 -1
  556. package/dist/esm/restricted/notify.js +0 -92
  557. package/dist/esm/restricted/notify.js.map +0 -1
  558. package/dist/esm/utils.js +0 -124
  559. package/dist/esm/utils.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/restricted/manageState.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { ManageStateParams, ManageStateResult } from '@metamask/snaps-sdk';\nimport { ManageStateOperation } from '@metamask/snaps-sdk';\nimport { STATE_ENCRYPTION_MAGIC_VALUE, parseJson } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray, Hex } from '@metamask/utils';\nimport { isObject, getJsonSize, assert, isValidJson } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { deriveEntropy } from '../utils';\n\n// The salt used for SIP-6-based entropy derivation.\nexport const STATE_ENCRYPTION_SALT = 'snap_manageState encryption';\n\nconst methodName = 'snap_manageState';\n\nexport type ManageStateMethodHooks = {\n /**\n * @returns The mnemonic of the user's primary keyring.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * A function that clears the state of the requesting Snap.\n */\n clearSnapState: (snapId: string, encrypted: boolean) => void;\n\n /**\n * A function that gets the encrypted state of the requesting Snap.\n *\n * @returns The current state of the Snap.\n */\n getSnapState: (snapId: string, encrypted: boolean) => string;\n\n /**\n * A function that updates the state of the requesting Snap.\n *\n * @param newState - The new state of the Snap.\n */\n updateSnapState: (\n snapId: string,\n newState: string,\n encrypted: boolean,\n ) => void;\n\n /**\n * Encrypts data with a key. This is assumed to perform symmetric encryption.\n *\n * @param key - The key to use for encryption, in hexadecimal format.\n * @param data - The JSON data to encrypt.\n * @returns The ciphertext as a string. The format for this string is\n * dependent on the implementation, but MUST be a string.\n */\n encrypt: (key: string, data: Json) => Promise<string>;\n\n /**\n * Decrypts data with a key. This is assumed to perform symmetric decryption.\n *\n * @param key - The key to use for decryption, in hexadecimal format.\n * @param cipherText - The ciphertext to decrypt. The format for this string\n * is dependent on the implementation, but MUST be a string.\n * @returns The decrypted data as a JSON object.\n */\n decrypt: (key: Hex, cipherText: string) => Promise<unknown>;\n};\n\ntype ManageStateSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: ManageStateMethodHooks;\n};\n\ntype ManageStateSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getManageStateImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_manageState` permission.\n * `snap_manageState` lets the Snap store and manage some of its state on\n * your device.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_manageState` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n ManageStateSpecificationBuilderOptions,\n ManageStateSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: ManageStateSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getManageStateImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<ManageStateMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n clearSnapState: true,\n getSnapState: true,\n updateSnapState: true,\n encrypt: true,\n decrypt: true,\n};\n\nexport const manageStateBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport const STORAGE_SIZE_LIMIT = 104857600; // In bytes (100MB)\n\ntype GetEncryptionKeyArgs = {\n snapId: string;\n mnemonicPhrase: Uint8Array;\n};\n\n/**\n * Get a deterministic encryption key to use for encrypting and decrypting the\n * state.\n *\n * This key should only be used for state encryption using `snap_manageState`.\n * To get other encryption keys, a different salt can be used.\n *\n * @param args - The encryption key args.\n * @param args.snapId - The ID of the snap to get the encryption key for.\n * @param args.mnemonicPhrase - The mnemonic phrase to derive the encryption key\n * from.\n * @returns The state encryption key.\n */\nexport async function getEncryptionKey({\n mnemonicPhrase,\n snapId,\n}: GetEncryptionKeyArgs) {\n return await deriveEntropy({\n mnemonicPhrase,\n input: snapId,\n salt: STATE_ENCRYPTION_SALT,\n magic: STATE_ENCRYPTION_MAGIC_VALUE,\n });\n}\n\ntype EncryptStateArgs = GetEncryptionKeyArgs & {\n state: Json;\n encryptFunction: ManageStateMethodHooks['encrypt'];\n};\n\n/**\n * Encrypt the state using a deterministic encryption algorithm, based on the\n * snap ID and mnemonic phrase.\n *\n * @param args - The encryption args.\n * @param args.state - The state to encrypt.\n * @param args.encryptFunction - The function to use for encrypting the state.\n * @param args.snapId - The ID of the snap to get the encryption key for.\n * @param args.mnemonicPhrase - The mnemonic phrase to derive the encryption key\n * from.\n * @returns The encrypted state.\n */\nasync function encryptState({\n state,\n encryptFunction,\n ...keyArgs\n}: EncryptStateArgs) {\n const encryptionKey = await getEncryptionKey(keyArgs);\n return await encryptFunction(encryptionKey, state);\n}\n\ntype DecryptStateArgs = GetEncryptionKeyArgs & {\n state: string;\n decryptFunction: ManageStateMethodHooks['decrypt'];\n};\n\n/**\n * Decrypt the state using a deterministic decryption algorithm, based on the\n * snap ID and mnemonic phrase.\n *\n * @param args - The encryption args.\n * @param args.state - The state to decrypt.\n * @param args.decryptFunction - The function to use for decrypting the state.\n * @param args.snapId - The ID of the snap to get the encryption key for.\n * @param args.mnemonicPhrase - The mnemonic phrase to derive the encryption key\n * from.\n * @returns The encrypted state.\n */\nasync function decryptState({\n state,\n decryptFunction,\n ...keyArgs\n}: DecryptStateArgs) {\n try {\n const encryptionKey = await getEncryptionKey(keyArgs);\n const decryptedState = await decryptFunction(encryptionKey, state);\n\n assert(isValidJson(decryptedState));\n\n return decryptedState as Record<string, Json>;\n } catch {\n throw rpcErrors.internal({\n message: 'Failed to decrypt snap state, the state must be corrupted.',\n });\n }\n}\n\n/**\n * Builds the method implementation for `snap_manageState`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.clearSnapState - A function that clears the state stored for a\n * snap.\n * @param hooks.getSnapState - A function that fetches the persisted decrypted\n * state for a snap.\n * @param hooks.updateSnapState - A function that updates the state stored for a\n * snap.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase\n * of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask\n * extension is unlocked and prompts the user to unlock their MetaMask if it is\n * locked.\n * @param hooks.encrypt - A function that encrypts the given state.\n * @param hooks.decrypt - A function that decrypts the given state.\n * @returns The method implementation which either returns `null` for a\n * successful state update/deletion or returns the decrypted state.\n * @throws If the params are invalid.\n */\nexport function getManageStateImplementation({\n getMnemonic,\n getUnlockPromise,\n clearSnapState,\n getSnapState,\n updateSnapState,\n encrypt,\n decrypt,\n}: ManageStateMethodHooks) {\n return async function manageState(\n options: RestrictedMethodOptions<ManageStateParams>,\n ): Promise<ManageStateResult> {\n const {\n params = {},\n method,\n context: { origin },\n } = options;\n const validatedParams = getValidatedParams(params, method);\n\n // If the encrypted param is undefined or null we default to true.\n const shouldEncrypt = validatedParams.encrypted ?? true;\n\n // We only need to prompt the user when the mnemonic is needed\n // which it isn't for the clear operation or unencrypted storage.\n if (\n shouldEncrypt &&\n validatedParams.operation !== ManageStateOperation.ClearState\n ) {\n await getUnlockPromise(true);\n }\n\n switch (validatedParams.operation) {\n case ManageStateOperation.ClearState:\n clearSnapState(origin, shouldEncrypt);\n return null;\n\n case ManageStateOperation.GetState: {\n const state = getSnapState(origin, shouldEncrypt);\n if (state === null) {\n return state;\n }\n return shouldEncrypt\n ? await decryptState({\n state,\n decryptFunction: decrypt,\n mnemonicPhrase: await getMnemonic(),\n snapId: origin,\n })\n : parseJson<Record<string, Json>>(state);\n }\n\n case ManageStateOperation.UpdateState: {\n const finalizedState = shouldEncrypt\n ? await encryptState({\n state: validatedParams.newState,\n encryptFunction: encrypt,\n mnemonicPhrase: await getMnemonic(),\n snapId: origin,\n })\n : JSON.stringify(validatedParams.newState);\n\n updateSnapState(origin, finalizedState, shouldEncrypt);\n return null;\n }\n\n default:\n throw rpcErrors.invalidParams(\n `Invalid ${method} operation: \"${\n validatedParams.operation as string\n }\"`,\n );\n }\n };\n}\n\n/**\n * Validates the manageState method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @param method - RPC method name used for debugging errors.\n * @param storageSizeLimit - Maximum allowed size (in bytes) of a new state object.\n * @returns The validated method parameter object.\n */\nexport function getValidatedParams(\n params: unknown,\n method: string,\n storageSizeLimit = STORAGE_SIZE_LIMIT,\n): ManageStateParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { operation, newState, encrypted } = params;\n\n if (\n !operation ||\n typeof operation !== 'string' ||\n !Object.values(ManageStateOperation).includes(\n operation as ManageStateOperation,\n )\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid manage state \"operation\".',\n });\n }\n\n if (encrypted !== undefined && typeof encrypted !== 'boolean') {\n throw rpcErrors.invalidParams({\n message: '\"encrypted\" parameter must be a boolean if specified.',\n });\n }\n\n if (operation === ManageStateOperation.UpdateState) {\n if (!isObject(newState)) {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"updateState\" parameter: The new state must be a plain object.`,\n data: {\n receivedNewState:\n typeof newState === 'undefined' ? 'undefined' : newState,\n },\n });\n }\n\n let size;\n try {\n // `getJsonSize` will throw if the state is not JSON serializable.\n size = getJsonSize(newState);\n } catch {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"updateState\" parameter: The new state must be JSON serializable.`,\n data: {\n receivedNewState:\n typeof newState === 'undefined' ? 'undefined' : newState,\n },\n });\n }\n\n if (size > storageSizeLimit) {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"updateState\" parameter: The new state must not exceed ${storageSizeLimit} bytes in size.`,\n data: {\n receivedNewState:\n typeof newState === 'undefined' ? 'undefined' : newState,\n },\n });\n }\n }\n\n return params as ManageStateParams;\n}\n"],"names":["STATE_ENCRYPTION_SALT","specificationBuilder","manageStateBuilder","STORAGE_SIZE_LIMIT","getEncryptionKey","getManageStateImplementation","getValidatedParams","methodName","allowedCaveats","methodHooks","permissionType","PermissionType","RestrictedMethod","targetName","methodImplementation","subjectTypes","SubjectType","Snap","getMnemonic","getUnlockPromise","clearSnapState","getSnapState","updateSnapState","encrypt","decrypt","Object","freeze","mnemonicPhrase","snapId","deriveEntropy","input","salt","magic","STATE_ENCRYPTION_MAGIC_VALUE","encryptState","state","encryptFunction","keyArgs","encryptionKey","decryptState","decryptFunction","decryptedState","assert","isValidJson","rpcErrors","internal","message","manageState","options","params","method","context","origin","validatedParams","shouldEncrypt","encrypted","operation","ManageStateOperation","ClearState","GetState","parseJson","UpdateState","finalizedState","newState","JSON","stringify","invalidParams","storageSizeLimit","isObject","values","includes","undefined","data","receivedNewState","size","getJsonSize"],"mappings":";;;;;;;;;;;IAiBaA,qBAAqB;eAArBA;;IAmFAC,oBAAoB;eAApBA;;IA2BAC,kBAAkB;eAAlBA;;IAMAC,kBAAkB;eAAlBA;;IAoBSC,gBAAgB;eAAhBA;;IA+FNC,4BAA4B;eAA5BA;;IAoFAC,kBAAkB;eAAlBA;;;sCAvU4B;2BAClB;0BAEW;4BACmB;uBAEG;wBAG7B;AAGvB,MAAMN,wBAAwB;AAErC,MAAMO,aAAa;AAiFZ,MAAMN,uBAIT,CAAC,EACHO,iBAAiB,IAAI,EACrBC,WAAW,EAC4B;IACvC,OAAO;QACLC,gBAAgBC,oCAAc,CAACC,gBAAgB;QAC/CC,YAAYN;QACZC;QACAM,sBAAsBT,6BAA6BI;QACnDM,cAAc;YAACC,iCAAW,CAACC,IAAI;SAAC;IAClC;AACF;AAEA,MAAMR,cAAyD;IAC7DS,aAAa;IACbC,kBAAkB;IAClBC,gBAAgB;IAChBC,cAAc;IACdC,iBAAiB;IACjBC,SAAS;IACTC,SAAS;AACX;AAEO,MAAMtB,qBAAqBuB,OAAOC,MAAM,CAAC;IAC9Cb,YAAYN;IACZN;IACAQ;AACF;AAEO,MAAMN,qBAAqB,WAAW,mBAAmB;AAoBzD,eAAeC,iBAAiB,EACrCuB,cAAc,EACdC,MAAM,EACe;IACrB,OAAO,MAAMC,IAAAA,qBAAa,EAAC;QACzBF;QACAG,OAAOF;QACPG,MAAM/B;QACNgC,OAAOC,wCAA4B;IACrC;AACF;AAOA;;;;;;;;;;;CAWC,GACD,eAAeC,aAAa,EAC1BC,KAAK,EACLC,eAAe,EACf,GAAGC,SACc;IACjB,MAAMC,gBAAgB,MAAMlC,iBAAiBiC;IAC7C,OAAO,MAAMD,gBAAgBE,eAAeH;AAC9C;AAOA;;;;;;;;;;;CAWC,GACD,eAAeI,aAAa,EAC1BJ,KAAK,EACLK,eAAe,EACf,GAAGH,SACc;IACjB,IAAI;QACF,MAAMC,gBAAgB,MAAMlC,iBAAiBiC;QAC7C,MAAMI,iBAAiB,MAAMD,gBAAgBF,eAAeH;QAE5DO,IAAAA,aAAM,EAACC,IAAAA,kBAAW,EAACF;QAEnB,OAAOA;IACT,EAAE,OAAM;QACN,MAAMG,oBAAS,CAACC,QAAQ,CAAC;YACvBC,SAAS;QACX;IACF;AACF;AAuBO,SAASzC,6BAA6B,EAC3Ca,WAAW,EACXC,gBAAgB,EAChBC,cAAc,EACdC,YAAY,EACZC,eAAe,EACfC,OAAO,EACPC,OAAO,EACgB;IACvB,OAAO,eAAeuB,YACpBC,OAAmD;QAEnD,MAAM,EACJC,SAAS,CAAC,CAAC,EACXC,MAAM,EACNC,SAAS,EAAEC,MAAM,EAAE,EACpB,GAAGJ;QACJ,MAAMK,kBAAkB/C,mBAAmB2C,QAAQC;QAEnD,kEAAkE;QAClE,MAAMI,gBAAgBD,gBAAgBE,SAAS,IAAI;QAEnD,8DAA8D;QAC9D,iEAAiE;QACjE,IACED,iBACAD,gBAAgBG,SAAS,KAAKC,8BAAoB,CAACC,UAAU,EAC7D;YACA,MAAMvC,iBAAiB;QACzB;QAEA,OAAQkC,gBAAgBG,SAAS;YAC/B,KAAKC,8BAAoB,CAACC,UAAU;gBAClCtC,eAAegC,QAAQE;gBACvB,OAAO;YAET,KAAKG,8BAAoB,CAACE,QAAQ;gBAAE;oBAClC,MAAMxB,QAAQd,aAAa+B,QAAQE;oBACnC,IAAInB,UAAU,MAAM;wBAClB,OAAOA;oBACT;oBACA,OAAOmB,gBACH,MAAMf,aAAa;wBACjBJ;wBACAK,iBAAiBhB;wBACjBG,gBAAgB,MAAMT;wBACtBU,QAAQwB;oBACV,KACAQ,IAAAA,qBAAS,EAAuBzB;gBACtC;YAEA,KAAKsB,8BAAoB,CAACI,WAAW;gBAAE;oBACrC,MAAMC,iBAAiBR,gBACnB,MAAMpB,aAAa;wBACjBC,OAAOkB,gBAAgBU,QAAQ;wBAC/B3B,iBAAiBb;wBACjBI,gBAAgB,MAAMT;wBACtBU,QAAQwB;oBACV,KACAY,KAAKC,SAAS,CAACZ,gBAAgBU,QAAQ;oBAE3CzC,gBAAgB8B,QAAQU,gBAAgBR;oBACxC,OAAO;gBACT;YAEA;gBACE,MAAMV,oBAAS,CAACsB,aAAa,CAC3B,CAAC,QAAQ,EAAEhB,OAAO,aAAa,EAC7BG,gBAAgBG,SAAS,CAC1B,CAAC,CAAC;QAET;IACF;AACF;AAWO,SAASlD,mBACd2C,MAAe,EACfC,MAAc,EACdiB,mBAAmBhE,kBAAkB;IAErC,IAAI,CAACiE,IAAAA,eAAQ,EAACnB,SAAS;QACrB,MAAML,oBAAS,CAACsB,aAAa,CAAC;YAC5BpB,SAAS;QACX;IACF;IAEA,MAAM,EAAEU,SAAS,EAAEO,QAAQ,EAAER,SAAS,EAAE,GAAGN;IAE3C,IACE,CAACO,aACD,OAAOA,cAAc,YACrB,CAAC/B,OAAO4C,MAAM,CAACZ,8BAAoB,EAAEa,QAAQ,CAC3Cd,YAEF;QACA,MAAMZ,oBAAS,CAACsB,aAAa,CAAC;YAC5BpB,SAAS;QACX;IACF;IAEA,IAAIS,cAAcgB,aAAa,OAAOhB,cAAc,WAAW;QAC7D,MAAMX,oBAAS,CAACsB,aAAa,CAAC;YAC5BpB,SAAS;QACX;IACF;IAEA,IAAIU,cAAcC,8BAAoB,CAACI,WAAW,EAAE;QAClD,IAAI,CAACO,IAAAA,eAAQ,EAACL,WAAW;YACvB,MAAMnB,oBAAS,CAACsB,aAAa,CAAC;gBAC5BpB,SAAS,CAAC,QAAQ,EAAEI,OAAO,+DAA+D,CAAC;gBAC3FsB,MAAM;oBACJC,kBACE,OAAOV,aAAa,cAAc,cAAcA;gBACpD;YACF;QACF;QAEA,IAAIW;QACJ,IAAI;YACF,kEAAkE;YAClEA,OAAOC,IAAAA,kBAAW,EAACZ;QACrB,EAAE,OAAM;YACN,MAAMnB,oBAAS,CAACsB,aAAa,CAAC;gBAC5BpB,SAAS,CAAC,QAAQ,EAAEI,OAAO,kEAAkE,CAAC;gBAC9FsB,MAAM;oBACJC,kBACE,OAAOV,aAAa,cAAc,cAAcA;gBACpD;YACF;QACF;QAEA,IAAIW,OAAOP,kBAAkB;YAC3B,MAAMvB,oBAAS,CAACsB,aAAa,CAAC;gBAC5BpB,SAAS,CAAC,QAAQ,EAAEI,OAAO,wDAAwD,EAAEiB,iBAAiB,eAAe,CAAC;gBACtHK,MAAM;oBACJC,kBACE,OAAOV,aAAa,cAAc,cAAcA;gBACpD;YACF;QACF;IACF;IAEA,OAAOd;AACT"}
@@ -1,92 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- specificationBuilder: function() {
13
- return specificationBuilder;
14
- },
15
- notifyBuilder: function() {
16
- return notifyBuilder;
17
- },
18
- getImplementation: function() {
19
- return getImplementation;
20
- },
21
- getValidatedParams: function() {
22
- return getValidatedParams;
23
- }
24
- });
25
- const _permissioncontroller = require("@metamask/permission-controller");
26
- const _rpcerrors = require("@metamask/rpc-errors");
27
- const _snapssdk = require("@metamask/snaps-sdk");
28
- const _snapsutils = require("@metamask/snaps-utils");
29
- const _utils = require("@metamask/utils");
30
- const methodName = 'snap_notify';
31
- const specificationBuilder = ({ allowedCaveats = null, methodHooks })=>{
32
- return {
33
- permissionType: _permissioncontroller.PermissionType.RestrictedMethod,
34
- targetName: methodName,
35
- allowedCaveats,
36
- methodImplementation: getImplementation(methodHooks),
37
- subjectTypes: [
38
- _permissioncontroller.SubjectType.Snap
39
- ]
40
- };
41
- };
42
- const methodHooks = {
43
- showNativeNotification: true,
44
- showInAppNotification: true,
45
- isOnPhishingList: true,
46
- maybeUpdatePhishingList: true
47
- };
48
- const notifyBuilder = Object.freeze({
49
- targetName: methodName,
50
- specificationBuilder,
51
- methodHooks
52
- });
53
- function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList }) {
54
- return async function implementation(args) {
55
- const { params, context: { origin } } = args;
56
- const validatedParams = getValidatedParams(params);
57
- await maybeUpdatePhishingList();
58
- (0, _snapsutils.validateTextLinks)(validatedParams.message, isOnPhishingList);
59
- switch(validatedParams.type){
60
- case _snapssdk.NotificationType.Native:
61
- return await showNativeNotification(origin, validatedParams);
62
- case _snapssdk.NotificationType.InApp:
63
- return await showInAppNotification(origin, validatedParams);
64
- default:
65
- throw _rpcerrors.rpcErrors.invalidParams({
66
- message: 'Must specify a valid notification "type".'
67
- });
68
- }
69
- };
70
- }
71
- function getValidatedParams(params) {
72
- if (!(0, _utils.isObject)(params)) {
73
- throw _rpcerrors.rpcErrors.invalidParams({
74
- message: 'Expected params to be a single object.'
75
- });
76
- }
77
- const { type, message } = params;
78
- if (!type || typeof type !== 'string' || !Object.values(_snapssdk.NotificationType).includes(type)) {
79
- throw _rpcerrors.rpcErrors.invalidParams({
80
- message: 'Must specify a valid notification "type".'
81
- });
82
- }
83
- // Set to the max message length on a Mac notification for now.
84
- if (!message || typeof message !== 'string' || message.length >= 50) {
85
- throw _rpcerrors.rpcErrors.invalidParams({
86
- message: 'Must specify a non-empty string "message" less than 50 characters long.'
87
- });
88
- }
89
- return params;
90
- }
91
-
92
- //# sourceMappingURL=notify.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/restricted/notify.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { NotificationType } from '@metamask/snaps-sdk';\nimport type {\n NotifyParams,\n NotifyResult,\n EnumToUnion,\n} from '@metamask/snaps-sdk';\nimport { validateTextLinks } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { isObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_notify';\n\nexport type NotificationArgs = {\n /**\n * Enum type to determine notification type.\n */\n type: EnumToUnion<NotificationType>;\n\n /**\n * A message to show on the notification.\n */\n message: string;\n};\n\nexport type NotifyMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showNativeNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showInAppNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n isOnPhishingList: (url: string) => boolean;\n\n maybeUpdatePhishingList: () => Promise<void>;\n};\n\ntype SpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: NotifyMethodHooks;\n};\n\ntype Specification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_notify` permission.\n * `snap_notify` allows snaps to send multiple types of notifications to its users.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_notify` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n SpecificationBuilderOptions,\n Specification\n> = ({ allowedCaveats = null, methodHooks }: SpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<NotifyMethodHooks> = {\n showNativeNotification: true,\n showInAppNotification: true,\n isOnPhishingList: true,\n maybeUpdatePhishingList: true,\n};\n\nexport const notifyBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_notify`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showNativeNotification - A function that shows a native browser notification.\n * @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.\n * @param hooks.isOnPhishingList - A function that checks for links against the phishing list.\n * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\n * @returns The method implementation which returns `null` on success.\n * @throws If the params are invalid.\n */\nexport function getImplementation({\n showNativeNotification,\n showInAppNotification,\n isOnPhishingList,\n maybeUpdatePhishingList,\n}: NotifyMethodHooks) {\n return async function implementation(\n args: RestrictedMethodOptions<NotifyParams>,\n ): Promise<NotifyResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n const validatedParams = getValidatedParams(params);\n\n await maybeUpdatePhishingList();\n\n validateTextLinks(validatedParams.message, isOnPhishingList);\n\n switch (validatedParams.type) {\n case NotificationType.Native:\n return await showNativeNotification(origin, validatedParams);\n case NotificationType.InApp:\n return await showInAppNotification(origin, validatedParams);\n default:\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n };\n}\n\n/**\n * Validates the notify method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated method parameter object.\n */\nexport function getValidatedParams(params: unknown): NotifyParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { type, message } = params;\n\n if (\n !type ||\n typeof type !== 'string' ||\n !Object.values(NotificationType).includes(type as NotificationType)\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n\n // Set to the max message length on a Mac notification for now.\n if (!message || typeof message !== 'string' || message.length >= 50) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n return params as NotificationArgs;\n}\n"],"names":["specificationBuilder","notifyBuilder","getImplementation","getValidatedParams","methodName","allowedCaveats","methodHooks","permissionType","PermissionType","RestrictedMethod","targetName","methodImplementation","subjectTypes","SubjectType","Snap","showNativeNotification","showInAppNotification","isOnPhishingList","maybeUpdatePhishingList","Object","freeze","implementation","args","params","context","origin","validatedParams","validateTextLinks","message","type","NotificationType","Native","InApp","rpcErrors","invalidParams","isObject","values","includes","length"],"mappings":";;;;;;;;;;;IA8EaA,oBAAoB;eAApBA;;IAqBAC,aAAa;eAAbA;;IAiBGC,iBAAiB;eAAjBA;;IAwCAC,kBAAkB;eAAlBA;;;sCAvJ4B;2BAClB;0BACO;4BAMC;uBAET;AAIzB,MAAMC,aAAa;AA2DZ,MAAMJ,uBAIT,CAAC,EAAEK,iBAAiB,IAAI,EAAEC,WAAW,EAA+B;IACtE,OAAO;QACLC,gBAAgBC,oCAAc,CAACC,gBAAgB;QAC/CC,YAAYN;QACZC;QACAM,sBAAsBT,kBAAkBI;QACxCM,cAAc;YAACC,iCAAW,CAACC,IAAI;SAAC;IAClC;AACF;AAEA,MAAMR,cAAoD;IACxDS,wBAAwB;IACxBC,uBAAuB;IACvBC,kBAAkB;IAClBC,yBAAyB;AAC3B;AAEO,MAAMjB,gBAAgBkB,OAAOC,MAAM,CAAC;IACzCV,YAAYN;IACZJ;IACAM;AACF;AAaO,SAASJ,kBAAkB,EAChCa,sBAAsB,EACtBC,qBAAqB,EACrBC,gBAAgB,EAChBC,uBAAuB,EACL;IAClB,OAAO,eAAeG,eACpBC,IAA2C;QAE3C,MAAM,EACJC,MAAM,EACNC,SAAS,EAAEC,MAAM,EAAE,EACpB,GAAGH;QAEJ,MAAMI,kBAAkBvB,mBAAmBoB;QAE3C,MAAML;QAENS,IAAAA,6BAAiB,EAACD,gBAAgBE,OAAO,EAAEX;QAE3C,OAAQS,gBAAgBG,IAAI;YAC1B,KAAKC,0BAAgB,CAACC,MAAM;gBAC1B,OAAO,MAAMhB,uBAAuBU,QAAQC;YAC9C,KAAKI,0BAAgB,CAACE,KAAK;gBACzB,OAAO,MAAMhB,sBAAsBS,QAAQC;YAC7C;gBACE,MAAMO,oBAAS,CAACC,aAAa,CAAC;oBAC5BN,SAAS;gBACX;QACJ;IACF;AACF;AASO,SAASzB,mBAAmBoB,MAAe;IAChD,IAAI,CAACY,IAAAA,eAAQ,EAACZ,SAAS;QACrB,MAAMU,oBAAS,CAACC,aAAa,CAAC;YAC5BN,SAAS;QACX;IACF;IAEA,MAAM,EAAEC,IAAI,EAAED,OAAO,EAAE,GAAGL;IAE1B,IACE,CAACM,QACD,OAAOA,SAAS,YAChB,CAACV,OAAOiB,MAAM,CAACN,0BAAgB,EAAEO,QAAQ,CAACR,OAC1C;QACA,MAAMI,oBAAS,CAACC,aAAa,CAAC;YAC5BN,SAAS;QACX;IACF;IAEA,+DAA+D;IAC/D,IAAI,CAACA,WAAW,OAAOA,YAAY,YAAYA,QAAQU,MAAM,IAAI,IAAI;QACnE,MAAML,oBAAS,CAACC,aAAa,CAAC;YAC5BN,SACE;QACJ;IACF;IAEA,OAAOL;AACT"}
package/dist/cjs/utils.js DELETED
@@ -1,98 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- selectHooks: function() {
13
- return selectHooks;
14
- },
15
- deriveEntropy: function() {
16
- return deriveEntropy;
17
- },
18
- getPathPrefix: function() {
19
- return getPathPrefix;
20
- },
21
- getNode: function() {
22
- return getNode;
23
- }
24
- });
25
- const _keytree = require("@metamask/key-tree");
26
- const _utils = require("@metamask/utils");
27
- const _sha3 = require("@noble/hashes/sha3");
28
- const HARDENED_VALUE = 0x80000000;
29
- function selectHooks(hooks, hookNames) {
30
- if (hookNames) {
31
- return Object.keys(hookNames).reduce((hookSubset, _hookName)=>{
32
- const hookName = _hookName;
33
- hookSubset[hookName] = hooks[hookName];
34
- return hookSubset;
35
- }, {});
36
- }
37
- return undefined;
38
- }
39
- /**
40
- * Get a BIP-32 derivation path array from a hash, which is compatible with
41
- * `@metamask/key-tree`. The hash is assumed to be 32 bytes long.
42
- *
43
- * @param hash - The hash to derive indices from.
44
- * @returns The derived indices as a {@link HardenedBIP32Node} array.
45
- */ function getDerivationPathArray(hash) {
46
- const array = [];
47
- const view = (0, _utils.createDataView)(hash);
48
- for(let index = 0; index < 8; index++){
49
- const uint32 = view.getUint32(index * 4);
50
- // This is essentially `index | 0x80000000`. Because JavaScript numbers are
51
- // signed, we use the bitwise unsigned right shift operator to ensure that
52
- // the result is a positive number.
53
- // eslint-disable-next-line no-bitwise
54
- const pathIndex = (uint32 | HARDENED_VALUE) >>> 0;
55
- array.push(`bip32:${pathIndex - HARDENED_VALUE}'`);
56
- }
57
- return array;
58
- }
59
- async function deriveEntropy({ input, salt = '', mnemonicPhrase, magic }) {
60
- const inputBytes = (0, _utils.stringToBytes)(input);
61
- const saltBytes = (0, _utils.stringToBytes)(salt);
62
- // Get the derivation path from the snap ID.
63
- const hash = (0, _sha3.keccak_256)((0, _utils.concatBytes)([
64
- inputBytes,
65
- (0, _sha3.keccak_256)(saltBytes)
66
- ]));
67
- const computedDerivationPath = getDerivationPathArray(hash);
68
- // Derive the private key using BIP-32.
69
- const { privateKey } = await _keytree.SLIP10Node.fromDerivationPath({
70
- derivationPath: [
71
- mnemonicPhrase,
72
- `bip32:${magic}`,
73
- ...computedDerivationPath
74
- ],
75
- curve: 'secp256k1'
76
- });
77
- // This should never happen, but this keeps TypeScript happy.
78
- (0, _utils.assert)(privateKey, 'Failed to derive the entropy.');
79
- return (0, _utils.add0x)(privateKey);
80
- }
81
- function getPathPrefix(curve) {
82
- if (curve === 'secp256k1') {
83
- return 'bip32';
84
- }
85
- return 'slip10';
86
- }
87
- async function getNode({ curve, secretRecoveryPhrase, path }) {
88
- const prefix = getPathPrefix(curve);
89
- return await _keytree.SLIP10Node.fromDerivationPath({
90
- curve,
91
- derivationPath: [
92
- secretRecoveryPhrase,
93
- ...path.slice(1).map((index)=>`${prefix}:${index}`)
94
- ]
95
- });
96
- }
97
-
98
- //# sourceMappingURL=utils.js.map
@@ -1,40 +0,0 @@
1
- import { rpcErrors } from '@metamask/rpc-errors';
2
- /**
3
- * Create a generic permission validator that validates the presence of certain caveats.
4
- *
5
- * This validator only validates the types of the caveats, not the values.
6
- *
7
- * @param caveatsToValidate - A list of objects that represent caveats.
8
- * @param caveatsToValidate.type - The string defining the caveat type.
9
- * @param caveatsToValidate.optional - An optional boolean flag that defines
10
- * whether the caveat is optional or not.
11
- * @returns A function that validates a permission.
12
- */ export function createGenericPermissionValidator(caveatsToValidate) {
13
- const validCaveatTypes = new Set(caveatsToValidate.map((caveat)=>caveat.type));
14
- const requiredCaveats = caveatsToValidate.filter((caveat)=>!caveat.optional);
15
- return function({ caveats }) {
16
- const actualCaveats = caveats ?? [];
17
- const passedCaveatTypes = actualCaveats.map((caveat)=>caveat.type);
18
- const passedCaveatsSet = new Set(passedCaveatTypes);
19
- // Disallow duplicates
20
- if (passedCaveatsSet.size !== passedCaveatTypes.length) {
21
- throw rpcErrors.invalidParams({
22
- message: 'Duplicate caveats are not allowed.'
23
- });
24
- }
25
- // Disallow caveats that don't match expected types
26
- if (!actualCaveats.every((caveat)=>validCaveatTypes.has(caveat.type))) {
27
- throw rpcErrors.invalidParams({
28
- message: `Expected the following caveats: ${caveatsToValidate.map((caveat)=>`"${caveat.type}"`).join(', ')}, received ${actualCaveats.map((caveat)=>`"${caveat.type}"`).join(', ')}.`
29
- });
30
- }
31
- // Fail if not all required caveats are specified
32
- if (!requiredCaveats.every((caveat)=>passedCaveatsSet.has(caveat.type))) {
33
- throw rpcErrors.invalidParams({
34
- message: `Expected the following caveats: ${requiredCaveats.map((caveat)=>`"${caveat.type}"`).join(', ')}.`
35
- });
36
- }
37
- };
38
- }
39
-
40
- //# sourceMappingURL=generic.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/endowments/caveats/generic.ts"],"sourcesContent":["import type {\n PermissionConstraint,\n PermissionValidatorConstraint,\n} from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\n\nexport type CaveatMapperReturnValue = Pick<PermissionConstraint, 'caveats'>;\n\nexport type CaveatMapperFunction = (value: Json) => CaveatMapperReturnValue;\n\n/**\n * Create a generic permission validator that validates the presence of certain caveats.\n *\n * This validator only validates the types of the caveats, not the values.\n *\n * @param caveatsToValidate - A list of objects that represent caveats.\n * @param caveatsToValidate.type - The string defining the caveat type.\n * @param caveatsToValidate.optional - An optional boolean flag that defines\n * whether the caveat is optional or not.\n * @returns A function that validates a permission.\n */\nexport function createGenericPermissionValidator(\n caveatsToValidate: {\n type: string;\n optional?: boolean;\n }[],\n): PermissionValidatorConstraint {\n const validCaveatTypes = new Set(\n caveatsToValidate.map((caveat) => caveat.type),\n );\n const requiredCaveats = caveatsToValidate.filter(\n (caveat) => !caveat.optional,\n );\n\n return function ({ caveats }) {\n const actualCaveats = caveats ?? [];\n const passedCaveatTypes = actualCaveats.map((caveat) => caveat.type);\n const passedCaveatsSet = new Set(passedCaveatTypes);\n\n // Disallow duplicates\n if (passedCaveatsSet.size !== passedCaveatTypes.length) {\n throw rpcErrors.invalidParams({\n message: 'Duplicate caveats are not allowed.',\n });\n }\n\n // Disallow caveats that don't match expected types\n if (!actualCaveats.every((caveat) => validCaveatTypes.has(caveat.type))) {\n throw rpcErrors.invalidParams({\n message: `Expected the following caveats: ${caveatsToValidate\n .map((caveat) => `\"${caveat.type}\"`)\n .join(', ')}, received ${actualCaveats\n .map((caveat) => `\"${caveat.type}\"`)\n .join(', ')}.`,\n });\n }\n\n // Fail if not all required caveats are specified\n if (!requiredCaveats.every((caveat) => passedCaveatsSet.has(caveat.type))) {\n throw rpcErrors.invalidParams({\n message: `Expected the following caveats: ${requiredCaveats\n .map((caveat) => `\"${caveat.type}\"`)\n .join(', ')}.`,\n });\n }\n };\n}\n"],"names":["rpcErrors","createGenericPermissionValidator","caveatsToValidate","validCaveatTypes","Set","map","caveat","type","requiredCaveats","filter","optional","caveats","actualCaveats","passedCaveatTypes","passedCaveatsSet","size","length","invalidParams","message","every","has","join"],"mappings":"AAIA,SAASA,SAAS,QAAQ,uBAAuB;AAOjD;;;;;;;;;;CAUC,GACD,OAAO,SAASC,iCACdC,iBAGG;IAEH,MAAMC,mBAAmB,IAAIC,IAC3BF,kBAAkBG,GAAG,CAAC,CAACC,SAAWA,OAAOC,IAAI;IAE/C,MAAMC,kBAAkBN,kBAAkBO,MAAM,CAC9C,CAACH,SAAW,CAACA,OAAOI,QAAQ;IAG9B,OAAO,SAAU,EAAEC,OAAO,EAAE;QAC1B,MAAMC,gBAAgBD,WAAW,EAAE;QACnC,MAAME,oBAAoBD,cAAcP,GAAG,CAAC,CAACC,SAAWA,OAAOC,IAAI;QACnE,MAAMO,mBAAmB,IAAIV,IAAIS;QAEjC,sBAAsB;QACtB,IAAIC,iBAAiBC,IAAI,KAAKF,kBAAkBG,MAAM,EAAE;YACtD,MAAMhB,UAAUiB,aAAa,CAAC;gBAC5BC,SAAS;YACX;QACF;QAEA,mDAAmD;QACnD,IAAI,CAACN,cAAcO,KAAK,CAAC,CAACb,SAAWH,iBAAiBiB,GAAG,CAACd,OAAOC,IAAI,IAAI;YACvE,MAAMP,UAAUiB,aAAa,CAAC;gBAC5BC,SAAS,CAAC,gCAAgC,EAAEhB,kBACzCG,GAAG,CAAC,CAACC,SAAW,CAAC,CAAC,EAAEA,OAAOC,IAAI,CAAC,CAAC,CAAC,EAClCc,IAAI,CAAC,MAAM,WAAW,EAAET,cACxBP,GAAG,CAAC,CAACC,SAAW,CAAC,CAAC,EAAEA,OAAOC,IAAI,CAAC,CAAC,CAAC,EAClCc,IAAI,CAAC,MAAM,CAAC,CAAC;YAClB;QACF;QAEA,iDAAiD;QACjD,IAAI,CAACb,gBAAgBW,KAAK,CAAC,CAACb,SAAWQ,iBAAiBM,GAAG,CAACd,OAAOC,IAAI,IAAI;YACzE,MAAMP,UAAUiB,aAAa,CAAC;gBAC5BC,SAAS,CAAC,gCAAgC,EAAEV,gBACzCH,GAAG,CAAC,CAACC,SAAW,CAAC,CAAC,EAAEA,OAAOC,IAAI,CAAC,CAAC,CAAC,EAClCc,IAAI,CAAC,MAAM,CAAC,CAAC;YAClB;QACF;IACF;AACF"}
@@ -1,4 +0,0 @@
1
- export * from './generic';
2
- export * from './requestTime';
3
-
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/endowments/caveats/index.ts"],"sourcesContent":["export * from './generic';\nexport * from './requestTime';\n"],"names":[],"mappings":"AAAA,cAAc,YAAY;AAC1B,cAAc,gBAAgB"}
@@ -1,93 +0,0 @@
1
- import { rpcErrors } from '@metamask/rpc-errors';
2
- import { MaxRequestTimeStruct, SnapCaveatType } from '@metamask/snaps-utils';
3
- import { assertStruct, hasProperty, isObject } from '@metamask/utils';
4
- /**
5
- * Asserts that the given value is a valid `maxRequestTime` value.
6
- *
7
- * @param value - The value to assert.
8
- * @param ErrorWrapper - An optional error wrapper to use. Defaults to
9
- * {@link AssertionError}.
10
- * @throws If the value is not a valid `maxRequestTime` value.
11
- */ function assertIsMaxRequestTime(value, ErrorWrapper) {
12
- assertStruct(value, MaxRequestTimeStruct, 'Invalid maxRequestTime', ErrorWrapper);
13
- }
14
- /**
15
- * Validate the value of a caveat. This does not validate the type of the
16
- * caveat itself, only the value of the caveat.
17
- *
18
- * @param caveat - The caveat to validate.
19
- * @throws If the caveat value is invalid.
20
- */ function validateMaxRequestTimeCaveat(caveat) {
21
- if (!hasProperty(caveat, 'value')) {
22
- throw rpcErrors.invalidParams({
23
- message: 'Invalid maxRequestTime caveat.'
24
- });
25
- }
26
- const { value } = caveat;
27
- assertIsMaxRequestTime(value, rpcErrors.invalidParams);
28
- }
29
- /**
30
- * Map a raw value from the `initialPermissions` to a caveat specification.
31
- * Note that this function does not do any validation, that's handled by the
32
- * PermissionsController when the permission is requested.
33
- *
34
- * @param value - The raw value from the `initialPermissions`.
35
- * @returns The caveat specification.
36
- */ export function getMaxRequestTimeCaveatMapper(value) {
37
- if (!value || !isObject(value) || isObject(value) && !hasProperty(value, 'maxRequestTime')) {
38
- return {
39
- caveats: null
40
- };
41
- }
42
- return {
43
- caveats: [
44
- {
45
- type: SnapCaveatType.MaxRequestTime,
46
- value: value.maxRequestTime
47
- }
48
- ]
49
- };
50
- }
51
- /**
52
- * Creates a wrapping caveat mapper that creates the `maxRequestTime` caveat
53
- * and merges it with any other caveats created by the mapper function.
54
- *
55
- * @param mapper - Another caveat mapper function.
56
- * @returns The caveat specification.
57
- */ export function createMaxRequestTimeMapper(mapper) {
58
- return function(value) {
59
- // We assume this to be used only with caveats of this type
60
- const { maxRequestTime, ...rest } = value;
61
- const mapperResult = mapper(rest);
62
- if (!maxRequestTime) {
63
- return mapperResult;
64
- }
65
- return {
66
- ...mapperResult,
67
- caveats: [
68
- ...mapperResult.caveats ?? [],
69
- {
70
- type: SnapCaveatType.MaxRequestTime,
71
- value: maxRequestTime
72
- }
73
- ]
74
- };
75
- };
76
- }
77
- /**
78
- * Getter function to get the {@link MaxRequestTime} caveat value from a permission if specified.
79
- *
80
- * @param permission - The permission to get the caveat value from.
81
- * @returns The caveat value if present, otherwise null.
82
- */ export function getMaxRequestTimeCaveat(permission) {
83
- const foundCaveat = permission?.caveats?.find((caveat)=>caveat.type === SnapCaveatType.MaxRequestTime);
84
- return (foundCaveat?.value) ?? null;
85
- }
86
- export const maxRequestTimeCaveatSpecifications = {
87
- [SnapCaveatType.MaxRequestTime]: Object.freeze({
88
- type: SnapCaveatType.MaxRequestTime,
89
- validator: (caveat)=>validateMaxRequestTimeCaveat(caveat)
90
- })
91
- };
92
-
93
- //# sourceMappingURL=requestTime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/endowments/caveats/requestTime.ts"],"sourcesContent":["import type {\n Caveat,\n CaveatSpecificationConstraint,\n PermissionConstraint,\n} from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { MaxRequestTimeStruct, SnapCaveatType } from '@metamask/snaps-utils';\nimport type { AssertionErrorConstructor, Json } from '@metamask/utils';\nimport { assertStruct, hasProperty, isObject } from '@metamask/utils';\n\nimport type { CaveatMapperFunction, CaveatMapperReturnValue } from './generic';\n\n/**\n * Asserts that the given value is a valid `maxRequestTime` value.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid `maxRequestTime` value.\n */\nfunction assertIsMaxRequestTime(\n value: unknown, // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is number {\n assertStruct(\n value,\n MaxRequestTimeStruct,\n 'Invalid maxRequestTime',\n ErrorWrapper,\n );\n}\n\n/**\n * Validate the value of a caveat. This does not validate the type of the\n * caveat itself, only the value of the caveat.\n *\n * @param caveat - The caveat to validate.\n * @throws If the caveat value is invalid.\n */\nfunction validateMaxRequestTimeCaveat(caveat: Caveat<string, any>) {\n if (!hasProperty(caveat, 'value')) {\n throw rpcErrors.invalidParams({\n message: 'Invalid maxRequestTime caveat.',\n });\n }\n\n const { value } = caveat;\n assertIsMaxRequestTime(value, rpcErrors.invalidParams);\n}\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionsController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function getMaxRequestTimeCaveatMapper(\n value: Json,\n): CaveatMapperReturnValue {\n if (\n !value ||\n !isObject(value) ||\n (isObject(value) && !hasProperty(value, 'maxRequestTime'))\n ) {\n return { caveats: null };\n }\n return {\n caveats: [\n {\n type: SnapCaveatType.MaxRequestTime,\n value: value.maxRequestTime,\n },\n ],\n };\n}\n\n/**\n * Creates a wrapping caveat mapper that creates the `maxRequestTime` caveat\n * and merges it with any other caveats created by the mapper function.\n *\n * @param mapper - Another caveat mapper function.\n * @returns The caveat specification.\n */\nexport function createMaxRequestTimeMapper(\n mapper: CaveatMapperFunction,\n): CaveatMapperFunction {\n return function (value: Json) {\n // We assume this to be used only with caveats of this type\n const { maxRequestTime, ...rest } = value as Record<string, Json>;\n\n const mapperResult = mapper(rest);\n\n if (!maxRequestTime) {\n return mapperResult;\n }\n\n return {\n ...mapperResult,\n caveats: [\n ...(mapperResult.caveats ?? []),\n {\n type: SnapCaveatType.MaxRequestTime,\n value: maxRequestTime,\n },\n ],\n };\n };\n}\n\n/**\n * Getter function to get the {@link MaxRequestTime} caveat value from a permission if specified.\n *\n * @param permission - The permission to get the caveat value from.\n * @returns The caveat value if present, otherwise null.\n */\nexport function getMaxRequestTimeCaveat(\n permission?: PermissionConstraint,\n): number | null {\n const foundCaveat = permission?.caveats?.find(\n (caveat) => caveat.type === SnapCaveatType.MaxRequestTime,\n );\n return (foundCaveat?.value as number) ?? null;\n}\n\nexport const maxRequestTimeCaveatSpecifications: Record<\n SnapCaveatType.MaxRequestTime,\n CaveatSpecificationConstraint\n> = {\n [SnapCaveatType.MaxRequestTime]: Object.freeze({\n type: SnapCaveatType.MaxRequestTime,\n validator: (caveat: Caveat<string, any>) =>\n validateMaxRequestTimeCaveat(caveat),\n }),\n};\n"],"names":["rpcErrors","MaxRequestTimeStruct","SnapCaveatType","assertStruct","hasProperty","isObject","assertIsMaxRequestTime","value","ErrorWrapper","validateMaxRequestTimeCaveat","caveat","invalidParams","message","getMaxRequestTimeCaveatMapper","caveats","type","MaxRequestTime","maxRequestTime","createMaxRequestTimeMapper","mapper","rest","mapperResult","getMaxRequestTimeCaveat","permission","foundCaveat","find","maxRequestTimeCaveatSpecifications","Object","freeze","validator"],"mappings":"AAKA,SAASA,SAAS,QAAQ,uBAAuB;AACjD,SAASC,oBAAoB,EAAEC,cAAc,QAAQ,wBAAwB;AAE7E,SAASC,YAAY,EAAEC,WAAW,EAAEC,QAAQ,QAAQ,kBAAkB;AAItE;;;;;;;CAOC,GACD,SAASC,uBACPC,KAAc,EACdC,YAAwC;IAExCL,aACEI,OACAN,sBACA,0BACAO;AAEJ;AAEA;;;;;;CAMC,GACD,SAASC,6BAA6BC,MAA2B;IAC/D,IAAI,CAACN,YAAYM,QAAQ,UAAU;QACjC,MAAMV,UAAUW,aAAa,CAAC;YAC5BC,SAAS;QACX;IACF;IAEA,MAAM,EAAEL,KAAK,EAAE,GAAGG;IAClBJ,uBAAuBC,OAAOP,UAAUW,aAAa;AACvD;AAEA;;;;;;;CAOC,GACD,OAAO,SAASE,8BACdN,KAAW;IAEX,IACE,CAACA,SACD,CAACF,SAASE,UACTF,SAASE,UAAU,CAACH,YAAYG,OAAO,mBACxC;QACA,OAAO;YAAEO,SAAS;QAAK;IACzB;IACA,OAAO;QACLA,SAAS;YACP;gBACEC,MAAMb,eAAec,cAAc;gBACnCT,OAAOA,MAAMU,cAAc;YAC7B;SACD;IACH;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,2BACdC,MAA4B;IAE5B,OAAO,SAAUZ,KAAW;QAC1B,2DAA2D;QAC3D,MAAM,EAAEU,cAAc,EAAE,GAAGG,MAAM,GAAGb;QAEpC,MAAMc,eAAeF,OAAOC;QAE5B,IAAI,CAACH,gBAAgB;YACnB,OAAOI;QACT;QAEA,OAAO;YACL,GAAGA,YAAY;YACfP,SAAS;mBACHO,aAAaP,OAAO,IAAI,EAAE;gBAC9B;oBACEC,MAAMb,eAAec,cAAc;oBACnCT,OAAOU;gBACT;aACD;QACH;IACF;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASK,wBACdC,UAAiC;IAEjC,MAAMC,cAAcD,YAAYT,SAASW,KACvC,CAACf,SAAWA,OAAOK,IAAI,KAAKb,eAAec,cAAc;IAE3D,OAAO,CAACQ,aAAajB,KAAe,KAAK;AAC3C;AAEA,OAAO,MAAMmB,qCAGT;IACF,CAACxB,eAAec,cAAc,CAAC,EAAEW,OAAOC,MAAM,CAAC;QAC7Cb,MAAMb,eAAec,cAAc;QACnCa,WAAW,CAACnB,SACVD,6BAA6BC;IACjC;AACF,EAAE"}
@@ -1,99 +0,0 @@
1
- import { PermissionType, SubjectType } from '@metamask/permission-controller';
2
- import { rpcErrors } from '@metamask/rpc-errors';
3
- import { SnapCaveatType, isCronjobSpecificationArray } from '@metamask/snaps-utils';
4
- import { assert, hasProperty, isPlainObject } from '@metamask/utils';
5
- import { SnapEndowments } from './enum';
6
- const permissionName = SnapEndowments.Cronjob;
7
- /**
8
- * `endowment:cronjob` returns nothing; it is intended to be used as a flag to determine whether the snap wants to run cronjobs.
9
- *
10
- * @param _builderOptions - Optional specification builder options.
11
- * @returns The specification for the cronjob endowment.
12
- */ const specificationBuilder = (_builderOptions)=>{
13
- return {
14
- permissionType: PermissionType.Endowment,
15
- targetName: permissionName,
16
- allowedCaveats: [
17
- SnapCaveatType.SnapCronjob
18
- ],
19
- endowmentGetter: (_getterOptions)=>undefined,
20
- subjectTypes: [
21
- SubjectType.Snap
22
- ]
23
- };
24
- };
25
- export const cronjobEndowmentBuilder = Object.freeze({
26
- targetName: permissionName,
27
- specificationBuilder
28
- });
29
- /**
30
- * Map a raw value from the `initialPermissions` to a caveat specification.
31
- * Note that this function does not do any validation, that's handled by the
32
- * PermissionsController when the permission is requested.
33
- *
34
- * @param value - The raw value from the `initialPermissions`.
35
- * @returns The caveat specification.
36
- */ export function getCronjobCaveatMapper(value) {
37
- return {
38
- caveats: [
39
- {
40
- type: SnapCaveatType.SnapCronjob,
41
- value
42
- }
43
- ]
44
- };
45
- }
46
- /**
47
- * Getter function to get the cronjobs from a permission.
48
- *
49
- * This does basic validation of the caveat, but does not validate the type or
50
- * value of the namespaces object itself, as this is handled by the
51
- * `PermissionsController` when the permission is requested.
52
- *
53
- * @param permission - The permission to get the keyring namespaces from.
54
- * @returns The cronjobs, or `null` if the permission does not have a
55
- * cronjob caveat.
56
- */ export function getCronjobCaveatJobs(permission) {
57
- if (!permission?.caveats) {
58
- return null;
59
- }
60
- assert(permission.caveats.length === 1);
61
- assert(permission.caveats[0].type === SnapCaveatType.SnapCronjob);
62
- const caveat = permission.caveats[0];
63
- return (caveat.value?.jobs) ?? null;
64
- }
65
- /**
66
- * Validate the cronjob specification values associated with a caveat.
67
- * This validates that the value is a non-empty array with valid
68
- * cronjob expression and request object.
69
- *
70
- * @param caveat - The caveat to validate.
71
- * @throws If the value is invalid.
72
- */ export function validateCronjobCaveat(caveat) {
73
- if (!hasProperty(caveat, 'value') || !isPlainObject(caveat.value)) {
74
- throw rpcErrors.invalidParams({
75
- message: 'Expected a plain object.'
76
- });
77
- }
78
- const { value } = caveat;
79
- if (!hasProperty(value, 'jobs') || !isPlainObject(value)) {
80
- throw rpcErrors.invalidParams({
81
- message: 'Expected a plain object.'
82
- });
83
- }
84
- if (!isCronjobSpecificationArray(value.jobs)) {
85
- throw rpcErrors.invalidParams({
86
- message: 'Expected a valid cronjob specification array.'
87
- });
88
- }
89
- }
90
- /**
91
- * Caveat specification for the Cronjob.
92
- */ export const cronjobCaveatSpecifications = {
93
- [SnapCaveatType.SnapCronjob]: Object.freeze({
94
- type: SnapCaveatType.SnapCronjob,
95
- validator: (caveat)=>validateCronjobCaveat(caveat)
96
- })
97
- };
98
-
99
- //# sourceMappingURL=cronjob.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/endowments/cronjob.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionConstraint,\n Caveat,\n CaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { CronjobSpecification } from '@metamask/snaps-utils';\nimport {\n SnapCaveatType,\n isCronjobSpecificationArray,\n} from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { assert, hasProperty, isPlainObject } from '@metamask/utils';\n\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.Cronjob;\n\ntype CronjobEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (_options?: any) => undefined;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * `endowment:cronjob` returns nothing; it is intended to be used as a flag to determine whether the snap wants to run cronjobs.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the cronjob endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n CronjobEndowmentSpecification\n> = (_builderOptions?: any) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: [SnapCaveatType.SnapCronjob],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => undefined,\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const cronjobEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionsController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function getCronjobCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.SnapCronjob,\n value,\n },\n ],\n };\n}\n\n/**\n * Getter function to get the cronjobs from a permission.\n *\n * This does basic validation of the caveat, but does not validate the type or\n * value of the namespaces object itself, as this is handled by the\n * `PermissionsController` when the permission is requested.\n *\n * @param permission - The permission to get the keyring namespaces from.\n * @returns The cronjobs, or `null` if the permission does not have a\n * cronjob caveat.\n */\nexport function getCronjobCaveatJobs(\n permission?: PermissionConstraint,\n): CronjobSpecification[] | null {\n if (!permission?.caveats) {\n return null;\n }\n\n assert(permission.caveats.length === 1);\n assert(permission.caveats[0].type === SnapCaveatType.SnapCronjob);\n\n const caveat = permission.caveats[0] as Caveat<string, { jobs: Json[] }>;\n\n return (caveat.value?.jobs as CronjobSpecification[]) ?? null;\n}\n\n/**\n * Validate the cronjob specification values associated with a caveat.\n * This validates that the value is a non-empty array with valid\n * cronjob expression and request object.\n *\n * @param caveat - The caveat to validate.\n * @throws If the value is invalid.\n */\nexport function validateCronjobCaveat(caveat: Caveat<string, any>) {\n if (!hasProperty(caveat, 'value') || !isPlainObject(caveat.value)) {\n throw rpcErrors.invalidParams({\n message: 'Expected a plain object.',\n });\n }\n\n const { value } = caveat;\n\n if (!hasProperty(value, 'jobs') || !isPlainObject(value)) {\n throw rpcErrors.invalidParams({\n message: 'Expected a plain object.',\n });\n }\n\n if (!isCronjobSpecificationArray(value.jobs)) {\n throw rpcErrors.invalidParams({\n message: 'Expected a valid cronjob specification array.',\n });\n }\n}\n\n/**\n * Caveat specification for the Cronjob.\n */\nexport const cronjobCaveatSpecifications: Record<\n SnapCaveatType.SnapCronjob,\n CaveatSpecificationConstraint\n> = {\n [SnapCaveatType.SnapCronjob]: Object.freeze({\n type: SnapCaveatType.SnapCronjob,\n validator: (caveat) => validateCronjobCaveat(caveat),\n }),\n};\n"],"names":["PermissionType","SubjectType","rpcErrors","SnapCaveatType","isCronjobSpecificationArray","assert","hasProperty","isPlainObject","SnapEndowments","permissionName","Cronjob","specificationBuilder","_builderOptions","permissionType","Endowment","targetName","allowedCaveats","SnapCronjob","endowmentGetter","_getterOptions","undefined","subjectTypes","Snap","cronjobEndowmentBuilder","Object","freeze","getCronjobCaveatMapper","value","caveats","type","getCronjobCaveatJobs","permission","length","caveat","jobs","validateCronjobCaveat","invalidParams","message","cronjobCaveatSpecifications","validator"],"mappings":"AAQA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AAEjD,SACEC,cAAc,EACdC,2BAA2B,QACtB,wBAAwB;AAE/B,SAASC,MAAM,EAAEC,WAAW,EAAEC,aAAa,QAAQ,kBAAkB;AAErE,SAASC,cAAc,QAAQ,SAAS;AAExC,MAAMC,iBAAiBD,eAAeE,OAAO;AAS7C;;;;;CAKC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBb,eAAec,SAAS;QACxCC,YAAYN;QACZO,gBAAgB;YAACb,eAAec,WAAW;SAAC;QAC5CC,iBAAiB,CAACC,iBAA2CC;QAC7DC,cAAc;YAACpB,YAAYqB,IAAI;SAAC;IAClC;AACF;AAEA,OAAO,MAAMC,0BAA0BC,OAAOC,MAAM,CAAC;IACnDV,YAAYN;IACZE;AACF,GAAY;AAEZ;;;;;;;CAOC,GACD,OAAO,SAASe,uBACdC,KAAW;IAEX,OAAO;QACLC,SAAS;YACP;gBACEC,MAAM1B,eAAec,WAAW;gBAChCU;YACF;SACD;IACH;AACF;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASG,qBACdC,UAAiC;IAEjC,IAAI,CAACA,YAAYH,SAAS;QACxB,OAAO;IACT;IAEAvB,OAAO0B,WAAWH,OAAO,CAACI,MAAM,KAAK;IACrC3B,OAAO0B,WAAWH,OAAO,CAAC,EAAE,CAACC,IAAI,KAAK1B,eAAec,WAAW;IAEhE,MAAMgB,SAASF,WAAWH,OAAO,CAAC,EAAE;IAEpC,OAAO,CAACK,OAAON,KAAK,EAAEO,IAA8B,KAAK;AAC3D;AAEA;;;;;;;CAOC,GACD,OAAO,SAASC,sBAAsBF,MAA2B;IAC/D,IAAI,CAAC3B,YAAY2B,QAAQ,YAAY,CAAC1B,cAAc0B,OAAON,KAAK,GAAG;QACjE,MAAMzB,UAAUkC,aAAa,CAAC;YAC5BC,SAAS;QACX;IACF;IAEA,MAAM,EAAEV,KAAK,EAAE,GAAGM;IAElB,IAAI,CAAC3B,YAAYqB,OAAO,WAAW,CAACpB,cAAcoB,QAAQ;QACxD,MAAMzB,UAAUkC,aAAa,CAAC;YAC5BC,SAAS;QACX;IACF;IAEA,IAAI,CAACjC,4BAA4BuB,MAAMO,IAAI,GAAG;QAC5C,MAAMhC,UAAUkC,aAAa,CAAC;YAC5BC,SAAS;QACX;IACF;AACF;AAEA;;CAEC,GACD,OAAO,MAAMC,8BAGT;IACF,CAACnC,eAAec,WAAW,CAAC,EAAEO,OAAOC,MAAM,CAAC;QAC1CI,MAAM1B,eAAec,WAAW;QAChCsB,WAAW,CAACN,SAAWE,sBAAsBF;IAC/C;AACF,EAAE"}
@@ -1,16 +0,0 @@
1
- export var SnapEndowments;
2
- (function(SnapEndowments) {
3
- SnapEndowments["NetworkAccess"] = 'endowment:network-access';
4
- SnapEndowments["SignatureInsight"] = 'endowment:signature-insight';
5
- SnapEndowments["TransactionInsight"] = 'endowment:transaction-insight';
6
- SnapEndowments["Cronjob"] = 'endowment:cronjob';
7
- SnapEndowments["EthereumProvider"] = 'endowment:ethereum-provider';
8
- SnapEndowments["Rpc"] = 'endowment:rpc';
9
- SnapEndowments["WebAssemblyAccess"] = 'endowment:webassembly';
10
- SnapEndowments["NameLookup"] = 'endowment:name-lookup';
11
- SnapEndowments["LifecycleHooks"] = 'endowment:lifecycle-hooks';
12
- SnapEndowments["Keyring"] = 'endowment:keyring';
13
- SnapEndowments["HomePage"] = 'endowment:page-home';
14
- })(SnapEndowments || (SnapEndowments = {}));
15
-
16
- //# sourceMappingURL=enum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/endowments/enum.ts"],"sourcesContent":["export enum SnapEndowments {\n NetworkAccess = 'endowment:network-access',\n SignatureInsight = 'endowment:signature-insight',\n TransactionInsight = 'endowment:transaction-insight',\n Cronjob = 'endowment:cronjob',\n EthereumProvider = 'endowment:ethereum-provider',\n Rpc = 'endowment:rpc',\n WebAssemblyAccess = 'endowment:webassembly',\n NameLookup = 'endowment:name-lookup',\n LifecycleHooks = 'endowment:lifecycle-hooks',\n Keyring = 'endowment:keyring',\n HomePage = 'endowment:page-home',\n}\n"],"names":["SnapEndowments","NetworkAccess","SignatureInsight","TransactionInsight","Cronjob","EthereumProvider","Rpc","WebAssemblyAccess","NameLookup","LifecycleHooks","Keyring","HomePage"],"mappings":"WAAO;UAAKA,cAAc;IAAdA,eACVC,mBAAgB;IADND,eAEVE,sBAAmB;IAFTF,eAGVG,wBAAqB;IAHXH,eAIVI,aAAU;IAJAJ,eAKVK,sBAAmB;IALTL,eAMVM,SAAM;IANIN,eAOVO,uBAAoB;IAPVP,eAQVQ,gBAAa;IARHR,eASVS,oBAAiB;IATPT,eAUVU,aAAU;IAVAV,eAWVW,cAAW;GAXDX,mBAAAA"}
@@ -1,33 +0,0 @@
1
- import { PermissionType, SubjectType } from '@metamask/permission-controller';
2
- import { SnapEndowments } from './enum';
3
- const permissionName = SnapEndowments.EthereumProvider;
4
- /**
5
- * `endowment:ethereum-provider` returns the name of the ethereum global browser API.
6
- * This is intended to populate the endowments of the
7
- * SES Compartment in which a Snap executes.
8
- *
9
- * This populates the global scope with an EIP-1193 provider, which DOES NOT implement all legacy functionality exposed to dapps.
10
- *
11
- * @param _builderOptions - Optional specification builder options.
12
- * @returns The specification for the network endowment.
13
- */ const specificationBuilder = (_builderOptions)=>{
14
- return {
15
- permissionType: PermissionType.Endowment,
16
- targetName: permissionName,
17
- allowedCaveats: null,
18
- endowmentGetter: (_getterOptions)=>{
19
- return [
20
- 'ethereum'
21
- ];
22
- },
23
- subjectTypes: [
24
- SubjectType.Snap
25
- ]
26
- };
27
- };
28
- export const ethereumProviderEndowmentBuilder = Object.freeze({
29
- targetName: permissionName,
30
- specificationBuilder
31
- });
32
-
33
- //# sourceMappingURL=ethereum-provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/endowments/ethereum-provider.ts"],"sourcesContent":["import type {\n EndowmentGetterParams,\n PermissionSpecificationBuilder,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\n\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.EthereumProvider;\n\ntype EthereumProviderEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (_options?: any) => ['ethereum'];\n allowedCaveats: null;\n}>;\n\n/**\n * `endowment:ethereum-provider` returns the name of the ethereum global browser API.\n * This is intended to populate the endowments of the\n * SES Compartment in which a Snap executes.\n *\n * This populates the global scope with an EIP-1193 provider, which DOES NOT implement all legacy functionality exposed to dapps.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the network endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n EthereumProviderEndowmentSpecification\n> = (_builderOptions?: any) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: null,\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => {\n return ['ethereum'];\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const ethereumProviderEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n"],"names":["PermissionType","SubjectType","SnapEndowments","permissionName","EthereumProvider","specificationBuilder","_builderOptions","permissionType","Endowment","targetName","allowedCaveats","endowmentGetter","_getterOptions","subjectTypes","Snap","ethereumProviderEndowmentBuilder","Object","freeze"],"mappings":"AAKA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAE9E,SAASC,cAAc,QAAQ,SAAS;AAExC,MAAMC,iBAAiBD,eAAeE,gBAAgB;AAStD;;;;;;;;;CASC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBP,eAAeQ,SAAS;QACxCC,YAAYN;QACZO,gBAAgB;QAChBC,iBAAiB,CAACC;YAChB,OAAO;gBAAC;aAAW;QACrB;QACAC,cAAc;YAACZ,YAAYa,IAAI;SAAC;IAClC;AACF;AAEA,OAAO,MAAMC,mCAAmCC,OAAOC,MAAM,CAAC;IAC5DR,YAAYN;IACZE;AACF,GAAY"}
@@ -1,27 +0,0 @@
1
- import { PermissionType, SubjectType } from '@metamask/permission-controller';
2
- import { SnapEndowments } from './enum';
3
- const permissionName = SnapEndowments.HomePage;
4
- /**
5
- * `endowment:page-home` returns nothing; it is intended to be used as a
6
- * flag by the snap controller to detect whether the snap has the capability to
7
- * use the snap home page feature.
8
- *
9
- * @param _builderOptions - Optional specification builder options.
10
- * @returns The specification for the `snap-pages` endowment.
11
- */ const specificationBuilder = (_builderOptions)=>{
12
- return {
13
- permissionType: PermissionType.Endowment,
14
- targetName: permissionName,
15
- allowedCaveats: null,
16
- endowmentGetter: (_getterOptions)=>undefined,
17
- subjectTypes: [
18
- SubjectType.Snap
19
- ]
20
- };
21
- };
22
- export const homePageEndowmentBuilder = Object.freeze({
23
- targetName: permissionName,
24
- specificationBuilder
25
- });
26
-
27
- //# sourceMappingURL=home-page.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/endowments/home-page.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport type { NonEmptyArray } from '@metamask/utils';\n\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.HomePage;\n\ntype HomePageEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => undefined;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * `endowment:page-home` returns nothing; it is intended to be used as a\n * flag by the snap controller to detect whether the snap has the capability to\n * use the snap home page feature.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the `snap-pages` endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n HomePageEndowmentSpecification\n> = (_builderOptions?: unknown) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: null,\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => undefined,\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const homePageEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n"],"names":["PermissionType","SubjectType","SnapEndowments","permissionName","HomePage","specificationBuilder","_builderOptions","permissionType","Endowment","targetName","allowedCaveats","endowmentGetter","_getterOptions","undefined","subjectTypes","Snap","homePageEndowmentBuilder","Object","freeze"],"mappings":"AAKA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAG9E,SAASC,cAAc,QAAQ,SAAS;AAExC,MAAMC,iBAAiBD,eAAeE,QAAQ;AAS9C;;;;;;;CAOC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBP,eAAeQ,SAAS;QACxCC,YAAYN;QACZO,gBAAgB;QAChBC,iBAAiB,CAACC,iBAA2CC;QAC7DC,cAAc;YAACb,YAAYc,IAAI;SAAC;IAClC;AACF;AAEA,OAAO,MAAMC,2BAA2BC,OAAOC,MAAM,CAAC;IACpDT,YAAYN;IACZE;AACF,GAAY"}