Commit 0b17dbd
committed
Fix: replace string manipulation with stronger Bitcoin types in Caravan export
This commit addresses @ValuedMammal feedback by replacing extensive string
manipulation with proper Bitcoin types throughout the Caravan wallet export
functionality, making the code more type-safe and less error-prone.
Key Changes:
- Type-safe BIP32 handling: Updated CaravanExtendedPublicKey to use
bitcoin::bip32::{DerivationPath, Fingerprint, Xpub} instead of strings.
Added custom serde implementation that properly handles "m/" prefix for
JSON compatibility while using proper types internally.
- Enhanced descriptor parsing: Changed extract_xpubs_from_multi() to
accept SortedMultiVec<DescriptorPublicKey, Ctx> instead of
SortedMultiVec<String, Ctx>, eliminating string parsing errors and
making the code more robust.
- Enum-based address types: Replaced string-based address type handling
with CaravanAddressType enum (P2SH, P2WSH, P2SHWrappedP2WSH) for better
type safety and validation.
- Proper descriptor construction: Updated to_descriptors() to use
Descriptor::new_sh_sortedmulti(), new_wsh_sortedmulti(), and
new_sh_wsh_sortedmulti() construction methods instead of string building,
ensuring standard format with checksums.
- Network type conversion: Replaced string-based network handling with
CaravanNetwork enum and From<bitcoin::Network> implementation using
NetworkKind pattern.
- Comprehensive validation: Enhanced test suite to verify that exported
descriptors can create functional BDK wallets with proper address
generation, ensuring practical usability.1 parent 9f86668 commit 0b17dbd
1 file changed
+328
-156
lines changed
0 commit comments