trufflesuite / drizzle-legacy

Reactive Ethereum datastore for dapp UIs.
http://truffleframework.com/docs/drizzle/getting-started
MIT License
503 stars 128 forks source link

Support hardware wallets #137

Closed adrianmcli closed 5 years ago

adrianmcli commented 5 years ago

n/t

Ledger seems to already provide a Web3 provider, so it shouldn't be too hard?

Wallets we would like to support: Ledger, Trezor, Keepkey

soundyogi commented 5 years ago

metamask supports ledger and trezor now

adrianmcli commented 5 years ago

@soundyogi Yea, we're aware of this too. Just need to test it and make any necessary tweaks. Are you saying that it already works now (with the current Drizzle)?

soundyogi commented 5 years ago

I am upgrading our dapp to drizzle and the new metamask provider.enable() system. So I cant report until I got it to work.

But I succesfully used my ledger via metamask using the old standard web3/metamask provider combo. So I dont see why it should not work (via metamask at least) since metamask abstracts the ledger away using its provider.

Of course pure ledger support without metamask is something different, but should be as you said very possible.

Sorry for this half-assed input :_D

I havent tried to use the ledger with using drizzle only. But will try to test it this week.

soundyogi commented 5 years ago

This looks quite helpful but also outdated: https://gist.github.com/gre/93fc39242c31a23c0570e71cc33bed5a

there are a few third party libs on npm. I will look into it further this week.

joshma91 commented 5 years ago

I've been trying to make Drizzle work purely with Ledger for the past few days but there's issues with Ganache that won't allow clean Ledger integration with Drizzle.

I adapted the gist that @soundyogi linked to into web3Saga.js within the initializeWeb3 function and I'm able to hand Drizzle the web3 that the Ledger provides. I'm able to access the full drizzle and drizzleState instances and can sign transactions issued through this.props.drizzle.web3.eth.sendRawTransaction in child components as well:

    try {
      const result = yield eth.getAddress("m/44'/60'/0'/0/0")
      console.log("I'm inside Drizzle!")
      if (result !== null) {
        const engine = new ProviderEngine()
        const getTransport = () => Transport.create()
        const ledger = createLedgerSubprovider(getTransport, {
          networkId,
          accountsLength: 5
        })
        console.log(ledger)
        engine.addProvider(ledger)
        engine.addProvider(new FetchSubprovider({ rpcUrl }))
        engine.start()
        return new Web3(engine)
      }
    } catch (error) {
      console.log(error)
    }

The issue comes when a new block arrives in Ganache. Ganache will crash with the following error:

TypeError: Cannot read property 'connection' of undefined
    at c._updateSubscriptions (/home/josh/.npm-packages/lib/node_modules/ganache-cli/build/cli.node.js:65:5443)
    at l.<anonymous> (/home/josh/.npm-packages/lib/node_modules/ganache-cli/build/cli.node.js:65:3860)
    at emitTwo (events.js:126:13)
    at l.emit (events.js:214:7)
    at o.<anonymous> (/home/josh/.npm-packages/lib/node_modules/ganache-cli/build/cli.node.js:37:29806)
    at emitTwo (events.js:126:13)
    at o.emit (events.js:214:7)
    at o._notificationHandler (/home/josh/.npm-packages/lib/node_modules/ganache-cli/build/cli.node.js:149:96040)

So I'm only able to have the things above working when I initialize Ganache with a really long block time (e.g. ganache-cli -b 200) since the arrival of a new block breaks everything. I'm going to raise an issue with Ganache as well, and I wonder if it's at all linked to this issue. What's curious is that Ledger and Drizzle have individually worked with Ganache for me. It's only once I bring all 3 in together that things break.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

This issue has been closed, but can be re-opened if further comments indicate that the problem persists. Feel free to tag maintainers if there is no reply to further comments.