Skip to main content

miden_node_utils/
signer.rs

1use core::convert::Infallible;
2use core::error;
3
4use miden_protocol::block::BlockHeader;
5use miden_protocol::crypto::dsa::ecdsa_k256_keccak::{PublicKey, SecretKey, Signature};
6
7// BLOCK SIGNER
8// ================================================================================================
9
10/// Trait which abstracts the signing of block headers with ECDSA signatures.
11///
12/// Production-level implementations will involve some sort of secure remote backend. The trait also
13/// allows for testing with local and ephemeral signers.
14pub trait BlockSigner {
15    type Error: error::Error + Send + Sync + 'static;
16    fn sign(
17        &self,
18        header: &BlockHeader,
19    ) -> impl Future<Output = Result<Signature, Self::Error>> + Send;
20    fn public_key(&self) -> PublicKey;
21}
22
23// SECRET KEY BLOCK SIGNER
24// ================================================================================================
25
26impl BlockSigner for SecretKey {
27    type Error = Infallible;
28
29    async fn sign(&self, header: &BlockHeader) -> Result<Signature, Self::Error> {
30        Ok(self.sign(header.commitment()))
31    }
32
33    fn public_key(&self) -> PublicKey {
34        self.public_key()
35    }
36}