@metamask-previews/wallet-cli 0.0.0-preview-4f4c98e → 0.0.0-preview-eb263b0ee
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/commands/daemon/call.cjs +79 -0
- package/dist/commands/daemon/call.cjs.map +1 -0
- package/dist/commands/daemon/{call.d.ts → call.d.cts} +2 -2
- package/dist/commands/daemon/call.d.cts.map +1 -0
- package/dist/commands/daemon/call.d.mts +14 -0
- package/dist/commands/daemon/call.d.mts.map +1 -0
- package/dist/commands/daemon/{call.js → call.mjs} +6 -6
- package/dist/commands/daemon/call.mjs.map +1 -0
- package/dist/commands/daemon/list.cjs +48 -0
- package/dist/commands/daemon/list.cjs.map +1 -0
- package/dist/commands/daemon/{list.d.ts → list.d.cts} +2 -2
- package/dist/commands/daemon/list.d.cts.map +1 -0
- package/dist/commands/daemon/list.d.mts +7 -0
- package/dist/commands/daemon/list.d.mts.map +1 -0
- package/dist/commands/daemon/{list.js → list.mjs} +6 -6
- package/dist/commands/daemon/list.mjs.map +1 -0
- package/dist/commands/daemon/purge.cjs +58 -0
- package/dist/commands/daemon/purge.cjs.map +1 -0
- package/dist/commands/daemon/{purge.d.ts → purge.d.cts} +2 -2
- package/dist/commands/daemon/purge.d.cts.map +1 -0
- package/dist/commands/daemon/purge.d.mts +10 -0
- package/dist/commands/daemon/purge.d.mts.map +1 -0
- package/dist/commands/daemon/{purge.js → purge.mjs} +7 -7
- package/dist/commands/daemon/purge.mjs.map +1 -0
- package/dist/commands/daemon/start.cjs +52 -0
- package/dist/commands/daemon/start.cjs.map +1 -0
- package/dist/commands/daemon/{start.d.ts → start.d.cts} +2 -2
- package/dist/commands/daemon/start.d.cts.map +1 -0
- package/dist/commands/daemon/start.d.mts +12 -0
- package/dist/commands/daemon/start.d.mts.map +1 -0
- package/dist/commands/daemon/{start.js → start.mjs} +4 -4
- package/dist/commands/daemon/start.mjs.map +1 -0
- package/dist/commands/daemon/status.cjs +59 -0
- package/dist/commands/daemon/status.cjs.map +1 -0
- package/dist/commands/daemon/{status.d.ts → status.d.cts} +2 -2
- package/dist/commands/daemon/status.d.cts.map +1 -0
- package/dist/commands/daemon/status.d.mts +7 -0
- package/dist/commands/daemon/status.d.mts.map +1 -0
- package/dist/commands/daemon/{status.js → status.mjs} +6 -6
- package/dist/commands/daemon/status.mjs.map +1 -0
- package/dist/commands/daemon/stop.cjs +26 -0
- package/dist/commands/daemon/stop.cjs.map +1 -0
- package/dist/commands/daemon/{stop.d.ts → stop.d.cts} +2 -2
- package/dist/commands/daemon/stop.d.cts.map +1 -0
- package/dist/commands/daemon/stop.d.mts +7 -0
- package/dist/commands/daemon/stop.d.mts.map +1 -0
- package/dist/commands/daemon/{stop.js → stop.mjs} +6 -6
- package/dist/commands/daemon/stop.mjs.map +1 -0
- package/dist/commands/wallet/send.cjs +332 -0
- package/dist/commands/wallet/send.cjs.map +1 -0
- package/dist/commands/wallet/{send.d.ts → send.d.cts} +3 -3
- package/dist/commands/wallet/send.d.cts.map +1 -0
- package/dist/commands/wallet/send.d.mts +42 -0
- package/dist/commands/wallet/send.d.mts.map +1 -0
- package/dist/commands/wallet/{send.js → send.mjs} +9 -9
- package/dist/commands/wallet/send.mjs.map +1 -0
- package/dist/commands/wallet/unlock.cjs +75 -0
- package/dist/commands/wallet/unlock.cjs.map +1 -0
- package/dist/commands/wallet/{unlock.d.ts → unlock.d.cts} +2 -2
- package/dist/commands/wallet/unlock.d.cts.map +1 -0
- package/dist/commands/wallet/unlock.d.mts +11 -0
- package/dist/commands/wallet/unlock.d.mts.map +1 -0
- package/dist/commands/wallet/{unlock.js → unlock.mjs} +7 -7
- package/dist/commands/wallet/unlock.mjs.map +1 -0
- package/dist/daemon/auto-approval.cjs +86 -0
- package/dist/daemon/auto-approval.cjs.map +1 -0
- package/dist/daemon/{auto-approval.d.ts → auto-approval.d.cts} +3 -3
- package/dist/daemon/auto-approval.d.cts.map +1 -0
- package/dist/daemon/auto-approval.d.mts +22 -0
- package/dist/daemon/auto-approval.d.mts.map +1 -0
- package/dist/daemon/{auto-approval.js → auto-approval.mjs} +1 -1
- package/dist/daemon/auto-approval.mjs.map +1 -0
- package/dist/daemon/daemon-client.cjs +149 -0
- package/dist/daemon/daemon-client.cjs.map +1 -0
- package/dist/daemon/{daemon-client.d.ts → daemon-client.d.cts} +2 -2
- package/dist/daemon/daemon-client.d.cts.map +1 -0
- package/dist/daemon/daemon-client.d.mts +84 -0
- package/dist/daemon/daemon-client.d.mts.map +1 -0
- package/dist/daemon/{daemon-client.js → daemon-client.mjs} +6 -6
- package/dist/daemon/daemon-client.mjs.map +1 -0
- package/dist/daemon/daemon-entry.cjs +278 -0
- package/dist/daemon/daemon-entry.cjs.map +1 -0
- package/dist/daemon/daemon-entry.d.cts +2 -0
- package/dist/daemon/daemon-entry.d.cts.map +1 -0
- package/dist/daemon/daemon-entry.d.mts +2 -0
- package/dist/daemon/daemon-entry.d.mts.map +1 -0
- package/dist/daemon/{daemon-entry.js → daemon-entry.mjs} +12 -12
- package/dist/daemon/daemon-entry.mjs.map +1 -0
- package/dist/daemon/daemon-spawn.cjs +138 -0
- package/dist/daemon/daemon-spawn.cjs.map +1 -0
- package/dist/daemon/{daemon-spawn.d.ts → daemon-spawn.d.cts} +2 -2
- 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.js → daemon-spawn.mjs} +7 -7
- package/dist/daemon/daemon-spawn.mjs.map +1 -0
- package/dist/daemon/data-dir.cjs +23 -0
- package/dist/daemon/data-dir.cjs.map +1 -0
- package/dist/daemon/{data-dir.d.ts → data-dir.d.cts} +1 -1
- package/dist/daemon/data-dir.d.cts.map +1 -0
- package/dist/daemon/data-dir.d.mts +14 -0
- package/dist/daemon/data-dir.d.mts.map +1 -0
- package/dist/daemon/{data-dir.js → data-dir.mjs} +3 -3
- package/dist/daemon/data-dir.mjs.map +1 -0
- package/dist/daemon/paths.cjs +20 -0
- package/dist/daemon/paths.cjs.map +1 -0
- package/dist/daemon/{paths.d.ts → paths.d.cts} +2 -2
- package/dist/daemon/paths.d.cts.map +1 -0
- package/dist/daemon/paths.d.mts +9 -0
- package/dist/daemon/paths.d.mts.map +1 -0
- package/dist/daemon/{paths.js → paths.mjs} +2 -2
- package/dist/daemon/paths.mjs.map +1 -0
- package/dist/daemon/prompts.cjs +55 -0
- package/dist/daemon/prompts.cjs.map +1 -0
- package/dist/daemon/{prompts.d.ts → prompts.d.cts} +1 -1
- package/dist/daemon/prompts.d.cts.map +1 -0
- package/dist/daemon/prompts.d.mts +31 -0
- package/dist/daemon/prompts.d.mts.map +1 -0
- package/dist/daemon/{prompts.js → prompts.mjs} +4 -4
- package/dist/daemon/prompts.mjs.map +1 -0
- package/dist/daemon/rpc-socket-server.cjs +284 -0
- package/dist/daemon/rpc-socket-server.cjs.map +1 -0
- package/dist/daemon/{rpc-socket-server.d.ts → rpc-socket-server.d.cts} +2 -2
- 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.js → rpc-socket-server.mjs} +7 -7
- package/dist/daemon/rpc-socket-server.mjs.map +1 -0
- package/dist/daemon/secrets.cjs +137 -0
- package/dist/daemon/secrets.cjs.map +1 -0
- package/dist/daemon/{secrets.d.ts → secrets.d.cts} +1 -1
- package/dist/daemon/secrets.d.cts.map +1 -0
- package/dist/daemon/secrets.d.mts +72 -0
- package/dist/daemon/secrets.d.mts.map +1 -0
- package/dist/daemon/{secrets.js → secrets.mjs} +3 -3
- package/dist/daemon/secrets.mjs.map +1 -0
- package/dist/daemon/send-transaction.cjs +147 -0
- package/dist/daemon/send-transaction.cjs.map +1 -0
- package/dist/daemon/{send-transaction.d.ts → send-transaction.d.cts} +9 -9
- package/dist/daemon/send-transaction.d.cts.map +1 -0
- package/dist/daemon/send-transaction.d.mts +102 -0
- package/dist/daemon/send-transaction.d.mts.map +1 -0
- package/dist/daemon/{send-transaction.js → send-transaction.mjs} +3 -3
- package/dist/daemon/send-transaction.mjs.map +1 -0
- package/dist/daemon/socket-line.cjs +93 -0
- package/dist/daemon/socket-line.cjs.map +1 -0
- package/dist/daemon/{socket-line.d.ts → socket-line.d.cts} +5 -2
- package/dist/daemon/socket-line.d.cts.map +1 -0
- package/dist/daemon/socket-line.d.mts +21 -0
- package/dist/daemon/socket-line.d.mts.map +1 -0
- package/dist/daemon/{socket-line.js → socket-line.mjs} +1 -1
- package/dist/daemon/socket-line.mjs.map +1 -0
- package/dist/daemon/stop-daemon.cjs +117 -0
- package/dist/daemon/stop-daemon.cjs.map +1 -0
- package/dist/daemon/{stop-daemon.d.ts → stop-daemon.d.cts} +1 -1
- package/dist/daemon/stop-daemon.d.cts.map +1 -0
- package/dist/daemon/stop-daemon.d.mts +28 -0
- package/dist/daemon/stop-daemon.d.mts.map +1 -0
- package/dist/daemon/{stop-daemon.js → stop-daemon.mjs} +4 -4
- package/dist/daemon/stop-daemon.mjs.map +1 -0
- package/dist/daemon/types.cjs +20 -0
- package/dist/daemon/types.cjs.map +1 -0
- package/dist/daemon/{types.d.ts → types.d.cts} +4 -4
- package/dist/daemon/types.d.cts.map +1 -0
- package/dist/daemon/types.d.mts +94 -0
- package/dist/daemon/types.d.mts.map +1 -0
- package/dist/daemon/{types.js → types.mjs} +1 -1
- package/dist/daemon/types.mjs.map +1 -0
- package/dist/daemon/utils.cjs +172 -0
- package/dist/daemon/utils.cjs.map +1 -0
- package/dist/daemon/{utils.d.ts → utils.d.cts} +3 -2
- package/dist/daemon/utils.d.cts.map +1 -0
- package/dist/daemon/utils.d.mts +87 -0
- package/dist/daemon/utils.d.mts.map +1 -0
- package/dist/daemon/{utils.js → utils.mjs} +3 -3
- package/dist/daemon/utils.mjs.map +1 -0
- package/dist/daemon/wallet-factory.cjs +341 -0
- package/dist/daemon/wallet-factory.cjs.map +1 -0
- package/dist/daemon/{wallet-factory.d.ts → wallet-factory.d.cts} +4 -4
- package/dist/daemon/wallet-factory.d.cts.map +1 -0
- package/dist/daemon/wallet-factory.d.mts +64 -0
- package/dist/daemon/wallet-factory.d.mts.map +1 -0
- package/dist/daemon/{wallet-factory.js → wallet-factory.mjs} +11 -11
- package/dist/daemon/wallet-factory.mjs.map +1 -0
- package/dist/persistence/KeyValueStore.cjs +79 -0
- package/dist/persistence/KeyValueStore.cjs.map +1 -0
- package/dist/persistence/{KeyValueStore.d.ts → KeyValueStore.d.cts} +2 -2
- package/dist/persistence/KeyValueStore.d.cts.map +1 -0
- package/dist/persistence/KeyValueStore.d.mts +18 -0
- package/dist/persistence/KeyValueStore.d.mts.map +1 -0
- package/dist/persistence/{KeyValueStore.js → KeyValueStore.mjs} +9 -2
- package/dist/persistence/KeyValueStore.mjs.map +1 -0
- package/dist/persistence/persistence.cjs +204 -0
- package/dist/persistence/persistence.cjs.map +1 -0
- package/dist/persistence/{persistence.d.ts → persistence.d.cts} +5 -5
- package/dist/persistence/persistence.d.cts.map +1 -0
- package/dist/persistence/persistence.d.mts +45 -0
- package/dist/persistence/persistence.d.mts.map +1 -0
- package/dist/persistence/{persistence.js → persistence.mjs} +2 -2
- package/dist/persistence/persistence.mjs.map +1 -0
- package/dist/test/run-command.cjs +73 -0
- package/dist/test/run-command.cjs.map +1 -0
- package/dist/test/{run-command.d.ts → run-command.d.cts} +4 -4
- package/dist/test/run-command.d.cts.map +1 -0
- package/dist/test/run-command.d.mts +27 -0
- package/dist/test/run-command.d.mts.map +1 -0
- package/dist/test/{run-command.js → run-command.mjs} +3 -3
- package/dist/test/run-command.mjs.map +1 -0
- package/package.json +8 -12
- package/dist/commands/daemon/call.d.ts.map +0 -1
- package/dist/commands/daemon/call.js.map +0 -1
- package/dist/commands/daemon/list.d.ts.map +0 -1
- package/dist/commands/daemon/list.js.map +0 -1
- package/dist/commands/daemon/purge.d.ts.map +0 -1
- package/dist/commands/daemon/purge.js.map +0 -1
- package/dist/commands/daemon/start.d.ts.map +0 -1
- package/dist/commands/daemon/start.js.map +0 -1
- package/dist/commands/daemon/status.d.ts.map +0 -1
- package/dist/commands/daemon/status.js.map +0 -1
- package/dist/commands/daemon/stop.d.ts.map +0 -1
- package/dist/commands/daemon/stop.js.map +0 -1
- package/dist/commands/wallet/send.d.ts.map +0 -1
- package/dist/commands/wallet/send.js.map +0 -1
- package/dist/commands/wallet/unlock.d.ts.map +0 -1
- package/dist/commands/wallet/unlock.js.map +0 -1
- package/dist/daemon/auto-approval.d.ts.map +0 -1
- package/dist/daemon/auto-approval.js.map +0 -1
- package/dist/daemon/daemon-client.d.ts.map +0 -1
- package/dist/daemon/daemon-client.js.map +0 -1
- package/dist/daemon/daemon-entry.d.ts +0 -2
- package/dist/daemon/daemon-entry.d.ts.map +0 -1
- package/dist/daemon/daemon-entry.js.map +0 -1
- package/dist/daemon/daemon-spawn.d.ts.map +0 -1
- package/dist/daemon/daemon-spawn.js.map +0 -1
- package/dist/daemon/data-dir.d.ts.map +0 -1
- package/dist/daemon/data-dir.js.map +0 -1
- package/dist/daemon/paths.d.ts.map +0 -1
- package/dist/daemon/paths.js.map +0 -1
- package/dist/daemon/prompts.d.ts.map +0 -1
- package/dist/daemon/prompts.js.map +0 -1
- package/dist/daemon/rpc-socket-server.d.ts.map +0 -1
- package/dist/daemon/rpc-socket-server.js.map +0 -1
- package/dist/daemon/secrets.d.ts.map +0 -1
- package/dist/daemon/secrets.js.map +0 -1
- package/dist/daemon/send-transaction.d.ts.map +0 -1
- package/dist/daemon/send-transaction.js.map +0 -1
- package/dist/daemon/socket-line.d.ts.map +0 -1
- package/dist/daemon/socket-line.js.map +0 -1
- package/dist/daemon/stop-daemon.d.ts.map +0 -1
- package/dist/daemon/stop-daemon.js.map +0 -1
- package/dist/daemon/types.d.ts.map +0 -1
- package/dist/daemon/types.js.map +0 -1
- package/dist/daemon/utils.d.ts.map +0 -1
- package/dist/daemon/utils.js.map +0 -1
- package/dist/daemon/wallet-factory.d.ts.map +0 -1
- package/dist/daemon/wallet-factory.js.map +0 -1
- package/dist/persistence/KeyValueStore.d.ts.map +0 -1
- package/dist/persistence/KeyValueStore.js.map +0 -1
- package/dist/persistence/persistence.d.ts.map +0 -1
- package/dist/persistence/persistence.js.map +0 -1
- package/dist/test/run-command.d.ts.map +0 -1
- package/dist/test/run-command.js.map +0 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runCommand = void 0;
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const errors_1 = require("@oclif/core/errors");
|
|
6
|
+
const TEST_DATA_DIR = '/tmp/mm-cli-test-data';
|
|
7
|
+
const TEST_PACKAGE_ROOT = '/tmp/mm-cli-test-root';
|
|
8
|
+
/**
|
|
9
|
+
* Invoke an oclif command class with the given argv and return the captured
|
|
10
|
+
* stdout/stderr/error so tests can assert on them.
|
|
11
|
+
*
|
|
12
|
+
* Bypasses `Command.run`'s static plugin-loading path (which requires a real
|
|
13
|
+
* `Config.load`) by constructing the command instance directly with a
|
|
14
|
+
* hand-rolled `Config` and invoking the protected `_run`. Spies on the
|
|
15
|
+
* Command prototype so `this.log` and `this.error` go to local buffers
|
|
16
|
+
* instead of stdout/stderr.
|
|
17
|
+
*
|
|
18
|
+
* @param CommandClass - The command class (a subclass of `@oclif/core` Command).
|
|
19
|
+
* @param argv - Command-line tokens (flags + positional args).
|
|
20
|
+
* @returns Captured stdout, stderr, and any `this.error()` payload.
|
|
21
|
+
*/
|
|
22
|
+
async function runCommand(CommandClass, argv = []) {
|
|
23
|
+
let stdout = '';
|
|
24
|
+
let stderr = '';
|
|
25
|
+
let error;
|
|
26
|
+
const fakeConfig = {
|
|
27
|
+
dataDir: TEST_DATA_DIR,
|
|
28
|
+
root: TEST_PACKAGE_ROOT,
|
|
29
|
+
bin: 'mm',
|
|
30
|
+
name: '@metamask/wallet-cli',
|
|
31
|
+
version: '0.0.0-test',
|
|
32
|
+
pjson: { name: '@metamask/wallet-cli', version: '0.0.0-test' },
|
|
33
|
+
findCommand: () => undefined,
|
|
34
|
+
runHook: async () => ({ successes: [], failures: [] }),
|
|
35
|
+
scopedEnvVar: () => undefined,
|
|
36
|
+
scopedEnvVarKey: () => '',
|
|
37
|
+
scopedEnvVarKeys: () => [],
|
|
38
|
+
scopedEnvVarTrue: () => false,
|
|
39
|
+
plugins: new Map(),
|
|
40
|
+
flexibleTaxonomy: false,
|
|
41
|
+
};
|
|
42
|
+
const logSpy = jest
|
|
43
|
+
.spyOn(core_1.Command.prototype, 'log')
|
|
44
|
+
.mockImplementation((message = '') => {
|
|
45
|
+
stdout += `${String(message)}\n`;
|
|
46
|
+
});
|
|
47
|
+
const errorSpy = jest
|
|
48
|
+
.spyOn(core_1.Command.prototype, 'error')
|
|
49
|
+
.mockImplementation((input) => {
|
|
50
|
+
const message = typeof input === 'string' ? input : input.message;
|
|
51
|
+
throw new errors_1.CLIError(message);
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
const instance = new CommandClass(argv, fakeConfig);
|
|
55
|
+
await instance._run();
|
|
56
|
+
}
|
|
57
|
+
catch (caught) {
|
|
58
|
+
if (caught instanceof errors_1.CLIError) {
|
|
59
|
+
error = caught;
|
|
60
|
+
stderr += `${caught.message}\n`;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw caught;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
logSpy.mockRestore();
|
|
68
|
+
errorSpy.mockRestore();
|
|
69
|
+
}
|
|
70
|
+
return { stdout, stderr, error };
|
|
71
|
+
}
|
|
72
|
+
exports.runCommand = runCommand;
|
|
73
|
+
//# sourceMappingURL=run-command.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-command.cjs","sour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K,CAAC,cAAO,CAAC,SAAS,EAAE,OAAO,CAAC;SACjC,kBAAkB,CAAC,CAAC,KAAqB,EAAE,EAAE;QAC5C,MAAM,OAAO,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;QAClE,MAAM,IAAI,iBAAQ,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEL,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACpD,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;IAAC,OAAO,MAAe,EAAE,CAAC;QACzB,IAAI,MAAM,YAAY,iBAAQ,EAAE,CAAC;YAC/B,KAAK,GAAG,MAAM,CAAC;YACf,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,IAAI,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,MAAM,MAAM,CAAC;QACf,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,WAAW,EAAE,CAAC;QACrB,QAAQ,CAAC,WAAW,EAAE,CAAC;IACzB,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACnC,CAAC;AAzDD,gCAyDC","sourcesContent":["import { Command } from '@oclif/core';\nimport type { Config } from '@oclif/core';\nimport { CLIError } from '@oclif/core/errors';\n\ntype CommandCtor = new (\n argv: string[],\n config: Config,\n) => Command & {\n _run: () => Promise<unknown>;\n};\n\nconst TEST_DATA_DIR = '/tmp/mm-cli-test-data';\nconst TEST_PACKAGE_ROOT = '/tmp/mm-cli-test-root';\n\n/**\n * Invoke an oclif command class with the given argv and return the captured\n * stdout/stderr/error so tests can assert on them.\n *\n * Bypasses `Command.run`'s static plugin-loading path (which requires a real\n * `Config.load`) by constructing the command instance directly with a\n * hand-rolled `Config` and invoking the protected `_run`. Spies on the\n * Command prototype so `this.log` and `this.error` go to local buffers\n * instead of stdout/stderr.\n *\n * @param CommandClass - The command class (a subclass of `@oclif/core` Command).\n * @param argv - Command-line tokens (flags + positional args).\n * @returns Captured stdout, stderr, and any `this.error()` payload.\n */\nexport async function runCommand(\n CommandClass: CommandCtor,\n argv: string[] = [],\n): Promise<{\n stdout: string;\n stderr: string;\n error: CLIError | undefined;\n}> {\n let stdout = '';\n let stderr = '';\n let error: CLIError | undefined;\n\n const fakeConfig = {\n dataDir: TEST_DATA_DIR,\n root: TEST_PACKAGE_ROOT,\n bin: 'mm',\n name: '@metamask/wallet-cli',\n version: '0.0.0-test',\n pjson: { name: '@metamask/wallet-cli', version: '0.0.0-test' },\n findCommand: () => undefined,\n runHook: async () => ({ successes: [], failures: [] }),\n scopedEnvVar: () => undefined,\n scopedEnvVarKey: () => '',\n scopedEnvVarKeys: () => [],\n scopedEnvVarTrue: () => false,\n plugins: new Map(),\n flexibleTaxonomy: false,\n } as unknown as Config;\n\n const logSpy = jest\n .spyOn(Command.prototype, 'log')\n .mockImplementation((message: unknown = '') => {\n stdout += `${String(message)}\\n`;\n });\n const errorSpy = jest\n .spyOn(Command.prototype, 'error')\n .mockImplementation((input: string | Error) => {\n const message = typeof input === 'string' ? input : input.message;\n throw new CLIError(message);\n });\n\n try {\n const instance = new CommandClass(argv, fakeConfig);\n await instance._run();\n } catch (caught: unknown) {\n if (caught instanceof CLIError) {\n error = caught;\n stderr += `${caught.message}\\n`;\n } else {\n throw caught;\n }\n } finally {\n logSpy.mockRestore();\n errorSpy.mockRestore();\n }\n\n return { stdout, stderr, error };\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Command } from
|
|
2
|
-
import type { Config } from
|
|
3
|
-
import { CLIError } from
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
import type { Config } from "@oclif/core";
|
|
3
|
+
import { CLIError } from "@oclif/core/errors";
|
|
4
4
|
type CommandCtor = new (argv: string[], config: Config) => Command & {
|
|
5
5
|
_run: () => Promise<unknown>;
|
|
6
6
|
};
|
|
@@ -24,4 +24,4 @@ export declare function runCommand(CommandClass: CommandCtor, argv?: string[]):
|
|
|
24
24
|
error: CLIError | undefined;
|
|
25
25
|
}>;
|
|
26
26
|
export {};
|
|
27
|
-
//# sourceMappingURL=run-command.d.
|
|
27
|
+
//# sourceMappingURL=run-command.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-command.d.cts","sourceRoot":"","sources":["../../src/test/run-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB;AACtC,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAoB;AAC1C,OAAO,EAAE,QAAQ,EAAE,2BAA2B;AAE9C,KAAK,WAAW,GAAG,KACjB,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,MAAM,KACX,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9B,CAAC;AAKF;;;;;;;;;;;;;GAaG;AACH,wBAAsB,UAAU,CAC9B,YAAY,EAAE,WAAW,EACzB,IAAI,GAAE,MAAM,EAAO,GAClB,OAAO,CAAC;IACT,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAC;CAC7B,CAAC,CAkDD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
import type { Config } from "@oclif/core";
|
|
3
|
+
import { CLIError } from "@oclif/core/errors";
|
|
4
|
+
type CommandCtor = new (argv: string[], config: Config) => Command & {
|
|
5
|
+
_run: () => Promise<unknown>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Invoke an oclif command class with the given argv and return the captured
|
|
9
|
+
* stdout/stderr/error so tests can assert on them.
|
|
10
|
+
*
|
|
11
|
+
* Bypasses `Command.run`'s static plugin-loading path (which requires a real
|
|
12
|
+
* `Config.load`) by constructing the command instance directly with a
|
|
13
|
+
* hand-rolled `Config` and invoking the protected `_run`. Spies on the
|
|
14
|
+
* Command prototype so `this.log` and `this.error` go to local buffers
|
|
15
|
+
* instead of stdout/stderr.
|
|
16
|
+
*
|
|
17
|
+
* @param CommandClass - The command class (a subclass of `@oclif/core` Command).
|
|
18
|
+
* @param argv - Command-line tokens (flags + positional args).
|
|
19
|
+
* @returns Captured stdout, stderr, and any `this.error()` payload.
|
|
20
|
+
*/
|
|
21
|
+
export declare function runCommand(CommandClass: CommandCtor, argv?: string[]): Promise<{
|
|
22
|
+
stdout: string;
|
|
23
|
+
stderr: string;
|
|
24
|
+
error: CLIError | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=run-command.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-command.d.mts","sourceRoot":"","sources":["../../src/test/run-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB;AACtC,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAoB;AAC1C,OAAO,EAAE,QAAQ,EAAE,2BAA2B;AAE9C,KAAK,WAAW,GAAG,KACjB,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,MAAM,KACX,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9B,CAAC;AAKF;;;;;;;;;;;;;GAaG;AACH,wBAAsB,UAAU,CAC9B,YAAY,EAAE,WAAW,EACzB,IAAI,GAAE,MAAM,EAAO,GAClB,OAAO,CAAC;IACT,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAC;CAC7B,CAAC,CAkDD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Command } from
|
|
2
|
-
import { CLIError } from
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
import { CLIError } from "@oclif/core/errors";
|
|
3
3
|
const TEST_DATA_DIR = '/tmp/mm-cli-test-data';
|
|
4
4
|
const TEST_PACKAGE_ROOT = '/tmp/mm-cli-test-root';
|
|
5
5
|
/**
|
|
@@ -66,4 +66,4 @@ export async function runCommand(CommandClass, argv = []) {
|
|
|
66
66
|
}
|
|
67
67
|
return { stdout, stderr, error };
|
|
68
68
|
}
|
|
69
|
-
//# sourceMappingURL=run-command.
|
|
69
|
+
//# sourceMappingURL=run-command.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-command.mjs","sourceRoot":"","sources":["../../src/test/run-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB;AAEtC,OAAO,EAAE,QAAQ,EAAE,2BAA2B;AAS9C,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAC9C,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAElD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,YAAyB,EACzB,OAAiB,EAAE;IAMnB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,KAA2B,CAAC;IAEhC,MAAM,UAAU,GAAG;QACjB,OAAO,EAAE,aAAa;QACtB,IAAI,EAAE,iBAAiB;QACvB,GAAG,EAAE,IAAI;QACT,IAAI,EAAE,sBAAsB;QAC5B,OAAO,EAAE,YAAY;QACrB,KAAK,EAAE,EAAE,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,YAAY,EAAE;QAC9D,WAAW,EAAE,GAAG,EAAE,CAAC,SAAS;QAC5B,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QACtD,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS;QAC7B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MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { Command } from '@oclif/core';\nimport type { Config } from '@oclif/core';\nimport { CLIError } from '@oclif/core/errors';\n\ntype CommandCtor = new (\n argv: string[],\n config: Config,\n) => Command & {\n _run: () => Promise<unknown>;\n};\n\nconst TEST_DATA_DIR = '/tmp/mm-cli-test-data';\nconst TEST_PACKAGE_ROOT = '/tmp/mm-cli-test-root';\n\n/**\n * Invoke an oclif command class with the given argv and return the captured\n * stdout/stderr/error so tests can assert on them.\n *\n * Bypasses `Command.run`'s static plugin-loading path (which requires a real\n * `Config.load`) by constructing the command instance directly with a\n * hand-rolled `Config` and invoking the protected `_run`. Spies on the\n * Command prototype so `this.log` and `this.error` go to local buffers\n * instead of stdout/stderr.\n *\n * @param CommandClass - The command class (a subclass of `@oclif/core` Command).\n * @param argv - Command-line tokens (flags + positional args).\n * @returns Captured stdout, stderr, and any `this.error()` payload.\n */\nexport async function runCommand(\n CommandClass: CommandCtor,\n argv: string[] = [],\n): Promise<{\n stdout: string;\n stderr: string;\n error: CLIError | undefined;\n}> {\n let stdout = '';\n let stderr = '';\n let error: CLIError | undefined;\n\n const fakeConfig = {\n dataDir: TEST_DATA_DIR,\n root: TEST_PACKAGE_ROOT,\n bin: 'mm',\n name: '@metamask/wallet-cli',\n version: '0.0.0-test',\n pjson: { name: '@metamask/wallet-cli', version: '0.0.0-test' },\n findCommand: () => undefined,\n runHook: async () => ({ successes: [], failures: [] }),\n scopedEnvVar: () => undefined,\n scopedEnvVarKey: () => '',\n scopedEnvVarKeys: () => [],\n scopedEnvVarTrue: () => false,\n plugins: new Map(),\n flexibleTaxonomy: false,\n } as unknown as Config;\n\n const logSpy = jest\n .spyOn(Command.prototype, 'log')\n .mockImplementation((message: unknown = '') => {\n stdout += `${String(message)}\\n`;\n });\n const errorSpy = jest\n .spyOn(Command.prototype, 'error')\n .mockImplementation((input: string | Error) => {\n const message = typeof input === 'string' ? input : input.message;\n throw new CLIError(message);\n });\n\n try {\n const instance = new CommandClass(argv, fakeConfig);\n await instance._run();\n } catch (caught: unknown) {\n if (caught instanceof CLIError) {\n error = caught;\n stderr += `${caught.message}\\n`;\n } else {\n throw caught;\n }\n } finally {\n logSpy.mockRestore();\n errorSpy.mockRestore();\n }\n\n return { stdout, stderr, error };\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-eb263b0ee",
|
|
4
4
|
"description": "The CLI of @metamask/wallet",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"bin/",
|
|
23
23
|
"dist/"
|
|
24
24
|
],
|
|
25
|
-
"type": "module",
|
|
26
25
|
"sideEffects": false,
|
|
27
26
|
"exports": {
|
|
28
27
|
"./package.json": "./package.json"
|
|
@@ -32,10 +31,8 @@
|
|
|
32
31
|
"registry": "https://registry.npmjs.org/"
|
|
33
32
|
},
|
|
34
33
|
"scripts": {
|
|
35
|
-
"build": "
|
|
36
|
-
"build:all": "
|
|
37
|
-
"build:clean": "yarn build:only-clean && yarn build",
|
|
38
|
-
"build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
|
|
34
|
+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
35
|
+
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
|
|
39
36
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/wallet-cli",
|
|
40
37
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/wallet-cli",
|
|
41
38
|
"lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
|
|
@@ -43,7 +40,7 @@
|
|
|
43
40
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
44
41
|
"test": "yarn test:prepare && NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
45
42
|
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
46
|
-
"test:e2e": "yarn test:prepare && NODE_OPTIONS=--experimental-vm-modules jest --config jest.config.e2e.
|
|
43
|
+
"test:e2e": "yarn test:prepare && NODE_OPTIONS=--experimental-vm-modules jest --config jest.config.e2e.js",
|
|
47
44
|
"test:e2e:install-anvil": "mm-foundryup",
|
|
48
45
|
"test:prepare": "./scripts/install-binaries.sh",
|
|
49
46
|
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
|
@@ -56,7 +53,7 @@
|
|
|
56
53
|
"@metamask/base-controller": "^9.1.0",
|
|
57
54
|
"@metamask/config-registry-controller": "^3.1.0",
|
|
58
55
|
"@metamask/messenger": "^2.0.0",
|
|
59
|
-
"@metamask/remote-feature-flag-controller": "^6.
|
|
56
|
+
"@metamask/remote-feature-flag-controller": "^6.0.0",
|
|
60
57
|
"@metamask/rpc-errors": "^7.0.2",
|
|
61
58
|
"@metamask/scure-bip39": "^2.1.1",
|
|
62
59
|
"@metamask/storage-service": "^1.0.2",
|
|
@@ -70,17 +67,16 @@
|
|
|
70
67
|
"devDependencies": {
|
|
71
68
|
"@metamask/auto-changelog": "^6.1.0",
|
|
72
69
|
"@metamask/foundryup": "^1.0.1",
|
|
70
|
+
"@ts-bridge/cli": "^0.6.4",
|
|
73
71
|
"@types/better-sqlite3": "^7.6.13",
|
|
74
72
|
"@types/jest": "^30.0.0",
|
|
75
|
-
"@typescript/native": "npm:typescript@^7.0.2",
|
|
76
73
|
"deepmerge": "^4.2.2",
|
|
77
74
|
"jest": "^30.4.2",
|
|
78
75
|
"jest-environment-node": "^30.4.1",
|
|
79
76
|
"nock": "^13.3.1",
|
|
80
|
-
"rimraf": "^5.0.5",
|
|
81
77
|
"ts-jest": "^29.4.11",
|
|
82
78
|
"tsx": "^4.20.5",
|
|
83
|
-
"typescript": "
|
|
79
|
+
"typescript": "~5.3.3"
|
|
84
80
|
},
|
|
85
81
|
"oclif": {
|
|
86
82
|
"bin": "mm",
|
|
@@ -89,6 +85,6 @@
|
|
|
89
85
|
"topicSeparator": " "
|
|
90
86
|
},
|
|
91
87
|
"engines": {
|
|
92
|
-
"node": "
|
|
88
|
+
"node": ">=20"
|
|
93
89
|
}
|
|
94
90
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"call.d.ts","sourceRoot":"","sources":["../../../src/commands/daemon/call.ts"],"names":[],"mappings":"AAEA,OAAO,EAAQ,OAAO,EAAS,MAAM,aAAa,CAAC;AASnD,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,OAAO;IAC7C,OAAgB,WAAW,SAAkD;IAE7E,OAAgB,QAAQ,WAItB;IAEF,OAAgB,IAAI;QAClB,MAAM;QAKN,MAAM;MAIN;IAEF,OAAgB,KAAK;QACnB,OAAO;MAKP;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAgDhC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../../src/commands/daemon/call.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EACL,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAE/B,MAAqB,UAAW,SAAQ,OAAO;IA6BtC,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACrD,MAAM,EAAE,MAAM,EAAE,GAAG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AAC;QAED,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC;QAC5C,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;CACF;AA7EiB,sBAAW,GAAG,8CAA8C,CAAC;AAE7D,mBAAQ,GAAG;IACzB,0DAA0D;IAC1D,0DAA0D;IAC1D,2EAA2E;CAC5E,CAAC;AAEc,eAAI,GAAG;IACrB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;QAClB,WAAW,EACT,6DAA6D;QAC/D,QAAQ,EAAE,IAAI;KACf,CAAC;IACF,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;QAClB,WAAW,EAAE,0DAA0D;QACvE,QAAQ,EAAE,KAAK;KAChB,CAAC;CACH,CAAC;AAEc,gBAAK,GAAG;IACtB,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;QACrB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,kCAAkC;QAC/C,QAAQ,EAAE,KAAK;KAChB,CAAC;CACH,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { isJsonRpcFailure } from '@metamask/utils';\nimport { Args, Command, Flags } from '@oclif/core';\n\nimport { sendCommand } from '../../daemon/daemon-client.js';\nimport { getDaemonPaths } from '../../daemon/paths.js';\nimport {\n formatJsonRpcError,\n makeDaemonConnectionError,\n} from '../../daemon/utils.js';\n\nexport default class DaemonCall extends Command {\n static override description = 'Call a messenger action on the wallet daemon';\n\n static override examples = [\n '<%= config.bin %> daemon call KeyringController:getState',\n '<%= config.bin %> daemon call NetworkController:getState',\n '<%= config.bin %> daemon call ApprovalController:getState --timeout 10000',\n ];\n\n static override args = {\n action: Args.string({\n description:\n 'The messenger action name (e.g. KeyringController:getState)',\n required: true,\n }),\n params: Args.string({\n description: 'JSON-encoded arguments array (e.g. \\'[\"arg1\", \"arg2\"]\\')',\n required: false,\n }),\n };\n\n static override flags = {\n timeout: Flags.integer({\n char: 't',\n description: 'Response timeout in milliseconds',\n required: false,\n }),\n };\n\n public async run(): Promise<void> {\n const { args, flags } = await this.parse(DaemonCall);\n const { action } = args;\n const timeoutMs = flags.timeout;\n\n // The daemon's `call` RPC expects `[action, ...args]`. `JSON.parse` returns\n // `unknown`, but anything it produces is structurally `Json`, so we cast to\n // `Json[]` once we've confirmed the parsed payload is an array.\n const rpcParams: Json[] = [action];\n if (args.params !== undefined) {\n let parsed: unknown;\n try {\n parsed = JSON.parse(args.params);\n } catch {\n this.error('params must be valid JSON');\n }\n\n if (!Array.isArray(parsed)) {\n this.error('params must be a JSON array');\n }\n\n rpcParams.push(...(parsed as Json[]));\n }\n\n const { socketPath } = getDaemonPaths(this.config.dataDir);\n\n let response;\n try {\n response = await sendCommand({\n socketPath,\n method: 'call',\n params: rpcParams,\n ...(timeoutMs === undefined ? {} : { timeoutMs }),\n });\n } catch (error) {\n this.error(makeDaemonConnectionError(error));\n }\n\n if (isJsonRpcFailure(response)) {\n this.error(formatJsonRpcError(response.error));\n }\n\n const isTTY = process.stdout.isTTY ?? false;\n if (isTTY) {\n this.log(JSON.stringify(response.result, null, 2));\n } else {\n process.stdout.write(`${JSON.stringify(response.result)}\\n`);\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/commands/daemon/list.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAUtC,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,OAAO;IAC7C,OAAgB,WAAW,SACsD;I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AAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;QAE5C,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC;QAC5C,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,qDAAqD;YACrD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACvB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClD,CAAC;YACD,OAAO;QACT,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;YAC3D,OAAO;QACT,CAAC;QAED,IAAI,CAAC,GAAG,CACN,GAAG,OAAO,CAAC,MAAM,mBAAmB,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG;YACpE,4CAA4C,CAC/C,CAAC;QACF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;CACF;AAhDiB,sBAAW,GACzB,8EAA8E,CAAC;AAEjE,mBAAQ,GAAG,CAAC,+BAA+B,CAAC,CAAC","sourcesContent":["import { isJsonRpcFailure } from '@metamask/utils';\nimport { Command } from '@oclif/core';\n\nimport { sendCommand } from '../../daemon/daemon-client.js';\nimport { getDaemonPaths } from '../../daemon/paths.js';\nimport {\n formatJsonRpcError,\n isStringArray,\n makeDaemonConnectionError,\n} from '../../daemon/utils.js';\n\nexport default class DaemonList extends Command {\n static override description =\n 'List the messenger actions the running daemon can dispatch via `daemon call`';\n\n static override examples = ['<%= config.bin %> daemon list'];\n\n public async run(): Promise<void> {\n await this.parse(DaemonList);\n const { socketPath } = getDaemonPaths(this.config.dataDir);\n\n let response;\n try {\n response = await sendCommand({ socketPath, method: 'listActions' });\n } catch (error) {\n this.error(makeDaemonConnectionError(error));\n }\n\n if (isJsonRpcFailure(response)) {\n this.error(formatJsonRpcError(response.error));\n }\n\n if (!isStringArray(response.result)) {\n this.error('Daemon returned an unexpected action list.');\n }\n\n const actions = [...response.result].sort();\n\n const isTTY = process.stdout.isTTY ?? false;\n if (!isTTY) {\n // Bare output so it pipes cleanly into `grep`/`fzf`.\n if (actions.length > 0) {\n process.stdout.write(`${actions.join('\\n')}\\n`);\n }\n return;\n }\n\n if (actions.length === 0) {\n this.log('The daemon has no callable actions registered.');\n return;\n }\n\n this.log(\n `${actions.length} callable action${actions.length === 1 ? '' : 's'} ` +\n '(dispatch with `mm daemon call <action>`):',\n );\n for (const action of actions) {\n this.log(` ${action}`);\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"purge.d.ts","sourceRoot":"","sources":["../../../src/commands/daemon/purge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAC;AAQ7C,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,OAAO;IAC9C,OAAgB,WAAW,SAC2B;IAEtD,OAAgB,QAAQ,WAGtB;IAEF,OAAgB,KAAK;QACnB,KAAK;MAIL;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAkDhC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"purge.js","sourceRoot":"","sources":["../../../src/commands/daemon/purge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,O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AAC,MAAM,MAAM;YACrB,GAAG,KAAK,CAAC,MAAM,MAAM;SACtB,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CACjD,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;IACxC,CAAC;CACF;AAlEiB,uBAAW,GACzB,mDAAmD,CAAC;AAEtC,oBAAQ,GAAG;IACzB,gCAAgC;IAChC,wCAAwC;CACzC,CAAC;AAEc,iBAAK,GAAG;IACtB,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC;QACnB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,0BAA0B;KACxC,CAAC;CACH,CAAC","sourcesContent":["import { Command, Flags } from '@oclif/core';\nimport { rm } from 'node:fs/promises';\n\nimport { pingDaemon } from '../../daemon/daemon-client.js';\nimport { getDaemonPaths } from '../../daemon/paths.js';\nimport { confirmPurge } from '../../daemon/prompts.js';\nimport { stopDaemon } from '../../daemon/stop-daemon.js';\n\nexport default class DaemonPurge extends Command {\n static override description =\n 'Stop the daemon and delete all daemon state files';\n\n static override examples = [\n '<%= config.bin %> daemon purge',\n '<%= config.bin %> daemon purge --force',\n ];\n\n static override flags = {\n force: Flags.boolean({\n char: 'f',\n description: 'Skip confirmation prompt',\n }),\n };\n\n public async run(): Promise<void> {\n const { flags } = await this.parse(DaemonPurge);\n\n if (!flags.force) {\n const confirmed = await confirmPurge();\n if (!confirmed) {\n this.log('Aborted.');\n return;\n }\n }\n\n const paths = getDaemonPaths(this.config.dataDir);\n\n const stopped = await stopDaemon(\n paths.socketPath,\n paths.pidPath,\n (message) => this.log(message),\n );\n\n if (!stopped) {\n // Purge is the escape hatch for a daemon that wouldn't shut down cleanly,\n // so proceed once we've confirmed it isn't responsive — deleting state\n // out from under a live daemon would risk corrupting it.\n const ping = await pingDaemon(paths.socketPath);\n if (ping.status === 'responsive') {\n this.error(\n 'Refusing to delete state while the daemon is still responsive.',\n );\n }\n this.log(\n 'Could not confirm clean shutdown; proceeding to delete state anyway.',\n );\n }\n\n // Whitelist only the daemon-owned files rather than rm'ing the entire\n // oclif dataDir, which may hold unrelated state (caches, oclif lock\n // files, future config). `force: true` makes ENOENT a no-op for any\n // file already removed by stopDaemon.\n await Promise.all(\n [\n paths.pidPath,\n paths.socketPath,\n paths.logPath,\n paths.dbPath,\n `${paths.dbPath}-wal`,\n `${paths.dbPath}-shm`,\n ].map(async (path) => rm(path, { force: true })),\n );\n\n this.log('All daemon state deleted.');\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../../src/commands/daemon/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAC;AAK7C,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,OAAO;IAC9C,OAAgB,WAAW,SAA6B;IAExD,OAAgB,QAAQ,WAItB;IAEF,OAAgB,KAAK;QACnB,mBAAmB;QAKnB,QAAQ;QAOR,GAAG;MAMH;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAuBhC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../src/commands/daemon/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAExD,MAAqB,WAAY,SAAQ,OAAO;IA8BvC,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAChD,MAAM,eAAe,GAAG,KAAK,CAAC,mBAAmB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Content":["import { Command, Flags } from '@oclif/core';\n\nimport { ensureDaemon } from '../../daemon/daemon-spawn.js';\nimport { Password, Srp } from '../../daemon/secrets.js';\n\nexport default class DaemonStart extends Command {\n static override description = 'Start the wallet daemon';\n\n static override examples = [\n '<%= config.bin %> daemon start --infura-project-id <key> --password <pw> --srp <phrase>',\n 'INFURA_PROJECT_ID=<key> MM_WALLET_PASSWORD=<pw> MM_WALLET_SRP=<phrase> <%= config.bin %> daemon start',\n '<%= config.bin %> daemon start --infura-project-id <key> --srp <phrase> # then `mm wallet unlock` later',\n ];\n\n static override flags = {\n 'infura-project-id': Flags.string({\n description: 'Infura project ID for network access',\n env: 'INFURA_PROJECT_ID',\n required: true,\n }),\n password: Flags.string({\n description:\n 'Wallet password (testing only — use MM_WALLET_PASSWORD env var in production). ' +\n 'Required on first run; on subsequent runs, omit (and leave MM_WALLET_PASSWORD unset) to start with a locked keyring and use `mm wallet unlock`.',\n env: 'MM_WALLET_PASSWORD',\n required: false,\n }),\n srp: Flags.string({\n description:\n 'Secret recovery phrase (testing only — use MM_WALLET_SRP env var in production)',\n env: 'MM_WALLET_SRP',\n required: true,\n }),\n };\n\n public async run(): Promise<void> {\n const { flags } = await this.parse(DaemonStart);\n const infuraProjectId = flags['infura-project-id'];\n const password = flags.password ? Password.from(flags.password) : undefined;\n const srp = Srp.from(flags.srp);\n\n const { state, socketPath } = await ensureDaemon({\n dataDir: this.config.dataDir,\n infuraProjectId,\n password,\n srp,\n packageRoot: this.config.root,\n });\n\n if (state === 'already-running') {\n this.log(\n `Daemon already running. Socket: ${socketPath}. ` +\n `The provided flags were not applied; run \\`mm daemon stop\\` and start again to change them.`,\n );\n return;\n }\n\n this.log(`Daemon running. Socket: ${socketPath}`);\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../src/commands/daemon/status.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,aAA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,uCAAuC,CAAC;AAEtD,qBAAQ,GAAG,CAAC,iCAAiC,CAAC,CAAC","sourcesContent":["import { isJsonRpcFailure } from '@metamask/utils';\nimport { Command } from '@oclif/core';\n\nimport { pingDaemon, sendCommand } from '../../daemon/daemon-client.js';\nimport { getDaemonPaths } from '../../daemon/paths.js';\nimport type { DaemonStatusInfo } from '../../daemon/types.js';\nimport { isProcessAlive, readPidFile } from '../../daemon/utils.js';\n\nexport default class DaemonStatus extends Command {\n static override description = 'Check the status of the wallet daemon';\n\n static override examples = ['<%= config.bin %> daemon status'];\n\n public async run(): Promise<void> {\n const { socketPath, pidPath } = getDaemonPaths(this.config.dataDir);\n\n const pid = await readPidFile(pidPath);\n const ping = await pingDaemon(socketPath);\n\n if (ping.status === 'absent') {\n // A missing socket alone does not prove the daemon is gone: stopDaemon\n // treats an absent socket plus an alive recorded PID as a daemon that\n // outlived its socket. Surface that orphan here rather than reporting a\n // clean \"not running\".\n if (pid !== undefined && isProcessAlive(pid)) {\n this.log(\n `Daemon socket is missing at ${socketPath} but recorded PID ${pid} is still alive. ` +\n `The daemon may be running without its socket; run \\`mm daemon stop\\` or \\`mm daemon purge\\`.`,\n );\n return;\n }\n this.log('Daemon is not running.');\n return;\n }\n\n if (ping.status === 'unreachable') {\n const pidPart = pid === undefined ? '' : ` (recorded PID: ${pid})`;\n this.log(\n `Daemon socket exists at ${socketPath} but is unresponsive${pidPart} ` +\n `[${ping.reason}]: ${ping.error.message}`,\n );\n return;\n }\n\n let response;\n try {\n response = await sendCommand({\n socketPath,\n method: 'getStatus',\n timeoutMs: 5_000,\n });\n } catch (error) {\n this.log(\n `Daemon socket is responsive but status request failed: ${error instanceof Error ? error.message : String(error)}`,\n );\n return;\n }\n\n if (isJsonRpcFailure(response)) {\n this.log(\n `Daemon is running but returned an error: ${response.error.message}`,\n );\n return;\n }\n\n const status = response.result as DaemonStatusInfo;\n if (pid !== undefined && pid !== status.pid) {\n this.log(\n `Warning: PID file records ${pid} but the running daemon reports ${status.pid}. ` +\n `Local state may be stale; consider \\`mm daemon purge\\`.`,\n );\n }\n this.log(\n `Daemon is running. PID: ${status.pid}, Uptime: ${status.uptime}s`,\n );\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stop.d.ts","sourceRoot":"","sources":["../../../src/commands/daemon/stop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAOtC,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,OAAO;IAC7C,OAAgB,WAAW,SAA4B;IAEvD,OAAgB,QAAQ,WAAqC;IAEhD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAiBhC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stop.js","sourceRoot":"","sources":["../../../src/commands/daemon/stop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,MAAqB,UAAW,SAAQ,OAAO;IAKtC,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAEpE,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,CAAC;QAC1C,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;QACvC,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YAClD,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;YACnC,OAAO;QACT,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CAChE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAClB,CAAC;QAEF,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,IAAI,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;CACF;AAtBiB,sBAAW,GAAG,wBAAwB,CAAC;AAEvC,mBAAQ,GAAG,CAAC,+BAA+B,CAAC,CAAC","sourcesContent":["import { Command } from '@oclif/core';\n\nimport { pingDaemon } from '../../daemon/daemon-client.js';\nimport { getDaemonPaths } from '../../daemon/paths.js';\nimport { stopDaemon } from '../../daemon/stop-daemon.js';\nimport { readPidFile } from '../../daemon/utils.js';\n\nexport default class DaemonStop extends Command {\n static override description = 'Stop the wallet daemon';\n\n static override examples = ['<%= config.bin %> daemon stop'];\n\n public async run(): Promise<void> {\n const { socketPath, pidPath } = getDaemonPaths(this.config.dataDir);\n\n const ping = await pingDaemon(socketPath);\n const pid = await readPidFile(pidPath);\n if (ping.status === 'absent' && pid === undefined) {\n this.log('Daemon is not running.');\n return;\n }\n\n const stopped = await stopDaemon(socketPath, pidPath, (message) =>\n this.log(message),\n );\n\n if (!stopped) {\n this.error('Daemon did not stop within timeout.');\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../../src/commands/wallet/send.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAuB,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAC;AAwC7C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAetD;AAED,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,OAAO;;IAC7C,OAAgB,WA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C;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,UAAU,CACjB,IAAiC,EACjC,WAAmB,EACnB,MAAkB;IAElB,MAAM,KAAK,GAAG;QACZ,gBAAgB;QAChB,cAAc,IAAI,CAAC,EAAE,EAAE;QACvB,cAAc,IAAI,CAAC,IAAI,EAAE;QACzB,cAAc,WAAW,SAAS,IAAI,CAAC,KAAK,OAAO;QACnD,cAAc,IAAI,CAAC,eAAe,EAAE;KACrC,CAAC;IACF,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,cAAc,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1C,CAAC;IACD,MAAM,QAAQ,GAAG;QACf,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS;QAC5C,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,gBAAgB,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS;QACvE,MAAM,CAAC,oBAAoB;YACzB,CAAC,CAAC,wBAAwB,MAAM,CAAC,oBAAoB,EAAE;YACvD,CAAC,CAAC,SAAS;QACb,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS;KAC5D,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IACvD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,KAAK,CAAC,IAAI,CAAC,cAAc,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import { is } from '@metamask/superstruct';\nimport type { Struct } from '@metamask/superstruct';\nimport { bigIntToHex, isJsonRpcFailure, toWei } from '@metamask/utils';\nimport type { Hex, Json, JsonRpcParams } from '@metamask/utils';\nimport { Command, Flags } from '@oclif/core';\n\nimport { sendCommand } from '../../daemon/daemon-client.js';\nimport { getDaemonPaths } from '../../daemon/paths.js';\nimport { confirmSend } from '../../daemon/prompts.js';\nimport {\n SendTransactionBroadcastResultStruct,\n SendTransactionDryRunResultStruct,\n} from '../../daemon/send-transaction.js';\nimport type { SendTransactionDryRunResult } from '../../daemon/send-transaction.js';\nimport {\n emptyToUndefined,\n formatJsonRpcError,\n makeDaemonConnectionError,\n} from '../../daemon/utils.js';\n\nconst ETHER_DECIMALS = 18;\n\n/**\n * Fallback response timeout (ms) for the broadcast call. Broadcasting waits for\n * signing and `eth_sendRawTransaction` server-side, which can far outlast the\n * 30s default used for cheap RPCs; too short a timeout would make a slow but\n * successful send look like a failure and tempt a duplicate re-send.\n * `--timeout` overrides it.\n */\nconst BROADCAST_TIMEOUT_MS = 120_000;\n\n/**\n * The transaction fields shown in the confirmation preview that the daemon\n * does not echo back (they are the raw `--data` / gas overrides the user\n * passed, so the CLI supplies them for display).\n */\ntype PlanExtras = {\n data?: string | undefined;\n gas?: string | undefined;\n maxFeePerGas?: string | undefined;\n maxPriorityFeePerGas?: string | undefined;\n gasPrice?: string | undefined;\n};\n\n/**\n * Convert a decimal ether amount to a `0x`-prefixed wei quantity.\n *\n * The fixed-point conversion is delegated to `@metamask/utils`' `toWei` rather\n * than re-deriving the wei math here. The daemon's `sendTransaction` boundary\n * expects canonical hex wei; this is where the human-friendly `--value` (ether)\n * is turned into it.\n *\n * `toWei` silently accepts negatives and throws opaque messages on other\n * malformed input, so the value is guarded up front for a clear error and a\n * strictly non-negative amount.\n *\n * @param amount - A non-negative decimal ether amount (e.g. `\"0.1\"`, `\"1\"`).\n * @returns The equivalent wei as a `0x`-prefixed hex string.\n * @throws If `amount` is not a non-negative decimal or has more than 18\n * fractional digits.\n */\nexport function parseEtherToWeiHex(amount: string): Hex {\n const trimmed = amount.trim();\n if (!/^\\d+(?:\\.\\d+)?$/u.test(trimmed)) {\n throw new Error(\n `Invalid value \"${amount}\": expected a non-negative decimal amount of ether (e.g. 0.1).`,\n );\n }\n\n if ((trimmed.split('.')[1] ?? '').length > ETHER_DECIMALS) {\n throw new Error(\n `Invalid value \"${amount}\": ether has at most ${ETHER_DECIMALS} decimal places.`,\n );\n }\n\n return bigIntToHex(toWei(trimmed, 'ether'));\n}\n\nexport default class WalletSend extends Command {\n static override description =\n 'Send a transaction through the daemon-hosted TransactionController. ' +\n 'Estimates gas automatically unless overridden, signs, broadcasts, and ' +\n 'prints the resulting transaction hash. The daemon auto-approves, so the ' +\n 'confirmation boundary is this command.';\n\n static override examples = [\n '<%= config.bin %> wallet send --to 0xRecipient --value 0.01 --chain-id 0x1',\n '<%= config.bin %> wallet send --to 0xRecipient --value 0.01 --network-client-id mainnet --yes',\n '<%= config.bin %> wallet send --to 0xContract --data 0xabcdef --value 0 --chain-id 0x1 --dry-run',\n ];\n\n static override flags = {\n to: Flags.string({\n description: 'Recipient address (0x-prefixed)',\n required: true,\n }),\n value: Flags.string({\n description: 'Amount to send, in ether (e.g. 0.01). Defaults to 0.',\n default: '0',\n }),\n from: Flags.string({\n description:\n 'Sender address (0x-prefixed). Defaults to the selected account.',\n }),\n data: Flags.string({\n description: 'Calldata as a 0x-prefixed hex string (for contract calls)',\n }),\n 'network-client-id': Flags.string({\n description:\n 'Network client to send on. Provide this or --chain-id, not both.',\n }),\n 'chain-id': Flags.string({\n description:\n 'Chain ID (0x-prefixed hex) to resolve to a network client. Provide this or --network-client-id, not both.',\n }),\n gas: Flags.string({\n description: 'Gas limit override, as a 0x-prefixed hex quantity',\n }),\n 'max-fee-per-gas': Flags.string({\n description: 'maxFeePerGas override, as a 0x-prefixed hex wei quantity',\n }),\n 'max-priority-fee-per-gas': Flags.string({\n description:\n 'maxPriorityFeePerGas override, as a 0x-prefixed hex wei quantity',\n }),\n 'gas-price': Flags.string({\n description:\n 'Legacy gasPrice override, as a 0x-prefixed hex wei quantity',\n }),\n 'dry-run': Flags.boolean({\n description:\n 'Resolve the network client and sender and validate params, but do not broadcast.',\n }),\n yes: Flags.boolean({\n char: 'y',\n description: 'Skip the confirmation prompt and broadcast immediately.',\n }),\n timeout: Flags.integer({\n char: 't',\n description: 'Response timeout in milliseconds',\n }),\n };\n\n public async run(): Promise<void> {\n const { flags } = await this.parse(WalletSend);\n\n const networkClientId = emptyToUndefined(flags['network-client-id']);\n const chainId = emptyToUndefined(flags['chain-id']);\n if ((networkClientId === undefined) === (chainId === undefined)) {\n this.error('Provide exactly one of --network-client-id or --chain-id.');\n }\n\n let value: string;\n try {\n value = parseEtherToWeiHex(flags.value);\n } catch (error) {\n // `parseEtherToWeiHex` only ever throws `Error`.\n this.error((error as Error).message);\n }\n\n // Everything except the network selector. The selector is added per call:\n // a confirmed broadcast pins the `networkClientId` the preview resolved\n // rather than re-sending `--chain-id` and re-resolving it.\n const baseParams: Record<string, Json> = {\n to: flags.to,\n value,\n ...(flags.from ? { from: flags.from } : {}),\n ...(flags.data ? { data: flags.data } : {}),\n ...(flags.gas ? { gas: flags.gas } : {}),\n ...(flags['max-fee-per-gas']\n ? { maxFeePerGas: flags['max-fee-per-gas'] }\n : {}),\n ...(flags['max-priority-fee-per-gas']\n ? { maxPriorityFeePerGas: flags['max-priority-fee-per-gas'] }\n : {}),\n ...(flags['gas-price'] ? { gasPrice: flags['gas-price'] } : {}),\n };\n // Exactly one selector is defined (guarded above); guard each spread by its\n // own `undefined` check so the object never carries an `undefined` value.\n const params: Record<string, Json> = {\n ...baseParams,\n ...(networkClientId === undefined ? {} : { networkClientId }),\n ...(chainId === undefined ? {} : { chainId }),\n };\n const planExtras: PlanExtras = {\n data: flags.data,\n gas: flags.gas,\n maxFeePerGas: flags['max-fee-per-gas'],\n maxPriorityFeePerGas: flags['max-priority-fee-per-gas'],\n gasPrice: flags['gas-price'],\n };\n\n const { socketPath } = getDaemonPaths(this.config.dataDir);\n const timeoutMs = flags.timeout;\n\n // A `dryRun` resolves the sender and network client server-side without\n // broadcasting. `--dry-run` stops after previewing; an interactive run\n // previews first so the confirmation shows (and then pins) the resolved\n // sender/network; `--yes` skips straight to the broadcast.\n if (flags['dry-run']) {\n const preview = await this.#dispatchSend({\n socketPath,\n params: { ...params, dryRun: true },\n timeoutMs,\n struct: SendTransactionDryRunResultStruct,\n broadcast: false,\n });\n this.log(formatPlan(preview, flags.value, planExtras));\n return;\n }\n\n let resolved: SendTransactionDryRunResult | undefined;\n if (!flags.yes) {\n const preview = await this.#dispatchSend({\n socketPath,\n params: { ...params, dryRun: true },\n timeoutMs,\n struct: SendTransactionDryRunResultStruct,\n broadcast: false,\n });\n\n let confirmed: boolean;\n try {\n confirmed = await confirmSend(\n formatPlan(preview, flags.value, planExtras),\n );\n } catch (error) {\n // Ctrl+C at the prompt (@inquirer/core's ExitPromptError) is a clean\n // abort, not a failure; anything else should surface.\n if (error instanceof Error && error.name === 'ExitPromptError') {\n this.log('Aborted.');\n return;\n }\n throw error;\n }\n if (!confirmed) {\n this.log('Aborted.');\n return;\n }\n resolved = preview;\n }\n\n // Broadcast the exact sender/network the user reviewed (when they confirmed\n // a preview), so what is signed matches what was shown. `--yes` skips the\n // preview, so there it re-resolves server-side from `params`.\n const broadcastParams: Record<string, Json> = resolved\n ? {\n ...baseParams,\n from: resolved.from,\n networkClientId: resolved.networkClientId,\n }\n : params;\n\n const result = await this.#dispatchSend({\n socketPath,\n params: broadcastParams,\n timeoutMs: timeoutMs ?? BROADCAST_TIMEOUT_MS,\n struct: SendTransactionBroadcastResultStruct,\n broadcast: true,\n });\n this.log('Transaction broadcast.');\n this.log(`Hash: ${result.transactionHash}`);\n this.log(`Id: ${result.transactionId}`);\n this.log(`Status: ${result.status}`);\n }\n\n /**\n * Send a `sendTransaction` RPC to the daemon and return its validated result,\n * translating connection errors, broadcast timeouts, JSON-RPC failures, and\n * unexpected payloads into command errors.\n *\n * @param options - Dispatch options.\n * @param options.socketPath - The daemon Unix socket path.\n * @param options.params - The `sendTransaction` params (with or without\n * `dryRun`).\n * @param options.timeoutMs - Optional response timeout in milliseconds.\n * @param options.struct - Struct the `result` payload must satisfy; the\n * return type is inferred from it.\n * @param options.broadcast - Whether this is the real (fund-moving) broadcast.\n * When true, a read timeout is reported with guidance that the send may\n * already be in flight, so the user does not blindly re-send.\n * @returns The validated `result` payload.\n */\n async #dispatchSend<Value>(options: {\n socketPath: string;\n params: JsonRpcParams;\n timeoutMs: number | undefined;\n struct: Struct<Value>;\n broadcast: boolean;\n }): Promise<Value> {\n const { socketPath, params, timeoutMs, struct, broadcast } = options;\n let response;\n try {\n response = await sendCommand({\n socketPath,\n method: 'sendTransaction',\n params,\n ...(timeoutMs === undefined ? {} : { timeoutMs }),\n });\n } catch (error) {\n if (broadcast && isReadTimeout(error)) {\n this.error(broadcastTimeoutMessage());\n }\n this.error(makeDaemonConnectionError(error));\n }\n\n if (isJsonRpcFailure(response)) {\n this.error(formatJsonRpcError(response.error));\n }\n\n const { result } = response;\n if (!is(result, struct)) {\n this.error(\n `The daemon returned an unexpected ${broadcast ? 'send' : 'dry-run'} ` +\n 'result. It may be running an incompatible version.',\n );\n }\n return result;\n }\n}\n\n/**\n * Whether an error is the daemon-client socket read timeout. It carries no\n * errno code, so its message is the only signal.\n *\n * @param error - The caught value.\n * @returns True if it is the read timeout.\n */\nfunction isReadTimeout(error: unknown): boolean {\n return error instanceof Error && error.message === 'Socket read timed out';\n}\n\n/**\n * The message shown when the broadcast call times out. A send is not\n * idempotent, and the daemon may still be broadcasting after the client gives\n * up waiting, so this warns against a blind re-run rather than reading as a\n * plain connection failure.\n *\n * @returns The user-facing guidance.\n */\nfunction broadcastTimeoutMessage(): string {\n return (\n 'The daemon did not respond in time, but your transaction may still be ' +\n 'broadcasting. Do NOT re-run this command — you could send it twice. ' +\n 'Check `mm daemon status`, the daemon log, or your account on-chain to ' +\n 'confirm, then use --timeout to wait longer if needed.'\n );\n}\n\n/**\n * Format a dry-run plan for display (and as the confirmation prompt body).\n *\n * @param plan - The dry-run result returned by the daemon.\n * @param etherAmount - The original `--value` (ether), shown alongside the\n * resolved wei so the user sees the human amount they typed.\n * @param extras - The `--data` / gas overrides the daemon does not echo back,\n * shown so the user confirms exactly what will be sent.\n * @returns A multi-line summary of the transaction to be sent.\n */\nfunction formatPlan(\n plan: SendTransactionDryRunResult,\n etherAmount: string,\n extras: PlanExtras,\n): string {\n const lines = [\n 'About to send:',\n ` To: ${plan.to}`,\n ` From: ${plan.from}`,\n ` Value: ${etherAmount} ETH (${plan.value} wei)`,\n ` Network: ${plan.networkClientId}`,\n ];\n if (extras.data) {\n lines.push(` Data: ${extras.data}`);\n }\n const gasParts = [\n extras.gas ? `gas=${extras.gas}` : undefined,\n extras.maxFeePerGas ? `maxFeePerGas=${extras.maxFeePerGas}` : undefined,\n extras.maxPriorityFeePerGas\n ? `maxPriorityFeePerGas=${extras.maxPriorityFeePerGas}`\n : undefined,\n extras.gasPrice ? `gasPrice=${extras.gasPrice}` : undefined,\n ].filter((part): part is string => part !== undefined);\n if (gasParts.length > 0) {\n lines.push(` Gas: ${gasParts.join(', ')}`);\n }\n return lines.join('\\n');\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unlock.d.ts","sourceRoot":"","sources":["../../../src/commands/wallet/unlock.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAC;AAU7C,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,OAAO;IAC/C,OAAgB,WAAW,SAGyC;IAEpE,OAAgB,QAAQ,WAItB;IAEF,OAAgB,KAAK;QACnB,QAAQ;QAOR,OAAO;MAKP;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CA+ChC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unlock.js","sourceRoot":"","sources":["../../../src/commands/wallet/unlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gB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';\n\nimport { sendCommand } from '../../daemon/daemon-client.js';\nimport { getDaemonPaths } from '../../daemon/paths.js';\nimport { promptPassword } from '../../daemon/prompts.js';\nimport {\n emptyToUndefined,\n makeDaemonConnectionError,\n} from '../../daemon/utils.js';\n\nexport default class WalletUnlock extends Command {\n static override description =\n 'Unlock the wallet (submits the password to KeyringController). ' +\n 'Use this after `mm daemon start` was run without `--password`, or ' +\n 'after the keyring was locked via `KeyringController:setLocked`.';\n\n static override examples = [\n '<%= config.bin %> wallet unlock --password <pw>',\n 'MM_WALLET_PASSWORD=<pw> <%= config.bin %> wallet unlock',\n '<%= config.bin %> wallet unlock # prompts interactively',\n ];\n\n static override flags = {\n password: Flags.string({\n description:\n 'Wallet password (testing only — use MM_WALLET_PASSWORD env var in production). ' +\n 'When omitted, the command prompts interactively.',\n env: 'MM_WALLET_PASSWORD',\n required: false,\n }),\n timeout: Flags.integer({\n char: 't',\n description: 'Response timeout in milliseconds',\n required: false,\n }),\n };\n\n public async run(): Promise<void> {\n const { flags } = await this.parse(WalletUnlock);\n const { timeout: timeoutMs } = flags;\n\n // `emptyToUndefined` collapses `--password ''` and `MM_WALLET_PASSWORD=''`\n // to undefined so the prompt fires instead of sending an empty string.\n const flagPassword = emptyToUndefined(flags.password);\n let password: string;\n try {\n password = flagPassword ?? (await promptPassword());\n } catch (error) {\n // Only swallow ExitPromptError (@inquirer/core's Ctrl+C signal); any\n // other rejection (import failure, internal prompt crash) should surface.\n if (error instanceof Error && error.name === 'ExitPromptError') {\n return;\n }\n throw error;\n }\n\n const { socketPath } = getDaemonPaths(this.config.dataDir);\n\n let response;\n try {\n response = await sendCommand({\n socketPath,\n method: 'call',\n params: ['KeyringController:submitPassword', password],\n ...(timeoutMs === undefined ? {} : { timeoutMs }),\n });\n } catch (error) {\n this.error(makeDaemonConnectionError(error));\n }\n\n if (isJsonRpcFailure(response)) {\n const { code, message, data } = response.error;\n // `isJsonRpcFailure` already validates that `data` is JSON, so\n // `JSON.stringify` cannot throw here.\n const dataSuffix =\n data === undefined || data === null\n ? ''\n : ` data=${JSON.stringify(data)}`;\n this.error(\n `Failed to unlock: ${message} (code ${String(code)})${dataSuffix}`,\n );\n }\n\n this.log('Wallet unlocked.');\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-approval.d.ts","sourceRoot":"","sources":["../../src/daemon/auto-approval.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACd,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAqBzC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,QAAQ,CAAC,aAAa,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC,EACjE,GAAG,CAAC,EAAE,MAAM,GACX,MAAM,IAAI,CAyCZ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-approval.js","sourceRoot":"","sources":["../../src/daemon/auto-approval.ts"],"names":[],"mappings":"AA2BA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,uBAAuB,CACrC,SAAiE,EACjE,GAAY;IAEZ,MAAM,KAAK,GACT,GAAG;QACH,CAAC,CAAC,OAAe,EAAQ,EAAE;YACzB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IAEL,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IAEnC,MAAM,UAAU,GAAG,CAAC,EAAU,EAAE,KAAc,EAAQ,EAAE;QACtD,KAAK,CAAC,0CAA0C,EAAE,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC1E,CAAC,CAAC;IAEF,MAAM,aAAa,GAAG,CAAC,EAAU,EAAQ,EAAE;QACzC,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACrB,OAAO;QACT,CAAC;QACD,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAEjB,IAAI,CAAC;YACH,SAAS;iBACN,IAAI,CAAC,kCAAkC,EAAE,EAAE,CAAC;iBAC5C,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;iBAChD,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QACxC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,kEAAkE;YAClE,uEAAuE;YACvE,uEAAuE;YACvE,8DAA8D;YAC9D,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACpB,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACxB,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,OAAO,GAA+B,CAAC,KAAK,EAAE,EAAE;QACpD,KAAK,MAAM,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,CAAC;YACrD,aAAa,CAAC,EAAE,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,+BAA+B,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,+BAA+B,CACtC,SAAiE,EACjE,OAAmC;IAEnC,MAAM,UAAU,GAAG,SAMlB,CAAC;IACF,UAAU,CAAC,SAAS,CAAC,iCAAiC,EAAE,OAAO,CAAC,CAAC;IACjE,OAAO,GAAG,EAAE;QACV,UAAU,CAAC,WAAW,CAAC,iCAAiC,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n DefaultActions,\n DefaultEvents,\n RootMessenger,\n} from '@metamask/wallet';\n\nimport type { Logger } from './types.js';\n\n/**\n * The slice of `ApprovalController` state this module reads. The full\n * state-change payload is the controller's `ApprovalControllerState`; auto\n * approval only needs the ids of the pending requests, so it looks at\n * `pendingApprovals` alone (the request bodies are irrelevant to accepting\n * them).\n */\ntype PendingApprovalsState = {\n pendingApprovals: Record<string, unknown>;\n};\n\n/**\n * Handler for `ApprovalController`'s state-change event, narrowed to the slice\n * auto approval reads. The `Patch[]` second argument from the raw event is\n * intentionally absent — auto approval re-accepts on every state change and\n * does not filter by patch.\n */\ntype ApprovalStateChangeHandler = (state: PendingApprovalsState) => void;\n\n/**\n * Subscribe the daemon to auto-accept every pending approval request.\n *\n * Without this, any `ApprovalController:addRequest` call hangs forever on a\n * headless daemon. **Everything is approved without a prompt** — trust boundary\n * is the `0600` same-user socket. A scoped policy is tracked in\n * {@link https://github.com/MetaMask/core/issues/9513}.\n *\n * The `inFlight` guard makes accepting each id idempotent: `acceptRequest`\n * deletes the request on resolve, which itself re-emits `stateChanged`. Without\n * it the same id would be accepted twice and the second accept would reject.\n * Both sync throws and async rejections are logged and swallowed so one bad\n * request cannot crash the daemon or wedge the subscription.\n *\n * @param messenger - The wallet root messenger.\n * @param log - Optional logger for accept failures. Defaults to `console.error`.\n * @returns A function that unsubscribes the auto-approval handler.\n */\nexport function subscribeToAutoApproval(\n messenger: Readonly<RootMessenger<DefaultActions, DefaultEvents>>,\n log?: Logger,\n): () => void {\n const logFn =\n log ??\n ((message: string): void => {\n console.error(message);\n });\n\n const inFlight = new Set<string>();\n\n const logFailure = (id: string, error: unknown): void => {\n logFn(`Failed to auto-accept approval request ${id}: ${String(error)}`);\n };\n\n const acceptRequest = (id: string): void => {\n if (inFlight.has(id)) {\n return;\n }\n inFlight.add(id);\n\n try {\n messenger\n .call('ApprovalController:acceptRequest', id)\n .catch((error: unknown) => logFailure(id, error))\n .finally(() => inFlight.delete(id));\n } catch (error) {\n // Synchronous throw means the Promise chain above was never built\n // (no .catch/.finally attached), so clean up the in-flight guard here.\n // The error is intentionally suppressed — a race-condition reject must\n // not crash the daemon or permanently wedge the subscription.\n inFlight.delete(id);\n logFailure(id, error);\n }\n };\n\n const handler: ApprovalStateChangeHandler = (state) => {\n for (const id of Object.keys(state.pendingApprovals)) {\n acceptRequest(id);\n }\n };\n\n return subscribeToApprovalStateChanged(messenger, handler);\n}\n\n/**\n * Subscribe a handler to `ApprovalController:stateChanged`.\n *\n * `ApprovalControllerEvents` only declares `ApprovalController:stateChange`\n * (via `ControllerStateChangeEvent`), not the non-deprecated\n * `ApprovalController:stateChanged` variant that `BaseController` publishes at\n * runtime. This helper localizes the unavoidable cast — using the same\n * technique as `subscribeToStateChanged` in the persistence layer — behind a\n * typed {@link ApprovalStateChangeHandler}, keeping the `state` payload\n * compile-checked at the call site instead of erased by a statement-level\n * `@ts-expect-error`.\n *\n * TODO: Remove this cast once `ApprovalControllerEvents` includes\n * `ControllerStateChangedEvent` (`:stateChanged`), matching the union already\n * exported by `BaseController`.\n *\n * @param messenger - The wallet root messenger.\n * @param handler - The state-change handler to register.\n * @returns A function that unsubscribes the handler.\n */\nfunction subscribeToApprovalStateChanged(\n messenger: Readonly<RootMessenger<DefaultActions, DefaultEvents>>,\n handler: ApprovalStateChangeHandler,\n): () => void {\n const subscriber = messenger as unknown as {\n subscribe: (eventType: string, handler: ApprovalStateChangeHandler) => void;\n unsubscribe: (\n eventType: string,\n handler: ApprovalStateChangeHandler,\n ) => void;\n };\n subscriber.subscribe('ApprovalController:stateChanged', handler);\n return () => {\n subscriber.unsubscribe('ApprovalController:stateChanged', handler);\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"daemon-client.d.ts","sourceRoot":"","sources":["../../src/daemon/daemon-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAWtE;;GAEG;AACH,KAAK,kBAAkB,GAAG;IACxB,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,MAAM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I,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;QACxE,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,KAAK,uBAAuB,EAAE,CAAC;QACxE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IACE,KAAK,YAAY,KAAK;QACtB,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAC;YAC7C,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;YAC3C,KAAK,CAAC,IAAI,KAAK,aAAa,CAAC,EAC/B,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,UAAkB;IACjD,IAAI,CAAC;QACH,MAAM,WAAW,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,IAAK,EAAE,CAAC,CAAC;QACzE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IAClC,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;YACrC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;QAC9B,CAAC;QACD,OAAO;YACL,MAAM,EAAE,aAAa;YACrB,MAAM,EAAE,mBAAmB,CAAC,KAAK,CAAC;YAClC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC;SACtB,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcParams, JsonRpcResponse } from '@metamask/utils';\nimport { assertIsJsonRpcResponse } from '@metamask/utils';\nimport { randomUUID } from 'node:crypto';\nimport { createConnection } from 'node:net';\nimport type { Socket } from 'node:net';\n\nimport { readLine, writeLine } from './socket-line.js';\nimport { isErrorWithCode } from './utils.js';\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\n\n/**\n * Options for {@link sendCommand}.\n */\ntype SendCommandOptions = {\n /** The Unix socket path. */\n socketPath: string;\n /** The RPC method name. */\n method: string;\n /** Optional method parameters (object or positional array). */\n params?: JsonRpcParams | undefined;\n /** Response read timeout in milliseconds (default: 30 000). */\n timeoutMs?: number | undefined;\n};\n\nasync function connectSocket(socketPath: string): Promise<Socket> {\n return new Promise((resolve, reject) => {\n const socket = createConnection(socketPath, () => {\n socket.removeAllListeners('error');\n resolve(socket);\n });\n socket.on('error', (error) => {\n // A failed connect never reaches the caller, so destroy the socket here\n // to avoid leaking its file descriptor.\n socket.destroy();\n reject(error);\n });\n });\n}\n\n/**\n * Send a JSON-RPC request to the daemon over a Unix socket and return the\n * response.\n *\n * Opens a connection, writes one JSON-RPC request line, reads one JSON-RPC\n * response line, then closes the connection. Retries once after a short delay\n * only on `ECONNREFUSED` — the connection was never established, so the daemon\n * provably never received the request and re-sending is safe. Does not retry\n * on `ECONNRESET`, which can drop after the daemon has already received and\n * acted on the request: blindly re-sending could execute a non-idempotent\n * action (e.g. a transaction broadcast) twice, so it is surfaced to the caller\n * instead. Verifies that the response `id` matches the outgoing request `id`.\n *\n * @param options - Command options.\n * @param options.socketPath - The Unix socket path.\n * @param options.method - The RPC method name.\n * @param options.params - Optional method parameters.\n * @param options.timeoutMs - Read timeout in milliseconds.\n * @returns The parsed JSON-RPC response.\n */\nexport async function sendCommand({\n socketPath,\n method,\n params,\n timeoutMs,\n}: SendCommandOptions): Promise<JsonRpcResponse> {\n const id = randomUUID();\n const request = {\n jsonrpc: '2.0',\n id,\n method,\n ...(params === undefined ? {} : { params }),\n };\n\n const effectiveTimeout = timeoutMs ?? DEFAULT_TIMEOUT_MS;\n\n const attempt = async (): Promise<JsonRpcResponse> => {\n const socket = await connectSocket(socketPath);\n try {\n await writeLine(socket, JSON.stringify(request));\n const responseLine = await readLine(socket, effectiveTimeout);\n const parsed: unknown = JSON.parse(responseLine);\n assertIsJsonRpcResponse(parsed);\n if (parsed.id !== id) {\n throw new Error(\n `JSON-RPC response id ${JSON.stringify(parsed.id)} does not match request id ${JSON.stringify(id)}`,\n );\n }\n return parsed;\n } finally {\n socket.destroy();\n }\n };\n\n try {\n return await attempt();\n } catch (error: unknown) {\n // Only retry on ECONNREFUSED: the connection was never established, so the\n // daemon provably never received the request and re-sending is safe.\n // ECONNRESET can drop *after* the daemon received and began (or finished)\n // processing the request, so blindly re-sending a non-idempotent request\n // (e.g. a transaction broadcast) could execute it twice. Surface it to the\n // caller instead of retrying.\n if (!isErrorWithCode(error, 'ECONNREFUSED')) {\n throw error;\n }\n await new Promise((resolve) => setTimeout(resolve, 100));\n return attempt();\n }\n}\n\n/**\n * Why an unreachable daemon cannot be queried.\n *\n * - `'refused'`: the connection could not be completed — `ECONNREFUSED`\n * (retried once) or `ECONNRESET` (a mid-request drop, not retried). Typical\n * of a daemon that has crashed or is mid-restart.\n * - `'timeout'`: the daemon accepted the connection but did not respond within\n * the read timeout — most likely wedged on a long-running operation.\n * - `'permission'`: the socket exists but cannot be opened (`EACCES` / `EPERM`).\n * The daemon almost certainly belongs to another user.\n * - `'protocol'`: the daemon responded but the response did not parse as a\n * valid JSON-RPC response, or the response id did not match.\n * - `'other'`: anything else.\n */\nexport type PingUnreachableReason =\n | 'refused'\n | 'timeout'\n | 'permission'\n | 'protocol'\n | 'other';\n\n/**\n * Outcome of a daemon health check.\n *\n * - `'responsive'`: the daemon answered a `getStatus` RPC.\n * - `'absent'`: the socket connect attempt failed with `ENOENT`, i.e. no\n * socket file exists at the path. No daemon present.\n * - `'unreachable'`: any other non-success outcome. The daemon may still be\n * alive but is not responding. Callers should not silently take over the\n * slot or assume the daemon is dead. The `reason` field categorises the\n * failure so callers can distinguish a wedged sibling daemon from a\n * foreign-user daemon from a transient crash. User-initiated stop / purge\n * flows may still escalate to signals against the recorded PID.\n */\nexport type PingResult =\n | { status: 'responsive' }\n | { status: 'absent' }\n | { status: 'unreachable'; reason: PingUnreachableReason; error: Error };\n\n/**\n * Normalize an unknown throw into a real Error instance so that downstream\n * consumers (which read `.message`) cannot crash on string/object throws.\n *\n * @param error - The caught value.\n * @returns An Error mirroring the caught value.\n */\nfunction toError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error));\n}\n\n/**\n * Categorise an unreachable error by Node errno / message shape so callers can\n * make decisions per failure mode rather than parsing message strings.\n *\n * @param error - The caught value.\n * @returns A {@link PingUnreachableReason} label.\n */\nfunction classifyUnreachable(error: unknown): PingUnreachableReason {\n if (\n isErrorWithCode(error, 'ECONNREFUSED') ||\n isErrorWithCode(error, 'ECONNRESET')\n ) {\n return 'refused';\n }\n if (isErrorWithCode(error, 'EACCES') || isErrorWithCode(error, 'EPERM')) {\n return 'permission';\n }\n if (error instanceof Error && error.message === 'Socket read timed out') {\n return 'timeout';\n }\n if (\n error instanceof Error &&\n (error.message.includes('JSON-RPC response id') ||\n /Expected .* JSON-RPC/u.test(error.message) ||\n error.name === 'SyntaxError')\n ) {\n return 'protocol';\n }\n return 'other';\n}\n\n/**\n * Check whether the daemon is running by sending a lightweight `getStatus`\n * RPC call. Distinguishes \"no daemon present\" (socket file missing) from\n * \"daemon present but unreachable\" (socket file exists but the daemon is\n * wedged, mid-shutdown, or owned by a different user).\n *\n * @param socketPath - The Unix socket path.\n * @returns A {@link PingResult} describing the daemon's reachability.\n */\nexport async function pingDaemon(socketPath: string): Promise<PingResult> {\n try {\n await sendCommand({ socketPath, method: 'getStatus', timeoutMs: 3_000 });\n return { status: 'responsive' };\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ENOENT')) {\n return { status: 'absent' };\n }\n return {\n status: 'unreachable',\n reason: classifyUnreachable(error),\n error: toError(error),\n };\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"daemon-entry.d.ts","sourceRoot":"","sources":["../../src/daemon/daemon-entry.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
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OAAO;QACT,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,IAAI,MAAM,KAAK,gBAAgB,EAAE,CAAC;QAChC,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACrC,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,OAAe;IACjC,OAAO,CAAC,OAAe,EAAQ,EAAE;QAC/B,MAAM,IAAI,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,OAAO,IAAI,CAAC;QAC1D,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YACjD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,MAAM,CAAC,KAAK,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC;QAC5E,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { define, literal } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport type { Wallet } from '@metamask/wallet';\nimport { appendFile, readFile, rm, writeFile } from 'node:fs/promises';\n\nimport { pingDaemon } from './daemon-client.js';\nimport { ensureOwnerOnlyDirectory } from './data-dir.js';\nimport { getDaemonPaths } from './paths.js';\nimport { startRpcSocketServer } from './rpc-socket-server.js';\nimport type { RpcSocketServerHandle } from './rpc-socket-server.js';\nimport { Password, Srp } from './secrets.js';\nimport {\n runSendTransaction,\n SendTransactionParamsStruct,\n} from './send-transaction.js';\nimport { defineHandler } from './types.js';\nimport type {\n DaemonStatusInfo,\n Logger,\n RpcDispatcher,\n RpcHandlerMap,\n} from './types.js';\nimport { isErrorWithCode, isProcessAlive, readPidFile } from './utils.js';\nimport { createWallet } from './wallet-factory.js';\n\n/**\n * Params struct for the `call` RPC method. `params` must be a non-empty array\n * whose first element is the messenger action name; remaining elements are\n * positional action arguments forwarded as-is to `messenger.call`.\n */\nconst callParamsStruct = define<[string, ...unknown[]]>(\n 'CallParams',\n (value) => {\n if (!Array.isArray(value)) {\n return 'Expected an array';\n }\n if (value.length === 0) {\n return 'Expected a non-empty array';\n }\n if (typeof value[0] !== 'string') {\n return 'Expected the first element to be a string action name';\n }\n return true;\n },\n);\n\nconst startTime = Date.now();\n\nmain().catch((error: unknown) => {\n process.stderr.write(`Daemon fatal: ${String(error)}\\n`);\n process.exitCode = 1;\n});\n\nasync function main(): Promise<void> {\n const dataDir = process.env.MM_DAEMON_DATA_DIR;\n if (!dataDir) {\n throw new Error('MM_DAEMON_DATA_DIR environment variable is required');\n }\n\n const infuraProjectId = process.env.INFURA_PROJECT_ID;\n if (!infuraProjectId) {\n throw new Error('INFURA_PROJECT_ID environment variable is required');\n }\n\n // Password is optional: when absent, the daemon starts without unlocking\n // the keyring (e.g. when the user prefers to call `mm wallet unlock`\n // interactively rather than embed the password in their environment).\n // First-run startup still requires a password; wallet-factory enforces\n // that and surfaces a clear error.\n const passwordRaw = process.env.MM_WALLET_PASSWORD;\n\n const srpRaw = process.env.MM_WALLET_SRP;\n if (!srpRaw) {\n throw new Error('MM_WALLET_SRP environment variable is required');\n }\n\n // Scrub before validation so a throw from Password.from / Srp.from (bad\n // value) does not leave the raw secrets in the long-lived daemon's env.\n delete process.env.MM_WALLET_PASSWORD;\n delete process.env.MM_WALLET_SRP;\n\n const password = passwordRaw ? Password.from(passwordRaw) : undefined;\n const srp = Srp.from(srpRaw);\n\n await ensureOwnerOnlyDirectory(dataDir);\n\n const {\n socketPath: defaultSocketPath,\n pidPath,\n logPath,\n dbPath,\n } = getDaemonPaths(dataDir);\n const socketPath = process.env.MM_DAEMON_SOCKET_PATH ?? defaultSocketPath;\n\n const log = makeLogger(logPath);\n log('Starting daemon...');\n\n // Pre-flight: refuse to take over if a responsive daemon already owns this\n // socket. If the existing PID file is stale (or the socket is dead), clean\n // it up so the exclusive PID-file write below has a chance to succeed.\n await claimDaemonSlot(pidPath, socketPath, log);\n\n const pidFileContents = `${process.pid}\\n${startTime}\\n`;\n\n // Claim the slot atomically BEFORE opening the SQLite database or\n // constructing the Wallet. Two concurrent `daemon start` invocations can\n // both pass `claimDaemonSlot` (the gap between its preflight and the slot\n // write is racy); without this ordering, both would open `wallet.db` and\n // both would run first-run SRP import before one loses the wx race.\n try {\n await writeFile(pidPath, pidFileContents, { flag: 'wx' });\n } catch (error) {\n throw error instanceof Error\n ? Object.assign(error, {\n message: `Failed to claim daemon slot at ${pidPath}: ${error.message}`,\n })\n : /* istanbul ignore next -- node:fs/promises always rejects with an Error */\n new Error(\n `Failed to claim daemon slot at ${pidPath}: ${String(error)}`,\n );\n }\n\n let wallet: Wallet | undefined;\n let dispose: (() => Promise<void>) | undefined;\n let handle: RpcSocketServerHandle | undefined;\n\n try {\n ({ wallet, dispose } = await createWallet({\n databasePath: dbPath,\n password,\n srp,\n infuraProjectId,\n log,\n }));\n\n const constructedWallet = wallet;\n // Arbitrary messenger dispatch is intentional: the CLI exposes the full\n // messenger surface over a Unix socket inside the per-user oclif data\n // directory. The dataDir is chmodded to 0o700 above and the socket to\n // 0o600 by the RPC server on bind, so only the owning user can open them,\n // but there is no in-process auth check beyond that filesystem-permission\n // barrier. The messenger is strongly typed by action name; we narrow it\n // once here to the RpcDispatcher shape the `call` handler needs.\n const dispatch = constructedWallet.messenger.call.bind(\n constructedWallet.messenger,\n ) as unknown as RpcDispatcher;\n\n const handlers: RpcHandlerMap = {\n getStatus: defineHandler(\n literal(null),\n async (): Promise<DaemonStatusInfo> => ({\n pid: process.pid,\n uptime: Math.floor((Date.now() - startTime) / 1000),\n }),\n ),\n call: defineHandler(callParamsStruct, async (params) => {\n const [action, ...args] = params;\n return await dispatch(action, ...(args as Json[]));\n }),\n // Exposes the callable surface for discovery: it grows silently as\n // controllers are wired, so consumers need a way to see it without a\n // hand-kept catalog that would rot.\n listActions: defineHandler(\n literal(null),\n async (): Promise<Json> =>\n constructedWallet.messenger.getRegisteredActionTypes(),\n ),\n // Dedicated send handler; see `runSendTransaction` for why the generic\n // `call` dispatch cannot carry a broadcast result.\n sendTransaction: defineHandler(\n SendTransactionParamsStruct,\n async (params) =>\n runSendTransaction(constructedWallet.messenger, params),\n ),\n };\n\n // `startRpcSocketServer` restricts the socket to the owner (chmod 0o600)\n // on bind and never leaves a live server/socket behind if it rejects, so\n // the catch below has nothing of its own to close.\n handle = await startRpcSocketServer({\n socketPath,\n handlers,\n onShutdown: async () => shutdown('RPC shutdown'),\n log,\n });\n } catch (error) {\n // `dispose` is undefined only when `createWallet` itself threw — it has\n // already torn down its own store in that case.\n if (dispose) {\n await dispose();\n }\n // Only remove the PID file if it's still ours (we may have lost the race\n // and the file now belongs to another daemon).\n await removeOwnedPidFile(pidPath, pidFileContents).catch(\n (rmError: unknown) => {\n log(`Failed to remove PID file during cleanup: ${String(rmError)}`);\n },\n );\n throw error;\n }\n\n // Stable non-undefined refs for the shutdown closures (TS won't narrow the\n // outer `let`s across closure escape).\n const activeHandle = handle;\n const activeDispose = dispose;\n\n log(`Daemon started. Socket: ${socketPath}`);\n\n let shutdownPromise: Promise<void> | undefined;\n\n /**\n * Shut down the daemon idempotently. Concurrent calls coalesce.\n *\n * @param reason - A label describing why shutdown was triggered.\n * @returns A promise that resolves when shutdown completes.\n */\n async function shutdown(reason: string): Promise<void> {\n if (shutdownPromise === undefined) {\n log(`Shutting down (${reason})...`);\n shutdownPromise = (async (): Promise<void> => {\n try {\n await activeHandle.close();\n } catch (closeError) {\n log(`handle.close() failed: ${String(closeError)}`);\n }\n try {\n await activeDispose();\n } catch (disposeError) {\n log(`dispose() failed during shutdown: ${String(disposeError)}`);\n }\n await Promise.all([\n removeOwnedPidFile(pidPath, pidFileContents).catch(\n (rmError: unknown) => {\n log(`Failed to remove PID file: ${String(rmError)}`);\n },\n ),\n rm(socketPath, { force: true }).catch((rmError: unknown) => {\n log(`Failed to remove socket file: ${String(rmError)}`);\n }),\n ]);\n })();\n }\n return shutdownPromise;\n }\n\n process.on('SIGTERM', () => {\n /* istanbul ignore next -- `shutdown` logs each step internally; the catch only guards against an unhandled rejection from the signal handler. */\n shutdown('SIGTERM').catch(() => undefined);\n });\n process.on('SIGINT', () => {\n /* istanbul ignore next -- `shutdown` logs each step internally; the catch only guards against an unhandled rejection from the signal handler. */\n shutdown('SIGINT').catch(() => undefined);\n });\n}\n\n/**\n * Refuse to start if a responsive daemon already owns the socket. Otherwise\n * clear any stale PID/socket files so the exclusive PID-file write can\n * proceed.\n *\n * @param pidPath - The PID file path.\n * @param socketPath - The socket path.\n * @param log - Logger for diagnostic messages.\n */\nasync function claimDaemonSlot(\n pidPath: string,\n socketPath: string,\n log: Logger,\n): Promise<void> {\n const existingPid = await readPidFile(pidPath);\n const ping = await pingDaemon(socketPath);\n\n if (ping.status === 'responsive') {\n const pidPart =\n existingPid === undefined\n ? '(no PID file present)'\n : `(pid ${existingPid})`;\n throw new Error(`A daemon is already running on ${socketPath} ${pidPart}`);\n }\n\n // Refuse to clobber when the recorded PID is still alive, regardless of\n // whether the socket exists. Possible scenarios:\n // - `unreachable`: wedged or mid-startup sibling daemon (socket present\n // but not responding to JSON-RPC).\n // - `absent`: a sibling daemon that hasn't yet bound its socket, or one\n // whose socket was manually removed. In either case, removing its PID\n // file would orphan it from `daemon stop`.\n if (existingPid !== undefined && isProcessAlive(existingPid)) {\n const detail =\n ping.status === 'unreachable'\n ? `socket at ${socketPath} is unresponsive (${ping.error.message})`\n : `no socket at ${socketPath}, but pid is still alive`;\n throw new Error(\n `A daemon is already running (pid ${existingPid}): ${detail}. ` +\n `Run \\`mm daemon stop\\` (or \\`mm daemon purge\\`) before starting a new daemon.`,\n );\n }\n\n if (ping.status === 'unreachable') {\n log(`Removing stale socket at ${socketPath} (${ping.error.message}).`);\n }\n // Always clear both files before claiming the slot. The PID file may be\n // corrupt (truncated, partial write from a crashed run); without this, the\n // exclusive `wx` write below would fail with EEXIST and the daemon could\n // not start until a human manually deleted the file.\n await Promise.all([\n rm(pidPath, { force: true }),\n rm(socketPath, { force: true }),\n ]);\n}\n\n/**\n * Remove the PID file only if it still contains our exact contents. Guards\n * against a racing daemon's PID file being removed by this daemon during\n * cleanup.\n *\n * @param pidPath - Path to the PID file.\n * @param expectedContents - The contents we wrote when claiming the slot.\n */\nasync function removeOwnedPidFile(\n pidPath: string,\n expectedContents: string,\n): Promise<void> {\n let actual: string;\n try {\n actual = await readFile(pidPath, 'utf-8');\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ENOENT')) {\n return;\n }\n throw error;\n }\n if (actual === expectedContents) {\n await rm(pidPath, { force: true });\n }\n}\n\n/**\n * Create a file logger that appends timestamped lines to `logPath`, falling\n * back to stderr if the append fails.\n *\n * @param logPath - The log file path.\n * @returns A logging function.\n */\nfunction makeLogger(logPath: string): Logger {\n return (message: string): void => {\n const line = `[${new Date().toISOString()}] ${message}\\n`;\n appendFile(logPath, line).catch((error: unknown) => {\n process.stderr.write(`[log write failed: ${String(error)}] ${message}\\n`);\n });\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"daemon-spawn.d.ts","sourceRoot":"","sources":["../../src/daemon/daemon-spawn.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAKpD;;;;;;;;GAQG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACrC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,kBAAkB,CAAC,CAuH7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"daemon-spawn.js","sourceRoot":"","sources":["../../src/daemon/daemon-spawn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAA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,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK;gBACvG,2BAA2B,OAAO,GAAG,CACxC,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,CAAC;QAC1C,IAAI,IAAI,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;YACjC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;YACxC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;QAC1C,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CACb,+BAA+B,CAAC,SAAS,GAAG,gBAAgB,CAAC,GAAG,IAAI,GAAG,CACxE,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,iBAAiB,CAAC,WAAmB;IAI5C,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC;IAC1E,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAC5C,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CAAC;IACvE,OAAO;QACL,SAAS,EAAE,QAAQ;QACnB,IAAI,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC;KAC1B,CAAC;AACJ,CAAC","sourcesContent":["import { spawn } from 'node:child_process';\nimport { closeSync, existsSync, openSync } from 'node:fs';\nimport { join } from 'node:path';\n\nimport { pingDaemon } from './daemon-client.js';\nimport { ensureOwnerOnlyDirectory } from './data-dir.js';\nimport { getDaemonPaths } from './paths.js';\nimport type { DaemonSpawnConfig } from './types.js';\n\nconst POLL_INTERVAL_MS = 100;\nconst MAX_POLLS = 300; // 30 seconds\n\n/**\n * Outcome of {@link ensureDaemon}.\n *\n * - `'already-running'`: a responsive daemon was found at the configured\n * socket path. The supplied flags (`infuraProjectId`, `password`, `srp`)\n * were NOT applied to that daemon; the caller should surface this so a\n * user who is trying to change them isn't silently ignored.\n * - `'started'`: a new daemon was spawned and is now responsive.\n */\nexport type EnsureDaemonResult = {\n state: 'already-running' | 'started';\n socketPath: string;\n};\n\n/**\n * Ensure the daemon is running. If a responsive daemon already exists, return\n * `'already-running'` (caller decides how to surface that). Otherwise spawn\n * one as a detached process and wait until the socket becomes responsive.\n *\n * Refuses to spawn when pinging the existing socket fails with anything other\n * than `ENOENT` (wedged or foreign daemon) — taking over could orphan the\n * existing process and corrupt its PID file.\n *\n * @param config - Spawn configuration.\n * @returns The state of the daemon and the socket path it's listening on.\n */\nexport async function ensureDaemon(\n config: DaemonSpawnConfig,\n): Promise<EnsureDaemonResult> {\n const { socketPath, logPath } = getDaemonPaths(config.dataDir);\n\n const initialPing = await pingDaemon(socketPath);\n switch (initialPing.status) {\n case 'responsive':\n return { state: 'already-running', socketPath };\n case 'unreachable':\n if (initialPing.reason === 'permission') {\n throw new Error(\n `Refusing to start: the socket at ${socketPath} is owned by another user. ` +\n `Choose a different data directory (MM_DAEMON_DATA_DIR) or remove the socket manually. ` +\n `(${initialPing.error.message})`,\n );\n }\n throw new Error(\n `Refusing to start: a daemon socket already exists at ${socketPath} but is unresponsive. ` +\n `Run \\`mm daemon stop\\` (or \\`mm daemon purge\\`) before starting a new daemon. ` +\n `(${initialPing.error.message})`,\n );\n case 'absent':\n break;\n /* istanbul ignore next -- exhaustiveness guard; unreachable for the current PingResult union */\n default: {\n const exhaustiveCheck: never = initialPing;\n throw new Error(\n `Unexpected daemon ping status: ${String(exhaustiveCheck)}`,\n );\n }\n }\n\n process.stderr.write('Starting daemon...\\n');\n\n const { entryPath, args } = resolveEntryPoint(config.packageRoot);\n\n // Create the data directory before opening the log file inside it. The daemon\n // entry also does this, but only after spawn — opening the log first would\n // ENOENT on a fresh data directory.\n await ensureOwnerOnlyDirectory(config.dataDir);\n\n // Redirect the detached daemon's stderr to its log file rather than\n // discarding it, so a crash after startup stays diagnosable. stdout stays\n // ignored — structured status goes through the file logger.\n const logFileDescriptor = openSync(logPath, 'a');\n\n const childEnv: NodeJS.ProcessEnv = {\n ...process.env,\n MM_DAEMON_DATA_DIR: config.dataDir,\n MM_DAEMON_SOCKET_PATH: socketPath,\n INFURA_PROJECT_ID: config.infuraProjectId,\n MM_WALLET_SRP: config.srp.unwrap(),\n };\n // `childEnv` spreads `process.env`, so an inherited `MM_WALLET_PASSWORD`\n // would otherwise leak into the child and unlock a daemon the caller meant\n // to start locked. When no password was supplied, delete the inherited key\n // so the daemon comes up locked; otherwise overwrite it with the supplied\n // value.\n if (config.password === undefined) {\n delete childEnv.MM_WALLET_PASSWORD;\n } else {\n childEnv.MM_WALLET_PASSWORD = config.password.unwrap();\n }\n\n const child = spawn(process.execPath, [...args, entryPath], {\n detached: true,\n stdio: ['ignore', 'ignore', logFileDescriptor],\n env: childEnv,\n });\n // The child dup'd the file descriptor into its stderr, so drop the parent's\n // copy. Safe on the success path: `spawn` reports failures via the 'error'\n // event, not a synchronous throw.\n closeSync(logFileDescriptor);\n\n type StartupOutcome =\n | { kind: 'pending' }\n | { kind: 'error'; error: Error }\n | { kind: 'exited'; code: number | null; signal: NodeJS.Signals | null };\n\n // A failed spawn (bad interpreter, EACCES, ENOENT) emits 'error' and may\n // never emit 'exit', so 'error' is recorded first and not overwritten by a\n // later 'exit' — the loop surfaces the real cause instead of hanging.\n const outcome: { current: StartupOutcome } = { current: { kind: 'pending' } };\n\n child.on('error', (error: Error) => {\n process.stderr.write(`Failed to spawn daemon process: ${String(error)}\\n`);\n outcome.current = { kind: 'error', error };\n });\n child.on('exit', (code, signal) => {\n if (outcome.current.kind === 'pending') {\n outcome.current = { kind: 'exited', code, signal };\n }\n });\n child.unref();\n\n for (let i = 0; i < MAX_POLLS; i++) {\n await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));\n const settled = outcome.current;\n if (settled.kind === 'error') {\n throw new Error(\n `Failed to spawn daemon process: ${settled.error.message}. ` +\n `Check the daemon log at ${logPath}.`,\n );\n }\n if (settled.kind === 'exited') {\n throw new Error(\n `Daemon process exited during startup (code=${String(settled.code)}, signal=${String(settled.signal)}). ` +\n `Check the daemon log at ${logPath}.`,\n );\n }\n const ping = await pingDaemon(socketPath);\n if (ping.status === 'responsive') {\n process.stderr.write('Daemon ready.\\n');\n return { state: 'started', socketPath };\n }\n }\n\n throw new Error(\n `Daemon did not start within ${(MAX_POLLS * POLL_INTERVAL_MS) / 1000}s`,\n );\n}\n\n/**\n * Resolve the daemon entry point path and any extra Node.js args needed.\n *\n * In production, uses the compiled dist output. In development, uses tsx\n * to run TypeScript source directly.\n *\n * @param packageRoot - The root directory of the wallet-cli package.\n * @returns The entry path and any extra node args.\n */\nfunction resolveEntryPoint(packageRoot: string): {\n entryPath: string;\n args: string[];\n} {\n const distEntry = join(packageRoot, 'dist', 'daemon', 'daemon-entry.mjs');\n if (existsSync(distEntry)) {\n return { entryPath: distEntry, args: [] };\n }\n\n const srcEntry = join(packageRoot, 'src', 'daemon', 'daemon-entry.ts');\n return {\n entryPath: srcEntry,\n args: ['--import', 'tsx'],\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"data-dir.d.ts","sourceRoot":"","sources":["../../src/daemon/data-dir.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG7E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"data-dir.js","sourceRoot":"","sources":["../../src/daemon/data-dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,OAAe;IAC5D,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACrD,MAAM,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import { mkdirSync } from 'node:fs';\nimport { chmod } from 'node:fs/promises';\n\n/**\n * Create the daemon's data directory (if it does not exist) and restrict it to\n * the owning user.\n *\n * The mode is `0o700` (owner-only). The daemon exposes the full wallet\n * messenger over the socket inside this directory, so anyone who can traverse\n * the dir can also `connect()` to the socket. Restricting to the owning user is\n * the only access-control boundary. We `chmod` after `mkdir` because the `mode`\n * option is ignored when the directory already exists.\n *\n * @param dataDir - The data directory to create and lock down.\n */\nexport async function ensureOwnerOnlyDirectory(dataDir: string): Promise<void> {\n mkdirSync(dataDir, { recursive: true, mode: 0o700 });\n await chmod(dataDir, 0o700);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/daemon/paths.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAO3D"}
|
package/dist/daemon/paths.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/daemon/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,OAAO;QACL,UAAU,EAAE,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC;QACxC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC;QACpC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC;QACpC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC;KACnC,CAAC;AACJ,CAAC","sourcesContent":["import { join } from 'node:path';\n\nimport type { DaemonPaths } from './types.js';\n\n/**\n * Resolve paths for daemon state files within the given data directory.\n *\n * @param dataDir - The base data directory (e.g. oclif config.dataDir).\n * @returns Resolved paths for socket, PID file, log file, and database file.\n */\nexport function getDaemonPaths(dataDir: string): DaemonPaths {\n return {\n socketPath: join(dataDir, 'daemon.sock'),\n pidPath: join(dataDir, 'daemon.pid'),\n logPath: join(dataDir, 'daemon.log'),\n dbPath: join(dataDir, 'wallet.db'),\n };\n}\n"]}
|