Skip to content

bitcoin-brasil/react-native-ldk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-ldk

⚠️ This is pre-alpha software and not suitable for production apps yet.

Description

This library hopes to simplify the process of adding Lightning via LDK to any React-Native app.

Getting started

yarn add @synonymdev/react-native-ldk
#or
npm i -S @synonymdev/react-native-ldk

iOS installation

cd ios && pod install && cd ../

Android installation

  1. Add the following line to dependencies in /android/app/build.gradle
dependencies {
  ...
  implementation files("../../node_modules/@synonymdev/react-native-ldk/android/libs/LDK-release.aar")
}
  1. Ensure minSdkVersion is set to at least 24 in /android/build.gradle

Running example app

#Build dist files
git clone https://github.com/synonymdev/react-native-ldk.git
cd react-native-ldk/lib/ && yarn install && yarn build && cd ../

cd example/ && yarn install && yarn rn-setup

yarn ios
#or
yarn android

Notes

  • It is important to not mix and match account names and seeds when starting LDK. Doing so can result in a corrupt save.

Using zero conf channels

Channels needs to be manually accepted but this is handled by channel-manager.ts if counterparty is in our trusted peer list.

const userConfig: TUserConfig = {
   channel_handshake_config: {
   	announced_channel: false,
   	minimum_depth: 1,
   	max_htlc_value_in_flight_percent_of_channel: 100,
   	negotiate_anchors_zero_fee_htlc_tx: true, //Required for zero conf
   },
   manually_accept_inbound_channels: true, //Required for zero conf
   accept_inbound_channels: true,
};

When starting LDK, provide a list of node public keys from which you are willing to accept zero-confirmation channels.

const lmStart = await lm.start(
  ...
  trustedZeroConfPeers: ['03fc8877790430d7fb29e7bcf6b8bbfa3050e5e89189e27f97300e8a1e9ce589a3']

From LND update your conf as specified here and open with these params: lncli openchannel --node_key=03c6b2081d6f333fe3a9655cdb864be7b6b46c8648188a44b6a412e41b63a43272 --local_amt=200000 --push_amt=50000 --private=true --zero_conf --channel_type=anchors

Upgrading LDK

  • Use latest LDK-release.aar from ldk-garbagecollected and place in lib/android/libs.
  • Use latest LDKFramework.xcframework from ldk-swift and place in lib/ios.
    • To get pod install working you might have to open the LDKFramework.xcframework directory, delete non ios frameworks and remove all references to deleted frameworks inside LDKFramework.xcframework/Info.plist.
  • Update Swift and Kotlin code if there are any breaking changes.

Testing

Tests are implemented using mocha-remote. To run tests at first you need to install docker and start tesing regtest enviroment using docker-compose:

cd example
docker-compose up

Then to run tests open two terminals and execute the following commands:

# Terminal 1
cd example
npm run start
# Terminal 2
cd example
npm run test:mocha

How to test your code

Because it's a native module, you need to mock this package.

The package provides a default mock you may use in your __mocks__/@synonymdev/react-native-ldk.js or jest.setup.js.

import * as mockLDK from '@synonymdev/react-native-ldk/dist/mock';

jest.mock('@synonymdev/react-native-ldk', () => mockLDK);

Releases

No releases published

Packages

No packages published

Languages

  • C++ 86.7%
  • TypeScript 5.7%
  • Swift 2.6%
  • Kotlin 2.1%
  • C 1.7%
  • Java 0.4%
  • Other 0.8%