@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.
- package/CHANGELOG.md +8 -0
- package/lib/HttpTransport.js +63 -137
- package/lib/HttpTransport.js.map +1 -1
- package/lib/WebSocketTransport.js +108 -178
- package/lib/WebSocketTransport.js.map +1 -1
- package/lib/withStaticURLs.d.ts +3 -3
- package/lib/withStaticURLs.d.ts.map +1 -1
- package/lib/withStaticURLs.js +59 -135
- package/lib/withStaticURLs.js.map +1 -1
- package/lib-es/HttpTransport.js +57 -132
- package/lib-es/HttpTransport.js.map +1 -1
- package/lib-es/WebSocketTransport.js +103 -174
- package/lib-es/WebSocketTransport.js.map +1 -1
- package/lib-es/withStaticURLs.d.ts +3 -3
- package/lib-es/withStaticURLs.d.ts.map +1 -1
- package/lib-es/withStaticURLs.js +55 -131
- package/lib-es/withStaticURLs.js.map +1 -1
- package/package.json +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @ledgerhq/hw-transport-http
|
|
2
2
|
|
|
3
|
+
## 6.27.14-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`87d2349fd8`](https://github.com/LedgerHQ/ledger-live/commit/87d2349fd835e5deb39d1ee8dfcf3539f4195472)]:
|
|
8
|
+
- @ledgerhq/errors@6.12.5-next.0
|
|
9
|
+
- @ledgerhq/hw-transport@6.28.3-next.0
|
|
10
|
+
|
|
3
11
|
## 6.27.13
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/lib/HttpTransport.js
CHANGED
|
@@ -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,136 +8,77 @@ 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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
const hw_transport_1 = __importDefault(require("@ledgerhq/hw-transport"));
|
|
17
|
+
const errors_1 = require("@ledgerhq/errors");
|
|
18
|
+
const axios_1 = __importDefault(require("axios"));
|
|
19
|
+
const logs_1 = require("@ledgerhq/logs");
|
|
61
20
|
/**
|
|
62
21
|
* HTTP transport implementation
|
|
63
22
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return _this;
|
|
70
|
-
}
|
|
71
|
-
HttpTransport.open = function (url, timeout) {
|
|
72
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
-
return __generator(this, function (_b) {
|
|
74
|
-
switch (_b.label) {
|
|
75
|
-
case 0: return [4 /*yield*/, HttpTransport.check(url, timeout)];
|
|
76
|
-
case 1:
|
|
77
|
-
_b.sent();
|
|
78
|
-
return [2 /*return*/, new HttpTransport(url)];
|
|
79
|
-
}
|
|
80
|
-
});
|
|
23
|
+
class HttpTransport extends hw_transport_1.default {
|
|
24
|
+
static open(url, timeout) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
yield HttpTransport.check(url, timeout);
|
|
27
|
+
return new HttpTransport(url);
|
|
81
28
|
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
})];
|
|
102
|
-
case 1:
|
|
103
|
-
response = _b.sent();
|
|
104
|
-
if (response.status !== 200) {
|
|
105
|
-
throw new errors_1.TransportError("failed to communicate to server. code=" + response.status, "HttpTransportStatus" + response.status);
|
|
106
|
-
}
|
|
107
|
-
return [4 /*yield*/, response.data];
|
|
108
|
-
case 2:
|
|
109
|
-
body = _b.sent();
|
|
110
|
-
if (body.error)
|
|
111
|
-
throw body.error;
|
|
112
|
-
(0, logs_1.log)("apdu", "<= " + body.data);
|
|
113
|
-
return [2 /*return*/, Buffer.from(body.data, "hex")];
|
|
114
|
-
}
|
|
29
|
+
}
|
|
30
|
+
constructor(url) {
|
|
31
|
+
super();
|
|
32
|
+
this.url = url;
|
|
33
|
+
}
|
|
34
|
+
exchange(apdu) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const apduHex = apdu.toString("hex");
|
|
37
|
+
(0, logs_1.log)("apdu", "=> " + apduHex);
|
|
38
|
+
const response = yield (0, axios_1.default)({
|
|
39
|
+
method: "POST",
|
|
40
|
+
url: this.url,
|
|
41
|
+
headers: {
|
|
42
|
+
Accept: "application/json",
|
|
43
|
+
"Content-Type": "application/json",
|
|
44
|
+
},
|
|
45
|
+
data: JSON.stringify({
|
|
46
|
+
apduHex,
|
|
47
|
+
}),
|
|
115
48
|
});
|
|
49
|
+
if (response.status !== 200) {
|
|
50
|
+
throw new errors_1.TransportError("failed to communicate to server. code=" + response.status, "HttpTransportStatus" + response.status);
|
|
51
|
+
}
|
|
52
|
+
const body = yield response.data;
|
|
53
|
+
if (body.error)
|
|
54
|
+
throw body.error;
|
|
55
|
+
(0, logs_1.log)("apdu", "<= " + body.data);
|
|
56
|
+
return Buffer.from(body.data, "hex");
|
|
116
57
|
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
58
|
+
}
|
|
59
|
+
setScrambleKey() { }
|
|
60
|
+
close() {
|
|
120
61
|
return Promise.resolve();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
response = _b.sent();
|
|
144
|
-
if (response.status !== 200) {
|
|
145
|
-
throw new errors_1.TransportError("failed to access HttpTransport(" +
|
|
146
|
-
url +
|
|
147
|
-
"): status " +
|
|
148
|
-
response.status, "HttpTransportNotAccessible");
|
|
149
|
-
}
|
|
150
|
-
return [2 /*return*/];
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
return HttpTransport;
|
|
156
|
-
}(hw_transport_1["default"]));
|
|
157
|
-
exports["default"] = HttpTransport;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.default = HttpTransport;
|
|
65
|
+
_a = HttpTransport;
|
|
66
|
+
HttpTransport.isSupported = () => Promise.resolve(typeof fetch === "function");
|
|
67
|
+
// this transport is not discoverable
|
|
68
|
+
HttpTransport.list = () => Promise.resolve([]);
|
|
69
|
+
HttpTransport.listen = (_observer) => ({
|
|
70
|
+
unsubscribe: () => { },
|
|
71
|
+
});
|
|
72
|
+
HttpTransport.check = (url, timeout = 5000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
const response = yield (0, axios_1.default)({
|
|
74
|
+
url,
|
|
75
|
+
timeout,
|
|
76
|
+
});
|
|
77
|
+
if (response.status !== 200) {
|
|
78
|
+
throw new errors_1.TransportError("failed to access HttpTransport(" +
|
|
79
|
+
url +
|
|
80
|
+
"): status " +
|
|
81
|
+
response.status, "HttpTransportNotAccessible");
|
|
82
|
+
}
|
|
83
|
+
});
|
|
158
84
|
//# sourceMappingURL=HttpTransport.js.map
|
package/lib/HttpTransport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpTransport.js","sourceRoot":"","sources":["../src/HttpTransport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HttpTransport.js","sourceRoot":"","sources":["../src/HttpTransport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0EAA+C;AAC/C,6CAAkD;AAClD,kDAA0B;AAC1B,yCAAqC;AACrC;;GAEG;AAEH,MAAqB,aAAc,SAAQ,sBAAS;IAyBlD,MAAM,CAAO,IAAI,CAAC,GAAW,EAAE,OAAgB;;YAC7C,MAAM,aAAa,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YACxC,OAAO,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;KAAA;IAID,YAAY,GAAW;QACrB,KAAK,EAAE,CAAC;QACR,IAAI,CA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CAAC,EAAE,CAAC,CAAC;AACtC,oBAAM,GAAG,CAAC,SAAc,EAAE,EAAE,CAAC,CAAC;IACnC,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC;CACtB,CAAC,CAAC;AACI,mBAAK,GAAG,CAAO,GAAW,EAAE,OAAO,GAAG,IAAI,EAAE,EAAE;IACnD,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAK,EAAC;QAC3B,GAAG;QACH,OAAO;KACR,CAAC,CAAC;IAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;QAC3B,MAAM,IAAI,uBAAc,CACtB,iCAAiC;YAC/B,GAAG;YACH,YAAY;YACZ,QAAQ,CAAC,MAAM,EACjB,4BAA4B,CAC7B,CAAC;KACH;AACH,CAAC,CAAA,CAAC"}
|
|
@@ -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,181 +8,126 @@ 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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
const hw_transport_1 = __importDefault(require("@ledgerhq/hw-transport"));
|
|
17
|
+
const errors_1 = require("@ledgerhq/errors");
|
|
18
|
+
const logs_1 = require("@ledgerhq/logs");
|
|
19
|
+
const WebSocket = global.WebSocket || require("ws");
|
|
61
20
|
/**
|
|
62
21
|
* WebSocket transport implementation
|
|
63
22
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (typeof e.data !== "string")
|
|
103
|
-
return;
|
|
104
|
-
var data = JSON.parse(e.data);
|
|
105
|
-
switch (data.type) {
|
|
106
|
-
case "opened":
|
|
107
|
-
return resolve(exchangeMethods_1);
|
|
108
|
-
case "error":
|
|
109
|
-
reject(new Error(data.error));
|
|
110
|
-
return exchangeMethods_1.rejectExchange(new errors_1.TransportError(data.error, "WSError"));
|
|
111
|
-
case "response":
|
|
112
|
-
return exchangeMethods_1.resolveExchange(Buffer.from(data.data, "hex"));
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
catch (e) {
|
|
117
|
-
reject(e);
|
|
118
|
-
}
|
|
119
|
-
})];
|
|
120
|
-
case 1:
|
|
121
|
-
exchangeMethods = _c.sent();
|
|
122
|
-
return [2 /*return*/, new WebSocketTransport(exchangeMethods)];
|
|
23
|
+
class WebSocketTransport extends hw_transport_1.default {
|
|
24
|
+
static open(url) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const exchangeMethods = yield new Promise((resolve, reject) => {
|
|
27
|
+
try {
|
|
28
|
+
const socket = new WebSocket(url);
|
|
29
|
+
const exchangeMethods = {
|
|
30
|
+
resolveExchange: (_b) => { },
|
|
31
|
+
rejectExchange: (_e) => { },
|
|
32
|
+
onDisconnect: () => { },
|
|
33
|
+
close: () => socket.close(),
|
|
34
|
+
send: (msg) => socket.send(msg),
|
|
35
|
+
};
|
|
36
|
+
socket.onopen = () => {
|
|
37
|
+
socket.send("open");
|
|
38
|
+
};
|
|
39
|
+
socket.onerror = (e) => {
|
|
40
|
+
exchangeMethods.onDisconnect();
|
|
41
|
+
reject(e);
|
|
42
|
+
};
|
|
43
|
+
socket.onclose = () => {
|
|
44
|
+
exchangeMethods.onDisconnect();
|
|
45
|
+
reject(new errors_1.TransportError("OpenFailed", "OpenFailed"));
|
|
46
|
+
};
|
|
47
|
+
socket.onmessage = (e) => {
|
|
48
|
+
if (typeof e.data !== "string")
|
|
49
|
+
return;
|
|
50
|
+
const data = JSON.parse(e.data);
|
|
51
|
+
switch (data.type) {
|
|
52
|
+
case "opened":
|
|
53
|
+
return resolve(exchangeMethods);
|
|
54
|
+
case "error":
|
|
55
|
+
reject(new Error(data.error));
|
|
56
|
+
return exchangeMethods.rejectExchange(new errors_1.TransportError(data.error, "WSError"));
|
|
57
|
+
case "response":
|
|
58
|
+
return exchangeMethods.resolveExchange(Buffer.from(data.data, "hex"));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
123
61
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
};
|
|
127
|
-
WebSocketTransport.prototype.exchange = function (apdu) {
|
|
128
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
-
var hex, res;
|
|
130
|
-
var _this = this;
|
|
131
|
-
return __generator(this, function (_c) {
|
|
132
|
-
switch (_c.label) {
|
|
133
|
-
case 0:
|
|
134
|
-
hex = apdu.toString("hex");
|
|
135
|
-
(0, logs_1.log)("apdu", "=> " + hex);
|
|
136
|
-
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
137
|
-
_this.hook.rejectExchange = function (e) { return reject(e); };
|
|
138
|
-
_this.hook.resolveExchange = function (b) { return resolve(b); };
|
|
139
|
-
_this.hook.send(hex);
|
|
140
|
-
})];
|
|
141
|
-
case 1:
|
|
142
|
-
res = _c.sent();
|
|
143
|
-
(0, logs_1.log)("apdu", "<= " + res.toString("hex"));
|
|
144
|
-
return [2 /*return*/, res];
|
|
62
|
+
catch (e) {
|
|
63
|
+
reject(e);
|
|
145
64
|
}
|
|
146
65
|
});
|
|
66
|
+
return new WebSocketTransport(exchangeMethods);
|
|
147
67
|
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
68
|
+
}
|
|
69
|
+
constructor(hook) {
|
|
70
|
+
super();
|
|
71
|
+
this.hook = hook;
|
|
72
|
+
hook.onDisconnect = () => {
|
|
73
|
+
this.emit("disconnect");
|
|
74
|
+
this.hook.rejectExchange(new errors_1.TransportError("WebSocket disconnected", "WSDisconnect"));
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
exchange(apdu) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const hex = apdu.toString("hex");
|
|
80
|
+
(0, logs_1.log)("apdu", "=> " + hex);
|
|
81
|
+
const res = yield new Promise((resolve, reject) => {
|
|
82
|
+
this.hook.rejectExchange = (e) => reject(e);
|
|
83
|
+
this.hook.resolveExchange = (b) => resolve(b);
|
|
84
|
+
this.hook.send(hex);
|
|
159
85
|
});
|
|
86
|
+
(0, logs_1.log)("apdu", "<= " + res.toString("hex"));
|
|
87
|
+
return res;
|
|
160
88
|
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
unsubscribe: function () { }
|
|
171
|
-
}); };
|
|
172
|
-
WebSocketTransport.check = function (url, timeout) {
|
|
173
|
-
if (timeout === void 0) { timeout = 5000; }
|
|
174
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
175
|
-
return __generator(_a, function (_c) {
|
|
176
|
-
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
177
|
-
var socket = new WebSocket(url);
|
|
178
|
-
var success = false;
|
|
179
|
-
setTimeout(function () {
|
|
180
|
-
socket.close();
|
|
181
|
-
}, timeout);
|
|
182
|
-
socket.onopen = function () {
|
|
183
|
-
success = true;
|
|
184
|
-
socket.close();
|
|
185
|
-
};
|
|
186
|
-
socket.onclose = function () {
|
|
187
|
-
if (success)
|
|
188
|
-
resolve(undefined);
|
|
189
|
-
else {
|
|
190
|
-
reject(new errors_1.TransportError("failed to access WebSocketTransport(" + url + ")", "WebSocketTransportNotAccessible"));
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
socket.onerror = function () {
|
|
194
|
-
reject(new errors_1.TransportError("failed to access WebSocketTransport(" + url + "): error", "WebSocketTransportNotAccessible"));
|
|
195
|
-
};
|
|
196
|
-
})];
|
|
89
|
+
}
|
|
90
|
+
setScrambleKey() { }
|
|
91
|
+
close() {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
this.hook.close();
|
|
94
|
+
return new Promise((success) => {
|
|
95
|
+
setTimeout(() => {
|
|
96
|
+
success(undefined);
|
|
97
|
+
}, 200);
|
|
197
98
|
});
|
|
198
99
|
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.default = WebSocketTransport;
|
|
103
|
+
_a = WebSocketTransport;
|
|
104
|
+
WebSocketTransport.isSupported = () => Promise.resolve(typeof WebSocket === "function");
|
|
105
|
+
// this transport is not discoverable
|
|
106
|
+
WebSocketTransport.list = () => Promise.resolve([]);
|
|
107
|
+
WebSocketTransport.listen = (_observer) => ({
|
|
108
|
+
unsubscribe: () => { },
|
|
109
|
+
});
|
|
110
|
+
WebSocketTransport.check = (url, timeout = 5000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
const socket = new WebSocket(url);
|
|
113
|
+
let success = false;
|
|
114
|
+
setTimeout(() => {
|
|
115
|
+
socket.close();
|
|
116
|
+
}, timeout);
|
|
117
|
+
socket.onopen = () => {
|
|
118
|
+
success = true;
|
|
119
|
+
socket.close();
|
|
120
|
+
};
|
|
121
|
+
socket.onclose = () => {
|
|
122
|
+
if (success)
|
|
123
|
+
resolve(undefined);
|
|
124
|
+
else {
|
|
125
|
+
reject(new errors_1.TransportError("failed to access WebSocketTransport(" + url + ")", "WebSocketTransportNotAccessible"));
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
socket.onerror = () => {
|
|
129
|
+
reject(new errors_1.TransportError("failed to access WebSocketTransport(" + url + "): error", "WebSocketTransportNotAccessible"));
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
});
|
|
203
133
|
//# sourceMappingURL=WebSocketTransport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketTransport.js","sourceRoot":"","sources":["../src/WebSocketTransport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebSocketTransport.js","sourceRoot":"","sources":["../src/WebSocketTransport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0EAA+C;AAC/C,6CAAkD;AAClD,yCAAqC;AAWrC,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;AACpD;;GAEG;AAEH,MAAqB,kBAAmB,SAAQ,sBAAS;IA2CvD,MAAM,CAAO,IAAI,CAAC,GAAW;;YAC3B,MAAM,eAAe,GAAG,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC5D,IAAI;oBACF,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;oBAClC,MAAM,eAAe,GAAG;wBACtB,eAAe,EAAE,CAAC,EAAU,EAAE,EAAE,GAAE,CAAC;wBACnC,cAAc,EAAE,CAAC,EAAO,EAAE,EAAE,GAAE,CAAC;wBAC/B,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;wBACtB,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE;wBAC3B,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;qBAChC,CAAC;oBAEF,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE;wBACnB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBACtB,CAAC,CAAC;oBAEF,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,EAAE,EAAE;wBACrB,eAAe,CAAC,YAAY,EAAE,CAAC;wBAC/B,MAAM,CAAC,CAAC,CAAC,CAAC;oBACZ,CAAC,CAAC;oBAEF,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE;wBACpB,eAAe,CAAC,YAAY,EAAE,CAAC;wBAC/B,MAAM,CAAC,IAAI,uB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AAC,CAAC;AACI,wBAAK,GAAG,CAAO,GAAW,EAAE,OAAO,GAAG,IAAI,EAAE,EAAE;IACnD,OAAA,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9B,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,UAAU,CAAC,GAAG,EAAE;YACd,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC,EAAE,OAAO,CAAC,CAAC;QAEZ,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE;YACnB,OAAO,GAAG,IAAI,CAAC;YACf,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC,CAAC;QAEF,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE;YACpB,IAAI,OAAO;gBAAE,OAAO,CAAC,SAAS,CAAC,CAAC;iBAC3B;gBACH,MAAM,CACJ,IAAI,uBAAc,CAChB,sCAAsC,GAAG,GAAG,GAAG,GAAG,EAClD,iCAAiC,CAClC,CACF,CAAC;aACH;QACH,CAAC,CAAC;QAEF,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE;YACpB,MAAM,CACJ,IAAI,uBAAc,CAChB,sCAAsC,GAAG,GAAG,GAAG,UAAU,EACzD,iCAAiC,CAClC,CACF,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,CAAC,CAAA;EAAA,CAAC"}
|
package/lib/withStaticURLs.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Transport from "@ledgerhq/hw-transport";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
type InS = string | string[];
|
|
3
|
+
type InP = Promise<InS> | InS;
|
|
4
|
+
type In = InP | (() => InP);
|
|
5
5
|
declare const _default: (urls: In) => typeof Transport;
|
|
6
6
|
export default _default;
|
|
7
7
|
//# sourceMappingURL=withStaticURLs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withStaticURLs.d.ts","sourceRoot":"","sources":["../src/withStaticURLs.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAU/C,
|
|
1
|
+
{"version":3,"file":"withStaticURLs.d.ts","sourceRoot":"","sources":["../src/withStaticURLs.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAU/C,KAAK,GAAG,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAC7B,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AAC9B,KAAK,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;+BAON,EAAE,KAAG,gBAAgB;AAA3C,wBAqEE"}
|