@ledgerhq/hw-transport-http
Advanced tools
Comparing version 1.1.1-beta.068e2a14 to 1.1.2-beta.068e2a14
@@ -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 _hwTransport = require("@ledgerhq/hw-transport"); | ||
@@ -18,8 +16,2 @@ | ||
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; } | ||
/** | ||
@@ -29,48 +21,14 @@ * 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); | ||
_createClass(HttpTransport, null, [{ | ||
key: "open", | ||
// this transport is not discoverable | ||
value: function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(url, timeout) { | ||
var response; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return fetch(url, { timeout: timeout }); | ||
case 2: | ||
response = _context.sent; | ||
if (!(response.status !== 200)) { | ||
_context.next = 5; | ||
break; | ||
} | ||
throw new Error("failed to access HttpTransport(" + url + "): status " + response.status); | ||
case 5: | ||
return _context.abrupt("return", new HttpTransport(url)); | ||
case 6: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function open(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
class HttpTransport extends _hwTransport2.default { | ||
// this transport is not discoverable | ||
static open(url, timeout) { | ||
return _asyncToGenerator(function* () { | ||
const response = yield fetch(url, { timeout }); | ||
if (response.status !== 200) { | ||
throw new Error("failed to access HttpTransport(" + url + "): status " + response.status); | ||
} | ||
return new HttpTransport(url); | ||
})(); | ||
} | ||
return open; | ||
}() | ||
}]); | ||
/** | ||
@@ -85,95 +43,41 @@ * The full url of an http server. | ||
*/ | ||
function HttpTransport(url) { | ||
_classCallCheck(this, HttpTransport); | ||
var _this = _possibleConstructorReturn(this, (HttpTransport.__proto__ || Object.getPrototypeOf(HttpTransport)).call(this)); | ||
_this.url = url; | ||
return _this; | ||
constructor(url) { | ||
super(); | ||
this.url = url; | ||
} | ||
_createClass(HttpTransport, [{ | ||
key: "exchange", | ||
value: function () { | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(apduHex, statusList) { | ||
var response, body; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return fetch(this.url, { | ||
method: "POST", | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify({ apduHex: apduHex, statusList: statusList }) | ||
}); | ||
exchange(apduHex, statusList) { | ||
var _this = this; | ||
case 2: | ||
response = _context2.sent; | ||
if (!(response.status !== 200)) { | ||
_context2.next = 5; | ||
break; | ||
} | ||
throw "failed to communicate to server. code=" + response.status; | ||
case 5: | ||
_context2.next = 7; | ||
return response.json(); | ||
case 7: | ||
body = _context2.sent; | ||
if (!body.error) { | ||
_context2.next = 10; | ||
break; | ||
} | ||
throw body.error; | ||
case 10: | ||
return _context2.abrupt("return", body.data); | ||
case 11: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
})); | ||
function exchange(_x3, _x4) { | ||
return _ref2.apply(this, arguments); | ||
return _asyncToGenerator(function* () { | ||
const response = yield fetch(_this.url, { | ||
method: "POST", | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify({ apduHex, statusList }) | ||
}); | ||
if (response.status !== 200) { | ||
throw "failed to communicate to server. code=" + response.status; | ||
} | ||
const body = yield response.json(); | ||
if (body.error) throw body.error; | ||
return body.data; | ||
})(); | ||
} | ||
return exchange; | ||
}() | ||
}, { | ||
key: "setScrambleKey", | ||
value: function setScrambleKey() {} | ||
}, { | ||
key: "close", | ||
value: function close() { | ||
return Promise.resolve(); | ||
} | ||
}]); | ||
setScrambleKey() {} | ||
return HttpTransport; | ||
}(_hwTransport2.default); | ||
close() { | ||
return Promise.resolve(); | ||
} | ||
} | ||
exports.default = HttpTransport; | ||
HttpTransport.list = function () { | ||
return Promise.resolve([]); | ||
}; | ||
HttpTransport.list = () => Promise.resolve([]); | ||
HttpTransport.discover = function (_observer) { | ||
return { | ||
unsubscribe: function unsubscribe() {} | ||
}; | ||
}; | ||
exports.default = HttpTransport; | ||
HttpTransport.discover = _observer => ({ | ||
unsubscribe: () => {} | ||
}); | ||
//# sourceMappingURL=HttpTransport.js.map |
{ | ||
"name": "@ledgerhq/hw-transport-http", | ||
"version": "1.1.1-beta.068e2a14", | ||
"version": "1.1.2-beta.068e2a14", | ||
"description": "Ledger Hardware Wallet communication layer over http", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@ledgerhq/hw-transport": "^1.1.1-beta.068e2a14" | ||
"@ledgerhq/hw-transport": "^1.1.2-beta.068e2a14" | ||
}, | ||
@@ -31,0 +31,0 @@ "devDependencies": { |
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
4
19148
345
+ Added@ledgerhq/hw-transport@1.1.2-beta.068e2a14(transitive)
- Removed@ledgerhq/hw-transport@1.1.1-beta.068e2a14(transitive)