feat(identity): add HD wallet support for SeedIdentity#270
feat(identity): add HD wallet support for SeedIdentity#270
Conversation
Introduces SeedIdentity and ReadonlySeedIdentity classes that derive
keys using BIP86 (Taproot) paths. This enables users to transition
to HD wallets while maintaining current single-key behavior.
- SeedIdentity.fromMnemonic() with optional passphrase support
- SeedIdentity.fromSeed() for raw 64-byte seeds
- BIP86 derivation: m/86'/{0|1}'/0'/0/0 (mainnet/testnet)
- Descriptor format: tr([fingerprint/path']xpub.../0/*)
- Strict validation requiring /0/* template for HD compatibility
- JSON serialization with xpub validation on restore
- ReadonlySeedIdentity for watch-only functionality
Add rudimentary HD wallet methods to enable multi-address derivation: SeedIdentity new methods: - deriveSigningDescriptor(index): derive descriptor at specific index - isOurs(descriptor): check if descriptor belongs to this identity - signWithDescriptor(descriptor, requests): batched transaction signing - signMessageWithDescriptor(descriptor, message): message signing at index ReadonlySeedIdentity new methods: - deriveSigningDescriptor(index): derive descriptor at specific index - isOurs(descriptor): check if descriptor belongs to this identity - xOnlyPublicKeyAtIndex(index): get x-only pubkey at index - compressedPublicKeyAtIndex(index): get compressed pubkey at index New types: - SigningRequest: interface for batched signing requests Backwards compatibility maintained - existing methods work at index 0.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
WalkthroughThis PR refactors wallet storage from StorageAdapter to a repository pattern, introduces comprehensive contract management (ContractManager, ContractWatcher, handlers), adds HD wallet support via SeedIdentity, and implements IndexedDB and in-memory repository backends with migration utilities. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ContractManager
participant ContractWatcher
participant IndexerProvider
participant WalletRepository
Client->>ContractManager: create(config)
ContractManager->>WalletRepository: initialize + load persisted contracts
ContractManager->>ContractWatcher: start watching
ContractWatcher->>IndexerProvider: subscribeForScripts(scripts)
IndexerProvider-->>ContractWatcher: subscription established
IndexerProvider-->>ContractWatcher: vtxo_received event
ContractWatcher->>ContractManager: handleVtxoReceived(contract, vtxos)
ContractManager->>WalletRepository: saveContract + VTXO cache
ContractManager-->>Client: emit contractEvent
Client->>ContractManager: getSpendablePaths(options)
ContractManager-->>Client: return PathSelection[]
sequenceDiagram
participant Wallet
participant ServiceWorkerWallet
participant Worker
participant StorageConfig
participant IndexedDBWalletRepository
participant IndexedDBContractRepository
Wallet.create->>ServiceWorkerWallet: create(config with storage)
ServiceWorkerWallet->>StorageConfig: resolve walletRepository
StorageConfig->>IndexedDBWalletRepository: instantiate
ServiceWorkerWallet->>StorageConfig: resolve contractRepository
StorageConfig->>IndexedDBContractRepository: instantiate
ServiceWorkerWallet->>Worker: initialize with repositories
Worker->>IndexedDBWalletRepository: getVtxos, saveVtxos, etc.
Worker->>IndexedDBContractRepository: getContracts, saveContract, etc.
ServiceWorkerWallet-->>Wallet: ready with persistent storage
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Adds rudimentary HD (Hierarchical Deterministic) wallet support to
SeedIdentity, enabling multiple address derivation while maintaining backwards compatibility.New Methods on SeedIdentity
deriveSigningDescriptor(index)- Derive a signing descriptor at a specific indexisOurs(descriptor)- Check if a descriptor belongs to this identitysignWithDescriptor(descriptor, requests[])- Batched transaction signing with descriptor-derived keysignMessageWithDescriptor(descriptor, message, type?)- Message signing at specific indexNew Methods on ReadonlySeedIdentity
deriveSigningDescriptor(index)- Derive a signing descriptor at specific indexisOurs(descriptor)- Check if a descriptor belongs to this identityxOnlyPublicKeyAtIndex(index)- Get x-only public key at specific indexcompressedPublicKeyAtIndex(index)- Get compressed public key at specific indexNew Types
SigningRequest- Interface for batched signing requests with optional input indexesKey Design Decisions
Test plan
deriveSigningDescriptorat various indexesisOurswith own/foreign/invalid descriptorssignWithDescriptorerror handlingsignMessageWithDescriptorwith schnorr/ecdsaSummary by CodeRabbit
Release Notes
New Features
Improvements
Chores
✏️ Tip: You can customize this high-level summary in your review settings.