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