Skip to content

Commit 73b5b56

Browse files
aaraniknocte
authored andcommitted
Secret inside TLVPayload is PaymentSecret
Secret field inside TLVPayload's PaymentData is PaymentSecret and not PaymentPreimage and It's used for mpp.
1 parent 6fe4b9f commit 73b5b56

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/DotNetLightning.Core/Serialization/TLVs.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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
| 8UL ->
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

src/DotNetLightning.Core/Utils/Primitives.fs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff 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

tests/DotNetLightning.Core.Tests/Generators/Msgs.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ let gossipTimestampFilterGen: Gen<GossipTimestampFilterMsg> = gen {
601601

602602
let 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)

0 commit comments

Comments
 (0)