def test_prevouts(self):
     coin = coins.by_name(self.tx.coin_name)
     sig_hasher = BitcoinSigHasher()
     sig_hasher.add_input(self.inp1, b"")
     sig_hasher.add_input(self.inp2, b"")
     prevouts_hash = get_tx_hash(sig_hasher.h_prevouts, double=coin.sign_hash_double)
     self.assertEqual(hexlify(prevouts_hash), b'96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37')
 def test_sequence(self):
     coin = coins.by_name(self.tx.coin_name)
     sig_hasher = BitcoinSigHasher()
     sig_hasher.add_input(self.inp1, b"")
     sig_hasher.add_input(self.inp2, b"")
     sequence_hash = get_tx_hash(sig_hasher.h_sequences, double=coin.sign_hash_double)
     self.assertEqual(hexlify(sequence_hash), b'52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b')
 def test_prevouts(self):
     coin = coins.by_name(self.tx.coin_name)
     bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))
     bip143.hash143_add_input(self.inp1)
     bip143.hash143_add_input(self.inp2)
     prevouts_hash = get_tx_hash(bip143.h_prevouts, double=coin.sign_hash_double)
     self.assertEqual(hexlify(prevouts_hash), b'96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37')
 def test_sequence(self):
     coin = coins.by_name(self.tx.coin_name)
     bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))
     bip143.hash143_add_input(self.inp1)
     bip143.hash143_add_input(self.inp2)
     sequence_hash = get_tx_hash(bip143.h_sequence, double=coin.sign_hash_double)
     self.assertEqual(hexlify(sequence_hash), b'52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b')
예제 #5
0
    def test_zip243(self):
        coin = coins.by_name("Zcash")

        for v in self.VECTORS:
            tx = SignTx(
                coin_name="Zcash",
                inputs_count=len(v["inputs"]),
                outputs_count=len(v["outputs"]),
                version=v["version"],
                lock_time=v["lock_time"],
                expiry=v["expiry"],
                version_group_id=v["version_group_id"],
                branch_id=v["branch_id"],
            )

            zip243 = Zip243SigHasher()

            for i in v["inputs"]:
                txi = TxInput(
                    amount=i["amount"],
                    prev_hash=unhexlify(i["prevout"][0]),
                    prev_index=i["prevout"][1],
                    script_type=i["script_type"],
                    sequence=i["sequence"],
                )
                zip243.add_input(txi, b"")

            for o in v["outputs"]:
                txo = PrevOutput(
                    amount=o["amount"],
                    script_pubkey=unhexlify(o["script_pubkey"]),
                )
                zip243.add_output(txo, txo.script_pubkey)

            self.assertEqual(hexlify(get_tx_hash(zip243.h_prevouts)),
                             v["prevouts_hash"])
            self.assertEqual(hexlify(get_tx_hash(zip243.h_sequence)),
                             v["sequence_hash"])
            self.assertEqual(hexlify(get_tx_hash(zip243.h_outputs)),
                             v["outputs_hash"])
            self.assertEqual(
                hexlify(
                    zip243.hash143(txi, [unhexlify(i["pubkey"])], 1, tx, coin,
                                   SigHashType.SIGHASH_ALL)),
                v["preimage_hash"])
 def test_bip143_sequence(self):
     coin = coins.by_name(self.tx.coin_name)
     bip143 = Bitcoin(self.tx, None, coin)
     bip143.hash143_add_input(self.inp1)
     sequence_hash = get_tx_hash(bip143.h_sequence,
                                 double=coin.sign_hash_double)
     self.assertEqual(
         hexlify(sequence_hash),
         b'18606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe198'
     )
 def test_bip143_prevouts(self):
     coin = coins.by_name(self.tx.coin_name)
     bip143 = Bitcoin(self.tx, None, coin)
     bip143.hash143_add_input(self.inp1)
     prevouts_hash = get_tx_hash(bip143.h_prevouts,
                                 double=coin.sign_hash_double)
     self.assertEqual(
         hexlify(prevouts_hash),
         b'b0287b4a252ac05af83d2dcef00ba313af78a3e9c329afa216eb3aa2a7b4613a'
     )
 def test_bip143_sequence(self):
     coin = coins.by_name(self.tx.coin_name)
     sig_hasher = BitcoinSigHasher()
     sig_hasher.add_input(self.inp1, b"")
     sequence_hash = get_tx_hash(sig_hasher.h_sequences,
                                 double=coin.sign_hash_double)
     self.assertEqual(
         hexlify(sequence_hash),
         b'18606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe198'
     )
 def test_bip143_prevouts(self):
     coin = coins.by_name(self.tx.coin_name)
     sig_hasher = BitcoinSigHasher()
     sig_hasher.add_input(self.inp1, b"")
     prevouts_hash = get_tx_hash(sig_hasher.h_prevouts,
                                 double=coin.sign_hash_double)
     self.assertEqual(
         hexlify(prevouts_hash),
         b'b0287b4a252ac05af83d2dcef00ba313af78a3e9c329afa216eb3aa2a7b4613a'
     )
예제 #10
0
    def test_zip143(self):
        coin = coins.by_name("Zcash")

        for v in self.VECTORS:
            tx = SignTx(
                coin_name="Zcash",
                inputs_count=len(v["inputs"]),
                outputs_count=len(v["outputs"]),
                version=v["version"],
                lock_time=v["lock_time"],
                expiry=v["expiry"],
                version_group_id=v["version_group_id"],
            )

            zip143 = Overwintered(tx, None, coin)

            for i in v["inputs"]:
                txi = TxInputType()
                txi.amount = i["amount"]
                txi.prev_hash = unhexlify(i["prevout"][0])
                txi.prev_index = i["prevout"][1]
                txi.script_type = i["script_type"]
                txi.sequence = i["sequence"]
                zip143.hash143_add_input(txi)
            for o in v["outputs"]:
                txo = TxOutputBinType()
                txo.amount = o["amount"]
                txo.script_pubkey = unhexlify(o["script_pubkey"])
                zip143.hash143_add_output(txo, txo.script_pubkey)

            self.assertEqual(hexlify(get_tx_hash(zip143.h_prevouts)),
                             v["prevouts_hash"])
            self.assertEqual(hexlify(get_tx_hash(zip143.h_sequence)),
                             v["sequence_hash"])
            self.assertEqual(hexlify(get_tx_hash(zip143.h_outputs)),
                             v["outputs_hash"])
            self.assertEqual(
                hexlify(
                    zip143.hash143_preimage_hash(txi,
                                                 unhexlify(i["pubkeyhash"]))),
                v["preimage_hash"],
            )
예제 #11
0
    def test_bip143_outputs(self):
        seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '')
        coin = coins.by_name(self.tx.coin_name)
        bip143 = Bip143Hash()

        for txo in [self.out1, self.out2]:
            script_pubkey = output_derive_script(txo.address, coin)
            txo_bin = PrevOutput(amount=txo.amount, script_pubkey=script_pubkey)
            bip143.add_output(txo_bin, script_pubkey)

        outputs_hash = get_tx_hash(bip143.h_outputs, double=coin.sign_hash_double)
        self.assertEqual(hexlify(outputs_hash), b'de984f44532e2173ca0d64314fcefe6d30da6f8cf27bafa706da61df8a226c83')
    def test_bip341(self):
        for i, tx in enumerate(VECTORS):
            hasher = BitcoinSigHasher()

            for txi in tx["inputs"]:
                hasher.add_input(txi, txi.script_pubkey)

            self.assertEqual(get_tx_hash(hasher.h_amounts), tx["sha_amounts"], f"sha_amounts tx {i}")
            self.assertEqual(get_tx_hash(hasher.h_prevouts), tx["sha_prevouts"], f"sha_prevouts tx {i}")
            self.assertEqual(get_tx_hash(hasher.h_scriptpubkeys), tx["sha_scriptpubkeys"], f"sha_scriptpubkeys tx {i}")
            self.assertEqual(get_tx_hash(hasher.h_sequences), tx["sha_sequences"], f"sha_sequences tx {i}")

            for txo in tx["outputs"]:
                hasher.add_output(txo, txo.script_pubkey)

            self.assertEqual(get_tx_hash(hasher.h_outputs), tx["sha_outputs"], f"sha_outputs tx {i}")

            for sh in tx["signature_hashes"]:
                txi = tx["inputs"][sh["index"]]
                result = hasher.hash341(sh["index"], tx["sign_tx"], sh["hash_type"])
                self.assertEqual(result, sh["result"], f"signature_hash tx {i} input {sh['index']}")
    def test_outputs(self):

        seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '')
        coin = coins.by_name(self.tx.coin_name)
        sig_hasher = BitcoinSigHasher()

        for txo in [self.out1, self.out2]:
            script_pubkey = output_derive_script(txo.address, coin)
            txo_bin = PrevOutput(amount=txo.amount, script_pubkey=script_pubkey)
            sig_hasher.add_output(txo_bin, script_pubkey)

        outputs_hash = get_tx_hash(sig_hasher.h_outputs, double=coin.sign_hash_double)
        self.assertEqual(hexlify(outputs_hash), b'863ef3e1a92afbfdb97f31ad0fc7683ee943e9abcf2501590ff8f6551f47e5e5')
    def test_outputs(self):

        seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '')
        coin = coins.by_name(self.tx.coin_name)
        bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))

        for txo in [self.out1, self.out2]:
            txo_bin = TxOutputBinType()
            txo_bin.amount = txo.amount
            script_pubkey = output_derive_script(txo.address, coin)
            bip143.hash143_add_output(txo_bin, script_pubkey)

        outputs_hash = get_tx_hash(bip143.h_outputs, double=coin.sign_hash_double)
        self.assertEqual(hexlify(outputs_hash), b'863ef3e1a92afbfdb97f31ad0fc7683ee943e9abcf2501590ff8f6551f47e5e5')