@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
@@ -24,25 +24,18 @@ const PlaceholderStruct = (0, superstruct_1.optional)((0, superstruct_1.size)((0
24
24
  * @param options - The specification builder options.
25
25
  * @param options.allowedCaveats - The optional allowed caveats for the
26
26
  * permission.
27
- * @param options.methodHooks - The RPC method hooks needed by the method
28
- * implementation.
27
+ * @param options.messenger - The messenger.
29
28
  * @returns The specification for the `snap_dialog` permission.
30
29
  */
31
- const specificationBuilder = ({ allowedCaveats = null, methodHooks, }) => {
30
+ const specificationBuilder = ({ allowedCaveats = null, messenger, }) => {
32
31
  return {
33
32
  permissionType: permission_controller_1.PermissionType.RestrictedMethod,
34
33
  targetName: methodName,
35
34
  allowedCaveats,
36
- methodImplementation: getDialogImplementation(methodHooks),
35
+ methodImplementation: getDialogImplementation({ messenger }),
37
36
  subjectTypes: [permission_controller_1.SubjectType.Snap],
38
37
  };
39
38
  };
40
- const methodHooks = {
41
- requestUserApproval: true,
42
- createInterface: true,
43
- getInterface: true,
44
- setInterfaceDisplayed: true,
45
- };
46
39
  /* eslint-disable jsdoc/check-indentation */
47
40
  /**
48
41
  * Display a [dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/)
@@ -88,7 +81,12 @@ const methodHooks = {
88
81
  exports.dialogBuilder = Object.freeze({
89
82
  targetName: methodName,
90
83
  specificationBuilder,
91
- methodHooks,
84
+ actionNames: [
85
+ 'ApprovalController:addRequest',
86
+ 'SnapInterfaceController:createInterface',
87
+ 'SnapInterfaceController:getInterface',
88
+ 'SnapInterfaceController:setInterfaceDisplayed',
89
+ ],
92
90
  });
93
91
  /* eslint-enable jsdoc/check-indentation */
94
92
  const AlertParametersWithContentStruct = (0, superstruct_1.object)({
@@ -166,17 +164,12 @@ const DialogParametersStruct = (0, snaps_sdk_1.selectiveUnion)((value) => {
166
164
  /**
167
165
  * Builds the method implementation for `snap_dialog`.
168
166
  *
169
- * @param hooks - The RPC method hooks.
170
- * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.
171
- * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.
172
- * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
173
- * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.
174
- * @param hooks.setInterfaceDisplayed - A function that sets the interface as
175
- * displayed in SnapInterfaceController.
167
+ * @param options - The options.
168
+ * @param options.messenger - The messenger.
176
169
  * @returns The method implementation which return value depends on the dialog
177
170
  * type, valid return types are: string, boolean, null.
178
171
  */
179
- function getDialogImplementation({ requestUserApproval, createInterface, getInterface, setInterfaceDisplayed, }) {
172
+ function getDialogImplementation({ messenger, }) {
180
173
  return async function dialogImplementation(args) {
181
174
  const { params, context: { origin }, } = args;
182
175
  if (!(0, utils_1.isObject)(params)) {
@@ -193,25 +186,25 @@ function getDialogImplementation({ requestUserApproval, createInterface, getInte
193
186
  : 'default';
194
187
  const approvalType = exports.DIALOG_APPROVAL_TYPES[validatedType];
195
188
  if ((0, utils_1.hasProperty)(validatedParams, 'content')) {
196
- const id = await createInterface(origin, validatedParams.content);
197
- setInterfaceDisplayed(origin, id);
198
- return requestUserApproval({
189
+ const id = messenger.call('SnapInterfaceController:createInterface', origin, validatedParams.content);
190
+ messenger.call('SnapInterfaceController:setInterfaceDisplayed', origin, id);
191
+ return messenger.call('ApprovalController:addRequest', {
199
192
  id: approvalType === exports.DIALOG_APPROVAL_TYPES.default ? id : undefined,
200
193
  origin,
201
194
  type: approvalType,
202
195
  requestData: { id, placeholder },
203
- });
196
+ }, true);
204
197
  }
205
- validateInterface(origin, validatedParams.id, getInterface);
206
- setInterfaceDisplayed(origin, validatedParams.id);
207
- return requestUserApproval({
198
+ validateInterface(origin, validatedParams.id, messenger);
199
+ messenger.call('SnapInterfaceController:setInterfaceDisplayed', origin, validatedParams.id);
200
+ return messenger.call('ApprovalController:addRequest', {
208
201
  id: approvalType === exports.DIALOG_APPROVAL_TYPES.default
209
202
  ? validatedParams.id
210
203
  : undefined,
211
204
  origin,
212
205
  type: approvalType,
213
206
  requestData: { id: validatedParams.id, placeholder },
214
- });
207
+ }, true);
215
208
  };
216
209
  }
217
210
  exports.getDialogImplementation = getDialogImplementation;
@@ -220,11 +213,11 @@ exports.getDialogImplementation = getDialogImplementation;
220
213
  *
221
214
  * @param origin - The origin of the request.
222
215
  * @param id - The interface ID.
223
- * @param getInterface - The function to get the interface.
216
+ * @param messenger - The messenger.
224
217
  */
225
- function validateInterface(origin, id, getInterface) {
218
+ function validateInterface(origin, id, messenger) {
226
219
  try {
227
- getInterface(origin, id);
220
+ messenger.call('SnapInterfaceController:getInterface', origin, id);
228
221
  }
229
222
  catch (error) {
230
223
  throw rpc_errors_1.rpcErrors.invalidParams({
@@ -1 +1 @@
1
- {"version":3,"file":"dialog.cjs","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":";;;AAKA,2EAA8E;AAC9E,qDAAiD;AACjD,mDAK6B;AAc7B,uDAA+E;AAE/E,2CAAuE;AAIvE,MAAM,UAAU,GAAG,aAAa,CAAC;AAMpB,QAAA,qBAAqB,GAAG;IACnC,CAAC,sBAAU,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,QAAQ;IACzC,CAAC,sBAAU,CAAC,YAAY,CAAC,EAAE,GAAG,UAAU,eAAe;IACvD,CAAC,sBAAU,CAAC,MAAM,CAAC,EAAE,GAAG,UAAU,SAAS;IAC3C,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF,MAAM,iBAAiB,GAAG,IAAA,sBAAQ,EAAC,IAAA,kBAAI,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AA0E1D;;;;;;;;;;;;;GAaG;AACH,MAAM,oBAAoB,GAItB,CAAC,EACH,cAAc,GAAG,IAAI,EACrB,WAAW,GACuB,EAAE,EAAE;IACtC,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,gBAAgB;QAC/C,UAAU,EAAE,UAAU;QACtB,cAAc;QACd,oBAAoB,EAAE,uBAAuB,CAAC,WAAW,CAAC;QAC1D,YAAY,EAAE,CAAC,mCAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,WAAW,GAAyC;IACxD,mBAAmB,EAAE,IAAI;IACzB,eAAe,EAAE,IAAI;IACrB,YAAY,EAAE,IAAI;IAClB,qBAAqB,EAAE,IAAI;CAC5B,CAAC;AAEF,4CAA4C;AAC5C;;;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,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,MAAwB;IAC7C,OAAO,IAAA,mBAAW,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAE,MAAM,CAAC,IAAmB,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/E,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,MAAwB;IAC9C,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,sBAAU,CAAC,MAAM,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {\n DialogType,\n enumValue,\n ComponentOrElementStruct,\n selectiveUnion,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n Component,\n InterfaceState,\n SnapId,\n PromptDialog,\n ComponentOrElement,\n InterfaceContext,\n ContentType,\n DialogResult,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { create, object, optional, size, string } from '@metamask/superstruct';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nexport type DialogApprovalTypes = Record<DialogType, string> & {\n default: string;\n};\n\nexport const DIALOG_APPROVAL_TYPES = {\n [DialogType.Alert]: `${methodName}:alert`,\n [DialogType.Confirmation]: `${methodName}:confirmation`,\n [DialogType.Prompt]: `${methodName}:prompt`,\n default: methodName,\n};\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype RequestUserApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData: {\n id: string;\n placeholder?: string;\n };\n};\n\ntype RequestUserApproval = (\n opts: RequestUserApprovalOptions,\n) => Promise<boolean | null | string | Json>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param opts - The `requestUserApproval` options.\n * @param opts.id - The approval ID. If not provided, a new approval ID will be generated.\n * @param opts.origin - The origin of the request. In this case, the Snap ID.\n * @param opts.type - The type of the approval request.\n * @param opts.requestData - The data of the approval request.\n * @param opts.requestData.id - The ID of the interface.\n * @param opts.requestData.placeholder - The placeholder of the `Prompt` dialog.\n */\n requestUserApproval: RequestUserApproval;\n\n /**\n * @param snapId - The Snap ID creating the interface.\n * @param content - The content of the interface.\n */\n createInterface: CreateInterface;\n /**\n * @param snapId - The SnapId requesting the interface.\n * @param id - The interface ID.\n */\n getInterface: GetInterface;\n\n /**\n * Set the interface as displayed.\n *\n * @param snapId - The Snap ID requesting the interface.\n * @param id - The interface ID.\n */\n setInterfaceDisplayed: (snapId: string, id: string) => void;\n};\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: DialogMethodHooks;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<DialogMethodHooks> = {\n requestUserApproval: true,\n createInterface: true,\n getInterface: true,\n setInterfaceDisplayed: true,\n};\n\n/* eslint-disable jsdoc/check-indentation */\n/**\n * Display a [dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/)\n * in the MetaMask UI.\n *\n * - `type` - The type of dialog. Not providing a type will create a fully\n * [custom dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/#display-a-custom-dialog).\n * Possible values are:\n * - `alert` - An alert that can only be acknowledged.\n * - `confirmation` - A confirmation that can be accepted or rejected.\n * - `prompt` - A prompt where the user can enter a text response.\n *\n * - One of:\n * - `content` - The content of the alert, as a\n * [custom UI](https://docs.metamask.io/snaps/features/custom-ui/) component.\n * - `id` - The ID of an\n * [interactive interface](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).\n * - `placeholder` - An optional placeholder text to display in the dialog. Only\n * applicable for the `prompt` dialog.\n *\n * @example\n * ```ts\n * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx';\n *\n * const walletAddress = await snap.request({\n * method: 'snap_dialog',\n * params: {\n * type: 'prompt',\n * content: (\n * <Box>\n * <Heading>What is the wallet address?</Heading>\n * <Text>Please enter the wallet address to be monitored.</Text>\n * </Box>\n * ),\n * placeholder: '0x123...',\n * },\n * });\n *\n * // `walletAddress` will be a string containing the address entered by the\n * // user.\n * ```\n */\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n/* eslint-enable jsdoc/check-indentation */\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\n\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return AlertParametersWithIdStruct;\n }\n return AlertParametersWithContentStruct;\n});\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return ConfirmationParametersWithIdStruct;\n }\n return ConfirmationParametersWithContentStruct;\n});\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return PromptParametersWithIdStruct;\n }\n return PromptParametersWithContentStruct;\n});\n\nconst DefaultParametersWithContentStruct = object({\n content: ComponentOrElementStruct,\n});\n\nconst DefaultParametersWithIdStruct = object({\n id: string(),\n});\n\nconst DefaultParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return DefaultParametersWithIdStruct;\n }\n return DefaultParametersWithContentStruct;\n});\n\nconst DialogParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'type')) {\n switch (value.type) {\n // We cannot use typedUnion here unfortunately.\n case DialogType.Alert:\n return AlertParametersStruct;\n case DialogType.Confirmation:\n return ConfirmationParametersStruct;\n case DialogType.Prompt:\n return PromptParametersStruct;\n default:\n throw new Error(\n `The \"type\" property must be one of: ${Object.values(DialogType).join(\n ', ',\n )}.`,\n );\n }\n }\n return DefaultParametersStruct;\n});\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.\n * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.\n * @param hooks.setInterfaceDisplayed - A function that sets the interface as\n * displayed in SnapInterfaceController.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n requestUserApproval,\n createInterface,\n getInterface,\n setInterfaceDisplayed,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<DialogResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Invalid params: Expected params to be a single object.',\n });\n }\n\n const validatedParams = getValidatedParams(params);\n const placeholder = isPromptDialog(validatedParams)\n ? validatedParams.placeholder\n : undefined;\n\n const validatedType = hasProperty(validatedParams, 'type')\n ? validatedParams.type\n : 'default';\n\n const approvalType =\n DIALOG_APPROVAL_TYPES[\n validatedType as keyof typeof DIALOG_APPROVAL_TYPES\n ];\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n\n setInterfaceDisplayed(origin, id);\n\n return requestUserApproval({\n id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,\n origin,\n type: approvalType,\n requestData: { id, placeholder },\n });\n }\n\n validateInterface(origin, validatedParams.id, getInterface);\n setInterfaceDisplayed(origin, validatedParams.id);\n\n return requestUserApproval({\n id:\n approvalType === DIALOG_APPROVAL_TYPES.default\n ? validatedParams.id\n : undefined,\n origin,\n type: approvalType,\n requestData: { id: validatedParams.id, placeholder },\n });\n };\n}\n/**\n * Validate that the interface ID is valid.\n *\n * @param origin - The origin of the request.\n * @param id - The interface ID.\n * @param getInterface - The function to get the interface.\n */\nfunction validateInterface(\n origin: string,\n id: string,\n getInterface: GetInterface,\n) {\n try {\n getInterface(origin, id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n\n/**\n * Gets the dialog type from the dialog parameters.\n *\n * @param params - The dialog parameters.\n * @returns The dialog type.\n */\nfunction getDialogType(params: DialogParameters): DialogType | undefined {\n return hasProperty(params, 'type') ? (params.type as DialogType) : undefined;\n}\n\n/**\n * Checks if the dialog parameters are for a prompt dialog.\n *\n * @param params - The dialog parameters.\n * @returns `true` if the dialog parameters are for a prompt dialog, `false` otherwise.\n */\nfunction isPromptDialog(params: DialogParameters): params is PromptDialog {\n return getDialogType(params) === DialogType.Prompt;\n}\n\n/**\n * Validates the confirm method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(params: unknown): DialogParameters {\n try {\n return create(params, DialogParametersStruct);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"dialog.cjs","sourceRoot":"","sources":["../../src/restricted/dialog.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C,CAAC,CAAC,CAAE,MAAM,CAAC,IAAmB,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/E,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,MAAwB;IAC9C,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,sBAAU,CAAC,MAAM,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {\n DialogType,\n enumValue,\n ComponentOrElementStruct,\n selectiveUnion,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n Component,\n PromptDialog,\n DialogResult,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { create, object, optional, size, string } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport type {\n ApprovalControllerAddRequestAction,\n SnapInterfaceControllerCreateInterfaceAction,\n SnapInterfaceControllerGetInterfaceAction,\n SnapInterfaceControllerSetInterfaceDisplayedAction,\n} from '../types';\n\nconst methodName = 'snap_dialog';\n\nexport type DialogApprovalTypes = Record<DialogType, string> & {\n default: string;\n};\n\nexport const DIALOG_APPROVAL_TYPES = {\n [DialogType.Alert]: `${methodName}:alert`,\n [DialogType.Confirmation]: `${methodName}:confirmation`,\n [DialogType.Prompt]: `${methodName}:prompt`,\n default: methodName,\n};\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\nexport type DialogMessengerActions =\n | ApprovalControllerAddRequestAction\n | SnapInterfaceControllerCreateInterfaceAction\n | SnapInterfaceControllerGetInterfaceAction\n | SnapInterfaceControllerSetInterfaceDisplayedAction;\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n messenger: Messenger<string, DialogMessengerActions>;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.messenger - The messenger.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n messenger,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation({ messenger }),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\n/* eslint-disable jsdoc/check-indentation */\n/**\n * Display a [dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/)\n * in the MetaMask UI.\n *\n * - `type` - The type of dialog. Not providing a type will create a fully\n * [custom dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/#display-a-custom-dialog).\n * Possible values are:\n * - `alert` - An alert that can only be acknowledged.\n * - `confirmation` - A confirmation that can be accepted or rejected.\n * - `prompt` - A prompt where the user can enter a text response.\n *\n * - One of:\n * - `content` - The content of the alert, as a\n * [custom UI](https://docs.metamask.io/snaps/features/custom-ui/) component.\n * - `id` - The ID of an\n * [interactive interface](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).\n * - `placeholder` - An optional placeholder text to display in the dialog. Only\n * applicable for the `prompt` dialog.\n *\n * @example\n * ```ts\n * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx';\n *\n * const walletAddress = await snap.request({\n * method: 'snap_dialog',\n * params: {\n * type: 'prompt',\n * content: (\n * <Box>\n * <Heading>What is the wallet address?</Heading>\n * <Text>Please enter the wallet address to be monitored.</Text>\n * </Box>\n * ),\n * placeholder: '0x123...',\n * },\n * });\n *\n * // `walletAddress` will be a string containing the address entered by the\n * // user.\n * ```\n */\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n actionNames: [\n 'ApprovalController:addRequest',\n 'SnapInterfaceController:createInterface',\n 'SnapInterfaceController:getInterface',\n 'SnapInterfaceController:setInterfaceDisplayed',\n ],\n} as const);\n/* eslint-enable jsdoc/check-indentation */\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\n\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return AlertParametersWithIdStruct;\n }\n return AlertParametersWithContentStruct;\n});\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return ConfirmationParametersWithIdStruct;\n }\n return ConfirmationParametersWithContentStruct;\n});\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return PromptParametersWithIdStruct;\n }\n return PromptParametersWithContentStruct;\n});\n\nconst DefaultParametersWithContentStruct = object({\n content: ComponentOrElementStruct,\n});\n\nconst DefaultParametersWithIdStruct = object({\n id: string(),\n});\n\nconst DefaultParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return DefaultParametersWithIdStruct;\n }\n return DefaultParametersWithContentStruct;\n});\n\nconst DialogParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'type')) {\n switch (value.type) {\n // We cannot use typedUnion here unfortunately.\n case DialogType.Alert:\n return AlertParametersStruct;\n case DialogType.Confirmation:\n return ConfirmationParametersStruct;\n case DialogType.Prompt:\n return PromptParametersStruct;\n default:\n throw new Error(\n `The \"type\" property must be one of: ${Object.values(DialogType).join(\n ', ',\n )}.`,\n );\n }\n }\n return DefaultParametersStruct;\n});\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param options - The options.\n * @param options.messenger - The messenger.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n messenger,\n}: DialogSpecificationBuilderOptions) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<DialogResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Invalid params: Expected params to be a single object.',\n });\n }\n\n const validatedParams = getValidatedParams(params);\n const placeholder = isPromptDialog(validatedParams)\n ? validatedParams.placeholder\n : undefined;\n\n const validatedType = hasProperty(validatedParams, 'type')\n ? validatedParams.type\n : 'default';\n\n const approvalType =\n DIALOG_APPROVAL_TYPES[\n validatedType as keyof typeof DIALOG_APPROVAL_TYPES\n ];\n\n if (hasProperty(validatedParams, 'content')) {\n const id = messenger.call(\n 'SnapInterfaceController:createInterface',\n origin,\n validatedParams.content as Component,\n );\n\n messenger.call(\n 'SnapInterfaceController:setInterfaceDisplayed',\n origin,\n id,\n );\n\n return messenger.call(\n 'ApprovalController:addRequest',\n {\n id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,\n origin,\n type: approvalType,\n requestData: { id, placeholder },\n },\n true,\n );\n }\n\n validateInterface(origin, validatedParams.id, messenger);\n\n messenger.call(\n 'SnapInterfaceController:setInterfaceDisplayed',\n origin,\n validatedParams.id,\n );\n\n return messenger.call(\n 'ApprovalController:addRequest',\n {\n id:\n approvalType === DIALOG_APPROVAL_TYPES.default\n ? validatedParams.id\n : undefined,\n origin,\n type: approvalType,\n requestData: { id: validatedParams.id, placeholder },\n },\n true,\n );\n };\n}\n/**\n * Validate that the interface ID is valid.\n *\n * @param origin - The origin of the request.\n * @param id - The interface ID.\n * @param messenger - The messenger.\n */\nfunction validateInterface(\n origin: string,\n id: string,\n messenger: Messenger<string, SnapInterfaceControllerGetInterfaceAction>,\n) {\n try {\n messenger.call('SnapInterfaceController:getInterface', origin, id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n\n/**\n * Gets the dialog type from the dialog parameters.\n *\n * @param params - The dialog parameters.\n * @returns The dialog type.\n */\nfunction getDialogType(params: DialogParameters): DialogType | undefined {\n return hasProperty(params, 'type') ? (params.type as DialogType) : undefined;\n}\n\n/**\n * Checks if the dialog parameters are for a prompt dialog.\n *\n * @param params - The dialog parameters.\n * @returns `true` if the dialog parameters are for a prompt dialog, `false` otherwise.\n */\nfunction isPromptDialog(params: DialogParameters): params is PromptDialog {\n return getDialogType(params) === DialogType.Prompt;\n}\n\n/**\n * Validates the confirm method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(params: unknown): DialogParameters {\n try {\n return create(params, DialogParametersStruct);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
@@ -1,11 +1,12 @@
1
+ import type { Messenger } from "@metamask/messenger";
1
2
  import type { PermissionSpecificationBuilder, RestrictedMethodOptions } from "@metamask/permission-controller";
2
3
  import { PermissionType } from "@metamask/permission-controller";
3
4
  import { DialogType } from "@metamask/snaps-sdk";
4
- import type { DialogParams, InterfaceState, SnapId, ComponentOrElement, InterfaceContext, ContentType, DialogResult } from "@metamask/snaps-sdk";
5
+ import type { DialogParams, DialogResult } from "@metamask/snaps-sdk";
5
6
  import type { InferMatching } from "@metamask/snaps-utils";
6
7
  import type { Infer } from "@metamask/superstruct";
7
- import type { Json, NonEmptyArray } from "@metamask/utils";
8
- import { type MethodHooksObject } from "../utils.cjs";
8
+ import type { NonEmptyArray } from "@metamask/utils";
9
+ import type { ApprovalControllerAddRequestAction, SnapInterfaceControllerCreateInterfaceAction, SnapInterfaceControllerGetInterfaceAction, SnapInterfaceControllerSetInterfaceDisplayedAction } from "../types.cjs";
9
10
  declare const methodName = "snap_dialog";
10
11
  export type DialogApprovalTypes = Record<DialogType, string> & {
11
12
  default: string;
@@ -18,54 +19,10 @@ export declare const DIALOG_APPROVAL_TYPES: {
18
19
  };
19
20
  declare const PlaceholderStruct: import("@metamask/superstruct").Struct<string | undefined, null>;
20
21
  export type Placeholder = Infer<typeof PlaceholderStruct>;
21
- type RequestUserApprovalOptions = {
22
- id?: string;
23
- origin: string;
24
- type: string;
25
- requestData: {
26
- id: string;
27
- placeholder?: string;
28
- };
29
- };
30
- type RequestUserApproval = (opts: RequestUserApprovalOptions) => Promise<boolean | null | string | Json>;
31
- type CreateInterface = (snapId: string, content: ComponentOrElement, context?: InterfaceContext, contentType?: ContentType) => Promise<string>;
32
- type GetInterface = (snapId: string, id: string) => {
33
- content: ComponentOrElement;
34
- snapId: SnapId;
35
- state: InterfaceState;
36
- };
37
- export type DialogMethodHooks = {
38
- /**
39
- * @param opts - The `requestUserApproval` options.
40
- * @param opts.id - The approval ID. If not provided, a new approval ID will be generated.
41
- * @param opts.origin - The origin of the request. In this case, the Snap ID.
42
- * @param opts.type - The type of the approval request.
43
- * @param opts.requestData - The data of the approval request.
44
- * @param opts.requestData.id - The ID of the interface.
45
- * @param opts.requestData.placeholder - The placeholder of the `Prompt` dialog.
46
- */
47
- requestUserApproval: RequestUserApproval;
48
- /**
49
- * @param snapId - The Snap ID creating the interface.
50
- * @param content - The content of the interface.
51
- */
52
- createInterface: CreateInterface;
53
- /**
54
- * @param snapId - The SnapId requesting the interface.
55
- * @param id - The interface ID.
56
- */
57
- getInterface: GetInterface;
58
- /**
59
- * Set the interface as displayed.
60
- *
61
- * @param snapId - The Snap ID requesting the interface.
62
- * @param id - The interface ID.
63
- */
64
- setInterfaceDisplayed: (snapId: string, id: string) => void;
65
- };
22
+ export type DialogMessengerActions = ApprovalControllerAddRequestAction | SnapInterfaceControllerCreateInterfaceAction | SnapInterfaceControllerGetInterfaceAction | SnapInterfaceControllerSetInterfaceDisplayedAction;
66
23
  type DialogSpecificationBuilderOptions = {
67
24
  allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
68
- methodHooks: DialogMethodHooks;
25
+ messenger: Messenger<string, DialogMessengerActions>;
69
26
  };
70
27
  /**
71
28
  * Display a [dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/)
@@ -116,7 +73,7 @@ export declare const dialogBuilder: Readonly<{
116
73
  methodImplementation: ReturnType<typeof getDialogImplementation>;
117
74
  allowedCaveats: Readonly<NonEmptyArray<string>> | null;
118
75
  }>;
119
- readonly methodHooks: MethodHooksObject<DialogMethodHooks>;
76
+ readonly actionNames: readonly ["ApprovalController:addRequest", "SnapInterfaceController:createInterface", "SnapInterfaceController:getInterface", "SnapInterfaceController:setInterfaceDisplayed"];
120
77
  }>;
121
78
  declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
122
79
  id: string;
@@ -491,16 +448,11 @@ export type DialogParameters = InferMatching<typeof DialogParametersStruct, Dial
491
448
  /**
492
449
  * Builds the method implementation for `snap_dialog`.
493
450
  *
494
- * @param hooks - The RPC method hooks.
495
- * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.
496
- * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.
497
- * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
498
- * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.
499
- * @param hooks.setInterfaceDisplayed - A function that sets the interface as
500
- * displayed in SnapInterfaceController.
451
+ * @param options - The options.
452
+ * @param options.messenger - The messenger.
501
453
  * @returns The method implementation which return value depends on the dialog
502
454
  * type, valid return types are: string, boolean, null.
503
455
  */
504
- export declare function getDialogImplementation({ requestUserApproval, createInterface, getInterface, setInterfaceDisplayed, }: DialogMethodHooks): (args: RestrictedMethodOptions<DialogParameters>) => Promise<DialogResult>;
456
+ export declare function getDialogImplementation({ messenger, }: DialogSpecificationBuilderOptions): (args: RestrictedMethodOptions<DialogParameters>) => Promise<DialogResult>;
505
457
  export {};
506
458
  //# sourceMappingURL=dialog.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dialog.d.cts","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,EACL,UAAU,EAIX,4BAA4B;AAC7B,OAAO,KAAK,EACV,YAAY,EAEZ,cAAc,EACd,MAAM,EAEN,kBAAkB,EAClB,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AQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC;IACxD,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;CACtD,CAAC;AAwCF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,aAAa;;;wBA9ER,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,8BAA8B,CAAC;wBAChD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;;;EAoF7C,CAAC;AAuEZ,QAAA,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAmB1B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAC1C,OAAO,sBAAsB,EAC7B,YAAY,CACb,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,SAAS,GACV,EAAE,iCAAiC,UAE1B,wBAAwB,gBAAgB,CAAC,KAC9C,QAAQ,YAAY,CAAC,CAyEzB"}
@@ -1,11 +1,12 @@
1
+ import type { Messenger } from "@metamask/messenger";
1
2
  import type { PermissionSpecificationBuilder, RestrictedMethodOptions } from "@metamask/permission-controller";
2
3
  import { PermissionType } from "@metamask/permission-controller";
3
4
  import { DialogType } from "@metamask/snaps-sdk";
4
- import type { DialogParams, InterfaceState, SnapId, ComponentOrElement, InterfaceContext, ContentType, DialogResult } from "@metamask/snaps-sdk";
5
+ import type { DialogParams, DialogResult } from "@metamask/snaps-sdk";
5
6
  import type { InferMatching } from "@metamask/snaps-utils";
6
7
  import type { Infer } from "@metamask/superstruct";
7
- import type { Json, NonEmptyArray } from "@metamask/utils";
8
- import { type MethodHooksObject } from "../utils.mjs";
8
+ import type { NonEmptyArray } from "@metamask/utils";
9
+ import type { ApprovalControllerAddRequestAction, SnapInterfaceControllerCreateInterfaceAction, SnapInterfaceControllerGetInterfaceAction, SnapInterfaceControllerSetInterfaceDisplayedAction } from "../types.mjs";
9
10
  declare const methodName = "snap_dialog";
10
11
  export type DialogApprovalTypes = Record<DialogType, string> & {
11
12
  default: string;
@@ -18,54 +19,10 @@ export declare const DIALOG_APPROVAL_TYPES: {
18
19
  };
19
20
  declare const PlaceholderStruct: import("@metamask/superstruct").Struct<string | undefined, null>;
20
21
  export type Placeholder = Infer<typeof PlaceholderStruct>;
21
- type RequestUserApprovalOptions = {
22
- id?: string;
23
- origin: string;
24
- type: string;
25
- requestData: {
26
- id: string;
27
- placeholder?: string;
28
- };
29
- };
30
- type RequestUserApproval = (opts: RequestUserApprovalOptions) => Promise<boolean | null | string | Json>;
31
- type CreateInterface = (snapId: string, content: ComponentOrElement, context?: InterfaceContext, contentType?: ContentType) => Promise<string>;
32
- type GetInterface = (snapId: string, id: string) => {
33
- content: ComponentOrElement;
34
- snapId: SnapId;
35
- state: InterfaceState;
36
- };
37
- export type DialogMethodHooks = {
38
- /**
39
- * @param opts - The `requestUserApproval` options.
40
- * @param opts.id - The approval ID. If not provided, a new approval ID will be generated.
41
- * @param opts.origin - The origin of the request. In this case, the Snap ID.
42
- * @param opts.type - The type of the approval request.
43
- * @param opts.requestData - The data of the approval request.
44
- * @param opts.requestData.id - The ID of the interface.
45
- * @param opts.requestData.placeholder - The placeholder of the `Prompt` dialog.
46
- */
47
- requestUserApproval: RequestUserApproval;
48
- /**
49
- * @param snapId - The Snap ID creating the interface.
50
- * @param content - The content of the interface.
51
- */
52
- createInterface: CreateInterface;
53
- /**
54
- * @param snapId - The SnapId requesting the interface.
55
- * @param id - The interface ID.
56
- */
57
- getInterface: GetInterface;
58
- /**
59
- * Set the interface as displayed.
60
- *
61
- * @param snapId - The Snap ID requesting the interface.
62
- * @param id - The interface ID.
63
- */
64
- setInterfaceDisplayed: (snapId: string, id: string) => void;
65
- };
22
+ export type DialogMessengerActions = ApprovalControllerAddRequestAction | SnapInterfaceControllerCreateInterfaceAction | SnapInterfaceControllerGetInterfaceAction | SnapInterfaceControllerSetInterfaceDisplayedAction;
66
23
  type DialogSpecificationBuilderOptions = {
67
24
  allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
68
- methodHooks: DialogMethodHooks;
25
+ messenger: Messenger<string, DialogMessengerActions>;
69
26
  };
70
27
  /**
71
28
  * Display a [dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/)
@@ -116,7 +73,7 @@ export declare const dialogBuilder: Readonly<{
116
73
  methodImplementation: ReturnType<typeof getDialogImplementation>;
117
74
  allowedCaveats: Readonly<NonEmptyArray<string>> | null;
118
75
  }>;
119
- readonly methodHooks: MethodHooksObject<DialogMethodHooks>;
76
+ readonly actionNames: readonly ["ApprovalController:addRequest", "SnapInterfaceController:createInterface", "SnapInterfaceController:getInterface", "SnapInterfaceController:setInterfaceDisplayed"];
120
77
  }>;
121
78
  declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
122
79
  id: string;
@@ -491,16 +448,11 @@ export type DialogParameters = InferMatching<typeof DialogParametersStruct, Dial
491
448
  /**
492
449
  * Builds the method implementation for `snap_dialog`.
493
450
  *
494
- * @param hooks - The RPC method hooks.
495
- * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.
496
- * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.
497
- * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
498
- * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.
499
- * @param hooks.setInterfaceDisplayed - A function that sets the interface as
500
- * displayed in SnapInterfaceController.
451
+ * @param options - The options.
452
+ * @param options.messenger - The messenger.
501
453
  * @returns The method implementation which return value depends on the dialog
502
454
  * type, valid return types are: string, boolean, null.
503
455
  */
504
- export declare function getDialogImplementation({ requestUserApproval, createInterface, getInterface, setInterfaceDisplayed, }: DialogMethodHooks): (args: RestrictedMethodOptions<DialogParameters>) => Promise<DialogResult>;
456
+ export declare function getDialogImplementation({ messenger, }: DialogSpecificationBuilderOptions): (args: RestrictedMethodOptions<DialogParameters>) => Promise<DialogResult>;
505
457
  export {};
506
458
  //# sourceMappingURL=dialog.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dialog.d.mts","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,EACL,UAAU,EAIX,4BAA4B;AAC7B,OAAO,KAAK,EACV,YAAY,EAEZ,cAAc,EACd,MAAM,EAEN,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,YAAY,EACb,4BAA4B;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAG3D,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AAElD,QAAA,MAAM,UAAU,gBAAgB,CAAC;AAEjC,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG;IAC7D,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,qBAAqB;;;;;CAKjC,CAAC;AAEF,QAAA,MAAM,iBAAiB,kEAAkC,CAAC;AAE1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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAmB1B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAC1C,OAAO,sBAAsB,EAC7B,YAAY,CACb,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,SAAS,GACV,EAAE,iCAAiC,UAE1B,wBAAwB,gBAAgB,CAAC,KAC9C,QAAQ,YAAY,CAAC,CAyEzB"}
@@ -21,25 +21,18 @@ const PlaceholderStruct = optional(size(string(), 1, 40));
21
21
  * @param options - The specification builder options.
22
22
  * @param options.allowedCaveats - The optional allowed caveats for the
23
23
  * permission.
24
- * @param options.methodHooks - The RPC method hooks needed by the method
25
- * implementation.
24
+ * @param options.messenger - The messenger.
26
25
  * @returns The specification for the `snap_dialog` permission.
27
26
  */
28
- const specificationBuilder = ({ allowedCaveats = null, methodHooks, }) => {
27
+ const specificationBuilder = ({ allowedCaveats = null, messenger, }) => {
29
28
  return {
30
29
  permissionType: PermissionType.RestrictedMethod,
31
30
  targetName: methodName,
32
31
  allowedCaveats,
33
- methodImplementation: getDialogImplementation(methodHooks),
32
+ methodImplementation: getDialogImplementation({ messenger }),
34
33
  subjectTypes: [SubjectType.Snap],
35
34
  };
36
35
  };
37
- const methodHooks = {
38
- requestUserApproval: true,
39
- createInterface: true,
40
- getInterface: true,
41
- setInterfaceDisplayed: true,
42
- };
43
36
  /* eslint-disable jsdoc/check-indentation */
44
37
  /**
45
38
  * Display a [dialog](https://docs.metamask.io/snaps/features/custom-ui/dialogs/)
@@ -85,7 +78,12 @@ const methodHooks = {
85
78
  export const dialogBuilder = Object.freeze({
86
79
  targetName: methodName,
87
80
  specificationBuilder,
88
- methodHooks,
81
+ actionNames: [
82
+ 'ApprovalController:addRequest',
83
+ 'SnapInterfaceController:createInterface',
84
+ 'SnapInterfaceController:getInterface',
85
+ 'SnapInterfaceController:setInterfaceDisplayed',
86
+ ],
89
87
  });
90
88
  /* eslint-enable jsdoc/check-indentation */
91
89
  const AlertParametersWithContentStruct = object({
@@ -163,17 +161,12 @@ const DialogParametersStruct = selectiveUnion((value) => {
163
161
  /**
164
162
  * Builds the method implementation for `snap_dialog`.
165
163
  *
166
- * @param hooks - The RPC method hooks.
167
- * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.
168
- * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.
169
- * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
170
- * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.
171
- * @param hooks.setInterfaceDisplayed - A function that sets the interface as
172
- * displayed in SnapInterfaceController.
164
+ * @param options - The options.
165
+ * @param options.messenger - The messenger.
173
166
  * @returns The method implementation which return value depends on the dialog
174
167
  * type, valid return types are: string, boolean, null.
175
168
  */
176
- export function getDialogImplementation({ requestUserApproval, createInterface, getInterface, setInterfaceDisplayed, }) {
169
+ export function getDialogImplementation({ messenger, }) {
177
170
  return async function dialogImplementation(args) {
178
171
  const { params, context: { origin }, } = args;
179
172
  if (!isObject(params)) {
@@ -190,25 +183,25 @@ export function getDialogImplementation({ requestUserApproval, createInterface,
190
183
  : 'default';
191
184
  const approvalType = DIALOG_APPROVAL_TYPES[validatedType];
192
185
  if (hasProperty(validatedParams, 'content')) {
193
- const id = await createInterface(origin, validatedParams.content);
194
- setInterfaceDisplayed(origin, id);
195
- return requestUserApproval({
186
+ const id = messenger.call('SnapInterfaceController:createInterface', origin, validatedParams.content);
187
+ messenger.call('SnapInterfaceController:setInterfaceDisplayed', origin, id);
188
+ return messenger.call('ApprovalController:addRequest', {
196
189
  id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,
197
190
  origin,
198
191
  type: approvalType,
199
192
  requestData: { id, placeholder },
200
- });
193
+ }, true);
201
194
  }
202
- validateInterface(origin, validatedParams.id, getInterface);
203
- setInterfaceDisplayed(origin, validatedParams.id);
204
- return requestUserApproval({
195
+ validateInterface(origin, validatedParams.id, messenger);
196
+ messenger.call('SnapInterfaceController:setInterfaceDisplayed', origin, validatedParams.id);
197
+ return messenger.call('ApprovalController:addRequest', {
205
198
  id: approvalType === DIALOG_APPROVAL_TYPES.default
206
199
  ? validatedParams.id
207
200
  : undefined,
208
201
  origin,
209
202
  type: approvalType,
210
203
  requestData: { id: validatedParams.id, placeholder },
211
- });
204
+ }, true);
212
205
  };
213
206
  }
214
207
  /**
@@ -216,11 +209,11 @@ export function getDialogImplementation({ requestUserApproval, createInterface,
216
209
  *
217
210
  * @param origin - The origin of the request.
218
211
  * @param id - The interface ID.
219
- * @param getInterface - The function to get the interface.
212
+ * @param messenger - The messenger.
220
213
  */
221
- function validateInterface(origin, id, getInterface) {
214
+ function validateInterface(origin, id, messenger) {
222
215
  try {
223
- getInterface(origin, id);
216
+ messenger.call('SnapInterfaceController:getInterface', origin, id);
224
217
  }
225
218
  catch (error) {
226
219
  throw rpcErrors.invalidParams({