@ledgerhq/hw-transport-node-hid
Advanced tools
Comparing version 6.27.13 to 6.27.14-nightly.0
# @ledgerhq/hw-transport-node-hid | ||
## 6.27.14-nightly.0 | ||
### Patch Changes | ||
- Updated dependencies [[`87d2349fd8`](https://github.com/LedgerHQ/ledger-live/commit/87d2349fd835e5deb39d1ee8dfcf3539f4195472)]: | ||
- @ledgerhq/errors@6.12.5-nightly.0 | ||
- @ledgerhq/devices@8.0.2-nightly.0 | ||
- @ledgerhq/hw-transport@6.28.3-nightly.0 | ||
- @ledgerhq/hw-transport-node-hid-noevents@6.27.14-nightly.0 | ||
## 6.27.13 | ||
@@ -4,0 +14,0 @@ |
@@ -1,26 +0,1 @@ | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
import EventEmitter from "events"; | ||
@@ -31,18 +6,18 @@ import { getDevices } from "@ledgerhq/hw-transport-node-hid-noevents"; | ||
import debounce from "lodash/debounce"; | ||
export default (function (delay, listenDevicesPollingSkip) { | ||
var events = new EventEmitter(); | ||
export default (delay, listenDevicesPollingSkip) => { | ||
const events = new EventEmitter(); | ||
events.setMaxListeners(0); | ||
var listDevices = getDevices(); | ||
var flatDevice = function (d) { return d.path; }; | ||
var getFlatDevices = function () { return __spreadArray([], __read(new Set(getDevices().map(function (d) { return flatDevice(d); }))), false); }; | ||
var getDeviceByPaths = function (paths) { | ||
return listDevices.find(function (d) { return paths.includes(flatDevice(d)); }); | ||
}; | ||
var lastDevices = getFlatDevices(); | ||
var poll = function () { | ||
let listDevices = getDevices(); | ||
const flatDevice = (d) => d.path; | ||
const getFlatDevices = () => [ | ||
...new Set(getDevices().map((d) => flatDevice(d))), | ||
]; | ||
const getDeviceByPaths = (paths) => listDevices.find((d) => paths.includes(flatDevice(d))); | ||
let lastDevices = getFlatDevices(); | ||
const poll = () => { | ||
if (!listenDevicesPollingSkip()) { | ||
log("hid-listen", "Polling for added or removed devices"); | ||
var changeFound = false; | ||
var currentDevices_1 = getFlatDevices(); | ||
var newDevices = currentDevices_1.filter(function (d) { return !lastDevices.includes(d); }); | ||
let changeFound = false; | ||
const currentDevices = getFlatDevices(); | ||
const newDevices = currentDevices.filter((d) => !lastDevices.includes(d)); | ||
if (newDevices.length > 0) { | ||
@@ -57,7 +32,7 @@ log("hid-listen", "New device found:", newDevices); | ||
} | ||
var removeDevices_1 = lastDevices.filter(function (d) { return !currentDevices_1.includes(d); }); | ||
if (removeDevices_1.length > 0) { | ||
log("hid-listen", "Removed device found:", removeDevices_1); | ||
events.emit("remove", getDeviceByPaths(removeDevices_1)); | ||
listDevices = listDevices.filter(function (d) { return !removeDevices_1.includes(flatDevice(d)); }); | ||
const removeDevices = lastDevices.filter((d) => !currentDevices.includes(d)); | ||
if (removeDevices.length > 0) { | ||
log("hid-listen", "Removed device found:", removeDevices); | ||
events.emit("remove", getDeviceByPaths(removeDevices)); | ||
listDevices = listDevices.filter((d) => !removeDevices.includes(flatDevice(d))); | ||
changeFound = true; | ||
@@ -69,3 +44,3 @@ } | ||
if (changeFound) { | ||
lastDevices = currentDevices_1; | ||
lastDevices = currentDevices; | ||
} | ||
@@ -78,4 +53,4 @@ } | ||
}; | ||
var debouncedPoll = debounce(poll, delay); | ||
var attachDetected = function (device) { | ||
const debouncedPoll = debounce(poll, delay); | ||
const attachDetected = (device) => { | ||
log("hid-listen", "Device add detected:", device); | ||
@@ -86,3 +61,3 @@ debouncedPoll(); | ||
log("hid-listen", "attach listener added"); | ||
var detachDetected = function (device) { | ||
const detachDetected = (device) => { | ||
log("hid-listen", "Device removal detected:", device); | ||
@@ -94,3 +69,3 @@ debouncedPoll(); | ||
return { | ||
stop: function () { | ||
stop: () => { | ||
log("hid-listen", "Stop received, removing listeners and cancelling pending debounced polls"); | ||
@@ -101,5 +76,5 @@ debouncedPoll.cancel(); | ||
}, | ||
events: events | ||
events, | ||
}; | ||
}); | ||
}; | ||
//# sourceMappingURL=listenDevices.js.map |
@@ -1,27 +0,1 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
import HID from "node-hid"; | ||
@@ -32,4 +6,4 @@ import TransportNodeHidNoEvents, { getDevices, } from "@ledgerhq/hw-transport-node-hid-noevents"; | ||
import listenDevices from "./listenDevices"; | ||
var listenDevicesDebounce = 500; | ||
var listenDevicesPollingSkip = function () { return false; }; | ||
let listenDevicesDebounce = 500; | ||
let listenDevicesPollingSkip = () => false; | ||
/** | ||
@@ -42,16 +16,12 @@ * node-hid Transport implementation | ||
*/ | ||
var TransportNodeHid = /** @class */ (function (_super) { | ||
__extends(TransportNodeHid, _super); | ||
function TransportNodeHid() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
export default class TransportNodeHid extends TransportNodeHidNoEvents { | ||
/** | ||
* if path="" is not provided, the library will take the first device | ||
*/ | ||
TransportNodeHid.open = function (path) { | ||
return Promise.resolve().then(function () { | ||
static open(path) { | ||
return Promise.resolve().then(() => { | ||
if (path) { | ||
return new TransportNodeHid(new HID.HID(path)); | ||
} | ||
var device = getDevices()[0]; | ||
const device = getDevices()[0]; | ||
if (!device) | ||
@@ -61,97 +31,84 @@ throw new TransportError("NoDevice", "NoDevice"); | ||
}); | ||
} | ||
} | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.isSupported = TransportNodeHidNoEvents.isSupported; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.list = TransportNodeHidNoEvents.list; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.setListenDevicesDebounce = (delay) => { | ||
listenDevicesDebounce = delay; | ||
}; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.setListenDevicesPollingSkip = (conditionToSkip) => { | ||
listenDevicesPollingSkip = conditionToSkip; | ||
}; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.setListenDevicesDebug = () => { | ||
console.warn("setListenDevicesDebug is deprecated. Use @ledgerhq/logs instead. No logs will get emitted there anymore."); | ||
}; | ||
/** | ||
*/ | ||
TransportNodeHid.listen = (observer) => { | ||
let unsubscribed = false; | ||
Promise.resolve(getDevices()).then((devices) => { | ||
// this needs to run asynchronously so the subscription is defined during this phase | ||
for (const device of devices) { | ||
if (!unsubscribed) { | ||
const descriptor = device.path; | ||
const deviceModel = identifyUSBProductId(device.productId); | ||
observer.next({ | ||
type: "add", | ||
descriptor, | ||
device, | ||
deviceModel, | ||
}); | ||
} | ||
} | ||
}); | ||
const { events, stop } = listenDevices(listenDevicesDebounce, listenDevicesPollingSkip); | ||
const onAdd = (device) => { | ||
if (unsubscribed || !device) | ||
return; | ||
const deviceModel = identifyUSBProductId(device.productId); | ||
observer.next({ | ||
type: "add", | ||
descriptor: device.path, | ||
deviceModel, | ||
device, | ||
}); | ||
}; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.isSupported = TransportNodeHidNoEvents.isSupported; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.list = TransportNodeHidNoEvents.list; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.setListenDevicesDebounce = function (delay) { | ||
listenDevicesDebounce = delay; | ||
const onRemove = (device) => { | ||
if (unsubscribed || !device) | ||
return; | ||
const deviceModel = identifyUSBProductId(device.productId); | ||
observer.next({ | ||
type: "remove", | ||
descriptor: device.path, | ||
deviceModel, | ||
device, | ||
}); | ||
}; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.setListenDevicesPollingSkip = function (conditionToSkip) { | ||
listenDevicesPollingSkip = conditionToSkip; | ||
events.on("add", onAdd); | ||
events.on("remove", onRemove); | ||
function unsubscribe() { | ||
unsubscribed = true; | ||
events.removeListener("add", onAdd); | ||
events.removeListener("remove", onRemove); | ||
stop(); | ||
} | ||
return { | ||
unsubscribe, | ||
}; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.setListenDevicesDebug = function () { | ||
console.warn("setListenDevicesDebug is deprecated. Use @ledgerhq/logs instead. No logs will get emitted there anymore."); | ||
}; | ||
/** | ||
*/ | ||
TransportNodeHid.listen = function (observer) { | ||
var unsubscribed = false; | ||
Promise.resolve(getDevices()).then(function (devices) { | ||
var e_1, _a; | ||
try { | ||
// this needs to run asynchronously so the subscription is defined during this phase | ||
for (var devices_1 = __values(devices), devices_1_1 = devices_1.next(); !devices_1_1.done; devices_1_1 = devices_1.next()) { | ||
var device = devices_1_1.value; | ||
if (!unsubscribed) { | ||
var descriptor = device.path; | ||
var deviceModel = identifyUSBProductId(device.productId); | ||
observer.next({ | ||
type: "add", | ||
descriptor: descriptor, | ||
device: device, | ||
deviceModel: deviceModel | ||
}); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (devices_1_1 && !devices_1_1.done && (_a = devices_1["return"])) _a.call(devices_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
}); | ||
var _a = listenDevices(listenDevicesDebounce, listenDevicesPollingSkip), events = _a.events, stop = _a.stop; | ||
var onAdd = function (device) { | ||
if (unsubscribed || !device) | ||
return; | ||
var deviceModel = identifyUSBProductId(device.productId); | ||
observer.next({ | ||
type: "add", | ||
descriptor: device.path, | ||
deviceModel: deviceModel, | ||
device: device | ||
}); | ||
}; | ||
var onRemove = function (device) { | ||
if (unsubscribed || !device) | ||
return; | ||
var deviceModel = identifyUSBProductId(device.productId); | ||
observer.next({ | ||
type: "remove", | ||
descriptor: device.path, | ||
deviceModel: deviceModel, | ||
device: device | ||
}); | ||
}; | ||
events.on("add", onAdd); | ||
events.on("remove", onRemove); | ||
function unsubscribe() { | ||
unsubscribed = true; | ||
events.removeListener("add", onAdd); | ||
events.removeListener("remove", onRemove); | ||
stop(); | ||
} | ||
return { | ||
unsubscribe: unsubscribe | ||
}; | ||
}; | ||
return TransportNodeHid; | ||
}(TransportNodeHidNoEvents)); | ||
export default TransportNodeHid; | ||
}; | ||
//# sourceMappingURL=TransportNodeHid.js.map |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.__esModule = true; | ||
var events_1 = __importDefault(require("events")); | ||
var hw_transport_node_hid_noevents_1 = require("@ledgerhq/hw-transport-node-hid-noevents"); | ||
var logs_1 = require("@ledgerhq/logs"); | ||
var usb_1 = __importDefault(require("usb")); | ||
var debounce_1 = __importDefault(require("lodash/debounce")); | ||
exports["default"] = (function (delay, listenDevicesPollingSkip) { | ||
var events = new events_1["default"](); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const events_1 = __importDefault(require("events")); | ||
const hw_transport_node_hid_noevents_1 = require("@ledgerhq/hw-transport-node-hid-noevents"); | ||
const logs_1 = require("@ledgerhq/logs"); | ||
const usb_1 = __importDefault(require("usb")); | ||
const debounce_1 = __importDefault(require("lodash/debounce")); | ||
exports.default = (delay, listenDevicesPollingSkip) => { | ||
const events = new events_1.default(); | ||
events.setMaxListeners(0); | ||
var listDevices = (0, hw_transport_node_hid_noevents_1.getDevices)(); | ||
var flatDevice = function (d) { return d.path; }; | ||
var getFlatDevices = function () { return __spreadArray([], __read(new Set((0, hw_transport_node_hid_noevents_1.getDevices)().map(function (d) { return flatDevice(d); }))), false); }; | ||
var getDeviceByPaths = function (paths) { | ||
return listDevices.find(function (d) { return paths.includes(flatDevice(d)); }); | ||
}; | ||
var lastDevices = getFlatDevices(); | ||
var poll = function () { | ||
let listDevices = (0, hw_transport_node_hid_noevents_1.getDevices)(); | ||
const flatDevice = (d) => d.path; | ||
const getFlatDevices = () => [ | ||
...new Set((0, hw_transport_node_hid_noevents_1.getDevices)().map((d) => flatDevice(d))), | ||
]; | ||
const getDeviceByPaths = (paths) => listDevices.find((d) => paths.includes(flatDevice(d))); | ||
let lastDevices = getFlatDevices(); | ||
const poll = () => { | ||
if (!listenDevicesPollingSkip()) { | ||
(0, logs_1.log)("hid-listen", "Polling for added or removed devices"); | ||
var changeFound = false; | ||
var currentDevices_1 = getFlatDevices(); | ||
var newDevices = currentDevices_1.filter(function (d) { return !lastDevices.includes(d); }); | ||
let changeFound = false; | ||
const currentDevices = getFlatDevices(); | ||
const newDevices = currentDevices.filter((d) => !lastDevices.includes(d)); | ||
if (newDevices.length > 0) { | ||
@@ -61,7 +36,7 @@ (0, logs_1.log)("hid-listen", "New device found:", newDevices); | ||
} | ||
var removeDevices_1 = lastDevices.filter(function (d) { return !currentDevices_1.includes(d); }); | ||
if (removeDevices_1.length > 0) { | ||
(0, logs_1.log)("hid-listen", "Removed device found:", removeDevices_1); | ||
events.emit("remove", getDeviceByPaths(removeDevices_1)); | ||
listDevices = listDevices.filter(function (d) { return !removeDevices_1.includes(flatDevice(d)); }); | ||
const removeDevices = lastDevices.filter((d) => !currentDevices.includes(d)); | ||
if (removeDevices.length > 0) { | ||
(0, logs_1.log)("hid-listen", "Removed device found:", removeDevices); | ||
events.emit("remove", getDeviceByPaths(removeDevices)); | ||
listDevices = listDevices.filter((d) => !removeDevices.includes(flatDevice(d))); | ||
changeFound = true; | ||
@@ -73,3 +48,3 @@ } | ||
if (changeFound) { | ||
lastDevices = currentDevices_1; | ||
lastDevices = currentDevices; | ||
} | ||
@@ -82,25 +57,25 @@ } | ||
}; | ||
var debouncedPoll = (0, debounce_1["default"])(poll, delay); | ||
var attachDetected = function (device) { | ||
const debouncedPoll = (0, debounce_1.default)(poll, delay); | ||
const attachDetected = (device) => { | ||
(0, logs_1.log)("hid-listen", "Device add detected:", device); | ||
debouncedPoll(); | ||
}; | ||
usb_1["default"].on("attach", attachDetected); | ||
usb_1.default.on("attach", attachDetected); | ||
(0, logs_1.log)("hid-listen", "attach listener added"); | ||
var detachDetected = function (device) { | ||
const detachDetected = (device) => { | ||
(0, logs_1.log)("hid-listen", "Device removal detected:", device); | ||
debouncedPoll(); | ||
}; | ||
usb_1["default"].on("detach", detachDetected); | ||
usb_1.default.on("detach", detachDetected); | ||
(0, logs_1.log)("hid-listen", "detach listener added"); | ||
return { | ||
stop: function () { | ||
stop: () => { | ||
(0, logs_1.log)("hid-listen", "Stop received, removing listeners and cancelling pending debounced polls"); | ||
debouncedPoll.cancel(); | ||
usb_1["default"].removeListener("attach", attachDetected); | ||
usb_1["default"].removeListener("detach", detachDetected); | ||
usb_1.default.removeListener("attach", attachDetected); | ||
usb_1.default.removeListener("detach", detachDetected); | ||
}, | ||
events: events | ||
events, | ||
}; | ||
}); | ||
}; | ||
//# sourceMappingURL=listenDevices.js.map |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
@@ -40,24 +25,13 @@ if (k2 === undefined) k2 = k; | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.__esModule = true; | ||
var node_hid_1 = __importDefault(require("node-hid")); | ||
var hw_transport_node_hid_noevents_1 = __importStar(require("@ledgerhq/hw-transport-node-hid-noevents")); | ||
var devices_1 = require("@ledgerhq/devices"); | ||
var errors_1 = require("@ledgerhq/errors"); | ||
var listenDevices_1 = __importDefault(require("./listenDevices")); | ||
var listenDevicesDebounce = 500; | ||
var listenDevicesPollingSkip = function () { return false; }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const node_hid_1 = __importDefault(require("node-hid")); | ||
const hw_transport_node_hid_noevents_1 = __importStar(require("@ledgerhq/hw-transport-node-hid-noevents")); | ||
const devices_1 = require("@ledgerhq/devices"); | ||
const errors_1 = require("@ledgerhq/errors"); | ||
const listenDevices_1 = __importDefault(require("./listenDevices")); | ||
let listenDevicesDebounce = 500; | ||
let listenDevicesPollingSkip = () => false; | ||
/** | ||
@@ -70,115 +44,99 @@ * node-hid Transport implementation | ||
*/ | ||
var TransportNodeHid = /** @class */ (function (_super) { | ||
__extends(TransportNodeHid, _super); | ||
function TransportNodeHid() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
class TransportNodeHid extends hw_transport_node_hid_noevents_1.default { | ||
/** | ||
* if path="" is not provided, the library will take the first device | ||
*/ | ||
TransportNodeHid.open = function (path) { | ||
return Promise.resolve().then(function () { | ||
static open(path) { | ||
return Promise.resolve().then(() => { | ||
if (path) { | ||
return new TransportNodeHid(new node_hid_1["default"].HID(path)); | ||
return new TransportNodeHid(new node_hid_1.default.HID(path)); | ||
} | ||
var device = (0, hw_transport_node_hid_noevents_1.getDevices)()[0]; | ||
const device = (0, hw_transport_node_hid_noevents_1.getDevices)()[0]; | ||
if (!device) | ||
throw new errors_1.TransportError("NoDevice", "NoDevice"); | ||
return new TransportNodeHid(new node_hid_1["default"].HID(device.path)); | ||
return new TransportNodeHid(new node_hid_1.default.HID(device.path)); | ||
}); | ||
} | ||
} | ||
exports.default = TransportNodeHid; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.isSupported = hw_transport_node_hid_noevents_1.default.isSupported; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.list = hw_transport_node_hid_noevents_1.default.list; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.setListenDevicesDebounce = (delay) => { | ||
listenDevicesDebounce = delay; | ||
}; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.setListenDevicesPollingSkip = (conditionToSkip) => { | ||
listenDevicesPollingSkip = conditionToSkip; | ||
}; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.setListenDevicesDebug = () => { | ||
console.warn("setListenDevicesDebug is deprecated. Use @ledgerhq/logs instead. No logs will get emitted there anymore."); | ||
}; | ||
/** | ||
*/ | ||
TransportNodeHid.listen = (observer) => { | ||
let unsubscribed = false; | ||
Promise.resolve((0, hw_transport_node_hid_noevents_1.getDevices)()).then((devices) => { | ||
// this needs to run asynchronously so the subscription is defined during this phase | ||
for (const device of devices) { | ||
if (!unsubscribed) { | ||
const descriptor = device.path; | ||
const deviceModel = (0, devices_1.identifyUSBProductId)(device.productId); | ||
observer.next({ | ||
type: "add", | ||
descriptor, | ||
device, | ||
deviceModel, | ||
}); | ||
} | ||
} | ||
}); | ||
const { events, stop } = (0, listenDevices_1.default)(listenDevicesDebounce, listenDevicesPollingSkip); | ||
const onAdd = (device) => { | ||
if (unsubscribed || !device) | ||
return; | ||
const deviceModel = (0, devices_1.identifyUSBProductId)(device.productId); | ||
observer.next({ | ||
type: "add", | ||
descriptor: device.path, | ||
deviceModel, | ||
device, | ||
}); | ||
}; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.isSupported = hw_transport_node_hid_noevents_1["default"].isSupported; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.list = hw_transport_node_hid_noevents_1["default"].list; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.setListenDevicesDebounce = function (delay) { | ||
listenDevicesDebounce = delay; | ||
const onRemove = (device) => { | ||
if (unsubscribed || !device) | ||
return; | ||
const deviceModel = (0, devices_1.identifyUSBProductId)(device.productId); | ||
observer.next({ | ||
type: "remove", | ||
descriptor: device.path, | ||
deviceModel, | ||
device, | ||
}); | ||
}; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.setListenDevicesPollingSkip = function (conditionToSkip) { | ||
listenDevicesPollingSkip = conditionToSkip; | ||
events.on("add", onAdd); | ||
events.on("remove", onRemove); | ||
function unsubscribe() { | ||
unsubscribed = true; | ||
events.removeListener("add", onAdd); | ||
events.removeListener("remove", onRemove); | ||
stop(); | ||
} | ||
return { | ||
unsubscribe, | ||
}; | ||
/** | ||
* | ||
*/ | ||
TransportNodeHid.setListenDevicesDebug = function () { | ||
console.warn("setListenDevicesDebug is deprecated. Use @ledgerhq/logs instead. No logs will get emitted there anymore."); | ||
}; | ||
/** | ||
*/ | ||
TransportNodeHid.listen = function (observer) { | ||
var unsubscribed = false; | ||
Promise.resolve((0, hw_transport_node_hid_noevents_1.getDevices)()).then(function (devices) { | ||
var e_1, _a; | ||
try { | ||
// this needs to run asynchronously so the subscription is defined during this phase | ||
for (var devices_2 = __values(devices), devices_2_1 = devices_2.next(); !devices_2_1.done; devices_2_1 = devices_2.next()) { | ||
var device = devices_2_1.value; | ||
if (!unsubscribed) { | ||
var descriptor = device.path; | ||
var deviceModel = (0, devices_1.identifyUSBProductId)(device.productId); | ||
observer.next({ | ||
type: "add", | ||
descriptor: descriptor, | ||
device: device, | ||
deviceModel: deviceModel | ||
}); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (devices_2_1 && !devices_2_1.done && (_a = devices_2["return"])) _a.call(devices_2); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
}); | ||
var _a = (0, listenDevices_1["default"])(listenDevicesDebounce, listenDevicesPollingSkip), events = _a.events, stop = _a.stop; | ||
var onAdd = function (device) { | ||
if (unsubscribed || !device) | ||
return; | ||
var deviceModel = (0, devices_1.identifyUSBProductId)(device.productId); | ||
observer.next({ | ||
type: "add", | ||
descriptor: device.path, | ||
deviceModel: deviceModel, | ||
device: device | ||
}); | ||
}; | ||
var onRemove = function (device) { | ||
if (unsubscribed || !device) | ||
return; | ||
var deviceModel = (0, devices_1.identifyUSBProductId)(device.productId); | ||
observer.next({ | ||
type: "remove", | ||
descriptor: device.path, | ||
deviceModel: deviceModel, | ||
device: device | ||
}); | ||
}; | ||
events.on("add", onAdd); | ||
events.on("remove", onRemove); | ||
function unsubscribe() { | ||
unsubscribed = true; | ||
events.removeListener("add", onAdd); | ||
events.removeListener("remove", onRemove); | ||
stop(); | ||
} | ||
return { | ||
unsubscribe: unsubscribe | ||
}; | ||
}; | ||
return TransportNodeHid; | ||
}(hw_transport_node_hid_noevents_1["default"])); | ||
exports["default"] = TransportNodeHid; | ||
}; | ||
//# sourceMappingURL=TransportNodeHid.js.map |
{ | ||
"name": "@ledgerhq/hw-transport-node-hid", | ||
"version": "6.27.13", | ||
"version": "6.27.14-nightly.0", | ||
"description": "Ledger Hardware Wallet Node implementation of the communication layer, using node-hid", | ||
@@ -33,6 +33,6 @@ "keywords": [ | ||
"usb": "^1.7.0", | ||
"@ledgerhq/devices": "^8.0.1", | ||
"@ledgerhq/errors": "^6.12.4", | ||
"@ledgerhq/hw-transport": "^6.28.2", | ||
"@ledgerhq/hw-transport-node-hid-noevents": "^6.27.13", | ||
"@ledgerhq/devices": "^8.0.2-nightly.0", | ||
"@ledgerhq/errors": "^6.12.5-nightly.0", | ||
"@ledgerhq/hw-transport": "^6.28.3-nightly.0", | ||
"@ledgerhq/hw-transport-node-hid-noevents": "^6.27.14-nightly.0", | ||
"@ledgerhq/logs": "^6.10.1" | ||
@@ -46,7 +46,6 @@ }, | ||
"jest": "^28.1.1", | ||
"rimraf": "^4.1.2", | ||
"rimraf": "^4.4.1", | ||
"source-map-support": "^0.5.21", | ||
"ts-jest": "^28.0.5", | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4" | ||
"ts-node": "^10.4.0" | ||
}, | ||
@@ -53,0 +52,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8
52391
702
1