Exemplo n.º 1
0
def get_last_word(first_words):
    _, is_wordlist_valid = bip39_is_checksum_valid(first_words)
    if is_wordlist_valid is False:
        raise Exception("Invalid BIP39 Word in first_words: %s" % first_words)

    # Find last word
    for word in Wordlist.from_file("english.txt"):
        challenge = first_words + " " + word
        is_checksum_valid, _ = bip39_is_checksum_valid(challenge)
        if is_checksum_valid:
            return word

    raise Exception("Can't find valid checksum word")
Exemplo n.º 2
0
def calculate_seed_and_xpubs(first_words):
    first_words = first_words.strip()
    last_word = get_last_word(first_words=first_words)
    whole_seed = first_words + " " + last_word
    is_checksum_valid, _ = bip39_is_checksum_valid(whole_seed)
    assert is_checksum_valid is True

    if constants.net == constants.BitcoinMainnet:
        derivation_path = "m/48'/0'/0'/2'"
    elif constants.net == constants.BitcoinTestnet:
        derivation_path = "m/48'/1'/0'/2'"
    else:
        raise Exception("Invalid Network: %s" % constants.net)

    ks = from_bip39_seed(seed=whole_seed, passphrase="", derivation=derivation_path)

    return (
        {
            "last_word": last_word,
            "whole_seed": whole_seed,
            "whole_seed_word_count": len(whole_seed.split()),
        },
        {
            "xfp": ks.get_root_fingerprint().upper(),  # uppercase to match others, unsure if that matters
            "p2wsh": ks.get_master_public_key(),
            "p2wsh_deriv": derivation_path,
        },
    )
Exemplo n.º 3
0
def main():
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('--check', action='store_true', default=False)
    args = arg_parser.parse_args()

    lines = [x.strip() for x in sys.stdin.readlines()]

    words = ""
    passw = ""
    if len(lines) == 2:
        passw = lines[1]
    if not (len(lines) in [1, 2]):
        print("wrong input", file=sys.stderr)
        sys.exit(1)

    words = lines[0]

    if (args.check):
        (checksum_ok, wordlist_ok) = keystore.bip39_is_checksum_valid(words)
        if not wordlist_ok:
            print("Unkown words!", file=sys.stderr)
            sys.exit(1)
        if not checksum_ok:
            print("Checksum NOT OK!", file=sys.stderr)
            sys.exit(1)

    print(util.bh2u(keystore.bip39_to_seed(words, passw)))
Exemplo n.º 4
0
def main():
    f = open('seedwords.txt')
    lines = f.read().split('\n')

    threads = []

    for line in lines:
        (checksum_ok, wordlist_ok) = keystore.bip39_is_checksum_valid(line)
        print("[CHECK] " + line)
        if not wordlist_ok:
            print("       Unknown words!", file=sys.stderr)
            continue
        if not checksum_ok:
            print("       Checksum NOT OK!", file=sys.stderr)
            continue
        print("       Check passed. Queued.")
        t = threading.Thread(target=checkPassphrase, args=(line, ))
        threads.append(t)
        t.start()

        if len(threads) == MAX_THREADS:
            for t in threads:
                t.join()

            threads.clear()
Exemplo n.º 5
0
 def update_next_button(self):
     from electrum.keystore import bip39_is_checksum_valid
     text = self.get_text()
     if self.is_bip39:
         is_seed, is_wordlist = bip39_is_checksum_valid(text)
     else:
         is_seed = bool(self._test(text))
     self.ids.next.disabled = not is_seed
Exemplo n.º 6
0
    def verify_seed(self,
                    seed,
                    bip39=False,
                    slip39=False,
                    wallet_type='standard',
                    language='en'):
        self._logger.debug('bip39 ' + str(bip39))
        self._logger.debug('slip39 ' + str(slip39))

        seed_type = ''
        seed_valid = False
        validation_message = ''

        if not (bip39 or slip39):
            seed_type = mnemonic.seed_type(seed)
            if seed_type != '':
                seed_valid = True
        elif bip39:
            is_checksum, is_wordlist = bip39_is_checksum_valid(seed)
            status = ('checksum: ' + ('ok' if is_checksum else 'failed')
                      ) if is_wordlist else 'unknown wordlist'
            validation_message = 'BIP39 (%s)' % status

            if is_checksum:
                seed_type = 'bip39'
                seed_valid = True

        elif slip39:  # TODO: incomplete impl, this code only validates a single share.
            try:
                share = decode_mnemonic(seed)
                seed_type = 'slip39'
                validation_message = 'SLIP39: share #%d in %dof%d scheme' % (
                    share.group_index, share.group_threshold,
                    share.group_count)
            except Slip39Error as e:
                validation_message = 'SLIP39: %s' % str(e)
            seed_valid = False  # for now

        # cosigning seed
        if wallet_type != 'standard' and seed_type not in [
                'standard', 'segwit'
        ]:
            seed_type = ''
            seed_valid = False

        self.seedType = seed_type
        self.seedTypeChanged.emit()

        if self.validationMessage != validation_message:
            self.validationMessage = validation_message
            self.validationMessageChanged.emit()

        if self.seedValid != seed_valid:
            self.seedValid = seed_valid
            self.seedValidChanged.emit()

        self._logger.debug('seed verified: ' + str(seed_valid))
Exemplo n.º 7
0
    def on_edit(self):
        s = ' '.join(self.get_seed_words())
        b = self.is_seed(s)
        if self.seed_type == 'bip39':
            from electrum.keystore import bip39_is_checksum_valid
            is_checksum, is_wordlist = bip39_is_checksum_valid(s)
            status = ('checksum: ' + ('ok' if is_checksum else 'failed')
                      ) if is_wordlist else 'unknown wordlist'
            label = 'BIP39' + ' (%s)' % status
        elif self.seed_type == 'slip39':
            self.slip39_mnemonics[self.slip39_mnemonic_index] = s
            try:
                slip39.decode_mnemonic(s)
            except slip39.Slip39Error as e:
                share_status = str(e)
                current_mnemonic_invalid = True
            else:
                share_status = _('Valid.')
                current_mnemonic_invalid = False

            label = _('SLIP39 share') + ' #%d: %s' % (
                self.slip39_mnemonic_index + 1, share_status)

            # No need to process mnemonics if the current mnemonic remains invalid after editing.
            if not (self.slip39_current_mnemonic_invalid
                    and current_mnemonic_invalid):
                self.slip39_seed, seed_status = slip39.process_mnemonics(
                    self.slip39_mnemonics)
                self.seed_status.setText(seed_status)
            self.slip39_current_mnemonic_invalid = current_mnemonic_invalid

            b = self.slip39_seed is not None
            self.update_share_buttons()
        else:
            t = seed_type(s)
            label = _('Seed Type') + ': ' + t if t else ''
            if t and not b:  # electrum seed, but does not conform to dialog rules
                msg = ' '.join([
                    '<b>' + _('Warning') + ':</b>  ',
                    _("Looks like you have entered a valid seed of type '{}' but this dialog does not support such seeds."
                      ).format(t),
                    _("If unsure, try restoring as '{}'.").format(
                        _("Standard wallet")),
                ])
                self.seed_warning.setText(msg)
            else:
                self.seed_warning.setText("")

        self.seed_type_label.setText(label)
        self.parent.next_button.setEnabled(b)

        # disable suggestions if user already typed an unknown word
        for word in self.get_seed_words()[:-1]:
            if word not in self.wordlist:
                self.seed_e.disable_suggestions()
                return
        self.seed_e.enable_suggestions()
    def on_edit(self, *, from_click=False):
        s = ' '.join(self.get_seed_words())
        b = self.is_seed(s)

        from electrum.keystore import bip39_is_checksum_valid
        from electrum.mnemonic import Wordlist, filenames

        lang = ''
        for type, file in filenames.items():
            word_list = Wordlist.from_file(file)
            is_checksum, is_wordlist = bip39_is_checksum_valid(s, wordlist=word_list)
            if is_wordlist:
                lang = type
                break

        if self.seed_type == 'bip39':
            status = ('checksum: ' + ('ok' if is_checksum else 'failed')) if is_wordlist else 'unknown wordlist'
            label = 'BIP39 - ' + lang + ' (%s)'%status
            if lang and lang != self.lang:
                if lang == 'en':
                    bip39_english_list = Mnemonic('en').wordlist
                    old_list = old_mnemonic.wordlist
                    only_old_list = set(old_list) - set(bip39_english_list)
                    self.wordlist = list(bip39_english_list) + list(only_old_list)  # concat both lists
                    self.wordlist.sort()
                    self.completer.model().setStringList(self.wordlist)
                    self.lang = 'en'
                else:
                    self.wordlist = list(Mnemonic(lang).wordlist)
                    self.wordlist.sort()
                    self.completer.model().setStringList(self.wordlist)
                    self.lang = lang
            b = is_checksum
        else:
            t = seed_type(s)
            label = _('Seed Type') + ': ' + t if t else ''

            if is_checksum and is_wordlist and not from_click:
                # This is a valid bip39 and this method was called from typing
                # Emulate selecting the bip39 option
                self.clayout.group.buttons()[1].click()
                return

        self.seed_type_label.setText(label)
        self.parent.next_button.setEnabled(b)

        # disable suggestions if user already typed an unknown word
        for word in self.get_seed_words()[:-1]:
            if word not in self.wordlist:
                self.seed_e.disable_suggestions()
                return
        self.seed_e.enable_suggestions()
Exemplo n.º 9
0
 def on_edit(self):
     s = self.get_seed()
     b = self.is_seed(s)
     if not self.is_bip39:
         t = seed_type(s)
         label = _('Seed Type') + ': ' + t if t else ''
     else:
         from electrum.keystore import bip39_is_checksum_valid
         is_checksum, is_wordlist = bip39_is_checksum_valid(s)
         status = ('checksum: ' + ('ok' if is_checksum else 'failed')) if is_wordlist else 'unknown wordlist'
         label = 'BIP39' + ' (%s)'%status
     self.seed_type_label.setText(label)
     self.parent.next_button.setEnabled(b)
Exemplo n.º 10
0
 def on_edit(self):
     from electrum.bitcoin import seed_type
     s = self.get_seed()
     b = self.is_seed(s)
     if not self.is_bip39:
         t = seed_type(s)
         label = _('Seed Type') + ': ' + t if t else ''
     else:
         from electrum.keystore import bip39_is_checksum_valid
         is_checksum, is_wordlist = bip39_is_checksum_valid(s)
         status = ('checksum: ' + ('ok' if is_checksum else 'failed')) if is_wordlist else 'unknown wordlist'
         label = 'BIP39' + ' (%s)'%status
     self.seed_type_label.setText(label)
     self.parent.next_button.setEnabled(b)
Exemplo n.º 11
0
def main():
    SEED_COUNTER = 0
    VALID_SEED_COUNT = 0

    TOTAL_COUNTER = 0
    SEED_START_TIME = time.time()
    while True:
        # GENERATE NEW SEED PHRASE
        word = ""
        WORD_COUNT = 0
        SEED_TO_TEST = ''
        for suit in my_shuffle(SEED_ARRAY):
            if (WORD_COUNT <= 24):
                word = word + " " + suit
                WORD_COUNT += 1
            if (WORD_COUNT == 24):
                line = word
                threads = []
                SEED_COUNTER += 1
                if (SEED_COUNTER >= 1000):
                    TOTAL_COUNTER += SEED_COUNTER
                    SEED_COUNTER = 0
                    TIME_SINCE = time.time() - SEED_START_TIME
                    print("[BRUTEFORCE] Checked " + str(TOTAL_COUNTER) +
                          " seeds and found " + str(VALID_SEED_COUNT) +
                          " valid seeds in " + str(TIME_SINCE) + " seconds.")

                (checksum_ok,
                 wordlist_ok) = keystore.bip39_is_checksum_valid(line)
                if not wordlist_ok:
                    print("       Unknown words!" + line, file=sys.stderr)
                    continue
                if not checksum_ok:
                    #print("       Checksum NOT OK!" + line, file=sys.stderr)
                    continue
                #print("       Check passed. Queued:  " + line)
                VALID_SEED_COUNT += 1

                t = threading.Thread(target=checkPassphrase, args=(line, ))
                threads.append(t)
                t.start()

                if len(threads) == MAX_THREADS:
                    for t in threads:
                        t.join()

                    threads.clear()
Exemplo n.º 12
0
def main():
    words = read_and_validate()

    wordlist = mnemonic.Mnemonic().wordlist
    print("Good last words:")
    ok_words = []
    for last in wordlist:
        (checksum_ok, wordlist_ok) = keystore.bip39_is_checksum_valid(
            " ".join(words + [last]))
        assert wordlist_ok
        if checksum_ok:
            print(last)
            ok_words.append(last)

    prng = coinchooser.PRNG(os.urandom(100))
    print("\nA random choice would be:")
    print(prng.choice(ok_words))
Exemplo n.º 13
0
    def on_edit(self):
        s = ' '.join(self.get_seed_words())
        b = self.is_seed(s)
        if self.seed_type == 'bip39':
            from electrum.keystore import bip39_is_checksum_valid
            is_checksum, is_wordlist = bip39_is_checksum_valid(s)
            status = ('checksum: ' + ('ok' if is_checksum else 'failed')
                      ) if is_wordlist else 'unknown wordlist'
            label = 'BIP39' + ' (%s)' % status
        elif self.seed_type == 'slip39':
            self.slip39_mnemonics[self.slip39_mnemonic_index] = s
            try:
                slip39.decode_mnemonic(s)
            except slip39.Slip39Error as e:
                share_status = str(e)
                current_mnemonic_invalid = True
            else:
                share_status = _('Valid.')
                current_mnemonic_invalid = False

            label = _('SLIP39 share') + ' #%d: %s' % (
                self.slip39_mnemonic_index + 1, share_status)

            # No need to process mnemonics if the current mnemonic remains invalid after editing.
            if not (self.slip39_current_mnemonic_invalid
                    and current_mnemonic_invalid):
                self.slip39_seed, seed_status = slip39.process_mnemonics(
                    self.slip39_mnemonics)
                self.seed_status.setText(seed_status)
            self.slip39_current_mnemonic_invalid = current_mnemonic_invalid

            b = self.slip39_seed is not None
            self.update_share_buttons()
        else:
            t = seed_type(s)
            label = _('Seed Type') + ': ' + t if t else ''

        self.seed_type_label.setText(label)
        self.parent.next_button.setEnabled(b)

        # disable suggestions if user already typed an unknown word
        for word in self.get_seed_words()[:-1]:
            if word not in self.wordlist:
                self.seed_e.disable_suggestions()
                return
        self.seed_e.enable_suggestions()
Exemplo n.º 14
0
    def on_edit(self):
        s = self.get_seed()
        b = self.is_seed(s)
        if not self.is_bip39:
            t = seed_type(s)
            label = _('Seed Type') + ': ' + t if t else ''
        else:
            from electrum.keystore import bip39_is_checksum_valid
            is_checksum, is_wordlist = bip39_is_checksum_valid(s)
            status = ('checksum: ' + ('ok' if is_checksum else 'failed')) if is_wordlist else 'unknown wordlist'
            label = 'BIP39' + ' (%s)'%status
        self.seed_type_label.setText(label)
        self.parent.next_button.setEnabled(b)

        # disable suggestions if user already typed an unknown word
        for word in self.get_seed().split(" ")[:-1]:
            if word not in self.wordlist:
                self.seed_e.disable_suggestions()
                return
        self.seed_e.enable_suggestions()
Exemplo n.º 15
0
    def on_edit(self):
        s = self.get_seed()
        b = self.is_seed(s)
        if not self.is_bip39:
            t = seed_type(s)
            label = _('Seed Type') + ': ' + t if t else ''
        else:
            from electrum.keystore import bip39_is_checksum_valid
            is_checksum, is_wordlist = bip39_is_checksum_valid(s)
            status = ('checksum: ' + ('ok' if is_checksum else 'failed')) if is_wordlist else 'unknown wordlist'
            label = 'BIP39' + ' (%s)'%status
        self.seed_type_label.setText(label)
        self.parent.next_button.setEnabled(b)

        # to account for bip39 seeds
        for word in self.get_seed().split(" ")[:-1]:
            if word not in self.wordlist:
                self.seed_e.disable_suggestions()
                return
        self.seed_e.enable_suggestions()
Exemplo n.º 16
0
def read_and_validate():
    lines = [x.strip() for x in sys.stdin.readlines()]

    if len(lines) != 1:
        print("Give words in one line", file=sys.stderr)
        sys.exit(1)

    first_line = lines[0]
    words = first_line.split()
    if (len(words) + 1) not in ACCEPTED_LENGTHS:
        print("{0} words given, but number should be one of {1}".format(
            len(words), str([x - 1 for x in ACCEPTED_LENGTHS])),
              file=sys.stderr)
        sys.exit(1)

    (first_checksum_ok,
     first_wordlist_ok) = keystore.bip39_is_checksum_valid(" ".join(words))
    if not first_wordlist_ok:
        print("Unkown words!", file=sys.stderr)
        sys.exit(1)

    return words
    def on_edit(self):
        s = ' '.join(self.get_seed_words())
        b = self.is_seed(s)
        if self.seed_type == 'bip39':
            from electrum.keystore import bip39_is_checksum_valid
            from electrum.mnemonic import Wordlist, filenames

            lang = ''
            for type, file in filenames.items():
                word_list = Wordlist.from_file(file)
                is_checksum, is_wordlist = bip39_is_checksum_valid(s, wordlist=word_list)
                if is_wordlist:
                    lang = type
                    break

            status = ('checksum: ' + ('ok' if is_checksum else 'failed')) if is_wordlist else 'unknown wordlist'
            label = 'BIP39 - ' + lang + ' (%s)'%status
            if lang and lang != self.lang:
                if lang == 'en':
                    bip39_english_list = Mnemonic('en').wordlist
                    old_list = old_mnemonic.wordlist
                    only_old_list = set(old_list) - set(bip39_english_list)
                    self.wordlist = list(bip39_english_list) + list(only_old_list)  # concat both lists
                    self.wordlist.sort()
                    self.completer.model().setStringList(self.wordlist)
                    self.lang = 'en'
                else:
                    self.wordlist = list(Mnemonic(lang).wordlist)
                    self.wordlist.sort()
                    self.completer.model().setStringList(self.wordlist)
                    self.lang = lang

        elif self.seed_type == 'slip39':
            self.slip39_mnemonics[self.slip39_mnemonic_index] = s
            try:
                slip39.decode_mnemonic(s)
            except slip39.Slip39Error as e:
                share_status = str(e)
                current_mnemonic_invalid = True
            else:
                share_status = _('Valid.')
                current_mnemonic_invalid = False

            label = _('SLIP39 share') + ' #%d: %s' % (self.slip39_mnemonic_index + 1, share_status)

            # No need to process mnemonics if the current mnemonic remains invalid after editing.
            if not (self.slip39_current_mnemonic_invalid and current_mnemonic_invalid):
                self.slip39_seed, seed_status = slip39.process_mnemonics(self.slip39_mnemonics)
                self.seed_status.setText(seed_status)
            self.slip39_current_mnemonic_invalid = current_mnemonic_invalid

            b = self.slip39_seed is not None
            self.update_share_buttons()
        else:
            t = seed_type(s)
            label = _('Seed Type') + ': ' + t if t else ''

        self.seed_type_label.setText(label)
        self.parent.next_button.setEnabled(b)

        # disable suggestions if user already typed an unknown word
        for word in self.get_seed_words()[:-1]:
            if word not in self.wordlist:
                self.seed_e.disable_suggestions()
                return
        self.seed_e.enable_suggestions()
Exemplo n.º 18
0
def main():
    SEED_COUNTER=0
    VALID_SEED_COUNT=0

    TOTAL_COUNTER=0
    SEED_START_TIME=time.time()
    while True:
        # GENERATE NEW SEED PHRASE
        word=""
        PAIRED_LIST=""
        WORD_COUNT=0
        SEED_TO_TEST=''
        for suit in my_shuffle(SEED_ARRAY):
            if (WORD_COUNT <= 18): 
                word=word+" "+suit
                WORD_COUNT+= 1
            if (WORD_COUNT == 18): 
            
            
            
                #pair up the shuffled words  
                CHOSEN_WORDS=word.split()
                PAIRED_LIST=[]
                PAIRED_LIST.append('code easily')
                PAIRED_LIST.append('attack early')
                PAIRED_LIST.append('almost open')
                PAIRED_LIST.append(CHOSEN_WORDS[0]+' '+CHOSEN_WORDS[1])
                PAIRED_LIST.append(CHOSEN_WORDS[2]+' '+CHOSEN_WORDS[3])
                PAIRED_LIST.append(CHOSEN_WORDS[4]+' '+CHOSEN_WORDS[5])
                PAIRED_LIST.append(CHOSEN_WORDS[6]+' '+CHOSEN_WORDS[7])
                PAIRED_LIST.append(CHOSEN_WORDS[8]+' '+CHOSEN_WORDS[9])
                PAIRED_LIST.append(CHOSEN_WORDS[10]+' '+CHOSEN_WORDS[11])
                PAIRED_LIST.append(CHOSEN_WORDS[12]+' '+CHOSEN_WORDS[13])
                PAIRED_LIST.append(CHOSEN_WORDS[14]+' '+CHOSEN_WORDS[15])
                PAIRED_LIST.append(CHOSEN_WORDS[16]+' '+CHOSEN_WORDS[17])
                # Now shuffle the pairs  and generate seed phrase
                PAIRED_WORDS=""
                PAIRED_WORD_COUNT=0
 
                for PAIR in my_shuffle(PAIRED_LIST):
                    if (PAIRED_WORD_COUNT <= 12): 
                        PAIRED_WORDS=PAIRED_WORDS+" "+PAIR
                        PAIRED_WORD_COUNT+= 1
                    if (PAIRED_WORD_COUNT == 12): 
                        line = PAIRED_WORDS
                        threads = []                
                        SEED_COUNTER+=1
                        if (SEED_COUNTER >= 1000):
                            TOTAL_COUNTER+=SEED_COUNTER
                            SEED_COUNTER=0
                            TIME_SINCE=time.time()-SEED_START_TIME
                            print("[BRUTEFORCE] Checked "+str(TOTAL_COUNTER)+" seeds and found "+str(VALID_SEED_COUNT)+" valid seeds in "+str(TIME_SINCE)+" seconds." )
    
         
                        (checksum_ok, wordlist_ok) = keystore.bip39_is_checksum_valid(line)
                        if not wordlist_ok:
                            print("       Unknown words!" + line, file=sys.stderr)
                            continue
                        if not checksum_ok:
                       #print("       Checksum NOT OK!" + line, file=sys.stderr)
                            continue
                    #print("       Check passed. Queued:  " + line)
                        VALID_SEED_COUNT+=1

                        t = threading.Thread(target=checkPassphrase, args=(line,))
                        threads.append(t)
                        t.start()

                        if len(threads) == MAX_THREADS:
                            for t in threads:
                                t.join()

                            threads.clear()
Exemplo n.º 19
0
 def test(self):
     mnemonic = u'gravity machine north sort system female filter attitude volume fold club stay feature office ecology stable narrow fog'
     is_checksum_valid, is_wordlist_valid = keystore.bip39_is_checksum_valid(mnemonic)
     self.assertTrue(is_wordlist_valid)
     self.assertTrue(is_checksum_valid)
Exemplo n.º 20
0
 def test(self):
     mnemonic = u'gravity machine north sort system female filter attitude volume fold club stay feature office ecology stable narrow fog'
     is_checksum_valid, is_wordlist_valid = keystore.bip39_is_checksum_valid(
         mnemonic)
     self.assertTrue(is_wordlist_valid)
     self.assertTrue(is_checksum_valid)
Exemplo n.º 21
0
import argparse
import sys

arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('--no-check', action='store_true', default=False)
args = arg_parser.parse_args()

lines = [x.strip() for x in sys.stdin.readlines()]

words = ""
passw = ""
if len(lines) == 2:
    passw = lines[1]
if not (len(lines) in [1, 2]):
    print("wrong input", file=sys.stderr)
    sys.exit(1)

words = lines[0]

if not args.no_check:
    (checksum_ok, wordlist_ok) = keystore.bip39_is_checksum_valid(words)
    if not wordlist_ok:
        print("Unknown words!", file=sys.stderr)
        sys.exit(1)
    if not checksum_ok:
        print("Checksum NOT OK!", file=sys.stderr)
        sys.exit(1)

print(keystore.bip39_to_seed(words, passw).hex())