diff --git a/packages/amino/src/index.ts b/packages/amino/src/index.ts index 340fd598..c45fd5bb 100644 --- a/packages/amino/src/index.ts +++ b/packages/amino/src/index.ts @@ -20,3 +20,5 @@ export { } from "./pubkeys"; export { createMultisigThresholdPubkey } from "./multisig"; export { decodeSignature, encodeSecp256k1Signature, StdSignature } from "./signature"; +export { AminoMsg, Coin, makeSignDoc, serializeSignDoc, StdFee, StdSignDoc } from "./signdoc"; +export { AccountData, Algo, AminoSignResponse, OfflineAminoSigner } from "./signer"; diff --git a/packages/launchpad/src/encoding.spec.ts b/packages/amino/src/signdoc.spec.ts similarity index 75% rename from packages/launchpad/src/encoding.spec.ts rename to packages/amino/src/signdoc.spec.ts index e58bb654..e23b705e 100644 --- a/packages/launchpad/src/encoding.spec.ts +++ b/packages/amino/src/signdoc.spec.ts @@ -1,8 +1,14 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { coin, coins } from "./coins"; -import { makeSignDoc, sortedJsonStringify } from "./encoding"; -import { MsgDelegate, MsgSend } from "./msgs"; -import { faucet, launchpad, makeRandomAddress } from "./testutils.spec"; +import { Random } from "@cosmjs/crypto"; +import { Bech32 } from "@cosmjs/encoding"; + +import { AminoMsg, makeSignDoc, sortedJsonStringify } from "./signdoc"; + +function makeRandomAddress(): string { + return Bech32.encode("cosmos", Random.getBytes(20)); +} +const testAddress = "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6"; +const testValidatorAddress = "cosmosvaloper1yfkkk04ve8a0sugj4fe6q6zxuvmvza8r3arurr"; describe("encoding", () => { describe("sortedJsonStringify", () => { @@ -55,24 +61,24 @@ describe("encoding", () => { describe("makeSignDoc", () => { it("works", () => { const chainId = "testspace-12"; - const msg1: MsgDelegate = { + const msg1: AminoMsg = { type: "cosmos-sdk/MsgDelegate", value: { - delegator_address: faucet.address0, - validator_address: launchpad.validator.address, - amount: coin(1234, "ustake"), + delegator_address: testAddress, + validator_address: testValidatorAddress, + amount: { amount: "1234", denom: "ustake" }, }, }; - const msg2: MsgSend = { + const msg2: AminoMsg = { type: "cosmos-sdk/MsgSend", value: { - from_address: faucet.address0, + from_address: testAddress, to_address: makeRandomAddress(), - amount: coins(1234567, "ucosm"), + amount: [{ amount: "1234567", denom: "ucosm" }], }, }; const fee = { - amount: coins(2000, "ucosm"), + amount: [{ amount: "2000", denom: "ucosm" }], gas: "180000", // 180k }; const memo = "Use your power wisely"; @@ -92,24 +98,24 @@ describe("encoding", () => { it("works with undefined memo", () => { const chainId = "testspace-12"; - const msg1: MsgDelegate = { + const msg1: AminoMsg = { type: "cosmos-sdk/MsgDelegate", value: { - delegator_address: faucet.address0, - validator_address: launchpad.validator.address, - amount: coin(1234, "ustake"), + delegator_address: testAddress, + validator_address: testValidatorAddress, + amount: { amount: "1234", denom: "ustake" }, }, }; - const msg2: MsgSend = { + const msg2: AminoMsg = { type: "cosmos-sdk/MsgSend", value: { - from_address: faucet.address0, + from_address: testAddress, to_address: makeRandomAddress(), - amount: coins(1234567, "ucosm"), + amount: [{ amount: "1234567", denom: "ucosm" }], }, }; const fee = { - amount: coins(2000, "ucosm"), + amount: [{ amount: "2000", denom: "ucosm" }], gas: "180000", // 180k }; const accountNumber = 15; diff --git a/packages/launchpad/src/encoding.ts b/packages/amino/src/signdoc.ts similarity index 83% rename from packages/launchpad/src/encoding.ts rename to packages/amino/src/signdoc.ts index 5d7b457d..bfd75dce 100644 --- a/packages/launchpad/src/encoding.ts +++ b/packages/amino/src/signdoc.ts @@ -2,8 +2,34 @@ import { toUtf8 } from "@cosmjs/encoding"; import { Uint53 } from "@cosmjs/math"; -import { StdFee } from "./fee"; -import { Msg } from "./msgs"; +export interface AminoMsg { + readonly type: string; + readonly value: any; +} + +export interface Coin { + readonly denom: string; + readonly amount: string; +} + +export interface StdFee { + readonly amount: readonly Coin[]; + readonly gas: string; +} + +/** + * The document to be signed + * + * @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdsigndoc + */ +export interface StdSignDoc { + readonly chain_id: string; + readonly account_number: string; + readonly sequence: string; + readonly fee: StdFee; + readonly msgs: readonly AminoMsg[]; + readonly memo: string; +} function sortedObject(obj: any): any { if (typeof obj !== "object" || obj === null) { @@ -27,22 +53,8 @@ export function sortedJsonStringify(obj: any): string { return JSON.stringify(sortedObject(obj)); } -/** - * The document to be signed - * - * @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdsigndoc - */ -export interface StdSignDoc { - readonly chain_id: string; - readonly account_number: string; - readonly sequence: string; - readonly fee: StdFee; - readonly msgs: readonly Msg[]; - readonly memo: string; -} - export function makeSignDoc( - msgs: readonly Msg[], + msgs: readonly AminoMsg[], fee: StdFee, chainId: string, memo: string | undefined, diff --git a/packages/launchpad/src/signer.ts b/packages/amino/src/signer.ts similarity index 90% rename from packages/launchpad/src/signer.ts rename to packages/amino/src/signer.ts index a2f25eb1..89de5a27 100644 --- a/packages/launchpad/src/signer.ts +++ b/packages/amino/src/signer.ts @@ -1,6 +1,5 @@ -import { StdSignature } from "@cosmjs/amino"; - -import { StdSignDoc } from "./encoding"; +import { StdSignature } from "./signature"; +import { StdSignDoc } from "./signdoc"; export type Algo = "secp256k1" | "ed25519" | "sr25519"; @@ -20,7 +19,7 @@ export interface AminoSignResponse { readonly signature: StdSignature; } -export interface OfflineSigner { +export interface OfflineAminoSigner { /** * Get AccountData array from wallet. Rejects if not enabled. */ diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index 78cb1dd4..16da8341 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { encodeSecp256k1Pubkey } from "@cosmjs/amino"; +import { encodeSecp256k1Pubkey, makeSignDoc as makeSignDocAmino } from "@cosmjs/amino"; import { ChangeAdminResult, CosmWasmFeeTable, @@ -13,7 +13,7 @@ import { } from "@cosmjs/cosmwasm-launchpad"; import { sha256 } from "@cosmjs/crypto"; import { fromBase64, toHex, toUtf8 } from "@cosmjs/encoding"; -import { CosmosFeeTable, makeSignDoc as makeSignDocAmino } from "@cosmjs/launchpad"; +import { CosmosFeeTable } from "@cosmjs/launchpad"; import { Int53, Uint53 } from "@cosmjs/math"; import { EncodeObject, diff --git a/packages/cosmwasm-stargate/src/testutils.spec.ts b/packages/cosmwasm-stargate/src/testutils.spec.ts index d89ff171..1643309f 100644 --- a/packages/cosmwasm-stargate/src/testutils.spec.ts +++ b/packages/cosmwasm-stargate/src/testutils.spec.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { AminoSignResponse, StdSignDoc } from "@cosmjs/amino"; import { Bip39, EnglishMnemonic, Random, Secp256k1, Slip10, Slip10Curve } from "@cosmjs/crypto"; import { Bech32, fromBase64 } from "@cosmjs/encoding"; -import { AminoSignResponse, Secp256k1HdWallet, StdSignDoc } from "@cosmjs/launchpad"; +import { Secp256k1HdWallet } from "@cosmjs/launchpad"; import { DirectSecp256k1HdWallet, DirectSignResponse, diff --git a/packages/launchpad/src/coins.ts b/packages/launchpad/src/coins.ts index 6f7b5321..e62617c8 100644 --- a/packages/launchpad/src/coins.ts +++ b/packages/launchpad/src/coins.ts @@ -1,10 +1,6 @@ +import { Coin } from "@cosmjs/amino"; import { Uint53, Uint64 } from "@cosmjs/math"; -export interface Coin { - readonly denom: string; - readonly amount: string; -} - /** Creates a coin */ export function coin(amount: number, denom: string): Coin { return { amount: new Uint53(amount).toString(), denom: denom }; diff --git a/packages/launchpad/src/cosmosclient.searchtx.spec.ts b/packages/launchpad/src/cosmosclient.searchtx.spec.ts index c127c166..dc643b12 100644 --- a/packages/launchpad/src/cosmosclient.searchtx.spec.ts +++ b/packages/launchpad/src/cosmosclient.searchtx.spec.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { makeSignDoc } from "@cosmjs/amino"; import { assert, sleep } from "@cosmjs/utils"; import { coins } from "./coins"; import { CosmosClient, isBroadcastTxFailure } from "./cosmosclient"; -import { makeSignDoc } from "./encoding"; import { LcdClient } from "./lcdapi"; import { isMsgSend, MsgSend } from "./msgs"; import { Secp256k1HdWallet } from "./secp256k1hdwallet"; diff --git a/packages/launchpad/src/cosmosclient.spec.ts b/packages/launchpad/src/cosmosclient.spec.ts index 768b27b6..db00aa23 100644 --- a/packages/launchpad/src/cosmosclient.spec.ts +++ b/packages/launchpad/src/cosmosclient.spec.ts @@ -1,10 +1,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { makeSignDoc, StdFee } from "@cosmjs/amino"; import { assert, sleep } from "@cosmjs/utils"; import { ReadonlyDate } from "readonly-date"; import { assertIsBroadcastTxSuccess, CosmosClient, PrivateCosmosClient } from "./cosmosclient"; -import { makeSignDoc } from "./encoding"; -import { StdFee } from "./fee"; import { findAttribute } from "./logs"; import { MsgSend } from "./msgs"; import { Secp256k1HdWallet } from "./secp256k1hdwallet"; diff --git a/packages/launchpad/src/cosmosclient.ts b/packages/launchpad/src/cosmosclient.ts index 9bb2764e..25fcce92 100644 --- a/packages/launchpad/src/cosmosclient.ts +++ b/packages/launchpad/src/cosmosclient.ts @@ -1,9 +1,8 @@ -import { Pubkey } from "@cosmjs/amino"; +import { Coin, Pubkey } from "@cosmjs/amino"; import { sha256 } from "@cosmjs/crypto"; import { fromBase64, fromHex, toHex } from "@cosmjs/encoding"; import { Uint53 } from "@cosmjs/math"; -import { Coin } from "./coins"; import { AuthExtension, BroadcastMode, diff --git a/packages/launchpad/src/fee.ts b/packages/launchpad/src/fee.ts index 027d7554..1703792f 100644 --- a/packages/launchpad/src/fee.ts +++ b/packages/launchpad/src/fee.ts @@ -1,11 +1,7 @@ +import { StdFee } from "@cosmjs/amino"; import { Decimal, Uint53 } from "@cosmjs/math"; -import { Coin, coins } from "./coins"; - -export interface StdFee { - readonly amount: readonly Coin[]; - readonly gas: string; -} +import { coins } from "./coins"; export type FeeTable = Record; diff --git a/packages/launchpad/src/index.ts b/packages/launchpad/src/index.ts index 04d91fb8..7d6219fb 100644 --- a/packages/launchpad/src/index.ts +++ b/packages/launchpad/src/index.ts @@ -1,5 +1,14 @@ // Re-exports for backwards compatibility export { + AccountData, + Algo, + AminoMsg as Msg, + AminoSignResponse, + Coin, + OfflineAminoSigner as OfflineSigner, + StdFee, + StdSignDoc, + StdSignature, decodeAminoPubkey, decodeBech32Pubkey, decodeSignature, @@ -7,9 +16,10 @@ export { encodeBech32Pubkey, encodeSecp256k1Pubkey, encodeSecp256k1Signature, + makeSignDoc, pubkeyToAddress, pubkeyType, - StdSignature, + serializeSignDoc, } from "@cosmjs/amino"; import { SinglePubkey } from "@cosmjs/amino"; /** @deprecated PubKey is deprecated. Use `SinglePubkey` or the more general `Pubkey` from `@cosmjs/amino`. */ @@ -18,8 +28,7 @@ export type PubKey = SinglePubkey; import * as logs from "./logs"; export { logs }; -export { Coin, coin, coins, parseCoins } from "./coins"; - +export { coin, coins, parseCoins } from "./coins"; export { Account, assertIsBroadcastTxSuccess, @@ -42,8 +51,7 @@ export { isSearchBySentFromOrToQuery, isSearchByTagsQuery, } from "./cosmosclient"; -export { makeSignDoc, serializeSignDoc, StdSignDoc } from "./encoding"; -export { buildFeeTable, FeeTable, GasLimits, GasPrice, StdFee } from "./fee"; +export { buildFeeTable, FeeTable, GasLimits, GasPrice } from "./fee"; export { AuthAccountsResponse, AuthExtension, @@ -127,7 +135,6 @@ export { isMsgUndelegate, isMsgWithdrawDelegatorReward, isMsgWithdrawValidatorCommission, - Msg, MsgBeginRedelegate, MsgCreateValidator, MsgDelegate, @@ -142,7 +149,6 @@ export { } from "./msgs"; export { makeCosmoshubPath } from "./paths"; export { findSequenceForSignedTx } from "./sequence"; -export { AccountData, Algo, AminoSignResponse, OfflineSigner } from "./signer"; export { CosmosFeeTable, SigningCosmosClient } from "./signingcosmosclient"; export { isStdTx, isWrappedStdTx, makeStdTx, CosmosSdkTx, StdTx, WrappedStdTx, WrappedTx } from "./tx"; export { executeKdf, KdfConfiguration } from "./wallet"; diff --git a/packages/launchpad/src/lcdapi/auth.ts b/packages/launchpad/src/lcdapi/auth.ts index 947ff1da..bea6e46b 100644 --- a/packages/launchpad/src/lcdapi/auth.ts +++ b/packages/launchpad/src/lcdapi/auth.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { Pubkey } from "@cosmjs/amino"; +import { Coin, Pubkey } from "@cosmjs/amino"; -import { Coin } from "../coins"; import { LcdClient } from "./lcdclient"; /** diff --git a/packages/launchpad/src/lcdapi/bank.ts b/packages/launchpad/src/lcdapi/bank.ts index f8b7d14e..552db8e8 100644 --- a/packages/launchpad/src/lcdapi/bank.ts +++ b/packages/launchpad/src/lcdapi/bank.ts @@ -1,4 +1,5 @@ -import { Coin } from "../coins"; +import { Coin } from "@cosmjs/amino"; + import { LcdClient } from "./lcdclient"; export interface BankBalancesResponse { diff --git a/packages/launchpad/src/lcdapi/distribution.spec.ts b/packages/launchpad/src/lcdapi/distribution.spec.ts index 039417b5..667219ad 100644 --- a/packages/launchpad/src/lcdapi/distribution.spec.ts +++ b/packages/launchpad/src/lcdapi/distribution.spec.ts @@ -1,10 +1,10 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { makeSignDoc } from "@cosmjs/amino"; import { Bech32 } from "@cosmjs/encoding"; import { sleep } from "@cosmjs/utils"; import { coin, coins } from "../coins"; import { assertIsBroadcastTxSuccess } from "../cosmosclient"; -import { makeSignDoc } from "../encoding"; import { MsgDelegate } from "../msgs"; import { Secp256k1HdWallet } from "../secp256k1hdwallet"; import { SigningCosmosClient } from "../signingcosmosclient"; diff --git a/packages/launchpad/src/lcdapi/distribution.ts b/packages/launchpad/src/lcdapi/distribution.ts index 36efd792..209e85c0 100644 --- a/packages/launchpad/src/lcdapi/distribution.ts +++ b/packages/launchpad/src/lcdapi/distribution.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { Coin } from "../coins"; +import { Coin } from "@cosmjs/amino"; + import { LcdClient } from "./lcdclient"; export interface RewardContainer { diff --git a/packages/launchpad/src/lcdapi/gov.spec.ts b/packages/launchpad/src/lcdapi/gov.spec.ts index bc28eade..f907c888 100644 --- a/packages/launchpad/src/lcdapi/gov.spec.ts +++ b/packages/launchpad/src/lcdapi/gov.spec.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { makeSignDoc } from "@cosmjs/amino"; import { sleep } from "@cosmjs/utils"; import { coins } from "../coins"; import { assertIsBroadcastTxSuccess } from "../cosmosclient"; -import { makeSignDoc } from "../encoding"; import { Secp256k1HdWallet } from "../secp256k1hdwallet"; import { SigningCosmosClient } from "../signingcosmosclient"; import { diff --git a/packages/launchpad/src/lcdapi/gov.ts b/packages/launchpad/src/lcdapi/gov.ts index f7b46635..7c05c0c3 100644 --- a/packages/launchpad/src/lcdapi/gov.ts +++ b/packages/launchpad/src/lcdapi/gov.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { Coin } from "../coins"; +import { Coin } from "@cosmjs/amino"; + import { LcdClient } from "./lcdclient"; export enum GovParametersType { diff --git a/packages/launchpad/src/lcdapi/lcdclient.spec.ts b/packages/launchpad/src/lcdapi/lcdclient.spec.ts index ff7495c7..d10cc24d 100644 --- a/packages/launchpad/src/lcdapi/lcdclient.spec.ts +++ b/packages/launchpad/src/lcdapi/lcdclient.spec.ts @@ -1,10 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { Coin, makeSignDoc, StdFee } from "@cosmjs/amino"; import { assert, sleep } from "@cosmjs/utils"; -import { Coin } from "../coins"; import { isBroadcastTxFailure } from "../cosmosclient"; -import { makeSignDoc } from "../encoding"; -import { StdFee } from "../fee"; import { parseLogs } from "../logs"; import { MsgSend } from "../msgs"; import { makeCosmoshubPath } from "../paths"; diff --git a/packages/launchpad/src/lcdapi/staking.spec.ts b/packages/launchpad/src/lcdapi/staking.spec.ts index cd8c3d0c..6ec3ab1f 100644 --- a/packages/launchpad/src/lcdapi/staking.spec.ts +++ b/packages/launchpad/src/lcdapi/staking.spec.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { makeSignDoc } from "@cosmjs/amino"; import { assert, sleep } from "@cosmjs/utils"; import { coin, coins } from "../coins"; import { assertIsBroadcastTxSuccess } from "../cosmosclient"; -import { makeSignDoc } from "../encoding"; import { MsgDelegate, MsgUndelegate } from "../msgs"; import { Secp256k1HdWallet } from "../secp256k1hdwallet"; import { SigningCosmosClient } from "../signingcosmosclient"; diff --git a/packages/launchpad/src/lcdapi/staking.ts b/packages/launchpad/src/lcdapi/staking.ts index 604e7047..219e803a 100644 --- a/packages/launchpad/src/lcdapi/staking.ts +++ b/packages/launchpad/src/lcdapi/staking.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { Coin } from "../coins"; +import { Coin } from "@cosmjs/amino"; + import { BlockHeader, SearchTxsResponse } from "./base"; import { LcdClient } from "./lcdclient"; diff --git a/packages/launchpad/src/lcdapi/supply.ts b/packages/launchpad/src/lcdapi/supply.ts index 7ddfc883..302a1c00 100644 --- a/packages/launchpad/src/lcdapi/supply.ts +++ b/packages/launchpad/src/lcdapi/supply.ts @@ -1,4 +1,5 @@ -import { Coin } from "../coins"; +import { Coin } from "@cosmjs/amino"; + import { LcdApiArray, LcdClient } from "./lcdclient"; export interface TotalSupplyAllResponse { diff --git a/packages/launchpad/src/msgs.ts b/packages/launchpad/src/msgs.ts index 3a627e74..f1a4a1f3 100644 --- a/packages/launchpad/src/msgs.ts +++ b/packages/launchpad/src/msgs.ts @@ -1,17 +1,12 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { Coin } from "./coins"; - -export interface Msg { - readonly type: string; - readonly value: any; -} +import { AminoMsg, Coin } from "@cosmjs/amino"; // auth (no messages) - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/auth/auth.proto // bank - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/bank/bank.proto /** A high level transaction of the coin module */ -export interface MsgSend extends Msg { +export interface MsgSend extends AminoMsg { readonly type: "cosmos-sdk/MsgSend"; readonly value: { /** Bech32 account address */ @@ -22,7 +17,7 @@ export interface MsgSend extends Msg { }; } -export function isMsgSend(msg: Msg): msg is MsgSend { +export function isMsgSend(msg: AminoMsg): msg is MsgSend { return (msg as MsgSend).type === "cosmos-sdk/MsgSend"; } @@ -39,7 +34,7 @@ interface Output { } /** A high level transaction of the coin module */ -export interface MsgMultiSend extends Msg { +export interface MsgMultiSend extends AminoMsg { readonly type: "cosmos-sdk/MsgMultiSend"; readonly value: { readonly inputs: readonly Input[]; @@ -47,14 +42,14 @@ export interface MsgMultiSend extends Msg { }; } -export function isMsgMultiSend(msg: Msg): msg is MsgMultiSend { +export function isMsgMultiSend(msg: AminoMsg): msg is MsgMultiSend { return (msg as MsgMultiSend).type === "cosmos-sdk/MsgMultiSend"; } // crisis - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/crisis/crisis.proto /** Verifies a particular invariance */ -export interface MsgVerifyInvariant extends Msg { +export interface MsgVerifyInvariant extends AminoMsg { readonly type: "cosmos-sdk/MsgVerifyInvariant"; readonly value: { /** Bech32 account address */ @@ -64,14 +59,14 @@ export interface MsgVerifyInvariant extends Msg { }; } -export function isMsgVerifyInvariant(msg: Msg): msg is MsgVerifyInvariant { +export function isMsgVerifyInvariant(msg: AminoMsg): msg is MsgVerifyInvariant { return (msg as MsgVerifyInvariant).type === "cosmos-sdk/MsgVerifyInvariant"; } // distribution - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/distribution/distribution.proto /** Changes the withdraw address for a delegator (or validator self-delegation) */ -export interface MsgSetWithdrawAddress extends Msg { +export interface MsgSetWithdrawAddress extends AminoMsg { // NOTE: Type string and names diverge here! readonly type: "cosmos-sdk/MsgModifyWithdrawAddress"; readonly value: { @@ -82,13 +77,13 @@ export interface MsgSetWithdrawAddress extends Msg { }; } -export function isMsgSetWithdrawAddress(msg: Msg): msg is MsgSetWithdrawAddress { +export function isMsgSetWithdrawAddress(msg: AminoMsg): msg is MsgSetWithdrawAddress { // NOTE: Type string and names diverge here! return (msg as MsgSetWithdrawAddress).type === "cosmos-sdk/MsgModifyWithdrawAddress"; } /** Message for delegation withdraw from a single validator */ -export interface MsgWithdrawDelegatorReward extends Msg { +export interface MsgWithdrawDelegatorReward extends AminoMsg { // NOTE: Type string and names diverge here! readonly type: "cosmos-sdk/MsgWithdrawDelegationReward"; readonly value: { @@ -99,13 +94,13 @@ export interface MsgWithdrawDelegatorReward extends Msg { }; } -export function isMsgWithdrawDelegatorReward(msg: Msg): msg is MsgWithdrawDelegatorReward { +export function isMsgWithdrawDelegatorReward(msg: AminoMsg): msg is MsgWithdrawDelegatorReward { // NOTE: Type string and names diverge here! return (msg as MsgWithdrawDelegatorReward).type === "cosmos-sdk/MsgWithdrawDelegationReward"; } /** Message for validator withdraw */ -export interface MsgWithdrawValidatorCommission extends Msg { +export interface MsgWithdrawValidatorCommission extends AminoMsg { readonly type: "cosmos-sdk/MsgWithdrawValidatorCommission"; readonly value: { /** Bech32 account address */ @@ -113,12 +108,12 @@ export interface MsgWithdrawValidatorCommission extends Msg { }; } -export function isMsgWithdrawValidatorCommission(msg: Msg): msg is MsgWithdrawValidatorCommission { +export function isMsgWithdrawValidatorCommission(msg: AminoMsg): msg is MsgWithdrawValidatorCommission { return (msg as MsgWithdrawValidatorCommission).type === "cosmos-sdk/MsgWithdrawValidatorCommission"; } /** Allows an account to directly fund the community pool. */ -export interface MsgFundCommunityPool extends Msg { +export interface MsgFundCommunityPool extends AminoMsg { readonly type: "cosmos-sdk/MsgFundCommunityPool"; readonly value: { readonly amount: readonly Coin[]; @@ -127,7 +122,7 @@ export interface MsgFundCommunityPool extends Msg { }; } -export function isMsgFundCommunityPool(msg: Msg): msg is MsgFundCommunityPool { +export function isMsgFundCommunityPool(msg: AminoMsg): msg is MsgFundCommunityPool { return (msg as MsgFundCommunityPool).type === "cosmos-sdk/MsgFundCommunityPool"; } @@ -139,7 +134,7 @@ interface Any { } /** Supports submitting arbitrary evidence */ -export interface MsgSubmitEvidence extends Msg { +export interface MsgSubmitEvidence extends AminoMsg { readonly type: "cosmos-sdk/MsgSubmitEvidence"; readonly value: { /** Bech32 account address */ @@ -148,14 +143,14 @@ export interface MsgSubmitEvidence extends Msg { }; } -export function isMsgSubmitEvidence(msg: Msg): msg is MsgSubmitEvidence { +export function isMsgSubmitEvidence(msg: AminoMsg): msg is MsgSubmitEvidence { return (msg as MsgSubmitEvidence).type === "cosmos-sdk/MsgSubmitEvidence"; } // gov - https://github.com/cosmos/cosmos-sdk/blob/efa73c7edb31a7bd65786501da213b294f89267a/proto/cosmos/gov/gov.proto /** Supports submitting arbitrary proposal content. */ -export interface MsgSubmitProposal extends Msg { +export interface MsgSubmitProposal extends AminoMsg { readonly type: "cosmos-sdk/MsgSubmitProposal"; readonly value: { readonly content: Any; @@ -165,7 +160,7 @@ export interface MsgSubmitProposal extends Msg { }; } -export function isMsgSubmitProposal(msg: Msg): msg is MsgSubmitProposal { +export function isMsgSubmitProposal(msg: AminoMsg): msg is MsgSubmitProposal { return (msg as MsgSubmitProposal).type === "cosmos-sdk/MsgSubmitProposal"; } @@ -178,7 +173,7 @@ enum VoteOption { } /** Casts a vote */ -export interface MsgVote extends Msg { +export interface MsgVote extends AminoMsg { readonly type: "cosmos-sdk/MsgVote"; readonly value: { readonly proposal_id: number; @@ -188,12 +183,12 @@ export interface MsgVote extends Msg { }; } -export function isMsgVote(msg: Msg): msg is MsgVote { +export function isMsgVote(msg: AminoMsg): msg is MsgVote { return (msg as MsgVote).type === "cosmos-sdk/MsgVote"; } /** Submits a deposit to an existing proposal */ -export interface MsgDeposit extends Msg { +export interface MsgDeposit extends AminoMsg { readonly type: "cosmos-sdk/MsgDeposit"; readonly value: { readonly proposal_id: number; @@ -203,7 +198,7 @@ export interface MsgDeposit extends Msg { }; } -export function isMsgDeposit(msg: Msg): msg is MsgDeposit { +export function isMsgDeposit(msg: AminoMsg): msg is MsgDeposit { return (msg as MsgDeposit).type === "cosmos-sdk/MsgDeposit"; } @@ -216,7 +211,7 @@ export function isMsgDeposit(msg: Msg): msg is MsgDeposit { // slashing - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/slashing/slashing.proto /** Unjails a jailed validator */ -export interface MsgUnjail extends Msg { +export interface MsgUnjail extends AminoMsg { readonly type: "cosmos-sdk/MsgUnjail"; readonly value: { /** Bech32 account address */ @@ -224,7 +219,7 @@ export interface MsgUnjail extends Msg { }; } -export function isMsgUnjail(msg: Msg): msg is MsgUnjail { +export function isMsgUnjail(msg: AminoMsg): msg is MsgUnjail { return (msg as MsgUnjail).type === "cosmos-sdk/MsgUnjail"; } @@ -247,7 +242,7 @@ interface Description { } /** Creates a new validator. */ -export interface MsgCreateValidator extends Msg { +export interface MsgCreateValidator extends AminoMsg { readonly type: "cosmos-sdk/MsgCreateValidator"; readonly value: { readonly description: Description; @@ -263,12 +258,12 @@ export interface MsgCreateValidator extends Msg { }; } -export function isMsgCreateValidator(msg: Msg): msg is MsgCreateValidator { +export function isMsgCreateValidator(msg: AminoMsg): msg is MsgCreateValidator { return (msg as MsgCreateValidator).type === "cosmos-sdk/MsgCreateValidator"; } /** Edits an existing validator. */ -export interface MsgEditValidator extends Msg { +export interface MsgEditValidator extends AminoMsg { readonly type: "cosmos-sdk/MsgEditValidator"; readonly value: { readonly description: Description; @@ -279,7 +274,7 @@ export interface MsgEditValidator extends Msg { }; } -export function isMsgEditValidator(msg: Msg): msg is MsgEditValidator { +export function isMsgEditValidator(msg: AminoMsg): msg is MsgEditValidator { return (msg as MsgEditValidator).type === "cosmos-sdk/MsgEditValidator"; } @@ -288,7 +283,7 @@ export function isMsgEditValidator(msg: Msg): msg is MsgEditValidator { * * @see https://docs.cosmos.network/master/modules/staking/03_messages.html#msgdelegate */ -export interface MsgDelegate extends Msg { +export interface MsgDelegate extends AminoMsg { readonly type: "cosmos-sdk/MsgDelegate"; readonly value: { /** Bech32 encoded delegator address */ @@ -299,12 +294,12 @@ export interface MsgDelegate extends Msg { }; } -export function isMsgDelegate(msg: Msg): msg is MsgDelegate { +export function isMsgDelegate(msg: AminoMsg): msg is MsgDelegate { return (msg as MsgDelegate).type === "cosmos-sdk/MsgDelegate"; } /** Performs a redelegation from a delegate and source validator to a destination validator */ -export interface MsgBeginRedelegate extends Msg { +export interface MsgBeginRedelegate extends AminoMsg { readonly type: "cosmos-sdk/MsgBeginRedelegate"; readonly value: { /** Bech32 encoded delegator address */ @@ -317,12 +312,12 @@ export interface MsgBeginRedelegate extends Msg { }; } -export function isMsgBeginRedelegate(msg: Msg): msg is MsgBeginRedelegate { +export function isMsgBeginRedelegate(msg: AminoMsg): msg is MsgBeginRedelegate { return (msg as MsgBeginRedelegate).type === "cosmos-sdk/MsgBeginRedelegate"; } /** Performs an undelegation from a delegate and a validator */ -export interface MsgUndelegate extends Msg { +export interface MsgUndelegate extends AminoMsg { readonly type: "cosmos-sdk/MsgUndelegate"; readonly value: { /** Bech32 encoded delegator address */ @@ -333,7 +328,7 @@ export interface MsgUndelegate extends Msg { }; } -export function isMsgUndelegate(msg: Msg): msg is MsgUndelegate { +export function isMsgUndelegate(msg: AminoMsg): msg is MsgUndelegate { return (msg as MsgUndelegate).type === "cosmos-sdk/MsgUndelegate"; } diff --git a/packages/launchpad/src/secp256k1hdwallet.spec.ts b/packages/launchpad/src/secp256k1hdwallet.spec.ts index 90213da1..e64e5aaf 100644 --- a/packages/launchpad/src/secp256k1hdwallet.spec.ts +++ b/packages/launchpad/src/secp256k1hdwallet.spec.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { serializeSignDoc, StdSignDoc } from "@cosmjs/amino"; import { Secp256k1, Secp256k1Signature, sha256 } from "@cosmjs/crypto"; import { fromBase64, fromHex } from "@cosmjs/encoding"; -import { serializeSignDoc, StdSignDoc } from "./encoding"; import { extractKdfConfiguration, Secp256k1HdWallet } from "./secp256k1hdwallet"; import { base64Matcher } from "./testutils.spec"; import { executeKdf, KdfConfiguration } from "./wallet"; diff --git a/packages/launchpad/src/secp256k1hdwallet.ts b/packages/launchpad/src/secp256k1hdwallet.ts index 38e29a43..956ad6aa 100644 --- a/packages/launchpad/src/secp256k1hdwallet.ts +++ b/packages/launchpad/src/secp256k1hdwallet.ts @@ -1,4 +1,12 @@ -import { encodeSecp256k1Signature, rawSecp256k1PubkeyToRawAddress } from "@cosmjs/amino"; +import { + AccountData, + AminoSignResponse, + encodeSecp256k1Signature, + OfflineAminoSigner, + rawSecp256k1PubkeyToRawAddress, + serializeSignDoc, + StdSignDoc, +} from "@cosmjs/amino"; import { Bip39, EnglishMnemonic, @@ -14,9 +22,7 @@ import { import { Bech32, fromBase64, fromUtf8, toBase64, toUtf8 } from "@cosmjs/encoding"; import { assert, isNonNullObject } from "@cosmjs/utils"; -import { serializeSignDoc, StdSignDoc } from "./encoding"; import { makeCosmoshubPath } from "./paths"; -import { AccountData, AminoSignResponse, OfflineSigner } from "./signer"; import { decrypt, encrypt, @@ -106,7 +112,7 @@ interface DerivationInfo { readonly prefix: string; } -export class Secp256k1HdWallet implements OfflineSigner { +export class Secp256k1HdWallet implements OfflineAminoSigner { /** * Restores a wallet from the given BIP39 mnemonic. * diff --git a/packages/launchpad/src/secp256k1wallet.spec.ts b/packages/launchpad/src/secp256k1wallet.spec.ts index c03fd3c6..57f20687 100644 --- a/packages/launchpad/src/secp256k1wallet.spec.ts +++ b/packages/launchpad/src/secp256k1wallet.spec.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { serializeSignDoc, StdSignDoc } from "@cosmjs/amino"; import { Secp256k1, Secp256k1Signature, Sha256 } from "@cosmjs/crypto"; import { fromBase64, fromHex } from "@cosmjs/encoding"; -import { serializeSignDoc, StdSignDoc } from "./encoding"; import { Secp256k1Wallet } from "./secp256k1wallet"; describe("Secp256k1Wallet", () => { diff --git a/packages/launchpad/src/secp256k1wallet.ts b/packages/launchpad/src/secp256k1wallet.ts index 247ba3d1..3280189d 100644 --- a/packages/launchpad/src/secp256k1wallet.ts +++ b/packages/launchpad/src/secp256k1wallet.ts @@ -1,16 +1,21 @@ -import { encodeSecp256k1Signature, rawSecp256k1PubkeyToRawAddress } from "@cosmjs/amino"; +import { + AccountData, + AminoSignResponse, + encodeSecp256k1Signature, + OfflineAminoSigner, + rawSecp256k1PubkeyToRawAddress, + serializeSignDoc, + StdSignDoc, +} from "@cosmjs/amino"; import { Secp256k1, Sha256 } from "@cosmjs/crypto"; import { Bech32 } from "@cosmjs/encoding"; -import { serializeSignDoc, StdSignDoc } from "./encoding"; -import { AccountData, AminoSignResponse, OfflineSigner } from "./signer"; - /** * A wallet that holds a single secp256k1 keypair. * * If you want to work with BIP39 mnemonics and multiple accounts, use Secp256k1HdWallet. */ -export class Secp256k1Wallet implements OfflineSigner { +export class Secp256k1Wallet implements OfflineAminoSigner { /** * Creates a Secp256k1Wallet from the given private key * diff --git a/packages/launchpad/src/sequence.ts b/packages/launchpad/src/sequence.ts index c833107a..c413f1c4 100644 --- a/packages/launchpad/src/sequence.ts +++ b/packages/launchpad/src/sequence.ts @@ -1,7 +1,6 @@ -import { decodeSignature } from "@cosmjs/amino"; +import { decodeSignature, makeSignDoc, serializeSignDoc } from "@cosmjs/amino"; import { Secp256k1, Secp256k1Signature, sha256 } from "@cosmjs/crypto"; -import { makeSignDoc, serializeSignDoc } from "./encoding"; import { WrappedStdTx } from "./tx"; /** diff --git a/packages/launchpad/src/signingcosmosclient.spec.ts b/packages/launchpad/src/signingcosmosclient.spec.ts index 307243a9..12fe1893 100644 --- a/packages/launchpad/src/signingcosmosclient.spec.ts +++ b/packages/launchpad/src/signingcosmosclient.spec.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { Coin } from "@cosmjs/amino"; import { assert } from "@cosmjs/utils"; -import { Coin, coin, coins } from "./coins"; +import { coin, coins } from "./coins"; import { assertIsBroadcastTxSuccess, PrivateCosmosClient } from "./cosmosclient"; import { GasPrice } from "./fee"; import { MsgDelegate, MsgSend } from "./msgs"; diff --git a/packages/launchpad/src/signingcosmosclient.ts b/packages/launchpad/src/signingcosmosclient.ts index 057efb4e..f97e7da2 100644 --- a/packages/launchpad/src/signingcosmosclient.ts +++ b/packages/launchpad/src/signingcosmosclient.ts @@ -1,13 +1,11 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { AminoMsg, Coin, makeSignDoc, OfflineAminoSigner, StdFee } from "@cosmjs/amino"; import equals from "fast-deep-equal"; -import { Coin } from "./coins"; import { Account, BroadcastTxResult, CosmosClient, GetSequenceResult } from "./cosmosclient"; -import { makeSignDoc } from "./encoding"; -import { buildFeeTable, FeeTable, GasLimits, GasPrice, StdFee } from "./fee"; +import { buildFeeTable, FeeTable, GasLimits, GasPrice } from "./fee"; import { BroadcastMode } from "./lcdapi"; -import { Msg, MsgSend } from "./msgs"; -import { OfflineSigner } from "./signer"; +import { MsgSend } from "./msgs"; import { makeStdTx, StdTx } from "./tx"; /** @@ -29,7 +27,7 @@ export class SigningCosmosClient extends CosmosClient { public readonly fees: CosmosFeeTable; public readonly signerAddress: string; - private readonly signer: OfflineSigner; + private readonly signer: OfflineAminoSigner; /** * Creates a new client with signing capability to interact with a Cosmos SDK blockchain. This is the bigger brother of CosmosClient. @@ -39,7 +37,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 signerAddress The address that will sign transactions using this instance. The `signer` must be able to sign with this address. - * @param signer An implementation of OfflineSigner which can provide signatures for transactions, potentially requiring user input. + * @param signer An implementation of OfflineAminoSigner which can provide signatures for transactions, potentially requiring user input. * @param gasPrice The price paid per unit of gas * @param gasLimits Custom overrides for gas limits related to specific transaction types * @param broadcastMode Defines at which point of the transaction processing the broadcastTx method returns @@ -47,7 +45,7 @@ export class SigningCosmosClient extends CosmosClient { public constructor( apiUrl: string, signerAddress: string, - signer: OfflineSigner, + signer: OfflineAminoSigner, gasPrice: GasPrice = defaultGasPrice, gasLimits: Partial> = {}, broadcastMode = BroadcastMode.Block, @@ -87,7 +85,11 @@ export class SigningCosmosClient extends CosmosClient { * Gets account number and sequence from the API, creates a sign doc, * creates a single signature, assembles the signed transaction and broadcasts it. */ - public async signAndBroadcast(msgs: readonly Msg[], fee: StdFee, memo = ""): Promise { + public async signAndBroadcast( + msgs: readonly AminoMsg[], + fee: StdFee, + memo = "", + ): Promise { const signedTx = await this.sign(msgs, fee, memo); return this.broadcastTx(signedTx); } @@ -96,7 +98,7 @@ export class SigningCosmosClient extends CosmosClient { * Gets account number and sequence from the API, creates a sign doc, * creates a single signature and assembles the signed transaction. */ - public async sign(msgs: readonly Msg[], fee: StdFee, memo = ""): Promise { + public async sign(msgs: readonly AminoMsg[], fee: StdFee, memo = ""): Promise { const { accountNumber, sequence } = await this.getSequence(); const chainId = await this.getChainId(); const signDoc = makeSignDoc(msgs, fee, chainId, memo, accountNumber, sequence); diff --git a/packages/launchpad/src/tx.spec.ts b/packages/launchpad/src/tx.spec.ts index 894a8069..bb6d11f7 100644 --- a/packages/launchpad/src/tx.spec.ts +++ b/packages/launchpad/src/tx.spec.ts @@ -1,9 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { StdSignature } from "@cosmjs/amino"; +import { StdFee, StdSignature } from "@cosmjs/amino"; +import { makeSignDoc } from "@cosmjs/amino/build/signdoc"; import { coins } from "./coins"; -import { makeSignDoc } from "./encoding"; -import { StdFee } from "./fee"; import { makeStdTx } from "./tx"; describe("tx", () => { diff --git a/packages/launchpad/src/tx.ts b/packages/launchpad/src/tx.ts index 0ef1082d..57bf5232 100644 --- a/packages/launchpad/src/tx.ts +++ b/packages/launchpad/src/tx.ts @@ -1,8 +1,4 @@ -import { StdSignature } from "@cosmjs/amino"; - -import { StdSignDoc } from "./encoding"; -import { StdFee } from "./fee"; -import { Msg } from "./msgs"; +import { AminoMsg, StdFee, StdSignature, StdSignDoc } from "@cosmjs/amino"; /** * A Cosmos SDK StdTx @@ -10,7 +6,7 @@ import { Msg } from "./msgs"; * @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdtx */ export interface StdTx { - readonly msg: readonly Msg[]; + readonly msg: readonly AminoMsg[]; readonly fee: StdFee; readonly signatures: readonly StdSignature[]; readonly memo: string | undefined; diff --git a/packages/proto-signing/package.json b/packages/proto-signing/package.json index 806b3a8f..4e80f6bc 100644 --- a/packages/proto-signing/package.json +++ b/packages/proto-signing/package.json @@ -44,7 +44,6 @@ }, "dependencies": { "@cosmjs/amino": "^0.25.0-alpha.0", - "@cosmjs/launchpad": "^0.25.0-alpha.0", "long": "^4.0.0", "protobufjs": "~6.10.2" }, diff --git a/packages/proto-signing/src/signer.ts b/packages/proto-signing/src/signer.ts index 65b6e6ab..dd6a8f3b 100644 --- a/packages/proto-signing/src/signer.ts +++ b/packages/proto-signing/src/signer.ts @@ -1,5 +1,4 @@ -import { StdSignature } from "@cosmjs/amino"; -import { OfflineSigner as OfflineAminoSigner } from "@cosmjs/launchpad"; +import { OfflineAminoSigner, StdSignature } from "@cosmjs/amino"; import { SignDoc } from "./codec/cosmos/tx/v1beta1/tx"; diff --git a/packages/stargate/src/aminotypes.ts b/packages/stargate/src/aminotypes.ts index 7392af22..c3024941 100644 --- a/packages/stargate/src/aminotypes.ts +++ b/packages/stargate/src/aminotypes.ts @@ -1,8 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { decodeBech32Pubkey, encodeBech32Pubkey } from "@cosmjs/amino"; +import { AminoMsg, decodeBech32Pubkey, encodeBech32Pubkey } from "@cosmjs/amino"; import { fromBase64, toBase64 } from "@cosmjs/encoding"; import { - Msg, MsgBeginRedelegate as LaunchpadMsgBeginRedelegate, MsgCreateValidator as LaunchpadMsgCreateValidator, MsgDelegate as LaunchpadMsgDelegate, @@ -416,7 +415,7 @@ export class AminoTypes { this.register = { ...filteredDefaultTypes, ...additions }; } - public toAmino({ typeUrl, value }: EncodeObject): Msg { + public toAmino({ typeUrl, value }: EncodeObject): AminoMsg { const converter = this.register[typeUrl]; if (!converter) { throw new Error( @@ -431,7 +430,7 @@ export class AminoTypes { }; } - public fromAmino({ type, value }: Msg): EncodeObject { + public fromAmino({ type, value }: AminoMsg): EncodeObject { const result = Object.entries(this.register).find(([_typeUrl, { aminoType }]) => aminoType === type); if (!result) { throw new Error( diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index c16d5a2d..271b5069 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -1,6 +1,6 @@ -import { encodeSecp256k1Pubkey } from "@cosmjs/amino"; +import { encodeSecp256k1Pubkey, makeSignDoc as makeSignDocAmino } from "@cosmjs/amino"; import { fromBase64 } from "@cosmjs/encoding"; -import { CosmosFeeTable, makeSignDoc as makeSignDocAmino } from "@cosmjs/launchpad"; +import { CosmosFeeTable } from "@cosmjs/launchpad"; import { Int53 } from "@cosmjs/math"; import { EncodeObject, diff --git a/packages/stargate/src/testutils.spec.ts b/packages/stargate/src/testutils.spec.ts index 8b093eb3..73d05d63 100644 --- a/packages/stargate/src/testutils.spec.ts +++ b/packages/stargate/src/testutils.spec.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { AminoSignResponse, StdSignDoc } from "@cosmjs/amino"; import { Bip39, EnglishMnemonic, Random, Secp256k1, Slip10, Slip10Curve } from "@cosmjs/crypto"; import { Bech32 } from "@cosmjs/encoding"; -import { AminoSignResponse, Secp256k1HdWallet, StdSignDoc } from "@cosmjs/launchpad"; +import { Secp256k1HdWallet } from "@cosmjs/launchpad"; import { coins, DirectSecp256k1HdWallet,