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

Function intent_attest

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

Source from the content-addressed store, hash-verified

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

Callers 1

runMethod · 0.85

Calls 8

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

Tested by 1

runMethod · 0.68