@metamask/snaps-simulation
Version:
A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment
1 lines • 2.01 kB
Source Map (JSON)
{"version":3,"file":"accounts.mjs","sourceRoot":"","sources":["../../../src/middleware/internal-methods/accounts.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,2BAA2B;AAO/C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAwB,EACxB,QAAgC,EAChC,KAAgC,EAChC,GAA6B,EAC7B,KAA8B;IAE9B,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAE9B,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,kBAAkB,CAAC;QAC9C,cAAc,EAAE;YACd,MAAM,WAAW,EAAE;YACnB,WAAW;YACX,WAAW;YACX,UAAU;YACV,SAAS;YACT,SAAS;SACV;KACF,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport { BIP44Node } from '@metamask/key-tree';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';\n\nexport type GetAccountsHandlerHooks = {\n getMnemonic: () => Promise<Uint8Array>;\n};\n\n/**\n * A mock handler for account related methods that always returns the first\n * address for the selected secret recovery phrase.\n *\n * @param _request - Incoming JSON-RPC request. This is ignored for this\n * specific handler.\n * @param response - The outgoing JSON-RPC response, modified to return the\n * result.\n * @param _next - The `json-rpc-engine` middleware next handler.\n * @param end - The `json-rpc-engine` middleware end handler.\n * @param hooks - Any hooks required by this handler.\n * @returns The JSON-RPC response.\n */\nexport async function getAccountsHandler(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: GetAccountsHandlerHooks,\n) {\n const { getMnemonic } = hooks;\n\n const node = await BIP44Node.fromDerivationPath({\n derivationPath: [\n await getMnemonic(),\n `bip32:44'`,\n `bip32:60'`,\n `bip32:0'`,\n `bip32:0`,\n `bip32:0`,\n ],\n });\n\n response.result = [node.address];\n return end();\n}\n"]}