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,
impl<'a, K> UcanBuilder<'a, K>where
K: KeyMaterial,
Sourcepub fn issued_by(self, issuer: &'a K) -> Self
pub fn issued_by(self, issuer: &'a K) -> Self
The UCAN must be signed with the private key of the issuer to be valid.
Sourcepub fn for_audience(self, audience: &str) -> Self
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.
Sourcepub fn with_lifetime(self, seconds: u64) -> Self
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.
Sourcepub fn with_expiration(self, timestamp: u64) -> Self
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.
Sourcepub fn not_before(self, timestamp: u64) -> Self
pub fn not_before(self, timestamp: u64) -> Self
Set the POSIX timestamp (in seconds) of when the UCAN becomes active.
Sourcepub fn with_fact<T: Serialize + DeserializeOwned>(
self,
key: &str,
fact: T,
) -> Self
pub fn with_fact<T: Serialize + DeserializeOwned>( self, key: &str, fact: T, ) -> Self
Add a fact or proof of knowledge to this UCAN.
Sourcepub fn with_nonce(self) -> Self
pub fn with_nonce(self) -> Self
Will ensure that the built UCAN includes a number used once.
Sourcepub fn witnessed_by(self, authority: &Ucan, hasher: Option<Code>) -> Self
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.
Sourcepub fn claiming_capability<C>(self, capability: C) -> Selfwhere
C: Into<Capability>,
pub fn claiming_capability<C>(self, capability: C) -> Selfwhere
C: Into<Capability>,
Claim a capability by inheritance (from an authorizing proof) or implicitly by ownership of the resource by this UCAN’s issuer
Sourcepub fn claiming_capabilities<C>(self, capabilities: &[C]) -> Self
pub fn claiming_capabilities<C>(self, capabilities: &[C]) -> Self
Claim capabilities by inheritance (from an authorizing proof) or implicitly by ownership of the resource by this UCAN’s issuer
Sourcepub fn delegating_from(self, authority: &Ucan, hasher: Option<Code>) -> Self
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.
Sourcepub fn default_hasher() -> Code
pub fn default_hasher() -> Code
Returns the default hasher (Code::Blake3_256) used for [Cid] encodings.
pub fn build(self) -> Result<Signable<'a, K>>
Trait Implementations§
Source§impl<'a, K> Clone for UcanBuilder<'a, K>where
K: KeyMaterial + Clone,
impl<'a, K> Clone for UcanBuilder<'a, K>where
K: KeyMaterial + Clone,
Source§fn clone(&self) -> UcanBuilder<'a, K>
fn clone(&self) -> UcanBuilder<'a, K>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more