bitcoin.py: rm bip340_tagged_hash (duplicated from electrum_ecc)
This commit is contained in:
@@ -28,6 +28,7 @@ import enum
|
||||
from enum import IntEnum, Enum
|
||||
|
||||
import electrum_ecc as ecc
|
||||
from electrum_ecc.util import bip340_tagged_hash
|
||||
|
||||
from .util import bfh, BitcoinException, assert_bytes, to_bytes, inv_dict, is_hex_str, classproperty
|
||||
from . import segwit_addr
|
||||
@@ -813,12 +814,6 @@ TapTreeLeaf = Tuple[int, bytes]
|
||||
TapTree = Union[TapTreeLeaf, Sequence['TapTree']]
|
||||
|
||||
|
||||
# FIXME just use electrum_ecc.util.bip340_tagged_hash instead
|
||||
def bip340_tagged_hash(tag: bytes, msg: bytes) -> bytes:
|
||||
# note: _libsecp256k1.secp256k1_tagged_sha256 benchmarks about 70% slower than this (on my machine)
|
||||
return sha256(sha256(tag) + sha256(tag) + msg)
|
||||
|
||||
|
||||
def taproot_tree_helper(script_tree: TapTree):
|
||||
if isinstance(script_tree, tuple):
|
||||
leaf_version, script = script_tree
|
||||
|
||||
@@ -12,6 +12,7 @@ import sys
|
||||
|
||||
import electrum_ecc as ecc
|
||||
from electrum_ecc import CURVE_ORDER, ecdsa_sig64_from_der_sig, ECPubkey, string_to_number
|
||||
from electrum_ecc.util import bip340_tagged_hash
|
||||
import attr
|
||||
|
||||
from .util import bfh, inv_dict, UserFacingException
|
||||
@@ -641,7 +642,7 @@ def derive_multisig_funding_key_if_we_opened(
|
||||
assert isinstance(nlocktime, int)
|
||||
nlocktime_bytes = int.to_bytes(nlocktime, length=4, byteorder="little", signed=False)
|
||||
node_id_prefix = remote_node_id_or_prefix[0:NODE_ID_PREFIX_LEN]
|
||||
funding_key = ecc.ECPrivkey(bitcoin.bip340_tagged_hash(
|
||||
funding_key = ecc.ECPrivkey(bip340_tagged_hash(
|
||||
tag=b"electrum/ln_multisig_funding_key/we_opened",
|
||||
msg=funding_root_secret + node_id_prefix + nlocktime_bytes,
|
||||
))
|
||||
@@ -665,7 +666,7 @@ def derive_multisig_funding_key_if_they_opened(
|
||||
assert isinstance(remote_funding_pubkey, bytes)
|
||||
assert len(remote_funding_pubkey) == 33
|
||||
node_id_prefix = remote_node_id_or_prefix[0:NODE_ID_PREFIX_LEN]
|
||||
funding_key = ecc.ECPrivkey(bitcoin.bip340_tagged_hash(
|
||||
funding_key = ecc.ECPrivkey(bip340_tagged_hash(
|
||||
tag=b"electrum/ln_multisig_funding_key/they_opened",
|
||||
msg=funding_root_secret + node_id_prefix + remote_funding_pubkey,
|
||||
))
|
||||
|
||||
@@ -41,6 +41,7 @@ import binascii
|
||||
import copy
|
||||
|
||||
import electrum_ecc as ecc
|
||||
from electrum_ecc.util import bip340_tagged_hash
|
||||
|
||||
from . import bitcoin, constants, segwit_addr, bip32
|
||||
from .bip32 import BIP32Node
|
||||
@@ -2319,7 +2320,7 @@ class PartialTransaction(Transaction):
|
||||
merkle_root = txin.tap_merkle_root or bytes()
|
||||
output_privkey_bytes = taproot_tweak_seckey(privkey_bytes, merkle_root)
|
||||
output_privkey = ecc.ECPrivkey(output_privkey_bytes)
|
||||
msg_hash = bitcoin.bip340_tagged_hash(b"TapSighash", pre_hash)
|
||||
msg_hash = bip340_tagged_hash(b"TapSighash", pre_hash)
|
||||
sig = output_privkey.schnorr_sign(msg_hash)
|
||||
sighash = txin.sighash if txin.sighash is not None else Sighash.DEFAULT
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user