-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(accounts): move to single argument functions
- Loading branch information
Showing
7 changed files
with
51 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
import { HDKey } from "@scure/bip32"; | ||
import { mnemonicToSeedSync } from "@scure/bip39"; | ||
|
||
import type { HDAccount, HDOptions } from "../types"; | ||
import type { Simplify } from "type-fest"; | ||
import type { HDAccount } from "../types"; | ||
import { | ||
type HDKeyToAccountOptions, | ||
hdKeyToAccount, | ||
} from "./hd-key-to-account.js"; | ||
|
||
export type MnemonicToAccountOptions = HDKeyToAccountOptions; | ||
export type MnemonicToAccountOptions = Simplify< | ||
{ mnemonic: string } & Partial<HDKeyToAccountOptions> | ||
>; | ||
|
||
/** | ||
* @description Creates an Account from a mnemonic phrase. | ||
* | ||
* @returns A HD Account. | ||
*/ | ||
export function mnemonicToAccount( | ||
mnemonic: string, | ||
opts: HDOptions = {}, | ||
): HDAccount { | ||
export function mnemonicToAccount({ | ||
mnemonic, | ||
...opts | ||
}: MnemonicToAccountOptions): HDAccount { | ||
const seed = mnemonicToSeedSync(mnemonic); | ||
return hdKeyToAccount(HDKey.fromMasterSeed(seed), opts); | ||
return hdKeyToAccount({ ...opts, hdKey: HDKey.fromMasterSeed(seed) }); | ||
} |