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

Function verify_did_binding

atomic-remote/src/storage.rs:585–598  ·  view source on GitHub ↗

Does the identity record a server returned actually belong to `did`? The failure modes are deliberately unified into one error: a missing key (an old server behind this endpoint), an unparseable key, and a key that simply is not the one the DID fingerprints all mean "this answer cannot be trusted for signature verification", and letting any of them through as success would accept a spoofed signer

(did: &str, info: &IdentityInfo)

Source from the content-addressed store, hash-verified

583/// be trusted for signature verification", and letting any of them through
584/// as success would accept a spoofed signer.
585fn verify_did_binding(did: &str, info: &IdentityInfo) -> Result<(), RemoteError> {
586 let key_b32 = info.public_key.as_deref().ok_or_else(|| {
587 RemoteError::other("identity lookup by DID returned no public key to verify")
588 })?;
589 let public_key = atomic_identity::keypair::PublicKey::from_base32(key_b32)
590 .map_err(|e| RemoteError::other(format!("returned public key is unusable: {e}")))?;
591 if atomic_canonical::did::did_matches_public_key(did, &public_key) {
592 Ok(())
593 } else {
594 Err(RemoteError::other(format!(
595 "server returned public key {key_b32} that does not match DID {did}"
596 )))
597 }
598}
599
600#[cfg(test)]
601mod tests {

Callers 1

Calls 1

did_matches_public_keyFunction · 0.85

Tested by

no test coverage detected