Skip to content

Commit

Permalink
fix: typeIndex increment and add arg for exportSeedPhrase
Browse files Browse the repository at this point in the history
  • Loading branch information
montelaidev committed Dec 11, 2024
1 parent 5db6a42 commit 953c11a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions packages/keyring-controller/src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uint8Array> {
async exportSeedPhrase(
password: string,
typeIndex: number,
): Promise<Uint8Array> {
await this.verifyPassword(password);
assertHasUint8ArrayMnemonic(this.#keyrings[0]);
return this.#keyrings[0].mnemonic;

const keyring = this.getKeyringsByType(KeyringTypes.hd).find(
(innerKeyring) =>
(innerKeyring as EthKeyring<Json> & { opts: { typeIndex: number } })
.opts.typeIndex === typeIndex,
) as EthKeyring<Json>;

if (!keyring) {
throw new Error(KeyringControllerError.KeyringNotFound);
}

assertHasUint8ArrayMnemonic(keyring);
return keyring.mnemonic;
}

/**
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 953c11a

Please sign in to comment.