@metamask/snaps-rpc-methods 14.3.0 → 15.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (350) hide show
  1. package/CHANGELOG.md +24 -1
  2. package/dist/permitted/cancelBackgroundEvent.cjs +20 -0
  3. package/dist/permitted/cancelBackgroundEvent.cjs.map +1 -1
  4. package/dist/permitted/cancelBackgroundEvent.d.cts +43 -3
  5. package/dist/permitted/cancelBackgroundEvent.d.cts.map +1 -1
  6. package/dist/permitted/cancelBackgroundEvent.d.mts +43 -3
  7. package/dist/permitted/cancelBackgroundEvent.d.mts.map +1 -1
  8. package/dist/permitted/cancelBackgroundEvent.mjs +20 -0
  9. package/dist/permitted/cancelBackgroundEvent.mjs.map +1 -1
  10. package/dist/permitted/clearState.cjs +13 -2
  11. package/dist/permitted/clearState.cjs.map +1 -1
  12. package/dist/permitted/clearState.d.cts +35 -3
  13. package/dist/permitted/clearState.d.cts.map +1 -1
  14. package/dist/permitted/clearState.d.mts +35 -3
  15. package/dist/permitted/clearState.d.mts.map +1 -1
  16. package/dist/permitted/clearState.mjs +13 -2
  17. package/dist/permitted/clearState.mjs.map +1 -1
  18. package/dist/permitted/closeWebSocket.cjs +19 -2
  19. package/dist/permitted/closeWebSocket.cjs.map +1 -1
  20. package/dist/permitted/closeWebSocket.d.cts +39 -4
  21. package/dist/permitted/closeWebSocket.d.cts.map +1 -1
  22. package/dist/permitted/closeWebSocket.d.mts +39 -4
  23. package/dist/permitted/closeWebSocket.d.mts.map +1 -1
  24. package/dist/permitted/closeWebSocket.mjs +19 -2
  25. package/dist/permitted/closeWebSocket.mjs.map +1 -1
  26. package/dist/permitted/createInterface.cjs +33 -2
  27. package/dist/permitted/createInterface.cjs.map +1 -1
  28. package/dist/permitted/createInterface.d.cts +68 -17
  29. package/dist/permitted/createInterface.d.cts.map +1 -1
  30. package/dist/permitted/createInterface.d.mts +68 -17
  31. package/dist/permitted/createInterface.d.mts.map +1 -1
  32. package/dist/permitted/createInterface.mjs +34 -3
  33. package/dist/permitted/createInterface.mjs.map +1 -1
  34. package/dist/permitted/endTrace.cjs +6 -2
  35. package/dist/permitted/endTrace.cjs.map +1 -1
  36. package/dist/permitted/endTrace.d.cts +28 -4
  37. package/dist/permitted/endTrace.d.cts.map +1 -1
  38. package/dist/permitted/endTrace.d.mts +28 -4
  39. package/dist/permitted/endTrace.d.mts.map +1 -1
  40. package/dist/permitted/endTrace.mjs +6 -2
  41. package/dist/permitted/endTrace.mjs.map +1 -1
  42. package/dist/permitted/getAllSnaps.cjs +4 -1
  43. package/dist/permitted/getAllSnaps.cjs.map +1 -1
  44. package/dist/permitted/getAllSnaps.d.cts +25 -3
  45. package/dist/permitted/getAllSnaps.d.cts.map +1 -1
  46. package/dist/permitted/getAllSnaps.d.mts +25 -3
  47. package/dist/permitted/getAllSnaps.d.mts.map +1 -1
  48. package/dist/permitted/getAllSnaps.mjs +4 -1
  49. package/dist/permitted/getAllSnaps.mjs.map +1 -1
  50. package/dist/permitted/getBackgroundEvents.cjs +24 -0
  51. package/dist/permitted/getBackgroundEvents.cjs.map +1 -1
  52. package/dist/permitted/getBackgroundEvents.d.cts +48 -3
  53. package/dist/permitted/getBackgroundEvents.d.cts.map +1 -1
  54. package/dist/permitted/getBackgroundEvents.d.mts +48 -3
  55. package/dist/permitted/getBackgroundEvents.d.mts.map +1 -1
  56. package/dist/permitted/getBackgroundEvents.mjs +24 -0
  57. package/dist/permitted/getBackgroundEvents.mjs.map +1 -1
  58. package/dist/permitted/getClientStatus.cjs +27 -2
  59. package/dist/permitted/getClientStatus.cjs.map +1 -1
  60. package/dist/permitted/getClientStatus.d.cts +50 -4
  61. package/dist/permitted/getClientStatus.d.cts.map +1 -1
  62. package/dist/permitted/getClientStatus.d.mts +50 -4
  63. package/dist/permitted/getClientStatus.d.mts.map +1 -1
  64. package/dist/permitted/getClientStatus.mjs +27 -2
  65. package/dist/permitted/getClientStatus.mjs.map +1 -1
  66. package/dist/permitted/getFile.cjs +28 -1
  67. package/dist/permitted/getFile.cjs.map +1 -1
  68. package/dist/permitted/getFile.d.cts +49 -3
  69. package/dist/permitted/getFile.d.cts.map +1 -1
  70. package/dist/permitted/getFile.d.mts +49 -3
  71. package/dist/permitted/getFile.d.mts.map +1 -1
  72. package/dist/permitted/getFile.mjs +28 -1
  73. package/dist/permitted/getFile.mjs.map +1 -1
  74. package/dist/permitted/getInterfaceContext.cjs +49 -3
  75. package/dist/permitted/getInterfaceContext.cjs.map +1 -1
  76. package/dist/permitted/getInterfaceContext.d.cts +65 -3
  77. package/dist/permitted/getInterfaceContext.d.cts.map +1 -1
  78. package/dist/permitted/getInterfaceContext.d.mts +65 -3
  79. package/dist/permitted/getInterfaceContext.d.mts.map +1 -1
  80. package/dist/permitted/getInterfaceContext.mjs +50 -4
  81. package/dist/permitted/getInterfaceContext.mjs.map +1 -1
  82. package/dist/permitted/getInterfaceState.cjs +27 -3
  83. package/dist/permitted/getInterfaceState.cjs.map +1 -1
  84. package/dist/permitted/getInterfaceState.d.cts +43 -3
  85. package/dist/permitted/getInterfaceState.d.cts.map +1 -1
  86. package/dist/permitted/getInterfaceState.d.mts +43 -3
  87. package/dist/permitted/getInterfaceState.d.mts.map +1 -1
  88. package/dist/permitted/getInterfaceState.mjs +28 -4
  89. package/dist/permitted/getInterfaceState.mjs.map +1 -1
  90. package/dist/permitted/getSnaps.cjs +21 -2
  91. package/dist/permitted/getSnaps.cjs.map +1 -1
  92. package/dist/permitted/getSnaps.d.cts +42 -4
  93. package/dist/permitted/getSnaps.d.cts.map +1 -1
  94. package/dist/permitted/getSnaps.d.mts +42 -4
  95. package/dist/permitted/getSnaps.d.mts.map +1 -1
  96. package/dist/permitted/getSnaps.mjs +21 -2
  97. package/dist/permitted/getSnaps.mjs.map +1 -1
  98. package/dist/permitted/getState.cjs +24 -2
  99. package/dist/permitted/getState.cjs.map +1 -1
  100. package/dist/permitted/getState.d.cts +46 -4
  101. package/dist/permitted/getState.d.cts.map +1 -1
  102. package/dist/permitted/getState.d.mts +46 -4
  103. package/dist/permitted/getState.d.mts.map +1 -1
  104. package/dist/permitted/getState.mjs +24 -2
  105. package/dist/permitted/getState.mjs.map +1 -1
  106. package/dist/permitted/getWebSockets.cjs +29 -2
  107. package/dist/permitted/getWebSockets.cjs.map +1 -1
  108. package/dist/permitted/getWebSockets.d.cts +50 -4
  109. package/dist/permitted/getWebSockets.d.cts.map +1 -1
  110. package/dist/permitted/getWebSockets.d.mts +50 -4
  111. package/dist/permitted/getWebSockets.d.mts.map +1 -1
  112. package/dist/permitted/getWebSockets.mjs +29 -2
  113. package/dist/permitted/getWebSockets.mjs.map +1 -1
  114. package/dist/permitted/handlers.cjs +0 -4
  115. package/dist/permitted/handlers.cjs.map +1 -1
  116. package/dist/permitted/handlers.d.cts +274 -56
  117. package/dist/permitted/handlers.d.cts.map +1 -1
  118. package/dist/permitted/handlers.d.mts +274 -56
  119. package/dist/permitted/handlers.d.mts.map +1 -1
  120. package/dist/permitted/handlers.mjs +0 -4
  121. package/dist/permitted/handlers.mjs.map +1 -1
  122. package/dist/permitted/index.cjs.map +1 -1
  123. package/dist/permitted/index.d.cts +1 -3
  124. package/dist/permitted/index.d.cts.map +1 -1
  125. package/dist/permitted/index.d.mts +1 -3
  126. package/dist/permitted/index.d.mts.map +1 -1
  127. package/dist/permitted/index.mjs.map +1 -1
  128. package/dist/permitted/invokeKeyring.cjs +8 -2
  129. package/dist/permitted/invokeKeyring.cjs.map +1 -1
  130. package/dist/permitted/invokeKeyring.d.cts +34 -4
  131. package/dist/permitted/invokeKeyring.d.cts.map +1 -1
  132. package/dist/permitted/invokeKeyring.d.mts +34 -4
  133. package/dist/permitted/invokeKeyring.d.mts.map +1 -1
  134. package/dist/permitted/invokeKeyring.mjs +8 -2
  135. package/dist/permitted/invokeKeyring.mjs.map +1 -1
  136. package/dist/permitted/invokeSnapSugar.cjs +25 -2
  137. package/dist/permitted/invokeSnapSugar.cjs.map +1 -1
  138. package/dist/permitted/invokeSnapSugar.d.cts +30 -3
  139. package/dist/permitted/invokeSnapSugar.d.cts.map +1 -1
  140. package/dist/permitted/invokeSnapSugar.d.mts +30 -3
  141. package/dist/permitted/invokeSnapSugar.d.mts.map +1 -1
  142. package/dist/permitted/invokeSnapSugar.mjs +25 -2
  143. package/dist/permitted/invokeSnapSugar.mjs.map +1 -1
  144. package/dist/permitted/listEntropySources.cjs +40 -1
  145. package/dist/permitted/listEntropySources.cjs.map +1 -1
  146. package/dist/permitted/listEntropySources.d.cts +64 -3
  147. package/dist/permitted/listEntropySources.d.cts.map +1 -1
  148. package/dist/permitted/listEntropySources.d.mts +64 -3
  149. package/dist/permitted/listEntropySources.d.mts.map +1 -1
  150. package/dist/permitted/listEntropySources.mjs +40 -1
  151. package/dist/permitted/listEntropySources.mjs.map +1 -1
  152. package/dist/permitted/openWebSocket.cjs +46 -2
  153. package/dist/permitted/openWebSocket.cjs.map +1 -1
  154. package/dist/permitted/openWebSocket.d.cts +66 -4
  155. package/dist/permitted/openWebSocket.d.cts.map +1 -1
  156. package/dist/permitted/openWebSocket.d.mts +66 -4
  157. package/dist/permitted/openWebSocket.d.mts.map +1 -1
  158. package/dist/permitted/openWebSocket.mjs +46 -2
  159. package/dist/permitted/openWebSocket.mjs.map +1 -1
  160. package/dist/permitted/requestSnaps.cjs +25 -2
  161. package/dist/permitted/requestSnaps.cjs.map +1 -1
  162. package/dist/permitted/requestSnaps.d.cts +51 -3
  163. package/dist/permitted/requestSnaps.d.cts.map +1 -1
  164. package/dist/permitted/requestSnaps.d.mts +51 -3
  165. package/dist/permitted/requestSnaps.d.mts.map +1 -1
  166. package/dist/permitted/requestSnaps.mjs +25 -2
  167. package/dist/permitted/requestSnaps.mjs.map +1 -1
  168. package/dist/permitted/resolveInterface.cjs +38 -2
  169. package/dist/permitted/resolveInterface.cjs.map +1 -1
  170. package/dist/permitted/resolveInterface.d.cts +55 -4
  171. package/dist/permitted/resolveInterface.d.cts.map +1 -1
  172. package/dist/permitted/resolveInterface.d.mts +55 -4
  173. package/dist/permitted/resolveInterface.d.mts.map +1 -1
  174. package/dist/permitted/resolveInterface.mjs +39 -3
  175. package/dist/permitted/resolveInterface.mjs.map +1 -1
  176. package/dist/permitted/scheduleBackgroundEvent.cjs +26 -0
  177. package/dist/permitted/scheduleBackgroundEvent.cjs.map +1 -1
  178. package/dist/permitted/scheduleBackgroundEvent.d.cts +49 -3
  179. package/dist/permitted/scheduleBackgroundEvent.d.cts.map +1 -1
  180. package/dist/permitted/scheduleBackgroundEvent.d.mts +49 -3
  181. package/dist/permitted/scheduleBackgroundEvent.d.mts.map +1 -1
  182. package/dist/permitted/scheduleBackgroundEvent.mjs +26 -0
  183. package/dist/permitted/scheduleBackgroundEvent.mjs.map +1 -1
  184. package/dist/permitted/sendWebSocketMessage.cjs +24 -2
  185. package/dist/permitted/sendWebSocketMessage.cjs.map +1 -1
  186. package/dist/permitted/sendWebSocketMessage.d.cts +44 -4
  187. package/dist/permitted/sendWebSocketMessage.d.cts.map +1 -1
  188. package/dist/permitted/sendWebSocketMessage.d.mts +44 -4
  189. package/dist/permitted/sendWebSocketMessage.d.mts.map +1 -1
  190. package/dist/permitted/sendWebSocketMessage.mjs +24 -2
  191. package/dist/permitted/sendWebSocketMessage.mjs.map +1 -1
  192. package/dist/permitted/setState.cjs +48 -2
  193. package/dist/permitted/setState.cjs.map +1 -1
  194. package/dist/permitted/setState.d.cts +72 -4
  195. package/dist/permitted/setState.d.cts.map +1 -1
  196. package/dist/permitted/setState.d.mts +72 -4
  197. package/dist/permitted/setState.d.mts.map +1 -1
  198. package/dist/permitted/setState.mjs +48 -2
  199. package/dist/permitted/setState.mjs.map +1 -1
  200. package/dist/permitted/startTrace.cjs +4 -1
  201. package/dist/permitted/startTrace.cjs.map +1 -1
  202. package/dist/permitted/startTrace.d.cts +26 -3
  203. package/dist/permitted/startTrace.d.cts.map +1 -1
  204. package/dist/permitted/startTrace.d.mts +26 -3
  205. package/dist/permitted/startTrace.d.mts.map +1 -1
  206. package/dist/permitted/startTrace.mjs +4 -1
  207. package/dist/permitted/startTrace.mjs.map +1 -1
  208. package/dist/permitted/trackError.cjs +4 -1
  209. package/dist/permitted/trackError.cjs.map +1 -1
  210. package/dist/permitted/trackError.d.cts +26 -3
  211. package/dist/permitted/trackError.d.cts.map +1 -1
  212. package/dist/permitted/trackError.d.mts +26 -3
  213. package/dist/permitted/trackError.d.mts.map +1 -1
  214. package/dist/permitted/trackError.mjs +4 -1
  215. package/dist/permitted/trackError.mjs.map +1 -1
  216. package/dist/permitted/trackEvent.cjs +4 -1
  217. package/dist/permitted/trackEvent.cjs.map +1 -1
  218. package/dist/permitted/trackEvent.d.cts +25 -4
  219. package/dist/permitted/trackEvent.d.cts.map +1 -1
  220. package/dist/permitted/trackEvent.d.mts +25 -4
  221. package/dist/permitted/trackEvent.d.mts.map +1 -1
  222. package/dist/permitted/trackEvent.mjs +4 -1
  223. package/dist/permitted/trackEvent.mjs.map +1 -1
  224. package/dist/permitted/updateInterface.cjs +47 -2
  225. package/dist/permitted/updateInterface.cjs.map +1 -1
  226. package/dist/permitted/updateInterface.d.cts +64 -3
  227. package/dist/permitted/updateInterface.d.cts.map +1 -1
  228. package/dist/permitted/updateInterface.d.mts +64 -3
  229. package/dist/permitted/updateInterface.d.mts.map +1 -1
  230. package/dist/permitted/updateInterface.mjs +48 -3
  231. package/dist/permitted/updateInterface.mjs.map +1 -1
  232. package/dist/restricted/caveats/snapIds.cjs.map +1 -1
  233. package/dist/restricted/caveats/snapIds.d.cts.map +1 -1
  234. package/dist/restricted/caveats/snapIds.d.mts.map +1 -1
  235. package/dist/restricted/caveats/snapIds.mjs.map +1 -1
  236. package/dist/restricted/dialog.cjs +49 -1
  237. package/dist/restricted/dialog.cjs.map +1 -1
  238. package/dist/restricted/dialog.d.cts +52 -2
  239. package/dist/restricted/dialog.d.cts.map +1 -1
  240. package/dist/restricted/dialog.d.mts +52 -2
  241. package/dist/restricted/dialog.d.mts.map +1 -1
  242. package/dist/restricted/dialog.mjs +49 -1
  243. package/dist/restricted/dialog.mjs.map +1 -1
  244. package/dist/restricted/getBip32Entropy.cjs +55 -0
  245. package/dist/restricted/getBip32Entropy.cjs.map +1 -1
  246. package/dist/restricted/getBip32Entropy.d.cts +55 -0
  247. package/dist/restricted/getBip32Entropy.d.cts.map +1 -1
  248. package/dist/restricted/getBip32Entropy.d.mts +55 -0
  249. package/dist/restricted/getBip32Entropy.d.mts.map +1 -1
  250. package/dist/restricted/getBip32Entropy.mjs +55 -0
  251. package/dist/restricted/getBip32Entropy.mjs.map +1 -1
  252. package/dist/restricted/getBip32PublicKey.cjs +36 -0
  253. package/dist/restricted/getBip32PublicKey.cjs.map +1 -1
  254. package/dist/restricted/getBip32PublicKey.d.cts +36 -0
  255. package/dist/restricted/getBip32PublicKey.d.cts.map +1 -1
  256. package/dist/restricted/getBip32PublicKey.d.mts +36 -0
  257. package/dist/restricted/getBip32PublicKey.d.mts.map +1 -1
  258. package/dist/restricted/getBip32PublicKey.mjs +36 -0
  259. package/dist/restricted/getBip32PublicKey.mjs.map +1 -1
  260. package/dist/restricted/getBip44Entropy.cjs +53 -0
  261. package/dist/restricted/getBip44Entropy.cjs.map +1 -1
  262. package/dist/restricted/getBip44Entropy.d.cts +53 -0
  263. package/dist/restricted/getBip44Entropy.d.cts.map +1 -1
  264. package/dist/restricted/getBip44Entropy.d.mts +53 -0
  265. package/dist/restricted/getBip44Entropy.d.mts.map +1 -1
  266. package/dist/restricted/getBip44Entropy.mjs +53 -0
  267. package/dist/restricted/getBip44Entropy.mjs.map +1 -1
  268. package/dist/restricted/getEntropy.cjs +35 -0
  269. package/dist/restricted/getEntropy.cjs.map +1 -1
  270. package/dist/restricted/getEntropy.d.cts +35 -0
  271. package/dist/restricted/getEntropy.d.cts.map +1 -1
  272. package/dist/restricted/getEntropy.d.mts +35 -0
  273. package/dist/restricted/getEntropy.d.mts.map +1 -1
  274. package/dist/restricted/getEntropy.mjs +35 -0
  275. package/dist/restricted/getEntropy.mjs.map +1 -1
  276. package/dist/restricted/getLocale.cjs +11 -0
  277. package/dist/restricted/getLocale.cjs.map +1 -1
  278. package/dist/restricted/getLocale.d.cts +11 -0
  279. package/dist/restricted/getLocale.d.cts.map +1 -1
  280. package/dist/restricted/getLocale.d.mts +11 -0
  281. package/dist/restricted/getLocale.d.mts.map +1 -1
  282. package/dist/restricted/getLocale.mjs +11 -0
  283. package/dist/restricted/getLocale.mjs.map +1 -1
  284. package/dist/restricted/getPreferences.cjs +24 -0
  285. package/dist/restricted/getPreferences.cjs.map +1 -1
  286. package/dist/restricted/getPreferences.d.cts +24 -0
  287. package/dist/restricted/getPreferences.d.cts.map +1 -1
  288. package/dist/restricted/getPreferences.d.mts +24 -0
  289. package/dist/restricted/getPreferences.d.mts.map +1 -1
  290. package/dist/restricted/getPreferences.mjs +24 -0
  291. package/dist/restricted/getPreferences.mjs.map +1 -1
  292. package/dist/restricted/index.d.cts +2 -2
  293. package/dist/restricted/index.d.mts +2 -2
  294. package/dist/restricted/invokeSnap.cjs +24 -2
  295. package/dist/restricted/invokeSnap.cjs.map +1 -1
  296. package/dist/restricted/invokeSnap.d.cts +29 -11
  297. package/dist/restricted/invokeSnap.d.cts.map +1 -1
  298. package/dist/restricted/invokeSnap.d.mts +29 -11
  299. package/dist/restricted/invokeSnap.d.mts.map +1 -1
  300. package/dist/restricted/invokeSnap.mjs +24 -2
  301. package/dist/restricted/invokeSnap.mjs.map +1 -1
  302. package/dist/restricted/manageAccounts.cjs +10 -0
  303. package/dist/restricted/manageAccounts.cjs.map +1 -1
  304. package/dist/restricted/manageAccounts.d.cts +10 -0
  305. package/dist/restricted/manageAccounts.d.cts.map +1 -1
  306. package/dist/restricted/manageAccounts.d.mts +10 -0
  307. package/dist/restricted/manageAccounts.d.mts.map +1 -1
  308. package/dist/restricted/manageAccounts.mjs +10 -0
  309. package/dist/restricted/manageAccounts.mjs.map +1 -1
  310. package/dist/restricted/manageState.cjs +42 -0
  311. package/dist/restricted/manageState.cjs.map +1 -1
  312. package/dist/restricted/manageState.d.cts +42 -0
  313. package/dist/restricted/manageState.d.cts.map +1 -1
  314. package/dist/restricted/manageState.d.mts +42 -0
  315. package/dist/restricted/manageState.d.mts.map +1 -1
  316. package/dist/restricted/manageState.mjs +42 -0
  317. package/dist/restricted/manageState.mjs.map +1 -1
  318. package/dist/restricted/notify.cjs +74 -0
  319. package/dist/restricted/notify.cjs.map +1 -1
  320. package/dist/restricted/notify.d.cts +75 -1
  321. package/dist/restricted/notify.d.cts.map +1 -1
  322. package/dist/restricted/notify.d.mts +75 -1
  323. package/dist/restricted/notify.d.mts.map +1 -1
  324. package/dist/restricted/notify.mjs +74 -0
  325. package/dist/restricted/notify.mjs.map +1 -1
  326. package/dist/utils.cjs +14 -1
  327. package/dist/utils.cjs.map +1 -1
  328. package/dist/utils.d.cts +6 -0
  329. package/dist/utils.d.cts.map +1 -1
  330. package/dist/utils.d.mts +6 -0
  331. package/dist/utils.d.mts.map +1 -1
  332. package/dist/utils.mjs +13 -0
  333. package/dist/utils.mjs.map +1 -1
  334. package/package.json +12 -8
  335. package/dist/permitted/experimentalProviderRequest.cjs +0 -152
  336. package/dist/permitted/experimentalProviderRequest.cjs.map +0 -1
  337. package/dist/permitted/experimentalProviderRequest.d.cts +0 -39
  338. package/dist/permitted/experimentalProviderRequest.d.cts.map +0 -1
  339. package/dist/permitted/experimentalProviderRequest.d.mts +0 -39
  340. package/dist/permitted/experimentalProviderRequest.d.mts.map +0 -1
  341. package/dist/permitted/experimentalProviderRequest.mjs +0 -149
  342. package/dist/permitted/experimentalProviderRequest.mjs.map +0 -1
  343. package/dist/permitted/getCurrencyRate.cjs +0 -63
  344. package/dist/permitted/getCurrencyRate.cjs.map +0 -1
  345. package/dist/permitted/getCurrencyRate.d.cts +0 -20
  346. package/dist/permitted/getCurrencyRate.d.cts.map +0 -1
  347. package/dist/permitted/getCurrencyRate.d.mts +0 -20
  348. package/dist/permitted/getCurrencyRate.d.mts.map +0 -1
  349. package/dist/permitted/getCurrencyRate.mjs +0 -60
  350. package/dist/permitted/getCurrencyRate.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"dialog.d.cts","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,EACL,UAAU,EAIX,4BAA4B;AAC7B,OAAO,KAAK,EACV,YAAY,EAEZ,cAAc,EACd,MAAM,EAEN,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACZ,4BAA4B;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAG3D,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AAElD,QAAA,MAAM,UAAU,gBAAgB,CAAC;AAEjC,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG;IAC7D,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,qBAAqB;;;;;CAKjC,CAAC;AAEF,QAAA,MAAM,iBAAiB,kEAAkC,CAAC;AAE1D,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE1D,KAAK,0BAA0B,GAAG;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE;QACX,EAAE,EAAE,MAAM,CAAC;QACX,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH,CAAC;AAEF,KAAK,mBAAmB,GAAG,CACzB,IAAI,EAAE,0BAA0B,KAC7B,OAAO,CAAC,OAAO,GAAG,IAAI,G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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,aAAa;;;wBAtFR,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,8BAA8B,CAAC;wBAChD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;;;EAuF7C,CAAC;AAuEZ,QAAA,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAmB1B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAC1C,OAAO,sBAAsB,EAC7B,YAAY,CACb,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,qBAAqB,GACtB,EAAE,iBAAiB,UAEV,wBAAwB,gBAAgB,CAAC,KAC9C,QAAQ,YAAY,CAAC,CAuDzB"}
@@ -1,7 +1,7 @@
1
1
  import type { PermissionSpecificationBuilder, RestrictedMethodOptions } from "@metamask/permission-controller";
2
2
  import { PermissionType } from "@metamask/permission-controller";
3
3
  import { DialogType } from "@metamask/snaps-sdk";
4
- import type { DialogParams, InterfaceState, SnapId, ComponentOrElement, InterfaceContext, ContentType } from "@metamask/snaps-sdk";
4
+ import type { DialogParams, InterfaceState, SnapId, ComponentOrElement, InterfaceContext, ContentType, DialogResult } from "@metamask/snaps-sdk";
5
5
  import type { InferMatching } from "@metamask/snaps-utils";
6
6
  import type { Infer } from "@metamask/superstruct";
7
7
  import type { Json, NonEmptyArray } from "@metamask/utils";
@@ -55,11 +55,59 @@ export type DialogMethodHooks = {
55
55
  * @param id - The interface ID.
56
56
  */
57
57
  getInterface: GetInterface;
58
+ /**
59
+ * Set the interface as displayed.
60
+ *
61
+ * @param snapId - The Snap ID requesting the interface.
62
+ * @param id - The interface ID.
63
+ */
64
+ setInterfaceDisplayed: (snapId: string, id: string) => void;
58
65
  };
59
66
  type DialogSpecificationBuilderOptions = {
60
67
  allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
61
68
  methodHooks: DialogMethodHooks;
62
69
  };
70
+ /**
71
+ * Display a [dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/)
72
+ * in the MetaMask UI.
73
+ *
74
+ * - `type` - The type of dialog. Not providing a type will create a fully
75
+ * [custom dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/#display-a-custom-dialog).
76
+ * Possible values are:
77
+ * - `alert` - An alert that can only be acknowledged.
78
+ * - `confirmation` - A confirmation that can be accepted or rejected.
79
+ * - `prompt` - A prompt where the user can enter a text response.
80
+ *
81
+ * - One of:
82
+ * - `content` - The content of the alert, as a
83
+ * [custom UI](https://docs.metamask.io/snaps/features/custom-ui/) component.
84
+ * - `id` - The ID of an
85
+ * [interactive interface](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
86
+ * - `placeholder` - An optional placeholder text to display in the dialog. Only
87
+ * applicable for the `prompt` dialog.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx';
92
+ *
93
+ * const walletAddress = await snap.request({
94
+ * method: 'snap_dialog',
95
+ * params: {
96
+ * type: 'prompt',
97
+ * content: (
98
+ * <Box>
99
+ * <Heading>What is the wallet address?</Heading>
100
+ * <Text>Please enter the wallet address to be monitored.</Text>
101
+ * </Box>
102
+ * ),
103
+ * placeholder: '0x123...',
104
+ * },
105
+ * });
106
+ *
107
+ * // `walletAddress` will be a string containing the address entered by the
108
+ * // user.
109
+ * ```
110
+ */
63
111
  export declare const dialogBuilder: Readonly<{
64
112
  readonly targetName: "snap_dialog";
65
113
  readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, DialogSpecificationBuilderOptions, {
@@ -448,9 +496,11 @@ export type DialogParameters = InferMatching<typeof DialogParametersStruct, Dial
448
496
  * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.
449
497
  * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
450
498
  * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.
499
+ * @param hooks.setInterfaceDisplayed - A function that sets the interface as
500
+ * displayed in SnapInterfaceController.
451
501
  * @returns The method implementation which return value depends on the dialog
452
502
  * type, valid return types are: string, boolean, null.
453
503
  */
454
- export declare function getDialogImplementation({ requestUserApproval, createInterface, getInterface, }: DialogMethodHooks): (args: RestrictedMethodOptions<DialogParameters>) => Promise<boolean | null | string | Json>;
504
+ export declare function getDialogImplementation({ requestUserApproval, createInterface, getInterface, setInterfaceDisplayed, }: DialogMethodHooks): (args: RestrictedMethodOptions<DialogParameters>) => Promise<DialogResult>;
455
505
  export {};
456
506
  //# sourceMappingURL=dialog.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dialog.d.mts","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,EACL,UAAU,EAIX,4BAA4B;AAC7B,OAAO,KAAK,EACV,YAAY,EAEZ,cAAc,EACd,MAAM,EAEN,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACZ,4BAA4B;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAC3D,OAAO,KAAK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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAmB1B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAC1C,OAAO,sBAAsB,EAC7B,YAAY,CACb,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,qBAAqB,GACtB,EAAE,iBAAiB,UAEV,wBAAwB,gBAAgB,CAAC,KAC9C,QAAQ,YAAY,CAAC,CAuDzB"}
@@ -38,12 +38,56 @@ const methodHooks = {
38
38
  requestUserApproval: true,
39
39
  createInterface: true,
40
40
  getInterface: true,
41
+ setInterfaceDisplayed: true,
41
42
  };
43
+ /* eslint-disable jsdoc/check-indentation */
44
+ /**
45
+ * Display a [dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/)
46
+ * in the MetaMask UI.
47
+ *
48
+ * - `type` - The type of dialog. Not providing a type will create a fully
49
+ * [custom dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/#display-a-custom-dialog).
50
+ * Possible values are:
51
+ * - `alert` - An alert that can only be acknowledged.
52
+ * - `confirmation` - A confirmation that can be accepted or rejected.
53
+ * - `prompt` - A prompt where the user can enter a text response.
54
+ *
55
+ * - One of:
56
+ * - `content` - The content of the alert, as a
57
+ * [custom UI](https://docs.metamask.io/snaps/features/custom-ui/) component.
58
+ * - `id` - The ID of an
59
+ * [interactive interface](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
60
+ * - `placeholder` - An optional placeholder text to display in the dialog. Only
61
+ * applicable for the `prompt` dialog.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx';
66
+ *
67
+ * const walletAddress = await snap.request({
68
+ * method: 'snap_dialog',
69
+ * params: {
70
+ * type: 'prompt',
71
+ * content: (
72
+ * <Box>
73
+ * <Heading>What is the wallet address?</Heading>
74
+ * <Text>Please enter the wallet address to be monitored.</Text>
75
+ * </Box>
76
+ * ),
77
+ * placeholder: '0x123...',
78
+ * },
79
+ * });
80
+ *
81
+ * // `walletAddress` will be a string containing the address entered by the
82
+ * // user.
83
+ * ```
84
+ */
42
85
  export const dialogBuilder = Object.freeze({
43
86
  targetName: methodName,
44
87
  specificationBuilder,
45
88
  methodHooks,
46
89
  });
90
+ /* eslint-enable jsdoc/check-indentation */
47
91
  const AlertParametersWithContentStruct = object({
48
92
  type: enumValue(DialogType.Alert),
49
93
  content: ComponentOrElementStruct,
@@ -124,10 +168,12 @@ const DialogParametersStruct = selectiveUnion((value) => {
124
168
  * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.
125
169
  * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
126
170
  * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.
171
+ * @param hooks.setInterfaceDisplayed - A function that sets the interface as
172
+ * displayed in SnapInterfaceController.
127
173
  * @returns The method implementation which return value depends on the dialog
128
174
  * type, valid return types are: string, boolean, null.
129
175
  */
130
- export function getDialogImplementation({ requestUserApproval, createInterface, getInterface, }) {
176
+ export function getDialogImplementation({ requestUserApproval, createInterface, getInterface, setInterfaceDisplayed, }) {
131
177
  return async function dialogImplementation(args) {
132
178
  const { params, context: { origin }, } = args;
133
179
  if (!isObject(params)) {
@@ -145,6 +191,7 @@ export function getDialogImplementation({ requestUserApproval, createInterface,
145
191
  const approvalType = DIALOG_APPROVAL_TYPES[validatedType];
146
192
  if (hasProperty(validatedParams, 'content')) {
147
193
  const id = await createInterface(origin, validatedParams.content);
194
+ setInterfaceDisplayed(origin, id);
148
195
  return requestUserApproval({
149
196
  id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,
150
197
  origin,
@@ -153,6 +200,7 @@ export function getDialogImplementation({ requestUserApproval, createInterface,
153
200
  });
154
201
  }
155
202
  validateInterface(origin, validatedParams.id, getInterface);
203
+ setInterfaceDisplayed(origin, validatedParams.id);
156
204
  return requestUserApproval({
157
205
  id: approvalType === DIALOG_APPROVAL_TYPES.default
158
206
  ? validatedParams.id
@@ -1 +1 @@
1
- {"version":3,"file":"dialog.mjs","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AACjD,OAAO,EACL,UAAU,EACV,SAAS,EACT,wBAAwB,EACxB,cAAc,EACf,4BAA4B;AAa7B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,8BAA8B;AAE/E,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,wBAAwB;AAIvE,MAAM,UAAU,GAAG,aAAa,CAAC;AAMjC,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,QAAQ;IACzC,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,GAAG,UAAU,eAAe;IACvD,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,GAAG,UAAU,SAAS;IAC3C,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF,MAAM,iBAAiB,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAkE1D;;;;;;;;;;;;;GAaG;AACH,MAAM,oBAAoB,GAItB,CAAC,EACH,cAAc,GAAG,IAAI,EACrB,WAAW,GACuB,EAAE,EAAE;IACtC,OAAO;QACL,cAAc,EAAE,cAAc,CAAC,gBAAgB;QAC/C,UAAU,EAAE,UAAU;QACtB,cAAc;QACd,oBAAoB,EAAE,uB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ED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,MAAwB;IAC9C,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,MAAM,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,CAAC","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 enumValue,\n ComponentOrElementStruct,\n selectiveUnion,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n Component,\n InterfaceState,\n SnapId,\n PromptDialog,\n ComponentOrElement,\n InterfaceContext,\n ContentType,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { create, object, optional, size, string } from '@metamask/superstruct';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nexport type DialogApprovalTypes = Record<DialogType, string> & {\n default: string;\n};\n\nexport const DIALOG_APPROVAL_TYPES = {\n [DialogType.Alert]: `${methodName}:alert`,\n [DialogType.Confirmation]: `${methodName}:confirmation`,\n [DialogType.Prompt]: `${methodName}:prompt`,\n default: methodName,\n};\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype RequestUserApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData: {\n id: string;\n placeholder?: string;\n };\n};\n\ntype RequestUserApproval = (\n opts: RequestUserApprovalOptions,\n) => Promise<boolean | null | string | Json>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param opts - The `requestUserApproval` options.\n * @param opts.id - The approval ID. If not provided, a new approval ID will be generated.\n * @param opts.origin - The origin of the request. In this case, the Snap ID.\n * @param opts.type - The type of the approval request.\n * @param opts.requestData - The data of the approval request.\n * @param opts.requestData.id - The ID of the interface.\n * @param opts.requestData.placeholder - The placeholder of the `Prompt` dialog.\n */\n requestUserApproval: RequestUserApproval;\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 requestUserApproval: 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\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\n\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return AlertParametersWithIdStruct;\n }\n return AlertParametersWithContentStruct;\n});\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return ConfirmationParametersWithIdStruct;\n }\n return ConfirmationParametersWithContentStruct;\n});\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return PromptParametersWithIdStruct;\n }\n return PromptParametersWithContentStruct;\n});\n\nconst DefaultParametersWithContentStruct = object({\n content: ComponentOrElementStruct,\n});\n\nconst DefaultParametersWithIdStruct = object({\n id: string(),\n});\n\nconst DefaultParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return DefaultParametersWithIdStruct;\n }\n return DefaultParametersWithContentStruct;\n});\n\nconst DialogParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'type')) {\n switch (value.type) {\n // We cannot use typedUnion here unfortunately.\n case DialogType.Alert:\n return AlertParametersStruct;\n case DialogType.Confirmation:\n return ConfirmationParametersStruct;\n case DialogType.Prompt:\n return PromptParametersStruct;\n default:\n throw new Error(\n `The \"type\" property must be one of: ${Object.values(DialogType).join(\n ', ',\n )}.`,\n );\n }\n }\n return DefaultParametersStruct;\n});\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.\n * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.\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 requestUserApproval,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string | Json> {\n const {\n params,\n context: { origin },\n } = args;\n\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Invalid params: Expected params to be a single object.',\n });\n }\n\n const validatedParams = getValidatedParams(params);\n const placeholder = isPromptDialog(validatedParams)\n ? validatedParams.placeholder\n : undefined;\n\n const validatedType = hasProperty(validatedParams, 'type')\n ? validatedParams.type\n : 'default';\n\n const approvalType =\n DIALOG_APPROVAL_TYPES[\n validatedType as keyof typeof DIALOG_APPROVAL_TYPES\n ];\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n\n return requestUserApproval({\n id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,\n origin,\n type: approvalType,\n requestData: { id, placeholder },\n });\n }\n\n validateInterface(origin, validatedParams.id, getInterface);\n\n return requestUserApproval({\n id:\n approvalType === DIALOG_APPROVAL_TYPES.default\n ? validatedParams.id\n : undefined,\n origin,\n type: approvalType,\n requestData: { id: validatedParams.id, placeholder },\n });\n };\n}\n/**\n * Validate that the interface ID is valid.\n *\n * @param origin - The origin of the request.\n * @param id - The interface ID.\n * @param getInterface - The function to get the interface.\n */\nfunction validateInterface(\n origin: string,\n id: string,\n getInterface: GetInterface,\n) {\n try {\n getInterface(origin, id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n\n/**\n * Gets the dialog type from the dialog parameters.\n *\n * @param params - The dialog parameters.\n * @returns The dialog type.\n */\nfunction getDialogType(params: DialogParameters): DialogType | undefined {\n return hasProperty(params, 'type') ? (params.type as DialogType) : undefined;\n}\n\n/**\n * Checks if the dialog parameters are for a prompt dialog.\n *\n * @param params - The dialog parameters.\n * @returns `true` if the dialog parameters are for a prompt dialog, `false` otherwise.\n */\nfunction isPromptDialog(params: DialogParameters): params is PromptDialog {\n return getDialogType(params) === DialogType.Prompt;\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 * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(params: unknown): DialogParameters {\n try {\n return create(params, DialogParametersStruct);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"dialog.mjs","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,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,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,CAAC","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 enumValue,\n ComponentOrElementStruct,\n selectiveUnion,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n Component,\n InterfaceState,\n SnapId,\n PromptDialog,\n ComponentOrElement,\n InterfaceContext,\n ContentType,\n DialogResult,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { create, object, optional, size, string } from '@metamask/superstruct';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nexport type DialogApprovalTypes = Record<DialogType, string> & {\n default: string;\n};\n\nexport const DIALOG_APPROVAL_TYPES = {\n [DialogType.Alert]: `${methodName}:alert`,\n [DialogType.Confirmation]: `${methodName}:confirmation`,\n [DialogType.Prompt]: `${methodName}:prompt`,\n default: methodName,\n};\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype RequestUserApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData: {\n id: string;\n placeholder?: string;\n };\n};\n\ntype RequestUserApproval = (\n opts: RequestUserApprovalOptions,\n) => Promise<boolean | null | string | Json>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param opts - The `requestUserApproval` options.\n * @param opts.id - The approval ID. If not provided, a new approval ID will be generated.\n * @param opts.origin - The origin of the request. In this case, the Snap ID.\n * @param opts.type - The type of the approval request.\n * @param opts.requestData - The data of the approval request.\n * @param opts.requestData.id - The ID of the interface.\n * @param opts.requestData.placeholder - The placeholder of the `Prompt` dialog.\n */\n requestUserApproval: RequestUserApproval;\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 /**\n * Set the interface as displayed.\n *\n * @param snapId - The Snap ID requesting the interface.\n * @param id - The interface ID.\n */\n setInterfaceDisplayed: (snapId: string, id: string) => void;\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 requestUserApproval: true,\n createInterface: true,\n getInterface: true,\n setInterfaceDisplayed: true,\n};\n\n/* eslint-disable jsdoc/check-indentation */\n/**\n * Display a [dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/)\n * in the MetaMask UI.\n *\n * - `type` - The type of dialog. Not providing a type will create a fully\n * [custom dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/#display-a-custom-dialog).\n * Possible values are:\n * - `alert` - An alert that can only be acknowledged.\n * - `confirmation` - A confirmation that can be accepted or rejected.\n * - `prompt` - A prompt where the user can enter a text response.\n *\n * - One of:\n * - `content` - The content of the alert, as a\n * [custom UI](https://docs.metamask.io/snaps/features/custom-ui/) component.\n * - `id` - The ID of an\n * [interactive interface](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).\n * - `placeholder` - An optional placeholder text to display in the dialog. Only\n * applicable for the `prompt` dialog.\n *\n * @example\n * ```ts\n * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx';\n *\n * const walletAddress = await snap.request({\n * method: 'snap_dialog',\n * params: {\n * type: 'prompt',\n * content: (\n * <Box>\n * <Heading>What is the wallet address?</Heading>\n * <Text>Please enter the wallet address to be monitored.</Text>\n * </Box>\n * ),\n * placeholder: '0x123...',\n * },\n * });\n *\n * // `walletAddress` will be a string containing the address entered by the\n * // user.\n * ```\n */\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n/* eslint-enable jsdoc/check-indentation */\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\n\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return AlertParametersWithIdStruct;\n }\n return AlertParametersWithContentStruct;\n});\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return ConfirmationParametersWithIdStruct;\n }\n return ConfirmationParametersWithContentStruct;\n});\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return PromptParametersWithIdStruct;\n }\n return PromptParametersWithContentStruct;\n});\n\nconst DefaultParametersWithContentStruct = object({\n content: ComponentOrElementStruct,\n});\n\nconst DefaultParametersWithIdStruct = object({\n id: string(),\n});\n\nconst DefaultParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return DefaultParametersWithIdStruct;\n }\n return DefaultParametersWithContentStruct;\n});\n\nconst DialogParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'type')) {\n switch (value.type) {\n // We cannot use typedUnion here unfortunately.\n case DialogType.Alert:\n return AlertParametersStruct;\n case DialogType.Confirmation:\n return ConfirmationParametersStruct;\n case DialogType.Prompt:\n return PromptParametersStruct;\n default:\n throw new Error(\n `The \"type\" property must be one of: ${Object.values(DialogType).join(\n ', ',\n )}.`,\n );\n }\n }\n return DefaultParametersStruct;\n});\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.\n * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.\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 * @param hooks.setInterfaceDisplayed - A function that sets the interface as\n * displayed in 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 requestUserApproval,\n createInterface,\n getInterface,\n setInterfaceDisplayed,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<DialogResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Invalid params: Expected params to be a single object.',\n });\n }\n\n const validatedParams = getValidatedParams(params);\n const placeholder = isPromptDialog(validatedParams)\n ? validatedParams.placeholder\n : undefined;\n\n const validatedType = hasProperty(validatedParams, 'type')\n ? validatedParams.type\n : 'default';\n\n const approvalType =\n DIALOG_APPROVAL_TYPES[\n validatedType as keyof typeof DIALOG_APPROVAL_TYPES\n ];\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n\n setInterfaceDisplayed(origin, id);\n\n return requestUserApproval({\n id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,\n origin,\n type: approvalType,\n requestData: { id, placeholder },\n });\n }\n\n validateInterface(origin, validatedParams.id, getInterface);\n setInterfaceDisplayed(origin, validatedParams.id);\n\n return requestUserApproval({\n id:\n approvalType === DIALOG_APPROVAL_TYPES.default\n ? validatedParams.id\n : undefined,\n origin,\n type: approvalType,\n requestData: { id: validatedParams.id, placeholder },\n });\n };\n}\n/**\n * Validate that the interface ID is valid.\n *\n * @param origin - The origin of the request.\n * @param id - The interface ID.\n * @param getInterface - The function to get the interface.\n */\nfunction validateInterface(\n origin: string,\n id: string,\n getInterface: GetInterface,\n) {\n try {\n getInterface(origin, id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n\n/**\n * Gets the dialog type from the dialog parameters.\n *\n * @param params - The dialog parameters.\n * @returns The dialog type.\n */\nfunction getDialogType(params: DialogParameters): DialogType | undefined {\n return hasProperty(params, 'type') ? (params.type as DialogType) : undefined;\n}\n\n/**\n * Checks if the dialog parameters are for a prompt dialog.\n *\n * @param params - The dialog parameters.\n * @returns `true` if the dialog parameters are for a prompt dialog, `false` otherwise.\n */\nfunction isPromptDialog(params: DialogParameters): params is PromptDialog {\n return getDialogType(params) === DialogType.Prompt;\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 * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(params: unknown): DialogParameters {\n try {\n return create(params, DialogParametersStruct);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
@@ -39,6 +39,61 @@ const methodHooks = {
39
39
  getUnlockPromise: true,
40
40
  getClientCryptography: true,
41
41
  };
42
+ /**
43
+ * Enables you to [manage users' non-EVM accounts](https://docs.metamask.io/snaps/features/non-evm-networks/)
44
+ * by deriving the [SLIP-10](https://github.com/satoshilabs/slips/blob/master/slip-0010.md)
45
+ * keys specified by the `path` and `curve` parameters. The keys are derived
46
+ * using the entropy from the user's Secret Recovery Phrase.
47
+ *
48
+ * If the keys you want to derive conform to the [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)
49
+ * structure, use [snap_getBip44Entropy](https://docs.metamask.io/snaps/reference/snaps-api/snap_getbip44entropy)
50
+ * instead. Otherwise, use this method.
51
+ *
52
+ * This method is designed to be used with the [`@metamask/key-tree`](https://npmjs.com/package/@metamask/key-tree)
53
+ * module. `@metamask/key-tree` can help you get the [extended private keys](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys)
54
+ * for user addresses, but it's your responsibility to know how to use those
55
+ * keys to, for example, derive an address for the relevant protocol or sign a
56
+ * transaction for the user.
57
+ *
58
+ * @example
59
+ * ```json name="Manifest"
60
+ * {
61
+ * "initialPermissions": {
62
+ * "snap_getBip32Entropy": [
63
+ * {
64
+ * "path": ["m", "44'", "3'"],
65
+ * "curve": "secp256k1" // Or "ed25519", "ed25519Bip32"
66
+ * }
67
+ * ]
68
+ * }
69
+ * }
70
+ * ```
71
+ * ```ts name="Usage"
72
+ * import { SLIP10Node } from '@metamask/key-tree'
73
+ *
74
+ * // This example uses Dogecoin, which has a derivation path starting with
75
+ * // m/44'/3'.
76
+ * const dogecoinNode = await snap.request({
77
+ * method: 'snap_getBip32Entropy',
78
+ * params: {
79
+ * // The path and curve must be specified in the initial permissions.
80
+ * path: ['m', "44'", "3'"],
81
+ * curve: 'secp256k1',
82
+ * },
83
+ * })
84
+ *
85
+ * // Next, create an instance of a SLIP-10 node for the Dogecoin node.
86
+ * const dogecoinSlip10Node = await SLIP10Node.fromJSON(dogecoinNode)
87
+ *
88
+ * // m/44'/3'/0'
89
+ * const accountKey0 = await dogecoinSlip10Node.derive(["bip32:0'"])
90
+ *
91
+ * // m/44'/3'/1'
92
+ * const accountKey1 = await dogecoinSlip10Node.derive(["bip32:1'"])
93
+ *
94
+ * // Now, you can ask the user to sign transactions, etc.
95
+ * ```
96
+ */
42
97
  exports.getBip32EntropyBuilder = Object.freeze({
43
98
  targetName,
44
99
  specificationBuilder,
@@ -1 +1 @@
1
- {"version":3,"file":"getBip32Entropy.cjs","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":";;;AAOA,2EAA8E;AAC9E,qDAAiD;AAKjD,uDAAuD;AAEvD,2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AC;QAEf,kFAAkF;QAClF,IAAI,MAAM,CAAC,KAAK,KAAK,WAAW,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/D,MAAM,IAAI,GAAG,MAAM,IAAA,iCAAyB,EAC1C,eAAe,EACf,MAAM,CAAC,MAAM,CACd,CAAC;YAEF,MAAM,IAAI,GAAG,MAAM,IAAA,uBAAe,EAAC;gBACjC,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI;gBACJ,sBAAsB,EAAE,qBAAqB,EAAE;aAChD,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;QAED,MAAM,oBAAoB,GAAG,MAAM,IAAA,iCAAyB,EAC1D,WAAW,EACX,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,MAAM,IAAI,GAAG,MAAM,IAAA,2BAAmB,EAAC;YACrC,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,oBAAoB;YACpB,sBAAsB,EAAE,qBAAqB,EAAE;SAChD,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC;AA7CD,sEA6CC","sourcesContent":["import type { CryptographicFunctions } 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 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 {\n getNodeFromMnemonic,\n getNodeFromSeed,\n getValueFromEntropySource,\n} from '../utils';\n\nconst targetName = 'snap_getBip32Entropy';\n\nexport type GetBip32EntropyMethodHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Get the mnemonic seed of the provided source. If no source is provided, the\n * mnemonic seed of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic seed of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\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 getMnemonicSeed: true,\n getUnlockPromise: true,\n getClientCryptography: 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.getMnemonicSeed - A function to retrieve the BIP-39 seed 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 * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a `JsonSLIP10Node`.\n * @throws If the params are invalid.\n */\nexport function getBip32EntropyImplementation({\n getMnemonic,\n getMnemonicSeed,\n getUnlockPromise,\n getClientCryptography,\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 // Using the seed is much faster, but we can only do it for these specific curves.\n if (params.curve === 'secp256k1' || params.curve === 'ed25519') {\n const seed = await getValueFromEntropySource(\n getMnemonicSeed,\n params.source,\n );\n\n const node = await getNodeFromSeed({\n curve: params.curve,\n path: params.path,\n seed,\n cryptographicFunctions: getClientCryptography(),\n });\n\n return node.toJSON();\n }\n\n const secretRecoveryPhrase = await getValueFromEntropySource(\n getMnemonic,\n params.source,\n );\n\n const node = await getNodeFromMnemonic({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase,\n cryptographicFunctions: getClientCryptography(),\n });\n\n return node.toJSON();\n };\n}\n"]}
1
+ {"version":3,"file":"getBip32Entropy.cjs","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":";;;AAOA,2EAA8E;AAC9E,qDAAiD;AAKjD,uDAAuD;AAEvD,2CAAyC;AAGzC,wCAIkB;AAElB,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAoD1C;;;;;;;;GAQG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE,WAAW,EAA8C,EAAE,EAAE;IAClE,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc,EAAE,CAAC,4BAAc,CAAC,wBAAwB,CAAC;QACzD,oBAAoB,EAAE,6BAA6B,CAAC,WAAW,CAAC;QAChE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YACzB,IACE,OAAO,EAAE,MAAM,KAAK,CAAC;gBACrB,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,4BAAc,CAAC,wBAAwB,EAC3D,CAAC;gBACD,MAAM,sBAAS,CAAC,aAAa,CAAC;oBAC5B,OAAO,EAAE,sBAAsB,4BAAc,CAAC,wBAAwB,WAAW;iBAClF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,YAAY,EAAE,CAAC,mCAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,WAAW,GAAkD;IACjE,WAAW,EAAE,IAAI;IACjB,eAAe,EAAE,IAAI;IACrB,gBAAgB,EAAE,IAAI;IACtB,qBAAqB,EAAE,IAAI;CAC5B,CAAC;AAEF;;;;;;;;;;;;;;;;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;AACJ,CAAC;AA7CD,sEA6CC","sourcesContent":["import type { CryptographicFunctions } 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 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 {\n getNodeFromMnemonic,\n getNodeFromSeed,\n getValueFromEntropySource,\n} from '../utils';\n\nconst targetName = 'snap_getBip32Entropy';\n\nexport type GetBip32EntropyMethodHooks = {\n /**\n * Get the mnemonic of the provided source. If no source is provided, the\n * mnemonic of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Get the mnemonic seed of the provided source. If no source is provided, the\n * mnemonic seed of the primary keyring will be returned.\n *\n * @param source - The optional ID of the source to get the mnemonic of.\n * @returns The mnemonic seed of the provided source, or the default source if no\n * source is provided.\n */\n getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object or `undefined` to fall back to the default cryptographic\n * functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions | undefined;\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 getMnemonicSeed: true,\n getUnlockPromise: true,\n getClientCryptography: true,\n};\n\n/**\n * Enables you to [manage users' non-EVM accounts](https://docs.metamask.io/snaps/features/non-evm-networks/)\n * by deriving the [SLIP-10](https://github.com/satoshilabs/slips/blob/master/slip-0010.md)\n * keys specified by the `path` and `curve` parameters. The keys are derived\n * using the entropy from the user's Secret Recovery Phrase.\n *\n * If the keys you want to derive conform to the [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)\n * structure, use [snap_getBip44Entropy](https://docs.metamask.io/snaps/reference/snaps-api/snap_getbip44entropy)\n * instead. Otherwise, use this method.\n *\n * This method is designed to be used with the [`@metamask/key-tree`](https://npmjs.com/package/@metamask/key-tree)\n * module. `@metamask/key-tree` can help you get the [extended private keys](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys)\n * for user addresses, but it's your responsibility to know how to use those\n * keys to, for example, derive an address for the relevant protocol or sign a\n * transaction for the user.\n *\n * @example\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_getBip32Entropy\": [\n * {\n * \"path\": [\"m\", \"44'\", \"3'\"],\n * \"curve\": \"secp256k1\" // Or \"ed25519\", \"ed25519Bip32\"\n * }\n * ]\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * import { SLIP10Node } from '@metamask/key-tree'\n *\n * // This example uses Dogecoin, which has a derivation path starting with\n * // m/44'/3'.\n * const dogecoinNode = await snap.request({\n * method: 'snap_getBip32Entropy',\n * params: {\n * // The path and curve must be specified in the initial permissions.\n * path: ['m', \"44'\", \"3'\"],\n * curve: 'secp256k1',\n * },\n * })\n *\n * // Next, create an instance of a SLIP-10 node for the Dogecoin node.\n * const dogecoinSlip10Node = await SLIP10Node.fromJSON(dogecoinNode)\n *\n * // m/44'/3'/0'\n * const accountKey0 = await dogecoinSlip10Node.derive([\"bip32:0'\"])\n *\n * // m/44'/3'/1'\n * const accountKey1 = await dogecoinSlip10Node.derive([\"bip32:1'\"])\n *\n * // Now, you can ask the user to sign transactions, etc.\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.getMnemonicSeed - A function to retrieve the BIP-39 seed 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 * @param hooks.getClientCryptography - A function to retrieve the cryptographic\n * functions to use for the client.\n * @returns The method implementation which returns a `JsonSLIP10Node`.\n * @throws If the params are invalid.\n */\nexport function getBip32EntropyImplementation({\n getMnemonic,\n getMnemonicSeed,\n getUnlockPromise,\n getClientCryptography,\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 // Using the seed is much faster, but we can only do it for these specific curves.\n if (params.curve === 'secp256k1' || params.curve === 'ed25519') {\n const seed = await getValueFromEntropySource(\n getMnemonicSeed,\n params.source,\n );\n\n const node = await getNodeFromSeed({\n curve: params.curve,\n path: params.path,\n seed,\n cryptographicFunctions: getClientCryptography(),\n });\n\n return node.toJSON();\n }\n\n const secretRecoveryPhrase = await getValueFromEntropySource(\n getMnemonic,\n params.source,\n );\n\n const node = await getNodeFromMnemonic({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase,\n cryptographicFunctions: getClientCryptography(),\n });\n\n return node.toJSON();\n };\n}\n"]}
@@ -42,6 +42,61 @@ export type GetBip32EntropyMethodHooks = {
42
42
  type GetBip32EntropySpecificationBuilderOptions = {
43
43
  methodHooks: GetBip32EntropyMethodHooks;
44
44
  };
45
+ /**
46
+ * Enables you to [manage users' non-EVM accounts](https://docs.metamask.io/snaps/features/non-evm-networks/)
47
+ * by deriving the [SLIP-10](https://github.com/satoshilabs/slips/blob/master/slip-0010.md)
48
+ * keys specified by the `path` and `curve` parameters. The keys are derived
49
+ * using the entropy from the user's Secret Recovery Phrase.
50
+ *
51
+ * If the keys you want to derive conform to the [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)
52
+ * structure, use [snap_getBip44Entropy](https://docs.metamask.io/snaps/reference/snaps-api/snap_getbip44entropy)
53
+ * instead. Otherwise, use this method.
54
+ *
55
+ * This method is designed to be used with the [`@metamask/key-tree`](https://npmjs.com/package/@metamask/key-tree)
56
+ * module. `@metamask/key-tree` can help you get the [extended private keys](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys)
57
+ * for user addresses, but it's your responsibility to know how to use those
58
+ * keys to, for example, derive an address for the relevant protocol or sign a
59
+ * transaction for the user.
60
+ *
61
+ * @example
62
+ * ```json name="Manifest"
63
+ * {
64
+ * "initialPermissions": {
65
+ * "snap_getBip32Entropy": [
66
+ * {
67
+ * "path": ["m", "44'", "3'"],
68
+ * "curve": "secp256k1" // Or "ed25519", "ed25519Bip32"
69
+ * }
70
+ * ]
71
+ * }
72
+ * }
73
+ * ```
74
+ * ```ts name="Usage"
75
+ * import { SLIP10Node } from '@metamask/key-tree'
76
+ *
77
+ * // This example uses Dogecoin, which has a derivation path starting with
78
+ * // m/44'/3'.
79
+ * const dogecoinNode = await snap.request({
80
+ * method: 'snap_getBip32Entropy',
81
+ * params: {
82
+ * // The path and curve must be specified in the initial permissions.
83
+ * path: ['m', "44'", "3'"],
84
+ * curve: 'secp256k1',
85
+ * },
86
+ * })
87
+ *
88
+ * // Next, create an instance of a SLIP-10 node for the Dogecoin node.
89
+ * const dogecoinSlip10Node = await SLIP10Node.fromJSON(dogecoinNode)
90
+ *
91
+ * // m/44'/3'/0'
92
+ * const accountKey0 = await dogecoinSlip10Node.derive(["bip32:0'"])
93
+ *
94
+ * // m/44'/3'/1'
95
+ * const accountKey1 = await dogecoinSlip10Node.derive(["bip32:1'"])
96
+ *
97
+ * // Now, you can ask the user to sign transactions, etc.
98
+ * ```
99
+ */
45
100
  export declare const getBip32EntropyBuilder: Readonly<{
46
101
  readonly targetName: "snap_getBip32Entropy";
47
102
  readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, GetBip32EntropySpecificationBuilderOptions, {
@@ -1 +1 @@
1
- {"version":3,"file":"getBip32Entropy.d.cts","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAA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,EACX,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,0BAA0B,UAEnB,wBAAwB,qBAAqB,CAAC,KACnD,QAAQ,qBAAqB,CAAC,CAqClC"}
@@ -42,6 +42,61 @@ export type GetBip32EntropyMethodHooks = {
42
42
  type GetBip32EntropySpecificationBuilderOptions = {
43
43
  methodHooks: GetBip32EntropyMethodHooks;
44
44
  };
45
+ /**
46
+ * Enables you to [manage users' non-EVM accounts](https://docs.metamask.io/snaps/features/non-evm-networks/)
47
+ * by deriving the [SLIP-10](https://github.com/satoshilabs/slips/blob/master/slip-0010.md)
48
+ * keys specified by the `path` and `curve` parameters. The keys are derived
49
+ * using the entropy from the user's Secret Recovery Phrase.
50
+ *
51
+ * If the keys you want to derive conform to the [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)
52
+ * structure, use [snap_getBip44Entropy](https://docs.metamask.io/snaps/reference/snaps-api/snap_getbip44entropy)
53
+ * instead. Otherwise, use this method.
54
+ *
55
+ * This method is designed to be used with the [`@metamask/key-tree`](https://npmjs.com/package/@metamask/key-tree)
56
+ * module. `@metamask/key-tree` can help you get the [extended private keys](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys)
57
+ * for user addresses, but it's your responsibility to know how to use those
58
+ * keys to, for example, derive an address for the relevant protocol or sign a
59
+ * transaction for the user.
60
+ *
61
+ * @example
62
+ * ```json name="Manifest"
63
+ * {
64
+ * "initialPermissions": {
65
+ * "snap_getBip32Entropy": [
66
+ * {
67
+ * "path": ["m", "44'", "3'"],
68
+ * "curve": "secp256k1" // Or "ed25519", "ed25519Bip32"
69
+ * }
70
+ * ]
71
+ * }
72
+ * }
73
+ * ```
74
+ * ```ts name="Usage"
75
+ * import { SLIP10Node } from '@metamask/key-tree'
76
+ *
77
+ * // This example uses Dogecoin, which has a derivation path starting with
78
+ * // m/44'/3'.
79
+ * const dogecoinNode = await snap.request({
80
+ * method: 'snap_getBip32Entropy',
81
+ * params: {
82
+ * // The path and curve must be specified in the initial permissions.
83
+ * path: ['m', "44'", "3'"],
84
+ * curve: 'secp256k1',
85
+ * },
86
+ * })
87
+ *
88
+ * // Next, create an instance of a SLIP-10 node for the Dogecoin node.
89
+ * const dogecoinSlip10Node = await SLIP10Node.fromJSON(dogecoinNode)
90
+ *
91
+ * // m/44'/3'/0'
92
+ * const accountKey0 = await dogecoinSlip10Node.derive(["bip32:0'"])
93
+ *
94
+ * // m/44'/3'/1'
95
+ * const accountKey1 = await dogecoinSlip10Node.derive(["bip32:1'"])
96
+ *
97
+ * // Now, you can ask the user to sign transactions, etc.
98
+ * ```
99
+ */
45
100
  export declare const getBip32EntropyBuilder: Readonly<{
46
101
  readonly targetName: "snap_getBip32Entropy";
47
102
  readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, GetBip32EntropySpecificationBuilderOptions, {
@@ -1 +1 @@
1
- {"version":3,"file":"getBip32Entropy.d.mts","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAOlD,QAAA,MAAM,UAAU,yBAAyB,CAAC;AAE1C,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;;;;OAOG;IACH,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAElE;;;;;;;OAOG;IACH,eAAe,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,O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AU,CAAC,CAAC;IAElE;;;;;;;OAOG;IACH,eAAe,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAEtE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE;;;;;;OAMG;IACH,qBAAqB,EAAE,MAAM,sBAAsB,GAAG,SAAS,CAAC;CACjE,CAAC;AAEF,KAAK,0CAA0C,GAAG;IAChD,WAAW,EAAE,0BAA0B,CAAC;CACzC,CAAC;AAkDF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,eAAO,MAAM,sBAAsB;;;wBAtGjB,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,oCAAoC,CAAC;wBACtD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;mBAC3C,6BAA6B;;;EAsG/B,CAAC;AAEZ;;;;;;;;;;;;GAYG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,EAAE,0BAA0B,UAEnB,wBAAwB,qBAAqB,CAAC,KACnD,QAAQ,qBAAqB,CAAC,CAqClC"}
@@ -36,6 +36,61 @@ const methodHooks = {
36
36
  getUnlockPromise: true,
37
37
  getClientCryptography: true,
38
38
  };
39
+ /**
40
+ * Enables you to [manage users' non-EVM accounts](https://docs.metamask.io/snaps/features/non-evm-networks/)
41
+ * by deriving the [SLIP-10](https://github.com/satoshilabs/slips/blob/master/slip-0010.md)
42
+ * keys specified by the `path` and `curve` parameters. The keys are derived
43
+ * using the entropy from the user's Secret Recovery Phrase.
44
+ *
45
+ * If the keys you want to derive conform to the [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)
46
+ * structure, use [snap_getBip44Entropy](https://docs.metamask.io/snaps/reference/snaps-api/snap_getbip44entropy)
47
+ * instead. Otherwise, use this method.
48
+ *
49
+ * This method is designed to be used with the [`@metamask/key-tree`](https://npmjs.com/package/@metamask/key-tree)
50
+ * module. `@metamask/key-tree` can help you get the [extended private keys](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys)
51
+ * for user addresses, but it's your responsibility to know how to use those
52
+ * keys to, for example, derive an address for the relevant protocol or sign a
53
+ * transaction for the user.
54
+ *
55
+ * @example
56
+ * ```json name="Manifest"
57
+ * {
58
+ * "initialPermissions": {
59
+ * "snap_getBip32Entropy": [
60
+ * {
61
+ * "path": ["m", "44'", "3'"],
62
+ * "curve": "secp256k1" // Or "ed25519", "ed25519Bip32"
63
+ * }
64
+ * ]
65
+ * }
66
+ * }
67
+ * ```
68
+ * ```ts name="Usage"
69
+ * import { SLIP10Node } from '@metamask/key-tree'
70
+ *
71
+ * // This example uses Dogecoin, which has a derivation path starting with
72
+ * // m/44'/3'.
73
+ * const dogecoinNode = await snap.request({
74
+ * method: 'snap_getBip32Entropy',
75
+ * params: {
76
+ * // The path and curve must be specified in the initial permissions.
77
+ * path: ['m', "44'", "3'"],
78
+ * curve: 'secp256k1',
79
+ * },
80
+ * })
81
+ *
82
+ * // Next, create an instance of a SLIP-10 node for the Dogecoin node.
83
+ * const dogecoinSlip10Node = await SLIP10Node.fromJSON(dogecoinNode)
84
+ *
85
+ * // m/44'/3'/0'
86
+ * const accountKey0 = await dogecoinSlip10Node.derive(["bip32:0'"])
87
+ *
88
+ * // m/44'/3'/1'
89
+ * const accountKey1 = await dogecoinSlip10Node.derive(["bip32:1'"])
90
+ *
91
+ * // Now, you can ask the user to sign transactions, etc.
92
+ * ```
93
+ */
39
94
  export const getBip32EntropyBuilder = Object.freeze({
40
95
  targetName,
41
96
  specificationBuilder,