Skip to main content

lastid_sdk/types/
credential_response.rs

1//! Credential request response types.
2
3use std::fmt;
4
5use serde::{Deserialize, Serialize};
6
7use crate::types::RequestId;
8
9/// Response from creating a credential presentation request.
10///
11/// Contains all information needed to present a QR code to the user
12/// and poll for completion.
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct CredentialRequestResponse {
15    /// Unique identifier for this request (for polling)
16    pub request_id: RequestId,
17
18    /// `OpenID4VP` request URI for QR code display.
19    ///
20    /// This is the `openid4vp://` URL that the mobile app scans
21    /// to retrieve the presentation request details.
22    pub request_uri: String,
23
24    /// Request expiration time in seconds from creation.
25    pub expires_in: u64,
26
27    /// Cryptographic nonce for replay protection.
28    pub nonce: String,
29}
30
31impl CredentialRequestResponse {
32    /// Create a new credential request response.
33    #[must_use]
34    pub const fn new(
35        request_id: RequestId,
36        request_uri: String,
37        expires_in: u64,
38        nonce: String,
39    ) -> Self {
40        Self {
41            request_id,
42            request_uri,
43            expires_in,
44            nonce,
45        }
46    }
47
48    /// Get the request ID for polling.
49    #[must_use]
50    pub const fn request_id(&self) -> &RequestId {
51        &self.request_id
52    }
53
54    /// Get the `OpenID4VP` request URI for QR code display.
55    #[must_use]
56    pub fn request_uri(&self) -> &str {
57        &self.request_uri
58    }
59
60    /// Get the expiration time in seconds.
61    #[must_use]
62    pub const fn expires_in(&self) -> u64 {
63        self.expires_in
64    }
65
66    /// Get the nonce for verification.
67    #[must_use]
68    pub fn nonce(&self) -> &str {
69        &self.nonce
70    }
71}
72
73impl fmt::Display for CredentialRequestResponse {
74    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75        write!(
76            f,
77            "CredentialRequestResponse {{ request_id: {}, expires_in: {}s }}",
78            self.request_id, self.expires_in
79        )
80    }
81}