|
|
|
@ -32,14 +32,14 @@ class Bip143:
|
|
|
|
|
def add_output(self, txo_bin: TxOutputBinType):
|
|
|
|
|
write_tx_output(self.h_outputs, txo_bin)
|
|
|
|
|
|
|
|
|
|
def get_prevouts_hash(self) -> bytes:
|
|
|
|
|
return get_tx_hash(self.h_prevouts, double=True)
|
|
|
|
|
def get_prevouts_hash(self, coin: CoinInfo) -> bytes:
|
|
|
|
|
return get_tx_hash(self.h_prevouts, double=coin.sign_hash_double)
|
|
|
|
|
|
|
|
|
|
def get_sequence_hash(self) -> bytes:
|
|
|
|
|
return get_tx_hash(self.h_sequence, double=True)
|
|
|
|
|
def get_sequence_hash(self, coin: CoinInfo) -> bytes:
|
|
|
|
|
return get_tx_hash(self.h_sequence, double=coin.sign_hash_double)
|
|
|
|
|
|
|
|
|
|
def get_outputs_hash(self) -> bytes:
|
|
|
|
|
return get_tx_hash(self.h_outputs, double=True)
|
|
|
|
|
def get_outputs_hash(self, coin: CoinInfo) -> bytes:
|
|
|
|
|
return get_tx_hash(self.h_outputs, double=coin.sign_hash_double)
|
|
|
|
|
|
|
|
|
|
def preimage_hash(self, coin: CoinInfo, tx: SignTx, txi: TxInputType, pubkeyhash: bytes, sighash: int) -> bytes:
|
|
|
|
|
h_preimage = HashWriter(sha256)
|
|
|
|
@ -47,8 +47,8 @@ class Bip143:
|
|
|
|
|
assert not tx.overwintered
|
|
|
|
|
|
|
|
|
|
write_uint32(h_preimage, tx.version) # nVersion
|
|
|
|
|
write_bytes(h_preimage, bytearray(self.get_prevouts_hash())) # hashPrevouts
|
|
|
|
|
write_bytes(h_preimage, bytearray(self.get_sequence_hash())) # hashSequence
|
|
|
|
|
write_bytes(h_preimage, bytearray(self.get_prevouts_hash(coin))) # hashPrevouts
|
|
|
|
|
write_bytes(h_preimage, bytearray(self.get_sequence_hash(coin))) # hashSequence
|
|
|
|
|
|
|
|
|
|
write_bytes_rev(h_preimage, txi.prev_hash) # outpoint
|
|
|
|
|
write_uint32(h_preimage, txi.prev_index) # outpoint
|
|
|
|
@ -59,11 +59,11 @@ class Bip143:
|
|
|
|
|
|
|
|
|
|
write_uint64(h_preimage, txi.amount) # amount
|
|
|
|
|
write_uint32(h_preimage, txi.sequence) # nSequence
|
|
|
|
|
write_bytes(h_preimage, bytearray(self.get_outputs_hash())) # hashOutputs
|
|
|
|
|
write_bytes(h_preimage, bytearray(self.get_outputs_hash(coin))) # hashOutputs
|
|
|
|
|
write_uint32(h_preimage, tx.lock_time) # nLockTime
|
|
|
|
|
write_uint32(h_preimage, sighash) # nHashType
|
|
|
|
|
|
|
|
|
|
return get_tx_hash(h_preimage, double=True)
|
|
|
|
|
return get_tx_hash(h_preimage, double=coin.sign_hash_double)
|
|
|
|
|
|
|
|
|
|
# see https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#specification
|
|
|
|
|
# item 5 for details
|
|
|
|
|