refactor: Remove bare pubkey support for communikeys

Removes support for opening communikeys with bare pubkeys (npub/hex),
reserving that format for DMs. Communikeys now require either:
1. naddr format (kind 10222) - preferred
2. relay'pubkey format - with explicit relay hint

Changes:
- Removed bare pubkey parsing from parseIdentifier()
- Updated command reconstructor to require relay hints
- Updated getChatIdentifier to require relay URL
- Updated documentation to remove bare pubkey examples

This ensures communikeys always have relay hints for better
connectivity, while keeping bare pubkey format available for future
DM implementation.
This commit is contained in:
Claude
2026-01-16 10:55:19 +00:00
parent 5dc365e9ec
commit d20a41970b
3 changed files with 10 additions and 29 deletions

View File

@@ -139,7 +139,7 @@ function isLiveActivityMetadata(value: unknown): value is LiveActivityMetadata {
* Returns a string that can be passed to the `chat` command to open this conversation
*
* For NIP-29 groups: relay'group-id (without wss:// prefix)
* For communikeys (NIP-CC): relay'pubkey or just pubkey
* For communikeys (NIP-CC): relay'pubkey (relay hint required)
* For NIP-53 live activities: naddr1... encoding
*/
function getChatIdentifier(conversation: Conversation): string | null {
@@ -156,16 +156,12 @@ function getChatIdentifier(conversation: Conversation): string | null {
if (conversation.protocol === "communikeys") {
const pubkey = conversation.metadata?.groupId; // For communikeys, groupId is the pubkey
const relayUrl = conversation.metadata?.relayUrl;
if (!pubkey) return null;
// If there's a relay hint, include it
if (relayUrl) {
const cleanRelay = relayUrl.replace(/^wss?:\/\//, "");
return `${cleanRelay}'${pubkey}`;
}
// Communikeys require relay hints (from naddr or relay'pubkey format)
if (!pubkey || !relayUrl) return null;
// Otherwise just return the pubkey
return pubkey;
const cleanRelay = relayUrl.replace(/^wss?:\/\//, "");
return `${cleanRelay}'${pubkey}`;
}
if (conversation.protocol === "nip-53") {

View File

@@ -45,9 +45,7 @@ export class Nip29Adapter extends ChatProtocolAdapter {
* - relay.example.com'bitcoin-dev (NIP-29, wss:// prefix is optional)
* - naddr1... (kind 39000 group metadata address, NIP-29)
* - naddr1... (kind 10222 communikey definition, NIP-CC)
* - relay.example.com'npub1xxx (NIP-CC communikey)
* - npub1xxx (NIP-CC communikey, relays from kind 10222)
* - hex-pubkey (NIP-CC communikey, relays from kind 10222)
* - relay.example.com'npub1xxx (NIP-CC communikey with relay hint)
*/
parseIdentifier(input: string): ProtocolIdentifier | null {
// Try naddr format first
@@ -126,17 +124,6 @@ export class Nip29Adapter extends ChatProtocolAdapter {
};
}
// NIP-CC bare communikey format: npub1xxx or hex pubkey
// Check if input is a valid pubkey (relays will be fetched from kind 10222)
const pubkey = this.extractPubkey(input);
if (pubkey) {
return {
type: "group",
value: pubkey,
relays: [], // Will be resolved from kind 10222
};
}
return null;
}

View File

@@ -116,9 +116,9 @@ export function reconstructCommand(window: WindowInstance): string {
}
}
// NIP-CC communikeys: chat npub1... or chat relay'npub1...
// NIP-CC communikeys: chat relay'npub1... (relay hint required)
if (protocol === "communikeys" && identifier.type === "group") {
const relayUrl = identifier.relays?.[0] || "";
const relayUrl = identifier.relays?.[0];
const groupId = identifier.value; // This is a pubkey
if (relayUrl && groupId) {
@@ -127,10 +127,8 @@ export function reconstructCommand(window: WindowInstance): string {
return `chat ${cleanRelay}'${groupId}`;
}
// If no relay hint, just return the pubkey
if (groupId) {
return `chat ${groupId}`;
}
// Fallback: communikeys should always have relay hints
return "chat";
}
// NIP-53 live activities: chat naddr1...