Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-schnorr.py
Show All 23 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_1, | OP_1, | ||||
OP_CHECKMULTISIG, | OP_CHECKMULTISIG, | ||||
OP_CHECKSIG, | OP_CHECKSIG, | ||||
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(multi=False, sig='schnorr'): | def create_fund_and_spend_tx(multi=False, sig='schnorr'): | ||||
spendfrom = spendable_outputs.pop() | spendfrom = spendable_outputs.pop() | ||||
if multi: | if multi: | ||||
script = CScript([OP_1, public_key, OP_1, OP_CHECKMULTISIG]) | script = CScript([OP_1, public_key, OP_1, OP_CHECKMULTISIG]) | ||||
Show All 15 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 sig == 'schnorr': | if sig == 'schnorr': | ||||
txsig = schnorr.sign(privkeybytes, sighash) + hashbyte | txsig = private_key.sign_schnorr(sighash) + hashbyte | ||||
elif sig == 'ecdsa': | elif sig == 'ecdsa': | ||||
txsig = private_key.sign_ecdsa(sighash) + hashbyte | txsig = private_key.sign_ecdsa(sighash) + hashbyte | ||||
elif isinstance(sig, bytes): | elif isinstance(sig, bytes): | ||||
txsig = sig + hashbyte | txsig = sig + hashbyte | ||||
if multi: | if multi: | ||||
txspend.vin[0].scriptSig = CScript([b'', txsig]) | txspend.vin[0].scriptSig = CScript([b'', txsig]) | ||||
else: | else: | ||||
txspend.vin[0].scriptSig = CScript([txsig]) | txspend.vin[0].scriptSig = CScript([txsig]) | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |