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