use of tech.pegasys.web3signer.core.signing.BlsArtifactSigner 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.web3signer.core.signing.BlsArtifactSigner 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.web3signer.core.signing.BlsArtifactSigner 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.web3signer.core.signing.BlsArtifactSigner in project web3signer by ConsenSys.
the class ImportKeystoresHandler method decryptKeystoreAndCreateSigner.
private BlsArtifactSigner decryptKeystoreAndCreateSigner(String jsonKeystoreData, 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()));
}
use of tech.pegasys.web3signer.core.signing.BlsArtifactSigner 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));
}
Aggregations