Merge pull request #705 from cosmos/fix-tm-rpc-commit-parsing

Properly handle missing commit signatures
This commit is contained in:
Simon Warta 2021-03-12 20:37:54 +01:00 committed by GitHub
commit 2f49616749
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -409,16 +409,24 @@ type RpcSignature = {
/** hex encoded */
readonly validator_address: string;
readonly timestamp: string;
/** bae64 encoded */
readonly signature: string;
/**
* Base64 encoded signature.
* There are cases when this is not set, see https://github.com/cosmos/cosmjs/issues/704#issuecomment-797122415.
*/
readonly signature: string | null;
};
function decodeCommitSignature(data: RpcSignature): CommitSignature {
const nonZeroTime = data.timestamp && !data.timestamp.startsWith("0001-01-01");
return {
blockIdFlag: decodeBlockIdFlag(data.block_id_flag),
// FIXME: Return an optional validatorAddress instead of an empty Uint8Array
// in the next breaking release.
validatorAddress: fromHex(data.validator_address),
timestamp: fromRfc3339WithNanoseconds(assertNotEmpty(data.timestamp)),
signature: fromBase64(assertNotEmpty(data.signature)),
timestamp: nonZeroTime ? fromRfc3339WithNanoseconds(data.timestamp) : undefined,
// FIXME: Return an optional signature instead of an empty Uint8Array
// in the next breaking release.
signature: fromBase64(data.signature || ""),
};
}

View File

@ -23,6 +23,7 @@ export enum BlockIdFlag {
}
export interface CommitSignature {
/** If this is BlockIdFlag.Absent, all other fields are expected to be unset */
blockIdFlag: BlockIdFlag;
validatorAddress: Uint8Array;
timestamp?: ReadonlyDateWithNanoseconds;