mirror of
https://github.com/aljazceru/nutshell.git
synced 2026-01-05 09:54:21 +01:00
Dev: Update ruff precommit hooks (#434)
* update ruff * test * update ruff * only ruff check * CI rename
This commit is contained in:
@@ -68,6 +68,7 @@ def hash_to_curve(message: bytes) -> PublicKey:
|
||||
point = PublicKey(b"\x02" + _hash, raw=True)
|
||||
except Exception:
|
||||
msg_to_hash = _hash
|
||||
print(_hash)
|
||||
return point
|
||||
|
||||
|
||||
@@ -101,18 +102,14 @@ def hash_to_curve_domain_separated(message: bytes) -> PublicKey:
|
||||
raise ValueError("No valid point found")
|
||||
|
||||
|
||||
def step1_alice(
|
||||
secret_msg: str, blinding_factor: Optional[PrivateKey] = None
|
||||
) -> tuple[PublicKey, PrivateKey]:
|
||||
def step1_alice(secret_msg: str, blinding_factor: Optional[PrivateKey] = None) -> tuple[PublicKey, PrivateKey]:
|
||||
Y: PublicKey = hash_to_curve(secret_msg.encode("utf-8"))
|
||||
r = blinding_factor or PrivateKey()
|
||||
B_: PublicKey = Y + r.pubkey # type: ignore
|
||||
return B_, r
|
||||
|
||||
|
||||
def step1_alice_domain_separated(
|
||||
secret_msg: str, blinding_factor: Optional[PrivateKey] = None
|
||||
) -> tuple[PublicKey, PrivateKey]:
|
||||
def step1_alice_domain_separated(secret_msg: str, blinding_factor: Optional[PrivateKey] = None) -> tuple[PublicKey, PrivateKey]:
|
||||
Y: PublicKey = hash_to_curve_domain_separated(secret_msg.encode("utf-8"))
|
||||
r = blinding_factor or PrivateKey()
|
||||
B_: PublicKey = Y + r.pubkey # type: ignore
|
||||
@@ -151,9 +148,7 @@ def hash_e(*publickeys: PublicKey) -> bytes:
|
||||
return e
|
||||
|
||||
|
||||
def step2_bob_dleq(
|
||||
B_: PublicKey, a: PrivateKey, p_bytes: bytes = b""
|
||||
) -> Tuple[PrivateKey, PrivateKey]:
|
||||
def step2_bob_dleq(B_: PublicKey, a: PrivateKey, p_bytes: bytes = b"") -> Tuple[PrivateKey, PrivateKey]:
|
||||
if p_bytes:
|
||||
# deterministic p for testing
|
||||
p = PrivateKey(privkey=p_bytes, raw=True)
|
||||
@@ -174,9 +169,7 @@ def step2_bob_dleq(
|
||||
return epk, spk
|
||||
|
||||
|
||||
def alice_verify_dleq(
|
||||
B_: PublicKey, C_: PublicKey, e: PrivateKey, s: PrivateKey, A: PublicKey
|
||||
) -> bool:
|
||||
def alice_verify_dleq(B_: PublicKey, C_: PublicKey, e: PrivateKey, s: PrivateKey, A: PublicKey) -> bool:
|
||||
R1 = s.pubkey - A.mult(e) # type: ignore
|
||||
R2 = B_.mult(s) - C_.mult(e) # type: ignore
|
||||
e_bytes = e.private_key
|
||||
|
||||
@@ -27,7 +27,8 @@ BLINK_MAX_FEE_PERCENT = 0.5
|
||||
|
||||
|
||||
class BlinkWallet(LightningBackend):
|
||||
"""https://dev.blink.sv/
|
||||
"""
|
||||
https://dev.blink.sv/
|
||||
Create API Key at: https://dashboard.blink.sv/
|
||||
"""
|
||||
|
||||
@@ -54,10 +55,7 @@ class BlinkWallet(LightningBackend):
|
||||
try:
|
||||
r = await self.client.post(
|
||||
url=self.endpoint,
|
||||
data=(
|
||||
'{"query":"query me { me { defaultAccount { wallets { id'
|
||||
' walletCurrency balance }}}}", "variables":{}}'
|
||||
),
|
||||
data=('{"query":"query me { me { defaultAccount { wallets { id' ' walletCurrency balance }}}}", "variables":{}}'),
|
||||
)
|
||||
r.raise_for_status()
|
||||
except Exception as exc:
|
||||
@@ -71,9 +69,7 @@ class BlinkWallet(LightningBackend):
|
||||
resp: dict = r.json()
|
||||
except Exception:
|
||||
return StatusResponse(
|
||||
error_message=(
|
||||
f"Received invalid response from {self.endpoint}: {r.text}"
|
||||
),
|
||||
error_message=(f"Received invalid response from {self.endpoint}: {r.text}"),
|
||||
balance=0,
|
||||
)
|
||||
|
||||
@@ -137,9 +133,7 @@ class BlinkWallet(LightningBackend):
|
||||
|
||||
resp = r.json()
|
||||
assert resp, "invalid response"
|
||||
payment_request = resp["data"]["lnInvoiceCreateOnBehalfOfRecipient"]["invoice"][
|
||||
"paymentRequest"
|
||||
]
|
||||
payment_request = resp["data"]["lnInvoiceCreateOnBehalfOfRecipient"]["invoice"]["paymentRequest"]
|
||||
checking_id = payment_request
|
||||
|
||||
return InvoiceResponse(
|
||||
@@ -148,9 +142,7 @@ class BlinkWallet(LightningBackend):
|
||||
payment_request=payment_request,
|
||||
)
|
||||
|
||||
async def pay_invoice(
|
||||
self, quote: MeltQuote, fee_limit_msat: int
|
||||
) -> PaymentResponse:
|
||||
async def pay_invoice(self, quote: MeltQuote, fee_limit_msat: int) -> PaymentResponse:
|
||||
variables = {
|
||||
"input": {
|
||||
"paymentRequest": quote.request,
|
||||
@@ -185,9 +177,7 @@ class BlinkWallet(LightningBackend):
|
||||
return PaymentResponse(ok=False, error_message=str(e))
|
||||
|
||||
resp: dict = r.json()
|
||||
paid = self.payment_execution_statuses[
|
||||
resp["data"]["lnInvoicePaymentSend"]["status"]
|
||||
]
|
||||
paid = self.payment_execution_statuses[resp["data"]["lnInvoicePaymentSend"]["status"]]
|
||||
fee = resp["data"]["lnInvoicePaymentSend"]["transaction"]["settlementFee"]
|
||||
checking_id = quote.request
|
||||
|
||||
@@ -222,9 +212,7 @@ class BlinkWallet(LightningBackend):
|
||||
return PaymentStatus(paid=None)
|
||||
resp: dict = r.json()
|
||||
if resp["data"]["lnInvoicePaymentStatus"]["errors"]:
|
||||
logger.error(
|
||||
"Blink Error", resp["data"]["lnInvoicePaymentStatus"]["errors"]
|
||||
)
|
||||
logger.error("Blink Error", resp["data"]["lnInvoicePaymentStatus"]["errors"])
|
||||
return PaymentStatus(paid=None)
|
||||
paid = self.invoice_statuses[resp["data"]["lnInvoicePaymentStatus"]["status"]]
|
||||
return PaymentStatus(paid=paid)
|
||||
@@ -267,19 +255,11 @@ class BlinkWallet(LightningBackend):
|
||||
|
||||
resp: dict = r.json()
|
||||
# no result found
|
||||
if not resp["data"]["me"]["defaultAccount"]["walletById"][
|
||||
"transactionsByPaymentHash"
|
||||
]:
|
||||
if not resp["data"]["me"]["defaultAccount"]["walletById"]["transactionsByPaymentHash"]:
|
||||
return PaymentStatus(paid=None)
|
||||
|
||||
paid = self.payment_statuses[
|
||||
resp["data"]["me"]["defaultAccount"]["walletById"][
|
||||
"transactionsByPaymentHash"
|
||||
][0]["status"]
|
||||
]
|
||||
fee = resp["data"]["me"]["defaultAccount"]["walletById"][
|
||||
"transactionsByPaymentHash"
|
||||
][0]["settlementFee"]
|
||||
paid = self.payment_statuses[resp["data"]["me"]["defaultAccount"]["walletById"]["transactionsByPaymentHash"][0]["status"]]
|
||||
fee = resp["data"]["me"]["defaultAccount"]["walletById"]["transactionsByPaymentHash"][0]["settlementFee"]
|
||||
|
||||
return PaymentStatus(
|
||||
paid=paid,
|
||||
@@ -326,9 +306,7 @@ class BlinkWallet(LightningBackend):
|
||||
|
||||
fees_response_msat = int(resp["data"]["lnInvoiceFeeProbe"]["amount"]) * 1000
|
||||
# we either take fee_msat_response or the BLINK_MAX_FEE_PERCENT, whichever is higher
|
||||
fees_msat = max(
|
||||
fees_response_msat, math.ceil(amount_msat * BLINK_MAX_FEE_PERCENT)
|
||||
)
|
||||
fees_msat = max(fees_response_msat, math.ceil(amount_msat * BLINK_MAX_FEE_PERCENT))
|
||||
|
||||
fees = Amount(unit=Unit.msat, amount=fees_msat)
|
||||
amount = Amount(unit=Unit.msat, amount=amount_msat)
|
||||
|
||||
Reference in New Issue
Block a user