miden_validator/signers/
mod.rs1mod kms;
2pub use kms::KmsSigner;
3use miden_node_utils::spawn::spawn_blocking_in_current_span;
4use miden_protocol::block::BlockHeader;
5use miden_protocol::crypto::dsa::ecdsa_k256_keccak::{PublicKey, Signature, SigningKey};
6
7pub enum ValidatorSigner {
12 Kms(KmsSigner),
13 Local(SigningKey),
14}
15
16impl ValidatorSigner {
17 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 pub fn new_local(secret_key: SigningKey) -> Self {
28 Self::Local(secret_key)
29 }
30
31 pub fn public_key(&self) -> PublicKey {
33 match self {
34 Self::Kms(signer) => signer.public_key(),
35 Self::Local(signer) => signer.public_key(),
36 }
37 }
38
39 pub async fn sign(&self, header: &BlockHeader) -> anyhow::Result<Signature> {
41 let commitment = header.commitment();
42 let signature = match self {
43 Self::Kms(signer) => signer.sign(commitment).await?,
44 Self::Local(signer) => spawn_blocking_in_current_span({
45 let signer = signer.clone();
46 move || signer.sign(commitment)
47 })
48 .await
49 .unwrap_or_else(|e| std::panic::resume_unwind(e.into_panic())),
50 };
51
52 Ok(signature)
53 }
54}