Search in sources :

Example 21 with BLSKeyPair

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

the class MetricsAcceptanceTest method signMetricIncrementsWhenBlsSignRequestReceived.

@Test
void signMetricIncrementsWhenBlsSignRequestReceived(@TempDir Path testDirectory) throws JsonProcessingException {
    final MetadataFileHelpers fileHelpers = new MetadataFileHelpers();
    final BLSKeyPair keyPair = BLSTestUtil.randomKeyPair(1);
    fileHelpers.createUnencryptedYamlFileAt(testDirectory.resolve(keyPair.getPublicKey().toBytesCompressed().toHexString() + ".yaml"), keyPair.getSecretKey().toBytes().toHexString(), BLS);
    final SignerConfiguration signerConfiguration = new SignerConfigurationBuilder().withMetricsCategories("SIGNING").withMetricsEnabled(true).withKeyStoreDirectory(testDirectory).withMode("eth2").build();
    startSigner(signerConfiguration);
    final List<String> metricsOfInterest = List.of("signing_" + BLS.name().toLowerCase() + "_signing_duration_count", "signing_" + BLS.name().toLowerCase() + "_missing_identifier_count");
    final Set<String> initialMetrics = signer.getMetricsMatching(metricsOfInterest);
    assertThat(initialMetrics).hasSize(metricsOfInterest.size());
    assertThat(initialMetrics).allMatch(s -> s.endsWith("0.0"));
    signer.eth2Sign(keyPair.getPublicKey().toBytesCompressed().toHexString(), Eth2RequestUtils.createBlockRequest(UInt64.valueOf(1), Bytes32.fromHexString("0x1111")));
    final Set<String> metricsAfterSign = signer.getMetricsMatching(metricsOfInterest);
    assertThat(metricsAfterSign).containsOnly("signing_" + BLS.name().toLowerCase() + "_signing_duration_count 1.0", "signing_" + BLS.name().toLowerCase() + "_missing_identifier_count 0.0");
}
Also used : SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder) SignerConfiguration(tech.pegasys.web3signer.dsl.signer.SignerConfiguration) MetadataFileHelpers(tech.pegasys.web3signer.dsl.utils.MetadataFileHelpers) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with BLSKeyPair

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

the class Eth2Runner method loadAzureSigners.

final Collection<ArtifactSigner> loadAzureSigners() {
    final AzureKeyVault keyVault = AzureKeyVaultFactory.createAzureKeyVault(azureKeyVaultParameters);
    return keyVault.mapSecrets((name, value) -> {
        try {
            final Bytes privateKeyBytes = Bytes.fromHexString(value);
            final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.wrap(privateKeyBytes)));
            return new BlsArtifactSigner(keyPair, SignerOrigin.AZURE);
        } catch (final Exception e) {
            LOG.error("Failed to load secret named {} from azure key vault.", name);
            return null;
        }
    });
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BlsArtifactSigner(tech.pegasys.web3signer.signing.BlsArtifactSigner) AzureKeyVault(tech.pegasys.signers.azure.AzureKeyVault) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair)

Example 23 with BLSKeyPair

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

the class FcBlsArtifactSignerTest method setup.

@BeforeEach
public void setup() {
    final Bytes fcPrivateKey = Bytes.fromBase64String(FC_BLS_PRIVATE_KEY);
    // Filecoin private keys are serialised in little endian so must convert to big endian
    final Bytes32 privateKey = Bytes32.wrap(fcPrivateKey.reverse());
    final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(privateKey));
    fcBlsArtifactSigner = new FcBlsArtifactSigner(keyPair, FilecoinNetwork.TESTNET);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Bytes32(org.apache.tuweni.bytes.Bytes32) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 24 with BLSKeyPair

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

the class YamlSignerParserTest method azureSecretMetadataWithSystemAssignedManagedIdentityReturnsMetadata.

@Test
void azureSecretMetadataWithSystemAssignedManagedIdentityReturnsMetadata() throws IOException {
    final BlsArtifactSigner artifactSigner = new BlsArtifactSigner(new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.fromHexString(PRIVATE_KEY))), SignerOrigin.AZURE);
    when(blsArtifactSignerFactory.create(any(AzureSecretSigningMetadata.class))).thenReturn(artifactSigner);
    final Map<String, String> azureMetaDataMap = new HashMap<>();
    azureMetaDataMap.put("type", "azure-secret");
    azureMetaDataMap.put("vaultName", "sample-vault-name");
    azureMetaDataMap.put("secretName", "TEST-KEY");
    azureMetaDataMap.put("authenticationMode", AzureAuthenticationMode.SYSTEM_ASSIGNED_MANAGED_IDENTITY.name());
    final String yamlMetadata = YAML_OBJECT_MAPPER.writeValueAsString(azureMetaDataMap);
    final List<ArtifactSigner> result = signerParser.parse(yamlMetadata);
    assertThat(result).containsOnly(artifactSigner);
    verify(blsArtifactSignerFactory).create(hasCorrectAzureManagedIdentityMinimalMetadataArguments());
}
Also used : BlsArtifactSigner(tech.pegasys.web3signer.signing.BlsArtifactSigner) ArtifactSigner(tech.pegasys.web3signer.signing.ArtifactSigner) HashMap(java.util.HashMap) BlsArtifactSigner(tech.pegasys.web3signer.signing.BlsArtifactSigner) AzureSecretSigningMetadata(tech.pegasys.web3signer.signing.config.metadata.AzureSecretSigningMetadata) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with BLSKeyPair

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

the class YamlSignerParserTest method unencryptedMetaDataInfoWith0xPrefixPrivateKeyReturnsMetadata.

@Test
void unencryptedMetaDataInfoWith0xPrefixPrivateKeyReturnsMetadata() throws IOException {
    final ArtifactSigner artifactSigner = new BlsArtifactSigner(new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.fromHexString(PRIVATE_KEY))), SignerOrigin.FILE_RAW);
    when(blsArtifactSignerFactory.create(any(FileRawSigningMetadata.class))).thenReturn(artifactSigner);
    final Map<String, String> unencryptedKeyMetadataFile = new HashMap<>();
    unencryptedKeyMetadataFile.put("type", "file-raw");
    unencryptedKeyMetadataFile.put("privateKey", "0x" + PRIVATE_KEY);
    final String yamlMetadata = YAML_OBJECT_MAPPER.writeValueAsString(unencryptedKeyMetadataFile);
    final List<ArtifactSigner> result = signerParser.parse(yamlMetadata);
    assertThat(result).containsOnly(artifactSigner);
    verify(blsArtifactSignerFactory).create(hasPrivateKey(PRIVATE_KEY));
}
Also used : BlsArtifactSigner(tech.pegasys.web3signer.signing.BlsArtifactSigner) ArtifactSigner(tech.pegasys.web3signer.signing.ArtifactSigner) HashMap(java.util.HashMap) BlsArtifactSigner(tech.pegasys.web3signer.signing.BlsArtifactSigner) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) FileRawSigningMetadata(tech.pegasys.web3signer.signing.config.metadata.FileRawSigningMetadata) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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