Skip to content

Commit

Permalink
Improve EthereumSigner (#1057)
Browse files Browse the repository at this point in the history
* Improve `EthereumSigner`

* Add `RuntimeDebug`

* Typo

* Update primitives/account/src/lib.rs

---------

Co-authored-by: Wei Tang <[email protected]>
  • Loading branch information
AurevoirXavier and sorpaas authored Jun 26, 2023
1 parent 308409d commit 3b87145
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ sp-io = { version = "7.0.0", git = "https://github.com/paritytech/substrate", br
sp-keyring = { version = "7.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { version = "7.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime-interface = { version = "7.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-session = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-state-machine = { version = "0.13.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-std = { version = "5.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions primitives/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ serde = { workspace = true, optional = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-runtime-interface = { workspace = true }
sp-std = { workspace = true }

[dev-dependencies]
Expand All @@ -38,5 +39,6 @@ std = [
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-runtime-interface/std",
"sp-std/std",
]
19 changes: 17 additions & 2 deletions primitives/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
use scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
// Substrate
use sp_core::{ecdsa, H160, H256};
use sp_core::{ecdsa, RuntimeDebug, H160, H256};
use sp_io::hashing::keccak_256;
use sp_runtime_interface::pass_by::PassByInner;

/// A fully Ethereum-compatible `AccountId`.
/// Conforms to H160 address and ECDSA key standards.
Expand Down Expand Up @@ -114,7 +115,7 @@ impl From<ecdsa::Public> for AccountId20 {
}

#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[derive(Eq, PartialEq, Clone, Encode, Decode, sp_core::RuntimeDebug, TypeInfo)]
#[derive(Eq, PartialEq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct EthereumSignature(ecdsa::Signature);

impl sp_runtime::traits::Verify for EthereumSignature {
Expand Down Expand Up @@ -145,6 +146,20 @@ impl EthereumSignature {
}
}

#[derive(
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Encode,
Decode,
PassByInner,
MaxEncodedLen,
RuntimeDebug,
TypeInfo
)]
pub struct EthereumSigner([u8; 20]);

impl From<[u8; 20]> for EthereumSigner {
Expand Down

0 comments on commit 3b87145

Please sign in to comment.