Search in sources :

Example 1 with FileSignerConfig

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);
}
Also used : Signer(tech.pegasys.signers.secp256k1.api.Signer) FileSignerConfig(tech.pegasys.signers.secp256k1.filebased.FileSignerConfig) FileBasedSigningMetadataFile(tech.pegasys.signers.secp256k1.multikey.metadata.FileBasedSigningMetadataFile) Test(org.junit.jupiter.api.Test)

Example 2 with FileSignerConfig

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();
}
Also used : Signer(tech.pegasys.signers.secp256k1.api.Signer) FileSignerConfig(tech.pegasys.signers.secp256k1.filebased.FileSignerConfig) FileBasedSigningMetadataFile(tech.pegasys.signers.secp256k1.multikey.metadata.FileBasedSigningMetadataFile) PublicKeySignerIdentifier(tech.pegasys.signers.secp256k1.common.PublicKeySignerIdentifier) Test(org.junit.jupiter.api.Test)

Example 3 with FileSignerConfig

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)));
}
Also used : Path(java.nio.file.Path) FileSignerConfig(tech.pegasys.signers.secp256k1.filebased.FileSignerConfig) FileBasedSigningMetadataFile(tech.pegasys.signers.secp256k1.multikey.metadata.FileBasedSigningMetadataFile)

Example 4 with FileSignerConfig

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;
    }
}
Also used : Path(java.nio.file.Path) FileSignerConfig(tech.pegasys.signers.secp256k1.filebased.FileSignerConfig) FileBasedSigningMetadataFile(tech.pegasys.signers.secp256k1.multikey.metadata.FileBasedSigningMetadataFile) URISyntaxException(java.net.URISyntaxException) FileBasedSigningMetadataFile(tech.pegasys.signers.secp256k1.multikey.metadata.FileBasedSigningMetadataFile) File(java.io.File)

Aggregations

FileSignerConfig (tech.pegasys.signers.secp256k1.filebased.FileSignerConfig)4 FileBasedSigningMetadataFile (tech.pegasys.signers.secp256k1.multikey.metadata.FileBasedSigningMetadataFile)4 Path (java.nio.file.Path)2 Test (org.junit.jupiter.api.Test)2 Signer (tech.pegasys.signers.secp256k1.api.Signer)2 File (java.io.File)1 URISyntaxException (java.net.URISyntaxException)1 PublicKeySignerIdentifier (tech.pegasys.signers.secp256k1.common.PublicKeySignerIdentifier)1