Skip to main content

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