Struct ipns_entry::DataBuilder
source · pub struct DataBuilder { /* private fields */ }
Expand description
Example
use ipns_entry::DataBuilder;
use ipns_entry::entry::IpnsEntry;
use std::time::SystemTime;
use std::time::Duration;
use ipns_entry::signer::{Signables, Signed, Signer};
use libp2p_identity::PeerId;
use libp2p_identity::PublicKey;
use libp2p_identity::ed25519;
let value = "QmWEekX7EZLUd9VXRNMRXW3LXe4F6x7mB8oPxY5XLptrBq";
let ttl = 60 * 60 * 48; // 48 hours, the default
let validity: SystemTime = SystemTime::now() + Duration::from_secs(ttl);
let sequence = 0;
let (data, signables) = DataBuilder::new(value).validity(validity).sequence(sequence).ttl(ttl).build();
// Provide a Signer (holding your private keys) that takes `Signables {v1, v2}` and returns `Signed {v1, v2, pub_key}`
let signer = Signer::default();
let signed: Signed = signer.sign(signables)?;
let entry = IpnsEntry::new(data, signed);
let routable_bytes = entry.to_bytes();
// Decode received bytes into an Entry
let rxd_entry = IpnsEntry::from_bytes(&routable_bytes).expect("Valid routable bytes");
// Validate Entry against the IPNS Name (PeerId)
let peer_id = PeerId::from_public_key(&signer.public());
let verified = rxd_entry.is_valid_for(&peer_id).expect("valid against our peer id");
assert!(verified);
Implementations§
source§impl DataBuilder
impl DataBuilder
sourcepub fn new(value: &str) -> Self
pub fn new(value: &str) -> Self
Create a new DataBuilder with the required value. The default ttl is 48 hours. The default validity is 48 hours from now. The default sequence is 0.
Customize the ttl, validity, and sequence with the builder methods.
When the DataBuilder is ready, call signables()
to get the Signables {v1, v2}
which can be signed by the Signer.
pub fn value(&mut self, value: &str) -> &mut DataBuilder
pub fn validity(&mut self, validity: SystemTime) -> &mut DataBuilder
pub fn sequence(&mut self, sequence: u64) -> &mut DataBuilder
pub fn increment_sequence(&mut self) -> &mut DataBuilder
pub fn ttl(&mut self, ttl: u64) -> &mut DataBuilder
Trait Implementations§
source§impl Clone for DataBuilder
impl Clone for DataBuilder
source§fn clone(&self) -> DataBuilder
fn clone(&self) -> DataBuilder
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more