use of tech.pegasys.signers.secp256k1.common.PublicKeySignerIdentifier 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.common.PublicKeySignerIdentifier in project signers by ConsenSys.
the class MultiKeySignerProviderTest method getSignerForAvailableMetadataReturnsSigner.
@Test
void getSignerForAvailableMetadataReturnsSigner() {
when(loader.loadMetadata(any())).thenReturn(Optional.of(metadataFile));
final PublicKeySignerIdentifier signerIdentifier = new PublicKeySignerIdentifier(EthPublicKeyUtils.createPublicKey(Bytes.fromHexString(LOWER_CASE_PUBLIC_KEY)));
final Optional<Signer> signer = signerFactory.getSigner(signerIdentifier);
assertThat(signer).isNotEmpty();
assertThat(EthPublicKeyUtils.toHexString(signer.get().getPublicKey())).isEqualTo("0x" + LOWER_CASE_PUBLIC_KEY);
final ArgumentCaptor<SignerIdentifier> captor = ArgumentCaptor.forClass(PublicKeySignerIdentifier.class);
verify(publicKeyFileSelector).getConfigFilesFilter(captor.capture());
assertThat(captor.getValue().toStringIdentifier()).isEqualTo(LOWER_CASE_PUBLIC_KEY);
}
use of tech.pegasys.signers.secp256k1.common.PublicKeySignerIdentifier in project signers by ConsenSys.
the class FileBasedTomlLoadingAcceptanceTest method validFileBasedTomlFileWithMultineLinePasswordFileProducesSignerWhichReportsMatchingAddress.
@Test
void validFileBasedTomlFileWithMultineLinePasswordFileProducesSignerWhichReportsMatchingAddress(@TempDir Path tomlDirectory) throws URISyntaxException, IOException {
final Path passwordFile = Files.writeString(tomlDirectory.resolve("password.txt"), String.format("password%nsecond line%n"));
createFileBasedTomlFileAt(tomlDirectory.resolve(PUBLIC_KEY_HEX_STRING + ".toml").toAbsolutePath(), new File(Resources.getResource("secp256k1/UTC--2019-12-05T05-17-11.151993000Z--a01f618424b0113a9cebdc6cb66ca5b48e9120c5.key").toURI()).getAbsolutePath(), passwordFile.toString());
setup(tomlDirectory);
assertThat(signerProvider.availablePublicKeys(PublicKeySignerIdentifier::new).stream().map(EthPublicKeyUtils::toHexString)).containsOnly("0x" + PUBLIC_KEY_HEX_STRING);
}
use of tech.pegasys.signers.secp256k1.common.PublicKeySignerIdentifier in project signers by ConsenSys.
the class MultiKeyTransactionSigningAcceptanceTestBase method verifySignature.
void verifySignature(String publicKeyHex) {
ECPublicKey pubKey = EthPublicKeyUtils.createPublicKey(Bytes.fromHexString(publicKeyHex));
final Optional<Signer> signer = signerProvider.getSigner(new PublicKeySignerIdentifier(pubKey));
assertThat(signer).isNotEmpty();
final Signature signature = signer.get().sign(DATA_TO_SIGN);
final BigInteger messagePublicKey = recoverPublicKey(signature);
assertThat(EthPublicKeyUtils.createPublicKey(messagePublicKey)).isEqualTo(pubKey);
final ECDSASignature ecdsaSignature = new ECDSASignature(signature.getR(), signature.getS());
assertThat(ecdsaSignature.isCanonical()).isTrue();
}
Aggregations