@ledgerhq/hw-transport-node-hid
Advanced tools
Comparing version 6.27.15 to 6.27.16-nightly.0
# @ledgerhq/hw-transport-node-hid | ||
## 6.27.16-nightly.0 | ||
### Patch Changes | ||
- Updated dependencies [[`9adc1862dd`](https://github.com/LedgerHQ/ledger-live/commit/9adc1862dda605a722d19f3b6895bd324834c914)]: | ||
- @ledgerhq/errors@6.12.7-nightly.0 | ||
- @ledgerhq/devices@8.0.4-nightly.0 | ||
- @ledgerhq/hw-transport@6.28.5-nightly.0 | ||
- @ledgerhq/hw-transport-node-hid-noevents@6.27.16-nightly.0 | ||
## 6.27.15 | ||
@@ -4,0 +14,0 @@ |
@@ -10,7 +10,5 @@ import EventEmitter from "events"; | ||
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))); | ||
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(); | ||
@@ -22,3 +20,3 @@ const poll = () => { | ||
const currentDevices = getFlatDevices(); | ||
const newDevices = currentDevices.filter((d) => !lastDevices.includes(d)); | ||
const newDevices = currentDevices.filter(d => !lastDevices.includes(d)); | ||
if (newDevices.length > 0) { | ||
@@ -33,7 +31,7 @@ log("hid-listen", "New device found:", newDevices); | ||
} | ||
const removeDevices = lastDevices.filter((d) => !currentDevices.includes(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))); | ||
listDevices = listDevices.filter(d => !removeDevices.includes(flatDevice(d))); | ||
changeFound = true; | ||
@@ -54,3 +52,3 @@ } | ||
const debouncedPoll = debounce(poll, delay); | ||
const attachDetected = (device) => { | ||
const attachDetected = device => { | ||
log("hid-listen", "Device add detected:", device); | ||
@@ -61,3 +59,3 @@ debouncedPoll(); | ||
log("hid-listen", "attach listener added"); | ||
const detachDetected = (device) => { | ||
const detachDetected = device => { | ||
log("hid-listen", "Device removal detected:", device); | ||
@@ -64,0 +62,0 @@ debouncedPoll(); |
import HID from "node-hid"; | ||
import TransportNodeHidNoEvents, { getDevices, } from "@ledgerhq/hw-transport-node-hid-noevents"; | ||
import TransportNodeHidNoEvents, { getDevices } from "@ledgerhq/hw-transport-node-hid-noevents"; | ||
import { identifyUSBProductId } from "@ledgerhq/devices"; | ||
@@ -61,3 +61,3 @@ import { TransportError } from "@ledgerhq/errors"; | ||
let unsubscribed = false; | ||
Promise.resolve(getDevices()).then((devices) => { | ||
Promise.resolve(getDevices()).then(devices => { | ||
// this needs to run asynchronously so the subscription is defined during this phase | ||
@@ -78,3 +78,3 @@ for (const device of devices) { | ||
const { events, stop } = listenDevices(listenDevicesDebounce, listenDevicesPollingSkip); | ||
const onAdd = (device) => { | ||
const onAdd = device => { | ||
if (unsubscribed || !device) | ||
@@ -90,3 +90,3 @@ return; | ||
}; | ||
const onRemove = (device) => { | ||
const onRemove = device => { | ||
if (unsubscribed || !device) | ||
@@ -93,0 +93,0 @@ return; |
@@ -15,7 +15,5 @@ "use strict"; | ||
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))); | ||
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(); | ||
@@ -27,3 +25,3 @@ const poll = () => { | ||
const currentDevices = getFlatDevices(); | ||
const newDevices = currentDevices.filter((d) => !lastDevices.includes(d)); | ||
const newDevices = currentDevices.filter(d => !lastDevices.includes(d)); | ||
if (newDevices.length > 0) { | ||
@@ -38,7 +36,7 @@ (0, logs_1.log)("hid-listen", "New device found:", newDevices); | ||
} | ||
const removeDevices = lastDevices.filter((d) => !currentDevices.includes(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))); | ||
listDevices = listDevices.filter(d => !removeDevices.includes(flatDevice(d))); | ||
changeFound = true; | ||
@@ -59,3 +57,3 @@ } | ||
const debouncedPoll = (0, debounce_1.default)(poll, delay); | ||
const attachDetected = (device) => { | ||
const attachDetected = device => { | ||
(0, logs_1.log)("hid-listen", "Device add detected:", device); | ||
@@ -66,3 +64,3 @@ debouncedPoll(); | ||
(0, logs_1.log)("hid-listen", "attach listener added"); | ||
const detachDetected = (device) => { | ||
const detachDetected = device => { | ||
(0, logs_1.log)("hid-listen", "Device removal detected:", device); | ||
@@ -69,0 +67,0 @@ debouncedPoll(); |
@@ -90,3 +90,3 @@ "use strict"; | ||
let unsubscribed = false; | ||
Promise.resolve((0, hw_transport_node_hid_noevents_1.getDevices)()).then((devices) => { | ||
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 | ||
@@ -107,3 +107,3 @@ for (const device of devices) { | ||
const { events, stop } = (0, listenDevices_1.default)(listenDevicesDebounce, listenDevicesPollingSkip); | ||
const onAdd = (device) => { | ||
const onAdd = device => { | ||
if (unsubscribed || !device) | ||
@@ -119,3 +119,3 @@ return; | ||
}; | ||
const onRemove = (device) => { | ||
const onRemove = device => { | ||
if (unsubscribed || !device) | ||
@@ -122,0 +122,0 @@ return; |
{ | ||
"name": "@ledgerhq/hw-transport-node-hid", | ||
"version": "6.27.15", | ||
"version": "6.27.16-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.3", | ||
"@ledgerhq/errors": "^6.12.6", | ||
"@ledgerhq/hw-transport": "^6.28.4", | ||
"@ledgerhq/hw-transport-node-hid-noevents": "^6.27.15", | ||
"@ledgerhq/devices": "^8.0.4-nightly.0", | ||
"@ledgerhq/errors": "^6.12.7-nightly.0", | ||
"@ledgerhq/hw-transport": "^6.28.5-nightly.0", | ||
"@ledgerhq/hw-transport-node-hid-noevents": "^6.27.16-nightly.0", | ||
"@ledgerhq/logs": "^6.10.1" | ||
@@ -57,3 +57,3 @@ }, | ||
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts", | ||
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx", | ||
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache", | ||
"lint:fix": "pnpm lint --fix", | ||
@@ -60,0 +60,0 @@ "test": "jest" |
@@ -8,3 +8,3 @@ import EventEmitter from "events"; | ||
delay: number, | ||
listenDevicesPollingSkip: () => boolean | ||
listenDevicesPollingSkip: () => boolean, | ||
): { | ||
@@ -18,10 +18,7 @@ events: EventEmitter; | ||
const flatDevice = (d) => d.path; | ||
const flatDevice = d => d.path; | ||
const getFlatDevices = () => [ | ||
...new Set(getDevices().map((d) => flatDevice(d))), | ||
]; | ||
const getFlatDevices = () => [...new Set(getDevices().map(d => flatDevice(d)))]; | ||
const getDeviceByPaths = (paths) => | ||
listDevices.find((d) => paths.includes(flatDevice(d))); | ||
const getDeviceByPaths = paths => listDevices.find(d => paths.includes(flatDevice(d))); | ||
@@ -35,3 +32,3 @@ let lastDevices = getFlatDevices(); | ||
const currentDevices = getFlatDevices(); | ||
const newDevices = currentDevices.filter((d) => !lastDevices.includes(d)); | ||
const newDevices = currentDevices.filter(d => !lastDevices.includes(d)); | ||
@@ -47,5 +44,3 @@ if (newDevices.length > 0) { | ||
const removeDevices = lastDevices.filter( | ||
(d) => !currentDevices.includes(d) | ||
); | ||
const removeDevices = lastDevices.filter(d => !currentDevices.includes(d)); | ||
@@ -55,5 +50,3 @@ if (removeDevices.length > 0) { | ||
events.emit("remove", getDeviceByPaths(removeDevices)); | ||
listDevices = listDevices.filter( | ||
(d) => !removeDevices.includes(flatDevice(d)) | ||
); | ||
listDevices = listDevices.filter(d => !removeDevices.includes(flatDevice(d))); | ||
changeFound = true; | ||
@@ -75,3 +68,3 @@ } else { | ||
const attachDetected = (device) => { | ||
const attachDetected = device => { | ||
log("hid-listen", "Device add detected:", device); | ||
@@ -84,3 +77,3 @@ debouncedPoll(); | ||
const detachDetected = (device) => { | ||
const detachDetected = device => { | ||
log("hid-listen", "Device removal detected:", device); | ||
@@ -94,6 +87,3 @@ debouncedPoll(); | ||
stop: () => { | ||
log( | ||
"hid-listen", | ||
"Stop received, removing listeners and cancelling pending debounced polls" | ||
); | ||
log("hid-listen", "Stop received, removing listeners and cancelling pending debounced polls"); | ||
debouncedPoll.cancel(); | ||
@@ -100,0 +90,0 @@ usb.removeListener("attach", attachDetected); |
import HID from "node-hid"; | ||
import TransportNodeHidNoEvents, { | ||
getDevices, | ||
} from "@ledgerhq/hw-transport-node-hid-noevents"; | ||
import type { | ||
Observer, | ||
DescriptorEvent, | ||
Subscription, | ||
} from "@ledgerhq/hw-transport"; | ||
import TransportNodeHidNoEvents, { getDevices } from "@ledgerhq/hw-transport-node-hid-noevents"; | ||
import type { Observer, DescriptorEvent, Subscription } from "@ledgerhq/hw-transport"; | ||
import { identifyUSBProductId } from "@ledgerhq/devices"; | ||
@@ -54,3 +48,3 @@ import { TransportError } from "@ledgerhq/errors"; | ||
console.warn( | ||
"setListenDevicesDebug is deprecated. Use @ledgerhq/logs instead. No logs will get emitted there anymore." | ||
"setListenDevicesDebug is deprecated. Use @ledgerhq/logs instead. No logs will get emitted there anymore.", | ||
); | ||
@@ -62,6 +56,6 @@ }; | ||
static listen = ( | ||
observer: Observer<DescriptorEvent<string | null | undefined>> | ||
observer: Observer<DescriptorEvent<string | null | undefined>>, | ||
): Subscription => { | ||
let unsubscribed = false; | ||
Promise.resolve(getDevices()).then((devices) => { | ||
Promise.resolve(getDevices()).then(devices => { | ||
// this needs to run asynchronously so the subscription is defined during this phase | ||
@@ -81,8 +75,5 @@ for (const device of devices) { | ||
}); | ||
const { events, stop } = listenDevices( | ||
listenDevicesDebounce, | ||
listenDevicesPollingSkip | ||
); | ||
const { events, stop } = listenDevices(listenDevicesDebounce, listenDevicesPollingSkip); | ||
const onAdd = (device) => { | ||
const onAdd = device => { | ||
if (unsubscribed || !device) return; | ||
@@ -98,3 +89,3 @@ const deviceModel = identifyUSBProductId(device.productId); | ||
const onRemove = (device) => { | ||
const onRemove = device => { | ||
if (unsubscribed || !device) return; | ||
@@ -101,0 +92,0 @@ const deviceModel = identifyUSBProductId(device.productId); |
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
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
53347
679
1