launchpad: Use HdPath type

This commit is contained in:
willclarktech
2020-09-15 15:03:17 +02:00
parent bfbb01c6bf
commit 83a1775284
4 changed files with 12 additions and 15 deletions
+5 -5
View File
@@ -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<Secp256k1Wallet> {
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<Secp256k1Wallet> {
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,
+2 -1
View File
@@ -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),