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

Commit 4b09788

Browse files
authored
Add subkey inspect-node-key (#6153)
1 parent d166fcf commit 4b09788

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

bin/utils/subkey/src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ fn get_app<'a, 'b>(usage: &'a str) -> App<'a, 'b> {
267267
If the value is a file, the file content is used as URI. \
268268
If not given, you will be prompted for the URI.'
269269
"),
270+
SubCommand::with_name("inspect-node-key")
271+
.about("Print the peer ID corresponding to the node key in the given file")
272+
.args_from_usage("[file] 'Name of file to read the secret key from'"),
270273
SubCommand::with_name("sign")
271274
.about("Sign a message, provided on STDIN, with a given (secret) key")
272275
.args_from_usage("
@@ -439,6 +442,17 @@ where
439442
("inspect", Some(matches)) => {
440443
C::print_from_uri(&get_uri("uri", &matches)?, password, maybe_network, output);
441444
}
445+
("inspect-node-key", Some(matches)) => {
446+
let file = matches.value_of("file").ok_or(Error::Static("Input file name is required"))?;
447+
448+
let mut file_content = fs::read(file)?;
449+
let secret = libp2p_ed25519::SecretKey::from_bytes(&mut file_content)
450+
.map_err(|_| Error::Static("Bad node key file"))?;
451+
let keypair = libp2p_ed25519::Keypair::from(secret);
452+
let peer_id = PublicKey::Ed25519(keypair.public()).into_peer_id();
453+
454+
println!("{}", peer_id);
455+
}
442456
("sign", Some(matches)) => {
443457
let suri = get_uri("suri", &matches)?;
444458
let should_decode = matches.is_present("hex");

0 commit comments

Comments
 (0)