nbitcoin
Sorcha-Platform/Sorcha/.claude/skills/nbitcoin/SKILL.md
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.
Skill2 starsChanged 8 months ago
What's in it
- NBitcoin Skill
- Quick Start
- Generate a Mnemonic
- Derive Keys at BIP44 Path
- Validate a Mnemonic
- Key Concepts
- Common Patterns
- Wallet Creation Flow
- System Path Resolution
- See Also
- Related Skills
- Documentation Resources
Tools it asks for
- Read
- Edit
- Write
- Glob
- Grep
- Bash
- mcp__context7__resolve-library-id
- mcp__context7__query-docs
---
name: nbitcoin
description: |
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.
allowed-tools: Read, Edit, Write, Glob, Grep, Bash, mcp__context7__resolve-library-id, mcp__context7__query-docs
---
# NBitcoin Skill
NBitcoin provides HD wallet operations in Sorcha through the `Sorcha.Wallet.Core` project. The codebase wraps NBitcoin types in domain value objects (`Mnemonic`, `DerivationPath`) and uses them exclusively for BIP32/39/44 key derivation—NOT for transaction building. Actual signing uses `Sorcha.Cryptography` (ED25519, P-256, RSA-4096).
## Quick Start
### Generate a Mnemonic
```csharp
// src/Core/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)"
```
### Derive Keys at BIP44 Path
```csharp
// src/Core/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");
```
### Validate a Mnemonic
```csharp
if (Mnemonic.IsValid(userProvidedPhrase))
{
var mnemonic = new Mnemonic(userProvidedPhrase);
}
```
## Key Concepts
| Concept | Usage | Example |
|---------|-------|---------|
| `Mnemonic` | Wraps `NBitcoin.Mnemonic` | `Mnemonic.Generate(12)` |
| `DerivationPath` | Wraps `NBitcoin.KeyPath` | `DerivationPath.CreateBip44(0, 0, 0, 0)` |
| `ExtKey` | Extended private key | `ExtKey.CreateFromSeed(masterKey)` |
| System Paths | Sorcha-specific aliases | `"sorcha:register-attestation"` → `"m/44'/0'/0'/0/100"` |
| Gap Limit | BIP44: max 20 unused addresses | Enforced in `WalletManager.cs:493-508` |
## Common Patterns
### Wallet Creation Flow
**When:** User creates a new wallet.
```csharp
// 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);
```
### System Path Resolution
**When:** Using Sorcha-specific derivation purposes.
```csharp
// src/Common/Sorcha.Wallet.Contracts/Constants/SorchaDerivationPaths.cs
var resolvedPath = SorchaDerivationPaths.IsSystemPath(derivationPath)
? SorchaDerivationPaths.ResolvePath(derivationPath) // "sorcha:register-attestation" → "m/44'/0'/0'/0/100"
: derivationPath;
```
## See Also
- [patterns](references/patterns.md) - Value objects, key derivation, security patterns
- [workflows](references/workflows.md) - Wallet creation, recovery, address management
## Related Skills
- See the **cryptography** skill for signing operations (ED25519, P-256, RSA-4096)
- See the **dotnet** skill for .NET 10 patterns and DI configuration
- See the **xunit** skill and **fluent-assertions** skill for testing HD wallet operations
## Documentation Resources
> Fetch latest NBitcoin documentation with Context7.
**How to use Context7:**
1. Use `mcp__context7__resolve-library-id` to search for "nbitcoin"
2. Query with `mcp__context7__query-docs` using the resolved library ID
**Library ID:** `/metacosa/nbitcoin`
**Recommended Queries:**
- "NBitcoin BIP32 BIP39 BIP44 key derivation"
- "NBitcoin ExtKey master key child derivation"
- "NBitcoin Mnemonic passphrase seed"More agent context in Sorcha-Platform/Sorcha
79 other files this repository gives its agents, the first 60 shown.
AGENTS.md
CLAUDE.md
Copilot instructions
llms.txt
Skill
- aspire.claude/skills/aspire/SKILL.md
- aspnet-core.claude/skills/aspnet-core/SKILL.md
- blazor.claude/skills/blazor/SKILL.md
- blueprint-builder.claude/skills/blueprint-builder/SKILL.md
- configuring-opentelemetry-dotnet.claude/skills/configuring-opentelemetry-dotnet/SKILL.md
- coverage-analysis.claude/skills/coverage-analysis/SKILL.md
- coverlet.claude/skills/coverlet/SKILL.md
- cryptography.claude/skills/cryptography/SKILL.md
- database-expert.claude/skills/database-expert/SKILL.md
- docker.claude/skills/docker/SKILL.md
- dotnet.claude/skills/dotnet/SKILL.md
- entity-framework-core.claude/skills/entity-framework-core/SKILL.md
- entity-framework.claude/skills/entity-framework/SKILL.md
- fluent-assertions.claude/skills/fluent-assertions/SKILL.md
- frontend-design.claude/skills/frontend-design/SKILL.md
- grpc.claude/skills/grpc/SKILL.md
- jwt.claude/skills/jwt/SKILL.md
- mcp.claude/skills/mcp/SKILL.md
- microsoft-extensions.claude/skills/microsoft-extensions/SKILL.md
- migrate-xunit-to-xunit-v3.claude/skills/migrate-xunit-to-xunit-v3/SKILL.md
- minimal-api-file-upload.claude/skills/minimal-api-file-upload/SKILL.md
- minimal-apis.claude/skills/minimal-apis/SKILL.md
- mongodb.claude/skills/mongodb/SKILL.md
- moq.claude/skills/moq/SKILL.md
- network-bootstrap.claude/skills/network-bootstrap/SKILL.md
- nunit.claude/skills/nunit/SKILL.md
- optimizing-ef-core-queries.claude/skills/optimizing-ef-core-queries/SKILL.md
- playwright.claude/skills/playwright/SKILL.md
- postgresql.claude/skills/postgresql/SKILL.md
- prodexec.claude/skills/prodexec/SKILL.md
- redis.claude/skills/redis/SKILL.md
- scalar.claude/skills/scalar/SKILL.md
- signalr.claude/skills/signalr/SKILL.md
- sorcha-app.claude/skills/sorcha-app/SKILL.md
- sorcha-architecture.claude/skills/sorcha-architecture/SKILL.md
- sorcha-cli.claude/skills/sorcha-cli/SKILL.md
- sorcha-ui.claude/skills/sorcha-ui/SKILL.md
- speckit-agent-context-update.claude/skills/speckit-agent-context-update/SKILL.md
- speckit-analyze.claude/skills/speckit-analyze/SKILL.md
- speckit-checklist.claude/skills/speckit-checklist/SKILL.md
- speckit-clarify.claude/skills/speckit-clarify/SKILL.md
- speckit-constitution.claude/skills/speckit-constitution/SKILL.md
- speckit-git-commit.claude/skills/speckit-git-commit/SKILL.md
- speckit-git-feature.claude/skills/speckit-git-feature/SKILL.md
- speckit-git-initialize.claude/skills/speckit-git-initialize/SKILL.md
- speckit-git-remote.claude/skills/speckit-git-remote/SKILL.md
- speckit-git-validate.claude/skills/speckit-git-validate/SKILL.md
- speckit-implement.claude/skills/speckit-implement/SKILL.md
- speckit-plan.claude/skills/speckit-plan/SKILL.md
- speckit-specify.claude/skills/speckit-specify/SKILL.md
- speckit-tasks.claude/skills/speckit-tasks/SKILL.md
- speckit-taskstoissues.claude/skills/speckit-taskstoissues/SKILL.md
- verifiable-credentials.claude/skills/verifiable-credentials/SKILL.md
- walkthrough-builder.claude/skills/walkthrough-builder/SKILL.md
- worker-services.claude/skills/worker-services/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
Reports can't be read right now.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool public_context_discussion, action report. How to connect one.

