Skip to content

Commit 1c87f46

Browse files
Hintoniinuwa
authored andcommitted
Make typeshare an optional dependency
1 parent 5761345 commit 1c87f46

File tree

11 files changed

+69
-36
lines changed

11 files changed

+69
-36
lines changed

passkey-client/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ workspace = true
1818
android-asset-validation = ["dep:nom"]
1919
testable = ["dep:mockall"]
2020
tokio = ["dep:tokio"]
21+
typeshare = ["passkey-types/typeshare", "dep:typeshare"]
2122

2223
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
2324

@@ -35,7 +36,7 @@ reqwest = { version = "0.12", default-features = false, optional = true }
3536
serde = { version = "1", features = ["derive"] }
3637
serde_json = "1"
3738
tokio = { version = "1", features = ["sync"], optional = true }
38-
typeshare = "1"
39+
typeshare = { version = "1", optional = true }
3940
url = "2"
4041

4142
[dev-dependencies]

passkey-client/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use passkey_types::{
3131
},
3232
};
3333
use serde::Serialize;
34+
#[cfg(feature = "typeshare")]
3435
use typeshare::typeshare;
3536
use url::Url;
3637

@@ -45,7 +46,7 @@ pub use self::rp_id_verifier::android::{UnverifiedAssetLink, ValidationError, va
4546
#[cfg(test)]
4647
mod tests;
4748

48-
#[typeshare]
49+
#[cfg_attr(feature = "typeshare", typeshare)]
4950
#[derive(Debug, serde::Serialize, PartialEq, Eq)]
5051
#[serde(tag = "type", content = "content")]
5152
/// Errors produced by Webauthn Operations.

passkey-types/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ workspace = true
1818
default = []
1919
serialize_bytes_as_base64_string = []
2020
testable = ["dep:p256"]
21+
typeshare = ["dep:typeshare"]
2122

2223
[dependencies]
2324
bitflags = "2"
@@ -30,7 +31,7 @@ serde = { version = "1", features = ["derive"] }
3031
serde_json = { version = "1", features = ["preserve_order"] }
3132
sha2 = "0.10"
3233
strum = { version = "0.25", features = ["derive"] }
33-
typeshare = "1"
34+
typeshare = { version = "1", optional = true }
3435
url = { version = "2", features = ["serde"] }
3536
zeroize = { version = "1", features = ["zeroize_derive"] }
3637
# TODO: investigate rolling our own IANA listings and COSE keys

passkey-types/src/utils/bytes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ops::{Deref, DerefMut};
22

33
use serde::{Deserialize, Deserializer, Serialize, de::Visitor};
4+
#[cfg(feature = "typeshare")]
45
use typeshare::typeshare;
56

67
use super::encoding;
@@ -16,7 +17,7 @@ use super::encoding;
1617
/// This will use an array of numbers for JSON, and a byte string in CBOR for example.
1718
///
1819
/// It also supports deserializing from `base64` and `base64url` formatted strings.
19-
#[typeshare(transparent)]
20+
#[cfg_attr(feature = "typeshare", typeshare(transparent))]
2021
#[derive(Debug, Default, PartialEq, Eq, Clone, Hash)]
2122
#[repr(transparent)]
2223
pub struct Bytes(Vec<u8>);

passkey-types/src/webauthn.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! [WebAuthn Level 3]: https://w3c.github.io/webauthn
44
55
use serde::{Deserialize, Serialize};
6+
#[cfg(feature = "typeshare")]
67
use typeshare::typeshare;
78

89
use crate::{Bytes, utils::serde::ignore_unknown};
@@ -38,9 +39,12 @@ impl AuthenticatorResponse for AuthenticatorAttestationResponse {}
3839
/// <https://w3c.github.io/webauthn/#iface-pkcredential>
3940
#[derive(Debug, Deserialize, Serialize)]
4041
#[serde(rename_all = "camelCase")]
41-
#[typeshare(
42-
swift = "Equatable, Hashable",
43-
swiftGenericConstraints = "R: Equatable & Hashable"
42+
#[cfg_attr(
43+
feature = "typeshare",
44+
typeshare(
45+
swift = "Equatable, Hashable",
46+
swiftGenericConstraints = "R: Equatable & Hashable"
47+
)
4448
)]
4549
pub struct PublicKeyCredential<R: AuthenticatorResponse> {
4650
/// The id contains the credential ID, chosen by the authenticator. This is usually the base64url
@@ -51,7 +55,7 @@ pub struct PublicKeyCredential<R: AuthenticatorResponse> {
5155
/// authenticators.
5256
///
5357
/// > NOTE: This API does not constrain the format or length of this identifier, except that it
54-
/// MUST be sufficient for the authenticator to uniquely select a key.
58+
/// > MUST be sufficient for the authenticator to uniquely select a key.
5559
pub id: String,
5660

5761
/// The raw byte containing the credential ID, see [Self::id] for more information.

passkey-types/src/webauthn/assertion.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Types used for public key authentication
22
33
use serde::{Deserialize, Serialize};
4+
#[cfg(feature = "typeshare")]
45
use typeshare::typeshare;
56

67
use crate::{
@@ -22,7 +23,7 @@ use crate::{
2223
};
2324

2425
/// The response to the successful authentication of a [`PublicKeyCredential`]
25-
#[typeshare(swift = "Equatable, Hashable")]
26+
#[cfg_attr(feature = "typeshare", typeshare(swift = "Equatable, Hashable"))]
2627
pub type AuthenticatedPublicKeyCredential = PublicKeyCredential<AuthenticatorAssertionResponse>;
2728

2829
/// This type supplies `get()` requests with the data it needs to generate an assertion.
@@ -31,7 +32,7 @@ pub type AuthenticatedPublicKeyCredential = PublicKeyCredential<AuthenticatorAss
3132
/// <https://w3c.github.io/webauthn/#dictdef-publickeycredentialrequestoptions>
3233
#[derive(Debug, Serialize, Deserialize)]
3334
#[serde(rename_all = "camelCase")]
34-
#[typeshare]
35+
#[cfg_attr(feature = "typeshare", typeshare)]
3536
pub struct PublicKeyCredentialRequestOptions {
3637
/// This member specifies a challenge that the authenticator signs, along with other data, when
3738
/// producing an authentication assertion. See the [Cryptographic Challenges] security consideration.
@@ -173,7 +174,7 @@ pub struct PublicKeyCredentialRequestOptions {
173174
/// [`navigator.credentials.get`]: https://developer.mozilla.org/en-US/docs/Web/API/CredentialsContainer/get
174175
#[derive(Debug, Serialize, Deserialize)]
175176
#[serde(rename_all = "camelCase")]
176-
#[typeshare]
177+
#[cfg_attr(feature = "typeshare", typeshare)]
177178
pub struct CredentialRequestOptions {
178179
/// The key defining that this is a request for a webauthn credential.
179180
pub public_key: PublicKeyCredentialRequestOptions,
@@ -188,7 +189,7 @@ pub struct CredentialRequestOptions {
188189
/// <https://w3c.github.io/webauthn/#iface-authenticatorassertionresponse>
189190
#[derive(Debug, Deserialize, Serialize)]
190191
#[serde(rename_all = "camelCase")]
191-
#[typeshare(swift = "Equatable, Hashable")]
192+
#[cfg_attr(feature = "typeshare", typeshare(swift = "Equatable, Hashable"))]
192193
pub struct AuthenticatorAssertionResponse {
193194
/// This attribute contains the JSON serialization of [`CollectedClientData`] passed to the
194195
/// authenticator by the client in order to generate this credential. The exact JSON serialization

passkey-types/src/webauthn/attestation.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use coset::iana;
33
use indexmap::IndexMap;
44
use serde::{Deserialize, Serialize, Serializer};
55
use std::fmt;
6+
#[cfg(feature = "typeshare")]
67
use typeshare::typeshare;
78

89
use crate::{
@@ -25,7 +26,7 @@ use crate::{
2526
};
2627

2728
/// The response to the successful creation of a PublicKeyCredential
28-
#[typeshare(swift = "Equatable, Hashable")]
29+
#[cfg_attr(feature = "typeshare", typeshare(swift = "Equatable, Hashable"))]
2930
pub type CreatedPublicKeyCredential = PublicKeyCredential<AuthenticatorAttestationResponse>;
3031

3132
/// This is the expected input to [`navigator.credentials.create`] when wanting to create a webauthn
@@ -36,7 +37,7 @@ pub type CreatedPublicKeyCredential = PublicKeyCredential<AuthenticatorAttestati
3637
/// [`navigator.credentials.create`]: https://developer.mozilla.org/en-US/docs/Web/API/CredentialsContainer/create
3738
#[derive(Debug, Serialize, Deserialize)]
3839
#[serde(rename_all = "camelCase")]
39-
#[typeshare]
40+
#[cfg_attr(feature = "typeshare", typeshare)]
4041
pub struct CredentialCreationOptions {
4142
/// The key defining that this is a request for a webauthn credential.
4243
pub public_key: PublicKeyCredentialCreationOptions,
@@ -47,7 +48,7 @@ pub struct CredentialCreationOptions {
4748
/// <https://w3c.github.io/webauthn/#dictdef-publickeycredentialcreationoptions>
4849
#[derive(Debug, Serialize, Deserialize)]
4950
#[serde(rename_all = "camelCase")]
50-
#[typeshare]
51+
#[cfg_attr(feature = "typeshare", typeshare)]
5152
pub struct PublicKeyCredentialCreationOptions {
5253
/// This member contains a name and an identifier for the [Relying Party] responsible for the request.
5354
///
@@ -170,7 +171,7 @@ pub struct PublicKeyCredentialCreationOptions {
170171
///
171172
/// <https://w3c.github.io/webauthn/#dictdef-publickeycredentialrpentity>
172173
#[derive(Debug, Serialize, Deserialize, Clone)]
173-
#[typeshare]
174+
#[cfg_attr(feature = "typeshare", typeshare)]
174175
pub struct PublicKeyCredentialRpEntity {
175176
/// A unique identifier for the [Relying Party] entity, which sets the [RP ID].
176177
///
@@ -224,7 +225,7 @@ pub struct PublicKeyCredentialRpEntity {
224225
/// [Lang]: https://w3c.github.io/webauthn/#sctn-strings-langdir
225226
#[derive(Debug, Serialize, Deserialize, Clone)]
226227
#[serde(rename_all = "camelCase")]
227-
#[typeshare]
228+
#[cfg_attr(feature = "typeshare", typeshare)]
228229
pub struct PublicKeyCredentialUserEntity {
229230
/// The user handle of the user account. A user handle is an opaque byte sequence with a maximum
230231
/// size of 64 bytes, and is not meant to be displayed to the user.
@@ -275,14 +276,15 @@ pub struct PublicKeyCredentialUserEntity {
275276
///
276277
/// <https://w3c.github.io/webauthn/#dictdef-publickeycredentialparameters>
277278
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
278-
#[typeshare]
279+
#[cfg_attr(feature = "typeshare", typeshare)]
279280
pub struct PublicKeyCredentialParameters {
280281
/// This member specifies the type of credential to be created. The value SHOULD be a member of
281282
/// [`PublicKeyCredentialType`] but client platforms MUST ignore unknown values, ignoring any
282283
/// [`PublicKeyCredentialParameters`] with an [`PublicKeyCredentialType::Unknown`] type.
283284
#[serde(rename = "type", deserialize_with = "ignore_unknown")]
284285
pub ty: PublicKeyCredentialType,
285286

287+
#[cfg(feature = "typeshare")]
286288
/// This member specifies the cryptographic signature algorithm with which the newly generated
287289
/// credential will be used, and thus also the type of asymmetric key pair to be generated,
288290
/// e.g., RSA or Elliptic Curve.
@@ -293,6 +295,17 @@ pub struct PublicKeyCredentialParameters {
293295
#[serde(with = "i64_to_iana")]
294296
#[typeshare(serialized_as = "I54")] // because i64 fails for js
295297
pub alg: iana::Algorithm,
298+
299+
#[cfg(not(feature = "typeshare"))]
300+
/// This member specifies the cryptographic signature algorithm with which the newly generated
301+
/// credential will be used, and thus also the type of asymmetric key pair to be generated,
302+
/// e.g., RSA or Elliptic Curve.
303+
///
304+
/// > Note: we use `alg` as the latter member name, rather than spelling-out `algorithm`,
305+
/// > because it will be serialized into a message to the authenticator, which may be
306+
/// > sent over a low-bandwidth link.
307+
#[serde(with = "i64_to_iana")]
308+
pub alg: iana::Algorithm,
296309
}
297310

298311
impl PublicKeyCredentialParameters {
@@ -325,7 +338,7 @@ impl PublicKeyCredentialParameters {
325338
/// [Relying Parties]: https://w3c.github.io/webauthn/#webauthn-relying-party
326339
#[derive(Debug, Default, Serialize, Deserialize)]
327340
#[serde(rename_all = "camelCase")]
328-
#[typeshare]
341+
#[cfg_attr(feature = "typeshare", typeshare)]
329342
pub struct AuthenticatorSelectionCriteria {
330343
/// If this member is present, eligible authenticators are filtered to be only those
331344
/// authenticators attached with the specified [`AuthenticatorAttachment`] modality. If this
@@ -387,7 +400,7 @@ pub struct AuthenticatorSelectionCriteria {
387400
/// [discoverable credential]: https://w3c.github.io/webauthn/#client-side-discoverable-credential
388401
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
389402
#[serde(rename_all = "lowercase")]
390-
#[typeshare(serialized_as = "String")]
403+
#[cfg_attr(feature = "typeshare", typeshare(serialized_as = "String"))]
391404
pub enum ResidentKeyRequirement {
392405
/// The Relying Party prefers creating a [server-side credential], but will accept a client-side
393406
/// discoverable credential. The client and authenticator SHOULD create a server-side credential
@@ -424,7 +437,7 @@ pub enum ResidentKeyRequirement {
424437
/// [attestation conveyance]: https://w3c.github.io/webauthn/#attestation-conveyance
425438
#[derive(Debug, Default, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
426439
#[serde(rename_all = "lowercase")]
427-
#[typeshare(serialized_as = "String")]
440+
#[cfg_attr(feature = "typeshare", typeshare(serialized_as = "String"))]
428441
pub enum AttestationConveyancePreference {
429442
/// The Relying Party is not interested in authenticator attestation. For example, in order to
430443
/// potentially avoid having to obtain user consent to relay identifying information to the
@@ -473,7 +486,7 @@ pub enum AttestationConveyancePreference {
473486
/// [2]: https://w3c.github.io/webauthn/#sctn-attstn-fmt-ids
474487
#[derive(Debug, Default, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
475488
#[serde(rename_all = "kebab-case")]
476-
#[typeshare]
489+
#[cfg_attr(feature = "typeshare", typeshare)]
477490
pub enum AttestationStatementFormatIdentifiers {
478491
/// The `packed` attestation statement format is a WebAuthn-optimized format for attestation.
479492
/// It uses a very compact but still extensible encoding method. This format is implementable by
@@ -515,7 +528,7 @@ pub enum AttestationStatementFormatIdentifiers {
515528
/// [Relying Party]: https://w3c.github.io/webauthn/#relying-party
516529
#[derive(Debug, Clone, Deserialize, Serialize)]
517530
#[serde(rename_all = "camelCase")]
518-
#[typeshare(swift = "Equatable, Hashable")]
531+
#[cfg_attr(feature = "typeshare", typeshare(swift = "Equatable, Hashable"))]
519532
pub struct AuthenticatorAttestationResponse {
520533
/// This attribute contains the JSON serialization of [`CollectedClientData`] passed to the
521534
/// authenticator by the client in order to generate this credential. The exact JSON serialization
@@ -532,12 +545,19 @@ pub struct AuthenticatorAttestationResponse {
532545
#[serde(skip_serializing_if = "Option::is_none")]
533546
pub public_key: Option<Bytes>,
534547

548+
#[cfg(feature = "typeshare")]
535549
/// This is the [CoseAlgorithmIdentifier] of the new credential
536550
///
537551
/// [CoseAlgorithmIdentifier]: https://w3c.github.io/webauthn/#typedefdef-cosealgorithmidentifier
538552
#[typeshare(serialized_as = "I54")] // because i64 fails for js
539553
pub public_key_algorithm: i64,
540554

555+
#[cfg(not(feature = "typeshare"))]
556+
/// This is the [CoseAlgorithmIdentifier] of the new credential
557+
///
558+
/// [CoseAlgorithmIdentifier]: https://w3c.github.io/webauthn/#typedefdef-cosealgorithmidentifier
559+
pub public_key_algorithm: i64,
560+
541561
/// This attribute contains an attestation object, which is opaque to, and cryptographically
542562
/// protected against tampering by, the client. The attestation object contains both
543563
/// [`AuthenticatorData`] and an attestation statement. The former contains the [`Aaguid`], a unique
@@ -625,7 +645,7 @@ where
625645

626646
/// Used to limit the values of [`CollectedClientData::ty`] and serializes to static strings.
627647
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
628-
#[typeshare]
648+
#[cfg_attr(feature = "typeshare", typeshare)]
629649
pub enum ClientDataType {
630650
/// Serializes to the string `"webauthn.create"`
631651
#[serde(rename = "webauthn.create")]

passkey-types/src/webauthn/common.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Common types used in both Attestation (registration) and Assertion (authentication).
22
//!
33
use serde::{Deserialize, Serialize};
4+
#[cfg(feature = "typeshare")]
45
use typeshare::typeshare;
56

67
use crate::{
@@ -22,7 +23,7 @@ use crate::webauthn::{
2223
/// <https://w3c.github.io/webauthn/#enumdef-publickeycredentialtype>
2324
#[derive(Debug, Default, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
2425
#[serde(rename_all = "kebab-case")]
25-
#[typeshare(serialized_as = "String")]
26+
#[cfg_attr(feature = "typeshare", typeshare(serialized_as = "String"))]
2627
pub enum PublicKeyCredentialType {
2728
/// Currently the only type defined is a `PublicKey` meaning the public conterpart of an
2829
/// asymmetric key pair.
@@ -41,7 +42,7 @@ pub enum PublicKeyCredentialType {
4142
///
4243
/// <https://w3c.github.io/webauthn/#dictdef-publickeycredentialdescriptor>
4344
#[derive(Debug, Serialize, Deserialize)]
44-
#[typeshare]
45+
#[cfg_attr(feature = "typeshare", typeshare)]
4546
pub struct PublicKeyCredentialDescriptor {
4647
/// This member contains the type of the public key credential the caller is referring to. The
4748
/// value SHOULD be a member of [`PublicKeyCredentialType`] but client platforms MUST ignore any
@@ -93,7 +94,7 @@ impl PublicKeyCredentialDescriptor {
9394
/// [user verification]: https://w3c.github.io/webauthn/#user-verification
9495
#[derive(Debug, Default, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
9596
#[serde(rename_all = "lowercase")]
96-
#[typeshare(serialized_as = "String")]
97+
#[cfg_attr(feature = "typeshare", typeshare(serialized_as = "String"))]
9798
pub enum UserVerificationRequirement {
9899
/// The Relying Party requires user verification for the operation and will fail the overall
99100
/// ceremony if the response does not have the UV flag set. The client MUST return an error if
@@ -119,7 +120,7 @@ pub enum UserVerificationRequirement {
119120
/// <https://w3c.github.io/webauthn/#enum-transport>
120121
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
121122
#[serde(rename_all = "lowercase")]
122-
#[typeshare(serialized_as = "String")]
123+
#[cfg_attr(feature = "typeshare", typeshare(serialized_as = "String"))]
123124
pub enum AuthenticatorTransport {
124125
/// Indicates the respective authenticator can be contacted over removable USB.
125126
Usb,
@@ -150,7 +151,7 @@ pub enum AuthenticatorTransport {
150151
/// <https://w3c.github.io/webauthn/#enumdef-authenticatorattachment>
151152
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
152153
#[serde(rename_all = "kebab-case")]
153-
#[typeshare(serialized_as = "String")]
154+
#[cfg_attr(feature = "typeshare", typeshare(serialized_as = "String"))]
154155
pub enum AuthenticatorAttachment {
155156
/// This value indicates platform attachment which is attached using a client device-specific
156157
/// transport, called **platform attachment**, and is usually not removable from the client
@@ -182,7 +183,7 @@ pub enum AuthenticatorAttachment {
182183
/// <https://w3c.github.io/webauthn/#enum-hints>
183184
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
184185
#[serde(rename_all = "kebab-case")]
185-
#[typeshare(serialized_as = "String")]
186+
#[cfg_attr(feature = "typeshare", typeshare(serialized_as = "String"))]
186187
#[non_exhaustive]
187188
pub enum PublicKeyCredentialHints {
188189
/// Indicates that the Relying Party believes that users will satisfy this request with a physical

passkey-types/src/webauthn/extensions/credential_properties.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use serde::{Deserialize, Serialize};
2+
#[cfg(feature = "typeshare")]
23
use typeshare::typeshare;
34

45
#[cfg(doc)]
@@ -13,7 +14,7 @@ use crate::webauthn::PublicKeyCredential;
1314
/// [Relying Party]: https://w3c.github.io/webauthn/#relying-party
1415
#[derive(Debug, Deserialize, Serialize)]
1516
#[serde(rename_all = "camelCase")]
16-
#[typeshare(swift = "Equatable, Hashable")]
17+
#[cfg_attr(feature = "typeshare", typeshare(swift = "Equatable, Hashable"))]
1718
pub struct CredentialPropertiesOutput {
1819
/// This OPTIONAL property, known abstractly as the resident key credential property
1920
/// (i.e., client-side [discoverable credential] property), is a Boolean value indicating whether

0 commit comments

Comments
 (0)