Skip to main content

Ucan

Struct Ucan 

Source
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: UcanPayload

The 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

Source

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.)

Source

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).

Source

pub fn to_cbor(&self) -> Result<Vec<u8>, UcanError>

Encode this UCAN to canonical CBOR.

Source

pub fn issuer(&self) -> &Did

The issuer DID of this UCAN.

Source

pub fn audience(&self) -> &Did

The audience DID of this UCAN.

Source

pub fn capabilities(&self) -> &[Capability]

The capabilities this UCAN grants.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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 Clone for Ucan

Source§

fn clone(&self) -> Ucan

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Ucan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Ucan

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Ucan

Source§

fn eq(&self, other: &Ucan) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Ucan

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Ucan

Source§

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> 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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

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

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSync for T
where T: Sync,

§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> TerminalState for T
where T: Clone + Send + Sync,