UNPKG

@metamask/account-api

Version:
1 lines 1.76 kB
{"version":3,"file":"bip44.cjs","sourceRoot":"","sources":["../../src/api/bip44.ts"],"names":[],"mappings":";;AAsBA,wCAMC;AAQD,oDAMC;AA1BD;;;;;GAKG;AACH,SAAgB,cAAc,CAC5B,OAAgB;IAEhB,mEAAmE;IACnE,uDAAuD;IACvD,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,KAAK,UAAU,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,OAAgB;IAEhB,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;AACH,CAAC","sourcesContent":["import type {\n KeyringAccount,\n KeyringAccountEntropyMnemonicOptions,\n} from '@metamask/keyring-api';\n\n/**\n * BIP-44 compatible account type.\n */\nexport type Bip44Account<Account extends KeyringAccount> = Account & {\n // We force the option type for those accounts. (That's how we identify\n // if an account is BIP-44 compatible).\n options: {\n entropy: KeyringAccountEntropyMnemonicOptions;\n };\n};\n\n/**\n * Checks if an account is BIP-44 compatible.\n *\n * @param account - The account to be tested.\n * @returns True if the account is BIP-44 compatible.\n */\nexport function isBip44Account<Account extends KeyringAccount>(\n account: Account,\n): account is Bip44Account<Account> {\n // To be BIP-44 compatible, we just check for the entropy type (the\n // the `entropy` shape will be inferred automatically).\n return account.options.entropy?.type === 'mnemonic';\n}\n\n/**\n * Asserts a keyring account is BIP-44 compatible.\n *\n * @param account - Keyring account to check.\n * @throws If the keyring account is not compatible.\n */\nexport function assertIsBip44Account<Account extends KeyringAccount>(\n account: Account,\n): asserts account is Bip44Account<Account> {\n if (!isBip44Account(account)) {\n throw new Error('Account is not BIP-44 compatible');\n }\n}\n"]}