Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ data
.vscode
dump
.venv
.claude
4 changes: 4 additions & 0 deletions crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .paranoia import (
assert_sane_string,
assert_valid_expiration_seconds,
assert_valid_lud16,
assert_valid_msats,
assert_valid_positive_int,
assert_valid_pubkey,
Expand All @@ -35,6 +36,8 @@ async def create_nwc(data: CreateNWCKey) -> NWCKey:
assert_valid_wallet_id(data.wallet)
assert_sane_string(data.description)
assert_valid_expiration_seconds(data.expires_at)
if data.lud16:
assert_valid_lud16(data.lud16)
for permission in data.permissions:
assert_sane_string(permission)

Expand All @@ -53,6 +56,7 @@ async def create_nwc(data: CreateNWCKey) -> NWCKey:
permissions=" ".join(data.permissions),
created_at=int(time.time()),
last_used=int(time.time()),
lud16=data.lud16,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add some validation for lud16

)
await db.insert("nwcprovider.keys", nwckey_entry)
if data.budgets:
Expand Down
7 changes: 7 additions & 0 deletions migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,10 @@ async def m006_default_config3(db):
""",
{"value": "0"},
)


async def m007_add_lud16(db):
"""
Add lud16 column to keys table for lightning address support
"""
await db.execute("ALTER TABLE nwcprovider.keys ADD COLUMN lud16 TEXT")
10 changes: 10 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class NWCKey(BaseModel):
permissions: str
created_at: int
last_used: int
lud16: str | None = None

def get_permissions(self) -> list[str]:
try:
Expand Down Expand Up @@ -67,6 +68,7 @@ class CreateNWCKey(BaseModel):
expires_at: int
permissions: list[str]
budgets: list[NWCNewBudget] | None = None
lud16: str | None = None


class DeleteNWC(BaseModel):
Expand Down Expand Up @@ -102,13 +104,21 @@ class NWCRegistrationRequest(BaseModel):
description: str
expires_at: int
budgets: list[NWCNewBudget]
lud16: str | None = None


class NWCGetResponse(BaseModel):
data: NWCKey
budgets: list[NWCBudget]


class NWCGetAllResponse(BaseModel):
data: NWCKey
budgets: list[NWCBudget]
wallet_id: str
wallet_name: str


class NWCConfig(BaseModel):
key: str
value: str
20 changes: 20 additions & 0 deletions paranoia.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,26 @@ def assert_non_empty_string(v: str):
panic("string is empty")


# Check if string is a valid lud16 lightning address (eg. name@domain)
def assert_valid_lud16(v: str):
if not ENABLE_HARDENING:
return
assert_non_empty_string(v)
if len(v) > 255:
panic("lud16 is too long")
name, sep, domain = v.partition("@")
if not (sep and name and domain):
panic("lud16 must be in the form name@domain")
# LUD-16 restricts the name to a-z0-9-_.
if not all(c.isascii() and (c.isalnum() or c in "-_.") for c in name):
panic("lud16 name contains invalid characters")
# domain must look like a clearnet host (eg. example.com)
if "." not in domain or not all(
c.isascii() and (c.isalnum() or c in "-.") for c in domain
):
panic("lud16 domain is invalid")


# Assert valid json
def assert_valid_json(v: str):
if not ENABLE_HARDENING:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/image/NWC_Banner_Extension.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion static/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
window.app = Vue.createApp({
el: '#vue',
mixins: [windowMixin],
delimiters: ['${', '}'],
data: function () {
return {
config: {},
Expand Down
Loading
Loading