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

Function intent_attest

atomic-cli/src/commands/rpc.rs:1026–1106  ·  view source on GitHub ↗
(args: &super::intent::attest::IntentAttest)

Source from the content-addressed store, hash-verified

1024}
1025
1026pub fn intent_attest(args: &super::intent::attest::IntentAttest) -> CliResult<bool> {
1027 let Some(session) = Service::open()? else {
1028 return Ok(false);
1029 };
1030 let target = pb::AttestationTarget {
1031 kind: Some(TargetKind::IntentId(args.id.clone())),
1032 };
1033
1034 // Signing elsewhere, step 1: say what to sign — the document and the
1035 // bytes a key holder elsewhere (a browser, a hardware token, a signing
1036 // service) signs. No key on this machine is involved.
1037 if args.prepare {
1038 let request = pb::PrepareAttestationRequest {
1039 repository: Some(session.reference.clone()),
1040 meta: request_meta(),
1041 target: Some(target),
1042 identity_did: args.identity.clone().unwrap_or_default(),
1043 view: None,
1044 };
1045 let response = session.prepare_attestation(request)?;
1046 let document: serde_json::Value = serde_json::from_str(&response.document)
1047 .map_err(|e| CliError::Internal(anyhow::anyhow!("prepared document: {e}")))?;
1048 println!(
1049 "{}",
1050 serde_json::to_string_pretty(&serde_json::json!({
1051 "document": document,
1052 "signingBytes": data_encoding::BASE64.encode(&response.signing_bytes),
1053 }))
1054 .unwrap()
1055 );
1056 return Ok(true);
1057 }
1058
1059 // Signing elsewhere, step 2: record an attestation signed elsewhere. The
1060 // file holds the `--prepare` document with its proof attached; the service
1061 // re-derives the document from the intent AS IT IS NOW and verifies the
1062 // signature against it, so a stale or altered intent is refused.
1063 let caller_signature = if let Some(path) = &args.signed {
1064 let text = std::fs::read_to_string(path).map_err(CliError::Io)?;
1065 let signed: serde_json::Value =
1066 serde_json::from_str(&text).map_err(|e| CliError::InvalidArgument {
1067 message: format!("{} is not JSON: {e}", path.display()),
1068 })?;
1069 atomic_canonical::proof::proof_signature(&signed)
1070 .map_err(|e| CliError::InvalidArgument {
1071 message: format!("not an attested intent: {e}"),
1072 })?
1073 .as_bytes()
1074 .to_vec()
1075 } else {
1076 Vec::new()
1077 };
1078
1079 let request = pb::RecordAttestationRequest {
1080 repository: Some(session.reference.clone()),
1081 meta: request_meta(),
1082 target: Some(target),
1083 identity_did: args.identity.clone().unwrap_or_default(),

Callers 1

runMethod · 0.85

Calls 8

openFunction · 0.85
proof_signatureFunction · 0.85
print_attestation_jsonFunction · 0.85
request_metaFunction · 0.70
cloneMethod · 0.45
prepare_attestationMethod · 0.45
as_bytesMethod · 0.45
record_attestationMethod · 0.45

Tested by 1

runMethod · 0.68