Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add a sub command to generate a node key file #4884

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 bin/utils/subkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ derive_more = { version = "0.99.2" }
sc-rpc = { version = "2.0.0", path = "../../../client/rpc" }
jsonrpc-core-client = { version = "14.0.3", features = ["http"] }
hyper = "0.12.35"
libp2p = "0.15.0"
serde_json = "1.0"

[features]
Expand Down
15 changes: 15 additions & 0 deletions bin/utils/subkey/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use clap::{App, ArgMatches, SubCommand};
use codec::{Decode, Encode};
use hex_literal::hex;
use itertools::Itertools;
use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey};
use node_primitives::{Balance, Hash, Index, AccountId, Signature};
use node_runtime::{BalancesCall, Call, Runtime, SignedPayload, UncheckedExtrinsic, VERSION};
use serde_json::json;
Expand Down Expand Up @@ -248,6 +249,9 @@ fn get_app<'a, 'b>(usage: &'a str) -> App<'a, 'b> {
'The number of words in the phrase to generate. One of 12 \
(default), 15, 18, 21 and 24.'
"),
SubCommand::with_name("generate-node-key")
.about("Generate a random node libp2p key, save it to file and print its peer ID")
.args_from_usage("[file] 'Name of file to save secret key to'"),
SubCommand::with_name("inspect")
.about("Gets a public key and a SS58 address from the provided Secret URI")
.args_from_usage("[uri] 'A Key URI to be inspected. May be a secret seed, \
Expand Down Expand Up @@ -408,6 +412,17 @@ where
let mnemonic = generate_mnemonic(matches)?;
C::print_from_uri(mnemonic.phrase(), password, maybe_network, output);
}
("generate-node-key", Some(matches)) => {
let file = matches.value_of("file").ok_or(Error::Static("Output file name is required"))?;

let keypair = libp2p_ed25519::Keypair::generate();
let secret = keypair.secret();
let peer_id = PublicKey::Ed25519(keypair.public()).into_peer_id();

fs::write(file, secret.as_ref())?;

println!("{}", peer_id);
}
("inspect", Some(matches)) => {
C::print_from_uri(&get_uri("uri", &matches)?, password, maybe_network, output);
}
Expand Down