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)

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)

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.

Properties

KeyPath

public BitcoinKeyPath KeyPath { get; }

Property Value

BitcoinKeyPath

OutputDescriptor

public string OutputDescriptor { 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?)

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

Parameters

mnemonic string
passphrase string
network BitcoinNetwork
filePath string

Returns

SecureKeyManager

GetKeyAtIndex(uint)

public ExtPrivKey GetKeyAtIndex(uint index)

Parameters

index uint

Returns

ExtPrivKey

GetKeyFilePath(string)

Gets the path for the Key file

public static string GetKeyFilePath(string network)

Parameters

network string

Returns

string

GetNextKey(out uint)

public ExtPrivKey GetNextKey(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

UpdateLastUsedIndexOnFile()

public Task UpdateLastUsedIndexOnFile()

Returns

Task