penumbra_sdk_stake/component/stake/address.rs
1use {
2 sha2::{Digest, Sha256},
3 tendermint::PublicKey,
4};
5
6/// A type alias for 20-byte truncated SHA256 validator addresses.
7///
8/// This is the format in which [`tendermint::abci::types::CommitInfo`] presents vote information.
9pub(crate) type Address = [u8; ADDRESS_LEN];
10
11const ADDRESS_LEN: usize = 20;
12
13/// Translates from consensus keys to the truncated sha256 hashes in `last_commit_info`.
14//
15// NOTE: This should really be a refined type upstream, but we can't currently upstream to
16// tendermint-rs, for process reasons, and shouldn't do our own tendermint data modeling, so
17// this is an interim hack.
18pub(crate) fn validator_address(ck: &PublicKey) -> Address {
19 let ck_bytes = ck.to_bytes();
20 Sha256::digest(ck_bytes).as_slice()[0..ADDRESS_LEN]
21 .try_into()
22 .expect("Sha256 digest should be 20-bytes long")
23}