9
9
import time
10
10
11
11
from test_framework .blocktools import create_block , create_coinbase , add_witness_commitment , get_witness_script , WITNESS_COMMITMENT_HEADER
12
- from test_framework .key import CECKey , CPubKey
12
+ from test_framework .key import ECKey
13
13
from test_framework .messages import (
14
14
BIP125_SEQUENCE_NUMBER ,
15
15
CBlock ,
@@ -100,7 +100,7 @@ def get_p2pkh_script(pubkeyhash):
100
100
def sign_p2pk_witness_input (script , tx_to , in_idx , hashtype , value , key ):
101
101
"""Add signature for a P2PK witness program."""
102
102
tx_hash = SegwitVersion1SignatureHash (script , tx_to , in_idx , hashtype , value )
103
- signature = key .sign (tx_hash ) + chr (hashtype ).encode ('latin-1' )
103
+ signature = key .sign_ecdsa (tx_hash ) + chr (hashtype ).encode ('latin-1' )
104
104
tx_to .wit .vtxinwit [in_idx ].scriptWitness .stack = [signature , script ]
105
105
tx_to .rehash ()
106
106
@@ -1479,10 +1479,9 @@ def test_uncompressed_pubkey(self):
1479
1479
1480
1480
# Segwit transactions using uncompressed pubkeys are not accepted
1481
1481
# under default policy, but should still pass consensus.
1482
- key = CECKey ()
1483
- key .set_secretbytes (b"9" )
1484
- key .set_compressed (False )
1485
- pubkey = CPubKey (key .get_pubkey ())
1482
+ key = ECKey ()
1483
+ key .generate (False )
1484
+ pubkey = key .get_pubkey ().get_bytes ()
1486
1485
assert_equal (len (pubkey ), 65 ) # This should be an uncompressed pubkey
1487
1486
1488
1487
utxo = self .utxo .pop (0 )
@@ -1512,7 +1511,7 @@ def test_uncompressed_pubkey(self):
1512
1511
tx2 .vout .append (CTxOut (tx .vout [0 ].nValue - 1000 , script_wsh ))
1513
1512
script = get_p2pkh_script (pubkeyhash )
1514
1513
sig_hash = SegwitVersion1SignatureHash (script , tx2 , 0 , SIGHASH_ALL , tx .vout [0 ].nValue )
1515
- signature = key .sign (sig_hash ) + b'\x01 ' # 0x1 is SIGHASH_ALL
1514
+ signature = key .sign_ecdsa (sig_hash ) + b'\x01 ' # 0x1 is SIGHASH_ALL
1516
1515
tx2 .wit .vtxinwit .append (CTxInWitness ())
1517
1516
tx2 .wit .vtxinwit [0 ].scriptWitness .stack = [signature , pubkey ]
1518
1517
tx2 .rehash ()
@@ -1566,7 +1565,7 @@ def test_uncompressed_pubkey(self):
1566
1565
tx5 .vin .append (CTxIn (COutPoint (tx4 .sha256 , 0 ), b"" ))
1567
1566
tx5 .vout .append (CTxOut (tx4 .vout [0 ].nValue - 1000 , CScript ([OP_TRUE ])))
1568
1567
(sig_hash , err ) = SignatureHash (script_pubkey , tx5 , 0 , SIGHASH_ALL )
1569
- signature = key .sign (sig_hash ) + b'\x01 ' # 0x1 is SIGHASH_ALL
1568
+ signature = key .sign_ecdsa (sig_hash ) + b'\x01 ' # 0x1 is SIGHASH_ALL
1570
1569
tx5 .vin [0 ].scriptSig = CScript ([signature , pubkey ])
1571
1570
tx5 .rehash ()
1572
1571
# Should pass policy and consensus.
@@ -1579,9 +1578,9 @@ def test_uncompressed_pubkey(self):
1579
1578
@subtest
1580
1579
def test_signature_version_1 (self ):
1581
1580
1582
- key = CECKey ()
1583
- key .set_secretbytes ( b"9" )
1584
- pubkey = CPubKey ( key .get_pubkey ())
1581
+ key = ECKey ()
1582
+ key .generate ( )
1583
+ pubkey = key .get_pubkey (). get_bytes ( )
1585
1584
1586
1585
witness_program = CScript ([pubkey , CScriptOp (OP_CHECKSIG )])
1587
1586
witness_hash = sha256 (witness_program )
@@ -1716,7 +1715,7 @@ def test_signature_version_1(self):
1716
1715
1717
1716
script = get_p2pkh_script (pubkeyhash )
1718
1717
sig_hash = SegwitVersion1SignatureHash (script , tx2 , 0 , SIGHASH_ALL , tx .vout [0 ].nValue )
1719
- signature = key .sign (sig_hash ) + b'\x01 ' # 0x1 is SIGHASH_ALL
1718
+ signature = key .sign_ecdsa (sig_hash ) + b'\x01 ' # 0x1 is SIGHASH_ALL
1720
1719
1721
1720
# Check that we can't have a scriptSig
1722
1721
tx2 .vin [0 ].scriptSig = CScript ([signature , pubkey ])
0 commit comments