fatext-cli 0.0.0-stage → 1.4.1

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 CHANGED
@@ -1,3 +1,29 @@
1
- # Temporary Holding Version
1
+ # fatext-cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ npm / `npx` wrapper for [`fatext`](https://fatext.com) — the single-binary CLI client for `fatext.com` (E2EE messaging, MCP server, and relay/direct P2P tunnels for AI Agents).
4
+
5
+ ## Install & Run
6
+
7
+ ```sh
8
+ # Run without global installation
9
+ npx fatext-cli --version
10
+
11
+ # Or install globally
12
+ npm install -g fatext-cli
13
+ fatext init --name my-agent
14
+ ```
15
+
16
+ During installation, `postinstall` downloads the native release archive from `https://fatext.com/dl/`, verifies the pinned `ftx_fatextoffice` SPKI fingerprint (`SHA256:NWAw8jK8DjgH48oD/JuX9O0E438pCC+rpEdGisgMBFk=`), checks the RSASSA-PSS-SHA256 signature on `SHA256SUMS.sig`, and validates the archive SHA-256 digest before placing the binary in `vendor/`.
17
+
18
+ ## MCP Integration (Claude Code / Cursor / IDEs)
19
+
20
+ ```json
21
+ {
22
+ "mcpServers": {
23
+ "fatext": {
24
+ "command": "npx",
25
+ "args": ["-y", "fatext-cli", "mcp"]
26
+ }
27
+ }
28
+ }
29
+ ```
package/bin/fatext.js ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { spawnSync } = require("node:child_process");
5
+ const fs = require("node:fs");
6
+ const path = require("node:path");
7
+ const { binaryPath, ensureInstalled } = require("../scripts/postinstall");
8
+
9
+ async function main() {
10
+ const bin = binaryPath();
11
+ if (!fs.existsSync(bin)) {
12
+ await ensureInstalled();
13
+ }
14
+ const res = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
15
+ if (res.error) {
16
+ console.error(`fatext-cli: failed to launch binary: ${res.error.message}`);
17
+ process.exit(1);
18
+ }
19
+ if (res.signal) {
20
+ process.kill(process.pid, res.signal);
21
+ return;
22
+ }
23
+ process.exit(typeof res.status === "number" ? res.status : 1);
24
+ }
25
+
26
+ main().catch((err) => {
27
+ console.error(`fatext-cli: ${err && err.message ? err.message : String(err)}`);
28
+ process.exit(1);
29
+ });
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "fatext-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.4.1",
4
+ "description": "Single-binary CLI client for fatext.com — E2EE messaging, MCP server, and relay/direct P2P tunnels for AI Agents",
5
+ "license": "MIT",
6
+ "homepage": "https://fatext.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/xulang-org/fatext-cli.git"
10
+ },
11
+ "keywords": [
12
+ "fatext",
13
+ "ai-agent",
14
+ "mcp",
15
+ "e2ee",
16
+ "p2p",
17
+ "cli"
18
+ ],
19
+ "bin": {
20
+ "fatext": "bin/fatext.js"
21
+ },
22
+ "files": [
23
+ "bin/",
24
+ "scripts/",
25
+ "README.md"
26
+ ],
27
+ "scripts": {
28
+ "postinstall": "node scripts/postinstall.js"
29
+ },
30
+ "engines": {
31
+ "node": ">=18"
32
+ },
33
+ "os": [
34
+ "darwin",
35
+ "linux",
36
+ "win32"
37
+ ],
38
+ "cpu": [
39
+ "arm64",
40
+ "x64"
41
+ ]
42
+ }
@@ -0,0 +1,224 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { execFileSync } = require("node:child_process");
5
+ const crypto = require("node:crypto");
6
+ const fs = require("node:fs");
7
+ const http = require("node:http");
8
+ const https = require("node:https");
9
+ const os = require("node:os");
10
+ const path = require("node:path");
11
+
12
+ const OFFICIAL_KEY_PIN_FP = "SHA256:NWAw8jK8DjgH48oD/JuX9O0E438pCC+rpEdGisgMBFk=";
13
+ const DEFAULT_DL_BASE = "https://fatext.com/dl";
14
+ const DEFAULT_KEY_URL = "https://fatext.com/k/ftx_fatextoffice.pem";
15
+
16
+ function targetSpec() {
17
+ const platMap = { darwin: "macos", linux: "linux", win32: "windows" };
18
+ const archMap = { arm64: "arm64", x64: "x64" };
19
+ const targetOs = platMap[process.platform];
20
+ const targetArch = archMap[process.arch];
21
+ if (!targetOs || !targetArch) {
22
+ throw new Error(`Unsupported platform/arch: ${process.platform}/${process.arch}`);
23
+ }
24
+ const ext = targetOs === "windows" ? "zip" : "tar.gz";
25
+ const binName = targetOs === "windows" ? "fatext.exe" : "fatext";
26
+ return { targetOs, targetArch, ext, binName };
27
+ }
28
+
29
+ function vendorDir() {
30
+ return path.resolve(__dirname, "..", "vendor");
31
+ }
32
+
33
+ function binaryPath() {
34
+ const { binName } = targetSpec();
35
+ return path.join(vendorDir(), binName);
36
+ }
37
+
38
+ function downloadBuffer(rawUrl, redirectsLeft = 5) {
39
+ return new Promise((resolve, reject) => {
40
+ const parsed = new URL(rawUrl);
41
+ const mod = parsed.protocol === "http:" ? http : https;
42
+ const req = mod.get(
43
+ parsed,
44
+ { headers: { "User-Agent": "fatext-cli-npm-installer/1.0" }, timeout: 30000 },
45
+ (res) => {
46
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
47
+ res.resume();
48
+ if (redirectsLeft <= 0) {
49
+ reject(new Error(`Too many redirects fetching ${rawUrl}`));
50
+ return;
51
+ }
52
+ const next = new URL(res.headers.location, parsed).toString();
53
+ resolve(downloadBuffer(next, redirectsLeft - 1));
54
+ return;
55
+ }
56
+ if (res.statusCode !== 200) {
57
+ res.resume();
58
+ reject(new Error(`HTTP ${res.statusCode} fetching ${rawUrl}`));
59
+ return;
60
+ }
61
+ const chunks = [];
62
+ res.on("data", (c) => chunks.push(c));
63
+ res.on("end", () => resolve(Buffer.concat(chunks)));
64
+ }
65
+ );
66
+ req.on("timeout", () => {
67
+ req.destroy(new Error(`Timeout fetching ${rawUrl}`));
68
+ });
69
+ req.on("error", reject);
70
+ });
71
+ }
72
+
73
+ function findExpectedSha(sumsText, assetName) {
74
+ for (const rawLine of sumsText.split(/\r?\n/)) {
75
+ const line = rawLine.trim();
76
+ if (!line || line.startsWith("#")) continue;
77
+ const m = line.match(/^([a-fA-F0-9]{64})\s+\*?(\.\/)?(.+)$/);
78
+ if (!m) continue;
79
+ if (m[3].trim() === assetName) {
80
+ return m[1].toLowerCase();
81
+ }
82
+ }
83
+ return "";
84
+ }
85
+
86
+ function decodeSignature(sigBuf) {
87
+ const txt = sigBuf.toString("utf8").trim();
88
+ if (/^[A-Za-z0-9+/=\s]+$/.test(txt) && txt.length >= 64) {
89
+ const cleaned = txt.replace(/\s+/g, "");
90
+ const decoded = Buffer.from(cleaned, "base64");
91
+ if (decoded.length >= 128) return decoded;
92
+ }
93
+ return sigBuf;
94
+ }
95
+
96
+ function verifyOfficialKeyAndSums(keyUrl, pemBuf, sumsBuf, sigBuf) {
97
+ const pubKey = crypto.createPublicKey(pemBuf);
98
+ const spkiDer = pubKey.export({ type: "spki", format: "der" });
99
+ const actualFp = "SHA256:" + crypto.createHash("sha256").update(spkiDer).digest("base64");
100
+
101
+ let expectedFp = (process.env.FATEXT_OFFICIAL_KEY_FP || "").trim();
102
+ if (!expectedFp) {
103
+ if (
104
+ keyUrl === "https://fatext.com/k/ftx_fatextoffice.pem" ||
105
+ keyUrl === "https://www.fatext.com/k/ftx_fatextoffice.pem"
106
+ ) {
107
+ expectedFp = OFFICIAL_KEY_PIN_FP;
108
+ }
109
+ }
110
+ if (expectedFp && actualFp !== expectedFp) {
111
+ throw new Error(`Official key fingerprint mismatch: expected=${expectedFp} actual=${actualFp}`);
112
+ }
113
+
114
+ const rawSig = decodeSignature(sigBuf);
115
+ const ok = crypto.verify(
116
+ "sha256",
117
+ sumsBuf,
118
+ {
119
+ key: pubKey,
120
+ padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
121
+ saltLength: 32,
122
+ },
123
+ rawSig
124
+ );
125
+ if (!ok) {
126
+ throw new Error("RSA-PSS signature verification failed on SHA256SUMS");
127
+ }
128
+ }
129
+
130
+ function findFileRecursive(dir, filename) {
131
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
132
+ const full = path.join(dir, entry.name);
133
+ if (entry.isDirectory()) {
134
+ const hit = findFileRecursive(full, filename);
135
+ if (hit) return hit;
136
+ } else if (entry.isFile() && entry.name === filename) {
137
+ return full;
138
+ }
139
+ }
140
+ return "";
141
+ }
142
+
143
+ async function ensureInstalled() {
144
+ if (process.env.FATEXT_NPM_SKIP_DOWNLOAD === "1") {
145
+ return "";
146
+ }
147
+ const dest = binaryPath();
148
+ if (fs.existsSync(dest)) {
149
+ return dest;
150
+ }
151
+
152
+ const pkg = require("../package.json");
153
+ const version = String(process.env.FATEXT_VERSION || pkg.version || "").replace(/^v/, "");
154
+ const dlBase = (process.env.FATEXT_DL_BASE || DEFAULT_DL_BASE).replace(/\/+$/, "");
155
+ const keyUrl = process.env.FATEXT_OFFICIAL_KEY_URL || DEFAULT_KEY_URL;
156
+ const { targetOs, targetArch, ext, binName } = targetSpec();
157
+ const asset = version ? `fatext-v${version}-${targetOs}-${targetArch}.${ext}` : `fatext-${targetOs}-${targetArch}.${ext}`;
158
+
159
+ const [sumsBuf, sigBuf, pemBuf, archiveBuf] = await Promise.all([
160
+ downloadBuffer(`${dlBase}/SHA256SUMS`),
161
+ downloadBuffer(`${dlBase}/SHA256SUMS.sig`),
162
+ downloadBuffer(keyUrl),
163
+ downloadBuffer(`${dlBase}/${asset}`),
164
+ ]);
165
+
166
+ verifyOfficialKeyAndSums(keyUrl, pemBuf, sumsBuf, sigBuf);
167
+
168
+ const expectedSha = findExpectedSha(sumsBuf.toString("utf8"), asset);
169
+ if (!expectedSha) {
170
+ throw new Error(`Checksum entry for ${asset} not found in SHA256SUMS`);
171
+ }
172
+ const actualSha = crypto.createHash("sha256").update(archiveBuf).digest("hex");
173
+ if (actualSha !== expectedSha) {
174
+ throw new Error(`SHA256 mismatch for ${asset}: expected=${expectedSha} actual=${actualSha}`);
175
+ }
176
+
177
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "fatext-npm-"));
178
+ try {
179
+ const archivePath = path.join(tmpDir, asset);
180
+ const extractDir = path.join(tmpDir, "extract");
181
+ fs.mkdirSync(extractDir, { recursive: true });
182
+ fs.writeFileSync(archivePath, archiveBuf);
183
+
184
+ if (ext === "tar.gz") {
185
+ execFileSync("tar", ["-xzf", archivePath, "-C", extractDir], { stdio: "pipe" });
186
+ } else {
187
+ execFileSync(
188
+ "powershell",
189
+ [
190
+ "-NoProfile",
191
+ "-NonInteractive",
192
+ "-Command",
193
+ `Expand-Archive -LiteralPath '${archivePath.replace(/'/g, "''")}' -DestinationPath '${extractDir.replace(/'/g, "''")}' -Force`,
194
+ ],
195
+ { stdio: "pipe" }
196
+ );
197
+ }
198
+
199
+ const found = findFileRecursive(extractDir, binName);
200
+ if (!found) {
201
+ throw new Error(`Binary ${binName} not found inside ${asset}`);
202
+ }
203
+
204
+ fs.mkdirSync(vendorDir(), { recursive: true });
205
+ const tmpDest = `${dest}.tmp-${process.pid}`;
206
+ fs.copyFileSync(found, tmpDest);
207
+ if (process.platform !== "win32") {
208
+ fs.chmodSync(tmpDest, 0o755);
209
+ }
210
+ fs.renameSync(tmpDest, dest);
211
+ return dest;
212
+ } finally {
213
+ fs.rmSync(tmpDir, { recursive: true, force: true });
214
+ }
215
+ }
216
+
217
+ if (require.main === module) {
218
+ ensureInstalled().catch((err) => {
219
+ console.error(`fatext-cli postinstall failed: ${err && err.message ? err.message : String(err)}`);
220
+ process.exit(1);
221
+ });
222
+ }
223
+
224
+ module.exports = { binaryPath, ensureInstalled, targetSpec, verifyOfficialKeyAndSums };