ts_webauthn/options/
creation.rs1use serde::{Deserialize, Serialize};
4use ts_io::Base64Url;
5
6use crate::{credential::CredentialDescriptor, supported_algorithms::SupportedAlgorithm};
7
8#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
10#[serde(rename_all = "camelCase")]
11pub struct CredentialCreationOptions {
12 pub rp: RelyingParty,
14 pub user: User,
16 pub challenge: Base64Url,
18 pub pub_key_cred_params: Vec<CredentialParameters>,
20 #[serde(skip_serializing_if = "Option::is_none")]
22 pub timeout: Option<u64>,
23 #[serde(skip_serializing_if = "Option::is_none")]
26 pub exclude_credentials: Option<Vec<CredentialDescriptor>>,
27 #[serde(skip_serializing_if = "Option::is_none")]
29 pub authenticator_selection: Option<AuthenticatorSelectionCriteria>,
30 #[serde(skip_serializing_if = "Option::is_none")]
36 pub attestation: Option<String>,
37 #[serde(skip_serializing_if = "Option::is_none")]
46 pub attestation_formats: Option<Vec<String>>,
47 #[serde(skip_serializing_if = "Option::is_none")]
49 pub extensions: Option<serde_json::Map<String, serde_json::Value>>,
50}
51
52#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
54#[serde(rename_all = "camelCase")]
55pub struct RelyingParty {
56 pub name: String,
58 pub id: Option<String>,
60}
61
62#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
64#[serde(rename_all = "camelCase")]
65pub struct User {
66 pub id: Base64Url,
68 pub display_name: String,
70 pub name: String,
72}
73
74#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
76#[serde(rename_all = "camelCase")]
77pub struct CredentialParameters {
78 pub r#type: String,
80 pub alg: i64,
82}
83
84#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
86#[serde(rename_all = "camelCase")]
87pub struct AuthenticatorSelectionCriteria {
88 pub authenticator_attachment: Option<Vec<String>>,
90 pub resident_key: Option<String>,
95 pub require_resident_key: Option<bool>,
97 pub user_verification: Option<String>,
102}
103
104impl From<SupportedAlgorithm> for CredentialParameters {
105 fn from(value: SupportedAlgorithm) -> Self {
106 Self {
107 r#type: "public-key".to_string(),
108 alg: value.into(),
109 }
110 }
111}