Deduplicate and sort some types
This commit is contained in:
parent
0fe3e5eb4a
commit
5da7bbc93c
@ -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 {
|
||||
|
||||
@ -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<PostTxResponse> {
|
||||
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) ||
|
||||
|
||||
@ -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: {
|
||||
|
||||
@ -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[],
|
||||
|
||||
@ -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,
|
||||
|
||||
15
packages/bcp/types/decode.d.ts
vendored
15
packages/bcp/types/decode.d.ts
vendored
@ -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[],
|
||||
|
||||
12
packages/bcp/types/encode.d.ts
vendored
12
packages/bcp/types/encode.d.ts
vendored
@ -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;
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
const defaultHttpUrl = "http://localhost:1317";
|
||||
const defaultNetworkId = "testing";
|
||||
const defaultFee: types.StdFee = {
|
||||
const defaultFee: StdFee = {
|
||||
amount: [
|
||||
{
|
||||
amount: "5000",
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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",
|
||||
],
|
||||
],
|
||||
[
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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<StdSignature>;
|
||||
|
||||
@ -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<Msg>;
|
||||
readonly fee: StdFee;
|
||||
readonly signatures: ReadonlyArray<StdSignature>;
|
||||
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<Coin>;
|
||||
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;
|
||||
|
||||
4
packages/cosmwasm/types/cosmwasmclient.d.ts
vendored
4
packages/cosmwasm/types/cosmwasmclient.d.ts
vendored
@ -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;
|
||||
|
||||
4
packages/cosmwasm/types/restclient.d.ts
vendored
4
packages/cosmwasm/types/restclient.d.ts
vendored
@ -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;
|
||||
|
||||
@ -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<StdSignature>;
|
||||
}
|
||||
|
||||
35
packages/cosmwasm/types/types.d.ts
vendored
35
packages/cosmwasm/types/types.d.ts
vendored
@ -1,38 +1,3 @@
|
||||
import { Coin } from "@cosmwasm/sdk38";
|
||||
import { Msg } from "./msgs";
|
||||
/** An Amino/Cosmos SDK StdTx */
|
||||
export interface StdTx {
|
||||
readonly msg: ReadonlyArray<Msg>;
|
||||
readonly fee: StdFee;
|
||||
readonly signatures: ReadonlyArray<StdSignature>;
|
||||
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<Coin>;
|
||||
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;
|
||||
|
||||
@ -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";
|
||||
|
||||
14
packages/sdk38/types/index.d.ts
vendored
14
packages/sdk38/types/index.d.ts
vendored
@ -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";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user