Search in sources :

Example 1 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 : ArtifactSigner(tech.pegasys.web3signer.core.signing.ArtifactSigner) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) HashMap(java.util.HashMap) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) AzureSecretSigningMetadata(tech.pegasys.web3signer.core.multikey.metadata.AzureSecretSigningMetadata) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 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 : ArtifactSigner(tech.pegasys.web3signer.core.signing.ArtifactSigner) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) HashMap(java.util.HashMap) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) FileRawSigningMetadata(tech.pegasys.web3signer.core.multikey.metadata.FileRawSigningMetadata) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 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 : ArtifactSigner(tech.pegasys.web3signer.core.signing.ArtifactSigner) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) HashMap(java.util.HashMap) BlsArtifactSigner(tech.pegasys.web3signer.core.signing.BlsArtifactSigner) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) FileRawSigningMetadata(tech.pegasys.web3signer.core.multikey.metadata.FileRawSigningMetadata) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 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 5 with BLSKeyPair

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

the class BlsArtifactSignerFactory method create.

@Override
public ArtifactSigner create(final AwsKeySigningMetadata awsKeySigningMetadata) {
    try (final TimingContext ignored = privateKeyRetrievalTimer.labels("aws").startTimer()) {
        final Bytes32 keyBytes = Bytes32.wrap(extractBytesFromSecretsManager(awsKeySigningMetadata));
        final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(keyBytes));
        return signerFactory.apply(new BlsArtifactSignerArgs(keyPair, SignerOrigin.AWS));
    }
}
Also used : Bytes32(org.apache.tuweni.bytes.Bytes32) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) TimingContext(org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext)

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