UNPKG

@metamask-previews/account-api

Version:
43 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toMultichainAccountWalletId = toMultichainAccountWalletId; exports.toMultichainAccountId = toMultichainAccountId; exports.getGroupIndexFromAccountGroupId = getGroupIndexFromAccountGroupId; const wallet_1 = require("../wallet.cjs"); const GROUP_INDEX_REGEX = new RegExp(`^${wallet_1.AccountWalletCategory.Entropy}:.*:(?<groupIndex>\\d+)$`, 'u'); /** * Gets the multichain account wallet ID from its entropy source. * * @param entropySource - Entropy source ID of that wallet. * @returns The multichain account wallet ID. */ function toMultichainAccountWalletId(entropySource) { return `${wallet_1.AccountWalletCategory.Entropy}:${entropySource}`; } /** * Gets the multichain account ID from its multichain account wallet ID and its index. * * @param walletId - Multichain account wallet ID. * @param groupIndex - Index of that multichain account. * @returns The multichain account ID. */ function toMultichainAccountId(walletId, groupIndex) { return `${walletId}:${groupIndex}`; } /** * Gets the multichain account index from an account group ID. * * @param groupId - Account group ID. * @returns The multichain account index if extractable, undefined otherwise. */ function getGroupIndexFromAccountGroupId(groupId) { const matched = groupId.match(GROUP_INDEX_REGEX); if (matched) { if (matched.groups?.groupIndex !== undefined) { return Number(matched.groups.groupIndex); } } // Unable to extract group index. return undefined; } //# sourceMappingURL=id.cjs.map