Skip to main content

MutationProof

Struct MutationProof 

Source
pub struct MutationProof { /* private fields */ }
Expand description

Authorization for one write to one registration.

Carries only what the record cannot derive from the call itself: the sequence number claiming a position in the record’s history, and the signature over the whole request. Everything else the signature covers (which agent, which record instance, which operation, which arguments) the store already holds or was just handed, so a proof has nothing in it that could contradict the write it accompanies.

§Examples

use agent_uri::AgentUri;
use agent_uri_attestation::SigningKey;
use agent_uri_dht::{Endpoint, Mutation, MutationProof, Registration};

let key = SigningKey::generate();
let uri = AgentUri::parse(
    "agent://anthropic.com/assistant/chat/llm_01h455vb4pex5vsknk084sn02q"
).unwrap();

// In practice this record comes back from a lookup.
let record = Registration::new(
    uri,
    key.verifying_key(),
    vec![Endpoint::https("us-east-1.agent.anthropic.com")],
);

let endpoints = vec![Endpoint::https("eu-west-1.agent.anthropic.com")];
// Migrating does not change when the record lapses, so the expiry signed
// is the one the record already carries.
let mutation = Mutation::UpdateEndpoint {
    endpoints: &endpoints,
    expires_at: record.expires_at(),
};
let proof = MutationProof::sign_next(&key, &record, &mutation);

assert!(proof.authorizes(&record, &mutation).is_ok());

Implementations§

Source§

impl MutationProof

Source

pub fn sign_registration(key: &SigningKey, record: &Registration) -> Self

Signs the registration of record.

Covers the record as submitted: its key, endpoints, expiry, instance identity, and starting sequence. A relay can therefore forward a registration but not alter one.

Source

pub fn authorizes_registration( &self, record: &Registration, ) -> Result<(), DhtError>

Checks that this proof authorizes the registration of record.

Unlike a later write there is no history to advance past, so only the signature is at issue: the record’s own key must have signed the record exactly as submitted.

§Errors

Returns DhtError::Unauthorized if the signature does not answer for this record.

Source

pub fn sign_next( key: &SigningKey, record: &Registration, mutation: &Mutation<'_>, ) -> Self

Signs the next write to record.

The usual way to build a proof: look the record up, then sign against what you read. Signing against a stale copy produces a proof the store will refuse rather than one it will misapply.

Source

pub fn sign( key: &SigningKey, agent_uri: &AgentUri, version: RecordVersion, mutation: &Mutation<'_>, ) -> Self

Signs a write against an explicitly named version.

For a caller that cached a record’s version rather than the record.

Source

pub const fn from_parts(sequence: u64, signature: Signature) -> Self

Reassembles a proof received over the wire.

Source

pub const fn sequence(&self) -> u64

Returns the sequence number this proof claims.

Source

pub const fn signature(&self) -> Signature

Returns the signature.

Source

pub fn authorizes( &self, record: &Registration, mutation: &Mutation<'_>, ) -> Result<(), DhtError>

Checks that this proof authorizes mutation against record.

The whole authorization rule, in one place: the signature must be the record’s own key over exactly this record instance, position, operation and arguments, and the position must advance. A store calls this and has nothing further to decide.

§Errors

Returns DhtError::Unauthorized if the signature does not answer for this write, or DhtError::StaleSequence if it does but the write does not advance the record’s history.

Trait Implementations§

Source§

impl Clone for MutationProof

Source§

fn clone(&self) -> Self

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 Copy for MutationProof

Source§

impl Debug for MutationProof

Source§

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

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

impl Eq for MutationProof

Source§

impl PartialEq for MutationProof

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MutationProof

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.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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