GithubHelp home page GithubHelp logo

isabella232 / lib-ledger-core-react-native-bindings Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ledgerhq/lib-ledger-core-react-native-bindings

0.0 0.0 0.0 5.54 MB

JavaScript 0.01% Makefile 0.01% Python 0.04% Java 37.92% C++ 15.12% Objective-C 35.80% Objective-C++ 9.75% Shell 0.05% Scala 1.28% Ruby 0.03%

lib-ledger-core-react-native-bindings's Introduction

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

lib-ledger-core-react-native-bindings's People

Contributors

alekece avatar barjonr avatar gagbo avatar gre avatar haammar-ledger avatar henri-ly avatar hzheng-ledger avatar juan-cortes avatar khalilbellakrid avatar lfbarreto avatar llehmann-ledger avatar meriadec avatar mortalkastor avatar phaazon avatar pollastri-pierre avatar teams2ua avatar valpinkman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.