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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//! Batch signing and verification operations on SimpleAgent.
//!
//! These functions accept a `&SimpleAgent` reference and provide batch
//! operations. They were previously methods on `SimpleAgent` and were moved
//! here as part of Phase 5 (narrow contract).
use crateDocumentTraits;
use crateJacsError;
use cratecheck_document_size;
use crateSimpleAgent;
use crate*;
use ;
use info;
/// Signs multiple messages in a batch operation.
///
/// # IMPORTANT: Each Signature is Sacred
///
/// **Every signature in the batch is an irreversible, permanent commitment.**
/// Batch signing is convenient, but each document is independently signed with
/// full cryptographic weight. Before batch signing:
/// - Review ALL messages in the batch
/// - Verify each message represents your intent
/// - Understand you are making multiple permanent commitments
///
/// This is more efficient than calling `sign_message` repeatedly because it
/// amortizes the overhead of acquiring locks and key operations across all
/// messages.
///
/// # Arguments
///
/// * `agent` - The SimpleAgent to use for signing
/// * `messages` - A slice of JSON values to sign
///
/// # Returns
///
/// A vector of `SignedDocument` objects, one for each input message, in the
/// same order as the input slice.
///
/// # Errors
///
/// Returns an error if signing any message fails. In case of failure,
/// documents created before the failure are still stored but the partial
/// results are not returned (all-or-nothing return semantics).
///
/// # Example
///
/// ```rust,ignore
/// use jacs::simple::SimpleAgent;
/// use jacs::simple::batch;
/// use serde_json::json;
///
/// let agent = SimpleAgent::load(None, None)?;
///
/// let messages = vec![
/// json!({"action": "approve", "item": 1}),
/// json!({"action": "approve", "item": 2}),
/// ];
///
/// let refs: Vec<&serde_json::Value> = messages.iter().collect();
/// let signed_docs = batch::sign_messages(&agent, &refs)?;
/// ```
/// Verifies multiple signed documents in a batch operation.
///
/// This function processes each document sequentially, verifying signatures
/// and hashes for each. All documents are processed regardless of individual
/// failures, and results are returned for each input document.
///
/// # Arguments
///
/// * `agent` - The SimpleAgent to use for verification
/// * `documents` - A slice of JSON strings, each representing a signed JACS document
///
/// # Returns
///
/// A vector of `VerificationResult` in the same order as the input documents.
///
/// # Example
///
/// ```rust,ignore
/// use jacs::simple::SimpleAgent;
/// use jacs::simple::batch;
///
/// let agent = SimpleAgent::load(None, None)?;
///
/// let documents = vec![signed_doc1.as_str(), signed_doc2.as_str()];
/// let results = batch::verify(&agent, &documents);
/// for (i, result) in results.iter().enumerate() {
/// if result.valid {
/// println!("Document {} verified successfully", i);
/// }
/// }
/// ```