UNPKG

@metamask/multichain-account-service

Version:
35 lines 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createSnapKeyringClient = void 0; const keyring_snap_client_1 = require("@metamask/keyring-snap-client"); const v2_1 = require("@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}. */ function createSnapKeyringClient(sender, isV2) { if (isV2) { const client = new v2_1.KeyringClient(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 keyring_snap_client_1.KeyringClient(sender); return { getAccounts: async () => client.listAccounts(), deleteAccount: async (id) => client.deleteAccount(id), discoverAccounts: async (scopes, entropySource, groupIndex) => client.discoverAccounts(scopes, entropySource, groupIndex), }; } exports.createSnapKeyringClient = createSnapKeyringClient; //# sourceMappingURL=SnapKeyringClient.cjs.map