Make some Checkpoint hash fns public and rename them too (#1444)

* Make some checkpoint hash fns public and rename them too

* cargo fmt
pull/1451/head
Trevor Porter 2 years ago committed by GitHub
parent ffe107387b
commit ee075b114f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      rust/hyperlane-core/src/types/checkpoint.rs

@ -72,7 +72,9 @@ impl Decode for Checkpoint {
} }
impl Checkpoint { impl Checkpoint {
fn signing_hash(&self) -> H256 { /// A hash of the checkpoint contents.
/// The EIP-191 compliant version of this hash is signed by validators.
pub fn signing_hash(&self) -> H256 {
// sign: // sign:
// domain_hash(mailbox_address, mailbox_domain) || root || index (as u32) // domain_hash(mailbox_address, mailbox_domain) || root || index (as u32)
H256::from_slice( H256::from_slice(
@ -85,7 +87,8 @@ impl Checkpoint {
) )
} }
fn prepended_hash(&self) -> H256 { /// EIP-191 compliant hash of the signing hash of the checkpoint.
pub fn eth_signed_message_hash(&self) -> H256 {
hash_message(self.signing_hash()) hash_message(self.signing_hash())
} }
@ -140,14 +143,16 @@ impl Decode for SignedCheckpoint {
impl SignedCheckpoint { impl SignedCheckpoint {
/// Recover the Ethereum address of the signer /// Recover the Ethereum address of the signer
pub fn recover(&self) -> Result<Address, HyperlaneProtocolError> { pub fn recover(&self) -> Result<Address, HyperlaneProtocolError> {
Ok(self.signature.recover(self.checkpoint.prepended_hash())?) Ok(self
.signature
.recover(self.checkpoint.eth_signed_message_hash())?)
} }
/// Check whether a message was signed by a specific address /// Check whether a message was signed by a specific address
pub fn verify(&self, signer: Address) -> Result<(), HyperlaneProtocolError> { pub fn verify(&self, signer: Address) -> Result<(), HyperlaneProtocolError> {
Ok(self Ok(self
.signature .signature
.verify(self.checkpoint.prepended_hash(), signer)?) .verify(self.checkpoint.eth_signed_message_hash(), signer)?)
} }
} }

Loading…
Cancel
Save