From 7d4846c8b7f8ca1cbf40f3c1df61d318895ebdb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Fri, 22 Nov 2024 08:19:29 -0500 Subject: [PATCH] change(fc-pallet-pass/fc-traits-authn): rehash userId using the `[0, 0, ..., ...user]` array. --- pallets/pass/src/lib.rs | 10 +++++++--- traits/authn/src/lib.rs | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pallets/pass/src/lib.rs b/pallets/pass/src/lib.rs index d49e116..8d9f28e 100644 --- a/pallets/pass/src/lib.rs +++ b/pallets/pass/src/lib.rs @@ -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; @@ -234,8 +234,12 @@ pub mod pallet { impl, I: 'static> Pallet { pub fn account_id_for(user: HashedUserId) -> Result { - let account_id: T::AccountId = T::AccountId::decode(&mut TrailingZeroInput::new(&user)) - .map_err(|_| Error::::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::::AccountNotFound)?; Ok(account_id) } diff --git a/traits/authn/src/lib.rs b/traits/authn/src/lib.rs index a0dcc36..b5eae4a 100644 --- a/traits/authn/src/lib.rs +++ b/traits/authn/src/lib.rs @@ -45,7 +45,8 @@ type CxOf = ::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 {