@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/simulation.ts"],"sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n} from '@metamask/base-controller';\nimport { ControllerMessenger } from '@metamask/base-controller';\nimport { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport { mnemonicPhraseToBytes } from '@metamask/key-tree';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n fetchSnap,\n detectSnapLocation,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers';\nimport { getEncryptionKey } from '@metamask/snaps-rpc-methods';\nimport type {\n SnapId,\n AuxiliaryFileEncoding,\n Component,\n InterfaceState,\n} from '@metamask/snaps-sdk';\nimport type { FetchedSnapFiles } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport { getEndowments } from './methods';\nimport { createJsonRpcEngine } from './middleware';\nimport type { SimulationOptions, SimulationUserOptions } from './options';\nimport { getOptions } from './options';\nimport type { RunSagaFunction, Store } from './store';\nimport { createStore } from './store';\n\n/**\n * Options for the execution service, without the options that are shared\n * between all execution services.\n *\n * @template Service - The type of the execution service, i.e., the class that\n * creates the execution service.\n */\nexport type ExecutionServiceOptions<\n Service extends new (...args: any[]) => any,\n> = Omit<\n ConstructorParameters<Service>[0],\n keyof ConstructorParameters<typeof AbstractExecutionService<unknown>>[0]\n>;\n\n/**\n * The options for running a Snap in a simulated environment.\n *\n * @property executionService - The execution service to use.\n * @property executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @property options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport type InstallSnapOptions<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService<unknown>\n >,\n> = ExecutionServiceOptions<Service> extends Record<string, never>\n ? {\n executionService: Service;\n executionServiceOptions?: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n }\n : {\n executionService: Service;\n executionServiceOptions: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n };\n\nexport type InstalledSnap = {\n snapId: SnapId;\n store: Store;\n executionService: InstanceType<typeof AbstractExecutionService>;\n controllerMessenger: ControllerMessenger<ActionConstraint, EventConstraint>;\n runSaga: RunSagaFunction;\n};\n\nexport type MiddlewareHooks = {\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 /**\n * A hook that returns the Snap's auxiliary file for the given path.\n *\n * @param path - The path of the auxiliary file to get.\n * @param encoding - The encoding to use when returning the file.\n * @returns The Snap's auxiliary file for the given path.\n */\n getSnapFile: (\n path: string,\n encoding: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n createInterface: (content: Component) => Promise<string>;\n updateInterface: (id: string, content: Component) => Promise<void>;\n getInterfaceState: (id: string) => InterfaceState;\n};\n\n/**\n * Install a Snap in a simulated environment. This will fetch the Snap files,\n * create a Redux store, set up the controllers and JSON-RPC stack, register the\n * Snap, and run the Snap code in the execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport async function handleInstallSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId,\n {\n executionService,\n executionServiceOptions,\n options: rawOptions = {},\n }: Partial<InstallSnapOptions<Service>> = {},\n): Promise<InstalledSnap> {\n const options = getOptions(rawOptions);\n\n // Fetch Snap files.\n const location = detectSnapLocation(snapId, {\n allowLocal: true,\n });\n\n const snapFiles = await fetchSnap(snapId, location);\n\n // Create Redux store.\n const password = await getEncryptionKey({\n mnemonicPhrase: mnemonicPhraseToBytes(options.secretRecoveryPhrase),\n snapId,\n });\n\n const { store, runSaga } = createStore(password, options);\n\n const controllerMessenger = new ControllerMessenger<any, any>();\n\n registerActions(controllerMessenger);\n\n // Set up controllers and JSON-RPC stack.\n const hooks = getHooks(options, snapFiles, snapId, controllerMessenger);\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n store,\n hooks,\n permissionMiddleware: permissionController.createPermissionMiddleware({\n origin: snapId,\n }),\n });\n\n // Create execution service.\n const ExecutionService = executionService ?? NodeThreadExecutionService;\n const service = new ExecutionService({\n ...executionServiceOptions,\n messenger: controllerMessenger.getRestricted({\n name: 'ExecutionService',\n }),\n setupSnapProvider: (_snapId: string, rpcStream: Duplex) => {\n const mux = setupMultiplex(rpcStream, 'snapStream');\n const stream = mux.createStream('metamask-provider');\n const providerStream = createEngineStream({ engine });\n\n // Error function is difficult to test, so we ignore it.\n /* istanbul ignore next 2 */\n pipeline(stream, providerStream, stream, (error: unknown) => {\n if (error) {\n logError(`Provider stream failure.`, error);\n }\n });\n },\n });\n\n // Register the Snap. This sets up the Snap's permissions and subject\n // metadata.\n await registerSnap(snapId, snapFiles.manifest.result, {\n permissionController,\n subjectMetadataController,\n });\n\n // Run the Snap code in the execution service.\n await service.executeSnap({\n snapId,\n sourceCode: snapFiles.sourceCode.toString('utf8'),\n endowments: await getEndowments(permissionController, snapId),\n });\n\n return {\n snapId,\n store,\n executionService: service,\n controllerMessenger,\n runSaga,\n };\n}\n\n/**\n * Get the hooks for the simulation.\n *\n * @param options - The simulation options.\n * @param snapFiles - The Snap files.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The hooks for the simulation.\n */\nexport function getHooks(\n options: SimulationOptions,\n snapFiles: FetchedSnapFiles,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): MiddlewareHooks {\n return {\n getMnemonic: async () =>\n Promise.resolve(mnemonicPhraseToBytes(options.secretRecoveryPhrase)),\n getSnapFile: async (path: string, encoding: AuxiliaryFileEncoding) =>\n await getSnapFile(snapFiles.auxiliaryFiles, path, encoding),\n getIsLocked: () => false,\n createInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n ...args,\n ),\n updateInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterface',\n snapId,\n ...args,\n ),\n getInterfaceState: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).state,\n };\n}\n\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n */\nexport function registerActions(controllerMessenger: RootControllerMessenger) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:maybeUpdateState',\n async () => Promise.resolve(),\n );\n\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: 'all' }),\n );\n}\n"],"names":["handleInstallSnap","getHooks","registerActions","snapId","executionService","executionServiceOptions","options","rawOptions","getOptions","location","detectSnapLocation","allowLocal","snapFiles","fetchSnap","password","getEncryptionKey","mnemonicPhrase","mnemonicPhraseToBytes","secretRecoveryPhrase","store","runSaga","createStore","controllerMessenger","ControllerMessenger","hooks","subjectMetadataController","permissionController","getControllers","engine","createJsonRpcEngine","permissionMiddleware","createPermissionMiddleware","origin","ExecutionService","NodeThreadExecutionService","service","messenger","getRestricted","name","setupSnapProvider","_snapId","rpcStream","mux","setupMultiplex","stream","createStream","providerStream","createEngineStream","pipeline","error","logError","registerSnap","manifest","result","executeSnap","sourceCode","toString","endowments","getEndowments","getMnemonic","Promise","resolve","getSnapFile","path","encoding","auxiliaryFiles","getIsLocked","createInterface","args","call","updateInterface","getInterfaceState","state","registerActionHandler","type"],"mappings":";;;;;;;;;;;IAiIsBA,iBAAiB;eAAjBA;;IAyGNC,QAAQ;eAARA;;IAsCAC,eAAe;eAAfA;;;gCA5QoB;yCACD;yBACG;kCAO/B;iCAC0B;4BAQR;gCAEA;6BAGoB;uBACjB;yBACE;4BACM;yBAET;uBAEC;AA+FrB,eAAeF,kBAKpBG,MAAc,EACd,EACEC,gBAAgB,EAChBC,uBAAuB,EACvBC,SAASC,aAAa,CAAC,CAAC,EACa,GAAG,CAAC,CAAC;IAE5C,MAAMD,UAAUE,IAAAA,mBAAU,EAACD;IAE3B,oBAAoB;IACpB,MAAME,WAAWC,IAAAA,oCAAkB,EAACP,QAAQ;QAC1CQ,YAAY;IACd;IAEA,MAAMC,YAAY,MA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M,EAAE;QACpD3B;QACAD;IACF;IAEA,8CAA8C;IAC9C,MAAMU,QAAQmB,WAAW,CAAC;QACxBnD;QACAoD,YAAY3C,UAAU2C,UAAU,CAACC,QAAQ,CAAC;QAC1CC,YAAY,MAAMC,IAAAA,sBAAa,EAAChC,sBAAsBvB;IACxD;IAEA,OAAO;QACLA;QACAgB;QACAf,kBAAkB+B;QAClBb;QACAF;IACF;AACF;AAWO,SAASnB,SACdK,OAA0B,EAC1BM,SAA2B,EAC3BT,MAAc,EACdmB,mBAA4C;IAE5C,OAAO;QACLqC,aAAa,UACXC,QAAQC,OAAO,CAAC5C,IAAAA,8BAAqB,EAACX,QAAQY,oBAAoB;QACpE4C,aAAa,OAAOC,MAAcC,WAChC,MAAMF,IAAAA,kBAAW,EAAClD,UAAUqD,cAAc,EAAEF,MAAMC;QACpDE,aAAa,IAAM;QACnBC,iBAAiB,OAAO,GAAGC,OACzB9C,oBAAoB+C,IAAI,CACtB,2CACAlE,WACGiE;QAEPE,iBAAiB,OAAO,GAAGF,OACzB9C,oBAAoB+C,IAAI,CACtB,2CACAlE,WACGiE;QAEPG,mBAAmB,CAAC,GAAGH,OACrB9C,oBAAoB+C,IAAI,CACtB,wCACAlE,WACGiE,MACHI,KAAK;IACX;AACF;AAOO,SAAStE,gBAAgBoB,mBAA4C;IAC1EA,oBAAoBmD,qBAAqB,CACvC,uCACA,UAAYb,QAAQC,OAAO;IAG7BvC,oBAAoBmD,qBAAqB,CACvC,iCACA,IAAO,CAAA;YAAEpB,QAAQ;YAAOqB,MAAM;QAAM,CAAA;AAExC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./notifications"), exports);
6
+ _export_star(require("./state"), exports);
7
+ _export_star(require("./store"), exports);
8
+ _export_star(require("./ui"), exports);
9
+ function _export_star(from, to) {
10
+ Object.keys(from).forEach(function(k) {
11
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
12
+ Object.defineProperty(to, k, {
13
+ enumerable: true,
14
+ get: function() {
15
+ return from[k];
16
+ }
17
+ });
18
+ }
19
+ });
20
+ return from;
21
+ }
22
+
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/internals/simulation/store/index.ts"],"sourcesContent":["export * from './notifications';\nexport * from './state';\nexport * from './store';\nexport * from './ui';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ mocksSlice: function() {
13
+ return mocksSlice;
14
+ },
15
+ addJsonRpcMock: function() {
16
+ return addJsonRpcMock;
17
+ },
18
+ removeJsonRpcMock: function() {
19
+ return removeJsonRpcMock;
20
+ },
21
+ getJsonRpcMocks: function() {
22
+ return getJsonRpcMocks;
23
+ },
24
+ getJsonRpcMock: function() {
25
+ return getJsonRpcMock;
26
+ }
27
+ });
28
+ const _toolkit = require("@reduxjs/toolkit");
29
+ /**
30
+ * The initial notifications state.
31
+ */ const INITIAL_STATE = {
32
+ jsonRpc: {}
33
+ };
34
+ const mocksSlice = (0, _toolkit.createSlice)({
35
+ name: 'mocks',
36
+ initialState: INITIAL_STATE,
37
+ reducers: {
38
+ addJsonRpcMock: (state, action)=>{
39
+ // @ts-expect-error - TS2589: Type instantiation is excessively deep and
40
+ // possibly infinite.
41
+ state.jsonRpc[action.payload.method] = action.payload.result;
42
+ },
43
+ removeJsonRpcMock: (state, action)=>{
44
+ delete state.jsonRpc[action.payload];
45
+ }
46
+ }
47
+ });
48
+ const { addJsonRpcMock, removeJsonRpcMock } = mocksSlice.actions;
49
+ const getJsonRpcMocks = (state)=>state.mocks.jsonRpc;
50
+ const getJsonRpcMock = (0, _toolkit.createSelector)(getJsonRpcMocks, (_, method)=>method, (jsonRpcMocks, method)=>jsonRpcMocks[method]);
51
+
52
+ //# sourceMappingURL=mocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/internals/simulation/store/mocks.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\nexport type JsonRpcMock = {\n method: string;\n result: Json;\n};\n\nexport type MocksState = {\n jsonRpc: Record<string, Json>;\n};\n\n/**\n * The initial notifications state.\n */\nconst INITIAL_STATE: MocksState = {\n jsonRpc: {},\n};\n\nexport const mocksSlice = createSlice({\n name: 'mocks',\n initialState: INITIAL_STATE,\n reducers: {\n addJsonRpcMock: (state, action: PayloadAction<JsonRpcMock>) => {\n // @ts-expect-error - TS2589: Type instantiation is excessively deep and\n // possibly infinite.\n state.jsonRpc[action.payload.method] = action.payload.result;\n },\n removeJsonRpcMock: (state, action: PayloadAction<string>) => {\n delete state.jsonRpc[action.payload];\n },\n },\n});\n\nexport const { addJsonRpcMock, removeJsonRpcMock } = mocksSlice.actions;\n\n/**\n * Get the JSON-RPC mocks from the state.\n *\n * @param state - The application state.\n * @returns The JSON-RPC mocks.\n */\nexport const getJsonRpcMocks = (state: ApplicationState) => state.mocks.jsonRpc;\n\n/**\n * Get the JSON-RPC mock for a given method from the state.\n */\nexport const getJsonRpcMock = createSelector(\n getJsonRpcMocks,\n (_: unknown, method: string) => method,\n (jsonRpcMocks, method) => jsonRpcMocks[method],\n);\n"],"names":["mocksSlice","addJsonRpcMock","removeJsonRpcMock","getJsonRpcMocks","getJsonRpcMock","INITIAL_STATE","jsonRpc","createSlice","name","initialState","reducers","state","action","payload","method","result","actions","mocks","createSelector","_","jsonRpcMocks"],"mappings":";;;;;;;;;;;IAsBaA,UAAU;eAAVA;;IAeEC,cAAc;eAAdA;;IAAgBC,iBAAiB;eAAjBA;;IAQlBC,eAAe;eAAfA;;IAKAC,cAAc;eAAdA;;;yBAhD+B;AAa5C;;CAEC,GACD,MAAMC,gBAA4B;IAChCC,SAAS,CAAC;AACZ;AAEO,MAAMN,aAAaO,IAAAA,oBAAW,EAAC;IACpCC,MAAM;IACNC,cAAcJ;IACdK,UAAU;QACRT,gBAAgB,CAACU,OAAOC;YACtB,wEAAwE;YACxE,qBAAqB;YACrBD,MAAML,OAAO,CAACM,OAAOC,OAAO,CAACC,MAAM,CAAC,GAAGF,OAAOC,OAAO,CAACE,MAAM;QAC9D;QACAb,mBAAmB,CAACS,OAAOC;YACzB,OAAOD,MAAML,OAAO,CAACM,OAAOC,OAAO,CAAC;QACtC;IACF;AACF;AAEO,MAAM,EAAEZ,cAAc,EAAEC,iBAAiB,EAAE,GAAGF,WAAWgB,OAAO;AAQhE,MAAMb,kBAAkB,CAACQ,QAA4BA,MAAMM,KAAK,CAACX,OAAO;AAKxE,MAAMF,iBAAiBc,IAAAA,uBAAc,EAC1Cf,iBACA,CAACgB,GAAYL,SAAmBA,QAChC,CAACM,cAAcN,SAAWM,YAAY,CAACN,OAAO"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ notificationsSlice: function() {
13
+ return notificationsSlice;
14
+ },
15
+ addNotification: function() {
16
+ return addNotification;
17
+ },
18
+ removeNotification: function() {
19
+ return removeNotification;
20
+ },
21
+ clearNotifications: function() {
22
+ return clearNotifications;
23
+ },
24
+ getNotifications: function() {
25
+ return getNotifications;
26
+ }
27
+ });
28
+ const _toolkit = require("@reduxjs/toolkit");
29
+ /**
30
+ * The initial notifications state.
31
+ */ const INITIAL_STATE = {
32
+ notifications: []
33
+ };
34
+ const notificationsSlice = (0, _toolkit.createSlice)({
35
+ name: 'notifications',
36
+ initialState: INITIAL_STATE,
37
+ reducers: {
38
+ addNotification: (state, action)=>{
39
+ state.notifications.push(action.payload);
40
+ },
41
+ removeNotification: (state, action)=>{
42
+ state.notifications = state.notifications.filter((notification)=>notification.id !== action.payload);
43
+ },
44
+ clearNotifications: (state)=>{
45
+ state.notifications = [];
46
+ }
47
+ }
48
+ });
49
+ const { addNotification, removeNotification, clearNotifications } = notificationsSlice.actions;
50
+ const getNotifications = (0, _toolkit.createSelector)((state)=>state.notifications, ({ notifications })=>notifications);
51
+
52
+ //# sourceMappingURL=notifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/internals/simulation/store/notifications.ts"],"sourcesContent":["import type { NotificationType } from '@metamask/snaps-sdk';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\n/**\n * A notification object.\n *\n * @property id - A unique ID for the notification.\n * @property message - The notification message.\n * @property type - The notification type.\n */\nexport type Notification = {\n id: string;\n message: string;\n type: NotificationType;\n};\n\n/**\n * The notifications state.\n *\n * @property notifications - An array of notifications.\n */\nexport type NotificationsState = {\n notifications: Notification[];\n};\n\n/**\n * The initial notifications state.\n */\nconst INITIAL_STATE: NotificationsState = {\n notifications: [],\n};\n\nexport const notificationsSlice = createSlice({\n name: 'notifications',\n initialState: INITIAL_STATE,\n reducers: {\n addNotification: (state, action: PayloadAction<Notification>) => {\n state.notifications.push(action.payload);\n },\n removeNotification: (state, action: PayloadAction<string>) => {\n state.notifications = state.notifications.filter(\n (notification) => notification.id !== action.payload,\n );\n },\n clearNotifications: (state) => {\n state.notifications = [];\n },\n },\n});\n\nexport const { addNotification, removeNotification, clearNotifications } =\n notificationsSlice.actions;\n\n/**\n * Get the notifications from the state.\n *\n * @param state - The application state.\n * @returns An array of notifications.\n */\nexport const getNotifications = createSelector(\n (state: ApplicationState) => state.notifications,\n ({ notifications }) => notifications,\n);\n"],"names":["notificationsSlice","addNotification","removeNotification","clearNotifications","getNotifications","INITIAL_STATE","notifications","createSlice","name","initialState","reducers","state","action","push","payload","filter","notification","id","actions","createSelector"],"mappings":";;;;;;;;;;;IAmCaA,kBAAkB;eAAlBA;;IAkBEC,eAAe;eAAfA;;IAAiBC,kBAAkB;eAAlBA;;IAAoBC,kBAAkB;eAAlBA;;IASvCC,gBAAgB;eAAhBA;;;yBA5D+B;AA0B5C;;CAEC,GACD,MAAMC,gBAAoC;IACxCC,eAAe,EAAE;AACnB;AAEO,MAAMN,qBAAqBO,IAAAA,oBAAW,EAAC;IAC5CC,MAAM;IACNC,cAAcJ;IACdK,UAAU;QACRT,iBAAiB,CAACU,OAAOC;YACvBD,MAAML,aAAa,CAACO,IAAI,CAACD,OAAOE,OAAO;QACzC;QACAZ,oBAAoB,CAACS,OAAOC;YAC1BD,MAAML,aAAa,GAAGK,MAAML,aAAa,CAACS,MAAM,CAC9C,CAACC,eAAiBA,aAAaC,EAAE,KAAKL,OAAOE,OAAO;QAExD;QACAX,oBAAoB,CAACQ;YACnBA,MAAML,aAAa,GAAG,EAAE;QAC1B;IACF;AACF;AAEO,MAAM,EAAEL,eAAe,EAAEC,kBAAkB,EAAEC,kBAAkB,EAAE,GACtEH,mBAAmBkB,OAAO;AAQrB,MAAMd,mBAAmBe,IAAAA,uBAAc,EAC5C,CAACR,QAA4BA,MAAML,aAAa,EAChD,CAAC,EAAEA,aAAa,EAAE,GAAKA"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ stateSlice: function() {
13
+ return stateSlice;
14
+ },
15
+ setState: function() {
16
+ return setState;
17
+ },
18
+ clearState: function() {
19
+ return clearState;
20
+ },
21
+ getState: function() {
22
+ return getState;
23
+ }
24
+ });
25
+ const _toolkit = require("@reduxjs/toolkit");
26
+ /**
27
+ * The initial state.
28
+ */ const INITIAL_STATE = {
29
+ encrypted: null,
30
+ unencrypted: null
31
+ };
32
+ const stateSlice = (0, _toolkit.createSlice)({
33
+ name: 'state',
34
+ initialState: INITIAL_STATE,
35
+ reducers: {
36
+ setState: (state, action)=>{
37
+ if (action.payload.encrypted) {
38
+ state.encrypted = action.payload.state;
39
+ return state;
40
+ }
41
+ state.unencrypted = action.payload.state;
42
+ return state;
43
+ },
44
+ clearState: (state, action)=>{
45
+ if (action.payload.encrypted) {
46
+ state.encrypted = null;
47
+ return state;
48
+ }
49
+ state.unencrypted = null;
50
+ return state;
51
+ }
52
+ }
53
+ });
54
+ const { setState, clearState } = stateSlice.actions;
55
+ function getState(encrypted) {
56
+ return (0, _toolkit.createSelector)((state)=>state, ({ state })=>{
57
+ if (encrypted) {
58
+ return state.encrypted;
59
+ }
60
+ return state.unencrypted;
61
+ });
62
+ }
63
+
64
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/internals/simulation/store/state.ts"],"sourcesContent":["import type { PayloadAction } from '@reduxjs/toolkit';\nimport { createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\n/**\n * The Snap state object.\n *\n * @property encrypted - The encrypted state. Can be null if the Snap does not\n * have an encrypted state.\n * @property unencrypted - The unencrypted state. Can be null if the Snap does\n * not have an unencrypted state.\n */\nexport type State = {\n encrypted: string | null;\n unencrypted: string | null;\n};\n\n/**\n * The initial state.\n */\nconst INITIAL_STATE: State = {\n encrypted: null,\n unencrypted: null,\n};\n\n/**\n * The state slice, which stores the state of the Snap.\n */\nexport const stateSlice = createSlice({\n name: 'state',\n initialState: INITIAL_STATE,\n reducers: {\n setState: (\n state,\n action: PayloadAction<{ state: string | null; encrypted: boolean }>,\n ) => {\n if (action.payload.encrypted) {\n state.encrypted = action.payload.state;\n return state;\n }\n\n state.unencrypted = action.payload.state;\n return state;\n },\n clearState: (state, action: PayloadAction<{ encrypted: boolean }>) => {\n if (action.payload.encrypted) {\n state.encrypted = null;\n return state;\n }\n\n state.unencrypted = null;\n return state;\n },\n },\n});\n\nexport const { setState, clearState } = stateSlice.actions;\n\n/**\n * Get the state from the store.\n *\n * @param encrypted - Whether to get the encrypted or unencrypted state.\n * @returns A selector that returns the state.\n */\nexport function getState(encrypted: boolean) {\n return createSelector(\n (state: ApplicationState) => state,\n ({ state }) => {\n if (encrypted) {\n return state.encrypted;\n }\n\n return state.unencrypted;\n },\n );\n}\n"],"names":["stateSlice","setState","clearState","getState","INITIAL_STATE","encrypted","unencrypted","createSlice","name","initialState","reducers","state","action","payload","actions","createSelector"],"mappings":";;;;;;;;;;;IA6BaA,UAAU;eAAVA;;IA4BEC,QAAQ;eAARA;;IAAUC,UAAU;eAAVA;;IAQTC,QAAQ;eAARA;;;yBAhE4B;AAiB5C;;CAEC,GACD,MAAMC,gBAAuB;IAC3BC,WAAW;IACXC,aAAa;AACf;AAKO,MAAMN,aAAaO,IAAAA,oBAAW,EAAC;IACpCC,MAAM;IACNC,cAAcL;IACdM,UAAU;QACRT,UAAU,CACRU,OACAC;YAEA,IAAIA,OAAOC,OAAO,CAACR,SAAS,EAAE;gBAC5BM,MAAMN,SAAS,GAAGO,OAAOC,OAAO,CAACF,KAAK;gBACtC,OAAOA;YACT;YAEAA,MAAML,WAAW,GAAGM,OAAOC,OAAO,CAACF,KAAK;YACxC,OAAOA;QACT;QACAT,YAAY,CAACS,OAAOC;YAClB,IAAIA,OAAOC,OAAO,CAACR,SAAS,EAAE;gBAC5BM,MAAMN,SAAS,GAAG;gBAClB,OAAOM;YACT;YAEAA,MAAML,WAAW,GAAG;YACpB,OAAOK;QACT;IACF;AACF;AAEO,MAAM,EAAEV,QAAQ,EAAEC,UAAU,EAAE,GAAGF,WAAWc,OAAO;AAQnD,SAASX,SAASE,SAAkB;IACzC,OAAOU,IAAAA,uBAAc,EACnB,CAACJ,QAA4BA,OAC7B,CAAC,EAAEA,KAAK,EAAE;QACR,IAAIN,WAAW;YACb,OAAOM,MAAMN,SAAS;QACxB;QAEA,OAAOM,MAAML,WAAW;IAC1B;AAEJ"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "createStore", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createStore;
9
+ }
10
+ });
11
+ const _toolkit = require("@reduxjs/toolkit");
12
+ const _reduxsaga = /*#__PURE__*/ _interop_require_default(require("redux-saga"));
13
+ const _mocks = require("./mocks");
14
+ const _notifications = require("./notifications");
15
+ const _state = require("./state");
16
+ const _ui = require("./ui");
17
+ function _interop_require_default(obj) {
18
+ return obj && obj.__esModule ? obj : {
19
+ default: obj
20
+ };
21
+ }
22
+ function createStore(password, { state, unencryptedState }) {
23
+ const sagaMiddleware = (0, _reduxsaga.default)();
24
+ const store = (0, _toolkit.configureStore)({
25
+ reducer: {
26
+ mocks: _mocks.mocksSlice.reducer,
27
+ notifications: _notifications.notificationsSlice.reducer,
28
+ state: _state.stateSlice.reducer,
29
+ ui: _ui.uiSlice.reducer
30
+ },
31
+ middleware: (getDefaultMiddleware)=>getDefaultMiddleware({
32
+ thunk: false
33
+ }).concat(sagaMiddleware)
34
+ });
35
+ // Set initial state for the Snap.
36
+ if (state) {
37
+ store.dispatch((0, _state.setState)({
38
+ state: JSON.stringify({
39
+ password,
40
+ value: state
41
+ }),
42
+ encrypted: true
43
+ }));
44
+ }
45
+ if (unencryptedState) {
46
+ store.dispatch((0, _state.setState)({
47
+ state: JSON.stringify(unencryptedState),
48
+ encrypted: false
49
+ }));
50
+ }
51
+ return {
52
+ store,
53
+ runSaga: sagaMiddleware.run.bind(sagaMiddleware)
54
+ };
55
+ }
56
+
57
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/internals/simulation/store/store.ts"],"sourcesContent":["import { configureStore } from '@reduxjs/toolkit';\nimport createSagaMiddleware from 'redux-saga';\n\nimport type { SimulationOptions } from '../options';\nimport { mocksSlice } from './mocks';\nimport { notificationsSlice } from './notifications';\nimport { setState, stateSlice } from './state';\nimport { uiSlice } from './ui';\n\n/**\n * Create a Redux store.\n *\n * @param password - The password to use for state encryption.\n * @param options - The simulation options.\n * @param options.state - The initial state for the Snap.\n * @param options.unencryptedState - The initial unencrypted state for the Snap.\n * @returns A Redux store with the default state.\n */\nexport function createStore(\n password: string,\n { state, unencryptedState }: SimulationOptions,\n) {\n const sagaMiddleware = createSagaMiddleware();\n const store = configureStore({\n reducer: {\n mocks: mocksSlice.reducer,\n notifications: notificationsSlice.reducer,\n state: stateSlice.reducer,\n ui: uiSlice.reducer,\n },\n middleware: (getDefaultMiddleware) =>\n getDefaultMiddleware({ thunk: false }).concat(sagaMiddleware),\n });\n\n // Set initial state for the Snap.\n if (state) {\n store.dispatch(\n setState({\n state: JSON.stringify({\n password,\n value: state,\n }),\n encrypted: true,\n }),\n );\n }\n\n if (unencryptedState) {\n store.dispatch(\n setState({\n state: JSON.stringify(unencryptedState),\n encrypted: false,\n }),\n );\n }\n\n return {\n store,\n runSaga: sagaMiddleware.run.bind(sagaMiddleware),\n };\n}\n\nexport type Store = ReturnType<typeof createStore>['store'];\nexport type ApplicationState = ReturnType<Store['getState']>;\nexport type RunSagaFunction = ReturnType<typeof createStore>['runSaga'];\n"],"names":["createStore","password","state","unencryptedState","sagaMiddleware","createSagaMiddleware","store","configureStore","reducer","mocks","mocksSlice","notifications","notificationsSlice","stateSlice","ui","uiSlice","middleware","getDefaultMiddleware","thunk","concat","dispatch","setState","JSON","stringify","value","encrypted","runSaga","run","bind"],"mappings":";;;;+BAkBgBA;;;eAAAA;;;yBAlBe;kEACE;uBAGN;+BACQ;uBACE;oBACb;;;;;;AAWjB,SAASA,YACdC,QAAgB,EAChB,EAAEC,KAAK,EAAEC,gBAAgB,EAAqB;IAE9C,MAAMC,iBAAiBC,IAAAA,kBAAoB;IAC3C,MAAMC,QAAQC,IAAAA,uBAAc,EAAC;QAC3BC,SAAS;YACPC,OAAOC,iBAAU,CAACF,OAAO;YACzBG,eAAeC,iCAAkB,CAACJ,OAAO;YACzCN,OAAOW,iBAAU,CAACL,OAAO;YACzBM,IAAIC,WAAO,CAACP,OAAO;QACrB;QACAQ,YAAY,CAACC,uBACXA,qBAAqB;gBAAEC,OAAO;YAAM,GAAGC,MAAM,CAACf;IAClD;IAEA,kCAAkC;IAClC,IAAIF,OAAO;QACTI,MAAMc,QAAQ,CACZC,IAAAA,eAAQ,EAAC;YACPnB,OAAOoB,KAAKC,SAAS,CAAC;gBACpBtB;gBACAuB,OAAOtB;YACT;YACAuB,WAAW;QACb;IAEJ;IAEA,IAAItB,kBAAkB;QACpBG,MAAMc,QAAQ,CACZC,IAAAA,eAAQ,EAAC;YACPnB,OAAOoB,KAAKC,SAAS,CAACpB;YACtBsB,WAAW;QACb;IAEJ;IAEA,OAAO;QACLnB;QACAoB,SAAStB,eAAeuB,GAAG,CAACC,IAAI,CAACxB;IACnC;AACF"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ uiSlice: function() {
13
+ return uiSlice;
14
+ },
15
+ resolveInterface: function() {
16
+ return resolveInterface;
17
+ },
18
+ setInterface: function() {
19
+ return setInterface;
20
+ },
21
+ closeInterface: function() {
22
+ return closeInterface;
23
+ },
24
+ getCurrentInterface: function() {
25
+ return getCurrentInterface;
26
+ }
27
+ });
28
+ const _toolkit = require("@reduxjs/toolkit");
29
+ const INITIAL_STATE = {
30
+ current: null
31
+ };
32
+ const uiSlice = (0, _toolkit.createSlice)({
33
+ name: 'ui',
34
+ initialState: INITIAL_STATE,
35
+ reducers: {
36
+ setInterface (state, action) {
37
+ state.current = action.payload;
38
+ },
39
+ closeInterface (state) {
40
+ state.current = null;
41
+ }
42
+ }
43
+ });
44
+ const resolveInterface = (0, _toolkit.createAction)(`${uiSlice.name}/resolveInterface`);
45
+ const { setInterface, closeInterface } = uiSlice.actions;
46
+ const getCurrentInterface = (0, _toolkit.createSelector)((state)=>state.ui, (ui)=>ui.current);
47
+
48
+ //# sourceMappingURL=ui.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/internals/simulation/store/ui.ts"],"sourcesContent":["import type { DialogType } from '@metamask/snaps-sdk';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createAction, createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\nexport type Interface = {\n type: DialogType;\n id: string;\n};\n\nexport type UiState = {\n current?: Interface | null;\n};\n\nconst INITIAL_STATE: UiState = {\n current: null,\n};\n\nexport const uiSlice = createSlice({\n name: 'ui',\n initialState: INITIAL_STATE,\n reducers: {\n setInterface(state, action: PayloadAction<Interface>) {\n state.current = action.payload;\n },\n closeInterface(state) {\n state.current = null;\n },\n },\n});\n\nexport const resolveInterface = createAction<unknown>(\n `${uiSlice.name}/resolveInterface`,\n);\n\nexport const { setInterface, closeInterface } = uiSlice.actions;\n\nexport const getCurrentInterface = createSelector(\n (state: ApplicationState) => state.ui,\n (ui) => ui.current,\n);\n"],"names":["uiSlice","resolveInterface","setInterface","closeInterface","getCurrentInterface","INITIAL_STATE","current","createSlice","name","initialState","reducers","state","action","payload","createAction","actions","createSelector","ui"],"mappings":";;;;;;;;;;;IAmBaA,OAAO;eAAPA;;IAaAC,gBAAgB;eAAhBA;;IAIEC,YAAY;eAAZA;;IAAcC,cAAc;eAAdA;;IAEhBC,mBAAmB;eAAnBA;;;yBApC6C;AAa1D,MAAMC,gBAAyB;IAC7BC,SAAS;AACX;AAEO,MAAMN,UAAUO,IAAAA,oBAAW,EAAC;IACjCC,MAAM;IACNC,cAAcJ;IACdK,UAAU;QACRR,cAAaS,KAAK,EAAEC,MAAgC;YAClDD,MAAML,OAAO,GAAGM,OAAOC,OAAO;QAChC;QACAV,gBAAeQ,KAAK;YAClBA,MAAML,OAAO,GAAG;QAClB;IACF;AACF;AAEO,MAAML,mBAAmBa,IAAAA,qBAAY,EAC1C,CAAC,EAAEd,QAAQQ,IAAI,CAAC,iBAAiB,CAAC;AAG7B,MAAM,EAAEN,YAAY,EAAEC,cAAc,EAAE,GAAGH,QAAQe,OAAO;AAExD,MAAMX,sBAAsBY,IAAAA,uBAAc,EAC/C,CAACL,QAA4BA,MAAMM,EAAE,EACrC,CAACA,KAAOA,GAAGX,OAAO"}
@@ -12,9 +12,15 @@ _export(exports, {
12
12
  TransactionOptionsStruct: function() {
13
13
  return TransactionOptionsStruct;
14
14
  },
15
+ SignatureOptionsStruct: function() {
16
+ return SignatureOptionsStruct;
17
+ },
15
18
  SnapOptionsStruct: function() {
16
19
  return SnapOptionsStruct;
17
20
  },
21
+ JsonRpcMockOptionsStruct: function() {
22
+ return JsonRpcMockOptionsStruct;
23
+ },
18
24
  InterfaceStruct: function() {
19
25
  return InterfaceStruct;
20
26
  },
@@ -23,7 +29,6 @@ _export(exports, {
23
29
  }
24
30
  });
25
31
  const _snapssdk = require("@metamask/snaps-sdk");
26
- const _snapsutils = require("@metamask/snaps-utils");
27
32
  const _utils = require("@metamask/utils");
28
33
  const _crypto = require("crypto");
29
34
  const _superstruct = require("superstruct");
@@ -47,7 +52,7 @@ const TransactionOptionsStruct = (0, _superstruct.object)({
47
52
  */ // TODO: Move this coercer to `@metamask/utils`.
48
53
  from: (0, _superstruct.coerce)(_utils.StrictHexStruct, (0, _superstruct.optional)(BytesLikeStruct), (value)=>{
49
54
  if (value) {
50
- return (0, _utils.valueToBytes)(value);
55
+ return (0, _utils.bytesToHex)((0, _utils.valueToBytes)(value));
51
56
  }
52
57
  return (0, _utils.bytesToHex)((0, _crypto.randomBytes)(20));
53
58
  }),
@@ -57,7 +62,7 @@ const TransactionOptionsStruct = (0, _superstruct.object)({
57
62
  */ // TODO: Move this coercer to `@metamask/utils`.
58
63
  to: (0, _superstruct.coerce)(_utils.StrictHexStruct, (0, _superstruct.optional)(BytesLikeStruct), (value)=>{
59
64
  if (value) {
60
- return (0, _utils.valueToBytes)(value);
65
+ return (0, _utils.bytesToHex)((0, _utils.valueToBytes)(value));
61
66
  }
62
67
  return (0, _utils.bytesToHex)((0, _crypto.randomBytes)(20));
63
68
  }),
@@ -91,12 +96,49 @@ const TransactionOptionsStruct = (0, _superstruct.object)({
91
96
  (0, _superstruct.literal)('0x')
92
97
  ]), BytesLikeStruct, (value)=>(0, _utils.bytesToHex)((0, _utils.valueToBytes)(value))), '0x')
93
98
  });
99
+ const SignatureOptionsStruct = (0, _superstruct.object)({
100
+ /**
101
+ * The origin making the signature request.
102
+ */ origin: (0, _superstruct.defaulted)((0, _superstruct.string)(), 'metamask.io'),
103
+ /**
104
+ * The address signing the signature request. Defaults to a randomly generated
105
+ * address.
106
+ */ from: (0, _superstruct.coerce)(_utils.StrictHexStruct, (0, _superstruct.optional)(BytesLikeStruct), (value)=>{
107
+ if (value) {
108
+ return (0, _utils.bytesToHex)((0, _utils.valueToBytes)(value));
109
+ }
110
+ return (0, _utils.bytesToHex)((0, _crypto.randomBytes)(20));
111
+ }),
112
+ /**
113
+ * The data to send with the transaction. The data may be specified as a
114
+ * `string`, an object, or an array of objects. This covers the data types
115
+ * for the supported signature methods. Defaults to `0x`.
116
+ */ data: (0, _superstruct.defaulted)((0, _superstruct.union)([
117
+ _utils.StrictHexStruct,
118
+ (0, _superstruct.literal)('0x'),
119
+ (0, _superstruct.record)((0, _superstruct.string)(), (0, _superstruct.any)()),
120
+ (0, _superstruct.array)((0, _superstruct.record)((0, _superstruct.string)(), (0, _superstruct.any)()))
121
+ ]), '0x'),
122
+ /**
123
+ * The signature method being used.
124
+ */ signatureMethod: (0, _superstruct.defaulted)((0, _superstruct.union)([
125
+ (0, _superstruct.literal)('eth_sign'),
126
+ (0, _superstruct.literal)('personal_sign'),
127
+ (0, _superstruct.literal)('eth_signTypedData'),
128
+ (0, _superstruct.literal)('eth_signTypedData_v3'),
129
+ (0, _superstruct.literal)('eth_signTypedData_v4')
130
+ ]), 'personal_sign')
131
+ });
94
132
  const SnapOptionsStruct = (0, _superstruct.object)({
95
133
  /**
96
134
  * The timeout in milliseconds to use for requests to the snap. Defaults to
97
135
  * `1000`.
98
136
  */ timeout: (0, _superstruct.defaulted)((0, _superstruct.optional)((0, _superstruct.number)()), 1000)
99
137
  });
138
+ const JsonRpcMockOptionsStruct = (0, _superstruct.object)({
139
+ method: (0, _superstruct.string)(),
140
+ result: _utils.JsonStruct
141
+ });
100
142
  const InterfaceStruct = (0, _superstruct.type)({
101
143
  content: (0, _superstruct.optional)(_snapssdk.ComponentStruct)
102
144
  });
@@ -114,8 +156,8 @@ const SnapResponseStruct = (0, _superstruct.assign)(InterfaceStruct, (0, _supers
114
156
  id: (0, _superstruct.string)(),
115
157
  message: (0, _superstruct.string)(),
116
158
  type: (0, _superstruct.union)([
117
- (0, _snapsutils.enumValue)(_snapssdk.NotificationType.InApp),
118
- (0, _snapsutils.enumValue)(_snapssdk.NotificationType.Native)
159
+ (0, _snapssdk.enumValue)(_snapssdk.NotificationType.InApp),
160
+ (0, _snapssdk.enumValue)(_snapssdk.NotificationType.Native)
119
161
  ])
120
162
  }))
121
163
  }));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/internals/structs.ts"],"sourcesContent":["import { NotificationType, ComponentStruct } from '@metamask/snaps-sdk';\nimport { enumValue } from '@metamask/snaps-utils';\nimport {\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\nimport {\n array,\n assign,\n bigint,\n coerce,\n defaulted,\n instance,\n literal,\n number,\n object,\n optional,\n string,\n type,\n union,\n} from 'superstruct';\n\n// TODO: Export this from `@metamask/utils` instead.\nconst BytesLikeStruct = union([\n bigint(),\n number(),\n string(),\n instance(Uint8Array),\n]);\n\nexport const TransactionOptionsStruct = object({\n /**\n * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n\n /**\n * The origin to send the transaction from. Defaults to `metamask.io`.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address to send the transaction from. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return valueToBytes(value);\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The address to send the transaction to. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return valueToBytes(value);\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The value to send with the transaction. The value may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n value: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x0',\n ),\n\n /**\n * The gas limit to use for the transaction. The gas limit may be specified\n * as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.\n */\n gasLimit: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(21_000),\n ),\n\n /**\n * The max fee per gas (in Wei) to use for the transaction. The max fee per\n * gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.\n * Defaults to `1`.\n */\n maxFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The max priority fee per gas (in Wei) to use for the transaction. The max\n * priority fee per gas may be specified as a `number`, `bigint`, `string`,\n * or `Uint8Array`. Defaults to `1`.\n */\n maxPriorityFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The nonce to use for the transaction. The nonce may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n nonce: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(0),\n ),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.\n */\n data: defaulted(\n coerce(union([StrictHexStruct, literal('0x')]), BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x',\n ),\n});\n\nexport const SnapOptionsStruct = object({\n /**\n * The timeout in milliseconds to use for requests to the snap. Defaults to\n * `1000`.\n */\n timeout: defaulted(optional(number()), 1000),\n});\n\nexport const InterfaceStruct = type({\n content: optional(ComponentStruct),\n});\n\nexport const SnapResponseStruct = assign(\n InterfaceStruct,\n object({\n id: string(),\n\n response: union([\n object({\n result: JsonStruct,\n }),\n object({\n error: JsonStruct,\n }),\n ]),\n\n notifications: array(\n object({\n id: string(),\n message: string(),\n type: union([\n enumValue(NotificationType.InApp),\n enumValue(NotificationType.Native),\n ]),\n }),\n ),\n }),\n);\n"],"names":["TransactionOptionsStruct","SnapOptionsStruct","InterfaceStruct","SnapResponseStruct","BytesLikeStruct","union","bigint","number","string","instance","Uint8Array","object","chainId","defaulted","origin","from","coerce","StrictHexStruct","optional","value","valueToBytes","bytesToHex","randomBytes","to","gasLimit","maxFeePerGas","maxPriorityFeePerGas","nonce","data","literal","timeout","type","content","ComponentStruct","assign","id","response","result","JsonStruct","error","notifications","array","message","enumValue","NotificationType","InApp","Native"],"mappings":";;;;;;;;;;;IAiCaA,wBAAwB;eAAxBA;;IA0GAC,iBAAiB;eAAjBA;;IAQAC,eAAe;eAAfA;;IAIAC,kBAAkB;eAAlBA;;;0BAvJqC;4BACxB;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,IAAAA,mBAAM;QACVkC,SAASlC,IAAAA,mBAAM;QACfuB,MAAM1B,IAAAA,kBAAK,EAAC;YACVsC,IAAAA,qBAAS,EAACC,0BAAgB,CAACC,KAAK;YAChCF,IAAAA,qBAAS,EAACC,0BAAgB,CAACE,MAAM;SAClC;IACH;AAEJ"}
1
+ {"version":3,"sources":["../../../src/internals/structs.ts"],"sourcesContent":["import {\n NotificationType,\n ComponentStruct,\n enumValue,\n} from '@metamask/snaps-sdk';\nimport {\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\nimport {\n array,\n assign,\n bigint,\n coerce,\n defaulted,\n instance,\n literal,\n number,\n object,\n optional,\n string,\n type,\n union,\n record,\n any,\n} from 'superstruct';\n\n// TODO: Export this from `@metamask/utils` instead.\nconst BytesLikeStruct = union([\n bigint(),\n number(),\n string(),\n instance(Uint8Array),\n]);\n\nexport const TransactionOptionsStruct = object({\n /**\n * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n\n /**\n * The origin to send the transaction from. Defaults to `metamask.io`.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address to send the transaction from. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The address to send the transaction to. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The value to send with the transaction. The value may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n value: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x0',\n ),\n\n /**\n * The gas limit to use for the transaction. The gas limit may be specified\n * as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.\n */\n gasLimit: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(21_000),\n ),\n\n /**\n * The max fee per gas (in Wei) to use for the transaction. The max fee per\n * gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.\n * Defaults to `1`.\n */\n maxFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The max priority fee per gas (in Wei) to use for the transaction. The max\n * priority fee per gas may be specified as a `number`, `bigint`, `string`,\n * or `Uint8Array`. Defaults to `1`.\n */\n maxPriorityFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The nonce to use for the transaction. The nonce may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n nonce: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(0),\n ),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.\n */\n data: defaulted(\n coerce(union([StrictHexStruct, literal('0x')]), BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x',\n ),\n});\n\nexport const SignatureOptionsStruct = object({\n /**\n * The origin making the signature request.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address signing the signature request. Defaults to a randomly generated\n * address.\n */\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `string`, an object, or an array of objects. This covers the data types\n * for the supported signature methods. Defaults to `0x`.\n */\n data: defaulted(\n union([\n StrictHexStruct,\n literal('0x'),\n record(string(), any()),\n array(record(string(), any())),\n ]),\n '0x',\n ),\n\n /**\n * The signature method being used.\n */\n signatureMethod: defaulted(\n union([\n literal('eth_sign'),\n literal('personal_sign'),\n literal('eth_signTypedData'),\n literal('eth_signTypedData_v3'),\n literal('eth_signTypedData_v4'),\n ]),\n 'personal_sign',\n ),\n});\n\nexport const SnapOptionsStruct = object({\n /**\n * The timeout in milliseconds to use for requests to the snap. Defaults to\n * `1000`.\n */\n timeout: defaulted(optional(number()), 1000),\n});\n\nexport const JsonRpcMockOptionsStruct = object({\n method: string(),\n result: JsonStruct,\n});\n\nexport const InterfaceStruct = type({\n content: optional(ComponentStruct),\n});\n\nexport const SnapResponseStruct = assign(\n InterfaceStruct,\n object({\n id: string(),\n\n response: union([\n object({\n result: JsonStruct,\n }),\n object({\n error: JsonStruct,\n }),\n ]),\n\n notifications: array(\n object({\n id: string(),\n message: string(),\n type: union([\n enumValue(NotificationType.InApp),\n enumValue(NotificationType.Native),\n ]),\n }),\n ),\n }),\n);\n"],"names":["TransactionOptionsStruct","SignatureOptionsStruct","SnapOptionsStruct","JsonRpcMockOptionsStruct","InterfaceStruct","SnapResponseStruct","BytesLikeStruct","union","bigint","number","string","instance","Uint8Array","object","chainId","defaulted","origin","from","coerce","StrictHexStruct","optional","value","bytesToHex","valueToBytes","randomBytes","to","gasLimit","maxFeePerGas","maxPriorityFeePerGas","nonce","data","literal","record","any","array","signatureMethod","timeout","method","result","JsonStruct","type","content","ComponentStruct","assign","id","response","error","notifications","message","enumValue","NotificationType","InApp","Native"],"mappings":";;;;;;;;;;;IAsCaA,wBAAwB;eAAxBA;;IA0GAC,sBAAsB;eAAtBA;;IAgDAC,iBAAiB;eAAjBA;;IAQAC,wBAAwB;eAAxBA;;IAKAC,eA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IACH;AAEJ"}
@@ -86,7 +86,7 @@ const toRespondWithError = function(actual, expected) {
86
86
  pass
87
87
  };
88
88
  };
89
- const toSendNotification = async function(actual, expected, type) {
89
+ const toSendNotification = function(actual, expected, type) {
90
90
  assertActualIsSnapResponse(actual, 'toSendNotification');
91
91
  const { notifications } = actual;
92
92
  const pass = notifications.some((notification)=>this.equals(notification.message, expected) && (type === undefined || notification.type === type));
@@ -100,8 +100,11 @@ const toRender = function(actual, expected) {
100
100
  assertHasInterface(actual, 'toRender');
101
101
  const { content } = actual;
102
102
  const pass = this.equals(content, expected);
103
+ // This is typed as `string | null`, but in practice it's always a string. The
104
+ // function only returns `null` if both the expected and actual values are
105
+ // numbers, bigints, or booleans, which is never the case here.
103
106
  const difference = (0, _jestmatcherutils.diff)(expected, content);
104
- const message = pass ? ()=>`${this.utils.matcherHint('.not.toShowInterface')}\n\n` + `Expected: ${this.utils.printExpected(expected)}\n` + `Received: ${this.utils.printReceived(content)}` + `${difference ? `\n\nDifference:\n\n${difference}` : ''}` : ()=>`${this.utils.matcherHint('.toShowInterface')}\n\n` + `Expected: ${this.utils.printExpected(expected)}\n` + `Received: ${this.utils.printReceived(content)}` + `${difference ? `\n\nDifference:\n\n${difference}` : ''}`;
107
+ const message = pass ? ()=>`${this.utils.matcherHint('.not.toRender')}\n\n` + `Expected: ${this.utils.printExpected(expected)}\n` + `Received: ${this.utils.printReceived(content)}` + `\n\nDifference:\n\n${difference}` : ()=>`${this.utils.matcherHint('.toRender')}\n\n` + `Expected: ${this.utils.printExpected(expected)}\n` + `Received: ${this.utils.printReceived(content)}` + `\n\nDifference:\n\n${difference}`;
105
108
  return {
106
109
  message,
107
110
  pass
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/matchers.ts"],"sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport { is } from 'superstruct';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: Component } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = async function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n const difference = diff(expected, content);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`\n : () =>\n `${this.utils.matcherHint('.toShowInterface')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `${difference ? `\\n\\nDifference:\\n\\n${difference}` : ''}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"],"names":["toRespondWith","toRespondWithError","toSendNotification","toRender","assertActualIsSnapResponse","actual","matcherName","options","is","SnapResponseStruct","Error","matcherErrorMessage","matcherHint","undefined","RECEIVED_COLOR","printWithType","printReceived","assertHasInterface","InterfaceStruct","content","expected","response","hasProperty","message","utils","printExpected","error","pass","equals","result","type","notifications","some","notification","difference","diff","expect","extend"],"mappings":"AAAA,kCAAkC,GAElC,+EAA+E;AAC/E,yEAAyE;;;;;;;;;;;;IAkF5DA,aAAa;eAAbA;;IA8BAC,kBAAkB;eAAlBA;;IAuCAC,kBAAkB;eAAlBA;;IA2BA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E,CAAC,GACnD,CAAC,eAAe,EAAE,IAAI,CAACI,KAAK,CAACC,aAAa,CAACK,MAAM,EAAE,CAAC,GACpD,CAAC,UAAU,EAAE,IAAI,CAACN,KAAK,CAACR,aAAa,CAACe,eAAe,CAAC;IAE5D,OAAO;QAAER;QAASI;IAAK;AACzB;AAEO,MAAMxB,WAAmD,SAC9DE,MAAM,EACNe,QAAQ;IAERH,mBAAmBZ,QAAQ;IAE3B,MAAM,EAAEc,OAAO,EAAE,GAAGd;IACpB,MAAMsB,OAAO,IAAI,CAACC,MAAM,CAACT,SAASC;IAElC,MAAMc,aAAaC,IAAAA,sBAAI,EAACf,UAAUD;IAElC,MAAMI,UAAUI,OACZ,IACE,CAAC,EAAE,IAAI,CAACH,KAAK,CAACZ,WAAW,CAAC,wBAAwB,IAAI,CAAC,GACvD,CAAC,UAAU,EAAE,IAAI,CAACY,KAAK,CAACC,aAAa,CAACL,UAAU,EAAE,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACI,KAAK,CAACR,aAAa,CAACG,SAAS,CAAC,GAChD,CAAC,EAAEe,aAAa,CAAC,mBAAmB,EAAEA,WAAW,CAAC,GAAG,GAAG,CAAC,GAC3D,IACE,CAAC,EAAE,IAAI,CAACV,KAAK,CAACZ,WAAW,CAAC,oBAAoB,IAAI,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACY,KAAK,CAACC,aAAa,CAACL,UAAU,EAAE,CAAC,GACnD,CAAC,UAAU,EAAE,IAAI,CAACI,KAAK,CAACR,aAAa,CAACG,SAAS,CAAC,GAChD,CAAC,EAAEe,aAAa,CAAC,mBAAmB,EAAEA,WAAW,CAAC,GAAG,GAAG,CAAC;IAE/D,OAAO;QAAEX;QAASI;IAAK;AACzB;AAEAS,eAAM,CAACC,MAAM,CAAC;IACZrC;IACAC;IACAC;IACAC;AACF"}
1
+ {"version":3,"sources":["../../src/matchers.ts"],"sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport { is } from 'superstruct';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: Component } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string. The\n // function only returns `null` if both the expected and actual values are\n // numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expected, content);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference as string}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference as string}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"],"names":["toRespondWith","toRespondWithError","toSendNotification","toRender","assertActualIsSnapResponse","actual","matcherName","options","is","SnapResponseStruct","Error","matcherErrorMessage","matcherHint","undefined","RECEIVED_COLOR","printWithType","printReceived","assertHasInterface","InterfaceStruct","content","expected","response","hasProperty","message","utils","printExpected","error","pass","equals","result","type","notifications","some","notification","difference","diff","expect","extend"],"m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IACZrC;IACAC;IACAC;IACAC;AACF"}
@@ -10,16 +10,10 @@ Object.defineProperty(exports, "getOptions", {
10
10
  });
11
11
  const _superstruct = require("superstruct");
12
12
  const SnapsEnvironmentOptionsStruct = (0, _superstruct.type)({
13
- executionEnvironmentUrl: (0, _superstruct.optional)((0, _superstruct.string)()),
14
- simulatorUrl: (0, _superstruct.optional)((0, _superstruct.string)()),
15
- keepAlive: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
16
13
  server: (0, _superstruct.defaulted)((0, _superstruct.object)({
17
14
  enabled: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true),
18
15
  port: (0, _superstruct.defaulted)((0, _superstruct.number)(), 0),
19
16
  root: (0, _superstruct.defaulted)((0, _superstruct.string)(), process.cwd())
20
- }), {}),
21
- browser: (0, _superstruct.defaulted)((0, _superstruct.object)({
22
- headless: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true)
23
17
  }), {})
24
18
  });
25
19
  function getOptions(testEnvironmentOptions) {