UcanBuilder

Struct UcanBuilder 

Source
pub struct UcanBuilder<'a, K>
where K: KeyMaterial,
{ /* private fields */ }
Expand description

A builder API for UCAN tokens

Implementations§

Source§

impl<'a, K> UcanBuilder<'a, K>
where K: KeyMaterial,

Source

pub fn issued_by(self, issuer: &'a K) -> Self

The UCAN must be signed with the private key of the issuer to be valid.

Source

pub fn for_audience(self, audience: &str) -> Self

This is the identity this UCAN transfers rights to.

It could e.g. be the DID of a service you’re posting this UCAN as a JWT to, or it could be the DID of something that’ll use this UCAN as a proof to continue the UCAN chain as an issuer.

Source

pub fn with_lifetime(self, seconds: u64) -> Self

The number of seconds into the future (relative to when build() is invoked) to set the expiration. This is ignored if an explicit expiration is set.

Source

pub fn with_expiration(self, timestamp: u64) -> Self

Set the POSIX timestamp (in seconds) for when the UCAN should expire. Setting this value overrides a configured lifetime value.

Source

pub fn not_before(self, timestamp: u64) -> Self

Set the POSIX timestamp (in seconds) of when the UCAN becomes active.

Source

pub fn with_fact<T: Serialize + DeserializeOwned>( self, key: &str, fact: T, ) -> Self

Add a fact or proof of knowledge to this UCAN.

Source

pub fn with_nonce(self) -> Self

Will ensure that the built UCAN includes a number used once.

Source

pub fn witnessed_by(self, authority: &Ucan, hasher: Option<Code>) -> Self

Includes a UCAN in the list of proofs for the UCAN to be built. Note that the proof’s audience must match this UCAN’s issuer or else the proof chain will be invalidated! The proof is encoded into a [Cid], hashed via the UcanBuilder::default_hasher() algorithm, unless one is provided.

Source

pub fn claiming_capability<C>(self, capability: C) -> Self
where C: Into<Capability>,

Claim a capability by inheritance (from an authorizing proof) or implicitly by ownership of the resource by this UCAN’s issuer

Source

pub fn claiming_capabilities<C>(self, capabilities: &[C]) -> Self
where C: Into<Capability> + Clone,

Claim capabilities by inheritance (from an authorizing proof) or implicitly by ownership of the resource by this UCAN’s issuer

Source

pub fn delegating_from(self, authority: &Ucan, hasher: Option<Code>) -> Self

Delegate all capabilities from a given proof to the audience of the UCAN you’re building. The proof is encoded into a [Cid], hashed via the UcanBuilder::default_hasher() algorithm, unless one is provided.

Source

pub fn default_hasher() -> Code

Returns the default hasher (Code::Blake3_256) used for [Cid] encodings.

Source

pub fn build(self) -> Result<Signable<'a, K>>

Trait Implementations§

Source§

impl<'a, K> Clone for UcanBuilder<'a, K>
where K: KeyMaterial + Clone,

Source§

fn clone(&self) -> UcanBuilder<'a, K>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, K> Default for UcanBuilder<'a, K>
where K: KeyMaterial,

Source§

fn default() -> Self

Create an empty builder. Before finalising the builder, you need to at least call:

  • issued_by
  • to_audience and one of
  • with_lifetime or with_expiration.

To finalise the builder, call its build or build_parts method.

Auto Trait Implementations§

§

impl<'a, K> Freeze for UcanBuilder<'a, K>

§

impl<'a, K> RefUnwindSafe for UcanBuilder<'a, K>
where K: RefUnwindSafe,

§

impl<'a, K> Send for UcanBuilder<'a, K>

§

impl<'a, K> Sync for UcanBuilder<'a, K>

§

impl<'a, K> Unpin for UcanBuilder<'a, K>

§

impl<'a, K> UnwindSafe for UcanBuilder<'a, K>
where K: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> References<RawCodec> for T

Source§

fn references<R, E>(_c: RawCodec, _r: &mut R, _set: &mut E) -> Result<(), Error>
where R: Read, E: Extend<Cid<64>>,

Scrape the references from an impl Read. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<U> UcanStoreConditionalSend for U
where U: Send,

Source§

impl<U> UcanStoreConditionalSendSync for U
where U: Send + Sync,