(&self)
| 33 | |
| 34 | impl Command for MemoryAttest { |
| 35 | fn run(&self) -> CliResult<()> { |
| 36 | let root = find_repository_root()?; |
| 37 | let repo = Repository::open(&root).map_err(CliError::Repository)?; |
| 38 | |
| 39 | let inputs = bridge::read_memory(&repo, &self.id)?; |
| 40 | |
| 41 | // FIRST gate WITHOUT signing: refuse to sign a node that fails for a |
| 42 | // reason attestation cannot fix (unknown memoryKind/status, empty text). |
| 43 | // Missing proof/attributedTo are the expected pre-attest violations — |
| 44 | // exactly what signing fills — so we only refuse on violations OUTSIDE |
| 45 | // that fillable set. |
| 46 | let unattested = bridge::lift(&inputs)?; |
| 47 | let pre = validate_memory(&unattested); |
| 48 | let blocking: Vec<_> = pre |
| 49 | .results |
| 50 | .iter() |
| 51 | .filter(|v| !is_fillable_by_attest(v.path.as_deref())) |
| 52 | .collect(); |
| 53 | if !blocking.is_empty() { |
| 54 | eprintln!("Cannot attest {}: the memory does not conform.", self.id); |
| 55 | eprint!("{pre}"); |
| 56 | return Err(validation_failed(format!( |
| 57 | "memory {} does not conform; fix the violations above before attesting \ |
| 58 | (run `atomic memory validate {}`)", |
| 59 | self.id, self.id |
| 60 | ))); |
| 61 | } |
| 62 | |
| 63 | // Resolve identity + keypair the way `atomic identity sign` does. |
| 64 | let store = IdentityStore::open_default().map_err(|e| { |
| 65 | CliError::Internal(anyhow::anyhow!("Failed to open identity store: {}", e)) |
| 66 | })?; |
| 67 | let identity = if let Some(name) = &self.identity { |
| 68 | store |
| 69 | .load_by_name(name) |
| 70 | .map_err(|_| CliError::IdentityNotFound(name.clone()))? |
| 71 | } else { |
| 72 | store |
| 73 | .get_default() |
| 74 | .map_err(|e| { |
| 75 | CliError::Internal(anyhow::anyhow!("Failed to load default identity: {}", e)) |
| 76 | })? |
| 77 | .ok_or_else(|| CliError::InvalidArgument { |
| 78 | message: "No default identity set. Create one first:\n \ |
| 79 | atomic identity new <name> --email <email> --set-default" |
| 80 | .to_string(), |
| 81 | })? |
| 82 | }; |
| 83 | let keypair = store.load_keypair(&identity.id, None).map_err(|e| { |
| 84 | CliError::Internal(anyhow::anyhow!( |
| 85 | "Failed to load keypair for '{}': {}", |
| 86 | identity.name, |
| 87 | e |
| 88 | )) |
| 89 | })?; |
| 90 | |
| 91 | // Attest: lift + fill attributedTo (from the identity's did:atomic when |
| 92 | // absent) + hash + sign. |
nothing calls this directly
no test coverage detected