Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions packages/account-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- **BREAKING:** Use new `createAccounts` options for `AccountsProvider.createAccounts` ([#462](https://github.com/MetaMask/accounts/pull/462))
- This will allow to use various ways of constructing accounts (e.g. multiple indexes at once).
- **BREAKING:** Narrow `Bip44AccountProvider.capabilities` to only allow BIP-44 compatible capabilities ([#462](https://github.com/MetaMask/accounts/pull/462))

## [0.12.0]

### Changed
Expand Down
24 changes: 24 additions & 0 deletions packages/account-api/src/api/bip44.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type {
CreateAccountOptions,
KeyringAccount,
KeyringAccountEntropyMnemonicOptions,
KeyringCapabilities,
AccountCreationType,
} from '@metamask/keyring-api';

/**
Expand All @@ -14,6 +17,27 @@ export type Bip44Account<Account extends KeyringAccount> = Account & {
};
};

/**
* BIP-44 compatible account creation options.
*/
export type Bip44CreateAccountOptions = Extract<
CreateAccountOptions,
{
type:
| `${AccountCreationType.Bip44DerivePath}`
| `${AccountCreationType.Bip44DeriveIndex}`
| `${AccountCreationType.Bip44DeriveIndexRange}`
| `${AccountCreationType.Bip44Discover}`;
}
>;

/**
* BIP-44 compatible keyring capabilities.
*/
export type Bip44KeyringCapabilities = Required<
Pick<KeyringCapabilities, 'scopes' | 'bip44'>
>;

/**
* Checks if an account is BIP-44 compatible.
*
Expand Down
48 changes: 32 additions & 16 deletions packages/account-api/src/api/provider.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';
import type {
CreateAccountOptions,
EntropySourceId,
KeyringAccount,
KeyringCapabilities,
} from '@metamask/keyring-api';

import type { Bip44Account } from './bip44';
import type {
Bip44Account,
Bip44KeyringCapabilities,
Bip44CreateAccountOptions,

Check failure on line 11 in packages/account-api/src/api/provider.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (22.x)

'Bip44CreateAccountOptions' is defined but never used
} from './bip44';

/**
* An account provider is reponsible of providing accounts to an account group.
*/
export type AccountProvider<Account extends KeyringAccount> = {
/**
* Capabilities supported by this provider.
*/
get capabilities(): KeyringCapabilities;

/**
* Gets an account for a given ID.
*
Expand All @@ -21,18 +35,12 @@
getAccounts: () => Account[];

/**
* Creates accounts for a given entropy source and a given group
* index.
* Creates accounts according to the given options.
*
* @param options - Options.
* @param options.entropySource - Entropy source to use.
* @param options.groupIndex - Group index to use.
* @param options - Create accounts options.
* @returns The list of created accounts.
*/
createAccounts: (options: {
entropySource: EntropySourceId;
groupIndex: number;
}) => Promise<Account[]>;
createAccounts: (options: CreateAccountOptions) => Promise<Account[]>;

/**
* Discover accounts for a given entropy source and a given group
Expand All @@ -54,9 +62,17 @@
/**
* A BIP-44 provider is a provider that can provide BIP-44 compatible accounts.
*
* Note: This is an alias for the `AccountProvider` type, but with a more specific
* type for the account.
* NOTE: This is a narrow variant of the `AccountProvider` type for BIP-44.
*/
export type Bip44AccountProvider = AccountProvider<
Bip44Account<KeyringAccount>
>;
export type Bip44AccountProvider = Omit<
AccountProvider<Bip44Account<KeyringAccount>>,
'capabilities'
> & {
/**
* BIP-44 capabilities supported by this provider.
*/
get capabilities(): Bip44KeyringCapabilities;

// NOTE: We cannot narrow `createAccounts` here, otherwise it would become incompatible
// with the `AccountProvider` type.
};
Loading