@metamask/snaps-simulation 3.0.0 → 3.1.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [3.1.0]
11
+
12
+ ### Added
13
+
14
+ - Add support for `onStart` ([#3455](https://github.com/MetaMask/snaps/pull/3455))
15
+
10
16
  ## [3.0.0]
11
17
 
12
18
  ### Added
@@ -178,7 +184,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
178
184
 
179
185
  - Initial release of `@metamask/snaps-simulation` package ([#2727](https://github.com/MetaMask/snaps/pull/2727))
180
186
 
181
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@3.0.0...HEAD
187
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@3.1.0...HEAD
188
+ [3.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@3.0.0...@metamask/snaps-simulation@3.1.0
182
189
  [3.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@2.7.0...@metamask/snaps-simulation@3.0.0
183
190
  [2.7.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@2.6.0...@metamask/snaps-simulation@2.7.0
184
191
  [2.6.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@2.5.0...@metamask/snaps-simulation@2.6.0
package/dist/helpers.cjs CHANGED
@@ -124,6 +124,23 @@ function getHelpers({ snapId, store, executionService, runSaga, controllerMessen
124
124
  },
125
125
  });
126
126
  },
127
+ // This can't be async because it returns a `SnapRequest`.
128
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
129
+ onStart: (request) => {
130
+ log('Running onStart handler.');
131
+ return (0, request_1.handleRequest)({
132
+ snapId,
133
+ store,
134
+ executionService,
135
+ controllerMessenger,
136
+ runSaga,
137
+ handler: snaps_utils_1.HandlerType.OnStart,
138
+ request: {
139
+ method: '',
140
+ ...request,
141
+ },
142
+ });
143
+ },
127
144
  onNameLookup: async (nameLookupOptions) => {
128
145
  log('Requesting name lookup %o.', nameLookupOptions);
129
146
  const params = (0, superstruct_1.create)(nameLookupOptions, structs_1.NameLookupOptionsStruct);
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AACpD,uDAA+C;AAE/C,2CAAqD;AAErD,yCAAsC;AAEtC,2CAA0C;AAE1C,6CAA4D;AAC5D,2CAMmB;AAcnB,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,mBAAU,EAAE,SAAS,CAAC,CAAC;AAmMtD;;;;;;;;;;;GAWG;AACH,SAAgB,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,GACwC;IAC/C,MAAM,aAAa,GAAG,KAAK,EACzB,OAA2B,EACS,EAAE;QACtC,GAAG,CAAC,yBAAyB,EAAE,OAAO,CAAC,CAAC;QAExC,MAAM,EACJ,MAAM,EAAE,iBAAiB,EACzB,OAAO,EACP,GAAG,WAAW,EACf,GAAG,IAAA,oBAAM,EAAC,OAAO,EAAE,kCAAwB,CAAC,CAAC;QAE9C,MAAM,QAAQ,GAAG,MAAM,IAAA,uBAAa,EAAC;YACnC,MAAM;YACN,KAAK;YACL,gBAAgB;YAChB,OAAO;YACP,mBAAmB;YACnB,OAAO,EAAE,yBAAW,CAAC,aAAa;YAClC,OAAO,EAAE;gBACP,MAAM,EAAE,EAAE;gBACV,MAAM,EAAE;oBACN,OAAO;oBACP,WAAW;oBACX,iBAAiB;iBAClB;aACF;SACF,CAAC,CAAC;QAEH,IAAA,uCAA6B,EAAC,QAAQ,CAAC,CAAC;QAExC,OAAO,QAAQ,CAAC;IAClB,CAAC,CAA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,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;AA5SD,gCA4SC","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 * Send a JSON-RPC client request to the Snap.\n *\n * @param request - The JSON-RPC request.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onClientRequest(request: Omit<RequestOptions, 'origin'>): SnapRequest;\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 // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onClientRequest: (request) => {\n log('Sending client request.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnClientRequest,\n request,\n });\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":[],"mappings":";;;AAAA,uDAAoD;AACpD,uDAA+C;AAE/C,2CAAqD;AA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,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;AA/TD,gCA+TC","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 `onStart` handler.\n *\n * @returns The response.\n */\n onStart(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 * Send a JSON-RPC client request to the Snap.\n *\n * @param request - The JSON-RPC request.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onClientRequest(request: Omit<RequestOptions, 'origin'>): SnapRequest;\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 // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onStart: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onStart handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnStart,\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 // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onClientRequest: (request) => {\n log('Sending client request.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnClientRequest,\n request,\n });\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"]}
@@ -112,6 +112,12 @@ export type SnapHelpers = {
112
112
  * @returns The response.
113
113
  */
114
114
  onUpdate(request?: Pick<RequestOptions, 'origin'>): SnapRequest;
115
+ /**
116
+ * Get the response from the Snap's `onStart` handler.
117
+ *
118
+ * @returns The response.
119
+ */
120
+ onStart(request?: Pick<RequestOptions, 'origin'>): SnapRequest;
115
121
  /**
116
122
  * Get the response from the Snap's `onNameLookup` handler.
117
123
  *
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.cts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAInD,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;IACH,aAAa,CACX,WAAW,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GACxC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAEtC;;;;;;;;OAQG;IACH,eAAe,CACb,WAAW,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GACxC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAEtC;;;;;;;OAOG;IACH,WAAW,CACT,SAAS,CAA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,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,GACR,EAAE,aAAa,GAAG;IAAE,OAAO,EAAE,iBAAiB,CAAA;CAAE,GAAG,WAAW,CAwT9D"}
@@ -112,6 +112,12 @@ export type SnapHelpers = {
112
112
  * @returns The response.
113
113
  */
114
114
  onUpdate(request?: Pick<RequestOptions, 'origin'>): SnapRequest;
115
+ /**
116
+ * Get the response from the Snap's `onStart` handler.
117
+ *
118
+ * @returns The response.
119
+ */
120
+ onStart(request?: Pick<RequestOptions, 'origin'>): SnapRequest;
115
121
  /**
116
122
  * Get the response from the Snap's `onNameLookup` handler.
117
123
  *
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.mts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAInD,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;IACH,aAAa,CACX,WAAW,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GACxC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAEtC;;;;;;;;OAQG;IACH,eAAe,CACb,WAAW,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GACxC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAEtC;;;;;;;OAOG;IACH,WAAW,CACT,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GACpC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,OAAO,GACR,EAAE,aAAa,GAAG;IAAE,OAAO,EAAE,iBAAiB,CAAA;CAAE,GAAG,WAAW,CAwT9D"}
package/dist/helpers.mjs CHANGED
@@ -121,6 +121,23 @@ export function getHelpers({ snapId, store, executionService, runSaga, controlle
121
121
  },
122
122
  });
123
123
  },
124
+ // This can't be async because it returns a `SnapRequest`.
125
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
126
+ onStart: (request) => {
127
+ log('Running onStart handler.');
128
+ return handleRequest({
129
+ snapId,
130
+ store,
131
+ executionService,
132
+ controllerMessenger,
133
+ runSaga,
134
+ handler: HandlerType.OnStart,
135
+ request: {
136
+ method: '',
137
+ ...request,
138
+ },
139
+ });
140
+ },
124
141
  onNameLookup: async (nameLookupOptions) => {
125
142
  log('Requesting name lookup %o.', nameLookupOptions);
126
143
  const params = create(nameLookupOptions, NameLookupOptionsStruct);
@@ -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;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,EACtB,wBAAwB,EACzB,sBAAkB;AAcnB,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAmMtD;;;;;;;;;;;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,EACzB,OAA2B,E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,CAAC,CAAC;QACL,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 * Send a JSON-RPC client request to the Snap.\n *\n * @param request - The JSON-RPC request.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onClientRequest(request: Omit<RequestOptions, 'origin'>): SnapRequest;\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 // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onClientRequest: (request) => {\n log('Sending client request.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnClientRequest,\n request,\n });\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,EACtB,wBAAwB,EACzB,sBAAkB;AAcnB,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AA0MtD;;;;;;;;;;;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,EACzB,OAA2B,EACS,EAAE;QACtC,GAAG,CAAC,yBAAyB,EAAE,OAAO,CAAC,CAAC;QAExC,MAAM,EACJ,MAAM,EAAE,iBAAiB,EACzB,OAAO,EACP,GAAG,WAAW,EACf,GAAG,MAAM,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAAC;QAE9C,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC;YACnC,MAAM;YACN,KAAK;YACL,gBAAgB;YAChB,OAAO;YACP,mBAAmB;YACnB,OAAO,EAAE,W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CAAC,eAAe;gBACpC,OAAO;aACR,CAAC,CAAC;QACL,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 `onStart` handler.\n *\n * @returns The response.\n */\n onStart(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 * Send a JSON-RPC client request to the Snap.\n *\n * @param request - The JSON-RPC request.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onClientRequest(request: Omit<RequestOptions, 'origin'>): SnapRequest;\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 // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onStart: (request?: Pick<RequestOptions, 'origin'>) => {\n log('Running onStart handler.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnStart,\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 // This can't be async because it returns a `SnapRequest`.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n onClientRequest: (request) => {\n log('Sending client request.');\n\n return handleRequest({\n snapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnClientRequest,\n request,\n });\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 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport type {\n CaipChainId,\n Json,\n JsonRpcId,\n JsonRpcParams,\n} from '@metamask/utils';\n\nimport type {\n NameLookupOptionsStruct,\n SignatureOptionsStruct,\n SnapOptionsStruct,\n SnapResponseStruct,\n TransactionOptionsStruct,\n} from './structs';\n\nexport type RequestOptions = {\n /**\n * The JSON-RPC request ID.\n */\n id?: JsonRpcId;\n\n /**\n * The JSON-RPC method.\n */\n method: string;\n\n /**\n * The JSON-RPC params.\n */\n params?: JsonRpcParams;\n\n /**\n * The origin to send the request from.\n */\n origin?: string;\n};\n\n/**\n * The `runCronjob` options. This is the same as {@link RequestOptions}, except\n * that it does not have an `origin` property.\n */\nexport type CronjobOptions = Omit<RequestOptions, 'origin'>;\n\n/**\n * The options to use for transaction requests.\n *\n * @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults\n * to `eip155:1`.\n * @property origin - The origin to send the transaction from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the transaction from. Defaults to a\n * randomly generated address.\n * @property to - The address to send the transaction to. Defaults to a randomly\n * generated address.\n * @property value - The value to send with the transaction. Defaults to `0`.\n * @property data - The data to send with the transaction. Defaults to `0x`.\n * @property gasLimit - The gas limit to use for the transaction. Defaults to\n * `21_000`.\n * @property maxFeePerGas - The maximum fee per gas to use for the transaction.\n * Defaults to `1`.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas to use for\n * the transaction. Defaults to `1`.\n * @property nonce - The nonce to use for the transaction. Defaults to `0`.\n */\nexport type TransactionOptions = Infer<typeof TransactionOptionsStruct>;\n\n/**\n * The options to use for keyring requests.\n */\nexport type KeyringOptions = RequestOptions;\n\n/**\n * The options to use for name lookup requests.\n *\n * @property chainId - Chain ID.\n * @property domain - Domain name to lookup and resolve.\n * @property address - Address to lookup and resolve.\n */\nexport type NameLookupOptions = Infer<typeof NameLookupOptionsStruct>;\n\n/**\n * The options to use for signature requests.\n *\n * @property origin - The origin to send the signature request from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the signature from. Defaults to a\n * randomly generated address.\n * @property data - The data to sign. Defaults to `0x`.\n * @property signatureMethod - The signature method.\n */\nexport type SignatureOptions = Infer<typeof SignatureOptionsStruct>;\n\n/**\n * The options to use for requests to the snap.\n *\n * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.\n */\nexport type SnapOptions = Infer<typeof SnapOptionsStruct>;\n\n/**\n * Options for uploading a file.\n *\n * @property fileName - The name of the file. By default, this is inferred from\n * the file path if it's a path, and defaults to an empty string if it's a\n * `Uint8Array`.\n * @property contentType - The content type of the file. By default, this is\n * inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type cannot\n * be inferred from the file name.\n */\nexport type FileOptions = {\n fileName?: string;\n contentType?: string;\n};\n\nexport type SnapInterfaceActions = {\n /**\n * Click on an interface element.\n *\n * @param name - The element name to click.\n */\n clickElement(name: string): Promise<void>;\n\n /**\n * Type a value in a interface field.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n typeInField(name: string, value: string): Promise<void>;\n\n /**\n * Select an option with a value in a dropdown.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectInDropdown(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from radio group.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromRadioGroup(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from Selector component.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromSelector(name: string, value: string): Promise<void>;\n\n /**\n * Upload a file.\n *\n * @param name - The element name to upload the file to.\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n */\n uploadFile(\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n ): Promise<void>;\n\n /**\n * Wait for the interface to be updated.\n */\n waitForUpdate: () => Promise<SnapHandlerInterface>;\n};\n\n/**\n * A `snap_dialog` alert interface.\n */\nexport type SnapAlertInterface = {\n /**\n * The type of the interface. This is always `alert`.\n */\n type: 'alert';\n\n /**\n * The content to show in the alert.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the alert.\n */\n ok(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` confirmation interface.\n */\nexport type SnapConfirmationInterface = {\n /**\n * The type of the interface. This is always `confirmation`.\n */\n type: 'confirmation';\n\n /**\n * The content to show in the confirmation.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the confirmation.\n */\n ok(): Promise<void>;\n\n /**\n * Cancel the confirmation.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` prompt interface.\n */\nexport type SnapPromptInterface = {\n /**\n * The type of the interface. This is always `prompt`.\n */\n type: 'prompt';\n\n /**\n * The content to show in the prompt.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the prompt.\n *\n * @param value - The value to close the prompt with.\n */\n ok(value?: string): Promise<void>;\n\n /**\n * Cancel the prompt.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with two buttons defined.\n * The approval of this confirmation is handled by the snap.\n */\nexport type DefaultSnapInterfaceWithFooter = {\n /**\n * The content to show in the interface.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with one button defined.\n * A cancel button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithPartialFooter =\n DefaultSnapInterfaceWithFooter & {\n /**\n * Cancel the dialog.\n */\n cancel(): Promise<void>;\n };\n\n/**\n * A `snap_dialog` default interface that has no Footer defined.\n * A cancel and ok button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithoutFooter =\n DefaultSnapInterfaceWithPartialFooter & {\n /**\n * Close the dialog.\n *\n */\n ok(): Promise<void>;\n };\n\nexport type DefaultSnapInterface = (\n | DefaultSnapInterfaceWithFooter\n | DefaultSnapInterfaceWithPartialFooter\n | DefaultSnapInterfaceWithoutFooter\n) & {\n type?: never;\n};\n\nexport type SnapInterface = (\n | SnapAlertInterface\n | SnapConfirmationInterface\n | SnapPromptInterface\n | DefaultSnapInterface\n) &\n SnapInterfaceActions;\n\nexport type SnapRequestObject = {\n /**\n * Get a user interface object from a snap. This will throw an error if the\n * snap does not show a user interface within the timeout.\n *\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\n getInterface(options?: SnapOptions): Promise<SnapInterface>;\n};\n\n/**\n * A pending request object. This is a promise with extra\n * {@link SnapRequestObject} fields.\n */\nexport type SnapRequest = Promise<SnapResponse> & SnapRequestObject;\n\n/**\n * The options to use for mocking a JSON-RPC request.\n */\nexport type JsonRpcMockOptions = {\n /**\n * The JSON-RPC request method.\n */\n method: string;\n\n /**\n * The JSON-RPC response, which will be returned when a request with the\n * specified method is sent.\n */\n result: Json;\n};\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 Snap = {\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 cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified as the `request` param in 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 to the Snap.\n *\n * @param keyringRequest - Keyring request options.\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 nameLookupRequest: 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 * Send a JSON-RPC client request to the Snap.\n *\n * @param request - The JSON-RPC request.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onClientRequest(request: Omit<RequestOptions, 'origin'>): SnapRequest;\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 * @deprecated Snaps are now automatically closed when the test ends. This\n * method will be removed in a future release.\n */\n close(): Promise<void>;\n};\n\nexport type SnapHandlerInterface = {\n content: JSXElement;\n} & SnapInterfaceActions;\n\nexport type SnapResponseWithInterface = {\n id: string;\n response: { result: Json } | { error: Json };\n notifications: {\n id: string;\n message: string;\n type: EnumToUnion<NotificationType>;\n title?: string | undefined;\n content?: string | undefined;\n footerLink?: { text: string; href: string } | undefined;\n }[];\n getInterface(): SnapHandlerInterface;\n};\n\nexport type SnapResponseWithoutInterface = Omit<\n SnapResponseWithInterface,\n 'getInterface'\n>;\n\nexport type SnapResponseType =\n | SnapResponseWithoutInterface\n | SnapResponseWithInterface;\n\nexport type SnapResponse = InferMatching<\n typeof SnapResponseStruct,\n SnapResponseType\n>;\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport type {\n CaipChainId,\n Json,\n JsonRpcId,\n JsonRpcParams,\n} from '@metamask/utils';\n\nimport type {\n NameLookupOptionsStruct,\n SignatureOptionsStruct,\n SnapOptionsStruct,\n SnapResponseStruct,\n TransactionOptionsStruct,\n} from './structs';\n\nexport type RequestOptions = {\n /**\n * The JSON-RPC request ID.\n */\n id?: JsonRpcId;\n\n /**\n * The JSON-RPC method.\n */\n method: string;\n\n /**\n * The JSON-RPC params.\n */\n params?: JsonRpcParams;\n\n /**\n * The origin to send the request from.\n */\n origin?: string;\n};\n\n/**\n * The `runCronjob` options. This is the same as {@link RequestOptions}, except\n * that it does not have an `origin` property.\n */\nexport type CronjobOptions = Omit<RequestOptions, 'origin'>;\n\n/**\n * The options to use for transaction requests.\n *\n * @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults\n * to `eip155:1`.\n * @property origin - The origin to send the transaction from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the transaction from. Defaults to a\n * randomly generated address.\n * @property to - The address to send the transaction to. Defaults to a randomly\n * generated address.\n * @property value - The value to send with the transaction. Defaults to `0`.\n * @property data - The data to send with the transaction. Defaults to `0x`.\n * @property gasLimit - The gas limit to use for the transaction. Defaults to\n * `21_000`.\n * @property maxFeePerGas - The maximum fee per gas to use for the transaction.\n * Defaults to `1`.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas to use for\n * the transaction. Defaults to `1`.\n * @property nonce - The nonce to use for the transaction. Defaults to `0`.\n */\nexport type TransactionOptions = Infer<typeof TransactionOptionsStruct>;\n\n/**\n * The options to use for keyring requests.\n */\nexport type KeyringOptions = RequestOptions;\n\n/**\n * The options to use for name lookup requests.\n *\n * @property chainId - Chain ID.\n * @property domain - Domain name to lookup and resolve.\n * @property address - Address to lookup and resolve.\n */\nexport type NameLookupOptions = Infer<typeof NameLookupOptionsStruct>;\n\n/**\n * The options to use for signature requests.\n *\n * @property origin - The origin to send the signature request from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the signature from. Defaults to a\n * randomly generated address.\n * @property data - The data to sign. Defaults to `0x`.\n * @property signatureMethod - The signature method.\n */\nexport type SignatureOptions = Infer<typeof SignatureOptionsStruct>;\n\n/**\n * The options to use for requests to the snap.\n *\n * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.\n */\nexport type SnapOptions = Infer<typeof SnapOptionsStruct>;\n\n/**\n * Options for uploading a file.\n *\n * @property fileName - The name of the file. By default, this is inferred from\n * the file path if it's a path, and defaults to an empty string if it's a\n * `Uint8Array`.\n * @property contentType - The content type of the file. By default, this is\n * inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type cannot\n * be inferred from the file name.\n */\nexport type FileOptions = {\n fileName?: string;\n contentType?: string;\n};\n\nexport type SnapInterfaceActions = {\n /**\n * Click on an interface element.\n *\n * @param name - The element name to click.\n */\n clickElement(name: string): Promise<void>;\n\n /**\n * Type a value in a interface field.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n typeInField(name: string, value: string): Promise<void>;\n\n /**\n * Select an option with a value in a dropdown.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectInDropdown(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from radio group.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromRadioGroup(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from Selector component.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromSelector(name: string, value: string): Promise<void>;\n\n /**\n * Upload a file.\n *\n * @param name - The element name to upload the file to.\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n */\n uploadFile(\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n ): Promise<void>;\n\n /**\n * Wait for the interface to be updated.\n */\n waitForUpdate: () => Promise<SnapHandlerInterface>;\n};\n\n/**\n * A `snap_dialog` alert interface.\n */\nexport type SnapAlertInterface = {\n /**\n * The type of the interface. This is always `alert`.\n */\n type: 'alert';\n\n /**\n * The content to show in the alert.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the alert.\n */\n ok(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` confirmation interface.\n */\nexport type SnapConfirmationInterface = {\n /**\n * The type of the interface. This is always `confirmation`.\n */\n type: 'confirmation';\n\n /**\n * The content to show in the confirmation.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the confirmation.\n */\n ok(): Promise<void>;\n\n /**\n * Cancel the confirmation.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` prompt interface.\n */\nexport type SnapPromptInterface = {\n /**\n * The type of the interface. This is always `prompt`.\n */\n type: 'prompt';\n\n /**\n * The content to show in the prompt.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the prompt.\n *\n * @param value - The value to close the prompt with.\n */\n ok(value?: string): Promise<void>;\n\n /**\n * Cancel the prompt.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with two buttons defined.\n * The approval of this confirmation is handled by the snap.\n */\nexport type DefaultSnapInterfaceWithFooter = {\n /**\n * The content to show in the interface.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with one button defined.\n * A cancel button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithPartialFooter =\n DefaultSnapInterfaceWithFooter & {\n /**\n * Cancel the dialog.\n */\n cancel(): Promise<void>;\n };\n\n/**\n * A `snap_dialog` default interface that has no Footer defined.\n * A cancel and ok button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithoutFooter =\n DefaultSnapInterfaceWithPartialFooter & {\n /**\n * Close the dialog.\n *\n */\n ok(): Promise<void>;\n };\n\nexport type DefaultSnapInterface = (\n | DefaultSnapInterfaceWithFooter\n | DefaultSnapInterfaceWithPartialFooter\n | DefaultSnapInterfaceWithoutFooter\n) & {\n type?: never;\n};\n\nexport type SnapInterface = (\n | SnapAlertInterface\n | SnapConfirmationInterface\n | SnapPromptInterface\n | DefaultSnapInterface\n) &\n SnapInterfaceActions;\n\nexport type SnapRequestObject = {\n /**\n * Get a user interface object from a snap. This will throw an error if the\n * snap does not show a user interface within the timeout.\n *\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\n getInterface(options?: SnapOptions): Promise<SnapInterface>;\n};\n\n/**\n * A pending request object. This is a promise with extra\n * {@link SnapRequestObject} fields.\n */\nexport type SnapRequest = Promise<SnapResponse> & SnapRequestObject;\n\n/**\n * The options to use for mocking a JSON-RPC request.\n */\nexport type JsonRpcMockOptions = {\n /**\n * The JSON-RPC request method.\n */\n method: string;\n\n /**\n * The JSON-RPC response, which will be returned when a request with the\n * specified method is sent.\n */\n result: Json;\n};\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 Snap = {\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 cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified as the `request` param in 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 to the Snap.\n *\n * @param keyringRequest - Keyring request options.\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 `onStart` handler.\n *\n * @returns The response.\n */\n onStart(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 nameLookupRequest: 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 * Send a JSON-RPC client request to the Snap.\n *\n * @param request - The JSON-RPC request.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onClientRequest(request: Omit<RequestOptions, 'origin'>): SnapRequest;\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 * @deprecated Snaps are now automatically closed when the test ends. This\n * method will be removed in a future release.\n */\n close(): Promise<void>;\n};\n\nexport type SnapHandlerInterface = {\n content: JSXElement;\n} & SnapInterfaceActions;\n\nexport type SnapResponseWithInterface = {\n id: string;\n response: { result: Json } | { error: Json };\n notifications: {\n id: string;\n message: string;\n type: EnumToUnion<NotificationType>;\n title?: string | undefined;\n content?: string | undefined;\n footerLink?: { text: string; href: string } | undefined;\n }[];\n getInterface(): SnapHandlerInterface;\n};\n\nexport type SnapResponseWithoutInterface = Omit<\n SnapResponseWithInterface,\n 'getInterface'\n>;\n\nexport type SnapResponseType =\n | SnapResponseWithoutInterface\n | SnapResponseWithInterface;\n\nexport type SnapResponse = InferMatching<\n typeof SnapResponseStruct,\n SnapResponseType\n>;\n"]}
package/dist/types.d.cts CHANGED
@@ -403,6 +403,12 @@ export type Snap = {
403
403
  * @returns The response.
404
404
  */
405
405
  onUpdate(request?: Pick<RequestOptions, 'origin'>): SnapRequest;
406
+ /**
407
+ * Get the response from the Snap's `onStart` handler.
408
+ *
409
+ * @returns The response.
410
+ */
411
+ onStart(request?: Pick<RequestOptions, 'origin'>): SnapRequest;
406
412
  /**
407
413
  * Get the response from the Snap's `onNameLookup` handler.
408
414
  *
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,4BAA4B;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AACnD,OAAO,KAAK,EACV,WAAW,EACX,IAAI,EACJ,SAAS,EACT,aAAa,EACd,wBAAwB;AAEzB,OAAO,KAAK,EACV,uBAAuB,EACvB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACzB,sBAAkB;AAEnB,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,EAAE,CAAC,EAAE,SAAS,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;IAEvB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,cAAc,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEtE;;;;;;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AAkB,EACzB,gBAAgB,CACjB,CAAC"}
package/dist/types.d.mts CHANGED
@@ -403,6 +403,12 @@ export type Snap = {
403
403
  * @returns The response.
404
404
  */
405
405
  onUpdate(request?: Pick<RequestOptions, 'origin'>): SnapRequest;
406
+ /**
407
+ * Get the response from the Snap's `onStart` handler.
408
+ *
409
+ * @returns The response.
410
+ */
411
+ onStart(request?: Pick<RequestOptions, 'origin'>): SnapRequest;
406
412
  /**
407
413
  * Get the response from the Snap's `onNameLookup` handler.
408
414
  *
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,4BAA4B;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AACnD,OAAO,KAAK,EACV,WAAW,EACX,IAAI,EACJ,SAAS,EACT,aAAa,EACd,wBAAwB;AAEzB,OAAO,KAAK,EACV,uBAAuB,EACvB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACzB,sBAAkB;AAEnB,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,EAAE,CAAC,EAAE,SAAS,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;IAEvB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,cAA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f,CAAC;AAEF,MAAM,MAAM,gBAAgB,GACxB,4BAA4B,GAC5B,yBAAyB,CAAC;AAE9B,MAAM,MAAM,YAAY,GAAG,aAAa,CACtC,OAAO,kBAAkB,EACzB,gBAAgB,CACjB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport type {\n CaipChainId,\n Json,\n JsonRpcId,\n JsonRpcParams,\n} from '@metamask/utils';\n\nimport type {\n NameLookupOptionsStruct,\n SignatureOptionsStruct,\n SnapOptionsStruct,\n SnapResponseStruct,\n TransactionOptionsStruct,\n} from './structs';\n\nexport type RequestOptions = {\n /**\n * The JSON-RPC request ID.\n */\n id?: JsonRpcId;\n\n /**\n * The JSON-RPC method.\n */\n method: string;\n\n /**\n * The JSON-RPC params.\n */\n params?: JsonRpcParams;\n\n /**\n * The origin to send the request from.\n */\n origin?: string;\n};\n\n/**\n * The `runCronjob` options. This is the same as {@link RequestOptions}, except\n * that it does not have an `origin` property.\n */\nexport type CronjobOptions = Omit<RequestOptions, 'origin'>;\n\n/**\n * The options to use for transaction requests.\n *\n * @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults\n * to `eip155:1`.\n * @property origin - The origin to send the transaction from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the transaction from. Defaults to a\n * randomly generated address.\n * @property to - The address to send the transaction to. Defaults to a randomly\n * generated address.\n * @property value - The value to send with the transaction. Defaults to `0`.\n * @property data - The data to send with the transaction. Defaults to `0x`.\n * @property gasLimit - The gas limit to use for the transaction. Defaults to\n * `21_000`.\n * @property maxFeePerGas - The maximum fee per gas to use for the transaction.\n * Defaults to `1`.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas to use for\n * the transaction. Defaults to `1`.\n * @property nonce - The nonce to use for the transaction. Defaults to `0`.\n */\nexport type TransactionOptions = Infer<typeof TransactionOptionsStruct>;\n\n/**\n * The options to use for keyring requests.\n */\nexport type KeyringOptions = RequestOptions;\n\n/**\n * The options to use for name lookup requests.\n *\n * @property chainId - Chain ID.\n * @property domain - Domain name to lookup and resolve.\n * @property address - Address to lookup and resolve.\n */\nexport type NameLookupOptions = Infer<typeof NameLookupOptionsStruct>;\n\n/**\n * The options to use for signature requests.\n *\n * @property origin - The origin to send the signature request from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the signature from. Defaults to a\n * randomly generated address.\n * @property data - The data to sign. Defaults to `0x`.\n * @property signatureMethod - The signature method.\n */\nexport type SignatureOptions = Infer<typeof SignatureOptionsStruct>;\n\n/**\n * The options to use for requests to the snap.\n *\n * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.\n */\nexport type SnapOptions = Infer<typeof SnapOptionsStruct>;\n\n/**\n * Options for uploading a file.\n *\n * @property fileName - The name of the file. By default, this is inferred from\n * the file path if it's a path, and defaults to an empty string if it's a\n * `Uint8Array`.\n * @property contentType - The content type of the file. By default, this is\n * inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type cannot\n * be inferred from the file name.\n */\nexport type FileOptions = {\n fileName?: string;\n contentType?: string;\n};\n\nexport type SnapInterfaceActions = {\n /**\n * Click on an interface element.\n *\n * @param name - The element name to click.\n */\n clickElement(name: string): Promise<void>;\n\n /**\n * Type a value in a interface field.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n typeInField(name: string, value: string): Promise<void>;\n\n /**\n * Select an option with a value in a dropdown.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectInDropdown(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from radio group.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromRadioGroup(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from Selector component.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromSelector(name: string, value: string): Promise<void>;\n\n /**\n * Upload a file.\n *\n * @param name - The element name to upload the file to.\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n */\n uploadFile(\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n ): Promise<void>;\n\n /**\n * Wait for the interface to be updated.\n */\n waitForUpdate: () => Promise<SnapHandlerInterface>;\n};\n\n/**\n * A `snap_dialog` alert interface.\n */\nexport type SnapAlertInterface = {\n /**\n * The type of the interface. This is always `alert`.\n */\n type: 'alert';\n\n /**\n * The content to show in the alert.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the alert.\n */\n ok(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` confirmation interface.\n */\nexport type SnapConfirmationInterface = {\n /**\n * The type of the interface. This is always `confirmation`.\n */\n type: 'confirmation';\n\n /**\n * The content to show in the confirmation.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the confirmation.\n */\n ok(): Promise<void>;\n\n /**\n * Cancel the confirmation.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` prompt interface.\n */\nexport type SnapPromptInterface = {\n /**\n * The type of the interface. This is always `prompt`.\n */\n type: 'prompt';\n\n /**\n * The content to show in the prompt.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the prompt.\n *\n * @param value - The value to close the prompt with.\n */\n ok(value?: string): Promise<void>;\n\n /**\n * Cancel the prompt.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with two buttons defined.\n * The approval of this confirmation is handled by the snap.\n */\nexport type DefaultSnapInterfaceWithFooter = {\n /**\n * The content to show in the interface.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with one button defined.\n * A cancel button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithPartialFooter =\n DefaultSnapInterfaceWithFooter & {\n /**\n * Cancel the dialog.\n */\n cancel(): Promise<void>;\n };\n\n/**\n * A `snap_dialog` default interface that has no Footer defined.\n * A cancel and ok button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithoutFooter =\n DefaultSnapInterfaceWithPartialFooter & {\n /**\n * Close the dialog.\n *\n */\n ok(): Promise<void>;\n };\n\nexport type DefaultSnapInterface = (\n | DefaultSnapInterfaceWithFooter\n | DefaultSnapInterfaceWithPartialFooter\n | DefaultSnapInterfaceWithoutFooter\n) & {\n type?: never;\n};\n\nexport type SnapInterface = (\n | SnapAlertInterface\n | SnapConfirmationInterface\n | SnapPromptInterface\n | DefaultSnapInterface\n) &\n SnapInterfaceActions;\n\nexport type SnapRequestObject = {\n /**\n * Get a user interface object from a snap. This will throw an error if the\n * snap does not show a user interface within the timeout.\n *\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\n getInterface(options?: SnapOptions): Promise<SnapInterface>;\n};\n\n/**\n * A pending request object. This is a promise with extra\n * {@link SnapRequestObject} fields.\n */\nexport type SnapRequest = Promise<SnapResponse> & SnapRequestObject;\n\n/**\n * The options to use for mocking a JSON-RPC request.\n */\nexport type JsonRpcMockOptions = {\n /**\n * The JSON-RPC request method.\n */\n method: string;\n\n /**\n * The JSON-RPC response, which will be returned when a request with the\n * specified method is sent.\n */\n result: Json;\n};\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 Snap = {\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 cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified as the `request` param in 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 to the Snap.\n *\n * @param keyringRequest - Keyring request options.\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 nameLookupRequest: 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 * Send a JSON-RPC client request to the Snap.\n *\n * @param request - The JSON-RPC request.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onClientRequest(request: Omit<RequestOptions, 'origin'>): SnapRequest;\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 * @deprecated Snaps are now automatically closed when the test ends. This\n * method will be removed in a future release.\n */\n close(): Promise<void>;\n};\n\nexport type SnapHandlerInterface = {\n content: JSXElement;\n} & SnapInterfaceActions;\n\nexport type SnapResponseWithInterface = {\n id: string;\n response: { result: Json } | { error: Json };\n notifications: {\n id: string;\n message: string;\n type: EnumToUnion<NotificationType>;\n title?: string | undefined;\n content?: string | undefined;\n footerLink?: { text: string; href: string } | undefined;\n }[];\n getInterface(): SnapHandlerInterface;\n};\n\nexport type SnapResponseWithoutInterface = Omit<\n SnapResponseWithInterface,\n 'getInterface'\n>;\n\nexport type SnapResponseType =\n | SnapResponseWithoutInterface\n | SnapResponseWithInterface;\n\nexport type SnapResponse = InferMatching<\n typeof SnapResponseStruct,\n SnapResponseType\n>;\n"]}
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport type {\n CaipChainId,\n Json,\n JsonRpcId,\n JsonRpcParams,\n} from '@metamask/utils';\n\nimport type {\n NameLookupOptionsStruct,\n SignatureOptionsStruct,\n SnapOptionsStruct,\n SnapResponseStruct,\n TransactionOptionsStruct,\n} from './structs';\n\nexport type RequestOptions = {\n /**\n * The JSON-RPC request ID.\n */\n id?: JsonRpcId;\n\n /**\n * The JSON-RPC method.\n */\n method: string;\n\n /**\n * The JSON-RPC params.\n */\n params?: JsonRpcParams;\n\n /**\n * The origin to send the request from.\n */\n origin?: string;\n};\n\n/**\n * The `runCronjob` options. This is the same as {@link RequestOptions}, except\n * that it does not have an `origin` property.\n */\nexport type CronjobOptions = Omit<RequestOptions, 'origin'>;\n\n/**\n * The options to use for transaction requests.\n *\n * @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults\n * to `eip155:1`.\n * @property origin - The origin to send the transaction from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the transaction from. Defaults to a\n * randomly generated address.\n * @property to - The address to send the transaction to. Defaults to a randomly\n * generated address.\n * @property value - The value to send with the transaction. Defaults to `0`.\n * @property data - The data to send with the transaction. Defaults to `0x`.\n * @property gasLimit - The gas limit to use for the transaction. Defaults to\n * `21_000`.\n * @property maxFeePerGas - The maximum fee per gas to use for the transaction.\n * Defaults to `1`.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas to use for\n * the transaction. Defaults to `1`.\n * @property nonce - The nonce to use for the transaction. Defaults to `0`.\n */\nexport type TransactionOptions = Infer<typeof TransactionOptionsStruct>;\n\n/**\n * The options to use for keyring requests.\n */\nexport type KeyringOptions = RequestOptions;\n\n/**\n * The options to use for name lookup requests.\n *\n * @property chainId - Chain ID.\n * @property domain - Domain name to lookup and resolve.\n * @property address - Address to lookup and resolve.\n */\nexport type NameLookupOptions = Infer<typeof NameLookupOptionsStruct>;\n\n/**\n * The options to use for signature requests.\n *\n * @property origin - The origin to send the signature request from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the signature from. Defaults to a\n * randomly generated address.\n * @property data - The data to sign. Defaults to `0x`.\n * @property signatureMethod - The signature method.\n */\nexport type SignatureOptions = Infer<typeof SignatureOptionsStruct>;\n\n/**\n * The options to use for requests to the snap.\n *\n * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.\n */\nexport type SnapOptions = Infer<typeof SnapOptionsStruct>;\n\n/**\n * Options for uploading a file.\n *\n * @property fileName - The name of the file. By default, this is inferred from\n * the file path if it's a path, and defaults to an empty string if it's a\n * `Uint8Array`.\n * @property contentType - The content type of the file. By default, this is\n * inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type cannot\n * be inferred from the file name.\n */\nexport type FileOptions = {\n fileName?: string;\n contentType?: string;\n};\n\nexport type SnapInterfaceActions = {\n /**\n * Click on an interface element.\n *\n * @param name - The element name to click.\n */\n clickElement(name: string): Promise<void>;\n\n /**\n * Type a value in a interface field.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n typeInField(name: string, value: string): Promise<void>;\n\n /**\n * Select an option with a value in a dropdown.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectInDropdown(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from radio group.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromRadioGroup(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from Selector component.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromSelector(name: string, value: string): Promise<void>;\n\n /**\n * Upload a file.\n *\n * @param name - The element name to upload the file to.\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n */\n uploadFile(\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n ): Promise<void>;\n\n /**\n * Wait for the interface to be updated.\n */\n waitForUpdate: () => Promise<SnapHandlerInterface>;\n};\n\n/**\n * A `snap_dialog` alert interface.\n */\nexport type SnapAlertInterface = {\n /**\n * The type of the interface. This is always `alert`.\n */\n type: 'alert';\n\n /**\n * The content to show in the alert.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the alert.\n */\n ok(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` confirmation interface.\n */\nexport type SnapConfirmationInterface = {\n /**\n * The type of the interface. This is always `confirmation`.\n */\n type: 'confirmation';\n\n /**\n * The content to show in the confirmation.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the confirmation.\n */\n ok(): Promise<void>;\n\n /**\n * Cancel the confirmation.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` prompt interface.\n */\nexport type SnapPromptInterface = {\n /**\n * The type of the interface. This is always `prompt`.\n */\n type: 'prompt';\n\n /**\n * The content to show in the prompt.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n\n /**\n * Close the prompt.\n *\n * @param value - The value to close the prompt with.\n */\n ok(value?: string): Promise<void>;\n\n /**\n * Cancel the prompt.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with two buttons defined.\n * The approval of this confirmation is handled by the snap.\n */\nexport type DefaultSnapInterfaceWithFooter = {\n /**\n * The content to show in the interface.\n */\n content: JSXElement;\n\n /**\n * The ID of the interface.\n */\n id: string;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with one button defined.\n * A cancel button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithPartialFooter =\n DefaultSnapInterfaceWithFooter & {\n /**\n * Cancel the dialog.\n */\n cancel(): Promise<void>;\n };\n\n/**\n * A `snap_dialog` default interface that has no Footer defined.\n * A cancel and ok button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithoutFooter =\n DefaultSnapInterfaceWithPartialFooter & {\n /**\n * Close the dialog.\n *\n */\n ok(): Promise<void>;\n };\n\nexport type DefaultSnapInterface = (\n | DefaultSnapInterfaceWithFooter\n | DefaultSnapInterfaceWithPartialFooter\n | DefaultSnapInterfaceWithoutFooter\n) & {\n type?: never;\n};\n\nexport type SnapInterface = (\n | SnapAlertInterface\n | SnapConfirmationInterface\n | SnapPromptInterface\n | DefaultSnapInterface\n) &\n SnapInterfaceActions;\n\nexport type SnapRequestObject = {\n /**\n * Get a user interface object from a snap. This will throw an error if the\n * snap does not show a user interface within the timeout.\n *\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\n getInterface(options?: SnapOptions): Promise<SnapInterface>;\n};\n\n/**\n * A pending request object. This is a promise with extra\n * {@link SnapRequestObject} fields.\n */\nexport type SnapRequest = Promise<SnapResponse> & SnapRequestObject;\n\n/**\n * The options to use for mocking a JSON-RPC request.\n */\nexport type JsonRpcMockOptions = {\n /**\n * The JSON-RPC request method.\n */\n method: string;\n\n /**\n * The JSON-RPC response, which will be returned when a request with the\n * specified method is sent.\n */\n result: Json;\n};\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 Snap = {\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 cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified as the `request` param in 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 to the Snap.\n *\n * @param keyringRequest - Keyring request options.\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 `onStart` handler.\n *\n * @returns The response.\n */\n onStart(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 nameLookupRequest: 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 * Send a JSON-RPC client request to the Snap.\n *\n * @param request - The JSON-RPC request.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onClientRequest(request: Omit<RequestOptions, 'origin'>): SnapRequest;\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 * @deprecated Snaps are now automatically closed when the test ends. This\n * method will be removed in a future release.\n */\n close(): Promise<void>;\n};\n\nexport type SnapHandlerInterface = {\n content: JSXElement;\n} & SnapInterfaceActions;\n\nexport type SnapResponseWithInterface = {\n id: string;\n response: { result: Json } | { error: Json };\n notifications: {\n id: string;\n message: string;\n type: EnumToUnion<NotificationType>;\n title?: string | undefined;\n content?: string | undefined;\n footerLink?: { text: string; href: string } | undefined;\n }[];\n getInterface(): SnapHandlerInterface;\n};\n\nexport type SnapResponseWithoutInterface = Omit<\n SnapResponseWithInterface,\n 'getInterface'\n>;\n\nexport type SnapResponseType =\n | SnapResponseWithoutInterface\n | SnapResponseWithInterface;\n\nexport type SnapResponse = InferMatching<\n typeof SnapResponseStruct,\n SnapResponseType\n>;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-simulation",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -61,12 +61,12 @@
61
61
  "@metamask/json-rpc-middleware-stream": "^8.0.7",
62
62
  "@metamask/key-tree": "^10.1.1",
63
63
  "@metamask/permission-controller": "^11.0.6",
64
- "@metamask/phishing-controller": "^12.5.0",
65
- "@metamask/snaps-controllers": "^13.0.0",
66
- "@metamask/snaps-execution-environments": "^9.0.0",
67
- "@metamask/snaps-rpc-methods": "^13.0.0",
68
- "@metamask/snaps-sdk": "^8.0.0",
69
- "@metamask/snaps-utils": "^10.0.0",
64
+ "@metamask/phishing-controller": "^12.6.0",
65
+ "@metamask/snaps-controllers": "^13.1.0",
66
+ "@metamask/snaps-execution-environments": "^9.1.0",
67
+ "@metamask/snaps-rpc-methods": "^13.1.0",
68
+ "@metamask/snaps-sdk": "^8.1.0",
69
+ "@metamask/snaps-utils": "^10.1.0",
70
70
  "@metamask/superstruct": "^3.2.1",
71
71
  "@metamask/utils": "^11.4.0",
72
72
  "@reduxjs/toolkit": "^1.9.5",