Search in sources :

Example 26 with BLSKeyPair

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

the class YamlSignerParserTest method azureSecretMetadataWithAuthenticationModeReturnsMetadata.

@ParameterizedTest
@EnumSource(AzureAuthenticationMode.class)
void azureSecretMetadataWithAuthenticationModeReturnsMetadata(final AzureAuthenticationMode authenticationMode) 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("clientId", "sample-client-id");
    azureMetaDataMap.put("clientSecret", "sample-client-secret");
    azureMetaDataMap.put("tenantId", "sample-tenant-id");
    azureMetaDataMap.put("vaultName", "sample-vault-name");
    azureMetaDataMap.put("secretName", "TEST-KEY");
    azureMetaDataMap.put("authenticationMode", authenticationMode.name());
    azureMetaDataMap.put("keyType", "BLS");
    final String yamlMetadata = YAML_OBJECT_MAPPER.writeValueAsString(azureMetaDataMap);
    final List<ArtifactSigner> result = signerParser.parse(yamlMetadata);
    assertThat(result).containsOnly(artifactSigner);
    verify(blsArtifactSignerFactory).create(hasCorrectAzureMetadataArguments(authenticationMode));
}
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) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with BLSKeyPair

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

the class YamlSignerParserTest method azureSecretMetadataInfoReturnsMetadata.

@Test
void azureSecretMetadataInfoReturnsMetadata() 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("clientId", "sample-client-id");
    azureMetaDataMap.put("clientSecret", "sample-client-secret");
    azureMetaDataMap.put("tenantId", "sample-tenant-id");
    azureMetaDataMap.put("vaultName", "sample-vault-name");
    azureMetaDataMap.put("secretName", "TEST-KEY");
    azureMetaDataMap.put("keyType", "BLS");
    final String yamlMetadata = YAML_OBJECT_MAPPER.writeValueAsString(azureMetaDataMap);
    final List<ArtifactSigner> result = signerParser.parse(yamlMetadata);
    assertThat(result).containsOnly(artifactSigner);
    verify(blsArtifactSignerFactory).create(hasCorrectAzureMetadataArguments(AzureAuthenticationMode.CLIENT_SECRET));
}
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 28 with BLSKeyPair

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

the class YamlSignerParserTest method unencryptedMetaDataInfoWithPrivateKeyReturnsMetadata.

@Test
void unencryptedMetaDataInfoWithPrivateKeyReturnsMetadata() 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", 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)

Example 29 with BLSKeyPair

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

the class BlsArtifactSignerTest method signsData.

@Test
void signsData() {
    final Bytes message = Bytes.wrap("Hello, world!".getBytes(UTF_8));
    final BLSKeyPair keyPair = BLSTestUtil.randomKeyPair(4);
    final BLSSignature expectedSignature = BLS.sign(keyPair.getSecretKey(), message);
    final BlsArtifactSigner blsArtifactSigner = new BlsArtifactSigner(keyPair, SignerOrigin.FILE_RAW);
    final BlsArtifactSignature signature = blsArtifactSigner.sign(message);
    assertThat(signature.getSignatureData().toString()).isEqualTo(expectedSignature.toString());
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Test(org.junit.jupiter.api.Test)

Example 30 with BLSKeyPair

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

the class FileValidatorManager method decryptKeystoreAndCreateSigner.

private BlsArtifactSigner decryptKeystoreAndCreateSigner(final String jsonKeystoreData, final String password) throws JsonProcessingException, KeyStoreValidationException {
    final KeyStoreData keyStoreData = objectMapper.readValue(jsonKeystoreData, KeyStoreData.class);
    final Bytes privateKey = KeyStore.decrypt(password, keyStoreData);
    final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.wrap(privateKey)));
    return new BlsArtifactSigner(keyPair, SignerOrigin.FILE_KEYSTORE, Optional.ofNullable(keyStoreData.getPath()));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData) 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