lib

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

participant_private.rs (1917B)


      1 //! Native, nonpublishing provider smoke using published synthetic vector keys.
      2 //! No persistent store, relay or real participant is used.
      3 
      4 use core::num::NonZeroU64;
      5 use radroots_nostr::{
      6     key::parse_secret_key,
      7     signing::{LocalSigner, OsNonceSource},
      8 };
      9 use radroots_signing::{
     10     host::Shared,
     11     provider::{ParticipantProvider, PrivateText, ProviderCall},
     12     request::CancellationSignal,
     13 };
     14 use std::time::{SystemTime, UNIX_EPOCH};
     15 
     16 #[tokio::main]
     17 async fn main() -> Result<(), Box<dyn std::error::Error>> {
     18     // Public NIP-44 interoperability identities; never use these for custody.
     19     let alice = LocalSigner::new(parse_secret_key(
     20         "0000000000000000000000000000000000000000000000000000000000000001",
     21     )?)?
     22     .with_nonce_source(Shared::new(OsNonceSource));
     23     let bob = LocalSigner::new(parse_secret_key(
     24         "0000000000000000000000000000000000000000000000000000000000000002",
     25     )?)?;
     26     let now = u64::try_from(SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis())?;
     27     let deadline = NonZeroU64::new(now.checked_add(10_000).ok_or("deadline overflow")?)
     28         .ok_or("deadline unavailable")?;
     29     let call = |signer: &LocalSigner| {
     30         ProviderCall::new(signer.public_key(), deadline, CancellationSignal::new())
     31     };
     32     let text = "synthetic local food inquiry";
     33     let first = alice
     34         .encrypt_private(call(&alice), bob.public_key(), PrivateText::new(text)?)
     35         .await?;
     36     let second = alice
     37         .encrypt_private(call(&alice), bob.public_key(), PrivateText::new(text)?)
     38         .await?;
     39     assert_ne!(first.as_str(), second.as_str());
     40     for ciphertext in [first, second] {
     41         let opened = bob
     42             .decrypt_private(call(&bob), alice.public_key(), ciphertext)
     43             .await?;
     44         assert_eq!(opened.expose(), text);
     45     }
     46     println!("Native participant provider: OS entropy and two decryptions passed");
     47     Ok(())
     48 }