@metamask/snaps-rpc-methods 6.0.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (559) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/dist/chunk-2A5M65V3.js +21 -0
  3. package/dist/chunk-2A5M65V3.js.map +1 -0
  4. package/dist/chunk-2IL6T3EX.js +18 -0
  5. package/dist/chunk-2IL6T3EX.js.map +1 -0
  6. package/dist/chunk-2N2PZJDJ.mjs +105 -0
  7. package/dist/chunk-2N2PZJDJ.mjs.map +1 -0
  8. package/dist/chunk-2QEA2YZM.mjs +23 -0
  9. package/dist/chunk-2QEA2YZM.mjs.map +1 -0
  10. package/dist/chunk-2TYDIMR6.js +78 -0
  11. package/dist/chunk-2TYDIMR6.js.map +1 -0
  12. package/dist/chunk-2WCLK3LN.mjs +115 -0
  13. package/dist/chunk-2WCLK3LN.mjs.map +1 -0
  14. package/dist/chunk-3CSLIOIY.mjs +43 -0
  15. package/dist/chunk-3CSLIOIY.mjs.map +1 -0
  16. package/dist/chunk-3DWRS3YG.mjs +49 -0
  17. package/dist/chunk-3DWRS3YG.mjs.map +1 -0
  18. package/dist/chunk-3FKD2O7M.js +151 -0
  19. package/dist/chunk-3FKD2O7M.js.map +1 -0
  20. package/dist/chunk-4ALFLY5D.js +105 -0
  21. package/dist/chunk-4ALFLY5D.js.map +1 -0
  22. package/dist/chunk-4Z4X6EJP.mjs +67 -0
  23. package/dist/chunk-4Z4X6EJP.mjs.map +1 -0
  24. package/dist/chunk-5HIIIAIS.mjs +57 -0
  25. package/dist/chunk-5HIIIAIS.mjs.map +1 -0
  26. package/dist/chunk-632BZ6JY.js +83 -0
  27. package/dist/{cjs/utils.js.map → chunk-632BZ6JY.js.map} +1 -1
  28. package/dist/chunk-6DUTJBD2.mjs +82 -0
  29. package/dist/chunk-6DUTJBD2.mjs.map +1 -0
  30. package/dist/chunk-6PXDUIXN.js +67 -0
  31. package/dist/chunk-6PXDUIXN.js.map +1 -0
  32. package/dist/chunk-72V4CPGO.mjs +23 -0
  33. package/dist/chunk-72V4CPGO.mjs.map +1 -0
  34. package/dist/chunk-7O63CIBT.js +42 -0
  35. package/dist/chunk-7O63CIBT.js.map +1 -0
  36. package/dist/chunk-ABFJRV6Q.js +68 -0
  37. package/dist/chunk-ABFJRV6Q.js.map +1 -0
  38. package/dist/chunk-BZIPLSKM.mjs +39 -0
  39. package/dist/chunk-BZIPLSKM.mjs.map +1 -0
  40. package/dist/chunk-CIIMO4C2.js +45 -0
  41. package/dist/chunk-CIIMO4C2.js.map +1 -0
  42. package/dist/chunk-DBYI25UR.js +23 -0
  43. package/dist/chunk-DBYI25UR.js.map +1 -0
  44. package/dist/chunk-DDGDVWAW.js +45 -0
  45. package/dist/chunk-DDGDVWAW.js.map +1 -0
  46. package/dist/chunk-DR63Z4PV.mjs +83 -0
  47. package/dist/chunk-DR63Z4PV.mjs.map +1 -0
  48. package/dist/chunk-E2G25QVG.js +119 -0
  49. package/dist/chunk-E2G25QVG.js.map +1 -0
  50. package/dist/chunk-E4HGQWSS.js +43 -0
  51. package/dist/chunk-E4HGQWSS.js.map +1 -0
  52. package/dist/chunk-EAL6AH74.js +67 -0
  53. package/dist/chunk-EAL6AH74.js.map +1 -0
  54. package/dist/chunk-EB6OXVFN.mjs +52 -0
  55. package/dist/chunk-EB6OXVFN.mjs.map +1 -0
  56. package/dist/chunk-EKB7QNFO.mjs +54 -0
  57. package/dist/chunk-EKB7QNFO.mjs.map +1 -0
  58. package/dist/chunk-EPNGNDRH.mjs +80 -0
  59. package/dist/chunk-EPNGNDRH.mjs.map +1 -0
  60. package/dist/chunk-F5BEVZOB.js +47 -0
  61. package/dist/chunk-F5BEVZOB.js.map +1 -0
  62. package/dist/chunk-FMUQOZIO.js +57 -0
  63. package/dist/chunk-FMUQOZIO.js.map +1 -0
  64. package/dist/chunk-H45CGE4Z.js +23 -0
  65. package/dist/chunk-H45CGE4Z.js.map +1 -0
  66. package/dist/chunk-HIYXSQ6K.mjs +188 -0
  67. package/dist/chunk-HIYXSQ6K.mjs.map +1 -0
  68. package/dist/chunk-HLF4WCE4.mjs +20 -0
  69. package/dist/chunk-HLF4WCE4.mjs.map +1 -0
  70. package/dist/chunk-HODDBRLQ.js +75 -0
  71. package/dist/chunk-HODDBRLQ.js.map +1 -0
  72. package/dist/chunk-HOXOD5RL.mjs +68 -0
  73. package/dist/chunk-HOXOD5RL.mjs.map +1 -0
  74. package/dist/chunk-I5H5ZZRC.js +80 -0
  75. package/dist/chunk-I5H5ZZRC.js.map +1 -0
  76. package/dist/chunk-IDRDPYAN.js +70 -0
  77. package/dist/chunk-IDRDPYAN.js.map +1 -0
  78. package/dist/chunk-JEEKFTAL.mjs +59 -0
  79. package/dist/chunk-JEEKFTAL.mjs.map +1 -0
  80. package/dist/chunk-JPUJWFBS.js +115 -0
  81. package/dist/chunk-JPUJWFBS.js.map +1 -0
  82. package/dist/chunk-JURJUHQB.mjs +70 -0
  83. package/dist/chunk-JURJUHQB.mjs.map +1 -0
  84. package/dist/chunk-JV26U22G.js +52 -0
  85. package/dist/chunk-JV26U22G.js.map +1 -0
  86. package/dist/chunk-K73RKHXA.js +20 -0
  87. package/dist/chunk-K73RKHXA.js.map +1 -0
  88. package/dist/chunk-KDLWQGV3.js +74 -0
  89. package/dist/chunk-KDLWQGV3.js.map +1 -0
  90. package/dist/chunk-KE74K2JM.js +59 -0
  91. package/dist/chunk-KE74K2JM.js.map +1 -0
  92. package/dist/chunk-KVHYDTGR.js +1 -0
  93. package/dist/chunk-KVHYDTGR.js.map +1 -0
  94. package/dist/chunk-L7MGGL7Q.mjs +43 -0
  95. package/dist/chunk-L7MGGL7Q.mjs.map +1 -0
  96. package/dist/chunk-LITIVHN4.js +73 -0
  97. package/dist/chunk-LITIVHN4.js.map +1 -0
  98. package/dist/chunk-LU3J2EYE.js +51 -0
  99. package/dist/chunk-LU3J2EYE.js.map +1 -0
  100. package/dist/chunk-LX37AMSK.mjs +78 -0
  101. package/dist/chunk-LX37AMSK.mjs.map +1 -0
  102. package/dist/chunk-LYOKCYHO.mjs +1 -0
  103. package/dist/chunk-LYOKCYHO.mjs.map +1 -0
  104. package/dist/chunk-MDJZ4K3U.mjs +45 -0
  105. package/dist/chunk-MDJZ4K3U.mjs.map +1 -0
  106. package/dist/chunk-MVPKNRLA.mjs +21 -0
  107. package/dist/chunk-MVPKNRLA.mjs.map +1 -0
  108. package/dist/chunk-MYMH4S2N.mjs +23 -0
  109. package/dist/chunk-MYMH4S2N.mjs.map +1 -0
  110. package/dist/chunk-NE2GDZGZ.mjs +67 -0
  111. package/dist/chunk-NE2GDZGZ.mjs.map +1 -0
  112. package/dist/chunk-NTDD6M3B.mjs +32 -0
  113. package/dist/chunk-NTDD6M3B.mjs.map +1 -0
  114. package/dist/chunk-NUKEBOOL.js +78 -0
  115. package/dist/chunk-NUKEBOOL.js.map +1 -0
  116. package/dist/chunk-OMP4SFLK.js +1 -0
  117. package/dist/chunk-OMP4SFLK.js.map +1 -0
  118. package/dist/chunk-OU3QPU6E.mjs +45 -0
  119. package/dist/chunk-OU3QPU6E.mjs.map +1 -0
  120. package/dist/chunk-OUD66G6O.mjs +74 -0
  121. package/dist/chunk-OUD66G6O.mjs.map +1 -0
  122. package/dist/chunk-PEMZWIHQ.js +39 -0
  123. package/dist/chunk-PEMZWIHQ.js.map +1 -0
  124. package/dist/chunk-PSAM7MJM.mjs +78 -0
  125. package/dist/chunk-PSAM7MJM.mjs.map +1 -0
  126. package/dist/chunk-RC7LBS3H.js +35 -0
  127. package/dist/chunk-RC7LBS3H.js.map +1 -0
  128. package/dist/chunk-RHGOSBUT.js +21 -0
  129. package/dist/chunk-RHGOSBUT.js.map +1 -0
  130. package/dist/chunk-RKCEAMYH.mjs +18 -0
  131. package/dist/chunk-RKCEAMYH.mjs.map +1 -0
  132. package/dist/chunk-RWLBQVYX.mjs +73 -0
  133. package/dist/chunk-RWLBQVYX.mjs.map +1 -0
  134. package/dist/chunk-RZDRHJXI.js +23 -0
  135. package/dist/{cjs/endowments/web-assembly.js.map → chunk-RZDRHJXI.js.map} +1 -1
  136. package/dist/chunk-SCXW3FQO.js +49 -0
  137. package/dist/chunk-SCXW3FQO.js.map +1 -0
  138. package/dist/chunk-SMWKMPHG.mjs +35 -0
  139. package/dist/chunk-SMWKMPHG.mjs.map +1 -0
  140. package/dist/chunk-SXSNJEE7.js +18 -0
  141. package/dist/chunk-SXSNJEE7.js.map +1 -0
  142. package/dist/chunk-TNIGT6KN.js +32 -0
  143. package/dist/chunk-TNIGT6KN.js.map +1 -0
  144. package/dist/chunk-TRB2LS4N.js +54 -0
  145. package/dist/chunk-TRB2LS4N.js.map +1 -0
  146. package/dist/chunk-TZRCALSV.mjs +54 -0
  147. package/dist/chunk-TZRCALSV.mjs.map +1 -0
  148. package/dist/chunk-UJZ3HNXS.mjs +23 -0
  149. package/dist/chunk-UJZ3HNXS.mjs.map +1 -0
  150. package/dist/chunk-UXVJ7HYO.js +78 -0
  151. package/dist/{cjs/restricted/getBip32PublicKey.js.map → chunk-UXVJ7HYO.js.map} +1 -1
  152. package/dist/chunk-UYSXSKML.js +82 -0
  153. package/dist/chunk-UYSXSKML.js.map +1 -0
  154. package/dist/chunk-VFI5FR5U.mjs +119 -0
  155. package/dist/chunk-VFI5FR5U.mjs.map +1 -0
  156. package/dist/chunk-VRDGSBXX.mjs +78 -0
  157. package/dist/chunk-VRDGSBXX.mjs.map +1 -0
  158. package/dist/chunk-VSVVWO3W.mjs +42 -0
  159. package/dist/chunk-VSVVWO3W.mjs.map +1 -0
  160. package/dist/chunk-VZBSLVVA.js +23 -0
  161. package/dist/{cjs/endowments/ethereum-provider.js.map → chunk-VZBSLVVA.js.map} +1 -1
  162. package/dist/chunk-W2VJ5TWL.js +54 -0
  163. package/dist/chunk-W2VJ5TWL.js.map +1 -0
  164. package/dist/chunk-WHWFVRFH.js +69 -0
  165. package/dist/chunk-WHWFVRFH.js.map +1 -0
  166. package/dist/chunk-WI23VKOX.mjs +21 -0
  167. package/dist/chunk-WI23VKOX.mjs.map +1 -0
  168. package/dist/chunk-XAQ2P3BY.js +188 -0
  169. package/dist/chunk-XAQ2P3BY.js.map +1 -0
  170. package/dist/chunk-Y5ENHOIY.mjs +47 -0
  171. package/dist/chunk-Y5ENHOIY.mjs.map +1 -0
  172. package/dist/chunk-Y6EL5DBH.mjs +75 -0
  173. package/dist/chunk-Y6EL5DBH.mjs.map +1 -0
  174. package/dist/chunk-Y7DF3ZHO.mjs +1 -0
  175. package/dist/chunk-Y7DF3ZHO.mjs.map +1 -0
  176. package/dist/chunk-YJ3ZFIA7.mjs +51 -0
  177. package/dist/chunk-YJ3ZFIA7.mjs.map +1 -0
  178. package/dist/chunk-YK6IFDRN.mjs +151 -0
  179. package/dist/chunk-YK6IFDRN.mjs.map +1 -0
  180. package/dist/chunk-YN3OMGA5.mjs +69 -0
  181. package/dist/chunk-YN3OMGA5.mjs.map +1 -0
  182. package/dist/chunk-ZLLV3F4G.js +43 -0
  183. package/dist/chunk-ZLLV3F4G.js.map +1 -0
  184. package/dist/chunk-ZP3L7LAQ.mjs +18 -0
  185. package/dist/chunk-ZP3L7LAQ.mjs.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/caveats/permittedCoinTypes.ts"],"sourcesContent":["import type {\n PermissionConstraint,\n RestrictedMethodCaveatSpecificationConstraint,\n Caveat,\n} from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { GetBip44EntropyParams } from '@metamask/snaps-sdk';\nimport { FORBIDDEN_COIN_TYPES, SnapCaveatType } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty, isPlainObject } from '@metamask/utils';\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 permittedCoinTypesCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.PermittedCoinTypes,\n value,\n },\n ],\n };\n}\n\n/**\n * Validate the params for `snap_getBip44Entropy`.\n *\n * @param value - The params to validate.\n * @throws If the params are invalid.\n */\nexport function validateBIP44Params(\n value: unknown,\n): asserts value is GetBip44EntropyParams {\n if (!isPlainObject(value) || !hasProperty(value, 'coinType')) {\n throw rpcErrors.invalidParams({\n message: 'Expected a plain object containing a coin type.',\n });\n }\n\n if (\n typeof value.coinType !== 'number' ||\n !Number.isInteger(value.coinType) ||\n value.coinType < 0 ||\n value.coinType > 0x7fffffff\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Invalid \"coinType\" parameter. Coin type must be a non-negative integer.',\n });\n }\n\n if (FORBIDDEN_COIN_TYPES.includes(value.coinType)) {\n throw rpcErrors.invalidParams({\n message: `Coin type ${value.coinType} is forbidden.`,\n });\n }\n}\n\n/**\n * Validate the coin types values associated with a caveat. This checks if the\n * values are non-negative integers (>= 0).\n *\n * @param caveat - The caveat to validate.\n * @throws If the caveat is invalid.\n */\nexport function validateBIP44Caveat(caveat: Caveat<string, any>) {\n if (\n !hasProperty(caveat, 'value') ||\n !Array.isArray(caveat.value) ||\n caveat.value.length === 0\n ) {\n throw rpcErrors.invalidParams({\n message: 'Expected non-empty array of coin types.',\n });\n }\n\n caveat.value.forEach(validateBIP44Params);\n}\n\nexport const PermittedCoinTypesCaveatSpecification: Record<\n SnapCaveatType.PermittedCoinTypes,\n RestrictedMethodCaveatSpecificationConstraint\n> = {\n [SnapCaveatType.PermittedCoinTypes]: Object.freeze({\n type: SnapCaveatType.PermittedCoinTypes,\n decorator: (\n method,\n caveat: Caveat<\n SnapCaveatType.PermittedCoinTypes,\n GetBip44EntropyParams[]\n >,\n ) => {\n return async (args) => {\n const { params } = args;\n validateBIP44Params(params);\n\n const coinType = caveat.value.find(\n (caveatValue) => caveatValue.coinType === params.coinType,\n );\n\n if (!coinType) {\n throw providerErrors.unauthorized({\n message:\n 'The requested coin type is not permitted. Allowed coin types must be specified in the snap manifest.',\n });\n }\n\n return await method(args);\n };\n },\n validator: (caveat) => validateBIP44Caveat(caveat),\n }),\n};\n"],"names":["providerErrors","rpcErrors","FORBIDDEN_COIN_TYPES","SnapCaveatType","hasProperty","isPlainObject","permittedCoinTypesCaveatMapper","value","caveats","type","PermittedCoinTypes","validateBIP44Params","invalidParams","message","coinType","Number","isInteger","includes","validateBIP44Caveat","caveat","Array","isArray","length","forEach","PermittedCoinTypesCaveatSpecification","Object","freeze","decorator","method","args","params","find","caveatValue","unauthorized","validator"],"mappings":"AAKA,SAASA,cAAc,EAAEC,SAAS,QAAQ,uBAAuB;AAEjE,SAASC,oBAAoB,EAAEC,cAAc,QAAQ,wBAAwB;AAE7E,SAASC,WAAW,EAAEC,aAAa,QAAQ,kBAAkB;AAE7D;;;;;;;CAOC,GACD,OAAO,SAASC,+BACdC,KAAW;IAEX,OAAO;QACLC,SAAS;YACP;gBACEC,MAAMN,eAAeO,kBAAkB;gBACvCH;YACF;SACD;IACH;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASI,oBACdJ,KAAc;IAEd,IAAI,CAACF,cAAcE,UAAU,CAACH,YAAYG,OAAO,aAAa;QAC5D,MAAMN,UAAUW,aAAa,CAAC;YAC5BC,SAAS;QACX;IACF;IAEA,IACE,OAAON,MAAMO,QAAQ,KAAK,YAC1B,CAACC,OAAOC,SAAS,CAACT,MAAMO,QAAQ,KAChCP,MAAMO,QAAQ,GAAG,KACjBP,MAAMO,QAAQ,GAAG,YACjB;QACA,MAAMb,UAAUW,aAAa,CAAC;YAC5BC,SACE;QACJ;IACF;IAEA,IAAIX,qBAAqBe,QAAQ,CAACV,MAAMO,QAAQ,GAAG;QACjD,MAAMb,UAAUW,aAAa,CAAC;YAC5BC,SAAS,CAAC,UAAU,EAAEN,MAAMO,QAAQ,CAAC,cAAc,CAAC;QACtD;IACF;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASI,oBAAoBC,MAA2B;IAC7D,IACE,CAACf,YAAYe,QAAQ,YACrB,CAACC,MAAMC,OAAO,CAACF,OAAOZ,KAAK,KAC3BY,OAAOZ,KAAK,CAACe,MAAM,KAAK,GACxB;QACA,MAAMrB,UAAUW,aAAa,CAAC;YAC5BC,SAAS;QACX;IACF;IAEAM,OAAOZ,KAAK,CAACgB,OAAO,CAACZ;AACvB;AAEA,OAAO,MAAMa,wCAGT;IACF,CAACrB,eAAeO,kBAAkB,CAAC,EAAEe,OAAOC,MAAM,CAAC;QACjDjB,MAAMN,eAAeO,kBAAkB;QACvCiB,WAAW,CACTC,QACAT;YAKA,OAAO,OAAOU;gBACZ,MAAM,EAAEC,MAAM,EAAE,GAAGD;gBACnBlB,oBAAoBmB;gBAEpB,MAAMhB,WAAWK,OAAOZ,KAAK,CAACwB,IAAI,CAChC,CAACC,cAAgBA,YAAYlB,QAAQ,KAAKgB,OAAOhB,QAAQ;gBAG3D,IAAI,CAACA,UAAU;oBACb,MAAMd,eAAeiC,YAAY,CAAC;wBAChCpB,SACE;oBACJ;gBACF;gBAEA,OAAO,MAAMe,OAAOC;YACtB;QACF;QACAK,WAAW,CAACf,SAAWD,oBAAoBC;IAC7C;AACF,EAAE"}
@@ -1,64 +0,0 @@
1
- import { providerErrors, rpcErrors } from '@metamask/rpc-errors';
2
- import { SnapCaveatType, Bip32EntropyStruct, isEqual } from '@metamask/snaps-utils';
3
- import { assertStruct } from '@metamask/utils';
4
- import { array, size, type } from 'superstruct';
5
- /**
6
- * Map a raw value from the `initialPermissions` to a caveat specification.
7
- * Note that this function does not do any validation, that's handled by the
8
- * PermissionsController when the permission is requested.
9
- *
10
- * @param value - The raw value from the `initialPermissions`.
11
- * @returns The caveat specification.
12
- */ export function permittedDerivationPathsCaveatMapper(value) {
13
- return {
14
- caveats: [
15
- {
16
- type: SnapCaveatType.PermittedDerivationPaths,
17
- value
18
- }
19
- ]
20
- };
21
- }
22
- /**
23
- * Validate a caveat path object. The object must consist of a `path` array and
24
- * a `curve` string. Paths must start with `m`, and must contain at
25
- * least two indices. If `ed25519` is used, this checks if all the path indices
26
- * are hardened.
27
- *
28
- * @param value - The value to validate.
29
- * @throws If the value is invalid.
30
- */ export function validateBIP32Path(value) {
31
- assertStruct(value, Bip32EntropyStruct, 'Invalid BIP-32 entropy path definition', rpcErrors.invalidParams);
32
- }
33
- /**
34
- * Validate the path values associated with a caveat. This validates that the
35
- * value is a non-empty array with valid derivation paths and curves.
36
- *
37
- * @param caveat - The caveat to validate.
38
- * @throws If the value is invalid.
39
- */ export function validateBIP32CaveatPaths(caveat) {
40
- assertStruct(caveat, type({
41
- value: size(array(Bip32EntropyStruct), 1, Infinity)
42
- }), 'Invalid BIP-32 entropy caveat', rpcErrors.internal);
43
- }
44
- export const PermittedDerivationPathsCaveatSpecification = {
45
- [SnapCaveatType.PermittedDerivationPaths]: Object.freeze({
46
- type: SnapCaveatType.PermittedDerivationPaths,
47
- decorator: (method, caveat)=>{
48
- return async (args)=>{
49
- const { params } = args;
50
- validateBIP32Path(params);
51
- const path = caveat.value.find((caveatPath)=>isEqual(params.path.slice(0, caveatPath.path.length), caveatPath.path) && caveatPath.curve === params.curve);
52
- if (!path) {
53
- throw providerErrors.unauthorized({
54
- message: 'The requested path is not permitted. Allowed paths must be specified in the snap manifest.'
55
- });
56
- }
57
- return await method(args);
58
- };
59
- },
60
- validator: (caveat)=>validateBIP32CaveatPaths(caveat)
61
- })
62
- };
63
-
64
- //# sourceMappingURL=permittedDerivationPaths.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/restricted/caveats/permittedDerivationPaths.ts"],"sourcesContent":["import type {\n Caveat,\n PermissionConstraint,\n RestrictedMethodCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Bip32Entropy } from '@metamask/snaps-utils';\nimport {\n SnapCaveatType,\n Bip32EntropyStruct,\n isEqual,\n} from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport { array, size, type } from 'superstruct';\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 permittedDerivationPathsCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.PermittedDerivationPaths,\n value,\n },\n ],\n };\n}\n\n/**\n * Validate a caveat path object. The object must consist of a `path` array and\n * a `curve` string. Paths must start with `m`, and must contain at\n * least two indices. If `ed25519` is used, this checks if all the path indices\n * are hardened.\n *\n * @param value - The value to validate.\n * @throws If the value is invalid.\n */\nexport function validateBIP32Path(\n value: unknown,\n): asserts value is Bip32Entropy {\n assertStruct(\n value,\n Bip32EntropyStruct,\n 'Invalid BIP-32 entropy path definition',\n rpcErrors.invalidParams,\n );\n}\n\n/**\n * Validate the path values associated with a caveat. This validates that the\n * value is a non-empty array with valid derivation paths and curves.\n *\n * @param caveat - The caveat to validate.\n * @throws If the value is invalid.\n */\nexport function validateBIP32CaveatPaths(\n caveat: Caveat<string, any>,\n): asserts caveat is Caveat<string, Bip32Entropy[]> {\n assertStruct(\n caveat,\n type({ value: size(array(Bip32EntropyStruct), 1, Infinity) }),\n 'Invalid BIP-32 entropy caveat',\n rpcErrors.internal,\n );\n}\n\nexport const PermittedDerivationPathsCaveatSpecification: Record<\n SnapCaveatType.PermittedDerivationPaths,\n RestrictedMethodCaveatSpecificationConstraint\n> = {\n [SnapCaveatType.PermittedDerivationPaths]: Object.freeze({\n type: SnapCaveatType.PermittedDerivationPaths,\n decorator: (\n method,\n caveat: Caveat<SnapCaveatType.PermittedDerivationPaths, Bip32Entropy[]>,\n ) => {\n return async (args) => {\n const { params } = args;\n validateBIP32Path(params);\n\n const path = caveat.value.find(\n (caveatPath) =>\n isEqual(\n params.path.slice(0, caveatPath.path.length),\n caveatPath.path,\n ) && caveatPath.curve === params.curve,\n );\n\n if (!path) {\n throw providerErrors.unauthorized({\n message:\n 'The requested path is not permitted. Allowed paths must be specified in the snap manifest.',\n });\n }\n\n return await method(args);\n };\n },\n validator: (caveat) => validateBIP32CaveatPaths(caveat),\n }),\n};\n"],"names":["providerErrors","rpcErrors","SnapCaveatType","Bip32EntropyStruct","isEqual","assertStruct","array","size","type","permittedDerivationPathsCaveatMapper","value","caveats","PermittedDerivationPaths","validateBIP32Path","invalidParams","validateBIP32CaveatPaths","caveat","Infinity","internal","PermittedDerivationPathsCaveatSpecification","Object","freeze","decorator","method","args","params","path","find","caveatPath","slice","length","curve","unauthorized","message","validator"],"mappings":"AAKA,SAASA,cAAc,EAAEC,SAAS,QAAQ,uBAAuB;AAEjE,SACEC,cAAc,EACdC,kBAAkB,EAClBC,OAAO,QACF,wBAAwB;AAE/B,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,KAAK,EAAEC,IAAI,EAAEC,IAAI,QAAQ,cAAc;AAEhD;;;;;;;CAOC,GACD,OAAO,SAASC,qCACdC,KAAW;IAEX,OAAO;QACLC,SAAS;YACP;gBACEH,MAAMN,eAAeU,wBAAwB;gBAC7CF;YACF;SACD;IACH;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASG,kBACdH,KAAc;IAEdL,aACEK,OACAP,oBACA,0CACAF,UAAUa,aAAa;AAE3B;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,yBACdC,MAA2B;IAE3BX,aACEW,QACAR,KAAK;QAAEE,OAAOH,KAAKD,MAAMH,qBAAqB,GAAGc;IAAU,IAC3D,iCACAhB,UAAUiB,QAAQ;AAEtB;AAEA,OAAO,MAAMC,8CAGT;IACF,CAACjB,eAAeU,wBAAwB,CAAC,EAAEQ,OAAOC,MAAM,CAAC;QACvDb,MAAMN,eAAeU,wBAAwB;QAC7CU,WAAW,CACTC,QACAP;YAEA,OAAO,OAAOQ;gBACZ,MAAM,EAAEC,MAAM,EAAE,GAAGD;gBACnBX,kBAAkBY;gBAElB,MAAMC,OAAOV,OAAON,KAAK,CAACiB,IAAI,CAC5B,CAACC,aACCxB,QACEqB,OAAOC,IAAI,CAACG,KAAK,CAAC,GAAGD,WAAWF,IAAI,CAACI,MAAM,GAC3CF,WAAWF,IAAI,KACZE,WAAWG,KAAK,KAAKN,OAAOM,KAAK;gBAG1C,IAAI,CAACL,MAAM;oBACT,MAAM1B,eAAegC,YAAY,CAAC;wBAChCC,SACE;oBACJ;gBACF;gBAEA,OAAO,MAAMV,OAAOC;YACtB;QACF;QACAU,WAAW,CAAClB,SAAWD,yBAAyBC;IAClD;AACF,EAAE"}
@@ -1,50 +0,0 @@
1
- import { rpcErrors } from '@metamask/rpc-errors';
2
- import { SnapCaveatType, SnapIdsStruct } from '@metamask/snaps-utils';
3
- import { hasProperty, assertStruct } from '@metamask/utils';
4
- import { type } from 'superstruct';
5
- /**
6
- * Map a raw value from the `initialPermissions` to a caveat specification.
7
- * Note that this function does not do any validation, that's handled by the
8
- * PermissionsController when the permission is requested.
9
- *
10
- * @param value - The raw value from the `initialPermissions`.
11
- * @returns The caveat specification.
12
- */ export function snapIdsCaveatMapper(value) {
13
- return {
14
- caveats: [
15
- {
16
- type: SnapCaveatType.SnapIds,
17
- value
18
- }
19
- ]
20
- };
21
- }
22
- /**
23
- * Validates that the caveat value exists and is a non-empty object.
24
- *
25
- * @param caveat - The caveat to validate.
26
- * @throws If the caveat is invalid.
27
- */ export function validateSnapIdsCaveat(caveat) {
28
- assertStruct(caveat, type({
29
- value: SnapIdsStruct
30
- }), 'Expected caveat to have a value property of a non-empty object of snap IDs.', rpcErrors.invalidParams);
31
- }
32
- export const SnapIdsCaveatSpecification = {
33
- [SnapCaveatType.SnapIds]: Object.freeze({
34
- type: SnapCaveatType.SnapIds,
35
- validator: (caveat)=>validateSnapIdsCaveat(caveat),
36
- decorator: (method, caveat)=>{
37
- return async (args)=>{
38
- const { params, context: { origin } } = args;
39
- const snapIds = caveat.value;
40
- const { snapId } = params;
41
- if (!hasProperty(snapIds, snapId)) {
42
- throw new Error(`${origin} does not have permission to invoke ${snapId} snap.`);
43
- }
44
- return await method(args);
45
- };
46
- }
47
- })
48
- };
49
-
50
- //# sourceMappingURL=snapIds.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/restricted/caveats/snapIds.ts"],"sourcesContent":["import type {\n Caveat,\n RestrictedMethodOptions,\n RestrictedMethodParameters,\n RestrictedMethodCaveatSpecificationConstraint,\n PermissionConstraint,\n} from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { SnapIds } from '@metamask/snaps-utils';\nimport { SnapCaveatType, SnapIdsStruct } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty, assertStruct } from '@metamask/utils';\nimport { type } from 'superstruct';\n\nimport type { InvokeSnapParams } from '../invokeSnap';\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 snapIdsCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.SnapIds,\n value,\n },\n ],\n };\n}\n\n/**\n * Validates that the caveat value exists and is a non-empty object.\n *\n * @param caveat - The caveat to validate.\n * @throws If the caveat is invalid.\n */\nexport function validateSnapIdsCaveat(\n caveat: Caveat<string, any>,\n): asserts caveat is Caveat<string, SnapIds> {\n assertStruct(\n caveat,\n type({\n value: SnapIdsStruct,\n }),\n 'Expected caveat to have a value property of a non-empty object of snap IDs.',\n rpcErrors.invalidParams,\n );\n}\n\nexport const SnapIdsCaveatSpecification: Record<\n SnapCaveatType.SnapIds,\n RestrictedMethodCaveatSpecificationConstraint\n> = {\n [SnapCaveatType.SnapIds]: Object.freeze({\n type: SnapCaveatType.SnapIds,\n validator: (caveat) => validateSnapIdsCaveat(caveat),\n decorator: (method, caveat) => {\n return async (args) => {\n const {\n params,\n context: { origin },\n }: RestrictedMethodOptions<RestrictedMethodParameters> = args;\n const snapIds = caveat.value;\n const { snapId } = params as InvokeSnapParams;\n if (!hasProperty(snapIds, snapId)) {\n throw new Error(\n `${origin} does not have permission to invoke ${snapId} snap.`,\n );\n }\n return await method(args);\n };\n },\n }),\n};\n"],"names":["rpcErrors","SnapCaveatType","SnapIdsStruct","hasProperty","assertStruct","type","snapIdsCaveatMapper","value","caveats","SnapIds","validateSnapIdsCaveat","caveat","invalidParams","SnapIdsCaveatSpecification","Object","freeze","validator","decorator","method","args","params","context","origin","snapIds","snapId","Error"],"mappings":"AAOA,SAASA,SAAS,QAAQ,uBAAuB;AAEjD,SAASC,cAAc,EAAEC,aAAa,QAAQ,wBAAwB;AAEtE,SAASC,WAAW,EAAEC,YAAY,QAAQ,kBAAkB;AAC5D,SAASC,IAAI,QAAQ,cAAc;AAInC;;;;;;;CAOC,GACD,OAAO,SAASC,oBACdC,KAAW;IAEX,OAAO;QACLC,SAAS;YACP;gBACEH,MAAMJ,eAAeQ,OAAO;gBAC5BF;YACF;SACD;IACH;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASG,sBACdC,MAA2B;IAE3BP,aACEO,QACAN,KAAK;QACHE,OAAOL;IACT,IACA,+EACAF,UAAUY,aAAa;AAE3B;AAEA,OAAO,MAAMC,6BAGT;IACF,CAACZ,eAAeQ,OAAO,CAAC,EAAEK,OAAOC,MAAM,CAAC;QACtCV,MAAMJ,eAAeQ,OAAO;QAC5BO,WAAW,CAACL,SAAWD,sBAAsBC;QAC7CM,WAAW,CAACC,QAAQP;YAClB,OAAO,OAAOQ;gBACZ,MAAM,EACJC,MAAM,EACNC,SAAS,EAAEC,MAAM,EAAE,EACpB,GAAwDH;gBACzD,MAAMI,UAAUZ,OAAOJ,KAAK;gBAC5B,MAAM,EAAEiB,MAAM,EAAE,GAAGJ;gBACnB,IAAI,CAACjB,YAAYoB,SAASC,SAAS;oBACjC,MAAM,IAAIC,MACR,CAAC,EAAEH,OAAO,oCAAoC,EAAEE,OAAO,MAAM,CAAC;gBAElE;gBACA,OAAO,MAAMN,OAAOC;YACtB;QACF;IACF;AACF,EAAE"}
@@ -1,164 +0,0 @@
1
- import { PermissionType, SubjectType } from '@metamask/permission-controller';
2
- import { rpcErrors } from '@metamask/rpc-errors';
3
- import { DialogType, ComponentStruct, enumValue, union } from '@metamask/snaps-sdk';
4
- import { createUnion } from '@metamask/snaps-utils';
5
- import { hasProperty } from '@metamask/utils';
6
- import { create, enums, object, optional, size, string, type } from 'superstruct';
7
- const methodName = 'snap_dialog';
8
- const PlaceholderStruct = optional(size(string(), 1, 40));
9
- /**
10
- * The specification builder for the `snap_dialog` permission. `snap_dialog`
11
- * lets the Snap display one of the following dialogs to the user:
12
- * - An alert, for displaying information.
13
- * - A confirmation, for accepting or rejecting some action.
14
- * - A prompt, for inputting some information.
15
- *
16
- * @param options - The specification builder options.
17
- * @param options.allowedCaveats - The optional allowed caveats for the
18
- * permission.
19
- * @param options.methodHooks - The RPC method hooks needed by the method
20
- * implementation.
21
- * @returns The specification for the `snap_dialog` permission.
22
- */ const specificationBuilder = ({ allowedCaveats = null, methodHooks })=>{
23
- return {
24
- permissionType: PermissionType.RestrictedMethod,
25
- targetName: methodName,
26
- allowedCaveats,
27
- methodImplementation: getDialogImplementation(methodHooks),
28
- subjectTypes: [
29
- SubjectType.Snap
30
- ]
31
- };
32
- };
33
- const methodHooks = {
34
- showDialog: true,
35
- createInterface: true,
36
- getInterface: true
37
- };
38
- export const dialogBuilder = Object.freeze({
39
- targetName: methodName,
40
- specificationBuilder,
41
- methodHooks
42
- });
43
- // Note: We use `type` here instead of `object` because `type` does not validate
44
- // the keys of the object, which is what we want.
45
- const BaseParamsStruct = type({
46
- type: enums([
47
- DialogType.Alert,
48
- DialogType.Confirmation,
49
- DialogType.Prompt
50
- ])
51
- });
52
- const AlertParametersWithContentStruct = object({
53
- type: enumValue(DialogType.Alert),
54
- content: ComponentStruct
55
- });
56
- const AlertParametersWithIdStruct = object({
57
- type: enumValue(DialogType.Alert),
58
- id: string()
59
- });
60
- const AlertParametersStruct = union([
61
- AlertParametersWithContentStruct,
62
- AlertParametersWithIdStruct
63
- ]);
64
- const ConfirmationParametersWithContentStruct = object({
65
- type: enumValue(DialogType.Confirmation),
66
- content: ComponentStruct
67
- });
68
- const ConfirmationParametersWithIdStruct = object({
69
- type: enumValue(DialogType.Confirmation),
70
- id: string()
71
- });
72
- const ConfirmationParametersStruct = union([
73
- ConfirmationParametersWithContentStruct,
74
- ConfirmationParametersWithIdStruct
75
- ]);
76
- const PromptParametersWithContentStruct = object({
77
- type: enumValue(DialogType.Prompt),
78
- content: ComponentStruct,
79
- placeholder: PlaceholderStruct
80
- });
81
- const PromptParametersWithIdStruct = object({
82
- type: enumValue(DialogType.Prompt),
83
- id: string(),
84
- placeholder: PlaceholderStruct
85
- });
86
- const PromptParametersStruct = union([
87
- PromptParametersWithContentStruct,
88
- PromptParametersWithIdStruct
89
- ]);
90
- const DialogParametersStruct = union([
91
- AlertParametersStruct,
92
- ConfirmationParametersStruct,
93
- PromptParametersStruct
94
- ]);
95
- const structs = {
96
- [DialogType.Alert]: AlertParametersStruct,
97
- [DialogType.Confirmation]: ConfirmationParametersStruct,
98
- [DialogType.Prompt]: PromptParametersStruct
99
- };
100
- /**
101
- * Builds the method implementation for `snap_dialog`.
102
- *
103
- * @param hooks - The RPC method hooks.
104
- * @param hooks.showDialog - A function that shows the specified dialog in the
105
- * MetaMask UI and returns the appropriate value for the dialog type.
106
- * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
107
- * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.
108
- * @returns The method implementation which return value depends on the dialog
109
- * type, valid return types are: string, boolean, null.
110
- */ export function getDialogImplementation({ showDialog, createInterface, getInterface }) {
111
- return async function dialogImplementation(args) {
112
- const { params, context: { origin } } = args;
113
- const validatedType = getValidatedType(params);
114
- const validatedParams = getValidatedParams(params, structs[validatedType]);
115
- const placeholder = validatedParams.type === DialogType.Prompt ? validatedParams.placeholder : undefined;
116
- if (hasProperty(validatedParams, 'content')) {
117
- const id = await createInterface(origin, validatedParams.content);
118
- return showDialog(origin, validatedType, id, placeholder);
119
- }
120
- // Verify that the passed interface ID is valid.
121
- // This will throw if the interface ID is invalid (not created by the snap or doesn't exist)
122
- try {
123
- getInterface(origin, validatedParams.id);
124
- } catch (error) {
125
- throw rpcErrors.invalidParams({
126
- message: `Invalid params: ${error.message}`
127
- });
128
- }
129
- return showDialog(origin, validatedType, validatedParams.id, placeholder);
130
- };
131
- }
132
- /**
133
- * Get the validated type of the dialog parameters. Throws an error if the type
134
- * is invalid.
135
- *
136
- * @param params - The parameters to validate.
137
- * @returns The validated type of the dialog parameters.
138
- */ function getValidatedType(params) {
139
- try {
140
- return create(params, BaseParamsStruct).type;
141
- } catch (error) {
142
- throw rpcErrors.invalidParams({
143
- message: `The "type" property must be one of: ${Object.values(DialogType).join(', ')}.`
144
- });
145
- }
146
- }
147
- /**
148
- * Validates the confirm method `params` and returns them cast to the correct
149
- * type. Throws if validation fails.
150
- *
151
- * @param params - The unvalidated params object from the method request.
152
- * @param struct - The struct to validate the params against.
153
- * @returns The validated confirm method parameter object.
154
- */ function getValidatedParams(params, struct) {
155
- try {
156
- return createUnion(params, struct, 'type');
157
- } catch (error) {
158
- throw rpcErrors.invalidParams({
159
- message: `Invalid params: ${error.message}`
160
- });
161
- }
162
- }
163
-
164
- //# sourceMappingURL=dialog.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/restricted/dialog.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 {\n DialogType,\n ComponentStruct,\n enumValue,\n union,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n EnumToUnion,\n Component,\n InterfaceState,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport { createUnion } from '@metamask/snaps-utils';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport { hasProperty, type NonEmptyArray } from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n create,\n enums,\n object,\n optional,\n size,\n string,\n type,\n} from 'superstruct';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype ShowDialog = (\n snapId: string,\n type: EnumToUnion<DialogType>,\n id: string,\n placeholder?: Placeholder,\n) => Promise<null | boolean | string>;\n\ntype CreateInterface = (snapId: string, content: Component) => Promise<string>;\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: Component; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the alert.\n * @param type - The dialog type.\n * @param id - The interface ID.\n * @param placeholder - The placeholder for the Prompt dialog input.\n */\n showDialog: ShowDialog;\n\n /**\n * @param snapId - The Snap ID creating the interface.\n * @param content - The content of the interface.\n */\n createInterface: CreateInterface;\n /**\n * @param snapId - The SnapId requesting the interface.\n * @param id - The interface ID.\n */\n getInterface: GetInterface;\n};\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: DialogMethodHooks;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<DialogMethodHooks> = {\n showDialog: true,\n createInterface: true,\n getInterface: true,\n};\n\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n// Note: We use `type` here instead of `object` because `type` does not validate\n// the keys of the object, which is what we want.\nconst BaseParamsStruct = type({\n type: enums([DialogType.Alert, DialogType.Confirmation, DialogType.Prompt]),\n});\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentStruct,\n});\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = union([\n AlertParametersWithContentStruct,\n AlertParametersWithIdStruct,\n]);\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = union([\n ConfirmationParametersWithContentStruct,\n ConfirmationParametersWithIdStruct,\n]);\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = union([\n PromptParametersWithContentStruct,\n PromptParametersWithIdStruct,\n]);\n\nconst DialogParametersStruct = union([\n AlertParametersStruct,\n ConfirmationParametersStruct,\n PromptParametersStruct,\n]);\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\nconst structs = {\n [DialogType.Alert]: AlertParametersStruct,\n [DialogType.Confirmation]: ConfirmationParametersStruct,\n [DialogType.Prompt]: PromptParametersStruct,\n};\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showDialog - A function that shows the specified dialog in the\n * MetaMask UI and returns the appropriate value for the dialog type.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n showDialog,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string> {\n const {\n params,\n context: { origin },\n } = args;\n\n const validatedType = getValidatedType(params);\n const validatedParams = getValidatedParams(params, structs[validatedType]);\n\n const placeholder =\n validatedParams.type === DialogType.Prompt\n ? validatedParams.placeholder\n : undefined;\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n return showDialog(origin, validatedType, id, placeholder);\n }\n\n // Verify that the passed interface ID is valid.\n // This will throw if the interface ID is invalid (not created by the snap or doesn't exist)\n try {\n getInterface(origin, validatedParams.id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n\n return showDialog(origin, validatedType, validatedParams.id, placeholder);\n };\n}\n\n/**\n * Get the validated type of the dialog parameters. Throws an error if the type\n * is invalid.\n *\n * @param params - The parameters to validate.\n * @returns The validated type of the dialog parameters.\n */\nfunction getValidatedType(params: unknown): DialogType {\n try {\n return create(params, BaseParamsStruct).type;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `The \"type\" property must be one of: ${Object.values(\n DialogType,\n ).join(', ')}.`,\n });\n }\n}\n\n/**\n * Validates the confirm 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 struct - The struct to validate the params against.\n * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(\n params: unknown,\n struct: Struct<any, any>,\n): DialogParameters {\n try {\n return createUnion(params, struct, 'type');\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"],"names":["PermissionType","SubjectType","rpcErrors","DialogType","ComponentStruct","enumValue","union","createUnion","hasProperty","create","enums","object","optional","size","string","type","methodName","PlaceholderStruct","specificationBuilder","allowedCaveats","methodHooks","permissionType","RestrictedMethod","targetName","methodImplementation","getDialogImplementation","subjectTypes","Snap","showDialog","createInterface","getInterface","dialogBuilder","Object","freeze","BaseParamsStruct","Alert","Confirmation","Prompt","AlertParametersWithContentStruct","content","AlertParametersWithIdStruct","id","AlertParametersStruct","ConfirmationParametersWithContentStruct","ConfirmationParametersWithIdStruct","ConfirmationParametersStruct","PromptParametersWithContentStruct","placeholder","PromptParametersWithIdStruct","PromptParametersStruct","DialogParametersStruct","structs","dialogImplementation","args","params","context","origin","validatedType","getValidatedType","validatedParams","getValidatedParams","undefined","error","invalidParams","message","values","join","struct"],"mappings":"AAKA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AACjD,SACEC,UAAU,EACVC,eAAe,EACfC,SAAS,EACTC,KAAK,QACA,sBAAsB;AAQ7B,SAASC,WAAW,QAAQ,wBAAwB;AAEpD,SAASC,WAAW,QAA4B,kBAAkB;AAElE,SACEC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,QAAQ,EACRC,IAAI,EACJC,MAAM,EACNC,IAAI,QACC,cAAc;AAIrB,MAAMC,aAAa;AAEnB,MAAMC,oBAAoBL,SAASC,KAAKC,UAAU,GAAG;AAkDrD;;;;;;;;;;;;;CAaC,GACD,MAAMI,uBAIF,CAAC,EACHC,iBAAiB,IAAI,EACrBC,WAAW,EACuB;IAClC,OAAO;QACLC,gBAAgBrB,eAAesB,gBAAgB;QAC/CC,YAAYP;QACZG;QACAK,sBAAsBC,wBAAwBL;QAC9CM,cAAc;YAACzB,YAAY0B,IAAI;SAAC;IAClC;AACF;AAEA,MAAMP,cAAoD;IACxDQ,YAAY;IACZC,iBAAiB;IACjBC,cAAc;AAChB;AAEA,OAAO,MAAMC,gBAAgBC,OAAOC,MAAM,CAAC;IACzCV,YAAYP;IACZE;IACAE;AACF,GAAY;AAEZ,gFAAgF;AAChF,iDAAiD;AACjD,MAAMc,mBAAmBnB,KAAK;IAC5BA,MAAML,MAAM;QAACP,WAAWgC,KAAK;QAAEhC,WAAWiC,YAAY;QAAEjC,WAAWkC,MAAM;KAAC;AAC5E;AAEA,MAAMC,mCAAmC3B,OAAO;IAC9CI,MAAMV,UAAUF,WAAWgC,KAAK;IAChCI,SAASnC;AACX;AACA,MAAMoC,8BAA8B7B,OAAO;IACzCI,MAAMV,UAAUF,WAAWgC,KAAK;IAChCM,IAAI3B;AACN;AAEA,MAAM4B,wBAAwBpC,MAAM;IAClCgC;IACAE;CACD;AAED,MAAMG,0CAA0ChC,OAAO;IACrDI,MAAMV,UAAUF,WAAWiC,YAAY;IACvCG,SAASnC;AACX;AAEA,MAAMwC,qCAAqCjC,OAAO;IAChDI,MAAMV,UAAUF,WAAWiC,YAAY;IACvCK,IAAI3B;AACN;AAEA,MAAM+B,+BAA+BvC,MAAM;IACzCqC;IACAC;CACD;AAED,MAAME,oCAAoCnC,OAAO;IAC/CI,MAAMV,UAAUF,WAAWkC,MAAM;IACjCE,SAASnC;IACT2C,aAAa9B;AACf;AAEA,MAAM+B,+BAA+BrC,OAAO;IAC1CI,MAAMV,UAAUF,WAAWkC,MAAM;IACjCI,IAAI3B;IACJiC,aAAa9B;AACf;AAEA,MAAMgC,yBAAyB3C,MAAM;IACnCwC;IACAE;CACD;AAED,MAAME,yBAAyB5C,MAAM;IACnCoC;IACAG;IACAI;CACD;AAOD,MAAME,UAAU;IACd,CAAChD,WAAWgC,KAAK,CAAC,EAAEO;IACpB,CAACvC,WAAWiC,YAAY,CAAC,EAAES;IAC3B,CAAC1C,WAAWkC,MAAM,CAAC,EAAEY;AACvB;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASxB,wBAAwB,EACtCG,UAAU,EACVC,eAAe,EACfC,YAAY,EACM;IAClB,OAAO,eAAesB,qBACpBC,IAA+C;QAE/C,MAAM,EACJC,MAAM,EACNC,SAAS,EAAEC,MAAM,EAAE,EACpB,GAAGH;QAEJ,MAAMI,gBAAgBC,iBAAiBJ;QACvC,MAAMK,kBAAkBC,mBAAmBN,QAAQH,OAAO,CAACM,cAAc;QAEzE,MAAMV,cACJY,gBAAgB5C,IAAI,KAAKZ,WAAWkC,MAAM,GACtCsB,gBAAgBZ,WAAW,GAC3Bc;QAEN,IAAIrD,YAAYmD,iBAAiB,YAAY;YAC3C,MAAMlB,KAAK,MAAMZ,gBACf2B,QACAG,gBAAgBpB,OAAO;YAEzB,OAAOX,WAAW4B,QAAQC,eAAehB,IAAIM;QAC/C;QAEA,gDAAgD;QAChD,4FAA4F;QAC5F,IAAI;YACFjB,aAAa0B,QAAQG,gBAAgBlB,EAAE;QACzC,EAAE,OAAOqB,OAAO;YACd,MAAM5D,UAAU6D,aAAa,CAAC;gBAC5BC,SAAS,CAAC,gBAAgB,EAAEF,MAAME,OAAO,CAAC,CAAC;YAC7C;QACF;QAEA,OAAOpC,WAAW4B,QAAQC,eAAeE,gBAAgBlB,EAAE,EAAEM;IAC/D;AACF;AAEA;;;;;;CAMC,GACD,SAASW,iBAAiBJ,MAAe;IACvC,IAAI;QACF,OAAO7C,OAAO6C,QAAQpB,kBAAkBnB,IAAI;IAC9C,EAAE,OAAO+C,OAAO;QACd,MAAM5D,UAAU6D,aAAa,CAAC;YAC5BC,SAAS,CAAC,oCAAoC,EAAEhC,OAAOiC,MAAM,CAC3D9D,YACA+D,IAAI,CAAC,MAAM,CAAC,CAAC;QACjB;IACF;AACF;AAEA;;;;;;;CAOC,GACD,SAASN,mBACPN,MAAe,EACfa,MAAwB;IAExB,IAAI;QACF,OAAO5D,YAAY+C,QAAQa,QAAQ;IACrC,EAAE,OAAOL,OAAO;QACd,MAAM5D,UAAU6D,aAAa,CAAC;YAC5BC,SAAS,CAAC,gBAAgB,EAAEF,MAAME,OAAO,CAAC,CAAC;QAC7C;IACF;AACF"}
@@ -1,67 +0,0 @@
1
- import { PermissionType, SubjectType } from '@metamask/permission-controller';
2
- import { rpcErrors } from '@metamask/rpc-errors';
3
- import { SnapCaveatType } from '@metamask/snaps-utils';
4
- import { assert } from '@metamask/utils';
5
- import { getNode } from '../utils';
6
- const targetName = 'snap_getBip32Entropy';
7
- /**
8
- * The specification builder for the `snap_getBip32Entropy` permission.
9
- * `snap_getBip32Entropy` lets the Snap control private keys for a particular
10
- * BIP-32 node.
11
- *
12
- * @param options - The specification builder options.
13
- * @param options.methodHooks - The RPC method hooks needed by the method implementation.
14
- * @returns The specification for the `snap_getBip32Entropy` permission.
15
- */ const specificationBuilder = ({ methodHooks })=>{
16
- return {
17
- permissionType: PermissionType.RestrictedMethod,
18
- targetName,
19
- allowedCaveats: [
20
- SnapCaveatType.PermittedDerivationPaths
21
- ],
22
- methodImplementation: getBip32EntropyImplementation(methodHooks),
23
- validator: ({ caveats })=>{
24
- if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.PermittedDerivationPaths) {
25
- throw rpcErrors.invalidParams({
26
- message: `Expected a single "${SnapCaveatType.PermittedDerivationPaths}" caveat.`
27
- });
28
- }
29
- },
30
- subjectTypes: [
31
- SubjectType.Snap
32
- ]
33
- };
34
- };
35
- const methodHooks = {
36
- getMnemonic: true,
37
- getUnlockPromise: true
38
- };
39
- export const getBip32EntropyBuilder = Object.freeze({
40
- targetName,
41
- specificationBuilder,
42
- methodHooks
43
- });
44
- /**
45
- * Builds the method implementation for `snap_getBip32Entropy`.
46
- *
47
- * @param hooks - The RPC method hooks.
48
- * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
49
- * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
50
- * and prompts the user to unlock their MetaMask if it is locked.
51
- * @returns The method implementation which returns a `JsonSLIP10Node`.
52
- * @throws If the params are invalid.
53
- */ export function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise }) {
54
- return async function getBip32Entropy(args) {
55
- await getUnlockPromise(true);
56
- const { params } = args;
57
- assert(params);
58
- const node = await getNode({
59
- curve: params.curve,
60
- path: params.path,
61
- secretRecoveryPhrase: await getMnemonic()
62
- });
63
- return node.toJSON();
64
- };
65
- }
66
-
67
- //# sourceMappingURL=getBip32Entropy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/restricted/getBip32Entropy.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32EntropyParams,\n GetBip32EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getNode } from '../utils';\n\nconst targetName = 'snap_getBip32Entropy';\n\nexport type GetBip32EntropyMethodHooks = {\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\ntype GetBip32EntropySpecificationBuilderOptions = {\n methodHooks: GetBip32EntropyMethodHooks;\n};\n\ntype GetBip32EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip32Entropy` permission.\n * `snap_getBip32Entropy` lets the Snap control private keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32EntropySpecificationBuilderOptions,\n GetBip32EntropySpecification\n> = ({ methodHooks }: GetBip32EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32EntropyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n};\n\nexport const getBip32EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @returns The method implementation which returns a `JsonSLIP10Node`.\n * @throws If the params are invalid.\n */\nexport function getBip32EntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n}: GetBip32EntropyMethodHooks) {\n return async function getBip32Entropy(\n args: RestrictedMethodOptions<GetBip32EntropyParams>,\n ): Promise<GetBip32EntropyResult> {\n await getUnlockPromise(true);\n\n const { params } = args;\n assert(params);\n\n const node = await getNode({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase: await getMnemonic(),\n });\n\n return node.toJSON();\n };\n}\n"],"names":["PermissionType","SubjectType","rpcErrors","SnapCaveatType","assert","getNode","targetName","specificationBuilder","methodHooks","permissionType","RestrictedMethod","allowedCaveats","PermittedDerivationPaths","methodImplementation","getBip32EntropyImplementation","validator","caveats","length","type","invalidParams","message","subjectTypes","Snap","getMnemonic","getUnlockPromise","getBip32EntropyBuilder","Object","freeze","getBip32Entropy","args","params","node","curve","path","secretRecoveryPhrase","toJSON"],"mappings":"AAMA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AAKjD,SAASC,cAAc,QAAQ,wBAAwB;AAEvD,SAASC,MAAM,QAAQ,kBAAkB;AAGzC,SAASC,OAAO,QAAQ,WAAW;AAEnC,MAAMC,aAAa;AA4BnB;;;;;;;;CAQC,GACD,MAAMC,uBAIF,CAAC,EAAEC,WAAW,EAA8C;IAC9D,OAAO;QACLC,gBAAgBT,eAAeU,gBAAgB;QAC/CJ;QACAK,gBAAgB;YAACR,eAAeS,wBAAwB;SAAC;QACzDC,sBAAsBC,8BAA8BN;QACpDO,WAAW,CAAC,EAAEC,OAAO,EAAE;YACrB,IACEA,SAASC,WAAW,KACpBD,OAAO,CAAC,EAAE,CAACE,IAAI,KAAKf,eAAeS,wBAAwB,EAC3D;gBACA,MAAMV,UAAUiB,aAAa,CAAC;oBAC5BC,SAAS,CAAC,mBAAmB,EAAEjB,eAAeS,wBAAwB,CAAC,SAAS,CAAC;gBACnF;YACF;QACF;QACAS,cAAc;YAACpB,YAAYqB,IAAI;SAAC;IAClC;AACF;AAEA,MAAMd,cAA6D;IACjEe,aAAa;IACbC,kBAAkB;AACpB;AAEA,OAAO,MAAMC,yBAAyBC,OAAOC,MAAM,CAAC;IAClDrB;IACAC;IACAC;AACF,GAAY;AAEZ;;;;;;;;;CASC,GACD,OAAO,SAASM,8BAA8B,EAC5CS,WAAW,EACXC,gBAAgB,EACW;IAC3B,OAAO,eAAeI,gBACpBC,IAAoD;QAEpD,MAAML,iBAAiB;QAEvB,MAAM,EAAEM,MAAM,EAAE,GAAGD;QACnBzB,OAAO0B;QAEP,MAAMC,OAAO,MAAM1B,QAAQ;YACzB2B,OAAOF,OAAOE,KAAK;YACnBC,MAAMH,OAAOG,IAAI;YACjBC,sBAAsB,MAAMX;QAC9B;QAEA,OAAOQ,KAAKI,MAAM;IACpB;AACF"}
@@ -1,79 +0,0 @@
1
- import { PermissionType, SubjectType } from '@metamask/permission-controller';
2
- import { rpcErrors } from '@metamask/rpc-errors';
3
- import { bip32entropy, Bip32PathStruct, SnapCaveatType } from '@metamask/snaps-utils';
4
- import { assertStruct } from '@metamask/utils';
5
- import { boolean, enums, object, optional } from 'superstruct';
6
- import { getNode } from '../utils';
7
- const targetName = 'snap_getBip32PublicKey';
8
- export const Bip32PublicKeyArgsStruct = bip32entropy(object({
9
- path: Bip32PathStruct,
10
- curve: enums([
11
- 'ed25519',
12
- 'secp256k1'
13
- ]),
14
- compressed: optional(boolean())
15
- }));
16
- /**
17
- * The specification builder for the `snap_getBip32PublicKey` permission.
18
- * `snap_getBip32PublicKey` lets the Snap retrieve public keys for a particular
19
- * BIP-32 node.
20
- *
21
- * @param options - The specification builder options.
22
- * @param options.methodHooks - The RPC method hooks needed by the method implementation.
23
- * @returns The specification for the `snap_getBip32PublicKey` permission.
24
- */ const specificationBuilder = ({ methodHooks })=>{
25
- return {
26
- permissionType: PermissionType.RestrictedMethod,
27
- targetName,
28
- allowedCaveats: [
29
- SnapCaveatType.PermittedDerivationPaths
30
- ],
31
- methodImplementation: getBip32PublicKeyImplementation(methodHooks),
32
- validator: ({ caveats })=>{
33
- if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.PermittedDerivationPaths) {
34
- throw rpcErrors.invalidParams({
35
- message: `Expected a single "${SnapCaveatType.PermittedDerivationPaths}" caveat.`
36
- });
37
- }
38
- },
39
- subjectTypes: [
40
- SubjectType.Snap
41
- ]
42
- };
43
- };
44
- const methodHooks = {
45
- getMnemonic: true,
46
- getUnlockPromise: true
47
- };
48
- export const getBip32PublicKeyBuilder = Object.freeze({
49
- targetName,
50
- specificationBuilder,
51
- methodHooks
52
- });
53
- /**
54
- * Builds the method implementation for `snap_getBip32PublicKey`.
55
- *
56
- * @param hooks - The RPC method hooks.
57
- * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
58
- * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
59
- * and prompts the user to unlock their MetaMask if it is locked.
60
- * @returns The method implementation which returns a public key.
61
- * @throws If the params are invalid.
62
- */ export function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise }) {
63
- return async function getBip32PublicKey(args) {
64
- await getUnlockPromise(true);
65
- assertStruct(args.params, Bip32PublicKeyArgsStruct, 'Invalid BIP-32 public key params', rpcErrors.invalidParams);
66
- const { params } = args;
67
- const node = await getNode({
68
- curve: params.curve,
69
- path: params.path,
70
- secretRecoveryPhrase: await getMnemonic()
71
- });
72
- if (params.compressed) {
73
- return node.compressedPublicKey;
74
- }
75
- return node.publicKey;
76
- };
77
- }
78
-
79
- //# sourceMappingURL=getBip32PublicKey.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/restricted/getBip32PublicKey.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32PublicKeyParams,\n GetBip32PublicKeyResult,\n} from '@metamask/snaps-sdk';\nimport {\n bip32entropy,\n Bip32PathStruct,\n SnapCaveatType,\n} from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport { boolean, enums, object, optional } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getNode } from '../utils';\n\nconst targetName = 'snap_getBip32PublicKey';\n\nexport type GetBip32PublicKeyMethodHooks = {\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\ntype GetBip32PublicKeySpecificationBuilderOptions = {\n methodHooks: GetBip32PublicKeyMethodHooks;\n};\n\ntype GetBip32PublicKeySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32PublicKeyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\nexport const Bip32PublicKeyArgsStruct = bip32entropy(\n object({\n path: Bip32PathStruct,\n curve: enums(['ed25519', 'secp256k1']),\n compressed: optional(boolean()),\n }),\n);\n\n/**\n * The specification builder for the `snap_getBip32PublicKey` permission.\n * `snap_getBip32PublicKey` lets the Snap retrieve public keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32PublicKey` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32PublicKeySpecificationBuilderOptions,\n GetBip32PublicKeySpecification\n> = ({ methodHooks }: GetBip32PublicKeySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32PublicKeyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32PublicKeyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n};\n\nexport const getBip32PublicKeyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32PublicKey`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @returns The method implementation which returns a public key.\n * @throws If the params are invalid.\n */\nexport function getBip32PublicKeyImplementation({\n getMnemonic,\n getUnlockPromise,\n}: GetBip32PublicKeyMethodHooks) {\n return async function getBip32PublicKey(\n args: RestrictedMethodOptions<GetBip32PublicKeyParams>,\n ): Promise<GetBip32PublicKeyResult> {\n await getUnlockPromise(true);\n\n assertStruct(\n args.params,\n Bip32PublicKeyArgsStruct,\n 'Invalid BIP-32 public key params',\n rpcErrors.invalidParams,\n );\n\n const { params } = args;\n const node = await getNode({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase: await getMnemonic(),\n });\n\n if (params.compressed) {\n return node.compressedPublicKey;\n }\n\n return node.publicKey;\n };\n}\n"],"names":["PermissionType","SubjectType","rpcErrors","bip32entropy","Bip32PathStruct","SnapCaveatType","assertStruct","boolean","enums","object","optional","getNode","targetName","Bip32PublicKeyArgsStruct","path","curve","compressed","specificationBuilder","methodHooks","permissionType","RestrictedMethod","allowedCaveats","PermittedDerivationPaths","methodImplementation","getBip32PublicKeyImplementation","validator","caveats","length","type","invalidParams","message","subjectTypes","Snap","getMnemonic","getUnlockPromise","getBip32PublicKeyBuilder","Object","freeze","getBip32PublicKey","args","params","node","secretRecoveryPhrase","compressedPublicKey","publicKey"],"mappings":"AAMA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AAKjD,SACEC,YAAY,EACZC,eAAe,EACfC,cAAc,QACT,wBAAwB;AAE/B,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,OAAO,EAAEC,KAAK,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,cAAc;AAG/D,SAASC,OAAO,QAAQ,WAAW;AAEnC,MAAMC,aAAa;AA4BnB,OAAO,MAAMC,2BAA2BV,aACtCM,OAAO;IACLK,MAAMV;IACNW,OAAOP,MAAM;QAAC;QAAW;KAAY;IACrCQ,YAAYN,SAASH;AACvB,IACA;AAEF;;;;;;;;CAQC,GACD,MAAMU,uBAIF,CAAC,EAAEC,WAAW,EAAgD;IAChE,OAAO;QACLC,gBAAgBnB,eAAeoB,gBAAgB;QAC/CR;QACAS,gBAAgB;YAAChB,eAAeiB,wBAAwB;SAAC;QACzDC,sBAAsBC,gCAAgCN;QACtDO,WAAW,CAAC,EAAEC,OAAO,EAAE;YACrB,IACEA,SAASC,WAAW,KACpBD,OAAO,CAAC,EAAE,CAACE,IAAI,KAAKvB,eAAeiB,wBAAwB,EAC3D;gBACA,MAAMpB,UAAU2B,aAAa,CAAC;oBAC5BC,SAAS,CAAC,mBAAmB,EAAEzB,eAAeiB,wBAAwB,CAAC,SAAS,CAAC;gBACnF;YACF;QACF;QACAS,cAAc;YAAC9B,YAAY+B,IAAI;SAAC;IAClC;AACF;AAEA,MAAMd,cAA+D;IACnEe,aAAa;IACbC,kBAAkB;AACpB;AAEA,OAAO,MAAMC,2BAA2BC,OAAOC,MAAM,CAAC;IACpDzB;IACAK;IACAC;AACF,GAAY;AAEZ;;;;;;;;;CASC,GACD,OAAO,SAASM,gCAAgC,EAC9CS,WAAW,EACXC,gBAAgB,EACa;IAC7B,OAAO,eAAeI,kBACpBC,IAAsD;QAEtD,MAAML,iBAAiB;QAEvB5B,aACEiC,KAAKC,MAAM,EACX3B,0BACA,oCACAX,UAAU2B,aAAa;QAGzB,MAAM,EAAEW,MAAM,EAAE,GAAGD;QACnB,MAAME,OAAO,MAAM9B,QAAQ;YACzBI,OAAOyB,OAAOzB,KAAK;YACnBD,MAAM0B,OAAO1B,IAAI;YACjB4B,sBAAsB,MAAMT;QAC9B;QAEA,IAAIO,OAAOxB,UAAU,EAAE;YACrB,OAAOyB,KAAKE,mBAAmB;QACjC;QAEA,OAAOF,KAAKG,SAAS;IACvB;AACF"}
@@ -1,69 +0,0 @@
1
- import { BIP44CoinTypeNode } from '@metamask/key-tree';
2
- import { PermissionType, SubjectType } from '@metamask/permission-controller';
3
- import { rpcErrors } from '@metamask/rpc-errors';
4
- import { SnapCaveatType } from '@metamask/snaps-utils';
5
- const targetName = 'snap_getBip44Entropy';
6
- /**
7
- * The specification builder for the `snap_getBip44Entropy` permission.
8
- * `snap_getBip44Entropy_*` lets the Snap control private keys for a particular
9
- * BIP-32 coin type.
10
- *
11
- * @param options - The specification builder options.
12
- * @param options.methodHooks - The RPC method hooks needed by the method
13
- * implementation.
14
- * @returns The specification for the `snap_getBip44Entropy` permission.
15
- */ const specificationBuilder = ({ methodHooks })=>{
16
- return {
17
- permissionType: PermissionType.RestrictedMethod,
18
- targetName,
19
- allowedCaveats: [
20
- SnapCaveatType.PermittedCoinTypes
21
- ],
22
- methodImplementation: getBip44EntropyImplementation(methodHooks),
23
- validator: ({ caveats })=>{
24
- if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.PermittedCoinTypes) {
25
- throw rpcErrors.invalidParams({
26
- message: `Expected a single "${SnapCaveatType.PermittedCoinTypes}" caveat.`
27
- });
28
- }
29
- },
30
- subjectTypes: [
31
- SubjectType.Snap
32
- ]
33
- };
34
- };
35
- const methodHooks = {
36
- getMnemonic: true,
37
- getUnlockPromise: true
38
- };
39
- export const getBip44EntropyBuilder = Object.freeze({
40
- targetName,
41
- specificationBuilder,
42
- methodHooks
43
- });
44
- /**
45
- * Builds the method implementation for `snap_getBip44Entropy`.
46
- *
47
- * @param hooks - The RPC method hooks.
48
- * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase
49
- * of the user.
50
- * @param hooks.getUnlockPromise - A function that resolves once the MetaMask
51
- * extension is unlocked and prompts the user to unlock their MetaMask if it is
52
- * locked.
53
- * @returns The method implementation which returns a `BIP44CoinTypeNode`.
54
- * @throws If the params are invalid.
55
- */ export function getBip44EntropyImplementation({ getMnemonic, getUnlockPromise }) {
56
- return async function getBip44Entropy(args) {
57
- await getUnlockPromise(true);
58
- // `args.params` is validated by the decorator, so it's safe to assert here.
59
- const params = args.params;
60
- const node = await BIP44CoinTypeNode.fromDerivationPath([
61
- await getMnemonic(),
62
- `bip32:44'`,
63
- `bip32:${params.coinType}'`
64
- ]);
65
- return node.toJSON();
66
- };
67
- }
68
-
69
- //# sourceMappingURL=getBip44Entropy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/restricted/getBip44Entropy.ts"],"sourcesContent":["import { BIP44CoinTypeNode } from '@metamask/key-tree';\nimport type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip44EntropyParams,\n GetBip44EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst targetName = 'snap_getBip44Entropy';\n\nexport type GetBip44EntropyMethodHooks = {\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\ntype GetBip44EntropySpecificationBuilderOptions = {\n methodHooks: GetBip44EntropyMethodHooks;\n};\n\ntype GetBip44EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip44EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip44Entropy` permission.\n * `snap_getBip44Entropy_*` lets the Snap control private keys for a particular\n * BIP-32 coin type.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_getBip44Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip44EntropySpecificationBuilderOptions,\n GetBip44EntropySpecification\n> = ({ methodHooks }: GetBip44EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedCoinTypes],\n methodImplementation: getBip44EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedCoinTypes\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedCoinTypes}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip44EntropyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n};\n\nexport const getBip44EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip44Entropy`.\n *\n * @param hooks - The RPC method hooks.\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 * @returns The method implementation which returns a `BIP44CoinTypeNode`.\n * @throws If the params are invalid.\n */\nexport function getBip44EntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n}: GetBip44EntropyMethodHooks) {\n return async function getBip44Entropy(\n args: RestrictedMethodOptions<GetBip44EntropyParams>,\n ): Promise<GetBip44EntropyResult> {\n await getUnlockPromise(true);\n\n // `args.params` is validated by the decorator, so it's safe to assert here.\n const params = args.params as GetBip44EntropyParams;\n\n const node = await BIP44CoinTypeNode.fromDerivationPath([\n await getMnemonic(),\n `bip32:44'`,\n `bip32:${params.coinType}'`,\n ]);\n\n return node.toJSON();\n };\n}\n"],"names":["BIP44CoinTypeNode","PermissionType","SubjectType","rpcErrors","SnapCaveatType","targetName","specificationBuilder","methodHooks","permissionType","RestrictedMethod","allowedCaveats","PermittedCoinTypes","methodImplementation","getBip44EntropyImplementation","validator","caveats","length","type","invalidParams","message","subjectTypes","Snap","getMnemonic","getUnlockPromise","getBip44EntropyBuilder","Object","freeze","getBip44Entropy","args","params","node","fromDerivationPath","coinType","toJSON"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAOvD,SAASC,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AAKjD,SAASC,cAAc,QAAQ,wBAAwB;AAKvD,MAAMC,aAAa;AA4BnB;;;;;;;;;CASC,GACD,MAAMC,uBAIF,CAAC,EAAEC,WAAW,EAA8C;IAC9D,OAAO;QACLC,gBAAgBP,eAAeQ,gBAAgB;QAC/CJ;QACAK,gBAAgB;YAACN,eAAeO,kBAAkB;SAAC;QACnDC,sBAAsBC,8BAA8BN;QACpDO,WAAW,CAAC,EAAEC,OAAO,EAAE;YACrB,IACEA,SAASC,WAAW,KACpBD,OAAO,CAAC,EAAE,CAACE,IAAI,KAAKb,eAAeO,kBAAkB,EACrD;gBACA,MAAMR,UAAUe,aAAa,CAAC;oBAC5BC,SAAS,CAAC,mBAAmB,EAAEf,eAAeO,kBAAkB,CAAC,SAAS,CAAC;gBAC7E;YACF;QACF;QACAS,cAAc;YAAClB,YAAYmB,IAAI;SAAC;IAClC;AACF;AAEA,MAAMd,cAA6D;IACjEe,aAAa;IACbC,kBAAkB;AACpB;AAEA,OAAO,MAAMC,yBAAyBC,OAAOC,MAAM,CAAC;IAClDrB;IACAC;IACAC;AACF,GAAY;AAEZ;;;;;;;;;;;CAWC,GACD,OAAO,SAASM,8BAA8B,EAC5CS,WAAW,EACXC,gBAAgB,EACW;IAC3B,OAAO,eAAeI,gBACpBC,IAAoD;QAEpD,MAAML,iBAAiB;QAEvB,4EAA4E;QAC5E,MAAMM,SAASD,KAAKC,MAAM;QAE1B,MAAMC,OAAO,MAAM9B,kBAAkB+B,kBAAkB,CAAC;YACtD,MAAMT;YACN,CAAC,SAAS,CAAC;YACX,CAAC,MAAM,EAAEO,OAAOG,QAAQ,CAAC,CAAC,CAAC;SAC5B;QAED,OAAOF,KAAKG,MAAM;IACpB;AACF"}