Adapt types to fix

This commit is contained in:
Simon Warta 2021-03-12 20:26:03 +01:00
parent db90bd4445
commit c5e1b75c40
2 changed files with 11 additions and 4 deletions

View File

@ -409,18 +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: nonZeroTime ? fromRfc3339WithNanoseconds(data.timestamp) : undefined,
// FIXME: make this optional in type? (signature?: Uint8Array)
signature: fromBase64(optional(data.signature, "")),
// 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;