-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change(pass-webauthn): base structures
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.