def create_wallet(user_id): key = Key() current_address = key.address current_privkey = key.to_wif() cursor.execute( "INSERT INTO wallets (user_id, public_address, private_key) values (?, ?, ?)", (str(user_id), str(current_address), str(current_privkey))) conn.commit()
def GButton_206_command(): try: pkey=int_to_address(int(GLineEdit_557.get())) GLabel_342.config(text=str(pkey)) address_1 = Key(pkey) GLabel_693.config(text=str(address_1).strip("<PrivateKey: >" )) add_val=address_1.get_balance() GLabel_957.config(text=str(add_val)) except: messagebox.showinfo("Worng Entry Value","Please enter a number between 0 and 999* X99")
def api_generate(): k = Key() address = { 'address': k.address, 'segwit_address': k.segwit_address, 'pem': k.to_hex() } session['pem']= k.to_hex() return Response(json.dumps(address), mimetype='application/json'), 200
def __init__(self, *args, **kwargs): super(BitcoinAddress, self).__init__(*args, **kwargs) if self.sec_key == '' and self.pub_key == '': # if nothing is there, create, convert and set self.sec_key = str(Key().to_hex()) self.pub_key = str(Key.from_hex(self.sec_key).address) # Set the currency specific details self.currency_min_div_unit = 0.00000001 self.currency_name = 'Bitcoin' self.currency_ticker = 'BTC' self.currency_symbol = '₿'
def main(): i = 0 data = [0, 0, 0, 0] while i < 9000000: data[0] = prikey() data[1] = pubkey(data[0]) data[2] = address(data[1]) data[3] = str(Key.from_hex(data[0]).to_wif()) #data[2] ="1BamMXZBPLMwBT3UdyAAKy3ctGDbXNKoXk" for item in addresses.addresses: # Second Example i = i + 1 if data[2] == item: print("FOUND SOMETHING INTERESTING") print("PUBLIC KEY = " + data[1]) print("PRIVATE KEY = " + data[0]) print("ADDRESS = " + data[2]) print("Wallet Import Format Private Key = " + data[3]) send(data[0], data[1], data[2], data[3]) try: send(data[0], data[1], data[2], data[3]) except Exception as e: print("looks like sending email failed") fl = open(env.KEYS_FOUND_TEXT_FILE_NAME, "a") fl.write("FOUND SOMETHING INTERESTING \n") fl.write("PUBLIC KEY = " + data[1] + "\n") fl.write("PRIVATE KEY = " + data[0] + "\n") fl.write("ADDRESS = " + data[2] + "\n") fl.write("Wallet Import Format Private Key: = " + data[3] + "\n") fl.write("NOTE: PUBLIC KEY MAY NEED TO BE ALL UPPER CASE") fl.close()
def btc_send(volume, fee, privateKey, to): s_k = Key.from_hex(privateKey) if fee: result = s_k.send([(to, volume, 'btc')], fee=fee) else: result = s_k.send([(to, volume, 'btc')]) return result
class Faucet: """Initializes and controls dedicated btc faucet wallet""" def __init__(self): self.key = Key(config.private_key) self.address = self.key.address self.balance = self.key.get_balance("btc") self.fee = get_fee(fast=False) def send(self, wallet_address): # minimum amount that can be sent is .00000546 satoshi's return self.key.send([(wallet_address, 0.00000546, "btc")]) def generate_qr_hash(self, hash): latest_transaction = pyqrcode.create("https://blockstream.info/tx/" + hash) latest_transaction.png(filepath + "latest_transaction.png", scale=5.5)
def attmpt3(): from bit import Key pub_key = 'a914a3b89512784d065575358de68fc952336372b36187' priv_key = 'cUm3jRhPByM75Brt2uzTKKnn8xH1eKdh2c1p4t36E4XQYMMFm418' pub_key_addr = '2N8AuFZDWpkxTR4CTtEmWED4REYUEzaKafb' key = Key(priv_key) pk = key.public_key print(pk)
def decrypt(wif_private_key, torrent_path, cfg): path = get_torrent_data_path(torrent_path, cfg) priv_key = Key(wif_private_key) with open(path, 'rb') as f: encrypted_s = f.read() unencrypted_s = ecies.decrypt(priv_key._pk.secret, encrypted_s) unencrypted_j = json.loads(unencrypted_s) return unencrypted_j
def post_action_transaction(self): if not self.check_input_arguments(["address", "private_key", "amount" ]): return self._response(error_msg.PARAMS_ERROR) try: key = Key(self._input.get("private_key")) transaction_id = key.send( [(str(self._input.get("address")), self._input.get("amount"), "satoshi")], fee=80, ) logger.info("create transaction {}".format(transaction_id)) return self._response(data=transaction_id) except Exception as e: logger.error("create transaction error {}".format(e)) self._msg = str(e) self._ret = 1 return self._response()
def atmpt2(): ''' solution that works...''' from bit import Key wif_private_key = 'cPhnVqon8qro8WmFJ5ma24Lrp59XnudnhywdkPcERw4xM9Mhbr1e' private_key = Key(wif_private_key) encrypted = ecies.encrypt(private_key.public_key, b'this is a test') decrypted = ecies.decrypt(private_key._pk.secret, encrypted) print('encrypted', encrypted) print('decrypted', decrypted)
def get_somme(message, destinataire): current_user_id = message.from_user.id current_wallet = wallet_exist(current_user_id) current_key = Key(current_wallet[1]) solde = decimal.Decimal(current_key.get_balance('btc')) if message.text == 'Annuler': msg = bot.send_message( message.chat.id, "Bonjour, voici l'adresse de votre wallet Bitcoin : \n\n```" + current_wallet[0] + "```\n\nUtilisez-la pour réapprovisionner votre porte-feuille Bitcoin.", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(msg, process_step) else: try: somme = float(message.text) try: outputs = [ (str(destinataire), float(somme), 'btc'), ] trans_link = current_key.send(outputs) msg = bot.send_message( message.chat.id, "Très bien, l'argent a été envoyé ! Les fonds seront disponibles d'ici une heure.\nVoici l'adresse de votre transaction :\nhttps://blockchain.info/tx/" + str(trans_link) + ".", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(msg, process_step) except: msg = bot.send_message( message.chat.id, "Vos BTC n'ont pas été envoyés ! Vérifiez bien que vous avez assez de fonds et réessayez.", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(msg, process_step) except: msg = bot.send_message( message.chat.id, "Entrez la somme à envoyer sous le format suivant : *0.843* (avec un point) !", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(msg, process_step)
def test_hex(hex): if (len(hex) > 64): return False priv_key_compressed = Key.from_hex(hex) priv_key_uncompressed = uncompressed_key(priv_key_compressed) if test_key(priv_key_compressed): return True if test_key(priv_key_uncompressed): return True return False
def get_somme(message, destinataire): current_user_id = message.from_user.id current_wallet = wallet_exist(current_user_id) current_key = Key(current_wallet[1]) solde = decimal.Decimal(current_key.get_balance('btc')) if message.text == 'Back': msg = bot.send_message( message.chat.id, "Hello, here is the address of your Bitcoin wallet: \n\n```" + current_wallet[0] + "```\n\n Use it to fund your Bitcoin wallet.", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(msg, process_step) else: try: somme = float(message.text) try: outputs = [ (str(destinataire), float(somme), 'btc'), ] trans_link = current_key.send(outputs) msg = bot.send_message( message.chat.id, "All right, the money has been sent! Funds will be available within an hour. \n Here is the address of your transaction :\nhttps://blockchain.info/tx/" + str(trans_link) + ".", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(msg, process_step) except: msg = bot.send_message( message.chat.id, "Your wallet has no balance. Make sure you have enough funds and try again.", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(msg, process_step) except: msg = bot.send_message( message.chat.id, "Enter the amount to be sent in the following format: * 0.843 * (with a point)!", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(msg, process_step)
def get_address(message): current_user_id = message.from_user.id current_wallet = wallet_exist(current_user_id) current_key = Key(current_wallet[1]) solde = decimal.Decimal(current_key.get_balance('btc')) global destinataire if message.text == 'Annuler': msg = bot.send_message( message.chat.id, "Bonjour, voici l'adresse de votre wallet Bitcoin : \n\n```" + current_wallet[0] + "```\n\nUtilisez-la pour réapprovisionner votre porte-feuille Bitcoin.", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(msg, process_step) else: destinataire = str(message.text) if (check_address(destinataire) == False): msg = bot.send_message( message.chat.id, "L'adresse du destinataire est incorrecte !", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(msg, process_step) else: commission = decimal.Decimal(get_fee_cached() * 250 / 100000000) msg = bot.send_message( message.chat.id, "Quelle somme voulez-vous envoyer ?\n\nFonds disponibles : " + str(solde) + " BTC (~" + str( satoshi_to_currency( decimal.Decimal(solde) * decimal.Decimal(100000000), 'eur')) + " EUR).\n\n⚠️ Commission du réseau : " + str('%.6f' % commission) + " BTC (~" + str( satoshi_to_currency( commission * decimal.Decimal(100000000), 'eur')) + " EUR).", reply_markup=markup3, parse_mode="Markdown") bot.register_next_step_handler( msg, lambda msg: get_somme(msg, destinataire))
def getPage(pageNum): keyList = [] addrList = [] addrStr1 = "" addrStr2 = "" num = (pageNum - 1) * 128 + 1 try: for i in range(num, num + 128): key1 = Key.from_int(i) wif = bytes_to_wif(key1.to_bytes(), compressed=False) key2 = Key(wif) keyList.append(hex(i)[2:]) addrList.append(key2.address) addrList.append(key1.address) if len(addrStr1): addrStr1 = addrStr1 + "|" addrStr1 = addrStr1 + key2.address if len(addrStr2): addrStr2 = addrStr2 + "|" addrStr2 = addrStr2 + key1.address except: pass return [keyList, addrList, addrStr1, addrStr2]
def getAddress(phrases): keyList = [] addrList = [] addrStr1 = "" addrStr2 = "" try: for phrase in phrases: sha256hex = hashlib.sha256(phrase.encode("utf-8")).hexdigest() key1 = Key.from_hex(sha256hex) wif = bytes_to_wif(key1.to_bytes(), compressed=False) key2 = Key(wif) keyList.append(sha256hex) addrList.append(key2.address) addrList.append(key1.address) if len(addrStr1): addrStr1 = addrStr1 + "|" addrStr1 = addrStr1 + key2.address if len(addrStr2): addrStr2 = addrStr2 + "|" addrStr2 = addrStr2 + key1.address except: pass return [keyList, addrList, addrStr1, addrStr2]
def process_step(message): current_user_id = message.from_user.id current_wallet = wallet_exist(current_user_id) current_key = Key(current_wallet[1]) solde = decimal.Decimal(current_key.get_balance('btc')) if message.text == '💰 Solde': msg = bot.send_message( message.chat.id, "Adresse de votre wallet Bitcoin : ```" + current_wallet[0] + "```\n\nVous avez " + str(solde) + " BTC (~" + str( satoshi_to_currency( decimal.Decimal(solde) * decimal.Decimal(100000000), 'eur')) + " EUR).", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(message, process_step) elif message.text == '↔️ Retirer': msg = bot.send_message(message.chat.id, "Entrez l'adresse du destinataire", reply_markup=markup3, parse_mode="Markdown") bot.register_next_step_handler(msg, get_address)
def process_step(message): current_user_id = message.from_user.id current_wallet = wallet_exist(current_user_id) current_key = Key(current_wallet[1]) solde = decimal.Decimal(current_key.get_balance('btc')) if message.text == 'Ъњ░ Balance': msg = bot.send_message( message.chat.id, "Address of your Bitcoin wallet : ```" + current_wallet[0] + "```\n\nYou have " + str(solde) + " BTC (~" + str( satoshi_to_currency( decimal.Decimal(solde) * decimal.Decimal(100000000), 'eur')) + " EUR).", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(message, process_step) elif message.text == 'Рєћ№ИЈ Transfer': msg = bot.send_message(message.chat.id, "Enter the recipient's address", reply_markup=markup3, parse_mode="Markdown") bot.register_next_step_handler(msg, get_address)
def startGenerating(name, caseSens, thread, running): timestamp = int(time()) rate = times = 0 while True: if not running.value: sys.exit() if int(time()) == timestamp + 1: timestamp += 1 if times < 10: times += 0 if times == 10: print( f'Thread {thread} is generating ~{rate} addresses per second.' ) times += 1 rate = 0 rate += 1 key = Key() address = key.address if (not caseSens and address[1:len(name) + 1].lower() == name.lower()) or (caseSens and address[1:len(name) + 1] == name): privkey = key.to_wif() running.value = False print('-' * 100) print( f'''\nAdress successfully generated!\n\nAddress: {address}\nPrivate key: {privkey}\n''' ) print('-' * 100) print( '\nThe private key gives total access to your coins, so NEVER share it with anyone.' ) print( "Store the private key in a safe place IMMEDIATELY.\n\nThanks for using keepler's VanGen.\nYou can contribute to this project at github.com/Keepler/bitcoinvangen" )
def get_address(message): current_user_id = message.from_user.id current_wallet = wallet_exist(current_user_id) current_key = Key(current_wallet[1]) solde = decimal.Decimal(current_key.get_balance('btc')) global destinataire if message.text == 'Back': msg = bot.send_message( message.chat.id, "Hello, here is the address of your Bitcoin wallet : \n\n```" + current_wallet[0] + "```\n\nUse it to fund your Bitcoin wallet.", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(msg, process_step) else: destinataire = str(message.text) if (check_address(destinataire) == False): msg = bot.send_message(message.chat.id, "The recipient's address is incorrect!", reply_markup=markup, parse_mode="Markdown") bot.register_next_step_handler(msg, process_step) else: commission = decimal.Decimal(get_fee_cached() * 250 / 100000000) msg = bot.send_message( message.chat.id, "How much do you want to send? \ n \ nFunds available : " + str(solde) + " BTC (~" + str( satoshi_to_currency( decimal.Decimal(solde) * decimal.Decimal(100000000), 'eur')) + " EUR).\n\nРџа№ИЈ Network Commission : " + str('%.6f' % commission) + " BTC (~" + str( satoshi_to_currency( commission * decimal.Decimal(100000000), 'eur')) + " EUR).", reply_markup=markup3, parse_mode="Markdown") bot.register_next_step_handler( msg, lambda msg: get_somme(msg, destinataire))
def main(): data = [0, 0, 0, 0] while True: data[0] = privateKey() data[1] = publicKey(data[0]) data[2] = address(data[1]) data[3] = balance(data[2]) if (data[3] == -1): continue if (data[3] == 0): print("{:<34}".format(str(data[2])) + " = " + str(data[3])) if (data[3] > 0): print("\naddress: " + str(data[2]) + "\n" + "private key: " + str(data[0]) + "\n" + "WIF private key: " + str(Key.from_hex(data[0]).to_wif()) + "\n" + "public key: " + str(data[1]).upper() + "\n" + "balance: " + str(data[3]) + "\n") file = open("plutus.txt", "a") file.write("address: " + str(data[2]) + "\n" + "private key: " + str(data[0]) + "\n" + "WIF private key: " + str(Key.from_hex(data[0]).to_wif()) + "\n" + "public key: " + str(data[1]).upper() + "\n" + "balance: " + str(data[3]) + "\n\n") file.close()
def launch(self, compressed=False): for password in self.wordlist: self.pkey.from_passphrase(password) if compressed: wif = self.pkey.privatekey_to_wif(compressed=True) else: wif = self.pkey.privatekey_to_wif() key = Key(wif) balance = key.get_balance('btc') # If the balance is not empty if balance != "0": if key.address not in self.discoveries: print(f'{key.address} : {balance}') self.discoveries.append(key.address) self.file.write_discovery(key.address, password, self.pkey.wif, balance) self.balancetotal += float(balance) self.noemptyaddr += 1 else: print(f'Empty balance for : {password}') print(f'You have found a total of {self.balancetotal} btc') print(f'Addresses with btc : {self.noemptyaddr}') return self.discoveries
def __init__(self, master_wallet_wif, testnet=False, hold_transaction_seconds=20, decimals=-8): if testnet: self.key = PrivateKeyTestnet(master_wallet_wif) self.blockchain_explorer_url = 'https://testnet-api.smartbit.com.au/v1/blockchain/' else: self.key = Key(master_wallet_wif) self.blockchain_explorer_url = 'https://api.smartbit.com.au/v1/blockchain/' self.hold_transaction_seconds = hold_transaction_seconds self.decimals = decimals
def attmpt4_odd_pub_key(): from bit import Key pub_key = '035178ab67471945e966833ffe3c4f6ad8fbac6c2f79c1df80a6ab9686dfb70fde' priv_key = 'cSQh7Ve5YbKptjECW6gMtdhX9v4N1AiN7ypZ22RWBSN31RpkcAsY' pub_key_addr = '2N3qAgYYwv1mJGksATbqzfsJ5LoAxcoCR9J' data = b'We have had success with the odd public key' encrypted = attmpt4_alg(pub_key, data) sk = Key(priv_key) decrypted = ecies.decrypt(sk._pk.secret, encrypted) assert data == decrypted print(decrypted)
def attmpt4_even_pub_key(): from bit import Key pub_key = '02b01692bb20206f03417f9cfd3dfc51e545feb1d7ff5f5f6648a9747988009e8a' priv_key = 'cSetqogg21eiTnhuZ79ru4LBSPiGyfZPDiXy5EWgE1LYhu5NzoAL' pub_key_addr = '2NCrvwAoL7fc8p5bVaqkbXWUmDStvTUBZAb' data = b'We have had success with the even public key' encrypted = attmpt4_alg(pub_key, data) sk = Key(priv_key) decrypted = ecies.decrypt(sk._pk.secret, encrypted) assert data == decrypted print(decrypted)
def load(cls, json_content, test): wif = json_content["wif"] self = BitcoinTicket( PrivateKeyTestnet(wif) if test else Key(wif), json_content["amount"], json_content["spender_hash"], json_content["spender_code"], json_content["receiver_hash"], json_content["receiver_code"], json_content["master_is_spender"], json_content["leftover_address"], json_content["receiver_address"], TicketStatus(json_content["status"]), ) self.test = test self.last_update = json_content["last_update"] return self
def attmpt4_even_pub_key_old(): from bit import Key from coincurve import PublicKey pub_key = '02b01692bb20206f03417f9cfd3dfc51e545feb1d7ff5f5f6648a9747988009e8a' priv_key = 'cSetqogg21eiTnhuZ79ru4LBSPiGyfZPDiXy5EWgE1LYhu5NzoAL' pub_key_addr = '2NCrvwAoL7fc8p5bVaqkbXWUmDStvTUBZAb' pk = PublicKey(int(pub_key, 16).to_bytes(33, 'big')) sk = Key(priv_key) i_pk = int(pub_key, 16) num_bytes = i_pk.bit_length() // 8 + 1 # Only works with big endian despite sys.byteorder returning 'little' # Maybe something to do with how bitcoin does it. endianness = 'big' b_pk = i_pk.to_bytes(num_bytes, endianness) encrypted = ecies.encrypt( b_pk, b'We have had success with the an even public key') decrypted = ecies.decrypt(sk._pk.secret, encrypted) print(decrypted)
def encrypt_user_data(json_data, priv_key=None, pub_key=None): if priv_key is None and pub_key is None: raise Exception( "Only one of {priv_key, pub_key} may retain a value of None") data = encode_and_format(json_data) if pub_key is not None: i_pk = int(pub_key, 16) num_bytes = i_pk.bit_length() // 8 + 1 # Only works with big endian despite sys.byteorder returning 'little' # Maybe something to do with how bitcoin does it. endianness = 'big' b_pk = i_pk.to_bytes(num_bytes, endianness) encrypted = ecies.encrypt(b_pk, data) else: key = Key(priv_key) encrypted = ecies.encrypt(key.public_key, data) return encrypted
class BTCInfo: firstRun = True username = '' my_key = Key('') def PrintBalance(self): balance = BTCInfo.my_key.get_balance('USD') balanceBTC = BTCInfo.my_key.get_balance('BTC') print("[+]Your Balances: " + balance, balanceBTC) def firstTimeSetup(self): print('Welcome to PyCoins!') name = input('[+]Please enter your name:') BTCInfo.username = name print('Welcome, {}!'.format(BTCInfo.username)) key = input('[+]Enter your private key:') BTCInfo.my_key = key print('[+]PyCoins is ready!') time.sleep(3)