Socket
Socket
Sign inDemoInstall

@ledgerhq/hw-transport

Package Overview
Dependencies
Maintainers
6
Versions
366
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ledgerhq/hw-transport - npm Package Compare versions

Comparing version 2.0.5 to 2.1.0

92

lib/Transport.js

@@ -6,7 +6,6 @@ "use strict";

});
exports.StatusCodes = undefined;
exports.TransportError = TransportError;
exports.TransportStatusError = TransportStatusError;
var _invariant = require("invariant");
var _invariant2 = _interopRequireDefault(_invariant);
var _events = require("events");

@@ -21,2 +20,71 @@

/**
* all possible status codes.
* @see https://ledgerhq.github.io/btchip-doc/bitcoin-technical.html#_status_words
* @example
* import { StatusCodes } from "@ledgerhq/hw-transport";
*/
/**
*/
/**
*/
/**
*/
const StatusCodes = exports.StatusCodes = {
/**
* Incorrect length
*/
IncorrectLength: 0x6700,
/**
* Security status not satisfied (Bitcoin dongle is locked or invalid access rights)
*/
SecurityNotSatisfied: 0x6982,
/**
* Invalid data
*/
InvalidData: 0x6a80,
/**
* File not found
*/
FileNotFound: 0x6a82,
/**
* Incorrect parameter P1 or P2
*/
IncorrectParameter: 0x6b00,
/**
* Success
*/
Success: 0x9000
};
/**
* TransportError is used for any generic transport errors.
* e.g. Error thrown when data received by exchanges are incorrect or if exchanged failed to communicate with the device for various reason.
*/
function TransportError(message, id) {
this.name = "TransportError";
this.message = message;
this.stack = new Error().stack;
this.id = id;
}
//$FlowFixMe
TransportError.prototype = new Error();
/**
* Error thrown when a device returned a non success status.
* the error.statusCode is one of the `StatusCodes` exported by this library.
*/
function TransportStatusError(statusCode) {
this.name = "TransportStatusError";
this.message = "Invalid status " + statusCode.toString(16);
this.stack = new Error().stack;
this.statusCode = statusCode;
}
//$FlowFixMe
TransportStatusError.prototype = new Error();
/**
* Transport defines the generic interface to share between node/u2f impl

@@ -34,9 +102,13 @@ * A **Descriptor** is a parametric type that is up to be determined for the implementation.

this.send = (() => {
var _ref = _asyncToGenerator(function* (cla, ins, p1, p2, data = Buffer.alloc(0), statusList = [0x9000]) {
(0, _invariant2.default)(data.length < 256, "data.length exceed 256 bytes limit. Got: %s", data.length);
var _ref = _asyncToGenerator(function* (cla, ins, p1, p2, data = Buffer.alloc(0), statusList = [StatusCodes.Success]) {
if (data.length >= 256) {
throw new TransportError("data.length exceed 256 bytes limit. Got: " + data.length, "DataLengthTooBig");
}
const response = yield _this.exchange(Buffer.concat([Buffer.from([cla, ins, p1, p2]), Buffer.from([data.length]), data]));
const sw = response.readUInt16BE(response.length - 2);
(0, _invariant2.default)(statusList.some(function (s) {
if (!statusList.some(function (s) {
return s === sw;
}), "Invalid status %s", sw.toString(16));
})) {
throw new TransportStatusError(sw);
}
return response;

@@ -162,3 +234,5 @@ });

const descriptors = yield _this2.list();
(0, _invariant2.default)(descriptors.length !== 0, "No device found");
if (descriptors.length === 0) {
throw new TransportError("No device found", "NoDeviceFound");
}
const transport = yield _this2.open(descriptors[0], timeout);

@@ -165,0 +239,0 @@ transport.setDebugMode(debug);

5

package.json
{
"name": "@ledgerhq/hw-transport",
"version": "2.0.5",
"version": "2.1.0",
"description": "Ledger Hardware Wallet common interface of the communication layer",

@@ -26,4 +26,3 @@ "keywords": [

"dependencies": {
"events": "^1.1.1",
"invariant": "^2.2.0"
"events": "^1.1.1"
},

@@ -30,0 +29,0 @@ "devDependencies": {

//@flow
import invariant from "invariant";
import EventEmitter from "events";
/**
*/
export type Subscription = { unsubscribe: () => void };
/**
*/
export type DescriptorEvent<Descriptor> = {

@@ -11,4 +14,6 @@ type: "add" | "remove",

};
export type Observer<Descriptor> = {
next: (event: DescriptorEvent<Descriptor>) => void,
/**
*/
export type Observer<Ev> = {
next: (event: Ev) => void,
error: (e: ?Error) => void,

@@ -19,2 +24,61 @@ complete: () => void

/**
* all possible status codes.
* @see https://ledgerhq.github.io/btchip-doc/bitcoin-technical.html#_status_words
* @example
* import { StatusCodes } from "@ledgerhq/hw-transport";
*/
export const StatusCodes = {
/**
* Incorrect length
*/
IncorrectLength: 0x6700,
/**
* Security status not satisfied (Bitcoin dongle is locked or invalid access rights)
*/
SecurityNotSatisfied: 0x6982,
/**
* Invalid data
*/
InvalidData: 0x6a80,
/**
* File not found
*/
FileNotFound: 0x6a82,
/**
* Incorrect parameter P1 or P2
*/
IncorrectParameter: 0x6b00,
/**
* Success
*/
Success: 0x9000
};
/**
* TransportError is used for any generic transport errors.
* e.g. Error thrown when data received by exchanges are incorrect or if exchanged failed to communicate with the device for various reason.
*/
export function TransportError(message: string, id: string) {
this.name = "TransportError";
this.message = message;
this.stack = new Error().stack;
this.id = id;
}
//$FlowFixMe
TransportError.prototype = new Error();
/**
* Error thrown when a device returned a non success status.
* the error.statusCode is one of the `StatusCodes` exported by this library.
*/
export function TransportStatusError(statusCode: number) {
this.name = "TransportStatusError";
this.message = "Invalid status " + statusCode.toString(16);
this.stack = new Error().stack;
this.statusCode = statusCode;
}
//$FlowFixMe
TransportStatusError.prototype = new Error();
/**
* Transport defines the generic interface to share between node/u2f impl

@@ -139,9 +203,10 @@ * A **Descriptor** is a parametric type that is up to be determined for the implementation.

data: Buffer = Buffer.alloc(0),
statusList: Array<number> = [0x9000]
statusList: Array<number> = [StatusCodes.Success]
): Promise<Buffer> => {
invariant(
data.length < 256,
"data.length exceed 256 bytes limit. Got: %s",
data.length
);
if (data.length >= 256) {
throw new TransportError(
"data.length exceed 256 bytes limit. Got: " + data.length,
"DataLengthTooBig"
);
}
const response = await this.exchange(

@@ -155,7 +220,5 @@ Buffer.concat([

const sw = response.readUInt16BE(response.length - 2);
invariant(
statusList.some(s => s === sw),
"Invalid status %s",
sw.toString(16)
);
if (!statusList.some(s => s === sw)) {
throw new TransportStatusError(sw);
}
return response;

@@ -177,3 +240,5 @@ };

const descriptors = await this.list();
invariant(descriptors.length !== 0, "No device found");
if (descriptors.length === 0) {
throw new TransportError("No device found", "NoDeviceFound");
}
const transport = await this.open(descriptors[0], timeout);

@@ -180,0 +245,0 @@ transport.setDebugMode(debug);

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