Add --hex-secret option to exportwallet and importwallet commands #109
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new --hex-secret (short option -x) to both the exportwallet and importwallet subcommands in space-cli, enabling users to work with hex-encoded private keys directly.
Features Added
Export Wallet with Hex Secret (exportwallet -x)
Import Wallet with Hex Secret (importwallet -x)
Technical Implementation
Core Changes
Wallet Export Enhancement (wallet/src/export.rs, wallet/src/lib.rs)
Added hex_secret field to WalletExport struct
Implemented extract_hex_secret() method in SpacesWallet
Modified export_wallet() to conditionally include hex secret
RPC Interface Updates (client/src/rpc.rs)
Updated wallet_export RPC method to accept hex_secret parameter
Added xpriv_from_hex_secret() function for proper hex-to-xprv conversion
Implemented hex-based descriptor generation in wallet creation process
Added remove_checksum() helper function for descriptor formatting
CLI Command Enhancements (client/src/bin/space-cli.rs)
Added --hex-secret / -x options to both export and import commands
Implemented logic to skip descriptor field validation when using hex import
Added proper error handling for hex secret validation
Key Technical Details
Usage Examples
Export with Hex Secret
space-cli exportwallet -x ./wallet.json
Output includes:
Import with Hex Secret
space-cli importwallet -x ./wallet.json
Input JSON (descriptor field optional):
Testing
Files Modified
Breaking Changes
None. This is a purely additive feature that maintains full backward compatibility.
Related Issues
Resolves the need for direct hex private key support in wallet import/export operations, enabling easier integration with external key management systems and tools that work with raw hex-encoded private keys.