Skip to main content

Receipt

Struct Receipt 

Source
pub struct Receipt {
    pub body: ReceiptBody,
    pub signature_b64: String,
}
Expand description

A complete receipt: body + detached signature over JCS(body).

The wire shape is intentionally flat (13 body fields + signature_b64 at the top level) — the schema at schemas/receipt-v1.schema.json commits to it and downstream verifiers (avctl receipt-verify, external tools) consume it that way.

#[serde(flatten)] normally silently disables deny_unknown_fields on the inner struct, which would let a hostile issuer add extra top-level fields (“claim_extra”: “grant admin”) that the human reviewer sees but verify() accepts (the field never survives the round-trip to ReceiptBody used inside canonicalize). To close that gap without breaking the wire shape, the Deserialize impl is written by hand and rejects any top-level key outside the declared whitelist. See the allowed_receipt_top_level_keys_cover_body_fields_exactly test for the compile-time-ish drift guard.

Fields§

§body: ReceiptBody

Signed body.

§signature_b64: String

Ed25519 signature over the JCS canonicalization of the body, base64.

Implementations§

Source§

impl Receipt

Source

pub fn from_json_slice(bytes: &[u8]) -> Result<Self, ReceiptError>

Deserialize a receipt from wire bytes, rejecting any duplicate key at ANY nesting level.

The custom Deserialize impl for Receipt (below) already rejects duplicate top-level keys, but nested structs (ai_agent, tool_calls, cost, subject) went through serde’s default derive which relies on serde_json::Map / IndexMap — both silently collapse duplicate keys with last-wins semantics. A hostile issuer could then sign a receipt whose ai_agent.instance_uid appeared twice ("a" then "b"); JCS canonicalisation saw only "b" so the signature verified, but a first-wins auditor tool (jq’s default, some Python configs) displayed "a" — the exact split-brain the top-level guard was written to prevent, one level deeper.

Round-15 F4: pre-scan the JSON with a strict duplicate-key checker (check_no_duplicate_keys) before deserialising into Receipt. Callers verifying a receipt off the wire should prefer this over serde_json::from_slice::<Receipt>.

Source

pub fn from_json_str(s: &str) -> Result<Self, ReceiptError>

Same as Receipt::from_json_slice for owned/borrowed strings.

Source

pub fn issue( body: ReceiptBody, signer: &dyn Signer, ) -> Result<Self, ReceiptError>

Issue (sign) a receipt over body with signer.

The key_id and public_key_b64 fields of the body are overwritten from the signer — a caller can never claim someone else’s key identity.

Source

pub fn verify(&self, ring: &Keyring) -> Result<(), ReceiptError>

Verify offline against a keyring. Checks, in execution order:

  1. AtifTrajectory.retroactive == true (round-16 F8 — retroactive: false on an ATIF-promoted receipt is semantically nonsense; the schema pins it to const: true but the Rust type still accepts false; refuse it here so the two agree);
  2. the embedded public key matches the ring’s key for key_id (anti-substitution);
  3. the signature verifies over JCS(body).
Source

pub fn verify_embedded(&self) -> Result<(), ReceiptError>

Verify self-contained (trusting the embedded public key). Suitable when the verifier obtained the receipt over an authenticated channel or pins key ids separately. Prefer Receipt::verify with a ring.

Trait Implementations§

Source§

impl Clone for Receipt

Source§

fn clone(&self) -> Receipt

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 Receipt

Source§

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

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

impl<'de> Deserialize<'de> for Receipt

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

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

impl PartialEq for Receipt

Source§

fn eq(&self, other: &Receipt) -> 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 Receipt

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 StructuralPartialEq for Receipt

Auto Trait Implementations§

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.

§

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

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,