From 83a17752843654ed993a69f33171ffdc573f4e19 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Tue, 15 Sep 2020 13:34:29 +0200 Subject: [PATCH] launchpad: Use HdPath type --- packages/launchpad/src/secp256k1wallet.ts | 10 +++++----- packages/launchpad/src/wallet.ts | 3 ++- packages/launchpad/types/secp256k1wallet.d.ts | 10 +++------- packages/launchpad/types/wallet.d.ts | 4 ++-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/launchpad/src/secp256k1wallet.ts b/packages/launchpad/src/secp256k1wallet.ts index 6c393cfa..5f5aea9a 100644 --- a/packages/launchpad/src/secp256k1wallet.ts +++ b/packages/launchpad/src/secp256k1wallet.ts @@ -1,12 +1,12 @@ import { Bip39, EnglishMnemonic, + HdPath, pathToString, Random, Secp256k1, Slip10, Slip10Curve, - Slip10RawIndex, stringToPath, } from "@cosmjs/crypto"; import { fromBase64, fromUtf8, toBase64, toUtf8 } from "@cosmjs/encoding"; @@ -104,7 +104,7 @@ export function extractKdfConfiguration(serialization: string): KdfConfiguration * Derivation information required to derive a keypair and an address from a mnemonic. */ interface Secp256k1Derivation { - readonly hdPath: readonly Slip10RawIndex[]; + readonly hdPath: HdPath; readonly prefix: string; } @@ -118,7 +118,7 @@ export class Secp256k1Wallet implements OfflineSigner { */ public static async fromMnemonic( mnemonic: string, - hdPath: readonly Slip10RawIndex[] = makeCosmoshubPath(0), + hdPath: HdPath = makeCosmoshubPath(0), prefix = "cosmos", ): Promise { const mnemonicChecked = new EnglishMnemonic(mnemonic); @@ -143,7 +143,7 @@ export class Secp256k1Wallet implements OfflineSigner { */ public static async generate( length: 12 | 15 | 18 | 21 | 24 = 12, - hdPath: readonly Slip10RawIndex[] = makeCosmoshubPath(0), + hdPath: HdPath = makeCosmoshubPath(0), prefix = "cosmos", ): Promise { const entropyLength = 4 * Math.floor((11 * length) / 33); @@ -223,7 +223,7 @@ export class Secp256k1Wallet implements OfflineSigner { private constructor( mnemonic: EnglishMnemonic, - hdPath: readonly Slip10RawIndex[], + hdPath: HdPath, privkey: Uint8Array, pubkey: Uint8Array, prefix: string, diff --git a/packages/launchpad/src/wallet.ts b/packages/launchpad/src/wallet.ts index f8e4b1ab..eaded173 100644 --- a/packages/launchpad/src/wallet.ts +++ b/packages/launchpad/src/wallet.ts @@ -1,5 +1,6 @@ import { Argon2id, + HdPath, isArgon2idOptions, Random, Sha256, @@ -52,7 +53,7 @@ export function prehash(bytes: Uint8Array, type: PrehashType): Uint8Array { * The Cosmoshub derivation path in the form `m/44'/118'/0'/0/a` * with 0-based account index `a`. */ -export function makeCosmoshubPath(a: number): readonly Slip10RawIndex[] { +export function makeCosmoshubPath(a: number): HdPath { return [ Slip10RawIndex.hardened(44), Slip10RawIndex.hardened(118), diff --git a/packages/launchpad/types/secp256k1wallet.d.ts b/packages/launchpad/types/secp256k1wallet.d.ts index 06e9510c..a24a3366 100644 --- a/packages/launchpad/types/secp256k1wallet.d.ts +++ b/packages/launchpad/types/secp256k1wallet.d.ts @@ -1,4 +1,4 @@ -import { Slip10RawIndex } from "@cosmjs/crypto"; +import { HdPath } from "@cosmjs/crypto"; import { StdSignature } from "./types"; import { AccountData, EncryptionConfiguration, KdfConfiguration, OfflineSigner, PrehashType } from "./wallet"; /** @@ -40,11 +40,7 @@ export declare class Secp256k1Wallet implements OfflineSigner { * @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( - mnemonic: string, - hdPath?: readonly Slip10RawIndex[], - prefix?: string, - ): Promise; + static fromMnemonic(mnemonic: string, hdPath?: HdPath, prefix?: string): Promise; /** * Generates a new wallet with a BIP39 mnemonic of the given length. * @@ -54,7 +50,7 @@ export declare class Secp256k1Wallet implements OfflineSigner { */ static generate( length?: 12 | 15 | 18 | 21 | 24, - hdPath?: readonly Slip10RawIndex[], + hdPath?: HdPath, prefix?: string, ): Promise; /** diff --git a/packages/launchpad/types/wallet.d.ts b/packages/launchpad/types/wallet.d.ts index c0818ef2..5c284f5d 100644 --- a/packages/launchpad/types/wallet.d.ts +++ b/packages/launchpad/types/wallet.d.ts @@ -1,4 +1,4 @@ -import { Slip10RawIndex } from "@cosmjs/crypto"; +import { HdPath } from "@cosmjs/crypto"; import { StdSignature } from "./types"; export declare type PrehashType = "sha256" | "sha512" | null; export declare type Algo = "secp256k1" | "ed25519" | "sr25519"; @@ -22,7 +22,7 @@ export declare function prehash(bytes: Uint8Array, type: PrehashType): Uint8Arra * The Cosmoshub derivation path in the form `m/44'/118'/0'/0/a` * with 0-based account index `a`. */ -export declare function makeCosmoshubPath(a: number): readonly Slip10RawIndex[]; +export declare function makeCosmoshubPath(a: number): HdPath; /** * A fixed salt is chosen to archive a deterministic password to key derivation. * This reduces the scope of a potential rainbow attack to all CosmJS users.