UNPKG

@metamask/account-api

Version:
48 lines 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MULTICHAIN_ACCOUNT_WALLET_ID_REGEX = void 0; exports.toMultichainAccountWalletId = toMultichainAccountWalletId; exports.isMultichainAccountWalletId = isMultichainAccountWalletId; exports.parseMultichainAccountWalletId = parseMultichainAccountWalletId; const wallet_1 = require("../wallet.cjs"); /** * Regex to validate a valid multichain account wallet ID. */ exports.MULTICHAIN_ACCOUNT_WALLET_ID_REGEX = /^(?<walletId>(?<walletType>entropy):(?<walletSubId>.+))$/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.AccountWalletType.Entropy}:${entropySource}`; } /** * Checks if the given value is {@link MultichainAccountWalletId}. * * @param value - The value to check. * @returns Whether the value is a {@link MultichainAccountWalletId}. */ function isMultichainAccountWalletId(value) { return exports.MULTICHAIN_ACCOUNT_WALLET_ID_REGEX.test(value); } /** * Parse a multichain account wallet ID to an object containing wallet ID * information (wallet type and sub-ID). * * @param walletId - The account wallet ID to validate and parse. * @returns The parsed account wallet ID. * @throws When the wallet ID format is invalid. */ function parseMultichainAccountWalletId(walletId) { const match = exports.MULTICHAIN_ACCOUNT_WALLET_ID_REGEX.exec(walletId); if (!match?.groups) { throw new Error(`Invalid multichain account wallet ID: "${walletId}"`); } return { type: match.groups.walletType, subId: match.groups.walletSubId, }; } //# sourceMappingURL=wallet.cjs.map