Generic verify over a JSON-LD value — the same three checks as the typed path: (1) the content hash recomputes over `hashing_view`, (2) the signature verifies over `jcs(signing_view)`, (3) the proof's verificationMethod DID belongs to this key.
(value: &Value, public_key: &PublicKey)
| 202 | /// verifies over `jcs(signing_view)`, (3) the proof's verificationMethod DID |
| 203 | /// belongs to this key. |
| 204 | pub fn verify_value(value: &Value, public_key: &PublicKey) -> Result<()> { |
| 205 | let obj = value |
| 206 | .as_object() |
| 207 | .ok_or_else(|| CanonicalError::Proof("value is not a JSON object".into()))?; |
| 208 | |
| 209 | // 1. Content hash integrity. |
| 210 | let expected = obj |
| 211 | .get(PROP_CONTENT_HASH) |
| 212 | .and_then(Value::as_str) |
| 213 | .ok_or_else(|| CanonicalError::Proof("node carries no contentHash".into()))?; |
| 214 | let actual = hash::content_hash(&hashing_view(value)); |
| 215 | if expected != actual { |
| 216 | return Err(CanonicalError::HashMismatch { |
| 217 | expected: expected.to_string(), |
| 218 | actual, |
| 219 | }); |
| 220 | } |
| 221 | |
| 222 | // 2. Signature over the canonical signing bytes. |
| 223 | let proof: Proof = obj |
| 224 | .get(PROP_PROOF) |
| 225 | .cloned() |
| 226 | .and_then(|p| serde_json::from_value(p).ok()) |
| 227 | .ok_or_else(|| CanonicalError::Proof("node carries no proof".into()))?; |
| 228 | |
| 229 | // The proof's own metadata is stripped by `signing_view`, so it is not |
| 230 | // covered by the signature. Enforce the suite/purpose/type we expect here, |
| 231 | // otherwise a stored node's declared cryptosuite is silently mutable. |
| 232 | if proof.type_ != PROOF_TYPE |
| 233 | || proof.cryptosuite != CRYPTOSUITE |
| 234 | || proof.proof_purpose != PROOF_PURPOSE |
| 235 | { |
| 236 | return Err(CanonicalError::Verification(format!( |
| 237 | "unexpected proof metadata: type='{}' cryptosuite='{}' proofPurpose='{}'", |
| 238 | proof.type_, proof.cryptosuite, proof.proof_purpose |
| 239 | ))); |
| 240 | } |
| 241 | |
| 242 | let signature = decode_proof_value(&proof.proof_value)?; |
| 243 | let signing_bytes = jcs::canonicalize(&signing_view(value)).into_bytes(); |
| 244 | signature |
| 245 | .verify(&signing_bytes, public_key) |
| 246 | .map_err(|e| CanonicalError::Verification(e.to_string()))?; |
| 247 | |
| 248 | // 3. The proof's verificationMethod DID must belong to this key. |
| 249 | let did = did::did_from_verification_method(&proof.verification_method); |
| 250 | if !did::did_matches_public_key(did, public_key) { |
| 251 | return Err(CanonicalError::Verification( |
| 252 | "verificationMethod DID does not match the public key".into(), |
| 253 | )); |
| 254 | } |
| 255 | Ok(()) |
| 256 | } |
| 257 | |
| 258 | /// Produce a fully attested Intent node — a thin wrapper over |
| 259 | /// [`attest_value`] so hash and signature can never drift from any other node |