LedgerHQ / ledgerjs

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

Legerjs with Angular #225

Closed plazav closed 6 years ago

plazav commented 6 years ago

Can not configure Ledgerjs for working with hw-transport-u2f Here is official sample

 import TransportU2F from "@ledgerhq/hw-transport-u2f";
 TransportU2F.create().then(transport => ...)

Here is how I am trying

TransportU2F.create().then(transport => {
  const subscriber = transport.listen(n =>{
    transport.open(n.device.path)
    .then(trans => {

      });
    });
  });

But it is not even clear at what moment transport listen should be fired. I have tried to connect Ledger, to enter application... May be that is wrong code?

gre commented 6 years ago

I'm not understanding your code and it's not going to work: e.g. listen take an observer.

create() actually already use listen and open under the hood https://github.com/LedgerHQ/ledgerjs/blob/c22d3f24fcd5e4f17996ab6766d747fc2cc62dbd/packages/hw-transport/src/Transport.js#L285

So you just need create() , it is the simplest possible API.

Also in context of u2f, you have no way knowing if a device connect or disconnect, so if you were looking for this, it's unfortunate (hopefully webusb will fix it) and the only way is to pull&retry create() until it succeed.

plazav commented 6 years ago

Thank you! That was helpful!