mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 10:57:56 +00:00
Remove support for secp256k1 for network keys (#3897)
This commit is contained in:
committed by
Gavin Wood
parent
311be1d071
commit
eabdcbdd4f
@@ -29,7 +29,7 @@ use bitflags::bitflags;
|
||||
use consensus::{block_validation::BlockAnnounceValidator, import_queue::ImportQueue};
|
||||
use sr_primitives::traits::{Block as BlockT};
|
||||
use std::sync::Arc;
|
||||
use libp2p::identity::{Keypair, secp256k1, ed25519};
|
||||
use libp2p::identity::{Keypair, ed25519};
|
||||
use libp2p::wasm_ext;
|
||||
use libp2p::{PeerId, Multiaddr, multiaddr};
|
||||
use std::error::Error;
|
||||
@@ -364,15 +364,10 @@ impl NonReservedPeerMode {
|
||||
/// the evaluation of the node key configuration.
|
||||
#[derive(Clone)]
|
||||
pub enum NodeKeyConfig {
|
||||
/// A Secp256k1 secret key configuration.
|
||||
Secp256k1(Secret<secp256k1::SecretKey>),
|
||||
/// A Ed25519 secret key configuration.
|
||||
Ed25519(Secret<ed25519::SecretKey>)
|
||||
}
|
||||
|
||||
/// The options for obtaining a Secp256k1 secret key.
|
||||
pub type Secp256k1Secret = Secret<secp256k1::SecretKey>;
|
||||
|
||||
/// The options for obtaining a Ed25519 secret key.
|
||||
pub type Ed25519Secret = Secret<ed25519::SecretKey>;
|
||||
|
||||
@@ -385,7 +380,6 @@ pub enum Secret<K> {
|
||||
/// it is created with a newly generated secret key `K`. The format
|
||||
/// of the file is determined by `K`:
|
||||
///
|
||||
/// * `secp256k1::SecretKey`: An unencoded 32 bytes Secp256k1 secret key.
|
||||
/// * `ed25519::SecretKey`: An unencoded 32 bytes Ed25519 secret key.
|
||||
File(PathBuf),
|
||||
/// Always generate a new secret key `K`.
|
||||
@@ -406,20 +400,6 @@ impl NodeKeyConfig {
|
||||
pub fn into_keypair(self) -> io::Result<Keypair> {
|
||||
use NodeKeyConfig::*;
|
||||
match self {
|
||||
Secp256k1(Secret::New) =>
|
||||
Ok(Keypair::generate_secp256k1()),
|
||||
|
||||
Secp256k1(Secret::Input(k)) =>
|
||||
Ok(Keypair::Secp256k1(k.into())),
|
||||
|
||||
Secp256k1(Secret::File(f)) =>
|
||||
get_secret(f,
|
||||
|mut b| secp256k1::SecretKey::from_bytes(&mut b),
|
||||
secp256k1::SecretKey::generate,
|
||||
|b| b.to_bytes().to_vec())
|
||||
.map(secp256k1::Keypair::from)
|
||||
.map(Keypair::Secp256k1),
|
||||
|
||||
Ed25519(Secret::New) =>
|
||||
Ok(Keypair::generate_ed25519()),
|
||||
|
||||
@@ -526,9 +506,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_secret_input() {
|
||||
let sk = secp256k1::SecretKey::generate();
|
||||
let kp1 = NodeKeyConfig::Secp256k1(Secret::Input(sk.clone())).into_keypair().unwrap();
|
||||
let kp2 = NodeKeyConfig::Secp256k1(Secret::Input(sk)).into_keypair().unwrap();
|
||||
let sk = ed25519::SecretKey::generate();
|
||||
let kp1 = NodeKeyConfig::Ed25519(Secret::Input(sk.clone())).into_keypair().unwrap();
|
||||
let kp2 = NodeKeyConfig::Ed25519(Secret::Input(sk)).into_keypair().unwrap();
|
||||
assert!(secret_bytes(&kp1) == secret_bytes(&kp2));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
//! # Node identities and addresses
|
||||
//!
|
||||
//! In a decentralized network, each node possesses a network private key and a network public key.
|
||||
//! In Substrate, the keys are based on the ed25519 curve. As of the writing of this documentation,
|
||||
//! the secp256k1 curve can also be used, but is deprecated. Our local node's keypair must be
|
||||
//! passed as part of the network configuration.
|
||||
//! In Substrate, the keys are based on the ed25519 curve.
|
||||
//!
|
||||
//! From a node's public key, we can derive its *identity*. In Substrate and libp2p, a node's
|
||||
//! identity is represented with the [`PeerId`] struct. All network communications between nodes on
|
||||
|
||||
@@ -42,7 +42,7 @@ use sr_primitives::{traits::{Block as BlockT, NumberFor}, ConsensusEngineId};
|
||||
|
||||
use crate::{behaviour::{Behaviour, BehaviourOut}, config::{parse_str_addr, parse_addr}};
|
||||
use crate::{NetworkState, NetworkStateNotConnectedPeer, NetworkStatePeer};
|
||||
use crate::{transport, config::NodeKeyConfig, config::NonReservedPeerMode};
|
||||
use crate::{transport, config::NonReservedPeerMode};
|
||||
use crate::config::{Params, TransportConfig};
|
||||
use crate::error::Error;
|
||||
use crate::protocol::{self, Protocol, Context, CustomMessageOutcome, PeerInfo};
|
||||
@@ -185,9 +185,6 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkWorker
|
||||
};
|
||||
|
||||
// Private and public keys configuration.
|
||||
if let NodeKeyConfig::Secp256k1(_) = params.network_config.node_key {
|
||||
warn!(target: "sub-libp2p", "Secp256k1 keys are deprecated in favour of ed25519");
|
||||
}
|
||||
let local_identity = params.network_config.node_key.clone().into_keypair()?;
|
||||
let local_public = local_identity.public();
|
||||
let local_peer_id = local_public.clone().into_peer_id();
|
||||
|
||||
Reference in New Issue
Block a user