diff --git a/packages/keyring-controller/src/KeyringController.ts b/packages/keyring-controller/src/KeyringController.ts index 9bbfd729f7..dc67bcf85a 100644 --- a/packages/keyring-controller/src/KeyringController.ts +++ b/packages/keyring-controller/src/KeyringController.ts @@ -856,12 +856,27 @@ export class KeyringController extends BaseController< * Gets the seed phrase of the HD keyring. * * @param password - Password of the keyring. + * @param typeIndex - Hd keyring identifier * @returns Promise resolving to the seed phrase. */ - async exportSeedPhrase(password: string): Promise { + async exportSeedPhrase( + password: string, + typeIndex: number, + ): Promise { await this.verifyPassword(password); - assertHasUint8ArrayMnemonic(this.#keyrings[0]); - return this.#keyrings[0].mnemonic; + + const keyring = this.getKeyringsByType(KeyringTypes.hd).find( + (innerKeyring) => + (innerKeyring as EthKeyring & { opts: { typeIndex: number } }) + .opts.typeIndex === typeIndex, + ) as EthKeyring; + + if (!keyring) { + throw new Error(KeyringControllerError.KeyringNotFound); + } + + assertHasUint8ArrayMnemonic(keyring); + return keyring.mnemonic; } /** @@ -2247,7 +2262,7 @@ export class KeyringController extends BaseController< if (type === KeyringTypes.hd) { await keyring.deserialize({ ...(data ?? {}), - typeIndex: lastIndexOfType, + typeIndex: lastIndexOfType + 1, id: ulid(), }); } else {