mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 04:41:02 +00:00
Unique Usernames in Identity Pallet (#2651)
This PR allows _username authorities_ to issue unique usernames that correspond with an account. It also provides two-way lookup, that is from `AccountId` to a single, "primary" `Username` (alongside `Registration`) and multiple unique `Username`s to an `AccountId`. Key features: - Username Authorities added (and removed) via privileged origin. - Authorities have a `suffix` and an `allocation`. They can grant up to `allocation` usernames. Their `suffix` will be appended to the usernames that they issue. A suffix may be up to 7 characters long. - Users can ask an authority to grant them a username. This will take the form `myusername.suffix`. The entire name (including suffix) must be less than or equal to 32 alphanumeric characters. - Users can approve a username for themselves in one of two ways (that is, authorities cannot grant them arbitrarily): - Pre-sign the entire username (including suffix) with a secret key that corresponds to their `AccountId` (for keyed accounts, obviously); or - Accept the username after it has been granted by an authority (it will be queued until accepted) (for non-keyed accounts like pure proxies or multisigs). - The system does not require any funds or deposits. Users without an identity will be given a default one (presumably all fields set to `None`). If they update this info, they will need to place the normal storage deposit. - If a user does not have any username, their first one will be set as `Primary`, and their `AccountId` will map to that one. If they get subsequent usernames, they can choose which one to be their primary via `set_primary_username`. - There are some state cleanup functions to remove expired usernames that have not been accepted and dangling usernames whose owners have called `clear_identity`. TODO: - [x] Add migration to runtimes - [x] Probably do off-chain migration into People Chain genesis - [x] Address a few TODO questions in code (please review) --------- Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Dónal Murray <donal.murray@parity.io>
This commit is contained in:
@@ -19,7 +19,10 @@
|
||||
|
||||
pub use sp_core::H256;
|
||||
use sp_runtime::traits::Hash;
|
||||
pub use sp_runtime::{traits::BlakeTwo256, BuildStorage};
|
||||
pub use sp_runtime::{
|
||||
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Lazy, Verify},
|
||||
BuildStorage, MultiSignature,
|
||||
};
|
||||
use sp_std::convert::{TryFrom, TryInto};
|
||||
|
||||
pub use frame_support::{
|
||||
@@ -101,6 +104,7 @@ parameter_types! {
|
||||
pub const MaxSubAccounts: u32 = 2;
|
||||
pub const MaxAdditionalFields: u32 = 2;
|
||||
pub const MaxRegistrars: u32 = 20;
|
||||
pub const PendingUsernameExpiration: u64 = 100;
|
||||
}
|
||||
ord_parameter_types! {
|
||||
pub const One: u64 = 1;
|
||||
@@ -124,9 +128,34 @@ impl pallet_identity::Config for Test {
|
||||
type Slashed = ();
|
||||
type RegistrarOrigin = EnsureOneOrRoot;
|
||||
type ForceOrigin = EnsureTwoOrRoot;
|
||||
type OffchainSignature = AccountU64;
|
||||
type SigningPublicKey = AccountU64;
|
||||
type UsernameAuthorityOrigin = EnsureOneOrRoot;
|
||||
type PendingUsernameExpiration = PendingUsernameExpiration;
|
||||
type MaxSuffixLength = ConstU32<7>;
|
||||
type MaxUsernameLength = ConstU32<32>;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo)]
|
||||
pub struct AccountU64(u64);
|
||||
impl IdentifyAccount for AccountU64 {
|
||||
type AccountId = u64;
|
||||
fn into_account(self) -> u64 {
|
||||
0u64
|
||||
}
|
||||
}
|
||||
impl Verify for AccountU64 {
|
||||
type Signer = AccountU64;
|
||||
fn verify<L: Lazy<[u8]>>(
|
||||
&self,
|
||||
_msg: L,
|
||||
_signer: &<Self::Signer as IdentifyAccount>::AccountId,
|
||||
) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AllianceIdentityVerifier;
|
||||
impl IdentityVerifier<AccountId> for AllianceIdentityVerifier {
|
||||
fn has_required_identities(who: &AccountId) -> bool {
|
||||
@@ -135,7 +164,7 @@ impl IdentityVerifier<AccountId> for AllianceIdentityVerifier {
|
||||
|
||||
fn has_good_judgement(who: &AccountId) -> bool {
|
||||
if let Some(judgements) =
|
||||
Identity::identity(who).map(|registration| registration.judgements)
|
||||
Identity::identity(who).map(|(registration, _)| registration.judgements)
|
||||
{
|
||||
judgements
|
||||
.iter()
|
||||
|
||||
Reference in New Issue
Block a user