From 68a95c0646810ed7afe5022ac211c1f214d950c5 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 17 Oct 2021 00:48:04 +0000 Subject: [PATCH] Add lightning message-signing support --- src/cli.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index 00d805b..9bc2ef1 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -8,7 +8,7 @@ use bitcoin::hashes::Hash; use bitcoin::network::constants::Network; use bitcoin::secp256k1::key::PublicKey; use lightning::chain; -use lightning::chain::keysinterface::KeysManager; +use lightning::chain::keysinterface::{KeysInterface, KeysManager}; use lightning::ln::features::InvoiceFeatures; use lightning::ln::msgs::NetAddress; use lightning::ln::{PaymentHash, PaymentSecret}; @@ -412,6 +412,24 @@ pub(crate) async fn poll_for_user_input( } "nodeinfo" => node_info(channel_manager.clone(), peer_manager.clone()), "listpeers" => list_peers(peer_manager.clone()), + "signmessage" => { + const MSG_STARTPOS: usize = "signmsg".len() + 1; + if line.as_bytes().len() <= MSG_STARTPOS { + println!("ERROR: signmsg requires a message"); + print!("> "); + io::stdout().flush().unwrap(); + continue; + } + println!( + "{:?}", + lightning::util::message_signing::sign( + &line.as_bytes()[MSG_STARTPOS..], + &keys_manager.get_node_secret() + ) + ); + print!("> "); + io::stdout().flush().unwrap(); + } _ => println!("Unknown command. See `\"help\" for available commands."), } } @@ -431,6 +449,7 @@ fn help() { println!("forceclosechannel "); println!("nodeinfo"); println!("listpeers"); + println!("signmessage "); } fn node_info(channel_manager: Arc, peer_manager: Arc) { -- 2.39.5