diff --git a/pallets/pass/src/lib.rs b/pallets/pass/src/lib.rs index e191006..c99cb78 100644 --- a/pallets/pass/src/lib.rs +++ b/pallets/pass/src/lib.rs @@ -30,9 +30,12 @@ pub mod benchmarking; mod mock; #[cfg(test)] mod tests; + +mod extension; mod types; pub mod weights; +pub use extension::*; pub use pallet::*; pub use types::*; pub use weights::*; @@ -149,6 +152,15 @@ pub mod pallet { Self::do_add_device(&account_id, attestation) } + #[pallet::feeless_if( + |_: &OriginFor, device_id: &DeviceId, _: &CredentialOf, _: &Option>| -> bool { + if let Some(account_id) = Pallet::::account_id_for(credential.user_id()).ok() { + Pallet::::account_exists(&account_id) + } else { + false + } + } + )] #[pallet::call_index(3)] pub fn authenticate( origin: OriginFor, @@ -222,7 +234,7 @@ impl, I: 'static> Pallet { Ok(account_id) } - pub(crate) fn account_exists(who: &T::AccountId) -> bool { + pub fn account_exists(who: &T::AccountId) -> bool { frame_system::Pallet::::account_exists(who) } @@ -279,6 +291,15 @@ impl, I: 'static> Pallet { Ok(account_id) } + pub(crate) fn signer_from_session_key(who: &T::AccountId) -> Option { + let (account_id, until) = Sessions::::get(&who)?; + if frame_system::Pallet::::block_number() <= until { + Some(account_id) + } else { + None + } + } + pub(crate) fn do_authenticate( credential: CredentialOf, device_id: DeviceId,