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

Method run

atomic-cli/src/commands/memory/verify.rs:31–101  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

memory_verifyFunction · 0.85
find_repository_rootFunction · 0.85
open_readonly_repositoryFunction · 0.85
read_memoryFunction · 0.85
load_by_nameMethod · 0.80
load_attestationFunction · 0.70
verify_memoryFunction · 0.50
cloneMethod · 0.45
get_defaultMethod · 0.45

Tested by

no test coverage detected