UNPKG

@metamask-previews/account-api

Version:
1 lines 1.95 kB
{"version":3,"file":"group.cjs","sourceRoot":"","sources":["../../src/api/group.ts"],"names":[],"mappings":";;;AAuCA,4CAKC;AAQD,0DAIC;AAnDY,QAAA,+BAA+B,GAAW,SAAS,CAAC;AACpD,QAAA,0BAA0B,GAAW,SAAS,CAAC;AA0B5D;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAC9B,QAAyB,EACzB,EAAU;IAEV,OAAO,GAAG,QAAQ,IAAI,EAAE,EAAE,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CACrC,QAAyB;IAEzB,OAAO,gBAAgB,CAAC,QAAQ,EAAE,uCAA+B,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\nimport type { AccountId } from '@metamask/keyring-utils';\n\nimport type { AccountWalletId } from './wallet';\n\nexport const DEFAULT_ACCOUNT_GROUP_UNIQUE_ID: string = 'default';\nexport const DEFAULT_ACCOUNT_GROUP_NAME: string = 'Default';\n\nexport type AccountGroupId = `${AccountWalletId}:${string}`;\n\nexport type AccountGroup<Account extends KeyringAccount> = {\n get id(): AccountGroupId;\n\n get index(): number;\n\n /**\n * Gets the \"blockchain\" accounts for this multichain account.\n *\n * @param id - Account ID.\n * @returns The \"blockchain\" accounts.\n */\n getAccounts(): Account[];\n\n /**\n * Gets the \"blockchain\" account for a given account ID.\n *\n * @param id - Account ID.\n * @returns The \"blockchain\" account or undefined if not found.\n */\n getAccount(id: AccountId): Account | undefined;\n};\n\n/**\n * Convert a wallet ID and a unique ID, to a group ID.\n *\n * @param walletId - A wallet ID.\n * @param id - A unique ID.\n * @returns A group ID.\n */\nexport function toAccountGroupId(\n walletId: AccountWalletId,\n id: string,\n): AccountGroupId {\n return `${walletId}:${id}`;\n}\n\n/**\n * Convert a wallet ID to the default group ID.\n *\n * @param walletId - A wallet ID.\n * @returns The default group ID.\n */\nexport function toDefaultAccountGroupId(\n walletId: AccountWalletId,\n): AccountGroupId {\n return toAccountGroupId(walletId, DEFAULT_ACCOUNT_GROUP_UNIQUE_ID);\n}\n"]}