Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/account-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `assertIsBip44Account` ([#339](https://github.com/MetaMask/accounts/pull/339))

## [0.7.0]

### Added
Expand Down
14 changes: 14 additions & 0 deletions packages/account-api/src/api/bip44.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,17 @@ export function isBip44Account<Account extends KeyringAccount>(
KeyringAccountEntropyMnemonicOptionsStruct,
);
}

/**
* Asserts a keyring account is BIP-44 compatible.
*
* @param account - Keyring account to check.
* @throws If the keyring account is not compatible.
*/
export function assertIsBip44Account<Account extends KeyringAccount>(
account: Account,
): asserts account is Bip44Account<Account> {
if (!isBip44Account(account)) {
throw new Error('Account is not BIP-44 compatible');
}
}
5 changes: 5 additions & 0 deletions packages/account-api/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
toMultichainAccountWalletId,
toMultichainAccountGroupId,
isMultichainAccountGroupId,
assertIsBip44Account,
} from './api';

type MockedAccount = Bip44Account<InternalAccount>;
Expand Down Expand Up @@ -74,6 +75,7 @@ describe('index', () => {
describe('isBip44Account', () => {
it('returns true if the account is BIP-44 compatible', () => {
expect(isBip44Account(mockEvmAccount)).toBe(true);
expect(() => assertIsBip44Account(mockEvmAccount)).not.toThrow();
});

it.each([
Expand Down Expand Up @@ -134,6 +136,9 @@ describe('index', () => {
};

expect(isBip44Account(account)).toBe(false);
expect(() => assertIsBip44Account(account)).toThrow(
'Account is not BIP-44 compatible',
);
},
);
});
Expand Down
Loading