Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Dev: Update ruff precommit hooks" #436

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
type: string

jobs:
format:
formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -26,8 +26,8 @@ jobs:
cache: "poetry"
- name: Install packages
run: poetry install
- name: Ruff check
run: make ruff-check
- name: Check black
run: make black-check
mypy:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Nutshell CI
on:
push:
branches:
Expand Down
12 changes: 8 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude: "^cashu/nostr/.*"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -12,12 +12,16 @@ repos:
- id: debug-statements
- id: mixed-line-ending
- id: check-case-conflict
# - repo: https://github.com/psf/black
# rev: 23.11.0
# hooks:
# - id: black
# args: [--line-length=150]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.1
rev: v0.0.283
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.0
hooks:
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ ruff:
ruff-check:
poetry run ruff check .

black:
poetry run black .

black-check:
poetry run black . --check

mypy:
poetry run mypy cashu --check-untyped-defs

format: ruff
format: black ruff

check: ruff-check mypy
check: black-check ruff-check mypy

clean:
rm -r cashu.egg-info/ || true
Expand Down
17 changes: 12 additions & 5 deletions cashu/core/crypto/b_dhke.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def hash_to_curve(message: bytes) -> PublicKey:
point = PublicKey(b"\x02" + _hash, raw=True)
except Exception:
msg_to_hash = _hash
print(_hash)
return point


Expand Down Expand Up @@ -102,14 +101,18 @@ 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
Expand Down Expand Up @@ -148,7 +151,9 @@ 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)
Expand All @@ -169,7 +174,9 @@ def step2_bob_dleq(B_: PublicKey, a: PrivateKey, p_bytes: bytes = b"") -> Tuple[
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
Expand Down
46 changes: 34 additions & 12 deletions cashu/lightning/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@


class BlinkWallet(LightningBackend):
"""
https://dev.blink.sv/
"""https://dev.blink.sv/
Create API Key at: https://dashboard.blink.sv/
"""

Expand All @@ -55,7 +54,10 @@ async def status(self) -> StatusResponse:
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:
Expand All @@ -69,7 +71,9 @@ async def status(self) -> StatusResponse:
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,
)

Expand Down Expand Up @@ -133,7 +137,9 @@ async def create_invoice(

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(
Expand All @@ -142,7 +148,9 @@ async def create_invoice(
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,
Expand Down Expand Up @@ -177,7 +185,9 @@ async def pay_invoice(self, quote: MeltQuote, fee_limit_msat: int) -> PaymentRes
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

Expand Down Expand Up @@ -212,7 +222,9 @@ async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
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)
Expand Down Expand Up @@ -255,11 +267,19 @@ async def get_payment_status(self, checking_id: str) -> PaymentStatus:

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,
Expand Down Expand Up @@ -306,7 +326,9 @@ async def get_payment_quote(self, bolt11: str) -> PaymentQuoteResponse:

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)
Expand Down
Loading
Loading