ethers-io / ethers-ledger

Deprecated; please see `@ethersproject/hardware-wallets` instead
https://github.com/ethers-io/ethers.js/tree/ethers-v5-beta/packages/hardware-wallets
13 stars 11 forks source link

Unable to get it to work in Angular #3

Closed Jeroen96 closed 2 years ago

Jeroen96 commented 5 years ago

Hi,

I'm trying to get this package to work so i can use ethers.js in combination with an Ledger Nano S. I'm however unable to get this package to work in Angular. I've tried multiple things like importing it in TS according to the README or adding the .dist to the scripts array and using it like that.

import { LedgerSigner } from 'ledger-signer';
// import { LedgerSigner } from 'ethers-ledger';
// declare const LedgerSigner: any;

accessing the LedgerSigner from the ethers object returns a undefined.

NoahMarconi commented 4 years ago

Any luck with this one?

Jeroen96 commented 4 years ago

I wasn't able to get the base package as it is to work. I however took the source and removed all the node.js server related dependencies. Apart from that i had to fix a couple of things related to the ledger libraries.

You have to add the following to your polyfills.ts

// Fix for Ledger libraries #1 (https://github.com/LedgerHQ/ledgerjs/issues/332)
import 'regenerator-runtime/runtime';

// Fix for Ledger libraries #2 (https://github.com/LedgerHQ/ledgerjs/issues/392)
(window as any).global = window;
// @ts-ignore
window.Buffer = window.Buffer || require('buffer').Buffer;
NoahMarconi commented 4 years ago

Thanks for the tip! I only needed ledger for signing messages so I was able to use the ledger npm packages directly after adding your polyfills:

import TransportU2F from '@ledgerhq/hw-transport-u2f';
import Eth from '@ledgerhq/hw-app-eth';

***SNIP***

    const transport = await TransportU2F.create();
    const eth = new Eth(transport);
    const { address } = await eth.getAddress("44'/60'/0'/0'/0");
    console.log(address);
    console.log(await eth.signPersonalMessage("44'/60'/0'/0/0", Buffer.from("test").toString("hex")));
ricmoo commented 4 years ago

This package is a bit old, and I'm not sure how reliable it is. I didn't bring my Ledge with me (I'm home for the holidays) since I only use it for testing. Once I'm back, I'll break it out and get this package up-to-date and v5 compatible.

I also need to ping someone at KeepKey and Trezor to see if I can snag some test devices so we can get wider Hardware Wallet support... Are there any others that are common?

Firefly will of course be supported once I finish the new and improved firmware. :)

NoahMarconi commented 4 years ago

Awesome, enjoy the holidays! I'll stay subscribed to this thread to watch for v5 updates.

ricmoo commented 4 years ago

The new @ethersproject/hardware-wallets package should now work for both node (using hid) and the browser (using u2f).

Preliminary docs are here: https://docs-beta.ethers.io/api/other/hardware/#ledgersigner

This package is now managed through the umbrella ethers v5 repository, so this repo will be deprecated. This should also help keep all issues closer together. :)