Socket
Socket
Sign inDemoInstall

@ledgerhq/hw-transport

Package Overview
Dependencies
Maintainers
5
Versions
364
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 1.1.1-beta.068e2a14 to 1.1.2-beta.068e2a14

202

lib/Transport.js

@@ -7,4 +7,2 @@ "use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _invariant = require("invariant");

@@ -14,14 +12,10 @@

var _events2 = require("events");
var _events = require("events");
var _events3 = _interopRequireDefault(_events2);
var _events2 = _interopRequireDefault(_events);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**

@@ -32,39 +26,19 @@ * Transport defines the generic interface to share between node/u2f impl

*/
var Transport = function () {
function Transport() {
class Transport {
constructor() {
var _this = this;
_classCallCheck(this, Transport);
this.debug = false;
this._events = new _events3.default();
this._events = new _events2.default();
this.send = function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(cla, ins, p1, p2) {
var data = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : Buffer.alloc(0);
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
(0, _invariant2.default)(data.length < 256, "data.length exceed 256 bytes limit. Got: %s", data.length);
_context.t0 = Buffer;
_context.next = 4;
return _this.exchange(Buffer.concat([Buffer.from([cla, ins, p1, p2]), Buffer.from([data.length]), data]).toString("hex"), [0x9000]);
this.send = (() => {
var _ref = _asyncToGenerator(function* (cla, ins, p1, p2, data = Buffer.alloc(0)) {
(0, _invariant2.default)(data.length < 256, "data.length exceed 256 bytes limit. Got: %s", data.length);
return Buffer.from((yield _this.exchange(Buffer.concat([Buffer.from([cla, ins, p1, p2]), Buffer.from([data.length]), data]).toString("hex"), [0x9000])), "hex");
});
case 4:
_context.t1 = _context.sent;
return _context.abrupt("return", _context.t0.from.call(_context.t0, _context.t1, "hex"));
case 6:
case "end":
return _context.stop();
}
}
}, _callee, _this);
}));
return function (_x, _x2, _x3, _x4) {
return _ref.apply(this, arguments);
};
}();
})();
}

@@ -127,116 +101,60 @@

_createClass(Transport, [{
key: "on",
/**
* Listen to an event on an instance of transport.
* Transport implementation can have specific events. Here is the common events:
* * `"disconnect"` : triggered if Transport is disconnected
*/
on(eventName, cb) {
this._events.on(eventName, cb);
}
/**
* Stop listening to an event on an instance of transport.
*/
off(eventName, cb) {
this._events.removeListener(eventName, cb);
}
/**
* Listen to an event on an instance of transport.
* Transport implementation can have specific events. Here is the common events:
* * `"disconnect"` : triggered if Transport is disconnected
*/
value: function on(eventName, cb) {
this._events.on(eventName, cb);
}
emit(event, ...args) {
this._events.emit(event, ...args);
}
/**
* Stop listening to an event on an instance of transport.
*/
/**
* Enable or not logs of the binary exchange
*/
setDebugMode(debug) {
this.debug = debug;
}
}, {
key: "off",
value: function off(eventName, cb) {
this._events.removeListener(eventName, cb);
}
}, {
key: "emit",
value: function emit(event) {
var _events;
/**
* wrapper on top of exchange to simplify work of the implementation.
* @param cla
* @param ins
* @param p1
* @param p2
* @param data
* @return a Promise of response buffer
*/
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
(_events = this._events).emit.apply(_events, [event].concat(_toConsumableArray(args)));
}
/**
* create() allows to open the first descriptor available or throw if there is none.
* **DEPRECATED**: use `list()` or `discover()` and `open()` instead.
*/
static create(timeout, debug = false) {
var _this2 = this;
/**
* Enable or not logs of the binary exchange
*/
}, {
key: "setDebugMode",
value: function setDebugMode(debug) {
this.debug = debug;
}
/**
* wrapper on top of exchange to simplify work of the implementation.
* @param cla
* @param ins
* @param p1
* @param p2
* @param data
* @return a Promise of response buffer
*/
}], [{
key: "create",
/**
* create() allows to open the first descriptor available or throw if there is none.
* **DEPRECATED**: use `list()` or `discover()` and `open()` instead.
*/
value: function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(timeout) {
var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var descriptors, transport;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
console.warn(this.name + ".create is deprecated. Please use .list()/.discover() and .open() instead");
_context2.next = 3;
return this.list();
case 3:
descriptors = _context2.sent;
if (!(descriptors.length === 0)) {
_context2.next = 6;
break;
}
throw "No device found";
case 6:
_context2.next = 8;
return this.open(descriptors[0], timeout);
case 8:
transport = _context2.sent;
transport.setDebugMode(debug);
return _context2.abrupt("return", transport);
case 11:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
function create(_x6) {
return _ref2.apply(this, arguments);
return _asyncToGenerator(function* () {
console.warn(_this2.name + ".create is deprecated. Please use .list()/.discover() and .open() instead");
const descriptors = yield _this2.list();
if (descriptors.length === 0) {
throw "No device found";
}
return create;
}()
}]);
return Transport;
}();
const transport = yield _this2.open(descriptors[0], timeout);
transport.setDebugMode(debug);
return transport;
})();
}
}
exports.default = Transport;
//# sourceMappingURL=Transport.js.map
{
"name": "@ledgerhq/hw-transport",
"version": "1.1.1-beta.068e2a14",
"version": "1.1.2-beta.068e2a14",
"description": "Ledger Hardware Wallet common interface of the communication layer",

@@ -5,0 +5,0 @@ "keywords": [

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