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));
}
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();
});
}
Aggregations