@metamask-previews/wallet-cli 0.0.0-preview-b8d04f274 → 0.0.0-preview-1ccf11bcb
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 +5 -0
- package/README.md +13 -1
- package/dist/commands/daemon/start.cjs +7 -3
- package/dist/commands/daemon/start.cjs.map +1 -1
- package/dist/commands/daemon/start.d.cts +1 -1
- package/dist/commands/daemon/start.d.cts.map +1 -1
- package/dist/commands/daemon/start.d.mts +1 -1
- package/dist/commands/daemon/start.d.mts.map +1 -1
- package/dist/commands/daemon/start.mjs +7 -3
- package/dist/commands/daemon/start.mjs.map +1 -1
- package/dist/commands/wallet/unlock.cjs +75 -0
- package/dist/commands/wallet/unlock.cjs.map +1 -0
- package/dist/commands/wallet/unlock.d.cts +11 -0
- 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.mjs +73 -0
- package/dist/commands/wallet/unlock.mjs.map +1 -0
- package/dist/daemon/daemon-entry.cjs +52 -27
- package/dist/daemon/daemon-entry.cjs.map +1 -1
- package/dist/daemon/daemon-entry.mjs +52 -27
- package/dist/daemon/daemon-entry.mjs.map +1 -1
- package/dist/daemon/daemon-spawn.cjs +19 -8
- package/dist/daemon/daemon-spawn.cjs.map +1 -1
- package/dist/daemon/daemon-spawn.d.cts.map +1 -1
- package/dist/daemon/daemon-spawn.d.mts.map +1 -1
- package/dist/daemon/daemon-spawn.mjs +19 -8
- package/dist/daemon/daemon-spawn.mjs.map +1 -1
- package/dist/daemon/prompts.cjs +17 -1
- package/dist/daemon/prompts.cjs.map +1 -1
- package/dist/daemon/prompts.d.cts +9 -0
- package/dist/daemon/prompts.d.cts.map +1 -1
- package/dist/daemon/prompts.d.mts +9 -0
- package/dist/daemon/prompts.d.mts.map +1 -1
- package/dist/daemon/prompts.mjs +15 -0
- package/dist/daemon/prompts.mjs.map +1 -1
- package/dist/daemon/rpc-socket-server.cjs +14 -1
- package/dist/daemon/rpc-socket-server.cjs.map +1 -1
- package/dist/daemon/rpc-socket-server.d.cts.map +1 -1
- package/dist/daemon/rpc-socket-server.d.mts.map +1 -1
- package/dist/daemon/rpc-socket-server.mjs +14 -1
- package/dist/daemon/rpc-socket-server.mjs.map +1 -1
- package/dist/daemon/secrets.cjs +137 -0
- package/dist/daemon/secrets.cjs.map +1 -0
- package/dist/daemon/secrets.d.cts +72 -0
- 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.mjs +132 -0
- package/dist/daemon/secrets.mjs.map +1 -0
- package/dist/daemon/types.cjs +17 -0
- package/dist/daemon/types.cjs.map +1 -1
- package/dist/daemon/types.d.cts +58 -7
- package/dist/daemon/types.d.cts.map +1 -1
- package/dist/daemon/types.d.mts +58 -7
- package/dist/daemon/types.d.mts.map +1 -1
- package/dist/daemon/types.mjs +15 -1
- package/dist/daemon/types.mjs.map +1 -1
- package/dist/daemon/utils.cjs +14 -2
- package/dist/daemon/utils.cjs.map +1 -1
- package/dist/daemon/utils.d.cts +9 -0
- package/dist/daemon/utils.d.cts.map +1 -1
- package/dist/daemon/utils.d.mts +9 -0
- package/dist/daemon/utils.d.mts.map +1 -1
- package/dist/daemon/utils.mjs +12 -1
- package/dist/daemon/utils.mjs.map +1 -1
- package/dist/daemon/wallet-factory.cjs +50 -8
- package/dist/daemon/wallet-factory.cjs.map +1 -1
- package/dist/daemon/wallet-factory.d.cts +17 -8
- package/dist/daemon/wallet-factory.d.cts.map +1 -1
- package/dist/daemon/wallet-factory.d.mts +17 -8
- package/dist/daemon/wallet-factory.d.mts.map +1 -1
- package/dist/daemon/wallet-factory.mjs +50 -8
- package/dist/daemon/wallet-factory.mjs.map +1 -1
- package/package.json +7 -2
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _Password_value, _Srp_value;
|
|
13
|
+
import { validateMnemonic } from "@metamask/scure-bip39";
|
|
14
|
+
import { wordlist } from "@metamask/scure-bip39/dist/wordlists/english.js";
|
|
15
|
+
const REDACTED = '[redacted]';
|
|
16
|
+
const VALID_SRP_WORD_COUNTS = [12, 15, 18, 21, 24];
|
|
17
|
+
const INSPECT_CUSTOM = Symbol.for('nodejs.util.inspect.custom');
|
|
18
|
+
const WORDLIST_SET = new Set(wordlist);
|
|
19
|
+
/**
|
|
20
|
+
* Opaque wrapper around a wallet password.
|
|
21
|
+
*
|
|
22
|
+
* Constructed via {@link Password.from}, which validates the input. The
|
|
23
|
+
* underlying string is only reachable through {@link Password.unwrap}; every
|
|
24
|
+
* other path (`toString`, `JSON.stringify`, `util.inspect`, template-literal
|
|
25
|
+
* interpolation) yields `[redacted]`. This makes accidental logging produce a
|
|
26
|
+
* harmless placeholder instead of leaking the secret.
|
|
27
|
+
*/
|
|
28
|
+
export class Password {
|
|
29
|
+
// See .from() for why this is private.
|
|
30
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
31
|
+
constructor(value) {
|
|
32
|
+
_Password_value.set(this, void 0);
|
|
33
|
+
__classPrivateFieldSet(this, _Password_value, value, "f");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Wrap a non-empty string as a {@link Password}.
|
|
37
|
+
*
|
|
38
|
+
* Matches the `@metamask/keyring-controller` convention: any non-empty
|
|
39
|
+
* string is acceptable; minimum-length policy is left to the keyring.
|
|
40
|
+
*
|
|
41
|
+
* @param value - The raw password string.
|
|
42
|
+
* @returns A redacting {@link Password} wrapper.
|
|
43
|
+
* @throws If `value` is empty.
|
|
44
|
+
*/
|
|
45
|
+
static from(value) {
|
|
46
|
+
if (value.length === 0) {
|
|
47
|
+
throw new Error('Password must be a non-empty string');
|
|
48
|
+
}
|
|
49
|
+
return new Password(value);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reveal the underlying password string. Call this only at trust boundaries
|
|
53
|
+
* (e.g. handing the value to the keyring or to a child-process env var).
|
|
54
|
+
*
|
|
55
|
+
* @returns The original password string.
|
|
56
|
+
*/
|
|
57
|
+
unwrap() {
|
|
58
|
+
return __classPrivateFieldGet(this, _Password_value, "f");
|
|
59
|
+
}
|
|
60
|
+
toString() {
|
|
61
|
+
return REDACTED;
|
|
62
|
+
}
|
|
63
|
+
toJSON() {
|
|
64
|
+
return REDACTED;
|
|
65
|
+
}
|
|
66
|
+
[(_Password_value = new WeakMap(), INSPECT_CUSTOM)]() {
|
|
67
|
+
return REDACTED;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Opaque wrapper around a BIP-39 secret recovery phrase.
|
|
72
|
+
*
|
|
73
|
+
* Constructed via {@link Srp.from}, which validates the word count
|
|
74
|
+
* (12/15/18/21/24) and that every word is present in the BIP-39 English
|
|
75
|
+
* wordlist. The underlying string is only reachable through {@link Srp.unwrap};
|
|
76
|
+
* every other path yields `[redacted]`.
|
|
77
|
+
*/
|
|
78
|
+
export class Srp {
|
|
79
|
+
// See .from() for why this is private.
|
|
80
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
81
|
+
constructor(value) {
|
|
82
|
+
_Srp_value.set(this, void 0);
|
|
83
|
+
__classPrivateFieldSet(this, _Srp_value, value, "f");
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Validate and wrap a BIP-39 mnemonic phrase.
|
|
87
|
+
*
|
|
88
|
+
* Whitespace is normalized (trimmed and collapsed) before validation so that
|
|
89
|
+
* copy-pasted phrases with accidental leading/trailing/extra spaces are
|
|
90
|
+
* accepted. Catching malformed input here (rather than letting it reach
|
|
91
|
+
* `KeyringController:createNewVaultAndRestore`) produces a clearer error.
|
|
92
|
+
*
|
|
93
|
+
* @param value - The raw mnemonic string.
|
|
94
|
+
* @returns A redacting {@link Srp} wrapper containing the normalized phrase.
|
|
95
|
+
* @throws If the word count is not one of 12/15/18/21/24, if any word is
|
|
96
|
+
* not present in the BIP-39 English wordlist, or if the checksum is invalid.
|
|
97
|
+
*/
|
|
98
|
+
static from(value) {
|
|
99
|
+
const words = value.trim().split(/\s+/u);
|
|
100
|
+
if (!VALID_SRP_WORD_COUNTS.includes(words.length)) {
|
|
101
|
+
throw new Error(`Secret recovery phrase must be 12, 15, 18, 21, or 24 words (got ${words.length})`);
|
|
102
|
+
}
|
|
103
|
+
for (const word of words) {
|
|
104
|
+
if (!WORDLIST_SET.has(word)) {
|
|
105
|
+
throw new Error('Secret recovery phrase contains a word not in the BIP-39 English wordlist');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const normalized = words.join(' ');
|
|
109
|
+
if (!validateMnemonic(normalized, wordlist)) {
|
|
110
|
+
throw new Error('Secret recovery phrase has an invalid checksum');
|
|
111
|
+
}
|
|
112
|
+
return new Srp(normalized);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Reveal the underlying mnemonic string. Call this only at trust boundaries.
|
|
116
|
+
*
|
|
117
|
+
* @returns The original mnemonic string.
|
|
118
|
+
*/
|
|
119
|
+
unwrap() {
|
|
120
|
+
return __classPrivateFieldGet(this, _Srp_value, "f");
|
|
121
|
+
}
|
|
122
|
+
toString() {
|
|
123
|
+
return REDACTED;
|
|
124
|
+
}
|
|
125
|
+
toJSON() {
|
|
126
|
+
return REDACTED;
|
|
127
|
+
}
|
|
128
|
+
[(_Srp_value = new WeakMap(), INSPECT_CUSTOM)]() {
|
|
129
|
+
return REDACTED;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=secrets.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.mjs","sourceRoot":"","sources":["../../src/daemon/secrets.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,gBAAgB,EAAE,8BAA8B;AACzD,OAAO,EAAE,QAAQ,EAAE,wDAAqD;AAExE,MAAM,QAAQ,GAAG,YAAY,CAAC;AAE9B,MAAM,qBAAqB,GAAsB,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAEtE,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAEhE,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;AAE5D;;;;;;;;GAQG;AACH,MAAM,OAAO,QAAQ;IAGnB,uCAAuC;IACvC,gDAAgD;IAChD,YAAoB,KAAa;QAJxB,kCAAe;QAKtB,uBAAA,IAAI,mBAAU,KAAK,MAAA,CAAC;IACtB,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,CAAC,KAAa;QACvB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,IAAI,QAAQ,CAAC,KAAK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,kBAAO,CAAC;IACrB,CAAC;IAED,QAAQ;QACN,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM;QACJ,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,8BAAC,cAAc,EAAC;QACd,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["import { validateMnemonic } from '@metamask/scure-bip39';\nimport { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';\n\nconst REDACTED = '[redacted]';\n\nconst VALID_SRP_WORD_COUNTS: readonly number[] = [12, 15, 18, 21, 24];\n\nconst INSPECT_CUSTOM = Symbol.for('nodejs.util.inspect.custom');\n\nconst WORDLIST_SET: ReadonlySet<string> = new Set(wordlist);\n\n/**\n * Opaque wrapper around a wallet password.\n *\n * Constructed via {@link Password.from}, which validates the input. The\n * underlying string is only reachable through {@link Password.unwrap}; every\n * other path (`toString`, `JSON.stringify`, `util.inspect`, template-literal\n * interpolation) yields `[redacted]`. This makes accidental logging produce a\n * harmless placeholder instead of leaking the secret.\n */\nexport class Password {\n readonly #value: string;\n\n // See .from() for why this is private.\n // eslint-disable-next-line no-restricted-syntax\n private constructor(value: string) {\n this.#value = value;\n }\n\n /**\n * Wrap a non-empty string as a {@link Password}.\n *\n * Matches the `@metamask/keyring-controller` convention: any non-empty\n * string is acceptable; minimum-length policy is left to the keyring.\n *\n * @param value - The raw password string.\n * @returns A redacting {@link Password} wrapper.\n * @throws If `value` is empty.\n */\n static from(value: string): Password {\n if (value.length === 0) {\n throw new Error('Password must be a non-empty string');\n }\n return new Password(value);\n }\n\n /**\n * Reveal the underlying password string. Call this only at trust boundaries\n * (e.g. handing the value to the keyring or to a child-process env var).\n *\n * @returns The original password string.\n */\n unwrap(): string {\n return this.#value;\n }\n\n toString(): string {\n return REDACTED;\n }\n\n toJSON(): string {\n return REDACTED;\n }\n\n [INSPECT_CUSTOM](): string {\n return REDACTED;\n }\n}\n\n/**\n * Opaque wrapper around a BIP-39 secret recovery phrase.\n *\n * Constructed via {@link Srp.from}, which validates the word count\n * (12/15/18/21/24) and that every word is present in the BIP-39 English\n * wordlist. The underlying string is only reachable through {@link Srp.unwrap};\n * every other path yields `[redacted]`.\n */\nexport class Srp {\n readonly #value: string;\n\n // See .from() for why this is private.\n // eslint-disable-next-line no-restricted-syntax\n private constructor(value: string) {\n this.#value = value;\n }\n\n /**\n * Validate and wrap a BIP-39 mnemonic phrase.\n *\n * Whitespace is normalized (trimmed and collapsed) before validation so that\n * copy-pasted phrases with accidental leading/trailing/extra spaces are\n * accepted. Catching malformed input here (rather than letting it reach\n * `KeyringController:createNewVaultAndRestore`) produces a clearer error.\n *\n * @param value - The raw mnemonic string.\n * @returns A redacting {@link Srp} wrapper containing the normalized phrase.\n * @throws If the word count is not one of 12/15/18/21/24, if any word is\n * not present in the BIP-39 English wordlist, or if the checksum is invalid.\n */\n static from(value: string): Srp {\n const words = value.trim().split(/\\s+/u);\n if (!VALID_SRP_WORD_COUNTS.includes(words.length)) {\n throw new Error(\n `Secret recovery phrase must be 12, 15, 18, 21, or 24 words (got ${words.length})`,\n );\n }\n for (const word of words) {\n if (!WORDLIST_SET.has(word)) {\n throw new Error(\n 'Secret recovery phrase contains a word not in the BIP-39 English wordlist',\n );\n }\n }\n\n const normalized = words.join(' ');\n if (!validateMnemonic(normalized, wordlist)) {\n throw new Error('Secret recovery phrase has an invalid checksum');\n }\n return new Srp(normalized);\n }\n\n /**\n * Reveal the underlying mnemonic string. Call this only at trust boundaries.\n *\n * @returns The original mnemonic string.\n */\n unwrap(): string {\n return this.#value;\n }\n\n toString(): string {\n return REDACTED;\n }\n\n toJSON(): string {\n return REDACTED;\n }\n\n [INSPECT_CUSTOM](): string {\n return REDACTED;\n }\n}\n"]}
|
package/dist/daemon/types.cjs
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineHandler = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Bundle a params struct with the handler that runs once `params` is
|
|
6
|
+
* validated. The server invokes `run` only after `paramsStruct` accepts the
|
|
7
|
+
* value, so `run` can trust the type of its argument.
|
|
8
|
+
*
|
|
9
|
+
* The returned definition erases `TParams` to `unknown` so heterogeneous
|
|
10
|
+
* handlers can share an {@link RpcHandlerMap}.
|
|
11
|
+
*
|
|
12
|
+
* @param paramsStruct - Struct that validates `params` for this method.
|
|
13
|
+
* @param run - Handler invoked with the validated params.
|
|
14
|
+
* @returns An {@link RpcHandlerDefinition} suitable for an {@link RpcHandlerMap}.
|
|
15
|
+
*/
|
|
16
|
+
function defineHandler(paramsStruct, run) {
|
|
17
|
+
return { paramsStruct, run };
|
|
18
|
+
}
|
|
19
|
+
exports.defineHandler = defineHandler;
|
|
3
20
|
//# sourceMappingURL=types.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/daemon/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json } from '@metamask/utils';\n\n/**\n * Sink for daemon diagnostic messages. A backgrounded daemon's stdio may be\n * discarded, so hosts supply a logger that writes somewhere durable.\n */\nexport type Logger = (message: string) => void;\n\n/**\n * A function that handles a JSON-RPC method call.\n *\n * The `
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/daemon/types.ts"],"names":[],"mappings":";;;AAiDA;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAC3B,YAA6B,EAC7B,GAAiC;IAEjC,OAAO,EAAE,YAAY,EAAE,GAAG,EAGzB,CAAC;AACJ,CAAC;AARD,sCAQC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\n\nimport type { Password, Srp } from './secrets';\n\n/**\n * Sink for daemon diagnostic messages. A backgrounded daemon's stdio may be\n * discarded, so hosts supply a logger that writes somewhere durable.\n */\nexport type Logger = (message: string) => void;\n\n/**\n * A function that handles a JSON-RPC method call after its params have been\n * validated by the corresponding {@link RpcHandlerDefinition.paramsStruct}.\n */\nexport type RpcHandler<TParams, TResult> = (\n params: TParams,\n) => Promise<TResult>;\n\n/**\n * Definition for a single JSON-RPC method: the struct that validates\n * incoming `params` plus the handler that runs once `params` is known to\n * match.\n *\n * The server (see `rpc-socket-server.ts`) validates the raw `params` against\n * `paramsStruct` before invoking `run`, so each handler body can trust the\n * shape of its input without re-checking.\n */\nexport type RpcHandlerDefinition<TParams, TResult extends Json | void> = {\n paramsStruct: Struct<TParams>;\n run: RpcHandler<TParams, TResult>;\n};\n\n/**\n * A map of RPC method names to their handler definitions.\n *\n * `TParams` is erased to `unknown` here so definitions with different narrow\n * params types (e.g. `null` vs. a tuple) can coexist in the same map. Consumers\n * therefore see each `run` as accepting `unknown` and must validate `params`\n * against the paired `paramsStruct` before invoking it — which is exactly what\n * the server (see `rpc-socket-server.ts`) does. The concrete `TParams` is\n * captured inside {@link defineHandler}, where the struct and handler are bound\n * together.\n */\nexport type RpcHandlerMap = Record<\n string,\n RpcHandlerDefinition<unknown, Json | void>\n>;\n\n/**\n * Bundle a params struct with the handler that runs once `params` is\n * validated. The server invokes `run` only after `paramsStruct` accepts the\n * value, so `run` can trust the type of its argument.\n *\n * The returned definition erases `TParams` to `unknown` so heterogeneous\n * handlers can share an {@link RpcHandlerMap}.\n *\n * @param paramsStruct - Struct that validates `params` for this method.\n * @param run - Handler invoked with the validated params.\n * @returns An {@link RpcHandlerDefinition} suitable for an {@link RpcHandlerMap}.\n */\nexport function defineHandler<TParams, TResult extends Json | void>(\n paramsStruct: Struct<TParams>,\n run: RpcHandler<TParams, TResult>,\n): RpcHandlerDefinition<unknown, TResult> {\n return { paramsStruct, run } as unknown as RpcHandlerDefinition<\n unknown,\n TResult\n >;\n}\n\n/**\n * Typed wrapper around `wallet.messenger.call` used by the `call` RPC.\n *\n * The messenger is strongly typed by action name; the daemon exposes the full\n * messenger surface over the socket and dispatches by string, so we consolidate\n * the unsafe cast into a single, documented escape hatch instead of repeating\n * it at each call site.\n */\nexport type RpcDispatcher = (action: string, ...args: Json[]) => Promise<Json>;\n\n/**\n * Resolved paths for daemon state files.\n */\nexport type DaemonPaths = {\n socketPath: string;\n pidPath: string;\n logPath: string;\n dbPath: string;\n};\n\n/**\n * Status information returned by the daemon's `getStatus` RPC method.\n */\nexport type DaemonStatusInfo = {\n pid: number;\n uptime: number;\n};\n\n/**\n * Configuration passed to the daemon spawner.\n *\n * `password` is optional: when omitted, the daemon starts without unlocking\n * the keyring, and the caller is expected to use `mm wallet unlock` before\n * any keyring-bound operation. First-run startup still requires both\n * `password` and `srp`; without `password`, the daemon will exit during\n * startup with a clear error. `srp` is always required by the type and\n * forwarded to the daemon; it is only consumed on first run.\n */\nexport type DaemonSpawnConfig = {\n dataDir: string;\n infuraProjectId: string;\n password?: Password;\n srp: Srp;\n packageRoot: string;\n};\n"]}
|
package/dist/daemon/types.d.cts
CHANGED
|
@@ -1,19 +1,63 @@
|
|
|
1
|
+
import type { Struct } from "@metamask/superstruct";
|
|
1
2
|
import type { Json } from "@metamask/utils";
|
|
3
|
+
import type { Password, Srp } from "./secrets.cjs";
|
|
2
4
|
/**
|
|
3
5
|
* Sink for daemon diagnostic messages. A backgrounded daemon's stdio may be
|
|
4
6
|
* discarded, so hosts supply a logger that writes somewhere durable.
|
|
5
7
|
*/
|
|
6
8
|
export type Logger = (message: string) => void;
|
|
7
9
|
/**
|
|
8
|
-
* A function that handles a JSON-RPC method call
|
|
10
|
+
* A function that handles a JSON-RPC method call after its params have been
|
|
11
|
+
* validated by the corresponding {@link RpcHandlerDefinition.paramsStruct}.
|
|
12
|
+
*/
|
|
13
|
+
export type RpcHandler<TParams, TResult> = (params: TParams) => Promise<TResult>;
|
|
14
|
+
/**
|
|
15
|
+
* Definition for a single JSON-RPC method: the struct that validates
|
|
16
|
+
* incoming `params` plus the handler that runs once `params` is known to
|
|
17
|
+
* match.
|
|
18
|
+
*
|
|
19
|
+
* The server (see `rpc-socket-server.ts`) validates the raw `params` against
|
|
20
|
+
* `paramsStruct` before invoking `run`, so each handler body can trust the
|
|
21
|
+
* shape of its input without re-checking.
|
|
22
|
+
*/
|
|
23
|
+
export type RpcHandlerDefinition<TParams, TResult extends Json | void> = {
|
|
24
|
+
paramsStruct: Struct<TParams>;
|
|
25
|
+
run: RpcHandler<TParams, TResult>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A map of RPC method names to their handler definitions.
|
|
9
29
|
*
|
|
10
|
-
*
|
|
30
|
+
* `TParams` is erased to `unknown` here so definitions with different narrow
|
|
31
|
+
* params types (e.g. `null` vs. a tuple) can coexist in the same map. Consumers
|
|
32
|
+
* therefore see each `run` as accepting `unknown` and must validate `params`
|
|
33
|
+
* against the paired `paramsStruct` before invoking it — which is exactly what
|
|
34
|
+
* the server (see `rpc-socket-server.ts`) does. The concrete `TParams` is
|
|
35
|
+
* captured inside {@link defineHandler}, where the struct and handler are bound
|
|
36
|
+
* together.
|
|
11
37
|
*/
|
|
12
|
-
export type
|
|
38
|
+
export type RpcHandlerMap = Record<string, RpcHandlerDefinition<unknown, Json | void>>;
|
|
13
39
|
/**
|
|
14
|
-
*
|
|
40
|
+
* Bundle a params struct with the handler that runs once `params` is
|
|
41
|
+
* validated. The server invokes `run` only after `paramsStruct` accepts the
|
|
42
|
+
* value, so `run` can trust the type of its argument.
|
|
43
|
+
*
|
|
44
|
+
* The returned definition erases `TParams` to `unknown` so heterogeneous
|
|
45
|
+
* handlers can share an {@link RpcHandlerMap}.
|
|
46
|
+
*
|
|
47
|
+
* @param paramsStruct - Struct that validates `params` for this method.
|
|
48
|
+
* @param run - Handler invoked with the validated params.
|
|
49
|
+
* @returns An {@link RpcHandlerDefinition} suitable for an {@link RpcHandlerMap}.
|
|
50
|
+
*/
|
|
51
|
+
export declare function defineHandler<TParams, TResult extends Json | void>(paramsStruct: Struct<TParams>, run: RpcHandler<TParams, TResult>): RpcHandlerDefinition<unknown, TResult>;
|
|
52
|
+
/**
|
|
53
|
+
* Typed wrapper around `wallet.messenger.call` used by the `call` RPC.
|
|
54
|
+
*
|
|
55
|
+
* The messenger is strongly typed by action name; the daemon exposes the full
|
|
56
|
+
* messenger surface over the socket and dispatches by string, so we consolidate
|
|
57
|
+
* the unsafe cast into a single, documented escape hatch instead of repeating
|
|
58
|
+
* it at each call site.
|
|
15
59
|
*/
|
|
16
|
-
export type
|
|
60
|
+
export type RpcDispatcher = (action: string, ...args: Json[]) => Promise<Json>;
|
|
17
61
|
/**
|
|
18
62
|
* Resolved paths for daemon state files.
|
|
19
63
|
*/
|
|
@@ -32,12 +76,19 @@ export type DaemonStatusInfo = {
|
|
|
32
76
|
};
|
|
33
77
|
/**
|
|
34
78
|
* Configuration passed to the daemon spawner.
|
|
79
|
+
*
|
|
80
|
+
* `password` is optional: when omitted, the daemon starts without unlocking
|
|
81
|
+
* the keyring, and the caller is expected to use `mm wallet unlock` before
|
|
82
|
+
* any keyring-bound operation. First-run startup still requires both
|
|
83
|
+
* `password` and `srp`; without `password`, the daemon will exit during
|
|
84
|
+
* startup with a clear error. `srp` is always required by the type and
|
|
85
|
+
* forwarded to the daemon; it is only consumed on first run.
|
|
35
86
|
*/
|
|
36
87
|
export type DaemonSpawnConfig = {
|
|
37
88
|
dataDir: string;
|
|
38
89
|
infuraProjectId: string;
|
|
39
|
-
password
|
|
40
|
-
srp:
|
|
90
|
+
password?: Password;
|
|
91
|
+
srp: Srp;
|
|
41
92
|
packageRoot: string;
|
|
42
93
|
};
|
|
43
94
|
//# sourceMappingURL=types.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/daemon/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAE/C
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../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,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,GAAG,EAAE,GAAG,CAAC;IACT,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC"}
|
package/dist/daemon/types.d.mts
CHANGED
|
@@ -1,19 +1,63 @@
|
|
|
1
|
+
import type { Struct } from "@metamask/superstruct";
|
|
1
2
|
import type { Json } from "@metamask/utils";
|
|
3
|
+
import type { Password, Srp } from "./secrets.mjs";
|
|
2
4
|
/**
|
|
3
5
|
* Sink for daemon diagnostic messages. A backgrounded daemon's stdio may be
|
|
4
6
|
* discarded, so hosts supply a logger that writes somewhere durable.
|
|
5
7
|
*/
|
|
6
8
|
export type Logger = (message: string) => void;
|
|
7
9
|
/**
|
|
8
|
-
* A function that handles a JSON-RPC method call
|
|
10
|
+
* A function that handles a JSON-RPC method call after its params have been
|
|
11
|
+
* validated by the corresponding {@link RpcHandlerDefinition.paramsStruct}.
|
|
12
|
+
*/
|
|
13
|
+
export type RpcHandler<TParams, TResult> = (params: TParams) => Promise<TResult>;
|
|
14
|
+
/**
|
|
15
|
+
* Definition for a single JSON-RPC method: the struct that validates
|
|
16
|
+
* incoming `params` plus the handler that runs once `params` is known to
|
|
17
|
+
* match.
|
|
18
|
+
*
|
|
19
|
+
* The server (see `rpc-socket-server.ts`) validates the raw `params` against
|
|
20
|
+
* `paramsStruct` before invoking `run`, so each handler body can trust the
|
|
21
|
+
* shape of its input without re-checking.
|
|
22
|
+
*/
|
|
23
|
+
export type RpcHandlerDefinition<TParams, TResult extends Json | void> = {
|
|
24
|
+
paramsStruct: Struct<TParams>;
|
|
25
|
+
run: RpcHandler<TParams, TResult>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A map of RPC method names to their handler definitions.
|
|
9
29
|
*
|
|
10
|
-
*
|
|
30
|
+
* `TParams` is erased to `unknown` here so definitions with different narrow
|
|
31
|
+
* params types (e.g. `null` vs. a tuple) can coexist in the same map. Consumers
|
|
32
|
+
* therefore see each `run` as accepting `unknown` and must validate `params`
|
|
33
|
+
* against the paired `paramsStruct` before invoking it — which is exactly what
|
|
34
|
+
* the server (see `rpc-socket-server.ts`) does. The concrete `TParams` is
|
|
35
|
+
* captured inside {@link defineHandler}, where the struct and handler are bound
|
|
36
|
+
* together.
|
|
11
37
|
*/
|
|
12
|
-
export type
|
|
38
|
+
export type RpcHandlerMap = Record<string, RpcHandlerDefinition<unknown, Json | void>>;
|
|
13
39
|
/**
|
|
14
|
-
*
|
|
40
|
+
* Bundle a params struct with the handler that runs once `params` is
|
|
41
|
+
* validated. The server invokes `run` only after `paramsStruct` accepts the
|
|
42
|
+
* value, so `run` can trust the type of its argument.
|
|
43
|
+
*
|
|
44
|
+
* The returned definition erases `TParams` to `unknown` so heterogeneous
|
|
45
|
+
* handlers can share an {@link RpcHandlerMap}.
|
|
46
|
+
*
|
|
47
|
+
* @param paramsStruct - Struct that validates `params` for this method.
|
|
48
|
+
* @param run - Handler invoked with the validated params.
|
|
49
|
+
* @returns An {@link RpcHandlerDefinition} suitable for an {@link RpcHandlerMap}.
|
|
50
|
+
*/
|
|
51
|
+
export declare function defineHandler<TParams, TResult extends Json | void>(paramsStruct: Struct<TParams>, run: RpcHandler<TParams, TResult>): RpcHandlerDefinition<unknown, TResult>;
|
|
52
|
+
/**
|
|
53
|
+
* Typed wrapper around `wallet.messenger.call` used by the `call` RPC.
|
|
54
|
+
*
|
|
55
|
+
* The messenger is strongly typed by action name; the daemon exposes the full
|
|
56
|
+
* messenger surface over the socket and dispatches by string, so we consolidate
|
|
57
|
+
* the unsafe cast into a single, documented escape hatch instead of repeating
|
|
58
|
+
* it at each call site.
|
|
15
59
|
*/
|
|
16
|
-
export type
|
|
60
|
+
export type RpcDispatcher = (action: string, ...args: Json[]) => Promise<Json>;
|
|
17
61
|
/**
|
|
18
62
|
* Resolved paths for daemon state files.
|
|
19
63
|
*/
|
|
@@ -32,12 +76,19 @@ export type DaemonStatusInfo = {
|
|
|
32
76
|
};
|
|
33
77
|
/**
|
|
34
78
|
* Configuration passed to the daemon spawner.
|
|
79
|
+
*
|
|
80
|
+
* `password` is optional: when omitted, the daemon starts without unlocking
|
|
81
|
+
* the keyring, and the caller is expected to use `mm wallet unlock` before
|
|
82
|
+
* any keyring-bound operation. First-run startup still requires both
|
|
83
|
+
* `password` and `srp`; without `password`, the daemon will exit during
|
|
84
|
+
* startup with a clear error. `srp` is always required by the type and
|
|
85
|
+
* forwarded to the daemon; it is only consumed on first run.
|
|
35
86
|
*/
|
|
36
87
|
export type DaemonSpawnConfig = {
|
|
37
88
|
dataDir: string;
|
|
38
89
|
infuraProjectId: string;
|
|
39
|
-
password
|
|
40
|
-
srp:
|
|
90
|
+
password?: Password;
|
|
91
|
+
srp: Srp;
|
|
41
92
|
packageRoot: string;
|
|
42
93
|
};
|
|
43
94
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/daemon/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAE/C
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/daemon/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,8BAA8B;AACpD,OAAO,KAAK,EAAE,IAAI,EAAE,w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gBAAgB,GAAG;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,GAAG,EAAE,GAAG,CAAC;IACT,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC"}
|
package/dist/daemon/types.mjs
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Bundle a params struct with the handler that runs once `params` is
|
|
3
|
+
* validated. The server invokes `run` only after `paramsStruct` accepts the
|
|
4
|
+
* value, so `run` can trust the type of its argument.
|
|
5
|
+
*
|
|
6
|
+
* The returned definition erases `TParams` to `unknown` so heterogeneous
|
|
7
|
+
* handlers can share an {@link RpcHandlerMap}.
|
|
8
|
+
*
|
|
9
|
+
* @param paramsStruct - Struct that validates `params` for this method.
|
|
10
|
+
* @param run - Handler invoked with the validated params.
|
|
11
|
+
* @returns An {@link RpcHandlerDefinition} suitable for an {@link RpcHandlerMap}.
|
|
12
|
+
*/
|
|
13
|
+
export function defineHandler(paramsStruct, run) {
|
|
14
|
+
return { paramsStruct, run };
|
|
15
|
+
}
|
|
2
16
|
//# sourceMappingURL=types.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/daemon/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json } from '@metamask/utils';\n\n/**\n * Sink for daemon diagnostic messages. A backgrounded daemon's stdio may be\n * discarded, so hosts supply a logger that writes somewhere durable.\n */\nexport type Logger = (message: string) => void;\n\n/**\n * A function that handles a JSON-RPC method call.\n *\n * The `
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/daemon/types.ts"],"names":[],"mappings":"AAiDA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAC3B,YAA6B,EAC7B,GAAiC;IAEjC,OAAO,EAAE,YAAY,EAAE,GAAG,EAGzB,CAAC;AACJ,CAAC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\n\nimport type { Password, Srp } from './secrets';\n\n/**\n * Sink for daemon diagnostic messages. A backgrounded daemon's stdio may be\n * discarded, so hosts supply a logger that writes somewhere durable.\n */\nexport type Logger = (message: string) => void;\n\n/**\n * A function that handles a JSON-RPC method call after its params have been\n * validated by the corresponding {@link RpcHandlerDefinition.paramsStruct}.\n */\nexport type RpcHandler<TParams, TResult> = (\n params: TParams,\n) => Promise<TResult>;\n\n/**\n * Definition for a single JSON-RPC method: the struct that validates\n * incoming `params` plus the handler that runs once `params` is known to\n * match.\n *\n * The server (see `rpc-socket-server.ts`) validates the raw `params` against\n * `paramsStruct` before invoking `run`, so each handler body can trust the\n * shape of its input without re-checking.\n */\nexport type RpcHandlerDefinition<TParams, TResult extends Json | void> = {\n paramsStruct: Struct<TParams>;\n run: RpcHandler<TParams, TResult>;\n};\n\n/**\n * A map of RPC method names to their handler definitions.\n *\n * `TParams` is erased to `unknown` here so definitions with different narrow\n * params types (e.g. `null` vs. a tuple) can coexist in the same map. Consumers\n * therefore see each `run` as accepting `unknown` and must validate `params`\n * against the paired `paramsStruct` before invoking it — which is exactly what\n * the server (see `rpc-socket-server.ts`) does. The concrete `TParams` is\n * captured inside {@link defineHandler}, where the struct and handler are bound\n * together.\n */\nexport type RpcHandlerMap = Record<\n string,\n RpcHandlerDefinition<unknown, Json | void>\n>;\n\n/**\n * Bundle a params struct with the handler that runs once `params` is\n * validated. The server invokes `run` only after `paramsStruct` accepts the\n * value, so `run` can trust the type of its argument.\n *\n * The returned definition erases `TParams` to `unknown` so heterogeneous\n * handlers can share an {@link RpcHandlerMap}.\n *\n * @param paramsStruct - Struct that validates `params` for this method.\n * @param run - Handler invoked with the validated params.\n * @returns An {@link RpcHandlerDefinition} suitable for an {@link RpcHandlerMap}.\n */\nexport function defineHandler<TParams, TResult extends Json | void>(\n paramsStruct: Struct<TParams>,\n run: RpcHandler<TParams, TResult>,\n): RpcHandlerDefinition<unknown, TResult> {\n return { paramsStruct, run } as unknown as RpcHandlerDefinition<\n unknown,\n TResult\n >;\n}\n\n/**\n * Typed wrapper around `wallet.messenger.call` used by the `call` RPC.\n *\n * The messenger is strongly typed by action name; the daemon exposes the full\n * messenger surface over the socket and dispatches by string, so we consolidate\n * the unsafe cast into a single, documented escape hatch instead of repeating\n * it at each call site.\n */\nexport type RpcDispatcher = (action: string, ...args: Json[]) => Promise<Json>;\n\n/**\n * Resolved paths for daemon state files.\n */\nexport type DaemonPaths = {\n socketPath: string;\n pidPath: string;\n logPath: string;\n dbPath: string;\n};\n\n/**\n * Status information returned by the daemon's `getStatus` RPC method.\n */\nexport type DaemonStatusInfo = {\n pid: number;\n uptime: number;\n};\n\n/**\n * Configuration passed to the daemon spawner.\n *\n * `password` is optional: when omitted, the daemon starts without unlocking\n * the keyring, and the caller is expected to use `mm wallet unlock` before\n * any keyring-bound operation. First-run startup still requires both\n * `password` and `srp`; without `password`, the daemon will exit during\n * startup with a clear error. `srp` is always required by the type and\n * forwarded to the daemon; it is only consumed on first run.\n */\nexport type DaemonSpawnConfig = {\n dataDir: string;\n infuraProjectId: string;\n password?: Password;\n srp: Srp;\n packageRoot: string;\n};\n"]}
|
package/dist/daemon/utils.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.waitFor = exports.sendSignal = exports.isProcessAlive = exports.readPidFile = exports.isStringArray = exports.formatJsonRpcError = exports.makeDaemonConnectionError = exports.isErrorWithCode = void 0;
|
|
3
|
+
exports.waitFor = exports.sendSignal = exports.isProcessAlive = exports.readPidFile = exports.isStringArray = exports.emptyToUndefined = exports.formatJsonRpcError = exports.makeDaemonConnectionError = exports.isErrorWithCode = void 0;
|
|
4
4
|
const utils_1 = require("@metamask/utils");
|
|
5
5
|
const promises_1 = require("node:fs/promises");
|
|
6
6
|
/**
|
|
@@ -37,7 +37,7 @@ function makeDaemonConnectionError(error) {
|
|
|
37
37
|
}
|
|
38
38
|
if (isErrorWithCode(error, 'EACCES') || isErrorWithCode(error, 'EPERM')) {
|
|
39
39
|
return ('Cannot connect to the daemon socket: permission denied. ' +
|
|
40
|
-
'The socket may be owned by another user, or
|
|
40
|
+
'The socket may be owned by another user, or MM_DAEMON_DATA_DIR ' +
|
|
41
41
|
'may point to a directory you cannot access.');
|
|
42
42
|
}
|
|
43
43
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -54,6 +54,18 @@ function formatJsonRpcError(error) {
|
|
|
54
54
|
return `${error.message} (code ${String(error.code)})`;
|
|
55
55
|
}
|
|
56
56
|
exports.formatJsonRpcError = formatJsonRpcError;
|
|
57
|
+
/**
|
|
58
|
+
* Treat an empty string the same as `undefined` — "no value supplied". Used
|
|
59
|
+
* to normalise `--password ''` and `MM_WALLET_PASSWORD=''` so they trigger
|
|
60
|
+
* the interactive prompt rather than sending an empty string to the keyring.
|
|
61
|
+
*
|
|
62
|
+
* @param value - The value to normalise.
|
|
63
|
+
* @returns `undefined` if `value` is `undefined` or `''`; `value` otherwise.
|
|
64
|
+
*/
|
|
65
|
+
function emptyToUndefined(value) {
|
|
66
|
+
return value === '' ? undefined : value;
|
|
67
|
+
}
|
|
68
|
+
exports.emptyToUndefined = emptyToUndefined;
|
|
57
69
|
/**
|
|
58
70
|
* Check whether a value is an array of strings. Used to validate untyped RPC
|
|
59
71
|
* results (e.g. the daemon's `listActions`) before treating them as `string[]`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/daemon/utils.ts"],"names":[],"mappings":";;;AACA,2CAAkE;AAClE,+CAA4C;AAE5C;;;;;;GAMG;AACH,SAAgB,eA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AS,CAAC;IACxC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC7B,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAZD,0BAYC","sourcesContent":["import type { JsonRpcError } from '@metamask/utils';\nimport { isErrorWithCode as hasErrorCode } from '@metamask/utils';\nimport { readFile } from 'node:fs/promises';\n\n/**\n * Check whether an unknown error is a Node.js system error with the given code.\n *\n * @param error - The error to check.\n * @param code - The expected error code (e.g. 'ENOENT', 'EPERM').\n * @returns True if the error matches the code.\n */\nexport function isErrorWithCode(error: unknown, code: string): boolean {\n return hasErrorCode(error) && error.code === code;\n}\n\n/**\n * Turn an error thrown while contacting the daemon socket into a user-facing\n * message for `Command.error`, so every command reports the same failure the\n * same way. Distinguishes a stopped daemon (`ENOENT`/`ECONNREFUSED`), a\n * connection dropped mid-request (`ECONNRESET`), and a permission problem\n * (`EACCES`/`EPERM`), falling back to the raw error message.\n *\n * @param error - The value thrown while contacting the daemon.\n * @returns A human-readable explanation of the failure.\n */\nexport function makeDaemonConnectionError(error: unknown): string {\n if (\n isErrorWithCode(error, 'ENOENT') ||\n isErrorWithCode(error, 'ECONNREFUSED')\n ) {\n return 'Daemon is not running. Start it with `mm daemon start`.';\n }\n // A reset drops an already-established connection, so the daemon was running\n // — most likely it crashed mid-request. Don't tell the user to start it.\n if (isErrorWithCode(error, 'ECONNRESET')) {\n return (\n 'Lost the connection to the daemon; it may have crashed while ' +\n 'handling the request. Check `mm daemon status` and the daemon log.'\n );\n }\n if (isErrorWithCode(error, 'EACCES') || isErrorWithCode(error, 'EPERM')) {\n return (\n 'Cannot connect to the daemon socket: permission denied. ' +\n 'The socket may be owned by another user, or MM_DAEMON_DATA_DIR ' +\n 'may point to a directory you cannot access.'\n );\n }\n return error instanceof Error ? error.message : String(error);\n}\n\n/**\n * Format the error of a JSON-RPC failure response into a user-facing message\n * for `Command.error`, so every command reports RPC failures the same way.\n *\n * @param error - The `error` field of a JSON-RPC failure response.\n * @returns The error message annotated with its numeric code.\n */\nexport function formatJsonRpcError(error: JsonRpcError): string {\n return `${error.message} (code ${String(error.code)})`;\n}\n\n/**\n * Treat an empty string the same as `undefined` — \"no value supplied\". Used\n * to normalise `--password ''` and `MM_WALLET_PASSWORD=''` so they trigger\n * the interactive prompt rather than sending an empty string to the keyring.\n *\n * @param value - The value to normalise.\n * @returns `undefined` if `value` is `undefined` or `''`; `value` otherwise.\n */\nexport function emptyToUndefined(\n value: string | undefined,\n): string | undefined {\n return value === '' ? undefined : value;\n}\n\n/**\n * Check whether a value is an array of strings. Used to validate untyped RPC\n * results (e.g. the daemon's `listActions`) before treating them as `string[]`.\n *\n * @param value - The value to check.\n * @returns True if the value is an array whose every element is a string.\n */\nexport function isStringArray(value: unknown): value is string[] {\n return (\n Array.isArray(value) && value.every((item) => typeof item === 'string')\n );\n}\n\n/**\n * Read a PID from a file. The file may contain just the PID, or the PID on\n * the first line followed by additional metadata (e.g. start time written by\n * the daemon).\n *\n * @param pidPath - The PID file path.\n * @returns The PID, or undefined if the file is missing or its first line is\n * not a positive integer.\n */\nexport async function readPidFile(\n pidPath: string,\n): Promise<number | undefined> {\n let contents: string;\n try {\n contents = await readFile(pidPath, 'utf-8');\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ENOENT')) {\n return undefined;\n }\n throw error;\n }\n // String.prototype.split always returns at least one element, so [0] is safe.\n const pid = Number(contents.split('\\n')[0].trim());\n return Number.isInteger(pid) && pid > 0 ? pid : undefined;\n}\n\n/**\n * Check whether a process is alive by sending signal 0.\n *\n * Treats `ESRCH` as \"process is gone\", `EPERM` as \"process exists but we\n * cannot signal it\" (still alive from our perspective), and rethrows\n * anything else so the caller can surface unexpected failures rather than\n * silently assuming the process is dead.\n *\n * @param pid - The process ID to check.\n * @returns True if the process exists.\n */\nexport function isProcessAlive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ESRCH')) {\n return false;\n }\n if (isErrorWithCode(error, 'EPERM')) {\n return true;\n }\n throw error;\n }\n}\n\n/**\n * Send a signal to a process. Returns true if the signal was sent, false if\n * the process does not exist (ESRCH). Re-throws on permission errors and\n * other failures.\n *\n * @param pid - The process ID.\n * @param signal - The signal to send.\n * @returns True if the signal was delivered, false if the process is gone.\n */\nexport function sendSignal(pid: number, signal: NodeJS.Signals): boolean {\n try {\n process.kill(pid, signal);\n return true;\n } catch (error: unknown) {\n if (isErrorWithCode(error, 'ESRCH')) {\n return false;\n }\n throw error;\n }\n}\n\n/**\n * Poll until a condition is met or the timeout elapses.\n *\n * @param check - A function that returns true when the condition is met.\n * @param timeoutMs - Maximum time to wait in milliseconds.\n * @returns True if the condition was met, false on timeout.\n */\nexport async function waitFor(\n check: () => boolean | Promise<boolean>,\n timeoutMs: number,\n): Promise<boolean> {\n const deadline = Date.now() + timeoutMs;\n while (Date.now() < deadline) {\n if (await check()) {\n return true;\n }\n await new Promise((resolve) => setTimeout(resolve, 250));\n }\n return false;\n}\n"]}
|
package/dist/daemon/utils.d.cts
CHANGED
|
@@ -27,6 +27,15 @@ export declare function makeDaemonConnectionError(error: unknown): string;
|
|
|
27
27
|
* @returns The error message annotated with its numeric code.
|
|
28
28
|
*/
|
|
29
29
|
export declare function formatJsonRpcError(error: JsonRpcError): string;
|
|
30
|
+
/**
|
|
31
|
+
* Treat an empty string the same as `undefined` — "no value supplied". Used
|
|
32
|
+
* to normalise `--password ''` and `MM_WALLET_PASSWORD=''` so they trigger
|
|
33
|
+
* the interactive prompt rather than sending an empty string to the keyring.
|
|
34
|
+
*
|
|
35
|
+
* @param value - The value to normalise.
|
|
36
|
+
* @returns `undefined` if `value` is `undefined` or `''`; `value` otherwise.
|
|
37
|
+
*/
|
|
38
|
+
export declare function emptyToUndefined(value: string | undefined): string | undefined;
|
|
30
39
|
/**
|
|
31
40
|
* Check whether a value is an array of strings. Used to validate untyped RPC
|
|
32
41
|
* results (e.g. the daemon's `listActions`) before treating them as `string[]`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/daemon/utils.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB;AAIpD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAErE;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAuBhE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAE9D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,EAAE,CAI/D;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAa7B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAanD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAUvE;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EACvC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC,CASlB"}
|
|
1
|
+
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/daemon/utils.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB;AAIpD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAErE;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAuBhE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAE9D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,MAAM,GAAG,SAAS,CAEpB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,EAAE,CAI/D;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAa7B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAanD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAUvE;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EACvC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC,CASlB"}
|
package/dist/daemon/utils.d.mts
CHANGED
|
@@ -27,6 +27,15 @@ export declare function makeDaemonConnectionError(error: unknown): string;
|
|
|
27
27
|
* @returns The error message annotated with its numeric code.
|
|
28
28
|
*/
|
|
29
29
|
export declare function formatJsonRpcError(error: JsonRpcError): string;
|
|
30
|
+
/**
|
|
31
|
+
* Treat an empty string the same as `undefined` — "no value supplied". Used
|
|
32
|
+
* to normalise `--password ''` and `MM_WALLET_PASSWORD=''` so they trigger
|
|
33
|
+
* the interactive prompt rather than sending an empty string to the keyring.
|
|
34
|
+
*
|
|
35
|
+
* @param value - The value to normalise.
|
|
36
|
+
* @returns `undefined` if `value` is `undefined` or `''`; `value` otherwise.
|
|
37
|
+
*/
|
|
38
|
+
export declare function emptyToUndefined(value: string | undefined): string | undefined;
|
|
30
39
|
/**
|
|
31
40
|
* Check whether a value is an array of strings. Used to validate untyped RPC
|
|
32
41
|
* results (e.g. the daemon's `listActions`) before treating them as `string[]`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/daemon/utils.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB;AAIpD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAErE;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAuBhE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAE9D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,EAAE,CAI/D;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAa7B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAanD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAUvE;AAED;;;;;;GAMG;AACH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mjs
CHANGED
|
@@ -33,7 +33,7 @@ export function makeDaemonConnectionError(error) {
|
|
|
33
33
|
}
|
|
34
34
|
if (isErrorWithCode(error, 'EACCES') || isErrorWithCode(error, 'EPERM')) {
|
|
35
35
|
return ('Cannot connect to the daemon socket: permission denied. ' +
|
|
36
|
-
'The socket may be owned by another user, or
|
|
36
|
+
'The socket may be owned by another user, or MM_DAEMON_DATA_DIR ' +
|
|
37
37
|
'may point to a directory you cannot access.');
|
|
38
38
|
}
|
|
39
39
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -48,6 +48,17 @@ export function makeDaemonConnectionError(error) {
|
|
|
48
48
|
export function formatJsonRpcError(error) {
|
|
49
49
|
return `${error.message} (code ${String(error.code)})`;
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Treat an empty string the same as `undefined` — "no value supplied". Used
|
|
53
|
+
* to normalise `--password ''` and `MM_WALLET_PASSWORD=''` so they trigger
|
|
54
|
+
* the interactive prompt rather than sending an empty string to the keyring.
|
|
55
|
+
*
|
|
56
|
+
* @param value - The value to normalise.
|
|
57
|
+
* @returns `undefined` if `value` is `undefined` or `''`; `value` otherwise.
|
|
58
|
+
*/
|
|
59
|
+
export function emptyToUndefined(value) {
|
|
60
|
+
return value === '' ? undefined : value;
|
|
61
|
+
}
|
|
51
62
|
/**
|
|
52
63
|
* Check whether a value is an array of strings. Used to validate untyped RPC
|
|
53
64
|
* results (e.g. the daemon's `listActions`) before treating them as `string[]`.
|