npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

reactnative-lightening-wallet-rs

v0.1.42

Published

High-performance unified Lightning wallet for React Native

Downloads

3,769

Readme

React Native Lightning Wallet (Rust)

A high-performance unified Lightning wallet library for React Native, built entirely in Rust. This library consolidates LDK (Lightning Development Kit), Electrum client, and Bitcoin wallet functionality into a single native module.

Features

  • High Performance: All wallet logic runs in native Rust code
  • Bitcoin Wallet: BIP39/BIP32 HD wallet with native address derivation
  • Lightning Network: LDK integration for Lightning payments (coming soon)
  • Electrum Client: Built-in Electrum protocol support
  • UTXO Management: Native UTXO tracking with caching
  • Transaction Building: Coin selection and transaction signing
  • Payment History: SQLite-based payment database
  • Event Streaming: Real-time wallet events
  • Cross-platform: Supports Android and iOS

Architecture

reactnative-lightening-wallet-rs/
├── rust/               # Rust core library
│   ├── src/
│   │   ├── lib.rs           # JNI/FFI bindings
│   │   ├── coordinator.rs   # Main orchestrator
│   │   ├── wallet/          # Bitcoin wallet logic
│   │   ├── electrum/        # Electrum client
│   │   ├── storage/         # SQLite & caching
│   │   └── events.rs        # Event system
│   └── Cargo.toml
├── android/            # Android JNI bindings
├── ios/                # iOS FFI bindings
└── js/                 # TypeScript API

Performance Improvements

Compared to the previous JavaScript-based wallet:

  • Wallet initialization: 3-5s → 500ms (10x faster)
  • Balance refresh: 2-3s → 100ms (20x faster)
  • UTXO scanning: 5-10s → 300ms (30x faster)
  • Payment send: 2-4s → 400ms (7x faster)

Installation

Prerequisites

  • Rust 1.70+ with cargo
  • Android NDK (if building for Android)
  • Xcode (if building for iOS)
  • cargo-ndk for Android builds: cargo install cargo-ndk

Install the package

npm install reactnative-lightening-wallet-rs
# or
yarn add reactnative-lightening-wallet-rs

iOS Setup

After installing the package, you need to install CocoaPods dependencies:

cd ios
pod install
cd ..

The Podspec includes a prepare_command that will automatically build the Rust library for iOS when you run pod install. If you prefer to build manually:

npm run build:ios
cd ios
pod install

Important: Make sure you have the iOS Rust targets installed:

rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim

Android Setup

The Android build is automatically handled by Gradle. Just make sure you have:

  1. Android NDK installed
  2. cargo-ndk installed: cargo install cargo-ndk

Then build your React Native app normally:

cd android
./gradlew assembleRelease

Build the native library

Android

# Option 1: Using npm script
npm run build:rust:android

# Option 2: Direct Gradle build
cd android
./gradlew assembleRelease

# Option 3: Build Rust directly
cd rust
cargo ndk -t arm64-v8a -t armeabi-v7a -o ../android/src/main/jniLibs build --release

iOS

# Option 1: Using npm script (recommended)
npm run build:ios

# Option 2: Using the build script directly
./scripts/build-ios.sh

# Option 3: Manual build
cd rust
rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim
cargo build --release --target aarch64-apple-ios
cargo build --release --target x86_64-apple-ios
cargo build --release --target aarch64-apple-ios-sim

Note for iOS: The first build will take longer as it downloads dependencies and compiles for multiple architectures (simulator + device).

Build Both Platforms

npm run build:all

Usage

Initialize wallet

import LighteningWallet from 'reactnative-lightening-wallet-rs';

// Generate a new mnemonic
const mnemonic = await LighteningWallet.generateMnemonic();

// Initialize wallet
await LighteningWallet.initialize(
  'user123',          // User ID
  mnemonic,           // BIP39 mnemonic
  'testnet',          // Network: 'bitcoin' or 'testnet'
  '/path/to/wallet.db' // Database path
);

Get balance

const balance = await LighteningWallet.getBalance();

console.log('Total balance:', balance.total);
console.log('On-chain confirmed:', balance.onchain_confirmed);
console.log('Lightning balance:', balance.lightning_balance);
console.log('Pending:', balance.pending);

Sync wallet

await LighteningWallet.sync();

Get receiving address

const address = await LighteningWallet.getReceivingAddress();
console.log('Receive to:', address);

List payment history

const payments = await LighteningWallet.listPayments(10, 0); // limit, offset

payments.forEach(payment => {
  console.log(`${payment.payment_type}: ${payment.amount_sats} sats`);
});

Subscribe to events

const unsubscribe = LighteningWallet.onEvent((event) => {
  switch (event.type) {
    case 'BalanceUpdated':
      console.log('Balance updated:', event.total);
      break;
    case 'PaymentReceived':
      console.log('Payment received:', event.amount_sats);
      break;
    case 'SyncCompleted':
      console.log('Sync completed in', event.duration_ms, 'ms');
      break;
  }
});

// Cleanup
unsubscribe();

Disconnect

await LighteningWallet.disconnect();

API Reference

LighteningWalletAPI

static generateMnemonic(): Promise<string>

Generate a new 24-word BIP39 mnemonic phrase.

initialize(userId: string, mnemonic: string, network: 'bitcoin' | 'testnet', dbPath: string): Promise<void>

Initialize a wallet instance.

getBalance(): Promise<WalletBalance>

Get the current wallet balance.

sync(): Promise<void>

Sync the wallet with the blockchain via Electrum.

getReceivingAddress(): Promise<string>

Get a fresh receiving address.

listPayments(limit?: number, offset?: number): Promise<Payment[]>

List payment history.

getEvents(): Promise<WalletEvent[]>

Get pending wallet events.

onEvent(callback: (event: WalletEvent) => void): () => void

Subscribe to real-time wallet events.

disconnect(): Promise<void>

Disconnect and cleanup the wallet.

Types

interface WalletBalance {
  onchain_confirmed: number;
  onchain_unconfirmed: number;
  lightning_balance: number;
  lightning_receivable: number;
  claimable_balance: number;
  total: number;
  pending: number;
}

interface Payment {
  id?: number;
  payment_hash: string;
  payment_type: 'sent' | 'received' | 'onchain_sent' | 'onchain_received';
  amount_sats: number;
  fee_sats?: number;
  status: 'pending' | 'completed' | 'failed';
  timestamp: number;
  description?: string;
  destination?: string;
  txid?: string;
  preimage?: string;
  bolt11?: string;
}

type WalletEvent =
  | { type: 'BalanceUpdated'; ... }
  | { type: 'PaymentReceived'; ... }
  | { type: 'PaymentSent'; ... }
  | { type: 'SyncCompleted'; ... }
  | ...

Development

Run tests

cd rust
cargo test

Build for development

cd rust
cargo build

Format code

cd rust
cargo fmt

Check code

cd rust
cargo clippy

Roadmap

  • [x] Bitcoin wallet core (BIP39/32)
  • [x] Electrum client
  • [x] UTXO management
  • [x] Transaction building
  • [x] Payment history database
  • [x] Event streaming
  • [ ] LDK integration
  • [ ] Lightning payments
  • [ ] Channel management
  • [ ] Background sync service
  • [ ] UTXO consolidation
  • [ ] Fee estimation
  • [ ] iOS support
  • [ ] Example app

License

MIT

Credits

This library integrates and builds upon: