lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

signer_commerce.rs (3011B)


      1 //! Portable crypto qualification through the existing observed signer scope.
      2 use super::*;
      3 use radroots_protocol::commerce::{CommerceSigningPlan, EncodedCommerceRumor};
      4 use radroots_signing::{
      5     SignReceipt, SignRequest, Signer, SignerStatus, commerce::VerifiedCommerceSigningPlan,
      6     signer::BoxFuture,
      7 };
      8 
      9 // Each observation/decryption uses the scope's existing single-call admission.
     10 // A second surrounding permit would consume that capacity before IO can start.
     11 struct ScopedProvider<'a>(&'a SignerSession);
     12 impl Signer for ScopedProvider<'_> {
     13     fn status(&self) -> BoxFuture<'_, Result<SignerStatus, radroots_signing::Error>> {
     14         Box::pin(async { Ok(SignerStatus::unavailable()) })
     15     }
     16     fn sign(
     17         &self,
     18         _request: SignRequest,
     19     ) -> BoxFuture<'_, Result<SignReceipt, radroots_signing::Error>> {
     20         Box::pin(async {
     21             Err(radroots_signing::Error::new(
     22                 radroots_signing::error::Kind::SignerUnavailable,
     23             ))
     24         })
     25     }
     26 }
     27 impl ParticipantProvider for ScopedProvider<'_> {
     28     fn provider_state(&self) -> BoxFuture<'_, Result<ProviderState, ProviderError>> {
     29         Box::pin(async move {
     30             if self.0.state() != SessionState::Running {
     31                 return Err(ProviderError::CapabilityUnavailable);
     32             }
     33             self.0.observe().await
     34         })
     35     }
     36     fn encrypt_private(
     37         &self,
     38         call: ProviderCall,
     39         recipient: radroots_domain::PublicKey,
     40         plaintext: PrivateText,
     41     ) -> BoxFuture<'_, Result<PrivateCiphertext, ProviderError>> {
     42         Box::pin(self.0.encrypt_private(call, recipient, plaintext))
     43     }
     44     fn decrypt_private(
     45         &self,
     46         call: ProviderCall,
     47         sender: radroots_domain::PublicKey,
     48         ciphertext: PrivateCiphertext,
     49     ) -> BoxFuture<'_, Result<PrivateText, ProviderError>> {
     50         Box::pin(self.0.decrypt_private(call, sender, ciphertext))
     51     }
     52 }
     53 impl SignerSession {
     54     /// Checks the exact original peer/self ciphertexts and signed routes through
     55     /// this attached scope. It signs nothing and grants no T1, dispatch, stock
     56     /// or network authority. The composing executor owns the complete task.
     57     pub async fn verify_commerce_plan(
     58         &self,
     59         call: ProviderCall,
     60         rumor: &EncodedCommerceRumor,
     61         plan: CommerceSigningPlan,
     62     ) -> Result<VerifiedCommerceSigningPlan, ProviderError> {
     63         if self.state() != SessionState::Running {
     64             return Err(ProviderError::CapabilityUnavailable);
     65         }
     66         if self.identity_changed() {
     67             return Err(ProviderError::IdentityChanged);
     68         }
     69         let observed = self
     70             .observed()
     71             .ok_or(ProviderError::CapabilityUnavailable)?;
     72         if observed.identity() != rumor.author() || call.identity() != observed.identity() {
     73             return Err(ProviderError::IdentityChanged);
     74         }
     75         VerifiedCommerceSigningPlan::verify(&ScopedProvider(self), call, rumor, plan).await
     76     }
     77 }