@ledgerhq/hw-transport-http
Advanced tools
Comparing version 4.24.0 to 4.26.0-beta.9614a692
@@ -6,60 +6,30 @@ "use strict"; | ||
}); | ||
exports.withStaticURL = undefined; | ||
var _promise = require("babel-runtime/core-js/promise"); | ||
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 _promise2 = _interopRequireDefault(_promise); | ||
var _hwTransport = require("@ledgerhq/hw-transport"); | ||
var _stringify = require("babel-runtime/core-js/json/stringify"); | ||
var _hwTransport2 = _interopRequireDefault(_hwTransport); | ||
var _stringify2 = _interopRequireDefault(_stringify); | ||
var _axios = require("axios"); | ||
var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of"); | ||
var _axios2 = _interopRequireDefault(_axios); | ||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _regenerator = require("babel-runtime/regenerator"); | ||
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"); }); }; } | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator"); | ||
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; } | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
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; } | ||
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck"); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn"); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _createClass2 = require("babel-runtime/helpers/createClass"); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _inherits2 = require("babel-runtime/helpers/inherits"); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _hwTransport = require("@ledgerhq/hw-transport"); | ||
var _hwTransport2 = _interopRequireDefault(_hwTransport); | ||
var _withStaticURL = require("./withStaticURL"); | ||
var _withStaticURL2 = _interopRequireDefault(_withStaticURL); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.withStaticURL = _withStaticURL2.default; | ||
/** | ||
* HTTP transport implementation | ||
*/ | ||
// NOTE in the future we might want to do WebSocket, because we could have the disconnect lifecycle hooked. | ||
var HttpTransport = function (_Transport) { | ||
_inherits(HttpTransport, _Transport); | ||
var HttpTransport = function (_Transport) { | ||
(0, _inherits3.default)(HttpTransport, _Transport); | ||
(0, _createClass3.default)(HttpTransport, null, [{ | ||
_createClass(HttpTransport, null, [{ | ||
key: "open", | ||
@@ -70,5 +40,5 @@ | ||
value: function () { | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(url, timeout) { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(url, timeout) { | ||
var response; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
@@ -78,3 +48,3 @@ switch (_context.prev = _context.next) { | ||
_context.next = 2; | ||
return fetch(url, { timeout: timeout }); | ||
return (0, _axios2.default)(url, { timeout: timeout }); | ||
@@ -110,15 +80,6 @@ case 2: | ||
/** | ||
* The full url of an http server. | ||
* * a GET is expected to return a 200 status on this url. | ||
* * a POST is expected to accept { apduHex, statusList } object in body and | ||
returns { data, error } where either data is filled with an hex result | ||
or error is filled with a text error. | ||
* @example | ||
* new HttpTransport("http://192.168.0.1/") | ||
*/ | ||
function HttpTransport(url) { | ||
(0, _classCallCheck3.default)(this, HttpTransport); | ||
_classCallCheck(this, HttpTransport); | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (HttpTransport.__proto__ || (0, _getPrototypeOf2.default)(HttpTransport)).call(this)); | ||
var _this = _possibleConstructorReturn(this, (HttpTransport.__proto__ || Object.getPrototypeOf(HttpTransport)).call(this)); | ||
@@ -129,8 +90,8 @@ _this.url = url; | ||
(0, _createClass3.default)(HttpTransport, [{ | ||
_createClass(HttpTransport, [{ | ||
key: "exchange", | ||
value: function () { | ||
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(apdu) { | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(apdu) { | ||
var response, body; | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
@@ -140,4 +101,5 @@ switch (_context2.prev = _context2.next) { | ||
_context2.next = 2; | ||
return fetch(this.url, { | ||
return (0, _axios2.default)({ | ||
method: "POST", | ||
url: this.url, | ||
headers: { | ||
@@ -147,3 +109,3 @@ Accept: "application/json", | ||
}, | ||
body: (0, _stringify2.default)({ apduHex: apdu.toString("hex") }) | ||
data: JSON.stringify({ apduHex: apdu.toString("hex") }) | ||
}); | ||
@@ -163,3 +125,3 @@ | ||
_context2.next = 7; | ||
return response.json(); | ||
return response.data; | ||
@@ -199,5 +161,6 @@ case 7: | ||
value: function close() { | ||
return _promise2.default.resolve(); | ||
return Promise.resolve(); | ||
} | ||
}]); | ||
return HttpTransport; | ||
@@ -207,7 +170,7 @@ }(_hwTransport2.default); | ||
HttpTransport.isSupported = function () { | ||
return _promise2.default.resolve(typeof fetch === "function"); | ||
return Promise.resolve(typeof fetch === "function"); | ||
}; | ||
HttpTransport.list = function () { | ||
return _promise2.default.resolve([]); | ||
return Promise.resolve([]); | ||
}; | ||
@@ -214,0 +177,0 @@ |
{ | ||
"name": "@ledgerhq/hw-transport-http", | ||
"version": "4.24.0", | ||
"version": "4.26.0-beta.9614a692", | ||
"description": "Ledger Hardware Wallet communication layer over http", | ||
@@ -25,6 +25,8 @@ "keywords": [ | ||
}, | ||
"main": "lib/HttpTransport.js", | ||
"main": "lib/withStaticURLs.js", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@ledgerhq/hw-transport": "^4.24.0" | ||
"@ledgerhq/hw-transport": "^4.26.0-beta.9614a692", | ||
"axios": "^0.18.0", | ||
"ws": "^6.1.0" | ||
}, | ||
@@ -31,0 +33,0 @@ "devDependencies": { |
//@flow | ||
import Transport, { TransportError } from "@ledgerhq/hw-transport"; | ||
import withStaticURL from "./withStaticURL"; | ||
export { withStaticURL }; | ||
import axios from "axios"; | ||
@@ -9,3 +8,2 @@ /** | ||
*/ | ||
// NOTE in the future we might want to do WebSocket, because we could have the disconnect lifecycle hooked. | ||
export default class HttpTransport extends Transport<string> { | ||
@@ -22,3 +20,3 @@ static isSupported = (): Promise<boolean> => | ||
static async open(url: string, timeout?: number) { | ||
const response = await fetch(url, { timeout }); | ||
const response = await axios(url, { timeout }); | ||
if (response.status !== 200) { | ||
@@ -38,11 +36,2 @@ throw new TransportError( | ||
/** | ||
* The full url of an http server. | ||
* * a GET is expected to return a 200 status on this url. | ||
* * a POST is expected to accept { apduHex, statusList } object in body and | ||
returns { data, error } where either data is filled with an hex result | ||
or error is filled with a text error. | ||
* @example | ||
* new HttpTransport("http://192.168.0.1/") | ||
*/ | ||
constructor(url: string) { | ||
@@ -54,4 +43,5 @@ super(); | ||
async exchange(apdu: Buffer): Promise<Buffer> { | ||
const response = await fetch(this.url, { | ||
const response = await axios({ | ||
method: "POST", | ||
url: this.url, | ||
headers: { | ||
@@ -61,3 +51,3 @@ Accept: "application/json", | ||
}, | ||
body: JSON.stringify({ apduHex: apdu.toString("hex") }) | ||
data: JSON.stringify({ apduHex: apdu.toString("hex") }) | ||
}); | ||
@@ -70,3 +60,3 @@ if (response.status !== 200) { | ||
} | ||
const body = await response.json(); | ||
const body = await response.data; | ||
if (body.error) throw body.error; | ||
@@ -73,0 +63,0 @@ return Buffer.from(body.data, "hex"); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
43700
16
595
2
3
1
+ Addedaxios@^0.18.0
+ Addedws@^6.1.0
+ Addedasync-limiter@1.0.1(transitive)
+ Addedaxios@0.18.1(transitive)
+ Addedfollow-redirects@1.5.10(transitive)
+ Addedis-buffer@2.0.5(transitive)
+ Addedws@6.2.3(transitive)