Skip to content

Commit

Permalink
change(fc-pallet-pass/fc-traits-authn): rehash userId using the `[0, …
Browse files Browse the repository at this point in the history
…0, ..., ...user]` array.
  • Loading branch information
pandres95 committed Nov 22, 2024
1 parent ab7ec10 commit 7d4846c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pallets/pass/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use fc_traits_authn::{
util::AuthorityFromPalletId, Authenticator, DeviceChallengeResponse, DeviceId, HashedUserId,
UserAuthenticator, UserChallengeResponse,
UserAuthenticator, UserChallengeResponse, HASHED_USER_ID_LEN,
};
use frame_support::traits::schedule::DispatchTime;
use frame_support::traits::Bounded;
Expand Down Expand Up @@ -234,8 +234,12 @@ pub mod pallet {

impl<T: Config<I>, I: 'static> Pallet<T, I> {
pub fn account_id_for(user: HashedUserId) -> Result<T::AccountId, DispatchError> {
let account_id: T::AccountId = T::AccountId::decode(&mut TrailingZeroInput::new(&user))
.map_err(|_| Error::<T, I>::AccountNotFound)?;
// we know the length of HashedUserId
let mut input = [0u8; 2 * HASHED_USER_ID_LEN];
input[HASHED_USER_ID_LEN..].copy_from_slice(&user);
let account_id: T::AccountId =
T::AccountId::decode(&mut TrailingZeroInput::new(&blake2_256(&input)))
.map_err(|_| Error::<T, I>::AccountNotFound)?;
Ok(account_id)
}

Expand Down
3 changes: 2 additions & 1 deletion traits/authn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ type CxOf<C> = <C as Challenger>::Context;

pub type DeviceId = [u8; 32];
pub type AuthorityId = [u8; 32];
pub type HashedUserId = [u8; 32];
pub const HASHED_USER_ID_LEN: usize = 32;
pub type HashedUserId = [u8; HASHED_USER_ID_LEN];

/// Given some context it deterministically generates a "challenge" used by authenticators
pub trait Challenger {
Expand Down

0 comments on commit 7d4846c

Please sign in to comment.