sdk38: Rename Secp256k1OfflineWallet -> Secp256k1Wallet

This commit is contained in:
willclarktech 2020-07-14 14:31:16 +02:00
parent 0561dd5dd5
commit 21f083336e
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
28 changed files with 82 additions and 89 deletions

View File

@ -1,4 +1,4 @@
const wallet = await Secp256k1OfflineWallet.fromMnemonic(
const wallet = await Secp256k1Wallet.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 Secp256k1OfflineWallet.fromMnemonic(mnemonic, makeCosmoshubPath(i), "cosmos");
const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic, makeCosmoshubPath(i), "cosmos");
const [{ address, pubkey }] = await wallet.getAccounts();
console.info(`Address ${i}: ${address}`);
console.info(`Pubkey ${i}: ${pubkey}`);

View File

@ -1,5 +1,5 @@
const mnemonic = Bip39.encode(Random.getBytes(16)).toString();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic);
const [{ address, pubkey }] = await wallet.getAccounts();
console.info("mnemonic:", mnemonic);

View File

@ -52,7 +52,7 @@ const connect = async (
}> => {
const options: Options = { ...defaultOptions, ...opts };
const feeTable = buildFeeTable(options.feeToken, options.gasPrice);
const wallet = await Secp256k1OfflineWallet.fromMnemonic(mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic);
const [{ address }] = await wallet.getAccounts();
const client = new SigningCosmWasmClient(options.httpUrl, address, wallet, feeTable);
@ -92,7 +92,7 @@ const randomAddress = async (prefix: string): Promise<string> => {
};
const mnemonicToAddress = async (prefix: string, mnemonic: string): Promise<string> => {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(mnemonic);
const wallet = await Secp256k1Wallet.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 Secp256k1OfflineWallet.fromMnemonic(faucetMnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(faucetMnemonic);
const client = new LcdClient(defaultHttpUrl);

View File

@ -100,7 +100,7 @@ export function main(originalArgs: readonly string[]): void {
"OfflineSigner",
"PubKey",
"pubkeyToAddress",
"Secp256k1OfflineWallet",
"Secp256k1Wallet",
"SigningCosmosClient",
"StdFee",
"StdTx",
@ -145,7 +145,7 @@ export function main(originalArgs: readonly string[]): void {
assert(Decimal.fromAtomics("12870000", 6).toString() === "12.87");
const mnemonic = Bip39.encode(Random.getBytes(16)).toString();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(mnemonic, makeCosmoshubPath(0));
const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic, makeCosmoshubPath(0));
const [{ address }] = await wallet.getAccounts();
const data = toAscii("foo bar");
const signature = await wallet.sign(address, data);

View File

@ -7,7 +7,7 @@ import {
LcdClient,
makeSignBytes,
MsgSend,
Secp256k1OfflineWallet,
Secp256k1Wallet,
} from "@cosmjs/sdk38";
import { assert, sleep } from "@cosmjs/utils";
@ -48,7 +48,7 @@ describe("CosmWasmClient.searchTx", () => {
beforeAll(async () => {
if (wasmdEnabled()) {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(wasmd.endpoint, alice.address0, wallet);
{

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/camelcase */
import { Sha256 } from "@cosmjs/crypto";
import { Bech32, fromHex, fromUtf8, toAscii, toBase64 } from "@cosmjs/encoding";
import { makeSignBytes, MsgSend, Secp256k1OfflineWallet, StdFee } from "@cosmjs/sdk38";
import { makeSignBytes, MsgSend, Secp256k1Wallet, StdFee } from "@cosmjs/sdk38";
import { assert, sleep } from "@cosmjs/utils";
import { ReadonlyDate } from "readonly-date";
@ -204,7 +204,7 @@ describe("CosmWasmClient", () => {
describe("postTx", () => {
it("works", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new CosmWasmClient(wasmd.endpoint);
const memo = "My first contract on chain";
@ -388,7 +388,7 @@ describe("CosmWasmClient", () => {
beforeAll(async () => {
if (wasmdEnabled()) {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.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() };
@ -439,7 +439,7 @@ describe("CosmWasmClient", () => {
beforeAll(async () => {
if (wasmdEnabled()) {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.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

@ -10,7 +10,7 @@ import {
makeSignBytes,
OfflineSigner,
PostTxsResponse,
Secp256k1OfflineWallet,
Secp256k1Wallet,
setupAuthExtension,
StdFee,
} from "@cosmjs/sdk38";
@ -256,7 +256,7 @@ describe("wasm", () => {
describe("postTx", () => {
it("can upload, instantiate and execute wasm", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = makeWasmClient(wasmd.endpoint);
const transferAmount = [coin(1234, "ucosm"), coin(321, "ustake")];
@ -324,7 +324,7 @@ describe("wasm", () => {
describe("query", () => {
it("can list upload code", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = makeWasmClient(wasmd.endpoint);
// check with contracts were here first to compare
@ -362,7 +362,7 @@ describe("wasm", () => {
it("can list contracts and get info", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = makeWasmClient(wasmd.endpoint);
const beneficiaryAddress = makeRandomAddress();
const transferAmount: readonly Coin[] = [
@ -438,7 +438,7 @@ describe("wasm", () => {
beforeAll(async () => {
if (wasmdEnabled()) {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const uploadResult = await uploadContract(client, wallet, getHackatom());
assert(!uploadResult.code);
const uploadLogs = parseLogs(uploadResult.logs);

View File

@ -1,13 +1,6 @@
import { Sha256 } from "@cosmjs/crypto";
import { toHex } from "@cosmjs/encoding";
import {
AuthExtension,
coin,
coins,
LcdClient,
Secp256k1OfflineWallet,
setupAuthExtension,
} from "@cosmjs/sdk38";
import { AuthExtension, coin, coins, LcdClient, Secp256k1Wallet, setupAuthExtension } from "@cosmjs/sdk38";
import { assert } from "@cosmjs/utils";
import { isPostTxFailure, PrivateCosmWasmClient } from "./cosmwasmclient";
@ -24,7 +17,7 @@ function makeWasmClient(apiUrl: string): LcdClient & AuthExtension & WasmExtensi
describe("SigningCosmWasmClient", () => {
describe("makeReadOnly", () => {
it("can be constructed", async () => {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
expect(client).toBeTruthy();
});
@ -33,7 +26,7 @@ describe("SigningCosmWasmClient", () => {
describe("getHeight", () => {
it("always uses authAccount implementation", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const openedClient = (client as unknown) as PrivateCosmWasmClient;
@ -51,7 +44,7 @@ describe("SigningCosmWasmClient", () => {
describe("upload", () => {
it("works", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const wasm = getHackatom().data;
const {
@ -70,7 +63,7 @@ describe("SigningCosmWasmClient", () => {
it("can set builder and source", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const hackatom = getHackatom();
@ -89,7 +82,7 @@ describe("SigningCosmWasmClient", () => {
describe("instantiate", () => {
it("works with transfer amount", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const { codeId } = await client.upload(getHackatom().data);
@ -115,7 +108,7 @@ describe("SigningCosmWasmClient", () => {
it("works with admin", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const { codeId } = await client.upload(getHackatom().data);
@ -138,7 +131,7 @@ describe("SigningCosmWasmClient", () => {
it("can instantiate one code multiple times", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const { codeId } = await client.upload(getHackatom().data);
@ -165,7 +158,7 @@ describe("SigningCosmWasmClient", () => {
describe("updateAdmin", () => {
it("can update an admin", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const { codeId } = await client.upload(getHackatom().data);
@ -198,7 +191,7 @@ describe("SigningCosmWasmClient", () => {
describe("clearAdmin", () => {
it("can clear an admin", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const { codeId } = await client.upload(getHackatom().data);
@ -231,7 +224,7 @@ describe("SigningCosmWasmClient", () => {
describe("migrate", () => {
it("can can migrate from one code ID to another", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.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);
@ -270,7 +263,7 @@ describe("SigningCosmWasmClient", () => {
describe("execute", () => {
it("works", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const { codeId } = await client.upload(getHackatom().data);
@ -311,7 +304,7 @@ describe("SigningCosmWasmClient", () => {
describe("sendTokens", () => {
it("works", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
// instantiate

View File

@ -176,7 +176,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
*
* @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API)
* @param senderAddress The address that will sign and send transactions using this instance
* @param signer A wallet provider which can provide signatures for transactions, potentially requiring user input.
* @param signer An implementation of OfflineSigner which can provide signatures for transactions, potentially requiring user input.
* @param customFees The fees that are paid for transactions
* @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns
*/

View File

@ -93,7 +93,7 @@ export declare class SigningCosmWasmClient extends CosmWasmClient {
*
* @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API)
* @param senderAddress The address that will sign and send transactions using this instance
* @param signer A wallet provider which can provide signatures for transactions, potentially requiring user input.
* @param signer An implementation of OfflineSigner which can provide signatures for transactions, potentially requiring user input.
* @param customFees The fees that are paid for transactions
* @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns
*/

View File

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/camelcase */
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm";
import { Coin, coins, makeCosmoshubPath, Secp256k1OfflineWallet } from "@cosmjs/sdk38";
import { Coin, coins, makeCosmoshubPath, Secp256k1Wallet } from "@cosmjs/sdk38";
import {
BalanceResponse,
@ -40,12 +40,12 @@ describe("Staking demo", () => {
it("works", async () => {
pendingWithoutWasmd();
// The owner of the contract that will collect the tax
const ownerWallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const ownerWallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const [{ address: ownerAddress }] = await ownerWallet.getAccounts();
const ownerClient = new SigningCosmWasmClient(httpUrl, ownerAddress, ownerWallet);
// a user of the contract
const userWallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic, makeCosmoshubPath(1));
const userWallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic, makeCosmoshubPath(1));
const [{ address: userAddress }] = await userWallet.getAccounts();
const userClient = new SigningCosmWasmClient(httpUrl, userAddress, userWallet, {
exec: {

View File

@ -1,5 +1,5 @@
import { pathToString } from "@cosmjs/crypto";
import { makeCosmoshubPath, OfflineSigner, Secp256k1OfflineWallet } from "@cosmjs/sdk38";
import { makeCosmoshubPath, OfflineSigner, Secp256k1Wallet } from "@cosmjs/sdk38";
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 Secp256k1OfflineWallet.fromMnemonic(mnemonic, path, addressPrefix);
const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic, path, addressPrefix);
const [{ address }] = await wallet.getAccounts();
if (logging) {
const role = i === 0 ? "token holder " : `distributor ${i}`;

View File

@ -16,7 +16,7 @@ import {
wasmdEnabled,
} from "./testutils.spec";
import { CosmosSdkTx } from "./types";
import { Secp256k1OfflineWallet } from "./wallet";
import { Secp256k1Wallet } from "./wallet";
interface TestTxSend {
readonly sender: string;
@ -32,7 +32,7 @@ describe("CosmosClient.searchTx", () => {
beforeAll(async () => {
if (wasmdEnabled()) {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic);
const accounts = await wallet.getAccounts();
const [{ address: walletAddress }] = accounts;
const client = new SigningCosmosClient(wasmd.endpoint, faucet.address, wallet);

View File

@ -16,7 +16,7 @@ import {
wasmd,
} from "./testutils.spec";
import { StdFee } from "./types";
import { Secp256k1OfflineWallet } from "./wallet";
import { Secp256k1Wallet } from "./wallet";
const blockTime = 1_000; // ms
@ -193,7 +193,7 @@ describe("CosmosClient", () => {
describe("postTx", () => {
it("works", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic);
const accounts = await wallet.getAccounts();
const [{ address: walletAddress }] = accounts;
const client = new CosmosClient(wasmd.endpoint);

View File

@ -55,4 +55,4 @@ export { findSequenceForSignedTx } from "./sequence";
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
export { FeeTable, SigningCosmosClient } from "./signingcosmosclient";
export { isStdTx, pubkeyType, CosmosSdkTx, PubKey, StdFee, StdSignature, StdTx } from "./types";
export { OfflineSigner, Secp256k1OfflineWallet, makeCosmoshubPath } from "./wallet";
export { OfflineSigner, Secp256k1Wallet, makeCosmoshubPath } from "./wallet";

View File

@ -19,7 +19,7 @@ import {
wasmdEnabled,
} from "../testutils.spec";
import { StdFee } from "../types";
import { makeCosmoshubPath, Secp256k1OfflineWallet } from "../wallet";
import { makeCosmoshubPath, Secp256k1Wallet } from "../wallet";
import { setupAuthExtension } from "./auth";
import { TxsResponse } from "./base";
import { LcdApiArray, LcdClient, normalizeLcdApiArray } from "./lcdclient";
@ -216,7 +216,7 @@ describe("LcdClient", () => {
beforeAll(async () => {
if (wasmdEnabled()) {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic);
const accounts = await wallet.getAccounts();
const [{ address: walletAddress }] = accounts;
const client = new SigningCosmosClient(wasmd.endpoint, faucet.address, wallet);
@ -350,7 +350,7 @@ describe("LcdClient", () => {
beforeAll(async () => {
if (wasmdEnabled()) {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic);
const client = new SigningCosmosClient(wasmd.endpoint, faucet.address, wallet);
const recipient = makeRandomAddress();
@ -531,7 +531,7 @@ describe("LcdClient", () => {
describe("postTx", () => {
it("can send tokens", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic);
const accounts = await wallet.getAccounts();
const [{ address: walletAddress }] = accounts;
@ -581,9 +581,9 @@ describe("LcdClient", () => {
it("can't send transaction with additional signatures", async () => {
pendingWithoutWasmd();
const account1 = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0));
const account2 = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1));
const account3 = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(2));
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 [address1, address2, address3] = await Promise.all(
[account1, account2, account3].map(async (wallet) => {
return (await wallet.getAccounts())[0].address;
@ -639,7 +639,7 @@ describe("LcdClient", () => {
it("can send multiple messages with one signature", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0));
const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0));
const accounts = await wallet.getAccounts();
const [{ address: walletAddress }] = accounts;
@ -698,8 +698,8 @@ describe("LcdClient", () => {
it("can send multiple messages with multiple signatures", async () => {
pendingWithoutWasmd();
const account1 = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0));
const account2 = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1));
const account1 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0));
const account2 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1));
const [address1, address2] = await Promise.all(
[account1, account2].map(async (wallet) => {
return (await wallet.getAccounts())[0].address;
@ -769,8 +769,8 @@ describe("LcdClient", () => {
it("can't send transaction with wrong signature order (1)", async () => {
pendingWithoutWasmd();
const account1 = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0));
const account2 = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1));
const account1 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0));
const account2 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1));
const [address1, address2] = await Promise.all(
[account1, account2].map(async (wallet) => {
return (await wallet.getAccounts())[0].address;
@ -835,8 +835,8 @@ describe("LcdClient", () => {
it("can't send transaction with wrong signature order (2)", async () => {
pendingWithoutWasmd();
const account1 = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0));
const account2 = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1));
const account1 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(0));
const account2 = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic, makeCosmoshubPath(1));
const [address1, address2] = await Promise.all(
[account1, account2].map(async (wallet) => {
return (await wallet.getAccounts())[0].address;

View File

@ -4,7 +4,7 @@ import { Coin } from "./coins";
import { isPostTxFailure, PrivateCosmWasmClient } from "./cosmosclient";
import { SigningCosmosClient } from "./signingcosmosclient";
import { makeRandomAddress, pendingWithoutWasmd } from "./testutils.spec";
import { Secp256k1OfflineWallet } from "./wallet";
import { Secp256k1Wallet } from "./wallet";
const httpUrl = "http://localhost:1317";
@ -21,7 +21,7 @@ const faucet = {
describe("SigningCosmosClient", () => {
describe("makeReadOnly", () => {
it("can be constructed", async () => {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic);
const client = new SigningCosmosClient(httpUrl, faucet.address, wallet);
expect(client).toBeTruthy();
});
@ -30,7 +30,7 @@ describe("SigningCosmosClient", () => {
describe("getHeight", () => {
it("always uses authAccount implementation", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic);
const client = new SigningCosmosClient(httpUrl, faucet.address, wallet);
const openedClient = (client as unknown) as PrivateCosmWasmClient;
@ -48,7 +48,7 @@ describe("SigningCosmosClient", () => {
describe("sendTokens", () => {
it("works", async () => {
pendingWithoutWasmd();
const wallet = await Secp256k1OfflineWallet.fromMnemonic(faucet.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic);
const client = new SigningCosmosClient(httpUrl, faucet.address, wallet);
// instantiate

View File

@ -46,7 +46,7 @@ export class SigningCosmosClient extends CosmosClient {
*
* @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API)
* @param senderAddress The address that will sign and send transactions using this instance
* @param signer A wallet provider which can provide signatures for transactions, potentially requiring user input.
* @param signer An implementation of OfflineSigner which can provide signatures for transactions, potentially requiring user input.
* @param customFees The fees that are paid for transactions
* @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns
*/

View File

@ -1,9 +1,9 @@
import { Secp256k1, Secp256k1Signature, Sha256 } from "@cosmjs/crypto";
import { fromBase64, fromHex, toAscii } from "@cosmjs/encoding";
import { Secp256k1OfflineWallet } from "./wallet";
import { Secp256k1Wallet } from "./wallet";
describe("Secp256k1OfflineWallet", () => {
describe("Secp256k1Wallet", () => {
// m/44'/118'/0'/0/0
// pubkey: 02baa4ef93f2ce84592a49b1d729c074eab640112522a7a89f7d03ebab21ded7b6
const defaultMnemonic = "special sign fit simple patrol salute grocery chicken wheat radar tonight ceiling";
@ -11,13 +11,13 @@ describe("Secp256k1OfflineWallet", () => {
const defaultAddress = "cosmos1jhg0e7s6gn44tfc5k37kr04sznyhedtc9rzys5";
it("can be constructed", async () => {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(defaultMnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(defaultMnemonic);
expect(wallet).toBeTruthy();
});
describe("getAccounts", () => {
it("resolves to a list of accounts if enabled", async () => {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(defaultMnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(defaultMnemonic);
const accounts = await wallet.getAccounts();
expect(accounts.length).toEqual(1);
expect(accounts[0]).toEqual({
@ -28,7 +28,7 @@ describe("Secp256k1OfflineWallet", () => {
});
it("creates the same address as Go implementation", async () => {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(
const wallet = await Secp256k1Wallet.fromMnemonic(
"oyster design unusual machine spread century engine gravity focus cave carry slot",
);
const [{ address }] = await wallet.getAccounts();
@ -38,7 +38,7 @@ describe("Secp256k1OfflineWallet", () => {
describe("sign", () => {
it("resolves to valid signature if enabled", async () => {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(defaultMnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(defaultMnemonic);
const message = toAscii("foo bar");
const signature = await wallet.sign(defaultAddress, message);
const valid = await Secp256k1.verifySignature(

View File

@ -63,16 +63,16 @@ export function makeCosmoshubPath(a: number): readonly Slip10RawIndex[] {
];
}
export class Secp256k1OfflineWallet implements OfflineSigner {
export class Secp256k1Wallet implements OfflineSigner {
public static async fromMnemonic(
mnemonic: string,
hdPath: readonly Slip10RawIndex[] = makeCosmoshubPath(0),
prefix = "cosmos",
): Promise<Secp256k1OfflineWallet> {
): Promise<Secp256k1Wallet> {
const seed = await Bip39.mnemonicToSeed(new EnglishMnemonic(mnemonic));
const { privkey } = Slip10.derivePath(Slip10Curve.Secp256k1, seed, hdPath);
const uncompressed = (await Secp256k1.makeKeypair(privkey)).pubkey;
return new Secp256k1OfflineWallet(privkey, Secp256k1.compressPubkey(uncompressed), prefix);
return new Secp256k1Wallet(privkey, Secp256k1.compressPubkey(uncompressed), prefix);
}
private readonly pubkey: Uint8Array;

View File

@ -53,4 +53,4 @@ export { findSequenceForSignedTx } from "./sequence";
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
export { FeeTable, SigningCosmosClient } from "./signingcosmosclient";
export { isStdTx, pubkeyType, CosmosSdkTx, PubKey, StdFee, StdSignature, StdTx } from "./types";
export { OfflineSigner, Secp256k1OfflineWallet, makeCosmoshubPath } from "./wallet";
export { OfflineSigner, Secp256k1Wallet, makeCosmoshubPath } from "./wallet";

View File

@ -21,7 +21,7 @@ export declare class SigningCosmosClient extends CosmosClient {
*
* @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API)
* @param senderAddress The address that will sign and send transactions using this instance
* @param signer A wallet provider which can provide signatures for transactions, potentially requiring user input.
* @param signer An implementation of OfflineSigner which can provide signatures for transactions, potentially requiring user input.
* @param customFees The fees that are paid for transactions
* @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns
*/

View File

@ -22,12 +22,12 @@ export interface OfflineSigner {
* with 0-based account index `a`.
*/
export declare function makeCosmoshubPath(a: number): readonly Slip10RawIndex[];
export declare class Secp256k1OfflineWallet implements OfflineSigner {
export declare class Secp256k1Wallet implements OfflineSigner {
static fromMnemonic(
mnemonic: string,
hdPath?: readonly Slip10RawIndex[],
prefix?: string,
): Promise<Secp256k1OfflineWallet>;
): Promise<Secp256k1Wallet>;
private readonly pubkey;
private readonly privkey;
private readonly prefix;

View File

@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/camelcase */
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm");
const { Secp256k1OfflineWallet } = require("@cosmjs/sdk38");
const { Secp256k1Wallet } = require("@cosmjs/sdk38");
const fs = require("fs");
const httpUrl = "http://localhost:1317";
@ -134,7 +134,7 @@ const initDataJade = {
};
async function main() {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.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/camelcase */
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm");
const { Secp256k1OfflineWallet } = require("@cosmjs/sdk38");
const { Secp256k1Wallet } = require("@cosmjs/sdk38");
const fs = require("fs");
const httpUrl = "http://localhost:1317";
@ -36,7 +36,7 @@ const luxury = {
};
async function main() {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const wasm = fs.readFileSync(__dirname + "/contracts/cw-nameservice.wasm");

View File

@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/camelcase */
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm");
const { coins, Secp256k1OfflineWallet } = require("@cosmjs/sdk38");
const { coins, Secp256k1Wallet } = require("@cosmjs/sdk38");
const fs = require("fs");
const httpUrl = "http://localhost:1317";
@ -38,7 +38,7 @@ const fees = {
};
async function main() {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(alice.mnemonic);
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet, fees);
const wasm = fs.readFileSync(__dirname + "/contracts/staking.wasm");