@totalreclaw/mcp-server 3.4.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/cli/setup.d.ts +10 -0
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli/setup.js +10 -0
- package/dist/cli/setup.js.map +1 -1
- package/dist/contradiction-sync.d.ts.map +1 -1
- package/dist/contradiction-sync.js +5 -4
- package/dist/contradiction-sync.js.map +1 -1
- 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/index.d.ts.map +1 -1
- package/dist/index.js +289 -47
- 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 -3
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +2 -2
- 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 +86 -3
- package/dist/subgraph/chain-config.d.ts.map +1 -1
- package/dist/subgraph/chain-config.js +71 -2
- package/dist/subgraph/chain-config.js.map +1 -1
- 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/store.d.ts +39 -2
- package/dist/subgraph/store.d.ts.map +1 -1
- package/dist/subgraph/store.js +44 -12
- package/dist/subgraph/store.js.map +1 -1
- package/dist/tools/account.d.ts.map +1 -1
- package/dist/tools/account.js +6 -0
- package/dist/tools/account.js.map +1 -1
- package/dist/tools/pair.d.ts.map +1 -1
- package/dist/tools/pair.js +63 -0
- package/dist/tools/pair.js.map +1 -1
- package/package.json +3 -3
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.resolveChainConfig = resolveChainConfig;
|
|
14
14
|
exports.buildSubgraphOverrides = buildSubgraphOverrides;
|
|
15
|
+
exports.fetchChainConfig = fetchChainConfig;
|
|
16
|
+
exports.assertDataEdgeResolvable = assertDataEdgeResolvable;
|
|
17
|
+
const store_js_1 = require("./store.js");
|
|
15
18
|
/** Default chain when billing is silent — Gnosis mainnet (single-chain, both tiers). */
|
|
16
19
|
const DEFAULT_CHAIN_ID = 100;
|
|
17
20
|
/** A DataEdge address is a 20-byte hex string. Reject anything else. */
|
|
@@ -22,8 +25,17 @@ const DATA_EDGE_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
|
22
25
|
* - `chain_id`: used verbatim when a finite number; otherwise Gnosis (100).
|
|
23
26
|
* - `data_edge_address`: used only when a valid `0x…40hex` string; otherwise
|
|
24
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.
|
|
25
37
|
*/
|
|
26
|
-
function resolveChainConfig(billing) {
|
|
38
|
+
function resolveChainConfig(billing, onMalformedDataEdge) {
|
|
27
39
|
let chainId = DEFAULT_CHAIN_ID;
|
|
28
40
|
const rawChain = billing?.chain_id;
|
|
29
41
|
if (typeof rawChain === 'number' && Number.isFinite(rawChain)) {
|
|
@@ -34,6 +46,9 @@ function resolveChainConfig(billing) {
|
|
|
34
46
|
if (typeof rawEdge === 'string' && DATA_EDGE_RE.test(rawEdge)) {
|
|
35
47
|
dataEdgeAddress = rawEdge;
|
|
36
48
|
}
|
|
49
|
+
else if (rawEdge !== undefined && rawEdge !== null) {
|
|
50
|
+
onMalformedDataEdge?.(rawEdge);
|
|
51
|
+
}
|
|
37
52
|
return { chainId, dataEdgeAddress };
|
|
38
53
|
}
|
|
39
54
|
/**
|
|
@@ -49,10 +64,18 @@ function resolveChainConfig(billing) {
|
|
|
49
64
|
function buildSubgraphOverrides(input) {
|
|
50
65
|
const overrides = {
|
|
51
66
|
relayUrl: input.relayUrl,
|
|
52
|
-
mnemonic: input.mnemonic,
|
|
53
67
|
authKeyHex: input.authKeyHex,
|
|
54
68
|
walletAddress: input.walletAddress,
|
|
55
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
|
+
}
|
|
56
79
|
// Only thread a finite chainId — never let an undefined clobber the store's
|
|
57
80
|
// Gnosis (100) default via the spread merge.
|
|
58
81
|
if (typeof input.chainId === 'number' && Number.isFinite(input.chainId)) {
|
|
@@ -63,4 +86,50 @@ function buildSubgraphOverrides(input) {
|
|
|
63
86
|
}
|
|
64
87
|
return overrides;
|
|
65
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
|
+
}
|
|
66
135
|
//# sourceMappingURL=chain-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain-config.js","sourceRoot":"","sources":["../../src/subgraph/chain-config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;
|
|
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,OAAmD,EACnD,mBAA4C;IAE5C,IAAI,OAAO,GAAG,gBAAgB,CAAC;IAC/B,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,CAAC;IACnC,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9D,OAAO,GAAG,QAAQ,CAAC;IACrB,CAAC;IAED,IAAI,eAAmC,CAAC;IACxC,MAAM,OAAO,GAAG,OAAO,EAAE,iBAAiB,CAAC;IAC3C,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9D,eAA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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"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TotalReclaw MCP — managed-mode credential resolution (Option E Phase 2 /
|
|
4
|
+
* #581, P2-13).
|
|
5
|
+
*
|
|
6
|
+
* Reads `~/.totalreclaw/credentials.json` (or `TOTALRECLAW_RECOVERY_PHRASE`)
|
|
7
|
+
* and resolves EITHER a BIP-39 mnemonic OR a `derived-bundle-v1` bundle,
|
|
8
|
+
* mirroring the precedence `python/src/totalreclaw/agent/state.py::_try_auto_configure`
|
|
9
|
+
* implements for Hermes:
|
|
10
|
+
*
|
|
11
|
+
* 1. `TOTALRECLAW_RECOVERY_PHRASE` env — retained, deprecated (phrase).
|
|
12
|
+
* 2. `credentials.json` `version: 2` — a `derived-bundle-v1` bundle.
|
|
13
|
+
* 3. `credentials.json` legacy — plaintext `{"mnemonic": "…"}`.
|
|
14
|
+
*
|
|
15
|
+
* Deliberately narrower than the Python precedence chain: MCP has no
|
|
16
|
+
* `TOTALRECLAW_CREDENTIALS_PROVIDER` / external-provider transport
|
|
17
|
+
* (`credential_provider.py`) and no OS-keychain unwrap
|
|
18
|
+
* (`credentials_wrap.py`) — both are tracked as explicit known gaps (see
|
|
19
|
+
* `mcp/README.md`, CLAUDE.md's Known Gaps table) rather than silently
|
|
20
|
+
* unsupported. A `keychain_wrapped: true` v2 file is a LOUD, actionable
|
|
21
|
+
* error here, not a silent skip — the same "never silently downgrade"
|
|
22
|
+
* posture the unknown-`version` branch below takes.
|
|
23
|
+
*
|
|
24
|
+
* This module never reads self-hosted credentials (`ClientState`/
|
|
25
|
+
* `MASTER_PASSWORD` in `index.ts`) — self-hosted mode is a completely
|
|
26
|
+
* separate credential system with no BIP-39 root at all (derived-bundle-v1.md
|
|
27
|
+
* §4.5.1) and callers MUST route around this module entirely when
|
|
28
|
+
* `TOTALRECLAW_SELF_HOSTED=true`. See `index.ts`'s `main()` for the gate.
|
|
29
|
+
*/
|
|
30
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
33
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
34
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
35
|
+
}
|
|
36
|
+
Object.defineProperty(o, k2, desc);
|
|
37
|
+
}) : (function(o, m, k, k2) {
|
|
38
|
+
if (k2 === undefined) k2 = k;
|
|
39
|
+
o[k2] = m[k];
|
|
40
|
+
}));
|
|
41
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
42
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
43
|
+
}) : function(o, v) {
|
|
44
|
+
o["default"] = v;
|
|
45
|
+
});
|
|
46
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
47
|
+
var ownKeys = function(o) {
|
|
48
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
49
|
+
var ar = [];
|
|
50
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
51
|
+
return ar;
|
|
52
|
+
};
|
|
53
|
+
return ownKeys(o);
|
|
54
|
+
};
|
|
55
|
+
return function (mod) {
|
|
56
|
+
if (mod && mod.__esModule) return mod;
|
|
57
|
+
var result = {};
|
|
58
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
59
|
+
__setModuleDefault(result, mod);
|
|
60
|
+
return result;
|
|
61
|
+
};
|
|
62
|
+
})();
|
|
63
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
+
exports.resolveManagedCredential = resolveManagedCredential;
|
|
65
|
+
exports.isV2BundleCredentialsFile = isV2BundleCredentialsFile;
|
|
66
|
+
const fs = __importStar(require("node:fs"));
|
|
67
|
+
const bip39_1 = require("@scure/bip39");
|
|
68
|
+
const english_js_1 = require("@scure/bip39/wordlists/english.js");
|
|
69
|
+
const bundle_js_1 = require("./bundle.js");
|
|
70
|
+
const setup_js_1 = require("../cli/setup.js");
|
|
71
|
+
function isValidBip39Mnemonic(candidate) {
|
|
72
|
+
const words = candidate.split(/\s+/);
|
|
73
|
+
if (words.length !== 12 && words.length !== 24)
|
|
74
|
+
return false;
|
|
75
|
+
const allWordsValid = words.every((w) => english_js_1.wordlist.includes(w));
|
|
76
|
+
return (0, bip39_1.validateMnemonic)(candidate, english_js_1.wordlist) || allWordsValid;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Resolve the managed-mode credential per the precedence above.
|
|
80
|
+
*
|
|
81
|
+
* Returns `undefined` when nothing is configured (equivalent to today's
|
|
82
|
+
* `resolveMnemonic()` returning `undefined` — falls through to
|
|
83
|
+
* `unconfigured` mode).
|
|
84
|
+
*
|
|
85
|
+
* Throws — never returns — on a credentials.json that is present but
|
|
86
|
+
* malformed in a way that must not be silently downgraded:
|
|
87
|
+
* - `version` present and not `2` (derived-bundle-v1.md §4.7 / the
|
|
88
|
+
* client-consistency contract: unknown version is a loud error).
|
|
89
|
+
* - `version === 2` but `keychain_wrapped: true` (MCP has no keychain
|
|
90
|
+
* unwrap — see the module doc).
|
|
91
|
+
* - `version === 2` and the bundle fails `parseBundleV1`'s §4.7
|
|
92
|
+
* validation (malformed hex, unknown `signing.kind`, address/key
|
|
93
|
+
* mismatch, …).
|
|
94
|
+
*
|
|
95
|
+
* A missing file, an unreadable file, or a file that fails to parse as JSON
|
|
96
|
+
* at all are treated as "nothing configured" (`undefined`) — matching the
|
|
97
|
+
* pre-existing `resolveMnemonic()` behaviour exactly, since a bare ENOENT or
|
|
98
|
+
* a syntax error is not evidence of tampering the way a well-formed-but-
|
|
99
|
+
* wrong `version` is.
|
|
100
|
+
*/
|
|
101
|
+
function resolveManagedCredential(opts = {}) {
|
|
102
|
+
const env = opts.env ?? process.env;
|
|
103
|
+
// 1. TOTALRECLAW_RECOVERY_PHRASE env — retained, deprecated.
|
|
104
|
+
const envPhrase = env.TOTALRECLAW_RECOVERY_PHRASE;
|
|
105
|
+
if (envPhrase && envPhrase.trim().length > 0) {
|
|
106
|
+
// #618 adversarial-review NIT (mirrors
|
|
107
|
+
// python/src/totalreclaw/agent/state.py's equivalent env-branch
|
|
108
|
+
// logging): the env phrase wins the precedence race unconditionally,
|
|
109
|
+
// which silently shadows a v2 bundle if one also happens to exist at
|
|
110
|
+
// the same path — a state an operator mid-migration (env var not yet
|
|
111
|
+
// unset after provisioning a bundle) could easily land in without
|
|
112
|
+
// noticing. Best-effort, plain JSON peek only (no parseBundleV1 — this
|
|
113
|
+
// is a diagnostic, not a validation path); never throws.
|
|
114
|
+
try {
|
|
115
|
+
const credentialsPath = opts.credentialsPath ?? setup_js_1.CREDENTIALS_PATH;
|
|
116
|
+
const raw = fs.readFileSync(credentialsPath, 'utf-8');
|
|
117
|
+
const parsed = JSON.parse(raw);
|
|
118
|
+
if (parsed.version === 2) {
|
|
119
|
+
console.error('TotalReclaw: TOTALRECLAW_RECOVERY_PHRASE is set and takes precedence over the ' +
|
|
120
|
+
`derived-bundle-v1 bundle at ${credentialsPath} (version: 2), which is being ` +
|
|
121
|
+
'shadowed. Unset the env var to use the bundle, or remove the bundle file if the ' +
|
|
122
|
+
'env-var phrase is the intended credential.');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// No file, unreadable, or not JSON — nothing to shadow, stay silent.
|
|
127
|
+
}
|
|
128
|
+
return { kind: 'mnemonic', mnemonic: envPhrase.trim() };
|
|
129
|
+
}
|
|
130
|
+
// 2/3. credentials.json
|
|
131
|
+
const credentialsPath = opts.credentialsPath ?? setup_js_1.CREDENTIALS_PATH;
|
|
132
|
+
let raw;
|
|
133
|
+
try {
|
|
134
|
+
raw = fs.readFileSync(credentialsPath, 'utf-8');
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return undefined; // no file — unconfigured, not an error.
|
|
138
|
+
}
|
|
139
|
+
let parsed;
|
|
140
|
+
try {
|
|
141
|
+
parsed = JSON.parse(raw);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return undefined; // unparsable — treated as unconfigured, matches legacy behaviour.
|
|
145
|
+
}
|
|
146
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
const obj = parsed;
|
|
150
|
+
const version = obj.version;
|
|
151
|
+
if (version === 2) {
|
|
152
|
+
if (obj.keychain_wrapped === true) {
|
|
153
|
+
throw new Error('credentials.json has version=2 with keychain_wrapped=true, but the MCP server ' +
|
|
154
|
+
'does not implement OS-keychain unwrapping (that is Python/Hermes-only — see ' +
|
|
155
|
+
'derived-bundle-v1.md §4.3 and mcp/README.md\'s Known Gaps). Provision a ' +
|
|
156
|
+
'plaintext derived-bundle-v1 bundle (the "headless / no keychain" storage form) ' +
|
|
157
|
+
'for MCP hosts instead.');
|
|
158
|
+
}
|
|
159
|
+
// parseBundleV1 runs every derived-bundle-v1.md §4.7 invariant and
|
|
160
|
+
// throws a loud, actionable Error on any violation — never a silent
|
|
161
|
+
// downgrade to legacy mnemonic handling.
|
|
162
|
+
const bundle = (0, bundle_js_1.parseBundleV1)(JSON.stringify(obj));
|
|
163
|
+
return { kind: 'bundle', bundle };
|
|
164
|
+
}
|
|
165
|
+
if (version !== undefined) {
|
|
166
|
+
throw new Error(`credentials.json has an unrecognised version=${JSON.stringify(version)}. Expected 2 ` +
|
|
167
|
+
'(a derived-bundle-v1 bundle) or no version key at all (legacy plaintext mnemonic). ' +
|
|
168
|
+
'Refusing to guess — an unknown version is never silently treated as legacy.');
|
|
169
|
+
}
|
|
170
|
+
// 4. Legacy: plaintext {"mnemonic": "…"}.
|
|
171
|
+
const mnemonicField = obj.mnemonic;
|
|
172
|
+
if (typeof mnemonicField === 'string' && mnemonicField.trim().length > 0) {
|
|
173
|
+
const trimmed = mnemonicField.trim();
|
|
174
|
+
if (isValidBip39Mnemonic(trimmed)) {
|
|
175
|
+
return { kind: 'mnemonic', mnemonic: trimmed };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
// ---------------------------------------------------------------------------
|
|
181
|
+
// Self-hosted diagnostic (#618 adversarial-review item 2). Lives here
|
|
182
|
+
// (rather than inline in `index.ts`) so it has direct test coverage —
|
|
183
|
+
// `index.ts` cannot be unit-tested (importing it executes `main()`).
|
|
184
|
+
// ---------------------------------------------------------------------------
|
|
185
|
+
/**
|
|
186
|
+
* Diagnostic-only check: does the credentials file at `credentialsPath`
|
|
187
|
+
* look like a `derived-bundle-v1` `version: 2` file? Plain `JSON.parse`,
|
|
188
|
+
* no WASM, no `parseBundleV1` — the only caller
|
|
189
|
+
* (`index.ts`'s `TOTALRECLAW_SELF_HOSTED` branch in `main()`) must never
|
|
190
|
+
* touch bundle parsing/validation at all; self-hosted mode is a wholly
|
|
191
|
+
* separate credential system (derived-bundle-v1.md §4.5.1) and this
|
|
192
|
+
* function exists purely to produce a more accurate diagnostic message —
|
|
193
|
+
* "is the `version` field present and `2`" — when self-hosted mode finds
|
|
194
|
+
* no usable mnemonic and would otherwise tell the operator to "set
|
|
195
|
+
* TOTALRECLAW_RECOVERY_PHRASE", which is actively wrong when a
|
|
196
|
+
* valid-but-wrong-mode bundle credential is already present.
|
|
197
|
+
*
|
|
198
|
+
* Never throws; a missing/corrupt/non-bundle file is simply `false`.
|
|
199
|
+
*/
|
|
200
|
+
function isV2BundleCredentialsFile(credentialsPath) {
|
|
201
|
+
try {
|
|
202
|
+
const raw = fs.readFileSync(credentialsPath, 'utf-8');
|
|
203
|
+
const parsed = JSON.parse(raw);
|
|
204
|
+
return parsed.version === 2;
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/subgraph/credentials.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDH,4DA0FC;AAuBD,8DAQC;AA1KD,4CAA8B;AAE9B,wCAAgD;AAChD,kEAA6D;AAE7D,2CAAkE;AAClE,8CAAmD;AAanD,SAAS,oBAAoB,CAAC,SAAiB;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IAC7D,MAAM,aAAa,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,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,KAAK,QAAQ,IAAI,aAAa,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzE,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,EAAE,CAAC;QACrC,IAAI,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC;YAClC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;QACjD,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,8EAA8E;AAC9E,sEAAsE;AACtE,sEAAsE;AACtE,qEAAqE;AACrE,8EAA8E;AAE9E;;;;;;;;;;;;;;GAcG;AACH,SAAgB,yBAAyB,CAAC,eAAuB;IAC/D,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAA0B,CAAC;QACxD,OAAO,MAAM,CAAC,OAAO,KAAK,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/dist/subgraph/store.d.ts
CHANGED
|
@@ -13,10 +13,35 @@
|
|
|
13
13
|
* Adapted from skill/plugin/subgraph-store.ts for the MCP server context.
|
|
14
14
|
* Config can be injected directly (for MCP server state) or read from env vars.
|
|
15
15
|
*/
|
|
16
|
-
import { type Chain } from 'viem';
|
|
16
|
+
import { type Chain, type LocalAccount } from 'viem';
|
|
17
|
+
/**
|
|
18
|
+
* Default EventfulDataEdge contract address on Gnosis mainnet — the
|
|
19
|
+
* PRODUCTION DataEdge. Exported (not just a local const) so callers that
|
|
20
|
+
* need to name it in a diagnostic/warning log (e.g. `index.ts`'s
|
|
21
|
+
* mnemonic-mode billing-unavailable fallback, #618 adversarial-review
|
|
22
|
+
* fixup) don't duplicate the literal and risk it drifting.
|
|
23
|
+
*/
|
|
24
|
+
export declare const DEFAULT_DATA_EDGE_ADDRESS = "0xC445af1D4EB9fce4e1E61fE96ea7B8feBF03c5ca";
|
|
17
25
|
export interface SubgraphStoreConfig {
|
|
18
26
|
relayUrl: string;
|
|
19
|
-
|
|
27
|
+
/**
|
|
28
|
+
* BIP-39 mnemonic for key derivation. Mutually exclusive with
|
|
29
|
+
* `ownerPrivateKeyHex` (Option E Phase 2 / #581, P2-13) — a bundle-mode
|
|
30
|
+
* caller has no mnemonic anywhere in the process (derived-bundle-v1.md
|
|
31
|
+
* §4.6 point 1) and threads the bundle's `signing.private_key` directly
|
|
32
|
+
* instead. Exactly one of the two must be present; see
|
|
33
|
+
* `resolveOwnerAccount` below for the resolution + error contract.
|
|
34
|
+
*/
|
|
35
|
+
mnemonic?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Bundle-mode signing key — 64 lowercase hex chars, no `0x` prefix
|
|
38
|
+
* (`bundle.signing.private_key`, `signing.kind === "owner-eoa"` only;
|
|
39
|
+
* Phase 2 does not support submitting on-chain with a `session-key`
|
|
40
|
+
* bundle — that requires the signing-delegation phase, see
|
|
41
|
+
* derived-bundle-v1.md §4.2). Takes precedence over `mnemonic` when both
|
|
42
|
+
* happen to be set (never expected in practice).
|
|
43
|
+
*/
|
|
44
|
+
ownerPrivateKeyHex?: string;
|
|
20
45
|
cachePath: string;
|
|
21
46
|
chainId: number;
|
|
22
47
|
dataEdgeAddress: string;
|
|
@@ -24,6 +49,18 @@ export interface SubgraphStoreConfig {
|
|
|
24
49
|
authKeyHex?: string;
|
|
25
50
|
walletAddress?: string;
|
|
26
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolve the Smart Account **owner** signing account from whichever
|
|
54
|
+
* credential source `config` carries.
|
|
55
|
+
*
|
|
56
|
+
* Prefers `ownerPrivateKeyHex` (bundle mode) over `mnemonic` (legacy mode)
|
|
57
|
+
* when — contrary to the normal precedence contract — both are somehow
|
|
58
|
+
* present, since the private key is the more direct source of truth and
|
|
59
|
+
* skips a redundant BIP-44 derivation. Throws a loud, actionable error when
|
|
60
|
+
* NEITHER is present rather than letting `mnemonicToAccount(undefined)`
|
|
61
|
+
* throw viem's own less legible error.
|
|
62
|
+
*/
|
|
63
|
+
export declare function resolveOwnerAccount(config: SubgraphStoreConfig): LocalAccount;
|
|
27
64
|
export interface FactPayload {
|
|
28
65
|
id: string;
|
|
29
66
|
timestamp: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/subgraph/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAwE,KAAK,KAAK,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/subgraph/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAwE,KAAK,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AAa3H;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,+CAA+C,CAAC;AAKtF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,GAAG,YAAY,CAc7E;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,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eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAqB/C;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,gBAAgB,EAAE,MAAM,EAAE,EAC1B,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAOtE;AAMD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAG1D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAkB/F"}
|
package/dist/subgraph/store.js
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
* Config can be injected directly (for MCP server state) or read from env vars.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.PROTOBUF_VERSION_V4 = void 0;
|
|
18
|
+
exports.PROTOBUF_VERSION_V4 = exports.DEFAULT_DATA_EDGE_ADDRESS = void 0;
|
|
19
|
+
exports.resolveOwnerAccount = resolveOwnerAccount;
|
|
19
20
|
exports.encodeFactProtobuf = encodeFactProtobuf;
|
|
20
21
|
exports.encodeVarint = encodeVarint;
|
|
21
22
|
exports.getChainFromId = getChainFromId;
|
|
@@ -38,10 +39,40 @@ const pimlico_1 = require("permissionless/clients/pimlico");
|
|
|
38
39
|
// ---------------------------------------------------------------------------
|
|
39
40
|
// Types
|
|
40
41
|
// ---------------------------------------------------------------------------
|
|
41
|
-
/**
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Default EventfulDataEdge contract address on Gnosis mainnet — the
|
|
44
|
+
* PRODUCTION DataEdge. Exported (not just a local const) so callers that
|
|
45
|
+
* need to name it in a diagnostic/warning log (e.g. `index.ts`'s
|
|
46
|
+
* mnemonic-mode billing-unavailable fallback, #618 adversarial-review
|
|
47
|
+
* fixup) don't duplicate the literal and risk it drifting.
|
|
48
|
+
*/
|
|
49
|
+
exports.DEFAULT_DATA_EDGE_ADDRESS = '0xC445af1D4EB9fce4e1E61fE96ea7B8feBF03c5ca';
|
|
43
50
|
/** Well-known ERC-4337 EntryPoint v0.7 address (same on all chains) */
|
|
44
51
|
const DEFAULT_ENTRYPOINT_ADDRESS = '0x0000000071727De22E5E9d8BAf0edAc6f37da032';
|
|
52
|
+
/**
|
|
53
|
+
* Resolve the Smart Account **owner** signing account from whichever
|
|
54
|
+
* credential source `config` carries.
|
|
55
|
+
*
|
|
56
|
+
* Prefers `ownerPrivateKeyHex` (bundle mode) over `mnemonic` (legacy mode)
|
|
57
|
+
* when — contrary to the normal precedence contract — both are somehow
|
|
58
|
+
* present, since the private key is the more direct source of truth and
|
|
59
|
+
* skips a redundant BIP-44 derivation. Throws a loud, actionable error when
|
|
60
|
+
* NEITHER is present rather than letting `mnemonicToAccount(undefined)`
|
|
61
|
+
* throw viem's own less legible error.
|
|
62
|
+
*/
|
|
63
|
+
function resolveOwnerAccount(config) {
|
|
64
|
+
if (config.ownerPrivateKeyHex) {
|
|
65
|
+
const hex = config.ownerPrivateKeyHex.startsWith('0x')
|
|
66
|
+
? config.ownerPrivateKeyHex
|
|
67
|
+
: `0x${config.ownerPrivateKeyHex}`;
|
|
68
|
+
return (0, accounts_1.privateKeyToAccount)(hex);
|
|
69
|
+
}
|
|
70
|
+
if (config.mnemonic) {
|
|
71
|
+
return (0, accounts_1.mnemonicToAccount)(config.mnemonic);
|
|
72
|
+
}
|
|
73
|
+
throw new Error('On-chain submission requires either a mnemonic or a bundle-mode ' +
|
|
74
|
+
'ownerPrivateKeyHex — neither is present on this SubgraphStoreConfig.');
|
|
75
|
+
}
|
|
45
76
|
// ---------------------------------------------------------------------------
|
|
46
77
|
// Protobuf encoding
|
|
47
78
|
// ---------------------------------------------------------------------------
|
|
@@ -179,8 +210,8 @@ async function submitFactOnChain(protobufPayload, config) {
|
|
|
179
210
|
if (!config.relayUrl) {
|
|
180
211
|
throw new Error('Relay URL is required for on-chain submission');
|
|
181
212
|
}
|
|
182
|
-
if (!config.mnemonic) {
|
|
183
|
-
throw new Error('Mnemonic is required for on-chain submission');
|
|
213
|
+
if (!config.mnemonic && !config.ownerPrivateKeyHex) {
|
|
214
|
+
throw new Error('Mnemonic or bundle-mode ownerPrivateKeyHex is required for on-chain submission');
|
|
184
215
|
}
|
|
185
216
|
const chain = getChainFromId(config.chainId);
|
|
186
217
|
const bundlerRpcUrl = getRelayBundlerUrl(config.relayUrl);
|
|
@@ -197,8 +228,9 @@ async function submitFactOnChain(protobufPayload, config) {
|
|
|
197
228
|
const authTransport = Object.keys(headers).length > 0
|
|
198
229
|
? (0, viem_1.http)(bundlerRpcUrl, { fetchOptions: { headers } })
|
|
199
230
|
: (0, viem_1.http)(bundlerRpcUrl);
|
|
200
|
-
// 1.
|
|
201
|
-
|
|
231
|
+
// 1. Resolve the owner signer — mnemonic-derived EOA (BIP-44
|
|
232
|
+
// m/44'/60'/0'/0/0) or bundle-mode `ownerPrivateKeyHex` directly.
|
|
233
|
+
const ownerAccount = resolveOwnerAccount(config);
|
|
202
234
|
// 2. Create a public client for chain reads (use default RPC, not bundler proxy)
|
|
203
235
|
const publicClient = (0, viem_1.createPublicClient)({
|
|
204
236
|
chain,
|
|
@@ -282,8 +314,8 @@ async function submitFactBatchOnChain(protobufPayloads, config) {
|
|
|
282
314
|
if (!config.relayUrl) {
|
|
283
315
|
throw new Error('Relay URL is required for on-chain submission');
|
|
284
316
|
}
|
|
285
|
-
if (!config.mnemonic) {
|
|
286
|
-
throw new Error('Mnemonic is required for on-chain submission');
|
|
317
|
+
if (!config.mnemonic && !config.ownerPrivateKeyHex) {
|
|
318
|
+
throw new Error('Mnemonic or bundle-mode ownerPrivateKeyHex is required for on-chain submission');
|
|
287
319
|
}
|
|
288
320
|
const chain = getChainFromId(config.chainId);
|
|
289
321
|
const bundlerRpcUrl = getRelayBundlerUrl(config.relayUrl);
|
|
@@ -299,7 +331,7 @@ async function submitFactBatchOnChain(protobufPayloads, config) {
|
|
|
299
331
|
const authTransport = Object.keys(headers).length > 0
|
|
300
332
|
? (0, viem_1.http)(bundlerRpcUrl, { fetchOptions: { headers } })
|
|
301
333
|
: (0, viem_1.http)(bundlerRpcUrl);
|
|
302
|
-
const ownerAccount = (
|
|
334
|
+
const ownerAccount = resolveOwnerAccount(config);
|
|
303
335
|
const publicClient = (0, viem_1.createPublicClient)({
|
|
304
336
|
chain,
|
|
305
337
|
transport: (0, viem_1.http)(),
|
|
@@ -368,7 +400,7 @@ function isLocalMode() {
|
|
|
368
400
|
async function submitFactLocal(protobufPayload, config) {
|
|
369
401
|
const rpcUrl = process.env.TOTALRECLAW_LOCAL_RPC;
|
|
370
402
|
const dataEdgeAddress = config.dataEdgeAddress;
|
|
371
|
-
const ownerAccount = (
|
|
403
|
+
const ownerAccount = resolveOwnerAccount(config);
|
|
372
404
|
const walletClient = (0, viem_1.createWalletClient)({
|
|
373
405
|
account: ownerAccount,
|
|
374
406
|
chain: chains_1.foundry,
|
|
@@ -441,7 +473,7 @@ function getSubgraphConfig(overrides) {
|
|
|
441
473
|
// billing chain_id (threaded via overrides) is authoritative; 84532
|
|
442
474
|
// (Base Sepolia) was retired. See chain-config.ts / #439.
|
|
443
475
|
chainId: 100,
|
|
444
|
-
dataEdgeAddress: process.env.TOTALRECLAW_DATA_EDGE_ADDRESS || DEFAULT_DATA_EDGE_ADDRESS,
|
|
476
|
+
dataEdgeAddress: process.env.TOTALRECLAW_DATA_EDGE_ADDRESS || exports.DEFAULT_DATA_EDGE_ADDRESS,
|
|
445
477
|
entryPointAddress: process.env.TOTALRECLAW_ENTRYPOINT_ADDRESS || DEFAULT_ENTRYPOINT_ADDRESS,
|
|
446
478
|
};
|
|
447
479
|
if (overrides) {
|