From 5da7bbc93c9f764a900b2a6c1840ed39ae32e7f2 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 2 Jun 2020 15:32:50 +0200 Subject: [PATCH] Deduplicate and sort some types --- packages/bcp/src/address.ts | 8 +-- packages/bcp/src/cosmwasmconnection.ts | 6 +-- packages/bcp/src/decode.spec.ts | 15 +++--- packages/bcp/src/decode.ts | 23 ++++---- packages/bcp/src/encode.ts | 23 +++++--- packages/bcp/types/decode.d.ts | 15 +++--- packages/bcp/types/encode.d.ts | 12 ++--- packages/cli/README.md | 4 +- packages/cli/examples/local_faucet.ts | 2 +- packages/cli/examples/mask.ts | 8 +-- packages/cli/src/cli.ts | 10 +++- .../src/cosmwasmclient.searchtx.spec.ts | 3 +- packages/cosmwasm/src/cosmwasmclient.spec.ts | 3 +- packages/cosmwasm/src/cosmwasmclient.ts | 4 +- packages/cosmwasm/src/restclient.spec.ts | 4 +- packages/cosmwasm/src/restclient.ts | 4 +- .../cosmwasm/src/signingcosmwasmclient.ts | 3 +- packages/cosmwasm/src/types.ts | 54 ------------------- packages/cosmwasm/types/cosmwasmclient.d.ts | 4 +- packages/cosmwasm/types/restclient.d.ts | 4 +- .../cosmwasm/types/signingcosmwasmclient.d.ts | 3 +- packages/cosmwasm/types/types.d.ts | 35 ------------ packages/sdk38/src/index.ts | 14 ++++- packages/sdk38/types/index.d.ts | 14 ++++- 24 files changed, 111 insertions(+), 164 deletions(-) diff --git a/packages/bcp/src/address.ts b/packages/bcp/src/address.ts index c0cb7b9a..4396357a 100644 --- a/packages/bcp/src/address.ts +++ b/packages/bcp/src/address.ts @@ -1,4 +1,4 @@ -import { pubkeyToAddress as sdkPubkeyToAddress, types } from "@cosmwasm/sdk38"; +import { PubKey, pubkeyToAddress as sdkPubkeyToAddress, pubkeyType } from "@cosmwasm/sdk38"; import { Address, Algorithm, PubkeyBundle } from "@iov/bcp"; import { Secp256k1 } from "@iov/crypto"; import { Encoding } from "@iov/encoding"; @@ -7,15 +7,15 @@ const { toBase64 } = Encoding; // See https://github.com/tendermint/tendermint/blob/f2ada0a604b4c0763bda2f64fac53d506d3beca7/docs/spec/blockchain/encoding.md#public-key-cryptography export function pubkeyToAddress(pubkey: PubkeyBundle, prefix: string): Address { - let sdkKey: types.PubKey; + let sdkKey: PubKey; if (pubkey.algo === Algorithm.Secp256k1) { sdkKey = { - type: types.pubkeyType.secp256k1, + type: pubkeyType.secp256k1, value: toBase64(pubkey.data.length > 33 ? Secp256k1.compressPubkey(pubkey.data) : pubkey.data), }; } else if (pubkey.algo === Algorithm.Ed25519) { sdkKey = { - type: types.pubkeyType.ed25519, + type: pubkeyType.ed25519, value: toBase64(pubkey.data), }; } else { diff --git a/packages/bcp/src/cosmwasmconnection.ts b/packages/bcp/src/cosmwasmconnection.ts index 56e97ef6..b28c2c0f 100644 --- a/packages/bcp/src/cosmwasmconnection.ts +++ b/packages/bcp/src/cosmwasmconnection.ts @@ -4,7 +4,7 @@ import { isMsgInstantiateContract, isMsgStoreCode, } from "@cosmwasm/cosmwasm"; -import { findSequenceForSignedTx, IndexedTx, SearchTxFilter, types } from "@cosmwasm/sdk38"; +import { findSequenceForSignedTx, IndexedTx, isMsgSend, isStdTx, SearchTxFilter } from "@cosmwasm/sdk38"; import { Account, AccountQuery, @@ -278,7 +278,7 @@ export class CosmWasmConnection implements BlockchainConnection { public async postTx(tx: PostableBytes): Promise { const txAsJson = JSON.parse(Encoding.fromUtf8(tx)); - if (!types.isStdTx(txAsJson)) throw new Error("Postable bytes must contain a JSON encoded StdTx"); + if (!isStdTx(txAsJson)) throw new Error("Postable bytes must contain a JSON encoded StdTx"); const { transactionHash, rawLog } = await this.cosmWasmClient.postTx(txAsJson); const transactionId = transactionHash as TransactionId; const firstEvent: BlockInfo = { state: TransactionState.Pending }; @@ -479,7 +479,7 @@ export class CosmWasmConnection implements BlockchainConnection { if (!firstMsg) throw new Error("Got transaction without a first message. What is going on here?"); let senderAddress: string; - if (types.isMsgSend(firstMsg)) { + if (isMsgSend(firstMsg)) { senderAddress = firstMsg.value.from_address; } else if ( isMsgStoreCode(firstMsg) || diff --git a/packages/bcp/src/decode.spec.ts b/packages/bcp/src/decode.spec.ts index d40e178d..26e57a1f 100644 --- a/packages/bcp/src/decode.spec.ts +++ b/packages/bcp/src/decode.spec.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/camelcase */ import { MsgExecuteContract } from "@cosmwasm/cosmwasm"; -import { Coin, IndexedTx, types } from "@cosmwasm/sdk38"; +import { Coin, IndexedTx, PubKey, StdSignature, StdTx } from "@cosmwasm/sdk38"; +import { Msg } from "@cosmwasm/sdk38/types/types"; import { Address, Algorithm, isSendTransaction, SendTransaction, TokenTicker } from "@iov/bcp"; import { Encoding } from "@iov/encoding"; import { assert } from "@iov/utils"; @@ -85,7 +86,7 @@ describe("decode", () => { describe("decodePubkey", () => { it("works for secp256k1", () => { - const pubkey: types.PubKey = { + const pubkey: PubKey = { type: "tendermint/PubKeySecp256k1", value: "AtQaCqFnshaZQp6rIkvAPyzThvCvXSDO+9AzbxVErqJP", }; @@ -93,7 +94,7 @@ describe("decode", () => { }); it("works for ed25519", () => { - const pubkey: types.PubKey = { + const pubkey: PubKey = { type: "tendermint/PubKeyEd25519", value: "s69CnMgLTpuRyEfecjws3mWssBrOICUx8C2O1DkKSto=", }; @@ -105,7 +106,7 @@ describe("decode", () => { it("throws for unsupported types", () => { // https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/sr25519/codec.go#L12 - const pubkey: types.PubKey = { + const pubkey: PubKey = { type: "tendermint/PubKeySr25519", value: "N4FJNPE5r/Twz55kO1QEIxyaGF5/HTXH6WgLQJWsy1o=", }; @@ -123,7 +124,7 @@ describe("decode", () => { describe("decodeFullSignature", () => { it("works", () => { - const fullSignature: types.StdSignature = { + const fullSignature: StdSignature = { pub_key: { type: "tendermint/PubKeySecp256k1", value: "AtQaCqFnshaZQp6rIkvAPyzThvCvXSDO+9AzbxVErqJP", @@ -146,7 +147,7 @@ describe("decode", () => { describe("parseMsg", () => { it("works for bank send transaction", () => { - const msg: types.Msg = { + const msg: Msg = { type: "cosmos-sdk/MsgSend", value: { from_address: "cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r", @@ -233,7 +234,7 @@ describe("decode", () => { sent_funds: [], }, }; - const tx: types.StdTx = { + const tx: StdTx = { msg: [msg], memo: defaultMemo, fee: { diff --git a/packages/bcp/src/decode.ts b/packages/bcp/src/decode.ts index 0adc918b..c8a91626 100644 --- a/packages/bcp/src/decode.ts +++ b/packages/bcp/src/decode.ts @@ -1,5 +1,6 @@ import { isMsgExecuteContract } from "@cosmwasm/cosmwasm"; -import { Coin, IndexedTx, types } from "@cosmwasm/sdk38"; +import { Coin, IndexedTx, PubKey, StdSignature } from "@cosmwasm/sdk38"; +import { isMsgSend, isStdTx, Msg, pubkeyType, StdFee, StdTx } from "@cosmwasm/sdk38/types/types"; import { Address, Algorithm, @@ -26,14 +27,14 @@ import { BankToken, Erc20Token } from "./types"; const { fromBase64 } = Encoding; -export function decodePubkey(pubkey: types.PubKey): PubkeyBundle { +export function decodePubkey(pubkey: PubKey): PubkeyBundle { switch (pubkey.type) { - case types.pubkeyType.secp256k1: + case pubkeyType.secp256k1: return { algo: Algorithm.Secp256k1, data: fromBase64(pubkey.value) as PubkeyBytes, }; - case types.pubkeyType.ed25519: + case pubkeyType.ed25519: return { algo: Algorithm.Ed25519, data: fromBase64(pubkey.value) as PubkeyBytes, @@ -47,7 +48,7 @@ export function decodeSignature(signature: string): SignatureBytes { return fromBase64(signature) as SignatureBytes; } -export function decodeFullSignature(signature: types.StdSignature, nonce: number): FullSignature { +export function decodeFullSignature(signature: StdSignature, nonce: number): FullSignature { return { nonce: nonce as Nonce, pubkey: decodePubkey(signature.pub_key), @@ -74,13 +75,13 @@ export function decodeAmount(tokens: readonly BankToken[], coin: Coin): Amount { } export function parseMsg( - msg: types.Msg, + msg: Msg, memo: string | undefined, chainId: ChainId, tokens: readonly BankToken[], erc20Tokens: readonly Erc20Token[], ): UnsignedTransaction { - if (types.isMsgSend(msg)) { + if (isMsgSend(msg)) { if (msg.value.amount.length !== 1) { throw new Error("Only MsgSend with one amount is supported"); } @@ -131,7 +132,7 @@ export function parseMsg( } } -export function parseFee(fee: types.StdFee, tokens: readonly BankToken[]): Fee { +export function parseFee(fee: StdFee, tokens: readonly BankToken[]): Fee { if (fee.amount.length !== 1) { throw new Error("Only fee with one amount is supported"); } @@ -142,12 +143,12 @@ export function parseFee(fee: types.StdFee, tokens: readonly BankToken[]): Fee { } export function parseUnsignedTx( - txValue: types.StdTx, + txValue: StdTx, chainId: ChainId, tokens: readonly BankToken[], erc20Tokens: readonly Erc20Token[], ): UnsignedTransaction { - if (!types.isStdTx(txValue)) { + if (!isStdTx(txValue)) { throw new Error("Only StdTx is supported"); } if (txValue.msg.length !== 1) { @@ -165,7 +166,7 @@ export function parseUnsignedTx( } export function parseSignedTx( - txValue: types.StdTx, + txValue: StdTx, chainId: ChainId, nonce: Nonce, tokens: readonly BankToken[], diff --git a/packages/bcp/src/encode.ts b/packages/bcp/src/encode.ts index 61006eeb..f8820a2a 100644 --- a/packages/bcp/src/encode.ts +++ b/packages/bcp/src/encode.ts @@ -1,5 +1,14 @@ /* eslint-disable @typescript-eslint/camelcase */ -import { Coin, encodeSecp256k1Pubkey, encodeSecp256k1Signature, types } from "@cosmwasm/sdk38"; +import { + Coin, + CosmosSdkTx, + encodeSecp256k1Pubkey, + encodeSecp256k1Signature, + PubKey, + pubkeyType, + StdFee, + StdSignature, +} from "@cosmwasm/sdk38"; import { Algorithm, Amount, @@ -18,13 +27,13 @@ import { BankToken, Erc20Token } from "./types"; const { toBase64 } = Encoding; // TODO: This function seems to be unused and is not well tested (e.g. uncompressed secp256k1 or ed25519) -export function encodePubkey(pubkey: PubkeyBundle): types.PubKey { +export function encodePubkey(pubkey: PubkeyBundle): PubKey { switch (pubkey.algo) { case Algorithm.Secp256k1: return encodeSecp256k1Pubkey(pubkey.data); case Algorithm.Ed25519: return { - type: types.pubkeyType.ed25519, + type: pubkeyType.ed25519, value: toBase64(pubkey.data), }; default: @@ -54,7 +63,7 @@ export function toBankCoin(amount: Amount, tokens: readonly BankToken[]): Coin { }; } -export function encodeFee(fee: Fee, tokens: readonly BankToken[]): types.StdFee { +export function encodeFee(fee: Fee, tokens: readonly BankToken[]): StdFee { if (fee.tokens === undefined) { throw new Error("Cannot encode fee without tokens"); } @@ -67,7 +76,7 @@ export function encodeFee(fee: Fee, tokens: readonly BankToken[]): types.StdFee }; } -export function encodeFullSignature(fullSignature: FullSignature): types.StdSignature { +export function encodeFullSignature(fullSignature: FullSignature): StdSignature { switch (fullSignature.pubkey.algo) { case Algorithm.Secp256k1: { const compressedPubkey = Secp256k1.compressPubkey(fullSignature.pubkey.data); @@ -83,7 +92,7 @@ export function buildUnsignedTx( tx: UnsignedTransaction, bankTokens: readonly BankToken[], erc20Tokens: readonly Erc20Token[] = [], -): types.CosmosSdkTx { +): CosmosSdkTx { if (!isSendTransaction(tx)) { throw new Error("Received transaction of unsupported kind"); } @@ -146,7 +155,7 @@ export function buildSignedTx( tx: SignedTransaction, bankTokens: readonly BankToken[], erc20Tokens: readonly Erc20Token[] = [], -): types.CosmosSdkTx { +): CosmosSdkTx { const built = buildUnsignedTx(tx.transaction, bankTokens, erc20Tokens); return { ...built, diff --git a/packages/bcp/types/decode.d.ts b/packages/bcp/types/decode.d.ts index cc52190a..ae0da97d 100644 --- a/packages/bcp/types/decode.d.ts +++ b/packages/bcp/types/decode.d.ts @@ -1,4 +1,5 @@ -import { Coin, IndexedTx, types } from "@cosmwasm/sdk38"; +import { Coin, IndexedTx, PubKey, StdSignature } from "@cosmwasm/sdk38"; +import { Msg, StdFee, StdTx } from "@cosmwasm/sdk38/types/types"; import { Amount, ChainId, @@ -14,27 +15,27 @@ import { } from "@iov/bcp"; import { Decimal } from "@iov/encoding"; import { BankToken, Erc20Token } from "./types"; -export declare function decodePubkey(pubkey: types.PubKey): PubkeyBundle; +export declare function decodePubkey(pubkey: PubKey): PubkeyBundle; export declare function decodeSignature(signature: string): SignatureBytes; -export declare function decodeFullSignature(signature: types.StdSignature, nonce: number): FullSignature; +export declare function decodeFullSignature(signature: StdSignature, nonce: number): FullSignature; export declare function coinToDecimal(tokens: readonly BankToken[], coin: Coin): readonly [Decimal, string]; export declare function decodeAmount(tokens: readonly BankToken[], coin: Coin): Amount; export declare function parseMsg( - msg: types.Msg, + msg: Msg, memo: string | undefined, chainId: ChainId, tokens: readonly BankToken[], erc20Tokens: readonly Erc20Token[], ): UnsignedTransaction; -export declare function parseFee(fee: types.StdFee, tokens: readonly BankToken[]): Fee; +export declare function parseFee(fee: StdFee, tokens: readonly BankToken[]): Fee; export declare function parseUnsignedTx( - txValue: types.StdTx, + txValue: StdTx, chainId: ChainId, tokens: readonly BankToken[], erc20Tokens: readonly Erc20Token[], ): UnsignedTransaction; export declare function parseSignedTx( - txValue: types.StdTx, + txValue: StdTx, chainId: ChainId, nonce: Nonce, tokens: readonly BankToken[], diff --git a/packages/bcp/types/encode.d.ts b/packages/bcp/types/encode.d.ts index 316e09d2..af4033d4 100644 --- a/packages/bcp/types/encode.d.ts +++ b/packages/bcp/types/encode.d.ts @@ -1,18 +1,18 @@ -import { Coin, types } from "@cosmwasm/sdk38"; +import { Coin, CosmosSdkTx, PubKey, StdFee, StdSignature } from "@cosmwasm/sdk38"; import { Amount, Fee, FullSignature, PubkeyBundle, SignedTransaction, UnsignedTransaction } from "@iov/bcp"; import { BankToken, Erc20Token } from "./types"; -export declare function encodePubkey(pubkey: PubkeyBundle): types.PubKey; +export declare function encodePubkey(pubkey: PubkeyBundle): PubKey; export declare function toErc20Amount(amount: Amount, erc20Token: Erc20Token): string; export declare function toBankCoin(amount: Amount, tokens: readonly BankToken[]): Coin; -export declare function encodeFee(fee: Fee, tokens: readonly BankToken[]): types.StdFee; -export declare function encodeFullSignature(fullSignature: FullSignature): types.StdSignature; +export declare function encodeFee(fee: Fee, tokens: readonly BankToken[]): StdFee; +export declare function encodeFullSignature(fullSignature: FullSignature): StdSignature; export declare function buildUnsignedTx( tx: UnsignedTransaction, bankTokens: readonly BankToken[], erc20Tokens?: readonly Erc20Token[], -): types.CosmosSdkTx; +): CosmosSdkTx; export declare function buildSignedTx( tx: SignedTransaction, bankTokens: readonly BankToken[], erc20Tokens?: readonly Erc20Token[], -): types.CosmosSdkTx; +): CosmosSdkTx; diff --git a/packages/cli/README.md b/packages/cli/README.md index e9d512f8..e9bb0653 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -50,7 +50,7 @@ const { account_number, sequence } = (await client.authAccounts(faucetAddress)). // Craft a send transaction const emptyAddress = Bech32.encode("cosmos", Random.getBytes(20)); const memo = "My first contract on chain"; -const sendTokensMsg: types.MsgSend = { +const sendTokensMsg: MsgSend = { type: "cosmos-sdk/MsgSend", value: { from_address: faucetAddress, @@ -66,7 +66,7 @@ const sendTokensMsg: types.MsgSend = { const signBytes = makeSignBytes([sendTokensMsg], defaultFee, defaultNetworkId, memo, account_number, sequence); const signature = await pen.sign(signBytes); -const signedTx: types.StdTx = { +const signedTx: StdTx = { msg: [sendTokensMsg], fee: defaultFee, memo: memo, diff --git a/packages/cli/examples/local_faucet.ts b/packages/cli/examples/local_faucet.ts index 21199c9c..77a447b6 100644 --- a/packages/cli/examples/local_faucet.ts +++ b/packages/cli/examples/local_faucet.ts @@ -1,6 +1,6 @@ const defaultHttpUrl = "http://localhost:1317"; const defaultNetworkId = "testing"; -const defaultFee: types.StdFee = { +const defaultFee: StdFee = { amount: [ { amount: "5000", diff --git a/packages/cli/examples/mask.ts b/packages/cli/examples/mask.ts index b1a4f4cb..7a36b0ba 100644 --- a/packages/cli/examples/mask.ts +++ b/packages/cli/examples/mask.ts @@ -5,7 +5,7 @@ export type HandleMsg = msgs: ( | { send: { - amount: types.Coin[]; + amount: Coin[]; from_address: string; to_address: string; }; @@ -15,7 +15,7 @@ export type HandleMsg = contract_addr: string; // this had to be changed - is Base64 encoded string msg: string; - send: types.Coin[] | null; + send: Coin[] | null; }; } | { @@ -53,7 +53,7 @@ export interface State { const base64Msg = (msg: object): string => toBase64(toUtf8(JSON.stringify(msg))); -const sendMsg = (from_address: string, to_address: string, amount: types.Coin[]) => { +const sendMsg = (from_address: string, to_address: string, amount: Coin[]) => { return { send: { from_address, @@ -63,7 +63,7 @@ const sendMsg = (from_address: string, to_address: string, amount: types.Coin[]) }; } -const contractMsg = (contract_addr: string, msg: object, amount?: types.Coin[]) => { +const contractMsg = (contract_addr: string, msg: object, amount?: Coin[]) => { return { contract: { contract_addr, diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 83932e1f..f6a6c0c2 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -62,18 +62,24 @@ export function main(originalArgs: readonly string[]): void { [ "@cosmwasm/sdk38", [ + "coin", + "coins", "encodeSecp256k1Pubkey", "encodeSecp256k1Signature", "logs", "makeCosmoshubPath", "makeSignBytes", "marshalTx", + "IndexedTx", + "Coin", + "MsgSend", "Pen", + "PubKey", "pubkeyToAddress", "RestClient", "Secp256k1Pen", - "types", - "IndexedTx", + "StdFee", + "StdTx", ], ], [ diff --git a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts index 431ed96f..4a152dd5 100644 --- a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/camelcase */ -import { Coin, makeSignBytes, Secp256k1Pen } from "@cosmwasm/sdk38"; +import { Coin, CosmosSdkTx, makeSignBytes, Secp256k1Pen } from "@cosmwasm/sdk38"; import { assert, sleep } from "@iov/utils"; import { CosmWasmClient } from "./cosmwasmclient"; @@ -15,7 +15,6 @@ import { wasmd, wasmdEnabled, } from "./testutils.spec"; -import { CosmosSdkTx } from "./types"; describe("CosmWasmClient.searchTx", () => { let sendSuccessful: diff --git a/packages/cosmwasm/src/cosmwasmclient.spec.ts b/packages/cosmwasm/src/cosmwasmclient.spec.ts index 6fffd7b7..c9998ec8 100644 --- a/packages/cosmwasm/src/cosmwasmclient.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.spec.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/camelcase */ -import { makeSignBytes, Secp256k1Pen } from "@cosmwasm/sdk38"; +import { makeSignBytes, Secp256k1Pen, StdFee } from "@cosmwasm/sdk38"; import { Sha256 } from "@iov/crypto"; import { Bech32, Encoding } from "@iov/encoding"; import { assert, sleep } from "@iov/utils"; @@ -21,7 +21,6 @@ import { wasmd, wasmdEnabled, } from "./testutils.spec"; -import { StdFee } from "./types"; const { fromHex, fromUtf8, toAscii, toBase64 } = Encoding; diff --git a/packages/cosmwasm/src/cosmwasmclient.ts b/packages/cosmwasm/src/cosmwasmclient.ts index 16f438a1..991fa633 100644 --- a/packages/cosmwasm/src/cosmwasmclient.ts +++ b/packages/cosmwasm/src/cosmwasmclient.ts @@ -1,10 +1,10 @@ -import { Coin, decodeBech32Pubkey, IndexedTx } from "@cosmwasm/sdk38"; +import { Coin, CosmosSdkTx, decodeBech32Pubkey, IndexedTx, PubKey, StdTx } from "@cosmwasm/sdk38"; import { Sha256 } from "@iov/crypto"; import { Encoding } from "@iov/encoding"; import { Log, parseLogs } from "./logs"; import { BroadcastMode, RestClient } from "./restclient"; -import { CosmosSdkTx, JsonObject, PubKey, StdTx } from "./types"; +import { JsonObject } from "./types"; export interface GetNonceResult { readonly accountNumber: number; diff --git a/packages/cosmwasm/src/restclient.spec.ts b/packages/cosmwasm/src/restclient.spec.ts index c006d5bb..1fe1d856 100644 --- a/packages/cosmwasm/src/restclient.spec.ts +++ b/packages/cosmwasm/src/restclient.spec.ts @@ -7,6 +7,9 @@ import { Pen, rawSecp256k1PubkeyToAddress, Secp256k1Pen, + StdFee, + StdSignature, + StdTx, } from "@cosmwasm/sdk38"; import { Sha256 } from "@iov/crypto"; import { Encoding } from "@iov/encoding"; @@ -44,7 +47,6 @@ import { wasmd, wasmdEnabled, } from "./testutils.spec"; -import { StdFee, StdSignature, StdTx } from "./types"; const { fromAscii, fromBase64, fromHex, toAscii, toBase64, toHex } = Encoding; diff --git a/packages/cosmwasm/src/restclient.ts b/packages/cosmwasm/src/restclient.ts index 0e5846c8..06c0c131 100644 --- a/packages/cosmwasm/src/restclient.ts +++ b/packages/cosmwasm/src/restclient.ts @@ -1,8 +1,8 @@ -import { Coin } from "@cosmwasm/sdk38"; +import { Coin, CosmosSdkTx, StdTx } from "@cosmwasm/sdk38"; import { Encoding, isNonNullObject } from "@iov/encoding"; import axios, { AxiosError, AxiosInstance } from "axios"; -import { CosmosSdkTx, JsonObject, Model, parseWasmData, StdTx, WasmData } from "./types"; +import { JsonObject, Model, parseWasmData, WasmData } from "./types"; const { fromBase64, fromUtf8, toHex, toUtf8 } = Encoding; diff --git a/packages/cosmwasm/src/signingcosmwasmclient.ts b/packages/cosmwasm/src/signingcosmwasmclient.ts index 99eed14c..9c44fd09 100644 --- a/packages/cosmwasm/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm/src/signingcosmwasmclient.ts @@ -1,4 +1,4 @@ -import { Coin, coins, makeSignBytes } from "@cosmwasm/sdk38"; +import { Coin, coins, makeSignBytes, StdFee, StdSignature } from "@cosmwasm/sdk38"; import { Sha256 } from "@iov/crypto"; import { Encoding } from "@iov/encoding"; import pako from "pako"; @@ -8,7 +8,6 @@ import { Account, CosmWasmClient, GetNonceResult, PostTxResult } from "./cosmwas import { findAttribute, Log } from "./logs"; import { MsgExecuteContract, MsgInstantiateContract, MsgSend, MsgStoreCode } from "./msgs"; import { BroadcastMode } from "./restclient"; -import { StdFee, StdSignature } from "./types"; export interface SigningCallback { (signBytes: Uint8Array): Promise; diff --git a/packages/cosmwasm/src/types.ts b/packages/cosmwasm/src/types.ts index 59c9a112..3bcfb2c9 100644 --- a/packages/cosmwasm/src/types.ts +++ b/packages/cosmwasm/src/types.ts @@ -1,61 +1,7 @@ -import { Coin } from "@cosmwasm/sdk38"; import { Encoding } from "@iov/encoding"; -import { Msg } from "./msgs"; - const { fromBase64, fromHex } = Encoding; -/** An Amino/Cosmos SDK StdTx */ -export interface StdTx { - readonly msg: ReadonlyArray; - readonly fee: StdFee; - readonly signatures: ReadonlyArray; - readonly memo: string | undefined; -} - -export function isStdTx(txValue: unknown): txValue is StdTx { - const { memo, msg, fee, signatures } = txValue as StdTx; - return ( - typeof memo === "string" && Array.isArray(msg) && typeof fee === "object" && Array.isArray(signatures) - ); -} - -export interface CosmosSdkTx { - readonly type: string; - readonly value: StdTx; -} - -export interface StdFee { - readonly amount: ReadonlyArray; - readonly gas: string; -} - -export interface StdSignature { - readonly pub_key: PubKey; - readonly signature: string; -} - -export interface PubKey { - // type is one of the strings defined in pubkeyTypes - // I don't use a string literal union here as that makes trouble with json test data: - // https://github.com/confio/cosmwasm-js/pull/44#pullrequestreview-353280504 - readonly type: string; - // Value field is base64-encoded in all cases - // Note: if type is Secp256k1, this must contain a COMPRESSED pubkey - to encode from bcp/keycontrol land, you must compress it first - readonly value: string; -} - -export const pubkeyType = { - /** @see https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/ed25519/ed25519.go#L22 */ - secp256k1: "tendermint/PubKeySecp256k1" as const, - /** @see https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/secp256k1/secp256k1.go#L23 */ - ed25519: "tendermint/PubKeyEd25519" as const, - /** @see https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/sr25519/codec.go#L12 */ - sr25519: "tendermint/PubKeySr25519" as const, -}; - -export const pubkeyTypes: readonly string[] = [pubkeyType.secp256k1, pubkeyType.ed25519, pubkeyType.sr25519]; - export interface WasmData { // key is hex-encoded readonly key: string; diff --git a/packages/cosmwasm/types/cosmwasmclient.d.ts b/packages/cosmwasm/types/cosmwasmclient.d.ts index d12633cc..4978b694 100644 --- a/packages/cosmwasm/types/cosmwasmclient.d.ts +++ b/packages/cosmwasm/types/cosmwasmclient.d.ts @@ -1,7 +1,7 @@ -import { Coin, IndexedTx } from "@cosmwasm/sdk38"; +import { Coin, CosmosSdkTx, IndexedTx, PubKey, StdTx } from "@cosmwasm/sdk38"; import { Log } from "./logs"; import { BroadcastMode, RestClient } from "./restclient"; -import { CosmosSdkTx, JsonObject, PubKey, StdTx } from "./types"; +import { JsonObject } from "./types"; export interface GetNonceResult { readonly accountNumber: number; readonly sequence: number; diff --git a/packages/cosmwasm/types/restclient.d.ts b/packages/cosmwasm/types/restclient.d.ts index 2c914be4..3bf65fe2 100644 --- a/packages/cosmwasm/types/restclient.d.ts +++ b/packages/cosmwasm/types/restclient.d.ts @@ -1,5 +1,5 @@ -import { Coin } from "@cosmwasm/sdk38"; -import { CosmosSdkTx, JsonObject, Model, StdTx } from "./types"; +import { Coin, CosmosSdkTx, StdTx } from "@cosmwasm/sdk38"; +import { JsonObject, Model } from "./types"; export interface CosmosSdkAccount { /** Bech32 account address */ readonly address: string; diff --git a/packages/cosmwasm/types/signingcosmwasmclient.d.ts b/packages/cosmwasm/types/signingcosmwasmclient.d.ts index d3f9e00e..75bd9b76 100644 --- a/packages/cosmwasm/types/signingcosmwasmclient.d.ts +++ b/packages/cosmwasm/types/signingcosmwasmclient.d.ts @@ -1,8 +1,7 @@ -import { Coin } from "@cosmwasm/sdk38"; +import { Coin, StdFee, StdSignature } from "@cosmwasm/sdk38"; import { Account, CosmWasmClient, GetNonceResult, PostTxResult } from "./cosmwasmclient"; import { Log } from "./logs"; import { BroadcastMode } from "./restclient"; -import { StdFee, StdSignature } from "./types"; export interface SigningCallback { (signBytes: Uint8Array): Promise; } diff --git a/packages/cosmwasm/types/types.d.ts b/packages/cosmwasm/types/types.d.ts index b7d54776..45d870c7 100644 --- a/packages/cosmwasm/types/types.d.ts +++ b/packages/cosmwasm/types/types.d.ts @@ -1,38 +1,3 @@ -import { Coin } from "@cosmwasm/sdk38"; -import { Msg } from "./msgs"; -/** An Amino/Cosmos SDK StdTx */ -export interface StdTx { - readonly msg: ReadonlyArray; - readonly fee: StdFee; - readonly signatures: ReadonlyArray; - readonly memo: string | undefined; -} -export declare function isStdTx(txValue: unknown): txValue is StdTx; -export interface CosmosSdkTx { - readonly type: string; - readonly value: StdTx; -} -export interface StdFee { - readonly amount: ReadonlyArray; - readonly gas: string; -} -export interface StdSignature { - readonly pub_key: PubKey; - readonly signature: string; -} -export interface PubKey { - readonly type: string; - readonly value: string; -} -export declare const pubkeyType: { - /** @see https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/ed25519/ed25519.go#L22 */ - secp256k1: "tendermint/PubKeySecp256k1"; - /** @see https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/secp256k1/secp256k1.go#L23 */ - ed25519: "tendermint/PubKeyEd25519"; - /** @see https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/sr25519/codec.go#L12 */ - sr25519: "tendermint/PubKeySr25519"; -}; -export declare const pubkeyTypes: readonly string[]; export interface WasmData { readonly key: string; readonly val: string; diff --git a/packages/sdk38/src/index.ts b/packages/sdk38/src/index.ts index d67248bf..b1f290f7 100644 --- a/packages/sdk38/src/index.ts +++ b/packages/sdk38/src/index.ts @@ -1,6 +1,5 @@ import * as logs from "./logs"; -import * as types from "./types"; -export { logs, types }; +export { logs }; export { pubkeyToAddress, rawSecp256k1PubkeyToAddress } from "./address"; export { Coin, coin, coins } from "./coins"; @@ -32,3 +31,14 @@ export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from ". export { findSequenceForSignedTx } from "./sequence"; export { encodeSecp256k1Signature, decodeSignature } from "./signature"; export { FeeTable, SigningCallback, SigningCosmosClient } from "./signingcosmosclient"; +export { + isMsgSend, + isStdTx, + pubkeyType, + CosmosSdkTx, + PubKey, + MsgSend, + StdFee, + StdSignature, + StdTx, +} from "./types"; diff --git a/packages/sdk38/types/index.d.ts b/packages/sdk38/types/index.d.ts index 78a73f2e..424559eb 100644 --- a/packages/sdk38/types/index.d.ts +++ b/packages/sdk38/types/index.d.ts @@ -1,6 +1,5 @@ import * as logs from "./logs"; -import * as types from "./types"; -export { logs, types }; +export { logs }; export { pubkeyToAddress, rawSecp256k1PubkeyToAddress } from "./address"; export { Coin, coin, coins } from "./coins"; export { @@ -30,3 +29,14 @@ export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from ". export { findSequenceForSignedTx } from "./sequence"; export { encodeSecp256k1Signature, decodeSignature } from "./signature"; export { FeeTable, SigningCallback, SigningCosmosClient } from "./signingcosmosclient"; +export { + isMsgSend, + isStdTx, + pubkeyType, + CosmosSdkTx, + PubKey, + MsgSend, + StdFee, + StdSignature, + StdTx, +} from "./types";