Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-schnorrmultisig.py
Show All 13 Lines | |||||
""" | """ | ||||
from test_framework.blocktools import ( | from test_framework.blocktools import ( | ||||
create_block, | create_block, | ||||
create_coinbase, | create_coinbase, | ||||
create_tx_with_script, | create_tx_with_script, | ||||
make_conform_to_ctor, | make_conform_to_ctor, | ||||
) | ) | ||||
from test_framework.key import CECKey | from test_framework.key import ECKey | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
CBlock, | CBlock, | ||||
COutPoint, | COutPoint, | ||||
CTransaction, | CTransaction, | ||||
CTxIn, | CTxIn, | ||||
CTxOut, | CTxOut, | ||||
FromHex, | FromHex, | ||||
ToHex, | ToHex, | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
tip = self.getbestblock(node) | tip = self.getbestblock(node) | ||||
self.log.info("Setting up spends to test and mining the fundings.") | self.log.info("Setting up spends to test and mining the fundings.") | ||||
fundings = [] | fundings = [] | ||||
# Generate a key pair | # Generate a key pair | ||||
privkeybytes = b"Schnorr!" * 4 | privkeybytes = b"Schnorr!" * 4 | ||||
private_key = CECKey() | private_key = ECKey() | ||||
private_key.set_secretbytes(privkeybytes) | private_key.set(privkeybytes, True) | ||||
# get uncompressed public key serialization | # get uncompressed public key serialization | ||||
public_key = private_key.get_pubkey() | public_key = private_key.get_pubkey().get_bytes() | ||||
def create_fund_and_spend_tx(dummy=OP_0, sigtype='ecdsa'): | def create_fund_and_spend_tx(dummy=OP_0, sigtype='ecdsa'): | ||||
spendfrom = spendable_outputs.pop() | spendfrom = spendable_outputs.pop() | ||||
script = CScript([OP_1, public_key, OP_1, OP_CHECKMULTISIG]) | script = CScript([OP_1, public_key, OP_1, OP_CHECKMULTISIG]) | ||||
value = spendfrom.vout[0].nValue | value = spendfrom.vout[0].nValue | ||||
Show All 12 Lines | def run_test(self): | ||||
# Sign the transaction | # Sign the transaction | ||||
sighashtype = SIGHASH_ALL | SIGHASH_FORKID | sighashtype = SIGHASH_ALL | SIGHASH_FORKID | ||||
hashbyte = bytes([sighashtype & 0xff]) | hashbyte = bytes([sighashtype & 0xff]) | ||||
sighash = SignatureHashForkId( | sighash = SignatureHashForkId( | ||||
script, txspend, 0, sighashtype, value) | script, txspend, 0, sighashtype, value) | ||||
if sigtype == 'schnorr': | if sigtype == 'schnorr': | ||||
txsig = schnorr.sign(privkeybytes, sighash) + hashbyte | txsig = schnorr.sign(privkeybytes, sighash) + hashbyte | ||||
elif sigtype == 'ecdsa': | elif sigtype == 'ecdsa': | ||||
txsig = private_key.sign(sighash) + hashbyte | txsig = private_key.sign_ecdsa(sighash) + hashbyte | ||||
txspend.vin[0].scriptSig = CScript([dummy, txsig]) | txspend.vin[0].scriptSig = CScript([dummy, txsig]) | ||||
txspend.rehash() | txspend.rehash() | ||||
return txspend | return txspend | ||||
# This is valid. | # This is valid. | ||||
ecdsa0tx = create_fund_and_spend_tx(OP_0, 'ecdsa') | ecdsa0tx = create_fund_and_spend_tx(OP_0, 'ecdsa') | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |