LedgerHQ / ledgerjs

⛔️ MOVED to monorepo "ledger-live"
https://github.com/LedgerHQ/ledger-live
Apache License 2.0
575 stars 377 forks source link

Node cannot use the library to connect, error `TransportNodeHid.open is not a function` #580

Open blewater opened 3 years ago

blewater commented 3 years ago

Hi, I have tried with Node v14,15 in ubuntu, macos with the same results. I cannot run the basic example listed:

import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
import AppBtc from "@ledgerhq/hw-app-btc";
const getBtcAddress = async () => {
  console.log(TransportNodeHid);
  /*
 {
  default: [class TransportNodeHid extends TransportNodeHidNoEvents] {
    isSupported: [Function (anonymous)],
    list: [Function (anonymous)],
    setListenDevicesDebounce: [Function (anonymous)],
    setListenDevicesPollingSkip: [Function (anonymous)],
    setListenDevicesDebug: [Function (anonymous)],
    listen: [Function (anonymous)]
  }
}
 */
  const transport = await TransportNodeHid.open(''); // Same with create()
  // (node:88348) UnhandledPromiseRejectionWarning: TypeError: TransportNodeHid.open is not a function
  const btc = new AppBtc(transport);
  const result = await btc.getWalletPublicKey("44'/0'/0'/0/0");
  return result.bitcoinAddress;
};
getBtcAddress().then((a) => console.log(a));

I see a similar closed issue #140 without a satisfying resolution.

from package.json:

  "dependencies": {
    "@cosmjs/ledger-amino": "^0.24.1",
    "@cosmjs/proto-signing": "^0.24.1",
    "@cosmjs/stargate": "^0.24.1",
    "@cosmjs/tendermint-rpc": "^0.24.1",
    "@ledgerhq/hw-app-btc": "^5.46.0",
    "@ledgerhq/hw-transport-node-hid": "^5.46.0",
    "make-lint": "^1.0.1"
  },
  "devDependencies": {
    "eslint": "^7.22.0",
    "eslint-config-standard": "^16.0.2",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.3.1",
    "prettier": "2.2.1"
  }

Can you help us out to use the library? Thanks

blewater commented 3 years ago

It is the default export. For Javascript use:

import { default as TransportNodeMod } from '@ledgerhq/hw-transport-node-hid';
const TransportNodeHid = TransportNodeMod.default;

For typescript, the following hack would do unless addressed at the source:

// ./src based path
import TransportModule from '../node_modules/@ledgerhq/hw-transport-node-hid/lib/TransportNodeHid.js';
const transport = TransportModule.default;