Search in sources :

Example 1 with PublicKeySignerIdentifier

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();
}
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 2 with PublicKeySignerIdentifier

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

Example 3 with PublicKeySignerIdentifier

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);
}
Also used : Path(java.nio.file.Path) EthPublicKeyUtils(tech.pegasys.signers.secp256k1.EthPublicKeyUtils) PublicKeySignerIdentifier(tech.pegasys.signers.secp256k1.common.PublicKeySignerIdentifier) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 4 with PublicKeySignerIdentifier

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();
}
Also used : Signer(tech.pegasys.signers.secp256k1.api.Signer) ECPublicKey(java.security.interfaces.ECPublicKey) Signature(tech.pegasys.signers.secp256k1.api.Signature) ECDSASignature(org.web3j.crypto.ECDSASignature) BigInteger(java.math.BigInteger) ECDSASignature(org.web3j.crypto.ECDSASignature) PublicKeySignerIdentifier(tech.pegasys.signers.secp256k1.common.PublicKeySignerIdentifier)

Aggregations

PublicKeySignerIdentifier (tech.pegasys.signers.secp256k1.common.PublicKeySignerIdentifier)4 Test (org.junit.jupiter.api.Test)3 Signer (tech.pegasys.signers.secp256k1.api.Signer)3 File (java.io.File)1 BigInteger (java.math.BigInteger)1 Path (java.nio.file.Path)1 ECPublicKey (java.security.interfaces.ECPublicKey)1 ECDSASignature (org.web3j.crypto.ECDSASignature)1 EthPublicKeyUtils (tech.pegasys.signers.secp256k1.EthPublicKeyUtils)1 Signature (tech.pegasys.signers.secp256k1.api.Signature)1 SignerIdentifier (tech.pegasys.signers.secp256k1.api.SignerIdentifier)1 FileSignerConfig (tech.pegasys.signers.secp256k1.filebased.FileSignerConfig)1 FileBasedSigningMetadataFile (tech.pegasys.signers.secp256k1.multikey.metadata.FileBasedSigningMetadataFile)1