From f3d9f02598e03b95601d1639d2a56f020c65ee54 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 11 Feb 2024 11:07:01 -0300 Subject: [PATCH] nip46: add a random element to id generation. --- nip46/client.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nip46/client.go b/nip46/client.go index f40dbf2..1a6eca4 100644 --- a/nip46/client.go +++ b/nip46/client.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "math/rand" "net/url" "strconv" "sync/atomic" @@ -22,6 +23,7 @@ type BunkerClient struct { relays []string sharedSecret []byte listeners *xsync.MapOf[string, chan Response] + idPrefix string // memoized getPublicKeyResponse string @@ -69,6 +71,7 @@ func ConnectBunker( relays: relays, sharedSecret: shared, listeners: xsync.NewMapOf[string, chan Response](), + idPrefix: "gn-" + strconv.Itoa(rand.Intn(65536)), } go func() { @@ -131,7 +134,7 @@ func (bunker *BunkerClient) SignEvent(ctx context.Context, evt *nostr.Event) err } func (bunker *BunkerClient) RPC(ctx context.Context, method string, params []string) (string, error) { - id := strconv.FormatUint(bunker.serial.Add(1), 10) + id := bunker.idPrefix + "-" + strconv.FormatUint(bunker.serial.Add(1), 10) req, err := json.Marshal(Request{ ID: id, Method: method,