@keeperhub/wallet 0.1.3 → 0.1.4
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/dist/cli.cjs +0 -74
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +0 -74
- package/dist/cli.js.map +1 -1
- package/dist/hook-entrypoint.cjs +0 -185
- package/dist/hook-entrypoint.cjs.map +1 -1
- package/dist/hook-entrypoint.js +0 -185
- package/dist/hook-entrypoint.js.map +1 -1
- package/dist/index.cjs +28 -119
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -15
- package/dist/index.d.ts +18 -15
- package/dist/index.js +28 -119
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/skill/keeperhub-wallet.skill.md +25 -7
package/dist/cli.cjs
CHANGED
|
@@ -111,34 +111,6 @@ function fund(walletAddress) {
|
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
// src/hmac.ts
|
|
115
|
-
var import_node_crypto = require("crypto");
|
|
116
|
-
function computeSignature(secret, method, path, subOrgId, body, timestamp) {
|
|
117
|
-
const bodyDigest = (0, import_node_crypto.createHash)("sha256").update(body).digest("hex");
|
|
118
|
-
const signingString = `${method}
|
|
119
|
-
${path}
|
|
120
|
-
${subOrgId}
|
|
121
|
-
${bodyDigest}
|
|
122
|
-
${timestamp}`;
|
|
123
|
-
return (0, import_node_crypto.createHmac)("sha256", secret).update(signingString).digest("hex");
|
|
124
|
-
}
|
|
125
|
-
function buildHmacHeaders(secret, method, path, subOrgId, body) {
|
|
126
|
-
const timestamp = String(Math.floor(Date.now() / 1e3));
|
|
127
|
-
const signature = computeSignature(
|
|
128
|
-
secret,
|
|
129
|
-
method,
|
|
130
|
-
path,
|
|
131
|
-
subOrgId,
|
|
132
|
-
body,
|
|
133
|
-
timestamp
|
|
134
|
-
);
|
|
135
|
-
return {
|
|
136
|
-
"X-KH-Sub-Org": subOrgId,
|
|
137
|
-
"X-KH-Timestamp": timestamp,
|
|
138
|
-
"X-KH-Signature": signature
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
114
|
// src/skill-install.ts
|
|
143
115
|
var import_promises = require("fs/promises");
|
|
144
116
|
var import_node_path2 = require("path");
|
|
@@ -398,47 +370,6 @@ async function cmdAdd(opts = {}) {
|
|
|
398
370
|
process.stdout.write(`config written to ${getWalletConfigPath()}
|
|
399
371
|
`);
|
|
400
372
|
}
|
|
401
|
-
async function cmdLink(opts = {}) {
|
|
402
|
-
const wallet = await readWalletConfig();
|
|
403
|
-
const baseUrl = resolveBaseUrl(opts.baseUrl);
|
|
404
|
-
const sessionCookie = process.env.KH_SESSION_COOKIE;
|
|
405
|
-
if (!sessionCookie) {
|
|
406
|
-
process.stderr.write(
|
|
407
|
-
"[keeperhub-wallet] link requires KH_SESSION_COOKIE env var.\nSign in at app.keeperhub.com, copy the session cookie, and re-run with:\n KH_SESSION_COOKIE='<cookie>' npx @keeperhub/wallet link\n"
|
|
408
|
-
);
|
|
409
|
-
process.exit(1);
|
|
410
|
-
}
|
|
411
|
-
const body = JSON.stringify({ subOrgId: wallet.subOrgId });
|
|
412
|
-
const headers = buildHmacHeaders(
|
|
413
|
-
wallet.hmacSecret,
|
|
414
|
-
"POST",
|
|
415
|
-
"/api/agentic-wallet/link",
|
|
416
|
-
wallet.subOrgId,
|
|
417
|
-
body
|
|
418
|
-
);
|
|
419
|
-
const response = await fetch(`${baseUrl}/api/agentic-wallet/link`, {
|
|
420
|
-
method: "POST",
|
|
421
|
-
headers: {
|
|
422
|
-
...headers,
|
|
423
|
-
"content-type": "application/json",
|
|
424
|
-
cookie: sessionCookie
|
|
425
|
-
},
|
|
426
|
-
body
|
|
427
|
-
});
|
|
428
|
-
const json = await response.json().catch(() => ({}));
|
|
429
|
-
if (!response.ok) {
|
|
430
|
-
process.stderr.write(
|
|
431
|
-
`[keeperhub-wallet] link failed: ${json.code ?? response.status}: ${json.error ?? ""}
|
|
432
|
-
`
|
|
433
|
-
);
|
|
434
|
-
process.exit(1);
|
|
435
|
-
}
|
|
436
|
-
if (json.already) {
|
|
437
|
-
process.stdout.write("already linked\n");
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
process.stdout.write("linked\n");
|
|
441
|
-
}
|
|
442
373
|
async function cmdFund() {
|
|
443
374
|
const wallet = await readWalletConfig();
|
|
444
375
|
const out = fund(wallet.walletAddress);
|
|
@@ -472,11 +403,6 @@ async function runCli(argv = process.argv) {
|
|
|
472
403
|
program.command("add").description("Provision a new agentic wallet (no account required)").option("--base-url <url>", "KeeperHub API base URL").action(async (opts) => {
|
|
473
404
|
await cmdAdd(opts);
|
|
474
405
|
});
|
|
475
|
-
program.command("link").description(
|
|
476
|
-
"Link the current wallet to your KeeperHub account (requires KH_SESSION_COOKIE env)"
|
|
477
|
-
).option("--base-url <url>", "KeeperHub API base URL").action(async (opts) => {
|
|
478
|
-
await cmdLink(opts);
|
|
479
|
-
});
|
|
480
406
|
program.command("fund").description(
|
|
481
407
|
"Print Coinbase Onramp URL (Base USDC) and Tempo deposit address"
|
|
482
408
|
).action(async () => {
|
package/dist/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts","../src/balance.ts","../src/chains.ts","../src/fund.ts","../src/hmac.ts","../src/skill-install.ts","../src/agent-detect.ts","../src/storage.ts","../src/types.ts"],"sourcesContent":["// CLI dispatcher for `npx @keeperhub/wallet <cmd>`. Ships 5 subcommands:\n// add (provision -- NO auth), link (HMAC + KH_SESSION_COOKIE dual-proof),\n// fund (pure string-build Coinbase Onramp + Tempo address), balance (Base\n// USDC + Tempo USDC.e), info (print subOrgId + walletAddress from\n// ~/.keeperhub/wallet.json).\n//\n// @security The HMAC secret written to wallet.json is NEVER printed to stdout\n// or stderr. `add` prints only subOrgId + walletAddress + the config path so\n// users can inspect perms. `info` never references the secret at all. Grep\n// rule: no process.stdout/process.stderr line in this file should include\n// wallet.hmacSecret or data.hmacSecret.\n//\n// Exit codes: 0 on success, 1 on any error (WalletConfigMissingError,\n// HTTP failure, validation error). Uncaught errors are written to stderr.\n\nimport { Command } from \"commander\";\nimport { checkBalance } from \"./balance.js\";\nimport { fund } from \"./fund.js\";\nimport { buildHmacHeaders } from \"./hmac.js\";\nimport { installSkill } from \"./skill-install.js\";\nimport {\n getWalletConfigPath,\n readWalletConfig,\n writeWalletConfig,\n} from \"./storage.js\";\nimport { WalletConfigMissingError } from \"./types.js\";\n\nconst TRAILING_SLASH = /\\/$/;\nconst WALLET_ADDRESS_PATTERN = /^0x[a-fA-F0-9]{40}$/;\n\nfunction resolveBaseUrl(override: string | undefined): string {\n const candidate =\n override ?? process.env.KEEPERHUB_API_URL ?? \"https://app.keeperhub.com\";\n return candidate.replace(TRAILING_SLASH, \"\");\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.length > 0;\n}\n\nfunction provisionInvalidError(\n message: string\n): Error & { code: \"PROVISION_RESPONSE_INVALID\" } {\n const err = new Error(message) as Error & {\n code: \"PROVISION_RESPONSE_INVALID\";\n };\n err.code = \"PROVISION_RESPONSE_INVALID\";\n return err;\n}\n\nfunction validateProvisionResponse(data: unknown): {\n subOrgId: string;\n walletAddress: `0x${string}`;\n hmacSecret: string;\n} {\n if (typeof data !== \"object\" || data === null) {\n throw provisionInvalidError(\"provision response is not an object\");\n }\n const { subOrgId, walletAddress, hmacSecret } = data as Record<\n string,\n unknown\n >;\n if (\n !(\n isNonEmptyString(subOrgId) &&\n isNonEmptyString(walletAddress) &&\n isNonEmptyString(hmacSecret)\n )\n ) {\n throw provisionInvalidError(\n \"provision response missing subOrgId, walletAddress, or hmacSecret\"\n );\n }\n if (!WALLET_ADDRESS_PATTERN.test(walletAddress)) {\n throw provisionInvalidError(\n `provision response walletAddress is not a valid 0x-prefixed 40-hex address: ${walletAddress}`\n );\n }\n return {\n subOrgId,\n walletAddress: walletAddress as `0x${string}`,\n hmacSecret,\n };\n}\n\nasync function cmdAdd(opts: { baseUrl?: string } = {}): Promise<void> {\n const baseUrl = resolveBaseUrl(opts.baseUrl);\n const response = await fetch(`${baseUrl}/api/agentic-wallet/provision`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: \"{}\",\n });\n if (!response.ok) {\n const text = await response.text();\n process.stderr.write(\n `[keeperhub-wallet] provision failed: HTTP ${response.status}: ${text}\\n`\n );\n process.exit(1);\n }\n const raw = (await response.json()) as unknown;\n const data = validateProvisionResponse(raw);\n await writeWalletConfig({\n subOrgId: data.subOrgId,\n walletAddress: data.walletAddress,\n hmacSecret: data.hmacSecret,\n });\n // Intentionally print only public fields. The hmacSecret is written to\n // wallet.json (chmod 0o600) but never printed -- T-34-cli-02 mitigation.\n process.stdout.write(`subOrgId: ${data.subOrgId}\\n`);\n process.stdout.write(`walletAddress: ${data.walletAddress}\\n`);\n process.stdout.write(`config written to ${getWalletConfigPath()}\\n`);\n}\n\nasync function cmdLink(opts: { baseUrl?: string } = {}): Promise<void> {\n const wallet = await readWalletConfig();\n const baseUrl = resolveBaseUrl(opts.baseUrl);\n const sessionCookie = process.env.KH_SESSION_COOKIE;\n if (!sessionCookie) {\n process.stderr.write(\n \"[keeperhub-wallet] link requires KH_SESSION_COOKIE env var.\\n\" +\n \"Sign in at app.keeperhub.com, copy the session cookie, and re-run with:\\n\" +\n \" KH_SESSION_COOKIE='<cookie>' npx @keeperhub/wallet link\\n\"\n );\n process.exit(1);\n }\n const body = JSON.stringify({ subOrgId: wallet.subOrgId });\n const headers = buildHmacHeaders(\n wallet.hmacSecret,\n \"POST\",\n \"/api/agentic-wallet/link\",\n wallet.subOrgId,\n body\n );\n const response = await fetch(`${baseUrl}/api/agentic-wallet/link`, {\n method: \"POST\",\n headers: {\n ...headers,\n \"content-type\": \"application/json\",\n cookie: sessionCookie,\n },\n body,\n });\n const json = (await response.json().catch(() => ({}))) as {\n ok?: boolean;\n already?: boolean;\n error?: string;\n code?: string;\n };\n if (!response.ok) {\n process.stderr.write(\n `[keeperhub-wallet] link failed: ${json.code ?? response.status}: ${json.error ?? \"\"}\\n`\n );\n process.exit(1);\n }\n if (json.already) {\n process.stdout.write(\"already linked\\n\");\n return;\n }\n process.stdout.write(\"linked\\n\");\n}\n\nasync function cmdFund(): Promise<void> {\n const wallet = await readWalletConfig();\n const out = fund(wallet.walletAddress);\n process.stdout.write(`${out.coinbaseOnrampUrl}\\n`);\n process.stdout.write(`Tempo address: ${out.tempoAddress}\\n`);\n process.stdout.write(`${out.disclaimer}\\n`);\n}\n\nasync function cmdBalance(): Promise<void> {\n const wallet = await readWalletConfig();\n const snap = await checkBalance(wallet);\n process.stdout.write(`Base USDC: ${snap.base.amount}\\n`);\n process.stdout.write(`Tempo USDC.e: ${snap.tempo.amount}\\n`);\n}\n\nasync function cmdInfo(): Promise<void> {\n const wallet = await readWalletConfig();\n process.stdout.write(`subOrgId: ${wallet.subOrgId}\\n`);\n process.stdout.write(`walletAddress: ${wallet.walletAddress}\\n`);\n}\n\nexport async function runCli(argv: string[] = process.argv): Promise<void> {\n const program = new Command();\n program\n .name(\"keeperhub-wallet\")\n .description(\n \"KeeperHub agentic wallet CLI (auto-pay x402 + MPP 402 responses)\"\n )\n .version(\"0.1.3\");\n\n program\n .command(\"add\")\n .description(\"Provision a new agentic wallet (no account required)\")\n .option(\"--base-url <url>\", \"KeeperHub API base URL\")\n .action(async (opts: { baseUrl?: string }) => {\n await cmdAdd(opts);\n });\n\n program\n .command(\"link\")\n .description(\n \"Link the current wallet to your KeeperHub account (requires KH_SESSION_COOKIE env)\"\n )\n .option(\"--base-url <url>\", \"KeeperHub API base URL\")\n .action(async (opts: { baseUrl?: string }) => {\n await cmdLink(opts);\n });\n\n program\n .command(\"fund\")\n .description(\n \"Print Coinbase Onramp URL (Base USDC) and Tempo deposit address\"\n )\n .action(async () => {\n await cmdFund();\n });\n\n program\n .command(\"balance\")\n .description(\"Print on-chain balance: Base USDC + Tempo USDC.e\")\n .action(async () => {\n await cmdBalance();\n });\n\n program\n .command(\"info\")\n .description(\"Print subOrgId and walletAddress from local config\")\n .action(async () => {\n await cmdInfo();\n });\n\n program\n .command(\"skill\")\n .description(\n \"Install the KeeperHub skill file into detected agent directories\"\n )\n .addCommand(\n new Command(\"install\")\n .description(\n \"Write skill file + register PreToolUse hook in all detected agents\"\n )\n .action(async () => {\n const result = await installSkill();\n for (const write of result.skillWrites) {\n process.stdout.write(\n `skill: ${write.agent} -> ${write.path} (${write.status})\\n`\n );\n }\n for (const reg of result.hookRegistrations) {\n if (reg.status === \"registered\") {\n process.stdout.write(\n `hook: ${reg.agent} -> PreToolUse registered\\n`\n );\n } else if (reg.status === \"notice\") {\n process.stderr.write(\n `notice: ${reg.agent} -> ${reg.message ?? \"\"}\\n`\n );\n }\n }\n if (result.skillWrites.length === 0) {\n process.stderr.write(\n \"No supported agent skill directories detected under $HOME. Create ~/.claude/, ~/.cursor/, ~/.cline/, ~/.windsurf/, or ~/.config/opencode/ and re-run.\\n\"\n );\n }\n })\n );\n\n try {\n await program.parseAsync(argv);\n } catch (err) {\n if (err instanceof WalletConfigMissingError) {\n process.stderr.write(`[keeperhub-wallet] ${err.message}\\n`);\n process.exit(1);\n }\n process.stderr.write(\n `[keeperhub-wallet] ${(err as Error).message ?? String(err)}\\n`\n );\n process.exit(1);\n }\n}\n","// checkBalance() unified view (PAY-05):\n// - Base USDC balanceOf (viem publicClient on Base)\n// - Tempo USDC.e balanceOf (viem publicClient on Tempo)\n//\n// Both legs are fetched in parallel via Promise.all. The on-chain reads\n// touch only the canonical USDC contract on their respective chains\n// (read-only ERC-20 balanceOf with no state mutation).\n//\n// The /api/agentic-wallet/credit ledger is intentionally NOT read here:\n// the server endpoint exists but no debit path is wired, so surfacing the\n// balance to users implied a capability that has not shipped. Restore the\n// leg here when KEEP-305/306 lands.\n//\n// @security balance.ts does not emit balance data to stdout/stderr via the\n// global console object or util.inspect (T-34-bal-02 mitigation). Any\n// stdout emitter added here is a privacy regression; grep-enforced in\n// acceptance criteria.\nimport {\n createPublicClient,\n erc20Abi,\n formatUnits,\n http,\n type PublicClient,\n} from \"viem\";\nimport { BASE_USDC, base, TEMPO_USDC_E, tempo } from \"./chains.js\";\nimport type { WalletConfig } from \"./types.js\";\n\n// USDC and USDC.e both use 6 decimals on Base + Tempo respectively.\nconst USDC_DECIMALS = 6;\n\nexport type BalanceSnapshot = {\n base: {\n chain: \"base\";\n token: \"USDC\";\n amount: string;\n address: `0x${string}`;\n };\n tempo: {\n chain: \"tempo\";\n token: \"USDC.e\";\n amount: string;\n address: `0x${string}`;\n };\n};\n\nexport type CheckBalanceOptions = {\n /** Injectable viem client for Base (tests mock readContract). */\n baseClient?: PublicClient;\n /** Injectable viem client for Tempo (tests mock readContract). */\n tempoClient?: PublicClient;\n};\n\n/**\n * Read the wallet's on-chain balance across Base + Tempo in parallel. Both\n * legs must resolve; any single failure rejects the Promise.\n *\n * Amounts are formatted as decimal strings (6-decimal USDC precision) so the\n * caller can render them without BigInt math.\n */\nexport async function checkBalance(\n wallet: WalletConfig,\n opts: CheckBalanceOptions = {}\n): Promise<BalanceSnapshot> {\n const baseClient =\n opts.baseClient ??\n (createPublicClient({\n chain: base,\n transport: http(),\n }) as unknown as PublicClient);\n const tempoClient =\n opts.tempoClient ??\n (createPublicClient({\n chain: tempo,\n transport: http(),\n }) as unknown as PublicClient);\n\n // Promise.all fires both reads concurrently. Total elapsed ~= max(leg)\n // rather than sum(leg); SC-3 (<2s) test asserts this.\n const [baseRaw, tempoRaw] = await Promise.all([\n baseClient.readContract({\n address: BASE_USDC,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [wallet.walletAddress],\n }) as Promise<bigint>,\n tempoClient.readContract({\n address: TEMPO_USDC_E,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [wallet.walletAddress],\n }) as Promise<bigint>,\n ]);\n\n return {\n base: {\n chain: \"base\",\n token: \"USDC\",\n amount: formatUnits(baseRaw, USDC_DECIMALS),\n address: wallet.walletAddress,\n },\n tempo: {\n chain: \"tempo\",\n token: \"USDC.e\",\n amount: formatUnits(tempoRaw, USDC_DECIMALS),\n address: wallet.walletAddress,\n },\n };\n}\n","// Sources (truth):\n// - lib/agentic-wallet/sign.ts:56 -- Base USDC at\n// 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 (chainId 8453).\n// - lib/mpp/server.ts:3 -- Tempo USDC.e at\n// 0x20c000000000000000000000b9537d11c60e8b50 (chainId 4217).\n//\n// Tempo is not in viem/chains core as of viem 2.48.1 (the version pinned in\n// this package). Define it inline via defineChain so the only dependency is\n// viem itself. TEMPO_RPC_URL overrides the default RPC for heavy readers who\n// want to point at their own node (T-34-bal-01 mitigation).\nimport { defineChain } from \"viem\";\n\nexport { base } from \"viem/chains\";\n\nexport const tempo = defineChain({\n id: 4217,\n name: \"Tempo\",\n nativeCurrency: { decimals: 18, name: \"Ether\", symbol: \"ETH\" },\n rpcUrls: {\n default: {\n http: [process.env.TEMPO_RPC_URL ?? \"https://rpc.tempo.xyz\"],\n },\n },\n blockExplorers: {\n default: { name: \"Tempo Explorer\", url: \"https://explorer.tempo.xyz\" },\n },\n});\n\n/** Circle-issued USDC on Base mainnet. */\nexport const BASE_USDC = \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\" as const;\n\n/** Bridged USDC (USDC.e) on Tempo mainnet. NOT the same contract as BASE_USDC. */\nexport const TEMPO_USDC_E =\n \"0x20c000000000000000000000b9537d11c60e8b50\" as const;\n","// Source: 34-RESEARCH Pattern 5 + Pitfall 5.\n// Coinbase deprecated the query-param pay.coinbase.com flow in favour of\n// sessionToken URLs on 2025-07-31, but the legacy endpoint still returns a\n// working Onramp page (it just may not pre-fill the asset/network/address\n// fields). We print the legacy URL for zero-dependency ergonomics and a\n// follow-up disclaimer so users know to paste manually if prefill is dropped.\n//\n// fund() is a pure string-build: no HTTP, no process spawn, no browser\n// invocation. Callers (the CLI `keeperhub-wallet fund` subcommand, the\n// `check_balance` skill in Phase 35) decide how to display the result.\n//\n// T-34-fund-01 mitigation: the host is hard-coded (pay.coinbase.com) and the\n// only user-supplied input is the wallet address, which is regex-validated\n// against the canonical 0x-prefixed 40-hex-char EVM format before any string\n// interpolation.\n\nexport type FundInstructions = {\n /** Coinbase Onramp deeplink (legacy query-param form). */\n coinbaseOnrampUrl: string;\n /** Tempo deposit address — same as the input wallet (EVM address shared). */\n tempoAddress: `0x${string}`;\n /** Plain-ASCII guidance string; no emojis (CLAUDE.md rule). */\n disclaimer: string;\n};\n\n// 0x followed by exactly 40 hex chars, case-insensitive. Kept at module scope\n// so the regex literal is compiled once (biome/ultracite useTopLevelRegex).\nconst EVM_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;\n\n// Coinbase Onramp legacy deeplink. The host + path pair is the documented\n// entry point for query-param-style Onramp sessions.\nconst COINBASE_HOST = \"pay.coinbase.com\";\nconst COINBASE_PATH = \"/buy/select-asset\";\n\n/**\n * Build Coinbase Onramp URL + Tempo deposit address for the given wallet.\n *\n * No HTTP calls are performed. The caller is expected to either print the\n * resulting URL (CLI) or render it in a chat bubble (skill). The returned\n * `disclaimer` explains the Onramp deprecation + the Tempo external-transfer\n * fallback in plain ASCII so terminal clients with ASCII-only fonts render\n * identically to emoji-capable clients.\n *\n * @throws if `walletAddress` does not match /^0x[0-9a-fA-F]{40}$/.\n */\nexport function fund(walletAddress: string): FundInstructions {\n if (!EVM_ADDRESS_RE.test(walletAddress)) {\n throw new Error(`Invalid EVM wallet address: ${walletAddress}`);\n }\n\n // addresses is a JSON-encoded map {walletAddress: [\"base\"]} per Coinbase\n // Onramp docs. Encoding into URLSearchParams guarantees the colon,\n // brackets, and quotes are percent-escaped correctly.\n const params = new URLSearchParams({\n defaultNetwork: \"base\",\n defaultAsset: \"USDC\",\n addresses: JSON.stringify({ [walletAddress]: [\"base\"] }),\n presetCryptoAmount: \"5\",\n });\n\n const coinbaseOnrampUrl = `https://${COINBASE_HOST}${COINBASE_PATH}?${params.toString()}`;\n\n const disclaimer =\n \"If the Coinbase page does not pre-fill, paste your address manually. \" +\n \"For Tempo USDC.e, transfer from an exchange or another wallet to the \" +\n \"address above -- Onramp does not support Tempo directly. Coinbase \" +\n \"sessionToken URLs are the 2025+ canonical form; legacy query-param \" +\n \"URLs may drop prefill on some accounts.\";\n\n return {\n coinbaseOnrampUrl,\n tempoAddress: walletAddress as `0x${string}`,\n disclaimer,\n };\n}\n","import { createHash, createHmac } from \"node:crypto\";\nimport type { HmacHeaders } from \"./types.js\";\n\n/**\n * Mirror of lib/agentic-wallet/hmac.ts::computeSignature.\n * Format (byte-for-byte identical to server):\n * `${method}\\n${path}\\n${subOrgId}\\n${sha256_hex(body)}\\n${timestamp}`\n * Post-HI-05: subOrgId is a signed field.\n *\n * @security Do NOT log the secret or the returned signature. Any stdout\n * emitter (the global console object or util.inspect) added to this\n * file is a T-34-08 violation (grep-enforced).\n */\nexport function computeSignature(\n secret: string,\n method: string,\n path: string,\n subOrgId: string,\n body: string,\n timestamp: string\n): string {\n const bodyDigest = createHash(\"sha256\").update(body).digest(\"hex\");\n const signingString = `${method}\\n${path}\\n${subOrgId}\\n${bodyDigest}\\n${timestamp}`;\n return createHmac(\"sha256\", secret).update(signingString).digest(\"hex\");\n}\n\n/**\n * Build the three X-KH-* headers that authenticate every request to\n * /api/agentic-wallet/* (except /provision, which uses the session cookie).\n *\n * Timestamp is unix seconds (Math.floor(Date.now() / 1000)); the server\n * enforces a symmetric 300-second replay window.\n */\nexport function buildHmacHeaders(\n secret: string,\n method: string,\n path: string,\n subOrgId: string,\n body: string\n): HmacHeaders {\n const timestamp = String(Math.floor(Date.now() / 1000));\n const signature = computeSignature(\n secret,\n method,\n path,\n subOrgId,\n body,\n timestamp\n );\n return {\n \"X-KH-Sub-Org\": subOrgId,\n \"X-KH-Timestamp\": timestamp,\n \"X-KH-Signature\": signature,\n };\n}\n","// Idempotent skill installer for @keeperhub/wallet.\n//\n// Two public entry points:\n// - installSkill(options?) -- writes keeperhub-wallet.skill.md into every\n// detected agent's skills directory and, for Claude Code, registers a\n// PreToolUse hook pointing at `keeperhub-wallet-hook` in\n// ~/.claude/settings.json. For non-claude agents, emits a stderr notice.\n// - registerClaudeCodeHook(settingsPath) -- pure settings.json patcher\n// used internally; exported so tests can drive it directly.\n//\n// Idempotency rule: re-running the installer MUST NOT create a duplicate\n// hook entry. We filter any existing array element whose serialised form\n// contains `keeperhub-wallet-hook` before appending a single fresh record.\n//\n// Preservation rule: all top-level keys in settings.json other than\n// hooks.PreToolUse MUST be byte-preserved. We only ever touch\n// hooks.PreToolUse; any foreign hooks.PostToolUse entries survive verbatim.\n\nimport { chmod, copyFile, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { type AgentTarget, detectAgents } from \"./agent-detect.js\";\n\nconst HOOK_COMMAND = \"keeperhub-wallet-hook\";\n// Match rule for de-dup: any existing PreToolUse entry whose JSON form\n// mentions this string is considered \"ours\" and is removed before append.\nconst KEEPERHUB_HOOK_MARKER = \"keeperhub-wallet-hook\";\n\nexport type InstallResult = {\n skillWrites: Array<{\n agent: string;\n path: string;\n status: \"written\" | \"skipped\";\n }>;\n hookRegistrations: Array<{\n agent: string;\n status: \"registered\" | \"notice\" | \"skipped\";\n message?: string;\n }>;\n};\n\nexport type InstallOptions = {\n homeOverride?: string;\n skillSourcePath?: string;\n onNotice?: (msg: string) => void;\n};\n\ntype ClaudeHookEntry = {\n matcher: string;\n hooks: Array<{ type: string; command: string }>;\n};\n\ntype ClaudeSettings = {\n hooks?: {\n PreToolUse?: unknown[];\n [k: string]: unknown;\n };\n [k: string]: unknown;\n};\n\nfunction buildKeeperhubEntry(): ClaudeHookEntry {\n return {\n matcher: \"*\",\n hooks: [{ type: \"command\", command: HOOK_COMMAND }],\n };\n}\n\nfunction resolveDefaultSkillSource(): string {\n // Resolve the module's own directory in a way that works in both ESM\n // (import.meta.url) and CJS (__dirname shim emitted by tsup). At runtime\n // the module lives inside dist/, so `../skill/` points at the sibling\n // skill/ directory shipped via pkg.files. During vitest tests the module\n // executes from src/, and `../skill/` resolves to packages/wallet/skill/.\n const here = dirname(fileURLToPath(import.meta.url));\n return join(here, \"..\", \"skill\", \"keeperhub-wallet.skill.md\");\n}\n\nfunction defaultNotice(msg: string): void {\n process.stderr.write(`${msg}\\n`);\n}\n\nexport async function registerClaudeCodeHook(\n settingsPath: string\n): Promise<void> {\n let raw: string | null = null;\n try {\n raw = await readFile(settingsPath, \"utf-8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw err;\n }\n }\n\n let config: ClaudeSettings = {};\n if (raw !== null) {\n try {\n config = JSON.parse(raw) as ClaudeSettings;\n } catch {\n throw new Error(\n `settings.json at ${settingsPath} is not valid JSON; aborting hook registration`\n );\n }\n }\n\n const hooks: Record<string, unknown> =\n typeof config.hooks === \"object\" && config.hooks !== null\n ? (config.hooks as Record<string, unknown>)\n : {};\n\n const existingPreToolUse = Array.isArray(hooks.PreToolUse)\n ? (hooks.PreToolUse as unknown[])\n : [];\n\n // De-dup: drop any element that references keeperhub-wallet-hook in its\n // serialised form. Covers both exact-shape matches and any legacy\n // representations we may have written in earlier versions.\n const filtered: unknown[] = [];\n for (const entry of existingPreToolUse) {\n const serialised = JSON.stringify(entry);\n if (!serialised.includes(KEEPERHUB_HOOK_MARKER)) {\n filtered.push(entry);\n }\n }\n filtered.push(buildKeeperhubEntry());\n\n hooks.PreToolUse = filtered;\n config.hooks = hooks as ClaudeSettings[\"hooks\"];\n\n await mkdir(dirname(settingsPath), { recursive: true, mode: 0o700 });\n const payload = `${JSON.stringify(config, null, 2)}\\n`;\n await writeFile(settingsPath, payload, { mode: 0o600 });\n // Reassert mode in case the file already existed with looser perms.\n await chmod(settingsPath, 0o600);\n}\n\nasync function writeSkillToAgent(\n agent: AgentTarget,\n skillSource: string\n): Promise<{ agent: string; path: string; status: \"written\" | \"skipped\" }> {\n await mkdir(agent.skillsDir, { recursive: true, mode: 0o755 });\n const target = join(agent.skillsDir, \"keeperhub-wallet.skill.md\");\n await copyFile(skillSource, target);\n await chmod(target, 0o644);\n return { agent: agent.agent, path: target, status: \"written\" };\n}\n\nfunction buildNoticeMessage(agent: AgentTarget): string {\n return `${agent.agent} does not support auto-registered PreToolUse hooks; run \\`${HOOK_COMMAND}\\` on every tool use via ${agent.agent}'s settings file at ${agent.settingsFile}`;\n}\n\nexport async function installSkill(\n options: InstallOptions = {}\n): Promise<InstallResult> {\n const agents = detectAgents(options.homeOverride);\n const skillSource = options.skillSourcePath ?? resolveDefaultSkillSource();\n const onNotice = options.onNotice ?? defaultNotice;\n\n const skillWrites: InstallResult[\"skillWrites\"] = [];\n const hookRegistrations: InstallResult[\"hookRegistrations\"] = [];\n\n for (const agent of agents) {\n const write = await writeSkillToAgent(agent, skillSource);\n skillWrites.push(write);\n\n if (agent.hookSupport === \"claude-code\") {\n await registerClaudeCodeHook(agent.settingsFile);\n hookRegistrations.push({\n agent: agent.agent,\n status: \"registered\",\n });\n } else {\n const message = buildNoticeMessage(agent);\n hookRegistrations.push({\n agent: agent.agent,\n status: \"notice\",\n message,\n });\n onNotice(message);\n }\n }\n\n return { skillWrites, hookRegistrations };\n}\n","// Cross-agent skill/settings directory discovery.\n//\n// Probes canonical paths under $HOME and returns one AgentTarget record per\n// agent whose parent directory exists. The `skills/` leaf may be absent --\n// installSkill() creates it.\n//\n// NOTE: `homedir()` is called per-invocation (via `homeOverride ?? homedir()`)\n// and NEVER hoisted to a module-level constant. Tests override\n// `process.env.HOME` in `beforeEach`; hoisting would freeze the harness's\n// original HOME at import time and detection would run against the real $HOME.\n\nimport { existsSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nexport type AgentTarget = {\n agent: \"claude-code\" | \"cursor\" | \"cline\" | \"windsurf\" | \"opencode\";\n skillsDir: string;\n settingsFile: string;\n hookSupport: \"claude-code\" | \"notice\";\n};\n\ntype AgentSpec = {\n agent: AgentTarget[\"agent\"];\n skillsRel: string[];\n settingsRel: string[];\n hookSupport: AgentTarget[\"hookSupport\"];\n};\n\n// Deterministic order: claude-code first (only agent with hook support),\n// then cursor, cline, windsurf, opencode.\nconst AGENT_SPECS: readonly AgentSpec[] = [\n {\n agent: \"claude-code\",\n skillsRel: [\".claude\", \"skills\"],\n settingsRel: [\".claude\", \"settings.json\"],\n hookSupport: \"claude-code\",\n },\n {\n agent: \"cursor\",\n skillsRel: [\".cursor\", \"skills\"],\n settingsRel: [\".cursor\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n {\n agent: \"cline\",\n skillsRel: [\".cline\", \"skills\"],\n settingsRel: [\".cline\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n {\n agent: \"windsurf\",\n skillsRel: [\".windsurf\", \"skills\"],\n settingsRel: [\".windsurf\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n {\n agent: \"opencode\",\n skillsRel: [\".config\", \"opencode\", \"skills\"],\n settingsRel: [\".config\", \"opencode\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n];\n\nexport function detectAgents(homeOverride?: string): AgentTarget[] {\n const home = homeOverride ?? homedir();\n const results: AgentTarget[] = [];\n for (const spec of AGENT_SPECS) {\n const skillsDir = join(home, ...spec.skillsRel);\n const settingsFile = join(home, ...spec.settingsRel);\n // \"Detected\" iff the parent of skills/ exists (e.g. ~/.claude/).\n // skills/ itself may be absent; installer creates it.\n if (existsSync(dirname(skillsDir))) {\n results.push({\n agent: spec.agent,\n skillsDir,\n settingsFile,\n hookSupport: spec.hookSupport,\n });\n }\n }\n return results;\n}\n","import { chmod, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { type WalletConfig, WalletConfigMissingError } from \"./types.js\";\n\n// NOTE: Every function calls `join(homedir(), \".keeperhub\", \"wallet.json\")`\n// itself. Do NOT hoist to a module-level `const WALLET_PATH` -- tests\n// override `process.env.HOME` in `beforeEach` and `homedir()` must re-read\n// that on each call. A hoisted constant would freeze the harness's original\n// HOME at import time and every test would write into the real\n// ~/.keeperhub/ directory.\n\nexport async function readWalletConfig(): Promise<WalletConfig> {\n const walletPath = join(homedir(), \".keeperhub\", \"wallet.json\");\n let raw: string;\n try {\n raw = await readFile(walletPath, \"utf-8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n throw new WalletConfigMissingError();\n }\n throw err;\n }\n const parsed = JSON.parse(raw) as Partial<WalletConfig>;\n if (!(parsed.subOrgId && parsed.walletAddress && parsed.hmacSecret)) {\n throw new Error(`Malformed wallet.json at ${walletPath}`);\n }\n return parsed as WalletConfig;\n}\n\nexport async function writeWalletConfig(config: WalletConfig): Promise<void> {\n const walletPath = join(homedir(), \".keeperhub\", \"wallet.json\");\n await mkdir(dirname(walletPath), { recursive: true, mode: 0o700 });\n await writeFile(walletPath, JSON.stringify(config, null, 2), { mode: 0o600 });\n // Reassert mode in case the file already existed with looser perms.\n await chmod(walletPath, 0o600);\n}\n\nexport function getWalletConfigPath(): string {\n return join(homedir(), \".keeperhub\", \"wallet.json\");\n}\n","// Shared types across the package. Phase 34.\nexport type WalletConfig = {\n /** Turnkey sub-org ID returned by POST /api/agentic-wallet/provision */\n subOrgId: string;\n /** EVM-shared wallet address (same for Base chainId 8453 and Tempo chainId 4217) */\n walletAddress: `0x${string}`;\n /** 64-char lowercase hex HMAC secret, minted server-side at provision; never logged */\n hmacSecret: string;\n};\n\nexport type HmacHeaders = {\n \"X-KH-Sub-Org\": string;\n \"X-KH-Timestamp\": string;\n \"X-KH-Signature\": string;\n};\n\nexport type HookDecision = {\n decision: \"allow\" | \"deny\" | \"ask\";\n reason?: string;\n};\n\nexport class KeeperHubError extends Error {\n readonly code: string;\n\n constructor(code: string, message: string) {\n super(message);\n this.name = \"KeeperHubError\";\n this.code = code;\n }\n}\n\nexport class WalletConfigMissingError extends Error {\n constructor() {\n super(\n \"Wallet config not found at ~/.keeperhub/wallet.json.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AAA,EACF,EACC;AAAA,IACC,IAAI,yBAAQ,SAAS,EAClB;AAAA,MACC;AAAA,IACF,EACC,OAAO,YAAY;AAClB,YAAM,SAAS,MAAM,aAAa;AAClC,iBAAW,SAAS,OAAO,aAAa;AACtC,gBAAQ,OAAO;AAAA,UACb,UAAU,MAAM,KAAK,OAAO,MAAM,IAAI,KAAK,MAAM,MAAM;AAAA;AAAA,QACzD;AAAA,MACF;AACA,iBAAW,OAAO,OAAO,mBAAmB;AAC1C,YAAI,IAAI,WAAW,cAAc;AAC/B,kBAAQ,OAAO;AAAA,YACb,SAAS,IAAI,KAAK;AAAA;AAAA,UACpB;AAAA,QACF,WAAW,IAAI,WAAW,UAAU;AAClC,kBAAQ,OAAO;AAAA,YACb,WAAW,IAAI,KAAK,OAAO,IAAI,WAAW,EAAE;AAAA;AAAA,UAC9C;AAAA,QACF;AAAA,MACF;AACA,UAAI,OAAO,YAAY,WAAW,GAAG;AACnC,gBAAQ,OAAO;AAAA,UACb;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACL;AAEF,MAAI;AACF,UAAM,QAAQ,WAAW,IAAI;AAAA,EAC/B,SAAS,KAAK;AACZ,QAAI,eAAe,0BAA0B;AAC3C,cAAQ,OAAO,MAAM,sBAAsB,IAAI,OAAO;AAAA,CAAI;AAC1D,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,YAAQ,OAAO;AAAA,MACb,sBAAuB,IAAc,WAAW,OAAO,GAAG,CAAC;AAAA;AAAA,IAC7D;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;","names":["import_viem","import_node_path","import_promises","import_node_os","import_node_path"]}
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../src/balance.ts","../src/chains.ts","../src/fund.ts","../src/skill-install.ts","../src/agent-detect.ts","../src/storage.ts","../src/types.ts"],"sourcesContent":["// CLI dispatcher for `npx @keeperhub/wallet <cmd>`. Ships 4 subcommands:\n// add (provision -- NO auth), fund (pure string-build Coinbase Onramp +\n// Tempo address), balance (Base USDC + Tempo USDC.e), info (print subOrgId\n// + walletAddress from ~/.keeperhub/wallet.json).\n//\n// v0.1.4 removed the `link` subcommand. /api/agentic-wallet/link still\n// exists server-side but the UX (copy-paste session cookie) was not fit\n// for real users; the server-approval ask tier that required linking\n// also collapsed into an inline ask in this release. See KEEP-307 and\n// KEEP-308 for the long-term design decisions.\n//\n// @security The HMAC secret written to wallet.json is NEVER printed to stdout\n// or stderr. `add` prints only subOrgId + walletAddress + the config path so\n// users can inspect perms. `info` never references the secret at all. Grep\n// rule: no process.stdout/process.stderr line in this file should include\n// wallet.hmacSecret or data.hmacSecret.\n//\n// Exit codes: 0 on success, 1 on any error (WalletConfigMissingError,\n// HTTP failure, validation error). Uncaught errors are written to stderr.\n\nimport { Command } from \"commander\";\nimport { checkBalance } from \"./balance.js\";\nimport { fund } from \"./fund.js\";\nimport { installSkill } from \"./skill-install.js\";\nimport {\n getWalletConfigPath,\n readWalletConfig,\n writeWalletConfig,\n} from \"./storage.js\";\nimport { WalletConfigMissingError } from \"./types.js\";\n\nconst TRAILING_SLASH = /\\/$/;\nconst WALLET_ADDRESS_PATTERN = /^0x[a-fA-F0-9]{40}$/;\n\nfunction resolveBaseUrl(override: string | undefined): string {\n const candidate =\n override ?? process.env.KEEPERHUB_API_URL ?? \"https://app.keeperhub.com\";\n return candidate.replace(TRAILING_SLASH, \"\");\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.length > 0;\n}\n\nfunction provisionInvalidError(\n message: string\n): Error & { code: \"PROVISION_RESPONSE_INVALID\" } {\n const err = new Error(message) as Error & {\n code: \"PROVISION_RESPONSE_INVALID\";\n };\n err.code = \"PROVISION_RESPONSE_INVALID\";\n return err;\n}\n\nfunction validateProvisionResponse(data: unknown): {\n subOrgId: string;\n walletAddress: `0x${string}`;\n hmacSecret: string;\n} {\n if (typeof data !== \"object\" || data === null) {\n throw provisionInvalidError(\"provision response is not an object\");\n }\n const { subOrgId, walletAddress, hmacSecret } = data as Record<\n string,\n unknown\n >;\n if (\n !(\n isNonEmptyString(subOrgId) &&\n isNonEmptyString(walletAddress) &&\n isNonEmptyString(hmacSecret)\n )\n ) {\n throw provisionInvalidError(\n \"provision response missing subOrgId, walletAddress, or hmacSecret\"\n );\n }\n if (!WALLET_ADDRESS_PATTERN.test(walletAddress)) {\n throw provisionInvalidError(\n `provision response walletAddress is not a valid 0x-prefixed 40-hex address: ${walletAddress}`\n );\n }\n return {\n subOrgId,\n walletAddress: walletAddress as `0x${string}`,\n hmacSecret,\n };\n}\n\nasync function cmdAdd(opts: { baseUrl?: string } = {}): Promise<void> {\n const baseUrl = resolveBaseUrl(opts.baseUrl);\n const response = await fetch(`${baseUrl}/api/agentic-wallet/provision`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: \"{}\",\n });\n if (!response.ok) {\n const text = await response.text();\n process.stderr.write(\n `[keeperhub-wallet] provision failed: HTTP ${response.status}: ${text}\\n`\n );\n process.exit(1);\n }\n const raw = (await response.json()) as unknown;\n const data = validateProvisionResponse(raw);\n await writeWalletConfig({\n subOrgId: data.subOrgId,\n walletAddress: data.walletAddress,\n hmacSecret: data.hmacSecret,\n });\n // Intentionally print only public fields. The hmacSecret is written to\n // wallet.json (chmod 0o600) but never printed -- T-34-cli-02 mitigation.\n process.stdout.write(`subOrgId: ${data.subOrgId}\\n`);\n process.stdout.write(`walletAddress: ${data.walletAddress}\\n`);\n process.stdout.write(`config written to ${getWalletConfigPath()}\\n`);\n}\n\nasync function cmdFund(): Promise<void> {\n const wallet = await readWalletConfig();\n const out = fund(wallet.walletAddress);\n process.stdout.write(`${out.coinbaseOnrampUrl}\\n`);\n process.stdout.write(`Tempo address: ${out.tempoAddress}\\n`);\n process.stdout.write(`${out.disclaimer}\\n`);\n}\n\nasync function cmdBalance(): Promise<void> {\n const wallet = await readWalletConfig();\n const snap = await checkBalance(wallet);\n process.stdout.write(`Base USDC: ${snap.base.amount}\\n`);\n process.stdout.write(`Tempo USDC.e: ${snap.tempo.amount}\\n`);\n}\n\nasync function cmdInfo(): Promise<void> {\n const wallet = await readWalletConfig();\n process.stdout.write(`subOrgId: ${wallet.subOrgId}\\n`);\n process.stdout.write(`walletAddress: ${wallet.walletAddress}\\n`);\n}\n\nexport async function runCli(argv: string[] = process.argv): Promise<void> {\n const program = new Command();\n program\n .name(\"keeperhub-wallet\")\n .description(\n \"KeeperHub agentic wallet CLI (auto-pay x402 + MPP 402 responses)\"\n )\n .version(\"0.1.3\");\n\n program\n .command(\"add\")\n .description(\"Provision a new agentic wallet (no account required)\")\n .option(\"--base-url <url>\", \"KeeperHub API base URL\")\n .action(async (opts: { baseUrl?: string }) => {\n await cmdAdd(opts);\n });\n\n program\n .command(\"fund\")\n .description(\n \"Print Coinbase Onramp URL (Base USDC) and Tempo deposit address\"\n )\n .action(async () => {\n await cmdFund();\n });\n\n program\n .command(\"balance\")\n .description(\"Print on-chain balance: Base USDC + Tempo USDC.e\")\n .action(async () => {\n await cmdBalance();\n });\n\n program\n .command(\"info\")\n .description(\"Print subOrgId and walletAddress from local config\")\n .action(async () => {\n await cmdInfo();\n });\n\n program\n .command(\"skill\")\n .description(\n \"Install the KeeperHub skill file into detected agent directories\"\n )\n .addCommand(\n new Command(\"install\")\n .description(\n \"Write skill file + register PreToolUse hook in all detected agents\"\n )\n .action(async () => {\n const result = await installSkill();\n for (const write of result.skillWrites) {\n process.stdout.write(\n `skill: ${write.agent} -> ${write.path} (${write.status})\\n`\n );\n }\n for (const reg of result.hookRegistrations) {\n if (reg.status === \"registered\") {\n process.stdout.write(\n `hook: ${reg.agent} -> PreToolUse registered\\n`\n );\n } else if (reg.status === \"notice\") {\n process.stderr.write(\n `notice: ${reg.agent} -> ${reg.message ?? \"\"}\\n`\n );\n }\n }\n if (result.skillWrites.length === 0) {\n process.stderr.write(\n \"No supported agent skill directories detected under $HOME. Create ~/.claude/, ~/.cursor/, ~/.cline/, ~/.windsurf/, or ~/.config/opencode/ and re-run.\\n\"\n );\n }\n })\n );\n\n try {\n await program.parseAsync(argv);\n } catch (err) {\n if (err instanceof WalletConfigMissingError) {\n process.stderr.write(`[keeperhub-wallet] ${err.message}\\n`);\n process.exit(1);\n }\n process.stderr.write(\n `[keeperhub-wallet] ${(err as Error).message ?? String(err)}\\n`\n );\n process.exit(1);\n }\n}\n","// checkBalance() unified view (PAY-05):\n// - Base USDC balanceOf (viem publicClient on Base)\n// - Tempo USDC.e balanceOf (viem publicClient on Tempo)\n//\n// Both legs are fetched in parallel via Promise.all. The on-chain reads\n// touch only the canonical USDC contract on their respective chains\n// (read-only ERC-20 balanceOf with no state mutation).\n//\n// The /api/agentic-wallet/credit ledger is intentionally NOT read here:\n// the server endpoint exists but no debit path is wired, so surfacing the\n// balance to users implied a capability that has not shipped. Restore the\n// leg here when KEEP-305/306 lands.\n//\n// @security balance.ts does not emit balance data to stdout/stderr via the\n// global console object or util.inspect (T-34-bal-02 mitigation). Any\n// stdout emitter added here is a privacy regression; grep-enforced in\n// acceptance criteria.\nimport {\n createPublicClient,\n erc20Abi,\n formatUnits,\n http,\n type PublicClient,\n} from \"viem\";\nimport { BASE_USDC, base, TEMPO_USDC_E, tempo } from \"./chains.js\";\nimport type { WalletConfig } from \"./types.js\";\n\n// USDC and USDC.e both use 6 decimals on Base + Tempo respectively.\nconst USDC_DECIMALS = 6;\n\nexport type BalanceSnapshot = {\n base: {\n chain: \"base\";\n token: \"USDC\";\n amount: string;\n address: `0x${string}`;\n };\n tempo: {\n chain: \"tempo\";\n token: \"USDC.e\";\n amount: string;\n address: `0x${string}`;\n };\n};\n\nexport type CheckBalanceOptions = {\n /** Injectable viem client for Base (tests mock readContract). */\n baseClient?: PublicClient;\n /** Injectable viem client for Tempo (tests mock readContract). */\n tempoClient?: PublicClient;\n};\n\n/**\n * Read the wallet's on-chain balance across Base + Tempo in parallel. Both\n * legs must resolve; any single failure rejects the Promise.\n *\n * Amounts are formatted as decimal strings (6-decimal USDC precision) so the\n * caller can render them without BigInt math.\n */\nexport async function checkBalance(\n wallet: WalletConfig,\n opts: CheckBalanceOptions = {}\n): Promise<BalanceSnapshot> {\n const baseClient =\n opts.baseClient ??\n (createPublicClient({\n chain: base,\n transport: http(),\n }) as unknown as PublicClient);\n const tempoClient =\n opts.tempoClient ??\n (createPublicClient({\n chain: tempo,\n transport: http(),\n }) as unknown as PublicClient);\n\n // Promise.all fires both reads concurrently. Total elapsed ~= max(leg)\n // rather than sum(leg); SC-3 (<2s) test asserts this.\n const [baseRaw, tempoRaw] = await Promise.all([\n baseClient.readContract({\n address: BASE_USDC,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [wallet.walletAddress],\n }) as Promise<bigint>,\n tempoClient.readContract({\n address: TEMPO_USDC_E,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [wallet.walletAddress],\n }) as Promise<bigint>,\n ]);\n\n return {\n base: {\n chain: \"base\",\n token: \"USDC\",\n amount: formatUnits(baseRaw, USDC_DECIMALS),\n address: wallet.walletAddress,\n },\n tempo: {\n chain: \"tempo\",\n token: \"USDC.e\",\n amount: formatUnits(tempoRaw, USDC_DECIMALS),\n address: wallet.walletAddress,\n },\n };\n}\n","// Sources (truth):\n// - lib/agentic-wallet/sign.ts:56 -- Base USDC at\n// 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 (chainId 8453).\n// - lib/mpp/server.ts:3 -- Tempo USDC.e at\n// 0x20c000000000000000000000b9537d11c60e8b50 (chainId 4217).\n//\n// Tempo is not in viem/chains core as of viem 2.48.1 (the version pinned in\n// this package). Define it inline via defineChain so the only dependency is\n// viem itself. TEMPO_RPC_URL overrides the default RPC for heavy readers who\n// want to point at their own node (T-34-bal-01 mitigation).\nimport { defineChain } from \"viem\";\n\nexport { base } from \"viem/chains\";\n\nexport const tempo = defineChain({\n id: 4217,\n name: \"Tempo\",\n nativeCurrency: { decimals: 18, name: \"Ether\", symbol: \"ETH\" },\n rpcUrls: {\n default: {\n http: [process.env.TEMPO_RPC_URL ?? \"https://rpc.tempo.xyz\"],\n },\n },\n blockExplorers: {\n default: { name: \"Tempo Explorer\", url: \"https://explorer.tempo.xyz\" },\n },\n});\n\n/** Circle-issued USDC on Base mainnet. */\nexport const BASE_USDC = \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\" as const;\n\n/** Bridged USDC (USDC.e) on Tempo mainnet. NOT the same contract as BASE_USDC. */\nexport const TEMPO_USDC_E =\n \"0x20c000000000000000000000b9537d11c60e8b50\" as const;\n","// Source: 34-RESEARCH Pattern 5 + Pitfall 5.\n// Coinbase deprecated the query-param pay.coinbase.com flow in favour of\n// sessionToken URLs on 2025-07-31, but the legacy endpoint still returns a\n// working Onramp page (it just may not pre-fill the asset/network/address\n// fields). We print the legacy URL for zero-dependency ergonomics and a\n// follow-up disclaimer so users know to paste manually if prefill is dropped.\n//\n// fund() is a pure string-build: no HTTP, no process spawn, no browser\n// invocation. Callers (the CLI `keeperhub-wallet fund` subcommand, the\n// `check_balance` skill in Phase 35) decide how to display the result.\n//\n// T-34-fund-01 mitigation: the host is hard-coded (pay.coinbase.com) and the\n// only user-supplied input is the wallet address, which is regex-validated\n// against the canonical 0x-prefixed 40-hex-char EVM format before any string\n// interpolation.\n\nexport type FundInstructions = {\n /** Coinbase Onramp deeplink (legacy query-param form). */\n coinbaseOnrampUrl: string;\n /** Tempo deposit address — same as the input wallet (EVM address shared). */\n tempoAddress: `0x${string}`;\n /** Plain-ASCII guidance string; no emojis (CLAUDE.md rule). */\n disclaimer: string;\n};\n\n// 0x followed by exactly 40 hex chars, case-insensitive. Kept at module scope\n// so the regex literal is compiled once (biome/ultracite useTopLevelRegex).\nconst EVM_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;\n\n// Coinbase Onramp legacy deeplink. The host + path pair is the documented\n// entry point for query-param-style Onramp sessions.\nconst COINBASE_HOST = \"pay.coinbase.com\";\nconst COINBASE_PATH = \"/buy/select-asset\";\n\n/**\n * Build Coinbase Onramp URL + Tempo deposit address for the given wallet.\n *\n * No HTTP calls are performed. The caller is expected to either print the\n * resulting URL (CLI) or render it in a chat bubble (skill). The returned\n * `disclaimer` explains the Onramp deprecation + the Tempo external-transfer\n * fallback in plain ASCII so terminal clients with ASCII-only fonts render\n * identically to emoji-capable clients.\n *\n * @throws if `walletAddress` does not match /^0x[0-9a-fA-F]{40}$/.\n */\nexport function fund(walletAddress: string): FundInstructions {\n if (!EVM_ADDRESS_RE.test(walletAddress)) {\n throw new Error(`Invalid EVM wallet address: ${walletAddress}`);\n }\n\n // addresses is a JSON-encoded map {walletAddress: [\"base\"]} per Coinbase\n // Onramp docs. Encoding into URLSearchParams guarantees the colon,\n // brackets, and quotes are percent-escaped correctly.\n const params = new URLSearchParams({\n defaultNetwork: \"base\",\n defaultAsset: \"USDC\",\n addresses: JSON.stringify({ [walletAddress]: [\"base\"] }),\n presetCryptoAmount: \"5\",\n });\n\n const coinbaseOnrampUrl = `https://${COINBASE_HOST}${COINBASE_PATH}?${params.toString()}`;\n\n const disclaimer =\n \"If the Coinbase page does not pre-fill, paste your address manually. \" +\n \"For Tempo USDC.e, transfer from an exchange or another wallet to the \" +\n \"address above -- Onramp does not support Tempo directly. Coinbase \" +\n \"sessionToken URLs are the 2025+ canonical form; legacy query-param \" +\n \"URLs may drop prefill on some accounts.\";\n\n return {\n coinbaseOnrampUrl,\n tempoAddress: walletAddress as `0x${string}`,\n disclaimer,\n };\n}\n","// Idempotent skill installer for @keeperhub/wallet.\n//\n// Two public entry points:\n// - installSkill(options?) -- writes keeperhub-wallet.skill.md into every\n// detected agent's skills directory and, for Claude Code, registers a\n// PreToolUse hook pointing at `keeperhub-wallet-hook` in\n// ~/.claude/settings.json. For non-claude agents, emits a stderr notice.\n// - registerClaudeCodeHook(settingsPath) -- pure settings.json patcher\n// used internally; exported so tests can drive it directly.\n//\n// Idempotency rule: re-running the installer MUST NOT create a duplicate\n// hook entry. We filter any existing array element whose serialised form\n// contains `keeperhub-wallet-hook` before appending a single fresh record.\n//\n// Preservation rule: all top-level keys in settings.json other than\n// hooks.PreToolUse MUST be byte-preserved. We only ever touch\n// hooks.PreToolUse; any foreign hooks.PostToolUse entries survive verbatim.\n\nimport { chmod, copyFile, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { type AgentTarget, detectAgents } from \"./agent-detect.js\";\n\nconst HOOK_COMMAND = \"keeperhub-wallet-hook\";\n// Match rule for de-dup: any existing PreToolUse entry whose JSON form\n// mentions this string is considered \"ours\" and is removed before append.\nconst KEEPERHUB_HOOK_MARKER = \"keeperhub-wallet-hook\";\n\nexport type InstallResult = {\n skillWrites: Array<{\n agent: string;\n path: string;\n status: \"written\" | \"skipped\";\n }>;\n hookRegistrations: Array<{\n agent: string;\n status: \"registered\" | \"notice\" | \"skipped\";\n message?: string;\n }>;\n};\n\nexport type InstallOptions = {\n homeOverride?: string;\n skillSourcePath?: string;\n onNotice?: (msg: string) => void;\n};\n\ntype ClaudeHookEntry = {\n matcher: string;\n hooks: Array<{ type: string; command: string }>;\n};\n\ntype ClaudeSettings = {\n hooks?: {\n PreToolUse?: unknown[];\n [k: string]: unknown;\n };\n [k: string]: unknown;\n};\n\nfunction buildKeeperhubEntry(): ClaudeHookEntry {\n return {\n matcher: \"*\",\n hooks: [{ type: \"command\", command: HOOK_COMMAND }],\n };\n}\n\nfunction resolveDefaultSkillSource(): string {\n // Resolve the module's own directory in a way that works in both ESM\n // (import.meta.url) and CJS (__dirname shim emitted by tsup). At runtime\n // the module lives inside dist/, so `../skill/` points at the sibling\n // skill/ directory shipped via pkg.files. During vitest tests the module\n // executes from src/, and `../skill/` resolves to packages/wallet/skill/.\n const here = dirname(fileURLToPath(import.meta.url));\n return join(here, \"..\", \"skill\", \"keeperhub-wallet.skill.md\");\n}\n\nfunction defaultNotice(msg: string): void {\n process.stderr.write(`${msg}\\n`);\n}\n\nexport async function registerClaudeCodeHook(\n settingsPath: string\n): Promise<void> {\n let raw: string | null = null;\n try {\n raw = await readFile(settingsPath, \"utf-8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw err;\n }\n }\n\n let config: ClaudeSettings = {};\n if (raw !== null) {\n try {\n config = JSON.parse(raw) as ClaudeSettings;\n } catch {\n throw new Error(\n `settings.json at ${settingsPath} is not valid JSON; aborting hook registration`\n );\n }\n }\n\n const hooks: Record<string, unknown> =\n typeof config.hooks === \"object\" && config.hooks !== null\n ? (config.hooks as Record<string, unknown>)\n : {};\n\n const existingPreToolUse = Array.isArray(hooks.PreToolUse)\n ? (hooks.PreToolUse as unknown[])\n : [];\n\n // De-dup: drop any element that references keeperhub-wallet-hook in its\n // serialised form. Covers both exact-shape matches and any legacy\n // representations we may have written in earlier versions.\n const filtered: unknown[] = [];\n for (const entry of existingPreToolUse) {\n const serialised = JSON.stringify(entry);\n if (!serialised.includes(KEEPERHUB_HOOK_MARKER)) {\n filtered.push(entry);\n }\n }\n filtered.push(buildKeeperhubEntry());\n\n hooks.PreToolUse = filtered;\n config.hooks = hooks as ClaudeSettings[\"hooks\"];\n\n await mkdir(dirname(settingsPath), { recursive: true, mode: 0o700 });\n const payload = `${JSON.stringify(config, null, 2)}\\n`;\n await writeFile(settingsPath, payload, { mode: 0o600 });\n // Reassert mode in case the file already existed with looser perms.\n await chmod(settingsPath, 0o600);\n}\n\nasync function writeSkillToAgent(\n agent: AgentTarget,\n skillSource: string\n): Promise<{ agent: string; path: string; status: \"written\" | \"skipped\" }> {\n await mkdir(agent.skillsDir, { recursive: true, mode: 0o755 });\n const target = join(agent.skillsDir, \"keeperhub-wallet.skill.md\");\n await copyFile(skillSource, target);\n await chmod(target, 0o644);\n return { agent: agent.agent, path: target, status: \"written\" };\n}\n\nfunction buildNoticeMessage(agent: AgentTarget): string {\n return `${agent.agent} does not support auto-registered PreToolUse hooks; run \\`${HOOK_COMMAND}\\` on every tool use via ${agent.agent}'s settings file at ${agent.settingsFile}`;\n}\n\nexport async function installSkill(\n options: InstallOptions = {}\n): Promise<InstallResult> {\n const agents = detectAgents(options.homeOverride);\n const skillSource = options.skillSourcePath ?? resolveDefaultSkillSource();\n const onNotice = options.onNotice ?? defaultNotice;\n\n const skillWrites: InstallResult[\"skillWrites\"] = [];\n const hookRegistrations: InstallResult[\"hookRegistrations\"] = [];\n\n for (const agent of agents) {\n const write = await writeSkillToAgent(agent, skillSource);\n skillWrites.push(write);\n\n if (agent.hookSupport === \"claude-code\") {\n await registerClaudeCodeHook(agent.settingsFile);\n hookRegistrations.push({\n agent: agent.agent,\n status: \"registered\",\n });\n } else {\n const message = buildNoticeMessage(agent);\n hookRegistrations.push({\n agent: agent.agent,\n status: \"notice\",\n message,\n });\n onNotice(message);\n }\n }\n\n return { skillWrites, hookRegistrations };\n}\n","// Cross-agent skill/settings directory discovery.\n//\n// Probes canonical paths under $HOME and returns one AgentTarget record per\n// agent whose parent directory exists. The `skills/` leaf may be absent --\n// installSkill() creates it.\n//\n// NOTE: `homedir()` is called per-invocation (via `homeOverride ?? homedir()`)\n// and NEVER hoisted to a module-level constant. Tests override\n// `process.env.HOME` in `beforeEach`; hoisting would freeze the harness's\n// original HOME at import time and detection would run against the real $HOME.\n\nimport { existsSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nexport type AgentTarget = {\n agent: \"claude-code\" | \"cursor\" | \"cline\" | \"windsurf\" | \"opencode\";\n skillsDir: string;\n settingsFile: string;\n hookSupport: \"claude-code\" | \"notice\";\n};\n\ntype AgentSpec = {\n agent: AgentTarget[\"agent\"];\n skillsRel: string[];\n settingsRel: string[];\n hookSupport: AgentTarget[\"hookSupport\"];\n};\n\n// Deterministic order: claude-code first (only agent with hook support),\n// then cursor, cline, windsurf, opencode.\nconst AGENT_SPECS: readonly AgentSpec[] = [\n {\n agent: \"claude-code\",\n skillsRel: [\".claude\", \"skills\"],\n settingsRel: [\".claude\", \"settings.json\"],\n hookSupport: \"claude-code\",\n },\n {\n agent: \"cursor\",\n skillsRel: [\".cursor\", \"skills\"],\n settingsRel: [\".cursor\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n {\n agent: \"cline\",\n skillsRel: [\".cline\", \"skills\"],\n settingsRel: [\".cline\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n {\n agent: \"windsurf\",\n skillsRel: [\".windsurf\", \"skills\"],\n settingsRel: [\".windsurf\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n {\n agent: \"opencode\",\n skillsRel: [\".config\", \"opencode\", \"skills\"],\n settingsRel: [\".config\", \"opencode\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n];\n\nexport function detectAgents(homeOverride?: string): AgentTarget[] {\n const home = homeOverride ?? homedir();\n const results: AgentTarget[] = [];\n for (const spec of AGENT_SPECS) {\n const skillsDir = join(home, ...spec.skillsRel);\n const settingsFile = join(home, ...spec.settingsRel);\n // \"Detected\" iff the parent of skills/ exists (e.g. ~/.claude/).\n // skills/ itself may be absent; installer creates it.\n if (existsSync(dirname(skillsDir))) {\n results.push({\n agent: spec.agent,\n skillsDir,\n settingsFile,\n hookSupport: spec.hookSupport,\n });\n }\n }\n return results;\n}\n","import { chmod, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { type WalletConfig, WalletConfigMissingError } from \"./types.js\";\n\n// NOTE: Every function calls `join(homedir(), \".keeperhub\", \"wallet.json\")`\n// itself. Do NOT hoist to a module-level `const WALLET_PATH` -- tests\n// override `process.env.HOME` in `beforeEach` and `homedir()` must re-read\n// that on each call. A hoisted constant would freeze the harness's original\n// HOME at import time and every test would write into the real\n// ~/.keeperhub/ directory.\n\nexport async function readWalletConfig(): Promise<WalletConfig> {\n const walletPath = join(homedir(), \".keeperhub\", \"wallet.json\");\n let raw: string;\n try {\n raw = await readFile(walletPath, \"utf-8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n throw new WalletConfigMissingError();\n }\n throw err;\n }\n const parsed = JSON.parse(raw) as Partial<WalletConfig>;\n if (!(parsed.subOrgId && parsed.walletAddress && parsed.hmacSecret)) {\n throw new Error(`Malformed wallet.json at ${walletPath}`);\n }\n return parsed as WalletConfig;\n}\n\nexport async function writeWalletConfig(config: WalletConfig): Promise<void> {\n const walletPath = join(homedir(), \".keeperhub\", \"wallet.json\");\n await mkdir(dirname(walletPath), { recursive: true, mode: 0o700 });\n await writeFile(walletPath, JSON.stringify(config, null, 2), { mode: 0o600 });\n // Reassert mode in case the file already existed with looser perms.\n await chmod(walletPath, 0o600);\n}\n\nexport function getWalletConfigPath(): string {\n return join(homedir(), \".keeperhub\", \"wallet.json\");\n}\n","// Shared types across the package. Phase 34.\nexport type WalletConfig = {\n /** Turnkey sub-org ID returned by POST /api/agentic-wallet/provision */\n subOrgId: string;\n /** EVM-shared wallet address (same for Base chainId 8453 and Tempo chainId 4217) */\n walletAddress: `0x${string}`;\n /** 64-char lowercase hex HMAC secret, minted server-side at provision; never logged */\n hmacSecret: string;\n};\n\nexport type HmacHeaders = {\n \"X-KH-Sub-Org\": string;\n \"X-KH-Timestamp\": string;\n \"X-KH-Signature\": string;\n};\n\nexport type HookDecision = {\n decision: \"allow\" | \"deny\" | \"ask\";\n reason?: string;\n};\n\nexport class KeeperHubError extends Error {\n readonly code: string;\n\n constructor(code: string, message: string) {\n super(message);\n this.name = \"KeeperHubError\";\n this.code = code;\n }\n}\n\nexport class WalletConfigMissingError extends Error {\n constructor() {\n super(\n \"Wallet config not found at ~/.keeperhub/wallet.json. Run `npx @keeperhub/wallet add` to provision.\"\n );\n this.name = \"WalletConfigMissingError\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBA,uBAAwB;;;ACHxB,IAAAA,eAMO;;;ACbP,kBAA4B;AAE5B,oBAAqB;AAEd,IAAM,YAAQ,yBAAY;AAAA,EAC/B,IAAI;AAAA,EACJ,MAAM;AA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AA,EAC/B,SAAS,KAAK;AACZ,QAAI,eAAe,0BAA0B;AAC3C,cAAQ,OAAO,MAAM,sBAAsB,IAAI,OAAO;AAAA,CAAI;AAC1D,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,YAAQ,OAAO;AAAA,MACb,sBAAuB,IAAc,WAAW,OAAO,GAAG,CAAC;AAAA;AAAA,IAC7D;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;","names":["import_viem","import_node_path","import_promises","import_node_os","import_node_path"]}
|
package/dist/cli.js
CHANGED
|
@@ -92,34 +92,6 @@ function fund(walletAddress) {
|
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
// src/hmac.ts
|
|
96
|
-
import { createHash, createHmac } from "crypto";
|
|
97
|
-
function computeSignature(secret, method, path, subOrgId, body, timestamp) {
|
|
98
|
-
const bodyDigest = createHash("sha256").update(body).digest("hex");
|
|
99
|
-
const signingString = `${method}
|
|
100
|
-
${path}
|
|
101
|
-
${subOrgId}
|
|
102
|
-
${bodyDigest}
|
|
103
|
-
${timestamp}`;
|
|
104
|
-
return createHmac("sha256", secret).update(signingString).digest("hex");
|
|
105
|
-
}
|
|
106
|
-
function buildHmacHeaders(secret, method, path, subOrgId, body) {
|
|
107
|
-
const timestamp = String(Math.floor(Date.now() / 1e3));
|
|
108
|
-
const signature = computeSignature(
|
|
109
|
-
secret,
|
|
110
|
-
method,
|
|
111
|
-
path,
|
|
112
|
-
subOrgId,
|
|
113
|
-
body,
|
|
114
|
-
timestamp
|
|
115
|
-
);
|
|
116
|
-
return {
|
|
117
|
-
"X-KH-Sub-Org": subOrgId,
|
|
118
|
-
"X-KH-Timestamp": timestamp,
|
|
119
|
-
"X-KH-Signature": signature
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
95
|
// src/skill-install.ts
|
|
124
96
|
import { chmod, copyFile, mkdir, readFile, writeFile } from "fs/promises";
|
|
125
97
|
import { dirname as dirname2, join as join2 } from "path";
|
|
@@ -379,47 +351,6 @@ async function cmdAdd(opts = {}) {
|
|
|
379
351
|
process.stdout.write(`config written to ${getWalletConfigPath()}
|
|
380
352
|
`);
|
|
381
353
|
}
|
|
382
|
-
async function cmdLink(opts = {}) {
|
|
383
|
-
const wallet = await readWalletConfig();
|
|
384
|
-
const baseUrl = resolveBaseUrl(opts.baseUrl);
|
|
385
|
-
const sessionCookie = process.env.KH_SESSION_COOKIE;
|
|
386
|
-
if (!sessionCookie) {
|
|
387
|
-
process.stderr.write(
|
|
388
|
-
"[keeperhub-wallet] link requires KH_SESSION_COOKIE env var.\nSign in at app.keeperhub.com, copy the session cookie, and re-run with:\n KH_SESSION_COOKIE='<cookie>' npx @keeperhub/wallet link\n"
|
|
389
|
-
);
|
|
390
|
-
process.exit(1);
|
|
391
|
-
}
|
|
392
|
-
const body = JSON.stringify({ subOrgId: wallet.subOrgId });
|
|
393
|
-
const headers = buildHmacHeaders(
|
|
394
|
-
wallet.hmacSecret,
|
|
395
|
-
"POST",
|
|
396
|
-
"/api/agentic-wallet/link",
|
|
397
|
-
wallet.subOrgId,
|
|
398
|
-
body
|
|
399
|
-
);
|
|
400
|
-
const response = await fetch(`${baseUrl}/api/agentic-wallet/link`, {
|
|
401
|
-
method: "POST",
|
|
402
|
-
headers: {
|
|
403
|
-
...headers,
|
|
404
|
-
"content-type": "application/json",
|
|
405
|
-
cookie: sessionCookie
|
|
406
|
-
},
|
|
407
|
-
body
|
|
408
|
-
});
|
|
409
|
-
const json = await response.json().catch(() => ({}));
|
|
410
|
-
if (!response.ok) {
|
|
411
|
-
process.stderr.write(
|
|
412
|
-
`[keeperhub-wallet] link failed: ${json.code ?? response.status}: ${json.error ?? ""}
|
|
413
|
-
`
|
|
414
|
-
);
|
|
415
|
-
process.exit(1);
|
|
416
|
-
}
|
|
417
|
-
if (json.already) {
|
|
418
|
-
process.stdout.write("already linked\n");
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
process.stdout.write("linked\n");
|
|
422
|
-
}
|
|
423
354
|
async function cmdFund() {
|
|
424
355
|
const wallet = await readWalletConfig();
|
|
425
356
|
const out = fund(wallet.walletAddress);
|
|
@@ -453,11 +384,6 @@ async function runCli(argv = process.argv) {
|
|
|
453
384
|
program.command("add").description("Provision a new agentic wallet (no account required)").option("--base-url <url>", "KeeperHub API base URL").action(async (opts) => {
|
|
454
385
|
await cmdAdd(opts);
|
|
455
386
|
});
|
|
456
|
-
program.command("link").description(
|
|
457
|
-
"Link the current wallet to your KeeperHub account (requires KH_SESSION_COOKIE env)"
|
|
458
|
-
).option("--base-url <url>", "KeeperHub API base URL").action(async (opts) => {
|
|
459
|
-
await cmdLink(opts);
|
|
460
|
-
});
|
|
461
387
|
program.command("fund").description(
|
|
462
388
|
"Print Coinbase Onramp URL (Base USDC) and Tempo deposit address"
|
|
463
389
|
).action(async () => {
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts","../src/balance.ts","../src/chains.ts","../src/fund.ts","../src/hmac.ts","../src/skill-install.ts","../src/agent-detect.ts","../src/storage.ts","../src/types.ts"],"sourcesContent":["// CLI dispatcher for `npx @keeperhub/wallet <cmd>`. Ships 5 subcommands:\n// add (provision -- NO auth), link (HMAC + KH_SESSION_COOKIE dual-proof),\n// fund (pure string-build Coinbase Onramp + Tempo address), balance (Base\n// USDC + Tempo USDC.e), info (print subOrgId + walletAddress from\n// ~/.keeperhub/wallet.json).\n//\n// @security The HMAC secret written to wallet.json is NEVER printed to stdout\n// or stderr. `add` prints only subOrgId + walletAddress + the config path so\n// users can inspect perms. `info` never references the secret at all. Grep\n// rule: no process.stdout/process.stderr line in this file should include\n// wallet.hmacSecret or data.hmacSecret.\n//\n// Exit codes: 0 on success, 1 on any error (WalletConfigMissingError,\n// HTTP failure, validation error). Uncaught errors are written to stderr.\n\nimport { Command } from \"commander\";\nimport { checkBalance } from \"./balance.js\";\nimport { fund } from \"./fund.js\";\nimport { buildHmacHeaders } from \"./hmac.js\";\nimport { installSkill } from \"./skill-install.js\";\nimport {\n getWalletConfigPath,\n readWalletConfig,\n writeWalletConfig,\n} from \"./storage.js\";\nimport { WalletConfigMissingError } from \"./types.js\";\n\nconst TRAILING_SLASH = /\\/$/;\nconst WALLET_ADDRESS_PATTERN = /^0x[a-fA-F0-9]{40}$/;\n\nfunction resolveBaseUrl(override: string | undefined): string {\n const candidate =\n override ?? process.env.KEEPERHUB_API_URL ?? \"https://app.keeperhub.com\";\n return candidate.replace(TRAILING_SLASH, \"\");\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.length > 0;\n}\n\nfunction provisionInvalidError(\n message: string\n): Error & { code: \"PROVISION_RESPONSE_INVALID\" } {\n const err = new Error(message) as Error & {\n code: \"PROVISION_RESPONSE_INVALID\";\n };\n err.code = \"PROVISION_RESPONSE_INVALID\";\n return err;\n}\n\nfunction validateProvisionResponse(data: unknown): {\n subOrgId: string;\n walletAddress: `0x${string}`;\n hmacSecret: string;\n} {\n if (typeof data !== \"object\" || data === null) {\n throw provisionInvalidError(\"provision response is not an object\");\n }\n const { subOrgId, walletAddress, hmacSecret } = data as Record<\n string,\n unknown\n >;\n if (\n !(\n isNonEmptyString(subOrgId) &&\n isNonEmptyString(walletAddress) &&\n isNonEmptyString(hmacSecret)\n )\n ) {\n throw provisionInvalidError(\n \"provision response missing subOrgId, walletAddress, or hmacSecret\"\n );\n }\n if (!WALLET_ADDRESS_PATTERN.test(walletAddress)) {\n throw provisionInvalidError(\n `provision response walletAddress is not a valid 0x-prefixed 40-hex address: ${walletAddress}`\n );\n }\n return {\n subOrgId,\n walletAddress: walletAddress as `0x${string}`,\n hmacSecret,\n };\n}\n\nasync function cmdAdd(opts: { baseUrl?: string } = {}): Promise<void> {\n const baseUrl = resolveBaseUrl(opts.baseUrl);\n const response = await fetch(`${baseUrl}/api/agentic-wallet/provision`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: \"{}\",\n });\n if (!response.ok) {\n const text = await response.text();\n process.stderr.write(\n `[keeperhub-wallet] provision failed: HTTP ${response.status}: ${text}\\n`\n );\n process.exit(1);\n }\n const raw = (await response.json()) as unknown;\n const data = validateProvisionResponse(raw);\n await writeWalletConfig({\n subOrgId: data.subOrgId,\n walletAddress: data.walletAddress,\n hmacSecret: data.hmacSecret,\n });\n // Intentionally print only public fields. The hmacSecret is written to\n // wallet.json (chmod 0o600) but never printed -- T-34-cli-02 mitigation.\n process.stdout.write(`subOrgId: ${data.subOrgId}\\n`);\n process.stdout.write(`walletAddress: ${data.walletAddress}\\n`);\n process.stdout.write(`config written to ${getWalletConfigPath()}\\n`);\n}\n\nasync function cmdLink(opts: { baseUrl?: string } = {}): Promise<void> {\n const wallet = await readWalletConfig();\n const baseUrl = resolveBaseUrl(opts.baseUrl);\n const sessionCookie = process.env.KH_SESSION_COOKIE;\n if (!sessionCookie) {\n process.stderr.write(\n \"[keeperhub-wallet] link requires KH_SESSION_COOKIE env var.\\n\" +\n \"Sign in at app.keeperhub.com, copy the session cookie, and re-run with:\\n\" +\n \" KH_SESSION_COOKIE='<cookie>' npx @keeperhub/wallet link\\n\"\n );\n process.exit(1);\n }\n const body = JSON.stringify({ subOrgId: wallet.subOrgId });\n const headers = buildHmacHeaders(\n wallet.hmacSecret,\n \"POST\",\n \"/api/agentic-wallet/link\",\n wallet.subOrgId,\n body\n );\n const response = await fetch(`${baseUrl}/api/agentic-wallet/link`, {\n method: \"POST\",\n headers: {\n ...headers,\n \"content-type\": \"application/json\",\n cookie: sessionCookie,\n },\n body,\n });\n const json = (await response.json().catch(() => ({}))) as {\n ok?: boolean;\n already?: boolean;\n error?: string;\n code?: string;\n };\n if (!response.ok) {\n process.stderr.write(\n `[keeperhub-wallet] link failed: ${json.code ?? response.status}: ${json.error ?? \"\"}\\n`\n );\n process.exit(1);\n }\n if (json.already) {\n process.stdout.write(\"already linked\\n\");\n return;\n }\n process.stdout.write(\"linked\\n\");\n}\n\nasync function cmdFund(): Promise<void> {\n const wallet = await readWalletConfig();\n const out = fund(wallet.walletAddress);\n process.stdout.write(`${out.coinbaseOnrampUrl}\\n`);\n process.stdout.write(`Tempo address: ${out.tempoAddress}\\n`);\n process.stdout.write(`${out.disclaimer}\\n`);\n}\n\nasync function cmdBalance(): Promise<void> {\n const wallet = await readWalletConfig();\n const snap = await checkBalance(wallet);\n process.stdout.write(`Base USDC: ${snap.base.amount}\\n`);\n process.stdout.write(`Tempo USDC.e: ${snap.tempo.amount}\\n`);\n}\n\nasync function cmdInfo(): Promise<void> {\n const wallet = await readWalletConfig();\n process.stdout.write(`subOrgId: ${wallet.subOrgId}\\n`);\n process.stdout.write(`walletAddress: ${wallet.walletAddress}\\n`);\n}\n\nexport async function runCli(argv: string[] = process.argv): Promise<void> {\n const program = new Command();\n program\n .name(\"keeperhub-wallet\")\n .description(\n \"KeeperHub agentic wallet CLI (auto-pay x402 + MPP 402 responses)\"\n )\n .version(\"0.1.3\");\n\n program\n .command(\"add\")\n .description(\"Provision a new agentic wallet (no account required)\")\n .option(\"--base-url <url>\", \"KeeperHub API base URL\")\n .action(async (opts: { baseUrl?: string }) => {\n await cmdAdd(opts);\n });\n\n program\n .command(\"link\")\n .description(\n \"Link the current wallet to your KeeperHub account (requires KH_SESSION_COOKIE env)\"\n )\n .option(\"--base-url <url>\", \"KeeperHub API base URL\")\n .action(async (opts: { baseUrl?: string }) => {\n await cmdLink(opts);\n });\n\n program\n .command(\"fund\")\n .description(\n \"Print Coinbase Onramp URL (Base USDC) and Tempo deposit address\"\n )\n .action(async () => {\n await cmdFund();\n });\n\n program\n .command(\"balance\")\n .description(\"Print on-chain balance: Base USDC + Tempo USDC.e\")\n .action(async () => {\n await cmdBalance();\n });\n\n program\n .command(\"info\")\n .description(\"Print subOrgId and walletAddress from local config\")\n .action(async () => {\n await cmdInfo();\n });\n\n program\n .command(\"skill\")\n .description(\n \"Install the KeeperHub skill file into detected agent directories\"\n )\n .addCommand(\n new Command(\"install\")\n .description(\n \"Write skill file + register PreToolUse hook in all detected agents\"\n )\n .action(async () => {\n const result = await installSkill();\n for (const write of result.skillWrites) {\n process.stdout.write(\n `skill: ${write.agent} -> ${write.path} (${write.status})\\n`\n );\n }\n for (const reg of result.hookRegistrations) {\n if (reg.status === \"registered\") {\n process.stdout.write(\n `hook: ${reg.agent} -> PreToolUse registered\\n`\n );\n } else if (reg.status === \"notice\") {\n process.stderr.write(\n `notice: ${reg.agent} -> ${reg.message ?? \"\"}\\n`\n );\n }\n }\n if (result.skillWrites.length === 0) {\n process.stderr.write(\n \"No supported agent skill directories detected under $HOME. Create ~/.claude/, ~/.cursor/, ~/.cline/, ~/.windsurf/, or ~/.config/opencode/ and re-run.\\n\"\n );\n }\n })\n );\n\n try {\n await program.parseAsync(argv);\n } catch (err) {\n if (err instanceof WalletConfigMissingError) {\n process.stderr.write(`[keeperhub-wallet] ${err.message}\\n`);\n process.exit(1);\n }\n process.stderr.write(\n `[keeperhub-wallet] ${(err as Error).message ?? String(err)}\\n`\n );\n process.exit(1);\n }\n}\n","// checkBalance() unified view (PAY-05):\n// - Base USDC balanceOf (viem publicClient on Base)\n// - Tempo USDC.e balanceOf (viem publicClient on Tempo)\n//\n// Both legs are fetched in parallel via Promise.all. The on-chain reads\n// touch only the canonical USDC contract on their respective chains\n// (read-only ERC-20 balanceOf with no state mutation).\n//\n// The /api/agentic-wallet/credit ledger is intentionally NOT read here:\n// the server endpoint exists but no debit path is wired, so surfacing the\n// balance to users implied a capability that has not shipped. Restore the\n// leg here when KEEP-305/306 lands.\n//\n// @security balance.ts does not emit balance data to stdout/stderr via the\n// global console object or util.inspect (T-34-bal-02 mitigation). Any\n// stdout emitter added here is a privacy regression; grep-enforced in\n// acceptance criteria.\nimport {\n createPublicClient,\n erc20Abi,\n formatUnits,\n http,\n type PublicClient,\n} from \"viem\";\nimport { BASE_USDC, base, TEMPO_USDC_E, tempo } from \"./chains.js\";\nimport type { WalletConfig } from \"./types.js\";\n\n// USDC and USDC.e both use 6 decimals on Base + Tempo respectively.\nconst USDC_DECIMALS = 6;\n\nexport type BalanceSnapshot = {\n base: {\n chain: \"base\";\n token: \"USDC\";\n amount: string;\n address: `0x${string}`;\n };\n tempo: {\n chain: \"tempo\";\n token: \"USDC.e\";\n amount: string;\n address: `0x${string}`;\n };\n};\n\nexport type CheckBalanceOptions = {\n /** Injectable viem client for Base (tests mock readContract). */\n baseClient?: PublicClient;\n /** Injectable viem client for Tempo (tests mock readContract). */\n tempoClient?: PublicClient;\n};\n\n/**\n * Read the wallet's on-chain balance across Base + Tempo in parallel. Both\n * legs must resolve; any single failure rejects the Promise.\n *\n * Amounts are formatted as decimal strings (6-decimal USDC precision) so the\n * caller can render them without BigInt math.\n */\nexport async function checkBalance(\n wallet: WalletConfig,\n opts: CheckBalanceOptions = {}\n): Promise<BalanceSnapshot> {\n const baseClient =\n opts.baseClient ??\n (createPublicClient({\n chain: base,\n transport: http(),\n }) as unknown as PublicClient);\n const tempoClient =\n opts.tempoClient ??\n (createPublicClient({\n chain: tempo,\n transport: http(),\n }) as unknown as PublicClient);\n\n // Promise.all fires both reads concurrently. Total elapsed ~= max(leg)\n // rather than sum(leg); SC-3 (<2s) test asserts this.\n const [baseRaw, tempoRaw] = await Promise.all([\n baseClient.readContract({\n address: BASE_USDC,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [wallet.walletAddress],\n }) as Promise<bigint>,\n tempoClient.readContract({\n address: TEMPO_USDC_E,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [wallet.walletAddress],\n }) as Promise<bigint>,\n ]);\n\n return {\n base: {\n chain: \"base\",\n token: \"USDC\",\n amount: formatUnits(baseRaw, USDC_DECIMALS),\n address: wallet.walletAddress,\n },\n tempo: {\n chain: \"tempo\",\n token: \"USDC.e\",\n amount: formatUnits(tempoRaw, USDC_DECIMALS),\n address: wallet.walletAddress,\n },\n };\n}\n","// Sources (truth):\n// - lib/agentic-wallet/sign.ts:56 -- Base USDC at\n// 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 (chainId 8453).\n// - lib/mpp/server.ts:3 -- Tempo USDC.e at\n// 0x20c000000000000000000000b9537d11c60e8b50 (chainId 4217).\n//\n// Tempo is not in viem/chains core as of viem 2.48.1 (the version pinned in\n// this package). Define it inline via defineChain so the only dependency is\n// viem itself. TEMPO_RPC_URL overrides the default RPC for heavy readers who\n// want to point at their own node (T-34-bal-01 mitigation).\nimport { defineChain } from \"viem\";\n\nexport { base } from \"viem/chains\";\n\nexport const tempo = defineChain({\n id: 4217,\n name: \"Tempo\",\n nativeCurrency: { decimals: 18, name: \"Ether\", symbol: \"ETH\" },\n rpcUrls: {\n default: {\n http: [process.env.TEMPO_RPC_URL ?? \"https://rpc.tempo.xyz\"],\n },\n },\n blockExplorers: {\n default: { name: \"Tempo Explorer\", url: \"https://explorer.tempo.xyz\" },\n },\n});\n\n/** Circle-issued USDC on Base mainnet. */\nexport const BASE_USDC = \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\" as const;\n\n/** Bridged USDC (USDC.e) on Tempo mainnet. NOT the same contract as BASE_USDC. */\nexport const TEMPO_USDC_E =\n \"0x20c000000000000000000000b9537d11c60e8b50\" as const;\n","// Source: 34-RESEARCH Pattern 5 + Pitfall 5.\n// Coinbase deprecated the query-param pay.coinbase.com flow in favour of\n// sessionToken URLs on 2025-07-31, but the legacy endpoint still returns a\n// working Onramp page (it just may not pre-fill the asset/network/address\n// fields). We print the legacy URL for zero-dependency ergonomics and a\n// follow-up disclaimer so users know to paste manually if prefill is dropped.\n//\n// fund() is a pure string-build: no HTTP, no process spawn, no browser\n// invocation. Callers (the CLI `keeperhub-wallet fund` subcommand, the\n// `check_balance` skill in Phase 35) decide how to display the result.\n//\n// T-34-fund-01 mitigation: the host is hard-coded (pay.coinbase.com) and the\n// only user-supplied input is the wallet address, which is regex-validated\n// against the canonical 0x-prefixed 40-hex-char EVM format before any string\n// interpolation.\n\nexport type FundInstructions = {\n /** Coinbase Onramp deeplink (legacy query-param form). */\n coinbaseOnrampUrl: string;\n /** Tempo deposit address — same as the input wallet (EVM address shared). */\n tempoAddress: `0x${string}`;\n /** Plain-ASCII guidance string; no emojis (CLAUDE.md rule). */\n disclaimer: string;\n};\n\n// 0x followed by exactly 40 hex chars, case-insensitive. Kept at module scope\n// so the regex literal is compiled once (biome/ultracite useTopLevelRegex).\nconst EVM_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;\n\n// Coinbase Onramp legacy deeplink. The host + path pair is the documented\n// entry point for query-param-style Onramp sessions.\nconst COINBASE_HOST = \"pay.coinbase.com\";\nconst COINBASE_PATH = \"/buy/select-asset\";\n\n/**\n * Build Coinbase Onramp URL + Tempo deposit address for the given wallet.\n *\n * No HTTP calls are performed. The caller is expected to either print the\n * resulting URL (CLI) or render it in a chat bubble (skill). The returned\n * `disclaimer` explains the Onramp deprecation + the Tempo external-transfer\n * fallback in plain ASCII so terminal clients with ASCII-only fonts render\n * identically to emoji-capable clients.\n *\n * @throws if `walletAddress` does not match /^0x[0-9a-fA-F]{40}$/.\n */\nexport function fund(walletAddress: string): FundInstructions {\n if (!EVM_ADDRESS_RE.test(walletAddress)) {\n throw new Error(`Invalid EVM wallet address: ${walletAddress}`);\n }\n\n // addresses is a JSON-encoded map {walletAddress: [\"base\"]} per Coinbase\n // Onramp docs. Encoding into URLSearchParams guarantees the colon,\n // brackets, and quotes are percent-escaped correctly.\n const params = new URLSearchParams({\n defaultNetwork: \"base\",\n defaultAsset: \"USDC\",\n addresses: JSON.stringify({ [walletAddress]: [\"base\"] }),\n presetCryptoAmount: \"5\",\n });\n\n const coinbaseOnrampUrl = `https://${COINBASE_HOST}${COINBASE_PATH}?${params.toString()}`;\n\n const disclaimer =\n \"If the Coinbase page does not pre-fill, paste your address manually. \" +\n \"For Tempo USDC.e, transfer from an exchange or another wallet to the \" +\n \"address above -- Onramp does not support Tempo directly. Coinbase \" +\n \"sessionToken URLs are the 2025+ canonical form; legacy query-param \" +\n \"URLs may drop prefill on some accounts.\";\n\n return {\n coinbaseOnrampUrl,\n tempoAddress: walletAddress as `0x${string}`,\n disclaimer,\n };\n}\n","import { createHash, createHmac } from \"node:crypto\";\nimport type { HmacHeaders } from \"./types.js\";\n\n/**\n * Mirror of lib/agentic-wallet/hmac.ts::computeSignature.\n * Format (byte-for-byte identical to server):\n * `${method}\\n${path}\\n${subOrgId}\\n${sha256_hex(body)}\\n${timestamp}`\n * Post-HI-05: subOrgId is a signed field.\n *\n * @security Do NOT log the secret or the returned signature. Any stdout\n * emitter (the global console object or util.inspect) added to this\n * file is a T-34-08 violation (grep-enforced).\n */\nexport function computeSignature(\n secret: string,\n method: string,\n path: string,\n subOrgId: string,\n body: string,\n timestamp: string\n): string {\n const bodyDigest = createHash(\"sha256\").update(body).digest(\"hex\");\n const signingString = `${method}\\n${path}\\n${subOrgId}\\n${bodyDigest}\\n${timestamp}`;\n return createHmac(\"sha256\", secret).update(signingString).digest(\"hex\");\n}\n\n/**\n * Build the three X-KH-* headers that authenticate every request to\n * /api/agentic-wallet/* (except /provision, which uses the session cookie).\n *\n * Timestamp is unix seconds (Math.floor(Date.now() / 1000)); the server\n * enforces a symmetric 300-second replay window.\n */\nexport function buildHmacHeaders(\n secret: string,\n method: string,\n path: string,\n subOrgId: string,\n body: string\n): HmacHeaders {\n const timestamp = String(Math.floor(Date.now() / 1000));\n const signature = computeSignature(\n secret,\n method,\n path,\n subOrgId,\n body,\n timestamp\n );\n return {\n \"X-KH-Sub-Org\": subOrgId,\n \"X-KH-Timestamp\": timestamp,\n \"X-KH-Signature\": signature,\n };\n}\n","// Idempotent skill installer for @keeperhub/wallet.\n//\n// Two public entry points:\n// - installSkill(options?) -- writes keeperhub-wallet.skill.md into every\n// detected agent's skills directory and, for Claude Code, registers a\n// PreToolUse hook pointing at `keeperhub-wallet-hook` in\n// ~/.claude/settings.json. For non-claude agents, emits a stderr notice.\n// - registerClaudeCodeHook(settingsPath) -- pure settings.json patcher\n// used internally; exported so tests can drive it directly.\n//\n// Idempotency rule: re-running the installer MUST NOT create a duplicate\n// hook entry. We filter any existing array element whose serialised form\n// contains `keeperhub-wallet-hook` before appending a single fresh record.\n//\n// Preservation rule: all top-level keys in settings.json other than\n// hooks.PreToolUse MUST be byte-preserved. We only ever touch\n// hooks.PreToolUse; any foreign hooks.PostToolUse entries survive verbatim.\n\nimport { chmod, copyFile, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { type AgentTarget, detectAgents } from \"./agent-detect.js\";\n\nconst HOOK_COMMAND = \"keeperhub-wallet-hook\";\n// Match rule for de-dup: any existing PreToolUse entry whose JSON form\n// mentions this string is considered \"ours\" and is removed before append.\nconst KEEPERHUB_HOOK_MARKER = \"keeperhub-wallet-hook\";\n\nexport type InstallResult = {\n skillWrites: Array<{\n agent: string;\n path: string;\n status: \"written\" | \"skipped\";\n }>;\n hookRegistrations: Array<{\n agent: string;\n status: \"registered\" | \"notice\" | \"skipped\";\n message?: string;\n }>;\n};\n\nexport type InstallOptions = {\n homeOverride?: string;\n skillSourcePath?: string;\n onNotice?: (msg: string) => void;\n};\n\ntype ClaudeHookEntry = {\n matcher: string;\n hooks: Array<{ type: string; command: string }>;\n};\n\ntype ClaudeSettings = {\n hooks?: {\n PreToolUse?: unknown[];\n [k: string]: unknown;\n };\n [k: string]: unknown;\n};\n\nfunction buildKeeperhubEntry(): ClaudeHookEntry {\n return {\n matcher: \"*\",\n hooks: [{ type: \"command\", command: HOOK_COMMAND }],\n };\n}\n\nfunction resolveDefaultSkillSource(): string {\n // Resolve the module's own directory in a way that works in both ESM\n // (import.meta.url) and CJS (__dirname shim emitted by tsup). At runtime\n // the module lives inside dist/, so `../skill/` points at the sibling\n // skill/ directory shipped via pkg.files. During vitest tests the module\n // executes from src/, and `../skill/` resolves to packages/wallet/skill/.\n const here = dirname(fileURLToPath(import.meta.url));\n return join(here, \"..\", \"skill\", \"keeperhub-wallet.skill.md\");\n}\n\nfunction defaultNotice(msg: string): void {\n process.stderr.write(`${msg}\\n`);\n}\n\nexport async function registerClaudeCodeHook(\n settingsPath: string\n): Promise<void> {\n let raw: string | null = null;\n try {\n raw = await readFile(settingsPath, \"utf-8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw err;\n }\n }\n\n let config: ClaudeSettings = {};\n if (raw !== null) {\n try {\n config = JSON.parse(raw) as ClaudeSettings;\n } catch {\n throw new Error(\n `settings.json at ${settingsPath} is not valid JSON; aborting hook registration`\n );\n }\n }\n\n const hooks: Record<string, unknown> =\n typeof config.hooks === \"object\" && config.hooks !== null\n ? (config.hooks as Record<string, unknown>)\n : {};\n\n const existingPreToolUse = Array.isArray(hooks.PreToolUse)\n ? (hooks.PreToolUse as unknown[])\n : [];\n\n // De-dup: drop any element that references keeperhub-wallet-hook in its\n // serialised form. Covers both exact-shape matches and any legacy\n // representations we may have written in earlier versions.\n const filtered: unknown[] = [];\n for (const entry of existingPreToolUse) {\n const serialised = JSON.stringify(entry);\n if (!serialised.includes(KEEPERHUB_HOOK_MARKER)) {\n filtered.push(entry);\n }\n }\n filtered.push(buildKeeperhubEntry());\n\n hooks.PreToolUse = filtered;\n config.hooks = hooks as ClaudeSettings[\"hooks\"];\n\n await mkdir(dirname(settingsPath), { recursive: true, mode: 0o700 });\n const payload = `${JSON.stringify(config, null, 2)}\\n`;\n await writeFile(settingsPath, payload, { mode: 0o600 });\n // Reassert mode in case the file already existed with looser perms.\n await chmod(settingsPath, 0o600);\n}\n\nasync function writeSkillToAgent(\n agent: AgentTarget,\n skillSource: string\n): Promise<{ agent: string; path: string; status: \"written\" | \"skipped\" }> {\n await mkdir(agent.skillsDir, { recursive: true, mode: 0o755 });\n const target = join(agent.skillsDir, \"keeperhub-wallet.skill.md\");\n await copyFile(skillSource, target);\n await chmod(target, 0o644);\n return { agent: agent.agent, path: target, status: \"written\" };\n}\n\nfunction buildNoticeMessage(agent: AgentTarget): string {\n return `${agent.agent} does not support auto-registered PreToolUse hooks; run \\`${HOOK_COMMAND}\\` on every tool use via ${agent.agent}'s settings file at ${agent.settingsFile}`;\n}\n\nexport async function installSkill(\n options: InstallOptions = {}\n): Promise<InstallResult> {\n const agents = detectAgents(options.homeOverride);\n const skillSource = options.skillSourcePath ?? resolveDefaultSkillSource();\n const onNotice = options.onNotice ?? defaultNotice;\n\n const skillWrites: InstallResult[\"skillWrites\"] = [];\n const hookRegistrations: InstallResult[\"hookRegistrations\"] = [];\n\n for (const agent of agents) {\n const write = await writeSkillToAgent(agent, skillSource);\n skillWrites.push(write);\n\n if (agent.hookSupport === \"claude-code\") {\n await registerClaudeCodeHook(agent.settingsFile);\n hookRegistrations.push({\n agent: agent.agent,\n status: \"registered\",\n });\n } else {\n const message = buildNoticeMessage(agent);\n hookRegistrations.push({\n agent: agent.agent,\n status: \"notice\",\n message,\n });\n onNotice(message);\n }\n }\n\n return { skillWrites, hookRegistrations };\n}\n","// Cross-agent skill/settings directory discovery.\n//\n// Probes canonical paths under $HOME and returns one AgentTarget record per\n// agent whose parent directory exists. The `skills/` leaf may be absent --\n// installSkill() creates it.\n//\n// NOTE: `homedir()` is called per-invocation (via `homeOverride ?? homedir()`)\n// and NEVER hoisted to a module-level constant. Tests override\n// `process.env.HOME` in `beforeEach`; hoisting would freeze the harness's\n// original HOME at import time and detection would run against the real $HOME.\n\nimport { existsSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nexport type AgentTarget = {\n agent: \"claude-code\" | \"cursor\" | \"cline\" | \"windsurf\" | \"opencode\";\n skillsDir: string;\n settingsFile: string;\n hookSupport: \"claude-code\" | \"notice\";\n};\n\ntype AgentSpec = {\n agent: AgentTarget[\"agent\"];\n skillsRel: string[];\n settingsRel: string[];\n hookSupport: AgentTarget[\"hookSupport\"];\n};\n\n// Deterministic order: claude-code first (only agent with hook support),\n// then cursor, cline, windsurf, opencode.\nconst AGENT_SPECS: readonly AgentSpec[] = [\n {\n agent: \"claude-code\",\n skillsRel: [\".claude\", \"skills\"],\n settingsRel: [\".claude\", \"settings.json\"],\n hookSupport: \"claude-code\",\n },\n {\n agent: \"cursor\",\n skillsRel: [\".cursor\", \"skills\"],\n settingsRel: [\".cursor\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n {\n agent: \"cline\",\n skillsRel: [\".cline\", \"skills\"],\n settingsRel: [\".cline\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n {\n agent: \"windsurf\",\n skillsRel: [\".windsurf\", \"skills\"],\n settingsRel: [\".windsurf\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n {\n agent: \"opencode\",\n skillsRel: [\".config\", \"opencode\", \"skills\"],\n settingsRel: [\".config\", \"opencode\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n];\n\nexport function detectAgents(homeOverride?: string): AgentTarget[] {\n const home = homeOverride ?? homedir();\n const results: AgentTarget[] = [];\n for (const spec of AGENT_SPECS) {\n const skillsDir = join(home, ...spec.skillsRel);\n const settingsFile = join(home, ...spec.settingsRel);\n // \"Detected\" iff the parent of skills/ exists (e.g. ~/.claude/).\n // skills/ itself may be absent; installer creates it.\n if (existsSync(dirname(skillsDir))) {\n results.push({\n agent: spec.agent,\n skillsDir,\n settingsFile,\n hookSupport: spec.hookSupport,\n });\n }\n }\n return results;\n}\n","import { chmod, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { type WalletConfig, WalletConfigMissingError } from \"./types.js\";\n\n// NOTE: Every function calls `join(homedir(), \".keeperhub\", \"wallet.json\")`\n// itself. Do NOT hoist to a module-level `const WALLET_PATH` -- tests\n// override `process.env.HOME` in `beforeEach` and `homedir()` must re-read\n// that on each call. A hoisted constant would freeze the harness's original\n// HOME at import time and every test would write into the real\n// ~/.keeperhub/ directory.\n\nexport async function readWalletConfig(): Promise<WalletConfig> {\n const walletPath = join(homedir(), \".keeperhub\", \"wallet.json\");\n let raw: string;\n try {\n raw = await readFile(walletPath, \"utf-8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n throw new WalletConfigMissingError();\n }\n throw err;\n }\n const parsed = JSON.parse(raw) as Partial<WalletConfig>;\n if (!(parsed.subOrgId && parsed.walletAddress && parsed.hmacSecret)) {\n throw new Error(`Malformed wallet.json at ${walletPath}`);\n }\n return parsed as WalletConfig;\n}\n\nexport async function writeWalletConfig(config: WalletConfig): Promise<void> {\n const walletPath = join(homedir(), \".keeperhub\", \"wallet.json\");\n await mkdir(dirname(walletPath), { recursive: true, mode: 0o700 });\n await writeFile(walletPath, JSON.stringify(config, null, 2), { mode: 0o600 });\n // Reassert mode in case the file already existed with looser perms.\n await chmod(walletPath, 0o600);\n}\n\nexport function getWalletConfigPath(): string {\n return join(homedir(), \".keeperhub\", \"wallet.json\");\n}\n","// Shared types across the package. Phase 34.\nexport type WalletConfig = {\n /** Turnkey sub-org ID returned by POST /api/agentic-wallet/provision */\n subOrgId: string;\n /** EVM-shared wallet address (same for Base chainId 8453 and Tempo chainId 4217) */\n walletAddress: `0x${string}`;\n /** 64-char lowercase hex HMAC secret, minted server-side at provision; never logged */\n hmacSecret: string;\n};\n\nexport type HmacHeaders = {\n \"X-KH-Sub-Org\": string;\n \"X-KH-Timestamp\": string;\n \"X-KH-Signature\": string;\n};\n\nexport type HookDecision = {\n decision: \"allow\" | \"deny\" | \"ask\";\n reason?: string;\n};\n\nexport class KeeperHubError extends Error {\n readonly code: string;\n\n constructor(code: string, message: string) {\n super(message);\n this.name = \"KeeperHubError\";\n this.code = code;\n }\n}\n\nexport class WalletConfigMissingError extends Error {\n constructor() {\n super(\n \"Wallet config not found at ~/.keeperhub/wallet.json. Run `npx @keeperhub/wallet add` to provision.\"\n );\n this.name = \"WalletConfigMissingError\";\n }\n}\n"],"mappings":";AAeA,SAAS,eAAe;;;ACExB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;ACbP,S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,EAClB;AAAA,MACC;AAAA,IACF,EACC,OAAO,YAAY;AAClB,YAAM,SAAS,MAAM,aAAa;AAClC,iBAAW,SAAS,OAAO,aAAa;AACtC,gBAAQ,OAAO;AAAA,UACb,UAAU,MAAM,KAAK,OAAO,MAAM,IAAI,KAAK,MAAM,MAAM;AAAA;AAAA,QACzD;AAAA,MACF;AACA,iBAAW,OAAO,OAAO,mBAAmB;AAC1C,YAAI,IAAI,WAAW,cAAc;AAC/B,kBAAQ,OAAO;AAAA,YACb,SAAS,IAAI,KAAK;AAAA;AAAA,UACpB;AAAA,QACF,WAAW,IAAI,WAAW,UAAU;AAClC,kBAAQ,OAAO;AAAA,YACb,WAAW,IAAI,KAAK,OAAO,IAAI,WAAW,EAAE;AAAA;AAAA,UAC9C;AAAA,QACF;AAAA,MACF;AACA,UAAI,OAAO,YAAY,WAAW,GAAG;AACnC,gBAAQ,OAAO;AAAA,UACb;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACL;AAEF,MAAI;AACF,UAAM,QAAQ,WAAW,IAAI;AAAA,EAC/B,SAAS,KAAK;AACZ,QAAI,eAAe,0BAA0B;AAC3C,cAAQ,OAAO,MAAM,sBAAsB,IAAI,OAAO;AAAA,CAAI;AAC1D,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,YAAQ,OAAO;AAAA,MACb,sBAAuB,IAAc,WAAW,OAAO,GAAG,CAAC;AAAA;AAAA,IAC7D;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;","names":["dirname","join","dirname","join","chmod","mkdir","readFile","writeFile","homedir","dirname","join","join","homedir","readFile","mkdir","dirname","writeFile","chmod"]}
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../src/balance.ts","../src/chains.ts","../src/fund.ts","../src/skill-install.ts","../src/agent-detect.ts","../src/storage.ts","../src/types.ts"],"sourcesContent":["// CLI dispatcher for `npx @keeperhub/wallet <cmd>`. Ships 4 subcommands:\n// add (provision -- NO auth), fund (pure string-build Coinbase Onramp +\n// Tempo address), balance (Base USDC + Tempo USDC.e), info (print subOrgId\n// + walletAddress from ~/.keeperhub/wallet.json).\n//\n// v0.1.4 removed the `link` subcommand. /api/agentic-wallet/link still\n// exists server-side but the UX (copy-paste session cookie) was not fit\n// for real users; the server-approval ask tier that required linking\n// also collapsed into an inline ask in this release. See KEEP-307 and\n// KEEP-308 for the long-term design decisions.\n//\n// @security The HMAC secret written to wallet.json is NEVER printed to stdout\n// or stderr. `add` prints only subOrgId + walletAddress + the config path so\n// users can inspect perms. `info` never references the secret at all. Grep\n// rule: no process.stdout/process.stderr line in this file should include\n// wallet.hmacSecret or data.hmacSecret.\n//\n// Exit codes: 0 on success, 1 on any error (WalletConfigMissingError,\n// HTTP failure, validation error). Uncaught errors are written to stderr.\n\nimport { Command } from \"commander\";\nimport { checkBalance } from \"./balance.js\";\nimport { fund } from \"./fund.js\";\nimport { installSkill } from \"./skill-install.js\";\nimport {\n getWalletConfigPath,\n readWalletConfig,\n writeWalletConfig,\n} from \"./storage.js\";\nimport { WalletConfigMissingError } from \"./types.js\";\n\nconst TRAILING_SLASH = /\\/$/;\nconst WALLET_ADDRESS_PATTERN = /^0x[a-fA-F0-9]{40}$/;\n\nfunction resolveBaseUrl(override: string | undefined): string {\n const candidate =\n override ?? process.env.KEEPERHUB_API_URL ?? \"https://app.keeperhub.com\";\n return candidate.replace(TRAILING_SLASH, \"\");\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.length > 0;\n}\n\nfunction provisionInvalidError(\n message: string\n): Error & { code: \"PROVISION_RESPONSE_INVALID\" } {\n const err = new Error(message) as Error & {\n code: \"PROVISION_RESPONSE_INVALID\";\n };\n err.code = \"PROVISION_RESPONSE_INVALID\";\n return err;\n}\n\nfunction validateProvisionResponse(data: unknown): {\n subOrgId: string;\n walletAddress: `0x${string}`;\n hmacSecret: string;\n} {\n if (typeof data !== \"object\" || data === null) {\n throw provisionInvalidError(\"provision response is not an object\");\n }\n const { subOrgId, walletAddress, hmacSecret } = data as Record<\n string,\n unknown\n >;\n if (\n !(\n isNonEmptyString(subOrgId) &&\n isNonEmptyString(walletAddress) &&\n isNonEmptyString(hmacSecret)\n )\n ) {\n throw provisionInvalidError(\n \"provision response missing subOrgId, walletAddress, or hmacSecret\"\n );\n }\n if (!WALLET_ADDRESS_PATTERN.test(walletAddress)) {\n throw provisionInvalidError(\n `provision response walletAddress is not a valid 0x-prefixed 40-hex address: ${walletAddress}`\n );\n }\n return {\n subOrgId,\n walletAddress: walletAddress as `0x${string}`,\n hmacSecret,\n };\n}\n\nasync function cmdAdd(opts: { baseUrl?: string } = {}): Promise<void> {\n const baseUrl = resolveBaseUrl(opts.baseUrl);\n const response = await fetch(`${baseUrl}/api/agentic-wallet/provision`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: \"{}\",\n });\n if (!response.ok) {\n const text = await response.text();\n process.stderr.write(\n `[keeperhub-wallet] provision failed: HTTP ${response.status}: ${text}\\n`\n );\n process.exit(1);\n }\n const raw = (await response.json()) as unknown;\n const data = validateProvisionResponse(raw);\n await writeWalletConfig({\n subOrgId: data.subOrgId,\n walletAddress: data.walletAddress,\n hmacSecret: data.hmacSecret,\n });\n // Intentionally print only public fields. The hmacSecret is written to\n // wallet.json (chmod 0o600) but never printed -- T-34-cli-02 mitigation.\n process.stdout.write(`subOrgId: ${data.subOrgId}\\n`);\n process.stdout.write(`walletAddress: ${data.walletAddress}\\n`);\n process.stdout.write(`config written to ${getWalletConfigPath()}\\n`);\n}\n\nasync function cmdFund(): Promise<void> {\n const wallet = await readWalletConfig();\n const out = fund(wallet.walletAddress);\n process.stdout.write(`${out.coinbaseOnrampUrl}\\n`);\n process.stdout.write(`Tempo address: ${out.tempoAddress}\\n`);\n process.stdout.write(`${out.disclaimer}\\n`);\n}\n\nasync function cmdBalance(): Promise<void> {\n const wallet = await readWalletConfig();\n const snap = await checkBalance(wallet);\n process.stdout.write(`Base USDC: ${snap.base.amount}\\n`);\n process.stdout.write(`Tempo USDC.e: ${snap.tempo.amount}\\n`);\n}\n\nasync function cmdInfo(): Promise<void> {\n const wallet = await readWalletConfig();\n process.stdout.write(`subOrgId: ${wallet.subOrgId}\\n`);\n process.stdout.write(`walletAddress: ${wallet.walletAddress}\\n`);\n}\n\nexport async function runCli(argv: string[] = process.argv): Promise<void> {\n const program = new Command();\n program\n .name(\"keeperhub-wallet\")\n .description(\n \"KeeperHub agentic wallet CLI (auto-pay x402 + MPP 402 responses)\"\n )\n .version(\"0.1.3\");\n\n program\n .command(\"add\")\n .description(\"Provision a new agentic wallet (no account required)\")\n .option(\"--base-url <url>\", \"KeeperHub API base URL\")\n .action(async (opts: { baseUrl?: string }) => {\n await cmdAdd(opts);\n });\n\n program\n .command(\"fund\")\n .description(\n \"Print Coinbase Onramp URL (Base USDC) and Tempo deposit address\"\n )\n .action(async () => {\n await cmdFund();\n });\n\n program\n .command(\"balance\")\n .description(\"Print on-chain balance: Base USDC + Tempo USDC.e\")\n .action(async () => {\n await cmdBalance();\n });\n\n program\n .command(\"info\")\n .description(\"Print subOrgId and walletAddress from local config\")\n .action(async () => {\n await cmdInfo();\n });\n\n program\n .command(\"skill\")\n .description(\n \"Install the KeeperHub skill file into detected agent directories\"\n )\n .addCommand(\n new Command(\"install\")\n .description(\n \"Write skill file + register PreToolUse hook in all detected agents\"\n )\n .action(async () => {\n const result = await installSkill();\n for (const write of result.skillWrites) {\n process.stdout.write(\n `skill: ${write.agent} -> ${write.path} (${write.status})\\n`\n );\n }\n for (const reg of result.hookRegistrations) {\n if (reg.status === \"registered\") {\n process.stdout.write(\n `hook: ${reg.agent} -> PreToolUse registered\\n`\n );\n } else if (reg.status === \"notice\") {\n process.stderr.write(\n `notice: ${reg.agent} -> ${reg.message ?? \"\"}\\n`\n );\n }\n }\n if (result.skillWrites.length === 0) {\n process.stderr.write(\n \"No supported agent skill directories detected under $HOME. Create ~/.claude/, ~/.cursor/, ~/.cline/, ~/.windsurf/, or ~/.config/opencode/ and re-run.\\n\"\n );\n }\n })\n );\n\n try {\n await program.parseAsync(argv);\n } catch (err) {\n if (err instanceof WalletConfigMissingError) {\n process.stderr.write(`[keeperhub-wallet] ${err.message}\\n`);\n process.exit(1);\n }\n process.stderr.write(\n `[keeperhub-wallet] ${(err as Error).message ?? String(err)}\\n`\n );\n process.exit(1);\n }\n}\n","// checkBalance() unified view (PAY-05):\n// - Base USDC balanceOf (viem publicClient on Base)\n// - Tempo USDC.e balanceOf (viem publicClient on Tempo)\n//\n// Both legs are fetched in parallel via Promise.all. The on-chain reads\n// touch only the canonical USDC contract on their respective chains\n// (read-only ERC-20 balanceOf with no state mutation).\n//\n// The /api/agentic-wallet/credit ledger is intentionally NOT read here:\n// the server endpoint exists but no debit path is wired, so surfacing the\n// balance to users implied a capability that has not shipped. Restore the\n// leg here when KEEP-305/306 lands.\n//\n// @security balance.ts does not emit balance data to stdout/stderr via the\n// global console object or util.inspect (T-34-bal-02 mitigation). Any\n// stdout emitter added here is a privacy regression; grep-enforced in\n// acceptance criteria.\nimport {\n createPublicClient,\n erc20Abi,\n formatUnits,\n http,\n type PublicClient,\n} from \"viem\";\nimport { BASE_USDC, base, TEMPO_USDC_E, tempo } from \"./chains.js\";\nimport type { WalletConfig } from \"./types.js\";\n\n// USDC and USDC.e both use 6 decimals on Base + Tempo respectively.\nconst USDC_DECIMALS = 6;\n\nexport type BalanceSnapshot = {\n base: {\n chain: \"base\";\n token: \"USDC\";\n amount: string;\n address: `0x${string}`;\n };\n tempo: {\n chain: \"tempo\";\n token: \"USDC.e\";\n amount: string;\n address: `0x${string}`;\n };\n};\n\nexport type CheckBalanceOptions = {\n /** Injectable viem client for Base (tests mock readContract). */\n baseClient?: PublicClient;\n /** Injectable viem client for Tempo (tests mock readContract). */\n tempoClient?: PublicClient;\n};\n\n/**\n * Read the wallet's on-chain balance across Base + Tempo in parallel. Both\n * legs must resolve; any single failure rejects the Promise.\n *\n * Amounts are formatted as decimal strings (6-decimal USDC precision) so the\n * caller can render them without BigInt math.\n */\nexport async function checkBalance(\n wallet: WalletConfig,\n opts: CheckBalanceOptions = {}\n): Promise<BalanceSnapshot> {\n const baseClient =\n opts.baseClient ??\n (createPublicClient({\n chain: base,\n transport: http(),\n }) as unknown as PublicClient);\n const tempoClient =\n opts.tempoClient ??\n (createPublicClient({\n chain: tempo,\n transport: http(),\n }) as unknown as PublicClient);\n\n // Promise.all fires both reads concurrently. Total elapsed ~= max(leg)\n // rather than sum(leg); SC-3 (<2s) test asserts this.\n const [baseRaw, tempoRaw] = await Promise.all([\n baseClient.readContract({\n address: BASE_USDC,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [wallet.walletAddress],\n }) as Promise<bigint>,\n tempoClient.readContract({\n address: TEMPO_USDC_E,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [wallet.walletAddress],\n }) as Promise<bigint>,\n ]);\n\n return {\n base: {\n chain: \"base\",\n token: \"USDC\",\n amount: formatUnits(baseRaw, USDC_DECIMALS),\n address: wallet.walletAddress,\n },\n tempo: {\n chain: \"tempo\",\n token: \"USDC.e\",\n amount: formatUnits(tempoRaw, USDC_DECIMALS),\n address: wallet.walletAddress,\n },\n };\n}\n","// Sources (truth):\n// - lib/agentic-wallet/sign.ts:56 -- Base USDC at\n// 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 (chainId 8453).\n// - lib/mpp/server.ts:3 -- Tempo USDC.e at\n// 0x20c000000000000000000000b9537d11c60e8b50 (chainId 4217).\n//\n// Tempo is not in viem/chains core as of viem 2.48.1 (the version pinned in\n// this package). Define it inline via defineChain so the only dependency is\n// viem itself. TEMPO_RPC_URL overrides the default RPC for heavy readers who\n// want to point at their own node (T-34-bal-01 mitigation).\nimport { defineChain } from \"viem\";\n\nexport { base } from \"viem/chains\";\n\nexport const tempo = defineChain({\n id: 4217,\n name: \"Tempo\",\n nativeCurrency: { decimals: 18, name: \"Ether\", symbol: \"ETH\" },\n rpcUrls: {\n default: {\n http: [process.env.TEMPO_RPC_URL ?? \"https://rpc.tempo.xyz\"],\n },\n },\n blockExplorers: {\n default: { name: \"Tempo Explorer\", url: \"https://explorer.tempo.xyz\" },\n },\n});\n\n/** Circle-issued USDC on Base mainnet. */\nexport const BASE_USDC = \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\" as const;\n\n/** Bridged USDC (USDC.e) on Tempo mainnet. NOT the same contract as BASE_USDC. */\nexport const TEMPO_USDC_E =\n \"0x20c000000000000000000000b9537d11c60e8b50\" as const;\n","// Source: 34-RESEARCH Pattern 5 + Pitfall 5.\n// Coinbase deprecated the query-param pay.coinbase.com flow in favour of\n// sessionToken URLs on 2025-07-31, but the legacy endpoint still returns a\n// working Onramp page (it just may not pre-fill the asset/network/address\n// fields). We print the legacy URL for zero-dependency ergonomics and a\n// follow-up disclaimer so users know to paste manually if prefill is dropped.\n//\n// fund() is a pure string-build: no HTTP, no process spawn, no browser\n// invocation. Callers (the CLI `keeperhub-wallet fund` subcommand, the\n// `check_balance` skill in Phase 35) decide how to display the result.\n//\n// T-34-fund-01 mitigation: the host is hard-coded (pay.coinbase.com) and the\n// only user-supplied input is the wallet address, which is regex-validated\n// against the canonical 0x-prefixed 40-hex-char EVM format before any string\n// interpolation.\n\nexport type FundInstructions = {\n /** Coinbase Onramp deeplink (legacy query-param form). */\n coinbaseOnrampUrl: string;\n /** Tempo deposit address — same as the input wallet (EVM address shared). */\n tempoAddress: `0x${string}`;\n /** Plain-ASCII guidance string; no emojis (CLAUDE.md rule). */\n disclaimer: string;\n};\n\n// 0x followed by exactly 40 hex chars, case-insensitive. Kept at module scope\n// so the regex literal is compiled once (biome/ultracite useTopLevelRegex).\nconst EVM_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;\n\n// Coinbase Onramp legacy deeplink. The host + path pair is the documented\n// entry point for query-param-style Onramp sessions.\nconst COINBASE_HOST = \"pay.coinbase.com\";\nconst COINBASE_PATH = \"/buy/select-asset\";\n\n/**\n * Build Coinbase Onramp URL + Tempo deposit address for the given wallet.\n *\n * No HTTP calls are performed. The caller is expected to either print the\n * resulting URL (CLI) or render it in a chat bubble (skill). The returned\n * `disclaimer` explains the Onramp deprecation + the Tempo external-transfer\n * fallback in plain ASCII so terminal clients with ASCII-only fonts render\n * identically to emoji-capable clients.\n *\n * @throws if `walletAddress` does not match /^0x[0-9a-fA-F]{40}$/.\n */\nexport function fund(walletAddress: string): FundInstructions {\n if (!EVM_ADDRESS_RE.test(walletAddress)) {\n throw new Error(`Invalid EVM wallet address: ${walletAddress}`);\n }\n\n // addresses is a JSON-encoded map {walletAddress: [\"base\"]} per Coinbase\n // Onramp docs. Encoding into URLSearchParams guarantees the colon,\n // brackets, and quotes are percent-escaped correctly.\n const params = new URLSearchParams({\n defaultNetwork: \"base\",\n defaultAsset: \"USDC\",\n addresses: JSON.stringify({ [walletAddress]: [\"base\"] }),\n presetCryptoAmount: \"5\",\n });\n\n const coinbaseOnrampUrl = `https://${COINBASE_HOST}${COINBASE_PATH}?${params.toString()}`;\n\n const disclaimer =\n \"If the Coinbase page does not pre-fill, paste your address manually. \" +\n \"For Tempo USDC.e, transfer from an exchange or another wallet to the \" +\n \"address above -- Onramp does not support Tempo directly. Coinbase \" +\n \"sessionToken URLs are the 2025+ canonical form; legacy query-param \" +\n \"URLs may drop prefill on some accounts.\";\n\n return {\n coinbaseOnrampUrl,\n tempoAddress: walletAddress as `0x${string}`,\n disclaimer,\n };\n}\n","// Idempotent skill installer for @keeperhub/wallet.\n//\n// Two public entry points:\n// - installSkill(options?) -- writes keeperhub-wallet.skill.md into every\n// detected agent's skills directory and, for Claude Code, registers a\n// PreToolUse hook pointing at `keeperhub-wallet-hook` in\n// ~/.claude/settings.json. For non-claude agents, emits a stderr notice.\n// - registerClaudeCodeHook(settingsPath) -- pure settings.json patcher\n// used internally; exported so tests can drive it directly.\n//\n// Idempotency rule: re-running the installer MUST NOT create a duplicate\n// hook entry. We filter any existing array element whose serialised form\n// contains `keeperhub-wallet-hook` before appending a single fresh record.\n//\n// Preservation rule: all top-level keys in settings.json other than\n// hooks.PreToolUse MUST be byte-preserved. We only ever touch\n// hooks.PreToolUse; any foreign hooks.PostToolUse entries survive verbatim.\n\nimport { chmod, copyFile, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { type AgentTarget, detectAgents } from \"./agent-detect.js\";\n\nconst HOOK_COMMAND = \"keeperhub-wallet-hook\";\n// Match rule for de-dup: any existing PreToolUse entry whose JSON form\n// mentions this string is considered \"ours\" and is removed before append.\nconst KEEPERHUB_HOOK_MARKER = \"keeperhub-wallet-hook\";\n\nexport type InstallResult = {\n skillWrites: Array<{\n agent: string;\n path: string;\n status: \"written\" | \"skipped\";\n }>;\n hookRegistrations: Array<{\n agent: string;\n status: \"registered\" | \"notice\" | \"skipped\";\n message?: string;\n }>;\n};\n\nexport type InstallOptions = {\n homeOverride?: string;\n skillSourcePath?: string;\n onNotice?: (msg: string) => void;\n};\n\ntype ClaudeHookEntry = {\n matcher: string;\n hooks: Array<{ type: string; command: string }>;\n};\n\ntype ClaudeSettings = {\n hooks?: {\n PreToolUse?: unknown[];\n [k: string]: unknown;\n };\n [k: string]: unknown;\n};\n\nfunction buildKeeperhubEntry(): ClaudeHookEntry {\n return {\n matcher: \"*\",\n hooks: [{ type: \"command\", command: HOOK_COMMAND }],\n };\n}\n\nfunction resolveDefaultSkillSource(): string {\n // Resolve the module's own directory in a way that works in both ESM\n // (import.meta.url) and CJS (__dirname shim emitted by tsup). At runtime\n // the module lives inside dist/, so `../skill/` points at the sibling\n // skill/ directory shipped via pkg.files. During vitest tests the module\n // executes from src/, and `../skill/` resolves to packages/wallet/skill/.\n const here = dirname(fileURLToPath(import.meta.url));\n return join(here, \"..\", \"skill\", \"keeperhub-wallet.skill.md\");\n}\n\nfunction defaultNotice(msg: string): void {\n process.stderr.write(`${msg}\\n`);\n}\n\nexport async function registerClaudeCodeHook(\n settingsPath: string\n): Promise<void> {\n let raw: string | null = null;\n try {\n raw = await readFile(settingsPath, \"utf-8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw err;\n }\n }\n\n let config: ClaudeSettings = {};\n if (raw !== null) {\n try {\n config = JSON.parse(raw) as ClaudeSettings;\n } catch {\n throw new Error(\n `settings.json at ${settingsPath} is not valid JSON; aborting hook registration`\n );\n }\n }\n\n const hooks: Record<string, unknown> =\n typeof config.hooks === \"object\" && config.hooks !== null\n ? (config.hooks as Record<string, unknown>)\n : {};\n\n const existingPreToolUse = Array.isArray(hooks.PreToolUse)\n ? (hooks.PreToolUse as unknown[])\n : [];\n\n // De-dup: drop any element that references keeperhub-wallet-hook in its\n // serialised form. Covers both exact-shape matches and any legacy\n // representations we may have written in earlier versions.\n const filtered: unknown[] = [];\n for (const entry of existingPreToolUse) {\n const serialised = JSON.stringify(entry);\n if (!serialised.includes(KEEPERHUB_HOOK_MARKER)) {\n filtered.push(entry);\n }\n }\n filtered.push(buildKeeperhubEntry());\n\n hooks.PreToolUse = filtered;\n config.hooks = hooks as ClaudeSettings[\"hooks\"];\n\n await mkdir(dirname(settingsPath), { recursive: true, mode: 0o700 });\n const payload = `${JSON.stringify(config, null, 2)}\\n`;\n await writeFile(settingsPath, payload, { mode: 0o600 });\n // Reassert mode in case the file already existed with looser perms.\n await chmod(settingsPath, 0o600);\n}\n\nasync function writeSkillToAgent(\n agent: AgentTarget,\n skillSource: string\n): Promise<{ agent: string; path: string; status: \"written\" | \"skipped\" }> {\n await mkdir(agent.skillsDir, { recursive: true, mode: 0o755 });\n const target = join(agent.skillsDir, \"keeperhub-wallet.skill.md\");\n await copyFile(skillSource, target);\n await chmod(target, 0o644);\n return { agent: agent.agent, path: target, status: \"written\" };\n}\n\nfunction buildNoticeMessage(agent: AgentTarget): string {\n return `${agent.agent} does not support auto-registered PreToolUse hooks; run \\`${HOOK_COMMAND}\\` on every tool use via ${agent.agent}'s settings file at ${agent.settingsFile}`;\n}\n\nexport async function installSkill(\n options: InstallOptions = {}\n): Promise<InstallResult> {\n const agents = detectAgents(options.homeOverride);\n const skillSource = options.skillSourcePath ?? resolveDefaultSkillSource();\n const onNotice = options.onNotice ?? defaultNotice;\n\n const skillWrites: InstallResult[\"skillWrites\"] = [];\n const hookRegistrations: InstallResult[\"hookRegistrations\"] = [];\n\n for (const agent of agents) {\n const write = await writeSkillToAgent(agent, skillSource);\n skillWrites.push(write);\n\n if (agent.hookSupport === \"claude-code\") {\n await registerClaudeCodeHook(agent.settingsFile);\n hookRegistrations.push({\n agent: agent.agent,\n status: \"registered\",\n });\n } else {\n const message = buildNoticeMessage(agent);\n hookRegistrations.push({\n agent: agent.agent,\n status: \"notice\",\n message,\n });\n onNotice(message);\n }\n }\n\n return { skillWrites, hookRegistrations };\n}\n","// Cross-agent skill/settings directory discovery.\n//\n// Probes canonical paths under $HOME and returns one AgentTarget record per\n// agent whose parent directory exists. The `skills/` leaf may be absent --\n// installSkill() creates it.\n//\n// NOTE: `homedir()` is called per-invocation (via `homeOverride ?? homedir()`)\n// and NEVER hoisted to a module-level constant. Tests override\n// `process.env.HOME` in `beforeEach`; hoisting would freeze the harness's\n// original HOME at import time and detection would run against the real $HOME.\n\nimport { existsSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nexport type AgentTarget = {\n agent: \"claude-code\" | \"cursor\" | \"cline\" | \"windsurf\" | \"opencode\";\n skillsDir: string;\n settingsFile: string;\n hookSupport: \"claude-code\" | \"notice\";\n};\n\ntype AgentSpec = {\n agent: AgentTarget[\"agent\"];\n skillsRel: string[];\n settingsRel: string[];\n hookSupport: AgentTarget[\"hookSupport\"];\n};\n\n// Deterministic order: claude-code first (only agent with hook support),\n// then cursor, cline, windsurf, opencode.\nconst AGENT_SPECS: readonly AgentSpec[] = [\n {\n agent: \"claude-code\",\n skillsRel: [\".claude\", \"skills\"],\n settingsRel: [\".claude\", \"settings.json\"],\n hookSupport: \"claude-code\",\n },\n {\n agent: \"cursor\",\n skillsRel: [\".cursor\", \"skills\"],\n settingsRel: [\".cursor\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n {\n agent: \"cline\",\n skillsRel: [\".cline\", \"skills\"],\n settingsRel: [\".cline\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n {\n agent: \"windsurf\",\n skillsRel: [\".windsurf\", \"skills\"],\n settingsRel: [\".windsurf\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n {\n agent: \"opencode\",\n skillsRel: [\".config\", \"opencode\", \"skills\"],\n settingsRel: [\".config\", \"opencode\", \"settings.json\"],\n hookSupport: \"notice\",\n },\n];\n\nexport function detectAgents(homeOverride?: string): AgentTarget[] {\n const home = homeOverride ?? homedir();\n const results: AgentTarget[] = [];\n for (const spec of AGENT_SPECS) {\n const skillsDir = join(home, ...spec.skillsRel);\n const settingsFile = join(home, ...spec.settingsRel);\n // \"Detected\" iff the parent of skills/ exists (e.g. ~/.claude/).\n // skills/ itself may be absent; installer creates it.\n if (existsSync(dirname(skillsDir))) {\n results.push({\n agent: spec.agent,\n skillsDir,\n settingsFile,\n hookSupport: spec.hookSupport,\n });\n }\n }\n return results;\n}\n","import { chmod, mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { type WalletConfig, WalletConfigMissingError } from \"./types.js\";\n\n// NOTE: Every function calls `join(homedir(), \".keeperhub\", \"wallet.json\")`\n// itself. Do NOT hoist to a module-level `const WALLET_PATH` -- tests\n// override `process.env.HOME` in `beforeEach` and `homedir()` must re-read\n// that on each call. A hoisted constant would freeze the harness's original\n// HOME at import time and every test would write into the real\n// ~/.keeperhub/ directory.\n\nexport async function readWalletConfig(): Promise<WalletConfig> {\n const walletPath = join(homedir(), \".keeperhub\", \"wallet.json\");\n let raw: string;\n try {\n raw = await readFile(walletPath, \"utf-8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n throw new WalletConfigMissingError();\n }\n throw err;\n }\n const parsed = JSON.parse(raw) as Partial<WalletConfig>;\n if (!(parsed.subOrgId && parsed.walletAddress && parsed.hmacSecret)) {\n throw new Error(`Malformed wallet.json at ${walletPath}`);\n }\n return parsed as WalletConfig;\n}\n\nexport async function writeWalletConfig(config: WalletConfig): Promise<void> {\n const walletPath = join(homedir(), \".keeperhub\", \"wallet.json\");\n await mkdir(dirname(walletPath), { recursive: true, mode: 0o700 });\n await writeFile(walletPath, JSON.stringify(config, null, 2), { mode: 0o600 });\n // Reassert mode in case the file already existed with looser perms.\n await chmod(walletPath, 0o600);\n}\n\nexport function getWalletConfigPath(): string {\n return join(homedir(), \".keeperhub\", \"wallet.json\");\n}\n","// Shared types across the package. Phase 34.\nexport type WalletConfig = {\n /** Turnkey sub-org ID returned by POST /api/agentic-wallet/provision */\n subOrgId: string;\n /** EVM-shared wallet address (same for Base chainId 8453 and Tempo chainId 4217) */\n walletAddress: `0x${string}`;\n /** 64-char lowercase hex HMAC secret, minted server-side at provision; never logged */\n hmacSecret: string;\n};\n\nexport type HmacHeaders = {\n \"X-KH-Sub-Org\": string;\n \"X-KH-Timestamp\": string;\n \"X-KH-Signature\": string;\n};\n\nexport type HookDecision = {\n decision: \"allow\" | \"deny\" | \"ask\";\n reason?: string;\n};\n\nexport class KeeperHubError extends Error {\n readonly code: string;\n\n constructor(code: string, message: string) {\n super(message);\n this.name = \"KeeperHubError\";\n this.code = code;\n }\n}\n\nexport class WalletConfigMissingError extends Error {\n constructor() {\n super(\n \"Wallet config not found at ~/.keeperhub/wallet.json. Run `npx @keeperhub/wallet add` to provision.\"\n );\n this.name = \"WalletConfigMissingError\";\n }\n}\n"],"mappings":";AAoBA,SAAS,eAAe;;;ACHxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;ACbP,SAAS,mBAAmB;AAE5B,SAAS,YAAY;AAEd,IAAM,QAAQ,YAAY;AAAA,EAC/B,IAAI;AAAA,EACJ,MAA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AAQ,OAAO;AAAA,UACb;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACL;AAEF,MAAI;AACF,UAAM,QAAQ,WAAW,IAAI;AAAA,EAC/B,SAAS,KAAK;AACZ,QAAI,eAAe,0BAA0B;AAC3C,cAAQ,OAAO,MAAM,sBAAsB,IAAI,OAAO;AAAA,CAAI;AAC1D,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,YAAQ,OAAO;AAAA,MACb,sBAAuB,IAAc,WAAW,OAAO,GAAG,CAAC;AAAA;AAAA,IAC7D;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;","names":["dirname","join","dirname","join","chmod","mkdir","readFile","writeFile","homedir","dirname","join","join","homedir","readFile","mkdir","dirname","writeFile","chmod"]}
|