ethers.js/packages/hardware-wallets/lib.esm/ledger-transport.js

36 lines
1.0 KiB
JavaScript
Raw Normal View History

2020-01-10 11:19:21 +03:00
"use strict";
2020-04-25 10:54:54 +03:00
let hidCache = null;
const hidWrapper = Object.freeze({
create: function () {
// Load the library if not loaded
if (hidCache == null) {
hidCache = new Promise((resolve, reject) => {
try {
let hid = require("@ledgerhq/hw-transport-node-hid");
if (hid.create == null) {
resolve(hid["default"]);
}
resolve(hid);
}
catch (error) {
reject(error);
}
});
/*
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 = Object.freeze({
"hid": hidWrapper,
"default": hidWrapper
});