From c453717dc74d3d9ce4190bd47ae77c86aa553a0b Mon Sep 17 00:00:00 2001 From: Jake Hartnell Date: Wed, 11 Nov 2020 11:55:18 -0800 Subject: [PATCH] Rename DirectSecp256k1Wallet -> DirectSecp256k1HdWallet --- packages/faucet/src/profile.ts | 4 ++-- ...pec.ts => directsecp256k1hdwallet.spec.ts} | 24 +++++++++---------- ...k1wallet.ts => directsecp256k1hdwallet.ts} | 10 ++++---- packages/proto-signing/src/index.ts | 2 +- packages/proto-signing/src/signing.spec.ts | 6 ++--- ...llet.d.ts => directsecp256k1hdwallet.d.ts} | 6 ++--- packages/proto-signing/types/index.d.ts | 2 +- .../src/signingstargateclient.spec.ts | 16 ++++++------- .../src/stargateclient.searchtx.spec.ts | 6 ++--- packages/stargate/src/stargateclient.spec.ts | 4 ++-- 10 files changed, 40 insertions(+), 40 deletions(-) rename packages/proto-signing/src/{directsecp256k1wallet.spec.ts => directsecp256k1hdwallet.spec.ts} (73%) rename packages/proto-signing/src/{directsecp256k1wallet.ts => directsecp256k1hdwallet.ts} (93%) rename packages/proto-signing/types/{directsecp256k1wallet.d.ts => directsecp256k1hdwallet.d.ts} (90%) diff --git a/packages/faucet/src/profile.ts b/packages/faucet/src/profile.ts index 2dacc568..0cb0a655 100644 --- a/packages/faucet/src/profile.ts +++ b/packages/faucet/src/profile.ts @@ -1,6 +1,6 @@ import { pathToString } from "@cosmjs/crypto"; import { makeCosmoshubPath, Secp256k1HdWallet, SigningCosmosClient } from "@cosmjs/launchpad"; -import { DirectSecp256k1Wallet, isOfflineDirectSigner, OfflineSigner } from "@cosmjs/proto-signing"; +import { DirectSecp256k1HdWallet, isOfflineDirectSigner, OfflineSigner } from "@cosmjs/proto-signing"; import { SigningStargateClient } from "@cosmjs/stargate"; import * as constants from "./constants"; @@ -12,7 +12,7 @@ export async function createWallets( stargate = true, logging = false, ): Promise> { - const createWallet = stargate ? DirectSecp256k1Wallet.fromMnemonic : Secp256k1HdWallet.fromMnemonic; + const createWallet = stargate ? DirectSecp256k1HdWallet.fromMnemonic : Secp256k1HdWallet.fromMnemonic; const wallets = new Array(); // first account is the token holder diff --git a/packages/proto-signing/src/directsecp256k1wallet.spec.ts b/packages/proto-signing/src/directsecp256k1hdwallet.spec.ts similarity index 73% rename from packages/proto-signing/src/directsecp256k1wallet.spec.ts rename to packages/proto-signing/src/directsecp256k1hdwallet.spec.ts index fc44ec2c..bb8fd105 100644 --- a/packages/proto-signing/src/directsecp256k1wallet.spec.ts +++ b/packages/proto-signing/src/directsecp256k1hdwallet.spec.ts @@ -2,11 +2,11 @@ import { Secp256k1, Secp256k1Signature, sha256 } from "@cosmjs/crypto"; import { fromBase64, fromHex } from "@cosmjs/encoding"; import { coins } from "@cosmjs/launchpad"; -import { DirectSecp256k1Wallet } from "./directsecp256k1wallet"; +import { DirectSecp256k1HdWallet } from "./directsecp256k1hdwallet"; import { makeAuthInfoBytes, makeSignBytes, makeSignDoc } from "./signing"; import { faucet, testVectors } from "./testutils.spec"; -describe("DirectSecp256k1Wallet", () => { +describe("DirectSecp256k1HdWallet", () => { // m/44'/118'/0'/0/0 // pubkey: 02baa4ef93f2ce84592a49b1d729c074eab640112522a7a89f7d03ebab21ded7b6 const defaultMnemonic = "special sign fit simple patrol salute grocery chicken wheat radar tonight ceiling"; @@ -15,7 +15,7 @@ describe("DirectSecp256k1Wallet", () => { describe("fromMnemonic", () => { it("works", async () => { - const wallet = await DirectSecp256k1Wallet.fromMnemonic(defaultMnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(defaultMnemonic); expect(wallet).toBeTruthy(); expect(wallet.mnemonic).toEqual(defaultMnemonic); }); @@ -23,22 +23,22 @@ describe("DirectSecp256k1Wallet", () => { describe("generate", () => { it("defaults to 12 words", async () => { - const wallet = await DirectSecp256k1Wallet.generate(); + const wallet = await DirectSecp256k1HdWallet.generate(); expect(wallet.mnemonic.split(" ").length).toEqual(12); }); it("can use different mnemonic lengths", async () => { - expect((await DirectSecp256k1Wallet.generate(12)).mnemonic.split(" ").length).toEqual(12); - expect((await DirectSecp256k1Wallet.generate(15)).mnemonic.split(" ").length).toEqual(15); - expect((await DirectSecp256k1Wallet.generate(18)).mnemonic.split(" ").length).toEqual(18); - expect((await DirectSecp256k1Wallet.generate(21)).mnemonic.split(" ").length).toEqual(21); - expect((await DirectSecp256k1Wallet.generate(24)).mnemonic.split(" ").length).toEqual(24); + expect((await DirectSecp256k1HdWallet.generate(12)).mnemonic.split(" ").length).toEqual(12); + expect((await DirectSecp256k1HdWallet.generate(15)).mnemonic.split(" ").length).toEqual(15); + expect((await DirectSecp256k1HdWallet.generate(18)).mnemonic.split(" ").length).toEqual(18); + expect((await DirectSecp256k1HdWallet.generate(21)).mnemonic.split(" ").length).toEqual(21); + expect((await DirectSecp256k1HdWallet.generate(24)).mnemonic.split(" ").length).toEqual(24); }); }); describe("getAccounts", () => { it("resolves to a list of accounts", async () => { - const wallet = await DirectSecp256k1Wallet.fromMnemonic(defaultMnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(defaultMnemonic); const accounts = await wallet.getAccounts(); expect(accounts.length).toEqual(1); expect(accounts[0]).toEqual({ @@ -49,7 +49,7 @@ describe("DirectSecp256k1Wallet", () => { }); it("creates the same address as Go implementation", async () => { - const wallet = await DirectSecp256k1Wallet.fromMnemonic( + const wallet = await DirectSecp256k1HdWallet.fromMnemonic( "oyster design unusual machine spread century engine gravity focus cave carry slot", ); const [{ address }] = await wallet.getAccounts(); @@ -60,7 +60,7 @@ describe("DirectSecp256k1Wallet", () => { describe("signDirect", () => { it("resolves to valid signature", async () => { const { sequence, bodyBytes } = testVectors[1]; - const wallet = await DirectSecp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const pubkey = { typeUrl: "/cosmos.crypto.secp256k1.PubKey", value: fromBase64(faucet.pubkey.value), diff --git a/packages/proto-signing/src/directsecp256k1wallet.ts b/packages/proto-signing/src/directsecp256k1hdwallet.ts similarity index 93% rename from packages/proto-signing/src/directsecp256k1wallet.ts rename to packages/proto-signing/src/directsecp256k1hdwallet.ts index d6d3960f..1b869c4b 100644 --- a/packages/proto-signing/src/directsecp256k1wallet.ts +++ b/packages/proto-signing/src/directsecp256k1hdwallet.ts @@ -28,7 +28,7 @@ interface Secp256k1Derivation { } /** A wallet for protobuf based signing using SIGN_MODE_DIRECT */ -export class DirectSecp256k1Wallet implements OfflineDirectSigner { +export class DirectSecp256k1HdWallet implements OfflineDirectSigner { /** * Restores a wallet from the given BIP39 mnemonic. * @@ -40,12 +40,12 @@ export class DirectSecp256k1Wallet implements OfflineDirectSigner { mnemonic: string, hdPath: HdPath = makeCosmoshubPath(0), prefix = "cosmos", - ): Promise { + ): Promise { const mnemonicChecked = new EnglishMnemonic(mnemonic); const seed = await Bip39.mnemonicToSeed(mnemonicChecked); const { privkey } = Slip10.derivePath(Slip10Curve.Secp256k1, seed, hdPath); const uncompressed = (await Secp256k1.makeKeypair(privkey)).pubkey; - return new DirectSecp256k1Wallet( + return new DirectSecp256k1HdWallet( mnemonicChecked, hdPath, privkey, @@ -65,11 +65,11 @@ export class DirectSecp256k1Wallet implements OfflineDirectSigner { length: 12 | 15 | 18 | 21 | 24 = 12, hdPath: HdPath = makeCosmoshubPath(0), prefix = "cosmos", - ): Promise { + ): Promise { const entropyLength = 4 * Math.floor((11 * length) / 33); const entropy = Random.getBytes(entropyLength); const mnemonic = Bip39.encode(entropy); - return DirectSecp256k1Wallet.fromMnemonic(mnemonic.toString(), hdPath, prefix); + return DirectSecp256k1HdWallet.fromMnemonic(mnemonic.toString(), hdPath, prefix); } /** Base secret */ diff --git a/packages/proto-signing/src/index.ts b/packages/proto-signing/src/index.ts index 00597feb..3d8c4c08 100644 --- a/packages/proto-signing/src/index.ts +++ b/packages/proto-signing/src/index.ts @@ -1,7 +1,7 @@ export { Coin } from "./msgs"; export { cosmosField, registered } from "./decorator"; export { EncodeObject, Registry } from "./registry"; -export { DirectSecp256k1Wallet } from "./directsecp256k1wallet"; +export { DirectSecp256k1HdWallet } from "./directsecp256k1hdwallet"; export { decodePubkey, encodePubkey } from "./pubkey"; export { isOfflineDirectSigner, OfflineDirectSigner, OfflineSigner } from "./signer"; export { makeAuthInfoBytes, makeSignBytes, makeSignDoc } from "./signing"; diff --git a/packages/proto-signing/src/signing.spec.ts b/packages/proto-signing/src/signing.spec.ts index 342f46af..c8b1372f 100644 --- a/packages/proto-signing/src/signing.spec.ts +++ b/packages/proto-signing/src/signing.spec.ts @@ -2,7 +2,7 @@ import { fromBase64, fromHex, toHex } from "@cosmjs/encoding"; import { cosmos, google } from "./codec"; -import { DirectSecp256k1Wallet } from "./directsecp256k1wallet"; +import { DirectSecp256k1HdWallet } from "./directsecp256k1hdwallet"; import { defaultRegistry } from "./msgs"; import { Registry, TxBodyValue } from "./registry"; import { makeAuthInfoBytes, makeSignBytes, makeSignDoc } from "./signing"; @@ -27,7 +27,7 @@ describe("signing", () => { const gasLimit = 200000; it("correctly parses test vectors", async () => { - const wallet = await DirectSecp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const [{ address, pubkey: pubkeyBytes }] = await wallet.getAccounts(); const prefixedPubkeyBytes = Uint8Array.from([0x0a, pubkeyBytes.length, ...pubkeyBytes]); @@ -61,7 +61,7 @@ describe("signing", () => { it("correctly generates test vectors", async () => { const myRegistry = new Registry(); - const wallet = await DirectSecp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const [{ address, pubkey: pubkeyBytes }] = await wallet.getAccounts(); const publicKey = PubKey.create({ key: pubkeyBytes, diff --git a/packages/proto-signing/types/directsecp256k1wallet.d.ts b/packages/proto-signing/types/directsecp256k1hdwallet.d.ts similarity index 90% rename from packages/proto-signing/types/directsecp256k1wallet.d.ts rename to packages/proto-signing/types/directsecp256k1hdwallet.d.ts index cd9ea1ef..f557689d 100644 --- a/packages/proto-signing/types/directsecp256k1wallet.d.ts +++ b/packages/proto-signing/types/directsecp256k1hdwallet.d.ts @@ -3,7 +3,7 @@ import { AccountData } from "@cosmjs/launchpad"; import { cosmos } from "./codec"; import { DirectSignResponse, OfflineDirectSigner } from "./signer"; /** A wallet for protobuf based signing using SIGN_MODE_DIRECT */ -export declare class DirectSecp256k1Wallet implements OfflineDirectSigner { +export declare class DirectSecp256k1HdWallet implements OfflineDirectSigner { /** * Restores a wallet from the given BIP39 mnemonic. * @@ -11,7 +11,7 @@ export declare class DirectSecp256k1Wallet implements OfflineDirectSigner { * @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?: HdPath, prefix?: string): Promise; + static fromMnemonic(mnemonic: string, hdPath?: HdPath, prefix?: string): Promise; /** * Generates a new wallet with a BIP39 mnemonic of the given length. * @@ -23,7 +23,7 @@ export declare class DirectSecp256k1Wallet implements OfflineDirectSigner { length?: 12 | 15 | 18 | 21 | 24, hdPath?: HdPath, prefix?: string, - ): Promise; + ): Promise; /** Base secret */ private readonly secret; /** Derivation instruction */ diff --git a/packages/proto-signing/types/index.d.ts b/packages/proto-signing/types/index.d.ts index 00597feb..3d8c4c08 100644 --- a/packages/proto-signing/types/index.d.ts +++ b/packages/proto-signing/types/index.d.ts @@ -1,7 +1,7 @@ export { Coin } from "./msgs"; export { cosmosField, registered } from "./decorator"; export { EncodeObject, Registry } from "./registry"; -export { DirectSecp256k1Wallet } from "./directsecp256k1wallet"; +export { DirectSecp256k1HdWallet } from "./directsecp256k1hdwallet"; export { decodePubkey, encodePubkey } from "./pubkey"; export { isOfflineDirectSigner, OfflineDirectSigner, OfflineSigner } from "./signer"; export { makeAuthInfoBytes, makeSignBytes, makeSignDoc } from "./signing"; diff --git a/packages/stargate/src/signingstargateclient.spec.ts b/packages/stargate/src/signingstargateclient.spec.ts index 279685a6..bd2741b3 100644 --- a/packages/stargate/src/signingstargateclient.spec.ts +++ b/packages/stargate/src/signingstargateclient.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { coin, coins, GasPrice, Secp256k1HdWallet } from "@cosmjs/launchpad"; -import { Coin, cosmosField, DirectSecp256k1Wallet, registered, Registry } from "@cosmjs/proto-signing"; +import { Coin, cosmosField, DirectSecp256k1HdWallet, registered, Registry } from "@cosmjs/proto-signing"; import { assert } from "@cosmjs/utils"; import { Message } from "protobufjs"; @@ -13,7 +13,7 @@ describe("SigningStargateClient", () => { describe("constructor", () => { it("can be constructed with default fees", async () => { pendingWithoutSimapp(); - const wallet = await DirectSecp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = await SigningStargateClient.connectWithWallet(simapp.tendermintUrl, wallet); const openedClient = (client as unknown) as PrivateSigningStargateClient; expect(openedClient.fees).toEqual({ @@ -31,7 +31,7 @@ describe("SigningStargateClient", () => { it("can be constructed with custom registry", async () => { pendingWithoutSimapp(); - const wallet = await DirectSecp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const registry = new Registry(); registry.register("/custom.MsgCustom", cosmos.bank.v1beta1.MsgSend); const options = { registry: registry }; @@ -42,7 +42,7 @@ describe("SigningStargateClient", () => { it("can be constructed with custom gas price", async () => { pendingWithoutSimapp(); - const wallet = await DirectSecp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const gasPrice = GasPrice.fromString("3.14utest"); const options = { gasPrice: gasPrice }; const client = await SigningStargateClient.connectWithWallet(simapp.tendermintUrl, wallet, options); @@ -62,7 +62,7 @@ describe("SigningStargateClient", () => { it("can be constructed with custom gas limits", async () => { pendingWithoutSimapp(); - const wallet = await DirectSecp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const gasLimits = { send: 160000, }; @@ -84,7 +84,7 @@ describe("SigningStargateClient", () => { it("can be constructed with custom gas price and gas limits", async () => { pendingWithoutSimapp(); - const wallet = await DirectSecp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const gasPrice = GasPrice.fromString("3.14utest"); const gasLimits = { send: 160000, @@ -109,7 +109,7 @@ describe("SigningStargateClient", () => { describe("sendTokens", () => { it("works", async () => { pendingWithoutSimapp(); - const wallet = await DirectSecp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = await SigningStargateClient.connectWithWallet(simapp.tendermintUrl, wallet); const transferAmount = coins(7890, "ucosm"); @@ -135,7 +135,7 @@ describe("SigningStargateClient", () => { describe("signAndBroadcast", () => { it("works with direct mode", async () => { pendingWithoutSimapp(); - const wallet = await DirectSecp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const msgDelegateTypeUrl = "/cosmos.staking.v1beta1.MsgDelegate"; const registry = new Registry(); registry.register(msgDelegateTypeUrl, cosmos.staking.v1beta1.MsgDelegate); diff --git a/packages/stargate/src/stargateclient.searchtx.spec.ts b/packages/stargate/src/stargateclient.searchtx.spec.ts index ede5bcda..06b12276 100644 --- a/packages/stargate/src/stargateclient.searchtx.spec.ts +++ b/packages/stargate/src/stargateclient.searchtx.spec.ts @@ -2,7 +2,7 @@ import { fromBase64, toBase64 } from "@cosmjs/encoding"; import { Coin, coins } from "@cosmjs/launchpad"; import { - DirectSecp256k1Wallet, + DirectSecp256k1HdWallet, encodePubkey, makeAuthInfoBytes, makeSignDoc, @@ -32,7 +32,7 @@ interface TestTxSend { async function sendTokens( client: StargateClient, registry: Registry, - wallet: DirectSecp256k1Wallet, + wallet: DirectSecp256k1HdWallet, recipient: string, amount: readonly Coin[], memo: string, @@ -96,7 +96,7 @@ describe("StargateClient.searchTx", () => { beforeAll(async () => { if (simappEnabled()) { - const wallet = await DirectSecp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = await StargateClient.connect(simapp.tendermintUrl); const unsuccessfulRecipient = makeRandomAddress(); const successfulRecipient = makeRandomAddress(); diff --git a/packages/stargate/src/stargateclient.spec.ts b/packages/stargate/src/stargateclient.spec.ts index 813d4006..857c1f01 100644 --- a/packages/stargate/src/stargateclient.spec.ts +++ b/packages/stargate/src/stargateclient.spec.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { fromBase64, toBase64 } from "@cosmjs/encoding"; import { - DirectSecp256k1Wallet, + DirectSecp256k1HdWallet, encodePubkey, makeAuthInfoBytes, makeSignDoc, @@ -256,7 +256,7 @@ describe("StargateClient", () => { it("broadcasts a transaction", async () => { pendingWithoutSimapp(); const client = await StargateClient.connect(simapp.tendermintUrl); - const wallet = await DirectSecp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const [{ address, pubkey: pubkeyBytes }] = await wallet.getAccounts(); const pubkey = encodePubkey({ type: "tendermint/PubKeySecp256k1",