Search in sources :

Example 16 with BLSKeyPair

use of tech.pegasys.teku.bls.BLSKeyPair in project teku by ConsenSys.

the class EncryptedKeystoreWriterTest method keysAreWrittenToEncryptedKeystores.

@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);
}
Also used : BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Test(org.junit.jupiter.api.Test)

Example 17 with BLSKeyPair

use of tech.pegasys.teku.bls.BLSKeyPair in project teku by ConsenSys.

the class ActiveKeyManagerTest method shouldReturnActiveRemoteValidatorsList.

@Test
void shouldReturnActiveRemoteValidatorsList() throws MalformedURLException {
    final BLSKeyPair keyPair1 = BLSTestUtil.randomKeyPair(1);
    final BLSKeyPair keyPair2 = BLSTestUtil.randomKeyPair(2);
    final BLSKeyPair keyPair3 = BLSTestUtil.randomKeyPair(3);
    final Validator validator1 = new Validator(keyPair1.getPublicKey(), NO_OP_REMOTE_SIGNER, Optional::empty, true);
    final Validator validator2 = new Validator(keyPair2.getPublicKey(), NO_OP_REMOTE_SIGNER, Optional::empty, false);
    final Validator validator3 = new Validator(keyPair3.getPublicKey(), NO_OP_SIGNER, Optional::empty, false);
    List<Validator> activeValidators = Arrays.asList(validator1, validator2, validator3);
    when(ownedValidators.getActiveValidators()).thenReturn(activeValidators);
    when(validatorLoader.getOwnedValidators()).thenReturn(ownedValidators);
    final List<ExternalValidator> result = keyManager.getActiveRemoteValidatorKeys();
    List<ExternalValidator> externalValidators = Arrays.asList(new ExternalValidator(keyPair1.getPublicKey(), Optional.of(new URL("http://example.com/")), true), new ExternalValidator(keyPair2.getPublicKey(), Optional.of(new URL("http://example.com/")), false));
    assertThat(result).isEqualTo(externalValidators);
}
Also used : Optional(java.util.Optional) ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 18 with BLSKeyPair

use of tech.pegasys.teku.bls.BLSKeyPair in project teku by ConsenSys.

the class GetKeysTest method getValidatorList.

private List<Validator> getValidatorList() {
    BLSKeyPair keyPair1 = BLSTestUtil.randomKeyPair(1);
    BLSKeyPair keyPair2 = BLSTestUtil.randomKeyPair(2);
    Validator validator1 = new Validator(keyPair1.getPublicKey(), NO_OP_SIGNER, Optional::empty, true);
    Validator validator2 = new Validator(keyPair2.getPublicKey(), NO_OP_SIGNER, Optional::empty, false);
    return Arrays.asList(validator1, validator2);
}
Also used : Optional(java.util.Optional) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Validator(tech.pegasys.teku.validator.client.Validator)

Example 19 with BLSKeyPair

use of tech.pegasys.teku.bls.BLSKeyPair in project teku by ConsenSys.

the class GetRemoteKeysTest method getValidatorList.

private List<Validator> getValidatorList() {
    BLSKeyPair keyPair1 = BLSTestUtil.randomKeyPair(1);
    BLSKeyPair keyPair2 = BLSTestUtil.randomKeyPair(2);
    Validator validator1 = new Validator(keyPair1.getPublicKey(), NO_OP_REMOTE_SIGNER, Optional::empty, false);
    Validator validator2 = new Validator(keyPair2.getPublicKey(), NO_OP_REMOTE_SIGNER, Optional::empty, false);
    return Arrays.asList(validator1, validator2);
}
Also used : Optional(java.util.Optional) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) Validator(tech.pegasys.teku.validator.client.Validator)

Example 20 with BLSKeyPair

use of tech.pegasys.teku.bls.BLSKeyPair in project web3signer by ConsenSys.

the class MetadataFileHelpers method createRandomUnencryptedBlsKeys.

public void createRandomUnencryptedBlsKeys(final Path directory, final int numberOfKeys) {
    final SecureRandom secureRandom = new SecureRandom();
    final MetadataFileHelpers metadataFileHelpers = new MetadataFileHelpers();
    for (int i = 0; i < numberOfKeys; i++) {
        final BLSKeyPair keyPair = BLSKeyPair.random(secureRandom);
        final String privateKey = keyPair.getSecretKey().toBytes().toHexString();
        final Path filename = directory.resolve(keyPair.getPublicKey().toString() + ".yaml");
        metadataFileHelpers.createUnencryptedYamlFileAt(filename, privateKey, KeyType.BLS);
    }
}
Also used : Path(java.nio.file.Path) SecureRandom(java.security.SecureRandom) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair)

Aggregations

BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)66 Test (org.junit.jupiter.api.Test)24 Bytes (org.apache.tuweni.bytes.Bytes)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 HashMap (java.util.HashMap)12 Bytes32 (org.apache.tuweni.bytes.Bytes32)11 TimingContext (org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext)10 Path (java.nio.file.Path)9 BlsArtifactSigner (tech.pegasys.web3signer.core.signing.BlsArtifactSigner)7 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)6 ArtifactSigner (tech.pegasys.web3signer.core.signing.ArtifactSigner)6 BlsArtifactSigner (tech.pegasys.web3signer.signing.BlsArtifactSigner)6 KeyStoreData (tech.pegasys.signers.bls.keystore.model.KeyStoreData)5 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)5 ArtifactSigner (tech.pegasys.web3signer.signing.ArtifactSigner)5 Disabled (org.junit.jupiter.api.Disabled)4 InlineEventThread (tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread)4 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)4 Optional (java.util.Optional)3 KeyStoreValidationException (tech.pegasys.signers.bls.keystore.KeyStoreValidationException)3