@metamask-previews/wallet-cli 0.0.0-preview-8633f7f2a → 0.0.0-preview-9de9aa4
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 +1 -2
- package/dist/daemon/daemon-client.cjs +140 -0
- package/dist/daemon/daemon-client.cjs.map +1 -0
- package/dist/daemon/daemon-client.d.cts +79 -0
- package/dist/daemon/daemon-client.d.cts.map +1 -0
- package/dist/daemon/daemon-client.d.mts +79 -0
- package/dist/daemon/daemon-client.d.mts.map +1 -0
- package/dist/daemon/daemon-client.mjs +135 -0
- package/dist/daemon/daemon-client.mjs.map +1 -0
- package/dist/daemon/daemon-spawn.cjs +106 -0
- package/dist/daemon/daemon-spawn.cjs.map +1 -0
- package/dist/daemon/daemon-spawn.d.cts +28 -0
- package/dist/daemon/daemon-spawn.d.cts.map +1 -0
- package/dist/daemon/daemon-spawn.d.mts +28 -0
- package/dist/daemon/daemon-spawn.d.mts.map +1 -0
- package/dist/daemon/daemon-spawn.mjs +102 -0
- package/dist/daemon/daemon-spawn.mjs.map +1 -0
- package/dist/daemon/prompts.cjs +21 -0
- package/dist/daemon/prompts.cjs.map +1 -0
- package/dist/daemon/prompts.d.cts +11 -0
- package/dist/daemon/prompts.d.cts.map +1 -0
- package/dist/daemon/prompts.d.mts +11 -0
- package/dist/daemon/prompts.d.mts.map +1 -0
- package/dist/daemon/prompts.mjs +17 -0
- package/dist/daemon/prompts.mjs.map +1 -0
- package/dist/daemon/rpc-socket-server.cjs +271 -0
- package/dist/daemon/rpc-socket-server.cjs.map +1 -0
- package/dist/daemon/rpc-socket-server.d.cts +44 -0
- package/dist/daemon/rpc-socket-server.d.cts.map +1 -0
- package/dist/daemon/rpc-socket-server.d.mts +44 -0
- package/dist/daemon/rpc-socket-server.d.mts.map +1 -0
- package/dist/daemon/rpc-socket-server.mjs +267 -0
- package/dist/daemon/rpc-socket-server.mjs.map +1 -0
- package/dist/daemon/socket-line.cjs +89 -0
- package/dist/daemon/socket-line.cjs.map +1 -0
- package/dist/daemon/socket-line.d.cts +19 -0
- package/dist/daemon/socket-line.d.cts.map +1 -0
- package/dist/daemon/socket-line.d.mts +19 -0
- package/dist/daemon/socket-line.d.mts.map +1 -0
- package/dist/daemon/socket-line.mjs +84 -0
- package/dist/daemon/socket-line.mjs.map +1 -0
- package/dist/daemon/stop-daemon.cjs +103 -0
- package/dist/daemon/stop-daemon.cjs.map +1 -0
- package/dist/daemon/stop-daemon.d.cts +18 -0
- package/dist/daemon/stop-daemon.d.cts.map +1 -0
- package/dist/daemon/stop-daemon.d.mts +18 -0
- package/dist/daemon/stop-daemon.d.mts.map +1 -0
- package/dist/daemon/stop-daemon.mjs +99 -0
- package/dist/daemon/stop-daemon.mjs.map +1 -0
- package/dist/daemon/types.cjs.map +1 -1
- package/dist/daemon/types.d.cts +28 -0
- package/dist/daemon/types.d.cts.map +1 -1
- package/dist/daemon/types.d.mts +28 -0
- package/dist/daemon/types.d.mts.map +1 -1
- package/dist/daemon/types.mjs.map +1 -1
- package/dist/daemon/utils.cjs +109 -0
- package/dist/daemon/utils.cjs.map +1 -0
- package/dist/daemon/utils.d.cts +50 -0
- package/dist/daemon/utils.d.cts.map +1 -0
- package/dist/daemon/utils.d.mts +50 -0
- package/dist/daemon/utils.d.mts.map +1 -0
- package/dist/daemon/utils.mjs +101 -0
- package/dist/daemon/utils.mjs.map +1 -0
- package/package.json +3 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { isErrorWithCode as hasErrorCode } from "@metamask/utils";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
/**
|
|
4
|
+
* Check whether an unknown error is a Node.js system error with the given code.
|
|
5
|
+
*
|
|
6
|
+
* @param error - The error to check.
|
|
7
|
+
* @param code - The expected error code (e.g. 'ENOENT', 'EPERM').
|
|
8
|
+
* @returns True if the error matches the code.
|
|
9
|
+
*/
|
|
10
|
+
export function isErrorWithCode(error, code) {
|
|
11
|
+
return hasErrorCode(error) && error.code === code;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Read a PID from a file. The file may contain just the PID, or the PID on
|
|
15
|
+
* the first line followed by additional metadata (e.g. start time written by
|
|
16
|
+
* the daemon).
|
|
17
|
+
*
|
|
18
|
+
* @param pidPath - The PID file path.
|
|
19
|
+
* @returns The PID, or undefined if the file is missing or its first line is
|
|
20
|
+
* not a positive integer.
|
|
21
|
+
*/
|
|
22
|
+
export async function readPidFile(pidPath) {
|
|
23
|
+
let contents;
|
|
24
|
+
try {
|
|
25
|
+
contents = await readFile(pidPath, 'utf-8');
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (isErrorWithCode(error, 'ENOENT')) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
// String.prototype.split always returns at least one element, so [0] is safe.
|
|
34
|
+
const pid = Number(contents.split('\n')[0].trim());
|
|
35
|
+
return Number.isInteger(pid) && pid > 0 ? pid : undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Check whether a process is alive by sending signal 0.
|
|
39
|
+
*
|
|
40
|
+
* Treats `ESRCH` as "process is gone", `EPERM` as "process exists but we
|
|
41
|
+
* cannot signal it" (still alive from our perspective), and rethrows
|
|
42
|
+
* anything else so the caller can surface unexpected failures rather than
|
|
43
|
+
* silently assuming the process is dead.
|
|
44
|
+
*
|
|
45
|
+
* @param pid - The process ID to check.
|
|
46
|
+
* @returns True if the process exists.
|
|
47
|
+
*/
|
|
48
|
+
export function isProcessAlive(pid) {
|
|
49
|
+
try {
|
|
50
|
+
process.kill(pid, 0);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (isErrorWithCode(error, 'ESRCH')) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (isErrorWithCode(error, 'EPERM')) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Send a signal to a process. Returns true if the signal was sent, false if
|
|
65
|
+
* the process does not exist (ESRCH). Re-throws on permission errors and
|
|
66
|
+
* other failures.
|
|
67
|
+
*
|
|
68
|
+
* @param pid - The process ID.
|
|
69
|
+
* @param signal - The signal to send.
|
|
70
|
+
* @returns True if the signal was delivered, false if the process is gone.
|
|
71
|
+
*/
|
|
72
|
+
export function sendSignal(pid, signal) {
|
|
73
|
+
try {
|
|
74
|
+
process.kill(pid, signal);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (isErrorWithCode(error, 'ESRCH')) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Poll until a condition is met or the timeout elapses.
|
|
86
|
+
*
|
|
87
|
+
* @param check - A function that returns true when the condition is met.
|
|
88
|
+
* @param timeoutMs - Maximum time to wait in milliseconds.
|
|
89
|
+
* @returns True if the condition was met, false on timeout.
|
|
90
|
+
*/
|
|
91
|
+
export async function waitFor(check, timeoutMs) {
|
|
92
|
+
const deadline = Date.now() + timeoutMs;
|
|
93
|
+
while (Date.now() < deadline) {
|
|
94
|
+
if (await check()) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/daemon/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,YAAY,EAAE,wBAAwB;AAClE,OAAO,EAAE,QAAQ,EAAE,yBAAyB;AAE5C;;;;;;GAMG;A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,UAAU,CAAC,GAAW,EAAE,MAAsB;IAC5D,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,KAAuC,EACvC,SAAiB;IAEjB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IACxC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC7B,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { isErrorWithCode as hasErrorCode } from '@metamask/utils';\nimport { readFile } from 'node:fs/promises';\n\n/**\n * Check whether an unknown error is a Node.js system error with the given code.\n *\n * @param error - The error to check.\n * @param code - The expected error code (e.g. 'ENOENT', 'EPERM').\n * @returns True if the error matches the code.\n */\nexport function isErrorWithCode(error: unknown, code: string): boolean {\n return hasErrorCode(error) && error.code === code;\n}\n\n/**\n * Read a PID from a file. The file may contain just the PID, or the PID on\n * the first line followed by additional metadata (e.g. start time written by\n * the daemon).\n *\n * @param pidPath - The PID file path.\n * @returns The PID, or undefined if the file is missing or its first line is\n * not a positive integer.\n */\nexport async function readPidFile(\n pidPath: string,\n): Promise<number | undefined> {\n let contents: string;\n try {\n contents = await readFile(pidPath, 'utf-8');\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ENOENT')) {\n return undefined;\n }\n throw error;\n }\n // String.prototype.split always returns at least one element, so [0] is safe.\n const pid = Number(contents.split('\\n')[0].trim());\n return Number.isInteger(pid) && pid > 0 ? pid : undefined;\n}\n\n/**\n * Check whether a process is alive by sending signal 0.\n *\n * Treats `ESRCH` as \"process is gone\", `EPERM` as \"process exists but we\n * cannot signal it\" (still alive from our perspective), and rethrows\n * anything else so the caller can surface unexpected failures rather than\n * silently assuming the process is dead.\n *\n * @param pid - The process ID to check.\n * @returns True if the process exists.\n */\nexport function isProcessAlive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ESRCH')) {\n return false;\n }\n if (isErrorWithCode(error, 'EPERM')) {\n return true;\n }\n throw error;\n }\n}\n\n/**\n * Send a signal to a process. Returns true if the signal was sent, false if\n * the process does not exist (ESRCH). Re-throws on permission errors and\n * other failures.\n *\n * @param pid - The process ID.\n * @param signal - The signal to send.\n * @returns True if the signal was delivered, false if the process is gone.\n */\nexport function sendSignal(pid: number, signal: NodeJS.Signals): boolean {\n try {\n process.kill(pid, signal);\n return true;\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ESRCH')) {\n return false;\n }\n throw error;\n }\n}\n\n/**\n * Poll until a condition is met or the timeout elapses.\n *\n * @param check - A function that returns true when the condition is met.\n * @param timeoutMs - Maximum time to wait in milliseconds.\n * @returns True if the condition was met, false on timeout.\n */\nexport async function waitFor(\n check: () => boolean | Promise<boolean>,\n timeoutMs: number,\n): Promise<boolean> {\n const deadline = Date.now() + timeoutMs;\n while (Date.now() < deadline) {\n if (await check()) {\n return true;\n }\n await new Promise((resolve) => setTimeout(resolve, 250));\n }\n return false;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/wallet-cli",
|
|
3
|
-
"version": "0.0.0-preview-
|
|
3
|
+
"version": "0.0.0-preview-9de9aa4",
|
|
4
4
|
"description": "The CLI of @metamask/wallet",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -43,7 +43,9 @@
|
|
|
43
43
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
+
"@inquirer/confirm": "^6.0.11",
|
|
46
47
|
"@metamask/base-controller": "^9.1.0",
|
|
48
|
+
"@metamask/rpc-errors": "^7.0.2",
|
|
47
49
|
"@metamask/utils": "^11.11.0",
|
|
48
50
|
"@metamask/wallet": "^4.0.0",
|
|
49
51
|
"@oclif/core": "^4.10.5",
|