From 54a89f8094e59fff4034428954cb778ddda4a880 Mon Sep 17 00:00:00 2001
From: Hugo Trentesaux <hugo@trentesaux.fr>
Date: Fri, 10 Nov 2023 16:28:45 +0100
Subject: [PATCH] merge new owner key and revocation signature

---
 docs/api/runtime-calls.md            |  6 +++---
 pallets/duniter-wot/src/mock.rs      |  6 ++----
 pallets/identity/src/benchmarking.rs |  4 ++--
 pallets/identity/src/lib.rs          | 22 +++++++++------------
 pallets/identity/src/mock.rs         |  6 ++----
 pallets/quota/src/mock.rs            |  6 ++----
 runtime/common/src/entities.rs       | 29 ----------------------------
 runtime/common/src/pallets_config.rs |  6 ++----
 8 files changed, 22 insertions(+), 63 deletions(-)

diff --git a/docs/api/runtime-calls.md b/docs/api/runtime-calls.md
index 7ef780bfd..e7b44b9c3 100644
--- a/docs/api/runtime-calls.md
+++ b/docs/api/runtime-calls.md
@@ -679,7 +679,7 @@ validate the owned identity (must meet the main wot requirements)
 
 ```rust
 new_key: T::AccountId
-new_key_sig: T::NewOwnerKeySignature
+new_key_sig: T::Signature
 ```
 </details>
 
@@ -699,7 +699,7 @@ The origin should be the old identity owner key.
 ```rust
 idty_index: T::IdtyIndex
 revocation_key: T::AccountId
-revocation_sig: T::RevocationSignature
+revocation_sig: T::Signature
 ```
 </details>
 
@@ -732,7 +732,7 @@ change sufficient ref count for given key
 
 ```rust
 account_id: T::AccountId
-payload_sig: T::NewOwnerKeySignature
+payload_sig: T::Signature
 ```
 </details>
 
diff --git a/pallets/duniter-wot/src/mock.rs b/pallets/duniter-wot/src/mock.rs
index 2eef61ea1..6d65720d3 100644
--- a/pallets/duniter-wot/src/mock.rs
+++ b/pallets/duniter-wot/src/mock.rs
@@ -129,12 +129,10 @@ impl pallet_identity::Config for Test {
     type IdtyIndex = IdtyIndex;
     type AccountLinker = ();
     type IdtyRemovalOtherReason = IdtyRemovalWotReason;
-    type NewOwnerKeySigner = UintAuthorityId;
-    type NewOwnerKeySignature = TestSignature;
+    type Signer = UintAuthorityId;
+    type Signature = TestSignature;
     type OnIdtyChange = DuniterWot;
     type RemoveIdentityConsumers = ();
-    type RevocationSigner = UintAuthorityId;
-    type RevocationSignature = TestSignature;
     type RuntimeEvent = RuntimeEvent;
     type WeightInfo = ();
     #[cfg(feature = "runtime-benchmarks")]
diff --git a/pallets/identity/src/benchmarking.rs b/pallets/identity/src/benchmarking.rs
index a579b917b..0f72bf76a 100644
--- a/pallets/identity/src/benchmarking.rs
+++ b/pallets/identity/src/benchmarking.rs
@@ -107,8 +107,8 @@ fn create_identities<T: Config>(i: u32) -> Result<(), &'static str> {
 benchmarks! {
     where_clause {
         where
-            T::NewOwnerKeySignature: From<sp_core::sr25519::Signature>,
-            T::RevocationSignature: From<sp_core::sr25519::Signature>,
+            T::Signature: From<sp_core::sr25519::Signature>,
+            T::Signature: From<sp_core::sr25519::Signature>,
             T::AccountId: From<AccountId32>,
             T::IdtyIndex: From<u32>,
     }
diff --git a/pallets/identity/src/lib.rs b/pallets/identity/src/lib.rs
index 810cd100e..b636f3c7e 100644
--- a/pallets/identity/src/lib.rs
+++ b/pallets/identity/src/lib.rs
@@ -105,17 +105,13 @@ pub mod pallet {
         type IdtyRemovalOtherReason: Clone + Codec + Debug + Eq + TypeInfo;
         /// On identity confirmed by its owner
         type OnIdtyChange: OnIdtyChange<Self>;
-        /// Signing key of new owner key payload
-        type NewOwnerKeySigner: IdentifyAccount<AccountId = Self::AccountId>;
-        /// Signature of new owner key payload
-        type NewOwnerKeySignature: Parameter + Verify<Signer = Self::NewOwnerKeySigner>;
+        /// Signing key of a payload
+        type Signer: IdentifyAccount<AccountId = Self::AccountId>;
+        /// Signature of a payload
+        type Signature: Parameter + Verify<Signer = Self::Signer>;
         /// Handle the logic that removes all identity consumers.
         /// "identity consumers" meaning all things that rely on the existence of the identity.
         type RemoveIdentityConsumers: RemoveIdentityConsumers<Self::IdtyIndex>;
-        /// Signing key of revocation payload
-        type RevocationSigner: IdentifyAccount<AccountId = Self::AccountId>;
-        /// Signature of revocation payload
-        type RevocationSignature: Parameter + Verify<Signer = Self::RevocationSigner>;
         /// Because this pallet emits events, it depends on the runtime's definition of an event.
         type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
         /// Type representing the weight of this pallet
@@ -430,7 +426,7 @@ pub mod pallet {
         pub fn change_owner_key(
             origin: OriginFor<T>,
             new_key: T::AccountId,
-            new_key_sig: T::NewOwnerKeySignature,
+            new_key_sig: T::Signature,
         ) -> DispatchResultWithPostInfo {
             // verification phase
             let who = ensure_signed(origin)?;
@@ -515,7 +511,7 @@ pub mod pallet {
             origin: OriginFor<T>,
             idty_index: T::IdtyIndex,
             revocation_key: T::AccountId,
-            revocation_sig: T::RevocationSignature,
+            revocation_sig: T::Signature,
         ) -> DispatchResultWithPostInfo {
             let _ = ensure_signed(origin)?;
 
@@ -617,9 +613,9 @@ pub mod pallet {
         #[pallet::call_index(8)]
         #[pallet::weight(T::WeightInfo::link_account())]
         pub fn link_account(
-            origin: OriginFor<T>,                 // origin must have an identity index
-            account_id: T::AccountId,             // id of account to link (must sign the payload)
-            payload_sig: T::NewOwnerKeySignature, // signature with linked identity
+            origin: OriginFor<T>,      // origin must have an identity index
+            account_id: T::AccountId,  // id of account to link (must sign the payload)
+            payload_sig: T::Signature, // signature with linked identity
         ) -> DispatchResultWithPostInfo {
             // verif
             let who = ensure_signed(origin)?;
diff --git a/pallets/identity/src/mock.rs b/pallets/identity/src/mock.rs
index 24416a85d..40038b7ed 100644
--- a/pallets/identity/src/mock.rs
+++ b/pallets/identity/src/mock.rs
@@ -110,12 +110,10 @@ impl pallet_identity::Config for Test {
     type IdtyIndex = u64;
     type AccountLinker = ();
     type IdtyRemovalOtherReason = ();
-    type NewOwnerKeySigner = AccountPublic;
-    type NewOwnerKeySignature = Signature;
+    type Signer = AccountPublic;
+    type Signature = Signature;
     type OnIdtyChange = ();
     type RemoveIdentityConsumers = ();
-    type RevocationSigner = AccountPublic;
-    type RevocationSignature = Signature;
     type RuntimeEvent = RuntimeEvent;
     type WeightInfo = ();
     #[cfg(feature = "runtime-benchmarks")]
diff --git a/pallets/quota/src/mock.rs b/pallets/quota/src/mock.rs
index 39431616b..17b825fc4 100644
--- a/pallets/quota/src/mock.rs
+++ b/pallets/quota/src/mock.rs
@@ -156,12 +156,10 @@ impl pallet_identity::Config for Test {
     type IdtyIndex = u64;
     type AccountLinker = ();
     type IdtyRemovalOtherReason = ();
-    type NewOwnerKeySigner = AccountPublic;
-    type NewOwnerKeySignature = Signature;
+    type Signer = AccountPublic;
+    type Signature = Signature;
     type OnIdtyChange = ();
     type RemoveIdentityConsumers = ();
-    type RevocationSigner = AccountPublic;
-    type RevocationSignature = Signature;
     type RuntimeEvent = RuntimeEvent;
     type WeightInfo = ();
 }
diff --git a/runtime/common/src/entities.rs b/runtime/common/src/entities.rs
index 5df05770f..823ae2a71 100644
--- a/runtime/common/src/entities.rs
+++ b/runtime/common/src/entities.rs
@@ -94,35 +94,6 @@ impl From<IdtyData> for pallet_universal_dividend::FirstEligibleUd {
     }
 }
 
-pub struct NewOwnerKeySigner(sp_core::sr25519::Public);
-
-impl sp_runtime::traits::IdentifyAccount for NewOwnerKeySigner {
-    type AccountId = crate::AccountId;
-    fn into_account(self) -> crate::AccountId {
-        <[u8; 32]>::from(self.0).into()
-    }
-}
-
-#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
-pub struct NewOwnerKeySignature(sp_core::sr25519::Signature);
-
-impl sp_runtime::traits::Verify for NewOwnerKeySignature {
-    type Signer = NewOwnerKeySigner;
-    fn verify<L: sp_runtime::traits::Lazy<[u8]>>(&self, msg: L, signer: &crate::AccountId) -> bool {
-        use sp_core::crypto::ByteArray as _;
-        match sp_core::sr25519::Public::from_slice(signer.as_ref()) {
-            Ok(signer) => self.0.verify(msg, &signer),
-            Err(()) => false,
-        }
-    }
-}
-
-impl From<sp_core::sr25519::Signature> for NewOwnerKeySignature {
-    fn from(a: sp_core::sr25519::Signature) -> Self {
-        NewOwnerKeySignature(a)
-    }
-}
-
 #[cfg_attr(feature = "std", derive(Deserialize, Serialize))]
 #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
 pub struct SmithMembershipMetaData<SessionKeysWrapper> {
diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs
index 9d0eb6a3c..df8cb7a91 100644
--- a/runtime/common/src/pallets_config.rs
+++ b/runtime/common/src/pallets_config.rs
@@ -468,12 +468,10 @@ macro_rules! pallets_config {
             type AccountLinker = Account;
             type IdtyNameValidator = IdtyNameValidatorImpl;
             type IdtyRemovalOtherReason = pallet_duniter_wot::IdtyRemovalWotReason;
-            type NewOwnerKeySigner = <NewOwnerKeySignature as sp_runtime::traits::Verify>::Signer;
-			type NewOwnerKeySignature = NewOwnerKeySignature;
+            type Signer = <Signature as sp_runtime::traits::Verify>::Signer;
+			type Signature = Signature;
             type OnIdtyChange = (common_runtime::handlers::OnIdtyChangeHandler<Runtime>, Wot, Quota, Account);
             type RemoveIdentityConsumers = RemoveIdentityConsumersImpl<Self>;
-            type RevocationSigner = <Signature as sp_runtime::traits::Verify>::Signer;
-            type RevocationSignature = Signature;
             type RuntimeEvent = RuntimeEvent;
             type WeightInfo = common_runtime::weights::pallet_identity::WeightInfo<Runtime>;
             #[cfg(feature = "runtime-benchmarks")]
-- 
GitLab