From d7c0ff2bb7256565aec02b6044f00411d8902ebd Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 22 Sep 2024 19:21:41 -0300 Subject: [PATCH] update go-nostr keyer interface and make req --auth work again. --- event.go | 5 +++-- go.mod | 2 +- go.sum | 4 ++-- helpers.go | 9 ++++++++- helpers_key.go | 4 ++-- paginate.go | 6 +++--- req.go | 6 +++--- 7 files changed, 22 insertions(+), 14 deletions(-) diff --git a/event.go b/event.go index 2197abc..cbc0ec5 100644 --- a/event.go +++ b/event.go @@ -239,7 +239,7 @@ example: return err } } else { - evt.PubKey = kr.GetPublicKey(ctx) + evt.PubKey, _ = kr.GetPublicKey(ctx) } // try to generate work with this difficulty -- runs forever @@ -302,7 +302,8 @@ example: // error publishing if strings.HasPrefix(err.Error(), "msg: auth-required:") && (sec != "" || bunker != nil) && doAuth { // if the relay is requesting auth and we can auth, let's do it - log("performing auth as %s... ", kr.GetPublicKey(ctx)) + pk, _ := kr.GetPublicKey(ctx) + log("performing auth as %s... ", pk) if err := relay.Auth(ctx, func(authEvent *nostr.Event) error { return kr.SignEvent(ctx, authEvent) }); err == nil { diff --git a/go.mod b/go.mod index 5ae81bc..384eea4 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/fiatjaf/khatru v0.7.5 github.com/mailru/easyjson v0.7.7 github.com/markusmobius/go-dateparser v1.2.3 - github.com/nbd-wtf/go-nostr v0.36.3 + github.com/nbd-wtf/go-nostr v0.37.2 golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 ) diff --git a/go.sum b/go.sum index c6a7a94..b3c3565 100644 --- a/go.sum +++ b/go.sum @@ -113,8 +113,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/nbd-wtf/go-nostr v0.36.3 h1:50fNFO8vQNMEIZ+6qUq0M5hlqEtA13WrtrKcz10eg9k= -github.com/nbd-wtf/go-nostr v0.36.3/go.mod h1:TGKGj00BmJRXvRe0LlpDN3KKbELhhPXgBwUEhzu3Oq0= +github.com/nbd-wtf/go-nostr v0.37.2 h1:42rriFqqz07EdydERwYeQnewl+Rah1Gq46I+Wh0KYYg= +github.com/nbd-wtf/go-nostr v0.37.2/go.mod h1:TGKGj00BmJRXvRe0LlpDN3KKbELhhPXgBwUEhzu3Oq0= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= diff --git a/helpers.go b/helpers.go index 8df8381..d8eb013 100644 --- a/helpers.go +++ b/helpers.go @@ -119,6 +119,13 @@ func connectToAllRelays( forcePreAuth bool, opts ...nostr.PoolOption, ) []*nostr.Relay { + sys.Pool = nostr.NewSimplePool(context.Background(), + append(opts, + nostr.WithEventMiddleware(sys.TrackEventHints), + nostr.WithPenaltyBox(), + )..., + ) + relays := make([]*nostr.Relay, 0, len(relayUrls)) relayLoop: for _, url := range relayUrls { @@ -137,7 +144,7 @@ relayLoop: if (*challengeTag)[1] == "" { return fmt.Errorf("auth not received yet *****") } - return signer(authEvent) + return signer(ctx, nostr.RelayEvent{Event: authEvent, Relay: relay}) }); err == nil { // auth succeeded break challengeWaitLoop diff --git a/helpers_key.go b/helpers_key.go index 977d677..62a6f80 100644 --- a/helpers_key.go +++ b/helpers_key.go @@ -48,10 +48,10 @@ func gatherKeyerFromArguments(ctx context.Context, c *cli.Command) (keyer.Keyer, if bunker != nil { kr = keyer.NewBunkerSignerFromBunkerClient(bunker) } else { - kr = keyer.NewPlainKeySigner(key) + kr, err = keyer.NewPlainKeySigner(key) } - return kr, nil + return kr, err } func gatherSecretKeyOrBunkerFromArguments(ctx context.Context, c *cli.Command) (string, *nip46.BunkerClient, error) { diff --git a/paginate.go b/paginate.go index 9d796f0..77ee9a7 100644 --- a/paginate.go +++ b/paginate.go @@ -12,8 +12,8 @@ import ( func paginateWithParams( interval time.Duration, globalLimit uint64, -) func(ctx context.Context, urls []string, filters nostr.Filters) chan nostr.IncomingEvent { - return func(ctx context.Context, urls []string, filters nostr.Filters) chan nostr.IncomingEvent { +) func(ctx context.Context, urls []string, filters nostr.Filters) chan nostr.RelayEvent { + return func(ctx context.Context, urls []string, filters nostr.Filters) chan nostr.RelayEvent { // filters will always be just one filter := filters[0] @@ -29,7 +29,7 @@ func paginateWithParams( } } var globalCount uint64 = 0 - globalCh := make(chan nostr.IncomingEvent) + globalCh := make(chan nostr.RelayEvent) repeatedCache := make([]string, 0, 300) nextRepeatedCache := make([]string, 0, 300) diff --git a/req.go b/req.go index 49f5d91..99dd1fb 100644 --- a/req.go +++ b/req.go @@ -76,7 +76,7 @@ example: relayUrls, c.Bool("force-pre-auth"), nostr.WithAuthHandler( - func(authEvent *nostr.Event) error { + func(ctx context.Context, authEvent nostr.RelayEvent) error { if !c.Bool("auth") && !c.Bool("force-pre-auth") { return fmt.Errorf("auth not authorized") } @@ -85,10 +85,10 @@ example: return err } - pk := kr.GetPublicKey(ctx) + pk, _ := kr.GetPublicKey(ctx) log("performing auth as %s... ", pk) - return kr.SignEvent(ctx, authEvent) + return kr.SignEvent(ctx, authEvent.Event) }, ), )