@ledgerhq/hw-transport-node-hid
Advanced tools
Comparing version 4.8.0-rc1.1b178f67 to 4.12.0-beta.fd04ab6f
@@ -1,3 +0,3 @@ | ||
// flow-typed signature: 75d330203ebfe98a2c99295790ffe07c | ||
// flow-typed version: <<STUB>>/@ledgerhq/hw-transport_v^2.1.0/flow_v0.63.1 | ||
// flow-typed signature: de76e43b7f594cd142bb9865fb4eb16a | ||
// flow-typed version: <<STUB>>/@ledgerhq/hw-transport_v^4.7.3/flow_v0.68.0 | ||
@@ -37,6 +37,2 @@ /** | ||
declare module '@ledgerhq/hw-transport/flow-typed/npm/invariant_v2.x.x' { | ||
declare module.exports: any; | ||
} | ||
declare module '@ledgerhq/hw-transport/src/Transport' { | ||
@@ -56,7 +52,4 @@ declare module.exports: any; | ||
} | ||
declare module '@ledgerhq/hw-transport/flow-typed/npm/invariant_v2.x.x.js' { | ||
declare module.exports: $Exports<'@ledgerhq/hw-transport/flow-typed/npm/invariant_v2.x.x'>; | ||
} | ||
declare module '@ledgerhq/hw-transport/src/Transport.js' { | ||
declare module.exports: $Exports<'@ledgerhq/hw-transport/src/Transport'>; | ||
} |
@@ -7,5 +7,6 @@ "use strict"; | ||
exports.default = function (device) { | ||
return device.vendorId === 0x2581 && device.productId === 0x3b7c || device.vendorId === 0x2c97; | ||
// We check the usagePage on Win/OSX, and interface on Linux for get only HID device | ||
exports.default = function (d) { | ||
return (["win32", "darwin"].includes(process.platform) ? d.usagePage === 0xffa0 : d.interface === 0) && (d.vendorId === 0x2581 && d.productId === 0x3b7c || d.vendorId === 0x2c97); | ||
}; | ||
//# sourceMappingURL=isLedgerDevice.js.map |
@@ -30,17 +30,19 @@ "use strict"; | ||
events.setMaxListeners(0); | ||
var timeoutDetection = void 0; | ||
var listDevices = (0, _getDevices2.default)(); | ||
var flatDevice = function flatDevice(device) { | ||
return device.path; | ||
var flatDevice = function flatDevice(d) { | ||
return d.path; | ||
}; | ||
var getFlatDevices = function getFlatDevices() { | ||
return [].concat((0, _toConsumableArray3.default)(new _set2.default((0, _getDevices2.default)().map(function (device) { | ||
return flatDevice(device); | ||
return [].concat((0, _toConsumableArray3.default)(new _set2.default((0, _getDevices2.default)().map(function (d) { | ||
return flatDevice(d); | ||
})))); | ||
}; | ||
var getDeviceByPath = function getDeviceByPath(ids) { | ||
return listDevices.find(function (device) { | ||
return flatDevice(device) === ids; | ||
var getDeviceByPaths = function getDeviceByPaths(paths) { | ||
return listDevices.find(function (d) { | ||
return paths.includes(flatDevice(d)); | ||
}); | ||
@@ -55,18 +57,18 @@ }; | ||
var addDevice = currentDevices.find(function (device) { | ||
return !lastDevices.includes(device); | ||
var newDevices = currentDevices.filter(function (d) { | ||
return !lastDevices.includes(d); | ||
}); | ||
var removeDevice = lastDevices.find(function (device) { | ||
return !currentDevices.includes(device); | ||
var removeDevices = lastDevices.filter(function (d) { | ||
return !currentDevices.includes(d); | ||
}); | ||
if (addDevice) { | ||
if (newDevices.length > 0) { | ||
listDevices = (0, _getDevices2.default)(); | ||
events.emit("add", getDeviceByPath(addDevice)); | ||
events.emit("add", getDeviceByPaths(newDevices)); | ||
} | ||
if (removeDevice) { | ||
events.emit("remove", getDeviceByPath(removeDevice)); | ||
listDevices = listDevices.filter(function (device) { | ||
return flatDevice(device) !== removeDevice; | ||
if (removeDevices.length > 0) { | ||
events.emit("remove", getDeviceByPaths(removeDevices)); | ||
listDevices = listDevices.filter(function (d) { | ||
return !removeDevices.includes(flatDevice(d)); | ||
}); | ||
@@ -73,0 +75,0 @@ } |
{ | ||
"name": "@ledgerhq/hw-transport-node-hid", | ||
"version": "4.8.0-rc1.1b178f67", | ||
"version": "4.12.0-beta.fd04ab6f", | ||
"description": "Ledger Hardware Wallet Node implementation of the communication layer, using node-hid", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@ledgerhq/hw-transport": "^4.8.0-rc1.1b178f67", | ||
"@ledgerhq/hw-transport": "^4.12.0-beta.fd04ab6f", | ||
"node-hid": "^0.7.2" | ||
@@ -31,0 +31,0 @@ }, |
@@ -1,3 +0,6 @@ | ||
export default device => | ||
(device.vendorId === 0x2581 && device.productId === 0x3b7c) || | ||
device.vendorId === 0x2c97; | ||
// We check the usagePage on Win/OSX, and interface on Linux for get only HID device | ||
export default d => | ||
(["win32", "darwin"].includes(process.platform) | ||
? d.usagePage === 0xffa0 | ||
: d.interface === 0) && | ||
((d.vendorId === 0x2581 && d.productId === 0x3b7c) || d.vendorId === 0x2c97); |
@@ -14,13 +14,15 @@ // @flow | ||
events.setMaxListeners(0); | ||
let timeoutDetection; | ||
let listDevices = getDevices(); | ||
const flatDevice = device => device.path; | ||
const flatDevice = d => d.path; | ||
const getFlatDevices = () => [ | ||
...new Set(getDevices().map(device => flatDevice(device))) | ||
...new Set(getDevices().map(d => flatDevice(d))) | ||
]; | ||
const getDeviceByPath = ids => | ||
listDevices.find(device => flatDevice(device) === ids); | ||
const getDeviceByPaths = paths => | ||
listDevices.find(d => paths.includes(flatDevice(d))); | ||
let lastDevices = getFlatDevices(); | ||
@@ -32,18 +34,16 @@ | ||
const addDevice = currentDevices.find( | ||
device => !lastDevices.includes(device) | ||
const newDevices = currentDevices.filter(d => !lastDevices.includes(d)); | ||
const removeDevices = lastDevices.filter( | ||
d => !currentDevices.includes(d) | ||
); | ||
const removeDevice = lastDevices.find( | ||
device => !currentDevices.includes(device) | ||
); | ||
if (addDevice) { | ||
if (newDevices.length > 0) { | ||
listDevices = getDevices(); | ||
events.emit("add", getDeviceByPath(addDevice)); | ||
events.emit("add", getDeviceByPaths(newDevices)); | ||
} | ||
if (removeDevice) { | ||
events.emit("remove", getDeviceByPath(removeDevice)); | ||
if (removeDevices.length > 0) { | ||
events.emit("remove", getDeviceByPaths(removeDevices)); | ||
listDevices = listDevices.filter( | ||
device => flatDevice(device) !== removeDevice | ||
d => !removeDevices.includes(flatDevice(d)) | ||
); | ||
@@ -50,0 +50,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
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
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
83372
1148