electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit ab2e03fcb5c1540d71bd16cb9368605053654a66
parent 304c4b02221ddda3e5f5610c9b4058bbd7ec54e7
Author: Janus <ysangkok@gmail.com>
Date:   Wed, 11 Apr 2018 16:12:54 +0200

lnbase: use valid pubkeys in open_channel

Diffstat:
Mlib/lnbase.py | 19++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/lib/lnbase.py b/lib/lnbase.py @@ -15,9 +15,11 @@ import hashlib import hmac import cryptography.hazmat.primitives.ciphers.aead as AEAD -from electrum.bitcoin import public_key_from_private_key, ser_to_point, point_to_ser, string_to_number +from electrum.bitcoin import public_key_from_private_key, ser_to_point, point_to_ser, string_to_number, deserialize_privkey, EC_KEY +from electrum.constants import set_testnet from electrum.util import PrintError from electrum.wallet import Wallet +from electrum.storage import WalletStorage tcp_socket_timeout = 10 server_response_timeout = 60 @@ -108,7 +110,7 @@ def gen_msg(msg_type, **kwargs): except KeyError: param = 0 try: - param = param.to_bytes(length=leng, byteorder="big") + if not isinstance(param, bytes): param = param.to_bytes(length=leng, byteorder="big") except ValueError: raise Exception("{} does not fit in {} bytes".format(k, leng)) lengths[k] = len(param) @@ -209,6 +211,15 @@ def create_ephemeral_key(privkey): pub = privkey_to_pubkey(privkey) return (privkey[:32], pub) +def get_unused_public_keys(): + set_testnet() + WALLET = Wallet(WalletStorage(os.environ["HOME"] + "/.electrum/testnet/wallets/default_wallet")) + for str_address in WALLET.get_unused_addresses(): + pri, redeem_script = WALLET.export_private_key(str_address, None) + + typ, pri, compressed = deserialize_privkey(pri) + pubk = binascii.unhexlify(EC_KEY(pri).get_public_key(True)) + yield pubk class Peer(PrintError): @@ -330,7 +341,9 @@ class Peer(PrintError): # send init self.send_message(gen_msg("init", gflen=0, lflen=0)) - msg = gen_msg("open_channel") + pubkeys = get_unused_public_keys() + + msg = gen_msg("open_channel", funding_pubkey=next(pubkeys), revocation_basepoint=next(pubkeys), htlc_basepoint=next(pubkeys), payment_basepoint=next(pubkeys), delayed_payment_basepoint=next(pubkeys), first_per_commitment_point=next(pubkeys)) self.send_message(msg) # loop