Compare commits

..

2 commits

Author SHA1 Message Date
0b1a548ee4
1.12.0 2023-08-10 18:11:16 +10:00
04bd6dd35d
Add NIP-05 verification compatibility 2023-08-10 18:05:46 +10:00
8 changed files with 67 additions and 2 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "lemoncurry", "name": "lemoncurry",
"version": "1.11.0", "version": "1.12.0",
"repository": "https://git.00dani.me/00dani/lemoncurry", "repository": "https://git.00dani.me/00dani/lemoncurry",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {

View file

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "lemoncurry" name = "lemoncurry"
version = "1.11.0" version = "1.12.0"
description = "Indieweb-compatible personal website" description = "Indieweb-compatible personal website"
authors = ["Danielle McLean <dani@00dani.me>"] authors = ["Danielle McLean <dani@00dani.me>"]
license = "MIT" license = "MIT"

View file

@ -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,

View 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),
),
]

View file

@ -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()

View file

@ -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"),
] ]

View file

@ -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
View 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)