@@ -14,6 +14,7 @@ import type {
1414 CaipChainId ,
1515 MetaMaskOptions ,
1616 KeyringResponse ,
17+ CreateAccountOptions ,
1718} from '@metamask/keyring-api' ;
1819import {
1920 EthBytesStruct ,
@@ -891,6 +892,39 @@ export class SnapKeyring {
891892 } ) ;
892893 }
893894
895+ /**
896+ * Create one or more accounts according to the provided options.
897+ *
898+ * This method supports batch account creation for BIP-44 derivation paths,
899+ * allowing the creation of multiple accounts up to a specified maximum index.
900+ *
901+ * @param snapId - Snap ID to create the accounts for.
902+ * @param options - Account creation options.
903+ * @returns A promise that resolves to an array of the created account objects.
904+ */
905+ async createAccounts (
906+ snapId : SnapId ,
907+ options : CreateAccountOptions ,
908+ ) : Promise < KeyringAccount [ ] > {
909+ const client = new KeyringInternalSnapClient ( {
910+ messenger : this . #messenger,
911+ snapId,
912+ } ) ;
913+
914+ // Add each returned account to the internal accounts map.
915+ // NOTE: This method DOES NOT rely on the `AccountCreated` event to add
916+ // accounts to the keyring, since those accounts are created in batch.
917+ const accounts = await client . createAccounts ( options ) ;
918+ for ( const account of accounts ) {
919+ this . #accounts. set ( account . id , { account, snapId } ) ;
920+ }
921+
922+ // Save the state after adding all accounts.
923+ await this . #callbacks. saveState ( ) ;
924+
925+ return accounts ;
926+ }
927+
894928 /**
895929 * Checks if a Snap ID is known from the keyring.
896930 *
0 commit comments