Add NIP-05 verification compatibility
This commit is contained in:
parent
2e7d12b3e6
commit
04bd6dd35d
6 changed files with 65 additions and 0 deletions
|
@ -20,6 +20,7 @@ class ProfileInline(admin.TabularInline):
|
||||||
class UserAdmin(BaseUserAdmin):
|
class UserAdmin(BaseUserAdmin):
|
||||||
fieldsets = BaseUserAdmin.fieldsets + (
|
fieldsets = BaseUserAdmin.fieldsets + (
|
||||||
("Profile", {"fields": ("avatar", "xmpp", "note")}),
|
("Profile", {"fields": ("avatar", "xmpp", "note")}),
|
||||||
|
("Nostr", {"fields": ("nostr_key", "nostr_relays")}),
|
||||||
)
|
)
|
||||||
inlines = (
|
inlines = (
|
||||||
PgpKeyInline,
|
PgpKeyInline,
|
||||||
|
|
22
users/migrations/0018_auto_20230810_1754.py
Normal file
22
users/migrations/0018_auto_20230810_1754.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Generated by Django 3.2.20 on 2023-08-10 07:54
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("users", "0017_rename_key_pgpkey"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="user",
|
||||||
|
name="nostr_key",
|
||||||
|
field=models.CharField(blank=True, max_length=32, null=True, unique=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="user",
|
||||||
|
name="nostr_relays",
|
||||||
|
field=models.JSONField(blank=True, default=list),
|
||||||
|
),
|
||||||
|
]
|
|
@ -81,6 +81,19 @@ class User(ModelMeta, AbstractUser):
|
||||||
help_text="SHA-256 hash of the user's OpenID URL, used for Libravatar",
|
help_text="SHA-256 hash of the user's OpenID URL, used for Libravatar",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
nostr_key = models.CharField(
|
||||||
|
max_length=32,
|
||||||
|
unique=True,
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
help_text="A Nostr public key in 32-byte hex format",
|
||||||
|
)
|
||||||
|
nostr_relays = models.JSONField(
|
||||||
|
default=list,
|
||||||
|
blank=True,
|
||||||
|
help_text="An array of Nostr relay URLs that this public key posts to",
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def calc_email_md5(self):
|
def calc_email_md5(self):
|
||||||
return md5(self.email.lower().encode("utf-8")).hexdigest()
|
return md5(self.email.lower().encode("utf-8")).hexdigest()
|
||||||
|
|
|
@ -8,5 +8,6 @@ urlpatterns = [
|
||||||
path("host-meta", views.host_meta_xml, name="host-meta"),
|
path("host-meta", views.host_meta_xml, name="host-meta"),
|
||||||
path("host-meta.json", views.host_meta_json, name="host-meta.json"),
|
path("host-meta.json", views.host_meta_json, name="host-meta.json"),
|
||||||
path("manifest.json", views.manifest, name="manifest"),
|
path("manifest.json", views.manifest, name="manifest"),
|
||||||
|
path("nostr.json", views.nostr_json, name="nostr.json"),
|
||||||
path("webfinger", views.webfinger, name="webfinger"),
|
path("webfinger", views.webfinger, name="webfinger"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from .static import keybase
|
from .static import keybase
|
||||||
from .host_meta import host_meta_xml, host_meta_json
|
from .host_meta import host_meta_xml, host_meta_json
|
||||||
from .manifest import manifest
|
from .manifest import manifest
|
||||||
|
from .nostr import nostr_json
|
||||||
from .webfinger import webfinger
|
from .webfinger import webfinger
|
||||||
|
|
27
wellknowns/views/nostr.py
Normal file
27
wellknowns/views/nostr.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
from django.http import JsonResponse
|
||||||
|
from users.models import User
|
||||||
|
|
||||||
|
aliases = {"00dani": ("_", "dani")}
|
||||||
|
unaliases = {alias: name for (name, aliases) in aliases.items() for alias in aliases}
|
||||||
|
|
||||||
|
|
||||||
|
def nostr_json(request) -> JsonResponse:
|
||||||
|
users = User.objects.filter(nostr_key__isnull=False)
|
||||||
|
|
||||||
|
if "name" in request.GET:
|
||||||
|
name = request.GET["name"]
|
||||||
|
if name in unaliases:
|
||||||
|
name = unaliases[name]
|
||||||
|
users = users.filter(username=name)
|
||||||
|
|
||||||
|
names = {u.username: u.nostr_key for u in users}
|
||||||
|
for name in list(names.keys()):
|
||||||
|
for alias in aliases.get(name, []):
|
||||||
|
names[alias] = names[name]
|
||||||
|
|
||||||
|
relays = {u.nostr_key: u.nostr_relays for u in users if u.nostr_relays}
|
||||||
|
|
||||||
|
response = {"names": names}
|
||||||
|
if relays:
|
||||||
|
response["relays"] = relays
|
||||||
|
return JsonResponse(response)
|
Loading…
Reference in a new issue