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