@@ -3,11 +3,14 @@ package main
33import (
44 "context"
55 "fmt"
6+ "strings"
67
78 "fiatjaf.com/nostr"
89 "fiatjaf.com/nostr/nip05"
910 "fiatjaf.com/nostr/nip19"
11+ "fiatjaf.com/nostr/nip42"
1012 "fiatjaf.com/nostr/sdk/hints"
13+ "github.com/fatih/color"
1114 "github.com/urfave/cli/v3"
1215)
1316
@@ -18,12 +21,18 @@ var fetch = &cli.Command{
1821 nak fetch nevent1qqsxrwm0hd3s3fddh4jc2574z3xzufq6qwuyz2rvv3n087zvym3dpaqprpmhxue69uhhqatzd35kxtnjv4kxz7tfdenju6t0xpnej4
1922 echo npub1h8spmtw9m2huyv6v2j2qd5zv956z2zdugl6mgx02f2upffwpm3nqv0j4ps | nak fetch --relay wss://relay.nostr.band` ,
2023 DisableSliceFlagSeparator : true ,
21- Flags : append (reqFilterFlags ,
22- & cli.StringSliceFlag {
23- Name : "relay" ,
24- Aliases : []string {"r" },
25- Usage : "also use these relays to fetch from" ,
26- },
24+ Flags : append (defaultKeyFlags ,
25+ append (reqFilterFlags ,
26+ & cli.StringSliceFlag {
27+ Name : "relay" ,
28+ Aliases : []string {"r" },
29+ Usage : "also use these relays to fetch from" ,
30+ },
31+ & cli.BoolFlag {
32+ Name : "auth" ,
33+ Usage : "always perform nip42 \" AUTH\" when facing an \" auth-required: \" rejection and try again" ,
34+ },
35+ )... ,
2736 ),
2837 ArgsUsage : "[nip05_or_nip19_code]" ,
2938 Action : func (ctx context.Context , c * cli.Command ) error {
@@ -106,6 +115,19 @@ var fetch = &cli.Command{
106115 continue
107116 }
108117
118+ sys .Pool .AuthRequiredHandler = func (ctx context.Context , authEvent * nostr.Event ) error {
119+ return authSigner (ctx , c , func (s string , args ... any ) {
120+ if strings .HasPrefix (s , "authenticating as" ) {
121+ cleanUrl , _ := strings .CutPrefix (
122+ nip42 .GetRelayURLFromAuthEvent (* authEvent ),
123+ "wss://" ,
124+ )
125+ s = "authenticating to " + color .CyanString (cleanUrl ) + " as" + s [len ("authenticating as" ):]
126+ }
127+ log (s + "\n " , args ... )
128+ }, authEvent )
129+ }
130+
109131 found := false
110132 for ie := range sys .Pool .FetchMany (ctx , relays , filter , nostr.SubscriptionOptions {
111133 Label : "nak-fetch" ,
0 commit comments