1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//! [`sign_trust_task`] — the sign-side counterpart to the
//! [`Verifier`](super::Verifier).
//!
//! Produces documents that the stock [`Verifier`](super::Verifier)
//! accepts by construction: the proof is computed over the document with
//! the `proof` member removed (the same canonicalisation contract the
//! verify side applies), and the in-band `issuer` is checked *before*
//! signing to equal the DID of the signer's `verificationMethod` — the
//! §4.7/§4.8 issuer binding the verify side enforces. A document that
//! would fail its own round-trip is rejected at sign time rather than at
//! the consumer.
//!
//! Defaults match the reference ecosystem's signing profile:
//! `proofPurpose: assertionMethod` (the upstream default) and the
//! `eddsa-jcs-2022` cryptosuite (applied here whenever the caller does
//! not pick a suite explicitly, overriding any signer-declared default so
//! the emitted suite is deterministic). Override either via
//! [`SignOptions`].
//!
//! ```rust,ignore
//! use trust_tasks_proof::affinidi::{sign_trust_task, SignOptions};
//!
//! // `doc` is the Trust Task document as serde_json::Value, `issuer`
//! // already set to the DID the secret's verification method belongs to.
//! let signed = sign_trust_task(&doc, &secret, SignOptions::new()).await?;
//! assert!(signed.get("proof").is_some());
//! ```
use CryptoSuite;
use Signer;
use ;
use Value;
/// Errors surfaced by [`sign_trust_task`].
/// Sign a Trust Task document and return it with an embedded `proof`.
///
/// The proof is computed over the document with the `proof` member
/// removed, exactly as the [`Verifier`](super::Verifier) canonicalises on
/// the verify side. **Any existing `proof` member is discarded and
/// replaced** — re-signing an already-signed document is treated as "mint
/// a fresh proof over the current content", never as appending a proof
/// set or signing over the old proof.
///
/// Defaults: `proofPurpose` falls back to `"assertionMethod"` (upstream
/// default) and the cryptosuite to [`CryptoSuite::EddsaJcs2022`] whenever
/// [`SignOptions::cryptosuite`] is unset — deliberately overriding the
/// signer's own declared default so the wire suite does not silently vary
/// with the signer implementation. Pass
/// [`SignOptions::with_cryptosuite`] / [`SignOptions::with_proof_purpose`]
/// to choose different values.
///
/// The document **must** already carry an in-band `issuer` equal to the
/// DID of the signer's `verificationMethod` (the portion before `#`,
/// compared by exact string equality per SPEC.md §4.8). This is the same
/// binding the stock verifier enforces; checking it here means a document
/// that could never verify is refused before a signature is produced.
///
/// `signer` is anything implementing the upstream
/// [`Signer`](affinidi_data_integrity::signer::Signer) trait —
/// an `affinidi_secrets_resolver::secrets::Secret` works directly, as do
/// KMS/HSM-backed remote signers.
pub async