Merge pull request #773 from cosmos/681-validator-pubkey-secp256k1

Add support for secp256k1 validator pubkeys to tendermint-rpc
This commit is contained in:
Simon Warta 2021-04-21 17:06:19 +02:00 committed by GitHub
commit 856aaa6a0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 15 deletions

View File

@ -86,6 +86,7 @@ and this project adheres to
`isMsgClearAdminEncodeObject` etc helpers.
- @cosmjs/stargate: Add transfer queries codec, as well as transfer query
methods to IBC query extension.
- @cosmjs/tendermint-rpc: Export `ValidatorSecp256k1Pubkey` interface.
### Changed
@ -152,6 +153,10 @@ and this project adheres to
instead of a single `hdPath`. `DirectSecp256k1HdWallet.generate` now also
accepts options via this interface. This adds support for multiple accounts
from the same mnemonic to `DirectSecp256k1HdWallet`.
- @cosmjs/tendermint-rpc: `ValidatorPubkey` is now a union of
`ValidatorEd25519Pubkey` and the newly exported `ValidatorSecp256k1Pubkey`
interface.
- @cosmjs/tendermint-rpc: `decodePubkey` now supports secp256k1 public keys.
### Deprecated

View File

@ -85,6 +85,12 @@ export {
toSeconds,
} from "./dates";
export { HttpClient, WebsocketClient } from "./rpcclients"; // TODO: Why do we export those outside of this package?
export { BlockIdFlag, CommitSignature, ValidatorEd25519Pubkey, ValidatorPubkey } from "./types";
export {
BlockIdFlag,
CommitSignature,
ValidatorEd25519Pubkey,
ValidatorSecp256k1Pubkey,
ValidatorPubkey,
} from "./types";
export * as tendermint34 from "./tendermint34";
export { Tendermint34Client } from "./tendermint34";

View File

@ -150,14 +150,21 @@ interface RpcPubkey {
}
function decodePubkey(data: RpcPubkey): ValidatorPubkey {
if (data.type === "tendermint/PubKeyEd25519") {
switch (data.type) {
// go-amino special code
return {
algorithm: "ed25519",
data: fromBase64(assertNotEmpty(data.value)),
};
case "tendermint/PubKeyEd25519":
return {
algorithm: "ed25519",
data: fromBase64(assertNotEmpty(data.value)),
};
case "tendermint/PubKeySecp256k1":
return {
algorithm: "secp256k1",
data: fromBase64(assertNotEmpty(data.value)),
};
default:
throw new Error(`unknown pubkey type: ${data.type}`);
}
throw new Error(`unknown pubkey type: ${data.type}`);
}
// for evidence, block results, etc.

View File

@ -156,14 +156,21 @@ interface RpcPubkey {
}
function decodePubkey(data: RpcPubkey): ValidatorPubkey {
if (data.type === "tendermint/PubKeyEd25519") {
switch (data.type) {
// go-amino special code
return {
algorithm: "ed25519",
data: fromBase64(assertNotEmpty(data.value)),
};
case "tendermint/PubKeyEd25519":
return {
algorithm: "ed25519",
data: fromBase64(assertNotEmpty(data.value)),
};
case "tendermint/PubKeySecp256k1":
return {
algorithm: "secp256k1",
data: fromBase64(assertNotEmpty(data.value)),
};
default:
throw new Error(`unknown pubkey type: ${data.type}`);
}
throw new Error(`unknown pubkey type: ${data.type}`);
}
// for evidence, block results, etc.

View File

@ -8,11 +8,15 @@ export interface ValidatorEd25519Pubkey {
readonly data: Uint8Array;
}
export interface ValidatorSecp256k1Pubkey {
readonly algorithm: "secp256k1";
readonly data: Uint8Array;
}
/**
* Union type for different possible pubkeys.
* Currently only Ed25519 supported.
*/
export type ValidatorPubkey = ValidatorEd25519Pubkey;
export type ValidatorPubkey = ValidatorEd25519Pubkey | ValidatorSecp256k1Pubkey;
export enum BlockIdFlag {
Unknown = 0,