| | 1 | | using NBitcoin; |
| | 2 | |
|
| | 3 | | namespace NLightning.Infrastructure.Crypto.Primitives; |
| | 4 | |
|
| | 5 | | /// <summary> |
| | 6 | | /// A secp256k1 private/public key pair. |
| | 7 | | /// </summary> |
| | 8 | | internal sealed class KeyPair : IDisposable |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// Gets the private key. |
| | 12 | | /// </summary> |
| | 13 | | /// <exception cref="ObjectDisposedException"> |
| | 14 | | /// Thrown if the current instance has already been disposed. |
| | 15 | | /// </exception> |
| 428 | 16 | | public Key PrivateKey { get; } |
| | 17 | |
|
| | 18 | | /// <summary> |
| | 19 | | /// Gets the public key. |
| | 20 | | /// </summary> |
| | 21 | | /// <exception cref="ObjectDisposedException"> |
| | 22 | | /// Thrown if the current instance has already been disposed. |
| | 23 | | /// </exception> |
| 300 | 24 | | public PubKey PublicKey { get; } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Gets the public key bytes. |
| | 28 | | /// </summary> |
| | 29 | | /// <exception cref="ObjectDisposedException"> |
| | 30 | | /// Thrown if the current instance has already been disposed. |
| | 31 | | /// </exception> |
| | 32 | | public byte[] PublicKeyBytes |
| | 33 | | { |
| | 34 | | get |
| | 35 | | { |
| 300 | 36 | | return PublicKey.ToBytes(); |
| | 37 | | } |
| | 38 | | } |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// Initializes a new instance of the <see cref="KeyPair"/> class. |
| | 42 | | /// </summary> |
| | 43 | | /// <param name="privateKey" cref="Key">The private key.</param> |
| | 44 | | /// <exception cref="ArgumentNullException"> |
| | 45 | | /// Thrown if the <paramref name="privateKey"/> is null. |
| | 46 | | /// </exception> |
| 172 | 47 | | internal KeyPair(Key privateKey) |
| | 48 | | { |
| 172 | 49 | | PrivateKey = privateKey; |
| 172 | 50 | | PublicKey = privateKey.PubKey; |
| 172 | 51 | | } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Erases the key pair from the memory. |
| | 55 | | /// </summary> |
| | 56 | | public void Dispose() |
| | 57 | | { |
| 236 | 58 | | PrivateKey.Dispose(); |
| 236 | 59 | | } |
| | 60 | | } |