Skip to content

Commit 8c61e52

Browse files
authored
init passkey pallet (#2033)
# Goal The goal of this PR is create an empty pallet for passkey Closes #2026 # Checklist - [x] Chain spec updated - [x] Tests added - [x] Benchmarks added - [x] Weights updated
1 parent d25b833 commit 8c61e52

File tree

12 files changed

+365
-4
lines changed

12 files changed

+365
-4
lines changed

Cargo.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ benchmarks-frequency-tx-payment \
123123
benchmarks-overhead \
124124
benchmarks-schemas \
125125
benchmarks-stateful-storage \
126-
benchmarks-handles\
127-
benchmarks-time-release\
126+
benchmarks-handles \
127+
benchmarks-time-release \
128+
benchmarks-passkey \
128129
benchmarks-pallet_balances \
129130
benchmarks-pallet_collator_selection \
130131
benchmarks-pallet_democracy \
@@ -145,6 +146,7 @@ benchmarks-schemas-local \
145146
benchmarks-frequency-tx-payment-local \
146147
benchmarks-stateful-storage-local \
147148
benchmarks-handles-local \
149+
benchmarks-passkey-local \
148150
benchmarks-time-release-local \
149151
benchmarks-pallet_balances-local \
150152
benchmarks-pallet_collator_selection-local \

pallets/passkey/Cargo.toml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[package]
2+
name = "pallet-passkey"
3+
description = "Provides a way to execute transactions using passkey signatures."
4+
authors = ["Frequency"]
5+
edition = "2021"
6+
homepage = "https://frequency.xyz"
7+
license = "Apache-2.0"
8+
repository = "https://github.com/frequency-chain/frequency/"
9+
publish = false
10+
version = "0.0.0"
11+
12+
[dependencies]
13+
parity-scale-codec = { workspace = true, features = ["max-encoded-len"] }
14+
scale-info = { workspace = true, features = ["derive"] }
15+
16+
frame-support = { workspace = true }
17+
frame-system = { workspace = true }
18+
sp-io = { workspace = true }
19+
sp-runtime = { workspace = true }
20+
sp-std = { workspace = true }
21+
frame-benchmarking = { workspace = true, optional = true }
22+
sp-core = { workspace = true }
23+
log = { workspace = true, default-features = false }
24+
25+
[dev-dependencies]
26+
common-runtime = { path = "../../runtime/common", default-features = false }
27+
28+
[features]
29+
default = ["std"]
30+
std = [
31+
"parity-scale-codec/std",
32+
"frame-support/std",
33+
"frame-system/std",
34+
"scale-info/std",
35+
"sp-io/std",
36+
"sp-runtime/std",
37+
"sp-std/std",
38+
"frame-benchmarking/std",
39+
]
40+
runtime-benchmarks = [
41+
"frame-support/runtime-benchmarks",
42+
"frame-system/runtime-benchmarks",
43+
"sp-runtime/runtime-benchmarks",
44+
"frame-benchmarking/runtime-benchmarks"
45+
]
46+
try-runtime = ["frame-support/try-runtime", "frame-system/try-runtime"]

pallets/passkey/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Passkey Pallet
2+
3+
Provides a way to execute transactions using passkey signatures.

pallets/passkey/src/benchmarking.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![allow(clippy::unwrap_used)]
2+
use super::*;
3+
4+
#[allow(unused)]
5+
use crate::Pallet as Passkey;
6+
use frame_benchmarking::{benchmarks, whitelisted_caller};
7+
use frame_system::RawOrigin;
8+
use sp_std::prelude::*;
9+
10+
benchmarks! {
11+
proxy {
12+
let caller: T::AccountId = whitelisted_caller();
13+
}: _(RawOrigin::Signed(caller))
14+
verify {
15+
}
16+
17+
impl_benchmark_test_suite!(
18+
Passkey,
19+
crate::mock::new_test_ext(),
20+
crate::mock::Test
21+
);
22+
}

pallets/passkey/src/lib.rs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//! Using Passkeys to execute transactions
2+
//!
3+
//! ## Quick Links
4+
//! - [Configuration: `Config`](Config)
5+
//! - [Extrinsics: `Call`](Call)
6+
//! - [Event Enum: `Event`](Event)
7+
//! - [Error Enum: `Error`](Error)
8+
#![doc = include_str!("../README.md")]
9+
// Substrate macros are tripping the clippy::expect_used lint.
10+
#![allow(clippy::expect_used)]
11+
#![cfg_attr(not(feature = "std"), no_std)]
12+
// Strong Documentation Lints
13+
#![deny(
14+
rustdoc::broken_intra_doc_links,
15+
rustdoc::missing_crate_level_docs,
16+
rustdoc::invalid_codeblock_attributes,
17+
missing_docs
18+
)]
19+
20+
use frame_support::{
21+
dispatch::{DispatchResult, GetDispatchInfo, PostDispatchInfo},
22+
pallet_prelude::*,
23+
traits::IsSubType,
24+
};
25+
use frame_system::pallet_prelude::*;
26+
use sp_runtime::traits::Dispatchable;
27+
28+
#[cfg(test)]
29+
mod mock;
30+
#[cfg(test)]
31+
mod tests;
32+
33+
pub mod weights;
34+
pub use weights::*;
35+
36+
#[cfg(feature = "runtime-benchmarks")]
37+
mod benchmarking;
38+
39+
pub use module::*;
40+
41+
#[frame_support::pallet]
42+
pub mod module {
43+
use super::*;
44+
45+
/// the storage version for this pallet
46+
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);
47+
48+
#[pallet::config]
49+
pub trait Config: frame_system::Config {
50+
/// The overarching event type.
51+
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
52+
53+
/// The overarching call type.
54+
type RuntimeCall: Parameter
55+
+ Dispatchable<RuntimeOrigin = Self::RuntimeOrigin, PostInfo = PostDispatchInfo>
56+
+ GetDispatchInfo
57+
+ From<frame_system::Call<Self>>
58+
+ IsSubType<Call<Self>>
59+
+ IsType<<Self as frame_system::Config>::RuntimeCall>;
60+
61+
/// Weight information for extrinsics in this pallet.
62+
type WeightInfo: WeightInfo;
63+
}
64+
65+
#[pallet::error]
66+
pub enum Error<T> {
67+
/// PlaceHolder error
68+
PlaceHolderError,
69+
}
70+
71+
#[pallet::event]
72+
#[pallet::generate_deposit(fn deposit_event)]
73+
pub enum Event<T: Config> {
74+
/// PlaceHolder event
75+
PlaceHolderEvent,
76+
}
77+
78+
#[pallet::pallet]
79+
#[pallet::storage_version(STORAGE_VERSION)]
80+
pub struct Pallet<T>(_);
81+
82+
#[pallet::call]
83+
impl<T: Config> Pallet<T> {
84+
/// proxy call
85+
#[pallet::call_index(0)]
86+
#[pallet::weight(T::WeightInfo::proxy())]
87+
pub fn proxy(_origin: OriginFor<T>) -> DispatchResult {
88+
Self::deposit_event(Event::PlaceHolderEvent);
89+
Ok(())
90+
}
91+
}
92+
}
93+
94+
impl<T: Config> Pallet<T> {}

pallets/passkey/src/mock.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//! Mocks for the Time-release module.
2+
3+
use super::*;
4+
use frame_support::{
5+
construct_runtime,
6+
traits::{ConstU32, Everything},
7+
};
8+
use sp_core::H256;
9+
use sp_runtime::{traits::IdentityLookup, BuildStorage};
10+
11+
use crate as pallet_passkey;
12+
13+
pub type AccountId = u128;
14+
impl frame_system::Config for Test {
15+
type RuntimeOrigin = RuntimeOrigin;
16+
type RuntimeCall = RuntimeCall;
17+
type Nonce = u64;
18+
type Hash = H256;
19+
type Hashing = ::sp_runtime::traits::BlakeTwo256;
20+
type AccountId = AccountId;
21+
type Lookup = IdentityLookup<Self::AccountId>;
22+
type RuntimeEvent = RuntimeEvent;
23+
type Block = Block;
24+
type BlockHashCount = ConstU32<250>;
25+
type BlockWeights = ();
26+
type BlockLength = ();
27+
type Version = ();
28+
type PalletInfo = PalletInfo;
29+
type AccountData = ();
30+
type OnNewAccount = ();
31+
type OnKilledAccount = ();
32+
type DbWeight = ();
33+
type BaseCallFilter = Everything;
34+
type SystemWeightInfo = ();
35+
type SS58Prefix = ();
36+
type OnSetCode = ();
37+
type MaxConsumers = ConstU32<16>;
38+
}
39+
40+
impl Config for Test {
41+
type RuntimeEvent = RuntimeEvent;
42+
type WeightInfo = ();
43+
type RuntimeCall = RuntimeCall;
44+
}
45+
46+
type Block = frame_system::mocking::MockBlockU32<Test>;
47+
48+
construct_runtime!(
49+
pub enum Test
50+
{
51+
System: frame_system::{Pallet, Call, Storage, Config<T>, Event<T>},
52+
Passkey: pallet_passkey::{Pallet, Storage, Call, Event<T>},
53+
}
54+
);
55+
56+
pub fn new_test_ext() -> sp_io::TestExternalities {
57+
let mut ext: sp_io::TestExternalities =
58+
frame_system::GenesisConfig::<Test>::default().build_storage().unwrap().into();
59+
ext.execute_with(|| System::set_block_number(1));
60+
ext
61+
}

pallets/passkey/src/tests.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! Unit tests for the passkey module.
2+
use super::*;
3+
use frame_support::assert_ok;
4+
use mock::*;
5+
6+
#[test]
7+
fn test_works() {
8+
new_test_ext().execute_with(|| {
9+
let caller_1 = 5;
10+
assert_ok!(Passkey::proxy(RuntimeOrigin::signed(caller_1),));
11+
});
12+
}

pallets/passkey/src/weights.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
//! Autogenerated weights for `pallet_passkey`
3+
//!
4+
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
5+
//! DATE: 2024-06-14, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]`
6+
//! WORST CASE MAP SIZE: `1000000`
7+
//! HOSTNAME: `ip-10-99-10-9.us-east-2.compute.internal`, CPU: `<UNKNOWN>`
8+
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("frequency-bench")`, DB CACHE: `1024`
9+
10+
// Executed Command:
11+
// ./scripts/../target/bench-dev/frequency
12+
// benchmark
13+
// pallet
14+
// --pallet=pallet_passkey
15+
// --extrinsic
16+
// *
17+
// --chain=frequency-bench
18+
// --heap-pages=4096
19+
// --wasm-execution=compiled
20+
// --additional-trie-layers=5
21+
// --steps=20
22+
// --repeat=10
23+
// --output=./scripts/../pallets/passkey/src/weights.rs
24+
// --template=./scripts/../.maintain/frame-weight-template.hbs
25+
26+
#![cfg_attr(rustfmt, rustfmt_skip)]
27+
#![allow(unused_parens)]
28+
#![allow(unused_imports)]
29+
#![allow(missing_docs)]
30+
31+
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
32+
use core::marker::PhantomData;
33+
34+
/// Weight functions needed for `pallet_passkey`.
35+
pub trait WeightInfo {
36+
fn proxy() -> Weight;
37+
}
38+
39+
/// Weights for `pallet_passkey` using the Substrate node and recommended hardware.
40+
pub struct SubstrateWeight<T>(PhantomData<T>);
41+
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
42+
fn proxy() -> Weight {
43+
// Proof Size summary in bytes:
44+
// Measured: `0`
45+
// Estimated: `0`
46+
// Minimum execution time: 3_000_000 picoseconds.
47+
Weight::from_parts(4_000_000, 0)
48+
}
49+
}
50+
51+
// For backwards compatibility and tests.
52+
impl WeightInfo for () {
53+
fn proxy() -> Weight {
54+
// Proof Size summary in bytes:
55+
// Measured: `0`
56+
// Estimated: `0`
57+
// Minimum execution time: 3_000_000 picoseconds.
58+
Weight::from_parts(4_000_000, 0)
59+
}
60+
}
61+
62+
63+
#[cfg(test)]
64+
mod tests {
65+
use frame_support::{traits::Get, weights::Weight, dispatch::DispatchClass};
66+
use common_runtime::constants::{MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO};
67+
use common_runtime::weights::extrinsic_weights::ExtrinsicBaseWeight;
68+
69+
struct BlockWeights;
70+
impl Get<frame_system::limits::BlockWeights> for BlockWeights {
71+
fn get() -> frame_system::limits::BlockWeights {
72+
frame_system::limits::BlockWeights::builder()
73+
.base_block(Weight::zero())
74+
.for_class(DispatchClass::all(), |weights| {
75+
weights.base_extrinsic = ExtrinsicBaseWeight::get().into();
76+
})
77+
.for_class(DispatchClass::non_mandatory(), |weights| {
78+
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
79+
})
80+
.build_or_panic()
81+
}
82+
}
83+
84+
}

0 commit comments

Comments
 (0)