felix-mcp 2.0.106 → 2.0.108
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 +22 -23
- package/dist/getting-started-guide.js +17 -11
- package/dist/index.js +144 -39
- package/dist/key-backup.js +200 -13
- package/dist/money-journal-identity.js +57 -0
- package/package.json +2 -1
- package/server.json +2 -2
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ identity, creates an encrypted backup, pins the same reviewed package in Claude
|
|
|
14
14
|
Code, and verifies the result:
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
npx -y --package felix-mcp@2.0.
|
|
17
|
+
npx -y --package felix-mcp@2.0.108 felix-keys onboard --accept-terms --client claude
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
Requires Node.js 20.10 or newer. The command checks the active runtime before
|
|
@@ -27,7 +27,9 @@ code are stored directly in macOS Keychain and are never printed or returned to
|
|
|
27
27
|
the MCP client. The encrypted backup is created and authenticated automatically.
|
|
28
28
|
|
|
29
29
|
Restart or reconnect the MCP after onboarding, then call `get_status` and
|
|
30
|
-
confirm the client is compatible.
|
|
30
|
+
confirm the client is compatible. Call `get_custody_recovery_status` and
|
|
31
|
+
require `ready: true` before funding; no credential or recovery material is
|
|
32
|
+
returned.
|
|
31
33
|
|
|
32
34
|
Claude Code requires one human action: open `/permissions` and allow the
|
|
33
35
|
`mcp__felix` tool namespace. Felix cannot grant that permission itself.
|
|
@@ -39,7 +41,7 @@ For Claude Desktop:
|
|
|
39
41
|
"mcpServers": {
|
|
40
42
|
"felix": {
|
|
41
43
|
"command": "npx",
|
|
42
|
-
"args": ["-y", "felix-mcp@2.0.
|
|
44
|
+
"args": ["-y", "felix-mcp@2.0.108"]
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
}
|
|
@@ -109,26 +111,15 @@ can still cause loss. Read the Risk and Custody disclosures before funding.
|
|
|
109
111
|
|
|
110
112
|
## Back up the owner
|
|
111
113
|
|
|
112
|
-
Guided onboarding creates the encrypted
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
Guided onboarding creates and authenticates the encrypted recovery file in the
|
|
115
|
+
standard local documents folder automatically. The agent does not copy a key,
|
|
116
|
+
choose a password, or ask the user to run another terminal command. Verify it
|
|
117
|
+
with `get_custody_recovery_status`; require `ready: true` before funding.
|
|
115
118
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
felix-keys verify --input ~/Documents/felix-custody-....json
|
|
121
|
-
felix-keys restore --input ~/Documents/felix-custody-....json
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
The guided flow generates a high-entropy recovery code and stores it in macOS
|
|
125
|
-
Keychain automatically. No human-created backup password is required. For
|
|
126
|
-
off-device recovery, a human can run `felix-keys export-recovery-code`; the code
|
|
127
|
-
is shown only in a native dialog and never printed. Manual backup accepts a
|
|
128
|
-
separate passphrase of at least 16 characters. Felix cannot recover a lost
|
|
129
|
-
recovery code, passphrase, or owner key. Restoring a different identity is
|
|
130
|
-
refused; use the explicit identity-replacement flow only when you understand
|
|
131
|
-
that accounts owned by the previous key may become unreachable.
|
|
119
|
+
The recovery code remains in macOS Keychain and never enters model context.
|
|
120
|
+
Owner-controlled off-device recovery is optional and separate from normal
|
|
121
|
+
onboarding. Felix cannot recover a lost owner key and will not replace an
|
|
122
|
+
existing identity silently.
|
|
132
123
|
|
|
133
124
|
## Account binding and keys
|
|
134
125
|
|
|
@@ -141,7 +132,15 @@ If the saved account and credential do not match, tools fail with
|
|
|
141
132
|
`session_binding_recovery_required`; they do not silently show a different
|
|
142
133
|
account. Use `list_accounts` and `use_child_account` to select the intended
|
|
143
134
|
child. Use `reload_launcher_key` only when you intentionally want the launcher
|
|
144
|
-
identity in that process.
|
|
135
|
+
identity in that process. It rereads the current macOS Keychain identity,
|
|
136
|
+
authenticates that owner's encrypted money-workflow journal, and changes the
|
|
137
|
+
session only after both checks pass.
|
|
138
|
+
|
|
139
|
+
Money-workflow journals are encrypted and isolated per owner identity. Existing
|
|
140
|
+
pre-2.0.108 journals migrate only after their authentication tag verifies. If a
|
|
141
|
+
tool returns `operation_state_unavailable`, preserve the journal and restore the
|
|
142
|
+
matching owner backup; never delete local workflow state or retry an unresolved
|
|
143
|
+
money action with a new idempotency key.
|
|
145
144
|
|
|
146
145
|
Scopes are least-privilege:
|
|
147
146
|
|
|
@@ -13,7 +13,7 @@ the current legal bundle at https://felix.trade/legal before accepting it.
|
|
|
13
13
|
Let your AI agent run this single command:
|
|
14
14
|
|
|
15
15
|
~~~bash
|
|
16
|
-
npx -y --package felix-mcp@2.0.
|
|
16
|
+
npx -y --package felix-mcp@2.0.108 felix-keys onboard --accept-terms --client claude
|
|
17
17
|
~~~
|
|
18
18
|
|
|
19
19
|
After the user reviews the terms and explicitly authorizes acceptance, the agent
|
|
@@ -31,15 +31,14 @@ valid registration and matching backup state are reused rather than replaced.
|
|
|
31
31
|
Requires Node.js 20.10 or newer. If an old Node is active, onboarding stops
|
|
32
32
|
before creating or changing any credential and prints the exact installed
|
|
33
33
|
version. Never put a key or recovery code in a prompt, command-line argument,
|
|
34
|
-
environment variable, or chat.
|
|
35
|
-
|
|
36
|
-
dialog and never prints it.
|
|
34
|
+
environment variable, or chat. Optional owner-controlled off-device recovery
|
|
35
|
+
is separate from onboarding and never returns recovery material to the agent.
|
|
37
36
|
|
|
38
37
|
Reconnect the MCP after onboarding. Claude Code also requires one host-level
|
|
39
38
|
permission: allow the 'mcp__felix' tool namespace. Felix cannot approve its own
|
|
40
|
-
tools. Call 'get_status' and confirm
|
|
41
|
-
|
|
42
|
-
creating an account.
|
|
39
|
+
tools. Call 'get_status' and confirm that the API key, owner signer, and client
|
|
40
|
+
compatibility are healthy. Then call 'get_custody_recovery_status' and require
|
|
41
|
+
'ready: true' before creating or funding an account.
|
|
43
42
|
|
|
44
43
|
### Explore without funds: explicit paper sandbox
|
|
45
44
|
|
|
@@ -90,8 +89,9 @@ The workflow resumes completed checkpoints and reports whether any money moved.
|
|
|
90
89
|
The MCP derives a unique account owner from the local root owner, verifies and
|
|
91
90
|
signs the exact Safe policy locally, activates the wallet, enables supported
|
|
92
91
|
venues, mints a least-privilege live key, stores the account binding in
|
|
93
|
-
Keychain, and activates it.
|
|
94
|
-
|
|
92
|
+
Keychain, and activates it. Guided onboarding already created the encrypted
|
|
93
|
+
recovery file; require 'get_custody_recovery_status.ready: true' before
|
|
94
|
+
depositing meaningful funds.
|
|
95
95
|
|
|
96
96
|
Registration, key minting, and an unfunded account reservation do not spend
|
|
97
97
|
chain gas. Felix covers initial wallet-activation gas only after the owner
|
|
@@ -197,14 +197,20 @@ allowlist, limit, or expiry before signing.
|
|
|
197
197
|
|
|
198
198
|
## Recovery and help
|
|
199
199
|
|
|
200
|
-
- Missing launcher key
|
|
201
|
-
|
|
200
|
+
- Missing launcher key on a new device: rerun the pinned guided onboarding
|
|
201
|
+
command, then reconnect. It safely reuses a matching installed identity.
|
|
202
202
|
- Missing owner key: restore the correct encrypted backup. Never create a new
|
|
203
203
|
owner for an already-funded account.
|
|
204
204
|
- Wrong child after reconnect: stop. MCP 2.0.96+ isolates persisted selection
|
|
205
205
|
per client process, so a new client starts on the launcher and an in-session
|
|
206
206
|
reconnect can restore only that session's child. Call 'use_child_account'
|
|
207
207
|
explicitly and verify 'get_status.mcp.active_account_id' before money work.
|
|
208
|
+
- Launcher identity changed while the MCP was running: call
|
|
209
|
+
'reload_launcher_key'. MCP 2.0.108+ rereads the current Keychain pair and
|
|
210
|
+
authenticates its owner-scoped encrypted money journal before changing the
|
|
211
|
+
session. If it returns 'operation_state_unavailable', preserve local state
|
|
212
|
+
and restore the matching owner backup; never delete the journal or invent a
|
|
213
|
+
new idempotency key for an unresolved operation.
|
|
208
214
|
- Interrupted money operation: reuse its idempotency key and read
|
|
209
215
|
'felix://operations/recovery'.
|
|
210
216
|
- Product or account issue: read 'felix://support/agent' and open an
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* - Every network call has a timeout and transient retry only when safe.
|
|
14
14
|
*/
|
|
15
15
|
import { createCipheriv, createDecipheriv, createHash, randomBytes, randomUUID, } from "node:crypto";
|
|
16
|
-
import { chmodSync, closeSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
16
|
+
import { chmodSync, closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
17
17
|
import * as nodeNet from "node:net";
|
|
18
18
|
import { homedir, userInfo } from "node:os";
|
|
19
19
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -28,6 +28,7 @@ import { getLocalOpenOrderReservation, localOwnerAddress, placePreparedOrder, si
|
|
|
28
28
|
import { FELIX_LEGAL_BUNDLE_VERSION, legalAcceptanceFields, } from "./legal.js";
|
|
29
29
|
import { acceptedCryptoWithdrawalAmount, assertDeriveDepositReady, assertGasSponsorshipReady, assertSubscriptionPaymentIntent, confirmFundingFeeTransfer, executeCryptoReturnBridge, executeCryptoWithdrawal, executeDeriveChainWithdrawal, deriveFundingNonceUnchanged, executeFeeSettlement, executeNativeUsdcSwap, executeOwnerEoaWithdrawal, polygonFundingNonceUnchanged, relayedFundingNonceUnchanged, waitForRelayedFundingSubmission, waitForPolygonFundingSubmission, waitForDeriveFundingSubmission, executeFundingFeeTransfer, executeFundingIntent, fundingFeeInstructionsMatch, fundingIntentNeedsRefresh, fundingFeeNonceUnchanged, gasSponsorshipNeedsRefresh, inspectFeeSettlementIntent, preflightFundingFeeTransfer, preflightRecoveredFundingFeeTransfer, readArbitrumOwnerUsdcUnits, readDeriveOwnerReturnState, signGasSponsorship, validateFundingFeeTransfer, } from "./funding.js";
|
|
30
30
|
import { safeClientErrorMessage } from "./safe-error.js";
|
|
31
|
+
import { freshWorkflowIdentityMarkerPath, legacyWorkflowJournalPath, scopedWorkflowJournalPath, workflowIdentityFingerprint, } from "./money-journal-identity.js";
|
|
31
32
|
import { isClientSignatureRequired, polymarketIntentReplay, } from "./polymarket-replay.js";
|
|
32
33
|
import { discloseFundingOwnerDebit } from "./funding-accounting.js";
|
|
33
34
|
import { signHyperliquidAgentApproval } from "./hyperliquid-onboarding.js";
|
|
@@ -36,6 +37,7 @@ import { policySubmitAmbiguity, policySubmitPending } from "./policy-workflow.js
|
|
|
36
37
|
import { executeSafeV3Migration, signSafeMigrationProof } from "./safe-migration.js";
|
|
37
38
|
import { deriveAccountOwnerPrivateKey, ownerAddressForPrivateKey, ownerPrivateKeyForAccountIdentity, signLiveKeyGrant, signRiskMandate, signSafeOnboardingProof, signSafeOnboardingTransactions, } from "./safe-onboarding.js";
|
|
38
39
|
import { signDeriveOnboardingTransactions } from "./derive-onboarding.js";
|
|
40
|
+
import { getCustodyRecoveryStatus } from "./key-backup.js";
|
|
39
41
|
import { clearRuntimeOwnerPrivateKey, getRuntimeOwnerPrivateKey, setRuntimeOwnerPrivateKey, } from "./secret-state.js";
|
|
40
42
|
import { STRATEGY_CTX_GUIDE, STRATEGY_EXAMPLES, STRATEGY_EXAMPLES_URI, STRATEGY_GUIDE_URI, STRATEGY_RESOURCES, strategyResourceText, } from "./strategy-guide.js";
|
|
41
43
|
import { AGENT_OPERATIONS_RESOURCES, agentOperationsResourceText, } from "./agent-ops-guide.js";
|
|
@@ -106,7 +108,7 @@ export function validatedApiBase(raw = process.env.FELIX_API_URL || `https://${O
|
|
|
106
108
|
return parsed.origin;
|
|
107
109
|
}
|
|
108
110
|
const API = validatedApiBase();
|
|
109
|
-
const MCP_VERSION = "2.0.
|
|
111
|
+
const MCP_VERSION = "2.0.108";
|
|
110
112
|
const PRACTICAL_NO_CAP_USD = 1_000_000_000;
|
|
111
113
|
const DEFAULT_WALLET_OPERATION_USD = 10_000_000;
|
|
112
114
|
const DEFAULT_WALLET_DAILY_USD = 100_000_000;
|
|
@@ -331,10 +333,18 @@ function persistActiveChildSession(accountId, apiKey) {
|
|
|
331
333
|
const HOSTED_TRANSPORT = process.env.FELIX_MCP_TRANSPORT === "http";
|
|
332
334
|
// Hosted MCP requests authenticate independently through AsyncLocalStorage and
|
|
333
335
|
// never need a process-wide launcher or signer credential.
|
|
334
|
-
const
|
|
336
|
+
const API_CREDENTIAL_FROM_ENV = Object.prototype.hasOwnProperty.call(process.env, "FELIX_API_KEY");
|
|
337
|
+
const OWNER_CREDENTIAL_FROM_ENV = Object.prototype.hasOwnProperty.call(process.env, "FELIX_ROOT_OWNER_PRIVATE_KEY") || Object.prototype.hasOwnProperty.call(process.env, "FELIX_OWNER_PRIVATE_KEY");
|
|
338
|
+
const KEYCHAIN_BACKED_CREDENTIALS = !HOSTED_TRANSPORT
|
|
339
|
+
&& (process.env.FELIX_CREDENTIAL_SOURCE === "keychain"
|
|
340
|
+
|| (!API_CREDENTIAL_FROM_ENV && !OWNER_CREDENTIAL_FROM_ENV));
|
|
341
|
+
// These are the currently trusted launcher credentials. They begin with the
|
|
342
|
+
// launch values and may change only through reload_launcher_key after the new
|
|
343
|
+
// Keychain pair and its authenticated journal have both been validated.
|
|
344
|
+
let START_KEY = HOSTED_TRANSPORT
|
|
335
345
|
? ""
|
|
336
346
|
: configuredCredential("FELIX_API_KEY", KEYCHAIN_API_SERVICE);
|
|
337
|
-
|
|
347
|
+
let START_OWNER_KEY = HOSTED_TRANSPORT
|
|
338
348
|
? ""
|
|
339
349
|
: Object.prototype.hasOwnProperty.call(process.env, "FELIX_ROOT_OWNER_PRIVATE_KEY")
|
|
340
350
|
? (process.env.FELIX_ROOT_OWNER_PRIVATE_KEY || "")
|
|
@@ -355,6 +365,7 @@ delete process.env.FELIX_OWNER_PRIVATE_KEY;
|
|
|
355
365
|
delete process.env.FELIX_ACTIVE_ACCOUNT_ID;
|
|
356
366
|
delete process.env.FELIX_EPHEMERAL_SESSION;
|
|
357
367
|
delete process.env.FELIX_BINDING_PROFILE;
|
|
368
|
+
delete process.env.FELIX_CREDENTIAL_SOURCE;
|
|
358
369
|
const PROCESS_STARTED_AT = new Date().toISOString();
|
|
359
370
|
const TIMEOUT_MS = clampInt(process.env.FELIX_TIMEOUT_MS, 3_000, 60_000, 20_000);
|
|
360
371
|
const CLOSE_POLL_WAIT_MS = clampInt(process.env.FELIX_CLOSE_POLL_WAIT_MS, 2_000, 30_000, 12_000);
|
|
@@ -488,30 +499,31 @@ export function markMoneyNotStarted(result) {
|
|
|
488
499
|
});
|
|
489
500
|
return result;
|
|
490
501
|
}
|
|
491
|
-
function
|
|
502
|
+
function moneyWorkflowOwnerKey(ownerKey = START_OWNER_KEY) {
|
|
503
|
+
if (EVM_PRIVATE_KEY_RE.test(ownerKey))
|
|
504
|
+
return ownerKey;
|
|
505
|
+
const runtimeOwner = getRuntimeOwnerPrivateKey();
|
|
506
|
+
return EVM_PRIVATE_KEY_RE.test(runtimeOwner || "") ? runtimeOwner : "";
|
|
507
|
+
}
|
|
508
|
+
function moneyWorkflowPath(ownerKey = START_OWNER_KEY) {
|
|
492
509
|
return process.env.FELIX_WORKFLOW_STATE_FILE
|
|
493
|
-
||
|
|
510
|
+
|| scopedWorkflowJournalPath(moneyWorkflowOwnerKey(ownerKey));
|
|
494
511
|
}
|
|
495
|
-
function moneyWorkflowEncryptionKey() {
|
|
496
|
-
|
|
497
|
-
START_OWNER_KEY,
|
|
498
|
-
getRuntimeOwnerPrivateKey(),
|
|
499
|
-
].find((candidate) => EVM_PRIVATE_KEY_RE.test(candidate || "")) || "";
|
|
512
|
+
function moneyWorkflowEncryptionKey(ownerKey = START_OWNER_KEY) {
|
|
513
|
+
ownerKey = moneyWorkflowOwnerKey(ownerKey);
|
|
500
514
|
if (!EVM_PRIVATE_KEY_RE.test(ownerKey)) {
|
|
501
515
|
throw new Error("A valid local owner key is required for the encrypted money-workflow journal.");
|
|
502
516
|
}
|
|
503
517
|
return createHash("sha256").update(`felix-money-workflows-v1:${ownerKey}`).digest();
|
|
504
518
|
}
|
|
505
|
-
function
|
|
506
|
-
const path = moneyWorkflowPath();
|
|
519
|
+
function readMoneyWorkflowJournalAtPath(path, encryptionKey) {
|
|
507
520
|
let encoded;
|
|
508
521
|
try {
|
|
509
522
|
encoded = readFileSync(path, "utf8");
|
|
510
523
|
}
|
|
511
524
|
catch (error) {
|
|
512
|
-
if (error.code === "ENOENT")
|
|
513
|
-
return
|
|
514
|
-
}
|
|
525
|
+
if (error.code === "ENOENT")
|
|
526
|
+
return undefined;
|
|
515
527
|
throw new Error("The encrypted money-workflow journal is unavailable; refusing to move funds.");
|
|
516
528
|
}
|
|
517
529
|
try {
|
|
@@ -535,8 +547,7 @@ function readMoneyWorkflowJournal(encryptionKey = moneyWorkflowEncryptionKey())
|
|
|
535
547
|
throw new Error("The encrypted money-workflow journal cannot be authenticated; refusing to move funds.");
|
|
536
548
|
}
|
|
537
549
|
}
|
|
538
|
-
function writeMoneyWorkflowJournalRaw(journal, encryptionKey = moneyWorkflowEncryptionKey()) {
|
|
539
|
-
const path = moneyWorkflowPath();
|
|
550
|
+
function writeMoneyWorkflowJournalRaw(journal, encryptionKey = moneyWorkflowEncryptionKey(), path = moneyWorkflowPath()) {
|
|
540
551
|
const directory = dirname(path);
|
|
541
552
|
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
542
553
|
if ((statSync(directory).mode & 0o077) !== 0) {
|
|
@@ -558,9 +569,14 @@ function writeMoneyWorkflowJournalRaw(journal, encryptionKey = moneyWorkflowEncr
|
|
|
558
569
|
writeFileSync(temporary, `${envelope}\n`, { mode: 0o600 });
|
|
559
570
|
renameSync(temporary, path);
|
|
560
571
|
chmodSync(path, 0o600);
|
|
572
|
+
if (!process.env.FELIX_WORKFLOW_STATE_FILE && existsSync(`${path}.fresh`)) {
|
|
573
|
+
try {
|
|
574
|
+
unlinkSync(`${path}.fresh`);
|
|
575
|
+
}
|
|
576
|
+
catch { /* marker cleanup is best effort after durable write */ }
|
|
577
|
+
}
|
|
561
578
|
}
|
|
562
|
-
function acquireMoneyJournalMutationLock() {
|
|
563
|
-
const journalPath = moneyWorkflowPath();
|
|
579
|
+
function acquireMoneyJournalMutationLock(journalPath = moneyWorkflowPath()) {
|
|
564
580
|
const directory = dirname(journalPath);
|
|
565
581
|
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
566
582
|
if ((statSync(directory).mode & 0o077) !== 0) {
|
|
@@ -611,6 +627,30 @@ function acquireMoneyJournalMutationLock() {
|
|
|
611
627
|
}
|
|
612
628
|
return undefined;
|
|
613
629
|
}
|
|
630
|
+
function readMoneyWorkflowJournal(encryptionKey = moneyWorkflowEncryptionKey(), ownerKey = START_OWNER_KEY) {
|
|
631
|
+
const path = moneyWorkflowPath(ownerKey);
|
|
632
|
+
const scoped = readMoneyWorkflowJournalAtPath(path, encryptionKey);
|
|
633
|
+
if (scoped)
|
|
634
|
+
return scoped;
|
|
635
|
+
const empty = { version: 1, entries: {}, operations: {} };
|
|
636
|
+
if (process.env.FELIX_WORKFLOW_STATE_FILE)
|
|
637
|
+
return empty;
|
|
638
|
+
// A newly registered identity is explicitly marked by felix-keys. Reads stay
|
|
639
|
+
// pure and see empty state; the first locked mutation creates the scoped
|
|
640
|
+
// authenticated journal and consumes the marker after its atomic write.
|
|
641
|
+
if (existsSync(freshWorkflowIdentityMarkerPath(ownerKey))) {
|
|
642
|
+
return empty;
|
|
643
|
+
}
|
|
644
|
+
// One-time compatibility migration for pre-2.0.108 installations. Migration
|
|
645
|
+
// is permitted only after the legacy AES-GCM tag authenticates with this
|
|
646
|
+
// owner. This read remains side-effect-free; the next locked mutation writes
|
|
647
|
+
// the authenticated state to the scoped path.
|
|
648
|
+
const legacyPath = legacyWorkflowJournalPath();
|
|
649
|
+
const legacy = readMoneyWorkflowJournalAtPath(legacyPath, encryptionKey);
|
|
650
|
+
if (!legacy)
|
|
651
|
+
return empty;
|
|
652
|
+
return legacy;
|
|
653
|
+
}
|
|
614
654
|
function writeMoneyWorkflowJournal(journal, encryptionKey = moneyWorkflowEncryptionKey()) {
|
|
615
655
|
const lock = acquireMoneyJournalMutationLock();
|
|
616
656
|
if (!lock) {
|
|
@@ -3066,7 +3106,7 @@ async function call(method, path, body, opts = {}) {
|
|
|
3066
3106
|
}
|
|
3067
3107
|
}
|
|
3068
3108
|
if (!key && !opts.public) {
|
|
3069
|
-
return clientError("missing_api_key", "Set FELIX_API_KEY to a Felix fk_ key.", "
|
|
3109
|
+
return clientError("missing_api_key", "Set FELIX_API_KEY to a Felix fk_ key.", "Run the pinned felix-keys onboard command, then restart the MCP. It creates the local identity and encrypted recovery file automatically.");
|
|
3070
3110
|
}
|
|
3071
3111
|
const idempotencyKey = opts.idempotencyKey || (opts.idempotent ? randomUUID() : undefined);
|
|
3072
3112
|
const transportAttempts = opts.retryOnError === false ? 1 : (method === "GET" || idempotencyKey ? 2 : 1);
|
|
@@ -6687,7 +6727,7 @@ function normalizedPolymarketOrderBody(args) {
|
|
|
6687
6727
|
}
|
|
6688
6728
|
const TOOL_RISK_GROUPS = {
|
|
6689
6729
|
read: [
|
|
6690
|
-
"get_status", "get_health", "get_metrics", "get_strategy_guide",
|
|
6730
|
+
"get_status", "get_health", "get_metrics", "get_custody_recovery_status", "get_strategy_guide",
|
|
6691
6731
|
"get_market_streaming_guide",
|
|
6692
6732
|
"search_markets", "list_markets", "get_quote", "get_orderbook", "get_option_chain",
|
|
6693
6733
|
"research_market", "screen_markets", "get_earnings_calendar",
|
|
@@ -6844,6 +6884,11 @@ const TOOLS = [
|
|
|
6844
6884
|
description: "Authenticated guide to client-observable reliability fields: request ID, server latency, retry timing, and the public status URL. Process and platform diagnostics are not returned.",
|
|
6845
6885
|
inputSchema: schema({}),
|
|
6846
6886
|
},
|
|
6887
|
+
{
|
|
6888
|
+
name: "get_custody_recovery_status",
|
|
6889
|
+
description: "Verify that guided onboarding created an encrypted local recovery file which authenticates to the currently installed owner and launcher identity. Returns status only; no key, recovery code, credential, or file contents are exposed.",
|
|
6890
|
+
inputSchema: schema({}),
|
|
6891
|
+
},
|
|
6847
6892
|
{
|
|
6848
6893
|
name: "get_strategy_guide",
|
|
6849
6894
|
description: `Return the bundled think(ctx) API and hand-written strategy examples without an API key, network request, or generation quota. The same content is published as ${STRATEGY_GUIDE_URI} and ${STRATEGY_EXAMPLES_URI}.`,
|
|
@@ -6865,7 +6910,7 @@ const TOOLS = [
|
|
|
6865
6910
|
},
|
|
6866
6911
|
{
|
|
6867
6912
|
name: "reload_launcher_key",
|
|
6868
|
-
description: "
|
|
6913
|
+
description: "Reload the current launcher API key and owner signer from macOS Keychain, validate their encrypted workflow journal, and explicitly leave any child account. No secret is returned.",
|
|
6869
6914
|
inputSchema: schema({}),
|
|
6870
6915
|
},
|
|
6871
6916
|
{
|
|
@@ -7975,6 +8020,20 @@ export function makeServer() {
|
|
|
7975
8020
|
}
|
|
7976
8021
|
try {
|
|
7977
8022
|
switch (name) {
|
|
8023
|
+
case "get_custody_recovery_status": {
|
|
8024
|
+
out = isHostedTransport()
|
|
8025
|
+
? {
|
|
8026
|
+
ok: true,
|
|
8027
|
+
available: false,
|
|
8028
|
+
status: "local_stdio_required",
|
|
8029
|
+
ready: false,
|
|
8030
|
+
secrets_displayed: false,
|
|
8031
|
+
action_required: true,
|
|
8032
|
+
next_step: "Call this tool from the trusted local stdio MCP after guided onboarding.",
|
|
8033
|
+
}
|
|
8034
|
+
: await getCustodyRecoveryStatus();
|
|
8035
|
+
break;
|
|
8036
|
+
}
|
|
7978
8037
|
case "get_strategy_guide": {
|
|
7979
8038
|
const section = nonEmptyString(a.section)?.toLowerCase() || "all";
|
|
7980
8039
|
if (!new Set(["api", "examples", "all"]).has(section)) {
|
|
@@ -8009,7 +8068,7 @@ export function makeServer() {
|
|
|
8009
8068
|
}
|
|
8010
8069
|
case "set_api_key": {
|
|
8011
8070
|
if (!SET_API_KEY_TOOL_ENABLED) {
|
|
8012
|
-
out = clientError("tool_disabled", "set_api_key is disabled to keep credentials out of model and tool transcripts.", "
|
|
8071
|
+
out = clientError("tool_disabled", "set_api_key is disabled to keep credentials out of model and tool transcripts.", "Run the pinned felix-keys onboard command, then restart or use reload_launcher_key. Guided onboarding creates and verifies the encrypted recovery file automatically.");
|
|
8013
8072
|
break;
|
|
8014
8073
|
}
|
|
8015
8074
|
else if (isHostedTransport()) {
|
|
@@ -8039,22 +8098,68 @@ export function makeServer() {
|
|
|
8039
8098
|
if (isHostedTransport()) {
|
|
8040
8099
|
out = clientError("hosted_transport_stateless", "reload_launcher_key is unavailable on the stateless hosted transport.", "Reconnect with the intended Bearer token.");
|
|
8041
8100
|
}
|
|
8042
|
-
else if (!API_KEY_RE.test(START_KEY)) {
|
|
8043
|
-
out = clientError("launcher_key_unavailable", "This MCP process was not launched with a valid FELIX_API_KEY.", "Store the intended launcher key with felix-keys in a human-operated terminal, then restart.");
|
|
8044
|
-
}
|
|
8045
8101
|
else {
|
|
8046
|
-
|
|
8047
|
-
|
|
8048
|
-
|
|
8049
|
-
|
|
8050
|
-
|
|
8051
|
-
|
|
8102
|
+
const candidateApiKey = KEYCHAIN_BACKED_CREDENTIALS
|
|
8103
|
+
? localKeychainCredential(KEYCHAIN_API_SERVICE)
|
|
8104
|
+
: START_KEY;
|
|
8105
|
+
const candidateOwnerKey = KEYCHAIN_BACKED_CREDENTIALS
|
|
8106
|
+
? localKeychainCredential(KEYCHAIN_OWNER_SERVICE)
|
|
8107
|
+
: START_OWNER_KEY;
|
|
8108
|
+
if (!API_KEY_RE.test(candidateApiKey)
|
|
8109
|
+
|| (KEYCHAIN_BACKED_CREDENTIALS && !EVM_PRIVATE_KEY_RE.test(candidateOwnerKey))) {
|
|
8110
|
+
out = clientError("launcher_key_unavailable", KEYCHAIN_BACKED_CREDENTIALS
|
|
8111
|
+
? "macOS Keychain does not contain a complete valid Felix launcher identity."
|
|
8112
|
+
: "This MCP process was not launched with a complete valid Felix launcher identity.", "Run felix-keys status and restore the intended encrypted backup before retrying. No session credential was changed.");
|
|
8113
|
+
break;
|
|
8114
|
+
}
|
|
8115
|
+
try {
|
|
8116
|
+
// Authenticate local recovery state before changing either signer or
|
|
8117
|
+
// API identity. A corrupt same-owner journal remains a hard stop.
|
|
8118
|
+
if (EVM_PRIVATE_KEY_RE.test(candidateOwnerKey)) {
|
|
8119
|
+
readMoneyWorkflowJournal(moneyWorkflowEncryptionKey(candidateOwnerKey), candidateOwnerKey);
|
|
8120
|
+
}
|
|
8121
|
+
const authenticated = await call("GET", "/v1/me/subscription", undefined, {
|
|
8122
|
+
authKey: candidateApiKey,
|
|
8123
|
+
retryOnError: false,
|
|
8124
|
+
timeoutMs: 30_000,
|
|
8125
|
+
});
|
|
8126
|
+
if (authenticated.ok === false) {
|
|
8127
|
+
out = clientError("launcher_key_rejected", "Felix rejected the launcher API key currently stored in Keychain.", "Restore the matching encrypted identity backup or register a fresh unfunded launcher. No session credential was changed.");
|
|
8128
|
+
break;
|
|
8129
|
+
}
|
|
8130
|
+
const previousOwner = EVM_PRIVATE_KEY_RE.test(START_OWNER_KEY)
|
|
8131
|
+
? ownerAddressForPrivateKey(START_OWNER_KEY)
|
|
8132
|
+
: null;
|
|
8133
|
+
START_KEY = candidateApiKey;
|
|
8134
|
+
START_OWNER_KEY = candidateOwnerKey;
|
|
8135
|
+
launcherAccountIdCache = undefined;
|
|
8136
|
+
setKey(candidateApiKey);
|
|
8137
|
+
runtimeManagedAccountId = undefined;
|
|
8138
|
+
runtimeBindingError = undefined;
|
|
8139
|
+
forgetActiveChildAccount();
|
|
8140
|
+
if (EVM_PRIVATE_KEY_RE.test(candidateOwnerKey)) {
|
|
8141
|
+
setRuntimeOwnerPrivateKey(candidateOwnerKey);
|
|
8142
|
+
}
|
|
8143
|
+
else {
|
|
8144
|
+
clearRuntimeOwnerPrivateKey();
|
|
8145
|
+
}
|
|
8146
|
+
const currentOwner = EVM_PRIVATE_KEY_RE.test(candidateOwnerKey)
|
|
8147
|
+
? ownerAddressForPrivateKey(candidateOwnerKey)
|
|
8148
|
+
: null;
|
|
8149
|
+
out = {
|
|
8150
|
+
ok: true,
|
|
8151
|
+
message: "Current Keychain launcher credential, owner signer, and workflow journal restored for this MCP session.",
|
|
8152
|
+
identity_changed: Boolean(previousOwner && currentOwner
|
|
8153
|
+
&& previousOwner.toLowerCase() !== currentOwner.toLowerCase()),
|
|
8154
|
+
workflow_journal_identity: currentOwner
|
|
8155
|
+
? workflowIdentityFingerprint(candidateOwnerKey)
|
|
8156
|
+
: null,
|
|
8157
|
+
_meta: { source: "mcp_keychain", key_prefix: candidateApiKey.slice(0, 12) },
|
|
8158
|
+
};
|
|
8159
|
+
}
|
|
8160
|
+
catch (error) {
|
|
8161
|
+
out = clientError("operation_state_unavailable", safeClientErrorMessage(error, "The encrypted money-workflow journal could not be validated; no session credential was changed."), "Preserve the journal and restore the matching owner backup. Never delete workflow state while a money operation may be unresolved.");
|
|
8052
8162
|
}
|
|
8053
|
-
out = {
|
|
8054
|
-
ok: true,
|
|
8055
|
-
message: "Launcher credential and owner signer restored for this MCP session.",
|
|
8056
|
-
_meta: { source: "mcp_launcher", key_prefix: START_KEY.slice(0, 12) },
|
|
8057
|
-
};
|
|
8058
8163
|
}
|
|
8059
8164
|
break;
|
|
8060
8165
|
}
|
|
@@ -11836,7 +11941,7 @@ export function makeServer() {
|
|
|
11836
11941
|
note: "After an interruption, retry create_account with the exact same idempotency_key. Felix resumes completed checkpoints instead of creating another account.",
|
|
11837
11942
|
},
|
|
11838
11943
|
next_actions: [
|
|
11839
|
-
"
|
|
11944
|
+
"Call get_custody_recovery_status and require ready:true before depositing meaningful funds.",
|
|
11840
11945
|
"Send Polygon native USDC or USDC.e to deposit_address, then call get_money_map.",
|
|
11841
11946
|
...(deriveDeferred ? [
|
|
11842
11947
|
"No manual Derive setup is required: the first fund_market call for options completes owner-signed onboarding before moving venue funds.",
|
package/dist/key-backup.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { constants as fsConstants, chmodSync, closeSync, existsSync, fstatSync, fsyncSync, linkSync, openSync, readFileSync, realpathSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { constants as fsConstants, chmodSync, closeSync, copyFileSync, existsSync, fstatSync, fsyncSync, linkSync, openSync, readdirSync, readFileSync, realpathSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
3
3
|
import { homedir, userInfo } from "node:os";
|
|
4
4
|
import { basename, delimiter, dirname, join, resolve } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -8,9 +8,11 @@ import { FELIX_LEGAL_BUNDLE_VERSION, legalAcceptanceFields, } from "./legal.js";
|
|
|
8
8
|
import { spawnSync } from "node:child_process";
|
|
9
9
|
import { getAddress, isAddress } from "viem";
|
|
10
10
|
import { privateKeyToAccount } from "viem/accounts";
|
|
11
|
+
import { markFreshWorkflowIdentity } from "./money-journal-identity.js";
|
|
11
12
|
export const OWNER_KEYCHAIN_SERVICE = "trade.felix.owner-key.v1";
|
|
12
13
|
export const API_KEYCHAIN_SERVICE = "trade.felix.api-key.v1";
|
|
13
14
|
export const BACKUP_RECOVERY_KEYCHAIN_SERVICE = "trade.felix.backup-recovery.v1";
|
|
15
|
+
export const BACKUP_PATH_KEYCHAIN_SERVICE = "trade.felix.backup-path.v1";
|
|
14
16
|
const BACKUP_FORMAT = "felix-custody-backup";
|
|
15
17
|
const BACKUP_VERSION = 1;
|
|
16
18
|
const PRIVATE_KEY_RE = /^0x[0-9a-fA-F]{64}$/;
|
|
@@ -392,7 +394,7 @@ function requireInteractiveMac() {
|
|
|
392
394
|
throw new Error("Felix Keychain backup currently requires macOS.");
|
|
393
395
|
}
|
|
394
396
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
395
|
-
throw new Error("
|
|
397
|
+
throw new Error("This optional owner-recovery command requires an interactive macOS session.");
|
|
396
398
|
}
|
|
397
399
|
}
|
|
398
400
|
function requireNativeMacSession() {
|
|
@@ -413,6 +415,119 @@ function defaultBackupPath(ownerAddress) {
|
|
|
413
415
|
const day = new Date().toISOString().slice(0, 10);
|
|
414
416
|
return join(directory, `felix-custody-${ownerAddress.slice(2, 10)}-${day}.json`);
|
|
415
417
|
}
|
|
418
|
+
function standardBackupDirectory() {
|
|
419
|
+
return existsSync(join(homedir(), "Documents"))
|
|
420
|
+
? join(homedir(), "Documents") : homedir();
|
|
421
|
+
}
|
|
422
|
+
function guidedBackupCandidates(ownerAddress) {
|
|
423
|
+
const directory = standardBackupDirectory();
|
|
424
|
+
const prefix = `felix-custody-${ownerAddress.slice(2, 10)}-`;
|
|
425
|
+
const candidates = [];
|
|
426
|
+
const storedPath = readKeychainPassword(BACKUP_PATH_KEYCHAIN_SERVICE);
|
|
427
|
+
if (storedPath && storedPath.length <= 4_096 && existsSync(expandPath(storedPath))) {
|
|
428
|
+
candidates.push(expandPath(storedPath));
|
|
429
|
+
}
|
|
430
|
+
const today = defaultBackupPath(ownerAddress);
|
|
431
|
+
if (existsSync(today))
|
|
432
|
+
candidates.push(today);
|
|
433
|
+
try {
|
|
434
|
+
candidates.push(...readdirSync(directory, { withFileTypes: true })
|
|
435
|
+
.filter((entry) => entry.isFile()
|
|
436
|
+
&& entry.name.startsWith(prefix)
|
|
437
|
+
&& /^felix-custody-[0-9a-fA-F]{8}-\d{4}-\d{2}-\d{2}\.json$/.test(entry.name))
|
|
438
|
+
.map((entry) => join(directory, entry.name)));
|
|
439
|
+
}
|
|
440
|
+
catch { /* Direct-file verification still works when folder listing is denied. */ }
|
|
441
|
+
return [...new Set(candidates)].sort().reverse().slice(0, 16);
|
|
442
|
+
}
|
|
443
|
+
function recoveryStatus(status, overrides = {}) {
|
|
444
|
+
const ready = status === "ready";
|
|
445
|
+
const nextSteps = {
|
|
446
|
+
ready: "none",
|
|
447
|
+
unsupported: "Run guided onboarding on a supported macOS device with Keychain available.",
|
|
448
|
+
identity_incomplete: "Run the pinned felix-keys onboard command; it creates and verifies the missing local identity and recovery file automatically.",
|
|
449
|
+
recovery_material_missing: "Do not fund this identity. Preserve any existing recovery file and restore its matching recovery material before continuing.",
|
|
450
|
+
backup_missing: "Run the pinned felix-keys onboard command again; it will create and authenticate the encrypted recovery file automatically.",
|
|
451
|
+
backup_verification_failed: "Do not fund or rotate this identity. Preserve the existing recovery files and resolve the failed authentication before continuing.",
|
|
452
|
+
};
|
|
453
|
+
return {
|
|
454
|
+
ok: true,
|
|
455
|
+
available: status !== "unsupported",
|
|
456
|
+
status,
|
|
457
|
+
ready,
|
|
458
|
+
automatic_backup: true,
|
|
459
|
+
local_identity_complete: false,
|
|
460
|
+
encrypted_backup_present: false,
|
|
461
|
+
backup_authenticated: false,
|
|
462
|
+
backup_matches_installed_identity: false,
|
|
463
|
+
recovery_material_stored_in_keychain: false,
|
|
464
|
+
secrets_displayed: false,
|
|
465
|
+
action_required: !ready,
|
|
466
|
+
next_step: nextSteps[status],
|
|
467
|
+
...overrides,
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
export async function assessCustodyRecoveryArtifacts(input) {
|
|
471
|
+
const ownerValid = Boolean(input.ownerKey && PRIVATE_KEY_RE.test(input.ownerKey));
|
|
472
|
+
const apiValid = Boolean(input.apiKey && API_KEY_RE.test(input.apiKey));
|
|
473
|
+
if (!ownerValid || !apiValid)
|
|
474
|
+
return recoveryStatus("identity_incomplete");
|
|
475
|
+
const identity = { local_identity_complete: true };
|
|
476
|
+
const candidates = (input.candidatePaths || []).slice(0, 16);
|
|
477
|
+
if (!input.recoveryCode || !isValidBackupRecoveryCode(input.recoveryCode)) {
|
|
478
|
+
return recoveryStatus("recovery_material_missing", {
|
|
479
|
+
...identity,
|
|
480
|
+
encrypted_backup_present: candidates.length > 0,
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
if (candidates.length === 0) {
|
|
484
|
+
return recoveryStatus("backup_missing", {
|
|
485
|
+
...identity,
|
|
486
|
+
recovery_material_stored_in_keychain: true,
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
let authenticated = false;
|
|
490
|
+
for (const candidate of candidates) {
|
|
491
|
+
try {
|
|
492
|
+
const credentials = await openBackupEnvelope(parseBackupEnvelope(readPrivateFile(candidate)), input.recoveryCode);
|
|
493
|
+
authenticated = true;
|
|
494
|
+
if (credentials.root_owner_private_key === input.ownerKey
|
|
495
|
+
&& credentials.launcher_api_key === input.apiKey) {
|
|
496
|
+
return recoveryStatus("ready", {
|
|
497
|
+
...identity,
|
|
498
|
+
encrypted_backup_present: true,
|
|
499
|
+
backup_authenticated: true,
|
|
500
|
+
backup_matches_installed_identity: true,
|
|
501
|
+
recovery_material_stored_in_keychain: true,
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
catch {
|
|
506
|
+
// Keep checking bounded candidates; no path or decryption detail is exposed.
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return recoveryStatus("backup_verification_failed", {
|
|
510
|
+
...identity,
|
|
511
|
+
encrypted_backup_present: true,
|
|
512
|
+
backup_authenticated: authenticated,
|
|
513
|
+
recovery_material_stored_in_keychain: true,
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
export async function getCustodyRecoveryStatus() {
|
|
517
|
+
if (process.platform !== "darwin")
|
|
518
|
+
return recoveryStatus("unsupported");
|
|
519
|
+
const ownerKey = readKeychainPassword(OWNER_KEYCHAIN_SERVICE);
|
|
520
|
+
const apiKey = readKeychainPassword(API_KEYCHAIN_SERVICE);
|
|
521
|
+
const recoveryCode = readKeychainPassword(BACKUP_RECOVERY_KEYCHAIN_SERVICE);
|
|
522
|
+
const ownerAddress = ownerKey && PRIVATE_KEY_RE.test(ownerKey)
|
|
523
|
+
? canonicalAddress(ownerKey) : undefined;
|
|
524
|
+
return assessCustodyRecoveryArtifacts({
|
|
525
|
+
ownerKey,
|
|
526
|
+
apiKey,
|
|
527
|
+
recoveryCode,
|
|
528
|
+
candidatePaths: ownerAddress ? guidedBackupCandidates(ownerAddress) : [],
|
|
529
|
+
});
|
|
530
|
+
}
|
|
416
531
|
export function writePrivateFile(pathValue, contents) {
|
|
417
532
|
const target = expandPath(pathValue);
|
|
418
533
|
const parent = dirname(target);
|
|
@@ -422,27 +537,79 @@ export function writePrivateFile(pathValue, contents) {
|
|
|
422
537
|
throw new Error("Backup destination already exists.");
|
|
423
538
|
const temporary = join(parentReal, `.${basename(target)}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`);
|
|
424
539
|
let descriptor;
|
|
540
|
+
let finalDescriptor;
|
|
541
|
+
let directoryDescriptor;
|
|
542
|
+
let destinationCreated = false;
|
|
425
543
|
try {
|
|
426
544
|
descriptor = openSync(temporary, fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_NOFOLLOW, 0o600);
|
|
427
545
|
writeFileSync(descriptor, contents, { encoding: "utf8" });
|
|
428
546
|
fsyncSync(descriptor);
|
|
429
547
|
closeSync(descriptor);
|
|
430
548
|
descriptor = undefined;
|
|
431
|
-
linkSync(temporary, targetResolved);
|
|
432
549
|
try {
|
|
433
|
-
|
|
550
|
+
linkSync(temporary, targetResolved);
|
|
551
|
+
destinationCreated = true;
|
|
552
|
+
}
|
|
553
|
+
catch (error) {
|
|
554
|
+
const code = error.code;
|
|
555
|
+
if (code === "EEXIST")
|
|
556
|
+
throw new Error("Backup destination already exists.");
|
|
557
|
+
if (!new Set(["EPERM", "EOPNOTSUPP", "EXDEV"]).has(String(code)))
|
|
558
|
+
throw error;
|
|
559
|
+
// Some cloud-managed Documents folders reject hard links. COPYFILE_EXCL
|
|
560
|
+
// preserves no-clobber behavior without weakening file permissions.
|
|
561
|
+
try {
|
|
562
|
+
copyFileSync(temporary, targetResolved, fsConstants.COPYFILE_EXCL);
|
|
563
|
+
destinationCreated = true;
|
|
564
|
+
}
|
|
565
|
+
catch (copyError) {
|
|
566
|
+
if (copyError.code === "EEXIST") {
|
|
567
|
+
throw new Error("Backup destination already exists.");
|
|
568
|
+
}
|
|
569
|
+
throw copyError;
|
|
570
|
+
}
|
|
434
571
|
}
|
|
435
|
-
catch { /* final hard link is already durable */ }
|
|
436
572
|
chmodSync(targetResolved, 0o600);
|
|
573
|
+
finalDescriptor = openSync(targetResolved, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW);
|
|
574
|
+
fsyncSync(finalDescriptor);
|
|
575
|
+
closeSync(finalDescriptor);
|
|
576
|
+
finalDescriptor = undefined;
|
|
577
|
+
try {
|
|
578
|
+
directoryDescriptor = openSync(parentReal, fsConstants.O_RDONLY);
|
|
579
|
+
fsyncSync(directoryDescriptor);
|
|
580
|
+
closeSync(directoryDescriptor);
|
|
581
|
+
directoryDescriptor = undefined;
|
|
582
|
+
}
|
|
583
|
+
catch (error) {
|
|
584
|
+
if (directoryDescriptor !== undefined)
|
|
585
|
+
closeSync(directoryDescriptor);
|
|
586
|
+
directoryDescriptor = undefined;
|
|
587
|
+
const code = error.code;
|
|
588
|
+
// macOS privacy controls can permit file creation while rejecting a
|
|
589
|
+
// directory descriptor. The completed file itself was already fsynced.
|
|
590
|
+
if (!new Set(["EPERM", "EACCES"]).has(String(code)))
|
|
591
|
+
throw error;
|
|
592
|
+
}
|
|
593
|
+
unlinkSync(temporary);
|
|
437
594
|
return targetResolved;
|
|
438
595
|
}
|
|
439
596
|
catch (error) {
|
|
440
597
|
if (descriptor !== undefined)
|
|
441
598
|
closeSync(descriptor);
|
|
599
|
+
if (finalDescriptor !== undefined)
|
|
600
|
+
closeSync(finalDescriptor);
|
|
601
|
+
if (directoryDescriptor !== undefined)
|
|
602
|
+
closeSync(directoryDescriptor);
|
|
442
603
|
try {
|
|
443
604
|
unlinkSync(temporary);
|
|
444
605
|
}
|
|
445
606
|
catch { /* best effort */ }
|
|
607
|
+
if (destinationCreated) {
|
|
608
|
+
try {
|
|
609
|
+
unlinkSync(targetResolved);
|
|
610
|
+
}
|
|
611
|
+
catch { /* best effort */ }
|
|
612
|
+
}
|
|
446
613
|
if (error instanceof Error && error.message === "Backup destination already exists.")
|
|
447
614
|
throw error;
|
|
448
615
|
throw new Error("Encrypted backup file could not be written.");
|
|
@@ -627,7 +794,7 @@ function setupCommand() {
|
|
|
627
794
|
if (verified !== ownerKey)
|
|
628
795
|
throw new Error("Owner Keychain write did not verify.");
|
|
629
796
|
console.log(`Felix owner key created for ${canonicalAddress(ownerKey)}.`);
|
|
630
|
-
console.log("No private key was printed.
|
|
797
|
+
console.log("No private key was printed. Run guided onboarding to register and create the encrypted recovery file automatically.");
|
|
631
798
|
}
|
|
632
799
|
catch {
|
|
633
800
|
try {
|
|
@@ -797,6 +964,7 @@ async function registerCommand(allowExisting = false, agentManaged = false) {
|
|
|
797
964
|
throw new Error("A Felix API key is already installed. Use felix-keys status, or remove it before registering again.");
|
|
798
965
|
}
|
|
799
966
|
let ownerKey = readKeychainPassword(OWNER_KEYCHAIN_SERVICE);
|
|
967
|
+
let ownerCreated = false;
|
|
800
968
|
if (ownerKey && !PRIVATE_KEY_RE.test(ownerKey)) {
|
|
801
969
|
throw new Error("The installed Felix owner Keychain item is invalid; registration was not attempted.");
|
|
802
970
|
}
|
|
@@ -813,6 +981,7 @@ async function registerCommand(allowExisting = false, agentManaged = false) {
|
|
|
813
981
|
catch { /* best effort */ }
|
|
814
982
|
throw new Error("Owner Keychain write did not verify; nothing was registered.");
|
|
815
983
|
}
|
|
984
|
+
ownerCreated = true;
|
|
816
985
|
}
|
|
817
986
|
const account = privateKeyToAccount(ownerKey);
|
|
818
987
|
const post = async (path, body) => {
|
|
@@ -863,10 +1032,12 @@ async function registerCommand(allowExisting = false, agentManaged = false) {
|
|
|
863
1032
|
catch { /* best effort */ }
|
|
864
1033
|
throw new Error("API-key Keychain write did not verify; the key was not retained.");
|
|
865
1034
|
}
|
|
1035
|
+
if (ownerCreated)
|
|
1036
|
+
markFreshWorkflowIdentity(ownerKey);
|
|
866
1037
|
console.log(`Felix account created: ${String(registered.account_id || "")}`);
|
|
867
1038
|
console.log(`Owner address: ${account.address}`);
|
|
868
1039
|
console.log(`API key stored in Keychain (prefix ${String(registered.prefix || "")}). The key itself was not printed.`);
|
|
869
|
-
console.log("Run
|
|
1040
|
+
console.log("Run guided onboarding to create and authenticate the encrypted recovery file automatically before funding.");
|
|
870
1041
|
}
|
|
871
1042
|
async function onboardCommand(client = "claude", output) {
|
|
872
1043
|
requireNativeMacSession();
|
|
@@ -882,7 +1053,7 @@ async function onboardCommand(client = "claude", output) {
|
|
|
882
1053
|
let recoveryCode = readKeychainPassword(BACKUP_RECOVERY_KEYCHAIN_SERVICE);
|
|
883
1054
|
let recoveryCodeCreated = false;
|
|
884
1055
|
if (recoveryCode && !isValidBackupRecoveryCode(recoveryCode)) {
|
|
885
|
-
throw new Error("The Felix backup-recovery Keychain item is invalid. No backup was changed
|
|
1056
|
+
throw new Error("The Felix backup-recovery Keychain item is invalid. No backup was changed or replaced.");
|
|
886
1057
|
}
|
|
887
1058
|
if (existsSync(target)) {
|
|
888
1059
|
const existing = parseBackupEnvelope(readPrivateFile(target));
|
|
@@ -939,15 +1110,31 @@ async function onboardCommand(client = "claude", output) {
|
|
|
939
1110
|
throw error;
|
|
940
1111
|
}
|
|
941
1112
|
}
|
|
1113
|
+
writeKeychainPassword(BACKUP_PATH_KEYCHAIN_SERVICE, "Felix encrypted-backup path", target);
|
|
1114
|
+
if (readKeychainPassword(BACKUP_PATH_KEYCHAIN_SERVICE) !== target) {
|
|
1115
|
+
throw new Error("The encrypted recovery file was created, but its local status reference did not verify. Rerun guided onboarding; the identity and file were not replaced.");
|
|
1116
|
+
}
|
|
942
1117
|
const clientState = client === "claude" ? configureClaudeMcp(true) : "skipped";
|
|
1118
|
+
const custodyRecovery = await assessCustodyRecoveryArtifacts({
|
|
1119
|
+
ownerKey,
|
|
1120
|
+
apiKey,
|
|
1121
|
+
recoveryCode,
|
|
1122
|
+
candidatePaths: [target],
|
|
1123
|
+
});
|
|
1124
|
+
if (!custodyRecovery.ready) {
|
|
1125
|
+
throw new Error("The encrypted recovery file did not verify after guided onboarding.");
|
|
1126
|
+
}
|
|
1127
|
+
const publicBackupPath = target.startsWith(`${homedir()}/`)
|
|
1128
|
+
? `~/${target.slice(homedir().length + 1)}` : basename(target);
|
|
943
1129
|
console.log(JSON.stringify({
|
|
944
1130
|
ok: true,
|
|
945
1131
|
owner_address: ownerAddress,
|
|
946
1132
|
registration: "ready",
|
|
947
1133
|
encrypted_backup: backupState,
|
|
948
|
-
backup_path:
|
|
1134
|
+
backup_path: publicBackupPath,
|
|
949
1135
|
backup_recovery: "macos_keychain",
|
|
950
|
-
|
|
1136
|
+
custody_recovery: custodyRecovery,
|
|
1137
|
+
off_device_recovery_copy: "optional_not_required_for_onboarding",
|
|
951
1138
|
mcp_client: client,
|
|
952
1139
|
mcp_configuration: clientState,
|
|
953
1140
|
secrets_displayed: false,
|
|
@@ -975,9 +1162,9 @@ Usage:
|
|
|
975
1162
|
onboard lets an agent complete registration, encrypted backup, MCP client
|
|
976
1163
|
configuration, and verification after the user explicitly accepts the current
|
|
977
1164
|
terms. The owner key, API key, and generated recovery code stay in macOS
|
|
978
|
-
Keychain and never enter agent output.
|
|
979
|
-
|
|
980
|
-
|
|
1165
|
+
Keychain and never enter agent output. No follow-up copy/paste or terminal
|
|
1166
|
+
backup step is required. Optional disaster-recovery export and restore actions
|
|
1167
|
+
remain owner-controlled native dialogs outside the normal agent workflow.
|
|
981
1168
|
restore refuses to replace a different installed identity; replace is the
|
|
982
1169
|
explicit identity-rotation command. Passphrases and keys cannot be supplied
|
|
983
1170
|
through command-line arguments.`);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { chmodSync, existsSync, mkdirSync, openSync, closeSync, statSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
6
|
+
const PRIVATE_KEY_RE = /^0x[0-9a-f]{64}$/i;
|
|
7
|
+
export function workflowIdentityFingerprint(ownerKey) {
|
|
8
|
+
if (!PRIVATE_KEY_RE.test(ownerKey)) {
|
|
9
|
+
throw new Error("A valid local owner key is required for the encrypted money-workflow journal.");
|
|
10
|
+
}
|
|
11
|
+
const address = privateKeyToAccount(ownerKey).address.toLowerCase();
|
|
12
|
+
return createHash("sha256")
|
|
13
|
+
.update(`felix-money-workflow-owner-v1:${address}`)
|
|
14
|
+
.digest("hex")
|
|
15
|
+
.slice(0, 24);
|
|
16
|
+
}
|
|
17
|
+
export function legacyWorkflowJournalPath() {
|
|
18
|
+
return join(homedir(), ".felix-mcp", "money-workflows.enc");
|
|
19
|
+
}
|
|
20
|
+
export function scopedWorkflowJournalPath(ownerKey) {
|
|
21
|
+
return join(homedir(), ".felix-mcp", "money-workflows", `${workflowIdentityFingerprint(ownerKey)}.enc`);
|
|
22
|
+
}
|
|
23
|
+
export function freshWorkflowIdentityMarkerPath(ownerKey) {
|
|
24
|
+
return `${scopedWorkflowJournalPath(ownerKey)}.fresh`;
|
|
25
|
+
}
|
|
26
|
+
// Registration marks only identities created in that exact flow. The MCP
|
|
27
|
+
// consumes the marker while creating an empty authenticated journal, so an
|
|
28
|
+
// unrelated legacy journal is never mistaken for the new owner.
|
|
29
|
+
export function markFreshWorkflowIdentity(ownerKey) {
|
|
30
|
+
const journalPath = scopedWorkflowJournalPath(ownerKey);
|
|
31
|
+
if (existsSync(journalPath))
|
|
32
|
+
return;
|
|
33
|
+
const markerPath = freshWorkflowIdentityMarkerPath(ownerKey);
|
|
34
|
+
const directory = dirname(markerPath);
|
|
35
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
36
|
+
if ((statSync(directory).mode & 0o077) !== 0) {
|
|
37
|
+
throw new Error("The Felix local state directory is not private.");
|
|
38
|
+
}
|
|
39
|
+
const fd = openSync(markerPath, "wx", 0o600);
|
|
40
|
+
try {
|
|
41
|
+
writeFileSync(fd, JSON.stringify({ version: 1, created_at: new Date().toISOString() }));
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
closeSync(fd);
|
|
45
|
+
}
|
|
46
|
+
chmodSync(markerPath, 0o600);
|
|
47
|
+
}
|
|
48
|
+
export function consumeFreshWorkflowIdentityMarker(ownerKey) {
|
|
49
|
+
const markerPath = freshWorkflowIdentityMarkerPath(ownerKey);
|
|
50
|
+
try {
|
|
51
|
+
unlinkSync(markerPath);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error.code !== "ENOENT")
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "felix-mcp",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.108",
|
|
4
4
|
"mcpName": "trade.felix/mcp",
|
|
5
5
|
"description": "Non-custodial trading infrastructure for AI agents: one wallet, one risk policy, every market.",
|
|
6
6
|
"homepage": "https://felix.trade/docs",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"test:release-artifact": "node scripts/verify-release-artifact.mjs",
|
|
39
39
|
"test:release-install": "node test_release_install.mjs",
|
|
40
40
|
"test:key-backup": "node test_key_backup.mjs",
|
|
41
|
+
"test:journal-identity": "node test_money_journal_identity.mjs",
|
|
41
42
|
"test:signing": "node test_signing_security.mjs",
|
|
42
43
|
"test:funding-rpc": "node test_funding_rpc_transport.mjs",
|
|
43
44
|
"test:funding-accounting": "node test_funding_accounting.mjs",
|
package/server.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "trade.felix/mcp",
|
|
4
4
|
"title": "Felix MCP",
|
|
5
5
|
"description": "Non-custodial trading infrastructure for AI agents across prediction markets, crypto, and options.",
|
|
6
|
-
"version": "2.0.
|
|
6
|
+
"version": "2.0.108",
|
|
7
7
|
"websiteUrl": "https://felix.trade/docs",
|
|
8
8
|
"icons": [
|
|
9
9
|
{
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
{
|
|
26
26
|
"registryType": "npm",
|
|
27
27
|
"identifier": "felix-mcp",
|
|
28
|
-
"version": "2.0.
|
|
28
|
+
"version": "2.0.108",
|
|
29
29
|
"transport": {
|
|
30
30
|
"type": "stdio"
|
|
31
31
|
}
|