diff --git a/primitives/account/src/lib.rs b/primitives/account/src/lib.rs index fe6906f99c..ee05acec9e 100644 --- a/primitives/account/src/lib.rs +++ b/primitives/account/src/lib.rs @@ -20,8 +20,9 @@ use scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; // Substrate -use sp_core::{ecdsa, RuntimeDebug, H160, H256}; +use sp_core::{crypto::AccountId32, ecdsa, RuntimeDebug, H160, H256}; use sp_io::hashing::keccak_256; +use sp_runtime::MultiSignature; use sp_runtime_interface::pass_by::PassByInner; /// A fully Ethereum-compatible `AccountId`. @@ -159,6 +160,13 @@ impl From<[u8; 32]> for AccountId20 { } } +impl From for AccountId20 { + fn from(account: AccountId32) -> Self { + let bytes: &[u8; 32] = account.as_ref(); + Self::from(*bytes) + } +} + #[derive(Eq, PartialEq, Clone, RuntimeDebug, Encode, Decode, TypeInfo)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct EthereumSignature(ecdsa::Signature); @@ -185,9 +193,23 @@ impl sp_runtime::traits::Verify for EthereumSignature { } } +impl From for EthereumSignature { + fn from(signature: MultiSignature) -> Self { + match signature { + MultiSignature::Ed25519(_) => { + panic!("Ed25519 not supported for EthereumSignature") + } + MultiSignature::Sr25519(_) => { + panic!("Sr25519 not supported for EthereumSignature") + } + MultiSignature::Ecdsa(sig) => Self(sig), + } + } +} + impl EthereumSignature { pub fn new(s: ecdsa::Signature) -> Self { - EthereumSignature(s) + Self(s) } }