LNP: Hash types improvements
@@ -303,6 +303,13 @@ impl DumbDefault for TempChannelId {
#[wrapper(FromStr, LowerHex, UpperHex)]
pub struct PaymentHash(Slice32);
+impl From<PaymentPreimage> for PaymentHash {
+ fn from(preimage: PaymentPreimage) -> Self {
+ let hash = sha256::Hash::hash(preimage.as_ref());
+ Self::from_inner(Slice32::from_inner(hash.into_inner()))
+ }
+}
+
impl FromHex for PaymentHash {
fn from_byte_iter<I>(iter: I) -> Result<Self, Error>
where
@@ -365,6 +372,18 @@ impl FromHex for PaymentPreimage {
}
}
+impl DumbDefault for PaymentPreimage {
+ fn dumb_default() -> Self {
+ Self(Default::default())
+ }
+}
+
+impl AsRef<[u8]> for PaymentPreimage {
+ fn as_ref(&self) -> &[u8] {
+ self.as_inner().as_ref()
+ }
+}
+
/// Payment secret use to authenticate sender to the receiver and tie MPP HTLCs
/// together
#[cfg_attr(feature = "serde", serde_as(as = "DisplayFromStr"))]
@@ -626,3 +645,14 @@ pub struct OnionPacket {
pub hop_data: Vec<u8>, //[u8; 20 * 65],
pub hmac: Hmac<sha256::Hash>,
}
+
+impl DumbDefault for OnionPacket {
+ fn dumb_default() -> Self {
+ OnionPacket {
+ version: 0,
+ public_key: *SECP256K1_PUBKEY_DUMB,
+ hop_data: empty!(),
+ hmac: zero!(),
+ }
+ }
+}
