closes #142 feat(wallet): improve wallet import validation and safe error handling#236
Merged
El-swaggerito merged 5 commits intoJul 23, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Wallet import flows previously failed unclearly when malformed, empty, non-string, or unsupported secret key values were provided.
This PR improves secret key validation across the SDK to reject invalid inputs cleanly with structured, typed errors (
PocketPayErrorwith codeINVALID_SECRET_KEY) while guaranteeing sensitive key material is redacted and never leaked into error messages, error properties, logs, or stack traces.Key Changes
1. Robust Secret Key Validation (
src/utils/index.ts)validateSecretKey(secretKey: unknown)with explicit preflight checks:PocketPayErrorwithreason: 'not_a_string'.PocketPayErrorwithreason: 'missing'.'S'throwPocketPayErrorwithreason: 'invalid_prefix'.PocketPayErrorwithreason: 'invalid_length'.PocketPayErrorwithreason: 'invalid_format'.validation.valueis omitted for secret key errors so raw secret values are never exposed in error objects, logs, or serialized output.2. Safe & Enhanced Import Helpers (
src/wallet/index.ts&src/index.ts)importWalletandgetPublicKeyto trim keys and safely wrap keypair derivation errors intoPocketPayError.safeImportWallet(secretKey)— returnsPocketPayResult<WalletKeypair>enhancedImportWallet(secretKey)— returnsEnhancedPocketPayResult<WalletKeypair>withaction: 'check_input'recovery hintssafeEnhancedImportWallet(secretKey)— non-throwing enriched result wrapper3. Comprehensive Unit Tests (
tests/wallet.test.ts)null,undefined, numbers, objects, arrays).G...).S1234567890).S+ 55 zeros).safeImportWallet,enhancedImportWallet, andsafeEnhancedImportWallet..message,.validation, or JSON serialization.4. Documentation Updates
docs/wallet-import-safety.md: Updated with validation rules, error reasons, redaction policies, and safe import wrapper usage.docs/error-handling.md: Updated enhanced operations table and recovery hints forimportWallet.docs/api-reference.md: Added Wallet Import API reference section forimportWallet,safeImportWallet,enhancedImportWallet, andsafeEnhancedImportWallet.Acceptance Criteria Checklist
not_a_string,missing,invalid_prefix,invalid_length,invalid_format).