junobuild_auth/delegation/
types.rs

1use crate::openid::jwkset::types::errors::GetOrRefreshJwksError;
2use crate::openid::jwt::types::errors::{JwtFindProviderError, JwtVerifyError};
3use crate::state::types::state::Salt;
4use candid::{CandidType, Deserialize, Principal};
5use serde::Serialize;
6use serde_bytes::ByteBuf;
7
8#[derive(CandidType, Serialize, Deserialize)]
9pub struct OpenIdPrepareDelegationArgs {
10    pub jwt: String,
11    pub salt: Salt,
12    pub session_key: SessionKey,
13}
14
15#[derive(CandidType, Serialize, Deserialize)]
16pub struct OpenIdGetDelegationArgs {
17    pub jwt: String,
18    pub salt: Salt,
19    pub session_key: SessionKey,
20    pub expiration: Timestamp,
21}
22
23pub type UserKey = PublicKey;
24pub type PublicKey = ByteBuf;
25pub type SessionKey = PublicKey;
26pub type Timestamp = u64;
27pub type Signature = ByteBuf;
28
29pub type PrepareDelegationResult = Result<PreparedDelegation, PrepareDelegationError>;
30pub type GetDelegationResult = Result<SignedDelegation, GetDelegationError>;
31
32#[derive(CandidType, Serialize, Deserialize)]
33pub struct PreparedDelegation {
34    pub user_key: UserKey,
35    pub expiration: Timestamp,
36}
37
38#[derive(CandidType, Serialize, Deserialize)]
39pub struct SignedDelegation {
40    pub delegation: Delegation,
41    pub signature: Signature,
42}
43
44pub type DelegationTargets = Vec<Principal>;
45
46#[derive(CandidType, Serialize, Deserialize)]
47pub struct Delegation {
48    pub pubkey: PublicKey,
49    pub expiration: Timestamp,
50    pub targets: Option<DelegationTargets>,
51}
52
53#[derive(CandidType, Serialize, Deserialize, Debug)]
54pub enum PrepareDelegationError {
55    DeriveSeedFailed(String),
56    GetOrFetchJwks(GetOrRefreshJwksError),
57    GetCachedJwks,
58    JwtFindProvider(JwtFindProviderError),
59    JwtVerify(JwtVerifyError),
60}
61
62#[derive(CandidType, Serialize, Deserialize, Debug)]
63pub enum GetDelegationError {
64    NoSuchDelegation,
65    DeriveSeedFailed(String),
66    GetOrFetchJwks(GetOrRefreshJwksError),
67    GetCachedJwks,
68    JwtFindProvider(JwtFindProviderError),
69    JwtVerify(JwtVerifyError),
70}