Search in sources :

Example 11 with Signature

use of tech.pegasys.signers.secp256k1.api.Signature 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 12 with Signature

use of tech.pegasys.signers.secp256k1.api.Signature in project web3signer by ConsenSys.

the class FilecoinVerifyTest method createSecpArtifactSignature.

private SecpArtifactSignature createSecpArtifactSignature(final Bytes signature) {
    final Bytes r = signature.slice(0, 32);
    final Bytes s = signature.slice(32, 32);
    final Bytes v = signature.slice(64);
    return new SecpArtifactSignature(new Signature(Numeric.toBigInt(v.toArrayUnsafe()), Numeric.toBigInt(r.toArrayUnsafe()), Numeric.toBigInt(s.toArrayUnsafe())));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Signature(tech.pegasys.signers.secp256k1.api.Signature) BLSSignature(tech.pegasys.teku.bls.BLSSignature) SecpArtifactSignature(tech.pegasys.web3signer.core.signing.SecpArtifactSignature) BlsArtifactSignature(tech.pegasys.web3signer.core.signing.BlsArtifactSignature) SecpArtifactSignature(tech.pegasys.web3signer.core.signing.SecpArtifactSignature)

Example 13 with Signature

use of tech.pegasys.signers.secp256k1.api.Signature in project web3signer by ConsenSys.

the class SecpArtifactSignature method fromBytes.

public static SecpArtifactSignature fromBytes(final Bytes signature) {
    final Bytes r = signature.slice(0, 32);
    final Bytes s = signature.slice(32, 32);
    final Bytes v = signature.slice(64);
    return new SecpArtifactSignature(new Signature(Numeric.toBigInt(v.toArrayUnsafe()), Numeric.toBigInt(r.toArrayUnsafe()), Numeric.toBigInt(s.toArrayUnsafe())));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Signature(tech.pegasys.signers.secp256k1.api.Signature)

Aggregations

Signature (tech.pegasys.signers.secp256k1.api.Signature)13 Bytes (org.apache.tuweni.bytes.Bytes)10 BigInteger (java.math.BigInteger)3 Test (org.junit.jupiter.api.Test)3 SignatureData (org.web3j.crypto.Sign.SignatureData)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 CsvSource (org.junit.jupiter.params.provider.CsvSource)2 Credentials (org.web3j.crypto.Credentials)2 ECDSASignature (org.web3j.crypto.ECDSASignature)2 ECKeyPair (org.web3j.crypto.ECKeyPair)2 Signer (tech.pegasys.signers.secp256k1.api.Signer)2 CredentialSigner (tech.pegasys.signers.secp256k1.filebased.CredentialSigner)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 CryptographyClient (com.azure.security.keyvault.keys.cryptography.CryptographyClient)1 SignResult (com.azure.security.keyvault.keys.cryptography.models.SignResult)1 ECPublicKey (java.security.interfaces.ECPublicKey)1 AzureKeyVault (tech.pegasys.signers.azure.AzureKeyVault)1 PublicKeySignerIdentifier (tech.pegasys.signers.secp256k1.common.PublicKeySignerIdentifier)1 SignerInitializationException (tech.pegasys.signers.secp256k1.common.SignerInitializationException)1 BlsArtifactSignature (tech.pegasys.web3signer.core.signing.BlsArtifactSignature)1