diff --git a/pass-webauthn/src/impls.rs b/pass-webauthn/src/impls.rs new file mode 100644 index 0000000..a60baba --- /dev/null +++ b/pass-webauthn/src/impls.rs @@ -0,0 +1,39 @@ +use frame_support::Parameter; +use traits_authn::{Challenger, DeviceChallengeResponse, UserChallengeResponse}; +use verifier::webauthn_verify; + +use crate::{Assertions, Attestation}; + +impl AsRef<[u8]> for Assertions { + fn as_ref(&self) -> &[u8] { + // See https://www.w3.org/TR/webauthn/#clientdatajson-serialization for more details + todo!("Concatenate assertions into the desired `authenticator_data`") + } +} + +impl DeviceChallengeResponse for Attestation +where + Cx: Parameter + Copy + 'static, +{ + fn is_valid(&self) -> bool { + webauthn_verify( + self.authenticator_data.as_ref(), + &self.client_data, + &self.signature, + &self.public_key, + ) + .is_ok() + } + + fn used_challenge(&self) -> (Cx, traits_authn::Challenge) { + (self.context, self.authenticator_data.challenge) + } + + fn authority(&self) -> traits_authn::AuthorityId { + self.rp_id + } + + fn device_id(&self) -> &traits_authn::DeviceId { + todo!() + } +} diff --git a/pass-webauthn/src/lib.rs b/pass-webauthn/src/lib.rs index 8731421..2eef0ca 100644 --- a/pass-webauthn/src/lib.rs +++ b/pass-webauthn/src/lib.rs @@ -1 +1,37 @@ #![cfg_attr(not(feature = "std"), no_std)] + +use codec::{Decode, Encode}; +use frame_support::{DebugNoBound, Parameter}; +use scale_info::TypeInfo; +use traits_authn::{AuthorityId, Challenge, Challenger}; + +#[cfg(test)] +mod tests; + +mod impls; + +type CxOf = ::Context; + +#[derive(Encode, Decode, TypeInfo, Debug, PartialEq, Eq, Clone)] +pub struct Assertions { + challenge: Challenge, +} + +#[derive(Encode, Decode, TypeInfo, DebugNoBound, PartialEq, Eq, Clone)] +pub struct Attestation { + pub(crate) rp_id: AuthorityId, + pub(crate) context: Cx, + pub(crate) authenticator_data: Assertions, + pub(crate) client_data: Vec, + pub(crate) signature: Vec, + pub(crate) public_key: Vec, +} + +#[derive(Encode, Decode)] +pub struct Credential { + pub(crate) rp_id: AuthorityId, + pub(crate) context: Cx, + pub(crate) authenticator_data: Assertions, + pub(crate) client_data: Vec, + pub(crate) signature: Vec, +} diff --git a/pass-webauthn/src/tests.rs b/pass-webauthn/src/tests.rs new file mode 100644 index 0000000..e69de29