Add signevent method to NIP-86 (nip86 + khatru)
Implements the signevent capability from nostr-protocol/nips#2389: relay admins can ask the relay to sign an unsigned event template with its own (self) key. - nip86: SignEvent MethodParams type + "signevent" decode case (round-trips the {kind, content, tags, created_at} param into a nostr.Event). - khatru: RelayManagementAPI.SignEvent hook + dispatch returning the signed event as the result.
This commit is contained in:
@@ -43,6 +43,7 @@ type RelayManagementAPI struct {
|
||||
Stats func(ctx context.Context) (nip86.Response, error)
|
||||
GrantAdmin 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)
|
||||
}
|
||||
|
||||
@@ -346,6 +347,14 @@ func (rl *Relay) HandleNIP86(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
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:
|
||||
if rl.ManagementAPI.Generic == nil {
|
||||
resp.Error = fmt.Sprintf("method '%s' not known", mp.MethodName())
|
||||
|
||||
Reference in New Issue
Block a user