@metamask/snaps-rpc-methods 15.1.1 → 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 (344) hide show
  1. package/CHANGELOG.md +27 -4
  2. package/dist/index.cjs +1 -4
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +1 -2
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.mts +1 -2
  7. package/dist/index.d.mts.map +1 -1
  8. package/dist/index.mjs +1 -2
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/permissions.cjs +18 -8
  11. package/dist/permissions.cjs.map +1 -1
  12. package/dist/permissions.d.cts +3 -2
  13. package/dist/permissions.d.cts.map +1 -1
  14. package/dist/permissions.d.mts +3 -2
  15. package/dist/permissions.d.mts.map +1 -1
  16. package/dist/permissions.mjs +17 -7
  17. package/dist/permissions.mjs.map +1 -1
  18. package/dist/permitted/cancelBackgroundEvent.cjs +10 -14
  19. package/dist/permitted/cancelBackgroundEvent.cjs.map +1 -1
  20. package/dist/permitted/cancelBackgroundEvent.d.cts +9 -12
  21. package/dist/permitted/cancelBackgroundEvent.d.cts.map +1 -1
  22. package/dist/permitted/cancelBackgroundEvent.d.mts +9 -12
  23. package/dist/permitted/cancelBackgroundEvent.d.mts.map +1 -1
  24. package/dist/permitted/cancelBackgroundEvent.mjs +10 -14
  25. package/dist/permitted/cancelBackgroundEvent.mjs.map +1 -1
  26. package/dist/permitted/clearState.cjs +10 -16
  27. package/dist/permitted/clearState.cjs.map +1 -1
  28. package/dist/permitted/clearState.d.cts +9 -23
  29. package/dist/permitted/clearState.d.cts.map +1 -1
  30. package/dist/permitted/clearState.d.mts +9 -23
  31. package/dist/permitted/clearState.d.mts.map +1 -1
  32. package/dist/permitted/clearState.mjs +10 -16
  33. package/dist/permitted/clearState.mjs.map +1 -1
  34. package/dist/permitted/closeWebSocket.cjs +7 -14
  35. package/dist/permitted/closeWebSocket.cjs.map +1 -1
  36. package/dist/permitted/closeWebSocket.d.cts +9 -12
  37. package/dist/permitted/closeWebSocket.d.cts.map +1 -1
  38. package/dist/permitted/closeWebSocket.d.mts +9 -12
  39. package/dist/permitted/closeWebSocket.d.mts.map +1 -1
  40. package/dist/permitted/closeWebSocket.mjs +7 -14
  41. package/dist/permitted/closeWebSocket.mjs.map +1 -1
  42. package/dist/permitted/createInterface.cjs +11 -15
  43. package/dist/permitted/createInterface.cjs.map +1 -1
  44. package/dist/permitted/createInterface.d.cts +23 -37
  45. package/dist/permitted/createInterface.d.cts.map +1 -1
  46. package/dist/permitted/createInterface.d.mts +23 -37
  47. package/dist/permitted/createInterface.d.mts.map +1 -1
  48. package/dist/permitted/createInterface.mjs +11 -15
  49. package/dist/permitted/createInterface.mjs.map +1 -1
  50. package/dist/permitted/endTrace.cjs +4 -6
  51. package/dist/permitted/endTrace.cjs.map +1 -1
  52. package/dist/permitted/endTrace.d.cts +8 -11
  53. package/dist/permitted/endTrace.d.cts.map +1 -1
  54. package/dist/permitted/endTrace.d.mts +8 -11
  55. package/dist/permitted/endTrace.d.mts.map +1 -1
  56. package/dist/permitted/endTrace.mjs +4 -6
  57. package/dist/permitted/endTrace.mjs.map +1 -1
  58. package/dist/permitted/getAllSnaps.cjs +5 -11
  59. package/dist/permitted/getAllSnaps.cjs.map +1 -1
  60. package/dist/permitted/getAllSnaps.d.cts +10 -14
  61. package/dist/permitted/getAllSnaps.d.cts.map +1 -1
  62. package/dist/permitted/getAllSnaps.d.mts +10 -14
  63. package/dist/permitted/getAllSnaps.d.mts.map +1 -1
  64. package/dist/permitted/getAllSnaps.mjs +5 -11
  65. package/dist/permitted/getAllSnaps.mjs.map +1 -1
  66. package/dist/permitted/getBackgroundEvents.cjs +8 -15
  67. package/dist/permitted/getBackgroundEvents.cjs.map +1 -1
  68. package/dist/permitted/getBackgroundEvents.d.cts +10 -13
  69. package/dist/permitted/getBackgroundEvents.d.cts.map +1 -1
  70. package/dist/permitted/getBackgroundEvents.d.mts +10 -13
  71. package/dist/permitted/getBackgroundEvents.d.mts.map +1 -1
  72. package/dist/permitted/getBackgroundEvents.mjs +8 -15
  73. package/dist/permitted/getBackgroundEvents.mjs.map +1 -1
  74. package/dist/permitted/getClientStatus.cjs +5 -6
  75. package/dist/permitted/getClientStatus.cjs.map +1 -1
  76. package/dist/permitted/getClientStatus.d.cts +17 -18
  77. package/dist/permitted/getClientStatus.d.cts.map +1 -1
  78. package/dist/permitted/getClientStatus.d.mts +17 -18
  79. package/dist/permitted/getClientStatus.d.mts.map +1 -1
  80. package/dist/permitted/getClientStatus.mjs +5 -6
  81. package/dist/permitted/getClientStatus.mjs.map +1 -1
  82. package/dist/permitted/getFile.cjs +7 -11
  83. package/dist/permitted/getFile.cjs.map +1 -1
  84. package/dist/permitted/getFile.d.cts +8 -10
  85. package/dist/permitted/getFile.d.cts.map +1 -1
  86. package/dist/permitted/getFile.d.mts +8 -10
  87. package/dist/permitted/getFile.d.mts.map +1 -1
  88. package/dist/permitted/getFile.mjs +7 -11
  89. package/dist/permitted/getFile.mjs.map +1 -1
  90. package/dist/permitted/getInterfaceContext.cjs +12 -15
  91. package/dist/permitted/getInterfaceContext.cjs.map +1 -1
  92. package/dist/permitted/getInterfaceContext.d.cts +9 -21
  93. package/dist/permitted/getInterfaceContext.d.cts.map +1 -1
  94. package/dist/permitted/getInterfaceContext.d.mts +9 -21
  95. package/dist/permitted/getInterfaceContext.d.mts.map +1 -1
  96. package/dist/permitted/getInterfaceContext.mjs +12 -15
  97. package/dist/permitted/getInterfaceContext.mjs.map +1 -1
  98. package/dist/permitted/getInterfaceState.cjs +11 -15
  99. package/dist/permitted/getInterfaceState.cjs.map +1 -1
  100. package/dist/permitted/getInterfaceState.d.cts +9 -21
  101. package/dist/permitted/getInterfaceState.d.cts.map +1 -1
  102. package/dist/permitted/getInterfaceState.d.mts +9 -21
  103. package/dist/permitted/getInterfaceState.d.mts.map +1 -1
  104. package/dist/permitted/getInterfaceState.mjs +11 -15
  105. package/dist/permitted/getInterfaceState.mjs.map +1 -1
  106. package/dist/permitted/getSnaps.cjs +6 -12
  107. package/dist/permitted/getSnaps.cjs.map +1 -1
  108. package/dist/permitted/getSnaps.d.cts +11 -14
  109. package/dist/permitted/getSnaps.d.cts.map +1 -1
  110. package/dist/permitted/getSnaps.d.mts +11 -14
  111. package/dist/permitted/getSnaps.d.mts.map +1 -1
  112. package/dist/permitted/getSnaps.mjs +6 -12
  113. package/dist/permitted/getSnaps.mjs.map +1 -1
  114. package/dist/permitted/getState.cjs +9 -11
  115. package/dist/permitted/getState.cjs.map +1 -1
  116. package/dist/permitted/getState.d.cts +17 -28
  117. package/dist/permitted/getState.d.cts.map +1 -1
  118. package/dist/permitted/getState.d.mts +17 -28
  119. package/dist/permitted/getState.d.mts.map +1 -1
  120. package/dist/permitted/getState.mjs +9 -11
  121. package/dist/permitted/getState.mjs.map +1 -1
  122. package/dist/permitted/getWebSockets.cjs +11 -14
  123. package/dist/permitted/getWebSockets.cjs.map +1 -1
  124. package/dist/permitted/getWebSockets.d.cts +10 -13
  125. package/dist/permitted/getWebSockets.d.cts.map +1 -1
  126. package/dist/permitted/getWebSockets.d.mts +10 -13
  127. package/dist/permitted/getWebSockets.d.mts.map +1 -1
  128. package/dist/permitted/getWebSockets.mjs +11 -14
  129. package/dist/permitted/getWebSockets.mjs.map +1 -1
  130. package/dist/permitted/index.cjs +0 -1
  131. package/dist/permitted/index.cjs.map +1 -1
  132. package/dist/permitted/index.d.cts +29 -25
  133. package/dist/permitted/index.d.cts.map +1 -1
  134. package/dist/permitted/index.d.mts +29 -25
  135. package/dist/permitted/index.d.mts.map +1 -1
  136. package/dist/permitted/index.mjs +0 -1
  137. package/dist/permitted/index.mjs.map +1 -1
  138. package/dist/permitted/invokeKeyring.cjs +12 -13
  139. package/dist/permitted/invokeKeyring.cjs.map +1 -1
  140. package/dist/permitted/invokeKeyring.d.cts +17 -16
  141. package/dist/permitted/invokeKeyring.d.cts.map +1 -1
  142. package/dist/permitted/invokeKeyring.d.mts +17 -16
  143. package/dist/permitted/invokeKeyring.d.mts.map +1 -1
  144. package/dist/permitted/invokeKeyring.mjs +12 -13
  145. package/dist/permitted/invokeKeyring.mjs.map +1 -1
  146. package/dist/permitted/invokeSnapSugar.cjs +6 -10
  147. package/dist/permitted/invokeSnapSugar.cjs.map +1 -1
  148. package/dist/permitted/invokeSnapSugar.d.cts +9 -12
  149. package/dist/permitted/invokeSnapSugar.d.cts.map +1 -1
  150. package/dist/permitted/invokeSnapSugar.d.mts +9 -12
  151. package/dist/permitted/invokeSnapSugar.d.mts.map +1 -1
  152. package/dist/permitted/invokeSnapSugar.mjs +6 -10
  153. package/dist/permitted/invokeSnapSugar.mjs.map +1 -1
  154. package/dist/permitted/listEntropySources.cjs +28 -12
  155. package/dist/permitted/listEntropySources.cjs.map +1 -1
  156. package/dist/permitted/listEntropySources.d.cts +12 -23
  157. package/dist/permitted/listEntropySources.d.cts.map +1 -1
  158. package/dist/permitted/listEntropySources.d.mts +12 -23
  159. package/dist/permitted/listEntropySources.d.mts.map +1 -1
  160. package/dist/permitted/listEntropySources.mjs +28 -12
  161. package/dist/permitted/listEntropySources.mjs.map +1 -1
  162. package/dist/permitted/middleware.cjs +70 -20
  163. package/dist/permitted/middleware.cjs.map +1 -1
  164. package/dist/permitted/middleware.d.cts +5 -2
  165. package/dist/permitted/middleware.d.cts.map +1 -1
  166. package/dist/permitted/middleware.d.mts +5 -2
  167. package/dist/permitted/middleware.d.mts.map +1 -1
  168. package/dist/permitted/middleware.mjs +70 -20
  169. package/dist/permitted/middleware.mjs.map +1 -1
  170. package/dist/permitted/openWebSocket.cjs +7 -14
  171. package/dist/permitted/openWebSocket.cjs.map +1 -1
  172. package/dist/permitted/openWebSocket.d.cts +9 -12
  173. package/dist/permitted/openWebSocket.d.cts.map +1 -1
  174. package/dist/permitted/openWebSocket.d.mts +9 -12
  175. package/dist/permitted/openWebSocket.d.mts.map +1 -1
  176. package/dist/permitted/openWebSocket.mjs +7 -14
  177. package/dist/permitted/openWebSocket.mjs.map +1 -1
  178. package/dist/permitted/requestSnaps.cjs +14 -19
  179. package/dist/permitted/requestSnaps.cjs.map +1 -1
  180. package/dist/permitted/requestSnaps.d.cts +9 -36
  181. package/dist/permitted/requestSnaps.d.cts.map +1 -1
  182. package/dist/permitted/requestSnaps.d.mts +9 -36
  183. package/dist/permitted/requestSnaps.d.mts.map +1 -1
  184. package/dist/permitted/requestSnaps.mjs +15 -20
  185. package/dist/permitted/requestSnaps.mjs.map +1 -1
  186. package/dist/permitted/resolveInterface.cjs +11 -15
  187. package/dist/permitted/resolveInterface.cjs.map +1 -1
  188. package/dist/permitted/resolveInterface.d.cts +12 -24
  189. package/dist/permitted/resolveInterface.d.cts.map +1 -1
  190. package/dist/permitted/resolveInterface.d.mts +12 -24
  191. package/dist/permitted/resolveInterface.d.mts.map +1 -1
  192. package/dist/permitted/resolveInterface.mjs +11 -15
  193. package/dist/permitted/resolveInterface.mjs.map +1 -1
  194. package/dist/permitted/scheduleBackgroundEvent.cjs +11 -14
  195. package/dist/permitted/scheduleBackgroundEvent.cjs.map +1 -1
  196. package/dist/permitted/scheduleBackgroundEvent.d.cts +10 -17
  197. package/dist/permitted/scheduleBackgroundEvent.d.cts.map +1 -1
  198. package/dist/permitted/scheduleBackgroundEvent.d.mts +10 -17
  199. package/dist/permitted/scheduleBackgroundEvent.d.mts.map +1 -1
  200. package/dist/permitted/scheduleBackgroundEvent.mjs +11 -14
  201. package/dist/permitted/scheduleBackgroundEvent.mjs.map +1 -1
  202. package/dist/permitted/sendWebSocketMessage.cjs +10 -14
  203. package/dist/permitted/sendWebSocketMessage.cjs.map +1 -1
  204. package/dist/permitted/sendWebSocketMessage.d.cts +9 -12
  205. package/dist/permitted/sendWebSocketMessage.d.cts.map +1 -1
  206. package/dist/permitted/sendWebSocketMessage.d.mts +9 -12
  207. package/dist/permitted/sendWebSocketMessage.d.mts.map +1 -1
  208. package/dist/permitted/sendWebSocketMessage.mjs +10 -14
  209. package/dist/permitted/sendWebSocketMessage.mjs.map +1 -1
  210. package/dist/permitted/setState.cjs +18 -21
  211. package/dist/permitted/setState.cjs.map +1 -1
  212. package/dist/permitted/setState.d.cts +18 -45
  213. package/dist/permitted/setState.d.cts.map +1 -1
  214. package/dist/permitted/setState.d.mts +18 -45
  215. package/dist/permitted/setState.d.mts.map +1 -1
  216. package/dist/permitted/setState.mjs +18 -21
  217. package/dist/permitted/setState.mjs.map +1 -1
  218. package/dist/permitted/startTrace.cjs +4 -6
  219. package/dist/permitted/startTrace.cjs.map +1 -1
  220. package/dist/permitted/startTrace.d.cts +8 -11
  221. package/dist/permitted/startTrace.d.cts.map +1 -1
  222. package/dist/permitted/startTrace.d.mts +8 -11
  223. package/dist/permitted/startTrace.d.mts.map +1 -1
  224. package/dist/permitted/startTrace.mjs +4 -6
  225. package/dist/permitted/startTrace.mjs.map +1 -1
  226. package/dist/permitted/trackError.cjs +4 -6
  227. package/dist/permitted/trackError.cjs.map +1 -1
  228. package/dist/permitted/trackError.d.cts +8 -11
  229. package/dist/permitted/trackError.d.cts.map +1 -1
  230. package/dist/permitted/trackError.d.mts +8 -11
  231. package/dist/permitted/trackError.d.mts.map +1 -1
  232. package/dist/permitted/trackError.mjs +4 -6
  233. package/dist/permitted/trackError.mjs.map +1 -1
  234. package/dist/permitted/trackEvent.cjs +4 -6
  235. package/dist/permitted/trackEvent.cjs.map +1 -1
  236. package/dist/permitted/trackEvent.d.cts +8 -11
  237. package/dist/permitted/trackEvent.d.cts.map +1 -1
  238. package/dist/permitted/trackEvent.d.mts +8 -11
  239. package/dist/permitted/trackEvent.d.mts.map +1 -1
  240. package/dist/permitted/trackEvent.mjs +4 -6
  241. package/dist/permitted/trackEvent.mjs.map +1 -1
  242. package/dist/permitted/updateInterface.cjs +11 -15
  243. package/dist/permitted/updateInterface.cjs.map +1 -1
  244. package/dist/permitted/updateInterface.d.cts +9 -22
  245. package/dist/permitted/updateInterface.d.cts.map +1 -1
  246. package/dist/permitted/updateInterface.d.mts +9 -22
  247. package/dist/permitted/updateInterface.d.mts.map +1 -1
  248. package/dist/permitted/updateInterface.mjs +11 -15
  249. package/dist/permitted/updateInterface.mjs.map +1 -1
  250. package/dist/restricted/dialog.cjs +23 -30
  251. package/dist/restricted/dialog.cjs.map +1 -1
  252. package/dist/restricted/dialog.d.cts +10 -58
  253. package/dist/restricted/dialog.d.cts.map +1 -1
  254. package/dist/restricted/dialog.d.mts +10 -58
  255. package/dist/restricted/dialog.d.mts.map +1 -1
  256. package/dist/restricted/dialog.mjs +23 -30
  257. package/dist/restricted/dialog.mjs.map +1 -1
  258. package/dist/restricted/getBip32Entropy.cjs +15 -12
  259. package/dist/restricted/getBip32Entropy.cjs.map +1 -1
  260. package/dist/restricted/getBip32Entropy.d.cts +11 -24
  261. package/dist/restricted/getBip32Entropy.d.cts.map +1 -1
  262. package/dist/restricted/getBip32Entropy.d.mts +11 -24
  263. package/dist/restricted/getBip32Entropy.d.mts.map +1 -1
  264. package/dist/restricted/getBip32Entropy.mjs +16 -13
  265. package/dist/restricted/getBip32Entropy.mjs.map +1 -1
  266. package/dist/restricted/getBip32PublicKey.cjs +15 -12
  267. package/dist/restricted/getBip32PublicKey.cjs.map +1 -1
  268. package/dist/restricted/getBip32PublicKey.d.cts +11 -24
  269. package/dist/restricted/getBip32PublicKey.d.cts.map +1 -1
  270. package/dist/restricted/getBip32PublicKey.d.mts +11 -24
  271. package/dist/restricted/getBip32PublicKey.d.mts.map +1 -1
  272. package/dist/restricted/getBip32PublicKey.mjs +16 -13
  273. package/dist/restricted/getBip32PublicKey.mjs.map +1 -1
  274. package/dist/restricted/getBip44Entropy.cjs +14 -10
  275. package/dist/restricted/getBip44Entropy.cjs.map +1 -1
  276. package/dist/restricted/getBip44Entropy.d.cts +11 -15
  277. package/dist/restricted/getBip44Entropy.d.cts.map +1 -1
  278. package/dist/restricted/getBip44Entropy.d.mts +11 -15
  279. package/dist/restricted/getBip44Entropy.d.mts.map +1 -1
  280. package/dist/restricted/getBip44Entropy.mjs +15 -11
  281. package/dist/restricted/getBip44Entropy.mjs.map +1 -1
  282. package/dist/restricted/getEntropy.cjs +10 -10
  283. package/dist/restricted/getEntropy.cjs.map +1 -1
  284. package/dist/restricted/getEntropy.d.cts +11 -15
  285. package/dist/restricted/getEntropy.d.cts.map +1 -1
  286. package/dist/restricted/getEntropy.d.mts +11 -15
  287. package/dist/restricted/getEntropy.d.mts.map +1 -1
  288. package/dist/restricted/getEntropy.mjs +11 -11
  289. package/dist/restricted/getEntropy.mjs.map +1 -1
  290. package/dist/restricted/index.cjs.map +1 -1
  291. package/dist/restricted/index.d.cts +20 -160
  292. package/dist/restricted/index.d.cts.map +1 -1
  293. package/dist/restricted/index.d.mts +20 -160
  294. package/dist/restricted/index.d.mts.map +1 -1
  295. package/dist/restricted/index.mjs.map +1 -1
  296. package/dist/restricted/invokeSnap.cjs +11 -12
  297. package/dist/restricted/invokeSnap.cjs.map +1 -1
  298. package/dist/restricted/invokeSnap.d.cts +9 -13
  299. package/dist/restricted/invokeSnap.d.cts.map +1 -1
  300. package/dist/restricted/invokeSnap.d.mts +9 -13
  301. package/dist/restricted/invokeSnap.d.mts.map +1 -1
  302. package/dist/restricted/invokeSnap.mjs +11 -12
  303. package/dist/restricted/invokeSnap.mjs.map +1 -1
  304. package/dist/restricted/manageState.cjs +21 -20
  305. package/dist/restricted/manageState.cjs.map +1 -1
  306. package/dist/restricted/manageState.d.cts +12 -34
  307. package/dist/restricted/manageState.d.cts.map +1 -1
  308. package/dist/restricted/manageState.d.mts +12 -34
  309. package/dist/restricted/manageState.d.mts.map +1 -1
  310. package/dist/restricted/manageState.mjs +21 -20
  311. package/dist/restricted/manageState.mjs.map +1 -1
  312. package/dist/restricted/notify.cjs +31 -24
  313. package/dist/restricted/notify.cjs.map +1 -1
  314. package/dist/restricted/notify.d.cts +16 -25
  315. package/dist/restricted/notify.d.cts.map +1 -1
  316. package/dist/restricted/notify.d.mts +16 -25
  317. package/dist/restricted/notify.d.mts.map +1 -1
  318. package/dist/restricted/notify.mjs +32 -25
  319. package/dist/restricted/notify.mjs.map +1 -1
  320. package/dist/types.cjs +3 -0
  321. package/dist/types.cjs.map +1 -0
  322. package/dist/types.d.cts +155 -0
  323. package/dist/types.d.cts.map +1 -0
  324. package/dist/types.d.mts +155 -0
  325. package/dist/types.d.mts.map +1 -0
  326. package/dist/types.mjs +2 -0
  327. package/dist/types.mjs.map +1 -0
  328. package/dist/utils.cjs +78 -24
  329. package/dist/utils.cjs.map +1 -1
  330. package/dist/utils.d.cts +21 -13
  331. package/dist/utils.d.cts.map +1 -1
  332. package/dist/utils.d.mts +21 -13
  333. package/dist/utils.d.mts.map +1 -1
  334. package/dist/utils.mjs +75 -22
  335. package/dist/utils.mjs.map +1 -1
  336. package/package.json +6 -6
  337. package/dist/permitted/handlers.cjs +0 -63
  338. package/dist/permitted/handlers.cjs.map +0 -1
  339. package/dist/permitted/handlers.d.cts +0 -299
  340. package/dist/permitted/handlers.d.cts.map +0 -1
  341. package/dist/permitted/handlers.d.mts +0 -299
  342. package/dist/permitted/handlers.d.mts.map +0 -1
  343. package/dist/permitted/handlers.mjs +0 -60
  344. package/dist/permitted/handlers.mjs.map +0 -1
@@ -1,20 +1,11 @@
1
1
  import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
2
- import type { GetInterfaceContextParams, GetInterfaceContextResult, InterfaceContext, JsonRpcRequest } from "@metamask/snaps-sdk";
2
+ import type { Messenger } from "@metamask/messenger";
3
+ import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller";
4
+ import type { GetInterfaceContextParams, GetInterfaceContextResult } from "@metamask/snaps-sdk";
3
5
  import { type InferMatching } from "@metamask/snaps-utils";
4
6
  import type { PendingJsonRpcResponse } from "@metamask/utils";
5
- import type { MethodHooksObject } from "../utils.cjs";
6
- export type GetInterfaceContextMethodHooks = {
7
- /**
8
- * @param permissionName - The name of the permission to check.
9
- * @returns Whether the Snap has the permission.
10
- */
11
- hasPermission: (permissionName: string) => boolean;
12
- /**
13
- * @param id - The interface ID.
14
- * @returns The interface context.
15
- */
16
- getInterfaceContext: (id: string) => InterfaceContext | null;
17
- };
7
+ import type { JsonRpcRequestWithOrigin, SnapInterfaceControllerGetInterfaceAction } from "../types.cjs";
8
+ export type GetInterfaceContextMethodActions = PermissionControllerHasPermissionAction | SnapInterfaceControllerGetInterfaceAction;
18
9
  /**
19
10
  * Get the context of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
20
11
  * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
@@ -52,9 +43,8 @@ export type GetInterfaceContextMethodHooks = {
52
43
  * ```
53
44
  */
54
45
  export declare const getInterfaceContextHandler: {
55
- methodNames: ["snap_getInterfaceContext"];
56
46
  implementation: typeof getInterfaceContextImplementation;
57
- hookNames: MethodHooksObject<GetInterfaceContextMethodHooks>;
47
+ actionNames: ("SnapInterfaceController:getInterface" | "PermissionController:hasPermission")[];
58
48
  };
59
49
  declare const GetInterfaceContextParametersStruct: import("@metamask/superstruct").Struct<{
60
50
  id: string;
@@ -70,12 +60,10 @@ export type GetInterfaceContextParameters = InferMatching<typeof GetInterfaceCon
70
60
  * @param _next - The `json-rpc-engine` "next" callback. Not used by this
71
61
  * function.
72
62
  * @param end - The `json-rpc-engine` "end" callback.
73
- * @param hooks - The RPC method hooks.
74
- * @param hooks.hasPermission - The function to check if the Snap has a given
75
- * permission.
76
- * @param hooks.getInterfaceContext - The function to get the interface context.
63
+ * @param _hooks - The RPC method hooks. Not used by this function.
64
+ * @param messenger - The messenger used to call controller actions.
77
65
  * @returns Nothing.
78
66
  */
79
- declare function getInterfaceContextImplementation(req: JsonRpcRequest<GetInterfaceContextParameters>, res: PendingJsonRpcResponse<GetInterfaceContextResult>, _next: unknown, end: JsonRpcEngineEndCallback, { hasPermission, getInterfaceContext }: GetInterfaceContextMethodHooks): void;
67
+ declare function getInterfaceContextImplementation(req: JsonRpcRequestWithOrigin<GetInterfaceContextParameters>, res: PendingJsonRpcResponse<GetInterfaceContextResult>, _next: unknown, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, GetInterfaceContextMethodActions>): void;
80
68
  export {};
81
69
  //# sourceMappingURL=getInterfaceContext.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getInterfaceContext.d.cts","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,kCAAkC;AAG1E,OAAO,KAAK,EACV,yBAAyB,EACzB,yBAAyB,EACzB,gBAAgB,EAChB,cAAc,EACf,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAUlD,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;;OAGG;IACH,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD;;;OAGG;IACH,mBAAmB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,gBAAgB,GAAG,IAAI,CAAC;CAC9D,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,0BAA0B;;;;CAQtC,CAAC;AAEF,QAAA,MAAM,mCAAmC;;;;EAEvC,CAAC;AAEH,MAAM,MAAM,6BAA6B,GAAG,aAAa,CACvD,OAAO,mCAAmC,EAC1C,yBAAyB,CAC1B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,iBAAS,iCAAiC,CACxC,GAAG,EAAE,cAAc,CAAC,6BAA6B,CAAC,EAClD,GAAG,EAAE,sBAAsB,CAAC,yBAAyB,CAAC,EACtD,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,EAAE,aAAa,EAAE,mBAAmB,EAAE,EAAE,8BAA8B,GACrE,IAAI,CAsBN"}
1
+ {"version":3,"file":"getInterfaceContext.d.cts","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,uCAAuC,EAAE,wCAAwC;AAE/F,OAAO,KAAK,EACV,yBAAyB,EACzB,yBAAyB,EAC1B,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAE9D,OAAO,KAAK,EACV,wBAAwB,EACxB,yCAAyC,EAC1C,qBAAiB;AAGlB,MAAM,MAAM,gCAAgC,GACxC,uCAAuC,GACvC,yCAAyC,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,0BAA0B;;;CAYtC,CAAC;AAEF,QAAA,MAAM,mCAAmC;;;;EAEvC,CAAC;AAEH,MAAM,MAAM,6BAA6B,GAAG,aAAa,CACvD,OAAO,mCAAmC,EAC1C,yBAAyB,CAC1B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,iBAAS,iCAAiC,CACxC,GAAG,EAAE,wBAAwB,CAAC,6BAA6B,CAAC,EAC5D,GAAG,EAAE,sBAAsB,CAAC,yBAAyB,CAAC,EACtD,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,gCAAgC,CAAC,GAC7D,IAAI,CAgCN"}
@@ -1,20 +1,11 @@
1
1
  import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
2
- import type { GetInterfaceContextParams, GetInterfaceContextResult, InterfaceContext, JsonRpcRequest } from "@metamask/snaps-sdk";
2
+ import type { Messenger } from "@metamask/messenger";
3
+ import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller";
4
+ import type { GetInterfaceContextParams, GetInterfaceContextResult } from "@metamask/snaps-sdk";
3
5
  import { type InferMatching } from "@metamask/snaps-utils";
4
6
  import type { PendingJsonRpcResponse } from "@metamask/utils";
5
- import type { MethodHooksObject } from "../utils.mjs";
6
- export type GetInterfaceContextMethodHooks = {
7
- /**
8
- * @param permissionName - The name of the permission to check.
9
- * @returns Whether the Snap has the permission.
10
- */
11
- hasPermission: (permissionName: string) => boolean;
12
- /**
13
- * @param id - The interface ID.
14
- * @returns The interface context.
15
- */
16
- getInterfaceContext: (id: string) => InterfaceContext | null;
17
- };
7
+ import type { JsonRpcRequestWithOrigin, SnapInterfaceControllerGetInterfaceAction } from "../types.mjs";
8
+ export type GetInterfaceContextMethodActions = PermissionControllerHasPermissionAction | SnapInterfaceControllerGetInterfaceAction;
18
9
  /**
19
10
  * Get the context of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
20
11
  * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
@@ -52,9 +43,8 @@ export type GetInterfaceContextMethodHooks = {
52
43
  * ```
53
44
  */
54
45
  export declare const getInterfaceContextHandler: {
55
- methodNames: ["snap_getInterfaceContext"];
56
46
  implementation: typeof getInterfaceContextImplementation;
57
- hookNames: MethodHooksObject<GetInterfaceContextMethodHooks>;
47
+ actionNames: ("SnapInterfaceController:getInterface" | "PermissionController:hasPermission")[];
58
48
  };
59
49
  declare const GetInterfaceContextParametersStruct: import("@metamask/superstruct").Struct<{
60
50
  id: string;
@@ -70,12 +60,10 @@ export type GetInterfaceContextParameters = InferMatching<typeof GetInterfaceCon
70
60
  * @param _next - The `json-rpc-engine` "next" callback. Not used by this
71
61
  * function.
72
62
  * @param end - The `json-rpc-engine` "end" callback.
73
- * @param hooks - The RPC method hooks.
74
- * @param hooks.hasPermission - The function to check if the Snap has a given
75
- * permission.
76
- * @param hooks.getInterfaceContext - The function to get the interface context.
63
+ * @param _hooks - The RPC method hooks. Not used by this function.
64
+ * @param messenger - The messenger used to call controller actions.
77
65
  * @returns Nothing.
78
66
  */
79
- declare function getInterfaceContextImplementation(req: JsonRpcRequest<GetInterfaceContextParameters>, res: PendingJsonRpcResponse<GetInterfaceContextResult>, _next: unknown, end: JsonRpcEngineEndCallback, { hasPermission, getInterfaceContext }: GetInterfaceContextMethodHooks): void;
67
+ declare function getInterfaceContextImplementation(req: JsonRpcRequestWithOrigin<GetInterfaceContextParameters>, res: PendingJsonRpcResponse<GetInterfaceContextResult>, _next: unknown, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, GetInterfaceContextMethodActions>): void;
80
68
  export {};
81
69
  //# sourceMappingURL=getInterfaceContext.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getInterfaceContext.d.mts","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,kCAAkC;AAG1E,OAAO,KAAK,EACV,yBAAyB,EACzB,yBAAyB,EACzB,gBAAgB,EAChB,cAAc,EACf,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAUlD,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;;OAGG;IACH,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD;;;OAGG;IACH,mBAAmB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,gBAAgB,GAAG,IAAI,CAAC;CAC9D,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,0BAA0B;;;;CAQtC,CAAC;AAEF,QAAA,MAAM,mCAAmC;;;;EAEvC,CAAC;AAEH,MAAM,MAAM,6BAA6B,GAAG,aAAa,CACvD,OAAO,mCAAmC,EAC1C,yBAAyB,CAC1B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,iBAAS,iCAAiC,CACxC,GAAG,EAAE,cAAc,CAAC,6BAA6B,CAAC,EAClD,GAAG,EAAE,sBAAsB,CAAC,yBAAyB,CAAC,EACtD,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,EAAE,aAAa,EAAE,mBAAmB,EAAE,EAAE,8BAA8B,GACrE,IAAI,CAsBN"}
1
+ {"version":3,"file":"getInterfaceContext.d.mts","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,uCAAuC,EAAE,wCAAwC;AAE/F,OAAO,KAAK,EACV,yBAAyB,EACzB,yBAAyB,EAC1B,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAE9D,OAAO,KAAK,EACV,wBAAwB,EACxB,yCAAyC,EAC1C,qBAAiB;AAGlB,MAAM,MAAM,gCAAgC,GACxC,uCAAuC,GACvC,yCAAyC,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,0BAA0B;;;CAYtC,CAAC;AAEF,QAAA,MAAM,mCAAmC;;;;EAEvC,CAAC;AAEH,MAAM,MAAM,6BAA6B,GAAG,aAAa,CACvD,OAAO,mCAAmC,EAC1C,yBAAyB,CAC1B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,iBAAS,iCAAiC,CACxC,GAAG,EAAE,wBAAwB,CAAC,6BAA6B,CAAC,EAC5D,GAAG,EAAE,sBAAsB,CAAC,yBAAyB,CAAC,EACtD,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,gCAAgC,CAAC,GAC7D,IAAI,CAgCN"}
@@ -1,11 +1,6 @@
1
1
  import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
2
2
  import { StructError, create, object, string } from "@metamask/superstruct";
3
3
  import { UI_PERMISSIONS } from "../utils.mjs";
4
- const methodName = 'snap_getInterfaceContext';
5
- const hookNames = {
6
- hasPermission: true,
7
- getInterfaceContext: true,
8
- };
9
4
  /**
10
5
  * Get the context of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
11
6
  * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
@@ -43,9 +38,11 @@ const hookNames = {
43
38
  * ```
44
39
  */
45
40
  export const getInterfaceContextHandler = {
46
- methodNames: [methodName],
47
41
  implementation: getInterfaceContextImplementation,
48
- hookNames,
42
+ actionNames: [
43
+ 'PermissionController:hasPermission',
44
+ 'SnapInterfaceController:getInterface',
45
+ ],
49
46
  };
50
47
  const GetInterfaceContextParametersStruct = object({
51
48
  id: string(),
@@ -58,23 +55,23 @@ const GetInterfaceContextParametersStruct = object({
58
55
  * @param _next - The `json-rpc-engine` "next" callback. Not used by this
59
56
  * function.
60
57
  * @param end - The `json-rpc-engine` "end" callback.
61
- * @param hooks - The RPC method hooks.
62
- * @param hooks.hasPermission - The function to check if the Snap has a given
63
- * permission.
64
- * @param hooks.getInterfaceContext - The function to get the interface context.
58
+ * @param _hooks - The RPC method hooks. Not used by this function.
59
+ * @param messenger - The messenger used to call controller actions.
65
60
  * @returns Nothing.
66
61
  */
67
- function getInterfaceContextImplementation(req, res, _next, end, { hasPermission, getInterfaceContext }) {
68
- if (!UI_PERMISSIONS.some(hasPermission)) {
62
+ function getInterfaceContextImplementation(req, res, _next, end, _hooks, messenger) {
63
+ const { params, origin } = req;
64
+ const isPermitted = UI_PERMISSIONS.some((permission) => messenger.call('PermissionController:hasPermission', origin, permission));
65
+ if (!isPermitted) {
69
66
  return end(providerErrors.unauthorized({
70
67
  message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,
71
68
  }));
72
69
  }
73
- const { params } = req;
74
70
  try {
75
71
  const validatedParams = getValidatedParams(params);
76
72
  const { id } = validatedParams;
77
- res.result = getInterfaceContext(id);
73
+ const { context } = messenger.call('SnapInterfaceController:getInterface', origin, id);
74
+ res.result = context;
78
75
  }
79
76
  catch (error) {
80
77
  return end(error);
@@ -1 +1 @@
1
- {"version":3,"file":"getInterfaceContext.mjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAQjE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AAI5E,OAAO,EAAE,cAAc,EAAE,qBAAiB;AAE1C,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAE9C,MAAM,SAAS,GAAsD;IACnE,aAAa,EAAE,IAAI;IACnB,mBAAmB,EAAE,IAAI;CAC1B,CAAC;AAgBF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,WAAW,EAAE,CAAC,UAAU,CAAU;IAClC,cAAc,EAAE,iCAAiC;IACjD,SAAS;CAKV,CAAC;AAEF,MAAM,mCAAmC,GAAG,MAAM,CAAC;IACjD,EAAE,EAAE,MAAM,EAAE;CACb,CAAC,CAAC;AAOH;;;;;;;;;;;;;GAaG;AACH,SAAS,iCAAiC,CACxC,GAAkD,EAClD,GAAsD,EACtD,KAAc,EACd,GAA6B,EAC7B,EAAE,aAAa,EAAE,mBAAmB,EAAkC;IAEtE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;QACxC,OAAO,GAAG,CACR,cAAc,CAAC,YAAY,CAAC;YAC1B,OAAO,EAAE,kFAAkF,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SACxH,CAAC,CACH,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC;QAE/B,GAAG,CAAC,MAAM,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,mCAAmC,CAAC,CAAC;IAC7D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceContextParams,\n GetInterfaceContextResult,\n InterfaceContext,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, string } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { UI_PERMISSIONS } from '../utils';\n\nconst methodName = 'snap_getInterfaceContext';\n\nconst hookNames: MethodHooksObject<GetInterfaceContextMethodHooks> = {\n hasPermission: true,\n getInterfaceContext: true,\n};\n\nexport type GetInterfaceContextMethodHooks = {\n /**\n * @param permissionName - The name of the permission to check.\n * @returns Whether the Snap has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * @param id - The interface ID.\n * @returns The interface context.\n */\n getInterfaceContext: (id: string) => InterfaceContext | null;\n};\n\n/**\n * Get the context of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)\n * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).\n *\n * @example\n * ```ts\n * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx';\n *\n * const interfaceId = await snap.request({\n * method: 'snap_createInterface',\n * params: {\n * ui: (\n * <Box>\n * <Heading>Hello, world!</Heading>\n * <Text>Welcome to my Snap homepage!</Text>\n * </Box>\n * ),\n * context: {\n * key: 'value'\n * }\n * },\n * })\n *\n * const context = await snap.request({\n * method: 'snap_getInterfaceContext',\n * params: {\n * id: interfaceId,\n * },\n * })\n *\n * console.log(context)\n * // {\n * // key: 'value'\n * // }\n * ```\n */\nexport const getInterfaceContextHandler = {\n methodNames: [methodName] as const,\n implementation: getInterfaceContextImplementation,\n hookNames,\n} satisfies PermittedHandlerExport<\n GetInterfaceContextMethodHooks,\n GetInterfaceContextParameters,\n GetInterfaceContextResult\n>;\n\nconst GetInterfaceContextParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceContextParameters = InferMatching<\n typeof GetInterfaceContextParametersStruct,\n GetInterfaceContextParams\n>;\n\n/**\n * The `snap_getInterfaceContext` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - The function to check if the Snap has a given\n * permission.\n * @param hooks.getInterfaceContext - The function to get the interface context.\n * @returns Nothing.\n */\nfunction getInterfaceContextImplementation(\n req: JsonRpcRequest<GetInterfaceContextParameters>,\n res: PendingJsonRpcResponse<GetInterfaceContextResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { hasPermission, getInterfaceContext }: GetInterfaceContextMethodHooks,\n): void {\n if (!UI_PERMISSIONS.some(hasPermission)) {\n return end(\n providerErrors.unauthorized({\n message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,\n }),\n );\n }\n\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n res.result = getInterfaceContext(id);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceContext 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 getInterfaceContext method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceContextParameters {\n try {\n return create(params, GetInterfaceContextParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
1
+ {"version":3,"file":"getInterfaceContext.mjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAMjE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AAO5E,OAAO,EAAE,cAAc,EAAE,qBAAiB;AAM1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,cAAc,EAAE,iCAAiC;IACjD,WAAW,EAAE;QACX,oCAAoC;QACpC,sCAAsC;KACvC;CAOF,CAAC;AAEF,MAAM,mCAAmC,GAAG,MAAM,CAAC;IACjD,EAAE,EAAE,MAAM,EAAE;CACb,CAAC,CAAC;AAOH;;;;;;;;;;;GAWG;AACH,SAAS,iCAAiC,CACxC,GAA4D,EAC5D,GAAsD,EACtD,KAAc,EACd,GAA6B,EAC7B,MAAa,EACb,SAA8D;IAE9D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAE/B,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CACrD,SAAS,CAAC,IAAI,CAAC,oCAAoC,EAAE,MAAM,EAAE,UAAU,CAAC,CACzE,CAAC;IAEF,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CACR,cAAc,CAAC,YAAY,CAAC;YAC1B,OAAO,EAAE,kFAAkF,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SACxH,CAAC,CACH,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC;QAE/B,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC,IAAI,CAChC,sCAAsC,EACtC,MAAM,EACN,EAAE,CACH,CAAC;QAEF,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,mCAAmC,CAAC,CAAC;IAC7D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,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, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceContextParams,\n GetInterfaceContextResult,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, string } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type {\n JsonRpcRequestWithOrigin,\n SnapInterfaceControllerGetInterfaceAction,\n} from '../types';\nimport { UI_PERMISSIONS } from '../utils';\n\nexport type GetInterfaceContextMethodActions =\n | PermissionControllerHasPermissionAction\n | SnapInterfaceControllerGetInterfaceAction;\n\n/**\n * Get the context of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)\n * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).\n *\n * @example\n * ```ts\n * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx';\n *\n * const interfaceId = await snap.request({\n * method: 'snap_createInterface',\n * params: {\n * ui: (\n * <Box>\n * <Heading>Hello, world!</Heading>\n * <Text>Welcome to my Snap homepage!</Text>\n * </Box>\n * ),\n * context: {\n * key: 'value'\n * }\n * },\n * })\n *\n * const context = await snap.request({\n * method: 'snap_getInterfaceContext',\n * params: {\n * id: interfaceId,\n * },\n * })\n *\n * console.log(context)\n * // {\n * // key: 'value'\n * // }\n * ```\n */\nexport const getInterfaceContextHandler = {\n implementation: getInterfaceContextImplementation,\n actionNames: [\n 'PermissionController:hasPermission',\n 'SnapInterfaceController:getInterface',\n ],\n} satisfies MethodHandler<\n never,\n GetInterfaceContextMethodActions,\n GetInterfaceContextParameters,\n GetInterfaceContextResult,\n { origin: string }\n>;\n\nconst GetInterfaceContextParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceContextParameters = InferMatching<\n typeof GetInterfaceContextParametersStruct,\n GetInterfaceContextParams\n>;\n\n/**\n * The `snap_getInterfaceContext` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param _hooks - The RPC method hooks. Not used by this function.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nfunction getInterfaceContextImplementation(\n req: JsonRpcRequestWithOrigin<GetInterfaceContextParameters>,\n res: PendingJsonRpcResponse<GetInterfaceContextResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n _hooks: never,\n messenger: Messenger<string, GetInterfaceContextMethodActions>,\n): void {\n const { params, origin } = req;\n\n const isPermitted = UI_PERMISSIONS.some((permission) =>\n messenger.call('PermissionController:hasPermission', origin, permission),\n );\n\n if (!isPermitted) {\n return end(\n providerErrors.unauthorized({\n message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,\n }),\n );\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n const { context } = messenger.call(\n 'SnapInterfaceController:getInterface',\n origin,\n id,\n );\n\n res.result = context;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceContext 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 getInterfaceContext method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceContextParameters {\n try {\n return create(params, GetInterfaceContextParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
@@ -4,11 +4,6 @@ exports.getInterfaceStateHandler = void 0;
4
4
  const rpc_errors_1 = require("@metamask/rpc-errors");
5
5
  const superstruct_1 = require("@metamask/superstruct");
6
6
  const utils_1 = require("../utils.cjs");
7
- const methodName = 'snap_getInterfaceState';
8
- const hookNames = {
9
- hasPermission: true,
10
- getInterfaceState: true,
11
- };
12
7
  /**
13
8
  * Get the form state of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
14
9
  * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
@@ -24,9 +19,11 @@ const hookNames = {
24
19
  * ```
25
20
  */
26
21
  exports.getInterfaceStateHandler = {
27
- methodNames: [methodName],
28
22
  implementation: getGetInterfaceStateImplementation,
29
- hookNames,
23
+ actionNames: [
24
+ 'PermissionController:hasPermission',
25
+ 'SnapInterfaceController:getInterfaceState',
26
+ ],
30
27
  };
31
28
  const GetInterfaceStateParametersStruct = (0, superstruct_1.object)({
32
29
  id: (0, superstruct_1.string)(),
@@ -39,23 +36,22 @@ const GetInterfaceStateParametersStruct = (0, superstruct_1.object)({
39
36
  * @param _next - The `json-rpc-engine` "next" callback. Not used by this
40
37
  * function.
41
38
  * @param end - The `json-rpc-engine` "end" callback.
42
- * @param hooks - The RPC method hooks.
43
- * @param hooks.hasPermission - The function to check if the Snap has a given
44
- * permission.
45
- * @param hooks.getInterfaceState - The function to get the interface state.
39
+ * @param _hooks - The RPC method hooks. Not used by this function.
40
+ * @param messenger - The messenger used to call controller actions.
46
41
  * @returns Nothing.
47
42
  */
48
- function getGetInterfaceStateImplementation(req, res, _next, end, { hasPermission, getInterfaceState }) {
49
- if (!utils_1.UI_PERMISSIONS.some(hasPermission)) {
43
+ function getGetInterfaceStateImplementation(req, res, _next, end, _hooks, messenger) {
44
+ const { params, origin } = req;
45
+ const isPermitted = utils_1.UI_PERMISSIONS.some((permission) => messenger.call('PermissionController:hasPermission', origin, permission));
46
+ if (!isPermitted) {
50
47
  return end(rpc_errors_1.providerErrors.unauthorized({
51
48
  message: `This method can only be used if the Snap has one of the following permissions: ${utils_1.UI_PERMISSIONS.join(', ')}.`,
52
49
  }));
53
50
  }
54
- const { params } = req;
55
51
  try {
56
52
  const validatedParams = getValidatedParams(params);
57
53
  const { id } = validatedParams;
58
- res.result = getInterfaceState(id);
54
+ res.result = messenger.call('SnapInterfaceController:getInterfaceState', origin, id);
59
55
  }
60
56
  catch (error) {
61
57
  return end(error);
@@ -1 +1 @@
1
- {"version":3,"file":"getInterfaceState.cjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceState.ts"],"names":[],"mappings":";;;AAEA,qDAAiE;AAQjE,uDAA4E;AAI5E,wCAA0C;AAE1C,MAAM,UAAU,GAAG,wBAAwB,CAAC;AAE5C,MAAM,SAAS,GAAoD;IACjE,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,IAAI;CACxB,CAAC;AAgBF;;;;;;;;;;;;;GAaG;AACU,QAAA,wBAAwB,GAAG;IACtC,WAAW,EAAE,CAAC,UAAU,CAAU;IAClC,cAAc,EAAE,kCAAkC;IAClD,SAAS;CAKV,CAAC;AAEF,MAAM,iCAAiC,GAAG,IAAA,oBAAM,EAAC;IAC/C,EAAE,EAAE,IAAA,oBAAM,GAAE;CACb,CAAC,CAAC;AAOH;;;;;;;;;;;;;GAaG;AACH,SAAS,kCAAkC,CACzC,GAAgD,EAChD,GAAoD,EACpD,KAAc,EACd,GAA6B,EAC7B,EAAE,aAAa,EAAE,iBAAiB,EAAgC;IAElE,IAAI,CAAC,sBAAc,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;QACxC,OAAO,GAAG,CACR,2BAAc,CAAC,YAAY,CAAC;YAC1B,OAAO,EAAE,kFAAkF,sBAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SACxH,CAAC,CACH,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC;QAE/B,GAAG,CAAC,MAAM,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,iCAAiC,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,yBAAW,EAAE,CAAC;YACjC,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceStateParams,\n GetInterfaceStateResult,\n InterfaceState,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, string } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { UI_PERMISSIONS } from '../utils';\n\nconst methodName = 'snap_getInterfaceState';\n\nconst hookNames: MethodHooksObject<GetInterfaceStateMethodHooks> = {\n hasPermission: true,\n getInterfaceState: true,\n};\n\nexport type GetInterfaceStateMethodHooks = {\n /**\n * @param permissionName - The name of the permission to check.\n * @returns Whether the Snap has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * @param id - The interface ID.\n * @returns The interface state.\n */\n getInterfaceState: (id: string) => InterfaceState;\n};\n\n/**\n * Get the form state of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)\n * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).\n *\n * @example\n * ```ts\n * const state = await snap.request({\n * method: 'snap_getInterfaceState',\n * params: {\n * id: interfaceId,\n * },\n * });\n * ```\n */\nexport const getInterfaceStateHandler = {\n methodNames: [methodName] as const,\n implementation: getGetInterfaceStateImplementation,\n hookNames,\n} satisfies PermittedHandlerExport<\n GetInterfaceStateMethodHooks,\n GetInterfaceStateParameters,\n GetInterfaceStateResult\n>;\n\nconst GetInterfaceStateParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceStateParameters = InferMatching<\n typeof GetInterfaceStateParametersStruct,\n GetInterfaceStateParams\n>;\n\n/**\n * The `snap_getInterfaceState` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - The function to check if the Snap has a given\n * permission.\n * @param hooks.getInterfaceState - The function to get the interface state.\n * @returns Nothing.\n */\nfunction getGetInterfaceStateImplementation(\n req: JsonRpcRequest<GetInterfaceStateParameters>,\n res: PendingJsonRpcResponse<GetInterfaceStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { hasPermission, getInterfaceState }: GetInterfaceStateMethodHooks,\n): void {\n if (!UI_PERMISSIONS.some(hasPermission)) {\n return end(\n providerErrors.unauthorized({\n message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,\n }),\n );\n }\n\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n res.result = getInterfaceState(id);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceState 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 getInterfaceState method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceStateParameters {\n try {\n return create(params, GetInterfaceStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
1
+ {"version":3,"file":"getInterfaceState.cjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceState.ts"],"names":[],"mappings":";;;AAMA,qDAAiE;AAMjE,uDAA4E;AAO5E,wCAA0C;AAM1C;;;;;;;;;;;;;GAaG;AACU,QAAA,wBAAwB,GAAG;IACtC,cAAc,EAAE,kCAAkC;IAClD,WAAW,EAAE;QACX,oCAAoC;QACpC,2CAA2C;KAC5C;CAOF,CAAC;AAEF,MAAM,iCAAiC,GAAG,IAAA,oBAAM,EAAC;IAC/C,EAAE,EAAE,IAAA,oBAAM,GAAE;CACb,CAAC,CAAC;AAOH;;;;;;;;;;;GAWG;AACH,SAAS,kCAAkC,CACzC,GAA0D,EAC1D,GAAoD,EACpD,KAAc,EACd,GAA6B,EAC7B,MAAa,EACb,SAA4D;IAE5D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAE/B,MAAM,WAAW,GAAG,sBAAc,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CACrD,SAAS,CAAC,IAAI,CAAC,oCAAoC,EAAE,MAAM,EAAE,UAAU,CAAC,CACzE,CAAC;IAEF,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CACR,2BAAc,CAAC,YAAY,CAAC;YAC1B,OAAO,EAAE,kFAAkF,sBAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SACxH,CAAC,CACH,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC;QAE/B,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,IAAI,CACzB,2CAA2C,EAC3C,MAAM,EACN,EAAE,CACH,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,iCAAiC,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,yBAAW,EAAE,CAAC;YACjC,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,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, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceStateParams,\n GetInterfaceStateResult,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, string } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type {\n JsonRpcRequestWithOrigin,\n SnapInterfaceControllerGetInterfaceStateAction,\n} from '../types';\nimport { UI_PERMISSIONS } from '../utils';\n\nexport type GetInterfaceStateMethodActions =\n | PermissionControllerHasPermissionAction\n | SnapInterfaceControllerGetInterfaceStateAction;\n\n/**\n * Get the form state of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)\n * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).\n *\n * @example\n * ```ts\n * const state = await snap.request({\n * method: 'snap_getInterfaceState',\n * params: {\n * id: interfaceId,\n * },\n * });\n * ```\n */\nexport const getInterfaceStateHandler = {\n implementation: getGetInterfaceStateImplementation,\n actionNames: [\n 'PermissionController:hasPermission',\n 'SnapInterfaceController:getInterfaceState',\n ],\n} satisfies MethodHandler<\n never,\n GetInterfaceStateMethodActions,\n GetInterfaceStateParameters,\n GetInterfaceStateResult,\n { origin: string }\n>;\n\nconst GetInterfaceStateParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceStateParameters = InferMatching<\n typeof GetInterfaceStateParametersStruct,\n GetInterfaceStateParams\n>;\n\n/**\n * The `snap_getInterfaceState` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param _hooks - The RPC method hooks. Not used by this function.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nfunction getGetInterfaceStateImplementation(\n req: JsonRpcRequestWithOrigin<GetInterfaceStateParameters>,\n res: PendingJsonRpcResponse<GetInterfaceStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n _hooks: never,\n messenger: Messenger<string, GetInterfaceStateMethodActions>,\n): void {\n const { params, origin } = req;\n\n const isPermitted = UI_PERMISSIONS.some((permission) =>\n messenger.call('PermissionController:hasPermission', origin, permission),\n );\n\n if (!isPermitted) {\n return end(\n providerErrors.unauthorized({\n message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,\n }),\n );\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n res.result = messenger.call(\n 'SnapInterfaceController:getInterfaceState',\n origin,\n id,\n );\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceState 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 getInterfaceState method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceStateParameters {\n try {\n return create(params, GetInterfaceStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
@@ -1,20 +1,11 @@
1
1
  import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
2
- import type { GetInterfaceStateParams, GetInterfaceStateResult, InterfaceState, JsonRpcRequest } from "@metamask/snaps-sdk";
2
+ import type { Messenger } from "@metamask/messenger";
3
+ import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller";
4
+ import type { GetInterfaceStateParams, GetInterfaceStateResult } from "@metamask/snaps-sdk";
3
5
  import { type InferMatching } from "@metamask/snaps-utils";
4
6
  import type { PendingJsonRpcResponse } from "@metamask/utils";
5
- import type { MethodHooksObject } from "../utils.cjs";
6
- export type GetInterfaceStateMethodHooks = {
7
- /**
8
- * @param permissionName - The name of the permission to check.
9
- * @returns Whether the Snap has the permission.
10
- */
11
- hasPermission: (permissionName: string) => boolean;
12
- /**
13
- * @param id - The interface ID.
14
- * @returns The interface state.
15
- */
16
- getInterfaceState: (id: string) => InterfaceState;
17
- };
7
+ import type { JsonRpcRequestWithOrigin, SnapInterfaceControllerGetInterfaceStateAction } from "../types.cjs";
8
+ export type GetInterfaceStateMethodActions = PermissionControllerHasPermissionAction | SnapInterfaceControllerGetInterfaceStateAction;
18
9
  /**
19
10
  * Get the form state of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
20
11
  * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
@@ -30,9 +21,8 @@ export type GetInterfaceStateMethodHooks = {
30
21
  * ```
31
22
  */
32
23
  export declare const getInterfaceStateHandler: {
33
- methodNames: ["snap_getInterfaceState"];
34
24
  implementation: typeof getGetInterfaceStateImplementation;
35
- hookNames: MethodHooksObject<GetInterfaceStateMethodHooks>;
25
+ actionNames: ("SnapInterfaceController:getInterfaceState" | "PermissionController:hasPermission")[];
36
26
  };
37
27
  declare const GetInterfaceStateParametersStruct: import("@metamask/superstruct").Struct<{
38
28
  id: string;
@@ -48,12 +38,10 @@ export type GetInterfaceStateParameters = InferMatching<typeof GetInterfaceState
48
38
  * @param _next - The `json-rpc-engine` "next" callback. Not used by this
49
39
  * function.
50
40
  * @param end - The `json-rpc-engine` "end" callback.
51
- * @param hooks - The RPC method hooks.
52
- * @param hooks.hasPermission - The function to check if the Snap has a given
53
- * permission.
54
- * @param hooks.getInterfaceState - The function to get the interface state.
41
+ * @param _hooks - The RPC method hooks. Not used by this function.
42
+ * @param messenger - The messenger used to call controller actions.
55
43
  * @returns Nothing.
56
44
  */
57
- declare function getGetInterfaceStateImplementation(req: JsonRpcRequest<GetInterfaceStateParameters>, res: PendingJsonRpcResponse<GetInterfaceStateResult>, _next: unknown, end: JsonRpcEngineEndCallback, { hasPermission, getInterfaceState }: GetInterfaceStateMethodHooks): void;
45
+ declare function getGetInterfaceStateImplementation(req: JsonRpcRequestWithOrigin<GetInterfaceStateParameters>, res: PendingJsonRpcResponse<GetInterfaceStateResult>, _next: unknown, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, GetInterfaceStateMethodActions>): void;
58
46
  export {};
59
47
  //# sourceMappingURL=getInterfaceState.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getInterfaceState.d.cts","sourceRoot":"","sources":["../../src/permitted/getInterfaceState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,kCAAkC;AAG1E,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACvB,cAAc,EACd,cAAc,EACf,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAUlD,MAAM,MAAM,4BAA4B,GAAG;IACzC;;;OAGG;IACH,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD;;;OAGG;IACH,iBAAiB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,cAAc,CAAC;CACnD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,wBAAwB;;;;CAQpC,CAAC;AAEF,QAAA,MAAM,iCAAiC;;;;EAErC,CAAC;AAEH,MAAM,MAAM,2BAA2B,GAAG,aAAa,CACrD,OAAO,iCAAiC,EACxC,uBAAuB,CACxB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,iBAAS,kCAAkC,CACzC,GAAG,EAAE,cAAc,CAAC,2BAA2B,CAAC,EAChD,GAAG,EAAE,sBAAsB,CAAC,uBAAuB,CAAC,EACpD,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,EAAE,aAAa,EAAE,iBAAiB,EAAE,EAAE,4BAA4B,GACjE,IAAI,CAsBN"}
1
+ {"version":3,"file":"getInterfaceState.d.cts","sourceRoot":"","sources":["../../src/permitted/getInterfaceState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,uCAAuC,EAAE,wCAAwC;AAE/F,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAE9D,OAAO,KAAK,EACV,wBAAwB,EACxB,8CAA8C,EAC/C,qBAAiB;AAGlB,MAAM,MAAM,8BAA8B,GACtC,uCAAuC,GACvC,8CAA8C,CAAC;AAEnD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,wBAAwB;;;CAYpC,CAAC;AAEF,QAAA,MAAM,iCAAiC;;;;EAErC,CAAC;AAEH,MAAM,MAAM,2BAA2B,GAAG,aAAa,CACrD,OAAO,iCAAiC,EACxC,uBAAuB,CACxB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,iBAAS,kCAAkC,CACzC,GAAG,EAAE,wBAAwB,CAAC,2BAA2B,CAAC,EAC1D,GAAG,EAAE,sBAAsB,CAAC,uBAAuB,CAAC,EACpD,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,8BAA8B,CAAC,GAC3D,IAAI,CA8BN"}
@@ -1,20 +1,11 @@
1
1
  import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
2
- import type { GetInterfaceStateParams, GetInterfaceStateResult, InterfaceState, JsonRpcRequest } from "@metamask/snaps-sdk";
2
+ import type { Messenger } from "@metamask/messenger";
3
+ import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller";
4
+ import type { GetInterfaceStateParams, GetInterfaceStateResult } from "@metamask/snaps-sdk";
3
5
  import { type InferMatching } from "@metamask/snaps-utils";
4
6
  import type { PendingJsonRpcResponse } from "@metamask/utils";
5
- import type { MethodHooksObject } from "../utils.mjs";
6
- export type GetInterfaceStateMethodHooks = {
7
- /**
8
- * @param permissionName - The name of the permission to check.
9
- * @returns Whether the Snap has the permission.
10
- */
11
- hasPermission: (permissionName: string) => boolean;
12
- /**
13
- * @param id - The interface ID.
14
- * @returns The interface state.
15
- */
16
- getInterfaceState: (id: string) => InterfaceState;
17
- };
7
+ import type { JsonRpcRequestWithOrigin, SnapInterfaceControllerGetInterfaceStateAction } from "../types.mjs";
8
+ export type GetInterfaceStateMethodActions = PermissionControllerHasPermissionAction | SnapInterfaceControllerGetInterfaceStateAction;
18
9
  /**
19
10
  * Get the form state of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
20
11
  * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
@@ -30,9 +21,8 @@ export type GetInterfaceStateMethodHooks = {
30
21
  * ```
31
22
  */
32
23
  export declare const getInterfaceStateHandler: {
33
- methodNames: ["snap_getInterfaceState"];
34
24
  implementation: typeof getGetInterfaceStateImplementation;
35
- hookNames: MethodHooksObject<GetInterfaceStateMethodHooks>;
25
+ actionNames: ("SnapInterfaceController:getInterfaceState" | "PermissionController:hasPermission")[];
36
26
  };
37
27
  declare const GetInterfaceStateParametersStruct: import("@metamask/superstruct").Struct<{
38
28
  id: string;
@@ -48,12 +38,10 @@ export type GetInterfaceStateParameters = InferMatching<typeof GetInterfaceState
48
38
  * @param _next - The `json-rpc-engine` "next" callback. Not used by this
49
39
  * function.
50
40
  * @param end - The `json-rpc-engine` "end" callback.
51
- * @param hooks - The RPC method hooks.
52
- * @param hooks.hasPermission - The function to check if the Snap has a given
53
- * permission.
54
- * @param hooks.getInterfaceState - The function to get the interface state.
41
+ * @param _hooks - The RPC method hooks. Not used by this function.
42
+ * @param messenger - The messenger used to call controller actions.
55
43
  * @returns Nothing.
56
44
  */
57
- declare function getGetInterfaceStateImplementation(req: JsonRpcRequest<GetInterfaceStateParameters>, res: PendingJsonRpcResponse<GetInterfaceStateResult>, _next: unknown, end: JsonRpcEngineEndCallback, { hasPermission, getInterfaceState }: GetInterfaceStateMethodHooks): void;
45
+ declare function getGetInterfaceStateImplementation(req: JsonRpcRequestWithOrigin<GetInterfaceStateParameters>, res: PendingJsonRpcResponse<GetInterfaceStateResult>, _next: unknown, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, GetInterfaceStateMethodActions>): void;
58
46
  export {};
59
47
  //# sourceMappingURL=getInterfaceState.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getInterfaceState.d.mts","sourceRoot":"","sources":["../../src/permitted/getInterfaceState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,kCAAkC;AAG1E,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACvB,cAAc,EACd,cAAc,EACf,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAUlD,MAAM,MAAM,4BAA4B,GAAG;IACzC;;;OAGG;IACH,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD;;;OAGG;IACH,iBAAiB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,cAAc,CAAC;CACnD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,wBAAwB;;;;CAQpC,CAAC;AAEF,QAAA,MAAM,iCAAiC;;;;EAErC,CAAC;AAEH,MAAM,MAAM,2BAA2B,GAAG,aAAa,CACrD,OAAO,iCAAiC,EACxC,uBAAuB,CACxB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,iBAAS,kCAAkC,CACzC,GAAG,EAAE,cAAc,CAAC,2BAA2B,CAAC,EAChD,GAAG,EAAE,sBAAsB,CAAC,uBAAuB,CAAC,EACpD,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,EAAE,aAAa,EAAE,iBAAiB,EAAE,EAAE,4BAA4B,GACjE,IAAI,CAsBN"}
1
+ {"version":3,"file":"getInterfaceState.d.mts","sourceRoot":"","sources":["../../src/permitted/getInterfaceState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,uCAAuC,EAAE,wCAAwC;AAE/F,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAE9D,OAAO,KAAK,EACV,wBAAwB,EACxB,8CAA8C,EAC/C,qBAAiB;AAGlB,MAAM,MAAM,8BAA8B,GACtC,uCAAuC,GACvC,8CAA8C,CAAC;AAEnD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,wBAAwB;;;CAYpC,CAAC;AAEF,QAAA,MAAM,iCAAiC;;;;EAErC,CAAC;AAEH,MAAM,MAAM,2BAA2B,GAAG,aAAa,CACrD,OAAO,iCAAiC,EACxC,uBAAuB,CACxB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,iBAAS,kCAAkC,CACzC,GAAG,EAAE,wBAAwB,CAAC,2BAA2B,CAAC,EAC1D,GAAG,EAAE,sBAAsB,CAAC,uBAAuB,CAAC,EACpD,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,8BAA8B,CAAC,GAC3D,IAAI,CA8BN"}
@@ -1,11 +1,6 @@
1
1
  import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
2
2
  import { StructError, create, object, string } from "@metamask/superstruct";
3
3
  import { UI_PERMISSIONS } from "../utils.mjs";
4
- const methodName = 'snap_getInterfaceState';
5
- const hookNames = {
6
- hasPermission: true,
7
- getInterfaceState: true,
8
- };
9
4
  /**
10
5
  * Get the form state of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
11
6
  * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
@@ -21,9 +16,11 @@ const hookNames = {
21
16
  * ```
22
17
  */
23
18
  export const getInterfaceStateHandler = {
24
- methodNames: [methodName],
25
19
  implementation: getGetInterfaceStateImplementation,
26
- hookNames,
20
+ actionNames: [
21
+ 'PermissionController:hasPermission',
22
+ 'SnapInterfaceController:getInterfaceState',
23
+ ],
27
24
  };
28
25
  const GetInterfaceStateParametersStruct = object({
29
26
  id: string(),
@@ -36,23 +33,22 @@ const GetInterfaceStateParametersStruct = object({
36
33
  * @param _next - The `json-rpc-engine` "next" callback. Not used by this
37
34
  * function.
38
35
  * @param end - The `json-rpc-engine` "end" callback.
39
- * @param hooks - The RPC method hooks.
40
- * @param hooks.hasPermission - The function to check if the Snap has a given
41
- * permission.
42
- * @param hooks.getInterfaceState - The function to get the interface state.
36
+ * @param _hooks - The RPC method hooks. Not used by this function.
37
+ * @param messenger - The messenger used to call controller actions.
43
38
  * @returns Nothing.
44
39
  */
45
- function getGetInterfaceStateImplementation(req, res, _next, end, { hasPermission, getInterfaceState }) {
46
- if (!UI_PERMISSIONS.some(hasPermission)) {
40
+ function getGetInterfaceStateImplementation(req, res, _next, end, _hooks, messenger) {
41
+ const { params, origin } = req;
42
+ const isPermitted = UI_PERMISSIONS.some((permission) => messenger.call('PermissionController:hasPermission', origin, permission));
43
+ if (!isPermitted) {
47
44
  return end(providerErrors.unauthorized({
48
45
  message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,
49
46
  }));
50
47
  }
51
- const { params } = req;
52
48
  try {
53
49
  const validatedParams = getValidatedParams(params);
54
50
  const { id } = validatedParams;
55
- res.result = getInterfaceState(id);
51
+ res.result = messenger.call('SnapInterfaceController:getInterfaceState', origin, id);
56
52
  }
57
53
  catch (error) {
58
54
  return end(error);
@@ -1 +1 @@
1
- {"version":3,"file":"getInterfaceState.mjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceState.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAQjE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AAI5E,OAAO,EAAE,cAAc,EAAE,qBAAiB;AAE1C,MAAM,UAAU,GAAG,wBAAwB,CAAC;AAE5C,MAAM,SAAS,GAAoD;IACjE,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,IAAI;CACxB,CAAC;AAgBF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,WAAW,EAAE,CAAC,UAAU,CAAU;IAClC,cAAc,EAAE,kCAAkC;IAClD,SAAS;CAKV,CAAC;AAEF,MAAM,iCAAiC,GAAG,MAAM,CAAC;IAC/C,EAAE,EAAE,MAAM,EAAE;CACb,CAAC,CAAC;AAOH;;;;;;;;;;;;;GAaG;AACH,SAAS,kCAAkC,CACzC,GAAgD,EAChD,GAAoD,EACpD,KAAc,EACd,GAA6B,EAC7B,EAAE,aAAa,EAAE,iBAAiB,EAAgC;IAElE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;QACxC,OAAO,GAAG,CACR,cAAc,CAAC,YAAY,CAAC;YAC1B,OAAO,EAAE,kFAAkF,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SACxH,CAAC,CACH,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC;QAE/B,GAAG,CAAC,MAAM,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,iCAAiC,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceStateParams,\n GetInterfaceStateResult,\n InterfaceState,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, string } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { UI_PERMISSIONS } from '../utils';\n\nconst methodName = 'snap_getInterfaceState';\n\nconst hookNames: MethodHooksObject<GetInterfaceStateMethodHooks> = {\n hasPermission: true,\n getInterfaceState: true,\n};\n\nexport type GetInterfaceStateMethodHooks = {\n /**\n * @param permissionName - The name of the permission to check.\n * @returns Whether the Snap has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * @param id - The interface ID.\n * @returns The interface state.\n */\n getInterfaceState: (id: string) => InterfaceState;\n};\n\n/**\n * Get the form state of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)\n * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).\n *\n * @example\n * ```ts\n * const state = await snap.request({\n * method: 'snap_getInterfaceState',\n * params: {\n * id: interfaceId,\n * },\n * });\n * ```\n */\nexport const getInterfaceStateHandler = {\n methodNames: [methodName] as const,\n implementation: getGetInterfaceStateImplementation,\n hookNames,\n} satisfies PermittedHandlerExport<\n GetInterfaceStateMethodHooks,\n GetInterfaceStateParameters,\n GetInterfaceStateResult\n>;\n\nconst GetInterfaceStateParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceStateParameters = InferMatching<\n typeof GetInterfaceStateParametersStruct,\n GetInterfaceStateParams\n>;\n\n/**\n * The `snap_getInterfaceState` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - The function to check if the Snap has a given\n * permission.\n * @param hooks.getInterfaceState - The function to get the interface state.\n * @returns Nothing.\n */\nfunction getGetInterfaceStateImplementation(\n req: JsonRpcRequest<GetInterfaceStateParameters>,\n res: PendingJsonRpcResponse<GetInterfaceStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { hasPermission, getInterfaceState }: GetInterfaceStateMethodHooks,\n): void {\n if (!UI_PERMISSIONS.some(hasPermission)) {\n return end(\n providerErrors.unauthorized({\n message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,\n }),\n );\n }\n\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n res.result = getInterfaceState(id);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceState 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 getInterfaceState method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceStateParameters {\n try {\n return create(params, GetInterfaceStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
1
+ {"version":3,"file":"getInterfaceState.mjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceState.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAMjE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AAO5E,OAAO,EAAE,cAAc,EAAE,qBAAiB;AAM1C;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,cAAc,EAAE,kCAAkC;IAClD,WAAW,EAAE;QACX,oCAAoC;QACpC,2CAA2C;KAC5C;CAOF,CAAC;AAEF,MAAM,iCAAiC,GAAG,MAAM,CAAC;IAC/C,EAAE,EAAE,MAAM,EAAE;CACb,CAAC,CAAC;AAOH;;;;;;;;;;;GAWG;AACH,SAAS,kCAAkC,CACzC,GAA0D,EAC1D,GAAoD,EACpD,KAAc,EACd,GAA6B,EAC7B,MAAa,EACb,SAA4D;IAE5D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAE/B,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CACrD,SAAS,CAAC,IAAI,CAAC,oCAAoC,EAAE,MAAM,EAAE,UAAU,CAAC,CACzE,CAAC;IAEF,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CACR,cAAc,CAAC,YAAY,CAAC;YAC1B,OAAO,EAAE,kFAAkF,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SACxH,CAAC,CACH,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC;QAE/B,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,IAAI,CACzB,2CAA2C,EAC3C,MAAM,EACN,EAAE,CACH,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,iCAAiC,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,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, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceStateParams,\n GetInterfaceStateResult,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, string } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type {\n JsonRpcRequestWithOrigin,\n SnapInterfaceControllerGetInterfaceStateAction,\n} from '../types';\nimport { UI_PERMISSIONS } from '../utils';\n\nexport type GetInterfaceStateMethodActions =\n | PermissionControllerHasPermissionAction\n | SnapInterfaceControllerGetInterfaceStateAction;\n\n/**\n * Get the form state of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)\n * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).\n *\n * @example\n * ```ts\n * const state = await snap.request({\n * method: 'snap_getInterfaceState',\n * params: {\n * id: interfaceId,\n * },\n * });\n * ```\n */\nexport const getInterfaceStateHandler = {\n implementation: getGetInterfaceStateImplementation,\n actionNames: [\n 'PermissionController:hasPermission',\n 'SnapInterfaceController:getInterfaceState',\n ],\n} satisfies MethodHandler<\n never,\n GetInterfaceStateMethodActions,\n GetInterfaceStateParameters,\n GetInterfaceStateResult,\n { origin: string }\n>;\n\nconst GetInterfaceStateParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceStateParameters = InferMatching<\n typeof GetInterfaceStateParametersStruct,\n GetInterfaceStateParams\n>;\n\n/**\n * The `snap_getInterfaceState` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param _hooks - The RPC method hooks. Not used by this function.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nfunction getGetInterfaceStateImplementation(\n req: JsonRpcRequestWithOrigin<GetInterfaceStateParameters>,\n res: PendingJsonRpcResponse<GetInterfaceStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n _hooks: never,\n messenger: Messenger<string, GetInterfaceStateMethodActions>,\n): void {\n const { params, origin } = req;\n\n const isPermitted = UI_PERMISSIONS.some((permission) =>\n messenger.call('PermissionController:hasPermission', origin, permission),\n );\n\n if (!isPermitted) {\n return end(\n providerErrors.unauthorized({\n message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,\n }),\n );\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n res.result = messenger.call(\n 'SnapInterfaceController:getInterfaceState',\n origin,\n id,\n );\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceState 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 getInterfaceState method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceStateParameters {\n try {\n return create(params, GetInterfaceStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSnapsHandler = void 0;
4
- const methodName = 'wallet_getSnaps';
5
- const hookNames = {
6
- getSnaps: true,
7
- };
8
4
  /**
9
5
  * Get permitted and installed Snaps for the requesting origin.
10
6
  *
@@ -27,26 +23,24 @@ const hookNames = {
27
23
  * ```
28
24
  */
29
25
  exports.getSnapsHandler = {
30
- methodNames: [methodName],
31
26
  implementation: getSnapsImplementation,
32
- hookNames,
27
+ actionNames: ['SnapController:getPermittedSnaps'],
33
28
  };
34
29
  /**
35
30
  * The `wallet_getSnaps` method implementation.
36
31
  * Fetches available snaps for the requesting origin and adds them to the JSON-RPC response.
37
32
  *
38
- * @param _req - The JSON-RPC request object. Not used by this function.
33
+ * @param req - The JSON-RPC request object.
39
34
  * @param res - The JSON-RPC response object.
40
35
  * @param _next - The `json-rpc-engine` "next" callback. Not used by this
41
36
  * function.
42
37
  * @param end - The `json-rpc-engine` "end" callback.
43
- * @param hooks - The RPC method hooks.
44
- * @param hooks.getSnaps - A function that returns the snaps available for the requesting origin.
38
+ * @param _hooks - The RPC method hooks. Not used by this function.
39
+ * @param messenger - The messenger used to call controller actions.
45
40
  * @returns Nothing.
46
41
  */
47
- async function getSnapsImplementation(_req, res, _next, end, { getSnaps }) {
48
- // getSnaps is already bound to the origin
49
- res.result = await getSnaps();
42
+ async function getSnapsImplementation(req, res, _next, end, _hooks, messenger) {
43
+ res.result = messenger.call('SnapController:getPermittedSnaps', req.origin);
50
44
  return end();
51
45
  }
52
46
  //# sourceMappingURL=getSnaps.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getSnaps.cjs","sourceRoot":"","sources":["../../src/permitted/getSnaps.ts"],"names":[],"mappings":";;;AAOA,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAErC,MAAM,SAAS,GAAqC;IAClD,QAAQ,EAAE,IAAI;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,eAAe,GAAG;IAC7B,WAAW,EAAE,CAAC,UAAU,CAAU;IAClC,cAAc,EAAE,sBAAsB;IACtC,SAAS;CAKV,CAAC;AASF;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,sBAAsB,CACnC,IAAa,EACb,GAA2C,EAC3C,KAAc,EACd,GAA6B,EAC7B,EAAE,QAAQ,EAAiB;IAE3B,0CAA0C;IAC1C,GAAG,CAAC,MAAM,GAAG,MAAM,QAAQ,EAAE,CAAC;IAC9B,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport type { GetSnapsResult } from '@metamask/snaps-sdk';\nimport type { JsonRpcParams, PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst methodName = 'wallet_getSnaps';\n\nconst hookNames: MethodHooksObject<GetSnapsHooks> = {\n getSnaps: true,\n};\n\n/**\n * Get permitted and installed Snaps for the requesting origin.\n *\n * @example\n * ```ts\n * const snaps = await snap.request({\n * method: 'wallet_getSnaps',\n * });\n * console.log(snaps);\n * // {\n * // 'npm:example-snap': {\n * // id: 'npm:example-snap',\n * // version: '1.0.0',\n * // initialPermissions: { ... },\n * // blocked: false,\n * // enabled: true,\n * // },\n * // ...,\n * // }\n * ```\n */\nexport const getSnapsHandler = {\n methodNames: [methodName] as const,\n implementation: getSnapsImplementation,\n hookNames,\n} satisfies PermittedHandlerExport<\n GetSnapsHooks,\n JsonRpcParams,\n GetSnapsResult\n>;\n\nexport type GetSnapsHooks = {\n /**\n * @returns The permitted and installed snaps for the requesting origin.\n */\n getSnaps: () => Promise<GetSnapsResult>;\n};\n\n/**\n * The `wallet_getSnaps` method implementation.\n * Fetches available snaps for the requesting origin and adds them to the JSON-RPC response.\n *\n * @param _req - The JSON-RPC request object. Not used by this function.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getSnaps - A function that returns the snaps available for the requesting origin.\n * @returns Nothing.\n */\nasync function getSnapsImplementation(\n _req: unknown,\n res: PendingJsonRpcResponse<GetSnapsResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getSnaps }: GetSnapsHooks,\n): Promise<void> {\n // getSnaps is already bound to the origin\n res.result = await getSnaps();\n return end();\n}\n"]}
1
+ {"version":3,"file":"getSnaps.cjs","sourceRoot":"","sources":["../../src/permitted/getSnaps.ts"],"names":[],"mappings":";;;AAgBA;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,eAAe,GAAG;IAC7B,cAAc,EAAE,sBAAsB;IACtC,WAAW,EAAE,CAAC,kCAAkC,CAAC;CAOlD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,sBAAsB,CACnC,GAAwC,EACxC,GAA2C,EAC3C,KAAc,EACd,GAA6B,EAC7B,MAAa,EACb,SAAmD;IAEnD,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,kCAAkC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5E,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 { GetSnapsResult } from '@metamask/snaps-sdk';\nimport type {\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type { SnapControllerGetPermittedSnapsAction } from '../types';\n\nexport type GetSnapsMethodActions = SnapControllerGetPermittedSnapsAction;\n\n/**\n * Get permitted and installed Snaps for the requesting origin.\n *\n * @example\n * ```ts\n * const snaps = await snap.request({\n * method: 'wallet_getSnaps',\n * });\n * console.log(snaps);\n * // {\n * // 'npm:example-snap': {\n * // id: 'npm:example-snap',\n * // version: '1.0.0',\n * // initialPermissions: { ... },\n * // blocked: false,\n * // enabled: true,\n * // },\n * // ...,\n * // }\n * ```\n */\nexport const getSnapsHandler = {\n implementation: getSnapsImplementation,\n actionNames: ['SnapController:getPermittedSnaps'],\n} satisfies MethodHandler<\n never,\n GetSnapsMethodActions,\n JsonRpcParams,\n GetSnapsResult,\n { origin: string }\n>;\n\n/**\n * The `wallet_getSnaps` method implementation.\n * Fetches available snaps for the requesting origin and adds them to the JSON-RPC response.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param _hooks - The RPC method hooks. Not used by this function.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nasync function getSnapsImplementation(\n req: JsonRpcRequest & { origin: string },\n res: PendingJsonRpcResponse<GetSnapsResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n _hooks: never,\n messenger: Messenger<string, GetSnapsMethodActions>,\n): Promise<void> {\n res.result = messenger.call('SnapController:getPermittedSnaps', req.origin);\n return end();\n}\n"]}