mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-13 18:31:26 +02:00
nip46: check signatures incoming from bunkers by default.
This commit is contained in:
parent
a0bf181547
commit
903770f78d
@ -30,6 +30,9 @@ type BunkerClient struct {
|
|||||||
|
|
||||||
// memoized
|
// memoized
|
||||||
getPublicKeyResponse string
|
getPublicKeyResponse string
|
||||||
|
|
||||||
|
// SkipSignatureCheck can be set if you don't want to double-check incoming signatures
|
||||||
|
SkipSignatureCheck bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConnectBunker establishes an RPC connection to a NIP-46 signer using the relays and secret provided in the bunkerURL.
|
// ConnectBunker establishes an RPC connection to a NIP-46 signer using the relays and secret provided in the bunkerURL.
|
||||||
@ -175,10 +178,25 @@ func (bunker *BunkerClient) GetPublicKey(ctx context.Context) (string, error) {
|
|||||||
|
|
||||||
func (bunker *BunkerClient) SignEvent(ctx context.Context, evt *nostr.Event) error {
|
func (bunker *BunkerClient) SignEvent(ctx context.Context, evt *nostr.Event) error {
|
||||||
resp, err := bunker.RPC(ctx, "sign_event", []string{evt.String()})
|
resp, err := bunker.RPC(ctx, "sign_event", []string{evt.String()})
|
||||||
if err == nil {
|
if err != nil {
|
||||||
err = easyjson.Unmarshal([]byte(resp), evt)
|
return err
|
||||||
}
|
}
|
||||||
return err
|
|
||||||
|
err = easyjson.Unmarshal([]byte(resp), evt)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !bunker.SkipSignatureCheck {
|
||||||
|
if ok := evt.CheckID(); !ok {
|
||||||
|
return fmt.Errorf("sign_event response from bunker has invalid id")
|
||||||
|
}
|
||||||
|
if ok, _ := evt.CheckSignature(); !ok {
|
||||||
|
return fmt.Errorf("sign_event response from bunker has invalid signature")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bunker *BunkerClient) NIP44Encrypt(
|
func (bunker *BunkerClient) NIP44Encrypt(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user