stargate: Update for hd wallet change
This commit is contained in:
parent
df0be28d5c
commit
4f487814ea
@ -214,7 +214,9 @@ describe("multisignature", () => {
|
||||
] = await Promise.all(
|
||||
[0, 1, 2, 3, 4].map(async (i) => {
|
||||
// Signing environment
|
||||
const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(i));
|
||||
const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, {
|
||||
hdPath: makeCosmoshubPath(i),
|
||||
});
|
||||
const pubkey = encodeSecp256k1Pubkey((await wallet.getAccounts())[0].pubkey);
|
||||
const address = (await wallet.getAccounts())[0].address;
|
||||
const signingClient = await SigningStargateClient.offline(wallet);
|
||||
|
||||
@ -1,8 +1,20 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoSignResponse, makeCosmoshubPath, Secp256k1HdWallet, StdSignDoc } from "@cosmjs/amino";
|
||||
import {
|
||||
AminoSignResponse,
|
||||
makeCosmoshubPath,
|
||||
Secp256k1HdWallet,
|
||||
Secp256k1HdWalletOptions,
|
||||
StdSignDoc,
|
||||
} from "@cosmjs/amino";
|
||||
import { Bip39, EnglishMnemonic, Random, Secp256k1, Slip10, Slip10Curve } from "@cosmjs/crypto";
|
||||
import { Bech32 } from "@cosmjs/encoding";
|
||||
import { coins, DirectSecp256k1HdWallet, DirectSignResponse, makeAuthInfoBytes } from "@cosmjs/proto-signing";
|
||||
import {
|
||||
coins,
|
||||
DirectSecp256k1HdWallet,
|
||||
DirectSecp256k1HdWalletOptions,
|
||||
DirectSignResponse,
|
||||
makeAuthInfoBytes,
|
||||
} from "@cosmjs/proto-signing";
|
||||
|
||||
import { SignMode } from "./codec/cosmos/tx/signing/v1beta1/signing";
|
||||
import { AuthInfo, SignDoc, TxBody } from "./codec/cosmos/tx/v1beta1/tx";
|
||||
@ -122,17 +134,26 @@ export const nonExistentAddress = "cosmos1p79apjaufyphcmsn4g07cynqf0wyjuezqu84hd
|
||||
export const nonNegativeIntegerMatcher = /^[0-9]+$/;
|
||||
export const tendermintIdMatcher = /^[0-9A-F]{64}$/;
|
||||
|
||||
const defaultHdWalletOptions = {
|
||||
bip39Password: "",
|
||||
hdPath: makeCosmoshubPath(0),
|
||||
prefix: "cosmos",
|
||||
};
|
||||
|
||||
/**
|
||||
* A class for testing clients using an Amino signer which modifies the transaction it receives before signing
|
||||
*/
|
||||
export class ModifyingSecp256k1HdWallet extends Secp256k1HdWallet {
|
||||
public static async fromMnemonic(
|
||||
mnemonic: string,
|
||||
hdPath = makeCosmoshubPath(0),
|
||||
prefix = "cosmos",
|
||||
options: Partial<Secp256k1HdWalletOptions> = {},
|
||||
): Promise<ModifyingSecp256k1HdWallet> {
|
||||
const { bip39Password, hdPath, prefix } = {
|
||||
...defaultHdWalletOptions,
|
||||
...options,
|
||||
};
|
||||
const mnemonicChecked = new EnglishMnemonic(mnemonic);
|
||||
const seed = await Bip39.mnemonicToSeed(mnemonicChecked);
|
||||
const seed = await Bip39.mnemonicToSeed(mnemonicChecked, bip39Password);
|
||||
const { privkey } = Slip10.derivePath(Slip10Curve.Secp256k1, seed, hdPath);
|
||||
const uncompressed = (await Secp256k1.makeKeypair(privkey)).pubkey;
|
||||
return new ModifyingSecp256k1HdWallet(
|
||||
@ -163,11 +184,11 @@ export class ModifyingSecp256k1HdWallet extends Secp256k1HdWallet {
|
||||
export class ModifyingDirectSecp256k1HdWallet extends DirectSecp256k1HdWallet {
|
||||
public static async fromMnemonic(
|
||||
mnemonic: string,
|
||||
hdPath = makeCosmoshubPath(0),
|
||||
prefix = "cosmos",
|
||||
options: Partial<DirectSecp256k1HdWalletOptions> = {},
|
||||
): Promise<DirectSecp256k1HdWallet> {
|
||||
const { bip39Password, hdPath, prefix } = { ...defaultHdWalletOptions, ...options };
|
||||
const mnemonicChecked = new EnglishMnemonic(mnemonic);
|
||||
const seed = await Bip39.mnemonicToSeed(mnemonicChecked);
|
||||
const seed = await Bip39.mnemonicToSeed(mnemonicChecked, bip39Password);
|
||||
const { privkey } = Slip10.derivePath(Slip10Curve.Secp256k1, seed, hdPath);
|
||||
const uncompressed = (await Secp256k1.makeKeypair(privkey)).pubkey;
|
||||
return new ModifyingDirectSecp256k1HdWallet(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user