Socket
Socket
Sign inDemoInstall

@ledgerhq/devices

Package Overview
Dependencies
Maintainers
20
Versions
261
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ledgerhq/devices - npm Package Compare versions

Comparing version 8.0.1 to 8.0.2-nightly.0

7

CHANGELOG.md
# @ledgerhq/devices
## 8.0.2-nightly.0
### Patch Changes
- Updated dependencies [[`87d2349fd8`](https://github.com/LedgerHQ/ledger-live/commit/87d2349fd835e5deb39d1ee8dfcf3539f4195472)]:
- @ledgerhq/errors@6.12.5-nightly.0
## 8.0.1

@@ -4,0 +11,0 @@

104

lib-es/ble/receiveAPDU.js
import { TransportError, DisconnectedDevice } from "@ledgerhq/errors";
import { Observable } from "rxjs";
import { log } from "@ledgerhq/logs";
var TagId = 0x05;
const TagId = 0x05;
// operator that transform the input raw stream into one apdu response and finishes
export var receiveAPDU = function (rawStream) {
return Observable.create(function (o) {
var notifiedIndex = 0;
var notifiedDataLength = 0;
var notifiedData = Buffer.alloc(0);
var sub = rawStream.subscribe({
complete: function () {
o.error(new DisconnectedDevice());
export const receiveAPDU = (rawStream) => Observable.create((o) => {
let notifiedIndex = 0;
let notifiedDataLength = 0;
let notifiedData = Buffer.alloc(0);
const sub = rawStream.subscribe({
complete: () => {
o.error(new DisconnectedDevice());
sub.unsubscribe();
},
error: (e) => {
log("ble-error", "in receiveAPDU " + String(e));
o.error(e);
sub.unsubscribe();
},
next: (value) => {
const tag = value.readUInt8(0);
const index = value.readUInt16BE(1);
let data = value.slice(3);
if (tag !== TagId) {
o.error(new TransportError("Invalid tag " + tag.toString(16), "InvalidTag"));
return;
}
if (notifiedIndex !== index) {
o.error(new TransportError("BLE: Invalid sequence number. discontinued chunk. Received " +
index +
" but expected " +
notifiedIndex, "InvalidSequence"));
return;
}
if (index === 0) {
notifiedDataLength = data.readUInt16BE(0);
data = data.slice(2);
}
notifiedIndex++;
notifiedData = Buffer.concat([notifiedData, data]);
if (notifiedData.length > notifiedDataLength) {
o.error(new TransportError("BLE: received too much data. discontinued chunk. Received " +
notifiedData.length +
" but expected " +
notifiedDataLength, "BLETooMuchData"));
return;
}
if (notifiedData.length === notifiedDataLength) {
o.next(notifiedData);
o.complete();
sub.unsubscribe();
},
error: function (e) {
log("ble-error", "in receiveAPDU " + String(e));
o.error(e);
sub.unsubscribe();
},
next: function (value) {
var tag = value.readUInt8(0);
var index = value.readUInt16BE(1);
var data = value.slice(3);
if (tag !== TagId) {
o.error(new TransportError("Invalid tag " + tag.toString(16), "InvalidTag"));
return;
}
if (notifiedIndex !== index) {
o.error(new TransportError("BLE: Invalid sequence number. discontinued chunk. Received " +
index +
" but expected " +
notifiedIndex, "InvalidSequence"));
return;
}
if (index === 0) {
notifiedDataLength = data.readUInt16BE(0);
data = data.slice(2);
}
notifiedIndex++;
notifiedData = Buffer.concat([notifiedData, data]);
if (notifiedData.length > notifiedDataLength) {
o.error(new TransportError("BLE: received too much data. discontinued chunk. Received " +
notifiedData.length +
" but expected " +
notifiedDataLength, "BLETooMuchData"));
return;
}
if (notifiedData.length === notifiedDataLength) {
o.next(notifiedData);
o.complete();
sub.unsubscribe();
}
}
});
return function () {
sub.unsubscribe();
};
},
});
};
return () => {
sub.unsubscribe();
};
});
//# sourceMappingURL=receiveAPDU.js.map

@@ -10,46 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
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 { Observable } from "rxjs";
import { log } from "@ledgerhq/logs";
var TagId = 0x05;
const TagId = 0x05;
function chunkBuffer(buffer, sizeForIndex) {
var chunks = [];
for (var i = 0, size = sizeForIndex(0); i < buffer.length; i += size, size = sizeForIndex(i)) {
const chunks = [];
for (let i = 0, size = sizeForIndex(0); i < buffer.length; i += size, size = sizeForIndex(i)) {
chunks.push(buffer.slice(i, i + size));

@@ -59,5 +21,5 @@ }

}
export var sendAPDU = function (write, apdu, mtuSize) {
var chunks = chunkBuffer(apdu, function (i) { return mtuSize - (i === 0 ? 5 : 3); }).map(function (buffer, i) {
var head = Buffer.alloc(i === 0 ? 5 : 3);
export const sendAPDU = (write, apdu, mtuSize) => {
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);

@@ -70,46 +32,17 @@ head.writeUInt16BE(i, 1);

});
return new Observable(function (o) {
var terminated = false;
return new Observable((o) => {
let terminated = false;
function main() {
return __awaiter(this, void 0, void 0, function () {
var chunks_1, chunks_1_1, chunk, e_1_1;
var e_1, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 5, 6, 7]);
chunks_1 = __values(chunks), chunks_1_1 = chunks_1.next();
_b.label = 1;
case 1:
if (!!chunks_1_1.done) return [3 /*break*/, 4];
chunk = chunks_1_1.value;
if (terminated)
return [2 /*return*/];
return [4 /*yield*/, write(chunk)];
case 2:
_b.sent();
_b.label = 3;
case 3:
chunks_1_1 = chunks_1.next();
return [3 /*break*/, 1];
case 4: return [3 /*break*/, 7];
case 5:
e_1_1 = _b.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 7];
case 6:
try {
if (chunks_1_1 && !chunks_1_1.done && (_a = chunks_1["return"])) _a.call(chunks_1);
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 7: return [2 /*return*/];
}
});
return __awaiter(this, void 0, void 0, function* () {
for (const chunk of chunks) {
if (terminated)
return;
yield write(chunk);
}
});
}
main().then(function () {
main().then(() => {
terminated = true;
o.complete();
}, function (e) {
}, (e) => {
terminated = true;

@@ -119,3 +52,3 @@ log("ble-error", "sendAPDU failure " + String(e));

});
var unsubscribe = function () {
const unsubscribe = () => {
if (!terminated) {

@@ -122,0 +55,0 @@ log("ble-verbose", "sendAPDU interruption");

import { DeviceModelId } from ".";
export var stringToDeviceModelId = function (strDeviceModelId, defaultDeviceModelId) {
export const stringToDeviceModelId = (strDeviceModelId, defaultDeviceModelId) => {
var _a;

@@ -4,0 +4,0 @@ if ((_a = Object.values(DeviceModelId)) === null || _a === void 0 ? void 0 : _a.includes(strDeviceModelId)) {

@@ -1,43 +0,17 @@

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 { DeviceModelId } from ".";
import { stringToDeviceModelId } from "./helpers";
describe("stringToDeviceModelId", function () {
var tests = [
describe("stringToDeviceModelId", () => {
const tests = [
{
input: ["stax", DeviceModelId.nanoSP],
expectedOutput: DeviceModelId.stax
expectedOutput: DeviceModelId.stax,
},
{
input: ["does-not-exist", DeviceModelId.nanoSP],
expectedOutput: DeviceModelId.nanoSP
expectedOutput: DeviceModelId.nanoSP,
},
];
tests.forEach(function (_a) {
var input = _a.input, expectedOutput = _a.expectedOutput;
test("Input: ".concat(JSON.stringify(input), " -> Expected output: ").concat(expectedOutput), function () {
var result = stringToDeviceModelId.apply(void 0, __spreadArray([], __read(input), false));
tests.forEach(({ input, expectedOutput }) => {
test(`Input: ${JSON.stringify(input)} -> Expected output: ${expectedOutput}`, () => {
const result = stringToDeviceModelId(...input);
expect(result).toEqual(expectedOutput);

@@ -44,0 +18,0 @@ });

/// <reference types="node" />
export declare type ResponseAcc = {
export type ResponseAcc = {
data: Buffer;

@@ -4,0 +4,0 @@ dataLength: number;

import { TransportError } from "@ledgerhq/errors";
var Tag = 0x05;
const Tag = 0x05;
function asUInt16BE(value) {
var b = Buffer.alloc(2);
const b = Buffer.alloc(2);
b.writeUInt16BE(value, 0);
return b;
}
var initialAcc = {
const initialAcc = {
data: Buffer.alloc(0),
dataLength: 0,
sequence: 0
sequence: 0,
};

@@ -16,8 +16,8 @@ /**

*/
var createHIDframing = function (channel, packetSize) {
const createHIDframing = (channel, packetSize) => {
return {
makeBlocks: function (apdu) {
var data = Buffer.concat([asUInt16BE(apdu.length), apdu]);
var blockSize = packetSize - 5;
var nbBlocks = Math.ceil(data.length / blockSize);
makeBlocks(apdu) {
let data = Buffer.concat([asUInt16BE(apdu.length), apdu]);
const blockSize = packetSize - 5;
const nbBlocks = Math.ceil(data.length / blockSize);
data = Buffer.concat([

@@ -27,9 +27,9 @@ data,

]);
var blocks = [];
for (var i = 0; i < nbBlocks; i++) {
var head = Buffer.alloc(5);
const blocks = [];
for (let i = 0; i < nbBlocks; i++) {
const head = Buffer.alloc(5);
head.writeUInt16BE(channel, 0);
head.writeUInt8(Tag, 2);
head.writeUInt16BE(i, 3);
var chunk = data.slice(i * blockSize, (i + 1) * blockSize);
const chunk = data.slice(i * blockSize, (i + 1) * blockSize);
blocks.push(Buffer.concat([head, chunk]));

@@ -39,4 +39,4 @@ }

},
reduceResponse: function (acc, chunk) {
var _a = acc || initialAcc, data = _a.data, dataLength = _a.dataLength, sequence = _a.sequence;
reduceResponse(acc, chunk) {
let { data, dataLength, sequence } = acc || initialAcc;
if (chunk.readUInt16BE(0) !== channel) {

@@ -55,3 +55,3 @@ throw new TransportError("Invalid channel", "InvalidChannel");

sequence++;
var chunkData = chunk.slice(acc ? 5 : 7);
const chunkData = chunk.slice(acc ? 5 : 7);
data = Buffer.concat([data, chunkData]);

@@ -62,12 +62,12 @@ if (data.length > dataLength) {

return {
data: data,
dataLength: dataLength,
sequence: sequence
data,
dataLength,
sequence,
};
},
getReducedResult: function (acc) {
getReducedResult(acc) {
if (acc && acc.dataLength === acc.data.length) {
return acc.data;
}
}
},
};

@@ -74,0 +74,0 @@ };

@@ -1,13 +0,1 @@

var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var _a;
import semver from "semver";

@@ -29,7 +17,7 @@ /**

*/
export var IIGenericHID = 0x01;
export var IIKeyboardHID = 0x02;
export var IIU2F = 0x04;
export var IICCID = 0x08;
export var IIWebUSB = 0x10;
export const IIGenericHID = 0x01;
export const IIKeyboardHID = 0x02;
export const IIU2F = 0x04;
export const IICCID = 0x08;
export const IIWebUSB = 0x10;
export var DeviceModelId;

@@ -43,4 +31,4 @@ (function (DeviceModelId) {

})(DeviceModelId || (DeviceModelId = {}));
var devices = (_a = {},
_a[DeviceModelId.blue] = {
const devices = {
[DeviceModelId.blue]: {
id: DeviceModelId.blue,

@@ -53,5 +41,5 @@ productName: "Ledger Blue",

masks: [0x31000000, 0x31010000],
getBlockSize: function (_firwareVersion) { return 4 * 1024; }
getBlockSize: (_firwareVersion) => 4 * 1024,
},
_a[DeviceModelId.nanoS] = {
[DeviceModelId.nanoS]: {
id: DeviceModelId.nanoS,

@@ -64,3 +52,3 @@ productName: "Ledger Nano S",

masks: [0x31100000],
getBlockSize: function (firmwareVersion) {
getBlockSize: (firmwareVersion) => {
var _a;

@@ -70,5 +58,5 @@ return semver.lt((_a = semver.coerce(firmwareVersion)) !== null && _a !== void 0 ? _a : "", "2.0.0")

: 2 * 1024;
}
},
},
_a[DeviceModelId.nanoSP] = {
[DeviceModelId.nanoSP]: {
id: DeviceModelId.nanoSP,

@@ -81,5 +69,5 @@ productName: "Ledger Nano S Plus",

masks: [0x33100000],
getBlockSize: function (_firmwareVersion) { return 32; }
getBlockSize: (_firmwareVersion) => 32,
},
_a[DeviceModelId.nanoX] = {
[DeviceModelId.nanoX]: {
id: DeviceModelId.nanoX,

@@ -92,3 +80,3 @@ productName: "Ledger Nano X",

masks: [0x33000000],
getBlockSize: function (_firwareVersion) { return 4 * 1024; },
getBlockSize: (_firwareVersion) => 4 * 1024,
bluetoothSpec: [

@@ -99,7 +87,7 @@ {

writeUuid: "13d63400-2c97-0004-0002-4c6564676572",
writeCmdUuid: "13d63400-2c97-0004-0003-4c6564676572"
writeCmdUuid: "13d63400-2c97-0004-0003-4c6564676572",
},
]
],
},
_a[DeviceModelId.stax] = {
[DeviceModelId.stax]: {
id: DeviceModelId.stax,

@@ -112,3 +100,3 @@ productName: "Ledger Stax",

masks: [0x33200000],
getBlockSize: function (_firmwareVersion) { return 32; },
getBlockSize: (_firmwareVersion) => 32,
bluetoothSpec: [

@@ -119,8 +107,8 @@ {

writeUuid: "13d63400-2c97-6004-0002-4c6564676572",
writeCmdUuid: "13d63400-2c97-6004-0003-4c6564676572"
writeCmdUuid: "13d63400-2c97-6004-0003-4c6564676572",
},
]
],
},
_a);
var productMap = {
};
const productMap = {
Blue: DeviceModelId.blue,

@@ -130,14 +118,14 @@ "Nano S": DeviceModelId.nanoS,

"Nano X": DeviceModelId.nanoX,
Stax: DeviceModelId.stax
Stax: DeviceModelId.stax,
};
var devicesList = Object.values(devices);
const devicesList = Object.values(devices);
/**
*
*/
export var ledgerUSBVendorId = 0x2c97;
export const ledgerUSBVendorId = 0x2c97;
/**
*
*/
export var getDeviceModel = function (id) {
var info = devices[id];
export const getDeviceModel = (id) => {
const info = devices[id];
if (!info)

@@ -151,7 +139,4 @@ throw new Error("device '" + id + "' does not exist");

*/
export var identifyTargetId = function (targetId) {
var deviceModel = devicesList.find(function (_a) {
var masks = _a.masks;
return masks.find(function (mask) { return (targetId & 0xffff0000) === mask; });
});
export const identifyTargetId = (targetId) => {
const deviceModel = devicesList.find(({ masks }) => masks.find((mask) => (targetId & 0xffff0000) === mask));
return deviceModel;

@@ -162,24 +147,24 @@ };

*/
export var identifyUSBProductId = function (usbProductId) {
var legacy = devicesList.find(function (d) { return d.legacyUsbProductId === usbProductId; });
export const identifyUSBProductId = (usbProductId) => {
const legacy = devicesList.find((d) => d.legacyUsbProductId === usbProductId);
if (legacy)
return legacy;
var mm = usbProductId >> 8;
var deviceModel = devicesList.find(function (d) { return d.productIdMM === mm; });
const mm = usbProductId >> 8;
const deviceModel = devicesList.find((d) => d.productIdMM === mm);
return deviceModel;
};
export var identifyProductName = function (productName) {
var deviceModel = devicesList.find(function (d) { return d.id === productMap[productName]; });
export const identifyProductName = (productName) => {
const deviceModel = devicesList.find((d) => d.id === productMap[productName]);
return deviceModel;
};
var bluetoothServices = [];
var serviceUuidToInfos = {};
for (var id in devices) {
var deviceModel = devices[id];
var bluetoothSpec = deviceModel.bluetoothSpec;
const bluetoothServices = [];
const serviceUuidToInfos = {};
for (const id in devices) {
const deviceModel = devices[id];
const { bluetoothSpec } = deviceModel;
if (bluetoothSpec) {
for (var i = 0; i < bluetoothSpec.length; i++) {
var spec = bluetoothSpec[i];
for (let i = 0; i < bluetoothSpec.length; i++) {
const spec = bluetoothSpec[i];
bluetoothServices.push(spec.serviceUuid);
serviceUuidToInfos[spec.serviceUuid] = serviceUuidToInfos[spec.serviceUuid.replace(/-/g, "")] = __assign({ deviceModel: deviceModel }, spec);
serviceUuidToInfos[spec.serviceUuid] = serviceUuidToInfos[spec.serviceUuid.replace(/-/g, "")] = Object.assign({ deviceModel }, spec);
}

@@ -191,7 +176,7 @@ }

*/
export var getBluetoothServiceUuids = function () { return bluetoothServices; };
export const getBluetoothServiceUuids = () => bluetoothServices;
/**
*
*/
export var getInfosForServiceUuid = function (uuid) { return serviceUuidToInfos[uuid.toLowerCase()]; };
export const getInfosForServiceUuid = (uuid) => serviceUuidToInfos[uuid.toLowerCase()];
//# sourceMappingURL=index.js.map
export function wrapApdu(apdu, key) {
if (apdu.length === 0)
return apdu;
var result = Buffer.alloc(apdu.length);
for (var i = 0; i < apdu.length; i++) {
const result = Buffer.alloc(apdu.length);
for (let i = 0; i < apdu.length; i++) {
result[i] = apdu[i] ^ key[i % key.length];

@@ -7,0 +7,0 @@ }

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.receiveAPDU = void 0;
var errors_1 = require("@ledgerhq/errors");
var rxjs_1 = require("rxjs");
var logs_1 = require("@ledgerhq/logs");
var TagId = 0x05;
const errors_1 = require("@ledgerhq/errors");
const rxjs_1 = require("rxjs");
const logs_1 = require("@ledgerhq/logs");
const TagId = 0x05;
// operator that transform the input raw stream into one apdu response and finishes
var receiveAPDU = function (rawStream) {
return rxjs_1.Observable.create(function (o) {
var notifiedIndex = 0;
var notifiedDataLength = 0;
var notifiedData = Buffer.alloc(0);
var sub = rawStream.subscribe({
complete: function () {
o.error(new errors_1.DisconnectedDevice());
const receiveAPDU = (rawStream) => rxjs_1.Observable.create((o) => {
let notifiedIndex = 0;
let notifiedDataLength = 0;
let notifiedData = Buffer.alloc(0);
const sub = rawStream.subscribe({
complete: () => {
o.error(new errors_1.DisconnectedDevice());
sub.unsubscribe();
},
error: (e) => {
(0, logs_1.log)("ble-error", "in receiveAPDU " + String(e));
o.error(e);
sub.unsubscribe();
},
next: (value) => {
const tag = value.readUInt8(0);
const index = value.readUInt16BE(1);
let data = value.slice(3);
if (tag !== TagId) {
o.error(new errors_1.TransportError("Invalid tag " + tag.toString(16), "InvalidTag"));
return;
}
if (notifiedIndex !== index) {
o.error(new errors_1.TransportError("BLE: Invalid sequence number. discontinued chunk. Received " +
index +
" but expected " +
notifiedIndex, "InvalidSequence"));
return;
}
if (index === 0) {
notifiedDataLength = data.readUInt16BE(0);
data = data.slice(2);
}
notifiedIndex++;
notifiedData = Buffer.concat([notifiedData, data]);
if (notifiedData.length > notifiedDataLength) {
o.error(new errors_1.TransportError("BLE: received too much data. discontinued chunk. Received " +
notifiedData.length +
" but expected " +
notifiedDataLength, "BLETooMuchData"));
return;
}
if (notifiedData.length === notifiedDataLength) {
o.next(notifiedData);
o.complete();
sub.unsubscribe();
},
error: function (e) {
(0, logs_1.log)("ble-error", "in receiveAPDU " + String(e));
o.error(e);
sub.unsubscribe();
},
next: function (value) {
var tag = value.readUInt8(0);
var index = value.readUInt16BE(1);
var data = value.slice(3);
if (tag !== TagId) {
o.error(new errors_1.TransportError("Invalid tag " + tag.toString(16), "InvalidTag"));
return;
}
if (notifiedIndex !== index) {
o.error(new errors_1.TransportError("BLE: Invalid sequence number. discontinued chunk. Received " +
index +
" but expected " +
notifiedIndex, "InvalidSequence"));
return;
}
if (index === 0) {
notifiedDataLength = data.readUInt16BE(0);
data = data.slice(2);
}
notifiedIndex++;
notifiedData = Buffer.concat([notifiedData, data]);
if (notifiedData.length > notifiedDataLength) {
o.error(new errors_1.TransportError("BLE: received too much data. discontinued chunk. Received " +
notifiedData.length +
" but expected " +
notifiedDataLength, "BLETooMuchData"));
return;
}
if (notifiedData.length === notifiedDataLength) {
o.next(notifiedData);
o.complete();
sub.unsubscribe();
}
}
});
return function () {
sub.unsubscribe();
};
},
});
};
return () => {
sub.unsubscribe();
};
});
exports.receiveAPDU = receiveAPDU;
//# sourceMappingURL=receiveAPDU.js.map

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

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
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.");
};
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendAPDU = void 0;
var rxjs_1 = require("rxjs");
var logs_1 = require("@ledgerhq/logs");
var TagId = 0x05;
const rxjs_1 = require("rxjs");
const logs_1 = require("@ledgerhq/logs");
const TagId = 0x05;
function chunkBuffer(buffer, sizeForIndex) {
var chunks = [];
for (var i = 0, size = sizeForIndex(0); i < buffer.length; i += size, size = sizeForIndex(i)) {
const chunks = [];
for (let i = 0, size = sizeForIndex(0); i < buffer.length; i += size, size = sizeForIndex(i)) {
chunks.push(buffer.slice(i, i + size));

@@ -62,5 +24,5 @@ }

}
var sendAPDU = function (write, apdu, mtuSize) {
var chunks = chunkBuffer(apdu, function (i) { return mtuSize - (i === 0 ? 5 : 3); }).map(function (buffer, i) {
var head = Buffer.alloc(i === 0 ? 5 : 3);
const sendAPDU = (write, apdu, mtuSize) => {
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);

@@ -73,46 +35,17 @@ head.writeUInt16BE(i, 1);

});
return new rxjs_1.Observable(function (o) {
var terminated = false;
return new rxjs_1.Observable((o) => {
let terminated = false;
function main() {
return __awaiter(this, void 0, void 0, function () {
var chunks_1, chunks_1_1, chunk, e_1_1;
var e_1, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 5, 6, 7]);
chunks_1 = __values(chunks), chunks_1_1 = chunks_1.next();
_b.label = 1;
case 1:
if (!!chunks_1_1.done) return [3 /*break*/, 4];
chunk = chunks_1_1.value;
if (terminated)
return [2 /*return*/];
return [4 /*yield*/, write(chunk)];
case 2:
_b.sent();
_b.label = 3;
case 3:
chunks_1_1 = chunks_1.next();
return [3 /*break*/, 1];
case 4: return [3 /*break*/, 7];
case 5:
e_1_1 = _b.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 7];
case 6:
try {
if (chunks_1_1 && !chunks_1_1.done && (_a = chunks_1["return"])) _a.call(chunks_1);
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 7: return [2 /*return*/];
}
});
return __awaiter(this, void 0, void 0, function* () {
for (const chunk of chunks) {
if (terminated)
return;
yield write(chunk);
}
});
}
main().then(function () {
main().then(() => {
terminated = true;
o.complete();
}, function (e) {
}, (e) => {
terminated = true;

@@ -122,3 +55,3 @@ (0, logs_1.log)("ble-error", "sendAPDU failure " + String(e));

});
var unsubscribe = function () {
const unsubscribe = () => {
if (!terminated) {

@@ -125,0 +58,0 @@ (0, logs_1.log)("ble-verbose", "sendAPDU interruption");

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringToDeviceModelId = void 0;
var _1 = require(".");
var stringToDeviceModelId = function (strDeviceModelId, defaultDeviceModelId) {
const _1 = require(".");
const stringToDeviceModelId = (strDeviceModelId, defaultDeviceModelId) => {
var _a;

@@ -7,0 +7,0 @@ if ((_a = Object.values(_1.DeviceModelId)) === null || _a === void 0 ? void 0 : _a.includes(strDeviceModelId)) {

"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));
};
exports.__esModule = true;
var _1 = require(".");
var helpers_1 = require("./helpers");
describe("stringToDeviceModelId", function () {
var tests = [
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require(".");
const helpers_1 = require("./helpers");
describe("stringToDeviceModelId", () => {
const tests = [
{
input: ["stax", _1.DeviceModelId.nanoSP],
expectedOutput: _1.DeviceModelId.stax
expectedOutput: _1.DeviceModelId.stax,
},
{
input: ["does-not-exist", _1.DeviceModelId.nanoSP],
expectedOutput: _1.DeviceModelId.nanoSP
expectedOutput: _1.DeviceModelId.nanoSP,
},
];
tests.forEach(function (_a) {
var input = _a.input, expectedOutput = _a.expectedOutput;
test("Input: ".concat(JSON.stringify(input), " -> Expected output: ").concat(expectedOutput), function () {
var result = helpers_1.stringToDeviceModelId.apply(void 0, __spreadArray([], __read(input), false));
tests.forEach(({ input, expectedOutput }) => {
test(`Input: ${JSON.stringify(input)} -> Expected output: ${expectedOutput}`, () => {
const result = (0, helpers_1.stringToDeviceModelId)(...input);
expect(result).toEqual(expectedOutput);

@@ -46,0 +20,0 @@ });

/// <reference types="node" />
export declare type ResponseAcc = {
export type ResponseAcc = {
data: Buffer;

@@ -4,0 +4,0 @@ dataLength: number;

"use strict";
exports.__esModule = true;
var errors_1 = require("@ledgerhq/errors");
var Tag = 0x05;
Object.defineProperty(exports, "__esModule", { value: true });
const errors_1 = require("@ledgerhq/errors");
const Tag = 0x05;
function asUInt16BE(value) {
var b = Buffer.alloc(2);
const b = Buffer.alloc(2);
b.writeUInt16BE(value, 0);
return b;
}
var initialAcc = {
const initialAcc = {
data: Buffer.alloc(0),
dataLength: 0,
sequence: 0
sequence: 0,
};

@@ -18,8 +18,8 @@ /**

*/
var createHIDframing = function (channel, packetSize) {
const createHIDframing = (channel, packetSize) => {
return {
makeBlocks: function (apdu) {
var data = Buffer.concat([asUInt16BE(apdu.length), apdu]);
var blockSize = packetSize - 5;
var nbBlocks = Math.ceil(data.length / blockSize);
makeBlocks(apdu) {
let data = Buffer.concat([asUInt16BE(apdu.length), apdu]);
const blockSize = packetSize - 5;
const nbBlocks = Math.ceil(data.length / blockSize);
data = Buffer.concat([

@@ -29,9 +29,9 @@ data,

]);
var blocks = [];
for (var i = 0; i < nbBlocks; i++) {
var head = Buffer.alloc(5);
const blocks = [];
for (let i = 0; i < nbBlocks; i++) {
const head = Buffer.alloc(5);
head.writeUInt16BE(channel, 0);
head.writeUInt8(Tag, 2);
head.writeUInt16BE(i, 3);
var chunk = data.slice(i * blockSize, (i + 1) * blockSize);
const chunk = data.slice(i * blockSize, (i + 1) * blockSize);
blocks.push(Buffer.concat([head, chunk]));

@@ -41,4 +41,4 @@ }

},
reduceResponse: function (acc, chunk) {
var _a = acc || initialAcc, data = _a.data, dataLength = _a.dataLength, sequence = _a.sequence;
reduceResponse(acc, chunk) {
let { data, dataLength, sequence } = acc || initialAcc;
if (chunk.readUInt16BE(0) !== channel) {

@@ -57,3 +57,3 @@ throw new errors_1.TransportError("Invalid channel", "InvalidChannel");

sequence++;
var chunkData = chunk.slice(acc ? 5 : 7);
const chunkData = chunk.slice(acc ? 5 : 7);
data = Buffer.concat([data, chunkData]);

@@ -64,15 +64,15 @@ if (data.length > dataLength) {

return {
data: data,
dataLength: dataLength,
sequence: sequence
data,
dataLength,
sequence,
};
},
getReducedResult: function (acc) {
getReducedResult(acc) {
if (acc && acc.dataLength === acc.data.length) {
return acc.data;
}
}
},
};
};
exports["default"] = createHIDframing;
exports.default = createHIDframing;
//# sourceMappingURL=hid-framing.js.map
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInfosForServiceUuid = exports.getBluetoothServiceUuids = exports.identifyProductName = exports.identifyUSBProductId = exports.identifyTargetId = exports.getDeviceModel = exports.ledgerUSBVendorId = exports.DeviceModelId = exports.IIWebUSB = exports.IICCID = exports.IIU2F = exports.IIKeyboardHID = exports.IIGenericHID = void 0;
var semver_1 = __importDefault(require("semver"));
const semver_1 = __importDefault(require("semver"));
/**

@@ -48,4 +36,4 @@ * The USB product IDs will be defined as MMII, encoding a model (MM) and an interface bitfield (II)

})(DeviceModelId = exports.DeviceModelId || (exports.DeviceModelId = {}));
var devices = (_a = {},
_a[DeviceModelId.blue] = {
const devices = {
[DeviceModelId.blue]: {
id: DeviceModelId.blue,

@@ -58,5 +46,5 @@ productName: "Ledger Blue",

masks: [0x31000000, 0x31010000],
getBlockSize: function (_firwareVersion) { return 4 * 1024; }
getBlockSize: (_firwareVersion) => 4 * 1024,
},
_a[DeviceModelId.nanoS] = {
[DeviceModelId.nanoS]: {
id: DeviceModelId.nanoS,

@@ -69,10 +57,10 @@ productName: "Ledger Nano S",

masks: [0x31100000],
getBlockSize: function (firmwareVersion) {
getBlockSize: (firmwareVersion) => {
var _a;
return semver_1["default"].lt((_a = semver_1["default"].coerce(firmwareVersion)) !== null && _a !== void 0 ? _a : "", "2.0.0")
return semver_1.default.lt((_a = semver_1.default.coerce(firmwareVersion)) !== null && _a !== void 0 ? _a : "", "2.0.0")
? 4 * 1024
: 2 * 1024;
}
},
},
_a[DeviceModelId.nanoSP] = {
[DeviceModelId.nanoSP]: {
id: DeviceModelId.nanoSP,

@@ -85,5 +73,5 @@ productName: "Ledger Nano S Plus",

masks: [0x33100000],
getBlockSize: function (_firmwareVersion) { return 32; }
getBlockSize: (_firmwareVersion) => 32,
},
_a[DeviceModelId.nanoX] = {
[DeviceModelId.nanoX]: {
id: DeviceModelId.nanoX,

@@ -96,3 +84,3 @@ productName: "Ledger Nano X",

masks: [0x33000000],
getBlockSize: function (_firwareVersion) { return 4 * 1024; },
getBlockSize: (_firwareVersion) => 4 * 1024,
bluetoothSpec: [

@@ -103,7 +91,7 @@ {

writeUuid: "13d63400-2c97-0004-0002-4c6564676572",
writeCmdUuid: "13d63400-2c97-0004-0003-4c6564676572"
writeCmdUuid: "13d63400-2c97-0004-0003-4c6564676572",
},
]
],
},
_a[DeviceModelId.stax] = {
[DeviceModelId.stax]: {
id: DeviceModelId.stax,

@@ -116,3 +104,3 @@ productName: "Ledger Stax",

masks: [0x33200000],
getBlockSize: function (_firmwareVersion) { return 32; },
getBlockSize: (_firmwareVersion) => 32,
bluetoothSpec: [

@@ -123,8 +111,8 @@ {

writeUuid: "13d63400-2c97-6004-0002-4c6564676572",
writeCmdUuid: "13d63400-2c97-6004-0003-4c6564676572"
writeCmdUuid: "13d63400-2c97-6004-0003-4c6564676572",
},
]
],
},
_a);
var productMap = {
};
const productMap = {
Blue: DeviceModelId.blue,

@@ -134,5 +122,5 @@ "Nano S": DeviceModelId.nanoS,

"Nano X": DeviceModelId.nanoX,
Stax: DeviceModelId.stax
Stax: DeviceModelId.stax,
};
var devicesList = Object.values(devices);
const devicesList = Object.values(devices);
/**

@@ -145,4 +133,4 @@ *

*/
var getDeviceModel = function (id) {
var info = devices[id];
const getDeviceModel = (id) => {
const info = devices[id];
if (!info)

@@ -157,7 +145,4 @@ throw new Error("device '" + id + "' does not exist");

*/
var identifyTargetId = function (targetId) {
var deviceModel = devicesList.find(function (_a) {
var masks = _a.masks;
return masks.find(function (mask) { return (targetId & 0xffff0000) === mask; });
});
const identifyTargetId = (targetId) => {
const deviceModel = devicesList.find(({ masks }) => masks.find((mask) => (targetId & 0xffff0000) === mask));
return deviceModel;

@@ -169,26 +154,26 @@ };

*/
var identifyUSBProductId = function (usbProductId) {
var legacy = devicesList.find(function (d) { return d.legacyUsbProductId === usbProductId; });
const identifyUSBProductId = (usbProductId) => {
const legacy = devicesList.find((d) => d.legacyUsbProductId === usbProductId);
if (legacy)
return legacy;
var mm = usbProductId >> 8;
var deviceModel = devicesList.find(function (d) { return d.productIdMM === mm; });
const mm = usbProductId >> 8;
const deviceModel = devicesList.find((d) => d.productIdMM === mm);
return deviceModel;
};
exports.identifyUSBProductId = identifyUSBProductId;
var identifyProductName = function (productName) {
var deviceModel = devicesList.find(function (d) { return d.id === productMap[productName]; });
const identifyProductName = (productName) => {
const deviceModel = devicesList.find((d) => d.id === productMap[productName]);
return deviceModel;
};
exports.identifyProductName = identifyProductName;
var bluetoothServices = [];
var serviceUuidToInfos = {};
for (var id in devices) {
var deviceModel = devices[id];
var bluetoothSpec = deviceModel.bluetoothSpec;
const bluetoothServices = [];
const serviceUuidToInfos = {};
for (const id in devices) {
const deviceModel = devices[id];
const { bluetoothSpec } = deviceModel;
if (bluetoothSpec) {
for (var i = 0; i < bluetoothSpec.length; i++) {
var spec = bluetoothSpec[i];
for (let i = 0; i < bluetoothSpec.length; i++) {
const spec = bluetoothSpec[i];
bluetoothServices.push(spec.serviceUuid);
serviceUuidToInfos[spec.serviceUuid] = serviceUuidToInfos[spec.serviceUuid.replace(/-/g, "")] = __assign({ deviceModel: deviceModel }, spec);
serviceUuidToInfos[spec.serviceUuid] = serviceUuidToInfos[spec.serviceUuid.replace(/-/g, "")] = Object.assign({ deviceModel }, spec);
}

@@ -200,3 +185,3 @@ }

*/
var getBluetoothServiceUuids = function () { return bluetoothServices; };
const getBluetoothServiceUuids = () => bluetoothServices;
exports.getBluetoothServiceUuids = getBluetoothServiceUuids;

@@ -206,4 +191,4 @@ /**

*/
var getInfosForServiceUuid = function (uuid) { return serviceUuidToInfos[uuid.toLowerCase()]; };
const getInfosForServiceUuid = (uuid) => serviceUuidToInfos[uuid.toLowerCase()];
exports.getInfosForServiceUuid = getInfosForServiceUuid;
//# sourceMappingURL=index.js.map
"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapApdu = void 0;

@@ -7,4 +7,4 @@ function wrapApdu(apdu, key) {

return apdu;
var result = Buffer.alloc(apdu.length);
for (var i = 0; i < apdu.length; i++) {
const result = Buffer.alloc(apdu.length);
for (let i = 0; i < apdu.length; i++) {
result[i] = apdu[i] ^ key[i % key.length];

@@ -11,0 +11,0 @@ }

{
"name": "@ledgerhq/devices",
"version": "8.0.1",
"version": "8.0.2-nightly.0",
"description": "Ledger devices",

@@ -58,3 +58,3 @@ "keywords": [

"semver": "^7.3.5",
"@ledgerhq/errors": "^6.12.4",
"@ledgerhq/errors": "^6.12.5-nightly.0",
"@ledgerhq/logs": "^6.10.1"

@@ -68,7 +68,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"
},

@@ -75,0 +74,0 @@ "gitHead": "dd0dea64b58e5a9125c8a422dcffd29e5ef6abec",

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

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