diff --git a/NOSTR_GIT.md b/NOSTR_GIT.md index ff5599b0..82f538c0 100644 --- a/NOSTR_GIT.md +++ b/NOSTR_GIT.md @@ -21,10 +21,14 @@ Nostr git repositories use a special URL format: nostr:/// ``` -- ``: The repository maintainer's Nostr public key (hex format) +- ``: The repository maintainer's Nostr public key (hex format or npub) - ``: The repository identifier (d tag, usually kebab-case) -Example: `nostr://abc123.../my-project` +**Important**: The system expects hex pubkeys but will automatically convert npub to hex if provided. + +Examples: +- `nostr://abc123def456.../my-project` (hex pubkey) +- `nostr://npub1abc123.../my-project` (will be converted to hex) ### 2. Creating Patches (Pull Requests) @@ -68,13 +72,13 @@ Nostr git is implemented as a `NostrGitProvider` that implements the `GitHostPro class NostrGitProvider implements GitHostProvider { // Query repository announcements (kind 30617) async getRepository(owner: string, repo: string): Promise - + // Check if user is a maintainer async canUserPush(owner: string, repo: string): Promise - + // Create patch event (kind 1617) async createPullRequest(options: CreatePullRequestOptions): Promise - + // ... other methods } ``` diff --git a/src/components/GitDialog.tsx b/src/components/GitDialog.tsx index 80791e7e..7431e436 100644 --- a/src/components/GitDialog.tsx +++ b/src/components/GitDialog.tsx @@ -424,7 +424,8 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog }); // Set origin remote to Nostr URL - const nostrUrl = `nostr://${nip19.npubEncode(user.pubkey)}/git.shakespeare.diy/${projectId}`; + // Format: nostr:/// + const nostrUrl = `nostr://${user.pubkey}/${projectId}`; try { // Remove existing origin if it exists diff --git a/src/components/git/PullRequestDialog.tsx b/src/components/git/PullRequestDialog.tsx index ebe3556e..70b2ad4a 100644 --- a/src/components/git/PullRequestDialog.tsx +++ b/src/components/git/PullRequestDialog.tsx @@ -38,6 +38,7 @@ import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useNostr } from '@/hooks/useNostr'; import { findCredentialsForRepo } from '@/lib/gitCredentials'; import { createGitHostProvider, detectGitHost, parseRepoUrl } from '@/lib/git-hosts'; +import { nip19 } from 'nostr-tools'; interface PullRequestDialogProps { projectId: string; @@ -207,8 +208,27 @@ export function PullRequestDialog({ if (url.startsWith('nostr://')) { match = url.match(/^nostr:\/\/([^/]+)\/(.+)$/); if (match) { - owner = match[1]; // pubkey in hex + let pubkeyOrNpub = match[1]; repo = match[2]; // repo-id (d tag) + + // Convert npub to hex if needed + if (pubkeyOrNpub.startsWith('npub1')) { + try { + const decoded = nip19.decode(pubkeyOrNpub); + if (decoded.type === 'npub') { + owner = decoded.data; // hex pubkey + } else { + throw new Error('Invalid npub'); + } + } catch (err) { + console.error('Failed to decode npub:', err); + setError('Invalid npub in Nostr URL'); + return; + } + } else { + owner = pubkeyOrNpub; // Already in hex format + } + platform = 'nostr'; apiUrl = ''; // Not applicable for Nostr console.log('Detected Nostr git:', { owner, repo }); diff --git a/src/lib/git-hosts/types.ts b/src/lib/git-hosts/types.ts index c359cf28..5965b0a4 100644 --- a/src/lib/git-hosts/types.ts +++ b/src/lib/git-hosts/types.ts @@ -1,3 +1,5 @@ +import { nip19 } from 'nostr-tools'; + /** * Git host provider abstraction for PR/MR operations */ @@ -131,9 +133,25 @@ export function parseRepoUrl(url: string): { owner: string; repo: string } | nul if (url.startsWith('nostr://')) { const match = url.match(/^nostr:\/\/([^/]+)\/(.+)$/); if (match) { + let owner = match[1]; // pubkey in hex or npub + const repo = match[2]; // repo-id (d tag) + + // Convert npub to hex if needed + if (owner.startsWith('npub1')) { + try { + const decoded = nip19.decode(owner); + if (decoded.type === 'npub') { + owner = decoded.data; + } + } catch (err) { + console.error('Failed to decode npub:', err); + return null; + } + } + return { - owner: match[1], // pubkey in hex - repo: match[2], // repo-id (d tag) + owner, // pubkey in hex + repo, // repo-id (d tag) }; } }