ethers.js/packages/hardware-wallets/src.ts/ledger-transport.ts

30 lines
800 B
TypeScript
Raw Normal View History

"use strict";
export type TransportCreator = {
create: () => Promise<Transport>;
};
let hidCache: Promise<typeof import("@ledgerhq/hw-transport-node-hid")> = null;
const hidWrapper = Object.freeze({
create: function(): Promise<Transport> {
// Load the library if not loaded
if (hidCache == null) {
hidCache = import("@ledgerhq/hw-transport-node-hid").then((hid) => {
if (hid.create == null) { return hid["default"]; }
return hid;
});
}
return hidCache.then((hid) => {
console.log(hid, hid.create);
return hid.create()
});
}
});
export const transports: { [ name: string ]: TransportCreator } = Object.freeze({
"hid": hidWrapper,
"default": hidWrapper
});