nip46: implement switch_relays on the signer side.
This commit is contained in:
@@ -16,6 +16,9 @@ type DynamicSigner struct {
|
|||||||
// { [handlePubkey]: {[clientKey]: Session} }
|
// { [handlePubkey]: {[clientKey]: Session} }
|
||||||
sessions map[nostr.PubKey]map[nostr.PubKey]Session
|
sessions map[nostr.PubKey]map[nostr.PubKey]Session
|
||||||
|
|
||||||
|
// used for switch_relays call
|
||||||
|
DefaultRelays []string
|
||||||
|
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
|
||||||
// the handler is the keypair we use to communicate with the NIP-46 client, decrypt requests, encrypt responses etc
|
// the handler is the keypair we use to communicate with the NIP-46 client, decrypt requests, encrypt responses etc
|
||||||
@@ -203,6 +206,9 @@ func (p *DynamicSigner) HandleRequest(ctx context.Context, event nostr.Event) (
|
|||||||
result = plaintext
|
result = plaintext
|
||||||
case "ping":
|
case "ping":
|
||||||
result = "pong"
|
result = "pong"
|
||||||
|
case "switch_relays":
|
||||||
|
j, _ := json.Marshal(p.DefaultRelays)
|
||||||
|
result = string(j)
|
||||||
default:
|
default:
|
||||||
return req, resp, eventResponse,
|
return req, resp, eventResponse,
|
||||||
fmt.Errorf("unknown method '%s'", req.Method)
|
fmt.Errorf("unknown method '%s'", req.Method)
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ type StaticKeySigner struct {
|
|||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
|
||||||
AuthorizeRequest func(harmless bool, from nostr.PubKey, secret string) bool
|
AuthorizeRequest func(harmless bool, from nostr.PubKey, secret string) bool
|
||||||
|
|
||||||
|
// used for switch_relays call
|
||||||
|
DefaultRelays []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStaticKeySigner(secretKey [32]byte) StaticKeySigner {
|
func NewStaticKeySigner(secretKey [32]byte) StaticKeySigner {
|
||||||
@@ -204,6 +207,9 @@ func (p *StaticKeySigner) HandleRequest(_ context.Context, event nostr.Event) (
|
|||||||
case "ping":
|
case "ping":
|
||||||
result = "pong"
|
result = "pong"
|
||||||
harmless = true
|
harmless = true
|
||||||
|
case "switch_relays":
|
||||||
|
j, _ := json.Marshal(p.DefaultRelays)
|
||||||
|
result = string(j)
|
||||||
default:
|
default:
|
||||||
return req, resp, eventResponse,
|
return req, resp, eventResponse,
|
||||||
fmt.Errorf("unknown method '%s'", req.Method)
|
fmt.Errorf("unknown method '%s'", req.Method)
|
||||||
|
|||||||
Reference in New Issue
Block a user