def create_account(self, address, account):
        if not check_account(account):
            return False

        if self.get_account_by_address(address) is None:
            client_public_key = account['public_key']
            decoded = client_public_key.decode("hex")
            pubkey = CPubKey(decoded)
            raw_address = P2PKHBitcoinAddress.from_pubkey(pubkey)
            derived_address = str(raw_address)
            if derived_address == address:
                account['nonce'] = generate_nonce()
                account['date_created'] = datetime.now().isoformat(' ')
                account['account_status'] = 'PENDING'
                account['address'] = str(address)
                try:
                    account['file_encryption_key'] = self.wallet.generate_encrypted_private_key()
                    self.account_table.put_item(Item=account)
                except botocore.exceptions.ClientError as e:
                    self.logger.exception("Houston, we have a problem: %s " % e.response)

                return self.send_confirmation_email(account)
            else:
                return None
        else:
            return None
Example #2
0
def VerifyMessage(address, message, sig):
    sig = base64.b64decode(sig)
    hash = message.GetHash()

    pubkey = CPubKey.recover_compact(hash, sig)

    return str(P2PKHBitcoinAddress.from_pubkey(pubkey)) == str(address)
Example #3
0
def VerifyMessage(address, message, sig):
    sig = base64.b64decode(sig)
    hash = message.GetHash()

    pubkey = CPubKey.recover_compact(hash, sig)

    return str(P2PKHBitcoinAddress.from_pubkey(pubkey)) == str(address)
    def create_account(self, address, account):
        if not check_account(account):
            return False

        if self.get_account_by_address(address) is None:
            client_public_key = account['public_key']
            decoded = client_public_key.decode("hex")
            pubkey = CPubKey(decoded)
            raw_address = P2PKHBitcoinAddress.from_pubkey(pubkey)
            derived_address = str(raw_address)
            if derived_address == address:
                account['nonce'] = generate_nonce()
                account['date_created'] = datetime.now().isoformat(' ')
                account['account_status'] = 'PENDING'
                account['address'] = str(address)
                try:
                    account[
                        'file_encryption_key'] = self.wallet.generate_encrypted_private_key(
                        )
                    self.account_table.put_item(Item=account)
                except botocore.exceptions.ClientError as e:
                    self.logger.exception("Houston, we have a problem: %s " %
                                          e.response)

                return self.send_confirmation_email(account)
            else:
                return None
        else:
            return None
Example #5
0
 def __init__(self, config):
     self.config = config
     requests.packages.urllib3.disable_warnings()
     self.notary_url = self.get_notary_url()
     response = requests.get(self.notary_url + '/api/v1/pubkey', verify=self.config.get_ssl_verify_mode())
     data = response.json()
     self.other_party_public_key_hex = data['public_key']
     other_party_public_key_decoded = self.other_party_public_key_hex.decode("hex")
     self.other_party_public_key = CPubKey(other_party_public_key_decoded)
     self.other_party_address = P2PKHBitcoinAddress.from_pubkey(self.other_party_public_key)
                              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)
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
pubkey_response = requests.get(notary_url+'/api/v1/pubkey', verify=False)
data = pubkey_response.json()
other_party_public_key_hex = data['public_key']
print data['public_key']
other_party_public_key_decoded = other_party_public_key_hex.decode("hex")
other_party_public_key = CPubKey(other_party_public_key_decoded)
other_party_address = P2PKHBitcoinAddress.from_pubkey(other_party_public_key)
address = str(wallet.get_bitcoin_address())

## Test GET challenge

response = requests.get(notary_url+'/api/v1/challenge/' + address, verify=False)
payload = json.loads(response.content)
if secure_message.verify_secure_payload(other_party_address, payload):
    message = secure_message.get_message_from_secure_payload(payload)
    print(message)

payload = secure_message.create_secure_payload(other_party_public_key_hex, message)
response = requests.put(notary_url+'/api/v1/challenge/' + address, data=payload, verify=False)
cookies = requests.utils.dict_from_cookiejar(response.cookies)

metadata = {
else:
    notary_url = config.get_local_server_url()

requests.packages.urllib3.disable_warnings()

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

## Test GET pubkey
pubkey_response = requests.get(notary_url+'/api/v1/pubkey', verify=False)
data = pubkey_response.json()
other_party_public_key_hex = data['public_key']
print data['public_key']
other_party_public_key_decoded = other_party_public_key_hex.decode("hex")
other_party_public_key = CPubKey(other_party_public_key_decoded)
other_party_address = P2PKHBitcoinAddress.from_pubkey(other_party_public_key)
address = str(wallet.get_bitcoin_address())

## Test GET challenge

response = requests.get(notary_url+'/api/v1/challenge/' + address, verify=False)
payload = json.loads(response.content)
if secure_message.verify_secure_payload(other_party_address, payload):
    message = secure_message.get_message_from_secure_payload(payload)
    print(message)

payload = secure_message.create_secure_payload(other_party_public_key_hex, message)
response = requests.put(notary_url+'/api/v1/challenge/' + address, data=payload, verify=False)
cookies = requests.utils.dict_from_cookiejar(response.cookies)

document_hash = hashfile.hash_file(test_data.notary_file_name)
Example #9
0
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)
encrypted = encrypt.encrypt(wallet.get_public_key(), message)
print("\nEncrypted: %s" % encrypted)

decrypted = encrypt.decrypt(wallet.get_private_key_wif(), encrypted)
print("\nDecrypted: %s" % decrypted)

signature = wallet.sign(message)
Example #10
0
 def get_bitcoin_address(self):
     return P2PKHBitcoinAddress.from_pubkey(self.private_key.pub)
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)
Example #12
0
 def get_bitcoin_address(self):
     return P2PKHBitcoinAddress.from_pubkey(self.private_key.pub)