Socket
Socket
Sign inDemoInstall

@ledgerhq/hw-transport-node-hid

Package Overview
Dependencies
Maintainers
7
Versions
399
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ledgerhq/hw-transport-node-hid - npm Package Compare versions

Comparing version 4.21.0 to 4.22.0-beta.96c1e355

9

lib/getDevices.js

@@ -12,11 +12,10 @@ "use strict";

var _isLedgerDevice = require("./isLedgerDevice");
var _isLedgerDevice2 = _interopRequireDefault(_isLedgerDevice);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var filterInterface = function filterInterface(device) {
return ["win32", "darwin"].includes(process.platform) ? device.usagePage === 0xffa0 : device.interface === 0;
};
function getDevices() {
return _nodeHid2.default.devices().filter(_isLedgerDevice2.default);
return _nodeHid2.default.devices(0x2c97, 0x0).filter(filterInterface);
}
//# sourceMappingURL=getDevices.js.map

@@ -19,2 +19,10 @@ "use strict";

var _usb = require("usb");
var _usb2 = _interopRequireDefault(_usb);
var _debounce = require("lodash/debounce");
var _debounce2 = _interopRequireDefault(_debounce);
var _getDevices = require("./getDevices");

@@ -26,7 +34,6 @@

exports.default = function (delay, listenDevicesPollingSkip) {
exports.default = function (delay, listenDevicesPollingSkip, debug) {
var events = new _events2.default();
events.setMaxListeners(0);
var timeoutDetection = void 0;
var listDevices = (0, _getDevices2.default)();

@@ -52,19 +59,30 @@

var checkDevices = function checkDevices() {
var poll = function poll() {
if (!listenDevicesPollingSkip()) {
debug("Polling for added or removed devices");
var changeFound = false;
var currentDevices = getFlatDevices();
var newDevices = currentDevices.filter(function (d) {
return !lastDevices.includes(d);
});
var removeDevices = lastDevices.filter(function (d) {
return !currentDevices.includes(d);
});
if (newDevices.length > 0) {
debug("New device found:", newDevices);
listDevices = (0, _getDevices2.default)();
events.emit("add", getDeviceByPaths(newDevices));
changeFound = true;
} else {
debug("No new device found");
}
var removeDevices = lastDevices.filter(function (d) {
return !currentDevices.includes(d);
});
if (removeDevices.length > 0) {
debug("Removed device found:", removeDevices);
events.emit("remove", getDeviceByPaths(removeDevices));

@@ -74,14 +92,41 @@ listDevices = listDevices.filter(function (d) {

});
changeFound = true;
} else {
debug("No removed device found");
}
lastDevices = currentDevices;
if (changeFound) {
lastDevices = currentDevices;
}
} else {
debug("Polling skipped, re-debouncing");
debouncedPoll();
}
setTimeout(checkDevices, delay);
};
timeoutDetection = setTimeout(checkDevices, delay);
var debouncedPoll = (0, _debounce2.default)(poll, delay);
var attachDetected = function attachDetected(device) {
debug("Device add detected:", device);
debouncedPoll();
};
_usb2.default.on("attach", attachDetected);
debug("attach listener added");
var detachDetected = function detachDetected(device) {
debug("Device removal detected:", device);
debouncedPoll();
};
_usb2.default.on("detach", detachDetected);
debug("detach listener added");
return {
stop: function stop() {
clearTimeout(timeoutDetection);
debug("Stop received, removing listeners and cancelling pending debounced polls");
debouncedPoll.cancel();
_usb2.default.removeListener("attach", attachDetected);
_usb2.default.removeListener("detach", detachDetected);
},

@@ -88,0 +133,0 @@ events: events

@@ -77,2 +77,3 @@ "use strict";

};
var listenDevicesDebug = function listenDevicesDebug() {};

@@ -423,2 +424,14 @@ /**

TransportNodeHid.setListenDevicesDebug = function (debug) {
listenDevicesDebug = typeof debug === "function" ? debug : debug ? function () {
var _console;
for (var _len = arguments.length, log = Array(_len), _key = 0; _key < _len; _key++) {
log[_key] = arguments[_key];
}
return (_console = console).log.apply(_console, ["[listenDevices]"].concat(log));
} : function () {};
};
TransportNodeHid.listen = function (observer) {

@@ -457,3 +470,3 @@ var unsubscribed = false;

var _listenDevices = (0, _listenDevices3.default)(listenDevicesPollingInterval, listenDevicesPollingSkip),
var _listenDevices = (0, _listenDevices3.default)(listenDevicesPollingInterval, listenDevicesPollingSkip, listenDevicesDebug),
events = _listenDevices.events,

@@ -460,0 +473,0 @@ stop = _listenDevices.stop;

{
"name": "@ledgerhq/hw-transport-node-hid",
"version": "4.21.0",
"version": "4.22.0-beta.96c1e355",
"description": "Ledger Hardware Wallet Node implementation of the communication layer, using node-hid",

@@ -28,4 +28,6 @@ "keywords": [

"dependencies": {
"@ledgerhq/hw-transport": "^4.21.0",
"node-hid": "^0.7.2"
"@ledgerhq/hw-transport": "^4.22.0-beta.96c1e355",
"lodash": "^4.17.10",
"node-hid": "^0.7.2",
"usb": "^1.3.2"
},

@@ -32,0 +34,0 @@ "devDependencies": {

// @flow
import HID from "node-hid";
import isLedgerDevice from "./isLedgerDevice";
const filterInterface = device =>
["win32", "darwin"].includes(process.platform)
? device.usagePage === 0xffa0
: device.interface === 0;
export default function getDevices(): Array<*> {
return HID.devices().filter(isLedgerDevice);
return HID.devices(0x2c97, 0x0).filter(filterInterface);
}
// @flow
import EventEmitter from "events";
import usb from "usb";
import debounce from "lodash/debounce";
import getDevices from "./getDevices";

@@ -8,3 +10,4 @@

delay: number,
listenDevicesPollingSkip: () => boolean
listenDevicesPollingSkip: () => boolean,
debug: (...any) => void
): {

@@ -17,3 +20,2 @@ events: EventEmitter,

let timeoutDetection;
let listDevices = getDevices();

@@ -32,17 +34,28 @@

const checkDevices = () => {
const poll = () => {
if (!listenDevicesPollingSkip()) {
debug("Polling for added or removed devices");
let changeFound = false;
const currentDevices = getFlatDevices();
const newDevices = currentDevices.filter(d => !lastDevices.includes(d));
const removeDevices = lastDevices.filter(
d => !currentDevices.includes(d)
);
if (newDevices.length > 0) {
debug("New device found:", newDevices);
listDevices = getDevices();
events.emit("add", getDeviceByPaths(newDevices));
changeFound = true;
} else {
debug("No new device found");
}
const removeDevices = lastDevices.filter(
d => !currentDevices.includes(d)
);
if (removeDevices.length > 0) {
debug("Removed device found:", removeDevices);
events.emit("remove", getDeviceByPaths(removeDevices));

@@ -52,14 +65,43 @@ listDevices = listDevices.filter(

);
changeFound = true;
} else {
debug("No removed device found");
}
lastDevices = currentDevices;
if (changeFound) {
lastDevices = currentDevices;
}
} else {
debug("Polling skipped, re-debouncing");
debouncedPoll();
}
setTimeout(checkDevices, delay);
};
timeoutDetection = setTimeout(checkDevices, delay);
const debouncedPoll = debounce(poll, delay);
const attachDetected = device => {
debug("Device add detected:", device);
debouncedPoll();
};
usb.on("attach", attachDetected);
debug("attach listener added");
const detachDetected = device => {
debug("Device removal detected:", device);
debouncedPoll();
};
usb.on("detach", detachDetected);
debug("detach listener added");
return {
stop: () => {
clearTimeout(timeoutDetection);
debug(
"Stop received, removing listeners and cancelling pending debounced polls"
);
debouncedPoll.cancel();
usb.removeListener("attach", attachDetected);
usb.removeListener("detach", detachDetected);
},

@@ -66,0 +108,0 @@ events

@@ -31,2 +31,3 @@ //@flow

let listenDevicesPollingSkip = () => false;
let listenDevicesDebug = () => {};

@@ -72,2 +73,11 @@ /**

static setListenDevicesDebug = (debug: boolean | ((log: string) => void)) => {
listenDevicesDebug =
typeof debug === "function"
? debug
: debug
? (...log) => console.log("[listenDevices]", ...log)
: () => {};
};
/**

@@ -90,3 +100,4 @@ */

listenDevicesPollingInterval,
listenDevicesPollingSkip
listenDevicesPollingSkip,
listenDevicesDebug
);

@@ -93,0 +104,0 @@

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc