(
&self,
request: Request<PrepareAttestationRequest>,
)
| 3090 | #[tonic::async_trait] |
| 3091 | impl attestation_service_server::AttestationService for AttestationImpl { |
| 3092 | async fn prepare_attestation( |
| 3093 | &self, |
| 3094 | request: Request<PrepareAttestationRequest>, |
| 3095 | ) -> Result<Response<PrepareAttestationResponse>, Status> { |
| 3096 | let request = request.into_inner(); |
| 3097 | let target = request.target.clone().ok_or_else(|| { |
| 3098 | domain_status(ErrorCode::InvalidArgument, "attestation target required") |
| 3099 | })?; |
| 3100 | let target_kind = target.kind.ok_or_else(|| { |
| 3101 | domain_status( |
| 3102 | ErrorCode::InvalidArgument, |
| 3103 | "attestation target kind required", |
| 3104 | ) |
| 3105 | })?; |
| 3106 | let handle = |
| 3107 | self.state |
| 3108 | .resolve(request.repository.as_ref().ok_or_else(|| { |
| 3109 | domain_status(ErrorCode::InvalidArgument, "repository required") |
| 3110 | })?)?; |
| 3111 | self.state.log_rpc("PrepareAttestation", Some(&handle)); |
| 3112 | let gate_handle = handle.clone(); |
| 3113 | let _gate = gate_handle.exclusive().await; |
| 3114 | let identity_name = request.identity_did.clone(); |
| 3115 | |
| 3116 | let response = tokio::task::spawn_blocking(move || match target_kind { |
| 3117 | TargetKind::IntentId(intent_id) => { |
| 3118 | let repo = handle.repository()?; |
| 3119 | let entry = repo |
| 3120 | .vault_intent_show(&intent_id) |
| 3121 | .map_err(repository_error)?; |
| 3122 | let frontmatter = parse_frontmatter(&entry)?; |
| 3123 | let body = body_of(&entry); |
| 3124 | // No key here: everything that must agree with verification — |
| 3125 | // the author, the content hash, the canonical bytes — is |
| 3126 | // computed now, so the external signer only ever signs bytes. |
| 3127 | let identity = load_identity_public(&identity_name)?; |
| 3128 | let node = lift_intent(&frontmatter, &body).map_err(|error| { |
| 3129 | domain_status(ErrorCode::InvalidArgument, format!("attest: {error}")) |
| 3130 | })?; |
| 3131 | refuse_unfillable(&node)?; |
| 3132 | let prepared = proof::prepare_attestation(node.to_value(), &identity.public_key); |
| 3133 | let document = serde_json::to_string(&prepared.value) |
| 3134 | .map_err(|e| Status::internal(e.to_string()))?; |
| 3135 | Ok::<_, Status>(PrepareAttestationResponse { |
| 3136 | document, |
| 3137 | signing_bytes: prepared.signing_bytes, |
| 3138 | snapshot: None, |
| 3139 | }) |
| 3140 | } |
| 3141 | other => Err(domain_status( |
| 3142 | ErrorCode::InvalidArgument, |
| 3143 | format!("attestation target {other:?} lands with its slice"), |
| 3144 | )), |
| 3145 | }) |
| 3146 | .await |
| 3147 | .map_err(|e| Status::internal(e.to_string()))??; |
| 3148 | Ok(Response::new(response)) |
| 3149 | } |
nothing calls this directly
no test coverage detected