@ledgerhq/devices
Advanced tools
Comparing version 8.0.3 to 8.0.4-nightly.0
# @ledgerhq/devices | ||
## 8.0.4-nightly.0 | ||
### Patch Changes | ||
- Updated dependencies [[`9adc1862dd`](https://github.com/LedgerHQ/ledger-live/commit/9adc1862dda605a722d19f3b6895bd324834c914)]: | ||
- @ledgerhq/errors@6.12.7-nightly.0 | ||
## 8.0.3 | ||
@@ -4,0 +11,0 @@ |
@@ -6,3 +6,3 @@ import { TransportError, DisconnectedDevice } from "@ledgerhq/errors"; | ||
// operator that transform the input raw stream into one apdu response and finishes | ||
export const receiveAPDU = (rawStream) => Observable.create((o) => { | ||
export const receiveAPDU = (rawStream) => Observable.create(o => { | ||
let notifiedIndex = 0; | ||
@@ -16,3 +16,3 @@ let notifiedDataLength = 0; | ||
}, | ||
error: (e) => { | ||
error: e => { | ||
log("ble-error", "in receiveAPDU " + String(e)); | ||
@@ -22,3 +22,3 @@ o.error(e); | ||
}, | ||
next: (value) => { | ||
next: value => { | ||
const tag = value.readUInt8(0); | ||
@@ -25,0 +25,0 @@ const index = value.readUInt16BE(1); |
@@ -21,3 +21,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
export const sendAPDU = (write, apdu, mtuSize) => { | ||
const chunks = chunkBuffer(apdu, (i) => mtuSize - (i === 0 ? 5 : 3)).map((buffer, i) => { | ||
const chunks = chunkBuffer(apdu, i => mtuSize - (i === 0 ? 5 : 3)).map((buffer, i) => { | ||
const head = Buffer.alloc(i === 0 ? 5 : 3); | ||
@@ -31,3 +31,3 @@ head.writeUInt8(TagId, 0); | ||
}); | ||
return new Observable((o) => { | ||
return new Observable(o => { | ||
let terminated = false; | ||
@@ -46,3 +46,3 @@ function main() { | ||
o.complete(); | ||
}, (e) => { | ||
}, e => { | ||
terminated = true; | ||
@@ -49,0 +49,0 @@ log("ble-error", "sendAPDU failure " + String(e)); |
@@ -49,8 +49,3 @@ import semver from "semver"; | ||
masks: [0x31100000], | ||
getBlockSize: (firmwareVersion) => { | ||
var _a; | ||
return semver.lt((_a = semver.coerce(firmwareVersion)) !== null && _a !== void 0 ? _a : "", "2.0.0") | ||
? 4 * 1024 | ||
: 2 * 1024; | ||
}, | ||
getBlockSize: (firmwareVersion) => { var _a; return semver.lt((_a = semver.coerce(firmwareVersion)) !== null && _a !== void 0 ? _a : "", "2.0.0") ? 4 * 1024 : 2 * 1024; }, | ||
}, | ||
@@ -130,3 +125,3 @@ [DeviceModelId.nanoSP]: { | ||
export const identifyTargetId = (targetId) => { | ||
const deviceModel = devicesList.find(({ masks }) => masks.find((mask) => (targetId & 0xffff0000) === mask)); | ||
const deviceModel = devicesList.find(({ masks }) => masks.find(mask => (targetId & 0xffff0000) === mask)); | ||
return deviceModel; | ||
@@ -138,11 +133,11 @@ }; | ||
export const identifyUSBProductId = (usbProductId) => { | ||
const legacy = devicesList.find((d) => d.legacyUsbProductId === usbProductId); | ||
const legacy = devicesList.find(d => d.legacyUsbProductId === usbProductId); | ||
if (legacy) | ||
return legacy; | ||
const mm = usbProductId >> 8; | ||
const deviceModel = devicesList.find((d) => d.productIdMM === mm); | ||
const deviceModel = devicesList.find(d => d.productIdMM === mm); | ||
return deviceModel; | ||
}; | ||
export const identifyProductName = (productName) => { | ||
const deviceModel = devicesList.find((d) => d.id === productMap[productName]); | ||
const deviceModel = devicesList.find(d => d.id === productMap[productName]); | ||
return deviceModel; | ||
@@ -149,0 +144,0 @@ }; |
@@ -9,3 +9,3 @@ "use strict"; | ||
// operator that transform the input raw stream into one apdu response and finishes | ||
const receiveAPDU = (rawStream) => rxjs_1.Observable.create((o) => { | ||
const receiveAPDU = (rawStream) => rxjs_1.Observable.create(o => { | ||
let notifiedIndex = 0; | ||
@@ -19,3 +19,3 @@ let notifiedDataLength = 0; | ||
}, | ||
error: (e) => { | ||
error: e => { | ||
(0, logs_1.log)("ble-error", "in receiveAPDU " + String(e)); | ||
@@ -25,3 +25,3 @@ o.error(e); | ||
}, | ||
next: (value) => { | ||
next: value => { | ||
const tag = value.readUInt8(0); | ||
@@ -28,0 +28,0 @@ const index = value.readUInt16BE(1); |
@@ -24,3 +24,3 @@ "use strict"; | ||
const sendAPDU = (write, apdu, mtuSize) => { | ||
const chunks = chunkBuffer(apdu, (i) => mtuSize - (i === 0 ? 5 : 3)).map((buffer, i) => { | ||
const chunks = chunkBuffer(apdu, i => mtuSize - (i === 0 ? 5 : 3)).map((buffer, i) => { | ||
const head = Buffer.alloc(i === 0 ? 5 : 3); | ||
@@ -34,3 +34,3 @@ head.writeUInt8(TagId, 0); | ||
}); | ||
return new rxjs_1.Observable((o) => { | ||
return new rxjs_1.Observable(o => { | ||
let terminated = false; | ||
@@ -49,3 +49,3 @@ function main() { | ||
o.complete(); | ||
}, (e) => { | ||
}, e => { | ||
terminated = true; | ||
@@ -52,0 +52,0 @@ (0, logs_1.log)("ble-error", "sendAPDU failure " + String(e)); |
@@ -55,8 +55,3 @@ "use strict"; | ||
masks: [0x31100000], | ||
getBlockSize: (firmwareVersion) => { | ||
var _a; | ||
return semver_1.default.lt((_a = semver_1.default.coerce(firmwareVersion)) !== null && _a !== void 0 ? _a : "", "2.0.0") | ||
? 4 * 1024 | ||
: 2 * 1024; | ||
}, | ||
getBlockSize: (firmwareVersion) => { var _a; return semver_1.default.lt((_a = semver_1.default.coerce(firmwareVersion)) !== null && _a !== void 0 ? _a : "", "2.0.0") ? 4 * 1024 : 2 * 1024; }, | ||
}, | ||
@@ -137,3 +132,3 @@ [DeviceModelId.nanoSP]: { | ||
const identifyTargetId = (targetId) => { | ||
const deviceModel = devicesList.find(({ masks }) => masks.find((mask) => (targetId & 0xffff0000) === mask)); | ||
const deviceModel = devicesList.find(({ masks }) => masks.find(mask => (targetId & 0xffff0000) === mask)); | ||
return deviceModel; | ||
@@ -146,7 +141,7 @@ }; | ||
const identifyUSBProductId = (usbProductId) => { | ||
const legacy = devicesList.find((d) => d.legacyUsbProductId === usbProductId); | ||
const legacy = devicesList.find(d => d.legacyUsbProductId === usbProductId); | ||
if (legacy) | ||
return legacy; | ||
const mm = usbProductId >> 8; | ||
const deviceModel = devicesList.find((d) => d.productIdMM === mm); | ||
const deviceModel = devicesList.find(d => d.productIdMM === mm); | ||
return deviceModel; | ||
@@ -156,3 +151,3 @@ }; | ||
const identifyProductName = (productName) => { | ||
const deviceModel = devicesList.find((d) => d.id === productMap[productName]); | ||
const deviceModel = devicesList.find(d => d.id === productMap[productName]); | ||
return deviceModel; | ||
@@ -159,0 +154,0 @@ }; |
{ | ||
"name": "@ledgerhq/devices", | ||
"version": "8.0.3", | ||
"version": "8.0.4-nightly.0", | ||
"description": "Ledger devices", | ||
@@ -58,3 +58,3 @@ "keywords": [ | ||
"semver": "^7.3.5", | ||
"@ledgerhq/errors": "^6.12.6", | ||
"@ledgerhq/errors": "^6.12.7-nightly.0", | ||
"@ledgerhq/logs": "^6.10.1" | ||
@@ -80,3 +80,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", | ||
@@ -83,0 +83,0 @@ "test": "jest" |
@@ -6,6 +6,4 @@ import { TransportError, DisconnectedDevice } from "@ledgerhq/errors"; | ||
// operator that transform the input raw stream into one apdu response and finishes | ||
export const receiveAPDU = ( | ||
rawStream: Observable<Buffer> | ||
): Observable<Buffer> => | ||
Observable.create((o) => { | ||
export const receiveAPDU = (rawStream: Observable<Buffer>): Observable<Buffer> => | ||
Observable.create(o => { | ||
let notifiedIndex = 0; | ||
@@ -19,3 +17,3 @@ let notifiedDataLength = 0; | ||
}, | ||
error: (e) => { | ||
error: e => { | ||
log("ble-error", "in receiveAPDU " + String(e)); | ||
@@ -25,3 +23,3 @@ o.error(e); | ||
}, | ||
next: (value) => { | ||
next: value => { | ||
const tag = value.readUInt8(0); | ||
@@ -32,5 +30,3 @@ const index = value.readUInt16BE(1); | ||
if (tag !== TagId) { | ||
o.error( | ||
new TransportError("Invalid tag " + tag.toString(16), "InvalidTag") | ||
); | ||
o.error(new TransportError("Invalid tag " + tag.toString(16), "InvalidTag")); | ||
return; | ||
@@ -46,4 +42,4 @@ } | ||
notifiedIndex, | ||
"InvalidSequence" | ||
) | ||
"InvalidSequence", | ||
), | ||
); | ||
@@ -68,4 +64,4 @@ return; | ||
notifiedDataLength, | ||
"BLETooMuchData" | ||
) | ||
"BLETooMuchData", | ||
), | ||
); | ||
@@ -72,0 +68,0 @@ return; |
@@ -5,13 +5,6 @@ import { Observable } from "rxjs"; | ||
function chunkBuffer( | ||
buffer: Buffer, | ||
sizeForIndex: (arg0: number) => number | ||
): Array<Buffer> { | ||
function chunkBuffer(buffer: Buffer, sizeForIndex: (arg0: number) => number): Array<Buffer> { | ||
const chunks: Buffer[] = []; | ||
for ( | ||
let i = 0, size = sizeForIndex(0); | ||
i < buffer.length; | ||
i += size, size = sizeForIndex(i) | ||
) { | ||
for (let i = 0, size = sizeForIndex(0); i < buffer.length; i += size, size = sizeForIndex(i)) { | ||
chunks.push(buffer.slice(i, i + size)); | ||
@@ -26,18 +19,16 @@ } | ||
apdu: Buffer, | ||
mtuSize: number | ||
mtuSize: number, | ||
): Observable<Buffer> => { | ||
const chunks = chunkBuffer(apdu, (i) => mtuSize - (i === 0 ? 5 : 3)).map( | ||
(buffer, i) => { | ||
const head = Buffer.alloc(i === 0 ? 5 : 3); | ||
head.writeUInt8(TagId, 0); | ||
head.writeUInt16BE(i, 1); | ||
const chunks = chunkBuffer(apdu, i => mtuSize - (i === 0 ? 5 : 3)).map((buffer, i) => { | ||
const head = Buffer.alloc(i === 0 ? 5 : 3); | ||
head.writeUInt8(TagId, 0); | ||
head.writeUInt16BE(i, 1); | ||
if (i === 0) { | ||
head.writeUInt16BE(apdu.length, 3); | ||
} | ||
if (i === 0) { | ||
head.writeUInt16BE(apdu.length, 3); | ||
} | ||
return Buffer.concat([head, buffer]); | ||
} | ||
); | ||
return new Observable((o) => { | ||
return Buffer.concat([head, buffer]); | ||
}); | ||
return new Observable(o => { | ||
let terminated = false; | ||
@@ -57,7 +48,7 @@ | ||
}, | ||
(e) => { | ||
e => { | ||
terminated = true; | ||
log("ble-error", "sendAPDU failure " + String(e)); | ||
o.error(e); | ||
} | ||
}, | ||
); | ||
@@ -64,0 +55,0 @@ |
@@ -22,5 +22,3 @@ import { DeviceModelId } from "."; | ||
tests.forEach(({ input, expectedOutput }) => { | ||
test(`Input: ${JSON.stringify( | ||
input | ||
)} -> Expected output: ${expectedOutput}`, () => { | ||
test(`Input: ${JSON.stringify(input)} -> Expected output: ${expectedOutput}`, () => { | ||
const result = stringToDeviceModelId(...input); | ||
@@ -27,0 +25,0 @@ expect(result).toEqual(expectedOutput); |
@@ -5,7 +5,5 @@ import { DeviceModelId } from "."; | ||
strDeviceModelId: string, | ||
defaultDeviceModelId: DeviceModelId | ||
defaultDeviceModelId: DeviceModelId, | ||
): DeviceModelId => { | ||
if ( | ||
Object.values(DeviceModelId)?.includes(strDeviceModelId as DeviceModelId) | ||
) { | ||
if (Object.values(DeviceModelId)?.includes(strDeviceModelId as DeviceModelId)) { | ||
return DeviceModelId[strDeviceModelId as DeviceModelId]; | ||
@@ -12,0 +10,0 @@ } |
@@ -52,5 +52,3 @@ import semver from "semver"; | ||
getBlockSize: (firmwareVersion: string): number => | ||
semver.lt(semver.coerce(firmwareVersion) ?? "", "2.0.0") | ||
? 4 * 1024 | ||
: 2 * 1024, | ||
semver.lt(semver.coerce(firmwareVersion) ?? "", "2.0.0") ? 4 * 1024 : 2 * 1024, | ||
}, | ||
@@ -133,7 +131,5 @@ [DeviceModelId.nanoSP]: { | ||
*/ | ||
export const identifyTargetId = ( | ||
targetId: number | ||
): DeviceModel | null | undefined => { | ||
export const identifyTargetId = (targetId: number): DeviceModel | null | undefined => { | ||
const deviceModel = devicesList.find(({ masks }) => | ||
masks.find((mask) => (targetId & 0xffff0000) === mask) | ||
masks.find(mask => (targetId & 0xffff0000) === mask), | ||
); | ||
@@ -147,16 +143,12 @@ | ||
*/ | ||
export const identifyUSBProductId = ( | ||
usbProductId: number | ||
): DeviceModel | null | undefined => { | ||
const legacy = devicesList.find((d) => d.legacyUsbProductId === usbProductId); | ||
export const identifyUSBProductId = (usbProductId: number): DeviceModel | null | undefined => { | ||
const legacy = devicesList.find(d => d.legacyUsbProductId === usbProductId); | ||
if (legacy) return legacy; | ||
const mm = usbProductId >> 8; | ||
const deviceModel = devicesList.find((d) => d.productIdMM === mm); | ||
const deviceModel = devicesList.find(d => d.productIdMM === mm); | ||
return deviceModel; | ||
}; | ||
export const identifyProductName = ( | ||
productName: string | ||
): DeviceModel | null | undefined => { | ||
const deviceModel = devicesList.find((d) => d.id === productMap[productName]); | ||
export const identifyProductName = (productName: string): DeviceModel | null | undefined => { | ||
const deviceModel = devicesList.find(d => d.id === productMap[productName]); | ||
return deviceModel; | ||
@@ -193,5 +185,4 @@ }; | ||
*/ | ||
export const getInfosForServiceUuid = ( | ||
uuid: string | ||
): BluetoothInfos | undefined => serviceUuidToInfos[uuid.toLowerCase()]; | ||
export const getInfosForServiceUuid = (uuid: string): BluetoothInfos | undefined => | ||
serviceUuidToInfos[uuid.toLowerCase()]; | ||
@@ -198,0 +189,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
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
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
97452
1487
1