@ledgerhq/hw-transport-node-speculos-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/SpeculosHttpTransport.d.ts +1 -1
- package/lib/SpeculosHttpTransport.d.ts.map +1 -1
- package/lib/SpeculosHttpTransport.js +70 -122
- package/lib/SpeculosHttpTransport.js.map +1 -1
- package/lib-es/SpeculosHttpTransport.d.ts +1 -1
- package/lib-es/SpeculosHttpTransport.d.ts.map +1 -1
- package/lib-es/SpeculosHttpTransport.js +64 -117
- package/lib-es/SpeculosHttpTransport.js.map +1 -1
- package/package.json +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @ledgerhq/hw-transport-node-speculos-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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpeculosHttpTransport.d.ts","sourceRoot":"","sources":["../src/SpeculosHttpTransport.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAG/C,
|
|
1
|
+
{"version":3,"file":"SpeculosHttpTransport.d.ts","sourceRoot":"","sources":["../src/SpeculosHttpTransport.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAG/C,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,SAAS;IAC1D,QAAQ,EAAE,aAAa,CAAC;IACxB,IAAI,EAAE,yBAAyB,CAAC;IAChC,WAAW,EAAE,GAAG,CAAC;gBAEL,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,yBAAyB;IAMpE,MAAM,CAAC,WAAW,QAAO,QAAQ,OAAO,CAAC,CAA0B;IAEnE,MAAM,CAAC,IAAI,QAAO,GAAG,CAAwB;IAC7C,MAAM,CAAC,MAAM,cAAe,GAAG;;MAE5B;IAEH,MAAM,CAAC,IAAI,SACH,yBAAyB,KAC9B,QAAQ,qBAAqB,CAAC,CA+B5B;IAEL;;;;OAIG;IACH,MAAM,QAAS,MAAM,KAAG,QAAQ,IAAI,CAAC,CAYhC;IAEC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAWpC,KAAK;CAKZ"}
|
|
@@ -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,41 +8,14 @@ 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
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const errors_1 = require("@ledgerhq/errors");
|
|
17
|
+
const hw_transport_1 = __importDefault(require("@ledgerhq/hw-transport"));
|
|
18
|
+
const logs_1 = require("@ledgerhq/logs");
|
|
61
19
|
/**
|
|
62
20
|
* Speculos TCP transport implementation
|
|
63
21
|
*
|
|
@@ -66,90 +24,80 @@ var logs_1 = require("@ledgerhq/logs");
|
|
|
66
24
|
* const transport = await SpeculosHttpTransport.open();
|
|
67
25
|
* const res = await transport.send(0xE0, 0x01, 0, 0);
|
|
68
26
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
var _this = _super.call(this) || this;
|
|
27
|
+
class SpeculosHttpTransport extends hw_transport_1.default {
|
|
28
|
+
constructor(instance, opts) {
|
|
29
|
+
super();
|
|
73
30
|
/**
|
|
74
31
|
* Press and release button
|
|
75
32
|
* buttons available: left, right, both
|
|
76
33
|
* @param {*} but
|
|
77
34
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
});
|
|
35
|
+
this.button = (but) => new Promise((resolve, reject) => {
|
|
36
|
+
const action = { action: "press-and-release" };
|
|
37
|
+
(0, logs_1.log)("speculos-button", "press-and-release", but);
|
|
38
|
+
this.instance
|
|
39
|
+
.post(`/button/${but}`, action)
|
|
40
|
+
.then((response) => {
|
|
41
|
+
resolve(response.data);
|
|
42
|
+
})
|
|
43
|
+
.catch((e) => {
|
|
44
|
+
reject(e);
|
|
89
45
|
});
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return _this;
|
|
46
|
+
});
|
|
47
|
+
this.instance = instance;
|
|
48
|
+
this.opts = opts;
|
|
94
49
|
}
|
|
95
|
-
|
|
96
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
(0, logs_1.log)("apdu", "<= " + data);
|
|
105
|
-
return Buffer.from(data, "hex");
|
|
106
|
-
})];
|
|
50
|
+
exchange(apdu) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const hex = apdu.toString("hex");
|
|
53
|
+
(0, logs_1.log)("apdu", "=> " + hex);
|
|
54
|
+
return this.instance.post("/apdu", { data: hex }).then((r) => {
|
|
55
|
+
// r.data is {"data": "hex value of response"}
|
|
56
|
+
const data = r.data.data;
|
|
57
|
+
(0, logs_1.log)("apdu", "<= " + data);
|
|
58
|
+
return Buffer.from(data, "hex");
|
|
107
59
|
});
|
|
108
60
|
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return [2 /*return*/, Promise.resolve()];
|
|
116
|
-
});
|
|
61
|
+
}
|
|
62
|
+
close() {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
// close event stream
|
|
65
|
+
this.eventStream.destroy();
|
|
66
|
+
return Promise.resolve();
|
|
117
67
|
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
response.data.on("close", function () {
|
|
141
|
-
(0, logs_1.log)("speculos-event", "close");
|
|
142
|
-
transport.emit("disconnect", new errors_1.DisconnectedDevice("Speculos exited!"));
|
|
143
|
-
});
|
|
144
|
-
transport.eventStream = response.data;
|
|
145
|
-
// we are connected to speculos
|
|
146
|
-
resolve(transport);
|
|
147
|
-
})["catch"](function (error) {
|
|
148
|
-
reject(error);
|
|
149
|
-
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.default = SpeculosHttpTransport;
|
|
71
|
+
SpeculosHttpTransport.isSupported = () => Promise.resolve(true);
|
|
72
|
+
// this transport is not discoverable
|
|
73
|
+
SpeculosHttpTransport.list = () => Promise.resolve([]);
|
|
74
|
+
SpeculosHttpTransport.listen = (_observer) => ({
|
|
75
|
+
unsubscribe: () => { },
|
|
76
|
+
});
|
|
77
|
+
SpeculosHttpTransport.open = (opts) => new Promise((resolve, reject) => {
|
|
78
|
+
const instance = axios_1.default.create(opts);
|
|
79
|
+
instance.defaults.baseURL = "http://localhost:5000";
|
|
80
|
+
const transport = new SpeculosHttpTransport(instance, opts);
|
|
81
|
+
instance({
|
|
82
|
+
url: "/events?stream=true",
|
|
83
|
+
responseType: "stream",
|
|
84
|
+
})
|
|
85
|
+
.then((response) => {
|
|
86
|
+
response.data.on("data", (chunk) => {
|
|
87
|
+
(0, logs_1.log)("speculos-event", chunk.toString());
|
|
88
|
+
// XXX: we could process display events here
|
|
89
|
+
// client side automation or UI tests/checks
|
|
150
90
|
});
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
91
|
+
response.data.on("close", () => {
|
|
92
|
+
(0, logs_1.log)("speculos-event", "close");
|
|
93
|
+
transport.emit("disconnect", new errors_1.DisconnectedDevice("Speculos exited!"));
|
|
94
|
+
});
|
|
95
|
+
transport.eventStream = response.data;
|
|
96
|
+
// we are connected to speculos
|
|
97
|
+
resolve(transport);
|
|
98
|
+
})
|
|
99
|
+
.catch((error) => {
|
|
100
|
+
reject(error);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
155
103
|
//# sourceMappingURL=SpeculosHttpTransport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpeculosHttpTransport.js","sourceRoot":"","sources":["../src/SpeculosHttpTransport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SpeculosHttpTransport.js","sourceRoot":"","sources":["../src/SpeculosHttpTransport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,kDAA0B;AAE1B,6CAAsD;AACtD,0EAA+C;AAC/C,yCAAqC;AAOrC;;;;;;;GAOG;AACH,MAAqB,qBAAsB,SAAQ,sBAAS;IAK1D,YAAY,QAAuB,EAAE,IAA+B;QAClE,KAAK,EAAE,CAAC;QA+CV;;;;WAIG;QACH,WAAM,GAAG,CAAC,GAAW,EAAiB,EAAE,CACtC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC9B,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;YAC/C,IAAA,UAAG,EAAC,iBAAiB,EAAE,mBAAmB,EAAE,GAAG,CAAC,CAAC;YACjD,IAAI,CAAC,QAAQ;iBACV,IAAI,CAAC,WAAW,GAAG,EAAE,EAAE,MAAM,CAAC;iBAC9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CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpeculosHttpTransport.d.ts","sourceRoot":"","sources":["../src/SpeculosHttpTransport.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAG/C,
|
|
1
|
+
{"version":3,"file":"SpeculosHttpTransport.d.ts","sourceRoot":"","sources":["../src/SpeculosHttpTransport.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAG/C,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,SAAS;IAC1D,QAAQ,EAAE,aAAa,CAAC;IACxB,IAAI,EAAE,yBAAyB,CAAC;IAChC,WAAW,EAAE,GAAG,CAAC;gBAEL,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,yBAAyB;IAMpE,MAAM,CAAC,WAAW,QAAO,QAAQ,OAAO,CAAC,CAA0B;IAEnE,MAAM,CAAC,IAAI,QAAO,GAAG,CAAwB;IAC7C,MAAM,CAAC,MAAM,cAAe,GAAG;;MAE5B;IAEH,MAAM,CAAC,IAAI,SACH,yBAAyB,KAC9B,QAAQ,qBAAqB,CAAC,CA+B5B;IAEL;;;;OAIG;IACH,MAAM,QAAS,MAAM,KAAG,QAAQ,IAAI,CAAC,CAYhC;IAEC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAWpC,KAAK;CAKZ"}
|
|
@@ -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,6 @@ 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
|
-
};
|
|
52
10
|
import axios from "axios";
|
|
53
11
|
import { DisconnectedDevice } from "@ledgerhq/errors";
|
|
54
12
|
import Transport from "@ledgerhq/hw-transport";
|
|
@@ -61,90 +19,79 @@ import { log } from "@ledgerhq/logs";
|
|
|
61
19
|
* const transport = await SpeculosHttpTransport.open();
|
|
62
20
|
* const res = await transport.send(0xE0, 0x01, 0, 0);
|
|
63
21
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
var _this = _super.call(this) || this;
|
|
22
|
+
export default class SpeculosHttpTransport extends Transport {
|
|
23
|
+
constructor(instance, opts) {
|
|
24
|
+
super();
|
|
68
25
|
/**
|
|
69
26
|
* Press and release button
|
|
70
27
|
* buttons available: left, right, both
|
|
71
28
|
* @param {*} but
|
|
72
29
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
30
|
+
this.button = (but) => new Promise((resolve, reject) => {
|
|
31
|
+
const action = { action: "press-and-release" };
|
|
32
|
+
log("speculos-button", "press-and-release", but);
|
|
33
|
+
this.instance
|
|
34
|
+
.post(`/button/${but}`, action)
|
|
35
|
+
.then((response) => {
|
|
36
|
+
resolve(response.data);
|
|
37
|
+
})
|
|
38
|
+
.catch((e) => {
|
|
39
|
+
reject(e);
|
|
84
40
|
});
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return _this;
|
|
41
|
+
});
|
|
42
|
+
this.instance = instance;
|
|
43
|
+
this.opts = opts;
|
|
89
44
|
}
|
|
90
|
-
|
|
91
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
log("apdu", "<= " + data);
|
|
100
|
-
return Buffer.from(data, "hex");
|
|
101
|
-
})];
|
|
45
|
+
exchange(apdu) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const hex = apdu.toString("hex");
|
|
48
|
+
log("apdu", "=> " + hex);
|
|
49
|
+
return this.instance.post("/apdu", { data: hex }).then((r) => {
|
|
50
|
+
// r.data is {"data": "hex value of response"}
|
|
51
|
+
const data = r.data.data;
|
|
52
|
+
log("apdu", "<= " + data);
|
|
53
|
+
return Buffer.from(data, "hex");
|
|
102
54
|
});
|
|
103
55
|
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return [2 /*return*/, Promise.resolve()];
|
|
111
|
-
});
|
|
56
|
+
}
|
|
57
|
+
close() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
// close event stream
|
|
60
|
+
this.eventStream.destroy();
|
|
61
|
+
return Promise.resolve();
|
|
112
62
|
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
});
|
|
135
|
-
response.data.on("close", function () {
|
|
136
|
-
log("speculos-event", "close");
|
|
137
|
-
transport.emit("disconnect", new DisconnectedDevice("Speculos exited!"));
|
|
138
|
-
});
|
|
139
|
-
transport.eventStream = response.data;
|
|
140
|
-
// we are connected to speculos
|
|
141
|
-
resolve(transport);
|
|
142
|
-
})["catch"](function (error) {
|
|
143
|
-
reject(error);
|
|
144
|
-
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
SpeculosHttpTransport.isSupported = () => Promise.resolve(true);
|
|
66
|
+
// this transport is not discoverable
|
|
67
|
+
SpeculosHttpTransport.list = () => Promise.resolve([]);
|
|
68
|
+
SpeculosHttpTransport.listen = (_observer) => ({
|
|
69
|
+
unsubscribe: () => { },
|
|
70
|
+
});
|
|
71
|
+
SpeculosHttpTransport.open = (opts) => new Promise((resolve, reject) => {
|
|
72
|
+
const instance = axios.create(opts);
|
|
73
|
+
instance.defaults.baseURL = "http://localhost:5000";
|
|
74
|
+
const transport = new SpeculosHttpTransport(instance, opts);
|
|
75
|
+
instance({
|
|
76
|
+
url: "/events?stream=true",
|
|
77
|
+
responseType: "stream",
|
|
78
|
+
})
|
|
79
|
+
.then((response) => {
|
|
80
|
+
response.data.on("data", (chunk) => {
|
|
81
|
+
log("speculos-event", chunk.toString());
|
|
82
|
+
// XXX: we could process display events here
|
|
83
|
+
// client side automation or UI tests/checks
|
|
145
84
|
});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
85
|
+
response.data.on("close", () => {
|
|
86
|
+
log("speculos-event", "close");
|
|
87
|
+
transport.emit("disconnect", new DisconnectedDevice("Speculos exited!"));
|
|
88
|
+
});
|
|
89
|
+
transport.eventStream = response.data;
|
|
90
|
+
// we are connected to speculos
|
|
91
|
+
resolve(transport);
|
|
92
|
+
})
|
|
93
|
+
.catch((error) => {
|
|
94
|
+
reject(error);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
150
97
|
//# sourceMappingURL=SpeculosHttpTransport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpeculosHttpTransport.js","sourceRoot":"","sources":["../src/SpeculosHttpTransport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SpeculosHttpTransport.js","sourceRoot":"","sources":["../src/SpeculosHttpTransport.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAOrC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,SAAS;IAK1D,YAAY,QAAuB,EAAE,IAA+B;QAClE,KAAK,EAAE,CAAC;QA+CV;;;;WAIG;QACH,WAAM,GAAG,CAAC,GAAW,EAAiB,EAAE,CACtC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC9B,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;YAC/C,GAAG,CAAC,iBAAiB,EAAE,mBAAmB,EAAE,GAAG,CAAC,CAAC;YACjD,IAAI,CAAC,QAAQ;iBACV,IAAI,CAAC,WAAW,GAAG,EA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package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/hw-transport-node-speculos-http",
|
|
3
|
-
"version": "6.27.
|
|
3
|
+
"version": "6.27.14-next.0",
|
|
4
4
|
"description": "Ledger Hardware Wallet communication layer with speculos Nano simulator using the http api",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"license": "Apache-2.0",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"axios": "^0.26.1",
|
|
32
|
-
"@ledgerhq/errors": "^6.12.
|
|
33
|
-
"@ledgerhq/hw-transport": "^6.28.
|
|
32
|
+
"@ledgerhq/errors": "^6.12.5-next.0",
|
|
33
|
+
"@ledgerhq/hw-transport": "^6.28.3-next.0",
|
|
34
34
|
"@ledgerhq/logs": "^6.10.1"
|
|
35
35
|
},
|
|
36
36
|
"gitHead": "dd0dea64b58e5a9125c8a422dcffd29e5ef6abec",
|
|
@@ -39,11 +39,10 @@
|
|
|
39
39
|
"@types/node": "^18.15.3",
|
|
40
40
|
"documentation": "13.2.4",
|
|
41
41
|
"jest": "^28.1.1",
|
|
42
|
-
"rimraf": "^4.1
|
|
42
|
+
"rimraf": "^4.4.1",
|
|
43
43
|
"source-map-support": "^0.5.21",
|
|
44
44
|
"ts-jest": "^28.0.5",
|
|
45
|
-
"ts-node": "^10.4.0"
|
|
46
|
-
"typescript": "^4"
|
|
45
|
+
"ts-node": "^10.4.0"
|
|
47
46
|
},
|
|
48
47
|
"scripts": {
|
|
49
48
|
"clean": "rimraf lib lib-es",
|