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