@@ -10,11 +10,6 @@ pub use secp256k1;
10
10
use std:: collections:: BTreeMap ;
11
11
use zeroize:: Zeroize ;
12
12
13
- #[ cfg( feature = "libp2p" ) ]
14
- use libp2p_core:: { identity:: Keypair as Libp2pKeypair , PeerId } ;
15
- #[ cfg( feature = "libp2p" ) ]
16
- use std:: convert:: TryFrom ;
17
-
18
13
/// A standard implementation of the `EnrKey` trait used to sign and modify ENR records. The variants here represent the currently
19
14
/// supported in-built signing schemes.
20
15
pub enum CombinedKey {
@@ -44,27 +39,6 @@ impl From<ed25519::SecretKey> for CombinedKey {
44
39
}
45
40
}
46
41
47
- #[ cfg( any( feature = "libp2p" , doc) ) ]
48
- impl TryFrom < Libp2pKeypair > for CombinedKey {
49
- type Error = & ' static str ;
50
-
51
- fn try_from ( keypair : Libp2pKeypair ) -> Result < Self , Self :: Error > {
52
- match keypair {
53
- Libp2pKeypair :: Secp256k1 ( key) => {
54
- let secret = secp256k1:: SecretKey :: parse ( & key. secret ( ) . to_bytes ( ) )
55
- . expect ( "libp2p key must be valid" ) ;
56
- Ok ( CombinedKey :: Secp256k1 ( secret) )
57
- }
58
- Libp2pKeypair :: Ed25519 ( key) => {
59
- let ed_keypair = ed25519:: SecretKey :: from_bytes ( & key. encode ( ) [ ..32 ] )
60
- . expect ( "libp2p key must be valid" ) ;
61
- Ok ( CombinedKey :: from ( ed_keypair) )
62
- }
63
- _ => Err ( "Unsupported key type" ) ,
64
- }
65
- }
66
- }
67
-
68
42
impl EnrKey for CombinedKey {
69
43
type PublicKey = CombinedPublicKey ;
70
44
@@ -178,44 +152,33 @@ impl EnrPublicKey for CombinedPublicKey {
178
152
/// Verify a raw message, given a public key for the v4 identity scheme.
179
153
fn verify_v4 ( & self , msg : & [ u8 ] , sig : & [ u8 ] ) -> bool {
180
154
match self {
181
- CombinedPublicKey :: Secp256k1 ( pk) => pk. verify_v4 ( msg, sig) ,
182
- CombinedPublicKey :: Ed25519 ( pk) => pk. verify_v4 ( msg, sig) ,
155
+ Self :: Secp256k1 ( pk) => pk. verify_v4 ( msg, sig) ,
156
+ Self :: Ed25519 ( pk) => pk. verify_v4 ( msg, sig) ,
183
157
}
184
158
}
185
159
186
160
/// Encodes the public key into compressed form, if possible.
187
161
fn encode ( & self ) -> Vec < u8 > {
188
162
match self {
189
163
// serialize in compressed form: 33 bytes
190
- CombinedPublicKey :: Secp256k1 ( pk) => pk. encode ( ) ,
191
- CombinedPublicKey :: Ed25519 ( pk) => pk. encode ( ) ,
164
+ Self :: Secp256k1 ( pk) => pk. encode ( ) ,
165
+ Self :: Ed25519 ( pk) => pk. encode ( ) ,
192
166
}
193
167
}
194
168
195
169
/// Encodes the public key in uncompressed form.
196
170
fn encode_uncompressed ( & self ) -> Vec < u8 > {
197
171
match self {
198
- CombinedPublicKey :: Secp256k1 ( pk) => pk. encode_uncompressed ( ) ,
199
- CombinedPublicKey :: Ed25519 ( pk) => pk. encode_uncompressed ( ) ,
172
+ Self :: Secp256k1 ( pk) => pk. encode_uncompressed ( ) ,
173
+ Self :: Ed25519 ( pk) => pk. encode_uncompressed ( ) ,
200
174
}
201
175
}
202
176
203
177
/// Generates the ENR public key string associated with the key type.
204
178
fn enr_key ( & self ) -> String {
205
179
match self {
206
- CombinedPublicKey :: Secp256k1 ( key) => key. enr_key ( ) ,
207
- CombinedPublicKey :: Ed25519 ( key) => key. enr_key ( ) ,
208
- }
209
- }
210
-
211
- #[ cfg( any( feature = "libp2p" , doc) ) ]
212
- /// Converts the publickey into a peer id, without consuming the key.
213
- ///
214
- /// This is only available with the `libp2p` feature flag.
215
- fn into_peer_id ( & self ) -> PeerId {
216
- match self {
217
- CombinedPublicKey :: Secp256k1 ( pk) => pk. into_peer_id ( ) ,
218
- CombinedPublicKey :: Ed25519 ( pk) => pk. into_peer_id ( ) ,
180
+ Self :: Secp256k1 ( key) => key. enr_key ( ) ,
181
+ Self :: Ed25519 ( key) => key. enr_key ( ) ,
219
182
}
220
183
}
221
184
}
0 commit comments