mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-17 19:13:56 +02:00
nip46: add a random element to id generation.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -22,6 +23,7 @@ type BunkerClient struct {
|
|||||||
relays []string
|
relays []string
|
||||||
sharedSecret []byte
|
sharedSecret []byte
|
||||||
listeners *xsync.MapOf[string, chan Response]
|
listeners *xsync.MapOf[string, chan Response]
|
||||||
|
idPrefix string
|
||||||
|
|
||||||
// memoized
|
// memoized
|
||||||
getPublicKeyResponse string
|
getPublicKeyResponse string
|
||||||
@@ -69,6 +71,7 @@ func ConnectBunker(
|
|||||||
relays: relays,
|
relays: relays,
|
||||||
sharedSecret: shared,
|
sharedSecret: shared,
|
||||||
listeners: xsync.NewMapOf[string, chan Response](),
|
listeners: xsync.NewMapOf[string, chan Response](),
|
||||||
|
idPrefix: "gn-" + strconv.Itoa(rand.Intn(65536)),
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
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) {
|
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{
|
req, err := json.Marshal(Request{
|
||||||
ID: id,
|
ID: id,
|
||||||
Method: method,
|
Method: method,
|
||||||
|
Reference in New Issue
Block a user