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

Function prepare_attestation

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

First half of [`attest_value`], for signers that hold the key somewhere else — a browser's WebCrypto, a hardware token, a remote signing service. Everything that must agree with [`verify_value`] (the author, the content hash, the canonical bytes) is computed here, so the external signer only ever signs bytes, and the result is an ordinary atomic attestation.

(mut value: Value, public_key: &PublicKey)

Source from the content-addressed store, hash-verified

135/// hash, the canonical bytes) is computed here, so the external signer only
136/// ever signs bytes, and the result is an ordinary atomic attestation.
137pub fn prepare_attestation(mut value: Value, public_key: &PublicKey) -> PreparedAttestation {
138 let did = did::did_for_public_key(public_key);
139
140 if let Some(obj) = value.as_object_mut() {
141 // Fill attributedTo only if there is no non-empty value already.
142 let has_author = obj
143 .get(PROP_ATTRIBUTED_TO)
144 .and_then(Value::as_str)
145 .map(|s| !s.is_empty())
146 .unwrap_or(false);
147 if !has_author {
148 obj.insert(PROP_ATTRIBUTED_TO.to_string(), Value::String(did));
149 }
150 }
151
152 // Hash first (over the value without proof/contentHash), then sign (over
153 // the value with contentHash, without proof).
154 let content_hash = hash::content_hash(&hashing_view(&value));
155 if let Some(obj) = value.as_object_mut() {
156 obj.insert(PROP_CONTENT_HASH.to_string(), Value::String(content_hash));
157 }
158
159 let signing_bytes = jcs::canonicalize(&signing_view(&value)).into_bytes();
160 PreparedAttestation {
161 value,
162 signing_bytes,
163 }
164}
165
166/// Second half of [`attest_value`]: attach the `eddsa-jcs-2022` proof for a
167/// signature over [`PreparedAttestation::signing_bytes`] made by

Callers 3

attest_valueFunction · 0.70
runMethod · 0.50

Calls 8

content_hashFunction · 0.85
hashing_viewFunction · 0.85
signing_viewFunction · 0.85
did_for_public_keyFunction · 0.70
canonicalizeFunction · 0.70
getMethod · 0.65
is_emptyMethod · 0.45
insertMethod · 0.45

Tested by 2

runMethod · 0.40