Skip to content

Commit 953c11a

Browse files
committed
fix: typeIndex increment and add arg for exportSeedPhrase
1 parent 5db6a42 commit 953c11a

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

packages/keyring-controller/src/KeyringController.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,12 +856,27 @@ export class KeyringController extends BaseController<
856856
* Gets the seed phrase of the HD keyring.
857857
*
858858
* @param password - Password of the keyring.
859+
* @param typeIndex - Hd keyring identifier
859860
* @returns Promise resolving to the seed phrase.
860861
*/
861-
async exportSeedPhrase(password: string): Promise<Uint8Array> {
862+
async exportSeedPhrase(
863+
password: string,
864+
typeIndex: number,
865+
): Promise<Uint8Array> {
862866
await this.verifyPassword(password);
863-
assertHasUint8ArrayMnemonic(this.#keyrings[0]);
864-
return this.#keyrings[0].mnemonic;
867+
868+
const keyring = this.getKeyringsByType(KeyringTypes.hd).find(
869+
(innerKeyring) =>
870+
(innerKeyring as EthKeyring<Json> & { opts: { typeIndex: number } })
871+
.opts.typeIndex === typeIndex,
872+
) as EthKeyring<Json>;
873+
874+
if (!keyring) {
875+
throw new Error(KeyringControllerError.KeyringNotFound);
876+
}
877+
878+
assertHasUint8ArrayMnemonic(keyring);
879+
return keyring.mnemonic;
865880
}
866881

867882
/**
@@ -2247,7 +2262,7 @@ export class KeyringController extends BaseController<
22472262
if (type === KeyringTypes.hd) {
22482263
await keyring.deserialize({
22492264
...(data ?? {}),
2250-
typeIndex: lastIndexOfType,
2265+
typeIndex: lastIndexOfType + 1,
22512266
id: ulid(),
22522267
});
22532268
} else {

0 commit comments

Comments
 (0)