Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-schnorrmultisig.py
Show All 26 Lines | from test_framework.messages import ( | ||||
CTxIn, | CTxIn, | ||||
CTxOut, | CTxOut, | ||||
FromHex, | FromHex, | ||||
ToHex, | ToHex, | ||||
) | ) | ||||
from test_framework.mininode import ( | from test_framework.mininode import ( | ||||
P2PDataStore, | P2PDataStore, | ||||
) | ) | ||||
from test_framework import schnorr | |||||
from test_framework.script import ( | from test_framework.script import ( | ||||
CScript, | CScript, | ||||
OP_0, | OP_0, | ||||
OP_1, | OP_1, | ||||
OP_CHECKMULTISIG, | OP_CHECKMULTISIG, | ||||
OP_TRUE, | OP_TRUE, | ||||
SIGHASH_ALL, | SIGHASH_ALL, | ||||
SIGHASH_FORKID, | SIGHASH_FORKID, | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
node.generatetoaddress(100, node.get_deterministic_priv_key().address) | node.generatetoaddress(100, node.get_deterministic_priv_key().address) | ||||
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 | |||||
private_key = ECKey() | private_key = ECKey() | ||||
private_key.set(privkeybytes, True) | private_key.set(b"Schnorr!" * 4, True) | ||||
# get uncompressed public key serialization | # get uncompressed public key serialization | ||||
public_key = private_key.get_pubkey().get_bytes() | 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]) | ||||
Show All 12 Lines | def run_test(self): | ||||
CTxIn(COutPoint(txfund.sha256, 0), b'')) | CTxIn(COutPoint(txfund.sha256, 0), b'')) | ||||
# 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 = private_key.sign_schnorr(sighash) + hashbyte | ||||
elif sigtype == 'ecdsa': | elif sigtype == 'ecdsa': | ||||
txsig = private_key.sign_ecdsa(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. | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |