Skip to main content

pg_core/
api.rs

1//! Definitions of the PostGuard protocol REST API.
2
3use crate::{artifacts::SigningKeyExt, identity::Attribute};
4use alloc::string::String;
5use alloc::vec::Vec;
6use irma::{ProofStatus, SessionStatus};
7use serde::{Deserialize, Serialize};
8
9/// The public parameters of the Private Key Generator (PKG).
10#[derive(Debug, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct Parameters<T> {
13    /// The formatting version of the Master Public Key.
14    pub format_version: u8,
15
16    /// The Master Public Key.
17    pub public_key: T,
18}
19
20/// An attribute in a disclosure request, extending [`Attribute`] with an `optional` flag.
21///
22/// When `optional` is true, the PKG wraps this attribute in a disjunction with an empty
23/// first option, allowing the user to skip disclosing it in the Yivi app.
24///
25/// This type is only used in API requests (JSON), not in the binary wire format.
26#[derive(Debug, Serialize, Deserialize, Clone)]
27pub struct DisclosureAttribute {
28    /// Attribute type.
29    #[serde(rename = "t")]
30    pub atype: String,
31
32    /// Attribute value.
33    #[serde(rename = "v")]
34    pub value: Option<String>,
35
36    /// Whether this attribute is optional in the disclosure session.
37    #[serde(default, skip_serializing_if = "crate::util::is_false")]
38    pub optional: bool,
39}
40
41/// An authentication request for a IRMA identity.
42#[derive(Debug, Serialize, Deserialize)]
43pub struct IrmaAuthRequest {
44    /// The conjunction of attributes for the disclosure request.
45    pub con: Vec<DisclosureAttribute>,
46    #[serde(skip_serializing_if = "Option::is_none")]
47    /// The validity (in seconds) of the JWT response.
48    pub validity: Option<u64>,
49}
50
51/// The key response from the Private Key Generator (PKG).
52#[derive(Debug, Serialize, Deserialize)]
53#[serde(rename_all = "camelCase")]
54pub struct KeyResponse<T> {
55    /// The status of the session.
56    pub status: SessionStatus,
57
58    /// The status of the IRMA proof.
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub proof_status: Option<ProofStatus>,
61
62    /// The key will remain `None` until the status is `Done` and the proof is `Valid`.
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub key: Option<T>,
65}
66
67/// The request Signing key request body.
68#[derive(Debug, Serialize, Deserialize)]
69#[serde(rename_all = "camelCase")]
70pub struct SigningKeyRequest {
71    /// The public signing identity.
72    pub pub_sign_id: Vec<Attribute>,
73
74    /// The private signing identity.
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub priv_sign_id: Option<Vec<Attribute>>,
77}
78
79/// The signing key response from the Private Key Generator (PKG).
80#[derive(Debug, Serialize, Deserialize)]
81#[serde(rename_all = "camelCase")]
82pub struct SigningKeyResponse {
83    /// The status of the session.
84    pub status: SessionStatus,
85
86    /// The status of the IRMA proof.
87    #[serde(skip_serializing_if = "Option::is_none")]
88    pub proof_status: Option<ProofStatus>,
89
90    /// The public signing key.
91    /// The key will remain `None` until the status is `Done` and the proof is `Valid`.
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub pub_sign_key: Option<SigningKeyExt>,
94
95    /// This private signing key.
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub priv_sign_key: Option<SigningKeyExt>,
98}