mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
after rebase clean-up
This commit is contained in:
parent
7e76e82152
commit
c0ae7b5534
7 changed files with 27 additions and 24 deletions
|
@ -16,7 +16,7 @@ import sys
|
||||||
|
|
||||||
import aiorpcx
|
import aiorpcx
|
||||||
|
|
||||||
from .crypto import sha256
|
from .crypto import sha256, sha256d
|
||||||
from . import bitcoin
|
from . import bitcoin
|
||||||
from . import ecc
|
from . import ecc
|
||||||
from .ecc import sig_string_from_r_and_s, get_r_and_s_from_sig_string
|
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]
|
bitcoin_key_2=bitcoin_keys[1]
|
||||||
)
|
)
|
||||||
to_hash = chan_ann[256+2:]
|
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)
|
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)
|
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",
|
self.send_message("announcement_signatures",
|
||||||
|
|
|
@ -29,9 +29,9 @@ from enum import Enum, auto
|
||||||
from typing import Optional, Dict, List, Tuple
|
from typing import Optional, Dict, List, Tuple
|
||||||
|
|
||||||
from .util import bfh, PrintError, bh2u
|
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 .bitcoin import redeem_script_to_address
|
||||||
from .crypto import sha256
|
from .crypto import sha256, sha256d
|
||||||
from . import ecc
|
from . import ecc
|
||||||
from .lnutil import Outpoint, LocalConfig, RemoteConfig, Keypair, OnlyPubkeyKeypair, ChannelConstraints, RevocationStore, EncumberedTransaction
|
from .lnutil import Outpoint, LocalConfig, RemoteConfig, Keypair, OnlyPubkeyKeypair, ChannelConstraints, RevocationStore, EncumberedTransaction
|
||||||
from .lnutil import get_per_commitment_secret_from_seed
|
from .lnutil import get_per_commitment_secret_from_seed
|
||||||
|
@ -328,7 +328,7 @@ class Channel(PrintError):
|
||||||
|
|
||||||
pending_local_commitment = self.pending_local_commitment
|
pending_local_commitment = self.pending_local_commitment
|
||||||
preimage_hex = pending_local_commitment.serialize_preimage(0)
|
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):
|
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)
|
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):
|
def verify_htlc(self, htlc, htlc_sigs, we_receive):
|
||||||
_, this_point, _ = self.points
|
_, this_point, _ = self.points
|
||||||
_script, htlc_tx = make_htlc_tx_with_open_channel(self, this_point, True, we_receive, self.pending_local_commitment, htlc)
|
_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)
|
remote_htlc_pubkey = derive_pubkey(self.config[REMOTE].htlc_basepoint.pubkey, this_point)
|
||||||
for idx, sig in enumerate(htlc_sigs):
|
for idx, sig in enumerate(htlc_sigs):
|
||||||
if ecc.verify_signature(remote_htlc_pubkey, sig, pre_hash):
|
if ecc.verify_signature(remote_htlc_pubkey, sig, pre_hash):
|
||||||
|
|
|
@ -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 .verifier import verify_tx_is_in_block, MerkleVerificationFailure
|
||||||
from .transaction import Transaction
|
from .transaction import Transaction
|
||||||
from .interface import GracefulDisconnect
|
from .interface import GracefulDisconnect
|
||||||
|
from .crypto import sha256d
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .network import Network
|
from .network import Network
|
||||||
|
@ -185,7 +186,7 @@ class LNChannelVerifier(NetworkJobOnDefaultServer):
|
||||||
def verify_sigs_for_channel_announcement(chan_ann: dict) -> bool:
|
def verify_sigs_for_channel_announcement(chan_ann: dict) -> bool:
|
||||||
msg_bytes = lnbase.gen_msg('channel_announcement', **chan_ann)
|
msg_bytes = lnbase.gen_msg('channel_announcement', **chan_ann)
|
||||||
pre_hash = msg_bytes[2+256:]
|
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']]
|
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']]
|
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):
|
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:
|
def verify_sig_for_channel_update(chan_upd: dict, node_id: bytes) -> bool:
|
||||||
msg_bytes = lnbase.gen_msg('channel_update', **chan_upd)
|
msg_bytes = lnbase.gen_msg('channel_update', **chan_upd)
|
||||||
pre_hash = msg_bytes[2+64:]
|
pre_hash = msg_bytes[2+64:]
|
||||||
h = bitcoin.Hash(pre_hash)
|
h = sha256d(pre_hash)
|
||||||
sig = chan_upd['signature']
|
sig = chan_upd['signature']
|
||||||
if not ecc.verify_signature(node_id, sig, h):
|
if not ecc.verify_signature(node_id, sig, h):
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -37,7 +37,7 @@ from . import constants
|
||||||
from .util import PrintError, bh2u, profiler, get_headers_dir, bfh, is_ip_address, list_enabled_bits
|
from .util import PrintError, bh2u, profiler, get_headers_dir, bfh, is_ip_address, list_enabled_bits
|
||||||
from .storage import JsonDB
|
from .storage import JsonDB
|
||||||
from .lnchannelverifier import LNChannelVerifier, verify_sig_for_channel_update
|
from .lnchannelverifier import LNChannelVerifier, verify_sig_for_channel_update
|
||||||
from .crypto import Hash
|
from .crypto import sha256d
|
||||||
from . import ecc
|
from . import ecc
|
||||||
from .lnutil import LN_GLOBAL_FEATURES_KNOWN_SET, LNPeerAddr, NUM_MAX_EDGES_IN_PAYMENT_PATH
|
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):
|
def on_node_announcement(self, msg_payload):
|
||||||
pubkey = msg_payload['node_id']
|
pubkey = msg_payload['node_id']
|
||||||
signature = msg_payload['signature']
|
signature = msg_payload['signature']
|
||||||
h = Hash(msg_payload['raw'][66:])
|
h = sha256d(msg_payload['raw'][66:])
|
||||||
if not ecc.verify_signature(pubkey, signature, h):
|
if not ecc.verify_signature(pubkey, signature, h):
|
||||||
return
|
return
|
||||||
old_node_info = self.nodes.get(pubkey, None)
|
old_node_info = self.nodes.get(pubkey, None)
|
||||||
|
|
|
@ -7,6 +7,7 @@ from typing import NamedTuple, Iterable, TYPE_CHECKING
|
||||||
import os
|
import os
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import jsonrpclib
|
import jsonrpclib
|
||||||
|
|
||||||
from .util import PrintError, bh2u, bfh, log_exceptions, ignore_exceptions
|
from .util import PrintError, bh2u, bfh, log_exceptions, ignore_exceptions
|
||||||
|
|
|
@ -17,9 +17,10 @@ import dns.exception
|
||||||
|
|
||||||
from . import constants
|
from . import constants
|
||||||
from . import keystore
|
from . import keystore
|
||||||
from . import bitcoin
|
|
||||||
from .keystore import BIP32_KeyStore
|
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 .util import bh2u, bfh, PrintError, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions
|
||||||
from .lntransport import LNResponderTransport
|
from .lntransport import LNResponderTransport
|
||||||
from .lnbase import Peer
|
from .lnbase import Peer
|
||||||
|
@ -84,7 +85,7 @@ class LNWorker(PrintError):
|
||||||
# TODO derive this deterministically from wallet.keystore at keystore generation time
|
# TODO derive this deterministically from wallet.keystore at keystore generation time
|
||||||
# probably along a hardened path ( lnd-equivalent would be m/1017'/coinType'/ )
|
# probably along a hardened path ( lnd-equivalent would be m/1017'/coinType'/ )
|
||||||
seed = os.urandom(32)
|
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.put('lightning_privkey2', xprv)
|
||||||
self.wallet.storage.write()
|
self.wallet.storage.write()
|
||||||
return keystore.from_xprv(xprv)
|
return keystore.from_xprv(xprv)
|
||||||
|
|
|
@ -20,14 +20,14 @@
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
|
|
||||||
import unittest
|
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 os
|
||||||
import binascii
|
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
|
from electrum.lnutil import SENT, LOCAL, REMOTE, RECEIVED
|
||||||
|
|
||||||
one_bitcoin_in_msat = bitcoin.COIN * 1000
|
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):
|
def bip32(sequence):
|
||||||
xprv, xpub = bitcoin.bip32_root(b"9dk", 'standard')
|
xprv, xpub = bip32_utils.bip32_root(b"9dk", 'standard')
|
||||||
xprv, xpub = bitcoin.bip32_private_derivation(xprv, "m/", sequence)
|
xprv, xpub = bip32_utils.bip32_private_derivation(xprv, "m/", sequence)
|
||||||
xtype, depth, fingerprint, child_number, c, k = bitcoin.deserialize_xprv(xprv)
|
xtype, depth, fingerprint, child_number, c, k = bip32_utils.deserialize_xprv(xprv)
|
||||||
assert len(k) == 32
|
assert len(k) == 32
|
||||||
assert type(k) is bytes
|
assert type(k) is bytes
|
||||||
return k
|
return k
|
||||||
|
@ -536,13 +536,13 @@ class TestChanReserve(unittest.TestCase):
|
||||||
force_state_transition(self.alice_channel, self.bob_channel)
|
force_state_transition(self.alice_channel, self.bob_channel)
|
||||||
self.check_bals(one_bitcoin_in_msat*3\
|
self.check_bals(one_bitcoin_in_msat*3\
|
||||||
- self.alice_channel.pending_local_fee,
|
- 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.bob_channel.settle_htlc(paymentPreimage, bob_idx)
|
||||||
self.alice_channel.receive_htlc_settle(paymentPreimage, alice_idx)
|
self.alice_channel.receive_htlc_settle(paymentPreimage, alice_idx)
|
||||||
force_state_transition(self.alice_channel, self.bob_channel)
|
force_state_transition(self.alice_channel, self.bob_channel)
|
||||||
self.check_bals(one_bitcoin_in_msat*3\
|
self.check_bals(one_bitcoin_in_msat*3\
|
||||||
- self.alice_channel.pending_local_fee,
|
- 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
|
# 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
|
# all the way down to his channel reserve, but since he is not paying
|
||||||
# the fee this is okay.
|
# the fee this is okay.
|
||||||
|
@ -552,7 +552,7 @@ class TestChanReserve(unittest.TestCase):
|
||||||
force_state_transition(self.alice_channel, self.bob_channel)
|
force_state_transition(self.alice_channel, self.bob_channel)
|
||||||
self.check_bals(one_bitcoin_in_msat*3\
|
self.check_bals(one_bitcoin_in_msat*3\
|
||||||
- self.alice_channel.pending_local_fee,
|
- self.alice_channel.pending_local_fee,
|
||||||
one_bitocin_in_msat*6)
|
one_bitcoin_in_msat*6)
|
||||||
|
|
||||||
def check_bals(self, amt1, amt2):
|
def check_bals(self, amt1, amt2):
|
||||||
self.assertEqual(self.alice_channel.available_to_spend(LOCAL), amt1)
|
self.assertEqual(self.alice_channel.available_to_spend(LOCAL), amt1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue