mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 00:41:31 +00:00
fix hash in make_offered_htlc
This commit is contained in:
parent
635d924dff
commit
b726d77bdc
2 changed files with 13 additions and 21 deletions
|
@ -134,16 +134,18 @@ def sha256d(x: Union[bytes, str]) -> bytes:
|
||||||
|
|
||||||
|
|
||||||
def hash_160(x: bytes) -> bytes:
|
def hash_160(x: bytes) -> bytes:
|
||||||
|
return ripemd(sha256(public_key))
|
||||||
|
|
||||||
|
def ripemd(x):
|
||||||
try:
|
try:
|
||||||
md = hashlib.new('ripemd160')
|
md = hashlib.new('ripemd160')
|
||||||
md.update(sha256(x))
|
md.update(x)
|
||||||
return md.digest()
|
return md.digest()
|
||||||
except BaseException:
|
except BaseException:
|
||||||
from . import ripemd
|
from . import ripemd
|
||||||
md = ripemd.new(sha256(x))
|
md = ripemd.new(x)
|
||||||
return md.digest()
|
return md.digest()
|
||||||
|
|
||||||
|
|
||||||
def hmac_oneshot(key: bytes, msg: bytes, digest) -> bytes:
|
def hmac_oneshot(key: bytes, msg: bytes, digest) -> bytes:
|
||||||
if hasattr(hmac, 'digest'):
|
if hasattr(hmac, 'digest'):
|
||||||
# requires python 3.7+; faster
|
# requires python 3.7+; faster
|
||||||
|
|
|
@ -266,24 +266,14 @@ def make_offered_htlc(revocation_pubkey, remote_htlcpubkey, local_htlcpubkey, pa
|
||||||
assert type(remote_htlcpubkey) is bytes
|
assert type(remote_htlcpubkey) is bytes
|
||||||
assert type(local_htlcpubkey) is bytes
|
assert type(local_htlcpubkey) is bytes
|
||||||
assert type(payment_preimage) is bytes
|
assert type(payment_preimage) is bytes
|
||||||
h = hashlib.new("ripemd160")
|
payment_hash = bitcoin.sha256(payment_preimage)
|
||||||
h.update(payment_preimage)
|
return bytes([opcodes.OP_DUP, opcodes.OP_HASH160]) + bfh(push_script(bh2u(bitcoin.hash_160(revocation_pubkey))))\
|
||||||
payment_hash = h.digest()#ripemd.new(payment_preimage).digest()
|
+ bytes([opcodes.OP_EQUAL, opcodes.OP_IF, opcodes.OP_CHECKSIG, opcodes.OP_ELSE]) \
|
||||||
assert type(payment_hash) is bytes
|
+ bfh(push_script(bh2u(remote_htlcpubkey)))\
|
||||||
return bytes([opcodes.OP_DUP, opcodes.OP_HASH160]) + bfh(push_script(bh2u(bitcoin.hash_160(revocation_pubkey)))) + bytes([opcodes.OP_EQUAL
|
+ bytes([opcodes.OP_SWAP, opcodes.OP_SIZE]) + bitcoin.add_number_to_script(32) + bytes([opcodes.OP_EQUAL, opcodes.OP_NOTIF, opcodes.OP_DROP])\
|
||||||
, opcodes.OP_IF
|
+ bitcoin.add_number_to_script(2) + bytes([opcodes.OP_SWAP]) + bfh(push_script(bh2u(local_htlcpubkey))) + bitcoin.add_number_to_script(2)\
|
||||||
, opcodes.OP_CHECKSIG
|
+ bytes([opcodes.OP_CHECKMULTISIG, opcodes.OP_ELSE, opcodes.OP_HASH160])\
|
||||||
, opcodes.OP_ELSE]) +\
|
+ bfh(push_script(bh2u(bitcoin.ripemd(payment_hash)))) + bytes([opcodes.OP_EQUALVERIFY, opcodes.OP_CHECKSIG, opcodes.OP_ENDIF, opcodes.OP_ENDIF])
|
||||||
bfh(push_script(bh2u(remote_htlcpubkey))) + bytes([opcodes.OP_SWAP, opcodes.OP_SIZE]) + bitcoin.add_number_to_script(32) + bytes([opcodes.OP_EQUAL,
|
|
||||||
opcodes.OP_NOTIF,
|
|
||||||
# to local node via htlc-timeout transaction (timelocked)
|
|
||||||
opcodes.OP_DROP]) + bitcoin.add_number_to_script(2) + bytes([opcodes.OP_SWAP]) + bfh(push_script(bh2u(local_htlcpubkey))) + bitcoin.add_number_to_script(2) + bytes([opcodes.OP_CHECKMULTISIG,
|
|
||||||
opcodes.OP_ELSE,
|
|
||||||
# to remote node with preimage
|
|
||||||
opcodes.OP_HASH160]) + bfh(push_script(bh2u(payment_hash))) + bytes([opcodes.OP_EQUALVERIFY,
|
|
||||||
opcodes.OP_CHECKSIG,
|
|
||||||
opcodes.OP_ENDIF,
|
|
||||||
opcodes.OP_ENDIF])
|
|
||||||
|
|
||||||
def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey, remotepubkey,
|
def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey, remotepubkey,
|
||||||
payment_pubkey, remote_payment_pubkey, revocation_pubkey, delayed_pubkey,
|
payment_pubkey, remote_payment_pubkey, revocation_pubkey, delayed_pubkey,
|
||||||
|
|
Loading…
Add table
Reference in a new issue