def from_seed(self, seed, storage): import mnemonic if not seed: return words = seed.strip().split() try: mnemonic.mn_decode(words) uses_electrum_words = True except Exception: uses_electrum_words = False try: seed.decode('hex') is_hex = True except Exception: is_hex = False if is_hex or (uses_electrum_words and len(words) != 13): print "old style wallet", len(words), words w = OldWallet(storage) w.init_seed(seed) #hex else: #assert is_seed(seed) w = Wallet(storage) w.init_seed(seed) return w
def recoverSK(seed): mn2 = seed.split(" ") #make array if len(mn2) > 13: mn2 = mn2[:24] sk = mnemonic.mn_decode(mn2) else: mn2 = mn2[:12] #mn2 += mn2[:] sk = cn_fast_hash(mnemonic.mn_decode(mn2)) #sk = mnemonic.mn_decode(mn2) return sk
def is_old_seed(seed): import mnemonic words = seed.strip().split() try: mnemonic.mn_decode(words) uses_electrum_words = True except Exception: uses_electrum_words = False try: seed.decode('hex') is_hex = True except Exception: is_hex = False return is_hex or (uses_electrum_words and len(words) == 12)
def is_old_seed(seed): import mnemonic words = seed.strip().split() try: mnemonic.mn_decode(words) uses_electrum_words = True except Exception: uses_electrum_words = False try: seed.decode('hex') is_hex = (len(seed) == 32) except Exception: is_hex = False return is_hex or (uses_electrum_words and len(words) == 12)
def recover(): droid.dialogCreateAlert("Wallet not found","Do you want to create a new wallet, or restore an existing one?") droid.dialogSetPositiveButtonText('Create') droid.dialogSetNeutralButtonText('Restore') droid.dialogSetNegativeButtonText('Cancel') droid.dialogShow() response = droid.dialogGetResponse().result droid.dialogDismiss() if response.get('which') == 'negative': exit(1) is_recovery = response.get('which') == 'neutral' if not is_recovery: wallet.new_seed(None) else: if modal_question("Input method",None,'QR Code', 'mnemonic'): code = droid.scanBarcode() r = code.result if r: seed = r['extras']['SCAN_RESULT'] else: exit(1) else: m = modal_input('Mnemonic','please enter your code') try: seed = mnemonic.mn_decode(m.split(' ')) except: modal_dialog('error: could not decode this seed') exit(1) wallet.seed = str(seed) modal_dialog('Your seed is:', wallet.seed) modal_dialog('Mnemonic code:', ' '.join(mnemonic.mn_encode(wallet.seed)) ) msg = "recovering wallet..." if is_recovery else "creating wallet..." droid.dialogCreateSpinnerProgress("Electrum", msg) droid.dialogShow() wallet.init_mpk( wallet.seed ) WalletSynchronizer(wallet,True).start() wallet.update() droid.dialogDismiss() droid.vibrate() if is_recovery: if wallet.is_found(): wallet.update_tx_history() wallet.fill_addressbook() modal_dialog("recovery successful") else: if not modal_question("no transactions found for this seed","do you want to keep this wallet?"): exit(1) change_password_dialog() wallet.save()
def run_recovery_dialog(wallet): message = "Please enter your wallet seed or the corresponding mnemonic list of words, and the gap limit of your wallet." dialog = gtk.MessageDialog( parent = None, flags = gtk.DIALOG_MODAL, buttons = gtk.BUTTONS_OK_CANCEL, message_format = message) vbox = dialog.vbox dialog.set_default_response(gtk.RESPONSE_OK) # ask seed, server and gap in the same dialog seed_box = gtk.HBox() seed_label = gtk.Label('Seed or mnemonic:') seed_label.set_size_request(150,-1) seed_box.pack_start(seed_label, False, False, 10) seed_label.show() seed_entry = gtk.Entry() seed_entry.show() seed_entry.set_size_request(450,-1) seed_box.pack_start(seed_entry, False, False, 10) add_help_button(seed_box, '.') seed_box.show() vbox.pack_start(seed_box, False, False, 5) gap = gtk.HBox() gap_label = gtk.Label('Gap limit:') gap_label.set_size_request(150,10) gap_label.show() gap.pack_start(gap_label,False, False, 10) gap_entry = gtk.Entry() gap_entry.set_text("%d"%wallet.gap_limit) gap_entry.connect('changed', numbify, True) gap_entry.show() gap.pack_start(gap_entry,False,False, 10) add_help_button(gap, 'The maximum gap that is allowed between unused addresses in your wallet. During wallet recovery, this parameter is used to decide when to stop the recovery process. If you increase this value, you will need to remember it in order to be able to recover your wallet from seed.') gap.show() vbox.pack_start(gap, False,False, 5) dialog.show() r = dialog.run() gap = gap_entry.get_text() seed = seed_entry.get_text() dialog.destroy() if r==gtk.RESPONSE_CANCEL: sys.exit(1) try: gap = int(gap) except: show_message("error") sys.exit(1) try: seed.decode('hex') except: print_error("Warning: Not hex, trying decode") seed = mnemonic.mn_decode( seed.split(' ') ) if not seed: show_message("no seed") sys.exit(1) wallet.seed = seed wallet.gap_limit = gap wallet.save()
outs.append({'value' : data["amounts"][i], 'address' : data["targets"][i]}) rtx = pbt.mktx(data["u"], outs) # serialized tx dtx = pbt.deserialize(rtx) base.display_dtx(dtx, data) print "Check balance and targets. Remove your data source (USB-stick)." print "Press <enter> to proceed, <ctrl-c> to cancel." raw_input() print print "Enter private key or (double) Electrum seed:" priv = raw_input().strip() if " " in priv: seed = mnemonic.mn_decode(priv.split(" ")) priv = pbt.electrum_privkey(seed, 0, 0) # root key source = pbt.privkey_to_address(priv) if source != data["source"]: print "Address from privkey:", source raise Exception ("Privkey does not match source address.") print # sign tx for i in range(len(dtx["ins"])): rtx = pbt.sign(rtx, i, priv) print "signed serialized tx:" print rtx58 = pbt.changebase(rtx, 16, 58)
print "Enter a title for this paper wallet and press <enter>." title = raw_input().strip() print "working...\n\n" # generate passPhrase entropy = rawEntropy entropy += os.urandom(32) + str(random.randrange(2**256)) + str( int(time.time())**7) # from Vitalik entropyHash = hashlib.sha256(entropy).hexdigest() words = mnemonic.mn_encode(entropyHash) if len(words) != WORDS: raise Exception("Encode error.") passPhrase = " ".join(words) seed = mnemonic.mn_decode(passPhrase.split(" ")) rootPrivKey = pbt.electrum_privkey(seed, 0, 0) rootAddress = pbt.electrum_address(seed, 0, 0) mpk = pbt.electrum_mpk(seed) # output parts = [" ".join(words[:WORDS / 2]), " ".join(words[WORDS / 2:])] for i, p in enumerate(parts): part = " ".join(p) for c in range(2): print "\n" + "-" * DASHLEN + "\n" if title: print title print "Electrum 1.x seed part %d of %d" % (i + 1, PARTS), " copy", "AB"[c]
def recover(): droid.dialogCreateAlert( "Wallet not found", "Do you want to create a new wallet, or restore an existing one?") droid.dialogSetPositiveButtonText('Create') droid.dialogSetNeutralButtonText('Restore') droid.dialogSetNegativeButtonText('Cancel') droid.dialogShow() response = droid.dialogGetResponse().result droid.dialogDismiss() if response.get('which') == 'negative': exit(1) is_recovery = response.get('which') == 'neutral' if not is_recovery: wallet.new_seed(None) else: if modal_question("Input method", None, 'QR Code', 'mnemonic'): code = droid.scanBarcode() r = code.result if r: seed = r['extras']['SCAN_RESULT'] else: exit(1) else: m = modal_input('Mnemonic', 'please enter your code') try: seed = mnemonic.mn_decode(m.split(' ')) except: modal_dialog('error: could not decode this seed') exit(1) wallet.seed = str(seed) modal_dialog('Your seed is:', wallet.seed) modal_dialog('Mnemonic code:', ' '.join(mnemonic.mn_encode(wallet.seed))) msg = "recovering wallet..." if is_recovery else "creating wallet..." droid.dialogCreateSpinnerProgress("Electrum", msg) droid.dialogShow() wallet.init_mpk(wallet.seed) WalletSynchronizer(wallet, True).start() wallet.update() droid.dialogDismiss() droid.vibrate() if is_recovery: if wallet.is_found(): wallet.update_tx_history() wallet.fill_addressbook() modal_dialog("recovery successful") else: if not modal_question("no transactions found for this seed", "do you want to keep this wallet?"): exit(1) change_password_dialog() wallet.save()
rawEntropy = raw_input() print "Enter a title for this paper wallet and press <enter>." title = raw_input().strip() print "working...\n\n" # generate passPhrase entropy = rawEntropy entropy += os.urandom(32) + str(random.randrange(2**256)) + str(int(time.time())**7) # from Vitalik entropyHash = hashlib.sha256(entropy).hexdigest() words = mnemonic.mn_encode(entropyHash) if len(words) != WORDS: raise Exception("Encode error.") passPhrase = " ".join(words) seed = mnemonic.mn_decode(passPhrase.split(" ")) rootPrivKey = pbt.electrum_privkey(seed, 0, 0) rootAddress = pbt.electrum_address(seed, 0, 0) mpk = pbt.electrum_mpk(seed) # output parts = [" ".join(words[:WORDS / 2]), " ".join(words[WORDS / 2:])] for i, p in enumerate(parts): part = " ".join(p) for c in range(2): print "\n" + "-" * DASHLEN + "\n" if title: print title print "Electrum 1.x seed part %d of %d" % (i + 1, PARTS), " copy", "AB"[c] if i == 0: