Beispiel #1
0
def createKeysAndAddresses():
	privkey_1 = wallet.get_private_key()
	privkey_2 = wallet.get_private_key()
	privkey_3 = wallet.get_private_key()
	print("Privkey 1:",privkey_1)
	print("Privkey 2:",privkey_2)
	print("Privkey 3:",privkey_3)

	wif1 = wallet.convert_to_WIF(privkey_1).decode()
	wif2 = wallet.convert_to_WIF(privkey_2).decode()
	wif3 = wallet.convert_to_WIF(privkey_3).decode()
	print("WIF key 1:",wif1)
	print("WIF key 2:",wif2)
	print("WIF key 3:",wif3)

	with open('minerkey', 'w') as f:
		f.write(wif1)
	with open('wif1', 'w') as f:
		f.write(wif1)
	with open('wif2', 'w') as f:
		f.write(wif2)
	with open('wif3', 'w') as f:
		f.write(wif3)

	pubkeys = []
	pubkeys.append(wallet.get_public_key(privkey_1))
	pubkeys.append(wallet.get_public_key(privkey_2))
	pubkeys.append(wallet.get_public_key(privkey_3))
	return pubkeys
Beispiel #2
0
 def test_gener_public_key(self):
     # uncompressed
     for counter in range(0, count_tests):
         self.assertEqual(
             wallet.get_public_key(wallet.generPrivKey(), False)[:2], "04")
     # compressed
     for counter in range(0, count_tests):
         random_public_key = wallet.get_public_key(
             wallet.generPrivKey())[:2]
         if random_public_key != "03":
             self.assertEqual(random_public_key, "02")
Beispiel #3
0
 def test_sign_message(self):
     for counter in range(0, count_tests):
         private_key = wallet.generPrivKey()
         public_key = wallet.get_public_key(private_key, False)
         message = wallet.generPrivKey()
         signed_message = wallet_cli.signMessage(private_key, message)[0]
         sign = bytes.fromhex(signed_message)
         vk = ecdsa.VerifyingKey.from_string(codecs.decode(
             public_key[2:], 'hex'),
                                             curve=ecdsa.SECP256k1)
         result = vk.verify(sign, bytes(message, "utf-8"))
         self.assertTrue(result)
def pubkey():
    """
    Return server public key. The key is encoded in hex and needs to be decoded
    from hex to be used by the encryption utility.
    """
    # request.method == 'GET'
    public_key = wallet.get_public_key()
    data = {
        'public_key': public_key.encode("hex")
    }
    js = json.dumps(data)

    resp = Response(js, status=200, mimetype='application/json')
    return resp
Beispiel #5
0
 def test_create_wallet_address(self):
     for counter in range(0, count_tests):
         address = wallet.createWallet(
             wallet.get_public_key(wallet.generPrivKey())).decode("utf-8")
         self.assertGreater(len(address), 0)
         self.assertNotRegex(address, 'O')
         self.assertNotRegex(address, 'I')
         self.assertNotRegex(address, 'l')
         self.assertNotRegex(address, '0')
         decode_address = binascii.hexlify(base58.b58decode(address))
         checksum = decode_address[-8:].decode("utf-8")
         hash_address = hashlib.new('sha256',
                                    binascii.unhexlify(
                                        decode_address[:-8])).hexdigest()
         hash_address = hashlib.new(
             'sha256', binascii.unhexlify(hash_address)).hexdigest()
         self.assertEqual(hash_address[:8], checksum)
wallet = wallet.create_wallet(config.get_wallet_type(), config.get_key_id(),
                              logger)
secure_message = SecureMessage(wallet)

## Test GET pubkey
req_pubkey = requests.get(notary_url + '/api/v1/pubkey',
                          verify=config.get_ssl_verify_mode())
data = req_pubkey.json()
other_party_public_key = data['public_key']
print data['public_key']
address = str(wallet.get_bitcoin_address())

## Test POST account

print("\nWallet Public Key Hex %s" % wallet.get_public_key_hex())
print("\nWallet Public Key %s" % wallet.get_public_key())
addrfromhex = P2PKHBitcoinAddress.from_pubkey(
    wallet.get_public_key_hex().decode("hex"))
print("\nAddress From Hex %s" % addrfromhex)
email = test_data.email_address

registration_message = {
    'public_key': wallet.get_public_key_hex(),
    'email': email
}

registration_payload = secure_message.create_secure_payload(
    other_party_public_key, json.dumps(registration_message))
response = requests.put(notary_url + '/api/v1/account/' + address,
                        data=registration_payload,
                        verify=config.get_ssl_verify_mode())
Beispiel #7
0
import encrypt
import wallet
from base58 import base58_check_encode
import os
from bitcoinlib.wallet import CBitcoinSecret, P2PKHBitcoinAddress
import requests
requests.packages.urllib3.disable_warnings()

def privateKeyToWif(key_hex):
    return base58_check_encode(0x80, key_hex.decode('hex'))

wallet = wallet.create_wallet(config.get_wallet_type(), config.get_key_id())

print("\nWallet Private Key %s" % wallet.get_private_key())
print("\nWallet Public Key %s" % wallet.get_public_key())
print("\nWallet Public Key Hex %s" % wallet.get_public_key_hex())
print("\nWallet Private Key WIF %s" % wallet.get_private_key_wif())
str = wallet.get_bitcoin_address()
print("\nWallet Address %s" % wallet.get_bitcoin_address())

pubkeyhex = wallet.get_public_key_hex()
pubkey = wallet.get_public_key()

addrfrom = P2PKHBitcoinAddress.from_pubkey(pubkey)
addrfromhex = P2PKHBitcoinAddress.from_pubkey(pubkeyhex.decode("hex"))
print("\nAddress From %s" % addrfrom)
print("\nAddress From Hex %s" % addrfromhex)

message = "bitid://localhost:5000/callback?x=30f56bc022dde976&u=1"

print("\nClear: %s" % message)
requests.packages.urllib3.disable_warnings()

logger = log_handlers.get_logger(config)
logger.debug("-------------------------ENVIRONMENT--------------------------")
logger.debug("Am I Local: %s " % config.is_local_host())

wallet = wallet.create_wallet(config.get_wallet_type(), config.get_key_id(), logger)
secure_message = SecureMessage(wallet)

## Test GET pubkey
req_pubkey = requests.get(notary_url+'/api/v1/pubkey', verify=config.get_ssl_verify_mode())
data = req_pubkey.json()
other_party_public_key = data['public_key']
print data['public_key']
address = str(wallet.get_bitcoin_address())

## Test POST account

print("\nWallet Public Key Hex %s" % wallet.get_public_key_hex())
print("\nWallet Public Key %s" % wallet.get_public_key())
addrfromhex = P2PKHBitcoinAddress.from_pubkey(wallet.get_public_key_hex().decode("hex"))
print("\nAddress From Hex %s" % addrfromhex)
email = test_data.email_address

registration_message = {'public_key': wallet.get_public_key_hex(), 'email': email}

registration_payload = secure_message.create_secure_payload(other_party_public_key, json.dumps(registration_message))
response = requests.put(notary_url+'/api/v1/account/' + address, data=registration_payload, verify=config.get_ssl_verify_mode())
print(response.status_code)
Beispiel #9
0
 def test_public_key(self):
     self.assertEqual(wallet.get_public_key(PRIVKEY), PUBLIC_KEY)