@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
@@ -37,26 +37,23 @@ const NotificationParametersStruct = (0, snaps_sdk_1.union)([
37
37
  *
38
38
  * @param options - The specification builder options.
39
39
  * @param options.allowedCaveats - The optional allowed caveats for the permission.
40
+ * @param options.messenger - The messenger.
40
41
  * @param options.methodHooks - The RPC method hooks needed by the method implementation.
41
42
  * @returns The specification for the `snap_notify` permission.
42
43
  */
43
- const specificationBuilder = ({ allowedCaveats = null, methodHooks }) => {
44
+ const specificationBuilder = ({ allowedCaveats = null, methodHooks, messenger, }) => {
44
45
  return {
45
46
  permissionType: permission_controller_1.PermissionType.RestrictedMethod,
46
47
  targetName: methodName,
47
48
  allowedCaveats,
48
- methodImplementation: getImplementation(methodHooks),
49
+ methodImplementation: getImplementation({ methodHooks, messenger }),
49
50
  subjectTypes: [permission_controller_1.SubjectType.Snap],
50
51
  };
51
52
  };
52
53
  exports.specificationBuilder = specificationBuilder;
53
54
  const methodHooks = {
54
- showNativeNotification: true,
55
- showInAppNotification: true,
56
55
  isOnPhishingList: true,
57
56
  maybeUpdatePhishingList: true,
58
- createInterface: true,
59
- getSnap: true,
60
57
  };
61
58
  /**
62
59
  * Display a
@@ -136,38 +133,47 @@ exports.notifyBuilder = Object.freeze({
136
133
  targetName: methodName,
137
134
  specificationBuilder: exports.specificationBuilder,
138
135
  methodHooks,
136
+ actionNames: [
137
+ 'RateLimitController:call',
138
+ 'SnapController:getSnap',
139
+ 'SnapInterfaceController:createInterface',
140
+ ],
139
141
  });
140
142
  /**
141
143
  * Builds the method implementation for `snap_notify`.
142
144
  *
143
- * @param hooks - The RPC method hooks.
144
- * @param hooks.showNativeNotification - A function that shows a native browser notification.
145
- * @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.
146
- * @param hooks.isOnPhishingList - A function that checks for links against the phishing list.
147
- * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
148
- * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
149
- * @param hooks.getSnap - A function that checks if a snap is installed.
145
+ * @param options - The options.
146
+ * @param options.messenger - The messenger.
147
+ * @param options.methodHooks - The RPC method hooks.
148
+ * @param options.methodHooks.isOnPhishingList - A function that checks for links against the phishing list.
149
+ * @param options.methodHooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
150
150
  * @returns The method implementation which returns `null` on success.
151
151
  * @throws If the params are invalid.
152
152
  */
153
- function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList, createInterface, getSnap, }) {
153
+ function getImplementation({ methodHooks: { isOnPhishingList, maybeUpdatePhishingList }, messenger, }) {
154
154
  return async function implementation(args) {
155
155
  const { params, context: { origin }, } = args;
156
156
  await maybeUpdatePhishingList();
157
- const validatedParams = getValidatedParams(params, isOnPhishingList, getSnap);
157
+ const validatedParams = getValidatedParams(params, isOnPhishingList, messenger);
158
158
  if ((0, utils_1.hasProperty)(validatedParams, 'content')) {
159
- const id = await createInterface(origin, validatedParams.content, undefined, snaps_sdk_1.ContentType.Notification);
159
+ const id = messenger.call('SnapInterfaceController:createInterface', origin, validatedParams.content, undefined, snaps_sdk_1.ContentType.Notification);
160
160
  validatedParams.content = id;
161
161
  }
162
162
  switch (validatedParams.type) {
163
163
  case snaps_sdk_1.NotificationType.Native:
164
- return await showNativeNotification(origin, validatedParams);
165
- case snaps_sdk_1.NotificationType.InApp:
166
- return await showInAppNotification(origin, validatedParams);
164
+ return (await messenger.call('RateLimitController:call', origin, 'showNativeNotification', origin, validatedParams.message));
165
+ case snaps_sdk_1.NotificationType.InApp: {
166
+ const { content, message, title, footerLink } = validatedParams;
167
+ return (await messenger.call('RateLimitController:call', origin, 'showInAppNotification', origin, {
168
+ interfaceId: content,
169
+ message,
170
+ title,
171
+ footerLink,
172
+ }));
173
+ }
174
+ /* istanbul ignore next */
167
175
  default:
168
- throw rpc_errors_1.rpcErrors.invalidParams({
169
- message: 'Must specify a valid notification "type".',
170
- });
176
+ return (0, utils_1.assertExhaustive)(validatedParams.type);
171
177
  }
172
178
  };
173
179
  }
@@ -178,11 +184,11 @@ exports.getImplementation = getImplementation;
178
184
  *
179
185
  * @param params - The unvalidated params object from the method request.
180
186
  * @param isOnPhishingList - The function that checks for links against the phishing list.
181
- * @param getSnap - A function that checks if a snap is installed.
187
+ * @param messenger - The messenger.
182
188
  * @returns The validated method parameter object.
183
189
  * @throws If the params are invalid.
184
190
  */
185
- function getValidatedParams(params, isOnPhishingList, getSnap) {
191
+ function getValidatedParams(params, isOnPhishingList, messenger) {
186
192
  if (!(0, utils_1.isObject)(params)) {
187
193
  throw rpc_errors_1.rpcErrors.invalidParams({
188
194
  message: 'Expected params to be a single object.',
@@ -212,6 +218,7 @@ function getValidatedParams(params, isOnPhishingList, getSnap) {
212
218
  }
213
219
  try {
214
220
  const validatedParams = (0, snaps_utils_1.createUnion)(params, NotificationParametersStruct, 'type');
221
+ const getSnap = (snapId) => messenger.call('SnapController:getSnap', snapId);
215
222
  (0, snaps_utils_1.validateTextLinks)(validatedParams.message, isOnPhishingList, getSnap);
216
223
  if ((0, utils_1.hasProperty)(validatedParams, 'footerLink')) {
217
224
  (0, snaps_utils_1.validateLink)(validatedParams.footerLink.href, isOnPhishingList, getSnap);
@@ -1 +1 @@
1
- {"version":3,"file":"notify.cjs","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":";;;AAKA,2EAA8E;AAC9E,qDAAiD;AAOjD,mDAO6B;AAC7B,uDAI+B;AAE/B,uDAAiE;AAEjE,2CAAwD;AAIxD,MAAM,UAAU,GAAG,aAAa,CAAC;AAEjC,MAAM,wBAAwB,GAAG,IAAA,oBAAM,EAAC;IACtC,IAAI,EAAE,IAAA,qBAAS,EAAC,4BAAgB,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,IAAA,oBAAM,GAAE;CAClB,CAAC,CAAC;AAEH,MAAM,uBAAuB,GAAG,IAAA,oBAAM,EAAC;IACrC,IAAI,EAAE,IAAA,qBAAS,EAAC,4BAAgB,CAAC,KAAK,CAAC;IACvC,OAAO,EAAE,IAAA,oBAAM,GAAE;CAClB,CAAC,CAAC;AAEH,MAAM,kCAAkC,GAAG,IAAA,oBAAM,EAAC;IAChD,IAAI,EAAE,IAAA,qBAAS,EAAC,4BAAgB,CAAC,KAAK,CAAC;IACvC,OAAO,EAAE,IAAA,oBAAM,GAAE;IACjB,OAAO,EAAE,oCAAwB;IACjC,KAAK,EAAE,IAAA,oBAAM,GAAE;IACf,UAAU,EAAE,IAAA,sBAAQ,EAClB,IAAA,oBAAM,EAAC;QACL,IAAI,EAAE,IAAA,oBAAM,GAAE;QACd,IAAI,EAAE,IAAA,oBAAM,GAAE;KACf,CAAC,CACH;CACF,CAAC,CAAC;AAEH,MAAM,4BAA4B,GAAG,IAAA,iBAAK,EAAC;IACzC,uBAAuB;IACvB,kCAAkC;IAClC,wBAAwB;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,MAAM;QAChC,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EACrC,CAAC;QACD,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,yEAAyE;SAC5E,CAAC,CAAC;IACL,CAAC;IAED,IACE,IAAI,KAAK,4BAAgB,CAAC,KAAK;QAC/B,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC,EACtC,CAAC;QACD,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,0EAA0E;SAC7E,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,IAAA,yBAAW,EACjC,MAAM,EACN,4BAA4B,EAC5B,MAAM,CACP,CAAC;QAEF,IAAA,+BAAiB,EAAC,eAAe,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAEtE,IAAI,IAAA,mBAAW,EAAC,eAAe,EAAE,YAAY,CAAC,EAAE,CAAC;YAC/C,IAAA,0BAAY,EAAC,eAAe,CAAC,UAAU,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,IAAA,2BAAe,EAAC,KAAK,CAAC,EAAE;SACrD,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAhED,gDAgEC","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 type {\n NotifyParams,\n NotifyResult,\n InterfaceContext,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport {\n enumValue,\n NotificationType,\n union,\n ContentType,\n getErrorMessage,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport {\n createUnion,\n validateLink,\n validateTextLinks,\n} from '@metamask/snaps-utils';\nimport type { InferMatching, Snap } from '@metamask/snaps-utils';\nimport { object, string, optional } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_notify';\n\nconst NativeNotificationStruct = object({\n type: enumValue(NotificationType.Native),\n message: string(),\n});\n\nconst InAppNotificationStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n});\n\nconst InAppNotificationWithDetailsStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n content: ComponentOrElementStruct,\n title: string(),\n footerLink: optional(\n object({\n href: string(),\n text: string(),\n }),\n ),\n});\n\nconst NotificationParametersStruct = union([\n InAppNotificationStruct,\n InAppNotificationWithDetailsStruct,\n NativeNotificationStruct,\n]);\n\nexport type NotificationArgs = InferMatching<\n typeof NotificationParametersStruct,\n NotifyParams\n>;\n\nexport type NotifyMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showNativeNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showInAppNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n isOnPhishingList: (url: string) => boolean;\n\n maybeUpdatePhishingList: () => Promise<void>;\n\n createInterface: (\n origin: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) => Promise<string>;\n getSnap: (snapId: string) => Snap | null;\n};\n\ntype SpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: NotifyMethodHooks;\n};\n\ntype Specification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_notify` permission.\n * `snap_notify` allows snaps to send multiple types of notifications to its users.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_notify` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n SpecificationBuilderOptions,\n Specification\n> = ({ allowedCaveats = null, methodHooks }: SpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<NotifyMethodHooks> = {\n showNativeNotification: true,\n showInAppNotification: true,\n isOnPhishingList: true,\n maybeUpdatePhishingList: true,\n createInterface: true,\n getSnap: true,\n};\n\n/**\n * Display a\n * [notification](https://docs.metamask.io/snaps/features/notifications/) in\n * MetaMask or natively in the OS. Snaps can trigger a short (up to 80\n * characters) notification message for actionable or time sensitive\n * information. `inApp` notifications can also include an optional\n * [expanded view](https://docs.metamask.io/snaps/features/notifications/#expanded-view).\n * The expanded view has a title, content, and optional footer link shown when\n * a user clicks on the notification.\n *\n * @example Basic in app notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'inApp',\n * message: 'This is an in-app notification',\n * },\n * });\n * ```\n *\n * @example Expandable in app notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'inApp',\n * message: 'This is an in-app notification',\n * title: 'Notification Title',\n * content: (\n * <Box>\n * <Text>This is the expanded content of the notification.</Text>\n * </Box>\n * ),\n * footerLink: {\n * href: 'https://example.com',\n * text: 'Click here for more info',\n * },\n * },\n * });\n * ```\n *\n * @example Native notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'native',\n * message: 'This is a native notification',\n * },\n * });\n * ```\n */\nexport const notifyBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_notify`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showNativeNotification - A function that shows a native browser notification.\n * @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.\n * @param hooks.isOnPhishingList - A function that checks for links against the phishing list.\n * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getSnap - A function that checks if a snap is installed.\n * @returns The method implementation which returns `null` on success.\n * @throws If the params are invalid.\n */\nexport function getImplementation({\n showNativeNotification,\n showInAppNotification,\n isOnPhishingList,\n maybeUpdatePhishingList,\n createInterface,\n getSnap,\n}: NotifyMethodHooks) {\n return async function implementation(\n args: RestrictedMethodOptions<NotifyParams>,\n ): Promise<NotifyResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n await maybeUpdatePhishingList();\n\n const validatedParams = getValidatedParams(\n params,\n isOnPhishingList,\n getSnap,\n );\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as ComponentOrElement,\n undefined,\n ContentType.Notification,\n );\n validatedParams.content = id;\n }\n\n switch (validatedParams.type) {\n case NotificationType.Native:\n return await showNativeNotification(origin, validatedParams);\n case NotificationType.InApp:\n return await showInAppNotification(origin, validatedParams);\n default:\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n };\n}\n\n/**\n * Validates the notify method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @param isOnPhishingList - The function that checks for links against the phishing list.\n * @param getSnap - A function that checks if a snap is installed.\n * @returns The validated method parameter object.\n * @throws If the params are invalid.\n */\nexport function getValidatedParams(\n params: unknown,\n isOnPhishingList: NotifyMethodHooks['isOnPhishingList'],\n getSnap: NotifyMethodHooks['getSnap'],\n): NotifyParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { type, message } = params;\n\n if (\n !type ||\n typeof type !== 'string' ||\n !Object.values(NotificationType).includes(type as NotificationType)\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n\n const isNotString = !message || typeof message !== 'string';\n // Set to the max message length on a Mac notification for now.\n if (\n type === NotificationType.Native &&\n (isNotString || message.length >= 50)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n if (\n type === NotificationType.InApp &&\n (isNotString || message.length >= 500)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 500 characters long.',\n });\n }\n\n try {\n const validatedParams = createUnion(\n params,\n NotificationParametersStruct,\n 'type',\n );\n\n validateTextLinks(validatedParams.message, isOnPhishingList, getSnap);\n\n if (hasProperty(validatedParams, 'footerLink')) {\n validateLink(validatedParams.footerLink.href, isOnPhishingList, getSnap);\n }\n\n return validatedParams;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"notify.cjs","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":";;;AAMA,2EAA8E;AAC9E,qDAAiD;AAMjD,mDAO6B;AAC7B,uDAI+B;AAE/B,uDAAiE;AAEjE,2CAA0E;AAS1E,MAAM,UAAU,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CAAC;YAC5B,OAAO,EACL,yEAAyE;SAC5E,CAAC,CAAC;IACL,CAAC;IAED,IACE,IAAI,KAAK,4BAAgB,CAAC,KAAK;QAC/B,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC,EACtC,CAAC;QACD,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,0EAA0E;SAC7E,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,IAAA,yBAAW,EACjC,MAAM,EACN,4BAA4B,EAC5B,MAAM,CACP,CAAC;QAEF,MAAM,OAAO,GAAG,CAAC,MAAc,EAAE,EAAE,CACjC,SAAS,CAAC,IAAI,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;QAEnD,IAAA,+BAAiB,EAAC,eAAe,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAEtE,IAAI,IAAA,mBAAW,EAAC,eAAe,EAAE,YAAY,CAAC,EAAE,CAAC;YAC/C,IAAA,0BAAY,EAAC,eAAe,CAAC,UAAU,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,IAAA,2BAAe,EAAC,KAAK,CAAC,EAAE;SACrD,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAnED,gDAmEC","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 type {\n NotifyParams,\n NotifyResult,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport {\n enumValue,\n NotificationType,\n union,\n ContentType,\n getErrorMessage,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport {\n createUnion,\n validateLink,\n validateTextLinks,\n} from '@metamask/snaps-utils';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport { object, string, optional } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertExhaustive, hasProperty, isObject } from '@metamask/utils';\n\nimport type {\n RateLimitControllerCallAction,\n SnapControllerGetSnapAction,\n SnapInterfaceControllerCreateInterfaceAction,\n} from '../types';\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_notify';\n\nconst NativeNotificationStruct = object({\n type: enumValue(NotificationType.Native),\n message: string(),\n});\n\nconst InAppNotificationStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n});\n\nconst InAppNotificationWithDetailsStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n content: ComponentOrElementStruct,\n title: string(),\n footerLink: optional(\n object({\n href: string(),\n text: string(),\n }),\n ),\n});\n\nconst NotificationParametersStruct = union([\n InAppNotificationStruct,\n InAppNotificationWithDetailsStruct,\n NativeNotificationStruct,\n]);\n\nexport type NotificationArgs = InferMatching<\n typeof NotificationParametersStruct,\n NotifyParams\n>;\n\nexport type NotifyMethodHooks = {\n isOnPhishingList: (url: string) => boolean;\n\n maybeUpdatePhishingList: () => Promise<void>;\n};\n\nexport type NotifyMessengerActions =\n | RateLimitControllerCallAction\n | SnapControllerGetSnapAction\n | SnapInterfaceControllerCreateInterfaceAction;\n\ntype SpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: NotifyMethodHooks;\n messenger: Messenger<string, NotifyMessengerActions>;\n};\n\ntype Specification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_notify` permission.\n * `snap_notify` allows snaps to send multiple types of notifications to its users.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.messenger - The messenger.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_notify` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n SpecificationBuilderOptions,\n Specification\n> = ({\n allowedCaveats = null,\n methodHooks,\n messenger,\n}: SpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getImplementation({ methodHooks, messenger }),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<NotifyMethodHooks> = {\n isOnPhishingList: true,\n maybeUpdatePhishingList: true,\n};\n\n/**\n * Display a\n * [notification](https://docs.metamask.io/snaps/features/notifications/) in\n * MetaMask or natively in the OS. Snaps can trigger a short (up to 80\n * characters) notification message for actionable or time sensitive\n * information. `inApp` notifications can also include an optional\n * [expanded view](https://docs.metamask.io/snaps/features/notifications/#expanded-view).\n * The expanded view has a title, content, and optional footer link shown when\n * a user clicks on the notification.\n *\n * @example Basic in app notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'inApp',\n * message: 'This is an in-app notification',\n * },\n * });\n * ```\n *\n * @example Expandable in app notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'inApp',\n * message: 'This is an in-app notification',\n * title: 'Notification Title',\n * content: (\n * <Box>\n * <Text>This is the expanded content of the notification.</Text>\n * </Box>\n * ),\n * footerLink: {\n * href: 'https://example.com',\n * text: 'Click here for more info',\n * },\n * },\n * });\n * ```\n *\n * @example Native notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'native',\n * message: 'This is a native notification',\n * },\n * });\n * ```\n */\nexport const notifyBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n actionNames: [\n 'RateLimitController:call',\n 'SnapController:getSnap',\n 'SnapInterfaceController:createInterface',\n ],\n} as const);\n\n/**\n * Builds the method implementation for `snap_notify`.\n *\n * @param options - The options.\n * @param options.messenger - The messenger.\n * @param options.methodHooks - The RPC method hooks.\n * @param options.methodHooks.isOnPhishingList - A function that checks for links against the phishing list.\n * @param options.methodHooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\n * @returns The method implementation which returns `null` on success.\n * @throws If the params are invalid.\n */\nexport function getImplementation({\n methodHooks: { isOnPhishingList, maybeUpdatePhishingList },\n messenger,\n}: SpecificationBuilderOptions) {\n return async function implementation(\n args: RestrictedMethodOptions<NotifyParams>,\n ): Promise<NotifyResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n await maybeUpdatePhishingList();\n\n const validatedParams = getValidatedParams(\n params,\n isOnPhishingList,\n messenger,\n );\n\n if (hasProperty(validatedParams, 'content')) {\n const id = messenger.call(\n 'SnapInterfaceController:createInterface',\n origin,\n validatedParams.content as ComponentOrElement,\n undefined,\n ContentType.Notification,\n );\n validatedParams.content = id;\n }\n\n switch (validatedParams.type) {\n case NotificationType.Native:\n return (await messenger.call(\n 'RateLimitController:call',\n origin,\n 'showNativeNotification',\n origin,\n validatedParams.message,\n )) as NotifyResult;\n case NotificationType.InApp: {\n const { content, message, title, footerLink } =\n validatedParams as NotificationArgs & {\n content?: string;\n title?: string;\n footerLink?: { href: string; text: string };\n };\n return (await messenger.call(\n 'RateLimitController:call',\n origin,\n 'showInAppNotification',\n origin,\n {\n interfaceId: content,\n message,\n title,\n footerLink,\n },\n )) as NotifyResult;\n }\n /* istanbul ignore next */\n default:\n return assertExhaustive(validatedParams.type as never);\n }\n };\n}\n\n/**\n * Validates the notify method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @param isOnPhishingList - The function that checks for links against the phishing list.\n * @param messenger - The messenger.\n * @returns The validated method parameter object.\n * @throws If the params are invalid.\n */\nexport function getValidatedParams(\n params: unknown,\n isOnPhishingList: NotifyMethodHooks['isOnPhishingList'],\n messenger: Messenger<string, NotifyMessengerActions>,\n): NotifyParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { type, message } = params;\n\n if (\n !type ||\n typeof type !== 'string' ||\n !Object.values(NotificationType).includes(type as NotificationType)\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n\n const isNotString = !message || typeof message !== 'string';\n // Set to the max message length on a Mac notification for now.\n if (\n type === NotificationType.Native &&\n (isNotString || message.length >= 50)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n if (\n type === NotificationType.InApp &&\n (isNotString || message.length >= 500)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 500 characters long.',\n });\n }\n\n try {\n const validatedParams = createUnion(\n params,\n NotificationParametersStruct,\n 'type',\n );\n\n const getSnap = (snapId: string) =>\n messenger.call('SnapController:getSnap', snapId);\n\n validateTextLinks(validatedParams.message, isOnPhishingList, getSnap);\n\n if (hasProperty(validatedParams, 'footerLink')) {\n validateLink(validatedParams.footerLink.href, isOnPhishingList, getSnap);\n }\n\n return validatedParams;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
@@ -1,9 +1,10 @@
1
+ import type { Messenger } from "@metamask/messenger";
1
2
  import type { PermissionSpecificationBuilder, RestrictedMethodOptions, ValidPermissionSpecification } from "@metamask/permission-controller";
2
3
  import { PermissionType } from "@metamask/permission-controller";
3
- import type { NotifyParams, NotifyResult, InterfaceContext, ComponentOrElement } from "@metamask/snaps-sdk";
4
- import { ContentType } from "@metamask/snaps-sdk";
5
- import type { InferMatching, Snap } from "@metamask/snaps-utils";
4
+ import type { NotifyParams, NotifyResult } from "@metamask/snaps-sdk";
5
+ import type { InferMatching } from "@metamask/snaps-utils";
6
6
  import type { NonEmptyArray } from "@metamask/utils";
7
+ import type { RateLimitControllerCallAction, SnapControllerGetSnapAction, SnapInterfaceControllerCreateInterfaceAction } from "../types.cjs";
7
8
  import { type MethodHooksObject } from "../utils.cjs";
8
9
  declare const methodName = "snap_notify";
9
10
  declare const NotificationParametersStruct: import("@metamask/superstruct").Struct<{
@@ -315,24 +316,14 @@ declare const NotificationParametersStruct: import("@metamask/superstruct").Stru
315
316
  }>]>;
316
317
  export type NotificationArgs = InferMatching<typeof NotificationParametersStruct, NotifyParams>;
317
318
  export type NotifyMethodHooks = {
318
- /**
319
- * @param snapId - The ID of the Snap that created the notification.
320
- * @param args - The notification arguments.
321
- */
322
- showNativeNotification: (snapId: string, args: NotificationArgs) => Promise<null>;
323
- /**
324
- * @param snapId - The ID of the Snap that created the notification.
325
- * @param args - The notification arguments.
326
- */
327
- showInAppNotification: (snapId: string, args: NotificationArgs) => Promise<null>;
328
319
  isOnPhishingList: (url: string) => boolean;
329
320
  maybeUpdatePhishingList: () => Promise<void>;
330
- createInterface: (origin: string, content: ComponentOrElement, context?: InterfaceContext, contentType?: ContentType) => Promise<string>;
331
- getSnap: (snapId: string) => Snap | null;
332
321
  };
322
+ export type NotifyMessengerActions = RateLimitControllerCallAction | SnapControllerGetSnapAction | SnapInterfaceControllerCreateInterfaceAction;
333
323
  type SpecificationBuilderOptions = {
334
324
  allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
335
325
  methodHooks: NotifyMethodHooks;
326
+ messenger: Messenger<string, NotifyMessengerActions>;
336
327
  };
337
328
  type Specification = ValidPermissionSpecification<{
338
329
  permissionType: PermissionType.RestrictedMethod;
@@ -346,6 +337,7 @@ type Specification = ValidPermissionSpecification<{
346
337
  *
347
338
  * @param options - The specification builder options.
348
339
  * @param options.allowedCaveats - The optional allowed caveats for the permission.
340
+ * @param options.messenger - The messenger.
349
341
  * @param options.methodHooks - The RPC method hooks needed by the method implementation.
350
342
  * @returns The specification for the `snap_notify` permission.
351
343
  */
@@ -433,31 +425,30 @@ export declare const notifyBuilder: Readonly<{
433
425
  allowedCaveats: Readonly<NonEmptyArray<string>> | null;
434
426
  }>;
435
427
  readonly methodHooks: MethodHooksObject<NotifyMethodHooks>;
428
+ readonly actionNames: readonly ["RateLimitController:call", "SnapController:getSnap", "SnapInterfaceController:createInterface"];
436
429
  }>;
437
430
  /**
438
431
  * Builds the method implementation for `snap_notify`.
439
432
  *
440
- * @param hooks - The RPC method hooks.
441
- * @param hooks.showNativeNotification - A function that shows a native browser notification.
442
- * @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.
443
- * @param hooks.isOnPhishingList - A function that checks for links against the phishing list.
444
- * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
445
- * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
446
- * @param hooks.getSnap - A function that checks if a snap is installed.
433
+ * @param options - The options.
434
+ * @param options.messenger - The messenger.
435
+ * @param options.methodHooks - The RPC method hooks.
436
+ * @param options.methodHooks.isOnPhishingList - A function that checks for links against the phishing list.
437
+ * @param options.methodHooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
447
438
  * @returns The method implementation which returns `null` on success.
448
439
  * @throws If the params are invalid.
449
440
  */
450
- export declare function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList, createInterface, getSnap, }: NotifyMethodHooks): (args: RestrictedMethodOptions<NotifyParams>) => Promise<NotifyResult>;
441
+ export declare function getImplementation({ methodHooks: { isOnPhishingList, maybeUpdatePhishingList }, messenger, }: SpecificationBuilderOptions): (args: RestrictedMethodOptions<NotifyParams>) => Promise<NotifyResult>;
451
442
  /**
452
443
  * Validates the notify method `params` and returns them cast to the correct
453
444
  * type. Throws if validation fails.
454
445
  *
455
446
  * @param params - The unvalidated params object from the method request.
456
447
  * @param isOnPhishingList - The function that checks for links against the phishing list.
457
- * @param getSnap - A function that checks if a snap is installed.
448
+ * @param messenger - The messenger.
458
449
  * @returns The validated method parameter object.
459
450
  * @throws If the params are invalid.
460
451
  */
461
- export declare function getValidatedParams(params: unknown, isOnPhishingList: NotifyMethodHooks['isOnPhishingList'], getSnap: NotifyMethodHooks['getSnap']): NotifyParams;
452
+ export declare function getValidatedParams(params: unknown, isOnPhishingList: NotifyMethodHooks['isOnPhishingList'], messenger: Messenger<string, NotifyMessengerActions>): NotifyParams;
462
453
  export {};
463
454
  //# sourceMappingURL=notify.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"notify.d.cts","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,4BAA4B,EAC7B,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EACnB,4BAA4B;AAC7B,OAAO,EAIL,WAAW,EAGZ,4BAA4B;AAM7B,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,8BAA8B;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AAElD,QAAA,MAAM,UAAU,gBAAgB,CAAC;AAyBjC,QAAA,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAC;AAEF,KAAK,aAAa,GAAG,4BAA4B,CAAC;IAChD,cAAc,EAAE,cAAc,CAAC,gBAAgB,CAAC;IAChD,UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B,oBAAoB,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAC3D,cAAc,EAAE,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC;CACxD,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,EAAE,8BAA8B,CAC/D,cAAc,CAAC,gBAAgB,EAC/B,2BAA2B,EAC3B,aAAa,CAad,CAAC;AAOF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,eAAO,MAAM,aAAa;;;wBAjHR,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,wBAAwB,CAAC;wBAC1C,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;;;;EAuH7C,CAAC;AAEZ;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,WAAW,EAAE,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,EAC1D,SAAS,GACV,EAAE,2BAA2B,UAEpB,wBAAwB,YAAY,CAAC,KAC1C,QAAQ,YAAY,CAAC,CA2DzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,OAAO,EACf,gBAAgB,EAAE,iBAAiB,CAAC,kBAAkB,CAAC,EACvD,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,sBAAsB,CAAC,GACnD,YAAY,CA+Dd"}
@@ -1,9 +1,10 @@
1
+ import type { Messenger } from "@metamask/messenger";
1
2
  import type { PermissionSpecificationBuilder, RestrictedMethodOptions, ValidPermissionSpecification } from "@metamask/permission-controller";
2
3
  import { PermissionType } from "@metamask/permission-controller";
3
- import type { NotifyParams, NotifyResult, InterfaceContext, ComponentOrElement } from "@metamask/snaps-sdk";
4
- import { ContentType } from "@metamask/snaps-sdk";
5
- import type { InferMatching, Snap } from "@metamask/snaps-utils";
4
+ import type { NotifyParams, NotifyResult } from "@metamask/snaps-sdk";
5
+ import type { InferMatching } from "@metamask/snaps-utils";
6
6
  import type { NonEmptyArray } from "@metamask/utils";
7
+ import type { RateLimitControllerCallAction, SnapControllerGetSnapAction, SnapInterfaceControllerCreateInterfaceAction } from "../types.mjs";
7
8
  import { type MethodHooksObject } from "../utils.mjs";
8
9
  declare const methodName = "snap_notify";
9
10
  declare const NotificationParametersStruct: import("@metamask/superstruct").Struct<{
@@ -315,24 +316,14 @@ declare const NotificationParametersStruct: import("@metamask/superstruct").Stru
315
316
  }>]>;
316
317
  export type NotificationArgs = InferMatching<typeof NotificationParametersStruct, NotifyParams>;
317
318
  export type NotifyMethodHooks = {
318
- /**
319
- * @param snapId - The ID of the Snap that created the notification.
320
- * @param args - The notification arguments.
321
- */
322
- showNativeNotification: (snapId: string, args: NotificationArgs) => Promise<null>;
323
- /**
324
- * @param snapId - The ID of the Snap that created the notification.
325
- * @param args - The notification arguments.
326
- */
327
- showInAppNotification: (snapId: string, args: NotificationArgs) => Promise<null>;
328
319
  isOnPhishingList: (url: string) => boolean;
329
320
  maybeUpdatePhishingList: () => Promise<void>;
330
- createInterface: (origin: string, content: ComponentOrElement, context?: InterfaceContext, contentType?: ContentType) => Promise<string>;
331
- getSnap: (snapId: string) => Snap | null;
332
321
  };
322
+ export type NotifyMessengerActions = RateLimitControllerCallAction | SnapControllerGetSnapAction | SnapInterfaceControllerCreateInterfaceAction;
333
323
  type SpecificationBuilderOptions = {
334
324
  allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
335
325
  methodHooks: NotifyMethodHooks;
326
+ messenger: Messenger<string, NotifyMessengerActions>;
336
327
  };
337
328
  type Specification = ValidPermissionSpecification<{
338
329
  permissionType: PermissionType.RestrictedMethod;
@@ -346,6 +337,7 @@ type Specification = ValidPermissionSpecification<{
346
337
  *
347
338
  * @param options - The specification builder options.
348
339
  * @param options.allowedCaveats - The optional allowed caveats for the permission.
340
+ * @param options.messenger - The messenger.
349
341
  * @param options.methodHooks - The RPC method hooks needed by the method implementation.
350
342
  * @returns The specification for the `snap_notify` permission.
351
343
  */
@@ -433,31 +425,30 @@ export declare const notifyBuilder: Readonly<{
433
425
  allowedCaveats: Readonly<NonEmptyArray<string>> | null;
434
426
  }>;
435
427
  readonly methodHooks: MethodHooksObject<NotifyMethodHooks>;
428
+ readonly actionNames: readonly ["RateLimitController:call", "SnapController:getSnap", "SnapInterfaceController:createInterface"];
436
429
  }>;
437
430
  /**
438
431
  * Builds the method implementation for `snap_notify`.
439
432
  *
440
- * @param hooks - The RPC method hooks.
441
- * @param hooks.showNativeNotification - A function that shows a native browser notification.
442
- * @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.
443
- * @param hooks.isOnPhishingList - A function that checks for links against the phishing list.
444
- * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
445
- * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
446
- * @param hooks.getSnap - A function that checks if a snap is installed.
433
+ * @param options - The options.
434
+ * @param options.messenger - The messenger.
435
+ * @param options.methodHooks - The RPC method hooks.
436
+ * @param options.methodHooks.isOnPhishingList - A function that checks for links against the phishing list.
437
+ * @param options.methodHooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
447
438
  * @returns The method implementation which returns `null` on success.
448
439
  * @throws If the params are invalid.
449
440
  */
450
- export declare function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList, createInterface, getSnap, }: NotifyMethodHooks): (args: RestrictedMethodOptions<NotifyParams>) => Promise<NotifyResult>;
441
+ export declare function getImplementation({ methodHooks: { isOnPhishingList, maybeUpdatePhishingList }, messenger, }: SpecificationBuilderOptions): (args: RestrictedMethodOptions<NotifyParams>) => Promise<NotifyResult>;
451
442
  /**
452
443
  * Validates the notify method `params` and returns them cast to the correct
453
444
  * type. Throws if validation fails.
454
445
  *
455
446
  * @param params - The unvalidated params object from the method request.
456
447
  * @param isOnPhishingList - The function that checks for links against the phishing list.
457
- * @param getSnap - A function that checks if a snap is installed.
448
+ * @param messenger - The messenger.
458
449
  * @returns The validated method parameter object.
459
450
  * @throws If the params are invalid.
460
451
  */
461
- export declare function getValidatedParams(params: unknown, isOnPhishingList: NotifyMethodHooks['isOnPhishingList'], getSnap: NotifyMethodHooks['getSnap']): NotifyParams;
452
+ export declare function getValidatedParams(params: unknown, isOnPhishingList: NotifyMethodHooks['isOnPhishingList'], messenger: Messenger<string, NotifyMessengerActions>): NotifyParams;
462
453
  export {};
463
454
  //# sourceMappingURL=notify.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"notify.d.mts","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,4BAA4B,EAC7B,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EACnB,4BAA4B;AAC7B,OAAO,EAIL,WAAW,EAGZ,4BAA4B;AAM7B,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,8BAA8B;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AAElD,QAAA,MAAM,UAAU,gBAAgB,CAAC;AAyBjC,QAAA,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B,oBAAoB,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAC3D,cAAc,EAAE,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC;CACxD,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,EAAE,8BAA8B,CAC/D,cAAc,CAAC,gBAAgB,EAC/B,2BAA2B,EAC3B,aAAa,CAad,CAAC;AAOF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,eAAO,MAAM,aAAa;;;wBAjHR,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,wBAAwB,CAAC;wBAC1C,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;;;;EAuH7C,CAAC;AAEZ;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,WAAW,EAAE,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,EAC1D,SAAS,GACV,EAAE,2BAA2B,UAEpB,wBAAwB,YAAY,CAAC,KAC1C,QAAQ,YAAY,CAAC,CA2DzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,OAAO,EACf,gBAAgB,EAAE,iBAAiB,CAAC,kBAAkB,CAAC,EACvD,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,sBAAsB,CAAC,GACnD,YAAY,CA+Dd"}
@@ -3,7 +3,7 @@ import { rpcErrors } from "@metamask/rpc-errors";
3
3
  import { enumValue, NotificationType, union, ContentType, getErrorMessage, ComponentOrElementStruct } from "@metamask/snaps-sdk";
4
4
  import { createUnion, validateLink, validateTextLinks } from "@metamask/snaps-utils";
5
5
  import { object, string, optional } from "@metamask/superstruct";
6
- import { hasProperty, isObject } from "@metamask/utils";
6
+ import { assertExhaustive, hasProperty, isObject } from "@metamask/utils";
7
7
  const methodName = 'snap_notify';
8
8
  const NativeNotificationStruct = object({
9
9
  type: enumValue(NotificationType.Native),
@@ -34,25 +34,22 @@ const NotificationParametersStruct = union([
34
34
  *
35
35
  * @param options - The specification builder options.
36
36
  * @param options.allowedCaveats - The optional allowed caveats for the permission.
37
+ * @param options.messenger - The messenger.
37
38
  * @param options.methodHooks - The RPC method hooks needed by the method implementation.
38
39
  * @returns The specification for the `snap_notify` permission.
39
40
  */
40
- export const specificationBuilder = ({ allowedCaveats = null, methodHooks }) => {
41
+ export const specificationBuilder = ({ allowedCaveats = null, methodHooks, messenger, }) => {
41
42
  return {
42
43
  permissionType: PermissionType.RestrictedMethod,
43
44
  targetName: methodName,
44
45
  allowedCaveats,
45
- methodImplementation: getImplementation(methodHooks),
46
+ methodImplementation: getImplementation({ methodHooks, messenger }),
46
47
  subjectTypes: [SubjectType.Snap],
47
48
  };
48
49
  };
49
50
  const methodHooks = {
50
- showNativeNotification: true,
51
- showInAppNotification: true,
52
51
  isOnPhishingList: true,
53
52
  maybeUpdatePhishingList: true,
54
- createInterface: true,
55
- getSnap: true,
56
53
  };
57
54
  /**
58
55
  * Display a
@@ -132,38 +129,47 @@ export const notifyBuilder = Object.freeze({
132
129
  targetName: methodName,
133
130
  specificationBuilder,
134
131
  methodHooks,
132
+ actionNames: [
133
+ 'RateLimitController:call',
134
+ 'SnapController:getSnap',
135
+ 'SnapInterfaceController:createInterface',
136
+ ],
135
137
  });
136
138
  /**
137
139
  * Builds the method implementation for `snap_notify`.
138
140
  *
139
- * @param hooks - The RPC method hooks.
140
- * @param hooks.showNativeNotification - A function that shows a native browser notification.
141
- * @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.
142
- * @param hooks.isOnPhishingList - A function that checks for links against the phishing list.
143
- * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
144
- * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
145
- * @param hooks.getSnap - A function that checks if a snap is installed.
141
+ * @param options - The options.
142
+ * @param options.messenger - The messenger.
143
+ * @param options.methodHooks - The RPC method hooks.
144
+ * @param options.methodHooks.isOnPhishingList - A function that checks for links against the phishing list.
145
+ * @param options.methodHooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
146
146
  * @returns The method implementation which returns `null` on success.
147
147
  * @throws If the params are invalid.
148
148
  */
149
- export function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList, createInterface, getSnap, }) {
149
+ export function getImplementation({ methodHooks: { isOnPhishingList, maybeUpdatePhishingList }, messenger, }) {
150
150
  return async function implementation(args) {
151
151
  const { params, context: { origin }, } = args;
152
152
  await maybeUpdatePhishingList();
153
- const validatedParams = getValidatedParams(params, isOnPhishingList, getSnap);
153
+ const validatedParams = getValidatedParams(params, isOnPhishingList, messenger);
154
154
  if (hasProperty(validatedParams, 'content')) {
155
- const id = await createInterface(origin, validatedParams.content, undefined, ContentType.Notification);
155
+ const id = messenger.call('SnapInterfaceController:createInterface', origin, validatedParams.content, undefined, ContentType.Notification);
156
156
  validatedParams.content = id;
157
157
  }
158
158
  switch (validatedParams.type) {
159
159
  case NotificationType.Native:
160
- return await showNativeNotification(origin, validatedParams);
161
- case NotificationType.InApp:
162
- return await showInAppNotification(origin, validatedParams);
160
+ return (await messenger.call('RateLimitController:call', origin, 'showNativeNotification', origin, validatedParams.message));
161
+ case NotificationType.InApp: {
162
+ const { content, message, title, footerLink } = validatedParams;
163
+ return (await messenger.call('RateLimitController:call', origin, 'showInAppNotification', origin, {
164
+ interfaceId: content,
165
+ message,
166
+ title,
167
+ footerLink,
168
+ }));
169
+ }
170
+ /* istanbul ignore next */
163
171
  default:
164
- throw rpcErrors.invalidParams({
165
- message: 'Must specify a valid notification "type".',
166
- });
172
+ return assertExhaustive(validatedParams.type);
167
173
  }
168
174
  };
169
175
  }
@@ -173,11 +179,11 @@ export function getImplementation({ showNativeNotification, showInAppNotificatio
173
179
  *
174
180
  * @param params - The unvalidated params object from the method request.
175
181
  * @param isOnPhishingList - The function that checks for links against the phishing list.
176
- * @param getSnap - A function that checks if a snap is installed.
182
+ * @param messenger - The messenger.
177
183
  * @returns The validated method parameter object.
178
184
  * @throws If the params are invalid.
179
185
  */
180
- export function getValidatedParams(params, isOnPhishingList, getSnap) {
186
+ export function getValidatedParams(params, isOnPhishingList, messenger) {
181
187
  if (!isObject(params)) {
182
188
  throw rpcErrors.invalidParams({
183
189
  message: 'Expected params to be a single object.',
@@ -207,6 +213,7 @@ export function getValidatedParams(params, isOnPhishingList, getSnap) {
207
213
  }
208
214
  try {
209
215
  const validatedParams = createUnion(params, NotificationParametersStruct, 'type');
216
+ const getSnap = (snapId) => messenger.call('SnapController:getSnap', snapId);
210
217
  validateTextLinks(validatedParams.message, isOnPhishingList, getSnap);
211
218
  if (hasProperty(validatedParams, 'footerLink')) {
212
219
  validateLink(validatedParams.footerLink.href, isOnPhishingList, getSnap);
@@ -1 +1 @@
1
- {"version":3,"file":"notify.mjs","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAOjD,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,eAAe,EACf,wBAAwB,EACzB,4BAA4B;AAC7B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,iBAAiB,EAClB,8BAA8B;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,8BAA8B;AAEjE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB;AAIxD,MAAM,UAAU,GAAG,aAAa,CAAC;AAEjC,MAAM,wBAAwB,GAAG,MAAM,CAAC;IACtC,IAAI,EAAE,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,MAAM,EAAE;CAClB,CAAC,CAAC;AAEH,MAAM,uBAAuB,GAAG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EAAE,CAAC;QACf,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,eAAe,CAAC,KAAK,CAAC,EAAE;SACrD,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 type {\n NotifyParams,\n NotifyResult,\n InterfaceContext,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport {\n enumValue,\n NotificationType,\n union,\n ContentType,\n getErrorMessage,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport {\n createUnion,\n validateLink,\n validateTextLinks,\n} from '@metamask/snaps-utils';\nimport type { InferMatching, Snap } from '@metamask/snaps-utils';\nimport { object, string, optional } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_notify';\n\nconst NativeNotificationStruct = object({\n type: enumValue(NotificationType.Native),\n message: string(),\n});\n\nconst InAppNotificationStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n});\n\nconst InAppNotificationWithDetailsStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n content: ComponentOrElementStruct,\n title: string(),\n footerLink: optional(\n object({\n href: string(),\n text: string(),\n }),\n ),\n});\n\nconst NotificationParametersStruct = union([\n InAppNotificationStruct,\n InAppNotificationWithDetailsStruct,\n NativeNotificationStruct,\n]);\n\nexport type NotificationArgs = InferMatching<\n typeof NotificationParametersStruct,\n NotifyParams\n>;\n\nexport type NotifyMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showNativeNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showInAppNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n isOnPhishingList: (url: string) => boolean;\n\n maybeUpdatePhishingList: () => Promise<void>;\n\n createInterface: (\n origin: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) => Promise<string>;\n getSnap: (snapId: string) => Snap | null;\n};\n\ntype SpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: NotifyMethodHooks;\n};\n\ntype Specification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_notify` permission.\n * `snap_notify` allows snaps to send multiple types of notifications to its users.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_notify` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n SpecificationBuilderOptions,\n Specification\n> = ({ allowedCaveats = null, methodHooks }: SpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<NotifyMethodHooks> = {\n showNativeNotification: true,\n showInAppNotification: true,\n isOnPhishingList: true,\n maybeUpdatePhishingList: true,\n createInterface: true,\n getSnap: true,\n};\n\n/**\n * Display a\n * [notification](https://docs.metamask.io/snaps/features/notifications/) in\n * MetaMask or natively in the OS. Snaps can trigger a short (up to 80\n * characters) notification message for actionable or time sensitive\n * information. `inApp` notifications can also include an optional\n * [expanded view](https://docs.metamask.io/snaps/features/notifications/#expanded-view).\n * The expanded view has a title, content, and optional footer link shown when\n * a user clicks on the notification.\n *\n * @example Basic in app notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'inApp',\n * message: 'This is an in-app notification',\n * },\n * });\n * ```\n *\n * @example Expandable in app notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'inApp',\n * message: 'This is an in-app notification',\n * title: 'Notification Title',\n * content: (\n * <Box>\n * <Text>This is the expanded content of the notification.</Text>\n * </Box>\n * ),\n * footerLink: {\n * href: 'https://example.com',\n * text: 'Click here for more info',\n * },\n * },\n * });\n * ```\n *\n * @example Native notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'native',\n * message: 'This is a native notification',\n * },\n * });\n * ```\n */\nexport const notifyBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_notify`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showNativeNotification - A function that shows a native browser notification.\n * @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.\n * @param hooks.isOnPhishingList - A function that checks for links against the phishing list.\n * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getSnap - A function that checks if a snap is installed.\n * @returns The method implementation which returns `null` on success.\n * @throws If the params are invalid.\n */\nexport function getImplementation({\n showNativeNotification,\n showInAppNotification,\n isOnPhishingList,\n maybeUpdatePhishingList,\n createInterface,\n getSnap,\n}: NotifyMethodHooks) {\n return async function implementation(\n args: RestrictedMethodOptions<NotifyParams>,\n ): Promise<NotifyResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n await maybeUpdatePhishingList();\n\n const validatedParams = getValidatedParams(\n params,\n isOnPhishingList,\n getSnap,\n );\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as ComponentOrElement,\n undefined,\n ContentType.Notification,\n );\n validatedParams.content = id;\n }\n\n switch (validatedParams.type) {\n case NotificationType.Native:\n return await showNativeNotification(origin, validatedParams);\n case NotificationType.InApp:\n return await showInAppNotification(origin, validatedParams);\n default:\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n };\n}\n\n/**\n * Validates the notify method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @param isOnPhishingList - The function that checks for links against the phishing list.\n * @param getSnap - A function that checks if a snap is installed.\n * @returns The validated method parameter object.\n * @throws If the params are invalid.\n */\nexport function getValidatedParams(\n params: unknown,\n isOnPhishingList: NotifyMethodHooks['isOnPhishingList'],\n getSnap: NotifyMethodHooks['getSnap'],\n): NotifyParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { type, message } = params;\n\n if (\n !type ||\n typeof type !== 'string' ||\n !Object.values(NotificationType).includes(type as NotificationType)\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n\n const isNotString = !message || typeof message !== 'string';\n // Set to the max message length on a Mac notification for now.\n if (\n type === NotificationType.Native &&\n (isNotString || message.length >= 50)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n if (\n type === NotificationType.InApp &&\n (isNotString || message.length >= 500)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 500 characters long.',\n });\n }\n\n try {\n const validatedParams = createUnion(\n params,\n NotificationParametersStruct,\n 'type',\n );\n\n validateTextLinks(validatedParams.message, isOnPhishingList, getSnap);\n\n if (hasProperty(validatedParams, 'footerLink')) {\n validateLink(validatedParams.footerLink.href, isOnPhishingList, getSnap);\n }\n\n return validatedParams;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"notify.mjs","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAMjD,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,eAAe,EACf,wBAAwB,EACzB,4BAA4B;AAC7B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,iBAAiB,EAClB,8BAA8B;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,8BAA8B;AAEjE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB;AAS1E,MAAM,UAAU,GAAG,aAAa,CAAC;AAEjC,MAAM,wBAAwB,GAAG,MAAM,CAAC;IACtC,IAAI,EAAE,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,MAAM,EAAE;CAClB,CAAC,CAAC;AAEH,MAAM,uBAAuB,GAAG,MAAM,CAAC;IACrC,IAAI,EAAE,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC;IACvC,OAAO,EAAE,MAAM,EAAE;CAClB,CAAC,CAAC;AAEH,MAAM,kCAAkC,GAAG,MAAM,CAAC;IAChD,IAAI,EAAE,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC;IACvC,OAAO,EAAE,MAAM,EAAE;IACjB,OAAO,EAAE,wBAAwB;IACjC,KAAK,EAAE,MAAM,EAAE;IACf,UAAU,EAAE,QAAQ,CAClB,MAAM,CAAC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CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,eAAe,CAAC,KAAK,CAAC,EAAE;SACrD,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 type {\n NotifyParams,\n NotifyResult,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport {\n enumValue,\n NotificationType,\n union,\n ContentType,\n getErrorMessage,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport {\n createUnion,\n validateLink,\n validateTextLinks,\n} from '@metamask/snaps-utils';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport { object, string, optional } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertExhaustive, hasProperty, isObject } from '@metamask/utils';\n\nimport type {\n RateLimitControllerCallAction,\n SnapControllerGetSnapAction,\n SnapInterfaceControllerCreateInterfaceAction,\n} from '../types';\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_notify';\n\nconst NativeNotificationStruct = object({\n type: enumValue(NotificationType.Native),\n message: string(),\n});\n\nconst InAppNotificationStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n});\n\nconst InAppNotificationWithDetailsStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n content: ComponentOrElementStruct,\n title: string(),\n footerLink: optional(\n object({\n href: string(),\n text: string(),\n }),\n ),\n});\n\nconst NotificationParametersStruct = union([\n InAppNotificationStruct,\n InAppNotificationWithDetailsStruct,\n NativeNotificationStruct,\n]);\n\nexport type NotificationArgs = InferMatching<\n typeof NotificationParametersStruct,\n NotifyParams\n>;\n\nexport type NotifyMethodHooks = {\n isOnPhishingList: (url: string) => boolean;\n\n maybeUpdatePhishingList: () => Promise<void>;\n};\n\nexport type NotifyMessengerActions =\n | RateLimitControllerCallAction\n | SnapControllerGetSnapAction\n | SnapInterfaceControllerCreateInterfaceAction;\n\ntype SpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: NotifyMethodHooks;\n messenger: Messenger<string, NotifyMessengerActions>;\n};\n\ntype Specification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_notify` permission.\n * `snap_notify` allows snaps to send multiple types of notifications to its users.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.messenger - The messenger.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_notify` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n SpecificationBuilderOptions,\n Specification\n> = ({\n allowedCaveats = null,\n methodHooks,\n messenger,\n}: SpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getImplementation({ methodHooks, messenger }),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<NotifyMethodHooks> = {\n isOnPhishingList: true,\n maybeUpdatePhishingList: true,\n};\n\n/**\n * Display a\n * [notification](https://docs.metamask.io/snaps/features/notifications/) in\n * MetaMask or natively in the OS. Snaps can trigger a short (up to 80\n * characters) notification message for actionable or time sensitive\n * information. `inApp` notifications can also include an optional\n * [expanded view](https://docs.metamask.io/snaps/features/notifications/#expanded-view).\n * The expanded view has a title, content, and optional footer link shown when\n * a user clicks on the notification.\n *\n * @example Basic in app notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'inApp',\n * message: 'This is an in-app notification',\n * },\n * });\n * ```\n *\n * @example Expandable in app notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'inApp',\n * message: 'This is an in-app notification',\n * title: 'Notification Title',\n * content: (\n * <Box>\n * <Text>This is the expanded content of the notification.</Text>\n * </Box>\n * ),\n * footerLink: {\n * href: 'https://example.com',\n * text: 'Click here for more info',\n * },\n * },\n * });\n * ```\n *\n * @example Native notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'native',\n * message: 'This is a native notification',\n * },\n * });\n * ```\n */\nexport const notifyBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n actionNames: [\n 'RateLimitController:call',\n 'SnapController:getSnap',\n 'SnapInterfaceController:createInterface',\n ],\n} as const);\n\n/**\n * Builds the method implementation for `snap_notify`.\n *\n * @param options - The options.\n * @param options.messenger - The messenger.\n * @param options.methodHooks - The RPC method hooks.\n * @param options.methodHooks.isOnPhishingList - A function that checks for links against the phishing list.\n * @param options.methodHooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\n * @returns The method implementation which returns `null` on success.\n * @throws If the params are invalid.\n */\nexport function getImplementation({\n methodHooks: { isOnPhishingList, maybeUpdatePhishingList },\n messenger,\n}: SpecificationBuilderOptions) {\n return async function implementation(\n args: RestrictedMethodOptions<NotifyParams>,\n ): Promise<NotifyResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n await maybeUpdatePhishingList();\n\n const validatedParams = getValidatedParams(\n params,\n isOnPhishingList,\n messenger,\n );\n\n if (hasProperty(validatedParams, 'content')) {\n const id = messenger.call(\n 'SnapInterfaceController:createInterface',\n origin,\n validatedParams.content as ComponentOrElement,\n undefined,\n ContentType.Notification,\n );\n validatedParams.content = id;\n }\n\n switch (validatedParams.type) {\n case NotificationType.Native:\n return (await messenger.call(\n 'RateLimitController:call',\n origin,\n 'showNativeNotification',\n origin,\n validatedParams.message,\n )) as NotifyResult;\n case NotificationType.InApp: {\n const { content, message, title, footerLink } =\n validatedParams as NotificationArgs & {\n content?: string;\n title?: string;\n footerLink?: { href: string; text: string };\n };\n return (await messenger.call(\n 'RateLimitController:call',\n origin,\n 'showInAppNotification',\n origin,\n {\n interfaceId: content,\n message,\n title,\n footerLink,\n },\n )) as NotifyResult;\n }\n /* istanbul ignore next */\n default:\n return assertExhaustive(validatedParams.type as never);\n }\n };\n}\n\n/**\n * Validates the notify method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @param isOnPhishingList - The function that checks for links against the phishing list.\n * @param messenger - The messenger.\n * @returns The validated method parameter object.\n * @throws If the params are invalid.\n */\nexport function getValidatedParams(\n params: unknown,\n isOnPhishingList: NotifyMethodHooks['isOnPhishingList'],\n messenger: Messenger<string, NotifyMessengerActions>,\n): NotifyParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { type, message } = params;\n\n if (\n !type ||\n typeof type !== 'string' ||\n !Object.values(NotificationType).includes(type as NotificationType)\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n\n const isNotString = !message || typeof message !== 'string';\n // Set to the max message length on a Mac notification for now.\n if (\n type === NotificationType.Native &&\n (isNotString || message.length >= 50)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n if (\n type === NotificationType.InApp &&\n (isNotString || message.length >= 500)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 500 characters long.',\n });\n }\n\n try {\n const validatedParams = createUnion(\n params,\n NotificationParametersStruct,\n 'type',\n );\n\n const getSnap = (snapId: string) =>\n messenger.call('SnapController:getSnap', snapId);\n\n validateTextLinks(validatedParams.message, isOnPhishingList, getSnap);\n\n if (hasProperty(validatedParams, 'footerLink')) {\n validateLink(validatedParams.footerLink.href, isOnPhishingList, getSnap);\n }\n\n return validatedParams;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
package/dist/types.cjs ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.cjs.map