@metamask/snaps-jest 4.0.0 → 5.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 (217) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/README.md +66 -179
  3. package/dist/cjs/environment.js +21 -82
  4. package/dist/cjs/environment.js.map +1 -1
  5. package/dist/cjs/helpers.js +118 -43
  6. package/dist/cjs/helpers.js.map +1 -1
  7. package/dist/cjs/internals/environment.js +1 -1
  8. package/dist/cjs/internals/environment.js.map +1 -1
  9. package/dist/cjs/internals/index.js +1 -4
  10. package/dist/cjs/internals/index.js.map +1 -1
  11. package/dist/cjs/internals/request.js +42 -94
  12. package/dist/cjs/internals/request.js.map +1 -1
  13. package/dist/cjs/internals/server.js +0 -4
  14. package/dist/cjs/internals/server.js.map +1 -1
  15. package/dist/cjs/internals/simulation/constants.js +29 -0
  16. package/dist/cjs/internals/simulation/constants.js.map +1 -0
  17. package/dist/cjs/internals/simulation/controllers.js +95 -0
  18. package/dist/cjs/internals/simulation/controllers.js.map +1 -0
  19. package/dist/cjs/internals/simulation/files.js +22 -0
  20. package/dist/cjs/internals/simulation/files.js.map +1 -0
  21. package/dist/cjs/internals/simulation/index.js +24 -0
  22. package/dist/cjs/internals/simulation/index.js.map +1 -0
  23. package/dist/cjs/internals/simulation/interface.js +98 -0
  24. package/dist/cjs/internals/simulation/interface.js.map +1 -0
  25. package/dist/cjs/internals/simulation/methods/constants.js +84 -0
  26. package/dist/cjs/internals/simulation/methods/constants.js.map +1 -0
  27. package/dist/cjs/internals/simulation/methods/hooks/encryption.js +33 -0
  28. package/dist/cjs/internals/simulation/methods/hooks/encryption.js.map +1 -0
  29. package/dist/cjs/internals/simulation/methods/hooks/get-locale.js +17 -0
  30. package/dist/cjs/internals/simulation/methods/hooks/get-locale.js.map +1 -0
  31. package/dist/cjs/internals/simulation/methods/hooks/index.js +25 -0
  32. package/dist/cjs/internals/simulation/methods/hooks/index.js.map +1 -0
  33. package/dist/cjs/internals/simulation/methods/hooks/interface.js +26 -0
  34. package/dist/cjs/internals/simulation/methods/hooks/interface.js.map +1 -0
  35. package/dist/cjs/internals/simulation/methods/hooks/notifications.js +66 -0
  36. package/dist/cjs/internals/simulation/methods/hooks/notifications.js.map +1 -0
  37. package/dist/cjs/internals/simulation/methods/hooks/show-dialog.js +43 -0
  38. package/dist/cjs/internals/simulation/methods/hooks/show-dialog.js.map +1 -0
  39. package/dist/cjs/internals/simulation/methods/hooks/state.js +80 -0
  40. package/dist/cjs/internals/simulation/methods/hooks/state.js.map +1 -0
  41. package/dist/cjs/internals/simulation/methods/index.js +20 -0
  42. package/dist/cjs/internals/simulation/methods/index.js.map +1 -0
  43. package/dist/cjs/internals/simulation/methods/specifications.js +81 -0
  44. package/dist/cjs/internals/simulation/methods/specifications.js.map +1 -0
  45. package/dist/cjs/internals/simulation/middleware/engine.js +31 -0
  46. package/dist/cjs/internals/simulation/middleware/engine.js.map +1 -0
  47. package/dist/cjs/internals/simulation/middleware/index.js +20 -0
  48. package/dist/cjs/internals/simulation/middleware/index.js.map +1 -0
  49. package/dist/cjs/internals/simulation/middleware/internal-methods/accounts.js +30 -0
  50. package/dist/cjs/internals/simulation/middleware/internal-methods/accounts.js.map +1 -0
  51. package/dist/cjs/internals/simulation/middleware/internal-methods/index.js +20 -0
  52. package/dist/cjs/internals/simulation/middleware/internal-methods/index.js.map +1 -0
  53. package/dist/cjs/internals/simulation/middleware/internal-methods/middleware.js +37 -0
  54. package/dist/cjs/internals/simulation/middleware/internal-methods/middleware.js.map +1 -0
  55. package/dist/cjs/internals/simulation/middleware/internal-methods/provider-state.js +23 -0
  56. package/dist/cjs/internals/simulation/middleware/internal-methods/provider-state.js.map +1 -0
  57. package/dist/cjs/internals/simulation/middleware/mock.js +23 -0
  58. package/dist/cjs/internals/simulation/middleware/mock.js.map +1 -0
  59. package/dist/cjs/internals/simulation/options.js +24 -0
  60. package/dist/cjs/internals/simulation/options.js.map +1 -0
  61. package/dist/cjs/internals/simulation/simulation.js +124 -0
  62. package/dist/cjs/internals/simulation/simulation.js.map +1 -0
  63. package/dist/cjs/internals/simulation/store/index.js +23 -0
  64. package/dist/cjs/internals/simulation/store/index.js.map +1 -0
  65. package/dist/cjs/internals/simulation/store/mocks.js +52 -0
  66. package/dist/cjs/internals/simulation/store/mocks.js.map +1 -0
  67. package/dist/cjs/internals/simulation/store/notifications.js +52 -0
  68. package/dist/cjs/internals/simulation/store/notifications.js.map +1 -0
  69. package/dist/cjs/internals/simulation/store/state.js +64 -0
  70. package/dist/cjs/internals/simulation/store/state.js.map +1 -0
  71. package/dist/cjs/internals/simulation/store/store.js +57 -0
  72. package/dist/cjs/internals/simulation/store/store.js.map +1 -0
  73. package/dist/cjs/internals/simulation/store/ui.js +48 -0
  74. package/dist/cjs/internals/simulation/store/ui.js.map +1 -0
  75. package/dist/cjs/internals/structs.js +47 -5
  76. package/dist/cjs/internals/structs.js.map +1 -1
  77. package/dist/cjs/matchers.js +5 -2
  78. package/dist/cjs/matchers.js.map +1 -1
  79. package/dist/cjs/options.js +0 -6
  80. package/dist/cjs/options.js.map +1 -1
  81. package/dist/esm/environment.js +22 -83
  82. package/dist/esm/environment.js.map +1 -1
  83. package/dist/esm/helpers.js +127 -46
  84. package/dist/esm/helpers.js.map +1 -1
  85. package/dist/esm/internals/environment.js +1 -1
  86. package/dist/esm/internals/environment.js.map +1 -1
  87. package/dist/esm/internals/index.js +1 -5
  88. package/dist/esm/internals/index.js.map +1 -1
  89. package/dist/esm/internals/request.js +61 -104
  90. package/dist/esm/internals/request.js.map +1 -1
  91. package/dist/esm/internals/server.js +1 -5
  92. package/dist/esm/internals/server.js.map +1 -1
  93. package/dist/esm/internals/simulation/constants.js +12 -0
  94. package/dist/esm/internals/simulation/constants.js.map +1 -0
  95. package/dist/esm/internals/simulation/controllers.js +90 -0
  96. package/dist/esm/internals/simulation/controllers.js.map +1 -0
  97. package/dist/esm/internals/simulation/files.js +19 -0
  98. package/dist/esm/internals/simulation/files.js.map +1 -0
  99. package/dist/esm/internals/simulation/index.js +7 -0
  100. package/dist/esm/internals/simulation/index.js.map +1 -0
  101. package/dist/esm/internals/simulation/interface.js +95 -0
  102. package/dist/esm/internals/simulation/interface.js.map +1 -0
  103. package/dist/esm/internals/simulation/methods/constants.js +69 -0
  104. package/dist/esm/internals/simulation/methods/constants.js.map +1 -0
  105. package/dist/esm/internals/simulation/methods/hooks/encryption.js +39 -0
  106. package/dist/esm/internals/simulation/methods/hooks/encryption.js.map +1 -0
  107. package/dist/esm/internals/simulation/methods/hooks/get-locale.js +13 -0
  108. package/dist/esm/internals/simulation/methods/hooks/get-locale.js.map +1 -0
  109. package/dist/esm/internals/simulation/methods/hooks/index.js +8 -0
  110. package/dist/esm/internals/simulation/methods/hooks/index.js.map +1 -0
  111. package/dist/esm/internals/simulation/methods/hooks/interface.js +18 -0
  112. package/dist/esm/internals/simulation/methods/hooks/interface.js.map +1 -0
  113. package/dist/esm/internals/simulation/methods/hooks/notifications.js +58 -0
  114. package/dist/esm/internals/simulation/methods/hooks/notifications.js.map +1 -0
  115. package/dist/esm/internals/simulation/methods/hooks/show-dialog.js +38 -0
  116. package/dist/esm/internals/simulation/methods/hooks/show-dialog.js.map +1 -0
  117. package/dist/esm/internals/simulation/methods/hooks/state.js +74 -0
  118. package/dist/esm/internals/simulation/methods/hooks/state.js.map +1 -0
  119. package/dist/esm/internals/simulation/methods/index.js +3 -0
  120. package/dist/esm/internals/simulation/methods/index.js.map +1 -0
  121. package/dist/esm/internals/simulation/methods/specifications.js +84 -0
  122. package/dist/esm/internals/simulation/methods/specifications.js.map +1 -0
  123. package/dist/esm/internals/simulation/middleware/engine.js +33 -0
  124. package/dist/esm/internals/simulation/middleware/engine.js.map +1 -0
  125. package/dist/esm/internals/simulation/middleware/index.js +3 -0
  126. package/dist/esm/internals/simulation/middleware/index.js.map +1 -0
  127. package/dist/esm/internals/simulation/middleware/internal-methods/accounts.js +31 -0
  128. package/dist/esm/internals/simulation/middleware/internal-methods/accounts.js.map +1 -0
  129. package/dist/esm/internals/simulation/middleware/internal-methods/index.js +3 -0
  130. package/dist/esm/internals/simulation/middleware/internal-methods/index.js.map +1 -0
  131. package/dist/esm/internals/simulation/middleware/internal-methods/middleware.js +37 -0
  132. package/dist/esm/internals/simulation/middleware/internal-methods/middleware.js.map +1 -0
  133. package/dist/esm/internals/simulation/middleware/internal-methods/provider-state.js +23 -0
  134. package/dist/esm/internals/simulation/middleware/internal-methods/provider-state.js.map +1 -0
  135. package/dist/esm/internals/simulation/middleware/mock.js +18 -0
  136. package/dist/esm/internals/simulation/middleware/mock.js.map +1 -0
  137. package/dist/esm/internals/simulation/options.js +20 -0
  138. package/dist/esm/internals/simulation/options.js.map +1 -0
  139. package/dist/esm/internals/simulation/simulation.js +128 -0
  140. package/dist/esm/internals/simulation/simulation.js.map +1 -0
  141. package/dist/esm/internals/simulation/store/index.js +6 -0
  142. package/dist/esm/internals/simulation/store/index.js.map +1 -0
  143. package/dist/esm/internals/simulation/store/mocks.js +32 -0
  144. package/dist/esm/internals/simulation/store/mocks.js.map +1 -0
  145. package/dist/esm/internals/simulation/store/notifications.js +30 -0
  146. package/dist/esm/internals/simulation/store/notifications.js.map +1 -0
  147. package/dist/esm/internals/simulation/store/state.js +47 -0
  148. package/dist/esm/internals/simulation/store/state.js.map +1 -0
  149. package/dist/esm/internals/simulation/store/store.js +50 -0
  150. package/dist/esm/internals/simulation/store/store.js.map +1 -0
  151. package/dist/esm/internals/simulation/store/ui.js +21 -0
  152. package/dist/esm/internals/simulation/store/ui.js.map +1 -0
  153. package/dist/esm/internals/structs.js +41 -5
  154. package/dist/esm/internals/structs.js.map +1 -1
  155. package/dist/esm/matchers.js +5 -2
  156. package/dist/esm/matchers.js.map +1 -1
  157. package/dist/esm/options.js +1 -7
  158. package/dist/esm/options.js.map +1 -1
  159. package/dist/esm/types.js.map +1 -1
  160. package/dist/types/environment.d.ts +14 -15
  161. package/dist/types/helpers.d.ts +64 -3
  162. package/dist/types/internals/index.d.ts +1 -4
  163. package/dist/types/internals/request.d.ts +38 -56
  164. package/dist/types/internals/simulation/constants.d.ts +13 -0
  165. package/dist/types/internals/simulation/controllers.d.ts +40 -0
  166. package/dist/types/internals/simulation/files.d.ts +11 -0
  167. package/dist/types/internals/simulation/index.d.ts +5 -0
  168. package/dist/types/internals/simulation/interface.d.ts +25 -0
  169. package/dist/types/internals/simulation/methods/constants.d.ts +10 -0
  170. package/dist/types/internals/simulation/methods/hooks/encryption.d.ts +29 -0
  171. package/dist/types/internals/simulation/methods/hooks/get-locale.d.ts +9 -0
  172. package/dist/types/internals/simulation/methods/hooks/index.d.ts +6 -0
  173. package/dist/types/internals/simulation/methods/hooks/interface.d.ts +16 -0
  174. package/dist/types/internals/simulation/methods/hooks/notifications.d.ts +16 -0
  175. package/dist/types/internals/simulation/methods/hooks/show-dialog.d.ts +9 -0
  176. package/dist/types/internals/simulation/methods/hooks/state.d.ts +22 -0
  177. package/dist/types/internals/simulation/methods/index.d.ts +1 -0
  178. package/dist/types/internals/simulation/methods/specifications.d.ts +56 -0
  179. package/dist/types/internals/simulation/middleware/engine.d.ts +26 -0
  180. package/dist/types/internals/simulation/middleware/index.d.ts +1 -0
  181. package/dist/types/internals/simulation/middleware/internal-methods/accounts.d.ts +18 -0
  182. package/dist/types/internals/simulation/middleware/internal-methods/index.d.ts +1 -0
  183. package/dist/types/internals/simulation/middleware/internal-methods/middleware.d.ts +22 -0
  184. package/dist/types/internals/simulation/middleware/internal-methods/provider-state.d.ts +14 -0
  185. package/dist/types/internals/simulation/middleware/mock.d.ts +10 -0
  186. package/dist/types/internals/simulation/options.d.ts +37 -0
  187. package/dist/types/internals/simulation/simulation.d.ts +98 -0
  188. package/dist/types/internals/simulation/store/index.d.ts +4 -0
  189. package/dist/types/internals/simulation/store/mocks.d.ts +35 -0
  190. package/dist/types/internals/simulation/store/notifications.d.ts +44 -0
  191. package/dist/types/internals/simulation/store/state.d.ts +55 -0
  192. package/dist/types/internals/simulation/store/store.d.ts +22 -0
  193. package/dist/types/internals/simulation/store/ui.d.ts +25 -0
  194. package/dist/types/internals/structs.d.ts +229 -16
  195. package/dist/types/options.d.ts +3 -35
  196. package/dist/types/types.d.ts +88 -41
  197. package/package.json +21 -12
  198. package/dist/cjs/internals/interface.js +0 -103
  199. package/dist/cjs/internals/interface.js.map +0 -1
  200. package/dist/cjs/internals/network.js +0 -148
  201. package/dist/cjs/internals/network.js.map +0 -1
  202. package/dist/cjs/internals/types.js +0 -6
  203. package/dist/cjs/internals/types.js.map +0 -1
  204. package/dist/cjs/internals/wait-for.js +0 -63
  205. package/dist/cjs/internals/wait-for.js.map +0 -1
  206. package/dist/esm/internals/interface.js +0 -100
  207. package/dist/esm/internals/interface.js.map +0 -1
  208. package/dist/esm/internals/network.js +0 -143
  209. package/dist/esm/internals/network.js.map +0 -1
  210. package/dist/esm/internals/types.js +0 -3
  211. package/dist/esm/internals/types.js.map +0 -1
  212. package/dist/esm/internals/wait-for.js +0 -63
  213. package/dist/esm/internals/wait-for.js.map +0 -1
  214. package/dist/types/internals/interface.d.ts +0 -25
  215. package/dist/types/internals/network.d.ts +0 -87
  216. package/dist/types/internals/types.d.ts +0 -18
  217. package/dist/types/internals/wait-for.d.ts +0 -38
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/internals/simulation/methods/constants.ts"],"sourcesContent":["export const EXCLUDED_SNAP_ENDOWMENTS = [];\n\nexport const EXCLUDED_SNAP_PERMISSIONS = [];\n\n/**\n * All unrestricted methods recognized by the `PermissionController`.\n * Unrestricted methods are ignored by the permission system, but every\n * JSON-RPC request seen by the permission system must correspond to a\n * restricted or unrestricted method, or the request will be rejected with a\n * \"method not found\" error.\n */\nexport const UNRESTRICTED_METHODS = Object.freeze([\n 'eth_blockNumber',\n 'eth_call',\n 'eth_chainId',\n 'eth_coinbase',\n 'eth_decrypt',\n 'eth_estimateGas',\n 'eth_feeHistory',\n 'eth_gasPrice',\n 'eth_getBalance',\n 'eth_getBlockByHash',\n 'eth_getBlockByNumber',\n 'eth_getBlockTransactionCountByHash',\n 'eth_getBlockTransactionCountByNumber',\n 'eth_getCode',\n 'eth_getEncryptionPublicKey',\n 'eth_getFilterChanges',\n 'eth_getFilterLogs',\n 'eth_getLogs',\n 'eth_getProof',\n 'eth_getStorageAt',\n 'eth_getTransactionByBlockHashAndIndex',\n 'eth_getTransactionByBlockNumberAndIndex',\n 'eth_getTransactionByHash',\n 'eth_getTransactionCount',\n 'eth_getTransactionReceipt',\n 'eth_getUncleByBlockHashAndIndex',\n 'eth_getUncleByBlockNumberAndIndex',\n 'eth_getUncleCountByBlockHash',\n 'eth_getUncleCountByBlockNumber',\n 'eth_getWork',\n 'eth_hashrate',\n 'eth_mining',\n 'eth_newBlockFilter',\n 'eth_newFilter',\n 'eth_newPendingTransactionFilter',\n 'eth_protocolVersion',\n 'eth_sendRawTransaction',\n 'eth_sendTransaction',\n 'eth_sign',\n 'eth_signTypedData',\n 'eth_signTypedData_v1',\n 'eth_signTypedData_v3',\n 'eth_signTypedData_v4',\n 'eth_submitHashrate',\n 'eth_submitWork',\n 'eth_syncing',\n 'eth_uninstallFilter',\n 'metamask_getProviderState',\n 'metamask_watchAsset',\n 'net_listening',\n 'net_peerCount',\n 'net_version',\n 'personal_ecRecover',\n 'personal_sign',\n 'wallet_watchAsset',\n 'web3_clientVersion',\n 'web3_sha3',\n]);\n"],"names":["EXCLUDED_SNAP_ENDOWMENTS","EXCLUDED_SNAP_PERMISSIONS","UNRESTRICTED_METHODS","Object","freeze"],"mappings":"AAAA,OAAO,MAAMA,2BAA2B,EAAE,CAAC;AAE3C,OAAO,MAAMC,4BAA4B,EAAE,CAAC;AAE5C;;;;;;CAMC,GACD,OAAO,MAAMC,uBAAuBC,OAAOC,MAAM,CAAC;IAChD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,EAAE"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Mocks encrypting a value using a password. This is not a real encryption
3
+ * method, but rather is used to simulate encryption in the tests.
4
+ *
5
+ * Ideally we would use a real encryption method, such as
6
+ * `@metamask/browser-passworder`, but it doesn't seem to work with Node.js 18
7
+ * without some mocking. We can switch to a real encryption method once we
8
+ * drop support for Node.js 18.
9
+ *
10
+ * @param password - The password to use.
11
+ * @param value - The value to encrypt.
12
+ * @returns The "encrypted" value.
13
+ */ export function encryptImplementation(password, value) {
14
+ return JSON.stringify({
15
+ password,
16
+ value
17
+ });
18
+ }
19
+ /**
20
+ * Mocks decrypting a value using a password. This is not a real encryption
21
+ * method, but rather is used to simulate encryption in the tests.
22
+ *
23
+ * Ideally we would use a real decryption method, such as
24
+ * `@metamask/browser-passworder`, but it doesn't seem to work with Node.js 18
25
+ * without some mocking. We can switch to a real encryption method once we
26
+ * drop support for Node.js 18.
27
+ *
28
+ * @param password - The password to use.
29
+ * @param value - The value to decrypt.
30
+ * @returns The "decrypted" value.
31
+ */ export function decryptImplementation(password, value) {
32
+ const decryptedValue = JSON.parse(value);
33
+ if (decryptedValue.password !== password) {
34
+ throw new Error('Incorrect password. This is a bug in `@metamask/snaps-jest`, please report it.');
35
+ }
36
+ return decryptedValue.value;
37
+ }
38
+
39
+ //# sourceMappingURL=encryption.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/encryption.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\n\n/**\n * Mocks encrypting a value using a password. This is not a real encryption\n * method, but rather is used to simulate encryption in the tests.\n *\n * Ideally we would use a real encryption method, such as\n * `@metamask/browser-passworder`, but it doesn't seem to work with Node.js 18\n * without some mocking. We can switch to a real encryption method once we\n * drop support for Node.js 18.\n *\n * @param password - The password to use.\n * @param value - The value to encrypt.\n * @returns The \"encrypted\" value.\n */\nexport function encryptImplementation(password: string, value: Json) {\n return JSON.stringify({\n password,\n value,\n });\n}\n\n/**\n * Mocks decrypting a value using a password. This is not a real encryption\n * method, but rather is used to simulate encryption in the tests.\n *\n * Ideally we would use a real decryption method, such as\n * `@metamask/browser-passworder`, but it doesn't seem to work with Node.js 18\n * without some mocking. We can switch to a real encryption method once we\n * drop support for Node.js 18.\n *\n * @param password - The password to use.\n * @param value - The value to decrypt.\n * @returns The \"decrypted\" value.\n */\nexport function decryptImplementation(password: string, value: string) {\n const decryptedValue = JSON.parse(value);\n if (decryptedValue.password !== password) {\n throw new Error(\n 'Incorrect password. This is a bug in `@metamask/snaps-jest`, please report it.',\n );\n }\n\n return decryptedValue.value;\n}\n"],"names":["encryptImplementation","password","value","JSON","stringify","decryptImplementation","decryptedValue","parse","Error"],"mappings":"AAEA;;;;;;;;;;;;CAYC,GACD,OAAO,SAASA,sBAAsBC,QAAgB,EAAEC,KAAW;IACjE,OAAOC,KAAKC,SAAS,CAAC;QACpBH;QACAC;IACF;AACF;AAEA;;;;;;;;;;;;CAYC,GACD,OAAO,SAASG,sBAAsBJ,QAAgB,EAAEC,KAAa;IACnE,MAAMI,iBAAiBH,KAAKI,KAAK,CAACL;IAClC,IAAII,eAAeL,QAAQ,KAAKA,UAAU;QACxC,MAAM,IAAIO,MACR;IAEJ;IAEA,OAAOF,eAAeJ,KAAK;AAC7B"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Get the implementation of the `getLocale` hook.
3
+ *
4
+ * @param options - The simulation options.
5
+ * @param options.locale - The locale to use.
6
+ * @returns The implementation of the `getLocale` hook.
7
+ */ export function getGetLocaleMethodImplementation({ locale }) {
8
+ return async ()=>{
9
+ return locale;
10
+ };
11
+ }
12
+
13
+ //# sourceMappingURL=get-locale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/get-locale.ts"],"sourcesContent":["import type { SimulationOptions } from '../../options';\n\n/**\n * Get the implementation of the `getLocale` hook.\n *\n * @param options - The simulation options.\n * @param options.locale - The locale to use.\n * @returns The implementation of the `getLocale` hook.\n */\nexport function getGetLocaleMethodImplementation({\n locale,\n}: SimulationOptions) {\n return async () => {\n return locale;\n };\n}\n"],"names":["getGetLocaleMethodImplementation","locale"],"mappings":"AAEA;;;;;;CAMC,GACD,OAAO,SAASA,iCAAiC,EAC/CC,MAAM,EACY;IAClB,OAAO;QACL,OAAOA;IACT;AACF"}
@@ -0,0 +1,8 @@
1
+ export * from './encryption';
2
+ export * from './get-locale';
3
+ export * from './notifications';
4
+ export * from './show-dialog';
5
+ export * from './state';
6
+ export * from './interface';
7
+
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/index.ts"],"sourcesContent":["export * from './encryption';\nexport * from './get-locale';\nexport * from './notifications';\nexport * from './show-dialog';\nexport * from './state';\nexport * from './interface';\n"],"names":[],"mappings":"AAAA,cAAc,eAAe;AAC7B,cAAc,eAAe;AAC7B,cAAc,kBAAkB;AAChC,cAAc,gBAAgB;AAC9B,cAAc,UAAU;AACxB,cAAc,cAAc"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Get the implementation of the `createInterface` hook.
3
+ *
4
+ * @param controllerMessenger - The controller messenger used to call actions.
5
+ * @returns The implementation of the `createInterface` hook.
6
+ */ export function getCreateInterfaceImplementation(controllerMessenger) {
7
+ return async (snapId, content)=>controllerMessenger.call('SnapInterfaceController:createInterface', snapId, content);
8
+ }
9
+ /**
10
+ * Get the implementation of the `getInterface` hook.
11
+ *
12
+ * @param controllerMessenger - The controller messenger used to call actions.
13
+ * @returns The implementation of the `getInterface` hook.
14
+ */ export function getGetInterfaceImplementation(controllerMessenger) {
15
+ return (snapId, id)=>controllerMessenger.call('SnapInterfaceController:getInterface', snapId, id);
16
+ }
17
+
18
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/interface.ts"],"sourcesContent":["import type { Component, SnapId } from '@metamask/snaps-sdk';\n\nimport type { RootControllerMessenger } from '../../controllers';\n\n/**\n * Get the implementation of the `createInterface` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `createInterface` hook.\n */\nexport function getCreateInterfaceImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return async (snapId: SnapId, content: Component) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n content,\n );\n}\n\n/**\n * Get the implementation of the `getInterface` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `getInterface` hook.\n */\nexport function getGetInterfaceImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return (snapId: SnapId, id: string) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n}\n"],"names":["getCreateInterfaceImplementation","controllerMessenger","snapId","content","call","getGetInterfaceImplementation","id"],"mappings":"AAIA;;;;;CAKC,GACD,OAAO,SAASA,iCACdC,mBAA4C;IAE5C,OAAO,OAAOC,QAAgBC,UAC5BF,oBAAoBG,IAAI,CACtB,2CACAF,QACAC;AAEN;AAEA;;;;;CAKC,GACD,OAAO,SAASE,8BACdJ,mBAA4C;IAE5C,OAAO,CAACC,QAAgBI,KACtBL,oBAAoBG,IAAI,CACtB,wCACAF,QACAI;AAEN"}
@@ -0,0 +1,58 @@
1
+ import { NotificationType } from '@metamask/snaps-sdk';
2
+ import { nanoid } from '@reduxjs/toolkit';
3
+ import { put } from 'redux-saga/effects';
4
+ import { addNotification } from '../../store';
5
+ /**
6
+ * Show a native notification to the user.
7
+ *
8
+ * @param _snapId - The ID of the Snap that created the notification.
9
+ * @param options - The notification options.
10
+ * @param options.message - The message to show in the notification.
11
+ * @yields Adds the notification to the store.
12
+ * @returns `null`.
13
+ */ function* showNativeNotificationImplementation(_snapId, { message }) {
14
+ yield put(addNotification({
15
+ id: nanoid(),
16
+ type: NotificationType.Native,
17
+ message
18
+ }));
19
+ return null;
20
+ }
21
+ /**
22
+ * Get a method that can be used to show a native notification.
23
+ *
24
+ * @param runSaga - A function to run a saga outside the usual Redux flow.
25
+ * @returns A method that can be used to show a native notification.
26
+ */ export function getShowNativeNotificationImplementation(runSaga) {
27
+ return async (...args)=>{
28
+ return await runSaga(showNativeNotificationImplementation, ...args).toPromise();
29
+ };
30
+ }
31
+ /**
32
+ * Show an in-app notification to the user.
33
+ *
34
+ * @param _snapId - The ID of the Snap that created the notification.
35
+ * @param options - The notification options.
36
+ * @param options.message - The message to show in the notification.
37
+ * @yields Adds the notification to the store.
38
+ * @returns `null`.
39
+ */ function* showInAppNotificationImplementation(_snapId, { message }) {
40
+ yield put(addNotification({
41
+ id: nanoid(),
42
+ type: NotificationType.InApp,
43
+ message
44
+ }));
45
+ return null;
46
+ }
47
+ /**
48
+ * Get a method that can be used to show an in-app notification.
49
+ *
50
+ * @param runSaga - A function to run a saga outside the usual Redux flow.
51
+ * @returns A method that can be used to show an in-app notification.
52
+ */ export function getShowInAppNotificationImplementation(runSaga) {
53
+ return async (...args)=>{
54
+ return await runSaga(showInAppNotificationImplementation, ...args).toPromise();
55
+ };
56
+ }
57
+
58
+ //# sourceMappingURL=notifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/notifications.ts"],"sourcesContent":["import type { NotifyParams } from '@metamask/snaps-sdk';\nimport { NotificationType } from '@metamask/snaps-sdk';\nimport { nanoid } from '@reduxjs/toolkit';\nimport type { SagaIterator } from 'redux-saga';\nimport { put } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { addNotification } from '../../store';\n\n/**\n * Show a native notification to the user.\n *\n * @param _snapId - The ID of the Snap that created the notification.\n * @param options - The notification options.\n * @param options.message - The message to show in the notification.\n * @yields Adds the notification to the store.\n * @returns `null`.\n */\nfunction* showNativeNotificationImplementation(\n _snapId: string,\n { message }: NotifyParams,\n): SagaIterator {\n yield put(\n addNotification({ id: nanoid(), type: NotificationType.Native, message }),\n );\n\n return null;\n}\n\n/**\n * Get a method that can be used to show a native notification.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @returns A method that can be used to show a native notification.\n */\nexport function getShowNativeNotificationImplementation(\n runSaga: RunSagaFunction,\n) {\n return async (\n ...args: Parameters<typeof showNativeNotificationImplementation>\n ) => {\n return await runSaga(\n showNativeNotificationImplementation,\n ...args,\n ).toPromise();\n };\n}\n\n/**\n * Show an in-app notification to the user.\n *\n * @param _snapId - The ID of the Snap that created the notification.\n * @param options - The notification options.\n * @param options.message - The message to show in the notification.\n * @yields Adds the notification to the store.\n * @returns `null`.\n */\nfunction* showInAppNotificationImplementation(\n _snapId: string,\n { message }: NotifyParams,\n): SagaIterator<null> {\n yield put(\n addNotification({ id: nanoid(), type: NotificationType.InApp, message }),\n );\n\n return null;\n}\n\n/**\n * Get a method that can be used to show an in-app notification.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @returns A method that can be used to show an in-app notification.\n */\nexport function getShowInAppNotificationImplementation(\n runSaga: RunSagaFunction,\n) {\n return async (\n ...args: Parameters<typeof showInAppNotificationImplementation>\n ) => {\n return await runSaga(\n showInAppNotificationImplementation,\n ...args,\n ).toPromise();\n };\n}\n"],"names":["NotificationType","nanoid","put","addNotification","showNativeNotificationImplementation","_snapId","message","id","type","Native","getShowNativeNotificationImplementation","runSaga","args","toPromise","showInAppNotificationImplementation","InApp","getShowInAppNotificationImplementation"],"mappings":"AACA,SAASA,gBAAgB,QAAQ,sBAAsB;AACvD,SAASC,MAAM,QAAQ,mBAAmB;AAE1C,SAASC,GAAG,QAAQ,qBAAqB;AAGzC,SAASC,eAAe,QAAQ,cAAc;AAE9C;;;;;;;;CAQC,GACD,UAAUC,qCACRC,OAAe,EACf,EAAEC,OAAO,EAAgB;IAEzB,MAAMJ,IACJC,gBAAgB;QAAEI,IAAIN;QAAUO,MAAMR,iBAAiBS,MAAM;QAAEH;IAAQ;IAGzE,OAAO;AACT;AAEA;;;;;CAKC,GACD,OAAO,SAASI,wCACdC,OAAwB;IAExB,OAAO,OACL,GAAGC;QAEH,OAAO,MAAMD,QACXP,yCACGQ,MACHC,SAAS;IACb;AACF;AAEA;;;;;;;;CAQC,GACD,UAAUC,oCACRT,OAAe,EACf,EAAEC,OAAO,EAAgB;IAEzB,MAAMJ,IACJC,gBAAgB;QAAEI,IAAIN;QAAUO,MAAMR,iBAAiBe,KAAK;QAAET;IAAQ;IAGxE,OAAO;AACT;AAEA;;;;;CAKC,GACD,OAAO,SAASU,uCACdL,OAAwB;IAExB,OAAO,OACL,GAAGC;QAEH,OAAO,MAAMD,QACXG,wCACGF,MACHC,SAAS;IACb;AACF"}
@@ -0,0 +1,38 @@
1
+ import { put, take } from 'redux-saga/effects';
2
+ import { resolveInterface, setInterface, closeInterface } from '../../store';
3
+ /**
4
+ * Show a dialog to the user. This will wait for `resolveUserInterface` to be
5
+ * dispatched before returning.
6
+ *
7
+ * @param _snapId - The ID of the Snap that created the dialog. This is ignored
8
+ * because the simulator only supports one Snap.
9
+ * @param type - The type of dialog to show.
10
+ * @param id - The interface ID.
11
+ * @param _placeholder - The placeholder text to show in the dialog. This is
12
+ * not implemented yet.
13
+ * @yields Sets the dialog in the store, waits for the user to resolve the
14
+ * dialog, and closes the dialog.
15
+ * @returns The result of the dialog.
16
+ */ function* showDialogImplementation(_snapId, type, id, _placeholder) {
17
+ yield put(setInterface({
18
+ type,
19
+ id
20
+ }));
21
+ // We use `take` to wait for `resolveUserInterface` to be dispatched, which
22
+ // indicates that the user has resolved the dialog.
23
+ const { payload } = yield take(resolveInterface.type);
24
+ yield put(closeInterface());
25
+ return payload;
26
+ }
27
+ /**
28
+ * Get the implementation of the `showDialog` hook.
29
+ *
30
+ * @param runSaga - The function to run a saga outside the usual Redux flow.
31
+ * @returns The implementation of the `showDialog` hook.
32
+ */ export function getShowDialogImplementation(runSaga) {
33
+ return async (...args)=>{
34
+ return await runSaga(showDialogImplementation, ...args).toPromise();
35
+ };
36
+ }
37
+
38
+ //# sourceMappingURL=show-dialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/show-dialog.ts"],"sourcesContent":["import type { DialogType } from '@metamask/snaps-sdk';\nimport type { SagaIterator } from 'redux-saga';\nimport { put, take } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { resolveInterface, setInterface, closeInterface } from '../../store';\n\n/**\n * Show a dialog to the user. This will wait for `resolveUserInterface` to be\n * dispatched before returning.\n *\n * @param _snapId - The ID of the Snap that created the dialog. This is ignored\n * because the simulator only supports one Snap.\n * @param type - The type of dialog to show.\n * @param id - The interface ID.\n * @param _placeholder - The placeholder text to show in the dialog. This is\n * not implemented yet.\n * @yields Sets the dialog in the store, waits for the user to resolve the\n * dialog, and closes the dialog.\n * @returns The result of the dialog.\n */\nfunction* showDialogImplementation(\n _snapId: string,\n type: DialogType,\n id: string,\n _placeholder?: string,\n): SagaIterator<unknown> {\n yield put(setInterface({ type, id }));\n\n // We use `take` to wait for `resolveUserInterface` to be dispatched, which\n // indicates that the user has resolved the dialog.\n const { payload } = yield take(resolveInterface.type);\n yield put(closeInterface());\n\n return payload;\n}\n\n/**\n * Get the implementation of the `showDialog` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `showDialog` hook.\n */\nexport function getShowDialogImplementation(runSaga: RunSagaFunction) {\n return async (...args: Parameters<typeof showDialogImplementation>) => {\n return await runSaga(showDialogImplementation, ...args).toPromise();\n };\n}\n"],"names":["put","take","resolveInterface","setInterface","closeInterface","showDialogImplementation","_snapId","type","id","_placeholder","payload","getShowDialogImplementation","runSaga","args","toPromise"],"mappings":"AAEA,SAASA,GAAG,EAAEC,IAAI,QAAQ,qBAAqB;AAG/C,SAASC,gBAAgB,EAAEC,YAAY,EAAEC,cAAc,QAAQ,cAAc;AAE7E;;;;;;;;;;;;;CAaC,GACD,UAAUC,yBACRC,OAAe,EACfC,IAAgB,EAChBC,EAAU,EACVC,YAAqB;IAErB,MAAMT,IAAIG,aAAa;QAAEI;QAAMC;IAAG;IAElC,2EAA2E;IAC3E,mDAAmD;IACnD,MAAM,EAAEE,OAAO,EAAE,GAAG,MAAMT,KAAKC,iBAAiBK,IAAI;IACpD,MAAMP,IAAII;IAEV,OAAOM;AACT;AAEA;;;;;CAKC,GACD,OAAO,SAASC,4BAA4BC,OAAwB;IAClE,OAAO,OAAO,GAAGC;QACf,OAAO,MAAMD,QAAQP,6BAA6BQ,MAAMC,SAAS;IACnE;AACF"}
@@ -0,0 +1,74 @@
1
+ import { put, select } from 'redux-saga/effects';
2
+ import { clearState, getState, setState } from '../../store';
3
+ /**
4
+ * Get the Snap state from the store.
5
+ *
6
+ * @param _snapId - The ID of the Snap to get the state for. This is ignored
7
+ * because the simulator only supports one Snap.
8
+ * @param encrypted - Whether to get the encrypted or unencrypted state.
9
+ * Defaults to encrypted state.
10
+ * @returns The state of the Snap.
11
+ * @yields Selects the state from the store.
12
+ */ function* getSnapStateImplementation(_snapId, encrypted = true) {
13
+ return yield select(getState(encrypted));
14
+ }
15
+ /**
16
+ * Get the implementation of the `getSnapState` hook.
17
+ *
18
+ * @param runSaga - The function to run a saga outside the usual Redux flow.
19
+ * @returns The implementation of the `getSnapState` hook.
20
+ */ export function getGetSnapStateMethodImplementation(runSaga) {
21
+ return (...args)=>{
22
+ return runSaga(getSnapStateImplementation, ...args).result();
23
+ };
24
+ }
25
+ /**
26
+ * Update the Snap state in the store.
27
+ *
28
+ * @param _snapId - The ID of the Snap to update the state for. This is ignored
29
+ * because the simulator only supports one Snap.
30
+ * @param newState - The new state.
31
+ * @param encrypted - Whether to update the encrypted or unencrypted state.
32
+ * Defaults to encrypted state.
33
+ * @yields Puts the new state in the store.
34
+ */ function* updateSnapStateImplementation(_snapId, newState, encrypted = true) {
35
+ yield put(setState({
36
+ state: newState,
37
+ encrypted
38
+ }));
39
+ }
40
+ /**
41
+ * Get the implementation of the `updateSnapState` hook.
42
+ *
43
+ * @param runSaga - The function to run a saga outside the usual Redux flow.
44
+ * @returns The implementation of the `updateSnapState` hook.
45
+ */ export function getUpdateSnapStateMethodImplementation(runSaga) {
46
+ return (...args)=>{
47
+ runSaga(updateSnapStateImplementation, ...args).result();
48
+ };
49
+ }
50
+ /**
51
+ * Clear the Snap state in the store.
52
+ *
53
+ * @param _snapId - The ID of the Snap to clear the state for. This is ignored
54
+ * because the simulator only supports one Snap.
55
+ * @param encrypted - Whether to clear the encrypted or unencrypted state.
56
+ * Defaults to encrypted state.
57
+ * @yields Puts the new state in the store.
58
+ */ function* clearSnapStateImplementation(_snapId, encrypted = true) {
59
+ yield put(clearState({
60
+ encrypted
61
+ }));
62
+ }
63
+ /**
64
+ * Get the implementation of the `clearSnapState` hook.
65
+ *
66
+ * @param runSaga - The function to run a saga outside the usual Redux flow.
67
+ * @returns The implementation of the `clearSnapState` hook.
68
+ */ export function getClearSnapStateMethodImplementation(runSaga) {
69
+ return async (...args)=>{
70
+ runSaga(clearSnapStateImplementation, ...args).result();
71
+ };
72
+ }
73
+
74
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/internals/simulation/methods/hooks/state.ts"],"sourcesContent":["import type { SagaIterator } from 'redux-saga';\nimport { put, select } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { clearState, getState, setState } from '../../store';\n\n/**\n * Get the Snap state from the store.\n *\n * @param _snapId - The ID of the Snap to get the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param encrypted - Whether to get the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @returns The state of the Snap.\n * @yields Selects the state from the store.\n */\nfunction* getSnapStateImplementation(\n _snapId: string,\n encrypted = true,\n): SagaIterator<string> {\n return yield select(getState(encrypted));\n}\n\n/**\n * Get the implementation of the `getSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `getSnapState` hook.\n */\nexport function getGetSnapStateMethodImplementation(runSaga: RunSagaFunction) {\n return (...args: Parameters<typeof getSnapStateImplementation>) => {\n return runSaga(getSnapStateImplementation, ...args).result();\n };\n}\n\n/**\n * Update the Snap state in the store.\n *\n * @param _snapId - The ID of the Snap to update the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param newState - The new state.\n * @param encrypted - Whether to update the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @yields Puts the new state in the store.\n */\nfunction* updateSnapStateImplementation(\n _snapId: string,\n newState: string,\n encrypted = true,\n): SagaIterator<void> {\n yield put(setState({ state: newState, encrypted }));\n}\n\n/**\n * Get the implementation of the `updateSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `updateSnapState` hook.\n */\nexport function getUpdateSnapStateMethodImplementation(\n runSaga: RunSagaFunction,\n) {\n return (...args: Parameters<typeof updateSnapStateImplementation>) => {\n runSaga(updateSnapStateImplementation, ...args).result();\n };\n}\n\n/**\n * Clear the Snap state in the store.\n *\n * @param _snapId - The ID of the Snap to clear the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param encrypted - Whether to clear the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @yields Puts the new state in the store.\n */\nfunction* clearSnapStateImplementation(\n _snapId: string,\n encrypted = true,\n): SagaIterator<void> {\n yield put(clearState({ encrypted }));\n}\n\n/**\n * Get the implementation of the `clearSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `clearSnapState` hook.\n */\nexport function getClearSnapStateMethodImplementation(\n runSaga: RunSagaFunction,\n) {\n return async (...args: Parameters<typeof clearSnapStateImplementation>) => {\n runSaga(clearSnapStateImplementation, ...args).result();\n };\n}\n"],"names":["put","select","clearState","getState","setState","getSnapStateImplementation","_snapId","encrypted","getGetSnapStateMethodImplementation","runSaga","args","result","updateSnapStateImplementation","newState","state","getUpdateSnapStateMethodImplementation","clearSnapStateImplementation","getClearSnapStateMethodImplementation"],"mappings":"AACA,SAASA,GAAG,EAAEC,MAAM,QAAQ,qBAAqB;AAGjD,SAASC,UAAU,EAAEC,QAAQ,EAAEC,QAAQ,QAAQ,cAAc;AAE7D;;;;;;;;;CASC,GACD,UAAUC,2BACRC,OAAe,EACfC,YAAY,IAAI;IAEhB,OAAO,MAAMN,OAAOE,SAASI;AAC/B;AAEA;;;;;CAKC,GACD,OAAO,SAASC,oCAAoCC,OAAwB;IAC1E,OAAO,CAAC,GAAGC;QACT,OAAOD,QAAQJ,+BAA+BK,MAAMC,MAAM;IAC5D;AACF;AAEA;;;;;;;;;CASC,GACD,UAAUC,8BACRN,OAAe,EACfO,QAAgB,EAChBN,YAAY,IAAI;IAEhB,MAAMP,IAAII,SAAS;QAAEU,OAAOD;QAAUN;IAAU;AAClD;AAEA;;;;;CAKC,GACD,OAAO,SAASQ,uCACdN,OAAwB;IAExB,OAAO,CAAC,GAAGC;QACTD,QAAQG,kCAAkCF,MAAMC,MAAM;IACxD;AACF;AAEA;;;;;;;;CAQC,GACD,UAAUK,6BACRV,OAAe,EACfC,YAAY,IAAI;IAEhB,MAAMP,IAAIE,WAAW;QAAEK;IAAU;AACnC;AAEA;;;;;CAKC,GACD,OAAO,SAASU,sCACdR,OAAwB;IAExB,OAAO,OAAO,GAAGC;QACfD,QAAQO,iCAAiCN,MAAMC,MAAM;IACvD;AACF"}
@@ -0,0 +1,3 @@
1
+ export * from './specifications';
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/internals/simulation/methods/index.ts"],"sourcesContent":["export * from './specifications';\n"],"names":[],"mappings":"AAAA,cAAc,mBAAmB"}
@@ -0,0 +1,84 @@
1
+ import { endowmentPermissionBuilders, buildSnapEndowmentSpecifications, buildSnapRestrictedMethodSpecifications } from '@metamask/snaps-rpc-methods';
2
+ import { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';
3
+ import { EXCLUDED_SNAP_ENDOWMENTS, EXCLUDED_SNAP_PERMISSIONS } from './constants';
4
+ import { getGetLocaleMethodImplementation, getClearSnapStateMethodImplementation, getGetSnapStateMethodImplementation, getUpdateSnapStateMethodImplementation, getShowDialogImplementation, getShowInAppNotificationImplementation, getShowNativeNotificationImplementation, encryptImplementation, decryptImplementation, getCreateInterfaceImplementation, getGetInterfaceImplementation } from './hooks';
5
+ /**
6
+ * Get a function which resolves with the specified result.
7
+ *
8
+ * @param result - The result to return.
9
+ * @returns The function implementation.
10
+ */ export function resolve(result) {
11
+ return ()=>result;
12
+ }
13
+ /**
14
+ * Get a function which resolves with the specified result.
15
+ *
16
+ * @param result - The result to return. If not specified, the function will
17
+ * resolve with `undefined`.
18
+ * @returns The function implementation.
19
+ */ export function asyncResolve(result) {
20
+ return async ()=>result;
21
+ }
22
+ /**
23
+ * Get the permission specifications for the Snap.
24
+ *
25
+ * @param options - The options.
26
+ * @param options.controllerMessenger - The controller messenger.
27
+ * @param options.hooks - The hooks.
28
+ * @param options.runSaga - The function to run a saga outside the usual Redux
29
+ * flow.
30
+ * @param options.options - The simulation options.
31
+ * @returns The permission specifications for the Snap.
32
+ */ export function getPermissionSpecifications({ controllerMessenger, hooks, runSaga, options }) {
33
+ return {
34
+ ...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),
35
+ ...buildSnapRestrictedMethodSpecifications(EXCLUDED_SNAP_PERMISSIONS, {
36
+ // Shared hooks.
37
+ ...hooks,
38
+ // Encryption and decryption hooks.
39
+ // TODO: Swap these out for the real implementations.
40
+ encrypt: encryptImplementation,
41
+ decrypt: decryptImplementation,
42
+ // Snaps-specific hooks.
43
+ clearSnapState: getClearSnapStateMethodImplementation(runSaga),
44
+ getLocale: getGetLocaleMethodImplementation(options),
45
+ getSnapState: getGetSnapStateMethodImplementation(runSaga),
46
+ getUnlockPromise: asyncResolve(true),
47
+ // TODO: Allow the user to specify the result of this function.
48
+ isOnPhishingList: resolve(false),
49
+ maybeUpdatePhishingList: asyncResolve(),
50
+ showDialog: getShowDialogImplementation(runSaga),
51
+ showInAppNotification: getShowInAppNotificationImplementation(runSaga),
52
+ showNativeNotification: getShowNativeNotificationImplementation(runSaga),
53
+ updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),
54
+ createInterface: getCreateInterfaceImplementation(controllerMessenger),
55
+ getInterface: getGetInterfaceImplementation(controllerMessenger)
56
+ })
57
+ };
58
+ }
59
+ /**
60
+ * Get the endowments for the Snap.
61
+ *
62
+ * @param permissionController - The permission controller.
63
+ * @param snapId - The ID of the Snap.
64
+ * @returns The endowments for the Snap.
65
+ */ export async function getEndowments(permissionController, snapId) {
66
+ const allEndowments = await Object.keys(endowmentPermissionBuilders).reduce(async (promise, permissionName)=>{
67
+ const accumulator = await promise;
68
+ if (permissionController.hasPermission(snapId, permissionName)) {
69
+ const endowments = await permissionController.getEndowments(snapId, permissionName);
70
+ if (endowments) {
71
+ return accumulator.concat(endowments);
72
+ }
73
+ }
74
+ return accumulator;
75
+ }, Promise.resolve([]));
76
+ return [
77
+ ...new Set([
78
+ ...DEFAULT_ENDOWMENTS,
79
+ ...allEndowments
80
+ ])
81
+ ];
82
+ }
83
+
84
+ //# sourceMappingURL=specifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/internals/simulation/methods/specifications.ts"],"sourcesContent":["import type { GenericPermissionController } from '@metamask/permission-controller';\nimport {\n endowmentPermissionBuilders,\n buildSnapEndowmentSpecifications,\n buildSnapRestrictedMethodSpecifications,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';\n\nimport type { RootControllerMessenger } from '../controllers';\nimport type { SimulationOptions } from '../options';\nimport type { RunSagaFunction } from '../store';\nimport {\n EXCLUDED_SNAP_ENDOWMENTS,\n EXCLUDED_SNAP_PERMISSIONS,\n} from './constants';\nimport {\n getGetLocaleMethodImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getShowDialogImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n encryptImplementation,\n decryptImplementation,\n getCreateInterfaceImplementation,\n getGetInterfaceImplementation,\n} from './hooks';\n\nexport type PermissionSpecificationsHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n};\n\nexport type GetPermissionSpecificationsOptions = {\n controllerMessenger: RootControllerMessenger;\n hooks: PermissionSpecificationsHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return.\n * @returns The function implementation.\n */\nexport function resolve(result: unknown) {\n return () => result;\n}\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return. If not specified, the function will\n * resolve with `undefined`.\n * @returns The function implementation.\n */\nexport function asyncResolve(result?: unknown) {\n return async () => result;\n}\n\n/**\n * Get the permission specifications for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.hooks - The hooks.\n * @param options.runSaga - The function to run a saga outside the usual Redux\n * flow.\n * @param options.options - The simulation options.\n * @returns The permission specifications for the Snap.\n */\nexport function getPermissionSpecifications({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n}: GetPermissionSpecificationsOptions) {\n return {\n ...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),\n ...buildSnapRestrictedMethodSpecifications(EXCLUDED_SNAP_PERMISSIONS, {\n // Shared hooks.\n ...hooks,\n\n // Encryption and decryption hooks.\n // TODO: Swap these out for the real implementations.\n encrypt: encryptImplementation,\n decrypt: decryptImplementation,\n\n // Snaps-specific hooks.\n clearSnapState: getClearSnapStateMethodImplementation(runSaga),\n getLocale: getGetLocaleMethodImplementation(options),\n getSnapState: getGetSnapStateMethodImplementation(runSaga),\n getUnlockPromise: asyncResolve(true),\n\n // TODO: Allow the user to specify the result of this function.\n isOnPhishingList: resolve(false),\n\n maybeUpdatePhishingList: asyncResolve(),\n showDialog: getShowDialogImplementation(runSaga),\n showInAppNotification: getShowInAppNotificationImplementation(runSaga),\n showNativeNotification: getShowNativeNotificationImplementation(runSaga),\n updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),\n createInterface: getCreateInterfaceImplementation(controllerMessenger),\n getInterface: getGetInterfaceImplementation(controllerMessenger),\n }),\n };\n}\n\n/**\n * Get the endowments for the Snap.\n *\n * @param permissionController - The permission controller.\n * @param snapId - The ID of the Snap.\n * @returns The endowments for the Snap.\n */\nexport async function getEndowments(\n permissionController: GenericPermissionController,\n snapId: SnapId,\n) {\n const allEndowments = await Object.keys(endowmentPermissionBuilders).reduce<\n Promise<string[]>\n >(async (promise, permissionName) => {\n const accumulator = await promise;\n if (permissionController.hasPermission(snapId, permissionName)) {\n const endowments = await permissionController.getEndowments(\n snapId,\n permissionName,\n );\n\n if (endowments) {\n return accumulator.concat(endowments as string[]);\n }\n }\n\n return accumulator;\n }, Promise.resolve([]));\n\n return [...new Set([...DEFAULT_ENDOWMENTS, ...allEndowments])];\n}\n"],"names":["endowmentPermissionBuilders","buildSnapEndowmentSpecifications","buildSnapRestrictedMethodSpecifications","DEFAULT_ENDOWMENTS","EXCLUDED_SNAP_ENDOWMENTS","EXCLUDED_SNAP_PERMISSIONS","getGetLocaleMethodImplementation","getClearSnapStateMethodImplementation","getGetSnapStateMethodImplementation","getUpdateSnapStateMethodImplementation","getShowDialogImplementation","getShowInAppNotificationImplementation","getShowNativeNotificationImplementation","encryptImplementation","decryptImplementation","getCreateInterfaceImplementation","getGetInterfaceImplementation","resolve","result","asyncResolve","getPermissionSpecifications","controllerMessenger","hooks","runSaga","options","encrypt","decrypt","clearSnapState","getLocale","getSnapState","getUnlockPromise","isOnPhishingList","maybeUpdatePhishingList","showDialog","showInAppNotification","showNativeNotification","updateSnapState","createInterface","getInterface","getEndowments","permissionController","snapId","allEndowments","Object","keys","reduce","promise","permissionName","accumulator","hasPermission","endowments","concat","Promise","Set"],"mappings":"AACA,SACEA,2BAA2B,EAC3BC,gCAAgC,EAChCC,uCAAuC,QAClC,8BAA8B;AAErC,SAASC,kBAAkB,QAAQ,wBAAwB;AAK3D,SACEC,wBAAwB,EACxBC,yBAAyB,QACpB,cAAc;AACrB,SACEC,gCAAgC,EAChCC,qCAAqC,EACrCC,mCAAmC,EACnCC,sCAAsC,EACtCC,2BAA2B,EAC3BC,sCAAsC,EACtCC,uCAAuC,EACvCC,qBAAqB,EACrBC,qBAAqB,EACrBC,gCAAgC,EAChCC,6BAA6B,QACxB,UAAU;AAkBjB;;;;;CAKC,GACD,OAAO,SAASC,QAAQC,MAAe;IACrC,OAAO,IAAMA;AACf;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,aAAaD,MAAgB;IAC3C,OAAO,UAAYA;AACrB;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASE,4BAA4B,EAC1CC,mBAAmB,EACnBC,KAAK,EACLC,OAAO,EACPC,OAAO,EAC4B;IACnC,OAAO;QACL,GAAGvB,iCAAiCG,yBAAyB;QAC7D,GAAGF,wCAAwCG,2BAA2B;YACpE,gBAAgB;YAChB,GAAGiB,KAAK;YAER,mCAAmC;YACnC,qDAAqD;YACrDG,SAASZ;YACTa,SAASZ;YAET,wBAAwB;YACxBa,gBAAgBpB,sCAAsCgB;YACtDK,WAAWtB,iCAAiCkB;YAC5CK,cAAcrB,oCAAoCe;YAClDO,kBAAkBX,aAAa;YAE/B,+DAA+D;YAC/DY,kBAAkBd,QAAQ;YAE1Be,yBAAyBb;YACzBc,YAAYvB,4BAA4Ba;YACxCW,uBAAuBvB,uCAAuCY;YAC9DY,wBAAwBvB,wCAAwCW;YAChEa,iBAAiB3B,uCAAuCc;YACxDc,iBAAiBtB,iCAAiCM;YAClDiB,cAActB,8BAA8BK;QAC9C,EAAE;IACJ;AACF;AAEA;;;;;;CAMC,GACD,OAAO,eAAekB,cACpBC,oBAAiD,EACjDC,MAAc;IAEd,MAAMC,gBAAgB,MAAMC,OAAOC,IAAI,CAAC5C,6BAA6B6C,MAAM,CAEzE,OAAOC,SAASC;QAChB,MAAMC,cAAc,MAAMF;QAC1B,IAAIN,qBAAqBS,aAAa,CAACR,QAAQM,iBAAiB;YAC9D,MAAMG,aAAa,MAAMV,qBAAqBD,aAAa,CACzDE,QACAM;YAGF,IAAIG,YAAY;gBACd,OAAOF,YAAYG,MAAM,CAACD;YAC5B;QACF;QAEA,OAAOF;IACT,GAAGI,QAAQnC,OAAO,CAAC,EAAE;IAErB,OAAO;WAAI,IAAIoC,IAAI;eAAIlD;eAAuBuC;SAAc;KAAE;AAChE"}
@@ -0,0 +1,33 @@
1
+ import { createFetchMiddleware } from '@metamask/eth-json-rpc-middleware';
2
+ import { JsonRpcEngine } from '@metamask/json-rpc-engine';
3
+ import { createSnapsMethodMiddleware } from '@metamask/snaps-rpc-methods';
4
+ import { DEFAULT_JSON_RPC_ENDPOINT } from '../constants';
5
+ import { createInternalMethodsMiddleware } from './internal-methods';
6
+ import { createMockMiddleware } from './mock';
7
+ /**
8
+ * Create a JSON-RPC engine for use in a simulated environment. This engine
9
+ * should be used to handle all JSON-RPC requests. It is set up to handle
10
+ * requests that would normally be handled internally by the MetaMask client, as
11
+ * well as Snap-specific requests.
12
+ *
13
+ * @param options - The options to use when creating the engine.
14
+ * @param options.store - The Redux store to use.
15
+ * @param options.hooks - Any hooks used by the middleware handlers.
16
+ * @param options.permissionMiddleware - The permission middleware to use.
17
+ * @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.
18
+ * @returns A JSON-RPC engine.
19
+ */ export function createJsonRpcEngine({ store, hooks, permissionMiddleware, endpoint = DEFAULT_JSON_RPC_ENDPOINT }) {
20
+ const engine = new JsonRpcEngine();
21
+ engine.push(createMockMiddleware(store));
22
+ engine.push(createInternalMethodsMiddleware(hooks));
23
+ engine.push(createSnapsMethodMiddleware(true, hooks));
24
+ engine.push(permissionMiddleware);
25
+ engine.push(createFetchMiddleware({
26
+ btoa: globalThis.btoa,
27
+ fetch: globalThis.fetch,
28
+ rpcUrl: endpoint
29
+ }));
30
+ return engine;
31
+ }
32
+
33
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/internals/simulation/middleware/engine.ts"],"sourcesContent":["import { createFetchMiddleware } from '@metamask/eth-json-rpc-middleware';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport type { RestrictedMethodParameters } from '@metamask/permission-controller';\nimport { createSnapsMethodMiddleware } from '@metamask/snaps-rpc-methods';\nimport type { Json } from '@metamask/utils';\n\nimport { DEFAULT_JSON_RPC_ENDPOINT } from '../constants';\nimport type { MiddlewareHooks } from '../simulation';\nimport type { Store } from '../store';\nimport { createInternalMethodsMiddleware } from './internal-methods';\nimport { createMockMiddleware } from './mock';\n\nexport type CreateJsonRpcEngineOptions = {\n store: Store;\n hooks: MiddlewareHooks;\n permissionMiddleware: JsonRpcMiddleware<RestrictedMethodParameters, Json>;\n endpoint?: string;\n};\n\n/**\n * Create a JSON-RPC engine for use in a simulated environment. This engine\n * should be used to handle all JSON-RPC requests. It is set up to handle\n * requests that would normally be handled internally by the MetaMask client, as\n * well as Snap-specific requests.\n *\n * @param options - The options to use when creating the engine.\n * @param options.store - The Redux store to use.\n * @param options.hooks - Any hooks used by the middleware handlers.\n * @param options.permissionMiddleware - The permission middleware to use.\n * @param options.endpoint - The JSON-RPC endpoint to use for Ethereum requests.\n * @returns A JSON-RPC engine.\n */\nexport function createJsonRpcEngine({\n store,\n hooks,\n permissionMiddleware,\n endpoint = DEFAULT_JSON_RPC_ENDPOINT,\n}: CreateJsonRpcEngineOptions) {\n const engine = new JsonRpcEngine();\n engine.push(createMockMiddleware(store));\n engine.push(createInternalMethodsMiddleware(hooks));\n engine.push(createSnapsMethodMiddleware(true, hooks));\n engine.push(permissionMiddleware);\n engine.push(\n createFetchMiddleware({\n btoa: globalThis.btoa,\n fetch: globalThis.fetch,\n rpcUrl: endpoint,\n }),\n );\n\n return engine;\n}\n"],"names":["createFetchMiddleware","JsonRpcEngine","createSnapsMethodMiddleware","DEFAULT_JSON_RPC_ENDPOINT","createInternalMethodsMiddleware","createMockMiddleware","createJsonRpcEngine","store","hooks","permissionMiddleware","endpoint","engine","push","btoa","globalThis","fetch","rpcUrl"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,oCAAoC;AAE1E,SAASC,aAAa,QAAQ,4BAA4B;AAE1D,SAASC,2BAA2B,QAAQ,8BAA8B;AAG1E,SAASC,yBAAyB,QAAQ,eAAe;AAGzD,SAASC,+BAA+B,QAAQ,qBAAqB;AACrE,SAASC,oBAAoB,QAAQ,SAAS;AAS9C;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,oBAAoB,EAClCC,KAAK,EACLC,KAAK,EACLC,oBAAoB,EACpBC,WAAWP,yBAAyB,EACT;IAC3B,MAAMQ,SAAS,IAAIV;IACnBU,OAAOC,IAAI,CAACP,qBAAqBE;IACjCI,OAAOC,IAAI,CAACR,gCAAgCI;IAC5CG,OAAOC,IAAI,CAACV,4BAA4B,MAAMM;IAC9CG,OAAOC,IAAI,CAACH;IACZE,OAAOC,IAAI,CACTZ,sBAAsB;QACpBa,MAAMC,WAAWD,IAAI;QACrBE,OAAOD,WAAWC,KAAK;QACvBC,QAAQN;IACV;IAGF,OAAOC;AACT"}
@@ -0,0 +1,3 @@
1
+ export * from './engine';
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/internals/simulation/middleware/index.ts"],"sourcesContent":["export * from './engine';\n"],"names":[],"mappings":"AAAA,cAAc,WAAW"}
@@ -0,0 +1,31 @@
1
+ import { BIP44Node } from '@metamask/key-tree';
2
+ /**
3
+ * A mock handler for account related methods that always returns the first
4
+ * address for the selected secret recovery phrase.
5
+ *
6
+ * @param _request - Incoming JSON-RPC request. This is ignored for this
7
+ * specific handler.
8
+ * @param response - The outgoing JSON-RPC response, modified to return the
9
+ * result.
10
+ * @param _next - The `json-rpc-engine` middleware next handler.
11
+ * @param end - The `json-rpc-engine` middleware end handler.
12
+ * @param hooks - Any hooks required by this handler.
13
+ */ export async function getAccountsHandler(_request, response, _next, end, hooks) {
14
+ const { getMnemonic } = hooks;
15
+ const node = await BIP44Node.fromDerivationPath({
16
+ derivationPath: [
17
+ await getMnemonic(),
18
+ `bip32:44'`,
19
+ `bip32:60'`,
20
+ `bip32:0'`,
21
+ `bip32:0`,
22
+ `bip32:0`
23
+ ]
24
+ });
25
+ response.result = [
26
+ node.address
27
+ ];
28
+ return end();
29
+ }
30
+
31
+ //# sourceMappingURL=accounts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/internals/simulation/middleware/internal-methods/accounts.ts"],"sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport { BIP44Node } from '@metamask/key-tree';\nimport type {\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nexport type GetAccountsHandlerHooks = {\n getMnemonic: () => Promise<Uint8Array>;\n};\n\n/**\n * A mock handler for account related methods that always returns the first\n * address for the selected secret recovery phrase.\n *\n * @param _request - Incoming JSON-RPC request. This is ignored for this\n * specific handler.\n * @param response - The outgoing JSON-RPC response, modified to return the\n * result.\n * @param _next - The `json-rpc-engine` middleware next handler.\n * @param end - The `json-rpc-engine` middleware end handler.\n * @param hooks - Any hooks required by this handler.\n */\nexport async function getAccountsHandler(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<Json>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: GetAccountsHandlerHooks,\n) {\n const { getMnemonic } = hooks;\n\n const node = await BIP44Node.fromDerivationPath({\n derivationPath: [\n await getMnemonic(),\n `bip32:44'`,\n `bip32:60'`,\n `bip32:0'`,\n `bip32:0`,\n `bip32:0`,\n ],\n });\n\n response.result = [node.address];\n return end();\n}\n"],"names":["BIP44Node","getAccountsHandler","_request","response","_next","end","hooks","getMnemonic","node","fromDerivationPath","derivationPath","result","address"],"mappings":"AAIA,SAASA,SAAS,QAAQ,qBAAqB;AAW/C;;;;;;;;;;;CAWC,GACD,OAAO,eAAeC,mBACpBC,QAAwB,EACxBC,QAAsC,EACtCC,KAAgC,EAChCC,GAA6B,EAC7BC,KAA8B;IAE9B,MAAM,EAAEC,WAAW,EAAE,GAAGD;IAExB,MAAME,OAAO,MAAMR,UAAUS,kBAAkB,CAAC;QAC9CC,gBAAgB;YACd,MAAMH;YACN,CAAC,SAAS,CAAC;YACX,CAAC,SAAS,CAAC;YACX,CAAC,QAAQ,CAAC;YACV,CAAC,OAAO,CAAC;YACT,CAAC,OAAO,CAAC;SACV;IACH;IAEAJ,SAASQ,MAAM,GAAG;QAACH,KAAKI,OAAO;KAAC;IAChC,OAAOP;AACT"}
@@ -0,0 +1,3 @@
1
+ export * from './middleware';
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/internals/simulation/middleware/internal-methods/index.ts"],"sourcesContent":["export * from './middleware';\n"],"names":[],"mappings":"AAAA,cAAc,eAAe"}
@@ -0,0 +1,37 @@
1
+ import { logError } from '@metamask/snaps-utils';
2
+ import { getAccountsHandler } from './accounts';
3
+ import { getProviderStateHandler } from './provider-state';
4
+ const methodHandlers = {
5
+ /* eslint-disable @typescript-eslint/naming-convention */ metamask_getProviderState: getProviderStateHandler,
6
+ eth_requestAccounts: getAccountsHandler,
7
+ eth_accounts: getAccountsHandler
8
+ };
9
+ /**
10
+ * Create a middleware for handling JSON-RPC methods normally handled internally
11
+ * by the MetaMask client.
12
+ *
13
+ * NOTE: This middleware provides all `hooks` to all handlers and should
14
+ * therefore NOT be used outside of the simulation environment. It is intended
15
+ * for testing purposes only.
16
+ *
17
+ * @param hooks - Any hooks used by the middleware handlers.
18
+ * @returns A middleware function.
19
+ */ export function createInternalMethodsMiddleware(hooks) {
20
+ // This should probably use createAsyncMiddleware.
21
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
22
+ return async function methodMiddleware(request, response, next, end) {
23
+ const handler = methodHandlers[request.method];
24
+ if (handler) {
25
+ try {
26
+ // Implementations may or may not be async, so we must await them.
27
+ return await handler(request, response, next, end, hooks);
28
+ } catch (error) {
29
+ logError(error);
30
+ return end(error);
31
+ }
32
+ }
33
+ return next();
34
+ };
35
+ }
36
+
37
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/internals/simulation/middleware/internal-methods/middleware.ts"],"sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport { getAccountsHandler } from './accounts';\nimport { getProviderStateHandler } from './provider-state';\n\nexport type InternalMethodsMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n};\n\nconst methodHandlers = {\n /* eslint-disable @typescript-eslint/naming-convention */\n metamask_getProviderState: getProviderStateHandler,\n eth_requestAccounts: getAccountsHandler,\n eth_accounts: getAccountsHandler,\n /* eslint-enable @typescript-eslint/naming-convention */\n};\n\n/**\n * Create a middleware for handling JSON-RPC methods normally handled internally\n * by the MetaMask client.\n *\n * NOTE: This middleware provides all `hooks` to all handlers and should\n * therefore NOT be used outside of the simulation environment. It is intended\n * for testing purposes only.\n *\n * @param hooks - Any hooks used by the middleware handlers.\n * @returns A middleware function.\n */\nexport function createInternalMethodsMiddleware(\n hooks: InternalMethodsMiddlewareHooks,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n // This should probably use createAsyncMiddleware.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return async function methodMiddleware(request, response, next, end) {\n const handler =\n methodHandlers[request.method as keyof typeof methodHandlers];\n if (handler) {\n try {\n // Implementations may or may not be async, so we must await them.\n return await handler(request, response, next, end, hooks);\n } catch (error: any) {\n logError(error);\n return end(error);\n }\n }\n\n return next();\n };\n}\n"],"names":["logError","getAccountsHandler","getProviderStateHandler","methodHandlers","metamask_getProviderState","eth_requestAccounts","eth_accounts","createInternalMethodsMiddleware","hooks","methodMiddleware","request","response","next","end","handler","method","error"],"mappings":"AACA,SAASA,QAAQ,QAAQ,wBAAwB;AAGjD,SAASC,kBAAkB,QAAQ,aAAa;AAChD,SAASC,uBAAuB,QAAQ,mBAAmB;AAW3D,MAAMC,iBAAiB;IACrB,uDAAuD,GACvDC,2BAA2BF;IAC3BG,qBAAqBJ;IACrBK,cAAcL;AAEhB;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASM,gCACdC,KAAqC;IAErC,kDAAkD;IAClD,kEAAkE;IAClE,OAAO,eAAeC,iBAAiBC,OAAO,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,GAAG;QACjE,MAAMC,UACJX,cAAc,CAACO,QAAQK,MAAM,CAAgC;QAC/D,IAAID,SAAS;YACX,IAAI;gBACF,kEAAkE;gBAClE,OAAO,MAAMA,QAAQJ,SAASC,UAAUC,MAAMC,KAAKL;YACrD,EAAE,OAAOQ,OAAY;gBACnBhB,SAASgB;gBACT,OAAOH,IAAIG;YACb;QACF;QAEA,OAAOJ;IACT;AACF"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A mock handler for metamask_getProviderState that always returns a specific
3
+ * hardcoded result.
4
+ *
5
+ * @param _request - Incoming JSON-RPC request. Ignored for this specific
6
+ * handler.
7
+ * @param response - The outgoing JSON-RPC response, modified to return the
8
+ * result.
9
+ * @param _next - The `json-rpc-engine` middleware next handler.
10
+ * @param end - The `json-rpc-engine` middleware end handler.
11
+ */ export async function getProviderStateHandler(_request, response, _next, end) {
12
+ // For now this will return a mocked result, this should probably match
13
+ // whatever network the simulation is using.
14
+ response.result = {
15
+ isUnlocked: true,
16
+ chainId: '0x01',
17
+ networkVersion: '0x01',
18
+ accounts: []
19
+ };
20
+ return end();
21
+ }
22
+
23
+ //# sourceMappingURL=provider-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../src/internals/simulation/middleware/internal-methods/provider-state.ts"],"sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type {\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\n/**\n * A mock handler for metamask_getProviderState that always returns a specific\n * hardcoded result.\n *\n * @param _request - Incoming JSON-RPC request. Ignored for this specific\n * handler.\n * @param response - The outgoing JSON-RPC response, modified to return the\n * result.\n * @param _next - The `json-rpc-engine` middleware next handler.\n * @param end - The `json-rpc-engine` middleware end handler.\n */\nexport async function getProviderStateHandler(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<Json>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n) {\n // For now this will return a mocked result, this should probably match\n // whatever network the simulation is using.\n response.result = {\n isUnlocked: true,\n chainId: '0x01',\n networkVersion: '0x01',\n accounts: [],\n };\n\n return end();\n}\n"],"names":["getProviderStateHandler","_request","response","_next","end","result","isUnlocked","chainId","networkVersion","accounts"],"mappings":"AAUA;;;;;;;;;;CAUC,GACD,OAAO,eAAeA,wBACpBC,QAAwB,EACxBC,QAAsC,EACtCC,KAAgC,EAChCC,GAA6B;IAE7B,uEAAuE;IACvE,4CAA4C;IAC5CF,SAASG,MAAM,GAAG;QAChBC,YAAY;QACZC,SAAS;QACTC,gBAAgB;QAChBC,UAAU,EAAE;IACd;IAEA,OAAOL;AACT"}