Add support for roles in nip 86

This commit is contained in:
Jon Staab
2026-06-22 09:50:44 -07:00
parent 545f2109ae
commit a525b66054
2 changed files with 193 additions and 0 deletions
+45
View File
@@ -43,6 +43,11 @@ 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
CreateRole func(ctx context.Context, id string, label string, description string, color int, order int) error
EditRole func(ctx context.Context, id string, label string, description string, color int, order int) error
DeleteRole func(ctx context.Context, id string) error
AssignRole func(ctx context.Context, pubkey nostr.PubKey, roleID string) error
UnassignRole func(ctx context.Context, pubkey nostr.PubKey, roleID string) error
Generic func(ctx context.Context, request nip86.Request) (nip86.Response, error)
}
@@ -330,6 +335,46 @@ func (rl *Relay) HandleNIP86(w http.ResponseWriter, r *http.Request) {
} else {
resp.Result = true
}
case nip86.CreateRole:
if rl.ManagementAPI.CreateRole == nil {
resp.Error = fmt.Sprintf("method %s not supported", thing.MethodName())
} else if err := rl.ManagementAPI.CreateRole(ctx, thing.ID, thing.Label, thing.Description, thing.Color, thing.Order); err != nil {
resp.Error = err.Error()
} else {
resp.Result = true
}
case nip86.EditRole:
if rl.ManagementAPI.EditRole == nil {
resp.Error = fmt.Sprintf("method %s not supported", thing.MethodName())
} else if err := rl.ManagementAPI.EditRole(ctx, thing.ID, thing.Label, thing.Description, thing.Color, thing.Order); err != nil {
resp.Error = err.Error()
} else {
resp.Result = true
}
case nip86.DeleteRole:
if rl.ManagementAPI.DeleteRole == nil {
resp.Error = fmt.Sprintf("method %s not supported", thing.MethodName())
} else if err := rl.ManagementAPI.DeleteRole(ctx, thing.ID); err != nil {
resp.Error = err.Error()
} else {
resp.Result = true
}
case nip86.AssignRole:
if rl.ManagementAPI.AssignRole == nil {
resp.Error = fmt.Sprintf("method %s not supported", thing.MethodName())
} else if err := rl.ManagementAPI.AssignRole(ctx, thing.PubKey, thing.RoleID); err != nil {
resp.Error = err.Error()
} else {
resp.Result = true
}
case nip86.UnassignRole:
if rl.ManagementAPI.UnassignRole == nil {
resp.Error = fmt.Sprintf("method %s not supported", thing.MethodName())
} else if err := rl.ManagementAPI.UnassignRole(ctx, thing.PubKey, thing.RoleID); err != nil {
resp.Error = err.Error()
} else {
resp.Result = true
}
case nip86.ListDisallowedKinds:
if rl.ManagementAPI.ListDisallowedKinds == nil {
resp.Error = fmt.Sprintf("method %s not supported", thing.MethodName())