pub struct Ucan {
pub payload: UcanPayload,
pub proofs: Vec<Ucan>,
pub signature: Vec<u8>,
}Expand description
A UCAN: a signed payload plus the proof chain of delegator UCANs.
The chain is the proofs vector — each entry is the delegator’s UCAN whose
audience is this UCAN’s issuer and whose capabilities must cover this UCAN’s
(validated in super::chain). A root UCAN (self-issued authority) has an
empty proofs vector.
Fields§
§payload: UcanPayloadThe signed claims.
proofs: Vec<Ucan>The delegation chain: delegator UCANs that authorize this one. Empty for a root.
signature: Vec<u8>Detached hybrid-COSE composite signature over UcanPayload::signing_bytes.
Implementations§
Source§impl Ucan
impl Ucan
Sourcepub fn from_cbor(bytes: &[u8]) -> Result<Self, UcanError>
pub fn from_cbor(bytes: &[u8]) -> Result<Self, UcanError>
Decode a UCAN from canonical CBOR. Pure structural decode — does NOT
verify signatures or attenuation (call Ucan::verify_signatures then
super::chain::validate_chain).
Fail-closed DoS guard: a decoded chain whose nesting meets or exceeds
super::chain::MAX_PROOF_DEPTH is rejected here, before it is ever
walked, so a maliciously deep proofs-within-proofs token cannot reach
(or exhaust the stack in) the validator. (The validator independently
re-enforces the same bound during the walk.)
Sourcepub fn proof_depth(&self) -> usize
pub fn proof_depth(&self) -> usize
The maximum nesting depth of this UCAN’s proof chain: 0 for a root (no
proofs), otherwise 1 + max(proof.proof_depth()). Used by from_cbor
as a parse-time DoS bound. Walks the in-memory tree iteratively-bounded by
the already-decoded structure (the decode itself is what we cap).
Sourcepub fn capabilities(&self) -> &[Capability]
pub fn capabilities(&self) -> &[Capability]
The capabilities this UCAN grants.
Sourcepub fn root(&self) -> &Ucan
pub fn root(&self) -> &Ucan
The root of this delegation chain — the self-issued authority at the
top, the entry with an empty proofs vector. For a delegated grant this
is the resource-owning delegator; its issuer is the source of
authority (#680/#681: the sub/delegator principal, distinct from the
leaf audience = the actor/presenter).
M1 walks the single-delegator-per-link chain via proofs[0] (the
linkage super::chain::validate also enforces). Depth is bounded by
super::chain::MAX_PROOF_DEPTH at decode, so this cannot runaway.
Sourcepub fn root_issuer(&self) -> &Did
pub fn root_issuer(&self) -> &Did
The DID of the delegation-chain root’s issuer — the ultimate source of
authority (the resource-owning delegator). Convenience over
Self::root().issuer(). See Self::root.
Sourcepub fn validate_structure(&self) -> Result<(), UcanError>
pub fn validate_structure(&self) -> Result<(), UcanError>
Structural validation independent of crypto/attenuation: a UCAN is
structurally well-formed iff both its DIDs resolve to valid did:key
Ed25519 identities and (if present) not_before <= expiration. Each
proof is recursively checked. Fail-closed on any malformation.
Sourcepub fn is_valid_at(&self, now: u64) -> bool
pub fn is_valid_at(&self, now: u64) -> bool
Is this UCAN temporally valid at now (unix seconds)? not_before
inclusive, expiration inclusive of now <= exp. A None bound is
unbounded on that side.
Sourcepub fn verify_signatures<V: UcanVerifier + ?Sized>(
&self,
verifier: &V,
) -> Result<(), UcanError>
pub fn verify_signatures<V: UcanVerifier + ?Sized>( &self, verifier: &V, ) -> Result<(), UcanError>
Verify the hybrid-COSE composite signature on THIS UCAN’s payload, AND
recursively on every proof in the chain. The issuer’s classical key is
taken from its did:key; the matching ML-DSA-65 anchor is resolved
through verifier (the trust store / key-binding layer — the same
register_pq_trust reality crypto::pq models). Fail-closed: any link
whose signature does not verify (or whose PQ anchor is missing under the
hybrid policy) rejects the whole UCAN.
This does NOT check attenuation/delegation linkage — that is
super::chain::validate_chain, deliberately separate.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Ucan
impl<'de> Deserialize<'de> for Ucan
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Ucan
impl StructuralPartialEq for Ucan
Auto Trait Implementations§
impl Freeze for Ucan
impl RefUnwindSafe for Ucan
impl Send for Ucan
impl Sync for Ucan
impl Unpin for Ucan
impl UnsafeUnpin for Ucan
impl UnwindSafe for Ucan
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more