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

Method run

atomic-cli/src/commands/intent/verify.rs:32–98  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

30
31impl Command for IntentVerify {
32 fn run(&self) -> CliResult<()> {
33 let root = find_repository_root()?;
34 let repo = Repository::open(&root).map_err(CliError::Repository)?;
35
36 let inputs = bridge::read_intent(&repo, &self.id)?;
37 let node = match bridge::load_attestation(&repo, &self.id, &inputs)? {
38 bridge::Attestation::None => {
39 return Err(CliError::InvalidArgument {
40 message: format!(
41 "no attestation found for {}; run `atomic intent attest {}` first",
42 self.id, self.id
43 ),
44 })
45 }
46 bridge::Attestation::Stale(_) => {
47 return Err(CliError::InvalidArgument {
48 message: format!(
49 "the attestation for {} is stale (the intent changed since it was \
50 signed); re-run `atomic intent attest {}`",
51 self.id, self.id
52 ),
53 })
54 }
55 bridge::Attestation::Fresh(node) => *node,
56 };
57
58 // Resolve the public key to verify against. `did:atomic` is a key
59 // fingerprint (not recoverable to a key), so a store-backed resolver is
60 // needed; for now we verify against the default (or named) identity and
61 // let atomic_canonical::verify's DID check catch a mismatch.
62 let store = IdentityStore::open_default().map_err(|e| {
63 CliError::Internal(anyhow::anyhow!("Failed to open identity store: {}", e))
64 })?;
65 let identity = if let Some(name) = &self.identity {
66 store
67 .load_by_name(name)
68 .map_err(|_| CliError::IdentityNotFound(name.clone()))?
69 } else {
70 store
71 .get_default()
72 .map_err(|e| {
73 CliError::Internal(anyhow::anyhow!("Failed to load default identity: {}", e))
74 })?
75 .ok_or_else(|| CliError::InvalidArgument {
76 message: "No default identity set. Create one first:\n \
77 atomic identity new <name> --email <email> --set-default"
78 .to_string(),
79 })?
80 };
81
82 verify(&node, &identity.public_key).map_err(|e| CliError::InvalidArgument {
83 message: format!(
84 "verification failed: {e} (if this intent was attested by a different \
85 identity, pass --identity <name>)"
86 ),
87 })?;
88
89 println!("Verified intent: {}", self.id);

Callers

nothing calls this directly

Calls 7

find_repository_rootFunction · 0.85
read_intentFunction · 0.85
load_by_nameMethod · 0.80
load_attestationFunction · 0.70
verifyFunction · 0.50
cloneMethod · 0.45
get_defaultMethod · 0.45

Tested by

no test coverage detected