-
Notifications
You must be signed in to change notification settings - Fork 327
LLC:hw
live-common libraries centralizes Ledger hardware wallet device logic via exposing many functions in src/hw
.
Most of these functions share one of these signature:
(Transport, ...) => Promise<...>
(Transport, ...) => Observable<...>
They take a Transport (a communication layer), potentially some parameters, will run logic with the device transport and will eventually return a result (it's asynchronous).
Many ways to communicate with our device exists as shown by the many implementations we have in ledgerjs.
To faciliate this fact, live-common unifies a modular and multi-transport system that allows to register some "transport modules" using registerTransportModule
(typically in your live-common-setup.js
). When you need to access a transport, you can use the generic open(id)
function OR if you need a race condition protection, you can use withDevice(id)(job)
where job
is a (t: typeof Transport) => Observable<T>
.
This is on userland to glue everything together, for instance:
import { from } from "rxjs";
import TransportWebHID from "@ledgerhq/hw-transport-webhid";
import TransportWebUSB from "@ledgerhq/hw-transport-webusb";
import { registerTransportModule } from "@ledgerhq/live-common/lib/hw";
import { withDevice } from "@ledgerhq/live-common/lib/hw/deviceAccess";
import getAddress from "@ledgerhq/live-common/lib/hw/getAddress";
/*
example_verifyAnAddress({
deviceId: "webhid",
currency: getCryptoCurrencyById("bitcoin"),
derivationMode: "",
path: "44'/0'/0'/0/0"
})
*/
function example_verifyAnAddress({ deviceId, currency, derivationMode, path }) {
withDevice(deviceId)(t =>
from(
getAddress(t, {
currency,
derivationMode,
path,
verify: true
})
)
).subscribe(
addrResult => console.log(addrResult),
error => console.error(error)
);
}
// setup the transport
registerTransportModule({
id: "webhid",
open: (id: string): ?Promise<*> => {
if (id.startsWith("webhid")) {
return TransportWebHID.create();
}
return null;
}
});
const webusbDevices = {};
registerTransportModule({
id: "webusb",
open: (id: string): ?Promise<*> => {
if (id.startsWith("webusb")) {
const existingDevice = webusbDevices[id];
return existingDevice
? TransportWebUSB.open(existingDevice)
: typeof TransportWebUSB.create();
}
return null;
}
});
TO BE DOCUMENTED. list out every src/hw that are interesting to cover and document quickly?
- Ledger Live Desktop
- Ledger Live Mobile
-
Ledger Live Common
- Introduction
- Currency Models
- Currency Bridge
- Account
- Account Bridge
- apps
- appsCheckAllAppVersions
- ledger-live bot
- Canonical Ways to Investigate Bugs
- Coin Integration Introduction
- Countervalues
- Packages Duplicates
- Derivation
- Developing with CLI
- Developing
- Gist Firmware Update
- Gist Transaction
- Hardware Wallet Logic
- Socket
- Assorted tips
- Integration Tests
- Process
- Monorepository Migration Guide
- Issues, Workaround and Tricks
- Common CI Troubleshooting
- Create staging builds using the CI
- Deprecated