4.19.1 • Published 3 years ago

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

Weekly downloads
752
License
MIT
Repository
github
Last release
3 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

3 years ago

5.0.0-beta.1

3 years ago

5.0.0-beta.0

3 years ago

4.19.0

3 years ago

4.19.1

3 years ago

4.18.8

3 years ago

4.18.6

3 years ago

4.18.5

3 years ago

4.17.4

3 years ago

4.17.3

3 years ago

4.17.2

3 years ago

4.17.1

3 years ago

4.17.0

3 years ago

4.17.0-okhttp3.0

3 years ago

4.17.0-beta.1

3 years ago

4.17.0-beta.0

3 years ago

4.16.3

4 years ago

4.16.2

4 years ago

4.16.1

4 years ago

4.16.0

4 years ago

4.15.13

4 years ago

4.15.12

4 years ago

4.15.11

4 years ago

4.15.10

4 years ago

4.15.19

4 years ago

4.15.9

4 years ago

4.15.8

4 years ago

4.15.7

4 years ago

4.15.4

4 years ago

4.15.2

4 years ago

4.15.3

4 years ago

4.15.0

4 years ago

4.15.1

4 years ago

4.14.2

4 years ago

4.14.1

4 years ago

4.14.0

4 years ago

4.13.3

4 years ago

4.13.2

4 years ago

4.13.1

4 years ago

4.13.0

4 years ago

4.12.3

4 years ago

4.12.2

4 years ago

4.12.1

4 years ago

4.12.0

4 years ago

4.12.0-beta.0

4 years ago

4.11.0

4 years ago

4.11.0-beta.3

4 years ago

4.11.0-beta.1

4 years ago

4.11.0-beta.2

4 years ago

4.11.0-beta.0

4 years ago

4.10.0

4 years ago

4.10.1-dev.0

4 years ago

4.10.0-alpha.0

4 years ago

4.10.0-alpha.1

4 years ago

4.9.0

4 years ago

4.9.1

4 years ago

4.8.0

4 years ago

4.7.1

4 years ago

4.7.0

4 years ago

4.6.0

4 years ago

4.5.1

4 years ago

4.5.0

4 years ago

4.4.0

4 years ago

4.3.1

4 years ago

4.3.0

4 years ago

4.2.0

4 years ago

4.1.0

4 years ago

4.0.0

4 years ago

4.0.0-alpha.1

4 years ago

4.0.0-alpha.0

4 years ago

3.10.0

5 years ago

3.9.2

5 years ago

3.9.1

5 years ago

3.9.0

5 years ago

3.8.1

5 years ago

3.8.0

5 years ago

3.7.0

5 years ago

3.6.0

5 years ago

3.5.3

5 years ago

3.5.2

5 years ago

3.5.1

5 years ago

3.5.0

5 years ago

3.4.0

5 years ago

3.3.4

5 years ago

3.3.3

5 years ago

3.3.2

5 years ago

3.3.1

5 years ago

3.3.0

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.8

5 years ago

3.1.7

5 years ago

3.1.6

5 years ago

3.1.5

5 years ago

3.1.4

5 years ago

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1-beta.0

5 years ago

3.1.0

5 years ago

3.1.0-beta.3

5 years ago

3.1.0-beta.2

5 years ago

3.1.0-beta.1

5 years ago

3.1.0-beta

5 years ago

3.0.0

5 years ago

3.0.0-beta.6

5 years ago

3.0.0-beta.5

5 years ago

3.0.0-beta.4

5 years ago

3.0.0-beta.3

5 years ago

3.0.0-beta.2

5 years ago

3.0.0-beta.1

5 years ago

3.0.0-beta.0

5 years ago

0.6.0-beta.8

5 years ago

0.6.0-beta.7

5 years ago

0.6.0-beta.6

5 years ago

0.6.0-beta.5

5 years ago

0.6.0-beta.4

5 years ago

0.6.0-beta.3

5 years ago

0.6.0-beta.2

5 years ago

0.6.0-beta.1

5 years ago

0.6.0-beta.0

5 years ago

0.5.2-rc

5 years ago

0.5.2

5 years ago

0.5.1-rc.3

5 years ago

0.5.1-rc.2

5 years ago

0.5.1-rc

5 years ago

0.5.0-rc

5 years ago

0.4.0-rc.3

5 years ago

0.4.0-rc.1

5 years ago

0.3.45

5 years ago

0.3.44

5 years ago

0.3.43

5 years ago

0.3.42

5 years ago

0.3.41

5 years ago

0.3.40

5 years ago

0.3.39

5 years ago

0.3.37

5 years ago

0.3.36

5 years ago

0.3.35

5 years ago

0.3.34

5 years ago

0.3.33

5 years ago

0.3.32

5 years ago

0.3.31

5 years ago

0.3.30

6 years ago

0.3.28

6 years ago

0.3.27

6 years ago

0.3.26

6 years ago

0.3.25

6 years ago

0.3.24

6 years ago

0.3.23

6 years ago

0.3.21

6 years ago

0.3.20

6 years ago

0.3.19

6 years ago

0.3.18

6 years ago

0.3.17

6 years ago

0.3.16

6 years ago

0.3.15

6 years ago

0.3.14

6 years ago

0.3.13

6 years ago

0.3.12

6 years ago

0.3.11

6 years ago

0.3.10

6 years ago

0.3.9

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago