stargate: Update tests for new Secp256k1HdWallet options
This commit is contained in:
@@ -216,7 +216,7 @@ describe("multisignature", () => {
|
|||||||
[0, 1, 2, 3, 4].map(async (i) => {
|
[0, 1, 2, 3, 4].map(async (i) => {
|
||||||
// Signing environment
|
// Signing environment
|
||||||
const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, {
|
const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, {
|
||||||
hdPath: makeCosmoshubPath(i),
|
hdPaths: [makeCosmoshubPath(i)],
|
||||||
});
|
});
|
||||||
const pubkey = encodeSecp256k1Pubkey((await wallet.getAccounts())[0].pubkey);
|
const pubkey = encodeSecp256k1Pubkey((await wallet.getAccounts())[0].pubkey);
|
||||||
const address = (await wallet.getAccounts())[0].address;
|
const address = (await wallet.getAccounts())[0].address;
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
import {
|
import { AminoSignResponse, Secp256k1HdWallet, Secp256k1HdWalletOptions, StdSignDoc } from "@cosmjs/amino";
|
||||||
AminoSignResponse,
|
import { Bip39, EnglishMnemonic, Random } from "@cosmjs/crypto";
|
||||||
makeCosmoshubPath,
|
|
||||||
Secp256k1HdWallet,
|
|
||||||
Secp256k1HdWalletOptions,
|
|
||||||
StdSignDoc,
|
|
||||||
} from "@cosmjs/amino";
|
|
||||||
import { Bip39, EnglishMnemonic, Random, Secp256k1, Slip10, Slip10Curve } from "@cosmjs/crypto";
|
|
||||||
import { Bech32 } from "@cosmjs/encoding";
|
import { Bech32 } from "@cosmjs/encoding";
|
||||||
import {
|
import {
|
||||||
coins,
|
coins,
|
||||||
@@ -155,12 +149,6 @@ export const nonExistentAddress = "cosmos1p79apjaufyphcmsn4g07cynqf0wyjuezqu84hd
|
|||||||
export const nonNegativeIntegerMatcher = /^[0-9]+$/;
|
export const nonNegativeIntegerMatcher = /^[0-9]+$/;
|
||||||
export const tendermintIdMatcher = /^[0-9A-F]{64}$/;
|
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
|
* A class for testing clients using an Amino signer which modifies the transaction it receives before signing
|
||||||
*/
|
*/
|
||||||
@@ -169,21 +157,9 @@ export class ModifyingSecp256k1HdWallet extends Secp256k1HdWallet {
|
|||||||
mnemonic: string,
|
mnemonic: string,
|
||||||
options: Partial<Secp256k1HdWalletOptions> = {},
|
options: Partial<Secp256k1HdWalletOptions> = {},
|
||||||
): Promise<ModifyingSecp256k1HdWallet> {
|
): Promise<ModifyingSecp256k1HdWallet> {
|
||||||
const { bip39Password, hdPath, prefix } = {
|
|
||||||
...defaultHdWalletOptions,
|
|
||||||
...options,
|
|
||||||
};
|
|
||||||
const mnemonicChecked = new EnglishMnemonic(mnemonic);
|
const mnemonicChecked = new EnglishMnemonic(mnemonic);
|
||||||
const seed = await Bip39.mnemonicToSeed(mnemonicChecked, bip39Password);
|
const seed = await Bip39.mnemonicToSeed(mnemonicChecked, options.bip39Password);
|
||||||
const { privkey } = Slip10.derivePath(Slip10Curve.Secp256k1, seed, hdPath);
|
return new ModifyingSecp256k1HdWallet(mnemonicChecked, { ...options, seed: seed });
|
||||||
const uncompressed = (await Secp256k1.makeKeypair(privkey)).pubkey;
|
|
||||||
return new ModifyingSecp256k1HdWallet(
|
|
||||||
mnemonicChecked,
|
|
||||||
hdPath,
|
|
||||||
privkey,
|
|
||||||
Secp256k1.compressPubkey(uncompressed),
|
|
||||||
prefix,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async signAmino(signerAddress: string, signDoc: StdSignDoc): Promise<AminoSignResponse> {
|
public async signAmino(signerAddress: string, signDoc: StdSignDoc): Promise<AminoSignResponse> {
|
||||||
@@ -207,18 +183,9 @@ export class ModifyingDirectSecp256k1HdWallet extends DirectSecp256k1HdWallet {
|
|||||||
mnemonic: string,
|
mnemonic: string,
|
||||||
options: Partial<DirectSecp256k1HdWalletOptions> = {},
|
options: Partial<DirectSecp256k1HdWalletOptions> = {},
|
||||||
): Promise<DirectSecp256k1HdWallet> {
|
): Promise<DirectSecp256k1HdWallet> {
|
||||||
const { bip39Password, hdPath, prefix } = { ...defaultHdWalletOptions, ...options };
|
|
||||||
const mnemonicChecked = new EnglishMnemonic(mnemonic);
|
const mnemonicChecked = new EnglishMnemonic(mnemonic);
|
||||||
const seed = await Bip39.mnemonicToSeed(mnemonicChecked, bip39Password);
|
const seed = await Bip39.mnemonicToSeed(mnemonicChecked, options.bip39Password);
|
||||||
const { privkey } = Slip10.derivePath(Slip10Curve.Secp256k1, seed, hdPath);
|
return new ModifyingDirectSecp256k1HdWallet(mnemonicChecked, { ...options, seed: seed });
|
||||||
const uncompressed = (await Secp256k1.makeKeypair(privkey)).pubkey;
|
|
||||||
return new ModifyingDirectSecp256k1HdWallet(
|
|
||||||
mnemonicChecked,
|
|
||||||
hdPath,
|
|
||||||
privkey,
|
|
||||||
Secp256k1.compressPubkey(uncompressed),
|
|
||||||
prefix,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async signDirect(address: string, signDoc: SignDoc): Promise<DirectSignResponse> {
|
public async signDirect(address: string, signDoc: SignDoc): Promise<DirectSignResponse> {
|
||||||
|
|||||||
Reference in New Issue
Block a user