smart_id_rust_client/models/api/signature_session.rs
1use crate::config::SmartIDConfig;
2use crate::error::Result;
3use crate::error::SmartIdClientError;
4use crate::models::api::response::SmartIdAPIResponse;
5use crate::models::common::{CertificateLevel, RequestProperties, VCCode};
6use crate::models::interaction::{encode_interactions_base_64, hash_encode_digest, Interaction};
7use crate::models::signature::{
8 HashingAlgorithm, SignatureAlgorithm, SignatureProtocol, SignatureProtocolParameters,
9 SignatureRequestAlgorithmParameters,
10};
11use serde::{Deserialize, Serialize};
12use serde_with::skip_serializing_none;
13
14// region SignatureSessionDeviceLinkRequest
15
16/// Signature Device Link Request
17///
18/// This struct represents a request for a signature session triggered by clicking on a link or scanning a qr code.
19///
20/// # Properties
21///
22/// * `relying_party_uuid` - The UUID of the relying party, provided by Smart ID.
23/// * `relying_party_name` - The name of the relying party, provided by Smart ID.
24/// * `initial_callback_url` - The initial callback URL for the signature session. This is used to redirect the user after the signature is completed.
25/// * `certificate_level` - The level of the certificate required for the signature.
26/// * `signature_protocol` - The protocol used for the signature.
27/// * `signature_protocol_parameters` - The parameters for the signature protocol.
28/// * `interactions` - A base64 encoded JSON string of interactions allowed during the signature session. At least one interaction is required. Interactions are limited based on the flow type, look at the Interaction documentation for more information.
29/// * `nonce` - An optional nonce for the request.
30/// * `request_properties` - Optional properties for the request.
31/// * `capabilities` - Used only when agreed with Smart-ID provider. When omitted, request capabilities are derived from the `certificate_level` parameter.
32///
33/// # Example
34///
35/// ```rust
36/// use smart_id_rust_client::config::SmartIDConfig;
37/// use smart_id_rust_client::models::api::signature_session::SignatureDeviceLinkRequest;
38/// use smart_id_rust_client::models::interaction::Interaction;
39/// use smart_id_rust_client::models::signature::{HashingAlgorithm, SignatureAlgorithm};
40/// use smart_id_rust_client::error::Result;
41///
42/// fn create_signature_request(cfg: &SmartIDConfig) -> Result<SignatureDeviceLinkRequest> {
43/// let interactions = vec![Interaction::DisplayTextAndPIN {
44/// display_text_60: "Sign document".to_string(),
45/// }];
46/// SignatureDeviceLinkRequest::new(
47/// cfg,
48/// interactions,
49/// "base64-encoded-digest".to_string(),
50/// SignatureAlgorithm::RsassaPss,
51/// HashingAlgorithm::sha_256,
52/// Some("https://example.com/callback".to_string()),
53/// )
54/// }
55/// ```
56#[skip_serializing_none]
57#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
58#[serde(rename_all = "camelCase")]
59pub struct SignatureDeviceLinkRequest {
60 #[serde(rename = "relyingPartyUUID")]
61 pub relying_party_uuid: String,
62 pub relying_party_name: String,
63 pub initial_callback_url: Option<String>,
64 pub certificate_level: CertificateLevel,
65 pub signature_protocol: SignatureProtocol,
66 pub signature_protocol_parameters: SignatureProtocolParameters,
67 pub nonce: Option<String>,
68 pub interactions: String,
69 pub request_properties: Option<RequestProperties>,
70 /// Used only when agreed with Smart-ID provider. When omitted request capabilities are derived from certificateLevel parameter.
71 pub capabilities: Option<Vec<String>>,
72}
73
74impl SignatureDeviceLinkRequest {
75 /// Creates a new `SignatureRequest`.
76 ///
77 /// # Arguments
78 ///
79 /// * `cfg` - The configuration for the Smart-ID service.
80 /// * `interactions` - A vector of interactions allowed during the signature session. At least one interaction is required. Interactions are limited based on the flow type, look at the Interaction documentation for more information.
81 /// * `digest` - The digest to be signed. Base64 encoded.
82 /// * `signature_algorithm` - The algorithm used for the signature.
83 /// * `hash_algorithm` - The hashing algorithm used for the signature.
84 /// * `initial_callback_url` - An optional initial callback URL for the signature session. This is used to redirect the user after the signature is completed.
85 ///
86 /// # Errors
87 ///
88 /// Returns an error if no interactions are defined or if any interaction has invalid text length.
89 pub fn new(
90 cfg: &SmartIDConfig,
91 interactions: Vec<Interaction>,
92 digest: String,
93 signature_algorithm: SignatureAlgorithm,
94 hash_algorithm: HashingAlgorithm,
95 initial_callback_url: Option<String>,
96 ) -> Result<Self> {
97 if interactions.is_empty() {
98 return Err(SmartIdClientError::ConfigMissingException(
99 "Define at least 1 interaction for an authentication request",
100 ));
101 };
102
103 for interaction in &interactions {
104 interaction.validate_text_length()?;
105 }
106
107 let encoded_interactions = encode_interactions_base_64(&interactions)?;
108
109 let hashed_and_encoded_digest = hash_encode_digest(&digest, &hash_algorithm)?;
110
111 Ok(SignatureDeviceLinkRequest {
112 relying_party_uuid: cfg.relying_party_uuid.clone(),
113 relying_party_name: cfg.relying_party_name.clone(),
114 initial_callback_url,
115 certificate_level: CertificateLevel::QUALIFIED,
116 signature_protocol: SignatureProtocol::RAW_DIGEST_SIGNATURE,
117 signature_protocol_parameters: SignatureProtocolParameters::RAW_DIGEST_SIGNATURE {
118 digest: hashed_and_encoded_digest,
119 signature_algorithm,
120 signature_algorithm_parameters: SignatureRequestAlgorithmParameters {
121 hash_algorithm,
122 },
123 },
124 nonce: None,
125 interactions: encoded_interactions,
126 request_properties: None,
127 capabilities: None,
128 })
129 }
130}
131
132pub(crate) type SignatureDeviceLinkResponse = SmartIdAPIResponse<SignatureDeviceLinkSession>;
133
134#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
135#[serde(rename_all = "camelCase")]
136pub struct SignatureDeviceLinkSession {
137 #[serde(rename = "sessionID")]
138 pub session_id: String,
139 pub session_secret: String,
140 pub session_token: String,
141 pub device_link_base: String,
142}
143
144// endregion: SignatureSessionDeviceLinkRequest
145
146// region SignatureNotificationRequest
147
148/// Signature Request
149///
150/// This struct represents a request for a signature session with the Smart ID service.
151/// It includes various parameters required for the signature process.
152///
153/// # Properties
154///
155/// * `relying_party_uuid` - The UUID of the relying party, provided by Smart ID.
156/// * `relying_party_name` - The name of the relying party, provided by Smart ID.
157/// * `certificate_level` - The level of the certificate required for the signature.
158/// * `signature_protocol` - The protocol used for the signature.
159/// * `signature_protocol_parameters` - The parameters for the signature protocol.
160/// * `interactions` - A base64 encoded JSON string of interactions allowed during the signature session. At least one interaction is required. Interactions are limited based on the flow type, look at the Interaction documentation for more information.
161/// * `nonce` - An optional nonce for the request.
162/// * `request_properties` - Optional properties for the request.
163/// * `capabilities` - Used only when agreed with Smart-ID provider. When omitted, request capabilities are derived from the `certificate_level` parameter.
164///
165/// # Example
166///
167/// ```rust
168/// use smart_id_rust_client::config::SmartIDConfig;
169/// use smart_id_rust_client::models::api::signature_session::SignatureNotificationRequest;
170/// use smart_id_rust_client::models::interaction::Interaction;
171/// use smart_id_rust_client::models::signature::{HashingAlgorithm, SignatureAlgorithm};
172/// use smart_id_rust_client::error::Result;///
173///
174/// use smart_id_rust_client::models::common::SessionConfig::SignatureNotification;
175///
176/// fn create_signature_request(cfg: &SmartIDConfig) -> Result<SignatureNotificationRequest> {
177/// let interactions = vec![Interaction::DisplayTextAndPIN {
178/// display_text_60: "Sign document".to_string(),
179/// }];
180/// SignatureNotificationRequest::new(
181/// cfg,
182/// interactions,
183/// "base64-encoded-digest".to_string(),
184/// SignatureAlgorithm::RsassaPss,
185/// HashingAlgorithm::sha_256,
186/// )
187/// }
188/// ```
189#[skip_serializing_none]
190#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
191#[serde(rename_all = "camelCase")]
192pub struct SignatureNotificationRequest {
193 #[serde(rename = "relyingPartyUUID")]
194 pub relying_party_uuid: String,
195 pub relying_party_name: String,
196 pub certificate_level: CertificateLevel,
197 pub signature_protocol: SignatureProtocol,
198 pub signature_protocol_parameters: SignatureProtocolParameters,
199 pub nonce: Option<String>,
200 pub interactions: String,
201 pub request_properties: Option<RequestProperties>,
202 /// Used only when agreed with Smart-ID provider. When omitted request capabilities are derived from certificateLevel parameter.
203 pub capabilities: Option<Vec<String>>,
204}
205
206impl SignatureNotificationRequest {
207 /// Creates a new `SignatureRequest`.
208 ///
209 /// # Arguments
210 ///
211 /// * `cfg` - The configuration for the Smart-ID service.
212 /// * `interactions` - A vector of interactions allowed during the signature session. At least one interaction is required. Interactions are limited based on the flow type, look at the Interaction documentation for more information.
213 /// * `digest` - The digest to be signed. Base64 encoded.
214 /// * `signature_algorithm` - The algorithm used for the signature.
215 ///
216 /// # Errors
217 ///
218 /// Returns an error if no interactions are defined or if any interaction has invalid text length.
219 pub fn new(
220 cfg: &SmartIDConfig,
221 interactions: Vec<Interaction>,
222 digest: String,
223 signature_algorithm: SignatureAlgorithm,
224 hash_algorithm: HashingAlgorithm,
225 ) -> Result<Self> {
226 if interactions.is_empty() {
227 return Err(SmartIdClientError::ConfigMissingException(
228 "Define at least 1 interaction for an authentication request",
229 ));
230 };
231
232 for interaction in &interactions {
233 interaction.validate_text_length()?;
234 }
235
236 let encoded_interactions = encode_interactions_base_64(&interactions)?;
237
238 let hashed_and_encoded_digest = hash_encode_digest(&digest, &hash_algorithm)?;
239
240 Ok(SignatureNotificationRequest {
241 relying_party_uuid: cfg.relying_party_uuid.clone(),
242 relying_party_name: cfg.relying_party_name.clone(),
243 certificate_level: CertificateLevel::QUALIFIED,
244 signature_protocol: SignatureProtocol::RAW_DIGEST_SIGNATURE,
245 signature_protocol_parameters: SignatureProtocolParameters::RAW_DIGEST_SIGNATURE {
246 digest: hashed_and_encoded_digest,
247 signature_algorithm,
248 signature_algorithm_parameters: SignatureRequestAlgorithmParameters {
249 hash_algorithm,
250 },
251 },
252 nonce: None,
253 interactions: encoded_interactions,
254 request_properties: None,
255 capabilities: None,
256 })
257 }
258}
259
260pub(crate) type SignatureNotificationResponse = SmartIdAPIResponse<SignatureNotificationSession>;
261
262#[derive(Clone, Debug, Serialize, Deserialize)]
263pub struct SignatureNotificationSession {
264 #[serde(rename = "sessionID")]
265 pub session_id: String,
266 pub vc: VCCode,
267}
268
269// endregion: SignatureNotificationRequest
270
271// region SignatureNotificationLinkedRequest
272
273/// Signature Notification Linked Request
274///
275/// This struct represents a request for a signature session with the Smart ID service using a push notification that is linked to a previous certificate choice session (No verification code required).
276///
277/// # Properties
278///
279/// * `relying_party_uuid` - The UUID of the relying party, provided by Smart ID.
280/// * `relying_party_name` - The name of the relying party, provided by Smart ID.
281/// * `certificate_level` - The level of the certificate required for the signature.
282/// * `signature_protocol` - The protocol used for the signature.
283/// * `signature_protocol_parameters` - The parameters for the signature protocol.
284/// * `linked_session_id` - The session ID of the linked certificate choice session.
285/// * `interactions` - A base64 encoded JSON string of interactions allowed during the signature session. At least one interaction is required. Interactions are limited based on the flow type, look at the Interaction documentation for more information.
286/// * `nonce` - An optional nonce for the request.
287/// * `request_properties` - Optional properties for the request.
288/// * `capabilities` - Used only when agreed with Smart-ID provider. When omitted, request capabilities are derived from the `certificate_level` parameter.
289///
290/// # Example
291///
292/// ```rust
293/// use smart_id_rust_client::config::SmartIDConfig;
294/// use smart_id_rust_client::models::api::signature_session::SignatureNotificationLinkedRequest;
295/// use smart_id_rust_client::models::interaction::Interaction;
296/// use smart_id_rust_client::models::signature::{HashingAlgorithm, SignatureAlgorithm};
297/// use smart_id_rust_client::error::Result;
298///
299/// fn create_signature_request(cfg: &SmartIDConfig) -> Result<SignatureNotificationLinkedRequest> {
300/// let interactions = vec![Interaction::DisplayTextAndPIN {
301/// display_text_60: "Sign document".to_string(),
302/// }];
303/// SignatureNotificationLinkedRequest::new(
304/// cfg,
305/// interactions,
306/// "base64-encoded-digest".to_string(),
307/// SignatureAlgorithm::RsassaPss,
308/// "56e1c1d0-dc07-4c71-890b-6200856b8c75".to_string(),
309/// HashingAlgorithm::sha_256,
310/// )
311/// }
312/// ```
313#[skip_serializing_none]
314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
315#[serde(rename_all = "camelCase")]
316pub struct SignatureNotificationLinkedRequest {
317 #[serde(rename = "relyingPartyUUID")]
318 pub relying_party_uuid: String,
319 pub relying_party_name: String,
320 pub certificate_level: CertificateLevel,
321 pub signature_protocol: SignatureProtocol,
322 pub signature_protocol_parameters: SignatureProtocolParameters,
323 #[serde(rename = "linkedSessionID")]
324 pub linked_session_id: String, // The session ID of the linked certificate choice session
325 pub nonce: Option<String>,
326 pub interactions: String, // Base64 encoded JSON of interactions
327 pub request_properties: Option<RequestProperties>,
328 /// Used only when agreed with Smart-ID provider. When omitted request capabilities are derived from certificateLevel parameter.
329 pub capabilities: Option<Vec<String>>,
330}
331
332impl SignatureNotificationLinkedRequest {
333 /// Creates a new `SignatureNotificationLinkedRequest`.
334 ///
335 /// # Arguments
336 ///
337 /// * `cfg` - The configuration for the Smart-ID service.
338 /// * `interactions` - A vector of interactions allowed during the signature session. At least one interaction is required. Interactions are limited based on the flow type, look at the Interaction documentation for more information.
339 /// * `digest` - The digest to be signed. Base64 encoded.
340 /// * `signature_algorithm` - The algorithm used for the signature.
341 /// * `linked_session_id` - The session ID of the linked certificate choice session.
342 ///
343 /// # Errors
344 ///
345 /// Returns an error if no interactions are defined or if any interaction has invalid text length.
346 pub fn new(
347 cfg: &SmartIDConfig,
348 interactions: Vec<Interaction>,
349 digest: String,
350 signature_algorithm: SignatureAlgorithm,
351 linked_session_id: String,
352 hash_algorithm: HashingAlgorithm,
353 ) -> Result<Self> {
354 if interactions.is_empty() {
355 return Err(SmartIdClientError::ConfigMissingException(
356 "Define at least 1 interaction for an authentication request",
357 ));
358 };
359
360 for interaction in &interactions {
361 interaction.validate_text_length()?;
362 }
363
364 let encoded_interactions = encode_interactions_base_64(&interactions)?;
365
366 let hashed_and_encoded_digest = hash_encode_digest(&digest, &hash_algorithm)?;
367
368 Ok(SignatureNotificationLinkedRequest {
369 relying_party_uuid: cfg.relying_party_uuid.clone(),
370 relying_party_name: cfg.relying_party_name.clone(),
371 linked_session_id,
372 certificate_level: CertificateLevel::QUALIFIED,
373 signature_protocol: SignatureProtocol::RAW_DIGEST_SIGNATURE,
374 signature_protocol_parameters: SignatureProtocolParameters::RAW_DIGEST_SIGNATURE {
375 digest: hashed_and_encoded_digest,
376 signature_algorithm,
377 signature_algorithm_parameters: SignatureRequestAlgorithmParameters {
378 hash_algorithm,
379 },
380 },
381 nonce: None,
382 interactions: encoded_interactions,
383 request_properties: None,
384 capabilities: None,
385 })
386 }
387}
388
389pub(crate) type SignatureNotificationLinkedResponse =
390 SmartIdAPIResponse<SignatureNotificationLinkedSession>;
391
392#[derive(Clone, Debug, Serialize, Deserialize)]
393pub struct SignatureNotificationLinkedSession {
394 #[serde(rename = "sessionID")]
395 pub session_id: String,
396}
397
398// endregion: SignatureNotificationLinkedRequest