Skip to content

Commit 2922a0d

Browse files
committed
git: support nostr://... URLs without requiring the <relay> component.
1 parent 35d628e commit 2922a0d

1 file changed

Lines changed: 28 additions & 18 deletions

File tree

git.go

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ aside from those, there is also:
369369
{
370370
Name: "clone",
371371
Usage: "clone a NIP-34 repository from a nostr:// URI",
372-
Description: `the <repository> parameter maybe in the form "<npub, hex, nprofile or nip05>/<identifier>", ngit-style like "nostr://<npub>/<relay>/<identifier>" or an "naddr1..." code.`,
372+
Description: `the <repository> parameter maybe in the form "<npub, hex, nprofile or nip05>/<identifier>", ngit-style like "nostr://<npub>/<relay>/<identifier>" or "nostr://<npub>/<identifier>" or an "naddr1..." code.`,
373373
ArgsUsage: "<repository> [directory]",
374374
Action: func(ctx context.Context, c *cli.Command) error {
375375
args := c.Args()
@@ -2633,30 +2633,40 @@ func parseRepositoryAddress(
26332633
}
26342634

26352635
// format 2: nostr://<npub_or_nip05>/<relay_hostname>/<identifier> (ngit-style)
2636+
// format 2b: nostr://<npub_or_nip05>/<identifier> (without relay)
26362637
if strings.HasPrefix(address, "nostr://") {
26372638
parts := strings.Split(address, "/")
2638-
if len(parts) != 5 {
2639-
return nostr.PubKey{}, "", nil, fmt.Errorf(
2640-
"invalid nostr URL format, expected nostr://<npub|nip05>/<relay_hostname>/<identifier>, got: %s", address,
2641-
)
2642-
}
2639+
if len(parts) == 5 {
2640+
// nostr://<owner>/<relay>/<identifier>
2641+
owner, err = parsePubKey(parts[2])
2642+
if err != nil {
2643+
return nostr.PubKey{}, "", nil, fmt.Errorf("invalid owner in URL: %w", err)
2644+
}
26432645

2644-
owner, err = parsePubKey(parts[2])
2645-
if err != nil {
2646-
return nostr.PubKey{}, "", nil, fmt.Errorf("invalid owner in URL: %w", err)
2647-
}
2646+
relayHost := parts[3]
2647+
identifier = parts[4]
26482648

2649-
relayHost := parts[3]
2650-
identifier = parts[4]
2649+
if strings.HasPrefix(relayHost, "wss:") || strings.HasPrefix(relayHost, "ws:") {
2650+
relayHints = []string{relayHost}
2651+
} else {
2652+
relayHints = []string{"wss://" + relayHost}
2653+
}
2654+
2655+
return owner, identifier, relayHints, nil
2656+
} else if len(parts) == 4 {
2657+
// nostr://<owner>/<identifier>
2658+
owner, err = parsePubKey(parts[2])
2659+
if err != nil {
2660+
return nostr.PubKey{}, "", nil, fmt.Errorf("invalid owner in URL: %w", err)
2661+
}
26512662

2652-
// construct relay hint from hostname
2653-
if strings.HasPrefix(relayHost, "wss:") || strings.HasPrefix(relayHost, "ws:") {
2654-
relayHints = []string{relayHost}
2663+
identifier = parts[3]
2664+
return owner, identifier, nil, nil
26552665
} else {
2656-
relayHints = []string{"wss://" + relayHost}
2666+
return nostr.PubKey{}, "", nil, fmt.Errorf(
2667+
"invalid nostr URL format, expected nostr://<npub|nip05>/<identifier> or nostr://<npub|nip05>/<relay>/<identifier>, got: %s", address,
2668+
)
26572669
}
2658-
2659-
return owner, identifier, relayHints, nil
26602670
}
26612671

26622672
// format 3: <npub, hex, nprofile or nip05>/<identifier>

0 commit comments

Comments
 (0)