forked from coracle/zooid
Add list allowed pubkeys nip 86 method
This commit is contained in:
@@ -108,7 +108,6 @@ See `justfile` for defined commands.
|
|||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- [ ] Add admin/owner/etc to list allowed pubkeys
|
|
||||||
- [ ] Watch configuration files and hot reload
|
- [ ] Watch configuration files and hot reload
|
||||||
- [ ] Free up resources after instance inactivity
|
- [ ] Free up resources after instance inactivity
|
||||||
- [ ] Admin/member lists
|
- [ ] Admin/member lists
|
||||||
|
|||||||
@@ -134,10 +134,6 @@ func (instance *Instance) HasAccess(pubkey nostr.PubKey) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if instance.Management.PubkeyIsBanned(pubkey) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
filter := nostr.Filter{
|
filter := nostr.Filter{
|
||||||
Kinds: []nostr.Kind{AUTH_JOIN},
|
Kinds: []nostr.Kind{AUTH_JOIN},
|
||||||
Authors: []nostr.PubKey{pubkey},
|
Authors: []nostr.PubKey{pubkey},
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
"fiatjaf.com/nostr/khatru"
|
"fiatjaf.com/nostr/khatru"
|
||||||
"fiatjaf.com/nostr/nip86"
|
"fiatjaf.com/nostr/nip86"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ManagementStore struct {
|
type ManagementStore struct {
|
||||||
@@ -162,6 +163,45 @@ func (m *ManagementStore) Enable(instance *Instance) {
|
|||||||
return reasons, nil
|
return reasons, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instance.Relay.ManagementAPI.ListAllowedPubKeys = func(ctx context.Context) ([]nip86.PubKeyReason, error) {
|
||||||
|
reasons := make([]nip86.PubKeyReason, 0)
|
||||||
|
|
||||||
|
reasons = append(reasons, nip86.PubKeyReason{
|
||||||
|
PubKey: nostr.MustPubKeyFromHex(m.Config.Self.Pubkey),
|
||||||
|
Reason: "relay owner",
|
||||||
|
})
|
||||||
|
|
||||||
|
reasons = append(reasons, nip86.PubKeyReason{
|
||||||
|
PubKey: m.Config.Secret.Public(),
|
||||||
|
Reason: "relay self",
|
||||||
|
})
|
||||||
|
|
||||||
|
for name, role := range m.Config.Roles {
|
||||||
|
for _, pubkey := range role.Pubkeys {
|
||||||
|
reasons = append(reasons, nip86.PubKeyReason{
|
||||||
|
PubKey: nostr.MustPubKeyFromHex(pubkey),
|
||||||
|
Reason: fmt.Sprintf("assigned to role: %s", name),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
filter := nostr.Filter{
|
||||||
|
Kinds: []nostr.Kind{AUTH_JOIN},
|
||||||
|
}
|
||||||
|
|
||||||
|
for event := range m.Events.QueryEvents(filter, 0) {
|
||||||
|
reasons = append(
|
||||||
|
reasons,
|
||||||
|
nip86.PubKeyReason{
|
||||||
|
PubKey: event.PubKey,
|
||||||
|
Reason: "joined via invite code",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return reasons, nil
|
||||||
|
}
|
||||||
|
|
||||||
instance.Relay.ManagementAPI.BanEvent = func(ctx context.Context, id nostr.ID, reason string) error {
|
instance.Relay.ManagementAPI.BanEvent = func(ctx context.Context, id nostr.ID, reason string) error {
|
||||||
instance.Events.DeleteEvent(id)
|
instance.Events.DeleteEvent(id)
|
||||||
|
|
||||||
|
|||||||
@@ -162,4 +162,4 @@ func TestManagementStore_EventIsBanned_NotBanned(t *testing.T) {
|
|||||||
if mgmt.EventIsBanned(eventID) {
|
if mgmt.EventIsBanned(eventID) {
|
||||||
t.Error("EventIsBanned() should return false for non-banned event")
|
t.Error("EventIsBanned() should return false for non-banned event")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user