chore: update lnurl lib to v0.8.0 (#102)

This commit is contained in:
dni ⚡ 2025-08-21 17:15:17 +02:00 committed by GitHub
commit e48be221b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 2356 additions and 574 deletions

View file

@ -132,11 +132,8 @@ def decode(hrp, addr):
return (None, None)
if data[0] == 0 and len(decoded) != 20 and len(decoded) != 32:
return (None, None)
if (
data[0] == 0
and spec != Encoding.BECH32
or data[0] != 0
and spec != Encoding.BECH32M
if (data[0] == 0 and spec != Encoding.BECH32) or (
data[0] != 0 and spec != Encoding.BECH32M
):
return (None, None)
return (data[0], decoded)

View file

@ -3,7 +3,6 @@ import time
from dataclasses import dataclass, field
from enum import IntEnum
from hashlib import sha256
from typing import List, Optional
from secp256k1 import PublicKey
@ -21,14 +20,14 @@ class EventKind(IntEnum):
@dataclass
class Event:
content: Optional[str] = None
public_key: Optional[str] = None
created_at: Optional[int] = None
content: str | None = None
public_key: str | None = None
created_at: int | None = None
kind: int = EventKind.TEXT_NOTE
tags: List[List[str]] = field(
tags: list[list[str]] = field(
default_factory=list
) # Dataclasses require special handling when the default value is a mutable type
signature: Optional[str] = None
signature: str | None = None
def __post_init__(self):
if self.content is not None and not isinstance(self.content, str):
@ -40,7 +39,7 @@ class Event:
@staticmethod
def serialize(
public_key: str, created_at: int, kind: int, tags: List[List[str]], content: str
public_key: str, created_at: int, kind: int, tags: list[list[str]], content: str
) -> bytes:
data = [0, public_key, created_at, kind, tags, content]
data_str = json.dumps(data, separators=(",", ":"), ensure_ascii=False)
@ -48,7 +47,7 @@ class Event:
@staticmethod
def compute_id(
public_key: str, created_at: int, kind: int, tags: List[List[str]], content: str
public_key: str, created_at: int, kind: int, tags: list[list[str]], content: str
):
return sha256(
Event.serialize(public_key, created_at, kind, tags, content)
@ -101,9 +100,9 @@ class Event:
@dataclass
class EncryptedDirectMessage(Event):
recipient_pubkey: Optional[str] = None
cleartext_content: Optional[str] = None
reference_event_id: Optional[str] = None
recipient_pubkey: str | None = None
cleartext_content: str | None = None
reference_event_id: str | None = None
def __post_init__(self):
if self.content is not None:

View file

@ -1,6 +1,5 @@
import base64
import secrets
from typing import Optional
import secp256k1
from cffi import FFI
@ -40,7 +39,7 @@ class PublicKey:
class PrivateKey:
def __init__(self, raw_secret: Optional[bytes] = None) -> None:
def __init__(self, raw_secret: bytes | None = None) -> None:
if raw_secret is not None:
self.raw_secret = raw_secret
else:
@ -127,9 +126,7 @@ class PrivateKey:
return self.raw_secret == other.raw_secret
def mine_vanity_key(
prefix: Optional[str] = None, suffix: Optional[str] = None
) -> PrivateKey:
def mine_vanity_key(prefix: str | None = None, suffix: str | None = None) -> PrivateKey:
if prefix is None and suffix is None:
raise ValueError("Expected at least one of 'prefix' or 'suffix' arguments")