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

Function verify_value

atomic-canonical/src/proof.rs:204–256  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

202/// verifies over `jcs(signing_view)`, (3) the proof's verificationMethod DID
203/// belongs to this key.
204pub 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

Callers 13

verifyFunction · 0.85
verify_requestFunction · 0.85
verify_revocationFunction · 0.85
verify_provFunction · 0.85
verifyFunction · 0.85
verify_memoryFunction · 0.85
attach_proofFunction · 0.85
verify_attestationFunction · 0.85

Calls 11

ProofClass · 0.85
content_hashFunction · 0.85
hashing_viewFunction · 0.85
decode_proof_valueFunction · 0.85
signing_viewFunction · 0.85
did_matches_public_keyFunction · 0.85
canonicalizeFunction · 0.70
getMethod · 0.65
okMethod · 0.45
verifyMethod · 0.45