synonymdev / react-native-ldk

React Native LDK
MIT License
51 stars 16 forks source link

react-native-ldk

:warning: 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") // <- this
    }
  2. Ensure minSdkVersion is set to at least 24 in /android/build.gradle

Development

Android

Version Bump

# apply your changes
cd example
yarn reinstall # bump versions package.json & podfile
cd ../
# copy version from `./lib/package.json` to `backup-server/package.json`

Running example app

See also ./example/README.md

# 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

Update config to match your local setup

In constants.ts update peers.lnd if you're using Polar locally.

Example for Android

//  export const peers = {
//  lnd: {
    pubKey:
      '_033f4d3032ce7f54224f4bd9747b50b7cd72074a859758e40e1ca46ffa79a34324_',
    address: '10.0.2.2',
    port: 9737,
// },

Notes

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

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);