nip46: add a random element to id generation.

This commit is contained in:
fiatjaf 2024-02-11 11:07:01 -03:00
parent 64cc356404
commit f3d9f02598
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -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,