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