ic_auth_wire/model/credential.rs
1//! Fixed proof layouts. Every field is untrusted until full verification.
2
3use ic_auth_protocol_types::Principal;
4use ic_wire::{Bytes, List, Text};
5use serde::{Deserialize, Serialize};
6
7///
8/// AudienceId
9///
10/// Claimed network and application identities, in fixed transport order.
11///
12
13#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
14pub struct AudienceId {
15 /// Claimed canonical network identifier.
16 pub canonical_network_id: [u8; 32],
17 /// Claimed application identifier; the historical field name is retained.
18 pub fleet_id: [u8; 32],
19}
20
21///
22/// DelegatedRoleGrant
23///
24/// Bounded grant text, before label grammar and authorization checks.
25///
26
27#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
28pub struct DelegatedRoleGrant {
29 /// Claimed role, not a protected role selection.
30 pub target: Text<64>,
31 /// Claimed scopes in received order; transport does not normalize them.
32 pub scopes: List<Text<64>, 32>,
33}
34
35///
36/// DelegationAudience
37///
38/// Delegation audience tag and payload.
39///
40
41#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
42pub enum DelegationAudience {
43 /// Network/application audience, retaining the existing tag name.
44 Fleet(AudienceId),
45}
46
47///
48/// ChainKeyAlgorithm
49///
50/// Root chain-key algorithm tag; this does not select trusted enrollment.
51///
52
53#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
54pub enum ChainKeyAlgorithm {
55 /// ECDSA on secp256k1.
56 EcdsaSecp256k1,
57}
58
59///
60/// ChainKeyKeyId
61///
62/// Untrusted root key lookup hint.
63///
64
65#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
66pub struct ChainKeyKeyId {
67 /// Bounded key name.
68 pub name: Text<128>,
69}
70
71///
72/// IssuerProofAlgorithm
73///
74/// Issuer proof algorithm tag, checked against protected enrollment later.
75///
76
77#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
78pub enum IssuerProofAlgorithm {
79 /// Version-one IC canister signature.
80 IcCanisterSignatureV1,
81}
82
83///
84/// IssuerProofBinding
85///
86/// Claimed issuer key binding; not an independent trust anchor.
87///
88
89#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
90pub enum IssuerProofBinding {
91 /// SHA-256 seed hash of the issuer canister-signature public key.
92 IcCanisterSignatureV1([u8; 32]),
93}
94
95///
96/// IcCanisterSignatureProofV1
97///
98/// Bounded opaque canister-signature material.
99///
100
101#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
102pub struct IcCanisterSignatureProofV1 {
103 /// CBOR signature/certificate/witness bytes requiring complete verification.
104 pub signature_cbor: Bytes<131072>,
105 /// DER key bytes requiring issuer and seed binding checks.
106 pub public_key_der: Bytes<256>,
107}
108
109///
110/// ChainKeyBatchHeaderV1
111///
112/// Claimed signed batch-header fields, preserving their existing order.
113///
114
115#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
116pub struct ChainKeyBatchHeaderV1 {
117 /// Claimed header schema, not validated by transport.
118 pub schema_version: u16,
119 /// Claimed root canister.
120 pub root_canister_id: Principal,
121 /// Batch identity.
122 pub batch_id: [u8; 32],
123 /// Claimed proof epoch.
124 pub proof_epoch: u64,
125 /// Claimed registry epoch.
126 pub registry_epoch: u64,
127 /// Registry commitment.
128 pub registry_hash: [u8; 32],
129 /// Merkle tree root.
130 pub tree_root: [u8; 32],
131 /// Inclusive validity start, in nanoseconds.
132 pub not_before_ns: u64,
133 /// Exclusive expiry, in nanoseconds.
134 pub expires_at_ns: u64,
135 /// Claimed root-signature algorithm.
136 pub algorithm: ChainKeyAlgorithm,
137 /// Claimed key name.
138 pub key_id: ChainKeyKeyId,
139 /// Derivation-path commitment.
140 pub derivation_path_hash: [u8; 32],
141 /// Claimed key version.
142 pub key_version: u64,
143}
144
145///
146/// ChainKeyDelegationCertV1
147///
148/// Delegation leaf carried with a chain-key batch proof.
149///
150
151#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
152pub struct ChainKeyDelegationCertV1 {
153 /// Claimed root canister.
154 pub root_canister_id: Principal,
155 /// Claimed delegated issuer.
156 pub issuer_canister_id: Principal,
157 /// Claimed proof epoch.
158 pub proof_epoch: u64,
159 /// Claimed issuer proof mechanism.
160 pub issuer_proof_algorithm: IssuerProofAlgorithm,
161 /// Issuer-binding commitment.
162 pub issuer_proof_binding_hash: [u8; 32],
163 /// Claimed issuer key binding.
164 pub issuer_proof_binding: IssuerProofBinding,
165 /// Claimed maximum credential lifetime, in nanoseconds.
166 pub max_token_ttl_ns: u64,
167 /// Claimed audience restriction.
168 pub audience: DelegationAudience,
169 /// Unnormalized delegated role/scope claims.
170 pub grants: List<DelegatedRoleGrant, 16>,
171 /// Inclusive validity start, in nanoseconds.
172 pub not_before_ns: u64,
173 /// Exclusive expiry, in nanoseconds.
174 pub expires_at_ns: u64,
175 /// Claimed registry epoch.
176 pub registry_epoch: u64,
177 /// Registry commitment.
178 pub registry_hash: [u8; 32],
179}
180
181///
182/// ChainKeyRootSignatureV1
183///
184/// Bounded root-signature material; length bounds do not verify a signature.
185///
186
187#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
188pub struct ChainKeyRootSignatureV1 {
189 /// Claimed root-signature algorithm.
190 pub algorithm: ChainKeyAlgorithm,
191 /// Untrusted key lookup hint.
192 pub key_id: ChainKeyKeyId,
193 /// Derivation components, in their supplied order.
194 pub derivation_path: List<Bytes<256>, 32>,
195 /// Root public-key material, not a trusted key installation.
196 pub public_key: Bytes<65>,
197 /// Root signature bytes.
198 pub signature: Bytes<64>,
199}
200
201///
202/// ChainKeyBatchWitnessStepV1
203///
204/// Ordered Merkle witness step with the existing discriminants.
205///
206
207#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
208pub enum ChainKeyBatchWitnessStepV1 {
209 /// Sibling preceding the current node.
210 LeftSibling([u8; 32]),
211 /// Sibling following the current node.
212 RightSibling([u8; 32]),
213}
214
215///
216/// ChainKeyBatchWitnessV1
217///
218/// Bounded ordered batch witness.
219///
220
221#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
222pub struct ChainKeyBatchWitnessV1 {
223 /// At most 64 sibling steps.
224 pub steps: List<ChainKeyBatchWitnessStepV1, 64>,
225}
226
227///
228/// IcChainKeyBatchSignatureProofV1
229///
230/// Root batch proof with all authenticated fields still unverified.
231///
232
233#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
234pub struct IcChainKeyBatchSignatureProofV1 {
235 /// Signed batch header.
236 pub header: ChainKeyBatchHeaderV1,
237 /// Issuer delegation leaf.
238 pub delegation_cert: ChainKeyDelegationCertV1,
239 /// Leaf inclusion witness.
240 pub issuer_witness: ChainKeyBatchWitnessV1,
241 /// Root signature and untrusted key material.
242 pub signature: ChainKeyRootSignatureV1,
243}
244
245///
246/// RootProof
247///
248/// Root proof tag and its bounded payload.
249///
250
251#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
252pub enum RootProof {
253 /// Version-one chain-key batch signature proof.
254 IcChainKeyBatchSignatureV1(IcChainKeyBatchSignatureProofV1),
255}
256
257///
258/// DelegationCert
259///
260/// Claimed root delegation; duplicate commitments require verifier agreement.
261///
262
263#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
264pub struct DelegationCert {
265 /// Claimed root identity.
266 pub root_pid: Principal,
267 /// Claimed issuer identity.
268 pub issuer_pid: Principal,
269 /// Claimed issuer proof mechanism.
270 pub issuer_proof_alg: IssuerProofAlgorithm,
271 /// Issuer-binding commitment.
272 pub issuer_proof_binding_hash: [u8; 32],
273 /// Claimed issuer key binding.
274 pub issuer_proof_binding: IssuerProofBinding,
275 /// Claimed issuance time, in nanoseconds.
276 pub issued_at_ns: u64,
277 /// Inclusive validity start, in nanoseconds.
278 pub not_before_ns: u64,
279 /// Exclusive expiry, in nanoseconds.
280 pub expires_at_ns: u64,
281 /// Claimed maximum credential lifetime, in nanoseconds.
282 pub max_token_ttl_ns: u64,
283 /// Claimed audience restriction.
284 pub aud: DelegationAudience,
285 /// Unnormalized delegated role/scope claims.
286 pub grants: List<DelegatedRoleGrant, 16>,
287}
288
289///
290/// DelegationProof
291///
292/// Claimed delegation and its root evidence.
293///
294
295#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
296pub struct DelegationProof {
297 /// Claimed delegation certificate.
298 pub cert: DelegationCert,
299 /// Root evidence, requiring protected authority verification.
300 pub root_proof: RootProof,
301}
302
303///
304/// CertifiedProof
305///
306/// Bounded certified credential proof.
307///
308
309#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
310pub struct CertifiedProof {
311 /// Root delegation evidence for the issuer.
312 pub delegation: DelegationProof,
313 /// Issuer signature over the canonical claims digest and domain.
314 pub issuer_signature: IcCanisterSignatureProofV1,
315}
316
317///
318/// PortableProof
319///
320/// Claimed proof mechanism; the host's enrollment selects the verifier.
321///
322
323#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
324#[expect(
325 clippy::large_enum_variant,
326 reason = "Wire 0.33 projects sparse evidence inline. Domain conversion boxes the certified variant."
327)]
328pub enum PortableProof {
329 /// Root-delegated certified issuer proof, transport tag zero.
330 Certified(CertifiedProof),
331 /// At most 64 signature bytes; strict verification later requires exactly 64.
332 Ed25519(Bytes<64>),
333}
334
335///
336/// PortableCredential
337///
338/// Opaque signed claims with an unverified proof envelope.
339///
340
341#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ic_wire::Wire)]
342pub struct PortableCredential {
343 /// Exact received signed bytes; transport must not decode/re-encode them.
344 pub claims: Bytes<65536>,
345 /// Claimed proof material requiring verification against protected inputs.
346 pub proof: PortableProof,
347}