Loading...
Loading...
Utilizes NBitcoin for HD wallet operations (BIP32/39/44). Use when: Creating wallets, deriving keys from mnemonics, working with BIP44 derivation paths, or implementing hierarchical deterministic wallet features.
npx skill4agent add stuartf303/sorcha nbitcoinSorcha.Wallet.CoreMnemonicDerivationPathSorcha.Cryptography// src/Common/Sorcha.Wallet.Core/Domain/ValueObjects/Mnemonic.cs
var mnemonic = Mnemonic.Generate(12); // or 24 for higher security
// NEVER log mnemonic.Phrase - use mnemonic.ToString() which returns "Mnemonic(12 words)"// src/Common/Sorcha.Wallet.Core/Services/Implementation/KeyManagementService.cs:62-111
var masterKey = await _keyManagement.DeriveMasterKeyAsync(mnemonic, passphrase);
var path = DerivationPath.CreateBip44(coinType: 0, account: 0, change: 0, addressIndex: 0);
var (privateKey, publicKey) = await _keyManagement.DeriveKeyAtPathAsync(masterKey, path, "ED25519");if (Mnemonic.IsValid(userProvidedPhrase))
{
var mnemonic = new Mnemonic(userProvidedPhrase);
}| Concept | Usage | Example |
|---|---|---|
| Wraps | |
| Wraps | |
| Extended private key | |
| System Paths | Sorcha-specific aliases | |
| Gap Limit | BIP44: max 20 unused addresses | Enforced in |
// 1. Generate mnemonic (NEVER store on server)
var mnemonic = Mnemonic.Generate(12);
// 2. Derive master key with optional passphrase
var masterKey = await _keyManagement.DeriveMasterKeyAsync(mnemonic, passphrase);
// 3. Derive first key at m/44'/0'/0'/0/0
var path = DerivationPath.CreateBip44(0, 0, 0, 0);
var (privateKey, publicKey) = await _keyManagement.DeriveKeyAtPathAsync(masterKey, path, algorithm);
// 4. Encrypt private key before storage
var (encryptedKey, keyId) = await _keyManagement.EncryptPrivateKeyAsync(privateKey, string.Empty);// src/Common/Sorcha.Wallet.Core/Constants/SorchaDerivationPaths.cs
var resolvedPath = SorchaDerivationPaths.IsSystemPath(derivationPath)
? SorchaDerivationPaths.ResolvePath(derivationPath) // "sorcha:register-attestation" → "m/44'/0'/0'/0/100"
: derivationPath;Fetch latest NBitcoin documentation with Context7.
mcp__context7__resolve-library-idmcp__context7__query-docs/metacosa/nbitcoin