Skip to content

Commit 8ac732c

Browse files
Prefactor -> Introduce sign_message on NodeSigner, to be used by LSPS5/service when signing notifications
1 parent b105bc5 commit 8ac732c

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ impl NodeSigner for KeyProvider {
365365
let secp_ctx = Secp256k1::signing_only();
366366
Ok(secp_ctx.sign_ecdsa(&msg_hash, &self.node_secret))
367367
}
368+
369+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()> {
370+
Ok(lightning::util::message_signing::sign(msg, &self.node_secret))
371+
}
368372
}
369373

370374
impl SignerProvider for KeyProvider {

fuzz/src/full_stack.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ impl NodeSigner for KeyProvider {
436436
Ok(secp_ctx.sign_ecdsa(&msg_hash, &self.node_secret))
437437
}
438438

439+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()> {
440+
Ok(lightning::util::message_signing::sign(msg, &self.node_secret))
441+
}
442+
439443
fn get_peer_storage_key(&self) -> PeerStorageKey {
440444
PeerStorageKey { inner: [42; 32] }
441445
}

fuzz/src/onion_message.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ impl NodeSigner for KeyProvider {
277277
unreachable!()
278278
}
279279

280+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()> {
281+
Ok(lightning::util::message_signing::sign(msg, &self.node_secret))
282+
}
283+
280284
fn get_peer_storage_key(&self) -> PeerStorageKey {
281285
unreachable!()
282286
}

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,8 @@ fn route_blinding_spec_test_vector() {
16331633
&self, _invoice: &UnsignedBolt12Invoice,
16341634
) -> Result<schnorr::Signature, ()> { unreachable!() }
16351635
fn sign_gossip_message(&self, _msg: UnsignedGossipMessage) -> Result<Signature, ()> { unreachable!() }
1636+
1637+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()> { Ok(crate::util::message_signing::sign(msg, &self.node_secret)) }
16361638
}
16371639
let logger = test_utils::TestLogger::with_id("".to_owned());
16381640

@@ -1944,6 +1946,7 @@ fn test_trampoline_inbound_payment_decoding() {
19441946
&self, _invoice: &UnsignedBolt12Invoice,
19451947
) -> Result<schnorr::Signature, ()> { unreachable!() }
19461948
fn sign_gossip_message(&self, _msg: UnsignedGossipMessage) -> Result<Signature, ()> { unreachable!() }
1949+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()> { Ok(crate::util::message_signing::sign(msg, &self.node_secret)) }
19471950
}
19481951
let logger = test_utils::TestLogger::with_id("".to_owned());
19491952

lightning/src/sign/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,17 @@ pub trait NodeSigner {
930930
/// message to be broadcast, as otherwise it may prevent one from receiving funds over the
931931
/// corresponding channel.
932932
fn sign_gossip_message(&self, msg: UnsignedGossipMessage) -> Result<Signature, ()>;
933+
934+
/// Sign an arbitrary message with the node's secret key.
935+
///
936+
/// Creates a digital signature of a message given the node's secret. The message is prefixed
937+
/// with "Lightning Signed Message:" before signing. See [this description of the format](https://web.archive.org/web/20191010011846/https://twitter.com/rusty_twit/status/1182102005914800128)
938+
/// for more details.
939+
///
940+
/// A receiver knowing the node's id and the message can be sure that the signature was generated by the caller.
941+
/// An `Err` can be returned to signal that the signer is unavailable / cannot produce a valid
942+
/// signature.
943+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()>;
933944
}
934945

935946
/// A trait that describes a wallet capable of creating a spending [`Transaction`] from a set of
@@ -2209,6 +2220,10 @@ impl NodeSigner for KeysManager {
22092220
let msg_hash = hash_to_message!(&Sha256dHash::hash(&msg.encode()[..])[..]);
22102221
Ok(self.secp_ctx.sign_ecdsa(&msg_hash, &self.node_secret))
22112222
}
2223+
2224+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()> {
2225+
Ok(crate::util::message_signing::sign(msg, &self.node_secret))
2226+
}
22122227
}
22132228

22142229
impl OutputSpender for KeysManager {
@@ -2374,6 +2389,10 @@ impl NodeSigner for PhantomKeysManager {
23742389
fn sign_gossip_message(&self, msg: UnsignedGossipMessage) -> Result<Signature, ()> {
23752390
self.inner.sign_gossip_message(msg)
23762391
}
2392+
2393+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()> {
2394+
self.inner.sign_message(msg)
2395+
}
23772396
}
23782397

23792398
impl OutputSpender for PhantomKeysManager {

lightning/src/util/dyn_signer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ delegate!(DynKeysInterface, NodeSigner,
211211
inner,
212212
fn get_node_id(, recipient: Recipient) -> Result<PublicKey, ()>,
213213
fn sign_gossip_message(, msg: UnsignedGossipMessage) -> Result<Signature, ()>,
214+
fn sign_message(, msg: &[u8]) -> Result<String, ()>,
214215
fn ecdh(, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()>,
215216
fn sign_invoice(, invoice: &RawBolt11Invoice, recipient: Recipient) -> Result<RecoverableSignature, ()>,
216217
fn sign_bolt12_invoice(,
@@ -278,6 +279,7 @@ delegate!(DynPhantomKeysInterface, NodeSigner,
278279
inner,
279280
fn get_node_id(, recipient: Recipient) -> Result<PublicKey, ()>,
280281
fn sign_gossip_message(, msg: UnsignedGossipMessage) -> Result<Signature, ()>,
282+
fn sign_message(, msg: &[u8]) -> Result<String, ()>,
281283
fn ecdh(, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()>,
282284
fn sign_invoice(, invoice: &RawBolt11Invoice, recipient: Recipient) -> Result<RecoverableSignature, ()>,
283285
fn sign_bolt12_invoice(, invoice: &crate::offers::invoice::UnsignedBolt12Invoice

lightning/src/util/test_utils.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,10 @@ impl NodeSigner for TestNodeSigner {
15691569
fn sign_gossip_message(&self, _msg: msgs::UnsignedGossipMessage) -> Result<Signature, ()> {
15701570
unreachable!()
15711571
}
1572+
1573+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()> {
1574+
Ok(crate::util::message_signing::sign(msg, &self.node_secret))
1575+
}
15721576
}
15731577

15741578
pub struct TestKeysInterface {
@@ -1631,6 +1635,10 @@ impl NodeSigner for TestKeysInterface {
16311635
fn sign_gossip_message(&self, msg: msgs::UnsignedGossipMessage) -> Result<Signature, ()> {
16321636
self.backing.sign_gossip_message(msg)
16331637
}
1638+
1639+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()> {
1640+
self.backing.sign_message(msg)
1641+
}
16341642
}
16351643

16361644
impl SignerProvider for TestKeysInterface {

0 commit comments

Comments
 (0)