From c42b341fe4c542974960752d6045f16288f06073 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 22 Jul 2020 08:40:28 +0200 Subject: [PATCH] Improve Secp256k1Wallet.fromMnemonic docs --- packages/sdk38/src/wallet.ts | 15 +++++++++++---- packages/sdk38/types/wallet.d.ts | 9 ++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/sdk38/src/wallet.ts b/packages/sdk38/src/wallet.ts index eb3059a3..1103f275 100644 --- a/packages/sdk38/src/wallet.ts +++ b/packages/sdk38/src/wallet.ts @@ -65,16 +65,23 @@ export function makeCosmoshubPath(a: number): readonly Slip10RawIndex[] { } export class Secp256k1Wallet implements OfflineSigner { + /** + * Restores a wallet from the given BIP39 mnemonic. + * + * @param mnemonic Any valid English mnemonic. + * @param hdPath The BIP-32/SLIP-10 derivation path. Defaults to the Cosmos Hub/ATOM path `m/44'/118'/0'/0/0`. + * @param prefix The bech32 address prefix (human readable part). Defaults to "cosmos". + */ public static async fromMnemonic( - mnemonicInput: string, + mnemonic: string, hdPath: readonly Slip10RawIndex[] = makeCosmoshubPath(0), prefix = "cosmos", ): Promise { - const mnemonic = new EnglishMnemonic(mnemonicInput); - const seed = await Bip39.mnemonicToSeed(mnemonic); + const mnemonicChecked = new EnglishMnemonic(mnemonic); + const seed = await Bip39.mnemonicToSeed(mnemonicChecked); const { privkey } = Slip10.derivePath(Slip10Curve.Secp256k1, seed, hdPath); const uncompressed = (await Secp256k1.makeKeypair(privkey)).pubkey; - return new Secp256k1Wallet(mnemonic, privkey, Secp256k1.compressPubkey(uncompressed), prefix); + return new Secp256k1Wallet(mnemonicChecked, privkey, Secp256k1.compressPubkey(uncompressed), prefix); } /** diff --git a/packages/sdk38/types/wallet.d.ts b/packages/sdk38/types/wallet.d.ts index 0f295b04..f37c6339 100644 --- a/packages/sdk38/types/wallet.d.ts +++ b/packages/sdk38/types/wallet.d.ts @@ -23,8 +23,15 @@ export interface OfflineSigner { */ export declare function makeCosmoshubPath(a: number): readonly Slip10RawIndex[]; export declare class Secp256k1Wallet implements OfflineSigner { + /** + * Restores a wallet from the given BIP39 mnemonic. + * + * @param mnemonic Any valid English mnemonic. + * @param hdPath The BIP-32/SLIP-10 derivation path. Defaults to the Cosmos Hub/ATOM path `m/44'/118'/0'/0/0`. + * @param prefix The bech32 address prefix (human readable part). Defaults to "cosmos". + */ static fromMnemonic( - mnemonicInput: string, + mnemonic: string, hdPath?: readonly Slip10RawIndex[], prefix?: string, ): Promise;