Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Split the projects into scoped libs + improve API doc #37

Merged
merged 74 commits into from
Jan 22, 2018
Merged

Conversation

gre
Copy link
Contributor

@gre gre commented Jan 10, 2018

This is a major refactoring on the project to split the library into multiple libraries.

new packages

We are introducing new libraries to replace the monolithic ledgerco.

to migrate, you will need to depend on the relevant packages instead of ledgerco. This will lighten your dependencies because ledgerco used to depend both on node-hid and u2f-api.

There is also new packages included (documented in the README.md and the API.md)

packages:

Package Version Description
@ledgerhq/hw-app-eth npm Ethereum Application API
@ledgerhq/hw-app-btc npm Bitcoin Application API
@ledgerhq/hw-transport-node-hid npm Node implementation of the communication layer, using node-hid (USB)
@ledgerhq/hw-transport-u2f npm Web implementation of the communication layer, using U2F api
@ledgerhq/hw-transport-http npm communicate to the device over HTTP
@ledgerhq/hw-transport npm The generic interface of the communication layer
@ledgerhq/hw-http-proxy-devserver npm DEVELOPMENT-only http server to communicate with the device with hw-transport-node-hid (bridge proxy for hw-transport)

api changes

There is also one more breaking change from the previous API: the _async suffix has been REMOVED in all methods of the APIs. The library is by nature asynchronous and it's common practice to do so in JS promise libraries. We also highly recommend you to use async/await babel transformer to make your code much simpler.

BEFORE

const ledger = require("ledgerco");
function example() {
  ledger.comm_node.create_async().then(function(comm) {
    var btc = ledger.btc(comm);
    btc.getWalletPublicKey_async("44'/0'/0'/0").then(
       function(result) { console.log(result);}).catch(
       function(error) { console.log(error); });
  });
}

AFTER

var Comm = require("@ledgerhq/hw-transport-node-hid"); // node
// OR
var Comm = require("@ledgerhq/hw-transport-u2f"); // web

var Btc = require("@ledgerhq/hw-app-btc");

function example() {
  Comm.list().then(devices => Comm.open(devices[0])).then(function(comm) {
    var btc = new Btc(comm);
    return btc.getWalletPublicKey("44'/0'/0'/0");
  }).then(function(result) {
    console.log(result);
  });
}

AFTER (modern)

import Comm from "@ledgerhq/hw-transport-node-hid"; // node
// OR
import Comm from "@ledgerhq/hw-transport-u2f"; // web

import Btc from "@ledgerhq/hw-app-btc";

async function example() {
  const devices = await Comm.list();
  const comm = await Comm.open(devices[0]);
  const btc = new Btc(comm);
  const result = await btc.getWalletPublicKey("44'/0'/0'/0");
  console.log(result);
}

create transport function is deprecated

Instead you should use list and discover and then use open.

open transport function creates the transport (async)

listen new transport function

We are also introducing a listen function in Transport implementations which is an alternative to list and allow to discover device as they come. It takes an observer and returns a subscription, as in this spec: https://github.com/tc39/proposal-observable . More examples will come later and implementation is yet to be fully implemented.

This is the first milestone for Ledger libs, we will have important other milestone soon! Cheers :)

@gre gre mentioned this pull request Jan 10, 2018
@gre gre mentioned this pull request Jan 21, 2018
@gre gre merged commit 0c5e510 into master Jan 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants