| | | 1 | | namespace NLightning.Domain.Channels.Models; |
| | | 2 | | |
| | | 3 | | using Crypto.Constants; |
| | | 4 | | using Crypto.ValueObjects; |
| | | 5 | | |
| | | 6 | | public class ChannelKeySetModel |
| | | 7 | | { |
| | 144 | 8 | | public uint KeyIndex { get; } |
| | 116 | 9 | | public CompactPubKey FundingCompactPubKey { get; } |
| | 88 | 10 | | public CompactPubKey RevocationCompactBasepoint { get; } |
| | 156 | 11 | | public CompactPubKey PaymentCompactBasepoint { get; } |
| | 88 | 12 | | public CompactPubKey DelayedPaymentCompactBasepoint { get; } |
| | | 13 | | |
| | 88 | 14 | | public CompactPubKey HtlcCompactBasepoint { get; } |
| | 200 | 15 | | public CompactPubKey CurrentPerCommitmentCompactPoint { get; private set; } |
| | 248 | 16 | | public ulong CurrentPerCommitmentIndex { get; private set; } |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// For remote key sets: stores their last revealed per-commitment secret |
| | | 20 | | /// This is needed to create penalty transactions if they broadcast old commitments |
| | | 21 | | /// For local key sets: this should be null (we don't store our own secrets) |
| | | 22 | | /// </summary> |
| | 180 | 23 | | public byte[]? LastRevealedPerCommitmentSecret { get; private set; } |
| | | 24 | | |
| | 180 | 25 | | public ChannelKeySetModel(uint keyIndex, CompactPubKey fundingCompactPubKey, |
| | 180 | 26 | | CompactPubKey revocationCompactBasepoint, CompactPubKey paymentCompactBasepoint, |
| | 180 | 27 | | CompactPubKey delayedPaymentCompactBasepoint, CompactPubKey htlcCompactBasepoint, |
| | 180 | 28 | | CompactPubKey currentPerCommitmentCompactPoint, |
| | 180 | 29 | | ulong currentPerCommitmentIndex = CryptoConstants.FirstPerCommitmentIndex, |
| | 180 | 30 | | byte[]? lastRevealedPerCommitmentSecret = null) |
| | | 31 | | { |
| | 180 | 32 | | KeyIndex = keyIndex; |
| | 180 | 33 | | FundingCompactPubKey = fundingCompactPubKey; |
| | 180 | 34 | | RevocationCompactBasepoint = revocationCompactBasepoint; |
| | 180 | 35 | | PaymentCompactBasepoint = paymentCompactBasepoint; |
| | 180 | 36 | | DelayedPaymentCompactBasepoint = delayedPaymentCompactBasepoint; |
| | 180 | 37 | | HtlcCompactBasepoint = htlcCompactBasepoint; |
| | 180 | 38 | | CurrentPerCommitmentCompactPoint = currentPerCommitmentCompactPoint; |
| | 180 | 39 | | CurrentPerCommitmentIndex = currentPerCommitmentIndex; |
| | 180 | 40 | | LastRevealedPerCommitmentSecret = lastRevealedPerCommitmentSecret; |
| | 180 | 41 | | } |
| | | 42 | | |
| | | 43 | | public void UpdatePerCommitmentPoint(CompactPubKey newPoint) |
| | | 44 | | { |
| | 0 | 45 | | CurrentPerCommitmentCompactPoint = newPoint; |
| | 0 | 46 | | CurrentPerCommitmentIndex--; |
| | 0 | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Store a revealed per-commitment secret from the counterparty |
| | | 51 | | /// This is called when they send a revoke_and_ack message |
| | | 52 | | /// </summary> |
| | | 53 | | public void RevealPerCommitmentSecret(byte[] secret) |
| | | 54 | | { |
| | 0 | 55 | | LastRevealedPerCommitmentSecret = secret; |
| | 0 | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Create a ChannelKeySet for the remote party (we don't generate their keys) |
| | | 60 | | /// </summary> |
| | | 61 | | public static ChannelKeySetModel CreateForRemote(CompactPubKey fundingPubKey, CompactPubKey revocationBasepoint, |
| | | 62 | | CompactPubKey paymentBasepoint, |
| | | 63 | | CompactPubKey delayedPaymentBasepoint, CompactPubKey htlcBasepoint, |
| | | 64 | | CompactPubKey firstPerCommitmentPoint) |
| | | 65 | | { |
| | 0 | 66 | | return new ChannelKeySetModel(0, fundingPubKey, revocationBasepoint, paymentBasepoint, delayedPaymentBasepoint, |
| | 0 | 67 | | htlcBasepoint, firstPerCommitmentPoint); |
| | | 68 | | } |
| | | 69 | | } |