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§

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.

Terminal method which generates the Signables from the Builder

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.