passkey_authenticator/lib.rs
1//! # Passkey Authenticator
2//!
3//! [![github]](https://github.com/1Password/passkey-rs/tree/main/passkey-authenticator)
4//! [![version]](https://crates.io/crates/passkey-authenticator)
5//! [![documentation]](https://docs.rs/passkey-authenticator/)
6//!
7//! This crate defines an [`Authenticator`] type along with a basic implementation of the [CTAP 2.0]
8//! specification. The [`Authenticator`] struct is designed in such a way that storage and user
9//! interaction are defined through traits, allowing only the parts that vary between vendors,
10//! but keeping the specification compliant implementation regardless of vendor. This is why the
11//! [`Ctap2Api`] trait is sealed, to prevent external implementations.
12//!
13//! ## Why RustCrypto?
14//!
15//! For targeting WASM, yes there are other cryptographic libraries out there that allow targeting
16//! WASM, but none of them are as easy to compile to wasm than the pure rust implementations of the
17//! [RustCrypto] libraries. Now this does come with limitations, so there are plans to provide a
18//! similar backing trait to "plug-in" the desired cryptography from a vendor. Work is ongoing for this.
19//!
20//! [github]: https://img.shields.io/badge/GitHub-1Password%2Fpasskey--rs%2Fpasskey--authenticator-informational?logo=github&style=flat
21//! [version]: https://img.shields.io/crates/v/passkey-authenticator?logo=rust&style=flat
22//! [documentation]: https://img.shields.io/docsrs/passkey-authenticator/latest?logo=docs.rs&style=flat
23//! [CTAP 2.0]: https://fidoalliance.org/specs/fido-v2.0-ps-20190130/fido-client-to-authenticator-protocol-v2.0-ps-20190130.html
24//! [RustCrypto]: https://github.com/RustCrypto
25
26mod authenticator;
27mod credential_store;
28mod ctap2;
29mod passkey;
30mod user_validation;
31
32#[cfg(all(feature = "linux", target_os = "linux"))]
33pub mod linux;
34
35use passkey_crypto::{CoseKey, PublicKeyT};
36
37pub use self::{
38 authenticator::{Authenticator, CredentialIdLength, extensions},
39 credential_store::{CredentialStore, DiscoverabilitySupport, MemoryStore, StoreInfo},
40 ctap2::Ctap2Api,
41 passkey::PasskeyAccessor,
42 user_validation::{UiHint, UserCheck, UserValidationMethod},
43};
44
45#[cfg(any(test, feature = "testable"))]
46pub use self::user_validation::MockUserValidationMethod;
47
48/// A COSE key pair, containing both the public and private keys.
49pub struct CoseKeyPair {
50 /// The public key.
51 pub public: CoseKey,
52 /// The private key.
53 pub private: CoseKey,
54}
55
56impl CoseKeyPair {
57 /// Create a new COSE key pair from a secret key and algorithm.
58 pub fn from_secret_key<SK: passkey_crypto::SecretKeyT>(private_key: &SK) -> Self {
59 let public_key = private_key.public_key();
60
61 Self {
62 public: public_key.to_cose_key(),
63 private: private_key.to_cose_key(),
64 }
65 }
66}
67
68#[cfg(test)]
69mod tests;