From 7a34d6270bb1ffe5ac70a2e5c1fd642ab76a48e1 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 15:46:33 +0100 Subject: [PATCH 01/13] proto-signing: Use OfflineAminoSigner from amino --- packages/proto-signing/src/signer.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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"; From 7a7329cc4feb2cf6b2f4bf2daaaf7d0e9b63199a Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 12:58:58 +0100 Subject: [PATCH 02/13] proto-signing: Remove @cosmjs/launchpad dependency --- packages/proto-signing/package.json | 1 - 1 file changed, 1 deletion(-) 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" }, From f616abc4d8a1c805e16a937fb8740c8249c41ad2 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 13:06:36 +0100 Subject: [PATCH 03/13] amino: Transfer signer interfaces from launchpad --- packages/amino/src/index.ts | 1 + packages/amino/src/signer.ts | 67 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 packages/amino/src/signer.ts diff --git a/packages/amino/src/index.ts b/packages/amino/src/index.ts index 340fd598..7c576317 100644 --- a/packages/amino/src/index.ts +++ b/packages/amino/src/index.ts @@ -20,3 +20,4 @@ export { } from "./pubkeys"; export { createMultisigThresholdPubkey } from "./multisig"; export { decodeSignature, encodeSecp256k1Signature, StdSignature } from "./signature"; +export { AccountData, Algo, AminoMsg, AminoSignResponse, OfflineAminoSigner, StdSignDoc } from "./signer"; diff --git a/packages/amino/src/signer.ts b/packages/amino/src/signer.ts new file mode 100644 index 00000000..fcfce60c --- /dev/null +++ b/packages/amino/src/signer.ts @@ -0,0 +1,67 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { StdSignature } from "./signature"; + +export interface AminoMsg { + readonly type: string; + readonly value: any; +} + +interface Coin { + readonly denom: string; + readonly amount: string; +} + +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; +} + +export type Algo = "secp256k1" | "ed25519" | "sr25519"; + +export interface AccountData { + /** A printable address (typically bech32 encoded) */ + readonly address: string; + readonly algo: Algo; + readonly pubkey: Uint8Array; +} + +export interface AminoSignResponse { + /** + * The sign doc that was signed. + * This may be different from the input signDoc when the signer modifies it as part of the signing process. + */ + readonly signed: StdSignDoc; + readonly signature: StdSignature; +} + +export interface OfflineAminoSigner { + /** + * Get AccountData array from wallet. Rejects if not enabled. + */ + readonly getAccounts: () => Promise; + + /** + * Request signature from whichever key corresponds to provided bech32-encoded address. Rejects if not enabled. + * + * The signer implementation may offer the user the ability to override parts of the signDoc. It must + * return the doc that was signed in the response. + * + * @param signerAddress The address of the account that should sign the transaction + * @param signDoc The content that should be signed + */ + readonly signAmino: (signerAddress: string, signDoc: StdSignDoc) => Promise; +} From 8ec39af7870b02211c504c63d173c265174dbc72 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 13:15:17 +0100 Subject: [PATCH 04/13] launchpad: Use signer interfaces from amino --- packages/launchpad/src/encoding.ts | 18 +---- packages/launchpad/src/index.ts | 12 ++- packages/launchpad/src/msgs.ts | 75 +++++++++---------- .../launchpad/src/secp256k1hdwallet.spec.ts | 3 +- packages/launchpad/src/secp256k1hdwallet.ts | 14 +++- .../launchpad/src/secp256k1wallet.spec.ts | 3 +- packages/launchpad/src/secp256k1wallet.ts | 14 +++- packages/launchpad/src/signer.ts | 39 ---------- packages/launchpad/src/signingcosmosclient.ts | 18 +++-- packages/launchpad/src/tx.ts | 6 +- 10 files changed, 83 insertions(+), 119 deletions(-) delete mode 100644 packages/launchpad/src/signer.ts diff --git a/packages/launchpad/src/encoding.ts b/packages/launchpad/src/encoding.ts index 5d7b457d..210701f6 100644 --- a/packages/launchpad/src/encoding.ts +++ b/packages/launchpad/src/encoding.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { AminoMsg, StdSignDoc } from "@cosmjs/amino"; import { toUtf8 } from "@cosmjs/encoding"; import { Uint53 } from "@cosmjs/math"; import { StdFee } from "./fee"; -import { Msg } from "./msgs"; function sortedObject(obj: any): any { if (typeof obj !== "object" || obj === null) { @@ -27,22 +27,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/index.ts b/packages/launchpad/src/index.ts index 04d91fb8..e03f05ad 100644 --- a/packages/launchpad/src/index.ts +++ b/packages/launchpad/src/index.ts @@ -1,5 +1,12 @@ // Re-exports for backwards compatibility export { + AccountData, + Algo, + AminoMsg as Msg, + AminoSignResponse, + OfflineAminoSigner as OfflineSigner, + StdSignDoc, + StdSignature, decodeAminoPubkey, decodeBech32Pubkey, decodeSignature, @@ -9,7 +16,6 @@ export { encodeSecp256k1Signature, pubkeyToAddress, pubkeyType, - StdSignature, } from "@cosmjs/amino"; import { SinglePubkey } from "@cosmjs/amino"; /** @deprecated PubKey is deprecated. Use `SinglePubkey` or the more general `Pubkey` from `@cosmjs/amino`. */ @@ -42,7 +48,7 @@ export { isSearchBySentFromOrToQuery, isSearchByTagsQuery, } from "./cosmosclient"; -export { makeSignDoc, serializeSignDoc, StdSignDoc } from "./encoding"; +export { makeSignDoc, serializeSignDoc } from "./encoding"; export { buildFeeTable, FeeTable, GasLimits, GasPrice, StdFee } from "./fee"; export { AuthAccountsResponse, @@ -127,7 +133,6 @@ export { isMsgUndelegate, isMsgWithdrawDelegatorReward, isMsgWithdrawValidatorCommission, - Msg, MsgBeginRedelegate, MsgCreateValidator, MsgDelegate, @@ -142,7 +147,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/msgs.ts b/packages/launchpad/src/msgs.ts index 3a627e74..e3eec942 100644 --- a/packages/launchpad/src/msgs.ts +++ b/packages/launchpad/src/msgs.ts @@ -1,17 +1,14 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { Coin } from "./coins"; +import { AminoMsg } from "@cosmjs/amino"; -export interface Msg { - readonly type: string; - readonly value: any; -} +import { Coin } from "./coins"; // 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 +19,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 +36,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 +44,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 +61,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 +79,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 +96,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 +110,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 +124,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 +136,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 +145,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 +162,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 +175,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 +185,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 +200,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 +213,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 +221,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 +244,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 +260,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 +276,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 +285,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 +296,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 +314,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 +330,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..5ad11121 100644 --- a/packages/launchpad/src/secp256k1hdwallet.spec.ts +++ b/packages/launchpad/src/secp256k1hdwallet.spec.ts @@ -1,8 +1,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { StdSignDoc } from "@cosmjs/amino"; import { Secp256k1, Secp256k1Signature, sha256 } from "@cosmjs/crypto"; import { fromBase64, fromHex } from "@cosmjs/encoding"; -import { serializeSignDoc, StdSignDoc } from "./encoding"; +import { serializeSignDoc } 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..460ce990 100644 --- a/packages/launchpad/src/secp256k1hdwallet.ts +++ b/packages/launchpad/src/secp256k1hdwallet.ts @@ -1,4 +1,11 @@ -import { encodeSecp256k1Signature, rawSecp256k1PubkeyToRawAddress } from "@cosmjs/amino"; +import { + AccountData, + AminoSignResponse, + encodeSecp256k1Signature, + OfflineAminoSigner, + rawSecp256k1PubkeyToRawAddress, + StdSignDoc, +} from "@cosmjs/amino"; import { Bip39, EnglishMnemonic, @@ -14,9 +21,8 @@ import { import { Bech32, fromBase64, fromUtf8, toBase64, toUtf8 } from "@cosmjs/encoding"; import { assert, isNonNullObject } from "@cosmjs/utils"; -import { serializeSignDoc, StdSignDoc } from "./encoding"; +import { serializeSignDoc } 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..d074bbad 100644 --- a/packages/launchpad/src/secp256k1wallet.spec.ts +++ b/packages/launchpad/src/secp256k1wallet.spec.ts @@ -1,8 +1,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { StdSignDoc } from "@cosmjs/amino"; import { Secp256k1, Secp256k1Signature, Sha256 } from "@cosmjs/crypto"; import { fromBase64, fromHex } from "@cosmjs/encoding"; -import { serializeSignDoc, StdSignDoc } from "./encoding"; +import { serializeSignDoc } from "./encoding"; import { Secp256k1Wallet } from "./secp256k1wallet"; describe("Secp256k1Wallet", () => { diff --git a/packages/launchpad/src/secp256k1wallet.ts b/packages/launchpad/src/secp256k1wallet.ts index 247ba3d1..4fbbcf48 100644 --- a/packages/launchpad/src/secp256k1wallet.ts +++ b/packages/launchpad/src/secp256k1wallet.ts @@ -1,16 +1,22 @@ -import { encodeSecp256k1Signature, rawSecp256k1PubkeyToRawAddress } from "@cosmjs/amino"; +import { + AccountData, + AminoSignResponse, + encodeSecp256k1Signature, + OfflineAminoSigner, + rawSecp256k1PubkeyToRawAddress, + 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"; +import { serializeSignDoc } from "./encoding"; /** * 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/signer.ts b/packages/launchpad/src/signer.ts deleted file mode 100644 index a2f25eb1..00000000 --- a/packages/launchpad/src/signer.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { StdSignature } from "@cosmjs/amino"; - -import { StdSignDoc } from "./encoding"; - -export type Algo = "secp256k1" | "ed25519" | "sr25519"; - -export interface AccountData { - /** A printable address (typically bech32 encoded) */ - readonly address: string; - readonly algo: Algo; - readonly pubkey: Uint8Array; -} - -export interface AminoSignResponse { - /** - * The sign doc that was signed. - * This may be different from the input signDoc when the signer modifies it as part of the signing process. - */ - readonly signed: StdSignDoc; - readonly signature: StdSignature; -} - -export interface OfflineSigner { - /** - * Get AccountData array from wallet. Rejects if not enabled. - */ - readonly getAccounts: () => Promise; - - /** - * Request signature from whichever key corresponds to provided bech32-encoded address. Rejects if not enabled. - * - * The signer implementation may offer the user the ability to override parts of the signDoc. It must - * return the doc that was signed in the response. - * - * @param signerAddress The address of the account that should sign the transaction - * @param signDoc The content that should be signed - */ - readonly signAmino: (signerAddress: string, signDoc: StdSignDoc) => Promise; -} diff --git a/packages/launchpad/src/signingcosmosclient.ts b/packages/launchpad/src/signingcosmosclient.ts index 057efb4e..e43fb9c3 100644 --- a/packages/launchpad/src/signingcosmosclient.ts +++ b/packages/launchpad/src/signingcosmosclient.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { AminoMsg, OfflineAminoSigner } from "@cosmjs/amino"; import equals from "fast-deep-equal"; import { Coin } from "./coins"; @@ -6,8 +7,7 @@ import { Account, BroadcastTxResult, CosmosClient, GetSequenceResult } from "./c import { makeSignDoc } from "./encoding"; import { buildFeeTable, FeeTable, GasLimits, GasPrice, StdFee } 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 +29,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 +39,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 +47,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 +87,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 +100,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.ts b/packages/launchpad/src/tx.ts index 0ef1082d..ff4b4a52 100644 --- a/packages/launchpad/src/tx.ts +++ b/packages/launchpad/src/tx.ts @@ -1,8 +1,6 @@ -import { StdSignature } from "@cosmjs/amino"; +import { AminoMsg, StdSignature, StdSignDoc } from "@cosmjs/amino"; -import { StdSignDoc } from "./encoding"; import { StdFee } from "./fee"; -import { Msg } from "./msgs"; /** * A Cosmos SDK StdTx @@ -10,7 +8,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; From 26d3ed650698565d65dd2d29f7fccba2642459d2 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 13:17:33 +0100 Subject: [PATCH 05/13] amino: Export Coin and StdFee --- packages/amino/src/index.ts | 11 ++++++++++- packages/amino/src/signer.ts | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/amino/src/index.ts b/packages/amino/src/index.ts index 7c576317..42ca9252 100644 --- a/packages/amino/src/index.ts +++ b/packages/amino/src/index.ts @@ -20,4 +20,13 @@ export { } from "./pubkeys"; export { createMultisigThresholdPubkey } from "./multisig"; export { decodeSignature, encodeSecp256k1Signature, StdSignature } from "./signature"; -export { AccountData, Algo, AminoMsg, AminoSignResponse, OfflineAminoSigner, StdSignDoc } from "./signer"; +export { + AccountData, + Algo, + AminoMsg, + AminoSignResponse, + Coin, + OfflineAminoSigner, + StdFee, + StdSignDoc, +} from "./signer"; diff --git a/packages/amino/src/signer.ts b/packages/amino/src/signer.ts index fcfce60c..cb1abc38 100644 --- a/packages/amino/src/signer.ts +++ b/packages/amino/src/signer.ts @@ -6,12 +6,12 @@ export interface AminoMsg { readonly value: any; } -interface Coin { +export interface Coin { readonly denom: string; readonly amount: string; } -interface StdFee { +export interface StdFee { readonly amount: readonly Coin[]; readonly gas: string; } From 48e4223ca0c67c00fbd32ecd0aa0f0cf1c47f124 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 13:26:02 +0100 Subject: [PATCH 06/13] launchpad: Use Coin and StdFee from amino --- packages/launchpad/src/coins.ts | 6 +----- packages/launchpad/src/cosmosclient.spec.ts | 2 +- packages/launchpad/src/cosmosclient.ts | 3 +-- packages/launchpad/src/encoding.ts | 4 +--- packages/launchpad/src/fee.ts | 8 ++------ packages/launchpad/src/index.ts | 7 ++++--- packages/launchpad/src/lcdapi/auth.ts | 3 +-- packages/launchpad/src/lcdapi/bank.ts | 3 ++- packages/launchpad/src/lcdapi/distribution.ts | 3 ++- packages/launchpad/src/lcdapi/gov.ts | 3 ++- packages/launchpad/src/lcdapi/lcdclient.spec.ts | 3 +-- packages/launchpad/src/lcdapi/staking.ts | 3 ++- packages/launchpad/src/lcdapi/supply.ts | 3 ++- packages/launchpad/src/msgs.ts | 4 +--- packages/launchpad/src/signingcosmosclient.spec.ts | 3 ++- packages/launchpad/src/signingcosmosclient.ts | 5 ++--- packages/launchpad/src/tx.spec.ts | 3 +-- packages/launchpad/src/tx.ts | 4 +--- 18 files changed, 29 insertions(+), 41 deletions(-) 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.spec.ts b/packages/launchpad/src/cosmosclient.spec.ts index 768b27b6..56d7933f 100644 --- a/packages/launchpad/src/cosmosclient.spec.ts +++ b/packages/launchpad/src/cosmosclient.spec.ts @@ -1,10 +1,10 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { 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/encoding.ts b/packages/launchpad/src/encoding.ts index 210701f6..00690962 100644 --- a/packages/launchpad/src/encoding.ts +++ b/packages/launchpad/src/encoding.ts @@ -1,10 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { AminoMsg, StdSignDoc } from "@cosmjs/amino"; +import { AminoMsg, StdFee, StdSignDoc } from "@cosmjs/amino"; import { toUtf8 } from "@cosmjs/encoding"; import { Uint53 } from "@cosmjs/math"; -import { StdFee } from "./fee"; - function sortedObject(obj: any): any { if (typeof obj !== "object" || obj === null) { return obj; 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 e03f05ad..0cd39b82 100644 --- a/packages/launchpad/src/index.ts +++ b/packages/launchpad/src/index.ts @@ -4,7 +4,9 @@ export { Algo, AminoMsg as Msg, AminoSignResponse, + Coin, OfflineAminoSigner as OfflineSigner, + StdFee, StdSignDoc, StdSignature, decodeAminoPubkey, @@ -24,8 +26,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, @@ -49,7 +50,7 @@ export { isSearchByTagsQuery, } from "./cosmosclient"; export { makeSignDoc, serializeSignDoc } from "./encoding"; -export { buildFeeTable, FeeTable, GasLimits, GasPrice, StdFee } from "./fee"; +export { buildFeeTable, FeeTable, GasLimits, GasPrice } from "./fee"; export { AuthAccountsResponse, AuthExtension, 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.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.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..bc3e7d3c 100644 --- a/packages/launchpad/src/lcdapi/lcdclient.spec.ts +++ b/packages/launchpad/src/lcdapi/lcdclient.spec.ts @@ -1,10 +1,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { Coin, 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.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 e3eec942..f1a4a1f3 100644 --- a/packages/launchpad/src/msgs.ts +++ b/packages/launchpad/src/msgs.ts @@ -1,7 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { AminoMsg } from "@cosmjs/amino"; - -import { Coin } from "./coins"; +import { AminoMsg, Coin } from "@cosmjs/amino"; // auth (no messages) - see https://github.com/cosmos/cosmos-sdk/blob/efa73c7/proto/cosmos/auth/auth.proto 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 e43fb9c3..3572d748 100644 --- a/packages/launchpad/src/signingcosmosclient.ts +++ b/packages/launchpad/src/signingcosmosclient.ts @@ -1,11 +1,10 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { AminoMsg, OfflineAminoSigner } from "@cosmjs/amino"; +import { AminoMsg, Coin, 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 { MsgSend } from "./msgs"; import { makeStdTx, StdTx } from "./tx"; diff --git a/packages/launchpad/src/tx.spec.ts b/packages/launchpad/src/tx.spec.ts index 894a8069..b79da7ca 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 { 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 ff4b4a52..57bf5232 100644 --- a/packages/launchpad/src/tx.ts +++ b/packages/launchpad/src/tx.ts @@ -1,6 +1,4 @@ -import { AminoMsg, StdSignature, StdSignDoc } from "@cosmjs/amino"; - -import { StdFee } from "./fee"; +import { AminoMsg, StdFee, StdSignature, StdSignDoc } from "@cosmjs/amino"; /** * A Cosmos SDK StdTx From e73fe0427461a802952f2c92943bb9ab4bbed606 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 13:55:28 +0100 Subject: [PATCH 07/13] stargate: Use signer types from amino --- packages/stargate/src/aminotypes.ts | 7 +++---- packages/stargate/src/testutils.spec.ts | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) 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/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, From 4d5e0866adb24242eb86b17f6cd3364fd3794f7c Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 15:17:29 +0100 Subject: [PATCH 08/13] cosmwasm-stargate: Use signer types from amino --- packages/cosmwasm-stargate/src/testutils.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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, From 651af7d6537202b3e9951c980b1c42f073333fbf Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 15:31:50 +0100 Subject: [PATCH 09/13] amino: Transfer signdoc functions from launchpad --- packages/amino/src/index.ts | 12 +-- packages/amino/src/signdoc.spec.ts | 135 +++++++++++++++++++++++++++++ packages/amino/src/signdoc.ts | 76 ++++++++++++++++ packages/amino/src/signer.ts | 30 +------ 4 files changed, 214 insertions(+), 39 deletions(-) create mode 100644 packages/amino/src/signdoc.spec.ts create mode 100644 packages/amino/src/signdoc.ts diff --git a/packages/amino/src/index.ts b/packages/amino/src/index.ts index 42ca9252..c45fd5bb 100644 --- a/packages/amino/src/index.ts +++ b/packages/amino/src/index.ts @@ -20,13 +20,5 @@ export { } from "./pubkeys"; export { createMultisigThresholdPubkey } from "./multisig"; export { decodeSignature, encodeSecp256k1Signature, StdSignature } from "./signature"; -export { - AccountData, - Algo, - AminoMsg, - AminoSignResponse, - Coin, - OfflineAminoSigner, - StdFee, - StdSignDoc, -} from "./signer"; +export { AminoMsg, Coin, makeSignDoc, serializeSignDoc, StdFee, StdSignDoc } from "./signdoc"; +export { AccountData, Algo, AminoSignResponse, OfflineAminoSigner } from "./signer"; diff --git a/packages/amino/src/signdoc.spec.ts b/packages/amino/src/signdoc.spec.ts new file mode 100644 index 00000000..e23b705e --- /dev/null +++ b/packages/amino/src/signdoc.spec.ts @@ -0,0 +1,135 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +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", () => { + it("leaves non-objects unchanged", () => { + expect(sortedJsonStringify(true)).toEqual(`true`); + expect(sortedJsonStringify(false)).toEqual(`false`); + expect(sortedJsonStringify("aabbccdd")).toEqual(`"aabbccdd"`); + expect(sortedJsonStringify(75)).toEqual(`75`); + expect(sortedJsonStringify(null)).toEqual(`null`); + expect(sortedJsonStringify([5, 6, 7, 1])).toEqual(`[5,6,7,1]`); + expect(sortedJsonStringify([5, ["a", "b"], true, null, 1])).toEqual(`[5,["a","b"],true,null,1]`); + }); + + it("sorts objects by key", () => { + // already sorted + expect(sortedJsonStringify({})).toEqual(`{}`); + expect(sortedJsonStringify({ a: 3 })).toEqual(`{"a":3}`); + expect(sortedJsonStringify({ a: 3, b: 2, c: 1 })).toEqual(`{"a":3,"b":2,"c":1}`); + + // not yet sorted + expect(sortedJsonStringify({ b: 2, a: 3, c: 1 })).toEqual(`{"a":3,"b":2,"c":1}`); + expect(sortedJsonStringify({ aaa: true, aa: true, a: true })).toEqual( + `{"a":true,"aa":true,"aaa":true}`, + ); + }); + + it("sorts nested objects", () => { + // already sorted + expect(sortedJsonStringify({ x: { y: { z: null } } })).toEqual(`{"x":{"y":{"z":null}}}`); + + // not yet sorted + expect(sortedJsonStringify({ b: { z: true, x: true, y: true }, a: true, c: true })).toEqual( + `{"a":true,"b":{"x":true,"y":true,"z":true},"c":true}`, + ); + }); + + it("sorts objects in arrays", () => { + // already sorted + expect(sortedJsonStringify([1, 2, { x: { y: { z: null } } }, 4])).toEqual( + `[1,2,{"x":{"y":{"z":null}}},4]`, + ); + + // not yet sorted + expect(sortedJsonStringify([1, 2, { b: { z: true, x: true, y: true }, a: true, c: true }, 4])).toEqual( + `[1,2,{"a":true,"b":{"x":true,"y":true,"z":true},"c":true},4]`, + ); + }); + }); + + describe("makeSignDoc", () => { + it("works", () => { + const chainId = "testspace-12"; + const msg1: AminoMsg = { + type: "cosmos-sdk/MsgDelegate", + value: { + delegator_address: testAddress, + validator_address: testValidatorAddress, + amount: { amount: "1234", denom: "ustake" }, + }, + }; + const msg2: AminoMsg = { + type: "cosmos-sdk/MsgSend", + value: { + from_address: testAddress, + to_address: makeRandomAddress(), + amount: [{ amount: "1234567", denom: "ucosm" }], + }, + }; + const fee = { + amount: [{ amount: "2000", denom: "ucosm" }], + gas: "180000", // 180k + }; + const memo = "Use your power wisely"; + const accountNumber = 15; + const sequence = 16; + + const signDoc = makeSignDoc([msg1, msg2], fee, chainId, memo, accountNumber, sequence); + expect(signDoc).toEqual({ + msgs: [msg1, msg2], + fee: fee, + chain_id: chainId, + account_number: accountNumber.toString(), + sequence: sequence.toString(), + memo: memo, + }); + }); + + it("works with undefined memo", () => { + const chainId = "testspace-12"; + const msg1: AminoMsg = { + type: "cosmos-sdk/MsgDelegate", + value: { + delegator_address: testAddress, + validator_address: testValidatorAddress, + amount: { amount: "1234", denom: "ustake" }, + }, + }; + const msg2: AminoMsg = { + type: "cosmos-sdk/MsgSend", + value: { + from_address: testAddress, + to_address: makeRandomAddress(), + amount: [{ amount: "1234567", denom: "ucosm" }], + }, + }; + const fee = { + amount: [{ amount: "2000", denom: "ucosm" }], + gas: "180000", // 180k + }; + const accountNumber = 15; + const sequence = 16; + + const signDoc = makeSignDoc([msg1, msg2], fee, chainId, undefined, accountNumber, sequence); + expect(signDoc).toEqual({ + msgs: [msg1, msg2], + fee: fee, + chain_id: chainId, + account_number: accountNumber.toString(), + sequence: sequence.toString(), + memo: "", + }); + }); + }); +}); diff --git a/packages/amino/src/signdoc.ts b/packages/amino/src/signdoc.ts new file mode 100644 index 00000000..bfd75dce --- /dev/null +++ b/packages/amino/src/signdoc.ts @@ -0,0 +1,76 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { toUtf8 } from "@cosmjs/encoding"; +import { Uint53 } from "@cosmjs/math"; + +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) { + return obj; + } + if (Array.isArray(obj)) { + return obj.map(sortedObject); + } + const sortedKeys = Object.keys(obj).sort(); + const result: Record = {}; + // NOTE: Use forEach instead of reduce for performance with large objects eg Wasm code + sortedKeys.forEach((key) => { + result[key] = sortedObject(obj[key]); + }); + return result; +} + +/** Returns a JSON string with objects sorted by key */ +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types +export function sortedJsonStringify(obj: any): string { + return JSON.stringify(sortedObject(obj)); +} + +export function makeSignDoc( + msgs: readonly AminoMsg[], + fee: StdFee, + chainId: string, + memo: string | undefined, + accountNumber: number | string, + sequence: number | string, +): StdSignDoc { + return { + chain_id: chainId, + account_number: Uint53.fromString(accountNumber.toString()).toString(), + sequence: Uint53.fromString(sequence.toString()).toString(), + fee: fee, + msgs: msgs, + memo: memo || "", + }; +} + +export function serializeSignDoc(signDoc: StdSignDoc): Uint8Array { + return toUtf8(sortedJsonStringify(signDoc)); +} diff --git a/packages/amino/src/signer.ts b/packages/amino/src/signer.ts index cb1abc38..0059cbc1 100644 --- a/packages/amino/src/signer.ts +++ b/packages/amino/src/signer.ts @@ -1,34 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { StdSignature } from "./signature"; - -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; -} +import { StdSignDoc } from "./signdoc"; export type Algo = "secp256k1" | "ed25519" | "sr25519"; From 772a23c5ae201906ec4c4076c6799f9b147d8e13 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 15:39:15 +0100 Subject: [PATCH 10/13] launchpad: Use SignDoc helpers from amino --- .../src/cosmosclient.searchtx.spec.ts | 2 +- packages/launchpad/src/cosmosclient.spec.ts | 3 +- packages/launchpad/src/encoding.spec.ts | 129 ------------------ packages/launchpad/src/encoding.ts | 48 ------- packages/launchpad/src/index.ts | 3 +- .../launchpad/src/lcdapi/distribution.spec.ts | 2 +- packages/launchpad/src/lcdapi/gov.spec.ts | 2 +- .../launchpad/src/lcdapi/lcdclient.spec.ts | 3 +- packages/launchpad/src/lcdapi/staking.spec.ts | 2 +- .../launchpad/src/secp256k1hdwallet.spec.ts | 3 +- packages/launchpad/src/secp256k1hdwallet.ts | 2 +- .../launchpad/src/secp256k1wallet.spec.ts | 3 +- packages/launchpad/src/secp256k1wallet.ts | 3 +- packages/launchpad/src/sequence.ts | 3 +- packages/launchpad/src/signingcosmosclient.ts | 4 +- packages/launchpad/src/tx.spec.ts | 2 +- 16 files changed, 16 insertions(+), 198 deletions(-) delete mode 100644 packages/launchpad/src/encoding.spec.ts delete mode 100644 packages/launchpad/src/encoding.ts 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 56d7933f..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 { StdFee } from "@cosmjs/amino"; +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 { findAttribute } from "./logs"; import { MsgSend } from "./msgs"; import { Secp256k1HdWallet } from "./secp256k1hdwallet"; diff --git a/packages/launchpad/src/encoding.spec.ts b/packages/launchpad/src/encoding.spec.ts deleted file mode 100644 index e58bb654..00000000 --- a/packages/launchpad/src/encoding.spec.ts +++ /dev/null @@ -1,129 +0,0 @@ -/* 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"; - -describe("encoding", () => { - describe("sortedJsonStringify", () => { - it("leaves non-objects unchanged", () => { - expect(sortedJsonStringify(true)).toEqual(`true`); - expect(sortedJsonStringify(false)).toEqual(`false`); - expect(sortedJsonStringify("aabbccdd")).toEqual(`"aabbccdd"`); - expect(sortedJsonStringify(75)).toEqual(`75`); - expect(sortedJsonStringify(null)).toEqual(`null`); - expect(sortedJsonStringify([5, 6, 7, 1])).toEqual(`[5,6,7,1]`); - expect(sortedJsonStringify([5, ["a", "b"], true, null, 1])).toEqual(`[5,["a","b"],true,null,1]`); - }); - - it("sorts objects by key", () => { - // already sorted - expect(sortedJsonStringify({})).toEqual(`{}`); - expect(sortedJsonStringify({ a: 3 })).toEqual(`{"a":3}`); - expect(sortedJsonStringify({ a: 3, b: 2, c: 1 })).toEqual(`{"a":3,"b":2,"c":1}`); - - // not yet sorted - expect(sortedJsonStringify({ b: 2, a: 3, c: 1 })).toEqual(`{"a":3,"b":2,"c":1}`); - expect(sortedJsonStringify({ aaa: true, aa: true, a: true })).toEqual( - `{"a":true,"aa":true,"aaa":true}`, - ); - }); - - it("sorts nested objects", () => { - // already sorted - expect(sortedJsonStringify({ x: { y: { z: null } } })).toEqual(`{"x":{"y":{"z":null}}}`); - - // not yet sorted - expect(sortedJsonStringify({ b: { z: true, x: true, y: true }, a: true, c: true })).toEqual( - `{"a":true,"b":{"x":true,"y":true,"z":true},"c":true}`, - ); - }); - - it("sorts objects in arrays", () => { - // already sorted - expect(sortedJsonStringify([1, 2, { x: { y: { z: null } } }, 4])).toEqual( - `[1,2,{"x":{"y":{"z":null}}},4]`, - ); - - // not yet sorted - expect(sortedJsonStringify([1, 2, { b: { z: true, x: true, y: true }, a: true, c: true }, 4])).toEqual( - `[1,2,{"a":true,"b":{"x":true,"y":true,"z":true},"c":true},4]`, - ); - }); - }); - - describe("makeSignDoc", () => { - it("works", () => { - const chainId = "testspace-12"; - const msg1: MsgDelegate = { - type: "cosmos-sdk/MsgDelegate", - value: { - delegator_address: faucet.address0, - validator_address: launchpad.validator.address, - amount: coin(1234, "ustake"), - }, - }; - const msg2: MsgSend = { - type: "cosmos-sdk/MsgSend", - value: { - from_address: faucet.address0, - to_address: makeRandomAddress(), - amount: coins(1234567, "ucosm"), - }, - }; - const fee = { - amount: coins(2000, "ucosm"), - gas: "180000", // 180k - }; - const memo = "Use your power wisely"; - const accountNumber = 15; - const sequence = 16; - - const signDoc = makeSignDoc([msg1, msg2], fee, chainId, memo, accountNumber, sequence); - expect(signDoc).toEqual({ - msgs: [msg1, msg2], - fee: fee, - chain_id: chainId, - account_number: accountNumber.toString(), - sequence: sequence.toString(), - memo: memo, - }); - }); - - it("works with undefined memo", () => { - const chainId = "testspace-12"; - const msg1: MsgDelegate = { - type: "cosmos-sdk/MsgDelegate", - value: { - delegator_address: faucet.address0, - validator_address: launchpad.validator.address, - amount: coin(1234, "ustake"), - }, - }; - const msg2: MsgSend = { - type: "cosmos-sdk/MsgSend", - value: { - from_address: faucet.address0, - to_address: makeRandomAddress(), - amount: coins(1234567, "ucosm"), - }, - }; - const fee = { - amount: coins(2000, "ucosm"), - gas: "180000", // 180k - }; - const accountNumber = 15; - const sequence = 16; - - const signDoc = makeSignDoc([msg1, msg2], fee, chainId, undefined, accountNumber, sequence); - expect(signDoc).toEqual({ - msgs: [msg1, msg2], - fee: fee, - chain_id: chainId, - account_number: accountNumber.toString(), - sequence: sequence.toString(), - memo: "", - }); - }); - }); -}); diff --git a/packages/launchpad/src/encoding.ts b/packages/launchpad/src/encoding.ts deleted file mode 100644 index 00690962..00000000 --- a/packages/launchpad/src/encoding.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import { AminoMsg, StdFee, StdSignDoc } from "@cosmjs/amino"; -import { toUtf8 } from "@cosmjs/encoding"; -import { Uint53 } from "@cosmjs/math"; - -function sortedObject(obj: any): any { - if (typeof obj !== "object" || obj === null) { - return obj; - } - if (Array.isArray(obj)) { - return obj.map(sortedObject); - } - const sortedKeys = Object.keys(obj).sort(); - const result: Record = {}; - // NOTE: Use forEach instead of reduce for performance with large objects eg Wasm code - sortedKeys.forEach((key) => { - result[key] = sortedObject(obj[key]); - }); - return result; -} - -/** Returns a JSON string with objects sorted by key */ -// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types -export function sortedJsonStringify(obj: any): string { - return JSON.stringify(sortedObject(obj)); -} - -export function makeSignDoc( - msgs: readonly AminoMsg[], - fee: StdFee, - chainId: string, - memo: string | undefined, - accountNumber: number | string, - sequence: number | string, -): StdSignDoc { - return { - chain_id: chainId, - account_number: Uint53.fromString(accountNumber.toString()).toString(), - sequence: Uint53.fromString(sequence.toString()).toString(), - fee: fee, - msgs: msgs, - memo: memo || "", - }; -} - -export function serializeSignDoc(signDoc: StdSignDoc): Uint8Array { - return toUtf8(sortedJsonStringify(signDoc)); -} diff --git a/packages/launchpad/src/index.ts b/packages/launchpad/src/index.ts index 0cd39b82..7d6219fb 100644 --- a/packages/launchpad/src/index.ts +++ b/packages/launchpad/src/index.ts @@ -16,8 +16,10 @@ export { encodeBech32Pubkey, encodeSecp256k1Pubkey, encodeSecp256k1Signature, + makeSignDoc, pubkeyToAddress, pubkeyType, + serializeSignDoc, } from "@cosmjs/amino"; import { SinglePubkey } from "@cosmjs/amino"; /** @deprecated PubKey is deprecated. Use `SinglePubkey` or the more general `Pubkey` from `@cosmjs/amino`. */ @@ -49,7 +51,6 @@ export { isSearchBySentFromOrToQuery, isSearchByTagsQuery, } from "./cosmosclient"; -export { makeSignDoc, serializeSignDoc } from "./encoding"; export { buildFeeTable, FeeTable, GasLimits, GasPrice } from "./fee"; export { AuthAccountsResponse, 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/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/lcdclient.spec.ts b/packages/launchpad/src/lcdapi/lcdclient.spec.ts index bc3e7d3c..d10cc24d 100644 --- a/packages/launchpad/src/lcdapi/lcdclient.spec.ts +++ b/packages/launchpad/src/lcdapi/lcdclient.spec.ts @@ -1,9 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { Coin, StdFee } from "@cosmjs/amino"; +import { Coin, makeSignDoc, StdFee } from "@cosmjs/amino"; import { assert, sleep } from "@cosmjs/utils"; import { isBroadcastTxFailure } from "../cosmosclient"; -import { makeSignDoc } from "../encoding"; 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/secp256k1hdwallet.spec.ts b/packages/launchpad/src/secp256k1hdwallet.spec.ts index 5ad11121..e64e5aaf 100644 --- a/packages/launchpad/src/secp256k1hdwallet.spec.ts +++ b/packages/launchpad/src/secp256k1hdwallet.spec.ts @@ -1,9 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { StdSignDoc } from "@cosmjs/amino"; +import { serializeSignDoc, StdSignDoc } from "@cosmjs/amino"; import { Secp256k1, Secp256k1Signature, sha256 } from "@cosmjs/crypto"; import { fromBase64, fromHex } from "@cosmjs/encoding"; -import { serializeSignDoc } 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 460ce990..956ad6aa 100644 --- a/packages/launchpad/src/secp256k1hdwallet.ts +++ b/packages/launchpad/src/secp256k1hdwallet.ts @@ -4,6 +4,7 @@ import { encodeSecp256k1Signature, OfflineAminoSigner, rawSecp256k1PubkeyToRawAddress, + serializeSignDoc, StdSignDoc, } from "@cosmjs/amino"; import { @@ -21,7 +22,6 @@ import { import { Bech32, fromBase64, fromUtf8, toBase64, toUtf8 } from "@cosmjs/encoding"; import { assert, isNonNullObject } from "@cosmjs/utils"; -import { serializeSignDoc } from "./encoding"; import { makeCosmoshubPath } from "./paths"; import { decrypt, diff --git a/packages/launchpad/src/secp256k1wallet.spec.ts b/packages/launchpad/src/secp256k1wallet.spec.ts index d074bbad..57f20687 100644 --- a/packages/launchpad/src/secp256k1wallet.spec.ts +++ b/packages/launchpad/src/secp256k1wallet.spec.ts @@ -1,9 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { StdSignDoc } from "@cosmjs/amino"; +import { serializeSignDoc, StdSignDoc } from "@cosmjs/amino"; import { Secp256k1, Secp256k1Signature, Sha256 } from "@cosmjs/crypto"; import { fromBase64, fromHex } from "@cosmjs/encoding"; -import { serializeSignDoc } from "./encoding"; import { Secp256k1Wallet } from "./secp256k1wallet"; describe("Secp256k1Wallet", () => { diff --git a/packages/launchpad/src/secp256k1wallet.ts b/packages/launchpad/src/secp256k1wallet.ts index 4fbbcf48..3280189d 100644 --- a/packages/launchpad/src/secp256k1wallet.ts +++ b/packages/launchpad/src/secp256k1wallet.ts @@ -4,13 +4,12 @@ import { encodeSecp256k1Signature, OfflineAminoSigner, rawSecp256k1PubkeyToRawAddress, + serializeSignDoc, StdSignDoc, } from "@cosmjs/amino"; import { Secp256k1, Sha256 } from "@cosmjs/crypto"; import { Bech32 } from "@cosmjs/encoding"; -import { serializeSignDoc } from "./encoding"; - /** * A wallet that holds a single secp256k1 keypair. * 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.ts b/packages/launchpad/src/signingcosmosclient.ts index 3572d748..1326e375 100644 --- a/packages/launchpad/src/signingcosmosclient.ts +++ b/packages/launchpad/src/signingcosmosclient.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { AminoMsg, Coin, OfflineAminoSigner, StdFee } from "@cosmjs/amino"; +import { AminoMsg, Coin, makeSignDoc, OfflineAminoSigner, StdFee } from "@cosmjs/amino"; +import {} from "@cosmjs/amino/build/signdoc"; import equals from "fast-deep-equal"; import { Account, BroadcastTxResult, CosmosClient, GetSequenceResult } from "./cosmosclient"; -import { makeSignDoc } from "./encoding"; import { buildFeeTable, FeeTable, GasLimits, GasPrice } from "./fee"; import { BroadcastMode } from "./lcdapi"; import { MsgSend } from "./msgs"; diff --git a/packages/launchpad/src/tx.spec.ts b/packages/launchpad/src/tx.spec.ts index b79da7ca..bb6d11f7 100644 --- a/packages/launchpad/src/tx.spec.ts +++ b/packages/launchpad/src/tx.spec.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { StdFee, StdSignature } from "@cosmjs/amino"; +import { makeSignDoc } from "@cosmjs/amino/build/signdoc"; import { coins } from "./coins"; -import { makeSignDoc } from "./encoding"; import { makeStdTx } from "./tx"; describe("tx", () => { From 3740724e7620b854255182ee55c0925845042842 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 15:40:38 +0100 Subject: [PATCH 11/13] stargate: Use SignDoc helper from amino --- packages/stargate/src/signingstargateclient.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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, From f98b4f1b7eddfb08dc970a216e879ae856c46a6d Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 15:41:34 +0100 Subject: [PATCH 12/13] cosmwasm-stargate: Use SignDoc helper from amino --- packages/cosmwasm-stargate/src/signingcosmwasmclient.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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, From 403286261d9ee65c372dda9bc52f6a4ebff5d1a6 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 16:07:50 +0100 Subject: [PATCH 13/13] Tidy up refactor mistakes --- packages/amino/src/signer.ts | 1 - packages/launchpad/src/signingcosmosclient.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/amino/src/signer.ts b/packages/amino/src/signer.ts index 0059cbc1..89de5a27 100644 --- a/packages/amino/src/signer.ts +++ b/packages/amino/src/signer.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/naming-convention */ import { StdSignature } from "./signature"; import { StdSignDoc } from "./signdoc"; diff --git a/packages/launchpad/src/signingcosmosclient.ts b/packages/launchpad/src/signingcosmosclient.ts index 1326e375..f97e7da2 100644 --- a/packages/launchpad/src/signingcosmosclient.ts +++ b/packages/launchpad/src/signingcosmosclient.ts @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { AminoMsg, Coin, makeSignDoc, OfflineAminoSigner, StdFee } from "@cosmjs/amino"; -import {} from "@cosmjs/amino/build/signdoc"; import equals from "fast-deep-equal"; import { Account, BroadcastTxResult, CosmosClient, GetSequenceResult } from "./cosmosclient";