def initialize_wallet(): result = {} print "Initializing new wallet ..." password = "******" try: while len(password) < WALLET_PASSWORD_LENGTH: password = raw_input("Enter new password: "******"Password is too short. Please make it at least %s characters long" % WALLET_PASSWORD_LENGTH else: wallet = HDWallet() hex_password = hexlify(password) hex_privkey = wallet.get_master_privkey() data = {} data['encrypted_master_private_key'] = aes_encrypt(hex_privkey, hex_password) file = open(WALLET_PATH, 'w') file.write(json.dumps(data)) file.close() print "Wallet created. Make sure to backup the following:" result['wallet_password'] = password result['master_private_key'] = hex_privkey except KeyboardInterrupt: print "\nExited." return result
def unlock_wallet(display_enabled=False): try: password = raw_input("Enter wallet password: "******"Incorrect password." else: print "Unlocked wallet." wallet = HDWallet(hex_privkey) child = wallet.get_child_keypairs(count=2, include_privkey=True) payment_keypair = child[0] owner_keypair = child[1] save_keys_to_memory(payment_keypair, owner_keypair) if display_enabled: display_wallet_info(payment_keypair[0], owner_keypair[0]) except KeyboardInterrupt: print "\nExited."
def unlock_wallet(display_enabled=False): if walletUnlocked(): if display_enabled: payment_address, owner_address = get_addresses_from_file() display_wallet_info(payment_address, owner_address) else: try: password = getpass("Enter wallet password: "******"Incorrect password.") else: print "Unlocked wallet." wallet = HDWallet(hex_privkey) child = wallet.get_child_keypairs(count=2, include_privkey=True) payment_keypair = child[0] owner_keypair = child[1] save_keys_to_memory(payment_keypair, owner_keypair) if display_enabled: display_wallet_info(payment_keypair[0], owner_keypair[0]) except KeyboardInterrupt: print "\nExited."
def initialize_wallet(): result = {} print "Initializing new wallet ..." password = "******" try: while len(password) < WALLET_PASSWORD_LENGTH: password = getpass("Enter new password: "******"Password is too short. Please make it at" msg += " least %s characters long" % WALLET_PASSWORD_LENGTH print msg else: confirm_password = getpass("Confirm new password: "******"Passwords don't match.") temp_wallet = HDWallet() hex_privkey = temp_wallet.get_master_privkey() hex_password = hexlify(password) wallet = HDWallet(hex_privkey) child = wallet.get_child_keypairs(count=2) encrypted_key = aes_encrypt(hex_privkey, hex_password) wallet_file_data = {} wallet_file_data[ 'encrypted_master_private_key'] = encrypted_key wallet_file_data['payment_addresses'] = [child[0]] wallet_file_data['owner_addresses'] = [child[1]] print "\nWallet created! Make sure to...\n", \ " 1. Remember your password and write it down in a safe place\n", \ " 2. Back up your encrypted master private key:\n\n", \ " " + encrypted_key + "\n" input_prompt = "Have you backed up your private key? (y/n): " user_input = raw_input(input_prompt) user_input = user_input.lower() if user_input == 'y': file = open(WALLET_PATH, 'w') file.write(json.dumps(wallet_file_data)) file.close() print "" else: exit_with_error( "Wallet could not be created. Try again and make sure to complete the backup process." ) except KeyboardInterrupt: exit_with_error("\nExited.") return result
def transfer_user(username): reply = {} try: user = get_authenticated_user(request.authorization) except Exception as e: raise GenericError(str(e)) try: hex_privkey = aes_decrypt(user.encrypted_privkey, SECRET_KEY) except Exception as e: raise GenericError(str(e)) wallet = HDWallet(hex_privkey) data = json.loads(request.data) fqu = username + "." + DEFAULT_NAMESPACE transfer_address = data['transfer_address'] owner_pubkey = data['owner_pubkey'] try: blockchain_record = bs_client.get_name_blockchain_record(fqu) except Exception as e: raise GenericError(str(e)) if 'value_hash' not in blockchain_record: raise GenericError("Not yet registered %s" % fqu) owner_address = blockchain_record['address'] check_address = get_address_from_pubkey(str(owner_pubkey)) if check_address != owner_address: raise GenericError("Given pubkey/address doesn't own this name.") if not is_b58check_address(transfer_address): raise InvalidAddressError(transfer_address) if USE_DEFAULT_PAYMENT and PAYMENT_PRIVKEY is not None: payment_privkey = BitcoinPrivateKey(PAYMENT_PRIVKEY) payment_privkey = payment_privkey.to_hex() else: pubkey, payment_privkey = wallet.get_next_keypair() if payment_privkey is None: raise PaymentError( addresses=wallet.get_keypairs(DEFAULT_CHILD_ADDRESSES)) resp = {} try: resp = bs_client.transfer_subsidized(fqu, transfer_address, keep_data=True, public_key=owner_pubkey, subsidy_key=payment_privkey) except Exception as e: reply['error'] = str(e) return jsonify(reply), 200 if 'subsidized_tx' in resp: reply['unsigned_tx'] = resp['subsidized_tx'] else: if 'error' in resp: reply['error'] = resp['error'] else: reply['error'] = resp return jsonify(reply), 200
import json from pybitcoin import BitcoinPrivateKey from registrar.wallet import HDWallet try: ONENAME_API_ID = os.environ['ONENAME_API_ID'] ONENAME_API_SECRET = os.environ['ONENAME_API_SECRET'] except: print "credentials not found" from onename.client import OnenameClient try: HEX_PRIV_KEY = os.environ['HEX_PRIV_KEY'] wallet = HDWallet(HEX_PRIV_KEY) except: wallet = HDWallet() if __name__ == '__main__': username = "******" profile = {"name": {"formatted": "Clone 4345"}, "v": "2"} owner_address, owner_privkey = wallet.get_keypairs(1, include_privkey=True)[0] c = OnenameClient(ONENAME_API_ID, ONENAME_API_SECRET, base_url='http://localhost:5000/v1') #c = OnenameClient(ONENAME_API_ID, ONENAME_API_SECRET) #print c.get_user_stats()
import json from pybitcoin import BitcoinPrivateKey from registrar.wallet import HDWallet try: ONENAME_API_ID = os.environ['ONENAME_API_ID'] ONENAME_API_SECRET = os.environ['ONENAME_API_SECRET'] except: print "credentials not found" from onename.client import OnenameClient try: HEX_PRIV_KEY = os.environ['HEX_PRIV_KEY'] wallet = HDWallet(HEX_PRIV_KEY) except: wallet = HDWallet() if __name__ == '__main__': username = "******" profile = {"name": {"formatted": "Clone 4345"}, "v": "2"} owner_address, owner_privkey = wallet.get_keypairs(1, include_privkey=True)[0] c = OnenameClient(ONENAME_API_ID, ONENAME_API_SECRET, base_url='http://localhost:5000/v1') #c = OnenameClient(ONENAME_API_ID, ONENAME_API_SECRET)