MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / load_for_delegate

Function load_for_delegate

atomic-canonical/src/delegation.rs:549–587  ·  view source on GitHub ↗

Every verified certificate in `store` naming `delegate` as its subject, newest first. Certificates that fail admission or verification are **skipped**, not returned as errors. This is the one place a corrupt or foreign file in the store could otherwise take down every agent operation, and a certificate that does not verify has no authority to convey in any case. A skip is not logged: this crate h

(
    store: &atomic_identity::IdentityStore,
    delegate: &Identity,
)

Source from the content-addressed store, hash-verified

547/// Verification is self-contained — it uses the delegator key the certificate
548/// carries — so this works on a machine that holds only the agent's key.
549pub fn load_for_delegate(
550 store: &atomic_identity::IdentityStore,
551 delegate: &Identity,
552) -> Result<Vec<StoredDelegation>> {
553 let delegate_did = delegate.id.to_did();
554 let stored = store
555 .list_delegations()
556 .map_err(|e| CanonicalError::Proof(format!("failed to list delegations: {e}")))?;
557
558 let mut out = Vec::new();
559 for (id, raw) in stored {
560 // Admission, not a plain parse: a stored certificate is a document this
561 // machine received from somewhere else, and it is about to be verified.
562 let Ok(value) = jcs::admit_document(raw.as_bytes()) else {
563 continue;
564 };
565 // Cheap discriminator before the Ed25519 verify: most certificates in
566 // a store belong to some other agent.
567 match parse(&value) {
568 Ok(parsed) if parsed.delegate == delegate_did => {}
569 _ => continue,
570 }
571 let Ok(delegation) = verify_self_contained(&value) else {
572 continue;
573 };
574
575 out.push(StoredDelegation {
576 revoked_locally: store.is_revoked_locally(&id),
577 id,
578 delegation,
579 document: value,
580 });
581 }
582
583 // Newest first: when several certificates cover the same ground, the most
584 // recently issued is the one the human meant.
585 out.sort_by_key(|d| std::cmp::Reverse(d.delegation.issued));
586 Ok(out)
587}
588
589/// The certificate currently in force for `delegate`, if any.
590pub fn active_for_delegate(

Calls 9

ProofClass · 0.85
admit_documentFunction · 0.85
verify_self_containedFunction · 0.85
to_didMethod · 0.80
is_revoked_locallyMethod · 0.80
parseFunction · 0.70
list_delegationsMethod · 0.45
as_bytesMethod · 0.45
pushMethod · 0.45