Skip to content

Commit 0137c7c

Browse files
Prefactor -> Introduce sign_message on NodeSigner, to be used by LSPS5/service when signing notifications
1 parent f3811c2 commit 0137c7c

File tree

7 files changed

+41
-0
lines changed

7 files changed

+41
-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
@@ -1643,6 +1643,8 @@ fn route_blinding_spec_test_vector() {
16431643
&self, _invoice: &UnsignedBolt12Invoice,
16441644
) -> Result<schnorr::Signature, ()> { unreachable!() }
16451645
fn sign_gossip_message(&self, _msg: UnsignedGossipMessage) -> Result<Signature, ()> { unreachable!() }
1646+
1647+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()> { Ok(crate::util::message_signing::sign(msg, &self.node_secret)) }
16461648
}
16471649
let logger = test_utils::TestLogger::with_id("".to_owned());
16481650

@@ -1954,6 +1956,7 @@ fn test_trampoline_inbound_payment_decoding() {
19541956
&self, _invoice: &UnsignedBolt12Invoice,
19551957
) -> Result<schnorr::Signature, ()> { unreachable!() }
19561958
fn sign_gossip_message(&self, _msg: UnsignedGossipMessage) -> Result<Signature, ()> { unreachable!() }
1959+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()> { Ok(crate::util::message_signing::sign(msg, &self.node_secret)) }
19571960
}
19581961
let logger = test_utils::TestLogger::with_id("".to_owned());
19591962

lightning/src/sign/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,14 @@ 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.
937+
/// A receiver knowing the node's id and the message can be sure that the signature was generated by the caller.
938+
/// An `Err` can be returned to signal that the signer is unavailable / cannot produce a valid
939+
/// signature.
940+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()>;
933941
}
934942

935943
/// A trait that describes a wallet capable of creating a spending [`Transaction`] from a set of
@@ -2209,6 +2217,10 @@ impl NodeSigner for KeysManager {
22092217
let msg_hash = hash_to_message!(&Sha256dHash::hash(&msg.encode()[..])[..]);
22102218
Ok(self.secp_ctx.sign_ecdsa(&msg_hash, &self.node_secret))
22112219
}
2220+
2221+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()> {
2222+
Ok(crate::util::message_signing::sign(msg, &self.node_secret))
2223+
}
22122224
}
22132225

22142226
impl OutputSpender for KeysManager {
@@ -2374,6 +2386,10 @@ impl NodeSigner for PhantomKeysManager {
23742386
fn sign_gossip_message(&self, msg: UnsignedGossipMessage) -> Result<Signature, ()> {
23752387
self.inner.sign_gossip_message(msg)
23762388
}
2389+
2390+
fn sign_message(&self, msg: &[u8]) -> Result<String, ()> {
2391+
self.inner.sign_message(msg)
2392+
}
23772393
}
23782394

23792395
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)