felix-mcp 2.0.106 → 2.0.107
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 +11 -3
- package/dist/getting-started-guide.js +7 -1
- package/dist/index.js +120 -35
- package/dist/key-backup.js +5 -0
- 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.107 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
|
|
@@ -39,7 +39,7 @@ For Claude Desktop:
|
|
|
39
39
|
"mcpServers": {
|
|
40
40
|
"felix": {
|
|
41
41
|
"command": "npx",
|
|
42
|
-
"args": ["-y", "felix-mcp@2.0.
|
|
42
|
+
"args": ["-y", "felix-mcp@2.0.107"]
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -141,7 +141,15 @@ If the saved account and credential do not match, tools fail with
|
|
|
141
141
|
`session_binding_recovery_required`; they do not silently show a different
|
|
142
142
|
account. Use `list_accounts` and `use_child_account` to select the intended
|
|
143
143
|
child. Use `reload_launcher_key` only when you intentionally want the launcher
|
|
144
|
-
identity in that process.
|
|
144
|
+
identity in that process. It rereads the current macOS Keychain identity,
|
|
145
|
+
authenticates that owner's encrypted money-workflow journal, and changes the
|
|
146
|
+
session only after both checks pass.
|
|
147
|
+
|
|
148
|
+
Money-workflow journals are encrypted and isolated per owner identity. Existing
|
|
149
|
+
pre-2.0.107 journals migrate only after their authentication tag verifies. If a
|
|
150
|
+
tool returns `operation_state_unavailable`, preserve the journal and restore the
|
|
151
|
+
matching owner backup; never delete local workflow state or retry an unresolved
|
|
152
|
+
money action with a new idempotency key.
|
|
145
153
|
|
|
146
154
|
Scopes are least-privilege:
|
|
147
155
|
|
|
@@ -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.107 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
|
|
@@ -205,6 +205,12 @@ allowlist, limit, or expiry before signing.
|
|
|
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.107+ 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";
|
|
@@ -106,7 +107,7 @@ export function validatedApiBase(raw = process.env.FELIX_API_URL || `https://${O
|
|
|
106
107
|
return parsed.origin;
|
|
107
108
|
}
|
|
108
109
|
const API = validatedApiBase();
|
|
109
|
-
const MCP_VERSION = "2.0.
|
|
110
|
+
const MCP_VERSION = "2.0.107";
|
|
110
111
|
const PRACTICAL_NO_CAP_USD = 1_000_000_000;
|
|
111
112
|
const DEFAULT_WALLET_OPERATION_USD = 10_000_000;
|
|
112
113
|
const DEFAULT_WALLET_DAILY_USD = 100_000_000;
|
|
@@ -331,10 +332,18 @@ function persistActiveChildSession(accountId, apiKey) {
|
|
|
331
332
|
const HOSTED_TRANSPORT = process.env.FELIX_MCP_TRANSPORT === "http";
|
|
332
333
|
// Hosted MCP requests authenticate independently through AsyncLocalStorage and
|
|
333
334
|
// never need a process-wide launcher or signer credential.
|
|
334
|
-
const
|
|
335
|
+
const API_CREDENTIAL_FROM_ENV = Object.prototype.hasOwnProperty.call(process.env, "FELIX_API_KEY");
|
|
336
|
+
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");
|
|
337
|
+
const KEYCHAIN_BACKED_CREDENTIALS = !HOSTED_TRANSPORT
|
|
338
|
+
&& (process.env.FELIX_CREDENTIAL_SOURCE === "keychain"
|
|
339
|
+
|| (!API_CREDENTIAL_FROM_ENV && !OWNER_CREDENTIAL_FROM_ENV));
|
|
340
|
+
// These are the currently trusted launcher credentials. They begin with the
|
|
341
|
+
// launch values and may change only through reload_launcher_key after the new
|
|
342
|
+
// Keychain pair and its authenticated journal have both been validated.
|
|
343
|
+
let START_KEY = HOSTED_TRANSPORT
|
|
335
344
|
? ""
|
|
336
345
|
: configuredCredential("FELIX_API_KEY", KEYCHAIN_API_SERVICE);
|
|
337
|
-
|
|
346
|
+
let START_OWNER_KEY = HOSTED_TRANSPORT
|
|
338
347
|
? ""
|
|
339
348
|
: Object.prototype.hasOwnProperty.call(process.env, "FELIX_ROOT_OWNER_PRIVATE_KEY")
|
|
340
349
|
? (process.env.FELIX_ROOT_OWNER_PRIVATE_KEY || "")
|
|
@@ -355,6 +364,7 @@ delete process.env.FELIX_OWNER_PRIVATE_KEY;
|
|
|
355
364
|
delete process.env.FELIX_ACTIVE_ACCOUNT_ID;
|
|
356
365
|
delete process.env.FELIX_EPHEMERAL_SESSION;
|
|
357
366
|
delete process.env.FELIX_BINDING_PROFILE;
|
|
367
|
+
delete process.env.FELIX_CREDENTIAL_SOURCE;
|
|
358
368
|
const PROCESS_STARTED_AT = new Date().toISOString();
|
|
359
369
|
const TIMEOUT_MS = clampInt(process.env.FELIX_TIMEOUT_MS, 3_000, 60_000, 20_000);
|
|
360
370
|
const CLOSE_POLL_WAIT_MS = clampInt(process.env.FELIX_CLOSE_POLL_WAIT_MS, 2_000, 30_000, 12_000);
|
|
@@ -488,30 +498,31 @@ export function markMoneyNotStarted(result) {
|
|
|
488
498
|
});
|
|
489
499
|
return result;
|
|
490
500
|
}
|
|
491
|
-
function
|
|
501
|
+
function moneyWorkflowOwnerKey(ownerKey = START_OWNER_KEY) {
|
|
502
|
+
if (EVM_PRIVATE_KEY_RE.test(ownerKey))
|
|
503
|
+
return ownerKey;
|
|
504
|
+
const runtimeOwner = getRuntimeOwnerPrivateKey();
|
|
505
|
+
return EVM_PRIVATE_KEY_RE.test(runtimeOwner || "") ? runtimeOwner : "";
|
|
506
|
+
}
|
|
507
|
+
function moneyWorkflowPath(ownerKey = START_OWNER_KEY) {
|
|
492
508
|
return process.env.FELIX_WORKFLOW_STATE_FILE
|
|
493
|
-
||
|
|
509
|
+
|| scopedWorkflowJournalPath(moneyWorkflowOwnerKey(ownerKey));
|
|
494
510
|
}
|
|
495
|
-
function moneyWorkflowEncryptionKey() {
|
|
496
|
-
|
|
497
|
-
START_OWNER_KEY,
|
|
498
|
-
getRuntimeOwnerPrivateKey(),
|
|
499
|
-
].find((candidate) => EVM_PRIVATE_KEY_RE.test(candidate || "")) || "";
|
|
511
|
+
function moneyWorkflowEncryptionKey(ownerKey = START_OWNER_KEY) {
|
|
512
|
+
ownerKey = moneyWorkflowOwnerKey(ownerKey);
|
|
500
513
|
if (!EVM_PRIVATE_KEY_RE.test(ownerKey)) {
|
|
501
514
|
throw new Error("A valid local owner key is required for the encrypted money-workflow journal.");
|
|
502
515
|
}
|
|
503
516
|
return createHash("sha256").update(`felix-money-workflows-v1:${ownerKey}`).digest();
|
|
504
517
|
}
|
|
505
|
-
function
|
|
506
|
-
const path = moneyWorkflowPath();
|
|
518
|
+
function readMoneyWorkflowJournalAtPath(path, encryptionKey) {
|
|
507
519
|
let encoded;
|
|
508
520
|
try {
|
|
509
521
|
encoded = readFileSync(path, "utf8");
|
|
510
522
|
}
|
|
511
523
|
catch (error) {
|
|
512
|
-
if (error.code === "ENOENT")
|
|
513
|
-
return
|
|
514
|
-
}
|
|
524
|
+
if (error.code === "ENOENT")
|
|
525
|
+
return undefined;
|
|
515
526
|
throw new Error("The encrypted money-workflow journal is unavailable; refusing to move funds.");
|
|
516
527
|
}
|
|
517
528
|
try {
|
|
@@ -535,8 +546,7 @@ function readMoneyWorkflowJournal(encryptionKey = moneyWorkflowEncryptionKey())
|
|
|
535
546
|
throw new Error("The encrypted money-workflow journal cannot be authenticated; refusing to move funds.");
|
|
536
547
|
}
|
|
537
548
|
}
|
|
538
|
-
function writeMoneyWorkflowJournalRaw(journal, encryptionKey = moneyWorkflowEncryptionKey()) {
|
|
539
|
-
const path = moneyWorkflowPath();
|
|
549
|
+
function writeMoneyWorkflowJournalRaw(journal, encryptionKey = moneyWorkflowEncryptionKey(), path = moneyWorkflowPath()) {
|
|
540
550
|
const directory = dirname(path);
|
|
541
551
|
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
542
552
|
if ((statSync(directory).mode & 0o077) !== 0) {
|
|
@@ -558,9 +568,14 @@ function writeMoneyWorkflowJournalRaw(journal, encryptionKey = moneyWorkflowEncr
|
|
|
558
568
|
writeFileSync(temporary, `${envelope}\n`, { mode: 0o600 });
|
|
559
569
|
renameSync(temporary, path);
|
|
560
570
|
chmodSync(path, 0o600);
|
|
571
|
+
if (!process.env.FELIX_WORKFLOW_STATE_FILE && existsSync(`${path}.fresh`)) {
|
|
572
|
+
try {
|
|
573
|
+
unlinkSync(`${path}.fresh`);
|
|
574
|
+
}
|
|
575
|
+
catch { /* marker cleanup is best effort after durable write */ }
|
|
576
|
+
}
|
|
561
577
|
}
|
|
562
|
-
function acquireMoneyJournalMutationLock() {
|
|
563
|
-
const journalPath = moneyWorkflowPath();
|
|
578
|
+
function acquireMoneyJournalMutationLock(journalPath = moneyWorkflowPath()) {
|
|
564
579
|
const directory = dirname(journalPath);
|
|
565
580
|
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
566
581
|
if ((statSync(directory).mode & 0o077) !== 0) {
|
|
@@ -611,6 +626,30 @@ function acquireMoneyJournalMutationLock() {
|
|
|
611
626
|
}
|
|
612
627
|
return undefined;
|
|
613
628
|
}
|
|
629
|
+
function readMoneyWorkflowJournal(encryptionKey = moneyWorkflowEncryptionKey(), ownerKey = START_OWNER_KEY) {
|
|
630
|
+
const path = moneyWorkflowPath(ownerKey);
|
|
631
|
+
const scoped = readMoneyWorkflowJournalAtPath(path, encryptionKey);
|
|
632
|
+
if (scoped)
|
|
633
|
+
return scoped;
|
|
634
|
+
const empty = { version: 1, entries: {}, operations: {} };
|
|
635
|
+
if (process.env.FELIX_WORKFLOW_STATE_FILE)
|
|
636
|
+
return empty;
|
|
637
|
+
// A newly registered identity is explicitly marked by felix-keys. Reads stay
|
|
638
|
+
// pure and see empty state; the first locked mutation creates the scoped
|
|
639
|
+
// authenticated journal and consumes the marker after its atomic write.
|
|
640
|
+
if (existsSync(freshWorkflowIdentityMarkerPath(ownerKey))) {
|
|
641
|
+
return empty;
|
|
642
|
+
}
|
|
643
|
+
// One-time compatibility migration for pre-2.0.107 installations. Migration
|
|
644
|
+
// is permitted only after the legacy AES-GCM tag authenticates with this
|
|
645
|
+
// owner. This read remains side-effect-free; the next locked mutation writes
|
|
646
|
+
// the authenticated state to the scoped path.
|
|
647
|
+
const legacyPath = legacyWorkflowJournalPath();
|
|
648
|
+
const legacy = readMoneyWorkflowJournalAtPath(legacyPath, encryptionKey);
|
|
649
|
+
if (!legacy)
|
|
650
|
+
return empty;
|
|
651
|
+
return legacy;
|
|
652
|
+
}
|
|
614
653
|
function writeMoneyWorkflowJournal(journal, encryptionKey = moneyWorkflowEncryptionKey()) {
|
|
615
654
|
const lock = acquireMoneyJournalMutationLock();
|
|
616
655
|
if (!lock) {
|
|
@@ -6865,7 +6904,7 @@ const TOOLS = [
|
|
|
6865
6904
|
},
|
|
6866
6905
|
{
|
|
6867
6906
|
name: "reload_launcher_key",
|
|
6868
|
-
description: "
|
|
6907
|
+
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
6908
|
inputSchema: schema({}),
|
|
6870
6909
|
},
|
|
6871
6910
|
{
|
|
@@ -8039,22 +8078,68 @@ export function makeServer() {
|
|
|
8039
8078
|
if (isHostedTransport()) {
|
|
8040
8079
|
out = clientError("hosted_transport_stateless", "reload_launcher_key is unavailable on the stateless hosted transport.", "Reconnect with the intended Bearer token.");
|
|
8041
8080
|
}
|
|
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
8081
|
else {
|
|
8046
|
-
|
|
8047
|
-
|
|
8048
|
-
|
|
8049
|
-
|
|
8050
|
-
|
|
8051
|
-
|
|
8082
|
+
const candidateApiKey = KEYCHAIN_BACKED_CREDENTIALS
|
|
8083
|
+
? localKeychainCredential(KEYCHAIN_API_SERVICE)
|
|
8084
|
+
: START_KEY;
|
|
8085
|
+
const candidateOwnerKey = KEYCHAIN_BACKED_CREDENTIALS
|
|
8086
|
+
? localKeychainCredential(KEYCHAIN_OWNER_SERVICE)
|
|
8087
|
+
: START_OWNER_KEY;
|
|
8088
|
+
if (!API_KEY_RE.test(candidateApiKey)
|
|
8089
|
+
|| (KEYCHAIN_BACKED_CREDENTIALS && !EVM_PRIVATE_KEY_RE.test(candidateOwnerKey))) {
|
|
8090
|
+
out = clientError("launcher_key_unavailable", KEYCHAIN_BACKED_CREDENTIALS
|
|
8091
|
+
? "macOS Keychain does not contain a complete valid Felix launcher identity."
|
|
8092
|
+
: "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.");
|
|
8093
|
+
break;
|
|
8094
|
+
}
|
|
8095
|
+
try {
|
|
8096
|
+
// Authenticate local recovery state before changing either signer or
|
|
8097
|
+
// API identity. A corrupt same-owner journal remains a hard stop.
|
|
8098
|
+
if (EVM_PRIVATE_KEY_RE.test(candidateOwnerKey)) {
|
|
8099
|
+
readMoneyWorkflowJournal(moneyWorkflowEncryptionKey(candidateOwnerKey), candidateOwnerKey);
|
|
8100
|
+
}
|
|
8101
|
+
const authenticated = await call("GET", "/v1/me/subscription", undefined, {
|
|
8102
|
+
authKey: candidateApiKey,
|
|
8103
|
+
retryOnError: false,
|
|
8104
|
+
timeoutMs: 30_000,
|
|
8105
|
+
});
|
|
8106
|
+
if (authenticated.ok === false) {
|
|
8107
|
+
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.");
|
|
8108
|
+
break;
|
|
8109
|
+
}
|
|
8110
|
+
const previousOwner = EVM_PRIVATE_KEY_RE.test(START_OWNER_KEY)
|
|
8111
|
+
? ownerAddressForPrivateKey(START_OWNER_KEY)
|
|
8112
|
+
: null;
|
|
8113
|
+
START_KEY = candidateApiKey;
|
|
8114
|
+
START_OWNER_KEY = candidateOwnerKey;
|
|
8115
|
+
launcherAccountIdCache = undefined;
|
|
8116
|
+
setKey(candidateApiKey);
|
|
8117
|
+
runtimeManagedAccountId = undefined;
|
|
8118
|
+
runtimeBindingError = undefined;
|
|
8119
|
+
forgetActiveChildAccount();
|
|
8120
|
+
if (EVM_PRIVATE_KEY_RE.test(candidateOwnerKey)) {
|
|
8121
|
+
setRuntimeOwnerPrivateKey(candidateOwnerKey);
|
|
8122
|
+
}
|
|
8123
|
+
else {
|
|
8124
|
+
clearRuntimeOwnerPrivateKey();
|
|
8125
|
+
}
|
|
8126
|
+
const currentOwner = EVM_PRIVATE_KEY_RE.test(candidateOwnerKey)
|
|
8127
|
+
? ownerAddressForPrivateKey(candidateOwnerKey)
|
|
8128
|
+
: null;
|
|
8129
|
+
out = {
|
|
8130
|
+
ok: true,
|
|
8131
|
+
message: "Current Keychain launcher credential, owner signer, and workflow journal restored for this MCP session.",
|
|
8132
|
+
identity_changed: Boolean(previousOwner && currentOwner
|
|
8133
|
+
&& previousOwner.toLowerCase() !== currentOwner.toLowerCase()),
|
|
8134
|
+
workflow_journal_identity: currentOwner
|
|
8135
|
+
? workflowIdentityFingerprint(candidateOwnerKey)
|
|
8136
|
+
: null,
|
|
8137
|
+
_meta: { source: "mcp_keychain", key_prefix: candidateApiKey.slice(0, 12) },
|
|
8138
|
+
};
|
|
8139
|
+
}
|
|
8140
|
+
catch (error) {
|
|
8141
|
+
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
8142
|
}
|
|
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
8143
|
}
|
|
8059
8144
|
break;
|
|
8060
8145
|
}
|
package/dist/key-backup.js
CHANGED
|
@@ -8,6 +8,7 @@ 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";
|
|
@@ -797,6 +798,7 @@ async function registerCommand(allowExisting = false, agentManaged = false) {
|
|
|
797
798
|
throw new Error("A Felix API key is already installed. Use felix-keys status, or remove it before registering again.");
|
|
798
799
|
}
|
|
799
800
|
let ownerKey = readKeychainPassword(OWNER_KEYCHAIN_SERVICE);
|
|
801
|
+
let ownerCreated = false;
|
|
800
802
|
if (ownerKey && !PRIVATE_KEY_RE.test(ownerKey)) {
|
|
801
803
|
throw new Error("The installed Felix owner Keychain item is invalid; registration was not attempted.");
|
|
802
804
|
}
|
|
@@ -813,6 +815,7 @@ async function registerCommand(allowExisting = false, agentManaged = false) {
|
|
|
813
815
|
catch { /* best effort */ }
|
|
814
816
|
throw new Error("Owner Keychain write did not verify; nothing was registered.");
|
|
815
817
|
}
|
|
818
|
+
ownerCreated = true;
|
|
816
819
|
}
|
|
817
820
|
const account = privateKeyToAccount(ownerKey);
|
|
818
821
|
const post = async (path, body) => {
|
|
@@ -863,6 +866,8 @@ async function registerCommand(allowExisting = false, agentManaged = false) {
|
|
|
863
866
|
catch { /* best effort */ }
|
|
864
867
|
throw new Error("API-key Keychain write did not verify; the key was not retained.");
|
|
865
868
|
}
|
|
869
|
+
if (ownerCreated)
|
|
870
|
+
markFreshWorkflowIdentity(ownerKey);
|
|
866
871
|
console.log(`Felix account created: ${String(registered.account_id || "")}`);
|
|
867
872
|
console.log(`Owner address: ${account.address}`);
|
|
868
873
|
console.log(`API key stored in Keychain (prefix ${String(registered.prefix || "")}). The key itself was not printed.`);
|
|
@@ -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.107",
|
|
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.107",
|
|
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.107",
|
|
29
29
|
"transport": {
|
|
30
30
|
"type": "stdio"
|
|
31
31
|
}
|