@metamask/snaps-rpc-methods 5.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 (505) hide show
  1. package/CHANGELOG.md +21 -3
  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/chunk-RZDRHJXI.js.map +1 -0
  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/chunk-VZBSLVVA.js.map +1 -0
  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/types/endowments/caveats/generic.d.ts +19 -0
  372. package/dist/types/endowments/caveats/index.d.ts +2 -0
  373. package/dist/types/endowments/caveats/requestTime.d.ts +29 -0
  374. package/dist/types/endowments/cronjob.d.ts +51 -0
  375. package/dist/types/endowments/enum.d.ts +13 -0
  376. package/dist/types/endowments/ethereum-provider.d.ts +14 -0
  377. package/dist/types/endowments/home-page.d.ts +15 -0
  378. package/dist/types/endowments/index.d.ts +131 -0
  379. package/dist/types/endowments/keyring.d.ts +39 -0
  380. package/dist/types/endowments/lifecycle-hooks.d.ts +15 -0
  381. package/dist/types/endowments/name-lookup.d.ts +49 -0
  382. package/dist/types/endowments/network-access.d.ts +14 -0
  383. package/dist/types/endowments/rpc.d.ts +38 -0
  384. package/dist/types/endowments/signature-insight.d.ts +39 -0
  385. package/dist/types/endowments/transaction-insight.d.ts +39 -0
  386. package/dist/types/endowments/web-assembly.d.ts +14 -0
  387. package/dist/types/index.d.ts +4 -2
  388. package/dist/types/permissions.d.ts +16 -0
  389. package/dist/types/permitted/createInterface.d.ts +150 -0
  390. package/dist/types/permitted/getInterfaceState.d.ts +18 -0
  391. package/dist/types/permitted/handlers.d.ts +4 -1
  392. package/dist/types/permitted/index.d.ts +4 -1
  393. package/dist/types/permitted/updateInterface.d.ts +152 -0
  394. package/dist/types/restricted/dialog.d.ts +776 -14
  395. package/dist/utils.js +13 -0
  396. package/dist/utils.js.map +1 -0
  397. package/dist/utils.mjs +13 -0
  398. package/dist/utils.mjs.map +1 -0
  399. package/package.json +22 -19
  400. package/dist/cjs/index.js +0 -43
  401. package/dist/cjs/index.js.map +0 -1
  402. package/dist/cjs/permitted/getAllSnaps.js +0 -44
  403. package/dist/cjs/permitted/getAllSnaps.js.map +0 -1
  404. package/dist/cjs/permitted/getClientStatus.js +0 -40
  405. package/dist/cjs/permitted/getClientStatus.js.map +0 -1
  406. package/dist/cjs/permitted/getFile.js +0 -63
  407. package/dist/cjs/permitted/getFile.js.map +0 -1
  408. package/dist/cjs/permitted/getSnaps.js +0 -39
  409. package/dist/cjs/permitted/getSnaps.js.map +0 -1
  410. package/dist/cjs/permitted/handlers.js +0 -37
  411. package/dist/cjs/permitted/handlers.js.map +0 -1
  412. package/dist/cjs/permitted/index.js +0 -21
  413. package/dist/cjs/permitted/index.js.map +0 -1
  414. package/dist/cjs/permitted/invokeKeyring.js +0 -87
  415. package/dist/cjs/permitted/invokeKeyring.js.map +0 -1
  416. package/dist/cjs/permitted/invokeSnapSugar.js +0 -62
  417. package/dist/cjs/permitted/invokeSnapSugar.js.map +0 -1
  418. package/dist/cjs/permitted/middleware.js +0 -38
  419. package/dist/cjs/permitted/middleware.js.map +0 -1
  420. package/dist/cjs/permitted/requestSnaps.js +0 -123
  421. package/dist/cjs/permitted/requestSnaps.js.map +0 -1
  422. package/dist/cjs/restricted/caveats/index.js +0 -38
  423. package/dist/cjs/restricted/caveats/index.js.map +0 -1
  424. package/dist/cjs/restricted/caveats/permittedCoinTypes.js +0 -83
  425. package/dist/cjs/restricted/caveats/permittedCoinTypes.js.map +0 -1
  426. package/dist/cjs/restricted/caveats/permittedDerivationPaths.js +0 -67
  427. package/dist/cjs/restricted/caveats/permittedDerivationPaths.js.map +0 -1
  428. package/dist/cjs/restricted/caveats/snapIds.js +0 -59
  429. package/dist/cjs/restricted/caveats/snapIds.js.map +0 -1
  430. package/dist/cjs/restricted/dialog.js +0 -145
  431. package/dist/cjs/restricted/dialog.js.map +0 -1
  432. package/dist/cjs/restricted/getBip32Entropy.js +0 -76
  433. package/dist/cjs/restricted/getBip32Entropy.js.map +0 -1
  434. package/dist/cjs/restricted/getBip32PublicKey.js +0 -91
  435. package/dist/cjs/restricted/getBip44Entropy.js +0 -76
  436. package/dist/cjs/restricted/getBip44Entropy.js.map +0 -1
  437. package/dist/cjs/restricted/getEntropy.js +0 -76
  438. package/dist/cjs/restricted/getEntropy.js.map +0 -1
  439. package/dist/cjs/restricted/getLocale.js +0 -49
  440. package/dist/cjs/restricted/getLocale.js.map +0 -1
  441. package/dist/cjs/restricted/index.js +0 -59
  442. package/dist/cjs/restricted/index.js.map +0 -1
  443. package/dist/cjs/restricted/invokeSnap.js +0 -99
  444. package/dist/cjs/restricted/invokeSnap.js.map +0 -1
  445. package/dist/cjs/restricted/manageAccounts.js +0 -68
  446. package/dist/cjs/restricted/manageAccounts.js.map +0 -1
  447. package/dist/cjs/restricted/manageState.js +0 -208
  448. package/dist/cjs/restricted/manageState.js.map +0 -1
  449. package/dist/cjs/restricted/notify.js +0 -92
  450. package/dist/cjs/restricted/notify.js.map +0 -1
  451. package/dist/cjs/utils.js +0 -98
  452. package/dist/esm/index.js +0 -6
  453. package/dist/esm/index.js.map +0 -1
  454. package/dist/esm/permitted/getAllSnaps.js +0 -37
  455. package/dist/esm/permitted/getAllSnaps.js.map +0 -1
  456. package/dist/esm/permitted/getClientStatus.js +0 -32
  457. package/dist/esm/permitted/getClientStatus.js.map +0 -1
  458. package/dist/esm/permitted/getFile.js +0 -45
  459. package/dist/esm/permitted/getFile.js.map +0 -1
  460. package/dist/esm/permitted/getSnaps.js +0 -31
  461. package/dist/esm/permitted/getSnaps.js.map +0 -1
  462. package/dist/esm/permitted/handlers.js +0 -19
  463. package/dist/esm/permitted/handlers.js.map +0 -1
  464. package/dist/esm/permitted/index.js +0 -4
  465. package/dist/esm/permitted/index.js.map +0 -1
  466. package/dist/esm/permitted/invokeKeyring.js +0 -79
  467. package/dist/esm/permitted/invokeKeyring.js.map +0 -1
  468. package/dist/esm/permitted/invokeSnapSugar.js +0 -60
  469. package/dist/esm/permitted/invokeSnapSugar.js.map +0 -1
  470. package/dist/esm/permitted/middleware.js +0 -34
  471. package/dist/esm/permitted/middleware.js.map +0 -1
  472. package/dist/esm/permitted/requestSnaps.js +0 -118
  473. package/dist/esm/permitted/requestSnaps.js.map +0 -1
  474. package/dist/esm/restricted/caveats/index.js +0 -20
  475. package/dist/esm/restricted/caveats/index.js.map +0 -1
  476. package/dist/esm/restricted/caveats/permittedCoinTypes.js +0 -77
  477. package/dist/esm/restricted/caveats/permittedCoinTypes.js.map +0 -1
  478. package/dist/esm/restricted/caveats/permittedDerivationPaths.js +0 -64
  479. package/dist/esm/restricted/caveats/permittedDerivationPaths.js.map +0 -1
  480. package/dist/esm/restricted/caveats/snapIds.js +0 -50
  481. package/dist/esm/restricted/caveats/snapIds.js.map +0 -1
  482. package/dist/esm/restricted/dialog.js +0 -138
  483. package/dist/esm/restricted/dialog.js.map +0 -1
  484. package/dist/esm/restricted/getBip32Entropy.js +0 -67
  485. package/dist/esm/restricted/getBip32Entropy.js.map +0 -1
  486. package/dist/esm/restricted/getBip32PublicKey.js +0 -79
  487. package/dist/esm/restricted/getBip32PublicKey.js.map +0 -1
  488. package/dist/esm/restricted/getBip44Entropy.js +0 -69
  489. package/dist/esm/restricted/getBip44Entropy.js.map +0 -1
  490. package/dist/esm/restricted/getEntropy.js +0 -58
  491. package/dist/esm/restricted/getEntropy.js.map +0 -1
  492. package/dist/esm/restricted/getLocale.js +0 -42
  493. package/dist/esm/restricted/getLocale.js.map +0 -1
  494. package/dist/esm/restricted/index.js +0 -27
  495. package/dist/esm/restricted/index.js.map +0 -1
  496. package/dist/esm/restricted/invokeSnap.js +0 -89
  497. package/dist/esm/restricted/invokeSnap.js.map +0 -1
  498. package/dist/esm/restricted/manageAccounts.js +0 -60
  499. package/dist/esm/restricted/manageAccounts.js.map +0 -1
  500. package/dist/esm/restricted/manageState.js +0 -225
  501. package/dist/esm/restricted/manageState.js.map +0 -1
  502. package/dist/esm/restricted/notify.js +0 -92
  503. package/dist/esm/restricted/notify.js.map +0 -1
  504. package/dist/esm/utils.js +0 -124
  505. package/dist/esm/utils.js.map +0 -1
@@ -0,0 +1,151 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/restricted/dialog.ts
2
+ var _permissioncontroller = require('@metamask/permission-controller');
3
+ var _rpcerrors = require('@metamask/rpc-errors');
4
+
5
+
6
+
7
+
8
+
9
+ var _snapssdk = require('@metamask/snaps-sdk');
10
+ var _snapsutils = require('@metamask/snaps-utils');
11
+ var _utils = require('@metamask/utils');
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+ var _superstruct = require('superstruct');
21
+ var methodName = "snap_dialog";
22
+ var PlaceholderStruct = _superstruct.optional.call(void 0, _superstruct.size.call(void 0, _superstruct.string.call(void 0, ), 1, 40));
23
+ var specificationBuilder = ({
24
+ allowedCaveats = null,
25
+ methodHooks: methodHooks2
26
+ }) => {
27
+ return {
28
+ permissionType: _permissioncontroller.PermissionType.RestrictedMethod,
29
+ targetName: methodName,
30
+ allowedCaveats,
31
+ methodImplementation: getDialogImplementation(methodHooks2),
32
+ subjectTypes: [_permissioncontroller.SubjectType.Snap]
33
+ };
34
+ };
35
+ var methodHooks = {
36
+ showDialog: true,
37
+ createInterface: true,
38
+ getInterface: true
39
+ };
40
+ var dialogBuilder = Object.freeze({
41
+ targetName: methodName,
42
+ specificationBuilder,
43
+ methodHooks
44
+ });
45
+ var BaseParamsStruct = _superstruct.type.call(void 0, {
46
+ type: _superstruct.enums.call(void 0, [_snapssdk.DialogType.Alert, _snapssdk.DialogType.Confirmation, _snapssdk.DialogType.Prompt])
47
+ });
48
+ var AlertParametersWithContentStruct = _superstruct.object.call(void 0, {
49
+ type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Alert),
50
+ content: _snapssdk.ComponentStruct
51
+ });
52
+ var AlertParametersWithIdStruct = _superstruct.object.call(void 0, {
53
+ type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Alert),
54
+ id: _superstruct.string.call(void 0, )
55
+ });
56
+ var AlertParametersStruct = _snapssdk.union.call(void 0, [
57
+ AlertParametersWithContentStruct,
58
+ AlertParametersWithIdStruct
59
+ ]);
60
+ var ConfirmationParametersWithContentStruct = _superstruct.object.call(void 0, {
61
+ type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Confirmation),
62
+ content: _snapssdk.ComponentStruct
63
+ });
64
+ var ConfirmationParametersWithIdStruct = _superstruct.object.call(void 0, {
65
+ type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Confirmation),
66
+ id: _superstruct.string.call(void 0, )
67
+ });
68
+ var ConfirmationParametersStruct = _snapssdk.union.call(void 0, [
69
+ ConfirmationParametersWithContentStruct,
70
+ ConfirmationParametersWithIdStruct
71
+ ]);
72
+ var PromptParametersWithContentStruct = _superstruct.object.call(void 0, {
73
+ type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Prompt),
74
+ content: _snapssdk.ComponentStruct,
75
+ placeholder: PlaceholderStruct
76
+ });
77
+ var PromptParametersWithIdStruct = _superstruct.object.call(void 0, {
78
+ type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Prompt),
79
+ id: _superstruct.string.call(void 0, ),
80
+ placeholder: PlaceholderStruct
81
+ });
82
+ var PromptParametersStruct = _snapssdk.union.call(void 0, [
83
+ PromptParametersWithContentStruct,
84
+ PromptParametersWithIdStruct
85
+ ]);
86
+ var DialogParametersStruct = _snapssdk.union.call(void 0, [
87
+ AlertParametersStruct,
88
+ ConfirmationParametersStruct,
89
+ PromptParametersStruct
90
+ ]);
91
+ var structs = {
92
+ [_snapssdk.DialogType.Alert]: AlertParametersStruct,
93
+ [_snapssdk.DialogType.Confirmation]: ConfirmationParametersStruct,
94
+ [_snapssdk.DialogType.Prompt]: PromptParametersStruct
95
+ };
96
+ function getDialogImplementation({
97
+ showDialog,
98
+ createInterface,
99
+ getInterface
100
+ }) {
101
+ return async function dialogImplementation(args) {
102
+ const {
103
+ params,
104
+ context: { origin }
105
+ } = args;
106
+ const validatedType = getValidatedType(params);
107
+ const validatedParams = getValidatedParams(params, structs[validatedType]);
108
+ const placeholder = validatedParams.type === _snapssdk.DialogType.Prompt ? validatedParams.placeholder : void 0;
109
+ if (_utils.hasProperty.call(void 0, validatedParams, "content")) {
110
+ const id = await createInterface(
111
+ origin,
112
+ validatedParams.content
113
+ );
114
+ return showDialog(origin, validatedType, id, placeholder);
115
+ }
116
+ try {
117
+ getInterface(origin, validatedParams.id);
118
+ } catch (error) {
119
+ throw _rpcerrors.rpcErrors.invalidParams({
120
+ message: `Invalid params: ${error.message}`
121
+ });
122
+ }
123
+ return showDialog(origin, validatedType, validatedParams.id, placeholder);
124
+ };
125
+ }
126
+ function getValidatedType(params) {
127
+ try {
128
+ return _superstruct.create.call(void 0, params, BaseParamsStruct).type;
129
+ } catch (error) {
130
+ throw _rpcerrors.rpcErrors.invalidParams({
131
+ message: `The "type" property must be one of: ${Object.values(
132
+ _snapssdk.DialogType
133
+ ).join(", ")}.`
134
+ });
135
+ }
136
+ }
137
+ function getValidatedParams(params, struct) {
138
+ try {
139
+ return _snapsutils.createUnion.call(void 0, params, struct, "type");
140
+ } catch (error) {
141
+ throw _rpcerrors.rpcErrors.invalidParams({
142
+ message: `Invalid params: ${error.message}`
143
+ });
144
+ }
145
+ }
146
+
147
+
148
+
149
+
150
+ exports.dialogBuilder = dialogBuilder; exports.getDialogImplementation = getDialogImplementation;
151
+ //# sourceMappingURL=chunk-3FKD2O7M.js.map
@@ -0,0 +1 @@
1
+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mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,WAAO,WAAW,QAAQ,eAAe,gBAAgB,IAAI,WAAW;AAAA,EAC1E;AACF;AASA,SAAS,iBAAiB,QAA6B;AACrD,MAAI;AACF,WAAO,OAAO,QAAQ,gBAAgB,EAAE;AAAA,EAC1C,SAAS,OAAO;AACd,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS,uCAAuC,OAAO;AAAA,QACrD;AAAA,MACF,EAAE,KAAK,IAAI,CAAC;AAAA,IACd,CAAC;AAAA,EACH;AACF;AAUA,SAAS,mBACP,QACA,QACkB;AAClB,MAAI;AACF,WAAO,YAAY,QAAQ,QAAQ,MAAM;AAAA,EAC3C,SAAS,OAAO;AACd,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,IAC3C,CAAC;AAAA,EACH;AACF","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"]}
@@ -0,0 +1,105 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkUYSXSKMLjs = require('./chunk-UYSXSKML.js');
4
+
5
+ // src/permitted/requestSnaps.ts
6
+ var _rpcerrors = require('@metamask/rpc-errors');
7
+
8
+
9
+
10
+ var _snapsutils = require('@metamask/snaps-utils');
11
+ var _utils = require('@metamask/utils');
12
+ var hookNames = {
13
+ installSnaps: true,
14
+ requestPermissions: true,
15
+ getPermissions: true
16
+ };
17
+ var requestSnapsHandler = {
18
+ methodNames: ["wallet_requestSnaps"],
19
+ implementation: requestSnapsImplementation,
20
+ hookNames
21
+ };
22
+ function hasRequestedSnaps(existingPermissions, requestedSnaps) {
23
+ const snapIdCaveat = _optionalChain([existingPermissions, 'access', _ => _[_chunkUYSXSKMLjs.WALLET_SNAP_PERMISSION_KEY], 'optionalAccess', _2 => _2.caveats, 'optionalAccess', _3 => _3.find, 'call', _4 => _4(
24
+ (caveat) => caveat.type === _snapsutils.SnapCaveatType.SnapIds
25
+ )]);
26
+ const permittedSnaps = _optionalChain([snapIdCaveat, 'optionalAccess', _5 => _5.value]);
27
+ if (_utils.isObject.call(void 0, permittedSnaps)) {
28
+ return Object.keys(requestedSnaps).every(
29
+ (requestedSnap) => _utils.hasProperty.call(void 0, permittedSnaps, requestedSnap)
30
+ );
31
+ }
32
+ return false;
33
+ }
34
+ function getSnapPermissionsRequest(existingPermissions, requestedPermissions) {
35
+ _snapsutils.verifyRequestedSnapPermissions.call(void 0, requestedPermissions);
36
+ if (!existingPermissions[_chunkUYSXSKMLjs.WALLET_SNAP_PERMISSION_KEY]) {
37
+ return requestedPermissions;
38
+ }
39
+ const snapIdCaveat = _optionalChain([existingPermissions, 'access', _6 => _6[_chunkUYSXSKMLjs.WALLET_SNAP_PERMISSION_KEY], 'access', _7 => _7.caveats, 'optionalAccess', _8 => _8.find, 'call', _9 => _9(
40
+ (caveat) => caveat.type === _snapsutils.SnapCaveatType.SnapIds
41
+ )]);
42
+ const permittedSnaps = _nullishCoalesce(_optionalChain([snapIdCaveat, 'optionalAccess', _10 => _10.value]), () => ( {}));
43
+ const requestedSnaps = requestedPermissions[_chunkUYSXSKMLjs.WALLET_SNAP_PERMISSION_KEY].caveats[0].value;
44
+ const snapIdSet = /* @__PURE__ */ new Set([
45
+ ...Object.keys(permittedSnaps),
46
+ ...Object.keys(requestedSnaps)
47
+ ]);
48
+ const mergedCaveatValue = [...snapIdSet].reduce(
49
+ (request, snapId) => {
50
+ request[snapId] = _nullishCoalesce(requestedSnaps[snapId], () => ( permittedSnaps[snapId]));
51
+ return request;
52
+ },
53
+ {}
54
+ );
55
+ requestedPermissions[_chunkUYSXSKMLjs.WALLET_SNAP_PERMISSION_KEY].caveats[0].value = mergedCaveatValue;
56
+ return requestedPermissions;
57
+ }
58
+ async function requestSnapsImplementation(req, res, _next, end, { installSnaps, requestPermissions, getPermissions }) {
59
+ const requestedSnaps = req.params;
60
+ if (!_utils.isObject.call(void 0, requestedSnaps)) {
61
+ return end(
62
+ _rpcerrors.rpcErrors.invalidParams({
63
+ message: '"params" must be an object.'
64
+ })
65
+ );
66
+ }
67
+ try {
68
+ if (Object.keys(requestedSnaps).length === 0) {
69
+ return end(
70
+ _rpcerrors.rpcErrors.invalidParams({
71
+ message: "Request must have at least one requested snap."
72
+ })
73
+ );
74
+ }
75
+ const requestedPermissions = {
76
+ [_chunkUYSXSKMLjs.WALLET_SNAP_PERMISSION_KEY]: {
77
+ caveats: [{ type: _snapsutils.SnapCaveatType.SnapIds, value: requestedSnaps }]
78
+ }
79
+ };
80
+ const existingPermissions = await getPermissions();
81
+ if (!existingPermissions) {
82
+ const [, metadata] = await requestPermissions(requestedPermissions);
83
+ res.result = metadata.data[_chunkUYSXSKMLjs.WALLET_SNAP_PERMISSION_KEY];
84
+ } else if (hasRequestedSnaps(existingPermissions, requestedSnaps)) {
85
+ res.result = await installSnaps(requestedSnaps);
86
+ } else {
87
+ const mergedPermissionsRequest = getSnapPermissionsRequest(
88
+ existingPermissions,
89
+ requestedPermissions
90
+ );
91
+ const [, metadata] = await requestPermissions(mergedPermissionsRequest);
92
+ res.result = metadata.data[_chunkUYSXSKMLjs.WALLET_SNAP_PERMISSION_KEY];
93
+ }
94
+ } catch (error) {
95
+ res.error = error;
96
+ }
97
+ return end();
98
+ }
99
+
100
+
101
+
102
+
103
+
104
+ exports.requestSnapsHandler = requestSnapsHandler; exports.hasRequestedSnaps = hasRequestedSnaps; exports.getSnapPermissionsRequest = getSnapPermissionsRequest;
105
+ //# sourceMappingURL=chunk-4ALFLY5D.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/permitted/requestSnaps.ts"],"names":[],"mappings":";;;;;AAOA,SAAS,iBAAiB;AAM1B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAMP,SAAS,aAAa,gBAAgB;AAKtC,IAAM,YAAkD;AAAA,EACtD,cAAc;AAAA,EACd,oBAAoB;AAAA,EACpB,gBAAgB;AAClB;AAKO,IAAM,sBAIT;AAAA,EACF,aAAa,CAAC,qBAAqB;AAAA,EACnC,gBAAgB;AAAA,EAChB;AACF;AA0CO,SAAS,kBACd,qBACA,gBACS;AACT,QAAM,eAAe,oBACnB,0BACF,GAAG,SAAS;AAAA,IACV,CAAC,WAAiC,OAAO,SAAS,eAAe;AAAA,EACnE;AAEA,QAAM,iBAAiB,cAAc;AACrC,MAAI,SAAS,cAAc,GAAG;AAC5B,WAAO,OAAO,KAAK,cAAc,EAAE;AAAA,MAAM,CAAC,kBACxC,YAAY,gBAAgB,aAAa;AAAA,IAC3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nE;AAAA,IACF;AACA,UAAM,sBAAsB,MAAM,eAAe;AAEjD,QAAI,CAAC,qBAAqB;AACxB,YAAM,CAAC,EAAE,QAAQ,IAAI,MAAM,mBAAmB,oBAAoB;AAClE,UAAI,SAAS,SAAS,KACpB,0BACF;AAAA,IACF,WAAW,kBAAkB,qBAAqB,cAAc,GAAG;AACjE,UAAI,SAAS,MAAM,aAAa,cAAc;AAAA,IAChD,OAAO;AACL,YAAM,2BAA2B;AAAA,QAC/B;AAAA,QACA;AAAA,MACF;AAEA,YAAM,CAAC,EAAE,QAAQ,IAAI,MAAM,mBAAmB,wBAAwB;AACtE,UAAI,SAAS,SAAS,KACpB,0BACF;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,QAAI,QAAQ;AAAA,EACd;AAEA,SAAO,IAAI;AACb","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type {\n PermissionConstraint,\n RequestedPermissions,\n Caveat,\n PermittedHandlerExport,\n} from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n RequestSnapsParams,\n RequestSnapsResult,\n} from '@metamask/snaps-sdk';\nimport type { SnapsPermissionRequest } from '@metamask/snaps-utils';\nimport {\n SnapCaveatType,\n verifyRequestedSnapPermissions,\n} from '@metamask/snaps-utils';\nimport type {\n JsonRpcRequest,\n PendingJsonRpcResponse,\n Json,\n} from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n\nimport { WALLET_SNAP_PERMISSION_KEY } from '../restricted/invokeSnap';\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<RequestSnapsHooks> = {\n installSnaps: true,\n requestPermissions: true,\n getPermissions: true,\n};\n\n/**\n * `wallet_requestSnaps` installs the requested Snaps and requests permission to use them if necessary.\n */\nexport const requestSnapsHandler: PermittedHandlerExport<\n RequestSnapsHooks,\n RequestSnapsParams,\n RequestSnapsResult\n> = {\n methodNames: ['wallet_requestSnaps'],\n implementation: requestSnapsImplementation,\n hookNames,\n};\n\nexport type RequestSnapsHooks = {\n /**\n * Installs the requested snaps if they are permitted.\n */\n installSnaps: (\n requestedSnaps: RequestSnapsParams,\n ) => Promise<RequestSnapsResult>;\n\n /**\n * Initiates a permission request for the requesting origin.\n *\n * @returns The result of the permissions request.\n */\n requestPermissions: (\n permissions: RequestedPermissions,\n ) => Promise<\n [\n Record<string, PermissionConstraint>,\n { data: Record<string, unknown>; id: string; origin: string },\n ]\n >;\n\n /**\n * Gets the current permissions for the requesting origin.\n *\n * @returns The current permissions of the requesting origin.\n */\n getPermissions: () => Promise<\n Record<string, PermissionConstraint> | undefined\n >;\n};\n\n/**\n * Checks whether an origin has existing `wallet_snap` permission and\n * whether or not it has the requested snapIds caveat.\n *\n * @param existingPermissions - The existing permissions for the origin.\n * @param requestedSnaps - The requested snaps.\n * @returns True if the existing permissions satisfy the requested snaps, otherwise false.\n */\nexport function hasRequestedSnaps(\n existingPermissions: Record<string, PermissionConstraint>,\n requestedSnaps: Record<string, unknown>,\n): boolean {\n const snapIdCaveat = existingPermissions[\n WALLET_SNAP_PERMISSION_KEY\n ]?.caveats?.find(\n (caveat: Caveat<string, Json>) => caveat.type === SnapCaveatType.SnapIds,\n );\n\n const permittedSnaps = snapIdCaveat?.value;\n if (isObject(permittedSnaps)) {\n return Object.keys(requestedSnaps).every((requestedSnap) =>\n hasProperty(permittedSnaps, requestedSnap),\n );\n }\n return false;\n}\n\n/**\n * Constructs a valid permission request with merged caveats based on existing permissions\n * and the requested snaps.\n *\n * @param existingPermissions - The existing permissions for the origin.\n * @param requestedPermissions - The permission request passed into `requestPermissions`.\n * @returns `requestedPermissions`.\n */\nexport function getSnapPermissionsRequest(\n existingPermissions: Record<string, PermissionConstraint>,\n requestedPermissions: unknown,\n): SnapsPermissionRequest {\n verifyRequestedSnapPermissions(requestedPermissions);\n\n if (!existingPermissions[WALLET_SNAP_PERMISSION_KEY]) {\n return requestedPermissions;\n }\n\n const snapIdCaveat = existingPermissions[\n WALLET_SNAP_PERMISSION_KEY\n ].caveats?.find(\n (caveat: Caveat<string, Json>) => caveat.type === SnapCaveatType.SnapIds,\n );\n\n const permittedSnaps = (snapIdCaveat?.value as Record<string, Json>) ?? {};\n\n const requestedSnaps =\n requestedPermissions[WALLET_SNAP_PERMISSION_KEY].caveats[0].value;\n\n const snapIdSet = new Set([\n ...Object.keys(permittedSnaps),\n ...Object.keys(requestedSnaps),\n ]);\n\n const mergedCaveatValue = [...snapIdSet].reduce<Record<string, Json>>(\n (request, snapId) => {\n request[snapId] = requestedSnaps[snapId] ?? permittedSnaps[snapId];\n return request;\n },\n {},\n );\n\n requestedPermissions[WALLET_SNAP_PERMISSION_KEY].caveats[0].value =\n mergedCaveatValue;\n\n return requestedPermissions;\n}\n\n/**\n * The `wallet_requestSnaps` method implementation.\n * Tries to install the requested snaps and adds them to the JSON-RPC response.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.installSnaps - A function that tries to install a given snap, prompting the user if necessary.\n * @param hooks.requestPermissions - A function that requests permissions on\n * behalf of a subject.\n * @param hooks.getPermissions - A function that gets the current permissions.\n * @returns A promise that resolves once the JSON-RPC response has been modified.\n * @throws If the params are invalid.\n */\nasync function requestSnapsImplementation(\n req: JsonRpcRequest<RequestSnapsParams>,\n res: PendingJsonRpcResponse<RequestSnapsResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { installSnaps, requestPermissions, getPermissions }: RequestSnapsHooks,\n): Promise<void> {\n const requestedSnaps = req.params;\n if (!isObject(requestedSnaps)) {\n return end(\n rpcErrors.invalidParams({\n message: '\"params\" must be an object.',\n }),\n );\n }\n\n try {\n if (Object.keys(requestedSnaps).length === 0) {\n return end(\n rpcErrors.invalidParams({\n message: 'Request must have at least one requested snap.',\n }),\n );\n }\n\n const requestedPermissions = {\n [WALLET_SNAP_PERMISSION_KEY]: {\n caveats: [{ type: SnapCaveatType.SnapIds, value: requestedSnaps }],\n },\n } as RequestedPermissions;\n const existingPermissions = await getPermissions();\n\n if (!existingPermissions) {\n const [, metadata] = await requestPermissions(requestedPermissions);\n res.result = metadata.data[\n WALLET_SNAP_PERMISSION_KEY\n ] as RequestSnapsResult;\n } else if (hasRequestedSnaps(existingPermissions, requestedSnaps)) {\n res.result = await installSnaps(requestedSnaps);\n } else {\n const mergedPermissionsRequest = getSnapPermissionsRequest(\n existingPermissions,\n requestedPermissions,\n );\n\n const [, metadata] = await requestPermissions(mergedPermissionsRequest);\n res.result = metadata.data[\n WALLET_SNAP_PERMISSION_KEY\n ] as RequestSnapsResult;\n }\n } catch (error) {\n res.error = error;\n }\n\n return end();\n}\n"]}
@@ -0,0 +1,67 @@
1
+ // src/restricted/caveats/permittedDerivationPaths.ts
2
+ import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
3
+ import {
4
+ SnapCaveatType,
5
+ Bip32EntropyStruct,
6
+ isEqual
7
+ } from "@metamask/snaps-utils";
8
+ import { assertStruct } from "@metamask/utils";
9
+ import { array, size, type } from "superstruct";
10
+ function permittedDerivationPathsCaveatMapper(value) {
11
+ return {
12
+ caveats: [
13
+ {
14
+ type: SnapCaveatType.PermittedDerivationPaths,
15
+ value
16
+ }
17
+ ]
18
+ };
19
+ }
20
+ function validateBIP32Path(value) {
21
+ assertStruct(
22
+ value,
23
+ Bip32EntropyStruct,
24
+ "Invalid BIP-32 entropy path definition",
25
+ rpcErrors.invalidParams
26
+ );
27
+ }
28
+ function validateBIP32CaveatPaths(caveat) {
29
+ assertStruct(
30
+ caveat,
31
+ type({ value: size(array(Bip32EntropyStruct), 1, Infinity) }),
32
+ "Invalid BIP-32 entropy caveat",
33
+ rpcErrors.internal
34
+ );
35
+ }
36
+ var PermittedDerivationPathsCaveatSpecification = {
37
+ [SnapCaveatType.PermittedDerivationPaths]: Object.freeze({
38
+ type: SnapCaveatType.PermittedDerivationPaths,
39
+ decorator: (method, caveat) => {
40
+ return async (args) => {
41
+ const { params } = args;
42
+ validateBIP32Path(params);
43
+ const path = caveat.value.find(
44
+ (caveatPath) => isEqual(
45
+ params.path.slice(0, caveatPath.path.length),
46
+ caveatPath.path
47
+ ) && caveatPath.curve === params.curve
48
+ );
49
+ if (!path) {
50
+ throw providerErrors.unauthorized({
51
+ message: "The requested path is not permitted. Allowed paths must be specified in the snap manifest."
52
+ });
53
+ }
54
+ return await method(args);
55
+ };
56
+ },
57
+ validator: (caveat) => validateBIP32CaveatPaths(caveat)
58
+ })
59
+ };
60
+
61
+ export {
62
+ permittedDerivationPathsCaveatMapper,
63
+ validateBIP32Path,
64
+ validateBIP32CaveatPaths,
65
+ PermittedDerivationPathsCaveatSpecification
66
+ };
67
+ //# sourceMappingURL=chunk-4Z4X6EJP.mjs.map
@@ -0,0 +1 @@
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"],"mappings":";AAKA,SAAS,gBAAgB,iBAAiB;AAE1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,oBAAoB;AAC7B,SAAS,OAAO,MAAM,YAAY;AAU3B,SAAS,qCACd,OACuC;AACvC,SAAO;AAAA,IACL,SAAS;AAAA,MACP;AAAA,QACE,MAAM,eAAe;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAWO,SAAS,kBACd,OAC+B;AAC/B;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EACZ;AACF;AASO,SAAS,yBACd,QACkD;AAClD;AAAA,IACE;AAAA,IACA,KAAK,EAAE,OAAO,KAAK,MAAM,kBAAkB,GAAG,GAAG,QAAQ,EAAE,CAAC;AAAA,IAC5D;AAAA,IACA,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,8CAGT;AAAA,EACF,CAAC,eAAe,wBAAwB,GAAG,OAAO,OAAO;AAAA,IACvD,MAAM,eAAe;AAAA,IACrB,WAAW,CACT,QACA,WACG;AACH,aAAO,OAAO,SAAS;AACrB,cAAM,EAAE,OAAO,IAAI;AACnB,0BAAkB,MAAM;AAExB,cAAM,OAAO,OAAO,MAAM;AAAA,UACxB,CAAC,eACC;AAAA,YACE,OAAO,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM;AAAA,YAC3C,WAAW;AAAA,UACb,KAAK,WAAW,UAAU,OAAO;AAAA,QACrC;AAEA,YAAI,CAAC,MAAM;AACT,gBAAM,eAAe,aAAa;AAAA,YAChC,SACE;AAAA,UACJ,CAAC;AAAA,QACH;AAEA,eAAO,MAAM,OAAO,IAAI;AAAA,MAC1B;AAAA,IACF;AAAA,IACA,WAAW,CAAC,WAAW,yBAAyB,MAAM;AAAA,EACxD,CAAC;AACH;","names":[]}
@@ -0,0 +1,57 @@
1
+ import {
2
+ getNode
3
+ } from "./chunk-DR63Z4PV.mjs";
4
+
5
+ // src/restricted/getBip32Entropy.ts
6
+ import { PermissionType, SubjectType } from "@metamask/permission-controller";
7
+ import { rpcErrors } from "@metamask/rpc-errors";
8
+ import { SnapCaveatType } from "@metamask/snaps-utils";
9
+ import { assert } from "@metamask/utils";
10
+ var targetName = "snap_getBip32Entropy";
11
+ var specificationBuilder = ({ methodHooks: methodHooks2 }) => {
12
+ return {
13
+ permissionType: PermissionType.RestrictedMethod,
14
+ targetName,
15
+ allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],
16
+ methodImplementation: getBip32EntropyImplementation(methodHooks2),
17
+ validator: ({ caveats }) => {
18
+ if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.PermittedDerivationPaths) {
19
+ throw rpcErrors.invalidParams({
20
+ message: `Expected a single "${SnapCaveatType.PermittedDerivationPaths}" caveat.`
21
+ });
22
+ }
23
+ },
24
+ subjectTypes: [SubjectType.Snap]
25
+ };
26
+ };
27
+ var methodHooks = {
28
+ getMnemonic: true,
29
+ getUnlockPromise: true
30
+ };
31
+ var getBip32EntropyBuilder = Object.freeze({
32
+ targetName,
33
+ specificationBuilder,
34
+ methodHooks
35
+ });
36
+ function getBip32EntropyImplementation({
37
+ getMnemonic,
38
+ getUnlockPromise
39
+ }) {
40
+ return async function getBip32Entropy(args) {
41
+ await getUnlockPromise(true);
42
+ const { params } = args;
43
+ assert(params);
44
+ const node = await getNode({
45
+ curve: params.curve,
46
+ path: params.path,
47
+ secretRecoveryPhrase: await getMnemonic()
48
+ });
49
+ return node.toJSON();
50
+ };
51
+ }
52
+
53
+ export {
54
+ getBip32EntropyBuilder,
55
+ getBip32EntropyImplementation
56
+ };
57
+ //# sourceMappingURL=chunk-5HIIIAIS.mjs.map
@@ -0,0 +1 @@
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"],"mappings":";;;;;AAMA,SAAS,gBAAgB,mBAAmB;AAC5C,SAAS,iBAAiB;AAK1B,SAAS,sBAAsB;AAE/B,SAAS,cAAc;AAKvB,IAAM,aAAa;AAqCnB,IAAM,uBAIF,CAAC,EAAE,aAAAA,aAAY,MAAkD;AACnE,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B;AAAA,IACA,gBAAgB,CAAC,eAAe,wBAAwB;AAAA,IACxD,sBAAsB,8BAA8BA,YAAW;AAAA,IAC/D,WAAW,CAAC,EAAE,QAAQ,MAAM;AAC1B,UACE,SAAS,WAAW,KACpB,QAAQ,CAAC,EAAE,SAAS,eAAe,0BACnC;AACA,cAAM,UAAU,cAAc;AAAA,UAC5B,SAAS,sBAAsB,eAAe,wBAAwB;AAAA,QACxE,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAEA,IAAM,cAA6D;AAAA,EACjE,aAAa;AAAA,EACb,kBAAkB;AACpB;AAEO,IAAM,yBAAyB,OAAO,OAAO;AAAA,EAClD;AAAA,EACA;AAAA,EACA;AACF,CAAU;AAYH,SAAS,8BAA8B;AAAA,EAC5C;AAAA,EACA;AACF,GAA+B;AAC7B,SAAO,eAAe,gBACpB,MACgC;AAChC,UAAM,iBAAiB,IAAI;AAE3B,UAAM,EAAE,OAAO,IAAI;AACnB,WAAO,MAAM;AAEb,UAAM,OAAO,MAAM,QAAQ;AAAA,MACzB,OAAO,OAAO;AAAA,MACd,MAAM,OAAO;AAAA,MACb,sBAAsB,MAAM,YAAY;AAAA,IAC1C,CAAC;AAED,WAAO,KAAK,OAAO;AAAA,EACrB;AACF;","names":["methodHooks"]}
@@ -0,0 +1,83 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils.ts
2
+ var _keytree = require('@metamask/key-tree');
3
+
4
+
5
+
6
+
7
+
8
+
9
+ var _utils = require('@metamask/utils');
10
+ var _sha3 = require('@noble/hashes/sha3');
11
+ var HARDENED_VALUE = 2147483648;
12
+ function selectHooks(hooks, hookNames) {
13
+ if (hookNames) {
14
+ return Object.keys(hookNames).reduce(
15
+ (hookSubset, _hookName) => {
16
+ const hookName = _hookName;
17
+ hookSubset[hookName] = hooks[hookName];
18
+ return hookSubset;
19
+ },
20
+ {}
21
+ );
22
+ }
23
+ return void 0;
24
+ }
25
+ function getDerivationPathArray(hash) {
26
+ const array = [];
27
+ const view = _utils.createDataView.call(void 0, hash);
28
+ for (let index = 0; index < 8; index++) {
29
+ const uint32 = view.getUint32(index * 4);
30
+ const pathIndex = (uint32 | HARDENED_VALUE) >>> 0;
31
+ array.push(`bip32:${pathIndex - HARDENED_VALUE}'`);
32
+ }
33
+ return array;
34
+ }
35
+ async function deriveEntropy({
36
+ input,
37
+ salt = "",
38
+ mnemonicPhrase,
39
+ magic
40
+ }) {
41
+ const inputBytes = _utils.stringToBytes.call(void 0, input);
42
+ const saltBytes = _utils.stringToBytes.call(void 0, salt);
43
+ const hash = _sha3.keccak_256.call(void 0, _utils.concatBytes.call(void 0, [inputBytes, _sha3.keccak_256.call(void 0, saltBytes)]));
44
+ const computedDerivationPath = getDerivationPathArray(hash);
45
+ const { privateKey } = await _keytree.SLIP10Node.fromDerivationPath({
46
+ derivationPath: [
47
+ mnemonicPhrase,
48
+ `bip32:${magic}`,
49
+ ...computedDerivationPath
50
+ ],
51
+ curve: "secp256k1"
52
+ });
53
+ _utils.assert.call(void 0, privateKey, "Failed to derive the entropy.");
54
+ return _utils.add0x.call(void 0, privateKey);
55
+ }
56
+ function getPathPrefix(curve) {
57
+ if (curve === "secp256k1") {
58
+ return "bip32";
59
+ }
60
+ return "slip10";
61
+ }
62
+ async function getNode({
63
+ curve,
64
+ secretRecoveryPhrase,
65
+ path
66
+ }) {
67
+ const prefix = getPathPrefix(curve);
68
+ return await _keytree.SLIP10Node.fromDerivationPath({
69
+ curve,
70
+ derivationPath: [
71
+ secretRecoveryPhrase,
72
+ ...path.slice(1).map((index) => `${prefix}:${index}`)
73
+ ]
74
+ });
75
+ }
76
+
77
+
78
+
79
+
80
+
81
+
82
+ exports.selectHooks = selectHooks; exports.deriveEntropy = deriveEntropy; exports.getPathPrefix = getPathPrefix; exports.getNode = getNode;
83
+ //# sourceMappingURL=chunk-632BZ6JY.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import type {\n HardenedBIP32Node,\n BIP32Node,\n SLIP10PathNode,\n} from '@metamask/key-tree';\nimport { SLIP10Node } from '@metamask/key-tree';\nimport type { MagicValue } from '@metamask/snaps-utils';\nimport type { Hex } from '@metamask/utils';\nimport {\n add0x,\n assert,\n concatBytes,\n createDataView,\n stringToBytes,\n} from '@metamask/utils';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\n\nconst HARDENED_VALUE = 0x80000000;\n\n/**\n * Maps an interface with method hooks to an object, using the keys of the\n * interface, and `true` as value. This ensures that the `methodHooks` object\n * has the same values as the interface.\n */\nexport type MethodHooksObject<HooksType extends Record<string, unknown>> = {\n [Key in keyof HooksType]: true;\n};\n\n/**\n * Returns the subset of the specified `hooks` that are included in the\n * `hookNames` object. This is a Principle of Least Authority (POLA) measure\n * to ensure that each RPC method implementation only has access to the\n * API \"hooks\" it needs to do its job.\n *\n * @param hooks - The hooks to select from.\n * @param hookNames - The names of the hooks to select.\n * @returns The selected hooks.\n * @template Hooks - The hooks to select from.\n * @template HookName - The names of the hooks to select.\n */\nexport function selectHooks<\n Hooks extends Record<string, unknown>,\n HookName extends keyof Hooks,\n>(\n hooks: Hooks,\n hookNames?: Record<HookName, boolean>,\n): Pick<Hooks, HookName> | undefined {\n if (hookNames) {\n return Object.keys(hookNames).reduce<Partial<Pick<Hooks, HookName>>>(\n (hookSubset, _hookName) => {\n const hookName = _hookName as HookName;\n hookSubset[hookName] = hooks[hookName];\n return hookSubset;\n },\n {},\n ) as Pick<Hooks, HookName>;\n }\n return undefined;\n}\n\n/**\n * Get a BIP-32 derivation path array from a hash, which is compatible with\n * `@metamask/key-tree`. The hash is assumed to be 32 bytes long.\n *\n * @param hash - The hash to derive indices from.\n * @returns The derived indices as a {@link HardenedBIP32Node} array.\n */\nfunction getDerivationPathArray(hash: Uint8Array): HardenedBIP32Node[] {\n const array: HardenedBIP32Node[] = [];\n const view = createDataView(hash);\n\n for (let index = 0; index < 8; index++) {\n const uint32 = view.getUint32(index * 4);\n\n // This is essentially `index | 0x80000000`. Because JavaScript numbers are\n // signed, we use the bitwise unsigned right shift operator to ensure that\n // the result is a positive number.\n // eslint-disable-next-line no-bitwise\n const pathIndex = (uint32 | HARDENED_VALUE) >>> 0;\n array.push(`bip32:${pathIndex - HARDENED_VALUE}'` as const);\n }\n\n return array;\n}\n\ntype DeriveEntropyOptions = {\n /**\n * The input value to derive entropy from.\n */\n input: string;\n\n /**\n * An optional salt to use when deriving entropy.\n */\n salt?: string;\n\n /**\n * The mnemonic phrase to use for entropy derivation.\n */\n mnemonicPhrase: Uint8Array;\n\n /**\n * A hardened BIP-32 index, which is used to derive the root key from the\n * mnemonic phrase.\n */\n magic: MagicValue;\n};\n\n/**\n * Derive entropy from the given mnemonic phrase and salt.\n *\n * This is based on the reference implementation of\n * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).\n *\n * @param options - The options for entropy derivation.\n * @param options.input - The input value to derive entropy from.\n * @param options.salt - An optional salt to use when deriving entropy.\n * @param options.mnemonicPhrase - The mnemonic phrase to use for entropy\n * derivation.\n * @param options.magic - A hardened BIP-32 index, which is used to derive the\n * root key from the mnemonic phrase.\n * @returns The derived entropy.\n */\nexport async function deriveEntropy({\n input,\n salt = '',\n mnemonicPhrase,\n magic,\n}: DeriveEntropyOptions): Promise<Hex> {\n const inputBytes = stringToBytes(input);\n const saltBytes = stringToBytes(salt);\n\n // Get the derivation path from the snap ID.\n const hash = keccak256(concatBytes([inputBytes, keccak256(saltBytes)]));\n const computedDerivationPath = getDerivationPathArray(hash);\n\n // Derive the private key using BIP-32.\n const { privateKey } = await SLIP10Node.fromDerivationPath({\n derivationPath: [\n mnemonicPhrase,\n `bip32:${magic}`,\n ...computedDerivationPath,\n ],\n curve: 'secp256k1',\n });\n\n // This should never happen, but this keeps TypeScript happy.\n assert(privateKey, 'Failed to derive the entropy.');\n\n return add0x(privateKey);\n}\n\n/**\n * Get the path prefix to use for key derivation in `key-tree`. This assumes the\n * following:\n *\n * - The Secp256k1 curve always use the BIP-32 specification.\n * - The Ed25519 curve always use the SLIP-10 specification.\n *\n * While this does not matter in most situations (no known case at the time of\n * writing), `key-tree` requires a specific specification to be used.\n *\n * @param curve - The curve to get the path prefix for. The curve is NOT\n * validated by this function.\n * @returns The path prefix, i.e., `secp256k1` or `ed25519`.\n */\nexport function getPathPrefix(\n curve: 'secp256k1' | 'ed25519',\n): 'bip32' | 'slip10' {\n if (curve === 'secp256k1') {\n return 'bip32';\n }\n\n return 'slip10';\n}\n\ntype GetNodeArgs = {\n curve: 'secp256k1' | 'ed25519';\n secretRecoveryPhrase: Uint8Array;\n path: string[];\n};\n\n/**\n * Get a `key-tree`-compatible node.\n *\n * Note: This function assumes that all the parameters have been validated\n * beforehand.\n *\n * @param options - The derivation options.\n * @param options.curve - The curve to use for derivation.\n * @param options.secretRecoveryPhrase - The secret recovery phrase to use for\n * derivation.\n * @param options.path - The derivation path to use as array, starting with an\n * \"m\" as the first item.\n */\nexport async function getNode({\n curve,\n secretRecoveryPhrase,\n path,\n}: GetNodeArgs) {\n const prefix = getPathPrefix(curve);\n return await SLIP10Node.fromDerivationPath({\n curve,\n derivationPath: [\n secretRecoveryPhrase,\n ...(path.slice(1).map((index) => `${prefix}:${index}`) as\n | BIP32Node[]\n | SLIP10PathNode[]),\n ],\n });\n}\n"],"names":["selectHooks","deriveEntropy","getPathPrefix","getNode","HARDENED_VALUE","hooks","hookNames","Object","keys","reduce","hookSubset","_hookName","hookName","undefined","getDerivationPathArray","hash","array","view","createDataView","index","uint32","getUint32","pathIndex","push","input","salt","mnemonicPhrase","magic","inputBytes","stringToBytes","saltBytes","keccak256","concatBytes","computedDerivationPath","privateKey","SLIP10Node","fromDerivationPath","derivationPath","curve","assert","add0x","secretRecoveryPhrase","path","prefix","slice","map"],"mappings":";;;;;;;;;;;IAwCgBA,WAAW;eAAXA;;IAmFMC,aAAa;eAAbA;;IA2CNC,aAAa;eAAbA;;IA6BMC,OAAO;eAAPA;;;yBA9LK;uBASpB;sBACiC;AAExC,MAAMC,iBAAiB;AAuBhB,SAASJ,YAIdK,KAAY,EACZC,SAAqC;IAErC,IAAIA,WAAW;QACb,OAAOC,OAAOC,IAAI,CAACF,WAAWG,MAAM,CAClC,CAACC,YAAYC;YACX,MAAMC,WAAWD;YACjBD,UAAU,CAACE,SAAS,GAAGP,KAAK,CAACO,SAAS;YACtC,OAAOF;QACT,GACA,CAAC;IAEL;IACA,OAAOG;AACT;AAEA;;;;;;CAMC,GACD,SAASC,uBAAuBC,IAAgB;IAC9C,MAAMC,QAA6B,EAAE;IACrC,MAAMC,OAAOC,IAAAA,qBAAc,EAACH;IAE5B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AS,cACd,OACoB;AACpB,MAAI,UAAU,aAAa;AACzB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAqBA,eAAsB,QAAQ;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AACF,GAAgB;AACd,QAAM,SAAS,cAAc,KAAK;AAClC,SAAO,MAAM,WAAW,mBAAmB;AAAA,IACzC;AAAA,IACA,gBAAgB;AAAA,MACd;AAAA,MACA,GAAI,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,UAAU,GAAG,MAAM,IAAI,KAAK,EAAE;AAAA,IAGvD;AAAA,EACF,CAAC;AACH","sourcesContent":["import type {\n HardenedBIP32Node,\n BIP32Node,\n SLIP10PathNode,\n} from '@metamask/key-tree';\nimport { SLIP10Node } from '@metamask/key-tree';\nimport type { MagicValue } from '@metamask/snaps-utils';\nimport type { Hex } from '@metamask/utils';\nimport {\n add0x,\n assert,\n concatBytes,\n createDataView,\n stringToBytes,\n} from '@metamask/utils';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\n\nconst HARDENED_VALUE = 0x80000000;\n\n/**\n * Maps an interface with method hooks to an object, using the keys of the\n * interface, and `true` as value. This ensures that the `methodHooks` object\n * has the same values as the interface.\n */\nexport type MethodHooksObject<HooksType extends Record<string, unknown>> = {\n [Key in keyof HooksType]: true;\n};\n\n/**\n * Returns the subset of the specified `hooks` that are included in the\n * `hookNames` object. This is a Principle of Least Authority (POLA) measure\n * to ensure that each RPC method implementation only has access to the\n * API \"hooks\" it needs to do its job.\n *\n * @param hooks - The hooks to select from.\n * @param hookNames - The names of the hooks to select.\n * @returns The selected hooks.\n * @template Hooks - The hooks to select from.\n * @template HookName - The names of the hooks to select.\n */\nexport function selectHooks<\n Hooks extends Record<string, unknown>,\n HookName extends keyof Hooks,\n>(\n hooks: Hooks,\n hookNames?: Record<HookName, boolean>,\n): Pick<Hooks, HookName> | undefined {\n if (hookNames) {\n return Object.keys(hookNames).reduce<Partial<Pick<Hooks, HookName>>>(\n (hookSubset, _hookName) => {\n const hookName = _hookName as HookName;\n hookSubset[hookName] = hooks[hookName];\n return hookSubset;\n },\n {},\n ) as Pick<Hooks, HookName>;\n }\n return undefined;\n}\n\n/**\n * Get a BIP-32 derivation path array from a hash, which is compatible with\n * `@metamask/key-tree`. The hash is assumed to be 32 bytes long.\n *\n * @param hash - The hash to derive indices from.\n * @returns The derived indices as a {@link HardenedBIP32Node} array.\n */\nfunction getDerivationPathArray(hash: Uint8Array): HardenedBIP32Node[] {\n const array: HardenedBIP32Node[] = [];\n const view = createDataView(hash);\n\n for (let index = 0; index < 8; index++) {\n const uint32 = view.getUint32(index * 4);\n\n // This is essentially `index | 0x80000000`. Because JavaScript numbers are\n // signed, we use the bitwise unsigned right shift operator to ensure that\n // the result is a positive number.\n // eslint-disable-next-line no-bitwise\n const pathIndex = (uint32 | HARDENED_VALUE) >>> 0;\n array.push(`bip32:${pathIndex - HARDENED_VALUE}'` as const);\n }\n\n return array;\n}\n\ntype DeriveEntropyOptions = {\n /**\n * The input value to derive entropy from.\n */\n input: string;\n\n /**\n * An optional salt to use when deriving entropy.\n */\n salt?: string;\n\n /**\n * The mnemonic phrase to use for entropy derivation.\n */\n mnemonicPhrase: Uint8Array;\n\n /**\n * A hardened BIP-32 index, which is used to derive the root key from the\n * mnemonic phrase.\n */\n magic: MagicValue;\n};\n\n/**\n * Derive entropy from the given mnemonic phrase and salt.\n *\n * This is based on the reference implementation of\n * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).\n *\n * @param options - The options for entropy derivation.\n * @param options.input - The input value to derive entropy from.\n * @param options.salt - An optional salt to use when deriving entropy.\n * @param options.mnemonicPhrase - The mnemonic phrase to use for entropy\n * derivation.\n * @param options.magic - A hardened BIP-32 index, which is used to derive the\n * root key from the mnemonic phrase.\n * @returns The derived entropy.\n */\nexport async function deriveEntropy({\n input,\n salt = '',\n mnemonicPhrase,\n magic,\n}: DeriveEntropyOptions): Promise<Hex> {\n const inputBytes = stringToBytes(input);\n const saltBytes = stringToBytes(salt);\n\n // Get the derivation path from the snap ID.\n const hash = keccak256(concatBytes([inputBytes, keccak256(saltBytes)]));\n const computedDerivationPath = getDerivationPathArray(hash);\n\n // Derive the private key using BIP-32.\n const { privateKey } = await SLIP10Node.fromDerivationPath({\n derivationPath: [\n mnemonicPhrase,\n `bip32:${magic}`,\n ...computedDerivationPath,\n ],\n curve: 'secp256k1',\n });\n\n // This should never happen, but this keeps TypeScript happy.\n assert(privateKey, 'Failed to derive the entropy.');\n\n return add0x(privateKey);\n}\n\n/**\n * Get the path prefix to use for key derivation in `key-tree`. This assumes the\n * following:\n *\n * - The Secp256k1 curve always use the BIP-32 specification.\n * - The Ed25519 curve always use the SLIP-10 specification.\n *\n * While this does not matter in most situations (no known case at the time of\n * writing), `key-tree` requires a specific specification to be used.\n *\n * @param curve - The curve to get the path prefix for. The curve is NOT\n * validated by this function.\n * @returns The path prefix, i.e., `secp256k1` or `ed25519`.\n */\nexport function getPathPrefix(\n curve: 'secp256k1' | 'ed25519',\n): 'bip32' | 'slip10' {\n if (curve === 'secp256k1') {\n return 'bip32';\n }\n\n return 'slip10';\n}\n\ntype GetNodeArgs = {\n curve: 'secp256k1' | 'ed25519';\n secretRecoveryPhrase: Uint8Array;\n path: string[];\n};\n\n/**\n * Get a `key-tree`-compatible node.\n *\n * Note: This function assumes that all the parameters have been validated\n * beforehand.\n *\n * @param options - The derivation options.\n * @param options.curve - The curve to use for derivation.\n * @param options.secretRecoveryPhrase - The secret recovery phrase to use for\n * derivation.\n * @param options.path - The derivation path to use as array, starting with an\n * \"m\" as the first item.\n */\nexport async function getNode({\n curve,\n secretRecoveryPhrase,\n path,\n}: GetNodeArgs) {\n const prefix = getPathPrefix(curve);\n return await SLIP10Node.fromDerivationPath({\n curve,\n derivationPath: [\n secretRecoveryPhrase,\n ...(path.slice(1).map((index) => `${prefix}:${index}`) as\n | BIP32Node[]\n | SLIP10PathNode[]),\n ],\n });\n}\n"]}
@@ -0,0 +1,82 @@
1
+ // src/restricted/invokeSnap.ts
2
+ import { PermissionType } from "@metamask/permission-controller";
3
+ import { rpcErrors } from "@metamask/rpc-errors";
4
+ import { HandlerType, SnapCaveatType } from "@metamask/snaps-utils";
5
+ var WALLET_SNAP_PERMISSION_KEY = "wallet_snap";
6
+ var handleSnapInstall = async ({ requestData, messagingSystem }) => {
7
+ const snaps = requestData.permissions[WALLET_SNAP_PERMISSION_KEY].caveats?.[0].value;
8
+ const permittedSnaps = messagingSystem.call(
9
+ `SnapController:getPermitted`,
10
+ requestData.metadata.origin
11
+ );
12
+ const dedupedSnaps = Object.keys(snaps).reduce(
13
+ (filteredSnaps, snap) => {
14
+ if (!permittedSnaps[snap]) {
15
+ filteredSnaps[snap] = snaps[snap];
16
+ }
17
+ return filteredSnaps;
18
+ },
19
+ {}
20
+ );
21
+ return messagingSystem.call(
22
+ `SnapController:install`,
23
+ requestData.metadata.origin,
24
+ dedupedSnaps
25
+ );
26
+ };
27
+ var specificationBuilder = ({ methodHooks: methodHooks2 }) => {
28
+ return {
29
+ permissionType: PermissionType.RestrictedMethod,
30
+ targetName: WALLET_SNAP_PERMISSION_KEY,
31
+ allowedCaveats: [SnapCaveatType.SnapIds],
32
+ methodImplementation: getInvokeSnapImplementation(methodHooks2),
33
+ validator: ({ caveats }) => {
34
+ if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.SnapIds) {
35
+ throw rpcErrors.invalidParams({
36
+ message: `Expected a single "${SnapCaveatType.SnapIds}" caveat.`
37
+ });
38
+ }
39
+ },
40
+ sideEffect: {
41
+ onPermitted: handleSnapInstall
42
+ }
43
+ };
44
+ };
45
+ var methodHooks = {
46
+ getSnap: true,
47
+ handleSnapRpcRequest: true
48
+ };
49
+ var invokeSnapBuilder = Object.freeze({
50
+ targetName: WALLET_SNAP_PERMISSION_KEY,
51
+ specificationBuilder,
52
+ methodHooks
53
+ });
54
+ function getInvokeSnapImplementation({
55
+ getSnap,
56
+ handleSnapRpcRequest
57
+ }) {
58
+ return async function invokeSnap(options) {
59
+ const { params = {}, context } = options;
60
+ const { snapId, request } = params;
61
+ if (!getSnap(snapId)) {
62
+ throw rpcErrors.invalidRequest({
63
+ message: `The snap "${snapId}" is not installed. Please install it first, before invoking the snap.`
64
+ });
65
+ }
66
+ const { origin } = context;
67
+ return await handleSnapRpcRequest({
68
+ snapId,
69
+ origin,
70
+ request,
71
+ handler: HandlerType.OnRpcRequest
72
+ });
73
+ };
74
+ }
75
+
76
+ export {
77
+ WALLET_SNAP_PERMISSION_KEY,
78
+ handleSnapInstall,
79
+ invokeSnapBuilder,
80
+ getInvokeSnapImplementation
81
+ };
82
+ //# sourceMappingURL=chunk-6DUTJBD2.mjs.map