@totalreclaw/mcp-server 3.3.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -2
- package/SKILL.md +1 -1
- package/dist/claims-helper.d.ts +1 -1
- package/dist/claims-helper.d.ts.map +1 -1
- package/dist/claims-helper.js +31 -31
- package/dist/claims-helper.js.map +1 -1
- package/dist/cli/setup.d.ts +10 -0
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli/setup.js +15 -5
- package/dist/cli/setup.js.map +1 -1
- package/dist/consolidation.d.ts +3 -5
- package/dist/consolidation.d.ts.map +1 -1
- package/dist/consolidation.js +47 -122
- package/dist/consolidation.js.map +1 -1
- package/dist/contradiction-sync.d.ts +2 -2
- package/dist/contradiction-sync.d.ts.map +1 -1
- package/dist/contradiction-sync.js +17 -16
- package/dist/contradiction-sync.js.map +1 -1
- package/dist/dispatch.d.ts +95 -0
- package/dist/dispatch.d.ts.map +1 -0
- package/dist/dispatch.js +191 -0
- package/dist/dispatch.js.map +1 -0
- package/dist/embedding-codec.d.ts +81 -0
- package/dist/embedding-codec.d.ts.map +1 -0
- package/dist/embedding-codec.js +223 -0
- package/dist/embedding-codec.js.map +1 -0
- package/dist/extraction/extractor.d.ts +1 -0
- package/dist/extraction/extractor.d.ts.map +1 -1
- package/dist/extraction/extractor.js +15 -15
- package/dist/extraction/extractor.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +484 -767
- package/dist/index.js.map +1 -1
- package/dist/pair-remote-client.d.ts +41 -0
- package/dist/pair-remote-client.d.ts.map +1 -1
- package/dist/pair-remote-client.js +130 -32
- package/dist/pair-remote-client.js.map +1 -1
- package/dist/prompts.d.ts +3 -4
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +3 -9
- package/dist/prompts.js.map +1 -1
- package/dist/server-setup.d.ts +35 -0
- package/dist/server-setup.d.ts.map +1 -0
- package/dist/server-setup.js +102 -0
- package/dist/server-setup.js.map +1 -0
- package/dist/subgraph/bundle.d.ts +129 -0
- package/dist/subgraph/bundle.d.ts.map +1 -0
- package/dist/subgraph/bundle.js +232 -0
- package/dist/subgraph/bundle.js.map +1 -0
- package/dist/subgraph/chain-config.d.ts +128 -0
- package/dist/subgraph/chain-config.d.ts.map +1 -0
- package/dist/subgraph/chain-config.js +135 -0
- package/dist/subgraph/chain-config.js.map +1 -0
- package/dist/subgraph/credentials.d.ts +83 -0
- package/dist/subgraph/credentials.d.ts.map +1 -0
- package/dist/subgraph/credentials.js +210 -0
- package/dist/subgraph/credentials.js.map +1 -0
- package/dist/subgraph/search.js +13 -13
- package/dist/subgraph/search.js.map +1 -1
- package/dist/subgraph/store.d.ts +39 -2
- package/dist/subgraph/store.d.ts.map +1 -1
- package/dist/subgraph/store.js +48 -13
- package/dist/subgraph/store.js.map +1 -1
- package/dist/tools/account.d.ts +5 -2
- package/dist/tools/account.d.ts.map +1 -1
- package/dist/tools/account.js +17 -4
- package/dist/tools/account.js.map +1 -1
- package/dist/tools/consolidate.d.ts +2 -2
- package/dist/tools/consolidate.d.ts.map +1 -1
- package/dist/tools/consolidate.js +2 -1
- package/dist/tools/consolidate.js.map +1 -1
- package/dist/tools/debrief.d.ts +2 -2
- package/dist/tools/debrief.d.ts.map +1 -1
- package/dist/tools/debrief.js +2 -1
- package/dist/tools/debrief.js.map +1 -1
- package/dist/tools/export.d.ts +2 -2
- package/dist/tools/export.d.ts.map +1 -1
- package/dist/tools/export.js +2 -1
- package/dist/tools/export.js.map +1 -1
- package/dist/tools/forget.d.ts +8 -2
- package/dist/tools/forget.d.ts.map +1 -1
- package/dist/tools/forget.js +14 -7
- package/dist/tools/forget.js.map +1 -1
- package/dist/tools/helpers.d.ts +40 -0
- package/dist/tools/helpers.d.ts.map +1 -0
- package/dist/tools/helpers.js +64 -0
- package/dist/tools/helpers.js.map +1 -0
- package/dist/tools/import-batch.d.ts +2 -1
- package/dist/tools/import-batch.d.ts.map +1 -1
- package/dist/tools/import-batch.js +1 -1
- package/dist/tools/import-batch.js.map +1 -1
- package/dist/tools/import-from.d.ts +2 -2
- package/dist/tools/import-from.d.ts.map +1 -1
- package/dist/tools/import-from.js +2 -1
- package/dist/tools/import-from.js.map +1 -1
- package/dist/tools/import.d.ts +2 -2
- package/dist/tools/import.d.ts.map +1 -1
- package/dist/tools/import.js +4 -3
- package/dist/tools/import.js.map +1 -1
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +7 -9
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/pair.d.ts +2 -1
- package/dist/tools/pair.d.ts.map +1 -1
- package/dist/tools/pair.js +67 -4
- package/dist/tools/pair.js.map +1 -1
- package/dist/tools/pin.d.ts +10 -7
- package/dist/tools/pin.d.ts.map +1 -1
- package/dist/tools/pin.js +43 -49
- package/dist/tools/pin.js.map +1 -1
- package/dist/tools/recall.d.ts +2 -2
- package/dist/tools/recall.d.ts.map +1 -1
- package/dist/tools/recall.js +22 -47
- package/dist/tools/recall.js.map +1 -1
- package/dist/tools/remember.d.ts +2 -2
- package/dist/tools/remember.d.ts.map +1 -1
- package/dist/tools/remember.js +30 -48
- package/dist/tools/remember.js.map +1 -1
- package/dist/tools/retype.d.ts +6 -1
- package/dist/tools/retype.d.ts.map +1 -1
- package/dist/tools/retype.js +37 -33
- package/dist/tools/retype.js.map +1 -1
- package/dist/tools/set-scope.d.ts +6 -1
- package/dist/tools/set-scope.d.ts.map +1 -1
- package/dist/tools/set-scope.js +14 -10
- package/dist/tools/set-scope.js.map +1 -1
- package/dist/tools/status.d.ts +2 -1
- package/dist/tools/status.d.ts.map +1 -1
- package/dist/tools/status.js +14 -12
- package/dist/tools/status.js.map +1 -1
- package/dist/tools/support.d.ts +5 -3
- package/dist/tools/support.d.ts.map +1 -1
- package/dist/tools/support.js +9 -8
- package/dist/tools/support.js.map +1 -1
- package/dist/tools/types.d.ts +38 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +17 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/upgrade.d.ts +2 -1
- package/dist/tools/upgrade.d.ts.map +1 -1
- package/dist/tools/upgrade.js +6 -4
- package/dist/tools/upgrade.js.map +1 -1
- package/package.json +3 -4
- package/dist/subgraph/index.d.ts +0 -7
- package/dist/subgraph/index.d.ts.map +0 -1
- package/dist/subgraph/index.js +0 -23
- package/dist/subgraph/index.js.map +0 -1
- package/dist/tools/migrate.d.ts +0 -88
- package/dist/tools/migrate.d.ts.map +0 -1
- package/dist/tools/migrate.js +0 -273
- package/dist/tools/migrate.js.map +0 -1
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TotalReclaw MCP — `derived-bundle-v1` credential bundle (Option E Phase 2 /
|
|
4
|
+
* #581, P2-13 — the MCP adapter).
|
|
5
|
+
*
|
|
6
|
+
* A bundle is what an agent host holds *instead of* the BIP-39 recovery
|
|
7
|
+
* phrase: the four HKDF-derived vault-global working keys plus a signing
|
|
8
|
+
* key, but never the phrase or the 64-byte seed that reproduces it. See
|
|
9
|
+
* `docs/specs/totalreclaw/client-consistency.md` ("Credential Material") for
|
|
10
|
+
* the full cross-client contract this file implements.
|
|
11
|
+
*
|
|
12
|
+
* Shared-core-first (CLAUDE.md): every byte of derivation, parsing, and
|
|
13
|
+
* validation lives in `rust/totalreclaw-core/src/bundle.rs` and crosses into
|
|
14
|
+
* TS only via the `@totalreclaw/core` WASM bindings (`parseBundleV1`,
|
|
15
|
+
* `validateBundleV1`, `deriveBundleFromMnemonic`). This module is a THIN
|
|
16
|
+
* adapter: it types the wire shape, calls the WASM binding, and converts hex
|
|
17
|
+
* fields to `Buffer` where the rest of the MCP codebase expects buffers. It
|
|
18
|
+
* does not reimplement HKDF, hex validation, or any §4.7 invariant — the
|
|
19
|
+
* mnemonic-mode `deriveKeys`/`deriveLshSeed` in `subgraph/crypto.ts` are the
|
|
20
|
+
* pattern followed here: WASM-backed wrappers, no local crypto.
|
|
21
|
+
*
|
|
22
|
+
* Mirrors `python/src/totalreclaw/bundle.py`'s shape (frozen dataclasses,
|
|
23
|
+
* zero logic) as closely as TS allows.
|
|
24
|
+
*
|
|
25
|
+
* **Dependency note / feature detection (release gate).** As of this
|
|
26
|
+
* writing, no published `@totalreclaw/core` npm release exposes
|
|
27
|
+
* `parseBundleV1` / `validateBundleV1` / `deriveBundleFromMnemonic` (checked:
|
|
28
|
+
* latest dist-tag 2.6.0-rc.1 does not carry them). Because this package's
|
|
29
|
+
* `package.json` dependency range (`^2.5.3`) is satisfied by versions that
|
|
30
|
+
* lack the bindings, this module CANNOT assume `require('@totalreclaw/core')`
|
|
31
|
+
* exposes them — doing so (e.g. `as typeof import('@totalreclaw/core')`)
|
|
32
|
+
* would type-check locally against a hand-built WASM copy but fail `tsc`
|
|
33
|
+
* against the real, published dependency in CI, which is exactly what
|
|
34
|
+
* happened on the first revision of this file (see PR #618 review history).
|
|
35
|
+
*
|
|
36
|
+
* So every bundle-touching WASM call routes through `ensureBundleBindings()`,
|
|
37
|
+
* which feature-detects the three functions at runtime and throws a single,
|
|
38
|
+
* actionable error if they're absent — never a TS compile-time assumption
|
|
39
|
+
* about what the installed package exports. **Mnemonic-mode code paths never
|
|
40
|
+
* call anything in this file that touches `wasm.*`** (`bundleVaultToBuffers`
|
|
41
|
+
* and `redactedBundleSummary` are pure functions over an already-parsed
|
|
42
|
+
* bundle and need no core binding), so a host running the published
|
|
43
|
+
* dependency with no bundle bindings is completely unaffected until it
|
|
44
|
+
* actually encounters a `version: 2` credentials.json — at which point it
|
|
45
|
+
* gets the actionable upgrade error instead of a silent misconfiguration.
|
|
46
|
+
*/
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.hasBundleBindings = hasBundleBindings;
|
|
49
|
+
exports.parseBundleV1 = parseBundleV1;
|
|
50
|
+
exports.validateBundleV1 = validateBundleV1;
|
|
51
|
+
exports.deriveBundleFromMnemonic = deriveBundleFromMnemonic;
|
|
52
|
+
exports.bundleVaultToBuffers = bundleVaultToBuffers;
|
|
53
|
+
exports.redactedBundleSummary = redactedBundleSummary;
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
55
|
+
const coreModule = require('@totalreclaw/core');
|
|
56
|
+
/** `require('@totalreclaw/core')`, typed as a partial — every field is
|
|
57
|
+
* checked for presence before use. Never cast to the full interface without
|
|
58
|
+
* going through `ensureBundleBindings()`. */
|
|
59
|
+
const wasm = coreModule;
|
|
60
|
+
/**
|
|
61
|
+
* Best-effort installed-version lookup, for the error message only. Never
|
|
62
|
+
* throws — a version string we can't determine still needs an actionable
|
|
63
|
+
* error, just without the "installed version X" detail.
|
|
64
|
+
*
|
|
65
|
+
* Deliberately does NOT `require('@totalreclaw/core/package.json')` — the
|
|
66
|
+
* published package's `exports` map only defines `.` and `./web`, so that
|
|
67
|
+
* subpath throws `ERR_PACKAGE_PATH_NOT_EXPORTED` under Node's exports
|
|
68
|
+
* enforcement (confirmed against the actual installed layout). Instead,
|
|
69
|
+
* resolve the package's entry file and walk up the filesystem to find its
|
|
70
|
+
* own `package.json` via plain `fs` access, which `exports` restrictions
|
|
71
|
+
* don't gate.
|
|
72
|
+
*/
|
|
73
|
+
function getInstalledCoreVersion() {
|
|
74
|
+
try {
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
76
|
+
const fs = require('node:fs');
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
78
|
+
const path = require('node:path');
|
|
79
|
+
let dir = path.dirname(require.resolve('@totalreclaw/core'));
|
|
80
|
+
for (let i = 0; i < 6; i++) {
|
|
81
|
+
const candidate = path.join(dir, 'package.json');
|
|
82
|
+
if (fs.existsSync(candidate)) {
|
|
83
|
+
const pkg = JSON.parse(fs.readFileSync(candidate, 'utf-8'));
|
|
84
|
+
if (pkg.name === '@totalreclaw/core' && pkg.version) {
|
|
85
|
+
return pkg.version;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const parent = path.dirname(dir);
|
|
89
|
+
if (parent === dir)
|
|
90
|
+
break;
|
|
91
|
+
dir = parent;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// best-effort
|
|
96
|
+
}
|
|
97
|
+
return 'unknown';
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Feature-detect the three bundle WASM bindings and return them narrowed to
|
|
101
|
+
* `BundleCoreBindings`, or throw a single, actionable error. This is the
|
|
102
|
+
* ONE guard every bundle entry point in this file (and only this file —
|
|
103
|
+
* `credentials.ts` / `pair-remote-client.ts` / `index.ts` all call INTO this
|
|
104
|
+
* module rather than `require('@totalreclaw/core')` directly, so this is
|
|
105
|
+
* genuinely the single choke point) routes through before touching
|
|
106
|
+
* `wasm.*`.
|
|
107
|
+
*/
|
|
108
|
+
function ensureBundleBindings() {
|
|
109
|
+
if (typeof wasm.parseBundleV1 === 'function' &&
|
|
110
|
+
typeof wasm.validateBundleV1 === 'function' &&
|
|
111
|
+
typeof wasm.deriveBundleFromMnemonic === 'function') {
|
|
112
|
+
return wasm;
|
|
113
|
+
}
|
|
114
|
+
const installed = getInstalledCoreVersion();
|
|
115
|
+
throw new Error('derived-bundle-v1: bundle-mode credentials require @totalreclaw/core >= 2.6.0 with bundle ' +
|
|
116
|
+
`bindings (parseBundleV1/validateBundleV1/deriveBundleFromMnemonic); installed version ` +
|
|
117
|
+
`${installed} lacks them — upgrade the @totalreclaw/core dependency. Mnemonic-mode ` +
|
|
118
|
+
'(plaintext recovery phrase) credentials are unaffected by this — this error only fires ' +
|
|
119
|
+
'when a credentials.json version: 2 (derived-bundle-v1) file is actually being read.');
|
|
120
|
+
}
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
// Feature-detection surface — exported so callers (and tests) can check
|
|
123
|
+
// availability without triggering the throw, e.g. to skip a test with a
|
|
124
|
+
// visible reason rather than failing.
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
/** True iff the installed `@totalreclaw/core` exposes all three bundle
|
|
127
|
+
* bindings. Never throws. */
|
|
128
|
+
function hasBundleBindings() {
|
|
129
|
+
return (typeof wasm.parseBundleV1 === 'function' &&
|
|
130
|
+
typeof wasm.validateBundleV1 === 'function' &&
|
|
131
|
+
typeof wasm.deriveBundleFromMnemonic === 'function');
|
|
132
|
+
}
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
// Parsing / validation — delegates to @totalreclaw/core. Never re-implements
|
|
135
|
+
// any derived-bundle-v1.md §4.7 invariant locally.
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
/**
|
|
138
|
+
* Parse and fully validate a `derived-bundle-v1` JSON string.
|
|
139
|
+
*
|
|
140
|
+
* Runs every §4.7 invariant inside `totalreclaw-core::bundle::parse_bundle_v1`
|
|
141
|
+
* (wrong version/schema, malformed hex, unknown `signing.kind`, an
|
|
142
|
+
* `owner-eoa` bundle carrying a `grant`, a `session-key` bundle with an
|
|
143
|
+
* inconsistent `grant`, `signing.address` not matching `address(private_key)`,
|
|
144
|
+
* …). Throws a plain `Error` — never a silent downgrade — on any violation.
|
|
145
|
+
*
|
|
146
|
+
* The thrown error's message is core's own message, which never contains
|
|
147
|
+
* hex key material (core's validation errors describe *shape* violations,
|
|
148
|
+
* not values).
|
|
149
|
+
*
|
|
150
|
+
* Throws `ensureBundleBindings()`'s actionable upgrade error if the
|
|
151
|
+
* installed `@totalreclaw/core` lacks the bundle bindings — checked BEFORE
|
|
152
|
+
* any attempt to call into the WASM module.
|
|
153
|
+
*/
|
|
154
|
+
function parseBundleV1(json) {
|
|
155
|
+
const bindings = ensureBundleBindings();
|
|
156
|
+
// bindings.parseBundleV1 throws a JsError on any validation failure —
|
|
157
|
+
// surface it as a normal Error with a stable, actionable prefix so
|
|
158
|
+
// callers don't need to know this crossed a WASM boundary.
|
|
159
|
+
let parsed;
|
|
160
|
+
try {
|
|
161
|
+
parsed = bindings.parseBundleV1(json);
|
|
162
|
+
}
|
|
163
|
+
catch (err) {
|
|
164
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
165
|
+
throw new Error(`derived-bundle-v1: invalid bundle — ${msg}`);
|
|
166
|
+
}
|
|
167
|
+
return parsed;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Validate a `derived-bundle-v1` JSON string without returning the parsed
|
|
171
|
+
* object. Throws on any violation; no-op on success.
|
|
172
|
+
*/
|
|
173
|
+
function validateBundleV1(json) {
|
|
174
|
+
const bindings = ensureBundleBindings();
|
|
175
|
+
try {
|
|
176
|
+
bindings.validateBundleV1(json);
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
180
|
+
throw new Error(`derived-bundle-v1: invalid bundle — ${msg}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Derive a `derived-bundle-v1` bundle from a BIP-39 mnemonic.
|
|
185
|
+
*
|
|
186
|
+
* NOT part of MCP's read-side credential-loading scope (P2-13) — MCP never
|
|
187
|
+
* derives a bundle from a mnemonic on its own initiative; that is Hermes's
|
|
188
|
+
* `local-migration` job (P2-9) or the SPA's `provisioned_by: "spa"` job.
|
|
189
|
+
* Exported anyway because the test fixtures (parity + pair-bundle tests)
|
|
190
|
+
* need a way to mint a bundle for `parseBundleV1` round-trip coverage
|
|
191
|
+
* without hand-rolling JSON, and because a future MCP-side migration tool
|
|
192
|
+
* (tracked as a known gap — see mcp/README.md) will need exactly this call.
|
|
193
|
+
*/
|
|
194
|
+
function deriveBundleFromMnemonic(mnemonic, chainId, provisionedBy, smartAccount) {
|
|
195
|
+
const bindings = ensureBundleBindings();
|
|
196
|
+
return bindings.deriveBundleFromMnemonic(mnemonic.trim(), BigInt(chainId), provisionedBy, smartAccount);
|
|
197
|
+
}
|
|
198
|
+
/** Convert a parsed bundle's hex vault keys to `Buffer`s. */
|
|
199
|
+
function bundleVaultToBuffers(bundle) {
|
|
200
|
+
return {
|
|
201
|
+
encryptionKey: Buffer.from(bundle.vault.encryption_key, 'hex'),
|
|
202
|
+
dedupKey: Buffer.from(bundle.vault.dedup_key, 'hex'),
|
|
203
|
+
authKey: Buffer.from(bundle.vault.auth_key, 'hex'),
|
|
204
|
+
lshSeed: Buffer.from(bundle.vault.lsh_seed, 'hex'),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
// ---------------------------------------------------------------------------
|
|
208
|
+
// Redaction — derived-bundle-v1.md §4.6 point 5: no value under `vault` or
|
|
209
|
+
// `signing.private_key` may ever be logged, printed, or included in an
|
|
210
|
+
// exception message. Python's `bundle.py` enforces this with `__repr__`
|
|
211
|
+
// overrides on frozen dataclasses; TS has no dataclass-repr equivalent, so
|
|
212
|
+
// every call site that might log a bundle MUST route through this helper
|
|
213
|
+
// instead of `JSON.stringify(bundle)` / `console.error(bundle)` directly.
|
|
214
|
+
// Also touches no WASM binding — pure function, no feature-detection needed.
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
/**
|
|
217
|
+
* A safe-to-log summary of a bundle: everything EXCEPT `vault.*` and
|
|
218
|
+
* `signing.private_key`. Use this (never the raw bundle object) in any
|
|
219
|
+
* `console.error` / log line that touches a bundle.
|
|
220
|
+
*/
|
|
221
|
+
function redactedBundleSummary(bundle) {
|
|
222
|
+
return {
|
|
223
|
+
schema: 'derived-bundle-v1',
|
|
224
|
+
signing_kind: bundle.signing.kind,
|
|
225
|
+
signing_address: bundle.signing.address,
|
|
226
|
+
smart_account: bundle.account.smart_account,
|
|
227
|
+
chain_id: bundle.account.chain_id,
|
|
228
|
+
provisioned_at: bundle.provisioned_at,
|
|
229
|
+
provisioned_by: bundle.provisioned_by,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.js","sourceR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IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC;KACnD,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,2EAA2E;AAC3E,uEAAuE;AACvE,wEAAwE;AACxE,2EAA2E;AAC3E,yEAAyE;AACzE,0EAA0E;AAC1E,6EAA6E;AAC7E,8EAA8E;AAE9E;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,MAAuB;IAC3D,OAAO;QACL,MAAM,EAAE,mBAAmB;QAC3B,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI;QACjC,eAAe,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO;QACvC,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,aAAa;QAC3C,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ;QACjC,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,cAAc,EAAE,MAAM,CAAC,cAAc;KACtC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chain + DataEdge resolution for the managed-service (subgraph) write path.
|
|
3
|
+
*
|
|
4
|
+
* Client-consistency contract (#439, sibling of the OpenClaw plugin #402/#460):
|
|
5
|
+
* the relay returns authoritative `chain_id` + `data_edge_address` in
|
|
6
|
+
* `GET /v1/billing/status`; chain-aware clients consume them verbatim so a
|
|
7
|
+
* future chain change needs zero client release. Both tiers run on Gnosis
|
|
8
|
+
* (chain 100) after ops-1 — the legacy Free → Base Sepolia (84532) routing
|
|
9
|
+
* was retired, so the local default here is 100, not 84532.
|
|
10
|
+
*/
|
|
11
|
+
import { type SubgraphStoreConfig } from './store.js';
|
|
12
|
+
export interface ResolvedChainConfig {
|
|
13
|
+
/** Chain to submit the write to (verbatim from billing, else Gnosis 100). */
|
|
14
|
+
chainId: number;
|
|
15
|
+
/** DataEdge contract from billing, or undefined to fall through to env/default. */
|
|
16
|
+
dataEdgeAddress?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Resolve chain + DataEdge from a `/v1/billing/status` response.
|
|
20
|
+
*
|
|
21
|
+
* - `chain_id`: used verbatim when a finite number; otherwise Gnosis (100).
|
|
22
|
+
* - `data_edge_address`: used only when a valid `0x…40hex` string; otherwise
|
|
23
|
+
* left undefined so the caller falls through to env / the store default.
|
|
24
|
+
*
|
|
25
|
+
* `onMalformedDataEdge` fires when `data_edge_address` is PRESENT but fails
|
|
26
|
+
* the `0x…40hex` shape check — distinct from the field being simply absent
|
|
27
|
+
* (a legitimate response shape for some relay versions/tiers). A present-
|
|
28
|
+
* but-garbage value is evidence of a relay bug or a tampered response and
|
|
29
|
+
* was previously dropped silently; callers that care (currently
|
|
30
|
+
* `fetchChainConfig` below) should log it loudly rather than let a caller
|
|
31
|
+
* silently fall through to the store's default DataEdge with no trace of
|
|
32
|
+
* why.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveChainConfig(billing: Record<string, unknown> | null | undefined, onMalformedDataEdge?: (raw: unknown) => void): ResolvedChainConfig;
|
|
35
|
+
export interface WriteConfigInput {
|
|
36
|
+
relayUrl: string;
|
|
37
|
+
/**
|
|
38
|
+
* Exactly one of `mnemonic` / `ownerPrivateKeyHex` must be set (Option E
|
|
39
|
+
* Phase 2 / #581, P2-13). Mnemonic-mode clients set `mnemonic`;
|
|
40
|
+
* bundle-mode clients (no mnemonic anywhere in the process — derived-
|
|
41
|
+
* bundle-v1.md §4.6 point 1) set `ownerPrivateKeyHex` from
|
|
42
|
+
* `bundle.signing.private_key` instead. `store.ts`'s
|
|
43
|
+
* `resolveOwnerAccount` prefers `ownerPrivateKeyHex` when both happen to
|
|
44
|
+
* be present (never expected in practice, but privateKey is the more
|
|
45
|
+
* direct source of truth so it wins rather than erroring).
|
|
46
|
+
*/
|
|
47
|
+
mnemonic?: string;
|
|
48
|
+
/** Bundle-mode signing key — 64 lowercase hex chars, no `0x` prefix. */
|
|
49
|
+
ownerPrivateKeyHex?: string;
|
|
50
|
+
authKeyHex: string;
|
|
51
|
+
walletAddress: string;
|
|
52
|
+
chainId: number;
|
|
53
|
+
dataEdgeAddress?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Build the `getSubgraphConfig` override object for a managed-service write,
|
|
57
|
+
* threading the billing-resolved chainId + DataEdge alongside the relay creds.
|
|
58
|
+
*
|
|
59
|
+
* Precedence for DataEdge: an explicit `TOTALRECLAW_DATA_EDGE_ADDRESS` env var
|
|
60
|
+
* must win. Because a passed override key supersedes env inside
|
|
61
|
+
* getSubgraphConfig's merge, we inject the billing-derived DataEdge ONLY when
|
|
62
|
+
* the env override is unset — mirroring the plugin's env || billing || default
|
|
63
|
+
* ordering.
|
|
64
|
+
*/
|
|
65
|
+
export declare function buildSubgraphOverrides(input: WriteConfigInput): Partial<SubgraphStoreConfig>;
|
|
66
|
+
/**
|
|
67
|
+
* `fetchChainConfig`'s result, extended with whether the billing call
|
|
68
|
+
* itself actually succeeded (200 + parseable JSON). Adversarial-review
|
|
69
|
+
* fixup (PR #618): a caller that only inspects `dataEdgeAddress` cannot
|
|
70
|
+
* tell "billing responded but omitted the field" (rare, arguably legitimate)
|
|
71
|
+
* apart from "billing was completely unreachable" (network error, timeout,
|
|
72
|
+
* non-200) — and those two cases need different responses in bundle mode.
|
|
73
|
+
* See `billingResolved`'s own doc comment.
|
|
74
|
+
*/
|
|
75
|
+
export interface FetchedChainConfig extends ResolvedChainConfig {
|
|
76
|
+
/**
|
|
77
|
+
* True iff the billing endpoint responded 200 with parseable JSON —
|
|
78
|
+
* `resolveChainConfig` actually ran against real billing data (even if
|
|
79
|
+
* `chain_id`/`data_edge_address` were absent or malformed within it).
|
|
80
|
+
* False on network failure, timeout, or a non-200 response: the caller
|
|
81
|
+
* fell all the way back to `fallbackChainId` with NO environment
|
|
82
|
+
* information at all. Bundle-mode callers (`index.ts`'s
|
|
83
|
+
* `initSubgraphStateFromBundle`) MUST check this before proceeding — see
|
|
84
|
+
* that function's fail-closed guard.
|
|
85
|
+
*/
|
|
86
|
+
billingResolved: boolean;
|
|
87
|
+
}
|
|
88
|
+
export interface FetchChainConfigOptions {
|
|
89
|
+
serverUrl: string;
|
|
90
|
+
smartAccountAddress: string;
|
|
91
|
+
authKeyHex: string;
|
|
92
|
+
/** Extra headers (client id, session tag, …) merged with Authorization. */
|
|
93
|
+
headers?: Record<string, string>;
|
|
94
|
+
/** Chain id to return when the billing call fails/is unreachable. */
|
|
95
|
+
fallbackChainId: number;
|
|
96
|
+
timeoutMs?: number;
|
|
97
|
+
/** Injectable for tests; defaults to the global `fetch`. */
|
|
98
|
+
fetchImpl?: typeof fetch;
|
|
99
|
+
/** Best-effort logger for the tier/chain line other init paths already print. */
|
|
100
|
+
onResolved?: (billing: Record<string, unknown>, resolved: ResolvedChainConfig) => void;
|
|
101
|
+
/**
|
|
102
|
+
* Fires whenever the billing call did NOT succeed — network error,
|
|
103
|
+
* timeout, or a non-200 response — right before falling back to
|
|
104
|
+
* `fallbackChainId` / no DataEdge. `reason` is a short, human-readable
|
|
105
|
+
* description (never contains key material — it only ever describes
|
|
106
|
+
* transport-level failure, ``err.message``/HTTP status).
|
|
107
|
+
*/
|
|
108
|
+
onBillingUnavailable?: (reason: string) => void;
|
|
109
|
+
}
|
|
110
|
+
export declare function fetchChainConfig(opts: FetchChainConfigOptions): Promise<FetchedChainConfig>;
|
|
111
|
+
export interface AssertDataEdgeResolvableOptions {
|
|
112
|
+
/** From `fetchChainConfig`'s result. */
|
|
113
|
+
billingResolved: boolean;
|
|
114
|
+
/** `process.env.TOTALRECLAW_DATA_EDGE_ADDRESS` (or the test override). */
|
|
115
|
+
envDataEdgeOverride: string | undefined;
|
|
116
|
+
/** Relay base URL, for the error message only. */
|
|
117
|
+
serverUrl: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Throws an actionable error when bundle-mode state construction has no
|
|
121
|
+
* confirmed DataEdge for this environment (billing failed, no env
|
|
122
|
+
* override). No-op (returns) when either `billingResolved` is true (the
|
|
123
|
+
* billing call succeeded — even if it happened not to carry a
|
|
124
|
+
* `data_edge_address`, that's `resolveChainConfig`'s concern, not this
|
|
125
|
+
* guard's) or an explicit env override is present.
|
|
126
|
+
*/
|
|
127
|
+
export declare function assertDataEdgeResolvable(opts: AssertDataEdgeResolvableOptions): void;
|
|
128
|
+
//# sourceMappingURL=chain-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-config.d.ts","sourceRoot":"","sources":["../../src/subgraph/chain-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAA6B,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAQjF,MAAM,WAAW,mBAAmB;IAClC,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,EACnD,mBAAmB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,GAC3C,mBAAmB,CAgBrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,mBAAmB,CAAC,CA2B9B;AAuBD;;;;;;;;GAQG;AACH,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC7D;;;;;;;;;OASG;IACH,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,qEAAqE;IACrE,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,iFAAiF;IACjF,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,mBAAmB,KAAK,IAAI,CAAC;IACvF;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CACjD;AAID,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,kBAAkB,CAAC,CA4B7B;AAuBD,MAAM,WAAW,+BAA+B;IAC9C,wCAAwC;IACxC,eAAe,EAAE,OAAO,CAAC;IACzB,0EAA0E;IAC1E,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,+BAA+B,GAAG,IAAI,CASpF"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Chain + DataEdge resolution for the managed-service (subgraph) write path.
|
|
4
|
+
*
|
|
5
|
+
* Client-consistency contract (#439, sibling of the OpenClaw plugin #402/#460):
|
|
6
|
+
* the relay returns authoritative `chain_id` + `data_edge_address` in
|
|
7
|
+
* `GET /v1/billing/status`; chain-aware clients consume them verbatim so a
|
|
8
|
+
* future chain change needs zero client release. Both tiers run on Gnosis
|
|
9
|
+
* (chain 100) after ops-1 — the legacy Free → Base Sepolia (84532) routing
|
|
10
|
+
* was retired, so the local default here is 100, not 84532.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.resolveChainConfig = resolveChainConfig;
|
|
14
|
+
exports.buildSubgraphOverrides = buildSubgraphOverrides;
|
|
15
|
+
exports.fetchChainConfig = fetchChainConfig;
|
|
16
|
+
exports.assertDataEdgeResolvable = assertDataEdgeResolvable;
|
|
17
|
+
const store_js_1 = require("./store.js");
|
|
18
|
+
/** Default chain when billing is silent — Gnosis mainnet (single-chain, both tiers). */
|
|
19
|
+
const DEFAULT_CHAIN_ID = 100;
|
|
20
|
+
/** A DataEdge address is a 20-byte hex string. Reject anything else. */
|
|
21
|
+
const DATA_EDGE_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
22
|
+
/**
|
|
23
|
+
* Resolve chain + DataEdge from a `/v1/billing/status` response.
|
|
24
|
+
*
|
|
25
|
+
* - `chain_id`: used verbatim when a finite number; otherwise Gnosis (100).
|
|
26
|
+
* - `data_edge_address`: used only when a valid `0x…40hex` string; otherwise
|
|
27
|
+
* left undefined so the caller falls through to env / the store default.
|
|
28
|
+
*
|
|
29
|
+
* `onMalformedDataEdge` fires when `data_edge_address` is PRESENT but fails
|
|
30
|
+
* the `0x…40hex` shape check — distinct from the field being simply absent
|
|
31
|
+
* (a legitimate response shape for some relay versions/tiers). A present-
|
|
32
|
+
* but-garbage value is evidence of a relay bug or a tampered response and
|
|
33
|
+
* was previously dropped silently; callers that care (currently
|
|
34
|
+
* `fetchChainConfig` below) should log it loudly rather than let a caller
|
|
35
|
+
* silently fall through to the store's default DataEdge with no trace of
|
|
36
|
+
* why.
|
|
37
|
+
*/
|
|
38
|
+
function resolveChainConfig(billing, onMalformedDataEdge) {
|
|
39
|
+
let chainId = DEFAULT_CHAIN_ID;
|
|
40
|
+
const rawChain = billing?.chain_id;
|
|
41
|
+
if (typeof rawChain === 'number' && Number.isFinite(rawChain)) {
|
|
42
|
+
chainId = rawChain;
|
|
43
|
+
}
|
|
44
|
+
let dataEdgeAddress;
|
|
45
|
+
const rawEdge = billing?.data_edge_address;
|
|
46
|
+
if (typeof rawEdge === 'string' && DATA_EDGE_RE.test(rawEdge)) {
|
|
47
|
+
dataEdgeAddress = rawEdge;
|
|
48
|
+
}
|
|
49
|
+
else if (rawEdge !== undefined && rawEdge !== null) {
|
|
50
|
+
onMalformedDataEdge?.(rawEdge);
|
|
51
|
+
}
|
|
52
|
+
return { chainId, dataEdgeAddress };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Build the `getSubgraphConfig` override object for a managed-service write,
|
|
56
|
+
* threading the billing-resolved chainId + DataEdge alongside the relay creds.
|
|
57
|
+
*
|
|
58
|
+
* Precedence for DataEdge: an explicit `TOTALRECLAW_DATA_EDGE_ADDRESS` env var
|
|
59
|
+
* must win. Because a passed override key supersedes env inside
|
|
60
|
+
* getSubgraphConfig's merge, we inject the billing-derived DataEdge ONLY when
|
|
61
|
+
* the env override is unset — mirroring the plugin's env || billing || default
|
|
62
|
+
* ordering.
|
|
63
|
+
*/
|
|
64
|
+
function buildSubgraphOverrides(input) {
|
|
65
|
+
const overrides = {
|
|
66
|
+
relayUrl: input.relayUrl,
|
|
67
|
+
authKeyHex: input.authKeyHex,
|
|
68
|
+
walletAddress: input.walletAddress,
|
|
69
|
+
};
|
|
70
|
+
// Exactly one signing source is threaded through — never both, and never
|
|
71
|
+
// neither (store.ts's resolveOwnerAccount throws an actionable error if
|
|
72
|
+
// neither ends up present on the final merged config).
|
|
73
|
+
if (input.ownerPrivateKeyHex) {
|
|
74
|
+
overrides.ownerPrivateKeyHex = input.ownerPrivateKeyHex;
|
|
75
|
+
}
|
|
76
|
+
else if (input.mnemonic) {
|
|
77
|
+
overrides.mnemonic = input.mnemonic;
|
|
78
|
+
}
|
|
79
|
+
// Only thread a finite chainId — never let an undefined clobber the store's
|
|
80
|
+
// Gnosis (100) default via the spread merge.
|
|
81
|
+
if (typeof input.chainId === 'number' && Number.isFinite(input.chainId)) {
|
|
82
|
+
overrides.chainId = input.chainId;
|
|
83
|
+
}
|
|
84
|
+
if (input.dataEdgeAddress && !process.env.TOTALRECLAW_DATA_EDGE_ADDRESS) {
|
|
85
|
+
overrides.dataEdgeAddress = input.dataEdgeAddress;
|
|
86
|
+
}
|
|
87
|
+
return overrides;
|
|
88
|
+
}
|
|
89
|
+
const DEFAULT_BILLING_TIMEOUT_MS = 5000;
|
|
90
|
+
async function fetchChainConfig(opts) {
|
|
91
|
+
const doFetch = opts.fetchImpl ?? fetch;
|
|
92
|
+
try {
|
|
93
|
+
const billingUrl = `${opts.serverUrl.replace(/\/+$/, '')}/v1/billing/status?wallet_address=${encodeURIComponent(opts.smartAccountAddress)}`;
|
|
94
|
+
const resp = await doFetch(billingUrl, {
|
|
95
|
+
method: 'GET',
|
|
96
|
+
headers: {
|
|
97
|
+
...(opts.headers ?? {}),
|
|
98
|
+
Authorization: `Bearer ${opts.authKeyHex}`,
|
|
99
|
+
},
|
|
100
|
+
signal: AbortSignal.timeout(opts.timeoutMs ?? DEFAULT_BILLING_TIMEOUT_MS),
|
|
101
|
+
});
|
|
102
|
+
if (resp.ok) {
|
|
103
|
+
const billing = (await resp.json());
|
|
104
|
+
const resolved = resolveChainConfig(billing, (raw) => {
|
|
105
|
+
console.error(`TotalReclaw: billing returned malformed data_edge_address (${JSON.stringify(raw)}) — falling back to env/default.`);
|
|
106
|
+
});
|
|
107
|
+
opts.onResolved?.(billing, resolved);
|
|
108
|
+
return { ...resolved, billingResolved: true };
|
|
109
|
+
}
|
|
110
|
+
opts.onBillingUnavailable?.(`billing responded HTTP ${resp.status}`);
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
114
|
+
opts.onBillingUnavailable?.(`billing fetch failed: ${msg}`);
|
|
115
|
+
}
|
|
116
|
+
return { chainId: opts.fallbackChainId, dataEdgeAddress: undefined, billingResolved: false };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Throws an actionable error when bundle-mode state construction has no
|
|
120
|
+
* confirmed DataEdge for this environment (billing failed, no env
|
|
121
|
+
* override). No-op (returns) when either `billingResolved` is true (the
|
|
122
|
+
* billing call succeeded — even if it happened not to carry a
|
|
123
|
+
* `data_edge_address`, that's `resolveChainConfig`'s concern, not this
|
|
124
|
+
* guard's) or an explicit env override is present.
|
|
125
|
+
*/
|
|
126
|
+
function assertDataEdgeResolvable(opts) {
|
|
127
|
+
if (opts.billingResolved || opts.envDataEdgeOverride)
|
|
128
|
+
return;
|
|
129
|
+
throw new Error('derived-bundle-v1: cannot resolve environment DataEdge — refusing to guess the production ' +
|
|
130
|
+
`default (${store_js_1.DEFAULT_DATA_EDGE_ADDRESS}). The billing lookup to ` +
|
|
131
|
+
`${opts.serverUrl.replace(/\/+$/, '')}/v1/billing/status failed and no ` +
|
|
132
|
+
'TOTALRECLAW_DATA_EDGE_ADDRESS override is set. Retry once the relay is reachable, or set ' +
|
|
133
|
+
'TOTALRECLAW_DATA_EDGE_ADDRESS explicitly for this environment.');
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=chain-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-config.js","sourceRoot":"","sources":["../../src/subgraph/chain-config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAiCH,gDAmBC;AAiCD,wDA6BC;AAuED,4CA8BC;AAwCD,4DASC;AAtQD,yCAAiF;AAEjF,wFAAwF;AACxF,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B,wEAAwE;AACxE,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAS3C;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,kBAAkB,CAChC,OAA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,UAAU,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACrC,OAAO,EAAE,GAAG,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;QAChD,CAAC;QACD,IAAI,CAAC,oBAAoB,EAAE,CAAC,0BAA0B,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACvE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7D,IAAI,CAAC,oBAAoB,EAAE,CAAC,yBAAyB,GAAG,EAAE,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC;AAC/F,CAAC;AAgCD;;;;;;;GAOG;AACH,SAAgB,wBAAwB,CAAC,IAAqC;IAC5E,IAAI,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,mBAAmB;QAAE,OAAO;IAC7D,MAAM,IAAI,KAAK,CACb,4FAA4F;QAC1F,YAAY,oCAAyB,2BAA2B;QAChE,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,mCAAmC;QACxE,2FAA2F;QAC3F,gEAAgE,CACnE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TotalReclaw MCP — managed-mode credential resolution (Option E Phase 2 /
|
|
3
|
+
* #581, P2-13).
|
|
4
|
+
*
|
|
5
|
+
* Reads `~/.totalreclaw/credentials.json` (or `TOTALRECLAW_RECOVERY_PHRASE`)
|
|
6
|
+
* and resolves EITHER a BIP-39 mnemonic OR a `derived-bundle-v1` bundle,
|
|
7
|
+
* mirroring the precedence `python/src/totalreclaw/agent/state.py::_try_auto_configure`
|
|
8
|
+
* implements for Hermes:
|
|
9
|
+
*
|
|
10
|
+
* 1. `TOTALRECLAW_RECOVERY_PHRASE` env — retained, deprecated (phrase).
|
|
11
|
+
* 2. `credentials.json` `version: 2` — a `derived-bundle-v1` bundle.
|
|
12
|
+
* 3. `credentials.json` legacy — plaintext `{"mnemonic": "…"}`.
|
|
13
|
+
*
|
|
14
|
+
* Deliberately narrower than the Python precedence chain: MCP has no
|
|
15
|
+
* `TOTALRECLAW_CREDENTIALS_PROVIDER` / external-provider transport
|
|
16
|
+
* (`credential_provider.py`) and no OS-keychain unwrap
|
|
17
|
+
* (`credentials_wrap.py`) — both are tracked as explicit known gaps (see
|
|
18
|
+
* `mcp/README.md`, CLAUDE.md's Known Gaps table) rather than silently
|
|
19
|
+
* unsupported. A `keychain_wrapped: true` v2 file is a LOUD, actionable
|
|
20
|
+
* error here, not a silent skip — the same "never silently downgrade"
|
|
21
|
+
* posture the unknown-`version` branch below takes.
|
|
22
|
+
*
|
|
23
|
+
* This module never reads self-hosted credentials (`ClientState`/
|
|
24
|
+
* `MASTER_PASSWORD` in `index.ts`) — self-hosted mode is a completely
|
|
25
|
+
* separate credential system with no BIP-39 root at all (derived-bundle-v1.md
|
|
26
|
+
* §4.5.1) and callers MUST route around this module entirely when
|
|
27
|
+
* `TOTALRECLAW_SELF_HOSTED=true`. See `index.ts`'s `main()` for the gate.
|
|
28
|
+
*/
|
|
29
|
+
import { type DerivedBundleV1 } from './bundle.js';
|
|
30
|
+
export type ResolvedCredential = {
|
|
31
|
+
kind: 'mnemonic';
|
|
32
|
+
mnemonic: string;
|
|
33
|
+
} | {
|
|
34
|
+
kind: 'bundle';
|
|
35
|
+
bundle: DerivedBundleV1;
|
|
36
|
+
};
|
|
37
|
+
export interface ResolveManagedCredentialOptions {
|
|
38
|
+
/** Override the credentials.json path — for tests. */
|
|
39
|
+
credentialsPath?: string;
|
|
40
|
+
/** Override the env — for tests. */
|
|
41
|
+
env?: NodeJS.ProcessEnv;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Resolve the managed-mode credential per the precedence above.
|
|
45
|
+
*
|
|
46
|
+
* Returns `undefined` when nothing is configured (equivalent to today's
|
|
47
|
+
* `resolveMnemonic()` returning `undefined` — falls through to
|
|
48
|
+
* `unconfigured` mode).
|
|
49
|
+
*
|
|
50
|
+
* Throws — never returns — on a credentials.json that is present but
|
|
51
|
+
* malformed in a way that must not be silently downgraded:
|
|
52
|
+
* - `version` present and not `2` (derived-bundle-v1.md §4.7 / the
|
|
53
|
+
* client-consistency contract: unknown version is a loud error).
|
|
54
|
+
* - `version === 2` but `keychain_wrapped: true` (MCP has no keychain
|
|
55
|
+
* unwrap — see the module doc).
|
|
56
|
+
* - `version === 2` and the bundle fails `parseBundleV1`'s §4.7
|
|
57
|
+
* validation (malformed hex, unknown `signing.kind`, address/key
|
|
58
|
+
* mismatch, …).
|
|
59
|
+
*
|
|
60
|
+
* A missing file, an unreadable file, or a file that fails to parse as JSON
|
|
61
|
+
* at all are treated as "nothing configured" (`undefined`) — matching the
|
|
62
|
+
* pre-existing `resolveMnemonic()` behaviour exactly, since a bare ENOENT or
|
|
63
|
+
* a syntax error is not evidence of tampering the way a well-formed-but-
|
|
64
|
+
* wrong `version` is.
|
|
65
|
+
*/
|
|
66
|
+
export declare function resolveManagedCredential(opts?: ResolveManagedCredentialOptions): ResolvedCredential | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Diagnostic-only check: does the credentials file at `credentialsPath`
|
|
69
|
+
* look like a `derived-bundle-v1` `version: 2` file? Plain `JSON.parse`,
|
|
70
|
+
* no WASM, no `parseBundleV1` — the only caller
|
|
71
|
+
* (`index.ts`'s `TOTALRECLAW_SELF_HOSTED` branch in `main()`) must never
|
|
72
|
+
* touch bundle parsing/validation at all; self-hosted mode is a wholly
|
|
73
|
+
* separate credential system (derived-bundle-v1.md §4.5.1) and this
|
|
74
|
+
* function exists purely to produce a more accurate diagnostic message —
|
|
75
|
+
* "is the `version` field present and `2`" — when self-hosted mode finds
|
|
76
|
+
* no usable mnemonic and would otherwise tell the operator to "set
|
|
77
|
+
* TOTALRECLAW_RECOVERY_PHRASE", which is actively wrong when a
|
|
78
|
+
* valid-but-wrong-mode bundle credential is already present.
|
|
79
|
+
*
|
|
80
|
+
* Never throws; a missing/corrupt/non-bundle file is simply `false`.
|
|
81
|
+
*/
|
|
82
|
+
export declare function isV2BundleCredentialsFile(credentialsPath: string): boolean;
|
|
83
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/subgraph/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAOH,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAGlE,MAAM,MAAM,kBAAkB,GAC1B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,CAAC;AAEhD,MAAM,WAAW,+BAA+B;IAC9C,sDAAsD;IACtD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACzB;AASD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,GAAE,+BAAoC,GACzC,kBAAkB,GAAG,SAAS,CAwFhC;AAQD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAQ1E"}
|