granttap-mcp 0.8.130 → 0.8.131

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.
@@ -10,7 +10,7 @@ keeps each phone response tied to the exact originating chat and prompt.
10
10
  Install the supported CLI on this computer, then run:
11
11
 
12
12
  ```bash
13
- npm install -g granttap-mcp@0.8.130
13
+ npm install -g granttap-mcp@0.8.131
14
14
  granttap setup
15
15
  granttap status
16
16
  ```
@@ -4,7 +4,7 @@
4
4
  "command": "node",
5
5
  "args": [
6
6
  "-e",
7
- "\"use strict\";\n\n// Cursor may start this MCP from any cwd. Execute JavaScript entry points with\n// Node itself: Windows batch shims require shell quoting that differs by host.\nconst { spawn } = require(\"node:child_process\");\nconst { existsSync } = require(\"node:fs\");\nconst { delimiter, dirname, join } = require(\"node:path\");\n\nconst PACKAGE = \"granttap-mcp@0.8.130\";\nconst dryRun = process.env.GRANTTAP_BOOTSTRAP_DRY_RUN === \"1\";\nconst platform = dryRun && process.env.GRANTTAP_BOOTSTRAP_PLATFORM\n ? process.env.GRANTTAP_BOOTSTRAP_PLATFORM : process.platform;\nconst nodeRoot = dryRun && process.env.GRANTTAP_BOOTSTRAP_NODE_ROOT\n ? process.env.GRANTTAP_BOOTSTRAP_NODE_ROOT : dirname(process.execPath);\nconst pathRoots = (process.env.PATH || \"\").split(delimiter).filter(Boolean);\nconst appData = process.env.APPDATA;\nconst roots = [nodeRoot, ...pathRoots, ...(appData ? [join(appData, \"npm\")] : [])];\nconst first = (paths) => paths.find((path) => existsSync(path));\n\nfunction launch() {\n if (platform !== \"win32\") {\n const installed = first(roots.map((root) => join(root, \"granttap-mcp\")));\n if (installed) return { command: installed, args: [] };\n const npx = first(roots.map((root) => join(root, \"npx\"))) || \"npx\";\n return { command: npx, args: [\"-y\", PACKAGE] };\n }\n const installed = first(roots.map((root) =>\n join(root, \"node_modules\", \"granttap-mcp\", \"bin\", \"granttap-mcp.mjs\")));\n if (installed) return { command: process.execPath, args: [installed] };\n const npx = first(roots.map((root) =>\n join(root, \"node_modules\", \"npm\", \"bin\", \"npx-cli.js\")));\n if (npx) return { command: process.execPath, args: [npx, \"-y\", PACKAGE] };\n throw new Error(\"Node.js/npm 22.13.0+ is required on this Windows device. Install npm and retry GrantTap.\");\n}\n\nlet target;\ntry { target = launch(); }\ncatch (error) {\n process.stderr.write(`[granttap] ${error.message}\\n`);\n process.exit(1);\n}\n\nif (dryRun) {\n process.stdout.write(JSON.stringify(target));\n process.exit(0);\n}\n\nconst child = spawn(target.command, target.args, { stdio: \"inherit\", windowsHide: true });\nchild.on(\"error\", (error) => {\n process.stderr.write(`[granttap] ${error.message}\\n`);\n process.exit(1);\n});\nchild.on(\"exit\", (code, signal) => {\n if (signal && platform !== \"win32\") {\n try { process.kill(process.pid, signal); } catch { process.exit(code ?? 1); }\n return;\n }\n process.exit(code ?? 1);\n});\n"
7
+ "\"use strict\";\n\n// Cursor may start this MCP from any cwd. Execute JavaScript entry points with\n// Node itself: Windows batch shims require shell quoting that differs by host.\nconst { spawn } = require(\"node:child_process\");\nconst { existsSync } = require(\"node:fs\");\nconst { delimiter, dirname, join } = require(\"node:path\");\n\nconst PACKAGE = \"granttap-mcp@0.8.131\";\nconst dryRun = process.env.GRANTTAP_BOOTSTRAP_DRY_RUN === \"1\";\nconst platform = dryRun && process.env.GRANTTAP_BOOTSTRAP_PLATFORM\n ? process.env.GRANTTAP_BOOTSTRAP_PLATFORM : process.platform;\nconst nodeRoot = dryRun && process.env.GRANTTAP_BOOTSTRAP_NODE_ROOT\n ? process.env.GRANTTAP_BOOTSTRAP_NODE_ROOT : dirname(process.execPath);\nconst pathRoots = (process.env.PATH || \"\").split(delimiter).filter(Boolean);\nconst appData = process.env.APPDATA;\nconst roots = [nodeRoot, ...pathRoots, ...(appData ? [join(appData, \"npm\")] : [])];\nconst first = (paths) => paths.find((path) => existsSync(path));\n\nfunction launch() {\n if (platform !== \"win32\") {\n const installed = first(roots.map((root) => join(root, \"granttap-mcp\")));\n if (installed) return { command: installed, args: [] };\n const npx = first(roots.map((root) => join(root, \"npx\"))) || \"npx\";\n return { command: npx, args: [\"-y\", PACKAGE] };\n }\n const installed = first(roots.map((root) =>\n join(root, \"node_modules\", \"granttap-mcp\", \"bin\", \"granttap-mcp.mjs\")));\n if (installed) return { command: process.execPath, args: [installed] };\n const npx = first(roots.map((root) =>\n join(root, \"node_modules\", \"npm\", \"bin\", \"npx-cli.js\")));\n if (npx) return { command: process.execPath, args: [npx, \"-y\", PACKAGE] };\n throw new Error(\"Node.js/npm 22.13.0+ is required on this Windows device. Install npm and retry GrantTap.\");\n}\n\nlet target;\ntry { target = launch(); }\ncatch (error) {\n process.stderr.write(`[granttap] ${error.message}\\n`);\n process.exit(1);\n}\n\nif (dryRun) {\n process.stdout.write(JSON.stringify(target));\n process.exit(0);\n}\n\nconst child = spawn(target.command, target.args, { stdio: \"inherit\", windowsHide: true });\nchild.on(\"error\", (error) => {\n process.stderr.write(`[granttap] ${error.message}\\n`);\n process.exit(1);\n});\nchild.on(\"exit\", (code, signal) => {\n if (signal && platform !== \"win32\") {\n try { process.kill(process.pid, signal); } catch { process.exit(code ?? 1); }\n return;\n }\n process.exit(code ?? 1);\n});\n"
8
8
  ]
9
9
  }
10
10
  }
@@ -7,7 +7,7 @@ const { spawn } = require("node:child_process");
7
7
  const { existsSync } = require("node:fs");
8
8
  const { delimiter, dirname, join } = require("node:path");
9
9
 
10
- const PACKAGE = "granttap-mcp@0.8.130";
10
+ const PACKAGE = "granttap-mcp@0.8.131";
11
11
  const dryRun = process.env.GRANTTAP_BOOTSTRAP_DRY_RUN === "1";
12
12
  const platform = dryRun && process.env.GRANTTAP_BOOTSTRAP_PLATFORM
13
13
  ? process.env.GRANTTAP_BOOTSTRAP_PLATFORM : process.platform;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "granttap-mcp",
3
- "version": "0.8.130",
3
+ "version": "0.8.131",
4
4
  "description": "Commercial computer runtime connecting local coding agents to GrantTap on Mac, iPhone, iPad and Apple Watch.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,6 +11,8 @@
11
11
  * QR code scanned by the phone). Nothing here ever leaves the device unsealed.
12
12
  */
13
13
  import nacl from "tweetnacl";
14
+ import {sharedBoxKey} from './shared-box';
15
+ export {clearSharedBoxKeys} from './shared-box';
14
16
 
15
17
  export type KeyPair = { publicKey: string; secretKey: string }; // base64
16
18
 
@@ -30,7 +32,7 @@ export function seal(
30
32
  ): { nonce: string; box: string } {
31
33
  const msg = new TextEncoder().encode(JSON.stringify(payload));
32
34
  const nonce = nacl.randomBytes(nacl.box.nonceLength);
33
- const box = nacl.box(msg, nonce, ub64(theirPublicKey), ub64(mySecretKey));
35
+ const box = nacl.box.after(msg, nonce, sharedBoxKey(theirPublicKey, mySecretKey));
34
36
  return { nonce: b64(nonce), box: b64(box) };
35
37
  }
36
38
 
@@ -52,7 +54,7 @@ export function open(
52
54
  ): unknown | null {
53
55
  let opened: Uint8Array | null = null;
54
56
  try {
55
- opened = nacl.box.open(ub64(box), ub64(nonce), ub64(theirPublicKey), ub64(mySecretKey));
57
+ opened = nacl.box.open.after(ub64(box), ub64(nonce), sharedBoxKey(theirPublicKey, mySecretKey));
56
58
  } catch {
57
59
  return null;
58
60
  }
@@ -6,7 +6,7 @@ import { OutboundFrameQueue, sendEncryptedPayload, priorityControlPayload } from
6
6
  import { openRelayMessage, parseRelayControl, waitForRelayPayload } from "./relay-inbound";
7
7
  import { consumeTaskJobOffer, type TaskDispatchListener } from "./task-dispatch";
8
8
  import { Payload, type Role } from "../protocol/schema";
9
- import { peerPublicKeys } from "./crypto";
9
+ import { clearSharedBoxKeys, peerPublicKeys } from "./crypto";
10
10
  import type { PeerConfig, RelayClientOptions, SendOptions } from "./relay-client-types";
11
11
  export type { PeerConfig, RelayClientOptions, SendOptions } from "./relay-client-types";
12
12
  import { RelayMessageAcceptance } from "./replay-store";
@@ -264,6 +264,7 @@ export class RelayClient {
264
264
  }
265
265
 
266
266
  close(): void {
267
+ clearSharedBoxKeys();
267
268
  this.frames?.cancel();
268
269
  this.socketHealth.stop();
269
270
  this.admissionLease.stop();
@@ -0,0 +1,15 @@
1
+ # Shared NaCl box keys
2
+
3
+ Repeated device envelopes reuse NaCl's documented `box.before` precomputation.
4
+ `box.after` and `box.open.after` produce and read the existing NaCl wire format;
5
+ every envelope still uses a fresh random nonce. Both devices' key bytes identify
6
+ the cache entry, so key rotation cannot select an older pairing's shared key.
7
+
8
+ The process-local LRU holds at most 64 keys for 60 seconds of monotonic time.
9
+ Expiration is enforced on lookup. Eviction, expiry and explicit transport close
10
+ zero the cached key material. Decoded private-key scratch buffers are zeroed on
11
+ each lookup; cache identifiers are SHA-256 digests, not raw private keys.
12
+
13
+ Tests in `tests/` cover direct NaCl interoperability, rotation, authentication,
14
+ fresh nonces, bounded derivation and erasure. This module uses the
15
+ GrantTap Commercial Source License.
@@ -0,0 +1,39 @@
1
+ import {createHash} from 'node:crypto';
2
+ import {performance} from 'node:perf_hooks';
3
+ import nacl from 'tweetnacl';
4
+
5
+ /** Bounded, process-local NaCl precomputation; raw private keys never become cache identities. */
6
+ export function createSharedBoxCache(options: {
7
+ capacity?: number; ttlMs?: number; now?: () => number;
8
+ derive?: (publicKey: Uint8Array, secretKey: Uint8Array) => Uint8Array;
9
+ } = {}) {
10
+ const capacity = Number.isSafeInteger(options.capacity) && options.capacity! > 0 ? Math.min(256, options.capacity!) : 64;
11
+ const ttlMs = Number.isFinite(options.ttlMs) && options.ttlMs! > 0 ? options.ttlMs! : 60_000;
12
+ const now = options.now ?? (() => performance.now()), derive = options.derive ?? nacl.box.before;
13
+ const entries = new Map<string, {key: Uint8Array; expiresAt: number}>();
14
+ return {
15
+ get(publicKey: string, secretKey: string): Uint8Array {
16
+ const pub = Buffer.from(publicKey, 'base64'), secret = Buffer.from(secretKey, 'base64');
17
+ try {
18
+ if (pub.length !== nacl.box.publicKeyLength) throw Error('bad public key size');
19
+ if (secret.length !== nacl.box.secretKeyLength) throw Error('bad secret key size');
20
+ const identity = createHash('sha256').update(pub).update(secret).digest('hex'), at = now();
21
+ const hit = entries.get(identity);
22
+ if (hit && hit.expiresAt > at) {entries.delete(identity); entries.set(identity, hit); return hit.key}
23
+ for (const [id, entry] of entries) if (entry.expiresAt <= at) {entry.key.fill(0); entries.delete(id)}
24
+ const key = derive(pub, secret);
25
+ entries.set(identity, {key, expiresAt: at + ttlMs});
26
+ while (entries.size > capacity) {
27
+ const id = entries.keys().next().value!;
28
+ entries.get(id)!.key.fill(0); entries.delete(id);
29
+ }
30
+ return key;
31
+ } finally {secret.fill(0)}
32
+ },
33
+ clear() {for (const entry of entries.values()) entry.key.fill(0); entries.clear()},
34
+ };
35
+ }
36
+
37
+ const sharedBoxes = createSharedBoxCache();
38
+ export const sharedBoxKey = (publicKey: string, secretKey: string) => sharedBoxes.get(publicKey, secretKey);
39
+ export const clearSharedBoxKeys = () => sharedBoxes.clear();