diff --git a/CHANGELOG.md b/CHANGELOG.md index 890154ba..aca16ad6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,8 @@ better represent the Amino tx interface. Deprecate `CosmosSdkTx`, which is an alias for `WrappedStdTx`. - @cosmjs/launchpad: Add `makeStdTx` to create an `StdTx`. +- @cosmjs/launchpad: Rename `Secp256k1Wallet` to `Secp256k1HdWallet`. Later on, + we'll use `Secp256k1Wallet` for single key wallets. - @cosmjs/launchpad-ledger: Add package supporting Ledger device integration for Launchpad. Two new classes are provided: `LedgerSigner` (for most use cases) and `LaunchpadLedger` for more fine-grained access. diff --git a/packages/cli/examples/coralnet.ts b/packages/cli/examples/coralnet.ts index c6c9117c..c8488040 100644 --- a/packages/cli/examples/coralnet.ts +++ b/packages/cli/examples/coralnet.ts @@ -16,7 +16,7 @@ const coralnetOptions: Options = { }, }; -const wallet = await Secp256k1Wallet.generate(12, coralnetOptions.hdPath, coralnetOptions.bech32prefix); +const wallet = await Secp256k1HdWallet.generate(12, coralnetOptions.hdPath, coralnetOptions.bech32prefix); const [{ address }] = await wallet.getAccounts(); const client = new SigningCosmWasmClient( diff --git a/packages/cli/examples/delegate.ts b/packages/cli/examples/delegate.ts index edcdfcfb..056a08de 100644 --- a/packages/cli/examples/delegate.ts +++ b/packages/cli/examples/delegate.ts @@ -1,4 +1,4 @@ -const wallet = await Secp256k1Wallet.fromMnemonic( +const wallet = await Secp256k1HdWallet.fromMnemonic( "enlist hip relief stomach skate base shallow young switch frequent cry park", ); const [{ address: senderAddress }] = await wallet.getAccounts(); diff --git a/packages/cli/examples/faucet_addresses.ts b/packages/cli/examples/faucet_addresses.ts index 2e080c11..604484e9 100644 --- a/packages/cli/examples/faucet_addresses.ts +++ b/packages/cli/examples/faucet_addresses.ts @@ -2,7 +2,7 @@ const mnemonic = "economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone"; for (let i of [0, 1, 2, 3, 4]) { - const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic, makeCosmoshubPath(i), "cosmos"); + const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic, makeCosmoshubPath(i), "cosmos"); const [{ address, pubkey }] = await wallet.getAccounts(); console.info(`Address ${i}: ${address}`); console.info(`Pubkey ${i}: ${toBase64(pubkey)}`); diff --git a/packages/cli/examples/generate_address.ts b/packages/cli/examples/generate_address.ts index 9e403284..bb0787b6 100644 --- a/packages/cli/examples/generate_address.ts +++ b/packages/cli/examples/generate_address.ts @@ -1,5 +1,5 @@ const mnemonic = Bip39.encode(Random.getBytes(16)).toString(); -const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic); +const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic); const [{ address, pubkey }] = await wallet.getAccounts(); console.info("mnemonic:", mnemonic); diff --git a/packages/cli/examples/helpers.ts b/packages/cli/examples/helpers.ts index fc82497c..572d56ed 100644 --- a/packages/cli/examples/helpers.ts +++ b/packages/cli/examples/helpers.ts @@ -33,7 +33,7 @@ const connect = async ( }> => { const options: Options = { ...defaultOptions, ...opts }; const gasPrice = GasPrice.fromString(`${options.gasPrice}${options.feeToken}`); - const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic); const [{ address }] = await wallet.getAccounts(); const client = new SigningCosmWasmClient(options.httpUrl, address, wallet, gasPrice); @@ -68,7 +68,7 @@ const randomAddress = async (prefix: string): Promise => { }; const mnemonicToAddress = async (prefix: string, mnemonic: string): Promise => { - const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic); const [{ address }] = await wallet.getAccounts(); return address; }; diff --git a/packages/cli/examples/local_faucet.ts b/packages/cli/examples/local_faucet.ts index ce72447f..98f27217 100644 --- a/packages/cli/examples/local_faucet.ts +++ b/packages/cli/examples/local_faucet.ts @@ -14,5 +14,5 @@ const faucetMnemonic = "economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone"; const faucetAddress = "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6"; -const wallet = await Secp256k1Wallet.fromMnemonic(faucetMnemonic); +const wallet = await Secp256k1HdWallet.fromMnemonic(faucetMnemonic); const client = new LcdClient(defaultHttpUrl); diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index cc3ad5e9..50ff5f71 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -113,7 +113,7 @@ export async function main(originalArgs: readonly string[]): Promise { "OfflineSigner", "PubKey", "pubkeyToAddress", - "Secp256k1Wallet", + "Secp256k1HdWallet", "SigningCosmosClient", "StdFee", "StdSignDoc", @@ -160,7 +160,7 @@ export async function main(originalArgs: readonly string[]): Promise { assert(Decimal.fromAtomics("12870000", 6).toString() === "12.87"); const mnemonic = Bip39.encode(Random.getBytes(16)).toString(); - const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic, makeCosmoshubPath(0)); + const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic, makeCosmoshubPath(0)); const [{ address }] = await wallet.getAccounts(); const data = toAscii("foo bar"); const fee: StdFee = { diff --git a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts index 9c386d77..aa15c45b 100644 --- a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts @@ -8,7 +8,7 @@ import { makeSignDoc, makeStdTx, MsgSend, - Secp256k1Wallet, + Secp256k1HdWallet, WrappedStdTx, } from "@cosmjs/launchpad"; import { assert, sleep } from "@cosmjs/utils"; @@ -50,7 +50,7 @@ describe("CosmWasmClient.searchTx", () => { beforeAll(async () => { if (wasmdEnabled()) { - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(wasmd.endpoint, alice.address0, wallet); { diff --git a/packages/cosmwasm/src/cosmwasmclient.spec.ts b/packages/cosmwasm/src/cosmwasmclient.spec.ts index 1e1143d1..e5e079a0 100644 --- a/packages/cosmwasm/src/cosmwasmclient.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.spec.ts @@ -7,7 +7,7 @@ import { makeSignDoc, makeStdTx, MsgSend, - Secp256k1Wallet, + Secp256k1HdWallet, StdFee, } from "@cosmjs/launchpad"; import { assert, sleep } from "@cosmjs/utils"; @@ -209,7 +209,7 @@ describe("CosmWasmClient", () => { describe("broadcastTx", () => { it("works", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new CosmWasmClient(wasmd.endpoint); const memo = "My first contract on chain"; @@ -369,7 +369,7 @@ describe("CosmWasmClient", () => { beforeAll(async () => { if (wasmdEnabled()) { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(wasmd.endpoint, alice.address0, wallet); const { codeId } = await client.upload(getHackatom().data); const initMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() }; @@ -420,7 +420,7 @@ describe("CosmWasmClient", () => { beforeAll(async () => { if (wasmdEnabled()) { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(wasmd.endpoint, alice.address0, wallet); const { codeId } = await client.upload(getHackatom().data); const initMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() }; diff --git a/packages/cosmwasm/src/lcdapi/wasm.spec.ts b/packages/cosmwasm/src/lcdapi/wasm.spec.ts index 459ecdf7..3ce269cf 100644 --- a/packages/cosmwasm/src/lcdapi/wasm.spec.ts +++ b/packages/cosmwasm/src/lcdapi/wasm.spec.ts @@ -13,7 +13,7 @@ import { makeSignDoc, makeStdTx, OfflineSigner, - Secp256k1Wallet, + Secp256k1HdWallet, setupAuthExtension, SigningCosmosClient, StdFee, @@ -139,7 +139,7 @@ describe("WasmExtension", () => { beforeAll(async () => { if (wasmdEnabled()) { - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const result = await uploadContract(wallet, hackatom); assertIsBroadcastTxSuccess(result); const logs = parseLogs(result.logs); @@ -189,7 +189,7 @@ describe("WasmExtension", () => { it("works", async () => { pendingWithoutWasmd(); assert(hackatomCodeId); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = makeWasmClient(wasmd.endpoint); const beneficiaryAddress = makeRandomAddress(); const transferAmount = coins(707707, "ucosm"); @@ -246,7 +246,7 @@ describe("WasmExtension", () => { it("can list contract history", async () => { pendingWithoutWasmd(); assert(hackatomCodeId); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = makeWasmClient(wasmd.endpoint); const beneficiaryAddress = makeRandomAddress(); const transferAmount = coins(707707, "ucosm"); @@ -472,7 +472,7 @@ describe("WasmExtension", () => { describe("broadcastTx", () => { it("can upload, instantiate and execute wasm", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = makeWasmClient(wasmd.endpoint); const transferAmount = [coin(1234, "ucosm"), coin(321, "ustake")]; diff --git a/packages/cosmwasm/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm/src/signingcosmwasmclient.spec.ts index 56c275a7..d10eb78c 100644 --- a/packages/cosmwasm/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm/src/signingcosmwasmclient.spec.ts @@ -9,7 +9,7 @@ import { GasPrice, LcdClient, MsgDelegate, - Secp256k1Wallet, + Secp256k1HdWallet, setupAuthExtension, } from "@cosmjs/launchpad"; import { assert } from "@cosmjs/utils"; @@ -35,13 +35,13 @@ function makeWasmClient(apiUrl: string): LcdClient & AuthExtension & WasmExtensi describe("SigningCosmWasmClient", () => { describe("makeReadOnly", () => { it("can be constructed", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); expect(client).toBeTruthy(); }); it("can be constructed with custom gas price", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const gasPrice = GasPrice.fromString("3.14utest"); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet, gasPrice); const openedClient = (client as unknown) as PrivateSigningCosmWasmClient; @@ -104,7 +104,7 @@ describe("SigningCosmWasmClient", () => { }); it("can be constructed with custom gas limits", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const gasLimits = { send: 160000, }; @@ -169,7 +169,7 @@ describe("SigningCosmWasmClient", () => { }); it("can be constructed with custom gas price and gas limits", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const gasPrice = GasPrice.fromString("3.14utest"); const gasLimits = { send: 160000, @@ -238,7 +238,7 @@ describe("SigningCosmWasmClient", () => { describe("getHeight", () => { it("always uses authAccount implementation", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); const openedClient = (client as unknown) as PrivateCosmWasmClient; @@ -256,7 +256,7 @@ describe("SigningCosmWasmClient", () => { describe("upload", () => { it("works", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); const wasm = getHackatom().data; const { @@ -275,7 +275,7 @@ describe("SigningCosmWasmClient", () => { it("can set builder and source", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); const hackatom = getHackatom(); @@ -294,7 +294,7 @@ describe("SigningCosmWasmClient", () => { describe("instantiate", () => { it("works with transfer amount", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); const { codeId } = await client.upload(getHackatom().data); @@ -320,7 +320,7 @@ describe("SigningCosmWasmClient", () => { it("works with admin", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); const { codeId } = await client.upload(getHackatom().data); @@ -343,7 +343,7 @@ describe("SigningCosmWasmClient", () => { it("can instantiate one code multiple times", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); const { codeId } = await client.upload(getHackatom().data); @@ -370,7 +370,7 @@ describe("SigningCosmWasmClient", () => { describe("updateAdmin", () => { it("can update an admin", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); const { codeId } = await client.upload(getHackatom().data); @@ -403,7 +403,7 @@ describe("SigningCosmWasmClient", () => { describe("clearAdmin", () => { it("can clear an admin", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); const { codeId } = await client.upload(getHackatom().data); @@ -436,7 +436,7 @@ describe("SigningCosmWasmClient", () => { describe("migrate", () => { it("can can migrate from one code ID to another", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); const { codeId: codeId1 } = await client.upload(getHackatom().data); const { codeId: codeId2 } = await client.upload(getHackatom().data); @@ -474,7 +474,7 @@ describe("SigningCosmWasmClient", () => { describe("execute", () => { it("works", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); const { codeId } = await client.upload(getHackatom().data); @@ -515,7 +515,7 @@ describe("SigningCosmWasmClient", () => { describe("sendTokens", () => { it("works", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); // instantiate @@ -542,7 +542,7 @@ describe("SigningCosmWasmClient", () => { describe("signAndBroadcast", () => { it("works", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); const msg: MsgDelegate = { diff --git a/packages/faucet/src/profile.ts b/packages/faucet/src/profile.ts index 52123bc8..39d9ec05 100644 --- a/packages/faucet/src/profile.ts +++ b/packages/faucet/src/profile.ts @@ -1,5 +1,5 @@ import { pathToString } from "@cosmjs/crypto"; -import { makeCosmoshubPath, OfflineSigner, Secp256k1Wallet } from "@cosmjs/launchpad"; +import { makeCosmoshubPath, OfflineSigner, Secp256k1HdWallet } from "@cosmjs/launchpad"; export async function createWallets( mnemonic: string, @@ -13,7 +13,7 @@ export async function createWallets( const numberOfIdentities = 1 + numberOfDistributors; for (let i = 0; i < numberOfIdentities; i++) { const path = makeCosmoshubPath(i); - const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic, path, addressPrefix); + const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic, path, addressPrefix); const [{ address }] = await wallet.getAccounts(); if (logging) { const role = i === 0 ? "token holder " : `distributor ${i}`; diff --git a/packages/launchpad/README.md b/packages/launchpad/README.md index c9706464..1319965b 100644 --- a/packages/launchpad/README.md +++ b/packages/launchpad/README.md @@ -214,19 +214,19 @@ assertIsBroadcastTxResult(result); ## Secure key storage -[Secp256k1Wallet](https://cosmwasm.github.io/cosmjs/latest/launchpad/classes/secp256k1wallet.html) +[Secp256k1HdWallet](https://cosmwasm.github.io/cosmjs/latest/launchpad/classes/secp256k1hdwallet.html) supports securely encrypted serialization/deserialization using Argon2 for key derivation and XChaCha20Poly1305 for authenticated encryption. It can be used as easily as: ```ts // generate an 18 word mnemonic -const wallet = await Secp256k1Wallet.generate(18); +const wallet = await Secp256k1HdWallet.generate(18); const serialized = await original.serialize("my password"); // serialized is encrypted and can now be stored in an application-specific way -const restored = await Secp256k1Wallet.deserialize(serialized, "my password"); +const restored = await Secp256k1HdWallet.deserialize(serialized, "my password"); ``` If you want to use really strong KDF parameters in a user interface, you should @@ -236,7 +236,7 @@ UI. This can be done in the advanced mode: **Session 1 (main thread)** ```ts -const wallet = await Secp256k1Wallet.generate(18); +const wallet = await Secp256k1HdWallet.generate(18); ``` **Session 1 (WebWorker)** @@ -286,7 +286,7 @@ const encryptionKey = await executeKdf(password, kdfConfiguration); **Session 2 (main thead)** ```ts -const restored = await Secp256k1Wallet.deserializeWithEncryptionKey( +const restored = await Secp256k1HdWallet.deserializeWithEncryptionKey( serialized, encryptionKey, ); diff --git a/packages/launchpad/src/cosmosclient.searchtx.spec.ts b/packages/launchpad/src/cosmosclient.searchtx.spec.ts index 5ff15c3a..dbdfcb3b 100644 --- a/packages/launchpad/src/cosmosclient.searchtx.spec.ts +++ b/packages/launchpad/src/cosmosclient.searchtx.spec.ts @@ -6,7 +6,7 @@ import { CosmosClient, isBroadcastTxFailure } from "./cosmosclient"; import { makeSignDoc } from "./encoding"; import { LcdClient } from "./lcdapi"; import { isMsgSend, MsgSend } from "./msgs"; -import { Secp256k1Wallet } from "./secp256k1wallet"; +import { Secp256k1HdWallet } from "./secp256k1hdwallet"; import { SigningCosmosClient } from "./signingcosmosclient"; import { faucet, @@ -32,7 +32,7 @@ describe("CosmosClient.searchTx", () => { beforeAll(async () => { if (wasmdEnabled()) { - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const accounts = await wallet.getAccounts(); const [{ address: walletAddress }] = accounts; const client = new SigningCosmosClient(wasmd.endpoint, faucet.address, wallet); diff --git a/packages/launchpad/src/cosmosclient.spec.ts b/packages/launchpad/src/cosmosclient.spec.ts index 95ee11b3..70305145 100644 --- a/packages/launchpad/src/cosmosclient.spec.ts +++ b/packages/launchpad/src/cosmosclient.spec.ts @@ -6,7 +6,7 @@ import { assertIsBroadcastTxSuccess, CosmosClient, PrivateCosmosClient } from ". import { makeSignDoc } from "./encoding"; import { findAttribute } from "./logs"; import { MsgSend } from "./msgs"; -import { Secp256k1Wallet } from "./secp256k1wallet"; +import { Secp256k1HdWallet } from "./secp256k1hdwallet"; import cosmoshub from "./testdata/cosmoshub.json"; import { faucet, @@ -199,7 +199,7 @@ describe("CosmosClient", () => { describe("broadcastTx", () => { it("works", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const accounts = await wallet.getAccounts(); const [{ address: walletAddress }] = accounts; const client = new CosmosClient(wasmd.endpoint); diff --git a/packages/launchpad/src/index.ts b/packages/launchpad/src/index.ts index d9589280..324b0fd2 100644 --- a/packages/launchpad/src/index.ts +++ b/packages/launchpad/src/index.ts @@ -116,4 +116,4 @@ export { CosmosFeeTable, SigningCosmosClient } from "./signingcosmosclient"; export { isStdTx, isWrappedStdTx, makeStdTx, CosmosSdkTx, StdTx, WrappedStdTx, WrappedTx } from "./tx"; export { pubkeyType, PubKey, StdFee, StdSignature } from "./types"; export { makeCosmoshubPath, executeKdf, KdfConfiguration } from "./wallet"; -export { extractKdfConfiguration, Secp256k1Wallet } from "./secp256k1wallet"; +export { extractKdfConfiguration, Secp256k1HdWallet } from "./secp256k1hdwallet"; diff --git a/packages/launchpad/src/lcdapi/distribution.spec.ts b/packages/launchpad/src/lcdapi/distribution.spec.ts index dc9f402e..d7b36ae6 100644 --- a/packages/launchpad/src/lcdapi/distribution.spec.ts +++ b/packages/launchpad/src/lcdapi/distribution.spec.ts @@ -6,7 +6,7 @@ import { coin, coins } from "../coins"; import { assertIsBroadcastTxSuccess } from "../cosmosclient"; import { makeSignDoc } from "../encoding"; import { MsgDelegate } from "../msgs"; -import { Secp256k1Wallet } from "../secp256k1wallet"; +import { Secp256k1HdWallet } from "../secp256k1hdwallet"; import { SigningCosmosClient } from "../signingcosmosclient"; import { bigDecimalMatcher, @@ -32,7 +32,7 @@ describe("DistributionExtension", () => { beforeAll(async () => { if (wasmdEnabled()) { - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = new SigningCosmosClient(wasmd.endpoint, faucet.address, wallet); const chainId = await client.getChainId(); diff --git a/packages/launchpad/src/lcdapi/gov.spec.ts b/packages/launchpad/src/lcdapi/gov.spec.ts index 5438915d..f21955c0 100644 --- a/packages/launchpad/src/lcdapi/gov.spec.ts +++ b/packages/launchpad/src/lcdapi/gov.spec.ts @@ -4,7 +4,7 @@ import { sleep } from "@cosmjs/utils"; import { coins } from "../coins"; import { assertIsBroadcastTxSuccess } from "../cosmosclient"; import { makeSignDoc } from "../encoding"; -import { Secp256k1Wallet } from "../secp256k1wallet"; +import { Secp256k1HdWallet } from "../secp256k1hdwallet"; import { SigningCosmosClient } from "../signingcosmosclient"; import { dateTimeStampMatcher, @@ -30,7 +30,7 @@ describe("GovExtension", () => { beforeAll(async () => { if (wasmdEnabled()) { - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = new SigningCosmosClient(wasmd.endpoint, faucet.address, wallet); const chainId = await client.getChainId(); diff --git a/packages/launchpad/src/lcdapi/lcdclient.spec.ts b/packages/launchpad/src/lcdapi/lcdclient.spec.ts index 051d8d86..3e1fbf85 100644 --- a/packages/launchpad/src/lcdapi/lcdclient.spec.ts +++ b/packages/launchpad/src/lcdapi/lcdclient.spec.ts @@ -6,7 +6,7 @@ import { isBroadcastTxFailure } from "../cosmosclient"; import { makeSignDoc } from "../encoding"; import { parseLogs } from "../logs"; import { MsgSend } from "../msgs"; -import { Secp256k1Wallet } from "../secp256k1wallet"; +import { Secp256k1HdWallet } from "../secp256k1hdwallet"; import { SigningCosmosClient } from "../signingcosmosclient"; import cosmoshub from "../testdata/cosmoshub.json"; import { @@ -192,7 +192,7 @@ describe("LcdClient", () => { beforeAll(async () => { if (wasmdEnabled()) { - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const accounts = await wallet.getAccounts(); const [{ address: walletAddress }] = accounts; const client = new SigningCosmosClient(wasmd.endpoint, faucet.address, wallet); @@ -319,7 +319,7 @@ describe("LcdClient", () => { beforeAll(async () => { if (wasmdEnabled()) { - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = new SigningCosmosClient(wasmd.endpoint, faucet.address, wallet); const recipient = makeRandomAddress(); @@ -501,7 +501,7 @@ describe("LcdClient", () => { describe("broadcastTx", () => { it("can send tokens", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const accounts = await wallet.getAccounts(); const [{ address: walletAddress }] = accounts; @@ -551,9 +551,9 @@ describe("LcdClient", () => { it("can't send transaction with additional signatures", async () => { pendingWithoutWasmd(); - const account1 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0)); - const account2 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1)); - const account3 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(2)); + const account1 = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0)); + const account2 = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1)); + const account3 = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(2)); const [address1, address2, address3] = await Promise.all( [account1, account2, account3].map(async (wallet) => { return (await wallet.getAccounts())[0].address; @@ -609,7 +609,7 @@ describe("LcdClient", () => { it("can send multiple messages with one signature", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0)); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0)); const accounts = await wallet.getAccounts(); const [{ address: walletAddress }] = accounts; @@ -663,8 +663,8 @@ describe("LcdClient", () => { it("can send multiple messages with multiple signatures", async () => { pendingWithoutWasmd(); - const account1 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0)); - const account2 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1)); + const account1 = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0)); + const account2 = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1)); const [address1, address2] = await Promise.all( [account1, account2].map(async (wallet) => { return (await wallet.getAccounts())[0].address; @@ -734,8 +734,8 @@ describe("LcdClient", () => { it("can't send transaction with wrong signature order (1)", async () => { pendingWithoutWasmd(); - const account1 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0)); - const account2 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1)); + const account1 = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0)); + const account2 = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1)); const [address1, address2] = await Promise.all( [account1, account2].map(async (wallet) => { return (await wallet.getAccounts())[0].address; @@ -800,8 +800,8 @@ describe("LcdClient", () => { it("can't send transaction with wrong signature order (2)", async () => { pendingWithoutWasmd(); - const account1 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0)); - const account2 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1)); + const account1 = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0)); + const account2 = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1)); const [address1, address2] = await Promise.all( [account1, account2].map(async (wallet) => { return (await wallet.getAccounts())[0].address; diff --git a/packages/launchpad/src/lcdapi/staking.spec.ts b/packages/launchpad/src/lcdapi/staking.spec.ts index c7e1439a..18feea20 100644 --- a/packages/launchpad/src/lcdapi/staking.spec.ts +++ b/packages/launchpad/src/lcdapi/staking.spec.ts @@ -5,7 +5,7 @@ import { coin, coins } from "../coins"; import { assertIsBroadcastTxSuccess } from "../cosmosclient"; import { makeSignDoc } from "../encoding"; import { MsgDelegate, MsgUndelegate } from "../msgs"; -import { Secp256k1Wallet } from "../secp256k1wallet"; +import { Secp256k1HdWallet } from "../secp256k1hdwallet"; import { SigningCosmosClient } from "../signingcosmosclient"; import { bigDecimalMatcher, @@ -32,7 +32,7 @@ describe("StakingExtension", () => { beforeAll(async () => { if (wasmdEnabled()) { - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = new SigningCosmosClient(wasmd.endpoint, faucet.address, wallet); const chainId = await client.getChainId(); diff --git a/packages/launchpad/src/secp256k1wallet.spec.ts b/packages/launchpad/src/secp256k1hdwallet.spec.ts similarity index 78% rename from packages/launchpad/src/secp256k1wallet.spec.ts rename to packages/launchpad/src/secp256k1hdwallet.spec.ts index f7f6f867..f8cb95ea 100644 --- a/packages/launchpad/src/secp256k1wallet.spec.ts +++ b/packages/launchpad/src/secp256k1hdwallet.spec.ts @@ -3,11 +3,11 @@ import { Secp256k1, Secp256k1Signature, Sha256 } from "@cosmjs/crypto"; import { fromBase64, fromHex } from "@cosmjs/encoding"; import { serializeSignDoc, StdSignDoc } from "./encoding"; -import { extractKdfConfiguration, Secp256k1Wallet } from "./secp256k1wallet"; +import { extractKdfConfiguration, Secp256k1HdWallet } from "./secp256k1hdwallet"; import { base64Matcher } from "./testutils.spec"; import { executeKdf, KdfConfiguration } from "./wallet"; -describe("Secp256k1Wallet", () => { +describe("Secp256k1HdWallet", () => { // m/44'/118'/0'/0/0 // pubkey: 02baa4ef93f2ce84592a49b1d729c074eab640112522a7a89f7d03ebab21ded7b6 const defaultMnemonic = "special sign fit simple patrol salute grocery chicken wheat radar tonight ceiling"; @@ -16,7 +16,7 @@ describe("Secp256k1Wallet", () => { describe("fromMnemonic", () => { it("works", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic(defaultMnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(defaultMnemonic); expect(wallet).toBeTruthy(); expect(wallet.mnemonic).toEqual(defaultMnemonic); }); @@ -24,25 +24,25 @@ describe("Secp256k1Wallet", () => { describe("generate", () => { it("defaults to 12 words", async () => { - const wallet = await Secp256k1Wallet.generate(); + const wallet = await Secp256k1HdWallet.generate(); expect(wallet.mnemonic.split(" ").length).toEqual(12); }); it("can use different mnemonic lengths", async () => { - expect((await Secp256k1Wallet.generate(12)).mnemonic.split(" ").length).toEqual(12); - expect((await Secp256k1Wallet.generate(15)).mnemonic.split(" ").length).toEqual(15); - expect((await Secp256k1Wallet.generate(18)).mnemonic.split(" ").length).toEqual(18); - expect((await Secp256k1Wallet.generate(21)).mnemonic.split(" ").length).toEqual(21); - expect((await Secp256k1Wallet.generate(24)).mnemonic.split(" ").length).toEqual(24); + expect((await Secp256k1HdWallet.generate(12)).mnemonic.split(" ").length).toEqual(12); + expect((await Secp256k1HdWallet.generate(15)).mnemonic.split(" ").length).toEqual(15); + expect((await Secp256k1HdWallet.generate(18)).mnemonic.split(" ").length).toEqual(18); + expect((await Secp256k1HdWallet.generate(21)).mnemonic.split(" ").length).toEqual(21); + expect((await Secp256k1HdWallet.generate(24)).mnemonic.split(" ").length).toEqual(24); }); }); describe("deserialize", () => { it("can restore", async () => { - const original = await Secp256k1Wallet.fromMnemonic(defaultMnemonic); + const original = await Secp256k1HdWallet.fromMnemonic(defaultMnemonic); const password = "123"; const serialized = await original.serialize(password); - const deserialized = await Secp256k1Wallet.deserialize(serialized, password); + const deserialized = await Secp256k1HdWallet.deserialize(serialized, password); expect(deserialized.mnemonic).toEqual(defaultMnemonic); expect(await deserialized.getAccounts()).toEqual([ { @@ -59,7 +59,7 @@ describe("Secp256k1Wallet", () => { const password = "123"; let serialized: string; { - const original = await Secp256k1Wallet.fromMnemonic(defaultMnemonic); + const original = await Secp256k1HdWallet.fromMnemonic(defaultMnemonic); const anyKdfParams: KdfConfiguration = { algorithm: "argon2id", params: { @@ -75,7 +75,7 @@ describe("Secp256k1Wallet", () => { { const kdfConfiguration = extractKdfConfiguration(serialized); const encryptionKey = await executeKdf(password, kdfConfiguration); - const deserialized = await Secp256k1Wallet.deserializeWithEncryptionKey(serialized, encryptionKey); + const deserialized = await Secp256k1HdWallet.deserializeWithEncryptionKey(serialized, encryptionKey); expect(deserialized.mnemonic).toEqual(defaultMnemonic); expect(await deserialized.getAccounts()).toEqual([ { @@ -90,7 +90,7 @@ describe("Secp256k1Wallet", () => { describe("getAccounts", () => { it("resolves to a list of accounts", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic(defaultMnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(defaultMnemonic); const accounts = await wallet.getAccounts(); expect(accounts.length).toEqual(1); expect(accounts[0]).toEqual({ @@ -101,7 +101,7 @@ describe("Secp256k1Wallet", () => { }); it("creates the same address as Go implementation", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic( + const wallet = await Secp256k1HdWallet.fromMnemonic( "oyster design unusual machine spread century engine gravity focus cave carry slot", ); const [{ address }] = await wallet.getAccounts(); @@ -111,7 +111,7 @@ describe("Secp256k1Wallet", () => { describe("sign", () => { it("resolves to valid signature if enabled", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic(defaultMnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(defaultMnemonic); const signDoc: StdSignDoc = { msgs: [], fee: { amount: [], gas: "23" }, @@ -133,7 +133,7 @@ describe("Secp256k1Wallet", () => { describe("serialize", () => { it("can save with password", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic(defaultMnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(defaultMnemonic); const serialized = await wallet.serialize("123"); expect(JSON.parse(serialized)).toEqual({ type: "secp256k1wallet-v1", @@ -155,7 +155,7 @@ describe("Secp256k1Wallet", () => { describe("serializeWithEncryptionKey", () => { it("can save with password", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic(defaultMnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(defaultMnemonic); const key = fromHex("aabb221100aabb332211aabb33221100aabb221100aabb332211aabb33221100"); const customKdfConfiguration: KdfConfiguration = { diff --git a/packages/launchpad/src/secp256k1wallet.ts b/packages/launchpad/src/secp256k1hdwallet.ts similarity index 85% rename from packages/launchpad/src/secp256k1wallet.ts rename to packages/launchpad/src/secp256k1hdwallet.ts index a515d3de..92b89194 100644 --- a/packages/launchpad/src/secp256k1wallet.ts +++ b/packages/launchpad/src/secp256k1hdwallet.ts @@ -46,14 +46,14 @@ const basicPasswordHashingOptions: KdfConfiguration = { * This interface describes a JSON object holding the encrypted wallet and the meta data. * All fields in here must be JSON types. */ -export interface Secp256k1WalletSerialization { +export interface Secp256k1HdWalletSerialization { /** A format+version identifier for this serialization format */ readonly type: string; /** Information about the key derivation function (i.e. password to encryption key) */ readonly kdf: KdfConfiguration; /** Information about the symmetric encryption */ readonly encryption: EncryptionConfiguration; - /** An instance of Secp256k1WalletData, which is stringified, encrypted and base64 encoded. */ + /** An instance of Secp256k1HdWalletData, which is stringified, encrypted and base64 encoded. */ readonly data: string; } @@ -61,15 +61,15 @@ export interface Secp256k1WalletSerialization { * Derivation information required to derive a keypair and an address from a mnemonic. * All fields in here must be JSON types. */ -interface Secp256k1DerivationJson { +interface DerivationInfoJson { readonly hdPath: string; readonly prefix: string; } -function isSecp256k1DerivationJson(thing: unknown): thing is Secp256k1DerivationJson { +function isDerivationJson(thing: unknown): thing is DerivationInfoJson { if (!isNonNullObject(thing)) return false; - if (typeof (thing as Secp256k1DerivationJson).hdPath !== "string") return false; - if (typeof (thing as Secp256k1DerivationJson).prefix !== "string") return false; + if (typeof (thing as DerivationInfoJson).hdPath !== "string") return false; + if (typeof (thing as DerivationInfoJson).prefix !== "string") return false; return true; } @@ -77,9 +77,9 @@ function isSecp256k1DerivationJson(thing: unknown): thing is Secp256k1Derivation * The data of a wallet serialization that is encrypted. * All fields in here must be JSON types. */ -export interface Secp256k1WalletData { +interface Secp256k1HdWalletData { readonly mnemonic: string; - readonly accounts: readonly Secp256k1DerivationJson[]; + readonly accounts: readonly DerivationInfoJson[]; } function extractKdfConfigurationV1(doc: any): KdfConfiguration { @@ -101,12 +101,13 @@ export function extractKdfConfiguration(serialization: string): KdfConfiguration /** * Derivation information required to derive a keypair and an address from a mnemonic. */ -interface Secp256k1Derivation { +interface DerivationInfo { readonly hdPath: HdPath; + /** The bech32 address prefix (human readable part). */ readonly prefix: string; } -export class Secp256k1Wallet implements OfflineSigner { +export class Secp256k1HdWallet implements OfflineSigner { /** * Restores a wallet from the given BIP39 mnemonic. * @@ -118,12 +119,12 @@ export class Secp256k1Wallet implements OfflineSigner { 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 Secp256k1Wallet( + return new Secp256k1HdWallet( mnemonicChecked, hdPath, privkey, @@ -143,11 +144,11 @@ export class Secp256k1Wallet implements OfflineSigner { 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 Secp256k1Wallet.fromMnemonic(mnemonic.toString(), hdPath, prefix); + return Secp256k1HdWallet.fromMnemonic(mnemonic.toString(), hdPath, prefix); } /** @@ -156,12 +157,12 @@ export class Secp256k1Wallet implements OfflineSigner { * @param password The user provided password used to generate an encryption key via a KDF. * This is not normalized internally (see "Unicode normalization" to learn more). */ - public static async deserialize(serialization: string, password: string): Promise { + public static async deserialize(serialization: string, password: string): Promise { const root = JSON.parse(serialization); if (!isNonNullObject(root)) throw new Error("Root document is not an object."); switch ((root as any).type) { case serializationTypeV1: - return Secp256k1Wallet.deserializeTypeV1(serialization, password); + return Secp256k1HdWallet.deserializeTypeV1(serialization, password); default: throw new Error("Unsupported serialization type"); } @@ -179,7 +180,7 @@ export class Secp256k1Wallet implements OfflineSigner { public static async deserializeWithEncryptionKey( serialization: string, encryptionKey: Uint8Array, - ): Promise { + ): Promise { const root = JSON.parse(serialization); if (!isNonNullObject(root)) throw new Error("Root document is not an object."); const untypedRoot: any = root; @@ -196,25 +197,28 @@ export class Secp256k1Wallet implements OfflineSigner { if (!Array.isArray(accounts)) throw new Error("Property 'accounts' is not an array"); if (accounts.length !== 1) throw new Error("Property 'accounts' only supports one entry"); const account = accounts[0]; - if (!isSecp256k1DerivationJson(account)) throw new Error("Account is not in the correct format."); - return Secp256k1Wallet.fromMnemonic(mnemonic, stringToPath(account.hdPath), account.prefix); + if (!isDerivationJson(account)) throw new Error("Account is not in the correct format."); + return Secp256k1HdWallet.fromMnemonic(mnemonic, stringToPath(account.hdPath), account.prefix); } default: throw new Error("Unsupported serialization type"); } } - private static async deserializeTypeV1(serialization: string, password: string): Promise { + private static async deserializeTypeV1( + serialization: string, + password: string, + ): Promise { const root = JSON.parse(serialization); if (!isNonNullObject(root)) throw new Error("Root document is not an object."); const encryptionKey = await executeKdf(password, (root as any).kdf); - return Secp256k1Wallet.deserializeWithEncryptionKey(serialization, encryptionKey); + return Secp256k1HdWallet.deserializeWithEncryptionKey(serialization, encryptionKey); } /** Base secret */ private readonly secret: EnglishMnemonic; /** Derivation instruction */ - private readonly accounts: readonly Secp256k1Derivation[]; + private readonly accounts: readonly DerivationInfo[]; /** Derived data */ private readonly pubkey: Uint8Array; private readonly privkey: Uint8Array; @@ -293,10 +297,10 @@ export class Secp256k1Wallet implements OfflineSigner { encryptionKey: Uint8Array, kdfConfiguration: KdfConfiguration, ): Promise { - const dataToEncrypt: Secp256k1WalletData = { + const dataToEncrypt: Secp256k1HdWalletData = { mnemonic: this.mnemonic, accounts: this.accounts.map( - (account): Secp256k1DerivationJson => ({ + (account): DerivationInfoJson => ({ hdPath: pathToString(account.hdPath), prefix: account.prefix, }), @@ -309,7 +313,7 @@ export class Secp256k1Wallet implements OfflineSigner { }; const encryptedData = await encrypt(dataToEncryptRaw, encryptionKey, encryptionConfiguration); - const out: Secp256k1WalletSerialization = { + const out: Secp256k1HdWalletSerialization = { type: serializationTypeV1, kdf: kdfConfiguration, encryption: encryptionConfiguration, diff --git a/packages/launchpad/src/signingcosmosclient.spec.ts b/packages/launchpad/src/signingcosmosclient.spec.ts index a6b2d0b6..28a71a52 100644 --- a/packages/launchpad/src/signingcosmosclient.spec.ts +++ b/packages/launchpad/src/signingcosmosclient.spec.ts @@ -5,7 +5,7 @@ import { Coin, coin, coins } from "./coins"; import { assertIsBroadcastTxSuccess, PrivateCosmosClient } from "./cosmosclient"; import { GasPrice } from "./gas"; import { MsgDelegate } from "./msgs"; -import { Secp256k1Wallet } from "./secp256k1wallet"; +import { Secp256k1HdWallet } from "./secp256k1hdwallet"; import { PrivateSigningCosmosClient, SigningCosmosClient } from "./signingcosmosclient"; import { makeRandomAddress, pendingWithoutWasmd, wasmd } from "./testutils.spec"; @@ -24,7 +24,7 @@ const faucet = { describe("SigningCosmosClient", () => { describe("makeReadOnly", () => { it("can be constructed with default fees", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = new SigningCosmosClient(httpUrl, faucet.address, wallet); const openedClient = (client as unknown) as PrivateSigningCosmosClient; expect(openedClient.fees).toEqual({ @@ -41,7 +41,7 @@ describe("SigningCosmosClient", () => { }); it("can be constructed with custom gas price", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const gasPrice = GasPrice.fromString("3.14utest"); const client = new SigningCosmosClient(httpUrl, faucet.address, wallet, gasPrice); const openedClient = (client as unknown) as PrivateSigningCosmosClient; @@ -59,7 +59,7 @@ describe("SigningCosmosClient", () => { }); it("can be constructed with custom gas limits", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const gasLimits = { send: 160000, }; @@ -79,7 +79,7 @@ describe("SigningCosmosClient", () => { }); it("can be constructed with custom gas price and gas limits", async () => { - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const gasPrice = GasPrice.fromString("3.14utest"); const gasLimits = { send: 160000, @@ -103,7 +103,7 @@ describe("SigningCosmosClient", () => { describe("getHeight", () => { it("always uses authAccount implementation", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = new SigningCosmosClient(httpUrl, faucet.address, wallet); const openedClient = (client as unknown) as PrivateCosmosClient; @@ -121,7 +121,7 @@ describe("SigningCosmosClient", () => { describe("sendTokens", () => { it("works", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = new SigningCosmosClient(httpUrl, faucet.address, wallet); // instantiate @@ -153,7 +153,7 @@ describe("SigningCosmosClient", () => { describe("signAndBroadcast", () => { it("works", async () => { pendingWithoutWasmd(); - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = new SigningCosmosClient(httpUrl, faucet.address, wallet); const msg: MsgDelegate = { diff --git a/packages/launchpad/types/index.d.ts b/packages/launchpad/types/index.d.ts index 62c3074d..fe5b08ea 100644 --- a/packages/launchpad/types/index.d.ts +++ b/packages/launchpad/types/index.d.ts @@ -114,4 +114,4 @@ export { CosmosFeeTable, SigningCosmosClient } from "./signingcosmosclient"; export { isStdTx, isWrappedStdTx, makeStdTx, CosmosSdkTx, StdTx, WrappedStdTx, WrappedTx } from "./tx"; export { pubkeyType, PubKey, StdFee, StdSignature } from "./types"; export { makeCosmoshubPath, executeKdf, KdfConfiguration } from "./wallet"; -export { extractKdfConfiguration, Secp256k1Wallet } from "./secp256k1wallet"; +export { extractKdfConfiguration, Secp256k1HdWallet } from "./secp256k1hdwallet"; diff --git a/packages/launchpad/types/secp256k1wallet.d.ts b/packages/launchpad/types/secp256k1hdwallet.d.ts similarity index 82% rename from packages/launchpad/types/secp256k1wallet.d.ts rename to packages/launchpad/types/secp256k1hdwallet.d.ts index 29c7b63d..7d3cbe00 100644 --- a/packages/launchpad/types/secp256k1wallet.d.ts +++ b/packages/launchpad/types/secp256k1hdwallet.d.ts @@ -6,34 +6,18 @@ import { EncryptionConfiguration, KdfConfiguration } from "./wallet"; * This interface describes a JSON object holding the encrypted wallet and the meta data. * All fields in here must be JSON types. */ -export interface Secp256k1WalletSerialization { +export interface Secp256k1HdWalletSerialization { /** A format+version identifier for this serialization format */ readonly type: string; /** Information about the key derivation function (i.e. password to encryption key) */ readonly kdf: KdfConfiguration; /** Information about the symmetric encryption */ readonly encryption: EncryptionConfiguration; - /** An instance of Secp256k1WalletData, which is stringified, encrypted and base64 encoded. */ + /** An instance of Secp256k1HdWalletData, which is stringified, encrypted and base64 encoded. */ readonly data: string; } -/** - * Derivation information required to derive a keypair and an address from a mnemonic. - * All fields in here must be JSON types. - */ -interface Secp256k1DerivationJson { - readonly hdPath: string; - readonly prefix: string; -} -/** - * The data of a wallet serialization that is encrypted. - * All fields in here must be JSON types. - */ -export interface Secp256k1WalletData { - readonly mnemonic: string; - readonly accounts: readonly Secp256k1DerivationJson[]; -} export declare function extractKdfConfiguration(serialization: string): KdfConfiguration; -export declare class Secp256k1Wallet implements OfflineSigner { +export declare class Secp256k1HdWallet implements OfflineSigner { /** * Restores a wallet from the given BIP39 mnemonic. * @@ -41,7 +25,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?: 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. * @@ -53,14 +37,14 @@ export declare class Secp256k1Wallet implements OfflineSigner { length?: 12 | 15 | 18 | 21 | 24, hdPath?: HdPath, prefix?: string, - ): Promise; + ): Promise; /** * Restores a wallet from an encrypted serialization. * * @param password The user provided password used to generate an encryption key via a KDF. * This is not normalized internally (see "Unicode normalization" to learn more). */ - static deserialize(serialization: string, password: string): Promise; + static deserialize(serialization: string, password: string): Promise; /** * Restores a wallet from an encrypted serialization. * @@ -73,7 +57,7 @@ export declare class Secp256k1Wallet implements OfflineSigner { static deserializeWithEncryptionKey( serialization: string, encryptionKey: Uint8Array, - ): Promise; + ): Promise; private static deserializeTypeV1; /** Base secret */ private readonly secret; @@ -105,4 +89,3 @@ export declare class Secp256k1Wallet implements OfflineSigner { */ serializeWithEncryptionKey(encryptionKey: Uint8Array, kdfConfiguration: KdfConfiguration): Promise; } -export {}; diff --git a/scripts/wasmd/deploy_erc20.js b/scripts/wasmd/deploy_erc20.js index c0925c86..1219d7f4 100755 --- a/scripts/wasmd/deploy_erc20.js +++ b/scripts/wasmd/deploy_erc20.js @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm"); -const { Secp256k1Wallet } = require("@cosmjs/launchpad"); +const { Secp256k1HdWallet } = require("@cosmjs/launchpad"); const fs = require("fs"); const httpUrl = "http://localhost:1317"; @@ -134,7 +134,7 @@ const initDataJade = { }; async function main() { - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); const wasm = fs.readFileSync(__dirname + "/contracts/cw-erc20.wasm"); diff --git a/scripts/wasmd/deploy_nameservice.js b/scripts/wasmd/deploy_nameservice.js index 713b77bf..fac379b5 100755 --- a/scripts/wasmd/deploy_nameservice.js +++ b/scripts/wasmd/deploy_nameservice.js @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm"); -const { Secp256k1Wallet } = require("@cosmjs/launchpad"); +const { Secp256k1HdWallet } = require("@cosmjs/launchpad"); const fs = require("fs"); const httpUrl = "http://localhost:1317"; @@ -36,7 +36,7 @@ const luxury = { }; async function main() { - const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet); const wasm = fs.readFileSync(__dirname + "/contracts/cw-nameservice.wasm"); diff --git a/scripts/wasmd/send_first.js b/scripts/wasmd/send_first.js index c12332b1..457fdab8 100755 --- a/scripts/wasmd/send_first.js +++ b/scripts/wasmd/send_first.js @@ -5,7 +5,7 @@ const { Random } = require("@cosmjs/crypto"); const { Bech32 } = require("@cosmjs/encoding"); const { coins, - Secp256k1Wallet, + Secp256k1HdWallet, SigningCosmosClient, assertIsBroadcastTxSuccess, } = require("@cosmjs/launchpad"); @@ -18,7 +18,7 @@ const faucet = { }; async function main() { - const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = new SigningCosmosClient(httpUrl, faucet.address0, wallet); const recipient = Bech32.encode("cosmos", Random.getBytes(20)); const amount = coins(226644, "ucosm");