mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 03:18:01 +00:00
Add a sub command to generate a node key file (#4884)
* Add a sub command to generate a node key file in the format required by a substrate node * Update lock file * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Updates as per code review Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Generated
+1
@@ -7445,6 +7445,7 @@ dependencies = [
|
||||
"hyper 0.12.35",
|
||||
"itertools",
|
||||
"jsonrpc-core-client",
|
||||
"libp2p",
|
||||
"node-primitives",
|
||||
"node-runtime",
|
||||
"pallet-balances",
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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;
|
||||
@@ -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, \
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user