UNPKG

@metamask/snaps-rpc-methods

Version:
1 lines 2.32 kB
{"version":3,"file":"getSnaps.mjs","sourceRoot":"","sources":["../../src/permitted/getSnaps.ts"],"names":[],"mappings":"AAOA,MAAM,SAAS,GAAqC;IAClD,QAAQ,EAAE,IAAI;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAIxB;IACF,WAAW,EAAE,CAAC,iBAAiB,CAAC;IAChC,cAAc,EAAE,sBAAsB;IACtC,SAAS;CACV,CAAC;AASF;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,sBAAsB,CACnC,IAAa,EACb,GAA2C,EAC3C,KAAc,EACd,GAA6B,EAC7B,EAAE,QAAQ,EAAiB;IAE3B,0CAA0C;IAC1C,GAAG,CAAC,MAAM,GAAG,MAAM,QAAQ,EAAE,CAAC;IAC9B,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport type { GetSnapsResult } from '@metamask/snaps-sdk';\nimport type { JsonRpcParams, PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetSnapsHooks> = {\n getSnaps: true,\n};\n\n/**\n * `wallet_getSnaps` gets the requester's permitted and installed Snaps.\n */\nexport const getSnapsHandler: PermittedHandlerExport<\n GetSnapsHooks,\n JsonRpcParams,\n GetSnapsResult\n> = {\n methodNames: ['wallet_getSnaps'],\n implementation: getSnapsImplementation,\n hookNames,\n};\n\nexport type GetSnapsHooks = {\n /**\n * @returns The permitted and installed snaps for the requesting origin.\n */\n getSnaps: () => Promise<GetSnapsResult>;\n};\n\n/**\n * The `wallet_getSnaps` method implementation.\n * Fetches available snaps for the requesting origin and adds them to the JSON-RPC response.\n *\n * @param _req - The JSON-RPC request object. Not used by this function.\n * @param res - 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.\n * @param hooks.getSnaps - A function that returns the snaps available for the requesting origin.\n * @returns Nothing.\n */\nasync function getSnapsImplementation(\n _req: unknown,\n res: PendingJsonRpcResponse<GetSnapsResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getSnaps }: GetSnapsHooks,\n): Promise<void> {\n // getSnaps is already bound to the origin\n res.result = await getSnaps();\n return end();\n}\n"]}