Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d1bc98d0f8 |
@@ -43,6 +43,7 @@ type RelayManagementAPI struct {
|
|||||||
Stats func(ctx context.Context) (nip86.Response, error)
|
Stats func(ctx context.Context) (nip86.Response, error)
|
||||||
GrantAdmin func(ctx context.Context, pubkey nostr.PubKey, methods []string) error
|
GrantAdmin func(ctx context.Context, pubkey nostr.PubKey, methods []string) error
|
||||||
RevokeAdmin func(ctx context.Context, pubkey nostr.PubKey, methods []string) error
|
RevokeAdmin func(ctx context.Context, pubkey nostr.PubKey, methods []string) error
|
||||||
|
SignEvent func(ctx context.Context, event nostr.Event) (nostr.Event, error)
|
||||||
Generic func(ctx context.Context, request nip86.Request) (nip86.Response, error)
|
Generic func(ctx context.Context, request nip86.Request) (nip86.Response, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,6 +347,14 @@ func (rl *Relay) HandleNIP86(w http.ResponseWriter, r *http.Request) {
|
|||||||
} else {
|
} else {
|
||||||
resp.Result = result
|
resp.Result = result
|
||||||
}
|
}
|
||||||
|
case nip86.SignEvent:
|
||||||
|
if rl.ManagementAPI.SignEvent == nil {
|
||||||
|
resp.Error = fmt.Sprintf("method %s not supported", thing.MethodName())
|
||||||
|
} else if result, err := rl.ManagementAPI.SignEvent(ctx, thing.Event); err != nil {
|
||||||
|
resp.Error = err.Error()
|
||||||
|
} else {
|
||||||
|
resp.Result = result
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
if rl.ManagementAPI.Generic == nil {
|
if rl.ManagementAPI.Generic == nil {
|
||||||
resp.Error = fmt.Sprintf("method '%s' not known", mp.MethodName())
|
resp.Error = fmt.Sprintf("method '%s' not known", mp.MethodName())
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package nip86
|
package nip86
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
@@ -242,6 +243,25 @@ func DecodeRequest(req Request) (MethodParams, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
case "stats":
|
case "stats":
|
||||||
return Stats{}, nil
|
return Stats{}, nil
|
||||||
|
case "signevent":
|
||||||
|
if len(req.Params) == 0 {
|
||||||
|
return nil, fmt.Errorf("invalid number of params for '%s'", req.Method)
|
||||||
|
}
|
||||||
|
|
||||||
|
// params[0] is an unsigned event template {kind, content, tags,
|
||||||
|
// created_at}; it arrives as a decoded JSON value, so round-trip it
|
||||||
|
// through JSON into an Event.
|
||||||
|
evtJSON, err := json.Marshal(req.Params[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid event param for '%s'", req.Method)
|
||||||
|
}
|
||||||
|
|
||||||
|
var evt nostr.Event
|
||||||
|
if err := json.Unmarshal(evtJSON, &evt); err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid event param for '%s'", req.Method)
|
||||||
|
}
|
||||||
|
|
||||||
|
return SignEvent{Event: evt}, nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown method '%s'", req.Method)
|
return nil, fmt.Errorf("unknown method '%s'", req.Method)
|
||||||
}
|
}
|
||||||
@@ -277,6 +297,7 @@ var (
|
|||||||
_ MethodParams = (*GrantAdmin)(nil)
|
_ MethodParams = (*GrantAdmin)(nil)
|
||||||
_ MethodParams = (*RevokeAdmin)(nil)
|
_ MethodParams = (*RevokeAdmin)(nil)
|
||||||
_ MethodParams = (*Stats)(nil)
|
_ MethodParams = (*Stats)(nil)
|
||||||
|
_ MethodParams = (*SignEvent)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
type SupportedMethods struct{}
|
type SupportedMethods struct{}
|
||||||
@@ -418,3 +439,11 @@ func (RevokeAdmin) MethodName() string { return "revokeadmin" }
|
|||||||
type Stats struct{}
|
type Stats struct{}
|
||||||
|
|
||||||
func (Stats) MethodName() string { return "stats" }
|
func (Stats) MethodName() string { return "stats" }
|
||||||
|
|
||||||
|
// SignEvent asks the relay to sign an unsigned event template with its own
|
||||||
|
// (self) key and return the full signed event. See NIP-86 `signevent`.
|
||||||
|
type SignEvent struct {
|
||||||
|
Event nostr.Event
|
||||||
|
}
|
||||||
|
|
||||||
|
func (SignEvent) MethodName() string { return "signevent" }
|
||||||
|
|||||||
Reference in New Issue
Block a user