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:
Claude
2026-06-20 15:06:17 +00:00
parent fefc85d500
commit d1bc98d0f8
2 changed files with 38 additions and 0 deletions
+9
View File
@@ -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())