UNPKG

@metamask/multichain-account-service

Version:
31 lines 1.46 kB
import { KeyringClient } from "@metamask/keyring-snap-client"; import { KeyringClient as KeyringClientV2 } from "@metamask/keyring-snap-client/v2"; /** * Builds a version-agnostic {@link SnapKeyringClient} backed by either the v1 * or v2 keyring client, based on the Snap's declared capabilities. * * @param sender - The transport used to talk to the Snap. * @param isV2 - Whether to back the client with the v2 keyring client. * @returns A {@link SnapKeyringClient}. */ export function createSnapKeyringClient(sender, isV2) { if (isV2) { const client = new KeyringClientV2(sender); return { getAccounts: async () => client.getAccounts(), deleteAccount: async (id) => client.deleteAccount(id), discoverAccounts: async () => { // v2 discovery is driven by `createAccounts({ bip44:discover })` through // the bridge keyring, so the client is never used for discovery here. throw new Error('discoverAccounts is not supported on the v2 keyring client'); }, }; } const client = new KeyringClient(sender); return { getAccounts: async () => client.listAccounts(), deleteAccount: async (id) => client.deleteAccount(id), discoverAccounts: async (scopes, entropySource, groupIndex) => client.discoverAccounts(scopes, entropySource, groupIndex), }; } //# sourceMappingURL=SnapKeyringClient.mjs.map