New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ledgerhq/hw-transport-u2f

Package Overview
Dependencies
Maintainers
5
Versions
184
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ledgerhq/hw-transport-u2f - npm Package Compare versions

Comparing version 1.1.1-beta.068e2a14 to 1.1.2-beta.068e2a14

155

lib/TransportU2F.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 _u2fApi = require("u2f-api");

@@ -18,27 +16,21 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /********************************************************************************
* Ledger Node JS API
* (c) 2016-2017 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
/********************************************************************************
* Ledger Node JS API
* (c) 2016-2017 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
function wrapApdu(apdu, key) {
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];

@@ -50,22 +42,15 @@ }

// Convert from normal to web-safe, strip trailing "="s
var webSafe64 = function webSafe64(base64) {
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
};
const webSafe64 = base64 => base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
// Convert from web-safe to normal, add trailing "="s
var normal64 = function normal64(base64) {
return base64.replace(/-/g, "+").replace(/_/g, "/") + "==".substring(0, 3 * base64.length % 4);
};
const normal64 = base64 => base64.replace(/-/g, "+").replace(/_/g, "/") + "==".substring(0, 3 * base64.length % 4);
function u2fPromise(response, statusList) {
var signatureData = response.signatureData;
return new Promise(function (resolve, reject) {
const { signatureData } = response;
return new Promise((resolve, reject) => {
if (typeof signatureData === "string") {
var data = Buffer.from(normal64(signatureData), "base64");
const data = Buffer.from(normal64(signatureData), "base64");
if (typeof statusList !== "undefined") {
var sw = data.readUInt16BE(data.length - 2);
var statusFound = statusList.some(function (s) {
return s === sw;
});
const sw = data.readUInt16BE(data.length - 2);
const statusFound = statusList.some(s => s === sw);
if (!statusFound) {

@@ -89,17 +74,8 @@ reject("Invalid status " + sw.toString(16));

*/
var TransportU2F = function (_Transport) {
_inherits(TransportU2F, _Transport);
class TransportU2F extends _hwTransport2.default {
// this transport is not discoverable but we are going to guess if it is here with isSupported()
function TransportU2F() {
var timeoutSeconds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 20;
_classCallCheck(this, TransportU2F);
var _this = _possibleConstructorReturn(this, (TransportU2F.__proto__ || Object.getPrototypeOf(TransportU2F)).call(this));
_this.timeoutSeconds = timeoutSeconds;
return _this;
constructor(timeoutSeconds = 20) {
super();
this.timeoutSeconds = timeoutSeconds;
}

@@ -110,53 +86,38 @@

*/
static open(_, timeout) {
return Promise.resolve(new TransportU2F(timeout));
}
exchange(apduHex, statusList) {
const apdu = Buffer.from(apduHex, "hex");
const keyHandle = wrapApdu(apdu, this.scrambleKey);
const challenge = Buffer.from("0000000000000000000000000000000000000000000000000000000000000000", "hex");
const signRequest = {
version: "U2F_V2",
keyHandle: webSafe64(keyHandle.toString("base64")),
challenge: webSafe64(challenge.toString("base64")),
appId: location.origin
};
return (0, _u2fApi.sign)(signRequest, this.timeoutSeconds).then(result => u2fPromise(result, statusList));
}
_createClass(TransportU2F, [{
key: "exchange",
value: function exchange(apduHex, statusList) {
var apdu = Buffer.from(apduHex, "hex");
var keyHandle = wrapApdu(apdu, this.scrambleKey);
var challenge = Buffer.from("0000000000000000000000000000000000000000000000000000000000000000", "hex");
var signRequest = {
version: "U2F_V2",
keyHandle: webSafe64(keyHandle.toString("base64")),
challenge: webSafe64(challenge.toString("base64")),
appId: location.origin
};
return (0, _u2fApi.sign)(signRequest, this.timeoutSeconds).then(function (result) {
return u2fPromise(result, statusList);
});
}
}, {
key: "setScrambleKey",
value: function setScrambleKey(scrambleKey) {
this.scrambleKey = Buffer.from(scrambleKey, "ascii");
}
}, {
key: "close",
value: function close() {
return Promise.resolve();
}
}], [{
key: "open",
value: function open(_, timeout) {
return Promise.resolve(new TransportU2F(timeout));
}
}]);
setScrambleKey(scrambleKey) {
this.scrambleKey = Buffer.from(scrambleKey, "ascii");
}
return TransportU2F;
}(_hwTransport2.default);
close() {
return Promise.resolve();
}
}
exports.default = TransportU2F;
TransportU2F.list = function () {
return (0, _u2fApi.isSupported)().then(function (supported) {
return supported ? [null] : [];
});
};
TransportU2F.list = () => (0, _u2fApi.isSupported)().then(supported => supported ? [null] : []);
TransportU2F.discover = function (observer) {
var unsubscribed = false;
(0, _u2fApi.isSupported)().then(function (supported) {
TransportU2F.discover = observer => {
let unsubscribed = false;
(0, _u2fApi.isSupported)().then(supported => {
if (!unsubscribed && supported) observer.next(null);
});
return {
unsubscribe: function unsubscribe() {
unsubscribe: () => {
unsubscribed = true;

@@ -166,4 +127,2 @@ }

};
exports.default = TransportU2F;
//# sourceMappingURL=TransportU2F.js.map
{
"name": "@ledgerhq/hw-transport-u2f",
"version": "1.1.1-beta.068e2a14",
"version": "1.1.2-beta.068e2a14",
"description": "Ledger Hardware Wallet Web implementation of the communication layer, using U2F api",

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

"dependencies": {
"@ledgerhq/hw-transport": "^1.1.1-beta.068e2a14",
"@ledgerhq/hw-transport": "^1.1.2-beta.068e2a14",
"u2f-api": "^0.2.7"

@@ -32,0 +32,0 @@ },

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