Skip to content

Spark Wallet Integration - Pull Request#40

Draft
dmnyc wants to merge 34 commits intoYakiHonne:mainfrom
dmnyc:feat/spark-wallet-integration
Draft

Spark Wallet Integration - Pull Request#40
dmnyc wants to merge 34 commits intoYakiHonne:mainfrom
dmnyc:feat/spark-wallet-integration

Conversation

@dmnyc
Copy link
Contributor

@dmnyc dmnyc commented Dec 14, 2025

Overview

This PR introduces a complete integration of Breez SDK Spark into YakiHonne, providing users with a self-custodial Lightning wallet option alongside the existing custodial NWC wallet. The integration enables seamless Bitcoin Lightning payments directly within the YakiHonne platform with full privacy mode support.

Branch: feat/spark-wallet-integration
Base: upstream/main
Changes: 45 files changed, 25,120 insertions(+), 332 deletions(-)
Commits: 26


Key Features

✅ Core Wallet Functionality

  • Self-Custodial Lightning Wallet - Full control of funds via Breez SDK 0.5.2
  • Privacy Mode - SDK configured for enhanced privacy with minimal metadata sharing
  • Seed Phrase Management - BIP39 mnemonic generation and secure recovery
  • Multiple Wallet Support - Works alongside existing YakiHonne NWC wallet
  • Auto-Connect - Automatic wallet restoration on app load for seamless UX

✅ Wallet Operations (SparkWalletManager with 4 Tabs)

  • Send Tab

    • Lightning invoices (bolt11)
    • LNURL-pay support
    • Lightning addresses
    • Zero-amount invoice support with custom amounts
    • Integrated into existing PaymentGateway for zaps
  • Receive Tab

    • Generate Lightning invoices with custom amounts
    • Optional description field
    • QR code generation (256x256, white background)
    • Copy invoice to clipboard
    • Two-step flow (form → invoice display)
  • Transactions Tab

    • Full payment history with SparkPaymentsList component
    • Expandable transaction details
    • Copy payment hash, preimage, invoice
    • Load more pagination (20 per page)
    • Manual refresh
  • Settings Tab

    • Lightning address management (username@breez.tips)
    • Real-time username availability checking
    • Download encrypted backup file
    • View/copy seed phrase (with confirmation)
    • Delete wallet (danger zone)
  • Balance Display Widget

    • Compact and full display modes
    • Show/hide privacy toggle
    • Optional USD conversion (CoinGecko API)
    • Real-time balance updates
    • Click to open wallet manager

✅ Backup & Recovery

  • Downloadable Encrypted Backups (Current Implementation)

    • Download encrypted backup file (.json)
    • Includes encrypted mnemonic and wallet metadata
    • Restore from file upload (drag-and-drop supported)
    • File stored locally on user's device
    • Matches YakiHonne UX philosophy of user-controlled backups
  • Seed Phrase Access

    • View and copy 12-word BIP39 recovery phrase
    • Protected behind confirmation dialog in Settings tab
    • Direct mnemonic access for manual paper backup
    • One-time display during wallet creation
  • Wallet Restoration Methods

    • From seed phrase - Manual entry of 12/24 BIP39 words
    • From file upload - Restore from encrypted .json backup file
    • Non-blocking sync during restoration
    • Full-screen progress overlay with status messages
    • Automatic wallet reconnection on app reload

Note on Nostr Relay Backup: The codebase includes infrastructure for optional Nostr-based backups (NIP-78 encrypted storage), but this feature is intentionally disabled in the current build to maintain YakiHonne's UX principle of downloadable, user-controlled backups. This could be enabled as a future enhancement if desired.

✅ Payment History

  • Comprehensive Transaction List

    • All incoming and outgoing payments
    • Payment status indicators (pending, complete, failed)
    • Timestamps with relative time display
    • Payment descriptions and memos
    • Payment IDs with copy-to-clipboard
  • Payment Details

    • Amount in sats
    • Transaction fees
    • Payment hash
    • Preimage (for completed payments)
    • Invoice details

✅ Zap Integration

  • Nostr Zap Receipts

    • Automatic zap receipt publishing to Nostr
    • Profile synchronization for zap metadata
    • Integration with existing zap flow
  • Payment Gateway Integration

    • Unified payment interface
    • Spark wallet option in zap modal
    • Seamless switching between wallet types

✅ User Experience

  • Onboarding Flow

    • Create new wallet option during signup
    • Restore existing wallet option
    • Clear wallet type selection (self-custodial vs custodial)
    • Spark wallet prioritized in UI (listed first)
  • Wallet Setup (3 Methods)

    • Create New Wallet - Generate BIP39 mnemonic with downloadable backup file
    • Restore from File - Upload encrypted backup file (.json/.txt with drag-and-drop)
    • Enter Seed Phrase - Manual 12/24-word BIP39 mnemonic entry
    • Lightning address configuration
    • Step-by-step guided flow with clear instructions
  • Full-Screen Loading States

    • Wallet restoration progress overlay
    • Clear status messages
    • Non-blocking background operations

✅ WASM & Deployment

  • Vercel Compatibility

    • Custom webpack configuration for WASM modules
    • Next.js 15.5.9 with Turbopack support
    • Proper WASM initialization and loading
    • Error handling for initialization failures
  • Security

    • Next.js 15.5.9 (patches CVE-2025-66478)
    • Secure key storage in IndexedDB
    • Encrypted backup storage

Technical Implementation

New Dependencies

"@breeztech/breez-sdk-spark": "^0.5.2"

Architecture

Service Layer (src/Helpers/Spark/)

  • spark.service.js - Core SDK wrapper and connection management
  • spark-wallet-manager.js - High-level wallet operations coordinator
  • spark-backup.service.js - Backup and restore functionality
  • spark-storage.service.js - Persistent storage (IndexedDB)
  • spark-zap-receipt.service.js - Nostr zap receipt publishing
  • spark-profile-sync.service.js - Profile data synchronization

UI Components (src/Components/Spark/)

  • SparkWalletSetup.js - Complete onboarding wizard with 4 setup methods
  • SparkWalletManager.js - Main wallet interface with Send/Receive/Transactions/Settings tabs
  • SparkPaymentsList.js - Transaction history with expandable payment details
  • SparkBalanceDisplay.js - Balance widget with compact/full modes and USD conversion

State Management (src/Store/)

  • SparkWallet.js - Redux slice for Spark wallet state
  • Integration with existing wallet state in Store.js

Styling

  • src/styles/spark-wallet.css - Complete UI styling (593 lines)
  • Responsive design for mobile and desktop
  • Consistent with YakiHonne design system

Key Technical Decisions

  1. Non-Blocking Sync - Initial wallet sync runs in background to prevent UI freezing
  2. Error Suppression - Harmless SDK disconnect errors suppressed for better UX
  3. Privacy Mode Default - SDK configured for privacy by default
  4. WASM Configuration - Custom webpack config for Vercel deployment
  5. Auto-Connect Pattern - Wallet automatically reconnects on app load

Modified Core Files

  • src/(PagesComponents)/Login.js - Added Spark wallet to onboarding
  • src/Components/AddWallet.js - Added Spark wallet option
  • src/Components/PaymentGateway.js - Integrated Spark into payment flow
  • src/Components/UserBalance.js - Added Spark balance display
  • src/Helpers/DB.js - Added Spark wallet storage tables
  • src/Helpers/Controlers.js - Added Spark controller methods
  • src/Store/Store.js - Added SparkWallet slice
  • next.config.js - WASM webpack configuration
  • package.json - Breez SDK dependency

Documentation

New Documentation Files

  • SPARK_WALLET_INTEGRATION.md - Complete integration guide
  • DEV_NOTES.md - Updated with Spark wallet details
  • SPARK_ARCHITECTURE.md - Technical architecture documentation
  • CHANGELOG.md - Updated with all Spark wallet changes

Changelog Highlights

2025-12-13: Spark Wallet v0.5.2 Integration

  • Upgraded to Breez SDK 0.5.2 with privacy mode
  • Fixed WASM runtime initialization on Vercel
  • Implemented non-blocking sync for better UX
  • Added comprehensive error suppression
  • UI improvements and wallet reordering
  • Security updates (Next.js 15.5.9)

Testing

Tested Scenarios

✅ New wallet creation
✅ Wallet restoration from seed phrase
✅ Sending Lightning payments (bolt11, LNURL, Lightning address)
✅ Receiving Lightning payments
✅ Balance synchronization
✅ Backup and restore functionality
✅ Payment history display
✅ Zap receipt publishing
✅ Auto-connect on app reload
✅ Vercel deployment
✅ WASM module loading
✅ Error handling and recovery

Known Working Environments

  • Development: ✅ Next.js dev server with Turbopack
  • Production: ✅ Vercel deployment
  • Browsers: ✅ Chrome, Firefox, Safari (latest versions)
  • Mobile: ✅ iOS Safari, Chrome Mobile

Work In Progress / Future Enhancements

The following features are planned for future iterations:

🚧 Payment Profile Display

Current State: Payment history shows transaction details without sender/recipient information

Planned Enhancement:

  • Display Nostr profile pictures for zap senders in payment history
  • Show display names instead of payment hashes when available
  • Pull profile metadata from Nostr events
  • Cache profile data for performance

Technical Approach:

  • Parse zap receipt events for sender pubkey
  • Fetch profile metadata using NDK
  • Display profile pictures using existing UserProfilePic component
  • Add profile name display with fallback to payment ID

Files to Modify:

  • src/Components/Spark/SparkPaymentsList.js
  • src/Helpers/Spark/spark-zap-receipt.service.js

🚧 Additional Planned Features

  • Nostr Relay Backup (Infrastructure exists, feature disabled)

    • Enable NIP-78 encrypted backup to Nostr relays
    • Multi-device wallet sync option
    • One simple flag to enable: createWallet(true) instead of createWallet(false)
  • Channel Management UI - Visual display of Lightning channel states

  • Fee Optimization - Automatic routing optimization for lower fees

  • Payment Filtering - Filter payment history by type, date, amount

  • Export Functionality - Export payment history as CSV/JSON

  • Multi-Currency Display - Show balances in USD, EUR, etc.

  • Advanced Privacy Controls - User-configurable privacy settings

  • Submarine Swaps - On-chain to Lightning swaps via Breez

  • LNURL-withdraw - Support for LNURL withdraw flow


Migration Notes

For Existing Users

  • Existing YakiHonne NWC wallets continue to work unchanged
  • Users can add a Spark wallet alongside their existing wallet
  • No breaking changes to existing wallet functionality
  • Smooth migration path from custodial to self-custodial

For New Users

  • Spark wallet is now the default recommended option during onboarding
  • Listed first in wallet selection UI
  • Clear indication of self-custodial vs custodial options

Security Considerations

What's Protected

✅ Private keys stored in encrypted IndexedDB
✅ Seed phrases never sent over network unencrypted
✅ Nostr backups use NIP-04 self-encryption
✅ Privacy mode enabled by default
✅ No analytics or tracking of wallet operations

User Responsibilities

⚠️ Users must backup their seed phrase (12 words)
⚠️ Lost seed phrases cannot be recovered
⚠️ Users are responsible for their own funds (self-custodial)


Performance Impact

  • Bundle Size: +2.4MB (Breez SDK WASM module)
  • Initial Load: +500ms (WASM initialization, one-time)
  • Runtime: Minimal impact, SDK operations are async
  • Storage: ~50KB IndexedDB for wallet state
  • Network: Minimal, only for Lightning operations

Breaking Changes

None - This is a purely additive feature. All existing functionality remains unchanged.


Dependencies

Added

  • @breeztech/breez-sdk-spark@^0.5.2 - Lightning wallet SDK

Updated

  • next@15.5.9 - Security patch for CVE-2025-66478
  • react@^19.1.0 - Latest stable
  • react-dom@^19.1.0 - Latest stable

Deployment Checklist

Before merging:

  • All tests passing
  • Vercel build successful
  • WASM modules loading correctly
  • No console errors in production
  • Documentation updated
  • Changelog updated
  • Security scan passed (Next.js 15.5.9)
  • Code review approved
  • QA testing complete

Screenshots

image image image image image

Demo

Live demo available at: https://sparkihonne.vercel.app

Test the following flows:

  1. Create new Spark wallet during signup
  2. Send a Lightning payment
  3. Receive a Lightning payment
  4. View payment history
  5. Backup and restore wallet

Questions & Support

For questions about this PR:

  • Review SPARK_WALLET_INTEGRATION.md for implementation details
  • Check DEV_NOTES.md for development setup
  • See SPARK_ARCHITECTURE.md for architecture overview

Credits

Integration developed using:


License

This integration maintains the same license as the YakiHonne project.


Reference

This project was developed for the Time2Build worldwide developer challenge to bring bitcoin to the world's leading open-source applications and services using the Breez SDK.

dmnyc and others added 30 commits November 2, 2025 00:24
Major improvements to Spark wallet UI and functionality:

Profile & Wallet Linking:
- Fix wallet link detection for Spark wallets (kind 4)
- Add sparkLightningAddress to Redux selectors
- Update checkIsLinked() to compare Lightning addresses with profile lud16
- Hide "wallet not linked" warning when Spark address matches profile

Send/Receive UI Improvements:
- Match NWC design patterns for consistency
- Add close (X) buttons to Send and Receive tabs
- Implement "Use invoice" toggle switch in Send tab
- Reorder fields: Message (optional) → Amount → Button
- Update button labels: "Send Payment" → "Send", "Generate Invoice" → "Generate invoice"

Payment History Enhancements:
- Add expandable payment details with +/− toggle button
- Display comprehensive info: ID, status, amount, fees, time, description, hash, preimage
- Add copy-to-clipboard for Payment ID, Payment Hash, and Preimage
- Integrate Sparkscan blockchain explorer links
- Use correct Sparkscan URL format: https://www.sparkscan.io/tx/{id}?network=mainnet

Payment Pagination:
- Implement offset-based pagination (20 payments per batch)
- Add "Load More" button for infinite scroll
- Support append mode for seamless history loading

Bug Fixes:
- Fix payment direction detection (handle lowercase 'send'/'receive')
- Properly convert BigInt amounts to Number for display
- Add color-coded status labels (green/orange/red)

Files modified:
- src/(PagesComponents)/Wallet.js
- src/Components/Spark/SparkWalletManager.js
- src/Components/Spark/SparkPaymentsList.js
- src/Helpers/Spark/spark-wallet-manager.js
- DEV_NOTES.md
## Error Handling & User Experience
- Convert all wallet connection errors to user-friendly toast notifications
- Add specific error messages for NWC relay failures and authorization issues
- Implement INSUFFICIENT_FUNDS detection with user-friendly messaging
- Change console.log to console.warn for handled errors to prevent Next.js error overlay
- Ensure users never see technical runtime errors

## Wallet Linking Fix
- Fix "None of connected wallets are linked" appearing incorrectly when switching wallets
- Update checkIsLinked() to check all wallets against profile address, not just selected wallet
- Users can now switch between Spark, NWC, and Alby without false warnings
- Properly recognize Spark Lightning addresses when viewing other wallet types

## Loading State Improvements
- Eliminate "Wallet not connected" flash on page refresh
- Add proper loading states showing "Connecting wallet..." with animation
- Hide balance display during Spark wallet connection instead of showing "N/A"
- Add sparkConnecting state check in SparkWalletManager component
- Improve sidebar balance behavior when Spark not connected

## UI Layout & Responsive Design
- Fix overflow issue where eyeball icon was pushed out by large USD values
- Add text truncation with ellipsis for very large balance numbers
- Improve number formatting with thousand separators
- Add mobile wallet icon in sidebar for narrow viewports
- Implement proper flexbox layout to prevent UI breaking with large balances

## Translation & Internationalization
- Add 9 new translation keys across all 11 languages:
  - "Wallet not connected"
  - "Connecting wallet..."
  - SparkBackupInvalidJson
  - SparkBackupWrongAccount
  - SparkBackupInvalidFormat
  - SparkBackupUnsupportedVersion
  - SparkBackupDecryptFailed
  - SparkWalletUnableReceive
  - SparkWalletUnableSend
- Update generic copy message from "LNURL was copied" to "Copied to clipboard!"

## Code Cleanup
- Remove all debug console.log statements
- Clean up temporary debugging code
- Maintain only console.error for actual failures and console.warn for handled errors
- Add descriptive labels to all production logging

## Documentation Updates
- Update DEV_NOTES.md with 2025-11-04 changelog entry
- Add comprehensive Production Deployment Checklist
- Update "Lessons Learned" with 5 new insights
- Add Lightning Address Configuration section to Spark README
- Document custom domain setup option (@yakihonne.com vs @breez.tips)
- Mark completed improvements in "What Could Be Improved" section

## Files Modified (29 files)
- Core: Wallet.js, UserBalance.js, SatsToUSD.js
- Spark: SparkWalletManager.js, SparkWalletSetup.js, spark.service.js
- Translations: All 11 language files (en, zh, fr, es, it, pt, th, ja, ar, hi)
- Docs: DEV_NOTES.md, src/Components/Spark/README.md

This release improves error handling, eliminates UI flashes, adds mobile support,
and prepares the Spark wallet integration for production deployment.
- Add @breeztech/breez-sdk-spark to transpilePackages
- Enable webpack layers experiment
- Add .wasm to resolve.extensions
- Convert Breez SDK imports to dynamic imports (client-side only)
- Prevents SSR issues with WebAssembly modules
- Install copy-webpack-plugin
- Configure webpack with syncWebAssembly and asyncWebAssembly experiments
- Add NormalModuleReplacementPlugin to handle wbg internal imports
- Create wbg-shim.js placeholder for WASM internal bindings
- Maintain server-side externals for Breez SDK
- Remove wbg-shim workaround (was causing issues)
- Simplify webpack config to only use asyncWebAssembly
- Remove copy-webpack-plugin dependency
- Add better error logging to spark.service.js for WASM init failures
- Add server-side external for @breeztech/breez-sdk-spark/web
- Create wbg-stub.js to satisfy webpack module resolution
- Add NormalModuleReplacementPlugin to replace wbg imports
- WASM bindings are handled at runtime, stub is just for build
- Local build successful, WASM bundled to static/wasm/
  Problem: The error "e.replace is not a function" occurred because
  import.meta.url is not properly resolved by webpack in Vercel's
  build environment, causing Breez SDK WASM initialization to fail.

  Solution:
  - Add postinstall script to copy WASM file to public/wasm/
  - Pass explicit WASM path to initBreezSDK() instead of relying on
    import.meta.url resolution
  - Ensures WASM file is accessible at /wasm/breez_sdk_spark_wasm_bg.wasm

  Changes:
  - package.json: Add postinstall script for WASM file deployment
  - src/Helpers/Spark/spark.service.js: Use explicit path in initializeWasm()
  - public/wasm/: Add breez_sdk_spark_wasm_bg.wasm (6.8MB)
  Problem: import.meta.url not resolved by webpack, causing
  "e.replace is not a function" error during WASM initialization.

  Solution:
  - Treat Breez WASM as asset/resource for webpack bundling
  - Dynamically import WASM to get webpack-resolved path
  - Pass resolved path to SDK init instead of relying on import.meta.url
  - Use IgnorePlugin for internal wbg imports

  Files changed:
  - next.config.mjs: Configure WASM as asset/resource, add IgnorePlugin
  - spark.service.js: Import WASM dynamically, pass to initBreezSDK()
  - package.json: Remove postinstall script

  Build output: WASM bundled to /_next/static/wasm/[hash].wasm
  - Add guards to getLinkFromAddr() in Helpers.js
  - Add guards to decodeNip19() in Helpers.js
  - Add guard to compactContent() in ClientHelpers.js
  - Prevents 'Cannot read properties of undefined (reading replaceAll)' errors
  - Fixes issue when rendering Spark wallet payment details on Vercel
- Add prominent loading spinner with progress messages
- Show 'Reading backup file...', 'Initializing Lightning Network...', 'Syncing wallet...'
- Full-screen overlay with darkened background for better visibility
- Addresses UX issue where 50+ second wallet restoration had minimal feedback
- Add spin animation keyframe for loading spinner

This provides much better user feedback during the lengthy WASM initialization
and Lightning network sync process.
… instead of 'Initializing Lightning Network...'
  Merges latest upstream changes while preserving Spark wallet integration:

  Upstream changes:
  - Add notification system with real-time updates
  - Add multi-currency support (fiat selector)
  - Add Russian language translations
  - Improve muted list handling with allTags support
  - Add relay sets management features
  - Add search relays configuration
  - Add WOT (Web of Trust) explanation page
  - Improve DM decryption with worker threads
  - Add dynamic windowed feed for performance
  - Various UI/UX improvements and bug fixes

  Spark wallet features preserved:
  - All Spark wallet integration files maintained
  - Redux state for Spark wallet (7 slices)
  - Wallet balance display now uses improved UI
  - Compatible with new currency selector feature

  Resolved conflicts in:
  - Wallet.js (merged balance display improvements)
  - AppInit.js (adopted upstream muted list handling)
  - SatsToUSD.js (merged multi-currency support)
  - Store.js (added both notification and Spark reducers)
  - AddWallet.js (removed unnecessary 'use client')

  197 files changed, 11744 insertions(+), 5717 deletions(-)
  - Change default import to named import for relaysOnPlatform
  - Update pnpm-lock.yaml after installing react-virtuoso
  - Regenerate service worker after build

  Fixes build error: '@/Content/Relays' does not contain a default export
  - Update @breeztech/breez-sdk-spark from 0.3.4 to
  0.5.2
  - Add event-based sync workaround for SDK promise
  bug
  - Enable private mode by default (required for
  recent-payment-pfps)
  - Fix refreshWalletState to avoid redundant sync
  calls

  The SDK 0.5.2 syncWallet() promise doesn't resolve,
  but the
  dataSynced event fires correctly. Created
  syncWalletWithEvent()
  method to listen for the event instead of waiting
  for the promise.

  Also prevents refreshWalletState from triggering
  another sync via
  getInfo(ensureSynced=false), since we already synced
   during connection.
Updated dependencies to fix Next.js CVE vulnerabilities.

The fix-react2shell-next tool automatically updated the following packages to their secure versions:
- next
- react-server-dom-webpack
- react-server-dom-parcel  
- react-server-dom-turbopack

All package.json files have been scanned and vulnerable versions have been patched to the correct fixed versions based on the official React advisory.

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
…o-uyt99o

Fix React Server Components RCE vulnerability
- Suppress harmless RecvError during wallet disconnect/delete operations
  - Added global console.error interceptor to catch WASM sync errors
  - Improved async error handling in disconnect() method
  - Prevents confusing error messages during normal cleanup

- Enable privacy mode by default
  - Hide payment IDs and Sparkscan block explorer links
  - Protects user privacy by preventing on-chain correlation

- Add Spark wallet auto-connect on app initialization
  - Automatically restores active Spark wallet when user logs in
  - Ensures wallet is available across all app pages

- Fix null reference errors
  - Add null checks in getFavRelays() for undefined tags
  - Prevents crashes when favorite relay data is incomplete

- Add comprehensive zap profile investigation documentation
  - Documents 3 implementation attempts for displaying zap sender profiles
  - Explains SDK 0.5.2 limitations and SDK 0.6.x requirements
  - Provides roadmap for future feature implementation

Based on Breez SDK 0.5.2 with event-based sync workaround.
- Upgrade Next.js to 15.5.9 (patches CVE-2025-66478 security vulnerability)
- Fix method name bug: checkUsernameAvailability -> checkLightningAddressAvailable
- Make initial wallet sync non-blocking to prevent UI freezing
- Add comprehensive error suppression for harmless SDK disconnect errors
- Reorder wallet options to prioritize Spark (self-custodial) over NWC
- Remove deprecated Sparkscan blockchain explorer references
- Update documentation with SDK 0.5.2 and privacy mode details

These changes resolve WASM runtime errors, security vulnerabilities, and improve
wallet stability while maintaining full functionality for create, restore, and delete.
- Complete feature list with actual implementation details
- Clarifies backup strategy (downloadable files, not Nostr relays)
- Documents 3 wallet setup methods and 4-tab wallet manager UI
- Includes work-in-progress section for payment profile display
- Notes optional Nostr backup infrastructure for future use
- Fix misleading Nostr backup references in SPARK_WALLET_INTEGRATION.md
- Update QUICK_START_SPARK.md to reflect file-based backups
- Add Claude Code credit to PR_SUMMARY.md Credits section
- Clarify that Nostr backup infrastructure exists but is disabled for YakiHonne UX
- All docs now accurately reflect downloadable backup file strategy
- Change 'Pay breez.tips user' to 'Pay YakiHonne user' in registerLightningAddress
- Ensures proper branding in Lightning address metadata
- Add proactive IndexedDB clearing before each connection to prevent WASM corruption
- Clean mnemonics at all entry points (restore, file upload, auto-restore) to remove non-ASCII characters
- Fix Redux serialization warning by converting Map to plain object
- Fix config property name (privateEnabledDefault vs private_enabled_default)
- Add comprehensive mnemonic validation in wallet manager
Root Cause:
- Two components (AppInit.js and Wallet.js) were independently calling
  restoreWallet() on page load, creating a race condition
- Concurrent WASM SDK calls caused memory corruption errors:
  'closure invoked recursively', 'memory access out of bounds'

Fix:
- AppInit.js: Single centralized auto-restore point with isConnected() guard
- Wallet.js: Removed duplicate restore logic, only refreshes if connected
- Added defensive mnemonic validation and connection guards

This follows the correct architectural pattern used in working Breez SDK
implementations - single initialization point prevents WASM race conditions.
  - Fix zap request encoding (encodeURI -> encodeURIComponent)
  - Fix payment status check (completed -> complete)
  - Fix payment response structure (return response.payment)
  - Add waitForPaymentCompletion to wait for async payment events
  - Fix QR code showing during active payment sending

  Fixes 4 critical bugs preventing zaps from working correctly.
@mostafa-khaldi
Copy link
Contributor

Thanks for the contribution, it was an amazing job integrating the Spark wallet in all the necessary places, although, there are rooms for improvement design wise to fully blend with YakiHonne UI/UX, but it's working greatly!

…ibility

  - Add NIP-44 v2 encryption for wallet backups (ChaCha20, HKDF-SHA256, HMAC-SHA256)
  - Maintain full backward compatibility with NIP-04 v1 backups
  - Support Primal's hybrid v2/NIP-04 backup format via smart encryption detection
  - Graceful fallback to NIP-04 for browser extensions without NIP-44 support
  - Add console logging to indicate which encryption method is being used

  Security improvements:
  - 5x faster encryption (101K ops/sec vs 19K ops/sec)
  - HKDF key derivation prevents key exposure attacks
  - HMAC authentication prevents tampering
  - Cure53 audited (December 2023)

  Backward compatibility:
  - Detects encryption via: explicit field, format pattern (?iv=), or version number
  - Can restore from v1 (NIP-04), v2 (NIP-44), and v2 (NIP-04) backups
  - Browser extensions without NIP-44 automatically use NIP-04 fallback
@dmnyc dmnyc force-pushed the feat/spark-wallet-integration branch from bae04f3 to 9cb0d60 Compare December 16, 2025 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants