@ledgerhq/coin-tester 0.12.0-nightly.20251120023735 → 0.12.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +5 -6
- package/lib/signers/speculos.d.ts +2 -2
- package/lib/signers/speculos.d.ts.map +1 -1
- package/lib/signers/speculos.js +15 -32
- package/lib/signers/speculos.js.map +1 -1
- package/lib-es/signers/speculos.d.ts +2 -2
- package/lib-es/signers/speculos.d.ts.map +1 -1
- package/lib-es/signers/speculos.js +15 -32
- package/lib-es/signers/speculos.js.map +1 -1
- package/package.json +3 -4
- package/src/signers/speculos.ts +20 -37
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
# @ledgerhq/coin-tester
|
|
2
2
|
|
|
3
|
-
## 0.12.0
|
|
3
|
+
## 0.12.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
-
- [#12563](https://github.com/LedgerHQ/ledger-live/pull/12563) [`b4a4e16`](https://github.com/LedgerHQ/ledger-live/commit/b4a4e160aae6fd64f944ab25633f6931dc4358d3) Thanks [@fAnselmi-Ledger](https://github.com/fAnselmi-Ledger)! - Add DMK speculos transport and device controller
|
|
8
|
-
|
|
9
7
|
- [#12499](https://github.com/LedgerHQ/ledger-live/pull/12499) [`48ad785`](https://github.com/LedgerHQ/ledger-live/commit/48ad785ce6f7f8fef27157b611e8c8e6e91bfe7e) Thanks [@qperrot](https://github.com/qperrot)! - Add tests on BTC coin tester regarding rbf and cancel
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
## 0.12.0-next.0
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#12499](https://github.com/LedgerHQ/ledger-live/pull/12499) [`48ad785`](https://github.com/LedgerHQ/ledger-live/commit/48ad785ce6f7f8fef27157b611e8c8e6e91bfe7e) Thanks [@qperrot](https://github.com/qperrot)! - Add tests on BTC coin tester regarding rbf and cancel
|
|
15
14
|
|
|
16
15
|
## 0.11.0
|
|
17
16
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import SpeculosTransportHttp from "@ledgerhq/hw-transport-node-speculos-http";
|
|
2
2
|
export declare const delay: (timing: number) => Promise<unknown>;
|
|
3
3
|
export declare function ensureEnv(): void;
|
|
4
4
|
export declare function spawnSpeculos(nanoAppEndpoint: `/${string}`, options?: {
|
|
@@ -7,7 +7,7 @@ export declare function spawnSpeculos(nanoAppEndpoint: `/${string}`, options?: {
|
|
|
7
7
|
endpoint: `/${string}`;
|
|
8
8
|
}>;
|
|
9
9
|
}): Promise<{
|
|
10
|
-
transport:
|
|
10
|
+
transport: SpeculosTransportHttp;
|
|
11
11
|
getOnSpeculosConfirmation: (approvalText?: string) => () => Promise<void>;
|
|
12
12
|
}>;
|
|
13
13
|
export declare function killSpeculos(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speculos.d.ts","sourceRoot":"","sources":["../../src/signers/speculos.ts"],"names":[],"mappings":"AAMA,OAAO,
|
|
1
|
+
{"version":3,"file":"speculos.d.ts","sourceRoot":"","sources":["../../src/signers/speculos.ts"],"names":[],"mappings":"AAMA,OAAO,qBAAqB,MAAM,2CAA2C,CAAC;AAM9E,eAAO,MAAM,KAAK,WAAY,MAAM,qBAAwD,CAAC;AAE7F,wBAAgB,SAAS,SAexB;AAeD,wBAAsB,aAAa,CACjC,eAAe,EAAE,IAAI,MAAM,EAAE,EAC7B,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,IAAI,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;CAC7D,GACA,OAAO,CAAC;IACT,SAAS,EAAE,qBAAqB,CAAC;IACjC,yBAAyB,EAAE,CAAC,YAAY,CAAC,EAAE,MAAM,KAAK,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3E,CAAC,CAmFD;AAED,wBAAsB,YAAY,kBAQjC"}
|
package/lib/signers/speculos.js
CHANGED
|
@@ -35,8 +35,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
35
35
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
36
36
|
const compose = __importStar(require("docker-compose"));
|
|
37
37
|
const axios_1 = __importStar(require("axios"));
|
|
38
|
-
const
|
|
39
|
-
const speculos_device_controller_1 = require("@ledgerhq/speculos-device-controller");
|
|
38
|
+
const hw_transport_node_speculos_http_1 = __importDefault(require("@ledgerhq/hw-transport-node-speculos-http"));
|
|
40
39
|
const { SPECULOS_API_PORT } = process.env;
|
|
41
40
|
const cwd = path_1.default.join(__dirname);
|
|
42
41
|
const delay = (timing) => new Promise(resolve => setTimeout(resolve, timing));
|
|
@@ -99,7 +98,7 @@ async function spawnSpeculos(nanoAppEndpoint, options) {
|
|
|
99
98
|
const { out } = await compose.logs("speculos", { cwd, env: process.env });
|
|
100
99
|
if (out.includes("Server started")) {
|
|
101
100
|
console.log(chalk_1.default.bgYellowBright.black(" - SPECULOS READY ✅ - "));
|
|
102
|
-
return
|
|
101
|
+
return hw_transport_node_speculos_http_1.default.open({
|
|
103
102
|
apiPort: SPECULOS_API_PORT,
|
|
104
103
|
});
|
|
105
104
|
}
|
|
@@ -107,39 +106,23 @@ async function spawnSpeculos(nanoAppEndpoint, options) {
|
|
|
107
106
|
return checkSpeculosLogs();
|
|
108
107
|
}
|
|
109
108
|
function getOnSpeculosConfirmation(approvalText = "Accept") {
|
|
110
|
-
|
|
111
|
-
if (e?.type
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const delayMs = 250;
|
|
117
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
118
|
-
try {
|
|
119
|
-
const { data } = await axios_1.default.get(`${baseURL}/events?currentscreenonly=true`, {
|
|
120
|
-
timeout: 2000,
|
|
109
|
+
async function onSpeculosConfirmation(e) {
|
|
110
|
+
if (e?.type === "device-signature-requested") {
|
|
111
|
+
const { data } = await axios_1.default.get(`http://localhost:${SPECULOS_API_PORT}/events?currentscreenonly=true`);
|
|
112
|
+
if (data.events[0].text !== approvalText) {
|
|
113
|
+
await axios_1.default.post(`http://localhost:${SPECULOS_API_PORT}/button/right`, {
|
|
114
|
+
action: "press-and-release",
|
|
121
115
|
});
|
|
122
|
-
|
|
123
|
-
if (text === approvalText) {
|
|
124
|
-
await buttonClient.both();
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
// not on the approval screen yet—scroll right and retry
|
|
128
|
-
await buttonClient.right();
|
|
116
|
+
onSpeculosConfirmation(e);
|
|
129
117
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
throw err;
|
|
137
|
-
}
|
|
118
|
+
else {
|
|
119
|
+
await axios_1.default.post(`http://localhost:${SPECULOS_API_PORT}/button/both`, {
|
|
120
|
+
action: "press-and-release",
|
|
121
|
+
});
|
|
138
122
|
}
|
|
139
|
-
await (0, exports.delay)(delayMs);
|
|
140
123
|
}
|
|
141
|
-
|
|
142
|
-
|
|
124
|
+
}
|
|
125
|
+
return onSpeculosConfirmation;
|
|
143
126
|
}
|
|
144
127
|
return checkSpeculosLogs().then(transport => {
|
|
145
128
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speculos.js","sourceRoot":"","sources":["../../src/signers/speculos.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"speculos.js","sourceRoot":"","sources":["../../src/signers/speculos.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,8BAeC;AAeD,sCA2FC;AAED,oCAQC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AK,CAAC,IAAI,CAAC,oBAAoB,iBAAiB,eAAe,EAAE;wBACrE,MAAM,EAAE,mBAAmB;qBAC5B,CAAC,CAAC;oBAEH,sBAAsB,CAAC,CAAC,CAAC,CAAC;gBAC5B,CAAC;qBAAM,CAAC;oBACN,MAAM,eAAK,CAAC,IAAI,CAAC,oBAAoB,iBAAiB,cAAc,EAAE;wBACpE,MAAM,EAAE,mBAAmB;qBAC5B,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,sBAAsB,CAAC;IAChC,CAAC;IAED,OAAO,iBAAiB,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;QAC1C,OAAO;YACL,SAAS;YACT,yBAAyB;SAC1B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAEM,KAAK,UAAU,YAAY;IAChC,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IACpC,MAAM,OAAO,CAAC,IAAI,CAAC;QACjB,GAAG;QACH,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;QAC/B,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,cAAc,EAAE,CAAC,kBAAkB,CAAC;KACrC,CAAC,CAAC;AACL,CAAC;AAED,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,mBAAmB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAC1F,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,IAAI,EAAE;IACvB,MAAM,YAAY,EAAE,CAAC;AACvB,CAAC,CAAC,CACH,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import SpeculosTransportHttp from "@ledgerhq/hw-transport-node-speculos-http";
|
|
2
2
|
export declare const delay: (timing: number) => Promise<unknown>;
|
|
3
3
|
export declare function ensureEnv(): void;
|
|
4
4
|
export declare function spawnSpeculos(nanoAppEndpoint: `/${string}`, options?: {
|
|
@@ -7,7 +7,7 @@ export declare function spawnSpeculos(nanoAppEndpoint: `/${string}`, options?: {
|
|
|
7
7
|
endpoint: `/${string}`;
|
|
8
8
|
}>;
|
|
9
9
|
}): Promise<{
|
|
10
|
-
transport:
|
|
10
|
+
transport: SpeculosTransportHttp;
|
|
11
11
|
getOnSpeculosConfirmation: (approvalText?: string) => () => Promise<void>;
|
|
12
12
|
}>;
|
|
13
13
|
export declare function killSpeculos(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speculos.d.ts","sourceRoot":"","sources":["../../src/signers/speculos.ts"],"names":[],"mappings":"AAMA,OAAO,
|
|
1
|
+
{"version":3,"file":"speculos.d.ts","sourceRoot":"","sources":["../../src/signers/speculos.ts"],"names":[],"mappings":"AAMA,OAAO,qBAAqB,MAAM,2CAA2C,CAAC;AAM9E,eAAO,MAAM,KAAK,WAAY,MAAM,qBAAwD,CAAC;AAE7F,wBAAgB,SAAS,SAexB;AAeD,wBAAsB,aAAa,CACjC,eAAe,EAAE,IAAI,MAAM,EAAE,EAC7B,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,IAAI,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;CAC7D,GACA,OAAO,CAAC;IACT,SAAS,EAAE,qBAAqB,CAAC;IACjC,yBAAyB,EAAE,CAAC,YAAY,CAAC,EAAE,MAAM,KAAK,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3E,CAAC,CAmFD;AAED,wBAAsB,YAAY,kBAQjC"}
|
|
@@ -3,8 +3,7 @@ import chalk from "chalk";
|
|
|
3
3
|
import fs from "fs/promises";
|
|
4
4
|
import * as compose from "docker-compose";
|
|
5
5
|
import axios, { AxiosError } from "axios";
|
|
6
|
-
import
|
|
7
|
-
import { deviceControllerClientFactory } from "@ledgerhq/speculos-device-controller";
|
|
6
|
+
import SpeculosTransportHttp from "@ledgerhq/hw-transport-node-speculos-http";
|
|
8
7
|
const { SPECULOS_API_PORT } = process.env;
|
|
9
8
|
const cwd = path.join(__dirname);
|
|
10
9
|
export const delay = (timing) => new Promise(resolve => setTimeout(resolve, timing));
|
|
@@ -66,7 +65,7 @@ export async function spawnSpeculos(nanoAppEndpoint, options) {
|
|
|
66
65
|
const { out } = await compose.logs("speculos", { cwd, env: process.env });
|
|
67
66
|
if (out.includes("Server started")) {
|
|
68
67
|
console.log(chalk.bgYellowBright.black(" - SPECULOS READY ✅ - "));
|
|
69
|
-
return
|
|
68
|
+
return SpeculosTransportHttp.open({
|
|
70
69
|
apiPort: SPECULOS_API_PORT,
|
|
71
70
|
});
|
|
72
71
|
}
|
|
@@ -74,39 +73,23 @@ export async function spawnSpeculos(nanoAppEndpoint, options) {
|
|
|
74
73
|
return checkSpeculosLogs();
|
|
75
74
|
}
|
|
76
75
|
function getOnSpeculosConfirmation(approvalText = "Accept") {
|
|
77
|
-
|
|
78
|
-
if (e?.type
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const delayMs = 250;
|
|
84
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
85
|
-
try {
|
|
86
|
-
const { data } = await axios.get(`${baseURL}/events?currentscreenonly=true`, {
|
|
87
|
-
timeout: 2000,
|
|
76
|
+
async function onSpeculosConfirmation(e) {
|
|
77
|
+
if (e?.type === "device-signature-requested") {
|
|
78
|
+
const { data } = await axios.get(`http://localhost:${SPECULOS_API_PORT}/events?currentscreenonly=true`);
|
|
79
|
+
if (data.events[0].text !== approvalText) {
|
|
80
|
+
await axios.post(`http://localhost:${SPECULOS_API_PORT}/button/right`, {
|
|
81
|
+
action: "press-and-release",
|
|
88
82
|
});
|
|
89
|
-
|
|
90
|
-
if (text === approvalText) {
|
|
91
|
-
await buttonClient.both();
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
// not on the approval screen yet—scroll right and retry
|
|
95
|
-
await buttonClient.right();
|
|
83
|
+
onSpeculosConfirmation(e);
|
|
96
84
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
throw err;
|
|
104
|
-
}
|
|
85
|
+
else {
|
|
86
|
+
await axios.post(`http://localhost:${SPECULOS_API_PORT}/button/both`, {
|
|
87
|
+
action: "press-and-release",
|
|
88
|
+
});
|
|
105
89
|
}
|
|
106
|
-
await delay(delayMs);
|
|
107
90
|
}
|
|
108
|
-
|
|
109
|
-
|
|
91
|
+
}
|
|
92
|
+
return onSpeculosConfirmation;
|
|
110
93
|
}
|
|
111
94
|
return checkSpeculosLogs().then(transport => {
|
|
112
95
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speculos.js","sourceRoot":"","sources":["../../src/signers/speculos.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,
|
|
1
|
+
{"version":3,"file":"speculos.js","sourceRoot":"","sources":["../../src/signers/speculos.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,qBAAqB,MAAM,2CAA2C,CAAC;AAG9E,MAAM,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,GAAU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oBACN,MAAM,KAAK,CAAC,IAAI,CAAC,oBAAoB,iBAAiB,cAAc,EAAE;wBACpE,MAAM,EAAE,mBAAmB;qBAC5B,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,sBAAsB,CAAC;IAChC,CAAC;IAED,OAAO,iBAAiB,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;QAC1C,OAAO;YACL,SAAS;YACT,yBAAyB;SAC1B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IACpC,MAAM,OAAO,CAAC,IAAI,CAAC;QACjB,GAAG;QACH,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;QAC/B,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,cAAc,EAAE,CAAC,kBAAkB,CAAC;KACrC,CAAC,CAAC;AACL,CAAC;AAED,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,mBAAmB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAC1F,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,IAAI,EAAE;IACvB,MAAM,YAAY,EAAE,CAAC;AACvB,CAAC,CAAC,CACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-tester",
|
|
3
|
-
"version": "0.12.0
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Deterministic testing of Ledger coin-modules",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@ledgerhq/speculos-device-controller": "0.1.0",
|
|
8
7
|
"axios": "1.12.2",
|
|
9
8
|
"chalk": "^4.1.2",
|
|
10
9
|
"docker-compose": "^1.1.0",
|
|
11
10
|
"lodash": "^4.17.21",
|
|
12
11
|
"rxjs": "7.8.1",
|
|
13
|
-
"@ledgerhq/
|
|
12
|
+
"@ledgerhq/hw-transport-node-speculos-http": "^6.31.0",
|
|
14
13
|
"@ledgerhq/types-devices": "^6.27.0"
|
|
15
14
|
},
|
|
16
15
|
"devDependencies": {
|
|
@@ -20,7 +19,7 @@
|
|
|
20
19
|
"ts-jest": "^28.0.8",
|
|
21
20
|
"typescript": "^5.1.3",
|
|
22
21
|
"@ledgerhq/types-cryptoassets": "^7.30.0",
|
|
23
|
-
"@ledgerhq/types-live": "^6.89.0
|
|
22
|
+
"@ledgerhq/types-live": "^6.89.0"
|
|
24
23
|
},
|
|
25
24
|
"typesVersions": {
|
|
26
25
|
"*": {
|
package/src/signers/speculos.ts
CHANGED
|
@@ -4,8 +4,7 @@ import fs from "fs/promises";
|
|
|
4
4
|
import * as compose from "docker-compose";
|
|
5
5
|
import axios, { AxiosError } from "axios";
|
|
6
6
|
import { SignOperationEvent } from "@ledgerhq/types-live";
|
|
7
|
-
import
|
|
8
|
-
import { deviceControllerClientFactory } from "@ledgerhq/speculos-device-controller";
|
|
7
|
+
import SpeculosTransportHttp from "@ledgerhq/hw-transport-node-speculos-http";
|
|
9
8
|
import { ENV } from "../types";
|
|
10
9
|
|
|
11
10
|
const { SPECULOS_API_PORT } = process.env as ENV;
|
|
@@ -49,7 +48,7 @@ export async function spawnSpeculos(
|
|
|
49
48
|
libraries?: Array<{ name: string; endpoint: `/${string}` }>;
|
|
50
49
|
},
|
|
51
50
|
): Promise<{
|
|
52
|
-
transport:
|
|
51
|
+
transport: SpeculosTransportHttp;
|
|
53
52
|
getOnSpeculosConfirmation: (approvalText?: string) => () => Promise<void>;
|
|
54
53
|
}> {
|
|
55
54
|
ensureEnv();
|
|
@@ -90,12 +89,12 @@ export async function spawnSpeculos(
|
|
|
90
89
|
},
|
|
91
90
|
});
|
|
92
91
|
|
|
93
|
-
async function checkSpeculosLogs(): Promise<
|
|
92
|
+
async function checkSpeculosLogs(): Promise<SpeculosTransportHttp> {
|
|
94
93
|
const { out } = await compose.logs("speculos", { cwd, env: process.env });
|
|
95
94
|
|
|
96
95
|
if (out.includes("Server started")) {
|
|
97
96
|
console.log(chalk.bgYellowBright.black(" - SPECULOS READY ✅ - "));
|
|
98
|
-
return
|
|
97
|
+
return SpeculosTransportHttp.open({
|
|
99
98
|
apiPort: SPECULOS_API_PORT,
|
|
100
99
|
});
|
|
101
100
|
}
|
|
@@ -105,43 +104,27 @@ export async function spawnSpeculos(
|
|
|
105
104
|
}
|
|
106
105
|
|
|
107
106
|
function getOnSpeculosConfirmation(approvalText = "Accept") {
|
|
108
|
-
|
|
109
|
-
if (e?.type
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
118
|
-
try {
|
|
119
|
-
const { data } = await axios.get(`${baseURL}/events?currentscreenonly=true`, {
|
|
120
|
-
timeout: 2000,
|
|
107
|
+
async function onSpeculosConfirmation(e?: SignOperationEvent): Promise<void> {
|
|
108
|
+
if (e?.type === "device-signature-requested") {
|
|
109
|
+
const { data } = await axios.get(
|
|
110
|
+
`http://localhost:${SPECULOS_API_PORT}/events?currentscreenonly=true`,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
if (data.events[0].text !== approvalText) {
|
|
114
|
+
await axios.post(`http://localhost:${SPECULOS_API_PORT}/button/right`, {
|
|
115
|
+
action: "press-and-release",
|
|
121
116
|
});
|
|
122
117
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// not on the approval screen yet—scroll right and retry
|
|
130
|
-
await buttonClient.right();
|
|
131
|
-
} catch (err) {
|
|
132
|
-
// retry on network issues
|
|
133
|
-
if (axios.isAxiosError(err)) {
|
|
134
|
-
// fall through to retry
|
|
135
|
-
} else {
|
|
136
|
-
throw err;
|
|
137
|
-
}
|
|
118
|
+
onSpeculosConfirmation(e);
|
|
119
|
+
} else {
|
|
120
|
+
await axios.post(`http://localhost:${SPECULOS_API_PORT}/button/both`, {
|
|
121
|
+
action: "press-and-release",
|
|
122
|
+
});
|
|
138
123
|
}
|
|
139
|
-
|
|
140
|
-
await delay(delayMs);
|
|
141
124
|
}
|
|
125
|
+
}
|
|
142
126
|
|
|
143
|
-
|
|
144
|
-
};
|
|
127
|
+
return onSpeculosConfirmation;
|
|
145
128
|
}
|
|
146
129
|
|
|
147
130
|
return checkSpeculosLogs().then(transport => {
|