diff --git a/packages/snaps-jest/src/helpers.test.tsx b/packages/snaps-jest/src/helpers.test.tsx index 55ec99aee4..6be9793850 100644 --- a/packages/snaps-jest/src/helpers.test.tsx +++ b/packages/snaps-jest/src/helpers.test.tsx @@ -746,10 +746,8 @@ describe('installSnap', () => { const { onKeyringRequest, close } = await installSnap(snapId); const response = await onKeyringRequest({ origin: 'metamask.io', - request: { - params: {}, - method: 'keyring_listAccounts', - }, + params: {}, + method: 'keyring_listAccounts', }); expect(response).toStrictEqual( diff --git a/packages/snaps-simulation/src/helpers.test.tsx b/packages/snaps-simulation/src/helpers.test.tsx index 8a97508718..9983b479cc 100644 --- a/packages/snaps-simulation/src/helpers.test.tsx +++ b/packages/snaps-simulation/src/helpers.test.tsx @@ -472,8 +472,7 @@ describe('helpers', () => { const { snapId, close: closeServer } = await getMockServer({ sourceCode: ` module.exports.onKeyringRequest = async ({ origin, request }) => { - // return handleKeyringRequest(keyring, request); - return request; + return { success: true }; } `, }); @@ -481,23 +480,17 @@ describe('helpers', () => { const { onKeyringRequest, close } = await installSnap(snapId); const response = await onKeyringRequest({ origin: 'metamask.io', - request: { - params: { - foo: 'bar', - }, + params: { + foo: 'bar', }, + method: 'keyring_createAccount', }); expect(response).toStrictEqual( expect.objectContaining({ response: { result: { - id: 1, - jsonrpc: '2.0', - method: '', - params: { - foo: 'bar', - }, + success: true, }, }, }), diff --git a/packages/snaps-simulation/src/helpers.ts b/packages/snaps-simulation/src/helpers.ts index b68f1acb34..b9fb255346 100644 --- a/packages/snaps-simulation/src/helpers.ts +++ b/packages/snaps-simulation/src/helpers.ts @@ -10,7 +10,6 @@ import { addJsonRpcMock, removeJsonRpcMock } from './store'; import { assertIsResponseWithInterface, JsonRpcMockOptionsStruct, - KeyringOptionsStruct, SignatureOptionsStruct, TransactionOptionsStruct, } from './structs'; @@ -234,11 +233,6 @@ export function getHelpers({ ): Promise => { log('Sending keyring request %o.', request); - const { origin: keyringRequestOrigin, request: keyringRequest } = create( - request, - KeyringOptionsStruct, - ); - const response = await handleRequest({ snapId, store, @@ -246,7 +240,7 @@ export function getHelpers({ runSaga, controllerMessenger, handler: HandlerType.OnKeyringRequest, - request: { origin: keyringRequestOrigin, ...keyringRequest }, + request, }); return response; diff --git a/packages/snaps-simulation/src/structs.ts b/packages/snaps-simulation/src/structs.ts index 4976605c17..a9a51351d3 100644 --- a/packages/snaps-simulation/src/structs.ts +++ b/packages/snaps-simulation/src/structs.ts @@ -24,8 +24,6 @@ import { JsonStruct, StrictHexStruct, valueToBytes, - JsonRpcIdStruct, - JsonRpcParamsStruct, } from '@metamask/utils'; import { randomBytes } from 'crypto'; @@ -39,28 +37,6 @@ const BytesLikeStruct = union([ instance(Uint8Array), ]); -export const RequestOptionsStruct = object({ - /** - * The JSON-RPC request ID. - */ - id: optional(JsonRpcIdStruct), - - /** - * The JSON-RPC method. - */ - method: string(), - - /** - * The JSON-RPC params. - */ - params: optional(JsonRpcParamsStruct), - - /** - * The origin to send the request from. - */ - origin: optional(string()), -}); - export const TransactionOptionsStruct = object({ /** * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`. @@ -167,17 +143,6 @@ export const TransactionOptionsStruct = object({ ), }); -export const KeyringOptionsStruct = object({ - /** - * The origin making the Keyring request. - */ - origin: defaulted(string(), 'metamask.io'), - /** - * Keyring request object with params. - */ - request: RequestOptionsStruct, -}); - export const SignatureOptionsStruct = object({ /** * The origin making the signature request. diff --git a/packages/snaps-simulation/src/types.ts b/packages/snaps-simulation/src/types.ts index 9374ba5a70..c472220308 100644 --- a/packages/snaps-simulation/src/types.ts +++ b/packages/snaps-simulation/src/types.ts @@ -2,21 +2,36 @@ import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk'; import type { JSXElement } from '@metamask/snaps-sdk/jsx'; import type { InferMatching } from '@metamask/snaps-utils'; import type { Infer } from '@metamask/superstruct'; -import type { Json } from '@metamask/utils'; +import type { Json, JsonRpcId, JsonRpcParams } from '@metamask/utils'; import type { - KeyringOptionsStruct, - RequestOptionsStruct, SignatureOptionsStruct, SnapOptionsStruct, SnapResponseStruct, TransactionOptionsStruct, } from './structs'; -/** - * JSON RPC Request object. - */ -export type RequestOptions = Infer; +export type RequestOptions = { + /** + * The JSON-RPC request ID. + */ + id?: JsonRpcId; + + /** + * The JSON-RPC method. + */ + method: string; + + /** + * The JSON-RPC params. + */ + params?: JsonRpcParams; + + /** + * The origin to send the request from. + */ + origin?: string; +}; /** * The `runCronjob` options. This is the same as {@link RequestOptions}, except @@ -49,12 +64,8 @@ export type TransactionOptions = Infer; /** * The options to use for keyring requests. - * - * @property origin - The origin to send the signature request from. Defaults to - * `metamask.io`. - * @property request - Keyring request with params. */ -export type KeyringOptions = Infer; +export type KeyringOptions = RequestOptions; /** * The options to use for signature requests.