@ledgerhq/hw-transport-http
Advanced tools
Comparing version 1.1.0-beta.8cc6fdd9 to 1.1.0-beta.9f0d7158
@@ -26,5 +26,49 @@ "use strict"; | ||
*/ | ||
// 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); | ||
} | ||
return open; | ||
}() | ||
}]); | ||
/** | ||
@@ -47,15 +91,13 @@ * The full url of an http server. | ||
} | ||
// this transport is not discoverable | ||
_createClass(HttpTransport, [{ | ||
key: "exchange", | ||
value: function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(apduHex, statusList) { | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(apduHex, statusList) { | ||
var response, body; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context.next = 2; | ||
_context2.next = 2; | ||
return fetch(this.url, { | ||
@@ -71,6 +113,6 @@ method: "POST", | ||
case 2: | ||
response = _context.sent; | ||
response = _context2.sent; | ||
if (!(response.status !== 200)) { | ||
_context.next = 5; | ||
_context2.next = 5; | ||
break; | ||
@@ -82,10 +124,10 @@ } | ||
case 5: | ||
_context.next = 7; | ||
_context2.next = 7; | ||
return response.json(); | ||
case 7: | ||
body = _context.sent; | ||
body = _context2.sent; | ||
if (!body.error) { | ||
_context.next = 10; | ||
_context2.next = 10; | ||
break; | ||
@@ -97,14 +139,14 @@ } | ||
case 10: | ||
return _context.abrupt("return", body.data); | ||
return _context2.abrupt("return", body.data); | ||
case 11: | ||
case "end": | ||
return _context.stop(); | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
}, _callee2, this); | ||
})); | ||
function exchange(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
function exchange(_x3, _x4) { | ||
return _ref2.apply(this, arguments); | ||
} | ||
@@ -131,3 +173,3 @@ | ||
HttpTransport.discover = function () { | ||
HttpTransport.discover = function (_cb) { | ||
return { unsubscribe: function unsubscribe() {} }; | ||
@@ -134,0 +176,0 @@ }; |
{ | ||
"name": "@ledgerhq/hw-transport-http", | ||
"version": "1.1.0-beta.8cc6fdd9", | ||
"version": "1.1.0-beta.9f0d7158", | ||
"description": "Ledger Hardware Wallet communication layer over http", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@ledgerhq/hw-transport": "^1.1.0-beta.8cc6fdd9" | ||
"@ledgerhq/hw-transport": "^1.1.0-beta.9f0d7158" | ||
}, | ||
@@ -31,0 +31,0 @@ "devDependencies": { |
@@ -7,7 +7,18 @@ //@flow | ||
*/ | ||
// 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> { | ||
// this transport is not discoverable | ||
static list = (): * => Promise.resolve([]); | ||
static discover = () => ({ unsubscribe: () => {} }); | ||
static discover = (_cb: *) => ({ unsubscribe: () => {} }); | ||
static async open(url: string, timeout?: number) { | ||
const response = await fetch(url, { timeout }); | ||
if (response.status !== 200) { | ||
throw new Error( | ||
"failed to access HttpTransport(" + url + "): status " + response.status | ||
); | ||
} | ||
return new HttpTransport(url); | ||
} | ||
url: string; | ||
@@ -14,0 +25,0 @@ |
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
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
21674
390
4