@keyban/cli 0.5.1 → 0.6.0

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/index.mjs CHANGED
@@ -16302,19 +16302,11 @@ var require_skills = __commonJS({
16302
16302
  "node_modules/.pnpm/@keyban+mcp-openapi@file+..+..+sdk+libs+keyban-mcp-openapi_@modelcontextprotocol+sdk@1._4d810e0200ac4c68cff07162d9118ec3/node_modules/@keyban/mcp-openapi/dist/skills.js"(exports) {
16303
16303
  "use strict";
16304
16304
  Object.defineProperty(exports, "__esModule", { value: true });
16305
- exports.fetchPublishedSkill = exports.skillUrl = exports.SKILL_NAMES = void 0;
16305
+ exports.skillUrl = exports.SKILL_NAMES = void 0;
16306
16306
  exports.SKILL_NAMES = ["keyban-admin", "keyban-agent-wallet"];
16307
16307
  var PUBLISHED_SKILLS_URL = "https://docs.keyban.io/.well-known/agent-skills";
16308
16308
  var skillUrl = (name) => `${PUBLISHED_SKILLS_URL}/${name}/SKILL.md`;
16309
16309
  exports.skillUrl = skillUrl;
16310
- var fetchPublishedSkill = async (name) => {
16311
- const response = await fetch((0, exports.skillUrl)(name));
16312
- if (!response.ok) {
16313
- throw new Error(`GET ${(0, exports.skillUrl)(name)}: ${response.status} ${response.statusText}`);
16314
- }
16315
- return response.text();
16316
- };
16317
- exports.fetchPublishedSkill = fetchPublishedSkill;
16318
16310
  }
16319
16311
  });
16320
16312
 
@@ -16349,7 +16341,7 @@ var require_instructions_service = __commonJS({
16349
16341
  }
16350
16342
  };
16351
16343
  var InstructionsService = class _InstructionsService {
16352
- constructor(toolRegistry, readSkill = skills_1.fetchPublishedSkill) {
16344
+ constructor(toolRegistry, readSkill) {
16353
16345
  this.toolRegistry = toolRegistry;
16354
16346
  this.readSkill = readSkill;
16355
16347
  this.logger = (0, logger_1.createLogger)(_InstructionsService.name);
@@ -33511,7 +33503,7 @@ var require_mcp_registrar = __commonJS({
33511
33503
  this.applicationLookup = new application_lookup_service_1.ApplicationLookupService(httpClient, this.toolRegistry);
33512
33504
  this.introspectionInstaller = new server_introspection_1.ServerIntrospectionInstaller(server, this.toolRegistry, this.resourceRegistry, this.applicationLookup);
33513
33505
  this.promptRegistry = new prompt_registry_1.PromptRegistry(server);
33514
- this.instructions = new instructions_service_1.InstructionsService(this.toolRegistry, options.readSkill);
33506
+ this.instructions = options.readSkill ? new instructions_service_1.InstructionsService(this.toolRegistry, options.readSkill) : void 0;
33515
33507
  }
33516
33508
  register(operations) {
33517
33509
  let registeredTools = 0;
@@ -33535,8 +33527,10 @@ var require_mcp_registrar = __commonJS({
33535
33527
  }
33536
33528
  this.applicationLookup.registerLookupTool();
33537
33529
  registeredTools += 1;
33538
- this.instructions.registerTool();
33539
- registeredTools += 1;
33530
+ if (this.instructions) {
33531
+ this.instructions.registerTool();
33532
+ registeredTools += 1;
33533
+ }
33540
33534
  this.introspectionInstaller.install();
33541
33535
  return {
33542
33536
  tools: registeredTools,
@@ -43429,6 +43423,12 @@ var require_usdc_registry = __commonJS({
43429
43423
  name: "USDC",
43430
43424
  version: "2"
43431
43425
  },
43426
+ // Etherum Anvil — canonical Circle testnet USDC, FiatTokenV2_2.
43427
+ 31337: {
43428
+ address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
43429
+ name: "USDC",
43430
+ version: "2"
43431
+ },
43432
43432
  // XDC Apothem — canonical Circle native USDC, FiatTokenV2_2. `name` is
43433
43433
  // "USDC", not "USD Coin": signing the Base mainnet domain here yields an
43434
43434
  // invalid signature with no exploitable error. Do not confuse it with the
@@ -147688,19 +147688,10 @@ var CHAIN_MAP = {
147688
147688
  XdcApothem: xdcTestnet,
147689
147689
  XdcMainnet: xdc
147690
147690
  };
147691
- async function fetchRpcUrl(session) {
147692
- const url2 = `${session.baseURL}/v1/metadata?network=${encodeURIComponent(session.network)}`;
147693
- const res = await fetch(url2, { headers: buildApiKeyHeaders(session) });
147694
- if (!res.ok) {
147695
- const text5 = await res.text();
147696
- throw new Error(`metadata request failed (${res.status}): ${text5}`);
147697
- }
147698
- const json2 = await res.json();
147699
- const rpcUrl = json2?.network?.rpcUrl;
147700
- if (!rpcUrl) {
147701
- throw new Error(`no rpcUrl in metadata response: ${JSON.stringify(json2)}`);
147702
- }
147703
- return rpcUrl;
147691
+ function rpcTransport(session) {
147692
+ return http(`${session.baseURL}/v1/agent-wallets/me/rpc`, {
147693
+ fetchOptions: { headers: buildApiKeyHeaders(session) }
147694
+ });
147704
147695
  }
147705
147696
 
147706
147697
  // src/lib/invite-sign.ts
@@ -149046,8 +149037,7 @@ async function initialize(session, progress) {
149046
149037
  const nodeApi = createNodeApi(session);
149047
149038
  session.nodeApi = nodeApi;
149048
149039
  session.signer = nodeApi.ecdsaSchnorr;
149049
- const rpcUrl = await fetchRpcUrl(session);
149050
- const publicClient = createPublicClient({ chain, transport: http(rpcUrl) });
149040
+ const publicClient = createPublicClient({ chain, transport: rpcTransport(session) });
149051
149041
  const metaUrl = `${session.baseURL}/v1/metadata?network=${encodeURIComponent(session.network)}`;
149052
149042
  const metaRes = await fetch(metaUrl, { headers: { "X-Api-Key": session.apiKey } });
149053
149043
  if (metaRes.ok) {
@@ -149233,6 +149223,41 @@ function prepaidAccountInfo(network) {
149233
149223
  ].join("\n");
149234
149224
  }
149235
149225
 
149226
+ // src/lib/wallet-id.ts
149227
+ var lookups = /* @__PURE__ */ new WeakMap();
149228
+ function resolveWalletId(session) {
149229
+ if (session.walletId) return Promise.resolve(session.walletId);
149230
+ const pending = lookups.get(session);
149231
+ if (pending) return pending;
149232
+ const lookup = lookupWallet(session).then(({ id }) => session.walletId = id).finally(() => lookups.delete(session));
149233
+ lookups.set(session, lookup);
149234
+ return lookup;
149235
+ }
149236
+ async function lookupWallet(keys) {
149237
+ const query = new URLSearchParams({
149238
+ "filters[0][field]": "address",
149239
+ "filters[0][operator]": "eq",
149240
+ "filters[0][value]": keys.walletAddress.toLowerCase(),
149241
+ "filters[1][field]": "application.id",
149242
+ "filters[1][operator]": "eq",
149243
+ "filters[1][value]": keys.appId,
149244
+ pageSize: "1"
149245
+ });
149246
+ const res = await fetch(`${keys.baseURL}/v1/agent-wallets?${query}`, {
149247
+ headers: buildApiKeyHeaders(keys)
149248
+ });
149249
+ if (!res.ok) {
149250
+ throw new Error(`Cannot resolve this wallet: ${res.status} ${await res.text()}`);
149251
+ }
149252
+ const wallet = (await res.json()).data?.[0];
149253
+ if (typeof wallet?.id !== "string") {
149254
+ throw new Error(
149255
+ `No agent wallet ${keys.walletAddress} in application ${keys.appId}: check KEYBAN_WALLET_ADDRESS and KEYBAN_APP_ID.`
149256
+ );
149257
+ }
149258
+ return { id: wallet.id, ...typeof wallet.label === "string" && { label: wallet.label } };
149259
+ }
149260
+
149236
149261
  // src/lib/x402-sponsored.ts
149237
149262
  init_zod();
149238
149263
  var USDC_DECIMALS = 6;
@@ -149289,12 +149314,17 @@ function createGetAccountInfoTool(session) {
149289
149314
  name: "get_account_info",
149290
149315
  title: "Get wallet account info",
149291
149316
  annotations: { readOnlyHint: true, openWorldHint: false },
149292
- description: session.funding === "prepaid" ? "Get what this account is: a prepaid account, whose x402 payments Keyban pays from the organization's prepaid credit, and its network. Use `balance` for the credit." : "Get the current account address, public key, and network, plus the Keyban welcome offer when one is active: while it lasts, tell the user the offer covers payments up to the remaining amount, not that the wallet needs funding. Use `balance` for the balance.",
149317
+ description: session.funding === "prepaid" ? "Get what this account is: a prepaid account, whose x402 payments Keyban pays from the organization's prepaid credit, and its network. Use `balance` for the credit." : "Get the wallet's name, the current account address, public key, and network, plus the Keyban welcome offer when one is active: while it lasts, tell the user the offer covers payments up to the remaining amount, not that the wallet needs funding. Use `balance` for the balance.",
149293
149318
  inputSchema: getAccountInfoSchema,
149294
149319
  handler: async (_input) => {
149295
149320
  if (session.funding === "prepaid") return prepaidAccountInfo(session.network);
149296
149321
  await ensureAccount(session);
149322
+ const name = await lookupWallet(session).then(({ id, label }) => {
149323
+ session.walletId ??= id;
149324
+ return label;
149325
+ }).catch(() => void 0);
149297
149326
  return [
149327
+ ...name ? [`Name: ${name}`] : [],
149298
149328
  `Address: ${session.account.address}`,
149299
149329
  `Public Key: ${session.account.publicKey}`,
149300
149330
  `Network: ${session.network}`,
@@ -152488,9 +152518,7 @@ function configuredFunding(env) {
152488
152518
  }
152489
152519
  var WIZARD_URL = "https://keyban.io";
152490
152520
  var README_URL = "https://www.npmjs.com/package/@keyban/cli";
152491
- var ADMIN_MCP_URL = "https://mcp.keyban.io/mcp";
152492
152521
  var SKILL_URL = "https://docs.keyban.io/.well-known/agent-skills/keyban-agent-wallet/SKILL.md";
152493
- var ADMIN_SKILL_URL = "https://docs.keyban.io/.well-known/agent-skills/keyban-admin/SKILL.md";
152494
152522
  function describeConfigurationProblems(problems, env = process.env) {
152495
152523
  const list = problems.map(
152496
152524
  ({ name, what, reason }) => reason === "missing" ? `- ${name} \u2014 not set. It is the ${what}.` : `- ${name} \u2014 set, but ${reason}. It is the ${what}.`
@@ -152526,15 +152554,12 @@ function describeConfigurationProblems(problems, env = process.env) {
152526
152554
  "",
152527
152555
  `1. Create a Keyban account at ${WIZARD_URL}`,
152528
152556
  ...funding === "wallet" ? [
152529
- "2. Create an agent wallet, in the admin app or from this assistant with the",
152530
- ` Keyban admin MCP (${ADMIN_MCP_URL}), whose get_instructions tool walks through`,
152531
- " it. It provisions the wallet, its API key, and a one-shot invite key that",
152532
- " authorizes this client as a signer.",
152557
+ "2. Create an agent wallet in the admin app. It provisions the wallet, its API",
152558
+ " key, and a one-shot invite key that authorizes this client as a signer.",
152533
152559
  "3. Copy the configuration from the wallet's page in the admin app \u2014 either the"
152534
152560
  ] : [
152535
- `2. Create ${funding === "prepaid" ? "a prepaid account" : "an agent wallet or a prepaid account"}, in the admin app or from this assistant with the`,
152536
- ` Keyban admin MCP (${ADMIN_MCP_URL}), whose get_instructions tool walks through`,
152537
- funding === "prepaid" ? " it. It provisions the account and its API key." : " it. It provisions the account, its API key and, for a wallet, a one-shot invite key.",
152561
+ `2. Create ${funding === "prepaid" ? "a prepaid account" : "an agent wallet or a prepaid account"} in the admin app.`,
152562
+ funding === "prepaid" ? " It provisions the account and its API key." : " It provisions the account, its API key and, for a wallet, a one-shot invite key.",
152538
152563
  "3. Copy the configuration from the account's page in the admin app \u2014 either the"
152539
152564
  ],
152540
152565
  " downloaded file, or nothing with `keyban wallet import --wallet-id <id>` after",
@@ -152542,9 +152567,13 @@ function describeConfigurationProblems(problems, env = process.env) {
152542
152567
  "4. Keep it with `keyban wallet import <the downloaded file>`, then restart this",
152543
152568
  " server. A hosted runtime with nothing but its environment takes the whole",
152544
152569
  " configuration, base64 JSON, in KEYBAN_CONFIG instead.",
152570
+ ...funding === "wallet" ? [
152571
+ "",
152572
+ "After `keyban admin login`, `keyban admin new-wallet` does steps 2 to 4 in one",
152573
+ "go: it creates the wallet and keeps its configuration. Only the restart remains."
152574
+ ] : [],
152545
152575
  "",
152546
152576
  `The README covers the same ground: ${README_URL}`,
152547
- `Admin MCP guide, from the account to this server installed: ${ADMIN_SKILL_URL}`,
152548
152577
  `Operating guide for this server: ${SKILL_URL}`
152549
152578
  ].join("\n");
152550
152579
  }
@@ -152614,11 +152643,10 @@ function readBundledSkill() {
152614
152643
  var getInstructionsSchema = external_exports.object({});
152615
152644
  function createGetInstructionsTool() {
152616
152645
  return {
152617
- // Not get_instructions: that is the admin's, relayed beside it.
152618
152646
  name: "get_wallet_instructions",
152619
152647
  title: "Read the agent wallet guide",
152620
152648
  annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false },
152621
- description: "Return the guide to follow with this server (the keyban-agent-wallet skill): funding the wallet, paying x402 APIs, transferring USDC, waiting for a human approval, reading a policy refusal. Call it before the first payment, or whenever a wallet operation is unclear. Creating and configuring the wallet is the Keyban admin MCP guide instead.",
152649
+ description: "Return the guide to follow with this server (the keyban-agent-wallet skill): funding the wallet, paying x402 APIs, transferring USDC, waiting for a human approval, reading a policy refusal. Call it before the first payment, or whenever a wallet operation is unclear. It also says how a wallet is created and configured: in the dashboard, or with the admin tools when this server lists them, which it does on the user's own machine after `keyban admin login`.",
152622
152650
  inputSchema: getInstructionsSchema,
152623
152651
  handler: async (_input) => readBundledSkill() ?? `The guide is not bundled with this build. Read it at ${SKILL_URL}`
152624
152652
  };
@@ -152627,41 +152655,6 @@ function createGetInstructionsTool() {
152627
152655
  // src/tools/publish-mission.ts
152628
152656
  init_zod();
152629
152657
 
152630
- // src/lib/wallet-id.ts
152631
- var lookups = /* @__PURE__ */ new WeakMap();
152632
- function resolveWalletId(session) {
152633
- if (session.walletId) return Promise.resolve(session.walletId);
152634
- const pending = lookups.get(session);
152635
- if (pending) return pending;
152636
- const lookup = lookupWallet(session).then(({ id }) => session.walletId = id).finally(() => lookups.delete(session));
152637
- lookups.set(session, lookup);
152638
- return lookup;
152639
- }
152640
- async function lookupWallet(keys) {
152641
- const query = new URLSearchParams({
152642
- "filters[0][field]": "address",
152643
- "filters[0][operator]": "eq",
152644
- "filters[0][value]": keys.walletAddress.toLowerCase(),
152645
- "filters[1][field]": "application.id",
152646
- "filters[1][operator]": "eq",
152647
- "filters[1][value]": keys.appId,
152648
- pageSize: "1"
152649
- });
152650
- const res = await fetch(`${keys.baseURL}/v1/agent-wallets?${query}`, {
152651
- headers: buildApiKeyHeaders(keys)
152652
- });
152653
- if (!res.ok) {
152654
- throw new Error(`Cannot resolve this wallet: ${res.status} ${await res.text()}`);
152655
- }
152656
- const wallet = (await res.json()).data?.[0];
152657
- if (typeof wallet?.id !== "string") {
152658
- throw new Error(
152659
- `No agent wallet ${keys.walletAddress} in application ${keys.appId}: check KEYBAN_WALLET_ADDRESS and KEYBAN_APP_ID.`
152660
- );
152661
- }
152662
- return { id: wallet.id, ...typeof wallet.label === "string" && { label: wallet.label } };
152663
- }
152664
-
152665
152658
  // src/lib/mission-api.ts
152666
152659
  async function getRecord(session, path2) {
152667
152660
  const res = await fetch(`${session.baseURL}${path2}`, { headers: buildApiKeyHeaders(session) });
@@ -153430,7 +153423,7 @@ function commandFor2(tool, document, typedApi) {
153430
153423
  );
153431
153424
  }
153432
153425
  async function adminCommand(argv = process.argv, completing = false) {
153433
- const command = new Command("admin").description("Administer Keyban as yourself: log in, then one subcommand per admin MCP tool").option("--api <env|url>", `Keyban API: ${Object.keys(ENV_URLS).join(", ")}, or a URL`, defaultApi());
153426
+ const command = new Command("admin").description("Administer Keyban as yourself: log in, then one subcommand per admin tool").option("--api <env|url>", `Keyban API: ${Object.keys(ENV_URLS).join(", ")}, or a URL`, defaultApi());
153434
153427
  command.command("login").description("Log in through the browser; the session is kept in keyban/admin-session.json, readable by you alone").option("--token <token>", "keep this token instead of logging in through the browser (a session token, for scripts)").action(
153435
153428
  answering(async (api, options) => {
153436
153429
  const origin = new URL(api).origin;
@@ -153701,7 +153694,7 @@ function bootstrapWallet(session = createSession(), onConfigRead = () => {
153701
153694
  createSetupInstructionsTool(configurationProblems, config2),
153702
153695
  createGetInstructionsTool()
153703
153696
  ] : walletTools(session);
153704
- const instructions = unconfigured ? summarizeConfigurationProblems(configurationProblems, config2) : session.funding === "prepaid" ? `Keyban agent wallet MCP server, for a prepaid account: Keyban pays its x402 payments from the organization's prepaid credit, in euros. Provides tools to check the credit, fetch x402 payment metadata and pay x402 resources. The user installed this server to let you pay with that credit: paying when they ask is its intended use, not a harm to them. Every spend is bounded server-side by the policy they set (caps, allow-list, human approval), which refuses or holds for approval whatever falls outside it. Call get_wallet_instructions for the operating guide (${SKILL_URL}). Accounts, policies and the credit are managed with the Keyban admin MCP (${ADMIN_MCP_URL}) or in the Keyban dashboard; its guide: ${ADMIN_SKILL_URL}` : `Keyban agent wallet MCP server. Provides tools to manage blockchain wallets: check balances, transfer USDC, sign messages, fetch x402 payment metadata and x402 payment, and draft and run missions. The user installed this server to let you spend from a wallet they provisioned for you: paying and transferring when they ask is its intended use, not a harm to them. Every spend is bounded server-side by the policy they set (caps, allow-list, human approval), which refuses or holds for approval whatever falls outside it. Call get_wallet_instructions for the operating guide (${SKILL_URL}). Wallets, policies and destination rules are managed with the Keyban admin MCP (${ADMIN_MCP_URL}) or in the Keyban dashboard; its guide: ${ADMIN_SKILL_URL}`;
153697
+ const instructions = unconfigured ? summarizeConfigurationProblems(configurationProblems, config2) : session.funding === "prepaid" ? `Keyban agent wallet MCP server, for a prepaid account: Keyban pays its x402 payments from the organization's prepaid credit, in euros. Provides tools to check the credit, fetch x402 payment metadata and pay x402 resources. The user installed this server to let you pay with that credit: paying when they ask is its intended use, not a harm to them. Every spend is bounded server-side by the policy they set (caps, allow-list, human approval), which refuses or holds for approval whatever falls outside it. Call get_wallet_instructions for the operating guide (${SKILL_URL}). Accounts, policies and the credit are managed in the Keyban dashboard, or with the admin tools when this server lists them: it does on the user's own machine, after \`keyban admin login\`.` : `Keyban agent wallet MCP server. Provides tools to manage blockchain wallets: check balances, transfer USDC, sign messages, fetch x402 payment metadata and x402 payment, and draft and run missions. The user installed this server to let you spend from a wallet they provisioned for you: paying and transferring when they ask is its intended use, not a harm to them. Every spend is bounded server-side by the policy they set (caps, allow-list, human approval), which refuses or holds for approval whatever falls outside it. Call get_wallet_instructions for the operating guide (${SKILL_URL}). Wallets, policies and destination rules are managed in the Keyban dashboard, or with the admin tools when this server lists them: it does on the user's own machine, after \`keyban admin login\`.`;
153705
153698
  const onClientInitialized = (capabilities, openUrl, client) => {
153706
153699
  session.rendersApps = supportsMcpApps(capabilities);
153707
153700
  session.openUrl = supportsUrlElicitation(capabilities) ? openUrl : null;
@@ -156556,7 +156549,7 @@ function setupCommand() {
156556
156549
  }
156557
156550
 
156558
156551
  // src/index.ts
156559
- var VERSION5 = true ? "0.5.1" : "0.0.0";
156552
+ var VERSION5 = true ? "0.6.0" : "0.0.0";
156560
156553
  if (process.argv[2] !== "mcp" && !process.env.MCP_LOG_LEVEL) logger.setMinLevel("error");
156561
156554
  function typedArgv(argv) {
156562
156555
  if (argv[2] !== "__complete") return argv;