-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
61 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,25 +17,23 @@ | |
// If you feel like getting in touch with us, you can do so at [email protected] | ||
|
||
use did::{ | ||
traits::deletion::RequireBoth, DeriveDidCallAuthorizationVerificationKeyRelationship, | ||
DeriveDidCallAuthorizationVerificationKeyRelationship, | ||
DeriveDidCallKeyRelationshipResult, DidRawOrigin, DidVerificationKeyRelationship, EnsureDidOrigin, | ||
RelationshipDeriveError, | ||
}; | ||
use frame_system::EnsureRoot; | ||
use runtime_common::{ | ||
constants, AccountId, DidIdentifier, EnsureNoLinkedAccountDeletionHook, EnsureNoLinkedWeb3NameDeletionHook, | ||
constants, | ||
AccountId, DidIdentifier, | ||
SendDustAndFeesToTreasury, | ||
}; | ||
use sp_core::ConstBool; | ||
|
||
use crate::{ | ||
weights::{self, rocksdb_weights::constants::RocksDbWeight}, | ||
weights::{self}, | ||
Balances, Migration, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, | ||
}; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
impl DeriveDidCallAuthorizationVerificationKeyRelationship for RuntimeCall { | ||
fn derive_verification_key_relationship(&self) -> DeriveDidCallKeyRelationshipResult { | ||
/// ensure that all calls have the same VerificationKeyRelationship | ||
|
@@ -95,46 +93,34 @@ impl did::traits::DidLifecycleHooks<Runtime> for DidLifecycleHooks { | |
type DeletionHook = EnsureNoNamesAndNoLinkedAccountsOnDidDeletion; | ||
} | ||
|
||
// Read size is given by the `MaxEncodedLen`: https://substrate.stackexchange.com/a/11843/1795. | ||
// Since the trait is not `const`, we have unit tests that make sure the | ||
// `max_encoded_len()` function matches this const. | ||
const WORST_CASE_WEB3_NAME_STORAGE_READ_SIZE: u64 = 33; | ||
/// Ensure there is no Web3Name linked to a DID. | ||
type EnsureNoWeb3NameOnDeletion = | ||
EnsureNoLinkedWeb3NameDeletionHook<{ RocksDbWeight::get().read }, WORST_CASE_WEB3_NAME_STORAGE_READ_SIZE, ()>; | ||
// Read size is given by the `MaxEncodedLen`: https://substrate.stackexchange.com/a/11843/1795. | ||
// Since the trait is not `const`, we have unit tests that make sure the | ||
// `max_encoded_len()` function matches this const. | ||
const WORST_CASE_DOT_NAME_STORAGE_READ_SIZE: u64 = 33; | ||
/// Ensure there is no Dotname linked to a DID. | ||
type EnsureNoDotNameOnDeletion = EnsureNoLinkedWeb3NameDeletionHook< | ||
{ RocksDbWeight::get().read }, | ||
WORST_CASE_DOT_NAME_STORAGE_READ_SIZE, | ||
DotNamesDeployment, | ||
>; | ||
/// Ensure there is neither a Web3Name nor a Dotname linked to a DID. | ||
type EnsureNoUsernamesOnDeletion = RequireBoth<EnsureNoWeb3NameOnDeletion, EnsureNoDotNameOnDeletion>; | ||
pub struct EnsureNoNamesAndNoLinkedAccountsOnDidDeletion; | ||
|
||
// Read size is given by the `MaxEncodedLen`: https://substrate.stackexchange.com/a/11843/1795. | ||
// Since the trait is not `const`, we have unit tests that make sure the | ||
// `max_encoded_len()` function matches this const. | ||
const WORST_CASE_LINKING_STORAGE_READ_SIZE: u64 = 33; | ||
/// Ensure there is no linked account (for a web3name) to a DID. | ||
type EnsureNoWeb3NameLinkedAccountsOnDeletion = | ||
EnsureNoLinkedAccountDeletionHook<{ RocksDbWeight::get().read }, WORST_CASE_LINKING_STORAGE_READ_SIZE, ()>; | ||
/// Ensure there is no unique linked account (for a dotname) to a DID. | ||
type EnsureNoDotNameLinkedAccountOnDeletion = EnsureNoLinkedWeb3NameDeletionHook< | ||
{ RocksDbWeight::get().read }, | ||
WORST_CASE_LINKING_STORAGE_READ_SIZE, | ||
UniqueLinkingDeployment, | ||
>; | ||
/// Ensure there is no account linked for both the DID's Web3Name and DotName. | ||
type EnsureNoLinkedAccountsOnDeletion = | ||
RequireBoth<EnsureNoWeb3NameLinkedAccountsOnDeletion, EnsureNoDotNameLinkedAccountOnDeletion>; | ||
impl did::traits::DidDeletionHook<Runtime> for EnsureNoNamesAndNoLinkedAccountsOnDidDeletion { | ||
fn can_delete(did: &did::DidIdentifierOf<Runtime>) -> bool { | ||
// 1. Check if there's a linked Web3name | ||
if pallet_web3_names::Names::<Runtime>::contains_key(did) { | ||
return false; | ||
} | ||
// 2. Check if there's a linked Dotname | ||
if pallet_web3_names::Names::<Runtime, DotNamesDeployment>::contains_key(did) { | ||
return false; | ||
} | ||
// 3. Check if there's a Web3name linked account | ||
if pallet_did_lookup::ConnectedAccounts::<Runtime>::iter_key_prefix(did) | ||
.next() | ||
.is_some() { | ||
return false; | ||
} | ||
// 4. Check if there's a Dotname linked account | ||
if pallet_did_lookup::ConnectedAccounts::<Runtime, UniqueLinkingDeployment>::iter_key_prefix(did) | ||
.next() | ||
.is_some() { | ||
return false; | ||
} | ||
|
||
/// Ensure there is no trace of names nor linked accounts for the DID. | ||
pub type EnsureNoNamesAndNoLinkedAccountsOnDidDeletion = | ||
RequireBoth<EnsureNoUsernamesOnDeletion, EnsureNoLinkedAccountsOnDeletion>; | ||
true | ||
} | ||
} | ||
|
||
impl did::Config for Runtime { | ||
type RuntimeEvent = RuntimeEvent; | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,25 +17,22 @@ | |
// If you feel like getting in touch with us, you can do so at [email protected] | ||
|
||
use did::{ | ||
traits::deletion::RequireBoth, DeriveDidCallAuthorizationVerificationKeyRelationship, | ||
DeriveDidCallAuthorizationVerificationKeyRelationship, | ||
DeriveDidCallKeyRelationshipResult, DidRawOrigin, DidVerificationKeyRelationship, EnsureDidOrigin, | ||
RelationshipDeriveError, | ||
}; | ||
use frame_system::EnsureRoot; | ||
use runtime_common::{ | ||
constants, did::EnsureNoLinkedAccountDeletionHook, AccountId, DidIdentifier, EnsureNoLinkedWeb3NameDeletionHook, | ||
SendDustAndFeesToTreasury, | ||
constants, | ||
AccountId, DidIdentifier, SendDustAndFeesToTreasury, | ||
}; | ||
use sp_core::ConstBool; | ||
|
||
use crate::{ | ||
weights::{self, rocksdb_weights::constants::RocksDbWeight}, | ||
weights::{self}, | ||
Balances, Migration, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, | ||
}; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
impl DeriveDidCallAuthorizationVerificationKeyRelationship for RuntimeCall { | ||
fn derive_verification_key_relationship(&self) -> DeriveDidCallKeyRelationshipResult { | ||
/// ensure that all calls have the same VerificationKeyRelationship | ||
|
@@ -95,46 +92,34 @@ impl did::traits::DidLifecycleHooks<Runtime> for DidLifecycleHooks { | |
type DeletionHook = EnsureNoNamesAndNoLinkedAccountsOnDidDeletion; | ||
} | ||
|
||
// Read size is given by the `MaxEncodedLen`: https://substrate.stackexchange.com/a/11843/1795. | ||
// Since the trait is not `const`, we have unit tests that make sure the | ||
// `max_encoded_len()` function matches this const. | ||
const WORST_CASE_WEB3_NAME_STORAGE_READ_SIZE: u64 = 33; | ||
/// Ensure there is no Web3Name linked to a DID. | ||
type EnsureNoWeb3NameOnDeletion = | ||
EnsureNoLinkedWeb3NameDeletionHook<{ RocksDbWeight::get().read }, WORST_CASE_WEB3_NAME_STORAGE_READ_SIZE, ()>; | ||
// Read size is given by the `MaxEncodedLen`: https://substrate.stackexchange.com/a/11843/1795. | ||
// Since the trait is not `const`, we have unit tests that make sure the | ||
// `max_encoded_len()` function matches this const. | ||
const WORST_CASE_DOT_NAME_STORAGE_READ_SIZE: u64 = 33; | ||
/// Ensure there is no Dotname linked to a DID. | ||
type EnsureNoDotNameOnDeletion = EnsureNoLinkedWeb3NameDeletionHook< | ||
{ RocksDbWeight::get().read }, | ||
WORST_CASE_DOT_NAME_STORAGE_READ_SIZE, | ||
DotNamesDeployment, | ||
>; | ||
/// Ensure there is neither a Web3Name nor a Dotname linked to a DID. | ||
type EnsureNoUsernamesOnDeletion = RequireBoth<EnsureNoWeb3NameOnDeletion, EnsureNoDotNameOnDeletion>; | ||
pub struct EnsureNoNamesAndNoLinkedAccountsOnDidDeletion; | ||
|
||
// Read size is given by the `MaxEncodedLen`: https://substrate.stackexchange.com/a/11843/1795. | ||
// Since the trait is not `const`, we have unit tests that make sure the | ||
// `max_encoded_len()` function matches this const. | ||
const WORST_CASE_LINKING_STORAGE_READ_SIZE: u64 = 33; | ||
/// Ensure there is no linked account (for a web3name) to a DID. | ||
type EnsureNoWeb3NameLinkedAccountsOnDeletion = | ||
EnsureNoLinkedAccountDeletionHook<{ RocksDbWeight::get().read }, WORST_CASE_LINKING_STORAGE_READ_SIZE, ()>; | ||
/// Ensure there is no unique linked account (for a dotname) to a DID. | ||
type EnsureNoDotNameLinkedAccountOnDeletion = EnsureNoLinkedWeb3NameDeletionHook< | ||
{ RocksDbWeight::get().read }, | ||
WORST_CASE_LINKING_STORAGE_READ_SIZE, | ||
UniqueLinkingDeployment, | ||
>; | ||
/// Ensure there is no account linked for both the DID's Web3Name and DotName. | ||
type EnsureNoLinkedAccountsOnDeletion = | ||
RequireBoth<EnsureNoWeb3NameLinkedAccountsOnDeletion, EnsureNoDotNameLinkedAccountOnDeletion>; | ||
impl did::traits::DidDeletionHook<Runtime> for EnsureNoNamesAndNoLinkedAccountsOnDidDeletion { | ||
fn can_delete(did: &did::DidIdentifierOf<Runtime>) -> bool { | ||
// 1. Check if there's a linked Web3name | ||
if pallet_web3_names::Names::<Runtime>::contains_key(did) { | ||
return false; | ||
} | ||
// 2. Check if there's a linked Dotname | ||
if pallet_web3_names::Names::<Runtime, DotNamesDeployment>::contains_key(did) { | ||
return false; | ||
} | ||
// 3. Check if there's a Web3name linked account | ||
if pallet_did_lookup::ConnectedAccounts::<Runtime>::iter_key_prefix(did) | ||
.next() | ||
.is_some() { | ||
return false; | ||
} | ||
// 4. Check if there's a Dotname linked account | ||
if pallet_did_lookup::ConnectedAccounts::<Runtime, UniqueLinkingDeployment>::iter_key_prefix(did) | ||
.next() | ||
.is_some() { | ||
return false; | ||
} | ||
|
||
/// Ensure there is no trace of names nor linked accounts for the DID. | ||
pub type EnsureNoNamesAndNoLinkedAccountsOnDidDeletion = | ||
RequireBoth<EnsureNoUsernamesOnDeletion, EnsureNoLinkedAccountsOnDeletion>; | ||
true | ||
} | ||
} | ||
|
||
impl did::Config for Runtime { | ||
type RuntimeEvent = RuntimeEvent; | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.