4.19.1 • Published 4 years ago

@ledgerhq/react-native-ledger-core v4.19.1

Weekly downloads
752
License
MIT
Repository
github
Last release
4 years ago

React Native Binding for Ledger Core Library

This repository provides a react native binding to Ledger Core Library

Project Structure

.
├── include                       # includes for Ledger Core
├── binding.gyp                   # clled during yarn phase, generates static libraries
├── Makefile                      # called during make phase, generates binding.xcodeproj
├── build                         # static libraries location
├── build_ios                     # binding.xcodeproj location
├── support-lib                   # sources for djinni objc support
├── ios                           # contains react native ios binding (xcodeproj)
│   |── RNLibLedgerCore.xcodeproj
│   └── Sources
│   │   ├── objc                  # bindings objective-c (generated automatically)
│   │   ├── objc-cpp              # used by bindings objective-c (generated automatically)
│   │   ├── objc-impl             # implementations of platform specific interfaces
│   │   ├── java                  # used by bindings java (generated automatically)
│   │   └── react-native-ios      # bindings react native ios (generated automatically)
│   └── Libraries                 # contains dynamic libraries (libledger-core.dylib)             
│
└── android                       # contains react native android binding (gradle)
    │── src/main/java             
    │    ├── co/ledger/core        # bindings java
    │    └── com/ledger/reactnative# bindings react native
    └── libs                       # contains shared libraries (libledger-core.so built with jni support)             

Use React Native iOS binding

  • add RNLibLedgerCore.xcodeproj under your Libraries's xcodeproj,
  • add RNLibLedgerCore to your Target Dependencies's xcodeproj section,
  • add libRNLibLedgerCore.a to your Link Binary With Libraries's xcodeproj section,
  • add libledger-core.dylib (under ios/Libraries) to your Frameworks's and Embeded Binaries xcodeproj sections,
  • add dynamic library's path to Library Search Paths section: $(SRCROOT)/PATH_TO_DYLIB.

Use React Native Android binding

  • include react-native-ledger-core in your app's gradle project, in settings.gradle add :

    include ':react-native-ledger-core'
    project(':react-native-ledger-core').projectDir = new File(rootProject.projectDir, '../node_modules/@ledgerhq/react-native-ledger-core/android')
  • add react-native-ledger-core to your app module's dependencies, in build.gradle add :

    compile project(':react-native-ledger-core')
  • load shared library in your app, e.g. in your MainApplication.java add:
    static {
      try {
        System.loadLibrary("ledger-core");
      } catch (UnsatisfiedLinkError e) {
        System.err.println("ledger-core native library failed to load: " + e);
        System.exit(1);
      }
    }
  • export package by adding RCTCoreBindingPackage to list of packages of your MainApplication.java

Call binding from JS side

Import native modules:

import { NativeModules } from "react-native";

Then you can access the native module :

NativeModules.ModuleName

iOS

Native Module's name is the one of corresponding react native binding interface's name which is located under ios/Sources/react-native-ios, for example to access native module of a wallet pool (ios/Sources/react-native-ios/RCTCoreLGWalletPool.h) you can call from JS side: NativeModules.CoreLGWalletPool

Android

Same but classes are the ones located under android/src/main/java/com/ledger/reactnative, for example you can call from JS side: NativeModules.CoreWalletPool (This will change later so modules will have same name)

Example (iOS)

import { NativeModules } from "react-native";
const {
  CoreLGSecp256k1,
  CoreLGHttpClient,
  CoreLGWebSocketClient,
  CoreLGPathResolver,
  CoreLGLogPrinter,
  CoreLGThreadDispatcher,
  CoreLGRandomNumberGenerator,
  CoreLGDatabaseBackend,
  CoreLGDynamicObject,
  CoreLGWalletPool,
} = NativeModules;

createWalletInstance = async () => {

  /*
  Platform specific interfaces, fully implemented in Objective-C
  */
  const httpClient = await CoreLGHttpClient.new();
  const webSocket = await CoreLGWebSocketClient.new();
  const pathResolver = await CoreLGPathResolver.new();
  const logPrinter = await CoreLGLogPrinter.new();
  const threadDispatcher = await CoreLGThreadDispatcher.new();
  const rng = await CoreLGRandomNumberGenerator.new();

  /*
  Common interfaces, fully implemented in C++
  */
  const backend = await CoreLGDatabaseBackend.getSqlite3Backend();
  const dynamicObject = await CoreLGDynamicObject.newInstance();

  //Instantiate wallet pool
  const walletPoolInstance = await CoreLGWalletPool.newInstance(
    "ledger_live_desktop",
    "",
    httpClient,
    webSocket,
    pathResolver,
    logPrinter,
    threadDispatcher,
    rng,
    backend,
    dynamicObject,
  );

  console.log(" >>> Wallet Pool Instance");
  console.log(walletPoolInstance);

  const currency = await CoreLGWalletPool.getCurrency(
    walletPoolInstance,
    "bitcoin",
  );

  const config = await CoreLGDynamicObject.newInstance();

  //Instantiate wallet
  console.log(" >>> createWallet");
  const wallet = await CoreLGWalletPool.createWallet(
    walletPoolInstance,
    "WALLET_IDENTIFIER",
    currency,
    config,
  );

  console.log(" >>> Wallet Instance ");
  console.log(wallet);
  return wallet;
};
5.0.0-beta.2

4 years ago

5.0.0-beta.1

4 years ago

5.0.0-beta.0

4 years ago

4.19.0

4 years ago

4.19.1

4 years ago

4.18.8

4 years ago

4.18.6

4 years ago

4.18.5

4 years ago

4.17.4

4 years ago

4.17.3

4 years ago

4.17.2

4 years ago

4.17.1

4 years ago

4.17.0

4 years ago

4.17.0-okhttp3.0

4 years ago

4.17.0-beta.1

4 years ago

4.17.0-beta.0

4 years ago

4.16.3

5 years ago

4.16.2

5 years ago

4.16.1

5 years ago

4.16.0

5 years ago

4.15.13

5 years ago

4.15.12

5 years ago

4.15.11

5 years ago

4.15.10

5 years ago

4.15.19

5 years ago

4.15.9

5 years ago

4.15.8

5 years ago

4.15.7

5 years ago

4.15.4

5 years ago

4.15.2

5 years ago

4.15.3

5 years ago

4.15.0

5 years ago

4.15.1

5 years ago

4.14.2

5 years ago

4.14.1

5 years ago

4.14.0

5 years ago

4.13.3

5 years ago

4.13.2

5 years ago

4.13.1

5 years ago

4.13.0

5 years ago

4.12.3

5 years ago

4.12.2

5 years ago

4.12.1

5 years ago

4.12.0

5 years ago

4.12.0-beta.0

5 years ago

4.11.0

5 years ago

4.11.0-beta.3

5 years ago

4.11.0-beta.1

5 years ago

4.11.0-beta.2

5 years ago

4.11.0-beta.0

5 years ago

4.10.0

5 years ago

4.10.1-dev.0

5 years ago

4.10.0-alpha.0

5 years ago

4.10.0-alpha.1

5 years ago

4.9.0

5 years ago

4.9.1

5 years ago

4.8.0

5 years ago

4.7.1

5 years ago

4.7.0

5 years ago

4.6.0

5 years ago

4.5.1

6 years ago

4.5.0

6 years ago

4.4.0

6 years ago

4.3.1

6 years ago

4.3.0

6 years ago

4.2.0

6 years ago

4.1.0

6 years ago

4.0.0

6 years ago

4.0.0-alpha.1

6 years ago

4.0.0-alpha.0

6 years ago

3.10.0

6 years ago

3.9.2

6 years ago

3.9.1

6 years ago

3.9.0

6 years ago

3.8.1

6 years ago

3.8.0

6 years ago

3.7.0

6 years ago

3.6.0

6 years ago

3.5.3

6 years ago

3.5.2

6 years ago

3.5.1

6 years ago

3.5.0

6 years ago

3.4.0

6 years ago

3.3.4

6 years ago

3.3.3

6 years ago

3.3.2

6 years ago

3.3.1

6 years ago

3.3.0

6 years ago

3.2.1

6 years ago

3.2.0

6 years ago

3.1.8

6 years ago

3.1.7

6 years ago

3.1.6

6 years ago

3.1.5

6 years ago

3.1.4

6 years ago

3.1.3

6 years ago

3.1.2

6 years ago

3.1.1-beta.0

6 years ago

3.1.0

6 years ago

3.1.0-beta.3

6 years ago

3.1.0-beta.2

6 years ago

3.1.0-beta.1

6 years ago

3.1.0-beta

6 years ago

3.0.0

6 years ago

3.0.0-beta.6

6 years ago

3.0.0-beta.5

6 years ago

3.0.0-beta.4

6 years ago

3.0.0-beta.3

6 years ago

3.0.0-beta.2

6 years ago

3.0.0-beta.1

6 years ago

3.0.0-beta.0

6 years ago

0.6.0-beta.8

6 years ago

0.6.0-beta.7

6 years ago

0.6.0-beta.6

6 years ago

0.6.0-beta.5

6 years ago

0.6.0-beta.4

6 years ago

0.6.0-beta.3

6 years ago

0.6.0-beta.2

6 years ago

0.6.0-beta.1

6 years ago

0.6.0-beta.0

6 years ago

0.5.2-rc

6 years ago

0.5.2

6 years ago

0.5.1-rc.3

6 years ago

0.5.1-rc.2

6 years ago

0.5.1-rc

6 years ago

0.5.0-rc

6 years ago

0.4.0-rc.3

6 years ago

0.4.0-rc.1

6 years ago

0.3.45

6 years ago

0.3.44

7 years ago

0.3.43

7 years ago

0.3.42

7 years ago

0.3.41

7 years ago

0.3.40

7 years ago

0.3.39

7 years ago

0.3.37

7 years ago

0.3.36

7 years ago

0.3.35

7 years ago

0.3.34

7 years ago

0.3.33

7 years ago

0.3.32

7 years ago

0.3.31

7 years ago

0.3.30

7 years ago

0.3.28

7 years ago

0.3.27

7 years ago

0.3.26

7 years ago

0.3.25

7 years ago

0.3.24

7 years ago

0.3.23

7 years ago

0.3.21

7 years ago

0.3.20

7 years ago

0.3.19

7 years ago

0.3.18

7 years ago

0.3.17

7 years ago

0.3.16

7 years ago

0.3.15

7 years ago

0.3.14

7 years ago

0.3.13

7 years ago

0.3.12

7 years ago

0.3.11

7 years ago

0.3.10

7 years ago

0.3.9

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago