Search in sources :

Example 1 with JsonRpcMethod

use of com.github.arteam.simplejsonrpc.core.annotation.JsonRpcMethod 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 2 with JsonRpcMethod

use of com.github.arteam.simplejsonrpc.core.annotation.JsonRpcMethod in project web3signer by ConsenSys.

the class FcJsonRpc method filecoinWalletVerify.

@JsonRpcMethod("Filecoin.WalletVerify")
public boolean filecoinWalletVerify(@JsonRpcParam("address") final String filecoinAddress, @JsonRpcParam("data") final Bytes dataToVerify, @JsonRpcParam("signature") final FilecoinSignature filecoinSignature) {
    final FilecoinAddress address = FilecoinAddress.fromString(filecoinAddress);
    final Bytes signature = Bytes.fromBase64String(filecoinSignature.getData());
    switch(address.getProtocol()) {
        case SECP256K1:
            checkArgument(filecoinSignature.getType() == SECP_VALUE, "Invalid signature type");
            return FilecoinVerify.verify(address, dataToVerify, SecpArtifactSignature.fromBytes(signature));
        case BLS:
            checkArgument(filecoinSignature.getType() == BLS_VALUE, "Invalid signature type");
            return FilecoinVerify.verify(address, dataToVerify, new BlsArtifactSignature(BLSSignature.fromBytesCompressed(signature)));
        default:
            throw new IllegalArgumentException("Invalid address protocol type");
    }
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BlsArtifactSignature(tech.pegasys.web3signer.signing.BlsArtifactSignature) FilecoinAddress(tech.pegasys.web3signer.signing.filecoin.FilecoinAddress) JsonRpcMethod(com.github.arteam.simplejsonrpc.core.annotation.JsonRpcMethod)

Aggregations

JsonRpcMethod (com.github.arteam.simplejsonrpc.core.annotation.JsonRpcMethod)2 Bytes (org.apache.tuweni.bytes.Bytes)2 BlsArtifactSignature (tech.pegasys.web3signer.signing.BlsArtifactSignature)2 OperationTimer (org.hyperledger.besu.plugin.services.metrics.OperationTimer)1 ArtifactSignature (tech.pegasys.web3signer.signing.ArtifactSignature)1 ArtifactSigner (tech.pegasys.web3signer.signing.ArtifactSigner)1 SecpArtifactSignature (tech.pegasys.web3signer.signing.SecpArtifactSignature)1 FilecoinAddress (tech.pegasys.web3signer.signing.filecoin.FilecoinAddress)1 FilecoinSignerNotFoundException (tech.pegasys.web3signer.signing.filecoin.exceptions.FilecoinSignerNotFoundException)1