@ledgerhq/hw-transport-http 6.27.13 → 6.27.14-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -23,133 +8,72 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
24
9
  });
25
10
  };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (_) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
54
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
55
13
  };
56
- exports.__esModule = true;
57
- var HttpTransport_1 = __importDefault(require("./HttpTransport"));
58
- var WebSocketTransport_1 = __importDefault(require("./WebSocketTransport"));
59
- var hw_transport_1 = __importDefault(require("@ledgerhq/hw-transport"));
60
- var getTransport = function (url) {
61
- return !url.startsWith("ws") ? HttpTransport_1["default"] : WebSocketTransport_1["default"];
62
- };
63
- var inferURLs = function (urls) { return __awaiter(void 0, void 0, void 0, function () {
64
- var r;
65
- return __generator(this, function (_a) {
66
- switch (_a.label) {
67
- case 0: return [4 /*yield*/, (typeof urls === "function" ? urls() : urls)];
68
- case 1:
69
- r = _a.sent();
70
- return [2 /*return*/, typeof r === "string" ? [r] : r];
71
- }
72
- });
73
- }); };
74
- exports["default"] = (function (urls) {
75
- var StaticTransport = /** @class */ (function (_super) {
76
- __extends(StaticTransport, _super);
77
- function StaticTransport() {
78
- return _super !== null && _super.apply(this, arguments) || this;
79
- }
80
- StaticTransport.isSupported = HttpTransport_1["default"].isSupported;
81
- StaticTransport.list = function () {
82
- return inferURLs(urls)
83
- .then(function (urls) {
84
- return Promise.all(urls.map(function (url) {
85
- return getTransport(url)
86
- .check(url)
87
- .then(function () { return [url]; })["catch"](function () { return []; });
88
- }));
89
- })
90
- .then(function (arrs) { return arrs.reduce(function (acc, a) { return acc.concat(a); }, []); });
91
- };
92
- StaticTransport.listen = function (observer) {
93
- var unsubscribed = false;
94
- var seen = {};
95
- function checkLoop() {
96
- var _this = this;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const HttpTransport_1 = __importDefault(require("./HttpTransport"));
16
+ const WebSocketTransport_1 = __importDefault(require("./WebSocketTransport"));
17
+ const hw_transport_1 = __importDefault(require("@ledgerhq/hw-transport"));
18
+ const getTransport = (url) => !url.startsWith("ws") ? HttpTransport_1.default : WebSocketTransport_1.default;
19
+ const inferURLs = (urls) => __awaiter(void 0, void 0, void 0, function* () {
20
+ const r = yield (typeof urls === "function" ? urls() : urls);
21
+ return typeof r === "string" ? [r] : r;
22
+ });
23
+ exports.default = (urls) => {
24
+ class StaticTransport extends hw_transport_1.default {
25
+ }
26
+ StaticTransport.isSupported = HttpTransport_1.default.isSupported;
27
+ StaticTransport.list = () => inferURLs(urls)
28
+ .then((urls) => Promise.all(urls.map((url) => getTransport(url)
29
+ .check(url)
30
+ .then(() => [url])
31
+ .catch(() => []))))
32
+ .then((arrs) => arrs.reduce((acc, a) => acc.concat(a), []));
33
+ StaticTransport.listen = (observer) => {
34
+ let unsubscribed = false;
35
+ const seen = {};
36
+ function checkLoop() {
37
+ if (unsubscribed)
38
+ return;
39
+ inferURLs(urls)
40
+ .then((urls) => Promise.all(urls.map((url) => __awaiter(this, void 0, void 0, function* () {
97
41
  if (unsubscribed)
98
42
  return;
99
- inferURLs(urls)
100
- .then(function (urls) {
101
- return Promise.all(urls.map(function (url) { return __awaiter(_this, void 0, void 0, function () {
102
- var e_1;
103
- return __generator(this, function (_a) {
104
- switch (_a.label) {
105
- case 0:
106
- if (unsubscribed)
107
- return [2 /*return*/];
108
- _a.label = 1;
109
- case 1:
110
- _a.trys.push([1, 3, , 4]);
111
- return [4 /*yield*/, getTransport(url).check(url)];
112
- case 2:
113
- _a.sent();
114
- if (unsubscribed)
115
- return [2 /*return*/];
116
- if (!seen[url]) {
117
- seen[url] = 1;
118
- observer.next({
119
- type: "add",
120
- descriptor: url
121
- });
122
- }
123
- return [3 /*break*/, 4];
124
- case 3:
125
- e_1 = _a.sent();
126
- // nothing
127
- if (seen[url]) {
128
- delete seen[url];
129
- observer.next({
130
- type: "remove",
131
- descriptor: url
132
- });
133
- }
134
- return [3 /*break*/, 4];
135
- case 4: return [2 /*return*/];
136
- }
43
+ try {
44
+ yield getTransport(url).check(url);
45
+ if (unsubscribed)
46
+ return;
47
+ if (!seen[url]) {
48
+ seen[url] = 1;
49
+ observer.next({
50
+ type: "add",
51
+ descriptor: url,
52
+ });
53
+ }
54
+ }
55
+ catch (e) {
56
+ // nothing
57
+ if (seen[url]) {
58
+ delete seen[url];
59
+ observer.next({
60
+ type: "remove",
61
+ descriptor: url,
137
62
  });
138
- }); }));
139
- })
140
- .then(function () { return new Promise(function (success) { return setTimeout(success, 5000); }); })
141
- .then(checkLoop);
142
- }
143
- checkLoop();
144
- return {
145
- unsubscribe: function () {
146
- unsubscribed = true;
63
+ }
147
64
  }
148
- };
65
+ }))))
66
+ .then(() => new Promise((success) => setTimeout(success, 5000)))
67
+ .then(checkLoop);
68
+ }
69
+ checkLoop();
70
+ return {
71
+ unsubscribe: () => {
72
+ unsubscribed = true;
73
+ },
149
74
  };
150
- StaticTransport.open = function (url) { return getTransport(url).open(url); };
151
- return StaticTransport;
152
- }(hw_transport_1["default"]));
75
+ };
76
+ StaticTransport.open = (url) => getTransport(url).open(url);
153
77
  return StaticTransport;
154
- });
78
+ };
155
79
  //# sourceMappingURL=withStaticURLs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"withStaticURLs.js","sourceRoot":"","sources":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,UAAU,EAAE,GAAG;yBAChB,CAAC,CAAC;qBACJ;iBACF;YACH,CAAC,CAAA,CAAC,CACH,CACF;iBACA,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;iBAC/D,IAAI,CAAC,SAAS,CAAC,CAAC;QACrB,CAAC;QAED,SAAS,EAAE,CAAC;QACZ,OAAO;YACL,WAAW,EAAE,GAAG,EAAE;gBAChB,YAAY,GAAG,IAAI,CAAC;YACtB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IACK,oBAAI,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAGrD,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC"}
@@ -1,18 +1,3 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -22,33 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
8
  });
24
9
  };
25
- var __generator = (this && this.__generator) || function (thisArg, body) {
26
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
- function verb(n) { return function (v) { return step([n, v]); }; }
29
- function step(op) {
30
- if (f) throw new TypeError("Generator is already executing.");
31
- while (_) try {
32
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
- if (y = 0, t) op = [op[0] & 2, t.value];
34
- switch (op[0]) {
35
- case 0: case 1: t = op; break;
36
- case 4: _.label++; return { value: op[1], done: false };
37
- case 5: _.label++; y = op[1]; op = [0]; continue;
38
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
- default:
40
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
- if (t[2]) _.ops.pop();
45
- _.trys.pop(); continue;
46
- }
47
- op = body.call(thisArg, _);
48
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
- }
51
- };
10
+ var _a;
52
11
  import Transport from "@ledgerhq/hw-transport";
53
12
  import { TransportError } from "@ledgerhq/errors";
54
13
  import axios from "axios";
@@ -56,98 +15,64 @@ import { log } from "@ledgerhq/logs";
56
15
  /**
57
16
  * HTTP transport implementation
58
17
  */
59
- var HttpTransport = /** @class */ (function (_super) {
60
- __extends(HttpTransport, _super);
61
- function HttpTransport(url) {
62
- var _this = _super.call(this) || this;
63
- _this.url = url;
64
- return _this;
65
- }
66
- HttpTransport.open = function (url, timeout) {
67
- return __awaiter(this, void 0, void 0, function () {
68
- return __generator(this, function (_b) {
69
- switch (_b.label) {
70
- case 0: return [4 /*yield*/, HttpTransport.check(url, timeout)];
71
- case 1:
72
- _b.sent();
73
- return [2 /*return*/, new HttpTransport(url)];
74
- }
75
- });
18
+ export default class HttpTransport extends Transport {
19
+ static open(url, timeout) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ yield HttpTransport.check(url, timeout);
22
+ return new HttpTransport(url);
76
23
  });
77
- };
78
- HttpTransport.prototype.exchange = function (apdu) {
79
- return __awaiter(this, void 0, void 0, function () {
80
- var apduHex, response, body;
81
- return __generator(this, function (_b) {
82
- switch (_b.label) {
83
- case 0:
84
- apduHex = apdu.toString("hex");
85
- log("apdu", "=> " + apduHex);
86
- return [4 /*yield*/, axios({
87
- method: "POST",
88
- url: this.url,
89
- headers: {
90
- Accept: "application/json",
91
- "Content-Type": "application/json"
92
- },
93
- data: JSON.stringify({
94
- apduHex: apduHex
95
- })
96
- })];
97
- case 1:
98
- response = _b.sent();
99
- if (response.status !== 200) {
100
- throw new TransportError("failed to communicate to server. code=" + response.status, "HttpTransportStatus" + response.status);
101
- }
102
- return [4 /*yield*/, response.data];
103
- case 2:
104
- body = _b.sent();
105
- if (body.error)
106
- throw body.error;
107
- log("apdu", "<= " + body.data);
108
- return [2 /*return*/, Buffer.from(body.data, "hex")];
109
- }
24
+ }
25
+ constructor(url) {
26
+ super();
27
+ this.url = url;
28
+ }
29
+ exchange(apdu) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const apduHex = apdu.toString("hex");
32
+ log("apdu", "=> " + apduHex);
33
+ const response = yield axios({
34
+ method: "POST",
35
+ url: this.url,
36
+ headers: {
37
+ Accept: "application/json",
38
+ "Content-Type": "application/json",
39
+ },
40
+ data: JSON.stringify({
41
+ apduHex,
42
+ }),
110
43
  });
44
+ if (response.status !== 200) {
45
+ throw new TransportError("failed to communicate to server. code=" + response.status, "HttpTransportStatus" + response.status);
46
+ }
47
+ const body = yield response.data;
48
+ if (body.error)
49
+ throw body.error;
50
+ log("apdu", "<= " + body.data);
51
+ return Buffer.from(body.data, "hex");
111
52
  });
112
- };
113
- HttpTransport.prototype.setScrambleKey = function () { };
114
- HttpTransport.prototype.close = function () {
53
+ }
54
+ setScrambleKey() { }
55
+ close() {
115
56
  return Promise.resolve();
116
- };
117
- var _a;
118
- _a = HttpTransport;
119
- HttpTransport.isSupported = function () {
120
- return Promise.resolve(typeof fetch === "function");
121
- };
122
- // this transport is not discoverable
123
- HttpTransport.list = function () { return Promise.resolve([]); };
124
- HttpTransport.listen = function (_observer) { return ({
125
- unsubscribe: function () { }
126
- }); };
127
- HttpTransport.check = function (url, timeout) {
128
- if (timeout === void 0) { timeout = 5000; }
129
- return __awaiter(void 0, void 0, void 0, function () {
130
- var response;
131
- return __generator(_a, function (_b) {
132
- switch (_b.label) {
133
- case 0: return [4 /*yield*/, axios({
134
- url: url,
135
- timeout: timeout
136
- })];
137
- case 1:
138
- response = _b.sent();
139
- if (response.status !== 200) {
140
- throw new TransportError("failed to access HttpTransport(" +
141
- url +
142
- "): status " +
143
- response.status, "HttpTransportNotAccessible");
144
- }
145
- return [2 /*return*/];
146
- }
147
- });
148
- });
149
- };
150
- return HttpTransport;
151
- }(Transport));
152
- export default HttpTransport;
57
+ }
58
+ }
59
+ _a = HttpTransport;
60
+ HttpTransport.isSupported = () => Promise.resolve(typeof fetch === "function");
61
+ // this transport is not discoverable
62
+ HttpTransport.list = () => Promise.resolve([]);
63
+ HttpTransport.listen = (_observer) => ({
64
+ unsubscribe: () => { },
65
+ });
66
+ HttpTransport.check = (url, timeout = 5000) => __awaiter(void 0, void 0, void 0, function* () {
67
+ const response = yield axios({
68
+ url,
69
+ timeout,
70
+ });
71
+ if (response.status !== 200) {
72
+ throw new TransportError("failed to access HttpTransport(" +
73
+ url +
74
+ "): status " +
75
+ response.status, "HttpTransportNotAccessible");
76
+ }
77
+ });
153
78
  //# sourceMappingURL=HttpTransport.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HttpTransport.js","sourceRoot":"","sources":["../src/HttpTransport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC;;GAEG;AAEH;IAA2C,iCAAS;IAgClD,uBAAY,GAAW;QAAvB,YACE,iBAAO,SAER;QADC,KAAI,CAAC,GAAG,GAAG,GAAG,CAAC;;IACjB,CAAC;IAVY,kBAAI,GAAjB,UAAkB,GAAW,EAAE,OAAgB;;;;4BAC7C,qBAAM,aAAa,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,EAAA;;wBAAvC,SAAuC,CAAC;wBACxC,sBAAO,IAAI,aAAa,CAAC,GAAG,CAAC,EAAC;;;;KAC/B;IASK,gCAAQ,GAAd,UAAe,IAAY;;;;;;wBACnB,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;wBACrC,GAAG,CAAC,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,CAAC;wBACZ,qBAAM,KAAK,CAAC;gCAC3B,MAAM,EAAE,MAAM;gCACd,GAAG,EAAE,IAAI,CAAC,GAAG;gCACb,OAAO,EAAE;oCACP,MAAM,EAAE,kBAAkB;oCAC1B,cAAc,EAAE,kBAAkB;iCACnC;gCACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oCACnB,OAAO,SAAA;iCACR,CAAC;6BACH,CAAC,EAAA;;wBAVI,QAAQ,GAAG,SAUf;wBAEF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;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