@metamask/snaps-simulation 2.5.0 → 2.7.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 (78) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/dist/helpers.cjs +26 -0
  3. package/dist/helpers.cjs.map +1 -1
  4. package/dist/helpers.d.cts +10 -0
  5. package/dist/helpers.d.cts.map +1 -1
  6. package/dist/helpers.d.mts +10 -0
  7. package/dist/helpers.d.mts.map +1 -1
  8. package/dist/helpers.mjs +26 -0
  9. package/dist/helpers.mjs.map +1 -1
  10. package/dist/methods/hooks/get-preferences.cjs +3 -1
  11. package/dist/methods/hooks/get-preferences.cjs.map +1 -1
  12. package/dist/methods/hooks/get-preferences.d.cts +3 -1
  13. package/dist/methods/hooks/get-preferences.d.cts.map +1 -1
  14. package/dist/methods/hooks/get-preferences.d.mts +3 -1
  15. package/dist/methods/hooks/get-preferences.d.mts.map +1 -1
  16. package/dist/methods/hooks/get-preferences.mjs +3 -1
  17. package/dist/methods/hooks/get-preferences.mjs.map +1 -1
  18. package/dist/middleware/internal-methods/accounts.cjs.map +1 -1
  19. package/dist/middleware/internal-methods/accounts.d.cts +2 -2
  20. package/dist/middleware/internal-methods/accounts.d.cts.map +1 -1
  21. package/dist/middleware/internal-methods/accounts.d.mts +2 -2
  22. package/dist/middleware/internal-methods/accounts.d.mts.map +1 -1
  23. package/dist/middleware/internal-methods/accounts.mjs.map +1 -1
  24. package/dist/middleware/internal-methods/chain-id.cjs.map +1 -1
  25. package/dist/middleware/internal-methods/chain-id.d.cts +2 -2
  26. package/dist/middleware/internal-methods/chain-id.d.cts.map +1 -1
  27. package/dist/middleware/internal-methods/chain-id.d.mts +2 -2
  28. package/dist/middleware/internal-methods/chain-id.d.mts.map +1 -1
  29. package/dist/middleware/internal-methods/chain-id.mjs.map +1 -1
  30. package/dist/middleware/internal-methods/middleware.cjs +2 -0
  31. package/dist/middleware/internal-methods/middleware.cjs.map +1 -1
  32. package/dist/middleware/internal-methods/middleware.d.cts.map +1 -1
  33. package/dist/middleware/internal-methods/middleware.d.mts.map +1 -1
  34. package/dist/middleware/internal-methods/middleware.mjs +2 -0
  35. package/dist/middleware/internal-methods/middleware.mjs.map +1 -1
  36. package/dist/middleware/internal-methods/net-version.cjs.map +1 -1
  37. package/dist/middleware/internal-methods/net-version.d.cts +2 -2
  38. package/dist/middleware/internal-methods/net-version.d.cts.map +1 -1
  39. package/dist/middleware/internal-methods/net-version.d.mts +2 -2
  40. package/dist/middleware/internal-methods/net-version.d.mts.map +1 -1
  41. package/dist/middleware/internal-methods/net-version.mjs.map +1 -1
  42. package/dist/middleware/internal-methods/provider-state.cjs.map +1 -1
  43. package/dist/middleware/internal-methods/provider-state.d.cts +2 -2
  44. package/dist/middleware/internal-methods/provider-state.d.cts.map +1 -1
  45. package/dist/middleware/internal-methods/provider-state.d.mts +2 -2
  46. package/dist/middleware/internal-methods/provider-state.d.mts.map +1 -1
  47. package/dist/middleware/internal-methods/provider-state.mjs.map +1 -1
  48. package/dist/middleware/internal-methods/switch-ethereum-chain.cjs +21 -0
  49. package/dist/middleware/internal-methods/switch-ethereum-chain.cjs.map +1 -0
  50. package/dist/middleware/internal-methods/switch-ethereum-chain.d.cts +16 -0
  51. package/dist/middleware/internal-methods/switch-ethereum-chain.d.cts.map +1 -0
  52. package/dist/middleware/internal-methods/switch-ethereum-chain.d.mts +16 -0
  53. package/dist/middleware/internal-methods/switch-ethereum-chain.d.mts.map +1 -0
  54. package/dist/middleware/internal-methods/switch-ethereum-chain.mjs +17 -0
  55. package/dist/middleware/internal-methods/switch-ethereum-chain.mjs.map +1 -0
  56. package/dist/options.cjs +1 -0
  57. package/dist/options.cjs.map +1 -1
  58. package/dist/options.d.cts +3 -0
  59. package/dist/options.d.cts.map +1 -1
  60. package/dist/options.d.mts +3 -0
  61. package/dist/options.d.mts.map +1 -1
  62. package/dist/options.mjs +1 -0
  63. package/dist/options.mjs.map +1 -1
  64. package/dist/simulation.cjs +1 -0
  65. package/dist/simulation.cjs.map +1 -1
  66. package/dist/simulation.d.cts +6 -0
  67. package/dist/simulation.d.cts.map +1 -1
  68. package/dist/simulation.d.mts +6 -0
  69. package/dist/simulation.d.mts.map +1 -1
  70. package/dist/simulation.mjs +1 -0
  71. package/dist/simulation.mjs.map +1 -1
  72. package/dist/types.cjs.map +1 -1
  73. package/dist/types.d.cts +10 -1
  74. package/dist/types.d.cts.map +1 -1
  75. package/dist/types.d.mts +10 -1
  76. package/dist/types.d.mts.map +1 -1
  77. package/dist/types.mjs.map +1 -1
  78. package/package.json +14 -14
package/CHANGELOG.md CHANGED
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.7.0]
11
+
12
+ ### Added
13
+
14
+ - Add `active` flag for `snap_getClientStatus` ([#3424](https://github.com/MetaMask/snaps/pull/3424))
15
+ - Add support for `onProtocolRequest` ([#3422](https://github.com/MetaMask/snaps/pull/3422))
16
+
17
+ ## [2.6.0]
18
+
19
+ ### Added
20
+
21
+ - Add support for `wallet_switchEthereumChain` ([#2634](https://github.com/MetaMask/snaps/pull/2634))
22
+ - Add `showTestnets` to `snap_getPreferences` ([#3395](https://github.com/MetaMask/snaps/pull/3395))
23
+
10
24
  ## [2.5.0]
11
25
 
12
26
  ### Added
@@ -153,7 +167,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
153
167
 
154
168
  - Initial release of `@metamask/snaps-simulation` package ([#2727](https://github.com/MetaMask/snaps/pull/2727))
155
169
 
156
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@2.5.0...HEAD
170
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@2.7.0...HEAD
171
+ [2.7.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@2.6.0...@metamask/snaps-simulation@2.7.0
172
+ [2.6.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@2.5.0...@metamask/snaps-simulation@2.6.0
157
173
  [2.5.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@2.4.1...@metamask/snaps-simulation@2.5.0
158
174
  [2.4.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@2.4.0...@metamask/snaps-simulation@2.4.1
159
175
  [2.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@2.3.0...@metamask/snaps-simulation@2.4.0
package/dist/helpers.cjs CHANGED
@@ -197,6 +197,32 @@ function getHelpers({ snapId, store, executionService, runSaga, controllerMessen
197
197
  (0, structs_1.assertIsResponseWithInterface)(response);
198
198
  return response;
199
199
  },
200
+ onProtocolRequest: async (scope, rawRequest) => {
201
+ log('Sending protocol request.');
202
+ const request = {
203
+ jsonrpc: '2.0',
204
+ id: rawRequest.id ?? 1,
205
+ method: rawRequest.method,
206
+ ...(rawRequest.params ? { params: rawRequest.params } : {}),
207
+ };
208
+ const response = await (0, request_1.handleRequest)({
209
+ snapId,
210
+ store,
211
+ executionService,
212
+ controllerMessenger,
213
+ runSaga,
214
+ handler: snaps_utils_1.HandlerType.OnProtocolRequest,
215
+ request: {
216
+ origin: rawRequest.origin,
217
+ method: '',
218
+ params: {
219
+ scope,
220
+ request,
221
+ },
222
+ },
223
+ });
224
+ return response;
225
+ },
200
226
  mockJsonRpc(mock) {
201
227
  log('Mocking JSON-RPC request %o.', mock);
202
228
  const { method, result } = (0, superstruct_1.create)(mock, structs_1.JsonRpcMockOptionsStruct);
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AACpD,uDAA+C;AAC/C,2CAAqD;AAErD,yCAAsC;AAEtC,2CAA0C;AAE1C,6CAA4D;AAC5D,2CAMmB;AAcnB,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,mBAAU,EAAE,SAAS,CAAC,CAA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/snaps-utils';\nimport { create } from '@metamask/superstruct';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { rootLogger } from './logger';\nimport type { SimulationOptions } from './options';\nimport { handleRequest } from './request';\nimport type { InstalledSnap } from './simulation';\nimport { addJsonRpcMock, removeJsonRpcMock } from './store';\nimport {\n assertIsResponseWithInterface,\n JsonRpcMockOptionsStruct,\n NameLookupOptionsStruct,\n SignatureOptionsStruct,\n TransactionOptionsStruct,\n} from './structs';\nimport type {\n CronjobOptions,\n JsonRpcMockOptions,\n KeyringOptions,\n NameLookupOptions,\n RequestOptions,\n SignatureOptions,\n SnapRequest,\n SnapResponseWithInterface,\n SnapResponseWithoutInterface,\n TransactionOptions,\n} from './types';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n */\nexport type SnapHelpers = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n onTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n * @deprecated Use {@link onTransaction} instead.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a signature request to the snap.\n *\n * @param signature - The signature request object. Contains the params from\n * the various signature methods, but has an extra `origin` and `signatureMethod` field.\n * Any missing fields will be filled in with default values.\n * @returns The response.\n */\n onSignature(\n signature?: Partial<SignatureOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onCronjob(cronjob?: Partial<CronjobOptions>): SnapRequest;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n * @deprecated Use {@link onCronjob} instead.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Run a background event in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param backgroundEvent - The background event request. This is similar to a JSON-RPC\n * request, and is normally specified in the `request` param of the `snap_scheduleBackgroundEvent` method.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onBackgroundEvent(backgroundEvent: CronjobOptions): SnapRequest;\n\n /**\n * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Get the response from the snap's `onSettingsPage` method.\n *\n * @returns The response.\n */\n onSettingsPage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a keyring request to the Snap.\n *\n * @param keyringRequest - Keyring request.\n * @returns The response.\n */\n onKeyringRequest(keyringRequest: KeyringOptions): SnapRequest;\n\n /**\n * Get the response from the Snap's `onInstall` handler.\n *\n * @returns The response.\n */\n onInstall(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onUpdate` handler.\n *\n * @returns The response.\n */\n onUpdate(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onNameLookup` handler.\n *\n * @returns The response.\n */\n onNameLookup(\n request: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Mock a JSON-RPC request. This will cause the snap to respond with the\n * specified response when a request with the specified method is sent.\n *\n * @param mock - The mock options.\n * @param mock.method - The JSON-RPC request method.\n * @param mock.result - The JSON-RPC response, which will be returned when a\n * request with the specified method is sent.\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpc({ method: 'eth_accounts', result: ['0x1234'] });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n */\n mockJsonRpc(mock: JsonRpcMockOptions): {\n /**\n * Remove the mock.\n */\n unmock(): void;\n };\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n */\n close(): Promise<void>;\n};\n\n/**\n * Get the helper functions for the Snap.\n *\n * @param snap - The installed Snap.\n * @param snap.snapId - The ID of the Snap.\n * @param snap.store - The Redux store.\n * @param snap.executionService - The execution service.\n * @param snap.runSaga - The `runSaga` function.\n * @param snap.controllerMessenger - The controller messenger.\n * @param snap.options - The simulation options.\n * @returns The Snap helpers.\n */\nexport function getHelpers({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n options,\n}: InstalledSnap & { options: SimulationOptions }): SnapHelpers {\n const onTransaction = async (\n request: TransactionOptions,\n ): Promise<SnapResponseWithInterface> => {\n log('Sending transaction %o.', request);\n\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(request, TransactionOptionsStruct);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnTransaction,\n request: {\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n };\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const onCronjob = (request: CronjobOptions) => {\n log('Running cronjob %o.', options);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnCronjob,\n request,\n });\n };\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const onKeyringRequest = (request: KeyringOptions) => {\n log('Sending keyring request %o.', request);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnKeyringRequest,\n request,\n });\n };\n\n return {\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n request: (request) => {\n log('Sending request %o.', request);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnRpcRequest,\n request,\n });\n },\n\n onTransaction,\n sendTransaction: onTransaction,\n\n onKeyringRequest,\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onInstall: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onInstall handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnInstall,\n request: {\n method: '',\n ...request,\n },\n });\n },\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onUpdate: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onUpdate handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnUpdate,\n request: {\n method: '',\n ...request,\n },\n });\n },\n\n onNameLookup: async (\n nameLookupOptions: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface> => {\n log('Requesting name lookup %o.', nameLookupOptions);\n\n const params = create(nameLookupOptions, NameLookupOptionsStruct);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnNameLookup,\n request: {\n method: '',\n params,\n },\n });\n\n return response;\n },\n\n onSignature: async (\n request: unknown,\n ): Promise<SnapResponseWithInterface> => {\n log('Requesting signature %o.', request);\n\n const { origin: signatureOrigin, ...signature } = create(\n request,\n SignatureOptionsStruct,\n );\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSignature,\n request: {\n method: '',\n params: {\n signature,\n signatureOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onCronjob,\n runCronjob: onCronjob,\n onBackgroundEvent: onCronjob,\n\n onHomePage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering home page.');\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnHomePage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onSettingsPage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering settings page.');\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSettingsPage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n mockJsonRpc(mock: JsonRpcMockOptions) {\n log('Mocking JSON-RPC request %o.', mock);\n\n const { method, result } = create(mock, JsonRpcMockOptionsStruct);\n store.dispatch(addJsonRpcMock({ method, result }));\n\n return {\n unmock() {\n log('Unmocking JSON-RPC request %o.', mock);\n\n store.dispatch(removeJsonRpcMock(method));\n },\n };\n },\n\n close: async () => {\n log('Closing execution service.');\n await executionService.terminateAllSnaps();\n },\n };\n}\n"]}
1
+ {"version":3,"file":"helpers.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"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AAmB;gBACnB,OAAO;gBACP,OAAO,EAAE,yBAAW,CAAC,iBAAiB;gBACtC,OAAO,EAAE;oBACP,MAAM,EAAE,UAAU,CAAC,MAAM;oBACzB,MAAM,EAAE,EAAE;oBACV,MAAM,EAAE;wBACN,KAAK;wBACL,OAAO;qBACR;iBACF;aACF,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,WAAW,CAAC,IAAwB;YAClC,GAAG,CAAC,8BAA8B,EAAE,IAAI,CAAC,CAAC;YAE1C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,oBAAM,EAAC,IAAI,EAAE,kCAAwB,CAAC,CAAC;YAClE,KAAK,CAAC,QAAQ,CAAC,IAAA,sBAAc,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;YAEnD,OAAO;gBACL,MAAM;oBACJ,GAAG,CAAC,gCAAgC,EAAE,IAAI,CAAC,CAAC;oBAE5C,KAAK,CAAC,QAAQ,CAAC,IAAA,yBAAiB,EAAC,MAAM,CAAC,CAAC,CAAC;gBAC5C,CAAC;aACF,CAAC;QACJ,CAAC;QAED,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAClC,MAAM,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC;AA5RD,gCA4RC","sourcesContent":["import { HandlerType } from '@metamask/snaps-utils';\nimport { create } from '@metamask/superstruct';\nimport type { CaipChainId } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { rootLogger } from './logger';\nimport type { SimulationOptions } from './options';\nimport { handleRequest } from './request';\nimport type { InstalledSnap } from './simulation';\nimport { addJsonRpcMock, removeJsonRpcMock } from './store';\nimport {\n assertIsResponseWithInterface,\n JsonRpcMockOptionsStruct,\n NameLookupOptionsStruct,\n SignatureOptionsStruct,\n TransactionOptionsStruct,\n} from './structs';\nimport type {\n CronjobOptions,\n JsonRpcMockOptions,\n KeyringOptions,\n NameLookupOptions,\n RequestOptions,\n SignatureOptions,\n SnapRequest,\n SnapResponseWithInterface,\n SnapResponseWithoutInterface,\n TransactionOptions,\n} from './types';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n */\nexport type SnapHelpers = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n onTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n * @deprecated Use {@link onTransaction} instead.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a signature request to the snap.\n *\n * @param signature - The signature request object. Contains the params from\n * the various signature methods, but has an extra `origin` and `signatureMethod` field.\n * Any missing fields will be filled in with default values.\n * @returns The response.\n */\n onSignature(\n signature?: Partial<SignatureOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onCronjob(cronjob?: Partial<CronjobOptions>): SnapRequest;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n * @deprecated Use {@link onCronjob} instead.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Run a background event in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param backgroundEvent - The background event request. This is similar to a JSON-RPC\n * request, and is normally specified in the `request` param of the `snap_scheduleBackgroundEvent` method.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onBackgroundEvent(backgroundEvent: CronjobOptions): SnapRequest;\n\n /**\n * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Get the response from the snap's `onSettingsPage` method.\n *\n * @returns The response.\n */\n onSettingsPage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a keyring request to the Snap.\n *\n * @param keyringRequest - Keyring request.\n * @returns The response.\n */\n onKeyringRequest(keyringRequest: KeyringOptions): SnapRequest;\n\n /**\n * Get the response from the Snap's `onInstall` handler.\n *\n * @returns The response.\n */\n onInstall(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onUpdate` handler.\n *\n * @returns The response.\n */\n onUpdate(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onNameLookup` handler.\n *\n * @returns The response.\n */\n onNameLookup(\n request: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Send a JSON-RPC protocol request to the Snap.\n *\n * @param scope - A CAIP-2 scope.\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onProtocolRequest(\n scope: CaipChainId,\n request: RequestOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Mock a JSON-RPC request. This will cause the snap to respond with the\n * specified response when a request with the specified method is sent.\n *\n * @param mock - The mock options.\n * @param mock.method - The JSON-RPC request method.\n * @param mock.result - The JSON-RPC response, which will be returned when a\n * request with the specified method is sent.\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpc({ method: 'eth_accounts', result: ['0x1234'] });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n */\n mockJsonRpc(mock: JsonRpcMockOptions): {\n /**\n * Remove the mock.\n */\n unmock(): void;\n };\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n */\n close(): Promise<void>;\n};\n\n/**\n * Get the helper functions for the Snap.\n *\n * @param snap - The installed Snap.\n * @param snap.snapId - The ID of the Snap.\n * @param snap.store - The Redux store.\n * @param snap.executionService - The execution service.\n * @param snap.runSaga - The `runSaga` function.\n * @param snap.controllerMessenger - The controller messenger.\n * @param snap.options - The simulation options.\n * @returns The Snap helpers.\n */\nexport function getHelpers({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n options,\n}: InstalledSnap & { options: SimulationOptions }): SnapHelpers {\n const onTransaction = async (\n request: TransactionOptions,\n ): Promise<SnapResponseWithInterface> => {\n log('Sending transaction %o.', request);\n\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(request, TransactionOptionsStruct);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnTransaction,\n request: {\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n };\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const onCronjob = (request: CronjobOptions) => {\n log('Running cronjob %o.', options);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnCronjob,\n request,\n });\n };\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const onKeyringRequest = (request: KeyringOptions) => {\n log('Sending keyring request %o.', request);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnKeyringRequest,\n request,\n });\n };\n\n return {\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n request: (request) => {\n log('Sending request %o.', request);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnRpcRequest,\n request,\n });\n },\n\n onTransaction,\n sendTransaction: onTransaction,\n\n onKeyringRequest,\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onInstall: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onInstall handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnInstall,\n request: {\n method: '',\n ...request,\n },\n });\n },\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onUpdate: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onUpdate handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnUpdate,\n request: {\n method: '',\n ...request,\n },\n });\n },\n\n onNameLookup: async (\n nameLookupOptions: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface> => {\n log('Requesting name lookup %o.', nameLookupOptions);\n\n const params = create(nameLookupOptions, NameLookupOptionsStruct);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnNameLookup,\n request: {\n method: '',\n params,\n },\n });\n\n return response;\n },\n\n onSignature: async (\n request: unknown,\n ): Promise<SnapResponseWithInterface> => {\n log('Requesting signature %o.', request);\n\n const { origin: signatureOrigin, ...signature } = create(\n request,\n SignatureOptionsStruct,\n );\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSignature,\n request: {\n method: '',\n params: {\n signature,\n signatureOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onCronjob,\n runCronjob: onCronjob,\n onBackgroundEvent: onCronjob,\n\n onHomePage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering home page.');\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnHomePage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onSettingsPage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering settings page.');\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSettingsPage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onProtocolRequest: async (\n scope,\n rawRequest,\n ): Promise<SnapResponseWithoutInterface> => {\n log('Sending protocol request.');\n\n const request = {\n jsonrpc: '2.0' as const,\n id: rawRequest.id ?? 1,\n method: rawRequest.method,\n ...(rawRequest.params ? { params: rawRequest.params } : {}),\n };\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnProtocolRequest,\n request: {\n origin: rawRequest.origin,\n method: '',\n params: {\n scope,\n request,\n },\n },\n });\n\n return response;\n },\n\n mockJsonRpc(mock: JsonRpcMockOptions) {\n log('Mocking JSON-RPC request %o.', mock);\n\n const { method, result } = create(mock, JsonRpcMockOptionsStruct);\n store.dispatch(addJsonRpcMock({ method, result }));\n\n return {\n unmock() {\n log('Unmocking JSON-RPC request %o.', mock);\n\n store.dispatch(removeJsonRpcMock(method));\n },\n };\n },\n\n close: async () => {\n log('Closing execution service.');\n await executionService.terminateAllSnaps();\n },\n };\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import type { CaipChainId } from "@metamask/utils";
1
2
  import type { SimulationOptions } from "./options.cjs";
2
3
  import type { InstalledSnap } from "./simulation.cjs";
3
4
  import type { CronjobOptions, JsonRpcMockOptions, KeyringOptions, NameLookupOptions, RequestOptions, SignatureOptions, SnapRequest, SnapResponseWithInterface, SnapResponseWithoutInterface, TransactionOptions } from "./types.cjs";
@@ -117,6 +118,15 @@ export type SnapHelpers = {
117
118
  * @returns The response.
118
119
  */
119
120
  onNameLookup(request: NameLookupOptions): Promise<SnapResponseWithoutInterface>;
121
+ /**
122
+ * Send a JSON-RPC protocol request to the Snap.
123
+ *
124
+ * @param scope - A CAIP-2 scope.
125
+ * @param request - The request. This is similar to a JSON-RPC request, but
126
+ * has an extra `origin` field.
127
+ * @returns The response promise, with extra {@link SnapRequestObject} fields.
128
+ */
129
+ onProtocolRequest(scope: CaipChainId, request: RequestOptions): Promise<SnapResponseWithoutInterface>;
120
130
  /**
121
131
  * Mock a JSON-RPC request. This will cause the snap to respond with the
122
132
  * specified response when a request with the specified method is sent.
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.cts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAkB;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAqB;AASlD,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,yBAAyB,EACzB,4BAA4B,EAC5B,kBAAkB,EACnB,oBAAgB;AAIjB;;;;;;;;;;;GAWG;AACH,M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EAAE,aAAa,GAAG;IAAE,OAAO,EAAE,iBAAiB,CAAA;CAAE,GAAG,WAAW,CAqR9D"}
@@ -1,3 +1,4 @@
1
+ import type { CaipChainId } from "@metamask/utils";
1
2
  import type { SimulationOptions } from "./options.mjs";
2
3
  import type { InstalledSnap } from "./simulation.mjs";
3
4
  import type { CronjobOptions, JsonRpcMockOptions, KeyringOptions, NameLookupOptions, RequestOptions, SignatureOptions, SnapRequest, SnapResponseWithInterface, SnapResponseWithoutInterface, TransactionOptions } from "./types.mjs";
@@ -117,6 +118,15 @@ export type SnapHelpers = {
117
118
  * @returns The response.
118
119
  */
119
120
  onNameLookup(request: NameLookupOptions): Promise<SnapResponseWithoutInterface>;
121
+ /**
122
+ * Send a JSON-RPC protocol request to the Snap.
123
+ *
124
+ * @param scope - A CAIP-2 scope.
125
+ * @param request - The request. This is similar to a JSON-RPC request, but
126
+ * has an extra `origin` field.
127
+ * @returns The response promise, with extra {@link SnapRequestObject} fields.
128
+ */
129
+ onProtocolRequest(scope: CaipChainId, request: RequestOptions): Promise<SnapResponseWithoutInterface>;
120
130
  /**
121
131
  * Mock a JSON-RPC request. This will cause the snap to respond with the
122
132
  * specified response when a request with the specified method is sent.
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.mts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAkB;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAqB;AASlD,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,yBAAyB,EACzB,4BAA4B,EAC5B,kBAAkB,EACnB,oBAAgB;AAIjB;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;;;;;OAMG;IACH,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,WAAW,CAAC;IAE9C;;;;;;;OAOG;I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 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
194
194
  assertIsResponseWithInterface(response);
195
195
  return response;
196
196
  },
197
+ onProtocolRequest: async (scope, rawRequest) => {
198
+ log('Sending protocol request.');
199
+ const request = {
200
+ jsonrpc: '2.0',
201
+ id: rawRequest.id ?? 1,
202
+ method: rawRequest.method,
203
+ ...(rawRequest.params ? { params: rawRequest.params } : {}),
204
+ };
205
+ const response = await handleRequest({
206
+ snapId,
207
+ store,
208
+ executionService,
209
+ controllerMessenger,
210
+ runSaga,
211
+ handler: HandlerType.OnProtocolRequest,
212
+ request: {
213
+ origin: rawRequest.origin,
214
+ method: '',
215
+ params: {
216
+ scope,
217
+ request,
218
+ },
219
+ },
220
+ });
221
+ return response;
222
+ },
197
223
  mockJsonRpc(mock) {
198
224
  log('Mocking JSON-RPC request %o.', mock);
199
225
  const { method, result } = create(mock, JsonRpcMockOptionsStruct);
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.mjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,8BAA8B;AACpD,OAAO,EAAE,MAAM,EAAE,8BAA8B;AAC/C,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,UAAU,EAAE,qBAAiB;AAEtC,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAE1C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,0BAAgB;AAC5D,OAAO,EACL,6BAA6B,EAC7B,wBAAwB,EACxB,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EACzB,sBAAkB;AAcnB,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AA8KtD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,GACwC;IAC/C,MAAM,aAAa,GAAG,KAAK,E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GAAG,MAAM,aAAa,CAAC;gBACnC,MAAM;gBACN,KAAK;gBACL,gBAAgB;gBAChB,mBAAmB;gBACnB,OAAO;gBACP,OAAO,EAAE,WAAW,CAAC,cAAc;gBACnC,OAAO,EAAE;oBACP,MAAM,EAAE,EAAE;iBACX;aACF,CAAC,CAAC;YAEH,6BAA6B,CAAC,QAAQ,CAAC,CAAC;YAExC,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,WAAW,CAAC,IAAwB;YAClC,GAAG,CAAC,8BAA8B,EAAE,IAAI,CAAC,CAAC;YAE1C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,wBAAwB,CAAC,CAAC;YAClE,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;YAEnD,OAAO;gBACL,MAAM;oBACJ,GAAG,CAAC,gCAAgC,EAAE,IAAI,CAAC,CAAC;oBAE5C,KAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC5C,CAAC;aACF,CAAC;QACJ,CAAC;QAED,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAClC,MAAM,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { HandlerType } from '@metamask/snaps-utils';\nimport { create } from '@metamask/superstruct';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { rootLogger } from './logger';\nimport type { SimulationOptions } from './options';\nimport { handleRequest } from './request';\nimport type { InstalledSnap } from './simulation';\nimport { addJsonRpcMock, removeJsonRpcMock } from './store';\nimport {\n assertIsResponseWithInterface,\n JsonRpcMockOptionsStruct,\n NameLookupOptionsStruct,\n SignatureOptionsStruct,\n TransactionOptionsStruct,\n} from './structs';\nimport type {\n CronjobOptions,\n JsonRpcMockOptions,\n KeyringOptions,\n NameLookupOptions,\n RequestOptions,\n SignatureOptions,\n SnapRequest,\n SnapResponseWithInterface,\n SnapResponseWithoutInterface,\n TransactionOptions,\n} from './types';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n */\nexport type SnapHelpers = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n onTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n * @deprecated Use {@link onTransaction} instead.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a signature request to the snap.\n *\n * @param signature - The signature request object. Contains the params from\n * the various signature methods, but has an extra `origin` and `signatureMethod` field.\n * Any missing fields will be filled in with default values.\n * @returns The response.\n */\n onSignature(\n signature?: Partial<SignatureOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onCronjob(cronjob?: Partial<CronjobOptions>): SnapRequest;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n * @deprecated Use {@link onCronjob} instead.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Run a background event in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param backgroundEvent - The background event request. This is similar to a JSON-RPC\n * request, and is normally specified in the `request` param of the `snap_scheduleBackgroundEvent` method.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onBackgroundEvent(backgroundEvent: CronjobOptions): SnapRequest;\n\n /**\n * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Get the response from the snap's `onSettingsPage` method.\n *\n * @returns The response.\n */\n onSettingsPage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a keyring request to the Snap.\n *\n * @param keyringRequest - Keyring request.\n * @returns The response.\n */\n onKeyringRequest(keyringRequest: KeyringOptions): SnapRequest;\n\n /**\n * Get the response from the Snap's `onInstall` handler.\n *\n * @returns The response.\n */\n onInstall(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onUpdate` handler.\n *\n * @returns The response.\n */\n onUpdate(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onNameLookup` handler.\n *\n * @returns The response.\n */\n onNameLookup(\n request: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Mock a JSON-RPC request. This will cause the snap to respond with the\n * specified response when a request with the specified method is sent.\n *\n * @param mock - The mock options.\n * @param mock.method - The JSON-RPC request method.\n * @param mock.result - The JSON-RPC response, which will be returned when a\n * request with the specified method is sent.\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpc({ method: 'eth_accounts', result: ['0x1234'] });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n */\n mockJsonRpc(mock: JsonRpcMockOptions): {\n /**\n * Remove the mock.\n */\n unmock(): void;\n };\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n */\n close(): Promise<void>;\n};\n\n/**\n * Get the helper functions for the Snap.\n *\n * @param snap - The installed Snap.\n * @param snap.snapId - The ID of the Snap.\n * @param snap.store - The Redux store.\n * @param snap.executionService - The execution service.\n * @param snap.runSaga - The `runSaga` function.\n * @param snap.controllerMessenger - The controller messenger.\n * @param snap.options - The simulation options.\n * @returns The Snap helpers.\n */\nexport function getHelpers({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n options,\n}: InstalledSnap & { options: SimulationOptions }): SnapHelpers {\n const onTransaction = async (\n request: TransactionOptions,\n ): Promise<SnapResponseWithInterface> => {\n log('Sending transaction %o.', request);\n\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(request, TransactionOptionsStruct);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnTransaction,\n request: {\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n };\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const onCronjob = (request: CronjobOptions) => {\n log('Running cronjob %o.', options);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnCronjob,\n request,\n });\n };\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const onKeyringRequest = (request: KeyringOptions) => {\n log('Sending keyring request %o.', request);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnKeyringRequest,\n request,\n });\n };\n\n return {\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n request: (request) => {\n log('Sending request %o.', request);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnRpcRequest,\n request,\n });\n },\n\n onTransaction,\n sendTransaction: onTransaction,\n\n onKeyringRequest,\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onInstall: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onInstall handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnInstall,\n request: {\n method: '',\n ...request,\n },\n });\n },\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onUpdate: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onUpdate handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnUpdate,\n request: {\n method: '',\n ...request,\n },\n });\n },\n\n onNameLookup: async (\n nameLookupOptions: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface> => {\n log('Requesting name lookup %o.', nameLookupOptions);\n\n const params = create(nameLookupOptions, NameLookupOptionsStruct);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnNameLookup,\n request: {\n method: '',\n params,\n },\n });\n\n return response;\n },\n\n onSignature: async (\n request: unknown,\n ): Promise<SnapResponseWithInterface> => {\n log('Requesting signature %o.', request);\n\n const { origin: signatureOrigin, ...signature } = create(\n request,\n SignatureOptionsStruct,\n );\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSignature,\n request: {\n method: '',\n params: {\n signature,\n signatureOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onCronjob,\n runCronjob: onCronjob,\n onBackgroundEvent: onCronjob,\n\n onHomePage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering home page.');\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnHomePage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onSettingsPage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering settings page.');\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSettingsPage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n mockJsonRpc(mock: JsonRpcMockOptions) {\n log('Mocking JSON-RPC request %o.', mock);\n\n const { method, result } = create(mock, JsonRpcMockOptionsStruct);\n store.dispatch(addJsonRpcMock({ method, result }));\n\n return {\n unmock() {\n log('Unmocking JSON-RPC request %o.', mock);\n\n store.dispatch(removeJsonRpcMock(method));\n },\n };\n },\n\n close: async () => {\n log('Closing execution service.');\n await executionService.terminateAllSnaps();\n },\n };\n}\n"]}
1
+ {"version":3,"file":"helpers.mjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,8BAA8B;AACpD,OAAO,EAAE,MAAM,EAAE,8BAA8B;AAE/C,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,UAAU,EAAE,qBAAiB;AAEtC,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAE1C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,0BAAgB;AAC5D,OAAO,EACL,6BAA6B,EAC7B,wBAAwB,EACxB,uBAAuB,EACvB,sBAAsB,EAC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,CAAC;QAClB,CAAC;QAED,WAAW,CAAC,IAAwB;YAClC,GAAG,CAAC,8BAA8B,EAAE,IAAI,CAAC,CAAC;YAE1C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,wBAAwB,CAAC,CAAC;YAClE,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;YAEnD,OAAO;gBACL,MAAM;oBACJ,GAAG,CAAC,gCAAgC,EAAE,IAAI,CAAC,CAAC;oBAE5C,KAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC5C,CAAC;aACF,CAAC;QACJ,CAAC;QAED,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAClC,MAAM,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { HandlerType } from '@metamask/snaps-utils';\nimport { create } from '@metamask/superstruct';\nimport type { CaipChainId } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { rootLogger } from './logger';\nimport type { SimulationOptions } from './options';\nimport { handleRequest } from './request';\nimport type { InstalledSnap } from './simulation';\nimport { addJsonRpcMock, removeJsonRpcMock } from './store';\nimport {\n assertIsResponseWithInterface,\n JsonRpcMockOptionsStruct,\n NameLookupOptionsStruct,\n SignatureOptionsStruct,\n TransactionOptionsStruct,\n} from './structs';\nimport type {\n CronjobOptions,\n JsonRpcMockOptions,\n KeyringOptions,\n NameLookupOptions,\n RequestOptions,\n SignatureOptions,\n SnapRequest,\n SnapResponseWithInterface,\n SnapResponseWithoutInterface,\n TransactionOptions,\n} from './types';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n */\nexport type SnapHelpers = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n onTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n * @deprecated Use {@link onTransaction} instead.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a signature request to the snap.\n *\n * @param signature - The signature request object. Contains the params from\n * the various signature methods, but has an extra `origin` and `signatureMethod` field.\n * Any missing fields will be filled in with default values.\n * @returns The response.\n */\n onSignature(\n signature?: Partial<SignatureOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onCronjob(cronjob?: Partial<CronjobOptions>): SnapRequest;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n * @deprecated Use {@link onCronjob} instead.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Run a background event in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param backgroundEvent - The background event request. This is similar to a JSON-RPC\n * request, and is normally specified in the `request` param of the `snap_scheduleBackgroundEvent` method.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onBackgroundEvent(backgroundEvent: CronjobOptions): SnapRequest;\n\n /**\n * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Get the response from the snap's `onSettingsPage` method.\n *\n * @returns The response.\n */\n onSettingsPage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a keyring request to the Snap.\n *\n * @param keyringRequest - Keyring request.\n * @returns The response.\n */\n onKeyringRequest(keyringRequest: KeyringOptions): SnapRequest;\n\n /**\n * Get the response from the Snap's `onInstall` handler.\n *\n * @returns The response.\n */\n onInstall(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onUpdate` handler.\n *\n * @returns The response.\n */\n onUpdate(request?: Pick<RequestOptions, 'origin'>): SnapRequest;\n\n /**\n * Get the response from the Snap's `onNameLookup` handler.\n *\n * @returns The response.\n */\n onNameLookup(\n request: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Send a JSON-RPC protocol request to the Snap.\n *\n * @param scope - A CAIP-2 scope.\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onProtocolRequest(\n scope: CaipChainId,\n request: RequestOptions,\n ): Promise<SnapResponseWithoutInterface>;\n\n /**\n * Mock a JSON-RPC request. This will cause the snap to respond with the\n * specified response when a request with the specified method is sent.\n *\n * @param mock - The mock options.\n * @param mock.method - The JSON-RPC request method.\n * @param mock.result - The JSON-RPC response, which will be returned when a\n * request with the specified method is sent.\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpc({ method: 'eth_accounts', result: ['0x1234'] });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n */\n mockJsonRpc(mock: JsonRpcMockOptions): {\n /**\n * Remove the mock.\n */\n unmock(): void;\n };\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n */\n close(): Promise<void>;\n};\n\n/**\n * Get the helper functions for the Snap.\n *\n * @param snap - The installed Snap.\n * @param snap.snapId - The ID of the Snap.\n * @param snap.store - The Redux store.\n * @param snap.executionService - The execution service.\n * @param snap.runSaga - The `runSaga` function.\n * @param snap.controllerMessenger - The controller messenger.\n * @param snap.options - The simulation options.\n * @returns The Snap helpers.\n */\nexport function getHelpers({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n options,\n}: InstalledSnap & { options: SimulationOptions }): SnapHelpers {\n const onTransaction = async (\n request: TransactionOptions,\n ): Promise<SnapResponseWithInterface> => {\n log('Sending transaction %o.', request);\n\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(request, TransactionOptionsStruct);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnTransaction,\n request: {\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n };\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const onCronjob = (request: CronjobOptions) => {\n log('Running cronjob %o.', options);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnCronjob,\n request,\n });\n };\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const onKeyringRequest = (request: KeyringOptions) => {\n log('Sending keyring request %o.', request);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnKeyringRequest,\n request,\n });\n };\n\n return {\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n request: (request) => {\n log('Sending request %o.', request);\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnRpcRequest,\n request,\n });\n },\n\n onTransaction,\n sendTransaction: onTransaction,\n\n onKeyringRequest,\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onInstall: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onInstall handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnInstall,\n request: {\n method: '',\n ...request,\n },\n });\n },\n\n // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onUpdate: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onUpdate handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnUpdate,\n request: {\n method: '',\n ...request,\n },\n });\n },\n\n onNameLookup: async (\n nameLookupOptions: NameLookupOptions,\n ): Promise<SnapResponseWithoutInterface> => {\n log('Requesting name lookup %o.', nameLookupOptions);\n\n const params = create(nameLookupOptions, NameLookupOptionsStruct);\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnNameLookup,\n request: {\n method: '',\n params,\n },\n });\n\n return response;\n },\n\n onSignature: async (\n request: unknown,\n ): Promise<SnapResponseWithInterface> => {\n log('Requesting signature %o.', request);\n\n const { origin: signatureOrigin, ...signature } = create(\n request,\n SignatureOptionsStruct,\n );\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSignature,\n request: {\n method: '',\n params: {\n signature,\n signatureOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onCronjob,\n runCronjob: onCronjob,\n onBackgroundEvent: onCronjob,\n\n onHomePage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering home page.');\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnHomePage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onSettingsPage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering settings page.');\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSettingsPage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onProtocolRequest: async (\n scope,\n rawRequest,\n ): Promise<SnapResponseWithoutInterface> => {\n log('Sending protocol request.');\n\n const request = {\n jsonrpc: '2.0' as const,\n id: rawRequest.id ?? 1,\n method: rawRequest.method,\n ...(rawRequest.params ? { params: rawRequest.params } : {}),\n };\n\n const response = await handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnProtocolRequest,\n request: {\n origin: rawRequest.origin,\n method: '',\n params: {\n scope,\n request,\n },\n },\n });\n\n return response;\n },\n\n mockJsonRpc(mock: JsonRpcMockOptions) {\n log('Mocking JSON-RPC request %o.', mock);\n\n const { method, result } = create(mock, JsonRpcMockOptionsStruct);\n store.dispatch(addJsonRpcMock({ method, result }));\n\n return {\n unmock() {\n log('Unmocking JSON-RPC request %o.', mock);\n\n store.dispatch(removeJsonRpcMock(method));\n },\n };\n },\n\n close: async () => {\n log('Closing execution service.');\n await executionService.terminateAllSnaps();\n },\n };\n}\n"]}
@@ -15,9 +15,10 @@ exports.getGetPreferencesMethodImplementation = void 0;
15
15
  * @param options.displayNftMedia - Whether to display NFT media.
16
16
  * @param options.useNftDetection - Whether to auto-detect NFTs.
17
17
  * @param options.useExternalPricingData - Whether to get token price data from an external source.
18
+ * @param options.showTestnets - Whether to show testnets.
18
19
  * @returns The implementation of the `getPreferences` hook.
19
20
  */
20
- function getGetPreferencesMethodImplementation({ currency, locale, hideBalances, useSecurityAlerts, simulateOnChainActions, useTokenDetection, batchCheckBalances, displayNftMedia, useNftDetection, useExternalPricingData, }) {
21
+ function getGetPreferencesMethodImplementation({ currency, locale, hideBalances, useSecurityAlerts, simulateOnChainActions, useTokenDetection, batchCheckBalances, displayNftMedia, useNftDetection, useExternalPricingData, showTestnets, }) {
21
22
  return () => {
22
23
  return {
23
24
  currency,
@@ -30,6 +31,7 @@ function getGetPreferencesMethodImplementation({ currency, locale, hideBalances,
30
31
  displayNftMedia,
31
32
  useNftDetection,
32
33
  useExternalPricingData,
34
+ showTestnets,
33
35
  };
34
36
  };
35
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"get-preferences.cjs","sourceRoot":"","sources":["../../../src/methods/hooks/get-preferences.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,qCAAqC,CAAC,EACpD,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,sBAAsB,GACJ;IAClB,OAAO,GAAG,EAAE;QACV,OAAO;YACL,QAAQ;YACR,MAAM;YACN,YAAY;YACZ,iBAAiB;YACjB,sBAAsB;YACtB,iBAAiB;YACjB,kBAAkB;YAClB,eAAe;YACf,eAAe;YACf,sBAAsB;SACvB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AA1BD,sFA0BC","sourcesContent":["import type { SimulationOptions } from '../../options';\n\n/**\n * Get the implementation of the `getPreferences` hook.\n *\n * @param options - The simulation options.\n * @param options.currency - The currency to use.\n * @param options.locale - The locale to use.\n * @param options.hideBalances - Whether to hide balances.\n * @param options.useSecurityAlerts - Whether to run transactions and signatures through security providers.\n * @param options.simulateOnChainActions - Whether to simulate transactions and signatures.\n * @param options.useTokenDetection - Whether to auto-detect tokens.\n * @param options.batchCheckBalances - Whether to fetch balances in an aggregated manner.\n * @param options.displayNftMedia - Whether to display NFT media.\n * @param options.useNftDetection - Whether to auto-detect NFTs.\n * @param options.useExternalPricingData - Whether to get token price data from an external source.\n * @returns The implementation of the `getPreferences` hook.\n */\nexport function getGetPreferencesMethodImplementation({\n currency,\n locale,\n hideBalances,\n useSecurityAlerts,\n simulateOnChainActions,\n useTokenDetection,\n batchCheckBalances,\n displayNftMedia,\n useNftDetection,\n useExternalPricingData,\n}: SimulationOptions) {\n return () => {\n return {\n currency,\n locale,\n hideBalances,\n useSecurityAlerts,\n simulateOnChainActions,\n useTokenDetection,\n batchCheckBalances,\n displayNftMedia,\n useNftDetection,\n useExternalPricingData,\n };\n };\n}\n"]}
1
+ {"version":3,"file":"get-preferences.cjs","sourceRoot":"","sources":["../../../src/methods/hooks/get-preferences.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,qCAAqC,CAAC,EACpD,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,YAAY,GACM;IAClB,OAAO,GAAG,EAAE;QACV,OAAO;YACL,QAAQ;YACR,MAAM;YACN,YAAY;YACZ,iBAAiB;YACjB,sBAAsB;YACtB,iBAAiB;YACjB,kBAAkB;YAClB,eAAe;YACf,eAAe;YACf,sBAAsB;YACtB,YAAY;SACb,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AA5BD,sFA4BC","sourcesContent":["import type { SimulationOptions } from '../../options';\n\n/**\n * Get the implementation of the `getPreferences` hook.\n *\n * @param options - The simulation options.\n * @param options.currency - The currency to use.\n * @param options.locale - The locale to use.\n * @param options.hideBalances - Whether to hide balances.\n * @param options.useSecurityAlerts - Whether to run transactions and signatures through security providers.\n * @param options.simulateOnChainActions - Whether to simulate transactions and signatures.\n * @param options.useTokenDetection - Whether to auto-detect tokens.\n * @param options.batchCheckBalances - Whether to fetch balances in an aggregated manner.\n * @param options.displayNftMedia - Whether to display NFT media.\n * @param options.useNftDetection - Whether to auto-detect NFTs.\n * @param options.useExternalPricingData - Whether to get token price data from an external source.\n * @param options.showTestnets - Whether to show testnets.\n * @returns The implementation of the `getPreferences` hook.\n */\nexport function getGetPreferencesMethodImplementation({\n currency,\n locale,\n hideBalances,\n useSecurityAlerts,\n simulateOnChainActions,\n useTokenDetection,\n batchCheckBalances,\n displayNftMedia,\n useNftDetection,\n useExternalPricingData,\n showTestnets,\n}: SimulationOptions) {\n return () => {\n return {\n currency,\n locale,\n hideBalances,\n useSecurityAlerts,\n simulateOnChainActions,\n useTokenDetection,\n batchCheckBalances,\n displayNftMedia,\n useNftDetection,\n useExternalPricingData,\n showTestnets,\n };\n };\n}\n"]}
@@ -13,9 +13,10 @@ import type { SimulationOptions } from "../../options.cjs";
13
13
  * @param options.displayNftMedia - Whether to display NFT media.
14
14
  * @param options.useNftDetection - Whether to auto-detect NFTs.
15
15
  * @param options.useExternalPricingData - Whether to get token price data from an external source.
16
+ * @param options.showTestnets - Whether to show testnets.
16
17
  * @returns The implementation of the `getPreferences` hook.
17
18
  */
18
- export declare function getGetPreferencesMethodImplementation({ currency, locale, hideBalances, useSecurityAlerts, simulateOnChainActions, useTokenDetection, batchCheckBalances, displayNftMedia, useNftDetection, useExternalPricingData, }: SimulationOptions): () => {
19
+ export declare function getGetPreferencesMethodImplementation({ currency, locale, hideBalances, useSecurityAlerts, simulateOnChainActions, useTokenDetection, batchCheckBalances, displayNftMedia, useNftDetection, useExternalPricingData, showTestnets, }: SimulationOptions): () => {
19
20
  currency: string;
20
21
  locale: string;
21
22
  hideBalances: boolean;
@@ -26,5 +27,6 @@ export declare function getGetPreferencesMethodImplementation({ currency, locale
26
27
  displayNftMedia: boolean;
27
28
  useNftDetection: boolean;
28
29
  useExternalPricingData: boolean;
30
+ showTestnets: boolean;
29
31
  };
30
32
  //# sourceMappingURL=get-preferences.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-preferences.d.cts","sourceRoot":"","sources":["../../../src/methods/hooks/get-preferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAAsB;AAEvD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qCAAqC,CAAC,EACpD,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,sBAAsB,GACvB,EAAE,iBAAiB;;;;;;;;;;;EAenB"}
1
+ {"version":3,"file":"get-preferences.d.cts","sourceRoot":"","sources":["../../../src/methods/hooks/get-preferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAAsB;AAEvD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qCAAqC,CAAC,EACpD,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,YAAY,GACb,EAAE,iBAAiB;;;;;;;;;;;;EAgBnB"}
@@ -13,9 +13,10 @@ import type { SimulationOptions } from "../../options.mjs";
13
13
  * @param options.displayNftMedia - Whether to display NFT media.
14
14
  * @param options.useNftDetection - Whether to auto-detect NFTs.
15
15
  * @param options.useExternalPricingData - Whether to get token price data from an external source.
16
+ * @param options.showTestnets - Whether to show testnets.
16
17
  * @returns The implementation of the `getPreferences` hook.
17
18
  */
18
- export declare function getGetPreferencesMethodImplementation({ currency, locale, hideBalances, useSecurityAlerts, simulateOnChainActions, useTokenDetection, batchCheckBalances, displayNftMedia, useNftDetection, useExternalPricingData, }: SimulationOptions): () => {
19
+ export declare function getGetPreferencesMethodImplementation({ currency, locale, hideBalances, useSecurityAlerts, simulateOnChainActions, useTokenDetection, batchCheckBalances, displayNftMedia, useNftDetection, useExternalPricingData, showTestnets, }: SimulationOptions): () => {
19
20
  currency: string;
20
21
  locale: string;
21
22
  hideBalances: boolean;
@@ -26,5 +27,6 @@ export declare function getGetPreferencesMethodImplementation({ currency, locale
26
27
  displayNftMedia: boolean;
27
28
  useNftDetection: boolean;
28
29
  useExternalPricingData: boolean;
30
+ showTestnets: boolean;
29
31
  };
30
32
  //# sourceMappingURL=get-preferences.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-preferences.d.mts","sourceRoot":"","sources":["../../../src/methods/hooks/get-preferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAAsB;AAEvD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qCAAqC,CAAC,EACpD,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,sBAAsB,GACvB,EAAE,iBAAiB;;;;;;;;;;;EAenB"}
1
+ {"version":3,"file":"get-preferences.d.mts","sourceRoot":"","sources":["../../../src/methods/hooks/get-preferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAAsB;AAEvD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qCAAqC,CAAC,EACpD,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,YAAY,GACb,EAAE,iBAAiB;;;;;;;;;;;;EAgBnB"}
@@ -12,9 +12,10 @@
12
12
  * @param options.displayNftMedia - Whether to display NFT media.
13
13
  * @param options.useNftDetection - Whether to auto-detect NFTs.
14
14
  * @param options.useExternalPricingData - Whether to get token price data from an external source.
15
+ * @param options.showTestnets - Whether to show testnets.
15
16
  * @returns The implementation of the `getPreferences` hook.
16
17
  */
17
- export function getGetPreferencesMethodImplementation({ currency, locale, hideBalances, useSecurityAlerts, simulateOnChainActions, useTokenDetection, batchCheckBalances, displayNftMedia, useNftDetection, useExternalPricingData, }) {
18
+ export function getGetPreferencesMethodImplementation({ currency, locale, hideBalances, useSecurityAlerts, simulateOnChainActions, useTokenDetection, batchCheckBalances, displayNftMedia, useNftDetection, useExternalPricingData, showTestnets, }) {
18
19
  return () => {
19
20
  return {
20
21
  currency,
@@ -27,6 +28,7 @@ export function getGetPreferencesMethodImplementation({ currency, locale, hideBa
27
28
  displayNftMedia,
28
29
  useNftDetection,
29
30
  useExternalPricingData,
31
+ showTestnets,
30
32
  };
31
33
  };
32
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"get-preferences.mjs","sourceRoot":"","sources":["../../../src/methods/hooks/get-preferences.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,qCAAqC,CAAC,EACpD,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,sBAAsB,GACJ;IAClB,OAAO,GAAG,EAAE;QACV,OAAO;YACL,QAAQ;YACR,MAAM;YACN,YAAY;YACZ,iBAAiB;YACjB,sBAAsB;YACtB,iBAAiB;YACjB,kBAAkB;YAClB,eAAe;YACf,eAAe;YACf,sBAAsB;SACvB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { SimulationOptions } from '../../options';\n\n/**\n * Get the implementation of the `getPreferences` hook.\n *\n * @param options - The simulation options.\n * @param options.currency - The currency to use.\n * @param options.locale - The locale to use.\n * @param options.hideBalances - Whether to hide balances.\n * @param options.useSecurityAlerts - Whether to run transactions and signatures through security providers.\n * @param options.simulateOnChainActions - Whether to simulate transactions and signatures.\n * @param options.useTokenDetection - Whether to auto-detect tokens.\n * @param options.batchCheckBalances - Whether to fetch balances in an aggregated manner.\n * @param options.displayNftMedia - Whether to display NFT media.\n * @param options.useNftDetection - Whether to auto-detect NFTs.\n * @param options.useExternalPricingData - Whether to get token price data from an external source.\n * @returns The implementation of the `getPreferences` hook.\n */\nexport function getGetPreferencesMethodImplementation({\n currency,\n locale,\n hideBalances,\n useSecurityAlerts,\n simulateOnChainActions,\n useTokenDetection,\n batchCheckBalances,\n displayNftMedia,\n useNftDetection,\n useExternalPricingData,\n}: SimulationOptions) {\n return () => {\n return {\n currency,\n locale,\n hideBalances,\n useSecurityAlerts,\n simulateOnChainActions,\n useTokenDetection,\n batchCheckBalances,\n displayNftMedia,\n useNftDetection,\n useExternalPricingData,\n };\n };\n}\n"]}
1
+ {"version":3,"file":"get-preferences.mjs","sourceRoot":"","sources":["../../../src/methods/hooks/get-preferences.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,qCAAqC,CAAC,EACpD,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,YAAY,GACM;IAClB,OAAO,GAAG,EAAE;QACV,OAAO;YACL,QAAQ;YACR,MAAM;YACN,YAAY;YACZ,iBAAiB;YACjB,sBAAsB;YACtB,iBAAiB;YACjB,kBAAkB;YAClB,eAAe;YACf,eAAe;YACf,sBAAsB;YACtB,YAAY;SACb,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { SimulationOptions } from '../../options';\n\n/**\n * Get the implementation of the `getPreferences` hook.\n *\n * @param options - The simulation options.\n * @param options.currency - The currency to use.\n * @param options.locale - The locale to use.\n * @param options.hideBalances - Whether to hide balances.\n * @param options.useSecurityAlerts - Whether to run transactions and signatures through security providers.\n * @param options.simulateOnChainActions - Whether to simulate transactions and signatures.\n * @param options.useTokenDetection - Whether to auto-detect tokens.\n * @param options.batchCheckBalances - Whether to fetch balances in an aggregated manner.\n * @param options.displayNftMedia - Whether to display NFT media.\n * @param options.useNftDetection - Whether to auto-detect NFTs.\n * @param options.useExternalPricingData - Whether to get token price data from an external source.\n * @param options.showTestnets - Whether to show testnets.\n * @returns The implementation of the `getPreferences` hook.\n */\nexport function getGetPreferencesMethodImplementation({\n currency,\n locale,\n hideBalances,\n useSecurityAlerts,\n simulateOnChainActions,\n useTokenDetection,\n batchCheckBalances,\n displayNftMedia,\n useNftDetection,\n useExternalPricingData,\n showTestnets,\n}: SimulationOptions) {\n return () => {\n return {\n currency,\n locale,\n hideBalances,\n useSecurityAlerts,\n simulateOnChainActions,\n useTokenDetection,\n batchCheckBalances,\n displayNftMedia,\n useNftDetection,\n useExternalPricingData,\n showTestnets,\n };\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"accounts.cjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/accounts.ts"],"names":[],"mappings":";;;AAIA,iDAA+C;AAW/C;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,kBAAkB,CACtC,QAAwB,EACxB,QAAsC,EACtC,KAAgC,EAChC,GAA6B,EAC7B,KAA8B;IAE9B,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAE9B,MAAM,IAAI,GAAG,MAAM,oBAAS,CAAC,kBAAkB,CAAC;QAC9C,cAAc,EAAE;YACd,MAAM,WAAW,EAAE;YACnB,WAAW;YACX,WAAW;YACX,UAAU;YACV,SAAS;YACT,SAAS;SACV;KACF,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAtBD,gDAsBC","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 * @returns The JSON-RPC response.\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"]}
1
+ {"version":3,"file":"accounts.cjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/accounts.ts"],"names":[],"mappings":";;;AAIA,iDAA+C;AAO/C;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,kBAAkB,CACtC,QAAwB,EACxB,QAAgC,EAChC,KAAgC,EAChC,GAA6B,EAC7B,KAA8B;IAE9B,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAE9B,MAAM,IAAI,GAAG,MAAM,oBAAS,CAAC,kBAAkB,CAAC;QAC9C,cAAc,EAAE;YACd,MAAM,WAAW,EAAE;YACnB,WAAW;YACX,WAAW;YACX,UAAU;YACV,SAAS;YACT,SAAS;SACV;KACF,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAtBD,gDAsBC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport { BIP44Node } from '@metamask/key-tree';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } 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 * @returns The JSON-RPC response.\n */\nexport async function getAccountsHandler(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse,\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"]}
@@ -1,5 +1,5 @@
1
1
  import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
2
- import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
2
+ import type { JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
3
3
  export type GetAccountsHandlerHooks = {
4
4
  getMnemonic: () => Promise<Uint8Array>;
5
5
  };
@@ -16,5 +16,5 @@ export type GetAccountsHandlerHooks = {
16
16
  * @param hooks - Any hooks required by this handler.
17
17
  * @returns The JSON-RPC response.
18
18
  */
19
- export declare function getAccountsHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse<Json>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: GetAccountsHandlerHooks): Promise<void>;
19
+ export declare function getAccountsHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: GetAccountsHandlerHooks): Promise<void>;
20
20
  //# sourceMappingURL=accounts.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"accounts.d.cts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AAEnC,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC,EACtC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,uBAAuB,iBAiB/B"}
1
+ {"version":3,"file":"accounts.d.cts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,wBAAwB;AAE9E,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,sBAAsB,EAChC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,uBAAuB,iBAiB/B"}
@@ -1,5 +1,5 @@
1
1
  import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
2
- import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
2
+ import type { JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
3
3
  export type GetAccountsHandlerHooks = {
4
4
  getMnemonic: () => Promise<Uint8Array>;
5
5
  };
@@ -16,5 +16,5 @@ export type GetAccountsHandlerHooks = {
16
16
  * @param hooks - Any hooks required by this handler.
17
17
  * @returns The JSON-RPC response.
18
18
  */
19
- export declare function getAccountsHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse<Json>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: GetAccountsHandlerHooks): Promise<void>;
19
+ export declare function getAccountsHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: GetAccountsHandlerHooks): Promise<void>;
20
20
  //# sourceMappingURL=accounts.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"accounts.d.mts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AAEnC,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC,EACtC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,uBAAuB,iBAiB/B"}
1
+ {"version":3,"file":"accounts.d.mts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,wBAAwB;AAE9E,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,sBAAsB,EAChC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,uBAAuB,iBAiB/B"}
@@ -1 +1 @@
1
- {"version":3,"file":"accounts.mjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/accounts.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,2BAA2B;AAW/C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAwB,EACxB,QAAsC,EACtC,KAAgC,EAChC,GAA6B,EAC7B,KAA8B;IAE9B,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAE9B,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,kBAAkB,CAAC;QAC9C,cAAc,EAAE;YACd,MAAM,WAAW,EAAE;YACnB,WAAW;YACX,WAAW;YACX,UAAU;YACV,SAAS;YACT,SAAS;SACV;KACF,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","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 * @returns The JSON-RPC response.\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"]}
1
+ {"version":3,"file":"accounts.mjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/accounts.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,2BAA2B;AAO/C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAwB,EACxB,QAAgC,EAChC,KAAgC,EAChC,GAA6B,EAC7B,KAA8B;IAE9B,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAE9B,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,kBAAkB,CAAC;QAC9C,cAAc,EAAE;YACd,MAAM,WAAW,EAAE;YACnB,WAAW;YACX,WAAW;YACX,UAAU;YACV,SAAS;YACT,SAAS;SACV;KACF,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport { BIP44Node } from '@metamask/key-tree';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } 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 * @returns The JSON-RPC response.\n */\nexport async function getAccountsHandler(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse,\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"chain-id.cjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/chain-id.ts"],"names":[],"mappings":";;;AAUA;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,iBAAiB,CACrC,QAAwB,EACxB,QAAsC,EACtC,KAAgC,EAChC,GAA6B;IAE7B,uEAAuE;IACvE,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;IAEzB,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAXD,8CAWC","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 eth_chainId 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 * @returns The JSON-RPC response.\n */\nexport async function getChainIdHandler(\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 = '0x01';\n\n return end();\n}\n"]}
1
+ {"version":3,"file":"chain-id.cjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/chain-id.ts"],"names":[],"mappings":";;;AAMA;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,iBAAiB,CACrC,QAAwB,EACxB,QAAgC,EAChC,KAAgC,EAChC,GAA6B;IAE7B,uEAAuE;IACvE,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;IAEzB,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAXD,8CAWC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';\n\n/**\n * A mock handler for eth_chainId 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 * @returns The JSON-RPC response.\n */\nexport async function getChainIdHandler(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse,\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 = '0x01';\n\n return end();\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
2
- import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
2
+ import type { JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
3
3
  /**
4
4
  * A mock handler for eth_chainId that always returns a specific
5
5
  * hardcoded result.
@@ -12,5 +12,5 @@ import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/uti
12
12
  * @param end - The `json-rpc-engine` middleware end handler.
13
13
  * @returns The JSON-RPC response.
14
14
  */
15
- export declare function getChainIdHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse<Json>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback): Promise<void>;
15
+ export declare function getChainIdHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback): Promise<void>;
16
16
  //# sourceMappingURL=chain-id.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chain-id.d.cts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/chain-id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AACnC,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC,EACtC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,iBAO9B"}
1
+ {"version":3,"file":"chain-id.d.cts","sourceRoot":"","sources":["../../../src/middleware/internal-methods/chain-id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,wBAAwB;AAE9E;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,sBAAsB,EAChC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,iBAO9B"}
@@ -1,5 +1,5 @@
1
1
  import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
2
- import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
2
+ import type { JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
3
3
  /**
4
4
  * A mock handler for eth_chainId that always returns a specific
5
5
  * hardcoded result.
@@ -12,5 +12,5 @@ import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/uti
12
12
  * @param end - The `json-rpc-engine` middleware end handler.
13
13
  * @returns The JSON-RPC response.
14
14
  */
15
- export declare function getChainIdHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse<Json>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback): Promise<void>;
15
+ export declare function getChainIdHandler(_request: JsonRpcRequest, response: PendingJsonRpcResponse, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback): Promise<void>;
16
16
  //# sourceMappingURL=chain-id.d.mts.map