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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
//! Substrate primitive for BLAKE3 hex digests.
//!
//! Two peer entries — [`hex_blake3`] for the in-memory-buffer shape
//! (`hex::encode(blake3::hash(bytes).as_bytes())`) every three-pillar
//! attestation producer that fed BLAKE3 a single buffer restated by
//! hand pre-lift, and [`hex_blake3_hash`] for the streaming-digest
//! shape (`hex::encode(hash.as_bytes())` where `hash =
//! blake3::Hasher::finalize()`) every consumer that folded per-item
//! updates into a `Hasher` before finalizing walked. Both peers ride
//! through ONE hex-encoding step at [`hex_blake3_hash`] so a future
//! swap onto `blake3::Hash::to_hex().to_string()` (or a different
//! encoding — base32, base64url, uppercase hex for a downstream tool)
//! lands at ONE substrate function and every downstream three-pillar
//! consumer inherits the upgrade mechanically.
//!
//! Return type is `String` for wire-shape stability with the pre-lift
//! consumers — `ReceiptEnvelope.{intent,artifact,control}_hash` are
//! typed as `String`, so a `Cow`/`&str` return would force allocation
//! at every call site regardless.
//!
//! # Which peer to call
//!
//! - Have `&[u8]` in hand → [`hex_blake3`]. Internally it composes
//! [`hex_blake3_hash`] over `blake3::hash(bytes)`.
//! - Have a `blake3::Hasher` you already folded per-item updates into
//! → `hex_blake3_hash(&h.finalize())`. Skips the one-shot round-trip
//! through `&[u8]` that would force the caller to materialize the
//! full input buffer just to re-hash it.
/// Compute the lowercase 64-char BLAKE3 hex digest of `bytes`.
///
/// # Invariants
///
/// - **Length:** the returned string is always exactly 64 chars
/// (BLAKE3's 32-byte digest encoded as lowercase hex).
/// - **Charset:** every char is one of `[0-9a-f]` (lowercase).
/// - **Determinism:** byte-identical output across runs for the same
/// input; matches both the `hex::encode(blake3::hash(x).as_bytes())`
/// and `blake3::hash(x).to_hex().to_string()` pre-lift spellings.
///
/// # `#[must_use]`
///
/// Every consumer either stores the returned hex into a receipt
/// pillar (`intent_hash`, `artifact_hash`, `control_hash`) or feeds
/// it into a DNS slot / stable name. Dropping the return means the
/// hash was computed for no observable reason — the attribute
/// surfaces that as a warning at every call site.
///
/// Delegates the terminal `hex::encode(...as_bytes())` step to the
/// sibling [`hex_blake3_hash`] primitive so the encoding rule lives at
/// ONE substrate owner; a future re-encoding (base32, base64url,
/// uppercase, `blake3::Hash::to_hex()`) reaches BOTH the one-shot and
/// the streaming corner through ONE edit.
/// Streaming-digest peer of [`hex_blake3`] — the ONE substrate owner
/// of the 1-link `hex::encode(hash.as_bytes())` encoding step every
/// three-pillar producer that folded per-item updates into a
/// `blake3::Hasher` walked pre-lift.
///
/// # Why it exists
///
/// The `Hasher::finalize() → hex::encode(<Hash>.as_bytes())` chain was
/// hand-authored at TWO sites past the ★★ PRIME-DIRECTIVE ≥ 2
/// duplication threshold, each carrying a `Hasher` it fed per-item
/// updates into before finalizing:
///
/// * [`crate::three_pillar::compose_root`] — folds the domain tag +
/// the four pillars (artifact, control, intent, previous) into a
/// `blake3::Hasher`, then encodes the final hash. Pre-lift ended
/// with `hex::encode(h.finalize().as_bytes())` inline; post-lift
/// ends with `hex_blake3_hash(&h.finalize())`.
/// * `tatara-reconciler::phase_machine::handle_running` — folds each
/// observed FluxCD resource's `(apiVersion, kind, ns, name)`
/// 4-slot identity into a `blake3::Hasher`, then encodes the final
/// hash as the artifact-pillar input for the ATTEST step.
///
/// Pre-lift the one-shot corner ([`hex_blake3`]) and the streaming
/// corner both restated `hex::encode(...as_bytes())` at their own
/// bodies, leaving a two-place drift trap — a future swap onto
/// `blake3::Hash::to_hex().to_string()` (a subtler pre-existing
/// spelling that appears at `crate::hostname::short_hex_blake3`), an
/// uppercase-hex flip for a downstream tool, or a base32-encoded
/// variant would have to land at BOTH sites or silently break receipt
/// verification at the corner that missed the update. Post-lift the
/// terminal hex step lives at ONE substrate owner and the one-shot
/// peer's body reduces to `hex_blake3_hash(&blake3::hash(bytes))`.
///
/// # Invariants
///
/// Same shape as [`hex_blake3`]: 64 chars of lowercase hex, every
/// char in `[0-9a-f]`, byte-identical to the pre-lift `hex::encode(<
/// hash>.as_bytes())` spelling.
///
/// # `#[must_use]`
///
/// Every consumer either stores the returned hex into a receipt
/// pillar or a `composed_root` slot. Dropping the return means the
/// caller finalized a `Hasher` for no observable reason — the
/// attribute surfaces that as a warning at every call site.
///
/// Theory anchor: THEORY.md §VI.1 (generation over composition — the
/// `hex::encode(...as_bytes())` step recurred at two hand-authored
/// sites past the ★★ PRIME-DIRECTIVE ≥ 2 duplication trigger, and is
/// lifted to ONE owner here). THEORY.md §II.1 invariant 5
/// (composition preserves proofs — the pin
/// [`tests::hex_blake3_hash_matches_pre_lift_hex_encode_spelling_bytewise`]
/// binds the streaming corner byte-identically to the pre-lift
/// spelling, and the cross-corner pin
/// [`tests::hex_blake3_bytes_form_delegates_through_hex_blake3_hash`]
/// binds the one-shot peer to `hex_blake3_hash` so a regression in
/// either surfaces at ONE substrate pin rather than as silent
/// composed_root drift across every downstream consumer).