@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
1 lines • 2.7 kB
Source Map (JSON)
{"version":3,"file":"getAllSnaps.mjs","sourceRoot":"","sources":["../../src/permitted/getAllSnaps.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAajD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,cAAc,EAAE,yBAAyB;IACzC,WAAW,EAAE,CAAC,4BAA4B,CAAC;CAO5C,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,yBAAyB,CACtC,OAAiC,EACjC,QAAmD,EACnD,KAAc,EACd,GAA6B,EAC7B,MAAa,EACb,SAAsD;IAEtD,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAE3B,IAAI,MAAM,KAAK,2BAA2B,EAAE,CAAC;QAC3C,OAAO,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IAC/D,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { Messenger } from '@metamask/messenger';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { TruncatedSnap } from '@metamask/snaps-utils';\nimport type { JsonRpcParams, PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type {\n JsonRpcRequestWithOrigin,\n SnapControllerGetAllSnapsAction,\n} from '../types';\n\nexport type GetAllSnapsResult = TruncatedSnap[];\n\nexport type GetAllSnapsMethodActions = SnapControllerGetAllSnapsAction;\n\n/**\n * `wallet_getAllSnaps` gets all installed Snaps. Currently, this can only be\n * called from `https://snaps.metamask.io`.\n *\n * @internal\n */\nexport const getAllSnapsHandler = {\n implementation: getAllSnapsImplementation,\n actionNames: ['SnapController:getAllSnaps'],\n} satisfies MethodHandler<\n never,\n GetAllSnapsMethodActions,\n JsonRpcParams,\n GetAllSnapsResult,\n { origin: string }\n>;\n\n/**\n * The `wallet_getAllSnaps` method implementation.\n * Fetches all installed snaps and adds them to the JSON-RPC response.\n *\n * @param request - The JSON-RPC request object.\n * @param response - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param _hooks - The RPC method hooks. Not used by this function.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nasync function getAllSnapsImplementation(\n request: JsonRpcRequestWithOrigin,\n response: PendingJsonRpcResponse<GetAllSnapsResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n _hooks: never,\n messenger: Messenger<string, GetAllSnapsMethodActions>,\n): Promise<void> {\n const { origin } = request;\n\n if (origin !== 'https://snaps.metamask.io') {\n return end(rpcErrors.methodNotFound());\n }\n\n response.result = messenger.call('SnapController:getAllSnaps');\n return end();\n}\n"]}