Skip to content

Commit 05dd6a1

Browse files
committed
Offer a version of hash_from_parts with data as iterator
1 parent a9786b1 commit 05dd6a1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lightning-invoice/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use bitcoin::secp256k1::PublicKey;
4343
use bitcoin::secp256k1::{Message, Secp256k1};
4444
use bitcoin::secp256k1::ecdsa::RecoverableSignature;
4545

46+
use alloc::boxed::Box;
4647
use core::cmp::Ordering;
4748
use core::fmt::{Display, Formatter, self};
4849
use core::iter::FilterMap;
@@ -999,6 +1000,12 @@ macro_rules! find_all_extract {
9991000

10001001
#[allow(missing_docs)]
10011002
impl RawBolt11Invoice {
1003+
/// Hash the HRP (as bytes) and signatureless data part (as Fe32 iterator)
1004+
fn hash_from_parts_iter<'s>(hrp_bytes: &[u8], data_without_signature_iter: Box<dyn Iterator<Item = Fe32> + 's>) -> [u8; 32] {
1005+
let data_part_signature = data_without_signature_iter.collect::<Vec<Fe32>>();
1006+
Self::hash_from_parts(hrp_bytes, &data_part_signature[..])
1007+
}
1008+
10021009
/// Hash the HRP as bytes and signatureless data part.
10031010
fn hash_from_parts(hrp_bytes: &[u8], data_without_signature: &[Fe32]) -> [u8; 32] {
10041011
use crate::de::FromBase32;
@@ -1029,9 +1036,9 @@ impl RawBolt11Invoice {
10291036
pub fn signable_hash(&self) -> [u8; 32] {
10301037
use crate::ser::Base32Iterable;
10311038

1032-
RawBolt11Invoice::hash_from_parts(
1039+
RawBolt11Invoice::hash_from_parts_iter(
10331040
self.hrp.to_string().as_bytes(),
1034-
&self.data.fe_iter().collect::<Vec<Fe32>>(),
1041+
self.data.fe_iter(),
10351042
)
10361043
}
10371044

0 commit comments

Comments
 (0)