1#[allow(unused_imports)]
13use crate::prelude::*;
14
15use serde_json::{json, Map, Value};
16
17use crate::attenuation;
18use crate::data_integrity::{self, BuildProofOptions};
19use crate::delegation;
20use crate::error::{CoreError, Result};
21use crate::grant_chain::{self, py_repr, py_repr_str};
22use crate::time::parse_protocol_time_ns;
23use zeroize::{Zeroize, Zeroizing};
24
25pub const DEFAULT_VALID_SECONDS: i64 = 300;
28pub const INVALID_VALID_SECONDS: &str =
31 "valid_seconds must be a whole number of seconds greater than zero";
32pub const NOT_A_DID: &str = "Vouch Signer requires 'did' to be a DID (did:<method>:...)";
34pub const PARENT_NOT_PLAIN_JSON: &str =
36 "Delegation refused: the parent grant is not plain JSON, so it has no digest";
37
38const NS_PER_SECOND: i128 = 1_000_000_000;
39
40fn to_micros(ns: i128) -> i128 {
43 ns.div_euclid(1000) * 1000
44}
45
46fn refused(msg: impl Into<String>) -> CoreError {
47 CoreError::Json(msg.into())
48}
49
50#[derive(Debug, Clone, Default)]
52pub struct IssueRequest {
53 pub issuer_did: String,
55 pub intent: Value,
58 pub now: String,
61 pub valid_from: Option<String>,
63 pub valid_seconds: Option<i64>,
66 pub reputation_score: Option<i64>,
68 pub delegation_chain: Option<Value>,
70 pub parent_credential: Option<Value>,
73 pub credential_id: Option<String>,
75 pub credential_status: Option<Value>,
77 pub verification_method: Option<String>,
80}
81
82pub fn format_protocol_time(ns: i128) -> Result<String> {
86 let secs = ns.div_euclid(NS_PER_SECOND);
87 let days = secs.div_euclid(86_400);
88 let rem = secs.rem_euclid(86_400);
89 let z = days + 719_468;
91 let era = z.div_euclid(146_097);
92 let doe = z.rem_euclid(146_097);
93 let yoe = (doe - doe / 1460 + doe / 36_524 - doe / 146_096) / 365;
94 let doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
95 let mp = (5 * doy + 2) / 153;
96 let day = doy - (153 * mp + 2) / 5 + 1;
97 let month = if mp < 10 { mp + 3 } else { mp - 9 };
98 let year = yoe + era * 400 + i128::from(month <= 2);
99 if !(1..=9999).contains(&year) {
100 return Err(refused("date value out of range"));
101 }
102 Ok(format!(
103 "{year:04}-{month:02}-{day:02}T{:02}:{:02}:{:02}Z",
104 rem / 3600,
105 rem % 3600 / 60,
106 rem % 60
107 ))
108}
109
110pub fn new_credential_id() -> Result<String> {
112 let mut b = [0u8; 16];
113 crate::random::fill(&mut b).map_err(|e| CoreError::Crypto(format!("rng: {e}")))?;
114 b[6] = (b[6] & 0x0f) | 0x40;
115 b[8] = (b[8] & 0x3f) | 0x80;
116 let h: String = b.iter().map(|x| format!("{x:02x}")).collect();
117 Ok(format!(
118 "urn:uuid:{}-{}-{}-{}-{}",
119 &h[..8],
120 &h[8..12],
121 &h[12..16],
122 &h[16..20],
123 &h[20..]
124 ))
125}
126
127pub fn did_key_mismatch(did: &str, public_key: &[u8]) -> Option<String> {
130 if !did.starts_with("did:key:") {
131 return None;
132 }
133 let own = match crate::multikey::encode_ed25519_public(public_key) {
134 Ok(mk) => format!("did:key:{mk}"),
135 Err(_) => "did:key:".to_string(),
136 };
137 (own != did)
138 .then(|| format!("{did} is the did:key of a different key; this key's did:key is {own}"))
139}
140
141pub fn validate_intent(intent: &Value) -> Result<()> {
145 crate::nesting::deep_guard!(Err(crate::nesting::too_deep()); intent);
146 let Some(obj) = intent.as_object() else {
147 return Err(refused("intent must be a dict"));
148 };
149 let required: &[&str] = if grant_chain::is_grant_intent(intent) {
150 &["action", "resource"]
151 } else {
152 &["action", "target", "resource"]
153 };
154 for name in required {
155 match obj.get(*name) {
156 None | Some(Value::Null) => {}
157 Some(Value::String(s)) if s.is_empty() => {}
158 Some(_) => continue,
159 }
160 return Err(refused(format!(
161 "intent.{name} is REQUIRED (Specification ยง5.4.1): Vouch credentials MUST bind to \
162 a concrete resource"
163 )));
164 }
165 if !obj["resource"].is_string() {
166 return Err(refused(
167 "intent.resource must be a non-empty string naming the resource",
168 ));
169 }
170 Ok(())
171}
172
173fn truthy(v: Option<&Value>) -> bool {
174 match v {
175 None | Some(Value::Null) => false,
176 Some(Value::Bool(b)) => *b,
177 Some(Value::Number(n)) => n.as_f64().is_some_and(|f| f != 0.0),
178 Some(Value::String(s)) => !s.is_empty(),
179 Some(Value::Array(a)) => !a.is_empty(),
180 Some(Value::Object(o)) => !o.is_empty(),
181 }
182}
183
184pub fn links_from_parent(parent: &Value, intent: &Value, signer_did: &str) -> Result<Vec<Value>> {
192 crate::nesting::deep_guard!(Err(crate::nesting::too_deep()); parent, intent);
193 let grants = grant_chain::parent_grants(parent)?;
194 let last = grants.last().expect("parent_grants is never empty");
195 let Some(parent_intent) = last
196 .get("credentialSubject")
197 .and_then(|s| s.get("intent"))
198 .filter(|i| i.is_object())
199 else {
200 return Err(refused(
201 "Delegation refused: the parent grant carries no intent object",
202 ));
203 };
204 if let (Some(Value::String(p)), Some(Value::String(c))) =
206 (parent_intent.get("resource"), intent.get("resource"))
207 {
208 if !p.is_empty() && !c.is_empty() && !attenuation::resource_within(c, p) {
209 return Err(refused(format!(
210 "Delegation violates resource-narrowing rule: child resource {} is not a \
211 sub-resource of parent {}",
212 py_repr_str(c),
213 py_repr_str(p)
214 )));
215 }
216 }
217 if !truthy(last.get("issuer"))
218 || !matches!(last.get("proof"), Some(Value::Object(_) | Value::Array(_)))
219 {
220 return Err(refused(
221 "Delegation refused: the parent grant is not a signed credential",
222 ));
223 }
224 let delegatee = parent_intent.get("delegatee");
225 if !truthy(delegatee) {
226 return Err(refused(
227 "Delegation refused: the parent grant names no delegatee; issue it with the \
228 delegatee's DID (for example vouch.delegate(..., to=did))",
229 ));
230 }
231 if delegatee.and_then(Value::as_str) != Some(signer_did) {
232 return Err(refused(format!(
233 "Delegation refused: the parent grant names delegatee {}, not this signer {}",
234 py_repr(delegatee),
235 py_repr_str(signer_did)
236 )));
237 }
238 let links = grant_chain::check_grant_chain(&grants, intent)?;
239 let child =
240 delegation::capability_view(&json!({"credentialSubject": {"intent": intent}}), false);
241 let capability = grant_chain::chain_capability(&grants, false)?;
242 if let Err(dimension) = attenuation::non_expansion(&capability, &child) {
243 return Err(refused(format!(
244 "Delegation violates the non-expansion rule: the child is broader than the parent \
245 grant on {}",
246 py_repr_str(dimension.as_str())
247 )));
248 }
249 Ok(links)
250}
251
252fn clamp_to_parent(parent: &Value, start_ns: i128, valid_seconds: i64) -> Result<(i128, i64)> {
255 let bound = |k: &str| {
256 parent
257 .get(k)
258 .and_then(Value::as_str)
259 .map(|t| parse_protocol_time_ns(t).map(to_micros))
260 };
261 let (Some(Ok(from)), Some(Ok(until))) = (bound("validFrom"), bound("validUntil")) else {
262 return Err(refused(
263 "Delegation refused: the parent grant has no validity window",
264 ));
265 };
266 let start = start_ns.max(from);
267 let remaining = (until - start) / NS_PER_SECOND;
269 if remaining <= 0 {
270 return Err(refused("Delegation refused: the parent grant has expired"));
271 }
272 let remaining = i64::try_from(remaining).unwrap_or(i64::MAX);
273 Ok((start, valid_seconds.min(remaining)))
274}
275
276pub fn prepare_credential(req: &IssueRequest) -> Result<Value> {
279 crate::nesting::deep_guard!(Err(crate::nesting::too_deep()); req);
280 check_issuer(&req.issuer_did)?;
281 let now = to_micros(parse_protocol_time_ns(&req.now)?);
282 let mut valid_seconds = match req.valid_seconds {
283 None => DEFAULT_VALID_SECONDS,
284 Some(s) if s > 0 => s,
285 Some(_) => return Err(refused(INVALID_VALID_SECONDS)),
286 };
287 let mut start = match &req.valid_from {
288 Some(t) => to_micros(parse_protocol_time_ns(t)?),
289 None => now,
290 };
291 let mut chain = req.delegation_chain.clone();
292 let mut parent_digest: Option<String> = None;
293 if let Some(parent) = &req.parent_credential {
294 if !req.intent.is_object() {
295 return Err(refused("intent must be a dict"));
296 }
297 let links = links_from_parent(parent, &req.intent, &req.issuer_did)?;
298 let direct = &links[links.len() - 1]["parentCredential"];
299 (start, valid_seconds) = clamp_to_parent(direct, start, valid_seconds)?;
300 if grant_chain::is_grant_intent(&req.intent) {
301 parent_digest = Some(
302 grant_chain::grant_digest(direct).map_err(|_| refused(PARENT_NOT_PLAIN_JSON))?,
303 );
304 chain = None;
305 } else {
306 chain = Some(Value::Array(links));
307 }
308 }
309
310 validate_intent(&req.intent)?;
311 let chain = chain.filter(truthy_chain);
312 if parent_digest.is_some() && chain.is_some() {
313 return Err(refused(
314 "a credential carries parentGrantDigest or a delegationChain, never both",
315 ));
316 }
317 let until = start + i128::from(valid_seconds) * NS_PER_SECOND;
318
319 let mut subject = Map::new();
320 subject.insert("id".into(), json!(req.issuer_did));
321 subject.insert(
322 "vouchVersion".into(),
323 json!(crate::credentials::PROTOCOL_VERSION),
324 );
325 subject.insert("intent".into(), req.intent.clone());
326 if let Some(score) = req.reputation_score {
327 subject.insert("reputationScore".into(), json!(score.clamp(0, 100)));
328 }
329 if let Some(digest) = parent_digest {
330 subject.insert(grant_chain::PARENT_GRANT_DIGEST.into(), json!(digest));
331 }
332 if let Some(chain) = chain {
333 subject.insert("delegationChain".into(), chain);
334 }
335 let id = match req.credential_id.as_deref() {
336 Some(id) if !id.is_empty() => id.to_string(),
337 _ => new_credential_id()?,
338 };
339 let mut vc = Map::new();
340 vc.insert(
341 "@context".into(),
342 json!([
343 crate::credentials::VC_CONTEXT_V2,
344 crate::credentials::VOUCH_CONTEXT_V1
345 ]),
346 );
347 vc.insert("id".into(), json!(id));
348 vc.insert(
349 "type".into(),
350 json!([
351 crate::credentials::VC_TYPE,
352 crate::credentials::VOUCH_CREDENTIAL_TYPE
353 ]),
354 );
355 vc.insert("issuer".into(), json!(req.issuer_did));
356 vc.insert("validFrom".into(), json!(format_protocol_time(start)?));
357 vc.insert("validUntil".into(), json!(format_protocol_time(until)?));
358 vc.insert("credentialSubject".into(), Value::Object(subject));
359 if let Some(status) = &req.credential_status {
360 vc.insert("credentialStatus".into(), status.clone());
361 }
362 Ok(Value::Object(vc))
363}
364
365fn truthy_chain(v: &Value) -> bool {
366 truthy(Some(v))
367}
368
369pub fn verification_method(req: &IssueRequest) -> String {
371 crate::nesting::deep_guard!(String::new(); req);
372 req.verification_method
373 .clone()
374 .unwrap_or_else(|| crate::verification_method::ed25519_method(&req.issuer_did))
375}
376
377fn slot_verification_method(ed25519_method: &str, slot: &str) -> String {
380 match ed25519_method.strip_suffix("#key-1") {
381 Some(base) => format!("{base}#{slot}"),
382 None => match ed25519_method.split_once('#') {
383 Some((base, _)) => format!("{base}#{slot}"),
384 None => format!("{ed25519_method}#{slot}"),
385 },
386 }
387}
388
389pub fn mldsa44_verification_method(ed25519_method: &str) -> String {
392 slot_verification_method(ed25519_method, "key-2")
393}
394
395pub fn slhdsa128_verification_method(ed25519_method: &str) -> String {
398 slot_verification_method(ed25519_method, "key-3")
399}
400
401fn created(req: &IssueRequest) -> Result<String> {
403 format_protocol_time(parse_protocol_time_ns(&req.now)?)
404}
405
406pub fn check_issuer(did: &str) -> Result<()> {
409 if did.is_empty() {
410 return Err(refused(
411 "Vouch Signer requires 'did' (Decentralized Identifier)",
412 ));
413 }
414 if !(did.starts_with("did:") && did.len() > 4) {
415 return Err(refused(NOT_A_DID));
416 }
417 Ok(())
418}
419
420fn check_signer(req: &IssueRequest, ed25519_seed: &[u8]) -> Result<()> {
421 check_issuer(&req.issuer_did)?;
422 let kp = crate::keys::Ed25519KeyPair::from_seed_slice(ed25519_seed)?;
423 match did_key_mismatch(&req.issuer_did, &kp.public_key()) {
424 Some(problem) => Err(refused(problem)),
425 None => Ok(()),
426 }
427}
428
429pub fn issue_credential(req: &IssueRequest, ed25519_seed: &[u8]) -> Result<Value> {
432 crate::nesting::deep_guard!(Err(crate::nesting::too_deep()); req);
433 check_signer(req, ed25519_seed)?;
434 let unsigned = prepare_credential(req)?;
435 let opts = BuildProofOptions::new(verification_method(req), created(req)?);
436 data_integrity::sign(&unsigned, ed25519_seed, &opts)
437}
438
439pub fn issue_credential_dual(
445 req: &IssueRequest,
446 ed25519_seed: &[u8],
447 mldsa44: &crate::pq::MlDsa44KeyPair,
448) -> Result<Value> {
449 crate::nesting::deep_guard!(Err(crate::nesting::too_deep()); req);
450 issue_credential_set(req, ed25519_seed, Some(mldsa44), None)
451}
452
453pub fn issue_credential_set(
460 req: &IssueRequest,
461 ed25519_seed: &[u8],
462 mldsa44: Option<&crate::pq::MlDsa44KeyPair>,
463 slhdsa128: Option<&crate::slh::SlhDsa128KeyPair>,
464) -> Result<Value> {
465 crate::nesting::deep_guard!(Err(crate::nesting::too_deep()); req);
466 check_signer(req, ed25519_seed)?;
467 let unsigned = prepare_credential(req)?;
468 let ed_vm = verification_method(req);
469 let ml_vm = mldsa44_verification_method(&ed_vm);
470 let slh_vm = slhdsa128_verification_method(&ed_vm);
471 crate::hybrid::sign_set(
472 &unsigned,
473 ed25519_seed,
474 &ed_vm,
475 mldsa44.map(|key| crate::hybrid::PqSigner {
476 key,
477 verification_method: &ml_vm,
478 }),
479 slhdsa128.map(|key| crate::hybrid::PqSigner {
480 key,
481 verification_method: &slh_vm,
482 }),
483 &created(req)?,
484 )
485}
486
487pub fn prepare_signing(req: &IssueRequest) -> Result<Value> {
493 crate::nesting::deep_guard!(Err(crate::nesting::too_deep()); req);
494 use base64::{engine::general_purpose::STANDARD, Engine};
495 let unsigned = prepare_credential(req)?;
496 let mut proof = Map::new();
497 proof.insert("type".into(), json!(data_integrity::PROOF_TYPE));
498 proof.insert("cryptosuite".into(), json!(data_integrity::CRYPTOSUITE_ID));
499 proof.insert("created".into(), json!(created(req)?));
500 proof.insert("verificationMethod".into(), json!(verification_method(req)));
501 proof.insert("proofPurpose".into(), json!("assertionMethod"));
502 data_integrity::add_document_context(&unsigned, &mut proof);
503 let input = data_integrity::hash_data(&unsigned, &proof)?;
504 Ok(json!({
505 "credential": unsigned,
506 "proof": Value::Object(proof),
507 "signingInput": STANDARD.encode(input),
508 }))
509}
510
511const REQUEST_MEMBERS: [&str; 17] = [
516 "issuer",
517 "intent",
518 "now",
519 "validFrom",
520 "validSeconds",
521 "reputationScore",
522 "delegationChain",
523 "parentCredential",
524 "credentialId",
525 "credentialStatus",
526 "verificationMethod",
527 "ed25519Seed",
528 "postQuantum",
529 "mldsa44SecretKey",
530 "mldsa44PublicKey",
531 "slhdsa128SecretKey",
532 "prepare",
533];
534
535fn present<'a>(obj: &'a Map<String, Value>, name: &str) -> Option<&'a Value> {
536 obj.get(name).filter(|v| !v.is_null())
537}
538
539fn text(obj: &Map<String, Value>, name: &str) -> Result<Option<String>> {
540 match present(obj, name) {
541 None => Ok(None),
542 Some(Value::String(s)) => Ok(Some(s.clone())),
543 Some(_) => Err(refused(format!("{name} must be a string"))),
544 }
545}
546
547fn b64(obj: &Map<String, Value>, name: &str) -> Result<Option<Vec<u8>>> {
548 use base64::{engine::general_purpose::STANDARD, Engine};
549 text(obj, name)?
550 .map(|s| {
551 STANDARD
552 .decode(s)
553 .map_err(|_| refused(format!("{name} must be standard base64")))
554 })
555 .transpose()
556}
557
558pub fn issue_request_from_json(obj: &Map<String, Value>) -> Result<IssueRequest> {
560 crate::nesting::deep_guard!(Err(crate::nesting::too_deep()); obj);
561 if let Some(name) = obj.keys().find(|k| !REQUEST_MEMBERS.contains(&k.as_str())) {
562 return Err(refused(format!(
563 "the request holds an unknown member {:?}",
564 name.chars().take(40).collect::<String>()
565 )));
566 }
567 let valid_seconds = match present(obj, "validSeconds") {
570 None => None,
571 Some(Value::Number(n)) if n.is_i64() => n.as_i64(),
572 Some(_) => Some(i64::MIN),
573 };
574 let whole = |name: &str| -> Result<Option<i64>> {
575 match present(obj, name) {
576 None => Ok(None),
577 Some(Value::Number(n)) => n
578 .as_i64()
579 .or_else(|| {
580 n.as_f64()
581 .filter(|f| f.is_finite())
582 .map(|f| crate::float::trunc(f) as i64)
583 })
584 .map(Some)
585 .ok_or_else(|| refused(format!("{name} must be a number"))),
586 Some(_) => Err(refused(format!("{name} must be a number"))),
587 }
588 };
589 Ok(IssueRequest {
590 issuer_did: text(obj, "issuer")?.ok_or_else(|| refused("issuer must be a DID"))?,
591 intent: obj.get("intent").cloned().unwrap_or(Value::Null),
592 now: text(obj, "now")?.ok_or_else(|| refused("now must be a protocol time"))?,
593 valid_from: text(obj, "validFrom")?,
594 valid_seconds,
595 reputation_score: whole("reputationScore")?,
596 delegation_chain: present(obj, "delegationChain").cloned(),
597 parent_credential: present(obj, "parentCredential").cloned(),
598 credential_id: text(obj, "credentialId")?,
599 credential_status: present(obj, "credentialStatus").cloned(),
600 verification_method: text(obj, "verificationMethod")?,
601 })
602}
603
604pub fn issue_json(request: &Value) -> Result<Value> {
615 crate::nesting::deep_guard!(Err(crate::nesting::too_deep()); request);
616 let obj = request
617 .as_object()
618 .ok_or_else(|| refused("the request must be a JSON object"))?;
619 let req = issue_request_from_json(obj)?;
620 if matches!(present(obj, "prepare"), Some(Value::Bool(true))) {
621 return prepare_signing(&req);
622 }
623 let seed =
625 Zeroizing::new(b64(obj, "ed25519Seed")?.ok_or_else(|| refused("ed25519Seed is required"))?);
626 if matches!(present(obj, "postQuantum"), Some(Value::Bool(true))) {
627 let slhdsa = match b64(obj, "slhdsa128SecretKey")?.map(Zeroizing::new) {
628 Some(secret) => Some(crate::slh::SlhDsa128KeyPair::from_secret(&secret)?),
629 None => None,
630 };
631 let wants_mldsa = slhdsa.is_none()
634 || present(obj, "mldsa44SecretKey").is_some()
635 || present(obj, "mldsa44PublicKey").is_some();
636 let mldsa = if wants_mldsa {
637 let secret = Zeroizing::new(
638 b64(obj, "mldsa44SecretKey")?
639 .ok_or_else(|| refused("mldsa44SecretKey is required for postQuantum"))?,
640 );
641 let public = b64(obj, "mldsa44PublicKey")?
642 .ok_or_else(|| refused("mldsa44PublicKey is required for postQuantum"))?;
643 Some(crate::pq::MlDsa44KeyPair::from_bytes(&secret, &public)?)
644 } else {
645 None
646 };
647 return issue_credential_set(&req, &seed, mldsa.as_ref(), slhdsa.as_ref());
648 }
649 issue_credential(&req, &seed)
650}
651
652pub const SECRET_MEMBERS: [&str; 3] = ["ed25519Seed", "mldsa44SecretKey", "slhdsa128SecretKey"];
654
655pub fn wipe_secrets(request: &mut Value) {
659 if let Some(obj) = request.as_object_mut() {
660 for name in SECRET_MEMBERS {
661 if let Some(Value::String(text)) = obj.get_mut(name) {
662 text.zeroize();
663 }
664 obj.remove(name);
665 }
666 }
667}
668
669pub fn issue_json_text(mut request: String) -> Result<Value> {
673 if let Err(e) = crate::nesting::check_text(request.as_bytes()) {
674 request.zeroize();
675 return Err(e);
676 }
677 let parsed = serde_json::from_str::<Value>(&request);
678 request.zeroize();
679 let mut parsed = parsed.map_err(|e| refused(format!("the request is not JSON: {e}")))?;
680 let out = issue_json(&parsed);
681 wipe_secrets(&mut parsed);
682 out
683}
684
685pub fn delegation_links_json(request: &Value) -> Result<Value> {
688 crate::nesting::deep_guard!(Err(crate::nesting::too_deep()); request);
689 let obj = request
690 .as_object()
691 .ok_or_else(|| refused("the request must be a JSON object"))?;
692 let parent = obj.get("parentCredential").unwrap_or(&Value::Null);
693 let intent = obj.get("intent").unwrap_or(&Value::Null);
694 let signer = text(obj, "signerDid")?.unwrap_or_default();
695 Ok(Value::Array(links_from_parent(parent, intent, &signer)?))
696}
697
698crate::nesting::nested_fields!(IssueRequest; intent, delegation_chain, parent_credential, credential_status);
700
701#[cfg(test)]
702mod tests {
703 use super::*;
704
705 #[test]
706 fn formats_whole_seconds() {
707 let t = parse_protocol_time_ns("2026-04-26T10:00:00.999Z").unwrap();
708 assert_eq!(format_protocol_time(t).unwrap(), "2026-04-26T10:00:00Z");
709 let t = parse_protocol_time_ns("2000-02-29T23:59:59Z").unwrap();
710 assert_eq!(format_protocol_time(t).unwrap(), "2000-02-29T23:59:59Z");
711 let t = parse_protocol_time_ns("1969-12-31T23:59:59Z").unwrap();
712 assert_eq!(format_protocol_time(t).unwrap(), "1969-12-31T23:59:59Z");
713 }
714
715 #[test]
716 #[cfg_attr(not(feature = "std"), ignore = "needs a random source (std)")]
717 fn credential_ids_are_uuid_v4() {
718 let id = new_credential_id().unwrap();
719 assert_eq!(id.len(), "urn:uuid:".len() + 36);
720 assert_eq!(&id[23..24], "4");
721 }
722
723 #[test]
724 fn did_key_must_name_the_signing_key() {
725 let kp = crate::keys::Ed25519KeyPair::from_seed(&[1u8; 32]);
726 assert!(did_key_mismatch(&kp.did_key(), &kp.public_key()).is_none());
727 let other = crate::keys::Ed25519KeyPair::from_seed(&[2u8; 32]);
728 assert!(did_key_mismatch(&other.did_key(), &kp.public_key()).is_some());
729 assert!(did_key_mismatch("did:web:a.example", &kp.public_key()).is_none());
730 }
731}