Exemple #1
0
 def test_public_key_from_private_key(self):
     for priv_details in self.priv_pub_addr:
         txin_type, privkey, compressed = deserialize_privkey(priv_details['priv'])
         result = ecc.ECPrivkey(privkey).get_public_key_hex(compressed=compressed)
         self.assertEqual(priv_details['pub'], result)
         self.assertEqual(priv_details['txin_type'], txin_type)
         self.assertEqual(priv_details['compressed'], compressed)
 def test_public_key_from_private_key(self):
     for priv_details in self.priv_pub_addr:
         txin_type, privkey, compressed = deserialize_privkey(
             priv_details['priv'])
         result = public_key_from_private_key(privkey, compressed)
         self.assertEqual(priv_details['pub'], result)
         self.assertEqual(priv_details['txin_type'], txin_type)
         self.assertEqual(priv_details['compressed'], compressed)
 def test_public_key_from_private_key(self):
     for priv_details in self.priv_pub_addr:
         txin_type, privkey, key_type = deserialize_privkey(
             priv_details['priv'])
         result = public_key_from_private_key(privkey, key_type)
         self.assertEqual(priv_details['pub'], result)
         self.assertEqual(priv_details['txin_type'], txin_type)
         self.assertEqual(priv_details['compressed'],
                          key_type == KeyType.ECDSA_COMPRESSED)
Exemple #4
0
 def test_serialize_privkey(self):
     for priv_details in self.priv_pub_addr:
         txin_type, privkey, compressed = deserialize_privkey(
             priv_details['priv'])
         priv2 = serialize_privkey(privkey, compressed, txin_type)
         self.assertEqual(priv_details['exported_privkey'], priv2)
Exemple #5
0
 def sign_message_with_wif_privkey(wif_privkey, msg):
     txin_type, privkey, compressed = deserialize_privkey(wif_privkey)
     key = ecc.ECPrivkey(privkey)
     return key.sign_message(msg, compressed)
 def sign_message_with_wif_privkey(wif_privkey, msg):
     txin_type, privkey, key_type = deserialize_privkey(wif_privkey)
     key = regenerate_key(privkey)
     return key.sign_message(msg, key_type == KeyType.ECDSA_COMPRESSED)
Exemple #7
0
 def test_serialize_privkey(self):
     for priv_details in self.priv_pub_addr:
         txin_type, privkey, compressed = deserialize_privkey(priv_details['priv'])
         priv2 = serialize_privkey(privkey, compressed, txin_type)
         self.assertEqual(priv_details['exported_privkey'], priv2)
Exemple #8
0
 def sign_message_with_wif_privkey(wif_privkey, msg):
     txin_type, privkey, compressed = deserialize_privkey(wif_privkey)
     key = ecc.ECPrivkey(privkey)
     return key.sign_message(msg, compressed)
Exemple #9
0
 def test_public_key_from_private_key(self):
     txin_type, privkey, compressed = deserialize_privkey(self.private_key)
     result = public_key_from_private_key(privkey, compressed)
     self.assertEqual(self.public_key_hex, result)
Exemple #10
0
from lib import transaction, bitcoin, util
from lib.util import bfh, bh2u
from lib.transaction import Transaction

kmd_unsigned_tx_serialized = 'put unsigned kmd raw tx here'
wif = 'put your wif key here'

txin_type, privkey, compressed = bitcoin.deserialize_privkey(wif)
pubkey = bitcoin.public_key_from_private_key(privkey, compressed)

jsontx = transaction.deserialize(kmd_unsigned_tx_serialized)
inputs = jsontx.get('inputs')
outputs = jsontx.get('outputs')
locktime = jsontx.get('lockTime', 0)

for txin in inputs:
    txin['type'] = txin_type
    txin['x_pubkeys'] = [pubkey]
    txin['pubkeys'] = [pubkey]
    txin['signatures'] = [None]
    txin['num_sig'] = 1
    txin['address'] = bitcoin.address_from_private_key(wif)
    txin['value'] = 100000000  # required for preimage calc

tx = Transaction.from_io(inputs, outputs, locktime=locktime)
tx.sign({pubkey: (privkey, compressed)})

print(tx.serialize())