@metamask/snaps-rpc-methods 15.1.0 → 16.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 (352) hide show
  1. package/CHANGELOG.md +34 -4
  2. package/dist/endowments/keyring.cjs +2 -5
  3. package/dist/endowments/keyring.cjs.map +1 -1
  4. package/dist/endowments/keyring.d.cts +0 -2
  5. package/dist/endowments/keyring.d.cts.map +1 -1
  6. package/dist/endowments/keyring.d.mts +0 -2
  7. package/dist/endowments/keyring.d.mts.map +1 -1
  8. package/dist/endowments/keyring.mjs +3 -6
  9. package/dist/endowments/keyring.mjs.map +1 -1
  10. package/dist/index.cjs +1 -4
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +1 -2
  13. package/dist/index.d.cts.map +1 -1
  14. package/dist/index.d.mts +1 -2
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +1 -2
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/permissions.cjs +18 -8
  19. package/dist/permissions.cjs.map +1 -1
  20. package/dist/permissions.d.cts +3 -2
  21. package/dist/permissions.d.cts.map +1 -1
  22. package/dist/permissions.d.mts +3 -2
  23. package/dist/permissions.d.mts.map +1 -1
  24. package/dist/permissions.mjs +17 -7
  25. package/dist/permissions.mjs.map +1 -1
  26. package/dist/permitted/cancelBackgroundEvent.cjs +10 -14
  27. package/dist/permitted/cancelBackgroundEvent.cjs.map +1 -1
  28. package/dist/permitted/cancelBackgroundEvent.d.cts +9 -12
  29. package/dist/permitted/cancelBackgroundEvent.d.cts.map +1 -1
  30. package/dist/permitted/cancelBackgroundEvent.d.mts +9 -12
  31. package/dist/permitted/cancelBackgroundEvent.d.mts.map +1 -1
  32. package/dist/permitted/cancelBackgroundEvent.mjs +10 -14
  33. package/dist/permitted/cancelBackgroundEvent.mjs.map +1 -1
  34. package/dist/permitted/clearState.cjs +10 -16
  35. package/dist/permitted/clearState.cjs.map +1 -1
  36. package/dist/permitted/clearState.d.cts +9 -23
  37. package/dist/permitted/clearState.d.cts.map +1 -1
  38. package/dist/permitted/clearState.d.mts +9 -23
  39. package/dist/permitted/clearState.d.mts.map +1 -1
  40. package/dist/permitted/clearState.mjs +10 -16
  41. package/dist/permitted/clearState.mjs.map +1 -1
  42. package/dist/permitted/closeWebSocket.cjs +7 -14
  43. package/dist/permitted/closeWebSocket.cjs.map +1 -1
  44. package/dist/permitted/closeWebSocket.d.cts +9 -12
  45. package/dist/permitted/closeWebSocket.d.cts.map +1 -1
  46. package/dist/permitted/closeWebSocket.d.mts +9 -12
  47. package/dist/permitted/closeWebSocket.d.mts.map +1 -1
  48. package/dist/permitted/closeWebSocket.mjs +7 -14
  49. package/dist/permitted/closeWebSocket.mjs.map +1 -1
  50. package/dist/permitted/createInterface.cjs +11 -15
  51. package/dist/permitted/createInterface.cjs.map +1 -1
  52. package/dist/permitted/createInterface.d.cts +23 -37
  53. package/dist/permitted/createInterface.d.cts.map +1 -1
  54. package/dist/permitted/createInterface.d.mts +23 -37
  55. package/dist/permitted/createInterface.d.mts.map +1 -1
  56. package/dist/permitted/createInterface.mjs +11 -15
  57. package/dist/permitted/createInterface.mjs.map +1 -1
  58. package/dist/permitted/endTrace.cjs +4 -6
  59. package/dist/permitted/endTrace.cjs.map +1 -1
  60. package/dist/permitted/endTrace.d.cts +8 -11
  61. package/dist/permitted/endTrace.d.cts.map +1 -1
  62. package/dist/permitted/endTrace.d.mts +8 -11
  63. package/dist/permitted/endTrace.d.mts.map +1 -1
  64. package/dist/permitted/endTrace.mjs +4 -6
  65. package/dist/permitted/endTrace.mjs.map +1 -1
  66. package/dist/permitted/getAllSnaps.cjs +5 -11
  67. package/dist/permitted/getAllSnaps.cjs.map +1 -1
  68. package/dist/permitted/getAllSnaps.d.cts +10 -14
  69. package/dist/permitted/getAllSnaps.d.cts.map +1 -1
  70. package/dist/permitted/getAllSnaps.d.mts +10 -14
  71. package/dist/permitted/getAllSnaps.d.mts.map +1 -1
  72. package/dist/permitted/getAllSnaps.mjs +5 -11
  73. package/dist/permitted/getAllSnaps.mjs.map +1 -1
  74. package/dist/permitted/getBackgroundEvents.cjs +8 -15
  75. package/dist/permitted/getBackgroundEvents.cjs.map +1 -1
  76. package/dist/permitted/getBackgroundEvents.d.cts +10 -13
  77. package/dist/permitted/getBackgroundEvents.d.cts.map +1 -1
  78. package/dist/permitted/getBackgroundEvents.d.mts +10 -13
  79. package/dist/permitted/getBackgroundEvents.d.mts.map +1 -1
  80. package/dist/permitted/getBackgroundEvents.mjs +8 -15
  81. package/dist/permitted/getBackgroundEvents.mjs.map +1 -1
  82. package/dist/permitted/getClientStatus.cjs +5 -6
  83. package/dist/permitted/getClientStatus.cjs.map +1 -1
  84. package/dist/permitted/getClientStatus.d.cts +17 -18
  85. package/dist/permitted/getClientStatus.d.cts.map +1 -1
  86. package/dist/permitted/getClientStatus.d.mts +17 -18
  87. package/dist/permitted/getClientStatus.d.mts.map +1 -1
  88. package/dist/permitted/getClientStatus.mjs +5 -6
  89. package/dist/permitted/getClientStatus.mjs.map +1 -1
  90. package/dist/permitted/getFile.cjs +7 -11
  91. package/dist/permitted/getFile.cjs.map +1 -1
  92. package/dist/permitted/getFile.d.cts +8 -10
  93. package/dist/permitted/getFile.d.cts.map +1 -1
  94. package/dist/permitted/getFile.d.mts +8 -10
  95. package/dist/permitted/getFile.d.mts.map +1 -1
  96. package/dist/permitted/getFile.mjs +7 -11
  97. package/dist/permitted/getFile.mjs.map +1 -1
  98. package/dist/permitted/getInterfaceContext.cjs +12 -15
  99. package/dist/permitted/getInterfaceContext.cjs.map +1 -1
  100. package/dist/permitted/getInterfaceContext.d.cts +9 -21
  101. package/dist/permitted/getInterfaceContext.d.cts.map +1 -1
  102. package/dist/permitted/getInterfaceContext.d.mts +9 -21
  103. package/dist/permitted/getInterfaceContext.d.mts.map +1 -1
  104. package/dist/permitted/getInterfaceContext.mjs +12 -15
  105. package/dist/permitted/getInterfaceContext.mjs.map +1 -1
  106. package/dist/permitted/getInterfaceState.cjs +11 -15
  107. package/dist/permitted/getInterfaceState.cjs.map +1 -1
  108. package/dist/permitted/getInterfaceState.d.cts +9 -21
  109. package/dist/permitted/getInterfaceState.d.cts.map +1 -1
  110. package/dist/permitted/getInterfaceState.d.mts +9 -21
  111. package/dist/permitted/getInterfaceState.d.mts.map +1 -1
  112. package/dist/permitted/getInterfaceState.mjs +11 -15
  113. package/dist/permitted/getInterfaceState.mjs.map +1 -1
  114. package/dist/permitted/getSnaps.cjs +6 -12
  115. package/dist/permitted/getSnaps.cjs.map +1 -1
  116. package/dist/permitted/getSnaps.d.cts +11 -14
  117. package/dist/permitted/getSnaps.d.cts.map +1 -1
  118. package/dist/permitted/getSnaps.d.mts +11 -14
  119. package/dist/permitted/getSnaps.d.mts.map +1 -1
  120. package/dist/permitted/getSnaps.mjs +6 -12
  121. package/dist/permitted/getSnaps.mjs.map +1 -1
  122. package/dist/permitted/getState.cjs +9 -11
  123. package/dist/permitted/getState.cjs.map +1 -1
  124. package/dist/permitted/getState.d.cts +17 -28
  125. package/dist/permitted/getState.d.cts.map +1 -1
  126. package/dist/permitted/getState.d.mts +17 -28
  127. package/dist/permitted/getState.d.mts.map +1 -1
  128. package/dist/permitted/getState.mjs +9 -11
  129. package/dist/permitted/getState.mjs.map +1 -1
  130. package/dist/permitted/getWebSockets.cjs +11 -14
  131. package/dist/permitted/getWebSockets.cjs.map +1 -1
  132. package/dist/permitted/getWebSockets.d.cts +10 -13
  133. package/dist/permitted/getWebSockets.d.cts.map +1 -1
  134. package/dist/permitted/getWebSockets.d.mts +10 -13
  135. package/dist/permitted/getWebSockets.d.mts.map +1 -1
  136. package/dist/permitted/getWebSockets.mjs +11 -14
  137. package/dist/permitted/getWebSockets.mjs.map +1 -1
  138. package/dist/permitted/index.cjs +0 -1
  139. package/dist/permitted/index.cjs.map +1 -1
  140. package/dist/permitted/index.d.cts +29 -25
  141. package/dist/permitted/index.d.cts.map +1 -1
  142. package/dist/permitted/index.d.mts +29 -25
  143. package/dist/permitted/index.d.mts.map +1 -1
  144. package/dist/permitted/index.mjs +0 -1
  145. package/dist/permitted/index.mjs.map +1 -1
  146. package/dist/permitted/invokeKeyring.cjs +12 -13
  147. package/dist/permitted/invokeKeyring.cjs.map +1 -1
  148. package/dist/permitted/invokeKeyring.d.cts +17 -16
  149. package/dist/permitted/invokeKeyring.d.cts.map +1 -1
  150. package/dist/permitted/invokeKeyring.d.mts +17 -16
  151. package/dist/permitted/invokeKeyring.d.mts.map +1 -1
  152. package/dist/permitted/invokeKeyring.mjs +12 -13
  153. package/dist/permitted/invokeKeyring.mjs.map +1 -1
  154. package/dist/permitted/invokeSnapSugar.cjs +6 -10
  155. package/dist/permitted/invokeSnapSugar.cjs.map +1 -1
  156. package/dist/permitted/invokeSnapSugar.d.cts +9 -12
  157. package/dist/permitted/invokeSnapSugar.d.cts.map +1 -1
  158. package/dist/permitted/invokeSnapSugar.d.mts +9 -12
  159. package/dist/permitted/invokeSnapSugar.d.mts.map +1 -1
  160. package/dist/permitted/invokeSnapSugar.mjs +6 -10
  161. package/dist/permitted/invokeSnapSugar.mjs.map +1 -1
  162. package/dist/permitted/listEntropySources.cjs +28 -12
  163. package/dist/permitted/listEntropySources.cjs.map +1 -1
  164. package/dist/permitted/listEntropySources.d.cts +12 -23
  165. package/dist/permitted/listEntropySources.d.cts.map +1 -1
  166. package/dist/permitted/listEntropySources.d.mts +12 -23
  167. package/dist/permitted/listEntropySources.d.mts.map +1 -1
  168. package/dist/permitted/listEntropySources.mjs +28 -12
  169. package/dist/permitted/listEntropySources.mjs.map +1 -1
  170. package/dist/permitted/middleware.cjs +70 -20
  171. package/dist/permitted/middleware.cjs.map +1 -1
  172. package/dist/permitted/middleware.d.cts +5 -2
  173. package/dist/permitted/middleware.d.cts.map +1 -1
  174. package/dist/permitted/middleware.d.mts +5 -2
  175. package/dist/permitted/middleware.d.mts.map +1 -1
  176. package/dist/permitted/middleware.mjs +70 -20
  177. package/dist/permitted/middleware.mjs.map +1 -1
  178. package/dist/permitted/openWebSocket.cjs +7 -14
  179. package/dist/permitted/openWebSocket.cjs.map +1 -1
  180. package/dist/permitted/openWebSocket.d.cts +9 -12
  181. package/dist/permitted/openWebSocket.d.cts.map +1 -1
  182. package/dist/permitted/openWebSocket.d.mts +9 -12
  183. package/dist/permitted/openWebSocket.d.mts.map +1 -1
  184. package/dist/permitted/openWebSocket.mjs +7 -14
  185. package/dist/permitted/openWebSocket.mjs.map +1 -1
  186. package/dist/permitted/requestSnaps.cjs +14 -19
  187. package/dist/permitted/requestSnaps.cjs.map +1 -1
  188. package/dist/permitted/requestSnaps.d.cts +9 -36
  189. package/dist/permitted/requestSnaps.d.cts.map +1 -1
  190. package/dist/permitted/requestSnaps.d.mts +9 -36
  191. package/dist/permitted/requestSnaps.d.mts.map +1 -1
  192. package/dist/permitted/requestSnaps.mjs +15 -20
  193. package/dist/permitted/requestSnaps.mjs.map +1 -1
  194. package/dist/permitted/resolveInterface.cjs +11 -15
  195. package/dist/permitted/resolveInterface.cjs.map +1 -1
  196. package/dist/permitted/resolveInterface.d.cts +12 -24
  197. package/dist/permitted/resolveInterface.d.cts.map +1 -1
  198. package/dist/permitted/resolveInterface.d.mts +12 -24
  199. package/dist/permitted/resolveInterface.d.mts.map +1 -1
  200. package/dist/permitted/resolveInterface.mjs +11 -15
  201. package/dist/permitted/resolveInterface.mjs.map +1 -1
  202. package/dist/permitted/scheduleBackgroundEvent.cjs +11 -14
  203. package/dist/permitted/scheduleBackgroundEvent.cjs.map +1 -1
  204. package/dist/permitted/scheduleBackgroundEvent.d.cts +10 -17
  205. package/dist/permitted/scheduleBackgroundEvent.d.cts.map +1 -1
  206. package/dist/permitted/scheduleBackgroundEvent.d.mts +10 -17
  207. package/dist/permitted/scheduleBackgroundEvent.d.mts.map +1 -1
  208. package/dist/permitted/scheduleBackgroundEvent.mjs +11 -14
  209. package/dist/permitted/scheduleBackgroundEvent.mjs.map +1 -1
  210. package/dist/permitted/sendWebSocketMessage.cjs +10 -14
  211. package/dist/permitted/sendWebSocketMessage.cjs.map +1 -1
  212. package/dist/permitted/sendWebSocketMessage.d.cts +9 -12
  213. package/dist/permitted/sendWebSocketMessage.d.cts.map +1 -1
  214. package/dist/permitted/sendWebSocketMessage.d.mts +9 -12
  215. package/dist/permitted/sendWebSocketMessage.d.mts.map +1 -1
  216. package/dist/permitted/sendWebSocketMessage.mjs +10 -14
  217. package/dist/permitted/sendWebSocketMessage.mjs.map +1 -1
  218. package/dist/permitted/setState.cjs +18 -21
  219. package/dist/permitted/setState.cjs.map +1 -1
  220. package/dist/permitted/setState.d.cts +18 -45
  221. package/dist/permitted/setState.d.cts.map +1 -1
  222. package/dist/permitted/setState.d.mts +18 -45
  223. package/dist/permitted/setState.d.mts.map +1 -1
  224. package/dist/permitted/setState.mjs +18 -21
  225. package/dist/permitted/setState.mjs.map +1 -1
  226. package/dist/permitted/startTrace.cjs +4 -6
  227. package/dist/permitted/startTrace.cjs.map +1 -1
  228. package/dist/permitted/startTrace.d.cts +8 -11
  229. package/dist/permitted/startTrace.d.cts.map +1 -1
  230. package/dist/permitted/startTrace.d.mts +8 -11
  231. package/dist/permitted/startTrace.d.mts.map +1 -1
  232. package/dist/permitted/startTrace.mjs +4 -6
  233. package/dist/permitted/startTrace.mjs.map +1 -1
  234. package/dist/permitted/trackError.cjs +4 -6
  235. package/dist/permitted/trackError.cjs.map +1 -1
  236. package/dist/permitted/trackError.d.cts +8 -11
  237. package/dist/permitted/trackError.d.cts.map +1 -1
  238. package/dist/permitted/trackError.d.mts +8 -11
  239. package/dist/permitted/trackError.d.mts.map +1 -1
  240. package/dist/permitted/trackError.mjs +4 -6
  241. package/dist/permitted/trackError.mjs.map +1 -1
  242. package/dist/permitted/trackEvent.cjs +4 -6
  243. package/dist/permitted/trackEvent.cjs.map +1 -1
  244. package/dist/permitted/trackEvent.d.cts +8 -11
  245. package/dist/permitted/trackEvent.d.cts.map +1 -1
  246. package/dist/permitted/trackEvent.d.mts +8 -11
  247. package/dist/permitted/trackEvent.d.mts.map +1 -1
  248. package/dist/permitted/trackEvent.mjs +4 -6
  249. package/dist/permitted/trackEvent.mjs.map +1 -1
  250. package/dist/permitted/updateInterface.cjs +11 -15
  251. package/dist/permitted/updateInterface.cjs.map +1 -1
  252. package/dist/permitted/updateInterface.d.cts +9 -22
  253. package/dist/permitted/updateInterface.d.cts.map +1 -1
  254. package/dist/permitted/updateInterface.d.mts +9 -22
  255. package/dist/permitted/updateInterface.d.mts.map +1 -1
  256. package/dist/permitted/updateInterface.mjs +11 -15
  257. package/dist/permitted/updateInterface.mjs.map +1 -1
  258. package/dist/restricted/dialog.cjs +23 -30
  259. package/dist/restricted/dialog.cjs.map +1 -1
  260. package/dist/restricted/dialog.d.cts +10 -58
  261. package/dist/restricted/dialog.d.cts.map +1 -1
  262. package/dist/restricted/dialog.d.mts +10 -58
  263. package/dist/restricted/dialog.d.mts.map +1 -1
  264. package/dist/restricted/dialog.mjs +23 -30
  265. package/dist/restricted/dialog.mjs.map +1 -1
  266. package/dist/restricted/getBip32Entropy.cjs +15 -12
  267. package/dist/restricted/getBip32Entropy.cjs.map +1 -1
  268. package/dist/restricted/getBip32Entropy.d.cts +11 -24
  269. package/dist/restricted/getBip32Entropy.d.cts.map +1 -1
  270. package/dist/restricted/getBip32Entropy.d.mts +11 -24
  271. package/dist/restricted/getBip32Entropy.d.mts.map +1 -1
  272. package/dist/restricted/getBip32Entropy.mjs +16 -13
  273. package/dist/restricted/getBip32Entropy.mjs.map +1 -1
  274. package/dist/restricted/getBip32PublicKey.cjs +15 -12
  275. package/dist/restricted/getBip32PublicKey.cjs.map +1 -1
  276. package/dist/restricted/getBip32PublicKey.d.cts +11 -24
  277. package/dist/restricted/getBip32PublicKey.d.cts.map +1 -1
  278. package/dist/restricted/getBip32PublicKey.d.mts +11 -24
  279. package/dist/restricted/getBip32PublicKey.d.mts.map +1 -1
  280. package/dist/restricted/getBip32PublicKey.mjs +16 -13
  281. package/dist/restricted/getBip32PublicKey.mjs.map +1 -1
  282. package/dist/restricted/getBip44Entropy.cjs +14 -10
  283. package/dist/restricted/getBip44Entropy.cjs.map +1 -1
  284. package/dist/restricted/getBip44Entropy.d.cts +11 -15
  285. package/dist/restricted/getBip44Entropy.d.cts.map +1 -1
  286. package/dist/restricted/getBip44Entropy.d.mts +11 -15
  287. package/dist/restricted/getBip44Entropy.d.mts.map +1 -1
  288. package/dist/restricted/getBip44Entropy.mjs +15 -11
  289. package/dist/restricted/getBip44Entropy.mjs.map +1 -1
  290. package/dist/restricted/getEntropy.cjs +10 -10
  291. package/dist/restricted/getEntropy.cjs.map +1 -1
  292. package/dist/restricted/getEntropy.d.cts +11 -15
  293. package/dist/restricted/getEntropy.d.cts.map +1 -1
  294. package/dist/restricted/getEntropy.d.mts +11 -15
  295. package/dist/restricted/getEntropy.d.mts.map +1 -1
  296. package/dist/restricted/getEntropy.mjs +11 -11
  297. package/dist/restricted/getEntropy.mjs.map +1 -1
  298. package/dist/restricted/index.cjs.map +1 -1
  299. package/dist/restricted/index.d.cts +20 -160
  300. package/dist/restricted/index.d.cts.map +1 -1
  301. package/dist/restricted/index.d.mts +20 -160
  302. package/dist/restricted/index.d.mts.map +1 -1
  303. package/dist/restricted/index.mjs.map +1 -1
  304. package/dist/restricted/invokeSnap.cjs +11 -12
  305. package/dist/restricted/invokeSnap.cjs.map +1 -1
  306. package/dist/restricted/invokeSnap.d.cts +9 -13
  307. package/dist/restricted/invokeSnap.d.cts.map +1 -1
  308. package/dist/restricted/invokeSnap.d.mts +9 -13
  309. package/dist/restricted/invokeSnap.d.mts.map +1 -1
  310. package/dist/restricted/invokeSnap.mjs +11 -12
  311. package/dist/restricted/invokeSnap.mjs.map +1 -1
  312. package/dist/restricted/manageState.cjs +21 -20
  313. package/dist/restricted/manageState.cjs.map +1 -1
  314. package/dist/restricted/manageState.d.cts +12 -34
  315. package/dist/restricted/manageState.d.cts.map +1 -1
  316. package/dist/restricted/manageState.d.mts +12 -34
  317. package/dist/restricted/manageState.d.mts.map +1 -1
  318. package/dist/restricted/manageState.mjs +21 -20
  319. package/dist/restricted/manageState.mjs.map +1 -1
  320. package/dist/restricted/notify.cjs +31 -24
  321. package/dist/restricted/notify.cjs.map +1 -1
  322. package/dist/restricted/notify.d.cts +16 -25
  323. package/dist/restricted/notify.d.cts.map +1 -1
  324. package/dist/restricted/notify.d.mts +16 -25
  325. package/dist/restricted/notify.d.mts.map +1 -1
  326. package/dist/restricted/notify.mjs +32 -25
  327. package/dist/restricted/notify.mjs.map +1 -1
  328. package/dist/types.cjs +3 -0
  329. package/dist/types.cjs.map +1 -0
  330. package/dist/types.d.cts +155 -0
  331. package/dist/types.d.cts.map +1 -0
  332. package/dist/types.d.mts +155 -0
  333. package/dist/types.d.mts.map +1 -0
  334. package/dist/types.mjs +2 -0
  335. package/dist/types.mjs.map +1 -0
  336. package/dist/utils.cjs +78 -24
  337. package/dist/utils.cjs.map +1 -1
  338. package/dist/utils.d.cts +21 -13
  339. package/dist/utils.d.cts.map +1 -1
  340. package/dist/utils.d.mts +21 -13
  341. package/dist/utils.d.mts.map +1 -1
  342. package/dist/utils.mjs +75 -22
  343. package/dist/utils.mjs.map +1 -1
  344. package/package.json +6 -6
  345. package/dist/permitted/handlers.cjs +0 -63
  346. package/dist/permitted/handlers.cjs.map +0 -1
  347. package/dist/permitted/handlers.d.cts +0 -299
  348. package/dist/permitted/handlers.d.cts.map +0 -1
  349. package/dist/permitted/handlers.d.mts +0 -299
  350. package/dist/permitted/handlers.d.mts.map +0 -1
  351. package/dist/permitted/handlers.mjs +0 -60
  352. package/dist/permitted/handlers.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"invokeSnapSugar.d.cts","sourceRoot":"","sources":["../../src/permitted/invokeSnapSugar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AAGnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,4BAA4B;AAC9E,OAA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AgB,CAAC,EAM/C,GAAG,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,EAC7C,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,4BAA4B,CAAC,GACzD,OAAO,CAAC,IAAI,CAAC,CAaf;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAsBpE"}
@@ -1,6 +1,10 @@
1
1
  import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
2
+ import type { Messenger } from "@metamask/messenger";
3
+ import type { PermissionControllerExecuteRestrictedMethodAction } from "@metamask/permission-controller";
2
4
  import type { InvokeSnapParams, InvokeSnapResult } from "@metamask/snaps-sdk";
3
- import type { JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
5
+ import type { PendingJsonRpcResponse } from "@metamask/utils";
6
+ import type { JsonRpcRequestWithOrigin } from "../types.mjs";
7
+ export type InvokeSnapSugarMethodActions = PermissionControllerExecuteRestrictedMethodAction;
4
8
  /**
5
9
  * Invoke a method of a Snap, designated by the `snapId` parameter, with a
6
10
  * JSON-RPC request specified in the `request` parameter. This is effectively a
@@ -27,14 +31,8 @@ import type { JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
27
31
  * ```
28
32
  */
29
33
  export declare const invokeSnapSugarHandler: {
30
- methodNames: ["wallet_invokeSnap"];
31
34
  implementation: typeof invokeSnapSugar;
32
- hookNames: {
33
- invokeSnap: true;
34
- };
35
- };
36
- export type InvokeSnapSugarHooks = {
37
- invokeSnap: (params: InvokeSnapParams) => Promise<InvokeSnapResult>;
35
+ actionNames: "PermissionController:executeRestrictedMethod"[];
38
36
  };
39
37
  /**
40
38
  * The `wallet_invokeSnap` method implementation.
@@ -44,13 +42,12 @@ export type InvokeSnapSugarHooks = {
44
42
  * @param res - The JSON-RPC response object.
45
43
  * @param _next - The `json-rpc-engine` "next" callback.
46
44
  * @param end - The `json-rpc-engine` "end" callback.
47
- * @param hooks - The RPC method hooks.
48
- * @param hooks.invokeSnap - A function to invoke a snap designated by its parameters,
49
- * bound to the requesting origin.
45
+ * @param _hooks - The RPC method hooks. Not used by this function.
46
+ * @param messenger - The messenger used to call controller actions.
50
47
  * @returns Nothing.
51
48
  * @throws If the params are invalid.
52
49
  */
53
- export declare function invokeSnapSugar(req: JsonRpcRequest<InvokeSnapParams>, res: PendingJsonRpcResponse<InvokeSnapResult>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, { invokeSnap }: InvokeSnapSugarHooks): Promise<void>;
50
+ export declare function invokeSnapSugar(req: JsonRpcRequestWithOrigin<InvokeSnapParams>, res: PendingJsonRpcResponse<InvokeSnapResult>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, InvokeSnapSugarMethodActions>): Promise<void>;
54
51
  /**
55
52
  * Validates the wallet_invokeSnap method `params` and returns them cast to the correct
56
53
  * type. Throws if validation fails.
@@ -1 +1 @@
1
- {"version":3,"file":"invokeSnapSugar.d.mts","sourceRoot":"","sources":["../../src/permitted/invokeSnapSugar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AAGnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,4BAA4B;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,wBAAwB;AAK9E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,sBAAsB;;;;;;CAUlC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACrE,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAsB,eAAe,C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BpE"}
@@ -1,6 +1,6 @@
1
1
  import { rpcErrors } from "@metamask/rpc-errors";
2
2
  import { isObject } from "@metamask/utils";
3
- const methodName = 'wallet_invokeSnap';
3
+ import { WALLET_SNAP_PERMISSION_KEY } from "../restricted/invokeSnap.mjs";
4
4
  /**
5
5
  * Invoke a method of a Snap, designated by the `snapId` parameter, with a
6
6
  * JSON-RPC request specified in the `request` parameter. This is effectively a
@@ -27,11 +27,8 @@ const methodName = 'wallet_invokeSnap';
27
27
  * ```
28
28
  */
29
29
  export const invokeSnapSugarHandler = {
30
- methodNames: [methodName],
31
30
  implementation: invokeSnapSugar,
32
- hookNames: {
33
- invokeSnap: true,
34
- },
31
+ actionNames: ['PermissionController:executeRestrictedMethod'],
35
32
  };
36
33
  /**
37
34
  * The `wallet_invokeSnap` method implementation.
@@ -41,9 +38,8 @@ export const invokeSnapSugarHandler = {
41
38
  * @param res - The JSON-RPC response object.
42
39
  * @param _next - The `json-rpc-engine` "next" callback.
43
40
  * @param end - The `json-rpc-engine` "end" callback.
44
- * @param hooks - The RPC method hooks.
45
- * @param hooks.invokeSnap - A function to invoke a snap designated by its parameters,
46
- * bound to the requesting origin.
41
+ * @param _hooks - The RPC method hooks. Not used by this function.
42
+ * @param messenger - The messenger used to call controller actions.
47
43
  * @returns Nothing.
48
44
  * @throws If the params are invalid.
49
45
  */
@@ -53,10 +49,10 @@ export async function invokeSnapSugar(req,
53
49
  // future. We use `InvokeSnapResult` here to make it clear that this is the
54
50
  // expected type of the result.
55
51
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments
56
- res, _next, end, { invokeSnap }) {
52
+ res, _next, end, _hooks, messenger) {
57
53
  try {
58
54
  const params = getValidatedParams(req.params);
59
- res.result = await invokeSnap(params);
55
+ res.result = await messenger.call('PermissionController:executeRestrictedMethod', req.origin, WALLET_SNAP_PERMISSION_KEY, params);
60
56
  }
61
57
  catch (error) {
62
58
  return end(error);
@@ -1 +1 @@
1
- {"version":3,"file":"invokeSnap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,EAAE,CAAC;QAC3D,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,+BAA+B;SACzC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACvB,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,yCAAyC;SACnD,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAA0B,CAAC;AACpC,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { InvokeSnapParams, InvokeSnapResult } from '@metamask/snaps-sdk';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';\nimport { isObject } from '@metamask/utils';\n\nconst methodName = 'wallet_invokeSnap';\n\n/**\n * Invoke a method of a Snap, designated by the `snapId` parameter, with a\n * JSON-RPC request specified in the `request` parameter. This is effectively a\n * wrapper around [`wallet_snap`](https://docs.metamask.io/snaps/reference/snaps-api/wallet_snap)\n * that allows for more convenient invocation of Snap methods without needing to\n * specify the full `wallet_snap` parameters.\n *\n * The Snap must be installed and the dapp must have permission to communicate\n * with the Snap, or the request is rejected. The dapp can install the Snap and\n * request permission to communicate with it using [`wallet_requestSnaps`](https://docs.metamask.io/snaps/reference/snaps-api/wallet_requestsnaps).\n *\n * @example\n * ```ts\n * const result = await snap.request({\n * method: 'wallet_invokeSnap',\n * params: {\n * snapId: 'npm:@metamask/example-snap',\n * request: {\n * method: 'someMethod',\n * params: { some: 'params' },\n * },\n * },\n * });\n * ```\n */\nexport const invokeSnapSugarHandler = {\n methodNames: [methodName] as const,\n implementation: invokeSnapSugar,\n hookNames: {\n invokeSnap: true,\n },\n} satisfies PermittedHandlerExport<\n InvokeSnapSugarHooks,\n InvokeSnapParams,\n InvokeSnapResult\n>;\n\nexport type InvokeSnapSugarHooks = {\n invokeSnap: (params: InvokeSnapParams) => Promise<InvokeSnapResult>;\n};\n\n/**\n * The `wallet_invokeSnap` method implementation.\n * Effectively calls `wallet_snap` under the hood.\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.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.invokeSnap - A function to invoke a snap designated by its parameters,\n * bound to the requesting origin.\n * @returns Nothing.\n * @throws If the params are invalid.\n */\nexport async function invokeSnapSugar(\n req: JsonRpcRequest<InvokeSnapParams>,\n // `InvokeSnapResult` is an alias for `Json` (which is the default type\n // argument for `PendingJsonRpcResponse`), but that may not be the case in the\n // future. We use `InvokeSnapResult` here to make it clear that this is the\n // expected type of the result.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\n res: PendingJsonRpcResponse<InvokeSnapResult>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n { invokeSnap }: InvokeSnapSugarHooks,\n): Promise<void> {\n try {\n const params = getValidatedParams(req.params);\n res.result = await invokeSnap(params);\n } catch (error) {\n return end(error);\n }\n return end();\n}\n\n/**\n * Validates the wallet_invokeSnap method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated method parameter object.\n */\nexport function getValidatedParams(params: unknown): InvokeSnapParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { snapId, request } = params;\n\n if (!snapId || typeof snapId !== 'string' || snapId === '') {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid snap ID.',\n });\n }\n\n if (!isObject(request)) {\n throw rpcErrors.invalidParams({\n message: 'Expected request to be a single object.',\n });\n }\n\n return params as InvokeSnapParams;\n}\n"]}
1
+ {"version":3,"file":"invokeSnapSugar.mjs","sourceRoot":"","sources":["../../src/permitted/invokeSnapSug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MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,+BAA+B;SACzC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACvB,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,yCAAyC;SACnD,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAA0B,CAAC;AACpC,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { Messenger } from '@metamask/messenger';\nimport type { PermissionControllerExecuteRestrictedMethodAction } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { InvokeSnapParams, InvokeSnapResult } from '@metamask/snaps-sdk';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { isObject } from '@metamask/utils';\n\nimport { WALLET_SNAP_PERMISSION_KEY } from '../restricted/invokeSnap';\nimport type { JsonRpcRequestWithOrigin } from '../types';\n\nexport type InvokeSnapSugarMethodActions =\n PermissionControllerExecuteRestrictedMethodAction;\n\n/**\n * Invoke a method of a Snap, designated by the `snapId` parameter, with a\n * JSON-RPC request specified in the `request` parameter. This is effectively a\n * wrapper around [`wallet_snap`](https://docs.metamask.io/snaps/reference/snaps-api/wallet_snap)\n * that allows for more convenient invocation of Snap methods without needing to\n * specify the full `wallet_snap` parameters.\n *\n * The Snap must be installed and the dapp must have permission to communicate\n * with the Snap, or the request is rejected. The dapp can install the Snap and\n * request permission to communicate with it using [`wallet_requestSnaps`](https://docs.metamask.io/snaps/reference/snaps-api/wallet_requestsnaps).\n *\n * @example\n * ```ts\n * const result = await snap.request({\n * method: 'wallet_invokeSnap',\n * params: {\n * snapId: 'npm:@metamask/example-snap',\n * request: {\n * method: 'someMethod',\n * params: { some: 'params' },\n * },\n * },\n * });\n * ```\n */\nexport const invokeSnapSugarHandler = {\n implementation: invokeSnapSugar,\n actionNames: ['PermissionController:executeRestrictedMethod'],\n} satisfies MethodHandler<\n never,\n InvokeSnapSugarMethodActions,\n InvokeSnapParams,\n InvokeSnapResult,\n { origin: string }\n>;\n\n/**\n * The `wallet_invokeSnap` method implementation.\n * Effectively calls `wallet_snap` under the hood.\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.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param _hooks - The RPC method hooks. Not used by this function.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n * @throws If the params are invalid.\n */\nexport async function invokeSnapSugar(\n req: JsonRpcRequestWithOrigin<InvokeSnapParams>,\n // `InvokeSnapResult` is an alias for `Json` (which is the default type\n // argument for `PendingJsonRpcResponse`), but that may not be the case in the\n // future. We use `InvokeSnapResult` here to make it clear that this is the\n // expected type of the result.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\n res: PendingJsonRpcResponse<InvokeSnapResult>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n _hooks: never,\n messenger: Messenger<string, InvokeSnapSugarMethodActions>,\n): Promise<void> {\n try {\n const params = getValidatedParams(req.params);\n res.result = await messenger.call(\n 'PermissionController:executeRestrictedMethod',\n req.origin,\n WALLET_SNAP_PERMISSION_KEY,\n params,\n );\n } catch (error) {\n return end(error);\n }\n return end();\n}\n\n/**\n * Validates the wallet_invokeSnap method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated method parameter object.\n */\nexport function getValidatedParams(params: unknown): InvokeSnapParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { snapId, request } = params;\n\n if (!snapId || typeof snapId !== 'string' || snapId === '') {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid snap ID.',\n });\n }\n\n if (!isObject(request)) {\n throw rpcErrors.invalidParams({\n message: 'Expected request to be a single object.',\n });\n }\n\n return params as InvokeSnapParams;\n}\n"]}
@@ -16,10 +16,11 @@ const REQUIRED_PERMISSIONS = [
16
16
  getBip44Entropy_1.getBip44EntropyBuilder.targetName,
17
17
  getEntropy_1.getEntropyBuilder.targetName,
18
18
  ];
19
- const methodName = 'snap_listEntropySources';
19
+ /**
20
+ * The keyring type used by HD (mnemonic-based) keyrings.
21
+ */
22
+ const HD_KEYRING_TYPE = 'HD Key Tree';
20
23
  const hookNames = {
21
- hasPermission: true,
22
- getEntropySources: true,
23
24
  getUnlockPromise: true,
24
25
  };
25
26
  /**
@@ -61,32 +62,47 @@ const hookNames = {
61
62
  * ```
62
63
  */
63
64
  exports.listEntropySourcesHandler = {
64
- methodNames: [methodName],
65
65
  implementation: listEntropySourcesImplementation,
66
66
  hookNames,
67
+ actionNames: [
68
+ 'PermissionController:hasPermission',
69
+ 'KeyringController:getState',
70
+ ],
67
71
  };
68
72
  /**
69
73
  * The `snap_listEntropySources` method implementation.
70
74
  *
71
- * @param _request - The JSON-RPC request object. Not used by this function.
75
+ * @param request - The JSON-RPC request object.
72
76
  * @param response - The JSON-RPC response object.
73
77
  * @param _next - The `json-rpc-engine` "next" callback. Not used by this
74
78
  * function.
75
79
  * @param end - The `json-rpc-engine` "end" callback.
76
80
  * @param hooks - The RPC method hooks.
77
- * @param hooks.hasPermission - The function to check if the origin has a
78
- * permission.
79
- * @param hooks.getEntropySources - The function to get the entropy sources.
80
81
  * @param hooks.getUnlockPromise - The function to get the unlock promise.
81
- * @returns Noting.
82
+ * @param messenger - The messenger used to call controller actions.
83
+ * @returns Nothing.
82
84
  */
83
- async function listEntropySourcesImplementation(_request, response, _next, end, { hasPermission, getEntropySources, getUnlockPromise, }) {
84
- const isPermitted = REQUIRED_PERMISSIONS.some(hasPermission);
85
+ async function listEntropySourcesImplementation(request, response, _next, end, { getUnlockPromise }, messenger) {
86
+ const { origin } = request;
87
+ const isPermitted = REQUIRED_PERMISSIONS.some((permission) => messenger.call('PermissionController:hasPermission', origin, permission));
85
88
  if (!isPermitted) {
86
89
  return end(rpc_errors_1.providerErrors.unauthorized());
87
90
  }
88
91
  await getUnlockPromise(true);
89
- response.result = getEntropySources();
92
+ const { keyrings } = messenger.call('KeyringController:getState');
93
+ response.result = keyrings
94
+ .map((keyring, index) => {
95
+ if (keyring.type === HD_KEYRING_TYPE) {
96
+ return {
97
+ id: keyring.metadata.id,
98
+ name: keyring.metadata.name,
99
+ type: 'mnemonic',
100
+ primary: index === 0,
101
+ };
102
+ }
103
+ return null;
104
+ })
105
+ .filter((entropySource) => Boolean(entropySource));
90
106
  return end();
91
107
  }
92
108
  //# sourceMappingURL=listEntropySources.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"listEntropySources.cjs","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":";;;AAEA,qDAAsD;AAStD,uEAAuE;AACvE,2EAA2E;AAC3E,uEAAuE;AACvE,6DAA6D;AAG7D;;;GAGG;AACH,MAAM,oBAAoB,GAAG;IAC3B,wCAAsB,CAAC,UAAU;IACjC,4CAAwB,CAAC,UAAU;IACnC,wCAAsB,CAAC,UAAU;IACjC,8BAAiB,CAAC,UAAU;CAC7B,CAAC;AAEF,MAAM,UAAU,GAAG,yBAAyB,CAAC;AAE7C,MAAM,SAAS,GAA+C;IAC5D,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,IAAI;IACvB,gBAAgB,EAAE,IAAI;CACvB,CAAC;AA0BF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACU,QAAA,yBAAyB,GAAG;IACvC,WAAW,EAAE,CAAC,UAAU,CAAU;IAClC,cAAc,EAAE,gCAAgC;IAChD,SAAS;CAKV,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,KAAK,UAAU,gCAAgC,CAC7C,QAAkD,EAClD,QAA0D,EAC1D,KAAc,EACd,GAA6B,EAC7B,EACE,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACQ;IAE1B,MAAM,WAAW,GAAG,oBAAoB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC7D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CAAC,2BAAc,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAE7B,QAAQ,CAAC,MAAM,GAAG,iBAAiB,EAAE,CAAC;IACtC,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors } from '@metamask/rpc-errors';\nimport type {\n EntropySource,\n JsonRpcRequest,\n ListEntropySourcesParams,\n ListEntropySourcesResult,\n} from '@metamask/snaps-sdk';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { getBip32EntropyBuilder } from '../restricted/getBip32Entropy';\nimport { getBip32PublicKeyBuilder } from '../restricted/getBip32PublicKey';\nimport { getBip44EntropyBuilder } from '../restricted/getBip44Entropy';\nimport { getEntropyBuilder } from '../restricted/getEntropy';\nimport type { MethodHooksObject } from '../utils';\n\n/**\n * A list of permissions that the requesting origin must have at least one of\n * in order to call this method.\n */\nconst REQUIRED_PERMISSIONS = [\n getBip32EntropyBuilder.targetName,\n getBip32PublicKeyBuilder.targetName,\n getBip44EntropyBuilder.targetName,\n getEntropyBuilder.targetName,\n];\n\nconst methodName = 'snap_listEntropySources';\n\nconst hookNames: MethodHooksObject<ListEntropySourcesHooks> = {\n hasPermission: true,\n getEntropySources: true,\n getUnlockPromise: true,\n};\n\nexport type ListEntropySourcesHooks = {\n /**\n * Check if the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * Get the entropy sources from the client.\n *\n * @returns The entropy sources.\n */\n getEntropySources: () => EntropySource[];\n\n /**\n * Wait 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/**\n * Get a list of entropy sources available to the Snap. The requesting origin\n * must have at least one of the following permissions to access entropy source\n * metadata:\n *\n * - `snap_getBip32Entropy`\n * - `snap_getBip32PublicKey`\n * - `snap_getBip44Entropy`\n * - `snap_getEntropy`\n *\n * @example\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_getBip32Entropy\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * const entropySources = await snap.request({ method: 'snap_listEntropySources' });\n * console.log(entropySources);\n * // Example output:\n * // [\n * // {\n * // name: 'Mnemonic 1',\n * // id: 'mnemonic-1',\n * // type: 'mnemonic',\n * // primary: true,\n * // },\n * // {\n * // name: 'Mnemonic 2',\n * // id: 'mnemonic-2',\n * // type: 'mnemonic',\n * // primary: false,\n * // },\n * // ]\n * ```\n */\nexport const listEntropySourcesHandler = {\n methodNames: [methodName] as const,\n implementation: listEntropySourcesImplementation,\n hookNames,\n} satisfies PermittedHandlerExport<\n ListEntropySourcesHooks,\n ListEntropySourcesParams,\n ListEntropySourcesResult\n>;\n\n/**\n * The `snap_listEntropySources` method implementation.\n *\n * @param _request - The JSON-RPC request object. Not used by this function.\n * @param response - 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.hasPermission - The function to check if the origin has a\n * permission.\n * @param hooks.getEntropySources - The function to get the entropy sources.\n * @param hooks.getUnlockPromise - The function to get the unlock promise.\n * @returns Noting.\n */\nasync function listEntropySourcesImplementation(\n _request: JsonRpcRequest<ListEntropySourcesParams>,\n response: PendingJsonRpcResponse<ListEntropySourcesResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n {\n hasPermission,\n getEntropySources,\n getUnlockPromise,\n }: ListEntropySourcesHooks,\n): Promise<void> {\n const isPermitted = REQUIRED_PERMISSIONS.some(hasPermission);\n if (!isPermitted) {\n return end(providerErrors.unauthorized());\n }\n\n await getUnlockPromise(true);\n\n response.result = getEntropySources();\n return end();\n}\n"]}
1
+ {"version":3,"file":"listEntropySources.cjs","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":";;;AAMA,qDAAsD;AAQtD,uEAAuE;AACvE,2EAA2E;AAC3E,uEAAuE;AACvE,6DAA6D;AAO7D;;;GAGG;AACH,MAAM,oBAAoB,GAAG;IAC3B,wCAAsB,CAAC,UAAU;IACjC,4CAAwB,CAAC,UAAU;IACnC,wCAAsB,CAAC,UAAU;IACjC,8BAAiB,CAAC,UAAU;CAC7B,CAAC;AAEF;;GAEG;AACH,MAAM,eAAe,GAAG,aAAa,CAAC;AAEtC,MAAM,SAAS,GAAqD;IAClE,gBAAgB,EAAE,IAAI;CACvB,CAAC;AAeF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACU,QAAA,yBAAyB,GAAG;IACvC,cAAc,EAAE,gCAAgC;IAChD,SAAS;IACT,WAAW,EAAE;QACX,oCAAoC;QACpC,4BAA4B;KAC7B;CAOF,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,gCAAgC,CAC7C,OAA2D,EAC3D,QAA0D,EAC1D,KAAc,EACd,GAA6B,EAC7B,EAAE,gBAAgB,EAAiC,EACnD,SAA6D;IAE7D,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAE3B,MAAM,WAAW,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAC3D,SAAS,CAAC,IAAI,CAAC,oCAAoC,EAAE,MAAM,EAAE,UAAU,CAAC,CACzE,CAAC;IAEF,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CAAC,2BAAc,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAE7B,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IAElE,QAAQ,CAAC,MAAM,GAAG,QAAQ;SACvB,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;QACtB,IAAI,OAAO,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;YACrC,OAAO;gBACL,EAAE,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE;gBACvB,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAC3B,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,KAAK,KAAK,CAAC;aACrB,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,aAAa,EAAkC,EAAE,CACxD,OAAO,CAAC,aAAa,CAAC,CACvB,CAAC;IAEJ,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { Messenger } from '@metamask/messenger';\nimport type { PermissionControllerHasPermissionAction } from '@metamask/permission-controller';\nimport { providerErrors } from '@metamask/rpc-errors';\nimport type {\n EntropySource,\n ListEntropySourcesParams,\n ListEntropySourcesResult,\n} from '@metamask/snaps-sdk';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { getBip32EntropyBuilder } from '../restricted/getBip32Entropy';\nimport { getBip32PublicKeyBuilder } from '../restricted/getBip32PublicKey';\nimport { getBip44EntropyBuilder } from '../restricted/getBip44Entropy';\nimport { getEntropyBuilder } from '../restricted/getEntropy';\nimport type {\n JsonRpcRequestWithOrigin,\n KeyringControllerGetStateAction,\n} from '../types';\nimport type { MethodHooksObject } from '../utils';\n\n/**\n * A list of permissions that the requesting origin must have at least one of\n * in order to call this method.\n */\nconst REQUIRED_PERMISSIONS = [\n getBip32EntropyBuilder.targetName,\n getBip32PublicKeyBuilder.targetName,\n getBip44EntropyBuilder.targetName,\n getEntropyBuilder.targetName,\n];\n\n/**\n * The keyring type used by HD (mnemonic-based) keyrings.\n */\nconst HD_KEYRING_TYPE = 'HD Key Tree';\n\nconst hookNames: MethodHooksObject<ListEntropySourcesMethodHooks> = {\n getUnlockPromise: true,\n};\n\nexport type ListEntropySourcesMethodHooks = {\n /**\n * Wait 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\nexport type ListEntropySourcesMethodActions =\n | PermissionControllerHasPermissionAction\n | KeyringControllerGetStateAction;\n\n/**\n * Get a list of entropy sources available to the Snap. The requesting origin\n * must have at least one of the following permissions to access entropy source\n * metadata:\n *\n * - `snap_getBip32Entropy`\n * - `snap_getBip32PublicKey`\n * - `snap_getBip44Entropy`\n * - `snap_getEntropy`\n *\n * @example\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_getBip32Entropy\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * const entropySources = await snap.request({ method: 'snap_listEntropySources' });\n * console.log(entropySources);\n * // Example output:\n * // [\n * // {\n * // name: 'Mnemonic 1',\n * // id: 'mnemonic-1',\n * // type: 'mnemonic',\n * // primary: true,\n * // },\n * // {\n * // name: 'Mnemonic 2',\n * // id: 'mnemonic-2',\n * // type: 'mnemonic',\n * // primary: false,\n * // },\n * // ]\n * ```\n */\nexport const listEntropySourcesHandler = {\n implementation: listEntropySourcesImplementation,\n hookNames,\n actionNames: [\n 'PermissionController:hasPermission',\n 'KeyringController:getState',\n ],\n} satisfies MethodHandler<\n ListEntropySourcesMethodHooks,\n ListEntropySourcesMethodActions,\n ListEntropySourcesParams,\n ListEntropySourcesResult,\n { origin: string }\n>;\n\n/**\n * The `snap_listEntropySources` method implementation.\n *\n * @param request - The JSON-RPC request object.\n * @param response - 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.getUnlockPromise - The function to get the unlock promise.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nasync function listEntropySourcesImplementation(\n request: JsonRpcRequestWithOrigin<ListEntropySourcesParams>,\n response: PendingJsonRpcResponse<ListEntropySourcesResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getUnlockPromise }: ListEntropySourcesMethodHooks,\n messenger: Messenger<string, ListEntropySourcesMethodActions>,\n): Promise<void> {\n const { origin } = request;\n\n const isPermitted = REQUIRED_PERMISSIONS.some((permission) =>\n messenger.call('PermissionController:hasPermission', origin, permission),\n );\n\n if (!isPermitted) {\n return end(providerErrors.unauthorized());\n }\n\n await getUnlockPromise(true);\n\n const { keyrings } = messenger.call('KeyringController:getState');\n\n response.result = keyrings\n .map((keyring, index) => {\n if (keyring.type === HD_KEYRING_TYPE) {\n return {\n id: keyring.metadata.id,\n name: keyring.metadata.name,\n type: 'mnemonic',\n primary: index === 0,\n };\n }\n\n return null;\n })\n .filter((entropySource): entropySource is EntropySource =>\n Boolean(entropySource),\n );\n\n return end();\n}\n"]}
@@ -1,21 +1,11 @@
1
1
  import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
2
- import type { EntropySource, JsonRpcRequest, ListEntropySourcesParams, ListEntropySourcesResult } from "@metamask/snaps-sdk";
2
+ import type { Messenger } from "@metamask/messenger";
3
+ import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller";
4
+ import type { ListEntropySourcesParams, ListEntropySourcesResult } from "@metamask/snaps-sdk";
3
5
  import type { PendingJsonRpcResponse } from "@metamask/utils";
6
+ import type { JsonRpcRequestWithOrigin, KeyringControllerGetStateAction } from "../types.cjs";
4
7
  import type { MethodHooksObject } from "../utils.cjs";
5
- export type ListEntropySourcesHooks = {
6
- /**
7
- * Check if the requesting origin has a given permission.
8
- *
9
- * @param permissionName - The name of the permission to check.
10
- * @returns Whether the origin has the permission.
11
- */
12
- hasPermission: (permissionName: string) => boolean;
13
- /**
14
- * Get the entropy sources from the client.
15
- *
16
- * @returns The entropy sources.
17
- */
18
- getEntropySources: () => EntropySource[];
8
+ export type ListEntropySourcesMethodHooks = {
19
9
  /**
20
10
  * Wait for the extension to be unlocked.
21
11
  *
@@ -23,6 +13,7 @@ export type ListEntropySourcesHooks = {
23
13
  */
24
14
  getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
25
15
  };
16
+ export type ListEntropySourcesMethodActions = PermissionControllerHasPermissionAction | KeyringControllerGetStateAction;
26
17
  /**
27
18
  * Get a list of entropy sources available to the Snap. The requesting origin
28
19
  * must have at least one of the following permissions to access entropy source
@@ -62,25 +53,23 @@ export type ListEntropySourcesHooks = {
62
53
  * ```
63
54
  */
64
55
  export declare const listEntropySourcesHandler: {
65
- methodNames: ["snap_listEntropySources"];
66
56
  implementation: typeof listEntropySourcesImplementation;
67
- hookNames: MethodHooksObject<ListEntropySourcesHooks>;
57
+ hookNames: MethodHooksObject<ListEntropySourcesMethodHooks>;
58
+ actionNames: ("KeyringController:getState" | "PermissionController:hasPermission")[];
68
59
  };
69
60
  /**
70
61
  * The `snap_listEntropySources` method implementation.
71
62
  *
72
- * @param _request - The JSON-RPC request object. Not used by this function.
63
+ * @param request - The JSON-RPC request object.
73
64
  * @param response - The JSON-RPC response object.
74
65
  * @param _next - The `json-rpc-engine` "next" callback. Not used by this
75
66
  * function.
76
67
  * @param end - The `json-rpc-engine` "end" callback.
77
68
  * @param hooks - The RPC method hooks.
78
- * @param hooks.hasPermission - The function to check if the origin has a
79
- * permission.
80
- * @param hooks.getEntropySources - The function to get the entropy sources.
81
69
  * @param hooks.getUnlockPromise - The function to get the unlock promise.
82
- * @returns Noting.
70
+ * @param messenger - The messenger used to call controller actions.
71
+ * @returns Nothing.
83
72
  */
84
- declare function listEntropySourcesImplementation(_request: JsonRpcRequest<ListEntropySourcesParams>, response: PendingJsonRpcResponse<ListEntropySourcesResult>, _next: unknown, end: JsonRpcEngineEndCallback, { hasPermission, getEntropySources, getUnlockPromise, }: ListEntropySourcesHooks): Promise<void>;
73
+ declare function listEntropySourcesImplementation(request: JsonRpcRequestWithOrigin<ListEntropySourcesParams>, response: PendingJsonRpcResponse<ListEntropySourcesResult>, _next: unknown, end: JsonRpcEngineEndCallback, { getUnlockPromise }: ListEntropySourcesMethodHooks, messenger: Messenger<string, ListEntropySourcesMethodActions>): Promise<void>;
85
74
  export {};
86
75
  //# sourceMappingURL=listEntropySources.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"listEntropySources.d.cts","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,kCAAkC;AAG1E,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,wBAAwB,EACzB,4BAA4B;AAC7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAM9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAqBlD,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;OAKG;IACH,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD;;;;OAIG;IACH,iBAAiB,EAAE,MAAM,aAAa,EAAE,CAAC;IAEzC;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,yBAAyB;;;;CAQrC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,iBAAe,gCAAgC,CAC7C,QAAQ,EAAE,cAAc,CAAC,wBAAwB,CAAC,EAClD,QAAQ,EAAE,sBAAsB,C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IAAI,CAAC,CAiCf"}
@@ -1,21 +1,11 @@
1
1
  import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
2
- import type { EntropySource, JsonRpcRequest, ListEntropySourcesParams, ListEntropySourcesResult } from "@metamask/snaps-sdk";
2
+ import type { Messenger } from "@metamask/messenger";
3
+ import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller";
4
+ import type { ListEntropySourcesParams, ListEntropySourcesResult } from "@metamask/snaps-sdk";
3
5
  import type { PendingJsonRpcResponse } from "@metamask/utils";
6
+ import type { JsonRpcRequestWithOrigin, KeyringControllerGetStateAction } from "../types.mjs";
4
7
  import type { MethodHooksObject } from "../utils.mjs";
5
- export type ListEntropySourcesHooks = {
6
- /**
7
- * Check if the requesting origin has a given permission.
8
- *
9
- * @param permissionName - The name of the permission to check.
10
- * @returns Whether the origin has the permission.
11
- */
12
- hasPermission: (permissionName: string) => boolean;
13
- /**
14
- * Get the entropy sources from the client.
15
- *
16
- * @returns The entropy sources.
17
- */
18
- getEntropySources: () => EntropySource[];
8
+ export type ListEntropySourcesMethodHooks = {
19
9
  /**
20
10
  * Wait for the extension to be unlocked.
21
11
  *
@@ -23,6 +13,7 @@ export type ListEntropySourcesHooks = {
23
13
  */
24
14
  getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
25
15
  };
16
+ export type ListEntropySourcesMethodActions = PermissionControllerHasPermissionAction | KeyringControllerGetStateAction;
26
17
  /**
27
18
  * Get a list of entropy sources available to the Snap. The requesting origin
28
19
  * must have at least one of the following permissions to access entropy source
@@ -62,25 +53,23 @@ export type ListEntropySourcesHooks = {
62
53
  * ```
63
54
  */
64
55
  export declare const listEntropySourcesHandler: {
65
- methodNames: ["snap_listEntropySources"];
66
56
  implementation: typeof listEntropySourcesImplementation;
67
- hookNames: MethodHooksObject<ListEntropySourcesHooks>;
57
+ hookNames: MethodHooksObject<ListEntropySourcesMethodHooks>;
58
+ actionNames: ("KeyringController:getState" | "PermissionController:hasPermission")[];
68
59
  };
69
60
  /**
70
61
  * The `snap_listEntropySources` method implementation.
71
62
  *
72
- * @param _request - The JSON-RPC request object. Not used by this function.
63
+ * @param request - The JSON-RPC request object.
73
64
  * @param response - The JSON-RPC response object.
74
65
  * @param _next - The `json-rpc-engine` "next" callback. Not used by this
75
66
  * function.
76
67
  * @param end - The `json-rpc-engine` "end" callback.
77
68
  * @param hooks - The RPC method hooks.
78
- * @param hooks.hasPermission - The function to check if the origin has a
79
- * permission.
80
- * @param hooks.getEntropySources - The function to get the entropy sources.
81
69
  * @param hooks.getUnlockPromise - The function to get the unlock promise.
82
- * @returns Noting.
70
+ * @param messenger - The messenger used to call controller actions.
71
+ * @returns Nothing.
83
72
  */
84
- declare function listEntropySourcesImplementation(_request: JsonRpcRequest<ListEntropySourcesParams>, response: PendingJsonRpcResponse<ListEntropySourcesResult>, _next: unknown, end: JsonRpcEngineEndCallback, { hasPermission, getEntropySources, getUnlockPromise, }: ListEntropySourcesHooks): Promise<void>;
73
+ declare function listEntropySourcesImplementation(request: JsonRpcRequestWithOrigin<ListEntropySourcesParams>, response: PendingJsonRpcResponse<ListEntropySourcesResult>, _next: unknown, end: JsonRpcEngineEndCallback, { getUnlockPromise }: ListEntropySourcesMethodHooks, messenger: Messenger<string, ListEntropySourcesMethodActions>): Promise<void>;
85
74
  export {};
86
75
  //# sourceMappingURL=listEntropySources.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"listEntropySources.d.mts","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,kCAAkC;AAG1E,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,wBAAwB,EACzB,4BAA4B;AAC7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAM9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAqBlD,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;OAKG;I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AA+B,GACvC,uCAAuC,GACvC,+BAA+B,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,yBAAyB;;;;CAarC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,iBAAe,gCAAgC,CAC7C,OAAO,EAAE,wBAAwB,CAAC,wBAAwB,CAAC,EAC3D,QAAQ,EAAE,sBAAsB,CAAC,wBAAwB,CAAC,EAC1D,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,EAAE,gBAAgB,EAAE,EAAE,6BAA6B,EACnD,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,+BAA+B,CAAC,GAC5D,OAAO,CAAC,IAAI,CAAC,CAiCf"}
@@ -13,10 +13,11 @@ const REQUIRED_PERMISSIONS = [
13
13
  getBip44EntropyBuilder.targetName,
14
14
  getEntropyBuilder.targetName,
15
15
  ];
16
- const methodName = 'snap_listEntropySources';
16
+ /**
17
+ * The keyring type used by HD (mnemonic-based) keyrings.
18
+ */
19
+ const HD_KEYRING_TYPE = 'HD Key Tree';
17
20
  const hookNames = {
18
- hasPermission: true,
19
- getEntropySources: true,
20
21
  getUnlockPromise: true,
21
22
  };
22
23
  /**
@@ -58,32 +59,47 @@ const hookNames = {
58
59
  * ```
59
60
  */
60
61
  export const listEntropySourcesHandler = {
61
- methodNames: [methodName],
62
62
  implementation: listEntropySourcesImplementation,
63
63
  hookNames,
64
+ actionNames: [
65
+ 'PermissionController:hasPermission',
66
+ 'KeyringController:getState',
67
+ ],
64
68
  };
65
69
  /**
66
70
  * The `snap_listEntropySources` method implementation.
67
71
  *
68
- * @param _request - The JSON-RPC request object. Not used by this function.
72
+ * @param request - The JSON-RPC request object.
69
73
  * @param response - The JSON-RPC response object.
70
74
  * @param _next - The `json-rpc-engine` "next" callback. Not used by this
71
75
  * function.
72
76
  * @param end - The `json-rpc-engine` "end" callback.
73
77
  * @param hooks - The RPC method hooks.
74
- * @param hooks.hasPermission - The function to check if the origin has a
75
- * permission.
76
- * @param hooks.getEntropySources - The function to get the entropy sources.
77
78
  * @param hooks.getUnlockPromise - The function to get the unlock promise.
78
- * @returns Noting.
79
+ * @param messenger - The messenger used to call controller actions.
80
+ * @returns Nothing.
79
81
  */
80
- async function listEntropySourcesImplementation(_request, response, _next, end, { hasPermission, getEntropySources, getUnlockPromise, }) {
81
- const isPermitted = REQUIRED_PERMISSIONS.some(hasPermission);
82
+ async function listEntropySourcesImplementation(request, response, _next, end, { getUnlockPromise }, messenger) {
83
+ const { origin } = request;
84
+ const isPermitted = REQUIRED_PERMISSIONS.some((permission) => messenger.call('PermissionController:hasPermission', origin, permission));
82
85
  if (!isPermitted) {
83
86
  return end(providerErrors.unauthorized());
84
87
  }
85
88
  await getUnlockPromise(true);
86
- response.result = getEntropySources();
89
+ const { keyrings } = messenger.call('KeyringController:getState');
90
+ response.result = keyrings
91
+ .map((keyring, index) => {
92
+ if (keyring.type === HD_KEYRING_TYPE) {
93
+ return {
94
+ id: keyring.metadata.id,
95
+ name: keyring.metadata.name,
96
+ type: 'mnemonic',
97
+ primary: index === 0,
98
+ };
99
+ }
100
+ return null;
101
+ })
102
+ .filter((entropySource) => Boolean(entropySource));
87
103
  return end();
88
104
  }
89
105
  //# sourceMappingURL=listEntropySources.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"listEntropySources.mjs","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,6BAA6B;AAStD,OAAO,EAAE,sBAAsB,EAAE,0CAAsC;AACvE,OAAO,EAAE,wBAAwB,EAAE,4CAAwC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,0CAAsC;AACvE,OAAO,EAAE,iBAAiB,EAAE,qCAAiC;AAG7D;;;GAGG;AACH,MAAM,oBAAoB,GAAG;IAC3B,sBAAsB,CAAC,UAAU;IACjC,wBAAwB,CAAC,UAAU;IACnC,sBAAsB,CAAC,UAAU;IACjC,iBAAiB,CAAC,UAAU;CAC7B,CAAC;AAEF,MAAM,UAAU,GAAG,yBAAyB,CAAC;AAE7C,MAAM,SAAS,GAA+C;IAC5D,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,IAAI;IACvB,gBAAgB,EAAE,IAAI;CACvB,CAAC;AA0BF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,WAAW,EAAE,CAAC,UAAU,CAAU;IAClC,cAAc,EAAE,gCAAgC;IAChD,SAAS;CAKV,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,KAAK,UAAU,gCAAgC,CAC7C,QAAkD,EAClD,QAA0D,EAC1D,KAAc,EACd,GAA6B,EAC7B,EACE,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACQ;IAE1B,MAAM,WAAW,GAAG,oBAAoB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC7D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAE7B,QAAQ,CAAC,MAAM,GAAG,iBAAiB,EAAE,CAAC;IACtC,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors } from '@metamask/rpc-errors';\nimport type {\n EntropySource,\n JsonRpcRequest,\n ListEntropySourcesParams,\n ListEntropySourcesResult,\n} from '@metamask/snaps-sdk';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { getBip32EntropyBuilder } from '../restricted/getBip32Entropy';\nimport { getBip32PublicKeyBuilder } from '../restricted/getBip32PublicKey';\nimport { getBip44EntropyBuilder } from '../restricted/getBip44Entropy';\nimport { getEntropyBuilder } from '../restricted/getEntropy';\nimport type { MethodHooksObject } from '../utils';\n\n/**\n * A list of permissions that the requesting origin must have at least one of\n * in order to call this method.\n */\nconst REQUIRED_PERMISSIONS = [\n getBip32EntropyBuilder.targetName,\n getBip32PublicKeyBuilder.targetName,\n getBip44EntropyBuilder.targetName,\n getEntropyBuilder.targetName,\n];\n\nconst methodName = 'snap_listEntropySources';\n\nconst hookNames: MethodHooksObject<ListEntropySourcesHooks> = {\n hasPermission: true,\n getEntropySources: true,\n getUnlockPromise: true,\n};\n\nexport type ListEntropySourcesHooks = {\n /**\n * Check if the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * Get the entropy sources from the client.\n *\n * @returns The entropy sources.\n */\n getEntropySources: () => EntropySource[];\n\n /**\n * Wait 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/**\n * Get a list of entropy sources available to the Snap. The requesting origin\n * must have at least one of the following permissions to access entropy source\n * metadata:\n *\n * - `snap_getBip32Entropy`\n * - `snap_getBip32PublicKey`\n * - `snap_getBip44Entropy`\n * - `snap_getEntropy`\n *\n * @example\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_getBip32Entropy\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * const entropySources = await snap.request({ method: 'snap_listEntropySources' });\n * console.log(entropySources);\n * // Example output:\n * // [\n * // {\n * // name: 'Mnemonic 1',\n * // id: 'mnemonic-1',\n * // type: 'mnemonic',\n * // primary: true,\n * // },\n * // {\n * // name: 'Mnemonic 2',\n * // id: 'mnemonic-2',\n * // type: 'mnemonic',\n * // primary: false,\n * // },\n * // ]\n * ```\n */\nexport const listEntropySourcesHandler = {\n methodNames: [methodName] as const,\n implementation: listEntropySourcesImplementation,\n hookNames,\n} satisfies PermittedHandlerExport<\n ListEntropySourcesHooks,\n ListEntropySourcesParams,\n ListEntropySourcesResult\n>;\n\n/**\n * The `snap_listEntropySources` method implementation.\n *\n * @param _request - The JSON-RPC request object. Not used by this function.\n * @param response - 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.hasPermission - The function to check if the origin has a\n * permission.\n * @param hooks.getEntropySources - The function to get the entropy sources.\n * @param hooks.getUnlockPromise - The function to get the unlock promise.\n * @returns Noting.\n */\nasync function listEntropySourcesImplementation(\n _request: JsonRpcRequest<ListEntropySourcesParams>,\n response: PendingJsonRpcResponse<ListEntropySourcesResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n {\n hasPermission,\n getEntropySources,\n getUnlockPromise,\n }: ListEntropySourcesHooks,\n): Promise<void> {\n const isPermitted = REQUIRED_PERMISSIONS.some(hasPermission);\n if (!isPermitted) {\n return end(providerErrors.unauthorized());\n }\n\n await getUnlockPromise(true);\n\n response.result = getEntropySources();\n return end();\n}\n"]}
1
+ {"version":3,"file":"listEntropySources.mjs","sourceRoot":"","sources":["../../src/permitted/listEntropySources.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,6BAA6B;AAQtD,OAAO,EAAE,sBAAsB,EAAE,0CAAsC;AACvE,OAAO,EAAE,wBAAwB,EAAE,4CAAwC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,0CAAsC;AACvE,OAAO,EAAE,iBAAiB,EAAE,qCAAiC;AAO7D;;;GAGG;AACH,MAAM,oBAAoB,GAAG;IAC3B,sBAAsB,CAAC,UAAU;IACjC,wBAAwB,CAAC,UAAU;IACnC,sBAAsB,CAAC,UAAU;IACjC,iBAAiB,CAAC,UAAU;CAC7B,CAAC;AAEF;;GAEG;AACH,MAAM,eAAe,GAAG,aAAa,CAAC;AAEtC,MAAM,SAAS,GAAqD;IAClE,gBAAgB,EA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AE,CACxD,OAAO,CAAC,aAAa,CAAC,CACvB,CAAC;IAEJ,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { Messenger } from '@metamask/messenger';\nimport type { PermissionControllerHasPermissionAction } from '@metamask/permission-controller';\nimport { providerErrors } from '@metamask/rpc-errors';\nimport type {\n EntropySource,\n ListEntropySourcesParams,\n ListEntropySourcesResult,\n} from '@metamask/snaps-sdk';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { getBip32EntropyBuilder } from '../restricted/getBip32Entropy';\nimport { getBip32PublicKeyBuilder } from '../restricted/getBip32PublicKey';\nimport { getBip44EntropyBuilder } from '../restricted/getBip44Entropy';\nimport { getEntropyBuilder } from '../restricted/getEntropy';\nimport type {\n JsonRpcRequestWithOrigin,\n KeyringControllerGetStateAction,\n} from '../types';\nimport type { MethodHooksObject } from '../utils';\n\n/**\n * A list of permissions that the requesting origin must have at least one of\n * in order to call this method.\n */\nconst REQUIRED_PERMISSIONS = [\n getBip32EntropyBuilder.targetName,\n getBip32PublicKeyBuilder.targetName,\n getBip44EntropyBuilder.targetName,\n getEntropyBuilder.targetName,\n];\n\n/**\n * The keyring type used by HD (mnemonic-based) keyrings.\n */\nconst HD_KEYRING_TYPE = 'HD Key Tree';\n\nconst hookNames: MethodHooksObject<ListEntropySourcesMethodHooks> = {\n getUnlockPromise: true,\n};\n\nexport type ListEntropySourcesMethodHooks = {\n /**\n * Wait 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\nexport type ListEntropySourcesMethodActions =\n | PermissionControllerHasPermissionAction\n | KeyringControllerGetStateAction;\n\n/**\n * Get a list of entropy sources available to the Snap. The requesting origin\n * must have at least one of the following permissions to access entropy source\n * metadata:\n *\n * - `snap_getBip32Entropy`\n * - `snap_getBip32PublicKey`\n * - `snap_getBip44Entropy`\n * - `snap_getEntropy`\n *\n * @example\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_getBip32Entropy\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * const entropySources = await snap.request({ method: 'snap_listEntropySources' });\n * console.log(entropySources);\n * // Example output:\n * // [\n * // {\n * // name: 'Mnemonic 1',\n * // id: 'mnemonic-1',\n * // type: 'mnemonic',\n * // primary: true,\n * // },\n * // {\n * // name: 'Mnemonic 2',\n * // id: 'mnemonic-2',\n * // type: 'mnemonic',\n * // primary: false,\n * // },\n * // ]\n * ```\n */\nexport const listEntropySourcesHandler = {\n implementation: listEntropySourcesImplementation,\n hookNames,\n actionNames: [\n 'PermissionController:hasPermission',\n 'KeyringController:getState',\n ],\n} satisfies MethodHandler<\n ListEntropySourcesMethodHooks,\n ListEntropySourcesMethodActions,\n ListEntropySourcesParams,\n ListEntropySourcesResult,\n { origin: string }\n>;\n\n/**\n * The `snap_listEntropySources` method implementation.\n *\n * @param request - The JSON-RPC request object.\n * @param response - 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.getUnlockPromise - The function to get the unlock promise.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nasync function listEntropySourcesImplementation(\n request: JsonRpcRequestWithOrigin<ListEntropySourcesParams>,\n response: PendingJsonRpcResponse<ListEntropySourcesResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getUnlockPromise }: ListEntropySourcesMethodHooks,\n messenger: Messenger<string, ListEntropySourcesMethodActions>,\n): Promise<void> {\n const { origin } = request;\n\n const isPermitted = REQUIRED_PERMISSIONS.some((permission) =>\n messenger.call('PermissionController:hasPermission', origin, permission),\n );\n\n if (!isPermitted) {\n return end(providerErrors.unauthorized());\n }\n\n await getUnlockPromise(true);\n\n const { keyrings } = messenger.call('KeyringController:getState');\n\n response.result = keyrings\n .map((keyring, index) => {\n if (keyring.type === HD_KEYRING_TYPE) {\n return {\n id: keyring.metadata.id,\n name: keyring.metadata.name,\n type: 'mnemonic',\n primary: index === 0,\n };\n }\n\n return null;\n })\n .filter((entropySource): entropySource is EntropySource =>\n Boolean(entropySource),\n );\n\n return end();\n}\n"]}
@@ -1,39 +1,89 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createSnapsMethodMiddleware = void 0;
4
+ const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
4
5
  const rpc_errors_1 = require("@metamask/rpc-errors");
5
6
  const snaps_utils_1 = require("@metamask/snaps-utils");
6
- const handlers_1 = require("./handlers.cjs");
7
- const utils_1 = require("../utils.cjs");
7
+ const cancelBackgroundEvent_1 = require("./cancelBackgroundEvent.cjs");
8
+ const clearState_1 = require("./clearState.cjs");
9
+ const closeWebSocket_1 = require("./closeWebSocket.cjs");
10
+ const createInterface_1 = require("./createInterface.cjs");
11
+ const endTrace_1 = require("./endTrace.cjs");
12
+ const getAllSnaps_1 = require("./getAllSnaps.cjs");
13
+ const getBackgroundEvents_1 = require("./getBackgroundEvents.cjs");
14
+ const getClientStatus_1 = require("./getClientStatus.cjs");
15
+ const getFile_1 = require("./getFile.cjs");
16
+ const getInterfaceContext_1 = require("./getInterfaceContext.cjs");
17
+ const getInterfaceState_1 = require("./getInterfaceState.cjs");
18
+ const getSnaps_1 = require("./getSnaps.cjs");
19
+ const getState_1 = require("./getState.cjs");
20
+ const getWebSockets_1 = require("./getWebSockets.cjs");
21
+ const invokeKeyring_1 = require("./invokeKeyring.cjs");
22
+ const invokeSnapSugar_1 = require("./invokeSnapSugar.cjs");
23
+ const listEntropySources_1 = require("./listEntropySources.cjs");
24
+ const openWebSocket_1 = require("./openWebSocket.cjs");
25
+ const requestSnaps_1 = require("./requestSnaps.cjs");
26
+ const resolveInterface_1 = require("./resolveInterface.cjs");
27
+ const scheduleBackgroundEvent_1 = require("./scheduleBackgroundEvent.cjs");
28
+ const sendWebSocketMessage_1 = require("./sendWebSocketMessage.cjs");
29
+ const setState_1 = require("./setState.cjs");
30
+ const startTrace_1 = require("./startTrace.cjs");
31
+ const trackError_1 = require("./trackError.cjs");
32
+ const trackEvent_1 = require("./trackEvent.cjs");
33
+ const updateInterface_1 = require("./updateInterface.cjs");
34
+ /* eslint-disable @typescript-eslint/naming-convention */
35
+ const methodHandlers = {
36
+ wallet_getAllSnaps: getAllSnaps_1.getAllSnapsHandler,
37
+ wallet_getSnaps: getSnaps_1.getSnapsHandler,
38
+ wallet_requestSnaps: requestSnaps_1.requestSnapsHandler,
39
+ wallet_invokeSnap: invokeSnapSugar_1.invokeSnapSugarHandler,
40
+ wallet_invokeKeyring: invokeKeyring_1.invokeKeyringHandler,
41
+ snap_clearState: clearState_1.clearStateHandler,
42
+ snap_getClientStatus: getClientStatus_1.getClientStatusHandler,
43
+ snap_getFile: getFile_1.getFileHandler,
44
+ snap_getState: getState_1.getStateHandler,
45
+ snap_createInterface: createInterface_1.createInterfaceHandler,
46
+ snap_updateInterface: updateInterface_1.updateInterfaceHandler,
47
+ snap_getInterfaceState: getInterfaceState_1.getInterfaceStateHandler,
48
+ snap_getInterfaceContext: getInterfaceContext_1.getInterfaceContextHandler,
49
+ snap_listEntropySources: listEntropySources_1.listEntropySourcesHandler,
50
+ snap_resolveInterface: resolveInterface_1.resolveInterfaceHandler,
51
+ snap_scheduleBackgroundEvent: scheduleBackgroundEvent_1.scheduleBackgroundEventHandler,
52
+ snap_cancelBackgroundEvent: cancelBackgroundEvent_1.cancelBackgroundEventHandler,
53
+ snap_getBackgroundEvents: getBackgroundEvents_1.getBackgroundEventsHandler,
54
+ snap_setState: setState_1.setStateHandler,
55
+ snap_trackError: trackError_1.trackErrorHandler,
56
+ snap_trackEvent: trackEvent_1.trackEventHandler,
57
+ snap_openWebSocket: openWebSocket_1.openWebSocketHandler,
58
+ snap_closeWebSocket: closeWebSocket_1.closeWebSocketHandler,
59
+ snap_sendWebSocketMessage: sendWebSocketMessage_1.sendWebSocketMessageHandler,
60
+ snap_getWebSockets: getWebSockets_1.getWebSocketsHandler,
61
+ snap_startTrace: startTrace_1.startTraceHandler,
62
+ snap_endTrace: endTrace_1.endTraceHandler,
63
+ };
64
+ /* eslint-enable @typescript-eslint/naming-convention */
8
65
  /**
9
66
  * Creates a middleware that handles permitted snap RPC methods.
10
67
  *
11
68
  * @param isSnap - A flag that should indicate whether the requesting origin is a snap or not.
12
69
  * @param hooks - An object containing the hooks made available to the permitted RPC methods.
70
+ * @param messenger - The messenger.
13
71
  * @returns The middleware.
14
72
  */
15
- function createSnapsMethodMiddleware(isSnap, hooks) {
73
+ function createSnapsMethodMiddleware(isSnap, hooks, messenger) {
74
+ const nestedMiddleware = (0, json_rpc_engine_1.createMethodMiddleware)({
75
+ handlers: methodHandlers,
76
+ hooks,
77
+ messenger,
78
+ onError: snaps_utils_1.logError,
79
+ });
16
80
  // This is not actually a misused promise, the type is just wrong
17
81
  // eslint-disable-next-line @typescript-eslint/no-misused-promises
18
82
  return async function methodMiddleware(request, response, next, end) {
19
- const handler = handlers_1.methodHandlers[request.method];
20
- if (handler) {
21
- if (String.prototype.startsWith.call(request.method, 'snap_') &&
22
- !isSnap) {
23
- return end(rpc_errors_1.rpcErrors.methodNotFound());
24
- }
25
- // TODO: Once json-rpc-engine types are up to date, we should type this correctly
26
- const { implementation, hookNames } = handler;
27
- try {
28
- // Implementations may or may not be async, so we must await them.
29
- return await implementation(request, response, next, end, (0, utils_1.selectHooks)(hooks, hookNames));
30
- }
31
- catch (error) {
32
- (0, snaps_utils_1.logError)(error);
33
- return end(error);
34
- }
83
+ if (String.prototype.startsWith.call(request.method, 'snap_') && !isSnap) {
84
+ return end(rpc_errors_1.rpcErrors.methodNotFound());
35
85
  }
36
- return next();
86
+ return nestedMiddleware(request, response, next, end);
37
87
  };
38
88
  }
39
89
  exports.createSnapsMethodMiddleware = createSnapsMethodMiddleware;