Table of Contents

Class SecureKeyManager

Namespace
NLightning.Infrastructure.Bitcoin.Managers
Assembly
NLightning.Infrastructure.Bitcoin.dll

Manages a securely stored private key using protected memory allocation. This class ensures that the private key remains inaccessible from regular memory and is securely wiped when no longer needed.

public class SecureKeyManager : ISecureKeyManager, IDisposable
Inheritance
SecureKeyManager
Implements
Inherited Members

Constructors

SecureKeyManager(byte[], BitcoinNetwork, string, uint)

Manages secure key operations for generating and managing cryptographic keys. Provides functionality to safely store, load, and derive secure keys protected in memory.

public SecureKeyManager(byte[] privateKey, BitcoinNetwork network, string filePath, uint heightOfBirth)

Parameters

privateKey byte[]

The private key to be managed.

network BitcoinNetwork

The network associated with the private key.

filePath string

The file path for storing the key data.

heightOfBirth uint

Block Height when the wallet was created

Properties

ChannelKeyPath

public BitcoinKeyPath ChannelKeyPath { get; }

Property Value

BitcoinKeyPath

DepositP2TrKeyPath

public BitcoinKeyPath DepositP2TrKeyPath { get; }

Property Value

BitcoinKeyPath

DepositP2WpkhKeyPath

public BitcoinKeyPath DepositP2WpkhKeyPath { get; }

Property Value

BitcoinKeyPath

HeightOfBirth

public uint HeightOfBirth { get; init; }

Property Value

uint

OutputChangeP2TrDescriptor

public string OutputChangeP2TrDescriptor { get; init; }

Property Value

string

OutputChangeP2WshDescriptor

public string OutputChangeP2WshDescriptor { get; init; }

Property Value

string

OutputChannelDescriptor

public string OutputChannelDescriptor { get; init; }

Property Value

string

OutputDepositP2TrDescriptor

public string OutputDepositP2TrDescriptor { get; init; }

Property Value

string

OutputDepositP2WshDescriptor

public string OutputDepositP2WshDescriptor { get; init; }

Property Value

string

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

~SecureKeyManager()

protected ~SecureKeyManager()

FromFilePath(string, BitcoinNetwork, string)

public static SecureKeyManager FromFilePath(string filePath, BitcoinNetwork expectedNetwork, string password)

Parameters

filePath string
expectedNetwork BitcoinNetwork
password string

Returns

SecureKeyManager

FromMnemonic(string, string, BitcoinNetwork, string?, uint)

public static SecureKeyManager FromMnemonic(string mnemonic, string passphrase, BitcoinNetwork network, string? filePath = null, uint currentHeight = 0)

Parameters

mnemonic string
passphrase string
network BitcoinNetwork
filePath string
currentHeight uint

Returns

SecureKeyManager

GetChannelKeyAtIndex(uint)

public ExtPrivKey GetChannelKeyAtIndex(uint index)

Parameters

index uint

Returns

ExtPrivKey

GetDepositP2TrKeyAtIndex(uint, bool)

public ExtPrivKey GetDepositP2TrKeyAtIndex(uint index, bool isChange)

Parameters

index uint
isChange bool

Returns

ExtPrivKey

GetDepositP2WpkhKeyAtIndex(uint, bool)

public ExtPrivKey GetDepositP2WpkhKeyAtIndex(uint index, bool isChange)

Parameters

index uint
isChange bool

Returns

ExtPrivKey

GetKeyFilePath(string)

Gets the path for the Key file

public static string GetKeyFilePath(string configPath)

Parameters

configPath string

Returns

string

GetNextChannelKey(out uint)

public ExtPrivKey GetNextChannelKey(out uint index)

Parameters

index uint

Returns

ExtPrivKey

GetNodeKeyPair()

public CryptoKeyPair GetNodeKeyPair()

Returns

CryptoKeyPair

GetNodePubKey()

public CompactPubKey GetNodePubKey()

Returns

CompactPubKey

SaveToFile(string)

public void SaveToFile(string password)

Parameters

password string

UpdateLastUsedChannelIndexOnFile()

public Task UpdateLastUsedChannelIndexOnFile()

Returns

Task