DustKeyDeriver
JNI bridge to Midnight's Rust cryptography for deriving dust keys.
Architecture:
Kotlin (Android) → JNI → Rust FFI → Midnight Ledger (Rust)What is Dust? Dust is Midnight's fee payment mechanism. Night UTXOs can be registered for dust generation, which produces dust tokens over time. These dust tokens are consumed to pay transaction fees.
Dust Key Derivation Path: Dust keys are derived at BIP-44 path: m/44'/2400'/account'/2/index
Role 2 = Dust (defined in MidnightKeyRole.DUST)
Typically index 0 for primary dust key
Native Library: This class loads libkuira_crypto_ffi.so (Android) which is compiled from:
Location:
kuira-crypto-ffi/Dependencies:
midnight-ledger(version-abstract FFI — see Cargo.toml)
Thread Safety: This object is thread-safe. The underlying Rust functions are pure and stateless.
Memory Safety:
The JNI bridge allocates C strings for results
Native memory is freed automatically after copying to Kotlin strings
The seed ByteArray is NOT cleared by this function - caller must wipe it
Usage:
val seed = deriveSeedFromBIP32() // 32 bytes at m/44'/2400'/0'/2/0
try {
val dustPublicKey = DustKeyDeriver.derivePublicKey(seed)
println("Dust PK: ${dustPublicKey}")
} finally {
MemoryUtils.wipe(seed) // CRITICAL: Always wipe seed
}Error Handling:
Returns null if FFI call fails (invalid seed, native library error, etc.)
Logs error details to stderr in the native library
On Android, check Logcat for native error messages
References:
Rust FFI:
kuira-crypto-ffi/src/lib.rsDust Spec:
midnight-libraries/midnight-ledger/spec/dust.md