Skip to content

Commit f2dbaf5

Browse files
committed
f - remove signature from offer
1 parent 0f55050 commit f2dbaf5

File tree

1 file changed

+3
-56
lines changed

1 file changed

+3
-56
lines changed

lightning/src/offers/offer.rs

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use bitcoin::blockdata::constants::genesis_block;
1313
use bitcoin::hash_types::BlockHash;
1414
use bitcoin::hashes::{Hash, sha256};
1515
use bitcoin::network::constants::Network;
16-
use bitcoin::secp256k1::{Message, PublicKey, Secp256k1, self};
16+
use bitcoin::secp256k1::PublicKey;
1717
use core::num::NonZeroU64;
1818
use core::ops::{Bound, RangeBounds};
1919
use core::time::Duration;
@@ -50,7 +50,7 @@ impl OfferBuilder {
5050
let offer = Offer {
5151
id, chains: None, metadata: None, amount: None, description, features: None,
5252
absolute_expiry: None, issuer: None, paths, quantity_min: None, quantity_max: None,
53-
node_id, send_invoice: None, signature: None,
53+
node_id, send_invoice: None,
5454
};
5555
OfferBuilder { offer }
5656
}
@@ -157,13 +157,6 @@ impl OfferBuilder {
157157
self.offer.id = merkle::root_hash(&self.offer.to_bytes());
158158
self.offer
159159
}
160-
161-
///
162-
pub fn build_signed<F>(self, sign: F) -> Result<Offer, secp256k1::Error>
163-
where F: FnOnce(&Message) -> Signature
164-
{
165-
self.build().sign(sign)
166-
}
167160
}
168161

169162
///
@@ -263,29 +256,6 @@ impl Offer {
263256
self.send_invoice.as_ref()
264257
}
265258

266-
fn sign<F>(mut self, sign: F) -> Result<Self, secp256k1::Error>
267-
where F: FnOnce(&Message) -> Signature
268-
{
269-
let digest = self.to_message_digest();
270-
let signature = sign(&digest);
271-
272-
let secp_ctx = Secp256k1::verification_only();
273-
let pubkey = self.node_id();
274-
secp_ctx.verify_schnorr(&signature, &digest, &pubkey.into())?;
275-
276-
self.signature = Some(signature);
277-
Ok(self)
278-
}
279-
280-
fn to_message_digest(&self) -> Message {
281-
Self::message_digest(self.id)
282-
}
283-
284-
fn message_digest(offer_id: sha256::Hash) -> Message {
285-
let tag = sha256::Hash::hash(concat!("lightning", "offer", "signature").as_bytes());
286-
Message::from_slice(&merkle::tagged_hash(tag, offer_id)).unwrap()
287-
}
288-
289259
fn to_bytes(&self) -> Vec<u8> {
290260
use util::ser::Writeable;
291261
let mut buffer = Vec::new();
@@ -316,7 +286,6 @@ impl Offer {
316286
quantity_max: self.quantity_max.map(Into::into),
317287
node_id: self.node_id.as_ref(),
318288
send_invoice: self.send_invoice.as_ref().map(|_| &()),
319-
signature: self.signature.as_ref(),
320289
}
321290
}
322291
}
@@ -360,7 +329,6 @@ tlv_stream!(struct OfferTlvStream {
360329
(22, quantity_max: u64),
361330
(24, node_id: PublicKey),
362331
(26, send_invoice: Empty),
363-
(240, signature: Signature),
364332
});
365333

366334
#[derive(Clone, Debug, PartialEq)]
@@ -387,7 +355,7 @@ mod tests {
387355

388356
use bitcoin::blockdata::constants::genesis_block;
389357
use bitcoin::network::constants::Network;
390-
use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
358+
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
391359
use core::num::NonZeroU64;
392360
use core::time::Duration;
393361
use ln::features::OfferFeatures;
@@ -429,7 +397,6 @@ mod tests {
429397
assert_eq!(offer.quantity_max(), 1);
430398
assert_eq!(offer.node_id(), pubkey());
431399
assert_eq!(offer.send_invoice(), None);
432-
assert_eq!(offer.signature(), None);
433400

434401
assert_eq!(tlv_stream.chains, None);
435402
assert_eq!(tlv_stream.metadata, None);
@@ -444,26 +411,6 @@ mod tests {
444411
assert_eq!(tlv_stream.quantity_max, None);
445412
assert_eq!(tlv_stream.node_id, Some(&pubkey()));
446413
assert_eq!(tlv_stream.send_invoice, None);
447-
assert_eq!(tlv_stream.signature, None);
448-
}
449-
450-
#[test]
451-
fn builds_signed_offer() {
452-
let secp_ctx = Secp256k1::new();
453-
let keys = KeyPair::from_secret_key(&secp_ctx, &privkey());
454-
let pubkey = PublicKey::from(keys);
455-
456-
let offer = OfferBuilder::new("foo".into(), Destination::NodeId(pubkey))
457-
.build_signed(|digest| secp_ctx.sign_schnorr_no_aux_rand(digest, &keys))
458-
.unwrap();
459-
assert!(offer.signature().is_some());
460-
461-
let wrong_keys = KeyPair::from_secret_key(&secp_ctx, &blinded_privkey(99));
462-
assert!(
463-
OfferBuilder::new("foo".into(), Destination::NodeId(pubkey))
464-
.build_signed(|digest| secp_ctx.sign_schnorr_no_aux_rand(digest, &wrong_keys))
465-
.is_err()
466-
);
467414
}
468415

469416
#[test]

0 commit comments

Comments
 (0)