1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#[cfg(feature = "ed25519")]
mod combined;
#[cfg(feature = "ed25519")]
mod ed25519;
#[cfg(any(feature = "libsecp256k1", doc))]
mod libsecp256k1;
#[cfg(feature = "rust-secp256k1")]
mod rust_secp256k1;
#[cfg(feature = "rust-secp256k1")]
pub use c_secp256k1;
#[cfg(feature = "ed25519")]
pub use combined::{CombinedKey, CombinedPublicKey};
#[cfg(feature = "ed25519")]
pub use ed25519_dalek;
#[cfg(any(feature = "libsecp256k1", doc))]
pub use secp256k1;
use rlp::DecoderError;
use std::{
collections::BTreeMap,
error::Error,
fmt::{self, Display},
};
pub trait EnrKey {
type PublicKey: EnrPublicKey + Clone;
fn sign_v4(&self, msg: &[u8]) -> Result<Vec<u8>, SigningError>;
fn public(&self) -> Self::PublicKey;
fn enr_to_public(content: &BTreeMap<String, Vec<u8>>) -> Result<Self::PublicKey, DecoderError>;
}
pub trait EnrPublicKey {
fn verify_v4(&self, msg: &[u8], sig: &[u8]) -> bool;
fn encode(&self) -> Vec<u8>;
fn encode_uncompressed(&self) -> Vec<u8>;
fn enr_key(&self) -> String;
}
#[derive(Debug)]
pub struct SigningError {
msg: String,
source: Option<Box<dyn Error + Send + Sync>>,
}
#[allow(dead_code)]
impl SigningError {
pub(crate) fn new<S: Display>(msg: S) -> Self {
Self {
msg: msg.to_string(),
source: None,
}
}
}
impl fmt::Display for SigningError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Key signing error: {}", self.msg)
}
}
impl Error for SigningError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
self.source.as_ref().map(|s| &**s as &dyn Error)
}
}