Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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/keyring-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add `Keyring.createAccounts` optional method ([#448](https://github.com/MetaMask/accounts/pull/448))
- This method is part of the keyring v2 specification and set as optional for backwards compatibility.
- This method can be used to create one or more accounts using the new keyring v2 account creation typed options.
- Add RPC support for this method through `KeyringRpcMethod.CreateAccounts`.
- Add support for account derivations using range of indices in `KeyringV2` ([#451](https://github.com/MetaMask/accounts/pull/451))
- Add `bip44:derive-index-range` capability to `KeyringCapabilities`.
- Add `AccountCreationType.Bip44DeriveIndexRange` and `CreateAccountBip44DeriveIndexRangeOptions`.
Expand Down
14 changes: 14 additions & 0 deletions packages/keyring-api/src/api/keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { Paginated, Pagination } from './pagination';
import type { KeyringRequest } from './request';
import type { KeyringResponse } from './response';
import type { Transaction } from './transaction';
import type { CreateAccountOptions } from './v2';

/**
* Keyring interface.
Expand Down Expand Up @@ -56,6 +57,19 @@ export type Keyring = {
options?: Record<string, Json> & MetaMaskOptions,
): Promise<KeyringAccount>;

/**
* Creates one or more new accounts according to the provided options.
*
* Deterministic account creation MUST be idempotent, meaning that for
* deterministic algorithms, like BIP-44, calling this method with the same
* options should always return the same accounts, even if the accounts
* already exist in the keyring.
*
* @param options - Options describing how to create the account(s).
* @returns A promise that resolves to an array of the created account objects.
*/
createAccounts?(options: CreateAccountOptions): Promise<KeyringAccount[]>;

/**
* Lists the assets of an account (fungibles and non-fungibles) represented
* by their respective CAIP-19:
Expand Down
19 changes: 19 additions & 0 deletions packages/keyring-api/src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
PaginationStruct,
CaipAccountIdStruct,
DiscoveredAccountStruct,
CreateAccountOptionsStruct,
} from './api';

/**
Expand All @@ -36,6 +37,7 @@ import {
export enum KeyringRpcMethod {
// Account management
CreateAccount = 'keyring_createAccount',
CreateAccounts = 'keyring_createAccounts',
DeleteAccount = 'keyring_deleteAccount',
DiscoverAccounts = 'keyring_discoverAccounts',
ExportAccount = 'keyring_exportAccount',
Expand Down Expand Up @@ -126,6 +128,23 @@ export const CreateAccountResponseStruct = KeyringAccountStruct;

export type CreateAccountResponse = Infer<typeof CreateAccountResponseStruct>;

// ----------------------------------------------------------------------------
// Create accounts

export const CreateAccountsRequestStruct = object({
...CommonHeader,
method: literal('keyring_createAccounts'),
params: object({
options: CreateAccountOptionsStruct,
}),
});

export type CreateAccountsRequest = Infer<typeof CreateAccountsRequestStruct>;

export const CreateAccountsResponseStruct = array(KeyringAccountStruct);

export type CreateAccountsResponse = Infer<typeof CreateAccountsResponseStruct>;

// ----------------------------------------------------------------------------
// Set selected accounts

Expand Down
6 changes: 6 additions & 0 deletions packages/keyring-snap-bridge/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]

### Added

- Add `SnapKeyring.createAccounts` method ([#448](https://github.com/MetaMask/accounts/pull/448))
- This method can be used to create one or more accounts using the new keyring v2 account creation typed options.
- Generic accounts will be filtered out if they are not allowed by the keyring configuration.

### Changed

- Bump `@metamask/snaps-controllers` from `^14.0.1` to `^17.2.0` ([#422](https://github.com/MetaMask/accounts/pull/422))
Expand Down
Loading
Loading