use of tech.pegasys.signers.secp256k1.filebased.FileSignerConfig in project signers by ConsenSys.
the class MultiKeySignerProviderTest method signerIsLoadedSuccessfullyWhenAddressHasCaseMismatchToFilename.
@Test
void signerIsLoadedSuccessfullyWhenAddressHasCaseMismatchToFilename() throws URISyntaxException {
final FileBasedSigningMetadataFile capitalisedMetadata = new FileBasedSigningMetadataFile(LOWERCASE_ADDRESS + ".toml", new FileSignerConfig(Path.of(Resources.getResource("metadata-toml-configs").toURI()).resolve(KEY_FILENAME), Path.of(Resources.getResource("metadata-toml-configs").toURI()).resolve(PASSWORD_FILENAME)));
final Signer signer = signerFactory.createSigner(capitalisedMetadata);
assertThat(signer).isNotNull();
assertThat(EthPublicKeyUtils.toHexString(signer.getPublicKey())).isEqualTo("0x" + LOWER_CASE_PUBLIC_KEY);
}
use of tech.pegasys.signers.secp256k1.filebased.FileSignerConfig in project signers by ConsenSys.
the class MultiKeySignerProviderTest method signerIsNotReturnedIfFileContainsPublicKeyDifferentToRequest.
@Test
void signerIsNotReturnedIfFileContainsPublicKeyDifferentToRequest() throws URISyntaxException {
final FileBasedSigningMetadataFile capitalisedMetadata = new FileBasedSigningMetadataFile(LOWERCASE_ADDRESS + ".toml", new FileSignerConfig(Path.of(Resources.getResource("metadata-toml-configs").toURI()).resolve(KEY_FILENAME), Path.of(Resources.getResource("metadata-toml-configs").toURI()).resolve(PASSWORD_FILENAME)));
when(loader.loadMetadata(any())).thenReturn(Optional.of(capitalisedMetadata));
final PublicKeySignerIdentifier signerIdentifier = new PublicKeySignerIdentifier(EthPublicKeyUtils.createPublicKey(Bytes.fromHexString("A".repeat(128))));
final Optional<Signer> signer = signerFactory.getSigner(signerIdentifier);
assertThat(signer).isEmpty();
}
use of tech.pegasys.signers.secp256k1.filebased.FileSignerConfig in project signers by ConsenSys.
the class SigningMetadataTomlConfigLoader method getFileBasedSigningMetadataFromToml.
private Optional<SigningMetadataFile> getFileBasedSigningMetadataFromToml(final String filename, final TomlParseResult result) {
final Optional<TomlTableAdapter> signingTable = getSigningTableFrom(filename, result);
if (signingTable.isEmpty()) {
return Optional.empty();
}
final TomlTableAdapter table = signingTable.get();
final String keyFilename = table.getString("key-file");
final Path keyPath = makeRelativePathAbsolute(keyFilename);
final String passwordFilename = table.getString("password-file");
final Path passwordPath = makeRelativePathAbsolute(passwordFilename);
return Optional.of(new FileBasedSigningMetadataFile(filename, new FileSignerConfig(keyPath, passwordPath)));
}
use of tech.pegasys.signers.secp256k1.filebased.FileSignerConfig in project signers by ConsenSys.
the class MetadataFileFixture method load.
static FileBasedSigningMetadataFile load(final String metadataFilename, final String keyFilename, final String passwordFilename) {
try {
final Path metadataTomlConfigsDirectory = Path.of(metadataTomlConfigPathUrl.toURI());
final Path metadataPath = metadataTomlConfigsDirectory.resolve(metadataFilename);
if (!metadataPath.toFile().exists()) {
fail("Missing metadata TOML file " + metadataPath.getFileName().toString());
return null;
}
return new FileBasedSigningMetadataFile(metadataPath.getFileName().toString(), new FileSignerConfig(new File(keyFilename).toPath(), new File(passwordFilename).toPath()));
} catch (URISyntaxException e) {
fail("URI Syntax Exception" + metadataFilename);
return null;
}
}
Aggregations