Search in sources :

Example 1 with CredentialSigner

use of tech.pegasys.signers.secp256k1.filebased.CredentialSigner in project web3signer by ConsenSys.

the class EthSecpArtifactSignerTest method signsData.

@Test
void signsData() {
    final ECKeyPair ecKeyPair = new ECKeyPair(Numeric.toBigInt(PRIVATE_KEY), Numeric.toBigInt(PUBLIC_KEY));
    final Credentials credentials = Credentials.create(ecKeyPair);
    final EthSecpArtifactSigner ethSecpArtifactSigner = new EthSecpArtifactSigner(new CredentialSigner(credentials));
    final Bytes message = Bytes.wrap("Hello, world!".getBytes(UTF_8));
    final SecpArtifactSignature signature = ethSecpArtifactSigner.sign(message);
    final SignatureData expectedSignature = Sign.signMessage(message.toArrayUnsafe(), ecKeyPair);
    final Signature signatureData = signature.getSignatureData();
    assertThat(signatureData.getR()).isEqualTo(Numeric.toBigInt(expectedSignature.getR()));
    assertThat(signatureData.getS()).isEqualTo(Numeric.toBigInt(expectedSignature.getS()));
    assertThat(signatureData.getV()).isEqualTo(Numeric.toBigInt(expectedSignature.getV()));
}
Also used : SignatureData(org.web3j.crypto.Sign.SignatureData) Bytes(org.apache.tuweni.bytes.Bytes) CredentialSigner(tech.pegasys.signers.secp256k1.filebased.CredentialSigner) ECKeyPair(org.web3j.crypto.ECKeyPair) Signature(tech.pegasys.signers.secp256k1.api.Signature) Credentials(org.web3j.crypto.Credentials) Test(org.junit.jupiter.api.Test)

Example 2 with CredentialSigner

use of tech.pegasys.signers.secp256k1.filebased.CredentialSigner in project web3signer by ConsenSys.

the class FcSecpArtifactSignerTest method setup.

@BeforeEach
public void setup() {
    final Bytes fcPrivateKey = Bytes.fromBase64String(FC_SECP_PRIVATE_KEY);
    final Credentials credentials = Credentials.create(fcPrivateKey.toHexString());
    fcSecpArtifactSigner = new FcSecpArtifactSigner(new CredentialSigner(credentials, false), FilecoinNetwork.TESTNET);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) CredentialSigner(tech.pegasys.signers.secp256k1.filebased.CredentialSigner) Credentials(org.web3j.crypto.Credentials) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with CredentialSigner

use of tech.pegasys.signers.secp256k1.filebased.CredentialSigner in project web3signer by ConsenSys.

the class EthSecpArtifactSignerTest method publicKeyIsReturnedAsIdentifier.

@Test
void publicKeyIsReturnedAsIdentifier() {
    final ECKeyPair ecKeyPair = new ECKeyPair(Numeric.toBigInt(PRIVATE_KEY), Numeric.toBigInt(PUBLIC_KEY));
    final Credentials credentials = Credentials.create(ecKeyPair);
    final EthSecpArtifactSigner ethSecpArtifactSigner = new EthSecpArtifactSigner(new CredentialSigner(credentials));
    assertThat(ethSecpArtifactSigner.getIdentifier()).isEqualTo("0x" + PUBLIC_KEY);
}
Also used : CredentialSigner(tech.pegasys.signers.secp256k1.filebased.CredentialSigner) ECKeyPair(org.web3j.crypto.ECKeyPair) Credentials(org.web3j.crypto.Credentials) Test(org.junit.jupiter.api.Test)

Example 4 with CredentialSigner

use of tech.pegasys.signers.secp256k1.filebased.CredentialSigner in project signers by ConsenSys.

the class HashicorpSignerFactory method create.

public Signer create(final HashicorpKeyConfig keyConfig) {
    try {
        final HashicorpConnectionFactory connectionFactory = new HashicorpConnectionFactory(vertx);
        final HashicorpConnection connection = connectionFactory.create(keyConfig.getConnectionParams());
        final String secret = connection.fetchKey(keyConfig.getKeyDefinition());
        final Credentials credentials = Credentials.create(secret);
        return new CredentialSigner(credentials);
    } catch (final HashicorpException e) {
        throw new SignerInitializationException("Failed to extract secret from Hashicorp vault.", e);
    }
}
Also used : SignerInitializationException(tech.pegasys.signers.secp256k1.common.SignerInitializationException) CredentialSigner(tech.pegasys.signers.secp256k1.filebased.CredentialSigner) HashicorpConnectionFactory(tech.pegasys.signers.hashicorp.HashicorpConnectionFactory) HashicorpConnection(tech.pegasys.signers.hashicorp.HashicorpConnection) HashicorpException(tech.pegasys.signers.hashicorp.HashicorpException) Credentials(org.web3j.crypto.Credentials)

Example 5 with CredentialSigner

use of tech.pegasys.signers.secp256k1.filebased.CredentialSigner in project web3signer by ConsenSys.

the class EthSecpArtifactSignerTest method publicKeyIsReturnedAsIdentifier.

@Test
void publicKeyIsReturnedAsIdentifier() {
    final ECKeyPair ecKeyPair = new ECKeyPair(Numeric.toBigInt(PRIVATE_KEY), Numeric.toBigInt(PUBLIC_KEY));
    final Credentials credentials = Credentials.create(ecKeyPair);
    final EthSecpArtifactSigner ethSecpArtifactSigner = new EthSecpArtifactSigner(new CredentialSigner(credentials));
    assertThat(ethSecpArtifactSigner.getIdentifier()).isEqualTo("0x" + PUBLIC_KEY);
}
Also used : CredentialSigner(tech.pegasys.signers.secp256k1.filebased.CredentialSigner) ECKeyPair(org.web3j.crypto.ECKeyPair) Credentials(org.web3j.crypto.Credentials) Test(org.junit.jupiter.api.Test)

Aggregations

Credentials (org.web3j.crypto.Credentials)7 CredentialSigner (tech.pegasys.signers.secp256k1.filebased.CredentialSigner)7 Bytes (org.apache.tuweni.bytes.Bytes)4 Test (org.junit.jupiter.api.Test)4 ECKeyPair (org.web3j.crypto.ECKeyPair)4 BeforeEach (org.junit.jupiter.api.BeforeEach)2 SignatureData (org.web3j.crypto.Sign.SignatureData)2 Signature (tech.pegasys.signers.secp256k1.api.Signature)2 HashicorpConnection (tech.pegasys.signers.hashicorp.HashicorpConnection)1 HashicorpConnectionFactory (tech.pegasys.signers.hashicorp.HashicorpConnectionFactory)1 HashicorpException (tech.pegasys.signers.hashicorp.HashicorpException)1 SignerInitializationException (tech.pegasys.signers.secp256k1.common.SignerInitializationException)1