Skip to content

Commit c06b080

Browse files
committed
Better LN status handling
1 parent 4ed7170 commit c06b080

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

‎quorra/classes.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,12 @@ class AqrOIDCLoginTransactionStates(str, Enum):
148148
confirmed = "confirmed"
149149
rejected = "rejected"
150150
token_issued = "token-issued"
151+
152+
153+
class LNStatusEnum(str, Enum):
154+
ok = "OK"
155+
error = "error"
156+
157+
class LNStatusResponse(BaseModel):
158+
status: LNStatusEnum
159+
reason: str | None = None

‎quorra/routers/lnurlauth.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ..classes import (
1717
User, Device,
1818
Transaction, TransactionTypes,
19-
ErrorResponse, QRDataResponse
19+
ErrorResponse, QRDataResponse, LNStatusResponse, LNStatusEnum
2020
)
2121

2222
from cryptography.hazmat.primitives.asymmetric.ec import (
@@ -56,8 +56,9 @@ async def verify_signature(k1: str, sig: str, key: str) -> bool:
5656
return True
5757

5858

59+
# TODO: Correct error response
5960
@router.get("/register", response_model=None, responses={403: {"model": ErrorResponse}})
60-
async def ln_register(session: SessionDep, k1: str, tag: str, sig: str, key: str, action: str | None = None):
61+
async def ln_register(session: SessionDep, k1: str, tag: str, sig: str, key: str, action: str | None = None) -> LNStatusResponse:
6162
"""Finishes device registration."""
6263
if not await verify_signature(k1, sig, key):
6364
raise HTTPException(status_code=403, detail="Invalid signature")
@@ -88,7 +89,7 @@ async def ln_register(session: SessionDep, k1: str, tag: str, sig: str, key: str
8889
session.refresh(d)
8990
# TODO: Pass the error back into the transaction if anything fails
9091
tx.set_state("finished")
91-
return None
92+
return LNStatusResponse(status=LNStatusEnum.ok)
9293

9394

9495
# TODO: Implement for LN
@@ -97,8 +98,9 @@ async def ln_register(session: SessionDep, k1: str, tag: str, sig: str, key: str
9798
# return None
9899

99100

101+
# TODO: Correct error response
100102
@router.get("/authenticate", response_model=None, responses={404: {"model": ErrorResponse}})
101-
async def ln_authenticate(session: SessionDep, k1: str, tag: str, sig: str, key: str, action: str | None = None):
103+
async def ln_authenticate(session: SessionDep, k1: str, tag: str, sig: str, key: str, action: str | None = None) -> LNStatusResponse:
102104
if not await verify_signature(k1, sig, key):
103105
raise HTTPException(status_code=403, detail="Invalid signature")
104106
safe_k1 = escape_valkey_tag(k1)
@@ -114,7 +116,7 @@ async def ln_authenticate(session: SessionDep, k1: str, tag: str, sig: str, key:
114116
tx.add_private_data(".user", {"uid": user.id, "device-id": device.id})
115117
await store_oidc_code(tx)
116118
tx.set_state("confirmed")
117-
return None
119+
return LNStatusResponse(status=LNStatusEnum.ok)
118120

119121

120122
@router.post("/qr", responses={404: {"model": ErrorResponse}})

0 commit comments

Comments
 (0)