Simplify sdk pubkey types

This commit is contained in:
Ethan Frey 2020-02-05 10:30:21 +01:00
parent 0f6721e5f4
commit dc93bfc1e7
4 changed files with 19 additions and 31 deletions

View File

@ -157,7 +157,7 @@ describe("decode", () => {
describe("parseTx", () => {
it("works", () => {
expect(parseTx(data.tx.value as types.StdTx, chainId, nonce, defaultTokens)).toEqual(signedTxJson);
expect(parseTx(data.tx.value, chainId, nonce, defaultTokens)).toEqual(signedTxJson);
});
});
@ -168,7 +168,7 @@ describe("decode", () => {
height: "2823",
txhash: txId,
raw_log: '[{"msg_index":0,"success":true,"log":""}]',
tx: data.tx as types.AminoTx,
tx: data.tx,
};
const expected = {
...signedTxJson,

View File

@ -1,7 +1,6 @@
import { Encoding } from "@iov/encoding";
import { decodeBech32Pubkey, encodeAddress, isValidAddress } from "./address";
import { PubKeyEd25519, PubKeySecp256k1 } from "./types";
const { toBase64, fromHex } = Encoding;
@ -37,7 +36,7 @@ describe("address", () => {
describe("encodeAddress", () => {
it("works for Secp256k1 compressed", () => {
const prefix = "cosmos";
const pubkey: PubKeySecp256k1 = {
const pubkey = {
type: "tendermint/PubKeySecp256k1",
value: "AtQaCqFnshaZQp6rIkvAPyzThvCvXSDO+9AzbxVErqJP",
};
@ -46,7 +45,7 @@ describe("address", () => {
it("works for Ed25519", () => {
const prefix = "cosmos";
const pubkey: PubKeyEd25519 = {
const pubkey = {
type: "tendermint/PubKeyEd25519",
value: toBase64(fromHex("12ee6f581fe55673a1e9e1382a0829e32075a0aa4763c968bc526e1852e78c95")),
};

View File

@ -100,24 +100,21 @@ export interface StdSignature {
readonly signature: string;
}
// value field is base64-encoded in all cases
export type PubKey = PubKeyEd25519 | PubKeySecp256k1 | PubKeySr25519;
export interface PubKeySecp256k1 {
readonly type: "tendermint/PubKeySecp256k1";
// Note: this contains a Secp256k1 COMPRESSED pubkey - to encode from bcp/keycontrol land, you must compress it first
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/cosm-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 interface PubKeyEd25519 {
readonly type: "tendermint/PubKeyEd25519";
readonly value: string;
}
export interface PubKeySr25519 {
readonly type: "tendermint/PubKeySr25519";
readonly value: string;
}
export const pubkeyTypes: string[] = [
"tendermint/PubKeySecp256k1",
"tendermint/PubKeyEd25519",
"tendermint/PubKeySr25519",
];
// bech32-encoded amino-binary encoded PubKey interface. oof.
export type Bech32PubKey = string;

View File

@ -70,19 +70,11 @@ export interface StdSignature {
readonly pub_key: PubKey;
readonly signature: string;
}
export declare type PubKey = PubKeyEd25519 | PubKeySecp256k1 | PubKeySr25519;
export interface PubKeySecp256k1 {
readonly type: "tendermint/PubKeySecp256k1";
readonly value: string;
}
export interface PubKeyEd25519 {
readonly type: "tendermint/PubKeyEd25519";
readonly value: string;
}
export interface PubKeySr25519 {
readonly type: "tendermint/PubKeySr25519";
export interface PubKey {
readonly type: string;
readonly value: string;
}
export declare const pubkeyTypes: string[];
export declare type Bech32PubKey = string;
export interface BaseAccount {
/** Bech32 account address */