From efb90d1f65cb31761645457b0c2631023b1aab56 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 2 Jun 2020 13:45:19 +0200 Subject: [PATCH] Sort some types between sdk38 and cosmwasm --- .../src/cosmwasmclient.searchtx.spec.ts | 5 +- packages/cosmwasm/src/cosmwasmclient.spec.ts | 5 +- packages/cosmwasm/src/cosmwasmclient.ts | 21 +---- packages/cosmwasm/src/index.ts | 13 ++- packages/cosmwasm/src/msgs.ts | 93 ++++++++++++++++++ packages/cosmwasm/src/pubkey.spec.ts | 57 ----------- packages/cosmwasm/src/pubkey.ts | 71 -------------- packages/cosmwasm/src/restclient.spec.ts | 33 ++++--- .../cosmwasm/src/signingcosmwasmclient.ts | 10 +- packages/cosmwasm/src/types.ts | 94 +------------------ packages/cosmwasm/types/cosmwasmclient.d.ts | 19 +--- packages/cosmwasm/types/index.d.ts | 13 ++- packages/cosmwasm/types/msgs.d.ts | 76 +++++++++++++++ packages/cosmwasm/types/pubkey.d.ts | 4 - packages/cosmwasm/types/types.d.ts | 76 +-------------- packages/sdk38/src/index.ts | 21 +++++ packages/sdk38/src/signingcosmosclient.ts | 38 -------- packages/sdk38/types/index.d.ts | 20 ++++ packages/sdk38/types/signingcosmosclient.d.ts | 34 ------- 19 files changed, 260 insertions(+), 443 deletions(-) create mode 100644 packages/cosmwasm/src/msgs.ts delete mode 100644 packages/cosmwasm/src/pubkey.spec.ts delete mode 100644 packages/cosmwasm/src/pubkey.ts create mode 100644 packages/cosmwasm/types/msgs.d.ts delete mode 100644 packages/cosmwasm/types/pubkey.d.ts diff --git a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts index 1b92ecba1e..431ed96fb6 100644 --- a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts @@ -1,8 +1,9 @@ /* eslint-disable @typescript-eslint/camelcase */ -import { Coin, Secp256k1Pen, makeSignBytes } from "@cosmwasm/sdk38"; +import { Coin, makeSignBytes, Secp256k1Pen } from "@cosmwasm/sdk38"; import { assert, sleep } from "@iov/utils"; import { CosmWasmClient } from "./cosmwasmclient"; +import { isMsgExecuteContract, isMsgInstantiateContract, isMsgSend, MsgSend } from "./msgs"; import { RestClient } from "./restclient"; import { SigningCosmWasmClient } from "./signingcosmwasmclient"; import { @@ -14,7 +15,7 @@ import { wasmd, wasmdEnabled, } from "./testutils.spec"; -import { CosmosSdkTx, isMsgExecuteContract, isMsgInstantiateContract, isMsgSend, MsgSend } from "./types"; +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 7c4904ed6b..6fffd7b770 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 { Secp256k1Pen, makeSignBytes } from "@cosmwasm/sdk38"; +import { makeSignBytes, Secp256k1Pen } from "@cosmwasm/sdk38"; import { Sha256 } from "@iov/crypto"; import { Bech32, Encoding } from "@iov/encoding"; import { assert, sleep } from "@iov/utils"; @@ -7,6 +7,7 @@ import { ReadonlyDate } from "readonly-date"; import { Code, CosmWasmClient, PrivateCosmWasmClient } from "./cosmwasmclient"; import { findAttribute } from "./logs"; +import { MsgSend } from "./msgs"; import { SigningCosmWasmClient } from "./signingcosmwasmclient"; import cosmoshub from "./testdata/cosmoshub.json"; import { @@ -20,7 +21,7 @@ import { wasmd, wasmdEnabled, } from "./testutils.spec"; -import { MsgSend, StdFee } from "./types"; +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 04c30d3c3c..16f438a173 100644 --- a/packages/cosmwasm/src/cosmwasmclient.ts +++ b/packages/cosmwasm/src/cosmwasmclient.ts @@ -1,9 +1,8 @@ -import { Coin } from "@cosmwasm/sdk38"; +import { Coin, decodeBech32Pubkey, IndexedTx } from "@cosmwasm/sdk38"; import { Sha256 } from "@iov/crypto"; import { Encoding } from "@iov/encoding"; import { Log, parseLogs } from "./logs"; -import { decodeBech32Pubkey } from "./pubkey"; import { BroadcastMode, RestClient } from "./restclient"; import { CosmosSdkTx, JsonObject, PubKey, StdTx } from "./types"; @@ -103,24 +102,6 @@ export interface ContractDetails extends Contract { readonly initMsg: object; } -/** A transaction that is indexed as part of the transaction history */ -export interface IndexedTx { - readonly height: number; - /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ - readonly hash: string; - /** Transaction execution error code. 0 on success. */ - readonly code: number; - readonly rawLog: string; - readonly logs: readonly Log[]; - readonly tx: CosmosSdkTx; - /** The gas limit as set by the user */ - readonly gasWanted?: number; - /** The gas used by the execution */ - readonly gasUsed?: number; - /** An RFC 3339 time string like e.g. '2020-02-15T10:39:10.4696305Z' */ - readonly timestamp: string; -} - export interface BlockHeader { readonly version: { readonly block: string; diff --git a/packages/cosmwasm/src/index.ts b/packages/cosmwasm/src/index.ts index 1a1892373d..1c03de9bde 100644 --- a/packages/cosmwasm/src/index.ts +++ b/packages/cosmwasm/src/index.ts @@ -1,6 +1,5 @@ import * as logs from "./logs"; -import * as types from "./types"; -export { logs, types }; +export { logs }; export { BroadcastMode, RestClient, TxsResponse } from "./restclient"; export { @@ -13,7 +12,6 @@ export { ContractDetails, CosmWasmClient, GetNonceResult, - IndexedTx, PostTxResult, SearchByHeightQuery, SearchByIdQuery, @@ -22,7 +20,6 @@ export { SearchTxQuery, SearchTxFilter, } from "./cosmwasmclient"; -export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey"; export { ExecuteResult, FeeTable, @@ -32,3 +29,11 @@ export { UploadMeta, UploadResult, } from "./signingcosmwasmclient"; +export { + isMsgExecuteContract, + isMsgInstantiateContract, + isMsgStoreCode, + MsgStoreCode, + MsgExecuteContract, + MsgInstantiateContract, +} from "./msgs"; diff --git a/packages/cosmwasm/src/msgs.ts b/packages/cosmwasm/src/msgs.ts new file mode 100644 index 0000000000..bf47a18c26 --- /dev/null +++ b/packages/cosmwasm/src/msgs.ts @@ -0,0 +1,93 @@ +import { Coin } from "@cosmwasm/sdk38"; + +interface MsgTemplate { + readonly type: string; + readonly value: any; +} + +/** A Cosmos SDK token transfer message */ +export interface MsgSend extends MsgTemplate { + readonly type: "cosmos-sdk/MsgSend"; + readonly value: { + /** Bech32 account address */ + readonly from_address: string; + /** Bech32 account address */ + readonly to_address: string; + readonly amount: ReadonlyArray; + }; +} + +/** + * Uploads Wam code to the chain + * + * @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L17 + */ +export interface MsgStoreCode extends MsgTemplate { + readonly type: "wasm/store-code"; + readonly value: { + /** Bech32 account address */ + readonly sender: string; + /** Base64 encoded Wasm */ + readonly wasm_byte_code: string; + /** A valid URI reference to the contract's source code. Can be empty. */ + readonly source: string; + /** A docker tag. Can be empty. */ + readonly builder: string; + }; +} + +/** + * Creates an instance of contract that was uploaded before. + * + * @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L73 + */ +export interface MsgInstantiateContract extends MsgTemplate { + readonly type: "wasm/instantiate"; + readonly value: { + /** Bech32 account address */ + readonly sender: string; + /** ID of the Wasm code that was uploaded before */ + readonly code_id: string; + /** Human-readable label for this contract */ + readonly label: string; + /** Init message as JavaScript object */ + readonly init_msg: any; + readonly init_funds: ReadonlyArray; + }; +} + +/** + * Creates an instance of contract that was uploaded before. + * + * @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L103 + */ +export interface MsgExecuteContract extends MsgTemplate { + readonly type: "wasm/execute"; + readonly value: { + /** Bech32 account address */ + readonly sender: string; + /** Bech32 account address */ + readonly contract: string; + /** Handle message as JavaScript object */ + readonly msg: any; + readonly sent_funds: ReadonlyArray; + }; +} + +export type Msg = MsgSend | MsgStoreCode | MsgInstantiateContract | MsgExecuteContract | MsgTemplate; + +export function isMsgSend(msg: Msg): msg is MsgSend { + return (msg as MsgSend).type === "cosmos-sdk/MsgSend"; +} + +export function isMsgStoreCode(msg: Msg): msg is MsgStoreCode { + return (msg as MsgStoreCode).type === "wasm/store-code"; +} + +export function isMsgInstantiateContract(msg: Msg): msg is MsgInstantiateContract { + return (msg as MsgInstantiateContract).type === "wasm/instantiate"; +} + +export function isMsgExecuteContract(msg: Msg): msg is MsgExecuteContract { + return (msg as MsgExecuteContract).type === "wasm/execute"; +} diff --git a/packages/cosmwasm/src/pubkey.spec.ts b/packages/cosmwasm/src/pubkey.spec.ts deleted file mode 100644 index cb344f7b1f..0000000000 --- a/packages/cosmwasm/src/pubkey.spec.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { Encoding } from "@iov/encoding"; - -import { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey"; -import { PubKey } from "./types"; - -const { fromBase64 } = Encoding; - -describe("pubkey", () => { - describe("encodeSecp256k1Pubkey", () => { - it("encodes a compresed pubkey", () => { - const pubkey = fromBase64("AtQaCqFnshaZQp6rIkvAPyzThvCvXSDO+9AzbxVErqJP"); - expect(encodeSecp256k1Pubkey(pubkey)).toEqual({ - type: "tendermint/PubKeySecp256k1", - value: "AtQaCqFnshaZQp6rIkvAPyzThvCvXSDO+9AzbxVErqJP", - }); - }); - - it("throws for uncompressed public keys", () => { - const pubkey = fromBase64( - "BE8EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQE7WHpoHoNswYeoFkuYpYSKK4mzFzMV/dB0DVAy4lnNU=", - ); - expect(() => encodeSecp256k1Pubkey(pubkey)).toThrowError(/public key must be compressed secp256k1/i); - }); - }); - - describe("decodeBech32Pubkey", () => { - it("works", () => { - expect( - decodeBech32Pubkey("cosmospub1addwnpepqd8sgxq7aw348ydctp3n5ajufgxp395hksxjzc6565yfp56scupfqhlgyg5"), - ).toEqual({ - type: "tendermint/PubKeySecp256k1", - value: "A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ", - }); - }); - - it("works for enigma pubkey", () => { - expect( - decodeBech32Pubkey("enigmapub1addwnpepqw5k9p439nw0zpg2aundx4umwx4nw233z5prpjqjv5anl5grmnchzp2xwvv"), - ).toEqual({ - type: "tendermint/PubKeySecp256k1", - value: "A6lihrEs3PEFCu8m01ebcas3KjEVAjDIEmU7P9ED3PFx", - }); - }); - }); - - describe("encodeBech32Pubkey", () => { - it("works for secp256k1", () => { - const pubkey: PubKey = { - type: "tendermint/PubKeySecp256k1", - value: "A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ", - }; - expect(encodeBech32Pubkey(pubkey, "cosmospub")).toEqual( - "cosmospub1addwnpepqd8sgxq7aw348ydctp3n5ajufgxp395hksxjzc6565yfp56scupfqhlgyg5", - ); - }); - }); -}); diff --git a/packages/cosmwasm/src/pubkey.ts b/packages/cosmwasm/src/pubkey.ts deleted file mode 100644 index 8835b97a54..0000000000 --- a/packages/cosmwasm/src/pubkey.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { Bech32, Encoding } from "@iov/encoding"; -import equal from "fast-deep-equal"; - -import { PubKey, pubkeyType } from "./types"; - -export function encodeSecp256k1Pubkey(pubkey: Uint8Array): PubKey { - if (pubkey.length !== 33 || (pubkey[0] !== 0x02 && pubkey[0] !== 0x03)) { - throw new Error("Public key must be compressed secp256k1, i.e. 33 bytes starting with 0x02 or 0x03"); - } - return { - type: pubkeyType.secp256k1, - value: Encoding.toBase64(pubkey), - }; -} - -// As discussed in https://github.com/binance-chain/javascript-sdk/issues/163 -// Prefixes listed here: https://github.com/tendermint/tendermint/blob/d419fffe18531317c28c29a292ad7d253f6cafdf/docs/spec/blockchain/encoding.md#public-key-cryptography -// Last bytes is varint-encoded length prefix -const pubkeyAminoPrefixSecp256k1 = Encoding.fromHex("eb5ae98721"); -const pubkeyAminoPrefixEd25519 = Encoding.fromHex("1624de6420"); -const pubkeyAminoPrefixSr25519 = Encoding.fromHex("0dfb1005"); -const pubkeyAminoPrefixLength = pubkeyAminoPrefixSecp256k1.length; - -export function decodeBech32Pubkey(bechEncoded: string): PubKey { - const { data } = Bech32.decode(bechEncoded); - - const aminoPrefix = data.slice(0, pubkeyAminoPrefixLength); - const rest = data.slice(pubkeyAminoPrefixLength); - if (equal(aminoPrefix, pubkeyAminoPrefixSecp256k1)) { - if (rest.length !== 33) { - throw new Error("Invalid rest data length. Expected 33 bytes (compressed secp256k1 pubkey)."); - } - return { - type: pubkeyType.secp256k1, - value: Encoding.toBase64(rest), - }; - } else if (equal(aminoPrefix, pubkeyAminoPrefixEd25519)) { - if (rest.length !== 32) { - throw new Error("Invalid rest data length. Expected 32 bytes (Ed25519 pubkey)."); - } - return { - type: pubkeyType.ed25519, - value: Encoding.toBase64(rest), - }; - } else if (equal(aminoPrefix, pubkeyAminoPrefixSr25519)) { - if (rest.length !== 32) { - throw new Error("Invalid rest data length. Expected 32 bytes (Sr25519 pubkey)."); - } - return { - type: pubkeyType.sr25519, - value: Encoding.toBase64(rest), - }; - } else { - throw new Error("Unsupported Pubkey type. Amino prefix: " + Encoding.toHex(aminoPrefix)); - } -} - -export function encodeBech32Pubkey(pubkey: PubKey, prefix: string): string { - let aminoPrefix: Uint8Array; - switch (pubkey.type) { - // Note: please don't add cases here without writing additional unit tests - case pubkeyType.secp256k1: - aminoPrefix = pubkeyAminoPrefixSecp256k1; - break; - default: - throw new Error("Unsupported pubkey type"); - } - - const data = new Uint8Array([...aminoPrefix, ...Encoding.fromBase64(pubkey.value)]); - return Bech32.encode(prefix, data); -} diff --git a/packages/cosmwasm/src/restclient.spec.ts b/packages/cosmwasm/src/restclient.spec.ts index dfe6739692..c006d5bb11 100644 --- a/packages/cosmwasm/src/restclient.spec.ts +++ b/packages/cosmwasm/src/restclient.spec.ts @@ -1,12 +1,28 @@ /* eslint-disable @typescript-eslint/camelcase */ -import { Coin, makeCosmoshubPath, Pen, rawSecp256k1PubkeyToAddress, Secp256k1Pen, makeSignBytes } from "@cosmwasm/sdk38"; +import { + Coin, + encodeBech32Pubkey, + makeCosmoshubPath, + makeSignBytes, + Pen, + rawSecp256k1PubkeyToAddress, + Secp256k1Pen, +} from "@cosmwasm/sdk38"; import { Sha256 } from "@iov/crypto"; import { Encoding } from "@iov/encoding"; import { assert, sleep } from "@iov/utils"; import { ReadonlyDate } from "readonly-date"; import { findAttribute, parseLogs } from "./logs"; -import { encodeBech32Pubkey } from "./pubkey"; +import { + isMsgInstantiateContract, + isMsgStoreCode, + Msg, + MsgExecuteContract, + MsgInstantiateContract, + MsgSend, + MsgStoreCode, +} from "./msgs"; import { PostTxsResponse, RestClient, TxsResponse } from "./restclient"; import { SigningCosmWasmClient } from "./signingcosmwasmclient"; import cosmoshub from "./testdata/cosmoshub.json"; @@ -28,18 +44,7 @@ import { wasmd, wasmdEnabled, } from "./testutils.spec"; -import { - isMsgInstantiateContract, - isMsgStoreCode, - Msg, - MsgExecuteContract, - MsgInstantiateContract, - MsgSend, - MsgStoreCode, - StdFee, - StdSignature, - StdTx, -} from "./types"; +import { StdFee, StdSignature, StdTx } from "./types"; const { fromAscii, fromBase64, fromHex, toAscii, toBase64, toHex } = Encoding; diff --git a/packages/cosmwasm/src/signingcosmwasmclient.ts b/packages/cosmwasm/src/signingcosmwasmclient.ts index bcdd29b0ac..99eed14c9a 100644 --- a/packages/cosmwasm/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm/src/signingcosmwasmclient.ts @@ -6,15 +6,9 @@ import pako from "pako"; import { isValidBuilder } from "./builder"; import { Account, CosmWasmClient, GetNonceResult, PostTxResult } from "./cosmwasmclient"; import { findAttribute, Log } from "./logs"; +import { MsgExecuteContract, MsgInstantiateContract, MsgSend, MsgStoreCode } from "./msgs"; import { BroadcastMode } from "./restclient"; -import { - MsgExecuteContract, - MsgInstantiateContract, - MsgSend, - MsgStoreCode, - StdFee, - StdSignature, -} from "./types"; +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 bfc8dbcf99..59c9a112e3 100644 --- a/packages/cosmwasm/src/types.ts +++ b/packages/cosmwasm/src/types.ts @@ -1,6 +1,8 @@ import { Coin } from "@cosmwasm/sdk38"; import { Encoding } from "@iov/encoding"; +import { Msg } from "./msgs"; + const { fromBase64, fromHex } = Encoding; /** An Amino/Cosmos SDK StdTx */ @@ -23,98 +25,6 @@ export interface CosmosSdkTx { readonly value: StdTx; } -interface MsgTemplate { - readonly type: string; - readonly value: any; -} - -/** A Cosmos SDK token transfer message */ -export interface MsgSend extends MsgTemplate { - readonly type: "cosmos-sdk/MsgSend"; - readonly value: { - /** Bech32 account address */ - readonly from_address: string; - /** Bech32 account address */ - readonly to_address: string; - readonly amount: ReadonlyArray; - }; -} - -/** - * Uploads Wam code to the chain - * - * @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L17 - */ -export interface MsgStoreCode extends MsgTemplate { - readonly type: "wasm/store-code"; - readonly value: { - /** Bech32 account address */ - readonly sender: string; - /** Base64 encoded Wasm */ - readonly wasm_byte_code: string; - /** A valid URI reference to the contract's source code. Can be empty. */ - readonly source: string; - /** A docker tag. Can be empty. */ - readonly builder: string; - }; -} - -/** - * Creates an instance of contract that was uploaded before. - * - * @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L73 - */ -export interface MsgInstantiateContract extends MsgTemplate { - readonly type: "wasm/instantiate"; - readonly value: { - /** Bech32 account address */ - readonly sender: string; - /** ID of the Wasm code that was uploaded before */ - readonly code_id: string; - /** Human-readable label for this contract */ - readonly label: string; - /** Init message as JavaScript object */ - readonly init_msg: any; - readonly init_funds: ReadonlyArray; - }; -} - -/** - * Creates an instance of contract that was uploaded before. - * - * @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L103 - */ -export interface MsgExecuteContract extends MsgTemplate { - readonly type: "wasm/execute"; - readonly value: { - /** Bech32 account address */ - readonly sender: string; - /** Bech32 account address */ - readonly contract: string; - /** Handle message as JavaScript object */ - readonly msg: any; - readonly sent_funds: ReadonlyArray; - }; -} - -export type Msg = MsgSend | MsgStoreCode | MsgInstantiateContract | MsgExecuteContract | MsgTemplate; - -export function isMsgSend(msg: Msg): msg is MsgSend { - return (msg as MsgSend).type === "cosmos-sdk/MsgSend"; -} - -export function isMsgStoreCode(msg: Msg): msg is MsgStoreCode { - return (msg as MsgStoreCode).type === "wasm/store-code"; -} - -export function isMsgInstantiateContract(msg: Msg): msg is MsgInstantiateContract { - return (msg as MsgInstantiateContract).type === "wasm/instantiate"; -} - -export function isMsgExecuteContract(msg: Msg): msg is MsgExecuteContract { - return (msg as MsgExecuteContract).type === "wasm/execute"; -} - export interface StdFee { readonly amount: ReadonlyArray; readonly gas: string; diff --git a/packages/cosmwasm/types/cosmwasmclient.d.ts b/packages/cosmwasm/types/cosmwasmclient.d.ts index 3b57ffde4e..d12633cc3f 100644 --- a/packages/cosmwasm/types/cosmwasmclient.d.ts +++ b/packages/cosmwasm/types/cosmwasmclient.d.ts @@ -1,4 +1,4 @@ -import { Coin } from "@cosmwasm/sdk38"; +import { Coin, IndexedTx } from "@cosmwasm/sdk38"; import { Log } from "./logs"; import { BroadcastMode, RestClient } from "./restclient"; import { CosmosSdkTx, JsonObject, PubKey, StdTx } from "./types"; @@ -72,23 +72,6 @@ export interface ContractDetails extends Contract { /** Argument passed on initialization of the contract */ readonly initMsg: object; } -/** A transaction that is indexed as part of the transaction history */ -export interface IndexedTx { - readonly height: number; - /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ - readonly hash: string; - /** Transaction execution error code. 0 on success. */ - readonly code: number; - readonly rawLog: string; - readonly logs: readonly Log[]; - readonly tx: CosmosSdkTx; - /** The gas limit as set by the user */ - readonly gasWanted?: number; - /** The gas used by the execution */ - readonly gasUsed?: number; - /** An RFC 3339 time string like e.g. '2020-02-15T10:39:10.4696305Z' */ - readonly timestamp: string; -} export interface BlockHeader { readonly version: { readonly block: string; diff --git a/packages/cosmwasm/types/index.d.ts b/packages/cosmwasm/types/index.d.ts index 1241731b70..e070d48cdc 100644 --- a/packages/cosmwasm/types/index.d.ts +++ b/packages/cosmwasm/types/index.d.ts @@ -1,6 +1,5 @@ import * as logs from "./logs"; -import * as types from "./types"; -export { logs, types }; +export { logs }; export { BroadcastMode, RestClient, TxsResponse } from "./restclient"; export { Account, @@ -12,7 +11,6 @@ export { ContractDetails, CosmWasmClient, GetNonceResult, - IndexedTx, PostTxResult, SearchByHeightQuery, SearchByIdQuery, @@ -21,7 +19,6 @@ export { SearchTxQuery, SearchTxFilter, } from "./cosmwasmclient"; -export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey"; export { ExecuteResult, FeeTable, @@ -31,3 +28,11 @@ export { UploadMeta, UploadResult, } from "./signingcosmwasmclient"; +export { + isMsgExecuteContract, + isMsgInstantiateContract, + isMsgStoreCode, + MsgStoreCode, + MsgExecuteContract, + MsgInstantiateContract, +} from "./msgs"; diff --git a/packages/cosmwasm/types/msgs.d.ts b/packages/cosmwasm/types/msgs.d.ts new file mode 100644 index 0000000000..2fb0ae6fd8 --- /dev/null +++ b/packages/cosmwasm/types/msgs.d.ts @@ -0,0 +1,76 @@ +import { Coin } from "@cosmwasm/sdk38"; +interface MsgTemplate { + readonly type: string; + readonly value: any; +} +/** A Cosmos SDK token transfer message */ +export interface MsgSend extends MsgTemplate { + readonly type: "cosmos-sdk/MsgSend"; + readonly value: { + /** Bech32 account address */ + readonly from_address: string; + /** Bech32 account address */ + readonly to_address: string; + readonly amount: ReadonlyArray; + }; +} +/** + * Uploads Wam code to the chain + * + * @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L17 + */ +export interface MsgStoreCode extends MsgTemplate { + readonly type: "wasm/store-code"; + readonly value: { + /** Bech32 account address */ + readonly sender: string; + /** Base64 encoded Wasm */ + readonly wasm_byte_code: string; + /** A valid URI reference to the contract's source code. Can be empty. */ + readonly source: string; + /** A docker tag. Can be empty. */ + readonly builder: string; + }; +} +/** + * Creates an instance of contract that was uploaded before. + * + * @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L73 + */ +export interface MsgInstantiateContract extends MsgTemplate { + readonly type: "wasm/instantiate"; + readonly value: { + /** Bech32 account address */ + readonly sender: string; + /** ID of the Wasm code that was uploaded before */ + readonly code_id: string; + /** Human-readable label for this contract */ + readonly label: string; + /** Init message as JavaScript object */ + readonly init_msg: any; + readonly init_funds: ReadonlyArray; + }; +} +/** + * Creates an instance of contract that was uploaded before. + * + * @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L103 + */ +export interface MsgExecuteContract extends MsgTemplate { + readonly type: "wasm/execute"; + readonly value: { + /** Bech32 account address */ + readonly sender: string; + /** Bech32 account address */ + readonly contract: string; + /** Handle message as JavaScript object */ + readonly msg: any; + readonly sent_funds: ReadonlyArray; + }; +} +export declare type Msg = MsgSend | MsgStoreCode | MsgInstantiateContract | MsgExecuteContract | MsgTemplate; +export declare function isMsgSend(msg: Msg): msg is MsgSend; +export declare function isMsgStoreCode(msg: Msg): msg is MsgStoreCode; +export declare function isMsgInstantiateContract(msg: Msg): msg is MsgInstantiateContract; +export declare function isMsgExecuteContract(msg: Msg): msg is MsgExecuteContract; +export {}; diff --git a/packages/cosmwasm/types/pubkey.d.ts b/packages/cosmwasm/types/pubkey.d.ts deleted file mode 100644 index b6ebdebc68..0000000000 --- a/packages/cosmwasm/types/pubkey.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { PubKey } from "./types"; -export declare function encodeSecp256k1Pubkey(pubkey: Uint8Array): PubKey; -export declare function decodeBech32Pubkey(bechEncoded: string): PubKey; -export declare function encodeBech32Pubkey(pubkey: PubKey, prefix: string): string; diff --git a/packages/cosmwasm/types/types.d.ts b/packages/cosmwasm/types/types.d.ts index e7592e6680..b7d54776ae 100644 --- a/packages/cosmwasm/types/types.d.ts +++ b/packages/cosmwasm/types/types.d.ts @@ -1,4 +1,5 @@ import { Coin } from "@cosmwasm/sdk38"; +import { Msg } from "./msgs"; /** An Amino/Cosmos SDK StdTx */ export interface StdTx { readonly msg: ReadonlyArray; @@ -11,80 +12,6 @@ export interface CosmosSdkTx { readonly type: string; readonly value: StdTx; } -interface MsgTemplate { - readonly type: string; - readonly value: any; -} -/** A Cosmos SDK token transfer message */ -export interface MsgSend extends MsgTemplate { - readonly type: "cosmos-sdk/MsgSend"; - readonly value: { - /** Bech32 account address */ - readonly from_address: string; - /** Bech32 account address */ - readonly to_address: string; - readonly amount: ReadonlyArray; - }; -} -/** - * Uploads Wam code to the chain - * - * @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L17 - */ -export interface MsgStoreCode extends MsgTemplate { - readonly type: "wasm/store-code"; - readonly value: { - /** Bech32 account address */ - readonly sender: string; - /** Base64 encoded Wasm */ - readonly wasm_byte_code: string; - /** A valid URI reference to the contract's source code. Can be empty. */ - readonly source: string; - /** A docker tag. Can be empty. */ - readonly builder: string; - }; -} -/** - * Creates an instance of contract that was uploaded before. - * - * @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L73 - */ -export interface MsgInstantiateContract extends MsgTemplate { - readonly type: "wasm/instantiate"; - readonly value: { - /** Bech32 account address */ - readonly sender: string; - /** ID of the Wasm code that was uploaded before */ - readonly code_id: string; - /** Human-readable label for this contract */ - readonly label: string; - /** Init message as JavaScript object */ - readonly init_msg: any; - readonly init_funds: ReadonlyArray; - }; -} -/** - * Creates an instance of contract that was uploaded before. - * - * @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L103 - */ -export interface MsgExecuteContract extends MsgTemplate { - readonly type: "wasm/execute"; - readonly value: { - /** Bech32 account address */ - readonly sender: string; - /** Bech32 account address */ - readonly contract: string; - /** Handle message as JavaScript object */ - readonly msg: any; - readonly sent_funds: ReadonlyArray; - }; -} -export declare type Msg = MsgSend | MsgStoreCode | MsgInstantiateContract | MsgExecuteContract | MsgTemplate; -export declare function isMsgSend(msg: Msg): msg is MsgSend; -export declare function isMsgStoreCode(msg: Msg): msg is MsgStoreCode; -export declare function isMsgInstantiateContract(msg: Msg): msg is MsgInstantiateContract; -export declare function isMsgExecuteContract(msg: Msg): msg is MsgExecuteContract; export interface StdFee { readonly amount: ReadonlyArray; readonly gas: string; @@ -120,4 +47,3 @@ export declare function parseWasmData({ key, val }: WasmData): Model; * This doen't privide any type safety over `any` but expresses intent in the code. */ export declare type JsonObject = any; -export {}; diff --git a/packages/sdk38/src/index.ts b/packages/sdk38/src/index.ts index 8ba8ea8635..d67248bf1e 100644 --- a/packages/sdk38/src/index.ts +++ b/packages/sdk38/src/index.ts @@ -4,6 +4,26 @@ export { logs, types }; export { pubkeyToAddress, rawSecp256k1PubkeyToAddress } from "./address"; export { Coin, coin, coins } from "./coins"; + +export { + Account, + Block, + BlockHeader, + Code, + CodeDetails, + Contract, + ContractDetails, + CosmosClient, + GetNonceResult, + IndexedTx, + PostTxResult, + SearchByHeightQuery, + SearchByIdQuery, + SearchBySentFromOrToQuery, + SearchByTagsQuery, + SearchTxQuery, + SearchTxFilter, +} from "./cosmosclient"; export { unmarshalTx } from "./decoding"; export { makeSignBytes, marshalTx } from "./encoding"; export { BroadcastMode, RestClient, TxsResponse } from "./restclient"; @@ -11,3 +31,4 @@ export { Pen, Secp256k1Pen, makeCosmoshubPath } from "./pen"; export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey"; export { findSequenceForSignedTx } from "./sequence"; export { encodeSecp256k1Signature, decodeSignature } from "./signature"; +export { FeeTable, SigningCallback, SigningCosmosClient } from "./signingcosmosclient"; diff --git a/packages/sdk38/src/signingcosmosclient.ts b/packages/sdk38/src/signingcosmosclient.ts index f20c7fef6d..c144955e8d 100644 --- a/packages/sdk38/src/signingcosmosclient.ts +++ b/packages/sdk38/src/signingcosmosclient.ts @@ -1,7 +1,6 @@ import { Coin, coins } from "./coins"; import { Account, CosmosClient, GetNonceResult, PostTxResult } from "./cosmosclient"; import { makeSignBytes } from "./encoding"; -import { Log } from "./logs"; import { BroadcastMode } from "./restclient"; import { MsgSend, StdFee, StdSignature } from "./types"; @@ -35,43 +34,6 @@ const defaultFees: FeeTable = { }, }; -export interface UploadMeta { - /** The source URL */ - readonly source?: string; - /** The builder tag */ - readonly builder?: string; -} - -export interface UploadResult { - /** Size of the original wasm code in bytes */ - readonly originalSize: number; - /** A hex encoded sha256 checksum of the original wasm code (that is stored on chain) */ - readonly originalChecksum: string; - /** Size of the compressed wasm code in bytes */ - readonly compressedSize: number; - /** A hex encoded sha256 checksum of the compressed wasm code (that stored in the transaction) */ - readonly compressedChecksum: string; - /** The ID of the code asigned by the chain */ - readonly codeId: number; - readonly logs: readonly Log[]; - /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ - readonly transactionHash: string; -} - -export interface InstantiateResult { - /** The address of the newly instantiated contract */ - readonly contractAddress: string; - readonly logs: readonly Log[]; - /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ - readonly transactionHash: string; -} - -export interface ExecuteResult { - readonly logs: readonly Log[]; - /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ - readonly transactionHash: string; -} - export class SigningCosmosClient extends CosmosClient { public readonly senderAddress: string; diff --git a/packages/sdk38/types/index.d.ts b/packages/sdk38/types/index.d.ts index 6f9a672b6f..78a73f2ec3 100644 --- a/packages/sdk38/types/index.d.ts +++ b/packages/sdk38/types/index.d.ts @@ -3,6 +3,25 @@ import * as types from "./types"; export { logs, types }; export { pubkeyToAddress, rawSecp256k1PubkeyToAddress } from "./address"; export { Coin, coin, coins } from "./coins"; +export { + Account, + Block, + BlockHeader, + Code, + CodeDetails, + Contract, + ContractDetails, + CosmosClient, + GetNonceResult, + IndexedTx, + PostTxResult, + SearchByHeightQuery, + SearchByIdQuery, + SearchBySentFromOrToQuery, + SearchByTagsQuery, + SearchTxQuery, + SearchTxFilter, +} from "./cosmosclient"; export { unmarshalTx } from "./decoding"; export { makeSignBytes, marshalTx } from "./encoding"; export { BroadcastMode, RestClient, TxsResponse } from "./restclient"; @@ -10,3 +29,4 @@ export { Pen, Secp256k1Pen, makeCosmoshubPath } from "./pen"; export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey"; export { findSequenceForSignedTx } from "./sequence"; export { encodeSecp256k1Signature, decodeSignature } from "./signature"; +export { FeeTable, SigningCallback, SigningCosmosClient } from "./signingcosmosclient"; diff --git a/packages/sdk38/types/signingcosmosclient.d.ts b/packages/sdk38/types/signingcosmosclient.d.ts index 00202b7cb9..d9ac523af6 100644 --- a/packages/sdk38/types/signingcosmosclient.d.ts +++ b/packages/sdk38/types/signingcosmosclient.d.ts @@ -1,6 +1,5 @@ import { Coin } from "./coins"; import { Account, CosmosClient, GetNonceResult, PostTxResult } from "./cosmosclient"; -import { Log } from "./logs"; import { BroadcastMode } from "./restclient"; import { StdFee, StdSignature } from "./types"; export interface SigningCallback { @@ -12,39 +11,6 @@ export interface FeeTable { readonly exec: StdFee; readonly send: StdFee; } -export interface UploadMeta { - /** The source URL */ - readonly source?: string; - /** The builder tag */ - readonly builder?: string; -} -export interface UploadResult { - /** Size of the original wasm code in bytes */ - readonly originalSize: number; - /** A hex encoded sha256 checksum of the original wasm code (that is stored on chain) */ - readonly originalChecksum: string; - /** Size of the compressed wasm code in bytes */ - readonly compressedSize: number; - /** A hex encoded sha256 checksum of the compressed wasm code (that stored in the transaction) */ - readonly compressedChecksum: string; - /** The ID of the code asigned by the chain */ - readonly codeId: number; - readonly logs: readonly Log[]; - /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ - readonly transactionHash: string; -} -export interface InstantiateResult { - /** The address of the newly instantiated contract */ - readonly contractAddress: string; - readonly logs: readonly Log[]; - /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ - readonly transactionHash: string; -} -export interface ExecuteResult { - readonly logs: readonly Log[]; - /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ - readonly transactionHash: string; -} export declare class SigningCosmosClient extends CosmosClient { readonly senderAddress: string; private readonly signCallback;