mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 15:02:20 +01:00
Merge pull request #3549 from lightning-signer/2025-01-invoice-base32
RawBolt11Invoice serialization utilities
This commit is contained in:
commit
39ff6025cd
1 changed files with 20 additions and 3 deletions
|
@ -48,6 +48,7 @@ use core::iter::FilterMap;
|
||||||
use core::num::ParseIntError;
|
use core::num::ParseIntError;
|
||||||
use core::ops::Deref;
|
use core::ops::Deref;
|
||||||
use core::slice::Iter;
|
use core::slice::Iter;
|
||||||
|
use core::str::FromStr;
|
||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
|
@ -78,8 +79,12 @@ use crate::prelude::*;
|
||||||
/// Re-export serialization traits
|
/// Re-export serialization traits
|
||||||
#[cfg(fuzzing)]
|
#[cfg(fuzzing)]
|
||||||
pub use crate::de::FromBase32;
|
pub use crate::de::FromBase32;
|
||||||
|
#[cfg(not(fuzzing))]
|
||||||
|
use crate::de::FromBase32;
|
||||||
#[cfg(fuzzing)]
|
#[cfg(fuzzing)]
|
||||||
pub use crate::ser::Base32Iterable;
|
pub use crate::ser::Base32Iterable;
|
||||||
|
#[cfg(not(fuzzing))]
|
||||||
|
use crate::ser::Base32Iterable;
|
||||||
|
|
||||||
/// Errors that indicate what is wrong with the invoice. They have some granularity for debug
|
/// Errors that indicate what is wrong with the invoice. They have some granularity for debug
|
||||||
/// reasons, but should generally result in an "invalid BOLT11 invoice" message for the user.
|
/// reasons, but should generally result in an "invalid BOLT11 invoice" message for the user.
|
||||||
|
@ -1086,9 +1091,6 @@ impl RawBolt11Invoice {
|
||||||
|
|
||||||
/// Calculate the hash of the encoded `RawBolt11Invoice` which should be signed.
|
/// Calculate the hash of the encoded `RawBolt11Invoice` which should be signed.
|
||||||
pub fn signable_hash(&self) -> [u8; 32] {
|
pub fn signable_hash(&self) -> [u8; 32] {
|
||||||
#[cfg(not(fuzzing))]
|
|
||||||
use crate::ser::Base32Iterable;
|
|
||||||
|
|
||||||
Self::hash_from_parts(self.hrp.to_string().as_bytes(), self.data.fe_iter())
|
Self::hash_from_parts(self.hrp.to_string().as_bytes(), self.data.fe_iter())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1189,6 +1191,21 @@ impl RawBolt11Invoice {
|
||||||
pub fn currency(&self) -> Currency {
|
pub fn currency(&self) -> Currency {
|
||||||
self.hrp.currency.clone()
|
self.hrp.currency.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert to HRP prefix and Fe32 encoded data part.
|
||||||
|
/// Can be used to transmit unsigned invoices for remote signing.
|
||||||
|
pub fn to_raw(&self) -> (String, Vec<Fe32>) {
|
||||||
|
(self.hrp.to_string(), self.data.fe_iter().collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert from HRP prefix and Fe32 encoded data part.
|
||||||
|
/// Can be used to receive unsigned invoices for remote signing.
|
||||||
|
pub fn from_raw(hrp: &str, data: &[Fe32]) -> Result<Self, Bolt11ParseError> {
|
||||||
|
let raw_hrp: RawHrp = RawHrp::from_str(hrp)?;
|
||||||
|
let data_part = RawDataPart::from_base32(data)?;
|
||||||
|
|
||||||
|
Ok(Self { hrp: raw_hrp, data: data_part })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PositiveTimestamp {
|
impl PositiveTimestamp {
|
||||||
|
|
Loading…
Add table
Reference in a new issue