fix: FakeWallet, bolt11 payment_secret is not the preimage (#3084)
This commit is contained in:
parent
681385e2a2
commit
6f611461f2
1 changed files with 10 additions and 6 deletions
|
|
@ -2,7 +2,7 @@ import asyncio
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from os import urandom
|
from os import urandom
|
||||||
from typing import AsyncGenerator, Dict, Optional, Set
|
from typing import AsyncGenerator, Optional
|
||||||
|
|
||||||
from bolt11 import (
|
from bolt11 import (
|
||||||
Bolt11,
|
Bolt11,
|
||||||
|
|
@ -34,8 +34,8 @@ class FakeWallet(Wallet):
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.queue: asyncio.Queue = asyncio.Queue(0)
|
self.queue: asyncio.Queue = asyncio.Queue(0)
|
||||||
self.payment_secrets: Dict[str, str] = {}
|
self.payment_secrets: dict[str, str] = {}
|
||||||
self.paid_invoices: Set[str] = set()
|
self.paid_invoices: set[str] = set()
|
||||||
self.secret = settings.fake_wallet_secret
|
self.secret = settings.fake_wallet_secret
|
||||||
self.privkey = fake_privkey(self.secret)
|
self.privkey = fake_privkey(self.secret)
|
||||||
|
|
||||||
|
|
@ -80,11 +80,12 @@ class FakeWallet(Wallet):
|
||||||
secret = urandom(32).hex()
|
secret = urandom(32).hex()
|
||||||
tags.add(TagChar.payment_secret, secret)
|
tags.add(TagChar.payment_secret, secret)
|
||||||
|
|
||||||
payment_hash = sha256(secret.encode()).hexdigest()
|
preimage = urandom(32)
|
||||||
|
payment_hash = sha256(preimage).hexdigest()
|
||||||
|
|
||||||
tags.add(TagChar.payment_hash, payment_hash)
|
tags.add(TagChar.payment_hash, payment_hash)
|
||||||
|
|
||||||
self.payment_secrets[payment_hash] = secret
|
self.payment_secrets[payment_hash] = preimage.hex()
|
||||||
|
|
||||||
bolt11 = Bolt11(
|
bolt11 = Bolt11(
|
||||||
currency="bc",
|
currency="bc",
|
||||||
|
|
@ -96,7 +97,10 @@ class FakeWallet(Wallet):
|
||||||
payment_request = encode(bolt11, self.privkey)
|
payment_request = encode(bolt11, self.privkey)
|
||||||
|
|
||||||
return InvoiceResponse(
|
return InvoiceResponse(
|
||||||
ok=True, checking_id=payment_hash, payment_request=payment_request
|
ok=True,
|
||||||
|
checking_id=payment_hash,
|
||||||
|
payment_request=payment_request,
|
||||||
|
# preimage=preimage.hex(),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def pay_invoice(self, bolt11: str, _: int) -> PaymentResponse:
|
async def pay_invoice(self, bolt11: str, _: int) -> PaymentResponse:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue