lib

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

host_signer.rs (2100B)


      1 use radroots_event::{GenericEventDraft, contract::AuthorRole};
      2 use radroots_event_codec::authoring::AuthoredEventPlan;
      3 use radroots_identity::PublicKey;
      4 use radroots_protocol::runtime::v1::OperationId;
      5 use radroots_signing::{
      6     Actor, AuthoredArtifactId, Error, SignReceipt, SignRequest, Signer, SignerStatus,
      7     SigningIntentId, SigningOperationId,
      8     actor::ActorSource,
      9     error::Kind,
     10     request::{CancellationPolicy, SignPolicy},
     11     signer::BoxFuture,
     12 };
     13 
     14 struct HostSigner;
     15 
     16 impl Signer for HostSigner {
     17     fn status(&self) -> BoxFuture<'_, Result<SignerStatus, Error>> {
     18         Box::pin(async { Ok(SignerStatus::unavailable()) })
     19     }
     20 
     21     fn sign(&self, _request: SignRequest) -> BoxFuture<'_, Result<SignReceipt, Error>> {
     22         Box::pin(async { Err(Error::new(Kind::SignerUnavailable)) })
     23     }
     24 }
     25 
     26 fn main() {
     27     let public_key =
     28         PublicKey::from_hex("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
     29             .expect("canonical public key");
     30     let actor = Actor::new(
     31         public_key,
     32         ActorSource::ExplicitPublicKey,
     33         [AuthorRole::Any],
     34     )
     35     .expect("validated actor");
     36     let draft = GenericEventDraft::new(
     37         "radroots.social.geochat.v1",
     38         20_000,
     39         1_700_000_000,
     40         Vec::new(),
     41         "host-composed signing",
     42         public_key.to_hex(),
     43     )
     44     .expect("validated generic draft");
     45     let plan = AuthoredEventPlan::from_generic(draft).expect("exact authored plan");
     46     let intent_id = SigningIntentId::new(
     47         SigningOperationId::new([1; 16]).expect("operation ID"),
     48         AuthoredArtifactId::new([2; 16]).expect("artifact ID"),
     49     );
     50     let policy = SignPolicy::new(
     51         1_700_000_030_000,
     52         CancellationPolicy::PreservePublishedRequest,
     53     )
     54     .expect("bounded policy");
     55     let request = SignRequest::new(OperationId::SyncPush, intent_id, actor, plan, policy)
     56         .expect("authorized request");
     57 
     58     let signer: &dyn Signer = &HostSigner;
     59     let future = signer.sign(request);
     60     drop(future); // The composing host chooses and drives its async executor.
     61 }