@metamask/eip-5792-middleware
Version:
Implements the JSON-RPC methods for sending multiple calls from the user's wallet, and checking their status, as referenced in EIP-5792
1 lines • 2.21 kB
Source Map (JSON)
{"version":3,"file":"wallet_getCapabilities.mjs","sourceRoot":"","sources":["../../src/methods/wallet_getCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAGjD,OAAO,EAA4B,qBAAqB,EAAE,qBAAiB;AAC3E,OAAO,EAAE,6BAA6B,EAAE,cAAc,EAAE,qBAAiB;AAEzE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,GAAmB,EACnB,GAA2B,EAC3B,EACE,WAAW,EACX,eAAe,GAIhB;IAED,IAAI,CAAC,eAAe,EAAE;QACpB,MAAM,SAAS,CAAC,kBAAkB,EAAE,CAAC;KACtC;IAED,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAElD,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9B,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAE/B,MAAM,6BAA6B,CAAC,OAAO,EAAE,GAAG,EAAE;QAChD,WAAW;KACZ,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IAEnE,GAAG,CAAC,MAAM,GAAG,YAAY,CAAC;AAC5B,CAAC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { type GetCapabilitiesHook, GetCapabilitiesStruct } from '../types';\nimport { validateAndNormalizeKeyholder, validateParams } from '../utils';\n\n/**\n * The RPC method handler middleware for `wallet_getCapabilities`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks object.\n * @param hooks.getAccounts - Function that retrieves available accounts.\n * @param hooks.getCapabilities - Function that retrieves the capabilities for atomic transactions on specified chains.\n */\nexport async function walletGetCapabilities(\n req: JsonRpcRequest,\n res: PendingJsonRpcResponse,\n {\n getAccounts,\n getCapabilities,\n }: {\n getAccounts: (req: JsonRpcRequest) => Promise<string[]>;\n getCapabilities?: GetCapabilitiesHook;\n },\n): Promise<void> {\n if (!getCapabilities) {\n throw rpcErrors.methodNotSupported();\n }\n\n validateParams(req.params, GetCapabilitiesStruct);\n\n const address = req.params[0];\n const chainIds = req.params[1];\n\n await validateAndNormalizeKeyholder(address, req, {\n getAccounts,\n });\n\n const capabilities = await getCapabilities(address, chainIds, req);\n\n res.result = capabilities;\n}\n"]}