diff --git a/src/cli.ts b/src/cli.ts index 2bc8406..ec94cfa 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -10,6 +10,7 @@ import { getNpubSuffix, addDaemonClient, ensureDaemonClient, + getUserNpub, } from "./utils/daemon-client"; import { getClientsList } from "./utils/clients"; import { existsSync, mkdirSync } from "fs"; @@ -909,6 +910,8 @@ npubsCmd .description("List configured admin npubs") .action(async () => { await ensureDaemonRunning(); + const config = await loadConfig(); + const userNpub = getUserNpub(config); const result = await callDaemon("/npubs"); if (result.error) { console.log(result.error); @@ -924,8 +927,18 @@ npubsCmd return; } console.log(`Admin npubs (${npubs.length}):`); + let found = false; for (const npub of npubs) { - console.log(`- ${npub}`); + const marker = npub === userNpub ? " → you" : ""; + if (npub === userNpub) found = true; + console.log(`- ${npub}${marker}`); + } + if (userNpub && !found) { + console.log(""); + console.log( + "Your npub is not in the admin list. Ask the admin to add your npub:", + ); + console.log(` ${userNpub}`); } }); diff --git a/src/utils/daemon-client.ts b/src/utils/daemon-client.ts index 0f20561..40f83c8 100644 --- a/src/utils/daemon-client.ts +++ b/src/utils/daemon-client.ts @@ -171,6 +171,16 @@ export function getNpubSuffix(config: RoutstrdConfig): string | null { } } +export function getUserNpub(config: RoutstrdConfig): string | null { + if (!config.nsec) return null; + try { + const secretKey = parseSecretKey(config.nsec); + return npubFromSecretKey(secretKey); + } catch { + return null; + } +} + export async function startDaemonProcess(): Promise { // Ensure logs directory exists (logger handles date-based files) if (!existsSync(LOGS_DIR)) {