@Test void keysAreWrittenToEncryptedKeystores(@TempDir final Path tempDir) { final KeysWriter keysWriter = new EncryptedKeystoreWriter( SecureRandomProvider.createSecureRandom(), PASSWORD, PASSWORD, tempDir, System.out::println); keysWriter.writeKeys(new BLSKeyPair(validator1SecretKey), new BLSKeyPair(withdrawal1SecretKey)); assertKeyStoreCreatedAndCanBeDecrypted( tempDir.resolve(trimPublicKey(validator1PubKey) + "_validator.json"), validator1SecretKey); assertKeyStoreCreatedAndCanBeDecrypted( tempDir.resolve(trimPublicKey(validator1PubKey) + "_withdrawal.json"), withdrawal1SecretKey); keysWriter.writeKeys(new BLSKeyPair(validator2SecretKey), new BLSKeyPair(withdrawal2SecretKey)); assertKeyStoreCreatedAndCanBeDecrypted( tempDir.resolve(trimPublicKey(validator2PubKey) + "_validator.json"), validator2SecretKey); assertKeyStoreCreatedAndCanBeDecrypted( tempDir.resolve(trimPublicKey(validator2PubKey) + "_withdrawal.json"), withdrawal2SecretKey); }
@Override public void writeKeys(final BLSKeyPair validatorKey, final BLSKeyPair withdrawalKey) throws UncheckedIOException, KeyStoreValidationException { commandOutput.accept( "Generating encrypted keystore for validator key [" + validatorKey.getPublicKey().toString() + "]"); final KeyStoreData validatorKeyStoreData = generateKeystoreData(validatorKey, validatorKeyPassword); commandOutput.accept( "Generating encrypted keystore for withdrawal key [" + withdrawalKey.getPublicKey().toString() + "]"); final KeyStoreData withdrawalKeyStoreData = generateKeystoreData(withdrawalKey, withdrawalKeyPassword); final String validatorFileName = validatorKey.getPublicKey().toAbbreviatedString() + "_validator.json"; final String withdrawalFileName = validatorKey.getPublicKey().toAbbreviatedString() + "_withdrawal.json"; saveKeyStore(outputPath.resolve(validatorFileName), validatorKeyStoreData); commandOutput.accept( "Withdrawal keystore [" + outputPath.resolve(validatorFileName) + "] saved successfully."); saveKeyStore(outputPath.resolve(withdrawalFileName), withdrawalKeyStoreData); commandOutput.accept( "Validator keystore [" + outputPath.resolve(withdrawalFileName) + "] saved successfully."); }
EncryptedKeystoreWriter implements KeysWriter { @Override public void writeKeys(final BLSKeyPair validatorKey, final BLSKeyPair withdrawalKey) throws UncheckedIOException, KeyStoreValidationException { commandOutput.accept( "Generating encrypted keystore for validator key [" + validatorKey.getPublicKey().toString() + "]"); final KeyStoreData validatorKeyStoreData = generateKeystoreData(validatorKey, validatorKeyPassword); commandOutput.accept( "Generating encrypted keystore for withdrawal key [" + withdrawalKey.getPublicKey().toString() + "]"); final KeyStoreData withdrawalKeyStoreData = generateKeystoreData(withdrawalKey, withdrawalKeyPassword); final String validatorFileName = validatorKey.getPublicKey().toAbbreviatedString() + "_validator.json"; final String withdrawalFileName = validatorKey.getPublicKey().toAbbreviatedString() + "_withdrawal.json"; saveKeyStore(outputPath.resolve(validatorFileName), validatorKeyStoreData); commandOutput.accept( "Withdrawal keystore [" + outputPath.resolve(validatorFileName) + "] saved successfully."); saveKeyStore(outputPath.resolve(withdrawalFileName), withdrawalKeyStoreData); commandOutput.accept( "Validator keystore [" + outputPath.resolve(withdrawalFileName) + "] saved successfully."); } }
EncryptedKeystoreWriter implements KeysWriter { @Override public void writeKeys(final BLSKeyPair validatorKey, final BLSKeyPair withdrawalKey) throws UncheckedIOException, KeyStoreValidationException { commandOutput.accept( "Generating encrypted keystore for validator key [" + validatorKey.getPublicKey().toString() + "]"); final KeyStoreData validatorKeyStoreData = generateKeystoreData(validatorKey, validatorKeyPassword); commandOutput.accept( "Generating encrypted keystore for withdrawal key [" + withdrawalKey.getPublicKey().toString() + "]"); final KeyStoreData withdrawalKeyStoreData = generateKeystoreData(withdrawalKey, withdrawalKeyPassword); final String validatorFileName = validatorKey.getPublicKey().toAbbreviatedString() + "_validator.json"; final String withdrawalFileName = validatorKey.getPublicKey().toAbbreviatedString() + "_withdrawal.json"; saveKeyStore(outputPath.resolve(validatorFileName), validatorKeyStoreData); commandOutput.accept( "Withdrawal keystore [" + outputPath.resolve(validatorFileName) + "] saved successfully."); saveKeyStore(outputPath.resolve(withdrawalFileName), withdrawalKeyStoreData); commandOutput.accept( "Validator keystore [" + outputPath.resolve(withdrawalFileName) + "] saved successfully."); } EncryptedKeystoreWriter(
      final SecureRandom secureRandom,
      final String validatorKeyPassword,
      final String withdrawalKeyPassword,
      final Path outputPath,
      final Consumer<String> commandOutput); }
EncryptedKeystoreWriter implements KeysWriter { @Override public void writeKeys(final BLSKeyPair validatorKey, final BLSKeyPair withdrawalKey) throws UncheckedIOException, KeyStoreValidationException { commandOutput.accept( "Generating encrypted keystore for validator key [" + validatorKey.getPublicKey().toString() + "]"); final KeyStoreData validatorKeyStoreData = generateKeystoreData(validatorKey, validatorKeyPassword); commandOutput.accept( "Generating encrypted keystore for withdrawal key [" + withdrawalKey.getPublicKey().toString() + "]"); final KeyStoreData withdrawalKeyStoreData = generateKeystoreData(withdrawalKey, withdrawalKeyPassword); final String validatorFileName = validatorKey.getPublicKey().toAbbreviatedString() + "_validator.json"; final String withdrawalFileName = validatorKey.getPublicKey().toAbbreviatedString() + "_withdrawal.json"; saveKeyStore(outputPath.resolve(validatorFileName), validatorKeyStoreData); commandOutput.accept( "Withdrawal keystore [" + outputPath.resolve(validatorFileName) + "] saved successfully."); saveKeyStore(outputPath.resolve(withdrawalFileName), withdrawalKeyStoreData); commandOutput.accept( "Validator keystore [" + outputPath.resolve(withdrawalFileName) + "] saved successfully."); } EncryptedKeystoreWriter(
      final SecureRandom secureRandom,
      final String validatorKeyPassword,
      final String withdrawalKeyPassword,
      final Path outputPath,
      final Consumer<String> commandOutput); @Override void writeKeys(final BLSKeyPair validatorKey, final BLSKeyPair withdrawalKey); }
EncryptedKeystoreWriter implements KeysWriter { @Override public void writeKeys(final BLSKeyPair validatorKey, final BLSKeyPair withdrawalKey) throws UncheckedIOException, KeyStoreValidationException { commandOutput.accept( "Generating encrypted keystore for validator key [" + validatorKey.getPublicKey().toString() + "]"); final KeyStoreData validatorKeyStoreData = generateKeystoreData(validatorKey, validatorKeyPassword); commandOutput.accept( "Generating encrypted keystore for withdrawal key [" + withdrawalKey.getPublicKey().toString() + "]"); final KeyStoreData withdrawalKeyStoreData = generateKeystoreData(withdrawalKey, withdrawalKeyPassword); final String validatorFileName = validatorKey.getPublicKey().toAbbreviatedString() + "_validator.json"; final String withdrawalFileName = validatorKey.getPublicKey().toAbbreviatedString() + "_withdrawal.json"; saveKeyStore(outputPath.resolve(validatorFileName), validatorKeyStoreData); commandOutput.accept( "Withdrawal keystore [" + outputPath.resolve(validatorFileName) + "] saved successfully."); saveKeyStore(outputPath.resolve(withdrawalFileName), withdrawalKeyStoreData); commandOutput.accept( "Validator keystore [" + outputPath.resolve(withdrawalFileName) + "] saved successfully."); } EncryptedKeystoreWriter(
      final SecureRandom secureRandom,
      final String validatorKeyPassword,
      final String withdrawalKeyPassword,
      final Path outputPath,
      final Consumer<String> commandOutput); @Override void writeKeys(final BLSKeyPair validatorKey, final BLSKeyPair withdrawalKey);  }