feat: create unsafe real invoice
This commit is contained in:
@@ -35,6 +35,8 @@ class KvListResponse(BaseModel):
|
||||
class CreateInvoiceRequest(BaseModel):
|
||||
wallet_id: str = Field(..., min_length=1, max_length=128)
|
||||
amount_sat: int = Field(..., gt=0)
|
||||
# todo: bridge for extensions to select currencies
|
||||
currency: str | None = Field(..., min_length=1, max_length=8)
|
||||
memo: str = Field(..., max_length=512)
|
||||
tag: str = Field(..., min_length=1, max_length=64)
|
||||
extra: dict[str, str] = Field(default_factory=dict)
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import secrets
|
||||
import time
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
|
||||
|
||||
from .api import ExtensionAPI
|
||||
from .models import (
|
||||
CreateInvoiceRequest,
|
||||
@@ -70,16 +69,22 @@ class InMemoryExtensionAPI(ExtensionAPI):
|
||||
if self.wallet_id and request.wallet_id != self.wallet_id:
|
||||
raise PermissionError("Extension cannot create invoices for this wallet.")
|
||||
|
||||
entropy = secrets.token_urlsafe(16)
|
||||
invoice_seed = (
|
||||
f"{self.extension_id}:{request.wallet_id}:{request.amount_sat}:"
|
||||
f"{request.memo}:{time.time_ns()}:{entropy}"
|
||||
from lnbits.core.models.payments import CreateInvoice
|
||||
from lnbits.core.services.payments import create_payment_request
|
||||
# todo: security stuff here
|
||||
payment = await create_payment_request(
|
||||
request.wallet_id,
|
||||
CreateInvoice(
|
||||
amount=request.amount_sat,
|
||||
unit=request.currency or "sat",
|
||||
memo=request.memo,
|
||||
extra=request.extra,
|
||||
),
|
||||
)
|
||||
payment_hash = hashlib.sha256(invoice_seed.encode()).hexdigest()
|
||||
return CreateInvoiceResponse(
|
||||
payment_hash=payment_hash,
|
||||
payment_request=f"lnbits-prototype-invoice:{payment_hash}",
|
||||
checking_id=f"{self.extension_id}:{payment_hash}",
|
||||
payment_hash=payment.payment_hash,
|
||||
payment_request=payment.payment_request or payment.bolt11,
|
||||
checking_id=payment.checking_id,
|
||||
)
|
||||
|
||||
async def wallet_list_user_wallets(
|
||||
|
||||
Reference in New Issue
Block a user