Ejemplo n.º 1
0
    def split_key(self):
        """
        Callback function for split button
        """
        try:
            m = self.mBox.value()
            n = self.nBox.value()
            mnemonics = self.mnemonicsTextEdit.toPlainText()
            language = self.languageComboBox.currentText()
            encoding = Encoding.BIP39
            if self.encodingComboBox1.currentIndex() == 1:
                encoding = Encoding.BASE58

            shares = split_shares(mnemonics, m, n, encoding, language=language)
            shares_text = "\n\n".join(shares)

            self.sharesTextEdit.setText(shares_text)

        except BadRequest as e:
            error_dialog = QtWidgets.QErrorMessage()
            error_dialog.showMessage("Bad Request! Invalid Input!")

        except Exception:
            error_dialog = QtWidgets.QErrorMessage()
            error_dialog.showMessage("Error!")
Ejemplo n.º 2
0
def split(input_type, m, n, encoding, export, lang):
    """
    Split the BIP39 mnemonic into Shamir39 shares
    """
    mnemonic = ""
    if input_type == "CMD":
        mnemonic = click.prompt("BIP39 Mnemonics: ", type=str)
    elif input_type == "FILE":
        file_path = click.prompt("Input File Path: ", type=str)
        if os.path.isfile(file_path):
            file_handler = open(file_path, "r")
            mnemonic = file_handler.read()
        else:
            raise click.FileError("File doesn't exist.")
    
    shares = split_shares(mnemonic, m, n, encoding, LANG_MAP[lang])
    click.echo(shares)

    if export == "MULTI":
        for share in shares:
            file_handler = open("shamir-share-{}.txt".format(shares.index(share)+1), "w")
            file_handler.write(share)
            file_handler.close()
    else:
        file_handler = open("shamir-share.txt", "w")
        for share in shares:
            file_handler.write(share)
            file_handler.write("\n")
        file_handler.close()
Ejemplo n.º 3
0
    def test_recovery(self):
        mnemonics = generate(18)
        # Get 5 of 8 split
        shamir_shares = split_shares(mnemonics, 7, 10)
        self.assertEqual(len(shamir_shares), 10)
        recovered_mnemonics = combine_shares(shamir_shares[:9])
        self.assertEqual(recovered_mnemonics, mnemonics)

        self.assertRaises(BadRequest, combine_shares, shamir_shares[:6])
Ejemplo n.º 4
0
 def test_split_shares_base58(self):
     mnemonics = generate(15)
     # Get 5 of 8 split
     shamir_shares = split_shares(mnemonics, 5, 8, encoding=Encoding.BASE58)
     self.assertEqual(len(shamir_shares), 8)
     random.shuffle(shamir_shares)
     recovered_mnemonics = combine_shares(shamir_shares[:5],
                                          encoding=Encoding.BASE58)
     self.assertEqual(recovered_mnemonics, mnemonics)
Ejemplo n.º 5
0
    def test_split_shares_italian(self):
        language = "italian"
        mnemonics = generate(15, language)
        # Get 5 of 8 split
        shamir_shares = split_shares(mnemonics, 5, 8, language=language)
        self.assertEqual(len(shamir_shares), 8)

        random.shuffle(shamir_shares)
        recovered_mnemonics = combine_shares(shamir_shares[:5],
                                             language=language)
        self.assertEqual(recovered_mnemonics, mnemonics)
Ejemplo n.º 6
0
 def test_recovery_base58(self):
     mnemonics = generate(18)
     # Get 5 of 8 split
     shamir_shares = split_shares(mnemonics,
                                  7,
                                  10,
                                  encoding=Encoding.BASE58)
     self.assertEqual(len(shamir_shares), 10)
     recovered_mnemonics = combine_shares(shamir_shares[:9],
                                          encoding=Encoding.BASE58)
     self.assertEqual(recovered_mnemonics, mnemonics)
     #Verify not equal values with less shares
     recovered_incorrect = combine_shares(shamir_shares[:6],
                                          encoding=Encoding.BASE58)
     self.assertNotEqual(mnemonics, recovered_incorrect)
Ejemplo n.º 7
0
    def test_base58_french(self):
        language = "french"
        mnemonics = generate(24, language=language)
        # Get 5 of 8 split
        shamir_shares = split_shares(mnemonics,
                                     10,
                                     15,
                                     encoding=Encoding.BASE58,
                                     language=language)
        self.assertEqual(len(shamir_shares), 15)
        random.shuffle(shamir_shares)
        recovered_mnemonics = combine_shares(shamir_shares[:10],
                                             encoding=Encoding.BASE58,
                                             language=language)
        self.assertEqual(recovered_mnemonics, mnemonics)

        recovered_incorrect = combine_shares(shamir_shares[:6],
                                             encoding=Encoding.BASE58,
                                             language=language)
        self.assertNotEqual(mnemonics, recovered_incorrect)
Ejemplo n.º 8
0
    def test_base58_italian(self):
        language = "italian"
        mnemonics = generate(15, language=language)
        # Get 5 of 8 split
        shamir_shares = split_shares(mnemonics,
                                     5,
                                     8,
                                     encoding=Encoding.BASE58,
                                     language=language)
        self.assertEqual(len(shamir_shares), 8)
        random.shuffle(shamir_shares)
        recovered_mnemonics = combine_shares(shamir_shares[:5],
                                             encoding=Encoding.BASE58,
                                             language=language)
        self.assertEqual(recovered_mnemonics, mnemonics)

        recovered_incorrect = combine_shares(shamir_shares[:3],
                                             encoding=Encoding.BASE58,
                                             language=language)
        self.assertNotEqual(mnemonics, recovered_incorrect)