Improve Secp256k1Wallet.fromMnemonic docs

This commit is contained in:
Simon Warta 2020-07-22 08:40:28 +02:00
parent 57914c2a61
commit c42b341fe4
2 changed files with 19 additions and 5 deletions

View File

@ -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<Secp256k1Wallet> {
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);
}
/**

View File

@ -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<Secp256k1Wallet>;