Browse Source

after rebase clean-up

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
SomberNight 6 years ago
committed by ThomasV
parent
commit
c0ae7b5534
  1. 4
      electrum/lnbase.py
  2. 8
      electrum/lnchan.py
  3. 5
      electrum/lnchannelverifier.py
  4. 4
      electrum/lnrouter.py
  5. 1
      electrum/lnwatcher.py
  6. 7
      electrum/lnworker.py
  7. 22
      electrum/tests/test_lnchan.py

4
electrum/lnbase.py

@ -16,7 +16,7 @@ import sys
import aiorpcx
from .crypto import sha256
from .crypto import sha256, sha256d
from . import bitcoin
from . import ecc
from .ecc import sig_string_from_r_and_s, get_r_and_s_from_sig_string
@ -868,7 +868,7 @@ class Peer(PrintError):
bitcoin_key_2=bitcoin_keys[1]
)
to_hash = chan_ann[256+2:]
h = bitcoin.Hash(to_hash)
h = sha256d(to_hash)
bitcoin_signature = ecc.ECPrivkey(chan.config[LOCAL].multisig_key.privkey).sign(h, sig_string_from_r_and_s, get_r_and_s_from_sig_string)
node_signature = ecc.ECPrivkey(self.privkey).sign(h, sig_string_from_r_and_s, get_r_and_s_from_sig_string)
self.send_message("announcement_signatures",

8
electrum/lnchan.py

@ -29,9 +29,9 @@ from enum import Enum, auto
from typing import Optional, Dict, List, Tuple
from .util import bfh, PrintError, bh2u
from .bitcoin import Hash, TYPE_SCRIPT, TYPE_ADDRESS
from .bitcoin import TYPE_SCRIPT, TYPE_ADDRESS
from .bitcoin import redeem_script_to_address
from .crypto import sha256
from .crypto import sha256, sha256d
from . import ecc
from .lnutil import Outpoint, LocalConfig, RemoteConfig, Keypair, OnlyPubkeyKeypair, ChannelConstraints, RevocationStore, EncumberedTransaction
from .lnutil import get_per_commitment_secret_from_seed
@ -328,7 +328,7 @@ class Channel(PrintError):
pending_local_commitment = self.pending_local_commitment
preimage_hex = pending_local_commitment.serialize_preimage(0)
pre_hash = Hash(bfh(preimage_hex))
pre_hash = sha256d(bfh(preimage_hex))
if not ecc.verify_signature(self.config[REMOTE].multisig_key.pubkey, sig, pre_hash):
raise Exception('failed verifying signature of our updated commitment transaction: ' + bh2u(sig) + ' preimage is ' + preimage_hex)
@ -357,7 +357,7 @@ class Channel(PrintError):
def verify_htlc(self, htlc, htlc_sigs, we_receive):
_, this_point, _ = self.points
_script, htlc_tx = make_htlc_tx_with_open_channel(self, this_point, True, we_receive, self.pending_local_commitment, htlc)
pre_hash = Hash(bfh(htlc_tx.serialize_preimage(0)))
pre_hash = sha256d(bfh(htlc_tx.serialize_preimage(0)))
remote_htlc_pubkey = derive_pubkey(self.config[REMOTE].htlc_basepoint.pubkey, this_point)
for idx, sig in enumerate(htlc_sigs):
if ecc.verify_signature(remote_htlc_pubkey, sig, pre_hash):

5
electrum/lnchannelverifier.py

@ -38,6 +38,7 @@ from .lnutil import invert_short_channel_id, funding_output_script_from_keys
from .verifier import verify_tx_is_in_block, MerkleVerificationFailure
from .transaction import Transaction
from .interface import GracefulDisconnect
from .crypto import sha256d
if TYPE_CHECKING:
from .network import Network
@ -185,7 +186,7 @@ class LNChannelVerifier(NetworkJobOnDefaultServer):
def verify_sigs_for_channel_announcement(chan_ann: dict) -> bool:
msg_bytes = lnbase.gen_msg('channel_announcement', **chan_ann)
pre_hash = msg_bytes[2+256:]
h = bitcoin.Hash(pre_hash)
h = sha256d(pre_hash)
pubkeys = [chan_ann['node_id_1'], chan_ann['node_id_2'], chan_ann['bitcoin_key_1'], chan_ann['bitcoin_key_2']]
sigs = [chan_ann['node_signature_1'], chan_ann['node_signature_2'], chan_ann['bitcoin_signature_1'], chan_ann['bitcoin_signature_2']]
for pubkey, sig in zip(pubkeys, sigs):
@ -197,7 +198,7 @@ def verify_sigs_for_channel_announcement(chan_ann: dict) -> bool:
def verify_sig_for_channel_update(chan_upd: dict, node_id: bytes) -> bool:
msg_bytes = lnbase.gen_msg('channel_update', **chan_upd)
pre_hash = msg_bytes[2+64:]
h = bitcoin.Hash(pre_hash)
h = sha256d(pre_hash)
sig = chan_upd['signature']
if not ecc.verify_signature(node_id, sig, h):
return False

4
electrum/lnrouter.py

@ -37,7 +37,7 @@ from . import constants
from .util import PrintError, bh2u, profiler, get_headers_dir, bfh, is_ip_address, list_enabled_bits
from .storage import JsonDB
from .lnchannelverifier import LNChannelVerifier, verify_sig_for_channel_update
from .crypto import Hash
from .crypto import sha256d
from . import ecc
from .lnutil import LN_GLOBAL_FEATURES_KNOWN_SET, LNPeerAddr, NUM_MAX_EDGES_IN_PAYMENT_PATH
@ -416,7 +416,7 @@ class ChannelDB(JsonDB):
def on_node_announcement(self, msg_payload):
pubkey = msg_payload['node_id']
signature = msg_payload['signature']
h = Hash(msg_payload['raw'][66:])
h = sha256d(msg_payload['raw'][66:])
if not ecc.verify_signature(pubkey, signature, h):
return
old_node_info = self.nodes.get(pubkey, None)

1
electrum/lnwatcher.py

@ -7,6 +7,7 @@ from typing import NamedTuple, Iterable, TYPE_CHECKING
import os
from collections import defaultdict
import asyncio
import jsonrpclib
from .util import PrintError, bh2u, bfh, log_exceptions, ignore_exceptions

7
electrum/lnworker.py

@ -17,9 +17,10 @@ import dns.exception
from . import constants
from . import keystore
from . import bitcoin
from .keystore import BIP32_KeyStore
from .bitcoin import sha256, COIN
from .bitcoin import COIN
from .crypto import sha256
from .bip32 import bip32_root
from .util import bh2u, bfh, PrintError, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions
from .lntransport import LNResponderTransport
from .lnbase import Peer
@ -84,7 +85,7 @@ class LNWorker(PrintError):
# TODO derive this deterministically from wallet.keystore at keystore generation time
# probably along a hardened path ( lnd-equivalent would be m/1017'/coinType'/ )
seed = os.urandom(32)
xprv, xpub = bitcoin.bip32_root(seed, xtype='standard')
xprv, xpub = bip32_root(seed, xtype='standard')
self.wallet.storage.put('lightning_privkey2', xprv)
self.wallet.storage.write()
return keystore.from_xprv(xprv)

22
electrum/tests/test_lnchan.py

@ -20,14 +20,14 @@
# THE SOFTWARE.
import unittest
import electrum.bitcoin as bitcoin
import electrum.lnbase as lnbase
import electrum.lnchan as lnchan
import electrum.lnutil as lnutil
import electrum.util as util
import os
import binascii
from electrum import bitcoin
from electrum import lnbase
from electrum import lnchan
from electrum import lnutil
from electrum import bip32 as bip32_utils
from electrum.lnutil import SENT, LOCAL, REMOTE, RECEIVED
one_bitcoin_in_msat = bitcoin.COIN * 1000
@ -96,9 +96,9 @@ def create_channel_state(funding_txid, funding_index, funding_sat, local_feerate
}
def bip32(sequence):
xprv, xpub = bitcoin.bip32_root(b"9dk", 'standard')
xprv, xpub = bitcoin.bip32_private_derivation(xprv, "m/", sequence)
xtype, depth, fingerprint, child_number, c, k = bitcoin.deserialize_xprv(xprv)
xprv, xpub = bip32_utils.bip32_root(b"9dk", 'standard')
xprv, xpub = bip32_utils.bip32_private_derivation(xprv, "m/", sequence)
xtype, depth, fingerprint, child_number, c, k = bip32_utils.deserialize_xprv(xprv)
assert len(k) == 32
assert type(k) is bytes
return k
@ -536,13 +536,13 @@ class TestChanReserve(unittest.TestCase):
force_state_transition(self.alice_channel, self.bob_channel)
self.check_bals(one_bitcoin_in_msat*3\
- self.alice_channel.pending_local_fee,
one_bitocin_in_msat*5)
one_bitcoin_in_msat*5)
self.bob_channel.settle_htlc(paymentPreimage, bob_idx)
self.alice_channel.receive_htlc_settle(paymentPreimage, alice_idx)
force_state_transition(self.alice_channel, self.bob_channel)
self.check_bals(one_bitcoin_in_msat*3\
- self.alice_channel.pending_local_fee,
one_bitocin_in_msat*7)
one_bitcoin_in_msat*7)
# And now let Bob add an HTLC of 1 BTC. This will take Bob's balance
# all the way down to his channel reserve, but since he is not paying
# the fee this is okay.
@ -552,7 +552,7 @@ class TestChanReserve(unittest.TestCase):
force_state_transition(self.alice_channel, self.bob_channel)
self.check_bals(one_bitcoin_in_msat*3\
- self.alice_channel.pending_local_fee,
one_bitocin_in_msat*6)
one_bitcoin_in_msat*6)
def check_bals(self, amt1, amt2):
self.assertEqual(self.alice_channel.available_to_spend(LOCAL), amt1)

Loading…
Cancel
Save