Skip to main content

miden_node_validator/signers/
mod.rs

1mod kms;
2pub use kms::KmsSigner;
3use miden_node_utils::signer::BlockSigner;
4use miden_protocol::block::BlockHeader;
5use miden_protocol::crypto::dsa::ecdsa_k256_keccak::{SecretKey, Signature};
6
7// VALIDATOR SIGNER
8// =================================================================================================
9
10/// Signer that the Validator uses to sign blocks.
11pub enum ValidatorSigner {
12    Kms(KmsSigner),
13    Local(SecretKey),
14}
15
16impl ValidatorSigner {
17    /// Constructs a signer which uses an AWS KMS key for signing.
18    ///
19    /// See [`KmsSigner`] for details as to env var configuration and AWS IAM policies
20    /// required to use this functionality.
21    pub async fn new_kms(key_id: impl Into<String>) -> anyhow::Result<Self> {
22        let kms_signer = KmsSigner::new(key_id).await?;
23        Ok(Self::Kms(kms_signer))
24    }
25
26    /// Constructs a signer which uses a local secret key for signing.
27    pub fn new_local(secret_key: SecretKey) -> Self {
28        Self::Local(secret_key)
29    }
30
31    /// Signs a block header using the configured signer.
32    pub async fn sign(&self, header: &BlockHeader) -> anyhow::Result<Signature> {
33        match self {
34            Self::Kms(signer) => {
35                let sig = signer.sign(header).await?;
36                Ok(sig)
37            },
38            Self::Local(signer) => {
39                let sig = <SecretKey as BlockSigner>::sign(signer, header).await?;
40                Ok(sig)
41            },
42        }
43    }
44}