Merge pull request #453 from CosmWasm/Secp256k1HdWallet

Rename Secp256k1Wallet to Secp256k1HdWallet
This commit is contained in:
Simon Warta 2020-10-08 10:48:04 +02:00 committed by GitHub
commit d28caf8a41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 140 additions and 151 deletions

View File

@ -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.

View File

@ -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(

View File

@ -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();

View File

@ -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)}`);

View File

@ -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);

View File

@ -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<string> => {
};
const mnemonicToAddress = async (prefix: string, mnemonic: string): Promise<string> => {
const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic);
const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic);
const [{ address }] = await wallet.getAccounts();
return address;
};

View File

@ -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);

View File

@ -113,7 +113,7 @@ export async function main(originalArgs: readonly string[]): Promise<void> {
"OfflineSigner",
"PubKey",
"pubkeyToAddress",
"Secp256k1Wallet",
"Secp256k1HdWallet",
"SigningCosmosClient",
"StdFee",
"StdSignDoc",
@ -160,7 +160,7 @@ export async function main(originalArgs: readonly string[]): Promise<void> {
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 = {

View File

@ -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);
{

View File

@ -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() };

View File

@ -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")];

View File

@ -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 = {

View File

@ -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}`;

View File

@ -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,
);

View File

@ -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);

View File

@ -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);

View File

@ -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";

View File

@ -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();

View File

@ -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();

View File

@ -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;

View File

@ -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();

View File

@ -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 = {

View File

@ -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<Secp256k1Wallet> {
): Promise<Secp256k1HdWallet> {
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<Secp256k1Wallet> {
): Promise<Secp256k1HdWallet> {
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<Secp256k1Wallet> {
public static async deserialize(serialization: string, password: string): Promise<Secp256k1HdWallet> {
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<Secp256k1Wallet> {
): Promise<Secp256k1HdWallet> {
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<Secp256k1Wallet> {
private static async deserializeTypeV1(
serialization: string,
password: string,
): Promise<Secp256k1HdWallet> {
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<string> {
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,

View File

@ -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 = {

View File

@ -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";

View File

@ -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<Secp256k1Wallet>;
static fromMnemonic(mnemonic: string, hdPath?: HdPath, prefix?: string): Promise<Secp256k1HdWallet>;
/**
* 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<Secp256k1Wallet>;
): Promise<Secp256k1HdWallet>;
/**
* 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<Secp256k1Wallet>;
static deserialize(serialization: string, password: string): Promise<Secp256k1HdWallet>;
/**
* Restores a wallet from an encrypted serialization.
*
@ -73,7 +57,7 @@ export declare class Secp256k1Wallet implements OfflineSigner {
static deserializeWithEncryptionKey(
serialization: string,
encryptionKey: Uint8Array,
): Promise<Secp256k1Wallet>;
): Promise<Secp256k1HdWallet>;
private static deserializeTypeV1;
/** Base secret */
private readonly secret;
@ -105,4 +89,3 @@ export declare class Secp256k1Wallet implements OfflineSigner {
*/
serializeWithEncryptionKey(encryptionKey: Uint8Array, kdfConfiguration: KdfConfiguration): Promise<string>;
}
export {};

View File

@ -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");

View File

@ -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");

View File

@ -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");