File tree Expand file tree Collapse file tree 3 files changed +31
-4
lines changed
tests/DotNetLightning.Core.Tests/Generators Expand file tree Collapse file tree 3 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -167,7 +167,7 @@ type HopPayloadTLV =
167167 | AmountToForward of LNMoney
168168 | OutgoingCLTV of uint32
169169 | ShortChannelId of ShortChannelId
170- | PaymentData of paymentSecret : PaymentPreimage * totalMsat : LNMoney
170+ | PaymentData of paymentSecret : PaymentSecret * totalMsat : LNMoney
171171 | Unknown of GenericTLV
172172 with
173173 static member FromGenericTLV ( tlv : GenericTLV ) =
@@ -183,8 +183,8 @@ type HopPayloadTLV =
183183 ShortChannelId.From8Bytes tlv.Value
184184 |> ShortChannelId
185185 | 8 UL ->
186- let secret = tlv.Value.[ 0 .. PaymentPreimage .LENGTH - 1 ] |> PaymentPreimage.Create
187- let totalMSat = UInt64.FromTruncatedBytes tlv.Value.[ PaymentPreimage .LENGTH..] |> LNMoney.MilliSatoshis
186+ let secret = tlv.Value.[ 0 .. PaymentSecret .LENGTH - 1 ] |> PaymentSecret.FromByteArray
187+ let totalMSat = UInt64.FromTruncatedBytes tlv.Value.[ PaymentSecret .LENGTH..] |> LNMoney.MilliSatoshis
188188 ( secret, totalMSat) |> PaymentData
189189 | _ -> Unknown tlv
190190
Original file line number Diff line number Diff line change @@ -215,6 +215,33 @@ module Primitives =
215215 member this.ToPubKey () =
216216 this.ToPrivKey() .PubKey
217217
218+ type PaymentSecret =
219+ private PaymentSecret of uint256
220+ with
221+ // as per BOLT-2:
222+ static member LENGTH = 32
223+
224+ static member Create ( secret : uint256 ) =
225+ PaymentSecret secret
226+
227+ static member FromByteArray ( secretBytes : array < byte >) =
228+ uint256( secretBytes, false )
229+ |> PaymentSecret
230+
231+ member this.Value =
232+ let ( PaymentSecret v ) = this in v
233+
234+ member this.ToHex () =
235+ let h = NBitcoin.DataEncoders.HexEncoder()
236+ let ba : byte [] = this.ToByteArray()
237+ ba |> h.EncodeData
238+
239+ member this.ToBytes () =
240+ this.Value.ToBytes( false )
241+
242+ member this.ToByteArray () =
243+ this.Value.ToBytes( false ) |> Array.ofSeq
244+
218245 let (| PaymentPreimage |) x =
219246 match x with
220247 | PaymentPreimage x -> x
Original file line number Diff line number Diff line change @@ -601,7 +601,7 @@ let gossipTimestampFilterGen: Gen<GossipTimestampFilterMsg> = gen {
601601
602602let private hopPayloadTlvGen =
603603 let paymentDataGen : Gen < _ * _ > =
604- (( PaymentPreimage .Create <!> bytesOfNGen ( 32 ) ), ( lnMoneyGen))
604+ (( PaymentSecret .Create <!> uint256Gen ), ( lnMoneyGen))
605605 ||> Gen.map2( fun a b -> ( a, b))
606606 Gen.frequency
607607 [( 1 , AmountToForward <!> lnMoneyGen)
You can’t perform that action at this time.
0 commit comments