tendermint-rpc: Add support for secp256k1 validator keys

This commit is contained in:
willclarktech 2021-04-21 10:39:26 +02:00
parent a4e4915d7a
commit 11e88bb91e
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
4 changed files with 39 additions and 15 deletions

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,