Search in sources :

Example 1 with SecpArtifactSignature

use of tech.pegasys.web3signer.signing.SecpArtifactSignature in project web3signer by ConsenSys.

the class Eth1Runner method populateRouter.

@Override
protected Router populateRouter(final Context context) {
    final RouterBuilder routerBuilder = context.getRouterBuilder();
    final LogErrorHandler errorHandler = context.getErrorHandler();
    final ArtifactSignerProvider signerProvider = context.getArtifactSignerProvider();
    addPublicKeysListHandler(routerBuilder, signerProvider, ETH1_LIST.name(), context.getErrorHandler());
    final SignerForIdentifier<SecpArtifactSignature> secpSigner = new SignerForIdentifier<>(signerProvider, this::formatSecpSignature, SECP256K1);
    routerBuilder.operation(ETH1_SIGN.name()).handler(new BlockingHandlerDecorator(new Eth1SignForIdentifierHandler(secpSigner, new HttpApiMetrics(context.getMetricsSystem(), SECP256K1)), false)).failureHandler(errorHandler);
    addReloadHandler(routerBuilder, signerProvider, RELOAD.name(), context.getErrorHandler());
    return context.getRouterBuilder().createRouter();
}
Also used : SignerForIdentifier(tech.pegasys.web3signer.core.service.http.handlers.signing.SignerForIdentifier) BlockingHandlerDecorator(io.vertx.ext.web.impl.BlockingHandlerDecorator) SecpArtifactSignature(tech.pegasys.web3signer.signing.SecpArtifactSignature) RouterBuilder(io.vertx.ext.web.openapi.RouterBuilder) ArtifactSignerProvider(tech.pegasys.web3signer.signing.ArtifactSignerProvider) DefaultArtifactSignerProvider(tech.pegasys.web3signer.signing.config.DefaultArtifactSignerProvider) Eth1SignForIdentifierHandler(tech.pegasys.web3signer.core.service.http.handlers.signing.Eth1SignForIdentifierHandler) HttpApiMetrics(tech.pegasys.web3signer.core.service.http.metrics.HttpApiMetrics) LogErrorHandler(tech.pegasys.web3signer.core.service.http.handlers.LogErrorHandler)

Example 2 with SecpArtifactSignature

use of tech.pegasys.web3signer.signing.SecpArtifactSignature in project web3signer by ConsenSys.

the class FcJsonRpc method filecoinWalletSign.

@JsonRpcMethod("Filecoin.WalletSign")
public FilecoinSignature filecoinWalletSign(@JsonRpcParam("identifier") final String filecoinAddress, @JsonRpcParam("data") final Bytes dataToSign, @JsonRpcOptional @JsonRpcParam("meta") final FilecoinMessageMsgMeta meta) {
    LOG.debug("Received FC sign request id = {}; data = {}", filecoinAddress, dataToSign);
    if (meta != null && meta.getExtra() != null) {
        final Bytes cidBytes = fcCidEncoder.createCid(meta.getExtra());
        checkArgument(dataToSign.equals(cidBytes), "Message invalid the data to sign doesn't match the CID of MsgMeta.extra");
    }
    final Optional<ArtifactSigner> signer = fcSigners.getSigner(filecoinAddress);
    final ArtifactSignature signature;
    if (signer.isPresent()) {
        signature = signer.get().sign(dataToSign);
    } else {
        throw new FilecoinSignerNotFoundException();
    }
    try (final OperationTimer.TimingContext ignored = metrics.getSigningTimer().labels(signature.getType().name()).startTimer()) {
        switch(signature.getType()) {
            case SECP256K1:
                metrics.incSecpSigningRequestCounter();
                final SecpArtifactSignature secpSig = (SecpArtifactSignature) signature;
                return new FilecoinSignature(SECP_VALUE, SecpArtifactSignature.toBytes(secpSig).toBase64String());
            case BLS:
                metrics.incBlsSigningRequestCounter();
                final BlsArtifactSignature blsSig = (BlsArtifactSignature) signature;
                return new FilecoinSignature(BLS_VALUE, blsSig.getSignatureData().toBytesCompressed().toBase64String());
            default:
                throw new IllegalArgumentException("Invalid Signature type created.");
        }
    }
}
Also used : BlsArtifactSignature(tech.pegasys.web3signer.signing.BlsArtifactSignature) SecpArtifactSignature(tech.pegasys.web3signer.signing.SecpArtifactSignature) ArtifactSignature(tech.pegasys.web3signer.signing.ArtifactSignature) Bytes(org.apache.tuweni.bytes.Bytes) OperationTimer(org.hyperledger.besu.plugin.services.metrics.OperationTimer) ArtifactSigner(tech.pegasys.web3signer.signing.ArtifactSigner) BlsArtifactSignature(tech.pegasys.web3signer.signing.BlsArtifactSignature) FilecoinSignerNotFoundException(tech.pegasys.web3signer.signing.filecoin.exceptions.FilecoinSignerNotFoundException) SecpArtifactSignature(tech.pegasys.web3signer.signing.SecpArtifactSignature) JsonRpcMethod(com.github.arteam.simplejsonrpc.core.annotation.JsonRpcMethod)

Example 3 with SecpArtifactSignature

use of tech.pegasys.web3signer.signing.SecpArtifactSignature in project web3signer by ConsenSys.

the class FilecoinVerifyTest method verifiesSecpSignatureWasSignedWithKey.

@Test
void verifiesSecpSignatureWasSignedWithKey() {
    final Bytes message = Bytes.fromBase64String(DATA);
    final SecpArtifactSignature artifactSignature = createSecpArtifactSignature(Bytes.fromBase64String(SECP_SIGNATURE));
    final FilecoinAddress filecoinAddress = FilecoinAddress.fromString("t1656rklyebnscuzs5dee3zwh2xknlqsy7r2ypxei");
    assertThat(FilecoinVerify.verify(filecoinAddress, message, artifactSignature)).isTrue();
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) SecpArtifactSignature(tech.pegasys.web3signer.signing.SecpArtifactSignature) Test(org.junit.jupiter.api.Test)

Example 4 with SecpArtifactSignature

use of tech.pegasys.web3signer.signing.SecpArtifactSignature 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) BlsArtifactSignature(tech.pegasys.web3signer.signing.BlsArtifactSignature) SecpArtifactSignature(tech.pegasys.web3signer.signing.SecpArtifactSignature) SecpArtifactSignature(tech.pegasys.web3signer.signing.SecpArtifactSignature)

Aggregations

SecpArtifactSignature (tech.pegasys.web3signer.signing.SecpArtifactSignature)4 Bytes (org.apache.tuweni.bytes.Bytes)3 BlsArtifactSignature (tech.pegasys.web3signer.signing.BlsArtifactSignature)2 JsonRpcMethod (com.github.arteam.simplejsonrpc.core.annotation.JsonRpcMethod)1 BlockingHandlerDecorator (io.vertx.ext.web.impl.BlockingHandlerDecorator)1 RouterBuilder (io.vertx.ext.web.openapi.RouterBuilder)1 OperationTimer (org.hyperledger.besu.plugin.services.metrics.OperationTimer)1 Test (org.junit.jupiter.api.Test)1 Signature (tech.pegasys.signers.secp256k1.api.Signature)1 BLSSignature (tech.pegasys.teku.bls.BLSSignature)1 LogErrorHandler (tech.pegasys.web3signer.core.service.http.handlers.LogErrorHandler)1 Eth1SignForIdentifierHandler (tech.pegasys.web3signer.core.service.http.handlers.signing.Eth1SignForIdentifierHandler)1 SignerForIdentifier (tech.pegasys.web3signer.core.service.http.handlers.signing.SignerForIdentifier)1 HttpApiMetrics (tech.pegasys.web3signer.core.service.http.metrics.HttpApiMetrics)1 ArtifactSignature (tech.pegasys.web3signer.signing.ArtifactSignature)1 ArtifactSigner (tech.pegasys.web3signer.signing.ArtifactSigner)1 ArtifactSignerProvider (tech.pegasys.web3signer.signing.ArtifactSignerProvider)1 DefaultArtifactSignerProvider (tech.pegasys.web3signer.signing.config.DefaultArtifactSignerProvider)1 FilecoinSignerNotFoundException (tech.pegasys.web3signer.signing.filecoin.exceptions.FilecoinSignerNotFoundException)1