From 9be6d6e732039ae8bacc19162a28ef339a836db6 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 25 Mar 2025 16:41:14 +0100 Subject: [PATCH] small fixes, imports, whitespace --- electrum/gui/qml/components/OpenChannelDialog.qml | 2 +- electrum/gui/qml/qewallet.py | 5 ++--- electrum/gui/qt/send_tab.py | 4 ++-- electrum/lntransport.py | 8 ++++++++ electrum/paymentrequest.py | 9 ++++----- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/electrum/gui/qml/components/OpenChannelDialog.qml b/electrum/gui/qml/components/OpenChannelDialog.qml index 7e82cd1a9..dfb056dbe 100644 --- a/electrum/gui/qml/components/OpenChannelDialog.qml +++ b/electrum/gui/qml/components/OpenChannelDialog.qml @@ -245,7 +245,7 @@ ElDialog { FlatButton { Layout.fillWidth: true - text: qsTr('Open Channel') + text: qsTr('Open Channel...') icon.source: '../../icons/confirmed.png' enabled: channelopener.valid onClicked: channelopener.openChannel() diff --git a/electrum/gui/qml/qewallet.py b/electrum/gui/qml/qewallet.py index e355547cc..c48cd3dd5 100644 --- a/electrum/gui/qml/qewallet.py +++ b/electrum/gui/qml/qewallet.py @@ -19,6 +19,7 @@ from electrum.lnutil import MIN_FUNDING_SAT from electrum.plugin import run_hook from electrum.wallet import Multisig_Wallet from electrum.crypto import pw_decode_with_version_and_mac +from electrum.fee_policy import FeePolicy, FixedFeePolicy from .auth import AuthMixin, auth_protect from .qeaddresslistmodel import QEAddressCoinListModel @@ -27,8 +28,6 @@ from .qeinvoicelistmodel import QEInvoiceListModel, QERequestListModel from .qetransactionlistmodel import QETransactionListModel from .qetypes import QEAmount from .util import QtEventListener, qt_event_listener -from ...lntransport import extract_nodeid -from ...fee_policy import FeePolicy if TYPE_CHECKING: from electrum.wallet import Abstract_Wallet @@ -843,7 +842,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener): except (NotEnoughFunds, NoDynamicFeeEstimates) as e: # Check if we had enough funds excluding fees, # if so, still provide opportunity to set lower fees. - fee_policy = FeePolicy('fixed:0') + fee_policy = FixedFeePolicy(0) tx = mktx(fee_policy) amount = tx.output_value() except NotEnoughFunds as e: diff --git a/electrum/gui/qt/send_tab.py b/electrum/gui/qt/send_tab.py index 461993fc5..4042c9b07 100644 --- a/electrum/gui/qt/send_tab.py +++ b/electrum/gui/qt/send_tab.py @@ -20,7 +20,7 @@ from electrum.network import TxBroadcastError, BestEffortRequestFailed from electrum.payment_identifier import (PaymentIdentifierType, PaymentIdentifier, invoice_from_payment_identifier, payment_identifier_from_invoice) from electrum.submarine_swaps import SwapServerError -from electrum.fee_policy import FeePolicy +from electrum.fee_policy import FeePolicy, FixedFeePolicy from .amountedit import AmountEdit, BTCAmountEdit, SizedFreezableLineEdit from .paytoedit import InvalidPaymentIdentifier @@ -264,7 +264,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger): except (NotEnoughFunds, NoDynamicFeeEstimates) as e: # Check if we had enough funds excluding fees, # if so, still provide opportunity to set lower fees. - tx = make_tx(FeePolicy('fixed:0')) + tx = make_tx(FixedFeePolicy(0)) except NotEnoughFunds as e: self.max_button.setChecked(False) text = self.wallet.get_text_not_enough_funds_mentioning_frozen() diff --git a/electrum/lntransport.py b/electrum/lntransport.py index b652beeda..59d9ac6be 100644 --- a/electrum/lntransport.py +++ b/electrum/lntransport.py @@ -45,12 +45,14 @@ class HandshakeState(object): self.h = sha256(self.h + data) return self.h + def get_nonce_bytes(n): """BOLT 8 requires the nonce to be 12 bytes, 4 bytes leading zeroes and 8 bytes little endian encoded 64 bit integer. """ return b"\x00"*4 + n.to_bytes(8, 'little') + def aead_encrypt(key: bytes, nonce: int, associated_data: bytes, data: bytes) -> bytes: nonce_bytes = get_nonce_bytes(nonce) return chacha20_poly1305_encrypt(key=key, @@ -58,6 +60,7 @@ def aead_encrypt(key: bytes, nonce: int, associated_data: bytes, data: bytes) -> associated_data=associated_data, data=data) + def aead_decrypt(key: bytes, nonce: int, associated_data: bytes, data: bytes) -> bytes: nonce_bytes = get_nonce_bytes(nonce) return chacha20_poly1305_decrypt(key=key, @@ -65,6 +68,7 @@ def aead_decrypt(key: bytes, nonce: int, associated_data: bytes, data: bytes) -> associated_data=associated_data, data=data) + def get_bolt8_hkdf(salt, ikm): """RFC5869 HKDF instantiated in the specific form used in Lightning BOLT 8: @@ -83,6 +87,7 @@ def get_bolt8_hkdf(salt, ikm): assert len(T1 + T2) == 64 return T1, T2 + def act1_initiator_message(hs, epriv, epub): ss = get_ecdh(epriv, hs.responder_pub) ck2, temp_k1 = get_bolt8_hkdf(hs.ck, ss) @@ -119,6 +124,7 @@ def split_host_port(host_port: str) -> Tuple[str, str]: # port returned as strin raise ConnStringFormatError('Port number must be decimal') return host, port + def extract_nodeid(connect_contents: str) -> Tuple[bytes, Optional[str]]: """Takes a connection-string-like str, and returns a tuple (node_id, rest), where rest is typically a host (with maybe port). Examples: @@ -144,6 +150,7 @@ def extract_nodeid(connect_contents: str) -> Tuple[bytes, Optional[str]]: raise ConnStringFormatError('Invalid node ID, must be 33 bytes and hexadecimal') return node_id, rest + class LNPeerAddr: # note: while not programmatically enforced, this class is meant to be *immutable* @@ -193,6 +200,7 @@ class LNPeerAddr: def __hash__(self): return hash((self.host, self.port, self.pubkey)) + class LNTransportBase: reader: StreamReader writer: StreamWriter diff --git a/electrum/paymentrequest.py b/electrum/paymentrequest.py index adba3b990..650b0e147 100644 --- a/electrum/paymentrequest.py +++ b/electrum/paymentrequest.py @@ -42,11 +42,10 @@ except ImportError: from . import bitcoin, constants, util, transaction, x509, rsakey from .util import bfh, make_aiohttp_session, error_text_bytes_to_safe_str, get_running_loop from .invoices import Invoice, get_id_from_onchain_outputs -from .crypto import sha256 from .bitcoin import address_to_script from .transaction import PartialTxOutput from .network import Network -from .logging import get_logger, Logger +from .logging import get_logger from .contacts import Contacts if TYPE_CHECKING: @@ -57,20 +56,19 @@ _logger = get_logger(__name__) REQUEST_HEADERS = {'Accept': 'application/bitcoin-paymentrequest', 'User-Agent': 'Electrum'} -ACK_HEADERS = {'Content-Type':'application/bitcoin-payment','Accept':'application/bitcoin-paymentack','User-Agent':'Electrum'} +ACK_HEADERS = {'Content-Type': 'application/bitcoin-payment', 'Accept': 'application/bitcoin-paymentack', 'User-Agent': 'Electrum'} ca_path = certifi.where() ca_list = None ca_keyID = None + def load_ca_list(): global ca_list, ca_keyID if ca_list is None: ca_list, ca_keyID = x509.load_certificates(ca_path) - - async def get_payment_request(url: str) -> 'PaymentRequest': u = urllib.parse.urlparse(url) error = None @@ -435,6 +433,7 @@ def check_ssl_config(config: 'SimpleConfig'): requestor = requestor[2:] return requestor + def sign_request_with_x509(pr, key_path, cert_path): from . import pem with open(key_path, 'r', encoding='utf-8') as f: