HDWallet
Hierarchical Deterministic (HD) Wallet for Midnight blockchain.
Implements BIP-32 key derivation following Midnight's specific derivation path:
m / 44' / 2400' / account' / role / indexFeatures:
BIP-32 compliant key derivation using BitcoinJ
Midnight-specific derivation paths (coin type 2400)
Support for multiple accounts and roles
Secure key management with hierarchical memory wiping
Usage:
// Create HD wallet from BIP-39 seed
val seed = BIP39.mnemonicToSeed(mnemonic)
try {
val wallet = HDWallet.fromSeed(seed)
try {
// Derive key at path: m/44'/2400'/0'/0/0
val key = wallet
.selectAccount(0)
.selectRole(MidnightKeyRole.NIGHT_EXTERNAL)
.deriveKeyAt(0)
// Use key...
} finally {
// Always clear wallet when done
wallet.clear()
}
} finally {
// Always wipe seed from memory
Arrays.fill(seed, 0.toByte())
}Security:
ALWAYS call clear when done to wipe keys from memory
ALWAYS wipe the seed array after calling fromSeed
Use try-finally blocks to ensure cleanup even on exceptions
This class tracks ALL derived keys and clears them hierarchically
Thread Safety:
This class is NOT thread-safe
Do not share instances across threads
Create separate instances for concurrent use
References:
BIP-32: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
BIP-44: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
Midnight SDK: https://github.com/midnightntwrk/midnight-wallet