Search in sources :

Example 1 with SeedValidationException

use of com.github.dedis.popstellar.utility.error.keys.SeedValidationException in project popstellar by dedis.

the class Wallet method importSeed.

/**
 * Method that allow import mnemonic seed.
 *
 * @param words a String.
 */
public void importSeed(@NonNull String words) throws SeedValidationException, GeneralSecurityException {
    try {
        MnemonicValidator.ofWordList(English.INSTANCE).validate(words);
    } catch (InvalidChecksumException | InvalidWordCountException | WordNotFoundException | UnexpectedWhiteSpaceException e) {
        throw new SeedValidationException(e);
    }
    seed = aead.encrypt(new SeedCalculator().calculateSeed(words, ""), new byte[0]);
    Log.d(TAG, "ImportSeed: new seed: " + Utils.bytesToHex(seed));
}
Also used : UnexpectedWhiteSpaceException(io.github.novacrypto.bip39.Validation.UnexpectedWhiteSpaceException) SeedValidationException(com.github.dedis.popstellar.utility.error.keys.SeedValidationException) SeedCalculator(io.github.novacrypto.bip39.SeedCalculator) WordNotFoundException(io.github.novacrypto.bip39.Validation.WordNotFoundException) InvalidWordCountException(io.github.novacrypto.bip39.Validation.InvalidWordCountException) InvalidChecksumException(io.github.novacrypto.bip39.Validation.InvalidChecksumException)

Example 2 with SeedValidationException

use of com.github.dedis.popstellar.utility.error.keys.SeedValidationException in project popstellar by dedis.

the class WalletFragment method setupOwnSeedButton.

private void setupOwnSeedButton() {
    String defaultSeed = "elbow six card empty next sight turn quality capital please vocal indoor";
    mWalletFragBinding.buttonOwnSeed.setOnClickListener(v -> {
        if (seedAlert != null && seedAlert.isShowing()) {
            seedAlert.dismiss();
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
        builder.setTitle("Type the 12 word seed:");
        final EditText input = new EditText(requireActivity());
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        input.setText(// for facilitate test we set a default seed for login in the Wallet
        defaultSeed);
        builder.setView(input);
        final boolean[] checked = new boolean[] { false };
        builder.setMultiChoiceItems(new String[] { "show password" }, checked, (dialogInterface, i, b) -> {
            checked[i] = b;
            if (b) {
                input.setInputType(InputType.TYPE_CLASS_TEXT);
            } else {
                input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            }
        });
        builder.setPositiveButton("Set up wallet", (dialog, which) -> {
            try {
                mHomeViewModel.importSeed(input.getText().toString());
            } catch (GeneralSecurityException | SeedValidationException e) {
                Log.e(TAG, "Error importing key", e);
                Toast.makeText(requireContext().getApplicationContext(), "Error importing key : " + e.getMessage() + "\ntry again", Toast.LENGTH_LONG).show();
            }
        });
        builder.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel());
        seedAlert = builder.create();
        seedAlert.show();
    });
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) EditText(android.widget.EditText) GeneralSecurityException(java.security.GeneralSecurityException) SeedValidationException(com.github.dedis.popstellar.utility.error.keys.SeedValidationException)

Aggregations

SeedValidationException (com.github.dedis.popstellar.utility.error.keys.SeedValidationException)2 EditText (android.widget.EditText)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 SeedCalculator (io.github.novacrypto.bip39.SeedCalculator)1 InvalidChecksumException (io.github.novacrypto.bip39.Validation.InvalidChecksumException)1 InvalidWordCountException (io.github.novacrypto.bip39.Validation.InvalidWordCountException)1 UnexpectedWhiteSpaceException (io.github.novacrypto.bip39.Validation.UnexpectedWhiteSpaceException)1 WordNotFoundException (io.github.novacrypto.bip39.Validation.WordNotFoundException)1 GeneralSecurityException (java.security.GeneralSecurityException)1