mod kms;
pub use kms::KmsSigner;
use miden_node_utils::spawn::spawn_blocking_in_current_span;
use miden_protocol::block::BlockHeader;
use miden_protocol::crypto::dsa::ecdsa_k256_keccak::{PublicKey, Signature, SigningKey};
pub enum ValidatorSigner {
Kms(KmsSigner),
Local(SigningKey),
}
impl ValidatorSigner {
pub async fn new_kms(key_id: impl Into<String>) -> anyhow::Result<Self> {
let kms_signer = KmsSigner::new(key_id).await?;
Ok(Self::Kms(kms_signer))
}
pub fn new_local(secret_key: SigningKey) -> Self {
Self::Local(secret_key)
}
pub fn public_key(&self) -> PublicKey {
match self {
Self::Kms(signer) => signer.public_key(),
Self::Local(signer) => signer.public_key(),
}
}
pub async fn sign(&self, header: &BlockHeader) -> anyhow::Result<Signature> {
let commitment = header.commitment();
let signature = match self {
Self::Kms(signer) => signer.sign(commitment).await?,
Self::Local(signer) => spawn_blocking_in_current_span({
let signer = signer.clone();
move || signer.sign(commitment)
})
.await
.unwrap_or_else(|e| std::panic::resume_unwind(e.into_panic())),
};
Ok(signature)
}
}