launchpad: Use HdPath type
This commit is contained in:
parent
bfbb01c6bf
commit
83a1775284
@ -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,
|
||||
|
||||
@ -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),
|
||||
|
||||
10
packages/launchpad/types/secp256k1wallet.d.ts
vendored
10
packages/launchpad/types/secp256k1wallet.d.ts
vendored
@ -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<Secp256k1Wallet>;
|
||||
static fromMnemonic(mnemonic: string, hdPath?: HdPath, prefix?: string): Promise<Secp256k1Wallet>;
|
||||
/**
|
||||
* 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<Secp256k1Wallet>;
|
||||
/**
|
||||
|
||||
4
packages/launchpad/types/wallet.d.ts
vendored
4
packages/launchpad/types/wallet.d.ts
vendored
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user