Skip to content

Commit

Permalink
change(pass-webauthn): base structures
Browse files Browse the repository at this point in the history
  • Loading branch information
pandres95 committed Oct 11, 2024
1 parent e444d6a commit b64eaa1
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pass-webauthn/src/impls.rs
Original file line number Diff line number Diff line change
@@ -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<Cx> DeviceChallengeResponse<Cx> for Attestation<Cx>
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!()
}
}
36 changes: 36 additions & 0 deletions pass-webauthn/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<Ch> = <Ch as Challenger>::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<Cx: Parameter> {
pub(crate) rp_id: AuthorityId,
pub(crate) context: Cx,
pub(crate) authenticator_data: Assertions,
pub(crate) client_data: Vec<u8>,
pub(crate) signature: Vec<u8>,
pub(crate) public_key: Vec<u8>,
}

#[derive(Encode, Decode)]
pub struct Credential<Cx: Parameter> {
pub(crate) rp_id: AuthorityId,
pub(crate) context: Cx,
pub(crate) authenticator_data: Assertions,
pub(crate) client_data: Vec<u8>,
pub(crate) signature: Vec<u8>,
}
Empty file added pass-webauthn/src/tests.rs
Empty file.

0 comments on commit b64eaa1

Please sign in to comment.