From b2f1506d72f1cb14c552d60e98d904ff24290720 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Tue, 15 Oct 2024 14:00:59 +1000 Subject: [PATCH] Remove filecoin mode (#1027) * build: Remove filecoin lotus devnet from CircleCi configuration * remove FilecoinSubCommand from Web3SignerApp * Remove filecoin related classes * changelog --- .circleci/config.yml | 23 +-- CHANGELOG.md | 2 + .../dsl/lotus/FilecoinJsonRpcEndpoint.java | 129 ------------- .../web3signer/dsl/lotus/FilecoinKey.java | 64 ------- .../web3signer/dsl/lotus/FilecoinKeyType.java | 22 --- .../web3signer/dsl/lotus/LotusNode.java | 62 ------- .../pegasys/web3signer/dsl/signer/Signer.java | 6 +- .../web3signer/tests/AcceptanceTestBase.java | 2 - .../tests/MetricsAcceptanceTest.java | 59 ------ .../CompareApisAcceptanceTestBase.java | 80 --------- .../CompareFilecoinApisAcceptanceTest.java | 94 ---------- .../filecoin/FcBlsSigningAcceptanceTest.java | 97 ---------- .../filecoin/FcBlsVerifyAcceptanceTest.java | 91 ---------- .../filecoin/FcSecpSigningAcceptanceTest.java | 91 ---------- .../filecoin/FcSecpVerifyAcceptanceTest.java | 76 -------- .../FilecoinKeyIdentifiersAcceptanceTest.java | 86 --------- .../KeyIdentifiersAcceptanceTestBase.java | 15 -- .../signing/SigningAcceptanceTestBase.java | 6 - .../pegasys/web3signer/Web3SignerApp.java | 4 +- .../subcommands/FilecoinSubCommand.java | 71 -------- .../common/Web3SignerMetricCategory.java | 1 - .../web3signer/core/FilecoinRunner.java | 170 ------------------ .../pegasys/web3signer/core/SignerTypes.java | 20 --- .../core/service/jsonrpc/FcCidEncoder.java | 29 --- .../core/service/jsonrpc/FcJsonRpc.java | 133 -------------- .../service/jsonrpc/FcJsonRpcMetrics.java | 105 ----------- .../jsonrpc/FilecoinJsonRpcModule.java | 39 ---- .../core/service/jsonrpc/FilecoinMessage.java | 121 ------------- .../jsonrpc/FilecoinMessageMsgMeta.java | 40 ----- .../service/jsonrpc/FilecoinMsgMetaType.java | 20 --- .../service/jsonrpc/FilecoinSignature.java | 55 ------ .../jsonrpc/FilecoinSignedMessage.java | 41 ----- .../openapi-specs/filecoin/web3signer.yaml | 90 ---------- .../main/resources/openapi-specs/index.html | 1 - .../core/service/http/SwaggerUIRouteTest.java | 1 - .../core/util/OpenApiSpecsExtractorTest.java | 3 +- .../signing/FcBlsArtifactSigner.java | 60 ------- .../signing/FcSecpArtifactSigner.java | 75 -------- .../signing/filecoin/FilecoinAddress.java | 118 ------------ .../signing/filecoin/FilecoinNetwork.java | 39 ---- .../signing/filecoin/FilecoinProtocol.java | 41 ----- .../signing/filecoin/FilecoinVerify.java | 72 -------- .../FilecoinSignerNotFoundException.java | 24 --- .../InvalidAddressChecksumException.java | 24 --- .../InvalidAddressLengthException.java | 24 --- .../InvalidAddressPayloadException.java | 24 --- .../InvalidFilecoinNetworkException.java | 24 --- .../InvalidFilecoinProtocolException.java | 24 --- .../signing/FcBlsArtifactSignerTest.java | 62 ------- .../signing/FcSecpArtifactSignerTest.java | 68 ------- .../signing/FilecoinAddressTest.java | 102 ----------- .../signing/filecoin/FilecoinVerifyTest.java | 67 ------- 52 files changed, 6 insertions(+), 2791 deletions(-) delete mode 100644 acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/FilecoinJsonRpcEndpoint.java delete mode 100644 acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/FilecoinKey.java delete mode 100644 acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/FilecoinKeyType.java delete mode 100644 acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/LotusNode.java delete mode 100644 acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/comparison/CompareApisAcceptanceTestBase.java delete mode 100644 acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/comparison/CompareFilecoinApisAcceptanceTest.java delete mode 100644 acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcBlsSigningAcceptanceTest.java delete mode 100644 acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcBlsVerifyAcceptanceTest.java delete mode 100644 acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcSecpSigningAcceptanceTest.java delete mode 100644 acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcSecpVerifyAcceptanceTest.java delete mode 100644 acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/publickeys/FilecoinKeyIdentifiersAcceptanceTest.java delete mode 100644 commandline/src/main/java/tech/pegasys/web3signer/commandline/subcommands/FilecoinSubCommand.java delete mode 100644 core/src/main/java/tech/pegasys/web3signer/core/FilecoinRunner.java delete mode 100644 core/src/main/java/tech/pegasys/web3signer/core/SignerTypes.java delete mode 100644 core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FcCidEncoder.java delete mode 100644 core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FcJsonRpc.java delete mode 100644 core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FcJsonRpcMetrics.java delete mode 100644 core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinJsonRpcModule.java delete mode 100644 core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinMessage.java delete mode 100644 core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinMessageMsgMeta.java delete mode 100644 core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinMsgMetaType.java delete mode 100644 core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinSignature.java delete mode 100644 core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinSignedMessage.java delete mode 100644 core/src/main/resources/openapi-specs/filecoin/web3signer.yaml delete mode 100644 signing/src/main/java/tech/pegasys/web3signer/signing/FcBlsArtifactSigner.java delete mode 100644 signing/src/main/java/tech/pegasys/web3signer/signing/FcSecpArtifactSigner.java delete mode 100644 signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinAddress.java delete mode 100644 signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinNetwork.java delete mode 100644 signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinProtocol.java delete mode 100644 signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinVerify.java delete mode 100644 signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/FilecoinSignerNotFoundException.java delete mode 100644 signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidAddressChecksumException.java delete mode 100644 signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidAddressLengthException.java delete mode 100644 signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidAddressPayloadException.java delete mode 100644 signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidFilecoinNetworkException.java delete mode 100644 signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidFilecoinProtocolException.java delete mode 100644 signing/src/test/java/tech/pegasys/web3signer/signing/FcBlsArtifactSignerTest.java delete mode 100644 signing/src/test/java/tech/pegasys/web3signer/signing/FcSecpArtifactSignerTest.java delete mode 100644 signing/src/test/java/tech/pegasys/web3signer/signing/FilecoinAddressTest.java delete mode 100644 signing/src/test/java/tech/pegasys/web3signer/signing/filecoin/FilecoinVerifyTest.java diff --git a/.circleci/config.yml b/.circleci/config.yml index 42e20b819..497da1866 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,25 +27,6 @@ executors: JAVA_TOOL_OPTIONS: -Xmx4096m GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.parallel=true -Dorg.gradle.workers.max=4 -Xmx4096m - executor_large_with_fc_devnet: # 4cpu, 8G ram - docker: - # Primary container - - image: cimg/openjdk:21.0 - auth: - <<: *docker-auth - # Secondary container running lotus as devnet on port 7777 - - image: textile/lotus-devnet - auth: - <<: *docker-auth - environment: - TEXLOTUSDEVNET_BIGSECTORS: false - resource_class: large - working_directory: ~/project - environment: - JAVA_TOOL_OPTIONS: -Xmx4096m - GRADLE_OPTS: -Dorg.gradle.daemon=false -Dorg.gradle.parallel=true -Dorg.gradle.workers.max=4 -Xmx4096m - LOTUS_PORT: 7777 - executor_node: docker: - image: cimg/node:17.1.0 @@ -203,13 +184,11 @@ jobs: - ./ acceptanceTests: - executor: executor_large_with_fc_devnet + executor: executor_large steps: - prepare - attach_workspace: at: ~/project - # Wait for FC-DevNet to be up - - run: sleep 5 && nc -vz localhost 7777 - run: name: Acceptance Tests no_output_timeout: 20m diff --git a/CHANGELOG.md b/CHANGELOG.md index ae740c634..109c08b9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## Next Release +### Breaking Changes +- Filecoin mode has been removed. ### Features Added - Java 21 for build and runtime. [#995](https://github.com/Consensys/web3signer/pull/995) diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/FilecoinJsonRpcEndpoint.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/FilecoinJsonRpcEndpoint.java deleted file mode 100644 index aa1bd7a10..000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/FilecoinJsonRpcEndpoint.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.dsl.lotus; - -import tech.pegasys.web3signer.core.service.jsonrpc.FilecoinJsonRpcModule; -import tech.pegasys.web3signer.core.service.jsonrpc.FilecoinSignature; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Optional; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.json.JsonMapper; -import com.github.arteam.simplejsonrpc.client.JsonRpcClient; -import com.google.common.net.MediaType; -import org.apache.http.HttpHeaders; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; -import org.apache.tuweni.bytes.Bytes; - -public abstract class FilecoinJsonRpcEndpoint { - - public static final String BLS_SIGTYPE = "bls"; - public static final String SECP_SIGTYPE = "secp256k1"; - - // This is required to be set if operating against a full Lotus node (as opposed to dev-lotus). - private static final Optional AUTH_TOKEN = - Optional.ofNullable(System.getenv("WEB3SIGNER_BEARER_TOKEN")); - - private static final ObjectMapper OBJECT_MAPPER = - JsonMapper.builder().addModule(new FilecoinJsonRpcModule()).build(); - - private final JsonRpcClient jsonRpcClient; - private final String rpcPath; - - protected FilecoinJsonRpcEndpoint(final String rpcPath) { - jsonRpcClient = new JsonRpcClient(this::executeRawJsonRpcRequest, OBJECT_MAPPER); - this.rpcPath = rpcPath; - } - - public String walletNew(final String sigType) { - return jsonRpcClient - .createRequest() - .method("Filecoin.WalletNew") - .params(sigType) - .id(101) - .returnAs(String.class) - .execute(); - } - - public FilecoinKey walletExport(final String address) { - return jsonRpcClient - .createRequest() - .method("Filecoin.WalletExport") - .params(address) - .id(101) - .returnAs(FilecoinKey.class) - .execute(); - } - - public Boolean walletHas(final String address) { - return jsonRpcClient - .createRequest() - .method("Filecoin.WalletHas") - .params(address) - .id(101) - .returnAs(Boolean.class) - .execute(); - } - - public List walletList() { - return jsonRpcClient - .createRequest() - .method("Filecoin.WalletList") - .id(101) - .returnAsList(String.class) - .execute(); - } - - public FilecoinSignature walletSign(final String address, final Bytes data) { - return jsonRpcClient - .createRequest() - .method("Filecoin.WalletSign") - .id(101) - .params(address, data) // metaData is not supported on FC local wallet signing API impl - .returnAs(FilecoinSignature.class) - .execute(); - } - - public Boolean walletVerify( - final String address, final Bytes data, final FilecoinSignature signature) { - return jsonRpcClient - .createRequest() - .method("Filecoin.WalletVerify") - .id(202) - .params(address, data, signature) - .returnAs(Boolean.class) - .execute(); - } - - public String executeRawJsonRpcRequest(final String request) throws IOException { - final String url = getUrl() + rpcPath; - final HttpPost post = new HttpPost(url); - post.setEntity(new StringEntity(request, StandardCharsets.UTF_8)); - post.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString()); - AUTH_TOKEN.ifPresent(token -> post.setHeader("Authorization", "Bearer " + token)); - try (final CloseableHttpClient httpClient = HttpClients.createDefault(); - final CloseableHttpResponse httpResponse = httpClient.execute(post)) { - return EntityUtils.toString(httpResponse.getEntity(), StandardCharsets.UTF_8); - } - } - - public abstract String getUrl(); -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/FilecoinKey.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/FilecoinKey.java deleted file mode 100644 index 7953770d2..000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/FilecoinKey.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.dsl.lotus; - -import static tech.pegasys.web3signer.dsl.lotus.FilecoinKeyType.BLS; - -import java.util.Objects; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.tuweni.bytes.Bytes; - -public class FilecoinKey { - private final FilecoinKeyType type; - private final Bytes privateKey; - // the hex version is to be stored in Signers configuration file - private final String privateKeyHex; - - @JsonCreator - public FilecoinKey( - @JsonProperty("Type") final FilecoinKeyType type, - @JsonProperty("PrivateKey") final Bytes privateKey) { - this.type = type; - this.privateKey = privateKey; - // FC BLS Key in Little endian, reverse it. - this.privateKeyHex = - type == BLS ? privateKey.reverse().toHexString() : privateKey.toHexString(); - } - - public FilecoinKeyType getType() { - return type; - } - - public Bytes getPrivateKey() { - return privateKey; - } - - public String getPrivateKeyHex() { - return privateKeyHex; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final FilecoinKey that = (FilecoinKey) o; - return type == that.type && privateKey.equals(that.privateKey); - } - - @Override - public int hashCode() { - return Objects.hash(type, privateKey); - } -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/FilecoinKeyType.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/FilecoinKeyType.java deleted file mode 100644 index ceecead55..000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/FilecoinKeyType.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.dsl.lotus; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public enum FilecoinKeyType { - @JsonProperty("bls") - BLS, - @JsonProperty("secp256k1") - SECP256K1 -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/LotusNode.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/LotusNode.java deleted file mode 100644 index 38e34fc09..000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/lotus/LotusNode.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.dsl.lotus; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.function.Function; -import java.util.stream.Collectors; - -/** - * Lotus is expected to be running outside of acceptance test. It can be executed using following - * docker command - * docker run --rm --name lotuslocalnet -e TEXLOTUSDEVNET_SPEED=1500 \ -e - * TEXLOTUSDEVNET_BIGSECTORS=false -p 1234:7777 \ -v /tmp/import:/tmp/import textile/lotus-devnet - * - */ -public class LotusNode extends FilecoinJsonRpcEndpoint { - - private final String fcUrl; - - public LotusNode(final String host, final int port) { - super("/rpc/v0"); - fcUrl = String.format("http://%s:%d", host, port); - } - - public LotusNode(final int port) { - this("127.0.0.1", port); - } - - public Map createKeys(final int blsKeysCount, final int secpKeysCount) { - final Set addresses = new HashSet<>(); - - for (int i = 0; i < blsKeysCount; i++) { - final String address = walletNew(BLS_SIGTYPE); - addresses.add(address); - } - - for (int i = 0; i < secpKeysCount; i++) { - final String address = walletNew(SECP_SIGTYPE); - addresses.add(address); - } - - return addresses.parallelStream() - .collect(Collectors.toMap(Function.identity(), this::walletExport)); - } - - @Override - public String getUrl() { - return fcUrl; - } -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/signer/Signer.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/signer/Signer.java index 2d9600248..14acb4ac0 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/signer/Signer.java +++ b/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/signer/Signer.java @@ -17,7 +17,6 @@ import static tech.pegasys.web3signer.dsl.tls.TlsClientHelper.createRequestSpecification; import static tech.pegasys.web3signer.dsl.utils.WaitUtils.waitFor; import static tech.pegasys.web3signer.signing.KeyType.BLS; -import static tech.pegasys.web3signer.tests.AcceptanceTestBase.JSON_RPC_PATH; import tech.pegasys.web3signer.core.service.http.SigningObjectMapperFactory; import tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody; @@ -25,7 +24,6 @@ import tech.pegasys.web3signer.dsl.Eth; import tech.pegasys.web3signer.dsl.PublicContracts; import tech.pegasys.web3signer.dsl.Transactions; -import tech.pegasys.web3signer.dsl.lotus.FilecoinJsonRpcEndpoint; import tech.pegasys.web3signer.dsl.signer.runner.Web3SignerRunner; import tech.pegasys.web3signer.dsl.tls.ClientTlsConfig; import tech.pegasys.web3signer.signing.KeyType; @@ -54,7 +52,7 @@ import org.web3j.protocol.core.JsonRpc2_0Web3j; import org.web3j.protocol.http.HttpService; -public class Signer extends FilecoinJsonRpcEndpoint { +public class Signer { private static final Logger LOG = LogManager.getLogger(); public static final String ETH1_SIGN_ENDPOINT = @@ -84,7 +82,6 @@ public class Signer extends FilecoinJsonRpcEndpoint { private Web3j jsonRpc; public Signer(final SignerConfiguration signerConfig, final ClientTlsConfig clientTlsConfig) { - super(JSON_RPC_PATH); this.signerConfig = signerConfig; this.runner = Web3SignerRunner.createRunner(signerConfig); this.hostname = signerConfig.hostname(); @@ -130,7 +127,6 @@ public void awaitStartupCompletion() { LOG.info("Signer is now responsive"); } - @Override public String getUrl() { return String.format(urlFormatting, hostname, runner.httpPort()); } diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/AcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/AcceptanceTestBase.java index f55d68c64..d28165845 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/AcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/AcceptanceTestBase.java @@ -25,9 +25,7 @@ public class AcceptanceTestBase { protected Signer signer; - public static final String JSON_RPC_PATH = "/rpc/v0"; - public static final Long FILECOIN_CHAIN_ID = 314L; public static final Long DEFAULT_CHAIN_ID = 1337L; protected static final String ETH_2_SLASHINGPROTECTION_PERMITTED_SIGNINGS = "eth2_slashingprotection_permitted_signings_total"; diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/MetricsAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/MetricsAcceptanceTest.java index 041125eb2..a8e6e8036 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/MetricsAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/MetricsAcceptanceTest.java @@ -38,71 +38,12 @@ import org.apache.tuweni.bytes.Bytes32; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; import org.web3j.crypto.ECKeyPair; import org.web3j.crypto.Keys; import org.web3j.utils.Numeric; public class MetricsAcceptanceTest extends AcceptanceTestBase { - @ParameterizedTest - @ValueSource(booleans = {true, false}) - void filecoinApisAreCounted(final boolean useConfigFile) { - final SignerConfiguration signerConfiguration = - new SignerConfigurationBuilder() - .withMetricsCategories("FILECOIN") - .withMetricsEnabled(true) - .withMode("filecoin") - .withUseConfigFile(useConfigFile) - .withChainIdProvider(new ConfigurationChainId(FILECOIN_CHAIN_ID)) - .build(); - startSigner(signerConfiguration); - - final Set metricsOfInterest = - Set.of( - "filecoin_" - + SECP256K1.name().toLowerCase(Locale.ROOT) - + "_signing_request_count_total", - "filecoin_" + BLS.name().toLowerCase(Locale.ROOT) + "_signing_request_count_total", - "filecoin_total_request_count_total", - "filecoin_wallet_has_count_total", - "filecoin_wallet_list_count_total", - "filecoin_wallet_sign_message_count_total"); - - final Map initialMetrics = signer.getMetricsMatching(metricsOfInterest); - assertThat(initialMetrics).hasSize(metricsOfInterest.size()); - assertThat(initialMetrics).values().allMatch(s -> s.endsWith("0.0")); - - signer.walletHas("t01234"); - final Map metricsAfterWalletHas = signer.getMetricsMatching(metricsOfInterest); - assertThat(metricsAfterWalletHas) - .containsAllEntriesOf( - Map.of( - "filecoin_total_request_count_total", - "1.0", - "filecoin_wallet_has_count_total", - "1.0")); - - signer.walletList(); - final Map metricsAfterWalletList = signer.getMetricsMatching(metricsOfInterest); - assertThat(metricsAfterWalletList) - .containsAllEntriesOf( - Map.of( - "filecoin_total_request_count_total", - "2.0", - "filecoin_wallet_has_count_total", - "1.0")); - - try { - signer.walletSign("t01234", Bytes.fromHexString("0x1234")); - } catch (final Exception e) { - // it is known that the signing will fail. - } - final Map metricsAfterWalletSign = signer.getMetricsMatching(metricsOfInterest); - assertThat(metricsAfterWalletSign).containsEntry("filecoin_total_request_count_total", "3.0"); - } - @Test void missingSignerMetricIncreasesWhenUnmatchedRequestReceived() throws JsonProcessingException { final SignerConfiguration signerConfiguration = diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/comparison/CompareApisAcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/comparison/CompareApisAcceptanceTestBase.java deleted file mode 100644 index 921485ce9..000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/comparison/CompareApisAcceptanceTestBase.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.tests.comparison; - -import static tech.pegasys.web3signer.dsl.lotus.FilecoinKeyType.BLS; -import static tech.pegasys.web3signer.dsl.lotus.FilecoinKeyType.SECP256K1; - -import tech.pegasys.web3signer.dsl.lotus.FilecoinKey; -import tech.pegasys.web3signer.dsl.lotus.LotusNode; -import tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder; -import tech.pegasys.web3signer.dsl.utils.MetadataFileHelpers; -import tech.pegasys.web3signer.signing.KeyType; -import tech.pegasys.web3signer.tests.AcceptanceTestBase; - -import java.nio.file.Path; -import java.util.Map; - -import org.apache.tuweni.bytes.Bytes; -import org.junit.jupiter.api.io.TempDir; - -public class CompareApisAcceptanceTestBase extends AcceptanceTestBase { - - protected static final LotusNode LOTUS_NODE = - new LotusNode(Integer.parseInt(System.getenv("LOTUS_PORT"))); - protected static final int NO_OF_BLS_KEYS = 2; - protected static final int NO_OF_SECP_KEYS = 2; - protected static final Map ADDRESS_MAP = - LOTUS_NODE.createKeys(NO_OF_BLS_KEYS, NO_OF_SECP_KEYS); - protected static final Map NON_EXISTENT_ADDRESS_MAP = - Map.of( - "f3q7sj7rgvvlfpc7gx7z7jeco5x3q3aa4g6s54w3rl5alzdb6xa422seznjmtp7agboegcvrakcv22eo5bjlna", - new FilecoinKey( - BLS, Bytes.fromBase64String("NlWGbwCt8rEK7OTDYat3jy+3tj60cER81cIDUSEnFjU=")), - "f3rzhwtyxwmfbgikcddna3bv3eedn3meyt75gc6urmunbju26asfhaycsim6oc5qvyqbldziq53l3ujfpprhfa", - new FilecoinKey( - BLS, Bytes.fromBase64String("tFzDgbfTT983FdhnZ8xZjr0JdP37DcijmVm+XvurhFY=")), - "f1jcaxt7yoonwcvllj52kjzh4buo7gjmzemm3c3ny", - new FilecoinKey( - SECP256K1, Bytes.fromBase64String("5airIxsTE4wslOvXDcHoTnZE2ZWYGw/ZMwJQY0p7Pi4=")), - "f1te5vep7vlsxoh5vqz3fqlm76gewzpd63juum6jq", - new FilecoinKey( - SECP256K1, Bytes.fromBase64String("0oKQu6xyg0bOCaqNqpHULzxDa4VDQu1D19iArDL8+JU="))); - - protected static final MetadataFileHelpers METADATA_FILE_HELPERS = new MetadataFileHelpers(); - - @TempDir protected Path testDirectory; - - protected void initAndStartSigner(final boolean initKeystoreDirectory) { - if (initKeystoreDirectory) { - initSignerKeystoreDirectory(); - } - - final SignerConfigurationBuilder builder = - new SignerConfigurationBuilder().withKeyStoreDirectory(testDirectory).withMode("filecoin"); - startSigner(builder.build()); - } - - private void initSignerKeystoreDirectory() { - ADDRESS_MAP.forEach( - (fcAddress, key) -> - METADATA_FILE_HELPERS.createUnencryptedYamlFileAt( - keyConfigFile(fcAddress), - key.getPrivateKeyHex(), - key.getType() == BLS ? KeyType.BLS : KeyType.SECP256K1)); - } - - private Path keyConfigFile(final String prefix) { - return testDirectory.resolve(prefix + ".yaml"); - } -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/comparison/CompareFilecoinApisAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/comparison/CompareFilecoinApisAcceptanceTest.java deleted file mode 100644 index a994661a7..000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/comparison/CompareFilecoinApisAcceptanceTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.tests.comparison; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; - -import tech.pegasys.web3signer.core.service.jsonrpc.FilecoinSignature; - -import java.util.List; - -import org.apache.tuweni.bytes.Bytes; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.RepeatedTest; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; -import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables; - -@EnabledIfEnvironmentVariables({ - @EnabledIfEnvironmentVariable(named = "LOTUS_PORT", matches = ".*") -}) -public class CompareFilecoinApisAcceptanceTest extends CompareApisAcceptanceTestBase { - - @BeforeEach - void initSigner() { - super.initAndStartSigner(true); - } - - @Test - void compareWalletHasResponses() { - ADDRESS_MAP.forEach( - (address, key) -> { - assertThat(LOTUS_NODE.walletHas(address)).isTrue(); - assertThat(signer.walletHas(address)).isTrue(); - }); - - NON_EXISTENT_ADDRESS_MAP.forEach( - (address, key) -> { - assertThat(LOTUS_NODE.walletHas(address)).isFalse(); - assertThat(signer.walletHas(address)).isFalse(); - }); - } - - @Test - void compareWalletListResponses() { - final List lotusWalletList = LOTUS_NODE.walletList(); - final List signerWalletList = signer.walletList(); - - // note: lotus node may have additional miner addresses which aren't loaded in Signer. - Assertions.assertThat(lotusWalletList).containsAll(signerWalletList); - } - - @RepeatedTest(25) - void compareWalletSignAndVerifyResponsesWithRandomDataToSign() { - - ADDRESS_MAP.keySet().parallelStream() - .forEach( - address -> { - final Bytes dataToSign = Bytes.random(32); - - assertThatCode( - () -> { - final FilecoinSignature lotusFcSig = - LOTUS_NODE.walletSign(address, dataToSign); - final FilecoinSignature signerFcSig = - signer.walletSign(address, dataToSign); - - assertThat(signerFcSig).isEqualTo(lotusFcSig); - - // verify signatures - final Boolean lotusSigVerify = - LOTUS_NODE.walletVerify(address, dataToSign, lotusFcSig); - final Boolean signerSigVerify = - signer.walletVerify(address, dataToSign, signerFcSig); - - assertThat(lotusSigVerify).isTrue(); - assertThat(signerSigVerify).isTrue(); - }) - .as("Running with data %s for address %s", dataToSign, address) - .doesNotThrowAnyException(); - }); - } -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcBlsSigningAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcBlsSigningAcceptanceTest.java deleted file mode 100644 index 534263a17..000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcBlsSigningAcceptanceTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.tests.filecoin; - -import static io.restassured.RestAssured.given; -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.equalTo; - -import tech.pegasys.teku.bls.BLSKeyPair; -import tech.pegasys.teku.bls.BLSPublicKey; -import tech.pegasys.teku.bls.BLSSecretKey; -import tech.pegasys.web3signer.dsl.utils.MetadataFileHelpers; -import tech.pegasys.web3signer.signing.BlsArtifactSignature; -import tech.pegasys.web3signer.signing.FcBlsArtifactSigner; -import tech.pegasys.web3signer.signing.KeyType; -import tech.pegasys.web3signer.signing.filecoin.FilecoinAddress; -import tech.pegasys.web3signer.signing.filecoin.FilecoinNetwork; -import tech.pegasys.web3signer.tests.signing.SigningAcceptanceTestBase; - -import java.nio.file.Path; -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.json.JsonMapper; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ValueNode; -import com.github.arteam.simplejsonrpc.core.domain.Request; -import io.restassured.http.ContentType; -import io.restassured.response.Response; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.junit.jupiter.api.Test; - -public class FcBlsSigningAcceptanceTest extends SigningAcceptanceTestBase { - - private static final Bytes DATA = Bytes.wrap("Hello World".getBytes(UTF_8)); - private static final Bytes CID = - Bytes.fromHexString( - "0x0171a0e402201dc01772ee0171f5f614c673e3c7fa1107a8cf727bdf5a6dadb379e93c0d1d00"); - private static final String PRIVATE_KEY = - "3ee2224386c82ffea477e2adf28a2929f5c349165a4196158c7f3a2ecca40f35"; - - private static final MetadataFileHelpers METADATA_FILE_HELPERS = new MetadataFileHelpers(); - private static final BLSSecretKey KEY = - BLSSecretKey.fromBytes(Bytes32.fromHexString(PRIVATE_KEY)); - private static final BLSKeyPair KEY_PAIR = new BLSKeyPair(KEY); - private static final BLSPublicKey PUBLIC_KEY = KEY_PAIR.getPublicKey(); - private static final FilecoinNetwork NETWORK = FilecoinNetwork.MAINNET; - private static final FcBlsArtifactSigner SIGNATURE_GENERATOR = - new FcBlsArtifactSigner(KEY_PAIR, NETWORK); - - final FilecoinAddress identifier = FilecoinAddress.blsAddress(PUBLIC_KEY.toBytesCompressed()); - - @Test - void receiveASignatureWhenSubmitSigningRequestToFilecoinEndpoint() { - final String configFilename = PUBLIC_KEY.toString().substring(2); - final Path keyConfigFile = testDirectory.resolve(configFilename + ".yaml"); - METADATA_FILE_HELPERS.createUnencryptedYamlFileAt(keyConfigFile, PRIVATE_KEY, KeyType.BLS); - setupFilecoinSigner(); - - final ValueNode id = JsonNodeFactory.instance.numberNode(1); - final ObjectMapper mapper = JsonMapper.builder().build(); - final Map metaData = Map.of("type", "message", "extra", DATA.toBase64String()); - final JsonNode params = - mapper.convertValue( - List.of(identifier.encode(FilecoinNetwork.MAINNET), CID.toBase64String(), metaData), - JsonNode.class); - - final Request request = new Request("2.0", "Filecoin.WalletSign", params, id); - final Response response = given().baseUri(signer.getUrl()).body(request).post(JSON_RPC_PATH); - - response - .then() - .statusCode(200) - .contentType(ContentType.JSON) - .body("jsonrpc", equalTo("2.0"), "id", equalTo(id.asInt())); - - final BlsArtifactSignature expectedSignature = SIGNATURE_GENERATOR.sign(CID); - final Map result = response.body().jsonPath().get("result"); - assertThat(result.get("Type")).isEqualTo(2); - assertThat(result.get("Data")) - .isEqualTo(expectedSignature.getSignatureData().toBytesCompressed().toBase64String()); - } -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcBlsVerifyAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcBlsVerifyAcceptanceTest.java deleted file mode 100644 index b5602bfd6..000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcBlsVerifyAcceptanceTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.tests.filecoin; - -import static io.restassured.RestAssured.given; -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.equalTo; - -import tech.pegasys.teku.bls.BLSKeyPair; -import tech.pegasys.teku.bls.BLSPublicKey; -import tech.pegasys.teku.bls.BLSSecretKey; -import tech.pegasys.web3signer.core.service.jsonrpc.FcJsonRpc; -import tech.pegasys.web3signer.core.service.jsonrpc.FilecoinSignature; -import tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder; -import tech.pegasys.web3signer.signing.BlsArtifactSignature; -import tech.pegasys.web3signer.signing.FcBlsArtifactSigner; -import tech.pegasys.web3signer.signing.filecoin.FilecoinAddress; -import tech.pegasys.web3signer.signing.filecoin.FilecoinNetwork; -import tech.pegasys.web3signer.tests.AcceptanceTestBase; - -import java.util.Base64; -import java.util.List; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.json.JsonMapper; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ValueNode; -import com.github.arteam.simplejsonrpc.core.domain.Request; -import io.restassured.http.ContentType; -import io.restassured.response.Response; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.junit.jupiter.api.Test; - -public class FcBlsVerifyAcceptanceTest extends AcceptanceTestBase { - private static final String DATA_STRING = - Base64.getEncoder().encodeToString("Hello World".getBytes(UTF_8)); - private static final String PRIVATE_KEY = - "5abc1334d98d1432150df310f9d2fd51780a2b8a7489891f5d4ab9e77e6fb169"; - - private static final BLSSecretKey KEY = - BLSSecretKey.fromBytes(Bytes32.fromHexString(PRIVATE_KEY)); - private static final BLSKeyPair KEY_PAIR = new BLSKeyPair(KEY); - private static final BLSPublicKey PUBLIC_KEY = KEY_PAIR.getPublicKey(); - private static final FilecoinNetwork NETWORK = FilecoinNetwork.TESTNET; - private static final FcBlsArtifactSigner SIGNATURE_GENERATOR = - new FcBlsArtifactSigner(KEY_PAIR, NETWORK); - private static final BlsArtifactSignature EXPECTED_SIGNATURE = - SIGNATURE_GENERATOR.sign(Bytes.fromBase64String(DATA_STRING)); - - final FilecoinAddress identifier = FilecoinAddress.blsAddress(PUBLIC_KEY.toBytesCompressed()); - - @Test - void receiveTrueResponseWhenSubmitValidVerifyRequestToFilecoinEndpoint() { - startSigner(new SignerConfigurationBuilder().withMode("filecoin").build()); - - final ValueNode id = JsonNodeFactory.instance.numberNode(1); - final ObjectMapper mapper = JsonMapper.builder().build(); - - final FilecoinSignature filecoinSignature = - new FilecoinSignature( - FcJsonRpc.BLS_VALUE, - EXPECTED_SIGNATURE.getSignatureData().toBytesCompressed().toBase64String()); - final JsonNode params = - mapper.convertValue( - List.of(identifier.encode(NETWORK), DATA_STRING, filecoinSignature), JsonNode.class); - - final Request request = new Request("2.0", "Filecoin.WalletVerify", params, id); - final Response response = given().baseUri(signer.getUrl()).body(request).post(JSON_RPC_PATH); - - response - .then() - .statusCode(200) - .contentType(ContentType.JSON) - .body("jsonrpc", equalTo("2.0"), "id", equalTo(id.asInt())); - - assertThat(response.body().jsonPath().getBoolean("result")).isEqualTo(true); - } -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcSecpSigningAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcSecpSigningAcceptanceTest.java deleted file mode 100644 index b4b9428ea..000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcSecpSigningAcceptanceTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.tests.filecoin; - -import static io.restassured.RestAssured.given; -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.equalTo; - -import tech.pegasys.web3signer.dsl.utils.MetadataFileHelpers; -import tech.pegasys.web3signer.signing.KeyType; -import tech.pegasys.web3signer.signing.filecoin.FilecoinAddress; -import tech.pegasys.web3signer.signing.filecoin.FilecoinNetwork; -import tech.pegasys.web3signer.tests.signing.SigningAcceptanceTestBase; - -import java.io.File; -import java.net.URISyntaxException; -import java.nio.file.Path; -import java.util.Base64; -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.json.JsonMapper; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ValueNode; -import com.github.arteam.simplejsonrpc.core.domain.Request; -import com.google.common.io.Resources; -import io.restassured.http.ContentType; -import io.restassured.response.Response; -import org.apache.tuweni.bytes.Bytes; -import org.junit.jupiter.api.Test; - -public class FcSecpSigningAcceptanceTest extends SigningAcceptanceTestBase { - - private final MetadataFileHelpers metadataFileHelpers = new MetadataFileHelpers(); - - // Public Key of Keystore stored in resource "secp256k1/wallet.json" - public static final String PUBLIC_KEY_HEX_STRING = - "09b02f8a5fddd222ade4ea4528faefc399623af3f736be3c44f03e2df22fb792f3931a4d9573d333ca74343305762a753388c3422a86d98b713fc91c1ea04842"; - final String dataString = Base64.getEncoder().encodeToString("Hello World".getBytes(UTF_8)); - final String expectedBase64Signature = - "rapLdQPn5RQkiPeG6ij/0cCSBbsvHgO1Mx/rZVyM+HUrpdjamK6QSwSHzobfTaF2ehGevZ31t4XwZc7M5SnPwwA="; - final FilecoinAddress identifier = - FilecoinAddress.secpAddress(Bytes.fromHexString("04" + PUBLIC_KEY_HEX_STRING)); - - @Test - void receiveASignatureWhenSubmitSigningRequestToFilecoinEndpoint() throws URISyntaxException { - final String keyPath = - new File(Resources.getResource("secp256k1/wallet.json").toURI()).getAbsolutePath(); - - final Path keyConfigFile = testDirectory.resolve("arbitrary_secp.yaml"); - - metadataFileHelpers.createKeyStoreYamlFileAt( - keyConfigFile, Path.of(keyPath), "pass", KeyType.SECP256K1); - - setupFilecoinSigner(); - - final ValueNode id = JsonNodeFactory.instance.numberNode(1); - final ObjectMapper mapper = JsonMapper.builder().build(); - final Map metaData = Map.of("type", "unknown"); - final JsonNode params = - mapper.convertValue( - List.of(identifier.encode(FilecoinNetwork.MAINNET), dataString, metaData), - JsonNode.class); - - final Request request = new Request("2.0", "Filecoin.WalletSign", params, id); - final Response response = given().baseUri(signer.getUrl()).body(request).post(JSON_RPC_PATH); - - response - .then() - .statusCode(200) - .contentType(ContentType.JSON) - .body("jsonrpc", equalTo("2.0"), "id", equalTo(id.asInt())); - - final Map result = response.body().jsonPath().get("result"); - assertThat(result.get("Type")).isEqualTo(1); - assertThat(result.get("Data")).isEqualTo(expectedBase64Signature); - } -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcSecpVerifyAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcSecpVerifyAcceptanceTest.java deleted file mode 100644 index 22315803b..000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/filecoin/FcSecpVerifyAcceptanceTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.tests.filecoin; - -import static io.restassured.RestAssured.given; -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.equalTo; - -import tech.pegasys.web3signer.core.service.jsonrpc.FcJsonRpc; -import tech.pegasys.web3signer.core.service.jsonrpc.FilecoinSignature; -import tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder; -import tech.pegasys.web3signer.signing.filecoin.FilecoinAddress; -import tech.pegasys.web3signer.signing.filecoin.FilecoinNetwork; -import tech.pegasys.web3signer.tests.AcceptanceTestBase; - -import java.util.Base64; -import java.util.List; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.json.JsonMapper; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ValueNode; -import com.github.arteam.simplejsonrpc.core.domain.Request; -import io.restassured.http.ContentType; -import io.restassured.response.Response; -import org.apache.tuweni.bytes.Bytes; -import org.junit.jupiter.api.Test; - -public class FcSecpVerifyAcceptanceTest extends AcceptanceTestBase { - // Public Key of Keystore stored in resource "secp256k1/wallet.json" - public static final String PUBLIC_KEY_HEX_STRING = - "09b02f8a5fddd222ade4ea4528faefc399623af3f736be3c44f03e2df22fb792f3931a4d9573d333ca74343305762a753388c3422a86d98b713fc91c1ea04842"; - final String dataString = Base64.getEncoder().encodeToString("Hello World".getBytes(UTF_8)); - final String expectedBase64Signature = - "rapLdQPn5RQkiPeG6ij/0cCSBbsvHgO1Mx/rZVyM+HUrpdjamK6QSwSHzobfTaF2ehGevZ31t4XwZc7M5SnPwwA="; - final FilecoinAddress identifier = - FilecoinAddress.secpAddress(Bytes.fromHexString("04" + PUBLIC_KEY_HEX_STRING)); - - @Test - void receiveTrueResponseWhenSubmitValidVerifyRequestToFilecoinEndpoint() { - startSigner(new SignerConfigurationBuilder().withMode("filecoin").build()); - - final ValueNode id = JsonNodeFactory.instance.numberNode(1); - final ObjectMapper mapper = JsonMapper.builder().build(); - - final FilecoinSignature filecoinSignature = - new FilecoinSignature(FcJsonRpc.SECP_VALUE, expectedBase64Signature); - final JsonNode params = - mapper.convertValue( - List.of(identifier.encode(FilecoinNetwork.TESTNET), dataString, filecoinSignature), - JsonNode.class); - - final Request request = new Request("2.0", "Filecoin.WalletVerify", params, id); - final Response response = given().baseUri(signer.getUrl()).body(request).post(JSON_RPC_PATH); - - response - .then() - .statusCode(200) - .contentType(ContentType.JSON) - .body("jsonrpc", equalTo("2.0"), "id", equalTo(id.asInt())); - - assertThat(response.body().jsonPath().getBoolean("result")).isEqualTo(true); - } -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/publickeys/FilecoinKeyIdentifiersAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/publickeys/FilecoinKeyIdentifiersAcceptanceTest.java deleted file mode 100644 index 2a27d761b..000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/publickeys/FilecoinKeyIdentifiersAcceptanceTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.tests.publickeys; - -import static org.assertj.core.api.Assertions.assertThat; - -import tech.pegasys.web3signer.signing.KeyType; - -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; - -public class FilecoinKeyIdentifiersAcceptanceTest extends KeyIdentifiersAcceptanceTestBase { - - @ParameterizedTest - @EnumSource(value = KeyType.class) - public void noLoadedKeysReturnsEmptyPublicKeyResponse() { - initAndStartSigner("filecoin"); - assertThat(signer.walletList()).isEmpty(); - } - - @ParameterizedTest - @EnumSource(value = KeyType.class) - public void invalidKeysReturnsEmptyPublicKeyResponse(final KeyType keyType) { - createKeys(keyType, false, privateKeys(keyType)); - initAndStartSigner("filecoin"); - assertThat(signer.walletList()).isEmpty(); - } - - @ParameterizedTest - @EnumSource(value = KeyType.class) - public void onlyValidKeysAreReturnedInPublicKeyResponse(final KeyType keyType) { - final String[] prvKeys = privateKeys(keyType); - createKeys(keyType, true, prvKeys[0]); - createKeys(keyType, false, prvKeys[1]); - initAndStartSigner("filecoin"); - - final String[] filecoinAddresses = filecoinAddresses(keyType); - assertThat(signer.walletList()).containsExactly(filecoinAddresses[0]); - } - - @ParameterizedTest - @EnumSource(value = KeyType.class) - public void filecoinWalletHasReturnFalseWhenKeysAreNotLoaded(final KeyType keyType) { - initAndStartSigner("filecoin"); - - final String[] filecoinAddresses = filecoinAddresses(keyType); - - assertThat(signer.walletHas(filecoinAddresses[0])).isEqualTo(false); - assertThat(signer.walletHas(filecoinAddresses[1])).isEqualTo(false); - } - - @ParameterizedTest - @EnumSource(value = KeyType.class) - public void filecoinWalletHasReturnsValidResponse(final KeyType keyType) { - final String[] prvKeys = privateKeys(keyType); - createKeys(keyType, true, prvKeys[0]); - createKeys(keyType, false, prvKeys[1]); - - initAndStartSigner("filecoin"); - - final String[] filecoinAddresses = filecoinAddresses(keyType); - - assertThat(signer.walletHas(filecoinAddresses[0])).isEqualTo(true); - assertThat(signer.walletHas(filecoinAddresses[1])).isEqualTo(false); - } - - @ParameterizedTest - @EnumSource(value = KeyType.class) - public void allLoadedKeysAreReturnedPublicKeyResponseWithEmptyAccept(final KeyType keyType) { - createKeys(keyType, true, privateKeys(keyType)); - initAndStartSigner("filecoin"); - - final String[] filecoinAddresses = filecoinAddresses(keyType); - assertThat(signer.walletList()).containsOnly(filecoinAddresses); - } -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/publickeys/KeyIdentifiersAcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/publickeys/KeyIdentifiersAcceptanceTestBase.java index bf941efed..0a7732343 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/publickeys/KeyIdentifiersAcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/publickeys/KeyIdentifiersAcceptanceTestBase.java @@ -53,15 +53,6 @@ public class KeyIdentifiersAcceptanceTestBase extends AcceptanceTestBase { protected static final String SECP_PUBLIC_KEY_1 = "0x24491715b7514b315d06b6be809173e7c8051a2cd1880d29f8af5efda30e0877e816820c91d46444afc4063742a1602648751df36e11b5c95037fab1d4dd93eb"; - // These values were generated using go-address https://github.com/filecoin-project/go-address - // with above corresponding public keys - protected static final String SECP_FC_ADDRESS_1 = "f1yv62jzybqbktnamqrart5ovqtpuiizf33dv45ga"; - protected static final String SECP_FC_ADDRESS_2 = "f1fg4ofyvbbqkobf7gdv4ggozuhen5johtimueabi"; - protected static final String BLS_FC_ADDRESS_1 = - "f3tcoti4s2fp6d6fiql47v7sdud5bwyjpod3spssheexllzogfnphg4bwcnfrvw7uylj77uy46eqe36xecyo6a"; - protected static final String BLS_FC_ADDRESS_2 = - "f3w3xgslow4fgr5clqa23ew6l4moiiyf6oqbglgkz47ula4xm7xxdkpi4kpmdbhqgts4k5n63qmjav6uulgb4q"; - protected static final MetadataFileHelpers METADATA_FILE_HELPERS = new MetadataFileHelpers(); @TempDir Path testDirectory; @@ -79,12 +70,6 @@ protected String[] createKeys( : createSecpKeys(isValid, privateKeys); } - protected String[] filecoinAddresses(final KeyType keyType) { - return keyType == BLS - ? new String[] {BLS_FC_ADDRESS_1, BLS_FC_ADDRESS_2} - : new String[] {SECP_FC_ADDRESS_1, SECP_FC_ADDRESS_2}; - } - protected String[] createBlsKeys(final boolean isValid, final String... privateKeys) { return Stream.of(privateKeys) .map( diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/signing/SigningAcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/signing/SigningAcceptanceTestBase.java index e3fc31257..b679c6f0e 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/signing/SigningAcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/web3signer/tests/signing/SigningAcceptanceTestBase.java @@ -37,12 +37,6 @@ protected void setupEth1Signer() { startSigner(builder.build()); } - protected void setupFilecoinSigner() { - final SignerConfigurationBuilder builder = new SignerConfigurationBuilder(); - builder.withKeyStoreDirectory(testDirectory).withMode("filecoin"); - startSigner(builder.build()); - } - protected void setupEth2Signer(final Eth2Network eth2Network, final SpecMilestone specMilestone) { final SignerConfigurationBuilder builder = new SignerConfigurationBuilder(); builder diff --git a/app/src/main/java/tech/pegasys/web3signer/Web3SignerApp.java b/app/src/main/java/tech/pegasys/web3signer/Web3SignerApp.java index 953ca2a07..b81053bf0 100644 --- a/app/src/main/java/tech/pegasys/web3signer/Web3SignerApp.java +++ b/app/src/main/java/tech/pegasys/web3signer/Web3SignerApp.java @@ -18,7 +18,6 @@ import tech.pegasys.web3signer.commandline.Web3SignerBaseCommand; import tech.pegasys.web3signer.commandline.subcommands.Eth1SubCommand; import tech.pegasys.web3signer.commandline.subcommands.Eth2SubCommand; -import tech.pegasys.web3signer.commandline.subcommands.FilecoinSubCommand; import tech.pegasys.web3signer.common.ApplicationInfo; import java.io.PrintWriter; @@ -45,8 +44,7 @@ public static void executeWithEnvironment( final PrintWriter errorWriter = new PrintWriter(System.err, true, UTF_8); final CommandlineParser cmdLineParser = new CommandlineParser(baseCommand, outputWriter, errorWriter, environment); - cmdLineParser.registerSubCommands( - new Eth2SubCommand(), new Eth1SubCommand(), new FilecoinSubCommand()); + cmdLineParser.registerSubCommands(new Eth2SubCommand(), new Eth1SubCommand()); final int result = cmdLineParser.parseCommandLine(args); if (result != 0) { diff --git a/commandline/src/main/java/tech/pegasys/web3signer/commandline/subcommands/FilecoinSubCommand.java b/commandline/src/main/java/tech/pegasys/web3signer/commandline/subcommands/FilecoinSubCommand.java deleted file mode 100644 index cfbd7497e..000000000 --- a/commandline/src/main/java/tech/pegasys/web3signer/commandline/subcommands/FilecoinSubCommand.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.commandline.subcommands; - -import tech.pegasys.web3signer.core.FilecoinRunner; -import tech.pegasys.web3signer.core.Runner; -import tech.pegasys.web3signer.signing.filecoin.FilecoinNetwork; - -import picocli.CommandLine; -import picocli.CommandLine.Command; -import picocli.CommandLine.HelpCommand; -import picocli.CommandLine.Option; - -@Command( - name = FilecoinSubCommand.COMMAND_NAME, - description = "Handle Filecoin signing operations and address reporting", - subcommands = {HelpCommand.class}, - mixinStandardHelpOptions = true) -public class FilecoinSubCommand extends ModeSubCommand { - - public static final String COMMAND_NAME = "filecoin"; - @CommandLine.Spec private CommandLine.Model.CommandSpec spec; // injected by picocli - - @Option( - names = {"--network"}, - description = "Filecoin network to use for addresses (default: ${DEFAULT-VALUE})", - paramLabel = "", - arity = "1") - private final FilecoinNetwork network = FilecoinNetwork.MAINNET; - - private long awsKmsClientCacheSize = 1; - - @Override - public Runner createRunner() { - return new FilecoinRunner(config, network, awsKmsClientCacheSize); - } - - @Override - public String getCommandName() { - return COMMAND_NAME; - } - - @Override - protected void validateArgs() { - // no special validation required - } - - @CommandLine.Option( - names = {"--aws-kms-client-cache-size"}, - paramLabel = "", - defaultValue = "1", - description = - "AWS Kms Client cache size. Should be set based on different set of credentials and region (default: ${DEFAULT-VALUE})") - public void setAwsKmsClientCacheSize(long awsKmsClientCacheSize) { - if (awsKmsClientCacheSize < 1) { - throw new CommandLine.ParameterException( - spec.commandLine(), "--aws-kms-client-cache-size must be positive"); - } - this.awsKmsClientCacheSize = awsKmsClientCacheSize; - } -} diff --git a/common/src/main/java/tech/pegasys/web3signer/common/Web3SignerMetricCategory.java b/common/src/main/java/tech/pegasys/web3signer/common/Web3SignerMetricCategory.java index a3d412263..ab64c88eb 100644 --- a/common/src/main/java/tech/pegasys/web3signer/common/Web3SignerMetricCategory.java +++ b/common/src/main/java/tech/pegasys/web3signer/common/Web3SignerMetricCategory.java @@ -22,7 +22,6 @@ public enum Web3SignerMetricCategory implements MetricCategory { ETH2_SLASHING_PROTECTION("eth2_slashingprotection"), - FILECOIN("filecoin"), HTTP("http"), SIGNING("signing"); diff --git a/core/src/main/java/tech/pegasys/web3signer/core/FilecoinRunner.java b/core/src/main/java/tech/pegasys/web3signer/core/FilecoinRunner.java deleted file mode 100644 index 0071b74d9..000000000 --- a/core/src/main/java/tech/pegasys/web3signer/core/FilecoinRunner.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.core; - -import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; -import static com.fasterxml.jackson.databind.MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS; -import static com.fasterxml.jackson.databind.MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES; -import static io.vertx.core.http.HttpHeaders.CONTENT_TYPE; -import static tech.pegasys.web3signer.core.service.http.handlers.ContentTypes.JSON_UTF_8; - -import tech.pegasys.web3signer.core.config.BaseConfig; -import tech.pegasys.web3signer.core.service.jsonrpc.FcJsonRpc; -import tech.pegasys.web3signer.core.service.jsonrpc.FcJsonRpcMetrics; -import tech.pegasys.web3signer.core.service.jsonrpc.FilecoinJsonRpcModule; -import tech.pegasys.web3signer.keystorage.aws.AwsSecretsManagerProvider; -import tech.pegasys.web3signer.keystorage.hashicorp.HashicorpConnectionFactory; -import tech.pegasys.web3signer.signing.ArtifactSignerProvider; -import tech.pegasys.web3signer.signing.FcBlsArtifactSigner; -import tech.pegasys.web3signer.signing.FcSecpArtifactSigner; -import tech.pegasys.web3signer.signing.config.AzureKeyVaultFactory; -import tech.pegasys.web3signer.signing.config.DefaultArtifactSignerProvider; -import tech.pegasys.web3signer.signing.config.SignerLoader; -import tech.pegasys.web3signer.signing.config.metadata.AbstractArtifactSignerFactory; -import tech.pegasys.web3signer.signing.config.metadata.BlsArtifactSignerFactory; -import tech.pegasys.web3signer.signing.config.metadata.Secp256k1ArtifactSignerFactory; -import tech.pegasys.web3signer.signing.config.metadata.interlock.InterlockKeyProvider; -import tech.pegasys.web3signer.signing.config.metadata.parser.YamlMapperFactory; -import tech.pegasys.web3signer.signing.config.metadata.parser.YamlSignerParser; -import tech.pegasys.web3signer.signing.config.metadata.yubihsm.YubiHsmOpaqueDataProvider; -import tech.pegasys.web3signer.signing.filecoin.FilecoinNetwork; -import tech.pegasys.web3signer.signing.secp256k1.aws.AwsKmsSignerFactory; -import tech.pegasys.web3signer.signing.secp256k1.aws.CachedAwsKmsClientFactory; -import tech.pegasys.web3signer.signing.secp256k1.azure.AzureHttpClientFactory; -import tech.pegasys.web3signer.signing.secp256k1.azure.AzureKeyVaultSignerFactory; - -import java.util.List; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.json.JsonMapper; -import com.github.arteam.simplejsonrpc.server.JsonRpcServer; -import io.vertx.core.Vertx; -import io.vertx.ext.web.Router; -import org.hyperledger.besu.plugin.services.MetricsSystem; - -public class FilecoinRunner extends Runner { - private static final int AWS_CACHE_MAXIMUM_SIZE = 1; - private static final String FC_JSON_RPC_PATH = "/rpc/v0"; - private final FilecoinNetwork network; - private final long awsKmsClientCacheSize; - - public FilecoinRunner( - final BaseConfig baseConfig, - final FilecoinNetwork network, - final long awsKmsClientCacheSize) { - super(baseConfig); - this.network = network; - this.awsKmsClientCacheSize = awsKmsClientCacheSize; - } - - @Override - protected void populateRouter(final Context context) { - addReloadHandler( - context.getRouter(), - List.of(context.getArtifactSignerProvider()), - context.getErrorHandler()); - - registerFilecoinJsonRpcRoute( - context.getRouter(), context.getMetricsSystem(), context.getArtifactSignerProvider()); - } - - private Router registerFilecoinJsonRpcRoute( - final Router router, - final MetricsSystem metricsSystem, - final ArtifactSignerProvider fcSigners) { - - final FcJsonRpcMetrics fcJsonRpcMetrics = new FcJsonRpcMetrics(metricsSystem); - final FcJsonRpc fileCoinJsonRpc = new FcJsonRpc(fcSigners, fcJsonRpcMetrics); - final ObjectMapper mapper = - JsonMapper.builder() - .enable(ACCEPT_CASE_INSENSITIVE_ENUMS) - .enable(ACCEPT_CASE_INSENSITIVE_PROPERTIES) - .disable(FAIL_ON_UNKNOWN_PROPERTIES) - .addModule(new FilecoinJsonRpcModule()) - .build(); - final JsonRpcServer jsonRpcServer = JsonRpcServer.withMapper(mapper); - - router - .post(FC_JSON_RPC_PATH) - .handler(fcJsonRpcMetrics::incTotalFilecoinRequests) - .blockingHandler( - routingContext -> { - final String body = routingContext.body().asString(); - final String jsonRpcResponse = jsonRpcServer.handle(body, fileCoinJsonRpc); - routingContext.response().putHeader(CONTENT_TYPE, JSON_UTF_8).end(jsonRpcResponse); - }, - false); - - return router; - } - - @Override - protected ArtifactSignerProvider createArtifactSignerProvider( - final Vertx vertx, final MetricsSystem metricsSystem) { - return new DefaultArtifactSignerProvider( - () -> { - final AzureKeyVaultFactory azureKeyVaultFactory = new AzureKeyVaultFactory(); - registerClose(azureKeyVaultFactory::close); - final AzureHttpClientFactory azureHttpClientFactory = new AzureHttpClientFactory(); - final AzureKeyVaultSignerFactory azureSignerFactory = - new AzureKeyVaultSignerFactory(azureKeyVaultFactory, azureHttpClientFactory); - final CachedAwsKmsClientFactory cachedAwsKmsClientFactory = - new CachedAwsKmsClientFactory(awsKmsClientCacheSize); - final boolean applySha3Hash = false; - final AwsKmsSignerFactory awsKmsSignerFactory = - new AwsKmsSignerFactory(cachedAwsKmsClientFactory, applySha3Hash); - - try (final HashicorpConnectionFactory hashicorpConnectionFactory = - new HashicorpConnectionFactory(); - final InterlockKeyProvider interlockKeyProvider = new InterlockKeyProvider(vertx); - final YubiHsmOpaqueDataProvider yubiHsmOpaqueDataProvider = - new YubiHsmOpaqueDataProvider(); - final AwsSecretsManagerProvider awsSecretsManagerProvider = - new AwsSecretsManagerProvider(AWS_CACHE_MAXIMUM_SIZE)) { - - final AbstractArtifactSignerFactory blsArtifactSignerFactory = - new BlsArtifactSignerFactory( - baseConfig.getKeyConfigPath(), - metricsSystem, - hashicorpConnectionFactory, - interlockKeyProvider, - yubiHsmOpaqueDataProvider, - awsSecretsManagerProvider, - (args) -> new FcBlsArtifactSigner(args.getKeyPair(), network), - azureKeyVaultFactory); - - final AbstractArtifactSignerFactory secpArtifactSignerFactory = - new Secp256k1ArtifactSignerFactory( - hashicorpConnectionFactory, - baseConfig.getKeyConfigPath(), - azureSignerFactory, - interlockKeyProvider, - yubiHsmOpaqueDataProvider, - signer -> new FcSecpArtifactSigner(signer, network), - azureKeyVaultFactory, - awsKmsSignerFactory, - applySha3Hash); - - return new SignerLoader(baseConfig.keystoreParallelProcessingEnabled()) - .load( - baseConfig.getKeyConfigPath(), - "yaml", - new YamlSignerParser( - List.of(blsArtifactSignerFactory, secpArtifactSignerFactory), - YamlMapperFactory.createYamlMapper( - baseConfig.getKeyStoreConfigFileMaxSize()))) - .getValues(); - } - }); - } -} diff --git a/core/src/main/java/tech/pegasys/web3signer/core/SignerTypes.java b/core/src/main/java/tech/pegasys/web3signer/core/SignerTypes.java deleted file mode 100644 index 0198c807f..000000000 --- a/core/src/main/java/tech/pegasys/web3signer/core/SignerTypes.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.core; - -public enum SignerTypes { - BLS, - ETH_SECP, - FC_SECP, - FC_BLS -} diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FcCidEncoder.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FcCidEncoder.java deleted file mode 100644 index 12ebfe271..000000000 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FcCidEncoder.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.core.service.jsonrpc; - -import tech.pegasys.web3signer.signing.util.Blake2b; - -import io.ipfs.cid.Cid; -import io.ipfs.cid.Cid.Codec; -import io.ipfs.multihash.Multihash; -import org.apache.tuweni.bytes.Bytes; - -public class FcCidEncoder { - - public Bytes createCid(final Bytes data) { - final Bytes hash = Blake2b.sum256(data); - final Cid cid = Cid.buildCidV1(Codec.DagCbor, Multihash.Type.blake2b_256, hash.toArrayUnsafe()); - return Bytes.wrap(cid.toBytes()); - } -} diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FcJsonRpc.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FcJsonRpc.java deleted file mode 100644 index 14b4a0340..000000000 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FcJsonRpc.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.core.service.jsonrpc; - -import static com.google.common.base.Preconditions.checkArgument; - -import tech.pegasys.teku.bls.BLSSignature; -import tech.pegasys.web3signer.signing.ArtifactSignature; -import tech.pegasys.web3signer.signing.ArtifactSigner; -import tech.pegasys.web3signer.signing.ArtifactSignerProvider; -import tech.pegasys.web3signer.signing.BlsArtifactSignature; -import tech.pegasys.web3signer.signing.SecpArtifactSignature; -import tech.pegasys.web3signer.signing.filecoin.FilecoinAddress; -import tech.pegasys.web3signer.signing.filecoin.FilecoinVerify; -import tech.pegasys.web3signer.signing.filecoin.exceptions.FilecoinSignerNotFoundException; - -import java.util.Optional; -import java.util.Set; - -import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcMethod; -import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcOptional; -import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcParam; -import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcService; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.plugin.services.metrics.OperationTimer; - -@JsonRpcService -public class FcJsonRpc { - - public static final int SECP_VALUE = 1; - public static final int BLS_VALUE = 2; - - private static final Logger LOG = LogManager.getLogger(); - - private final ArtifactSignerProvider fcSigners; - private final FcJsonRpcMetrics metrics; - private final FcCidEncoder fcCidEncoder = new FcCidEncoder(); - - public FcJsonRpc(final ArtifactSignerProvider fcSigners, final FcJsonRpcMetrics metrics) { - this.fcSigners = fcSigners; - this.metrics = metrics; - } - - @JsonRpcMethod("Filecoin.WalletList") - public Set filecoinWalletList() { - metrics.incWalletListRequestCounter(); - return fcSigners.availableIdentifiers(); - } - - @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 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."); - } - } - } - - @JsonRpcMethod("Filecoin.WalletHas") - public boolean filecoinWalletHas(@JsonRpcParam("address") final String address) { - metrics.incWalletHasRequestCounter(); - return fcSigners.availableIdentifiers().contains(address); - } - - @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"); - } - } -} diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FcJsonRpcMetrics.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FcJsonRpcMetrics.java deleted file mode 100644 index a228c8f80..000000000 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FcJsonRpcMetrics.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.core.service.jsonrpc; - -import tech.pegasys.web3signer.common.Web3SignerMetricCategory; -import tech.pegasys.web3signer.signing.KeyType; - -import java.util.Locale; - -import io.vertx.ext.web.RoutingContext; -import org.hyperledger.besu.plugin.services.MetricsSystem; -import org.hyperledger.besu.plugin.services.metrics.Counter; -import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; -import org.hyperledger.besu.plugin.services.metrics.OperationTimer; - -public class FcJsonRpcMetrics { - - private final Counter secpSigningRequestCounter; - private final Counter blsSigningRequestCounter; - private final Counter walletListRequestCounter; - private final Counter walletHasRequestCounter; - private final Counter walletSignMessageRequestCounter; - private final LabelledMetric signingTimer; - private final Counter totalFilecoinRequests; - - public FcJsonRpcMetrics(final MetricsSystem metricsSystem) { - this.secpSigningRequestCounter = - metricsSystem.createCounter( - Web3SignerMetricCategory.FILECOIN, - KeyType.SECP256K1.name().toLowerCase(Locale.ROOT) + "_signing_request_count", - "Number of signing requests made for SECP256k1 keys"); - this.blsSigningRequestCounter = - metricsSystem.createCounter( - Web3SignerMetricCategory.FILECOIN, - KeyType.BLS.name().toLowerCase(Locale.ROOT) + "_signing_request_count", - "Number of signing requests made for BLS keys"); - this.walletListRequestCounter = - metricsSystem.createCounter( - Web3SignerMetricCategory.FILECOIN, - "wallet_list_count", - "Number of times a Filecoin.WalletList request has been received"); - this.walletHasRequestCounter = - metricsSystem.createCounter( - Web3SignerMetricCategory.FILECOIN, - "wallet_has_count", - "Number of times a Filecoin.WalletHas request has been received"); - this.walletSignMessageRequestCounter = - metricsSystem.createCounter( - Web3SignerMetricCategory.FILECOIN, - "wallet_sign_message_count", - "Number of times a Filecoin.WalletSignMessage request has been received"); - - this.signingTimer = - metricsSystem.createLabelledTimer( - Web3SignerMetricCategory.FILECOIN, - "wallet_sign_duration", - "The duration for a signing operation", - "keyType"); - - this.totalFilecoinRequests = - metricsSystem.createCounter( - Web3SignerMetricCategory.FILECOIN, - "total_request_count", - "Total number of Filecoin requests received"); - } - - public void incSecpSigningRequestCounter() { - secpSigningRequestCounter.inc(); - } - - public void incBlsSigningRequestCounter() { - blsSigningRequestCounter.inc(); - } - - public void incWalletListRequestCounter() { - walletListRequestCounter.inc(); - } - - public void incWalletHasRequestCounter() { - walletHasRequestCounter.inc(); - } - - public void incWalletSignMessageRequestCounter() { - walletSignMessageRequestCounter.inc(); - } - - public LabelledMetric getSigningTimer() { - return signingTimer; - } - - public void incTotalFilecoinRequests(final RoutingContext rc) { - totalFilecoinRequests.inc(); - rc.next(); - } -} diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinJsonRpcModule.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinJsonRpcModule.java deleted file mode 100644 index 764ee070d..000000000 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinJsonRpcModule.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.core.service.jsonrpc; - -import tech.pegasys.web3signer.common.JacksonSerializers.Base64Deserialiser; -import tech.pegasys.web3signer.common.JacksonSerializers.Base64Serialiser; -import tech.pegasys.web3signer.common.JacksonSerializers.BigIntegerDecimalStringDeserialiser; -import tech.pegasys.web3signer.common.JacksonSerializers.BigIntegerDecimalStringSerialiser; -import tech.pegasys.web3signer.common.JacksonSerializers.NumberUInt64Deserializer; -import tech.pegasys.web3signer.common.JacksonSerializers.NumberUInt64Serialiser; - -import java.math.BigInteger; - -import com.fasterxml.jackson.databind.module.SimpleModule; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt64; - -public class FilecoinJsonRpcModule extends SimpleModule { - - public FilecoinJsonRpcModule() { - super("FilecoinJsonRpcModule"); - addDeserializer(Bytes.class, new Base64Deserialiser()); - addSerializer(Bytes.class, new Base64Serialiser()); - addDeserializer(UInt64.class, new NumberUInt64Deserializer()); - addSerializer(UInt64.class, new NumberUInt64Serialiser()); - addDeserializer(BigInteger.class, new BigIntegerDecimalStringDeserialiser()); - addSerializer(BigInteger.class, new BigIntegerDecimalStringSerialiser()); - } -} diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinMessage.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinMessage.java deleted file mode 100644 index e2d64212a..000000000 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinMessage.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.core.service.jsonrpc; - -import java.math.BigInteger; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonGetter; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt64; - -@SuppressWarnings("UnusedVariable") -public class FilecoinMessage { - - @JsonProperty("Version") - private final UInt64 version; - - @JsonProperty("To") - private final String to; - - @JsonProperty("From") - private final String from; - - @JsonProperty("Nonce") - private final UInt64 nonce; - - @JsonProperty("Value") - private final BigInteger value; - - @JsonProperty("GasFeeCap") - private final BigInteger gasFeeCap; - - @JsonProperty("GasPremium") - private final BigInteger gasPremium; - - @JsonProperty("GasLimit") - private final long gasLimit; - - @JsonProperty("Method") - private final UInt64 method; - - @JsonProperty("Params") - private final Bytes params; - - @JsonCreator - public FilecoinMessage( - final @JsonProperty("Version") UInt64 version, - final @JsonProperty("To") String to, - final @JsonProperty("From") String from, - final @JsonProperty("Nonce") UInt64 nonce, - final @JsonProperty("Value") BigInteger value, - final @JsonProperty("GasLimit") long gasLimit, - final @JsonProperty("GasFeeCap") BigInteger gasFeeCap, - final @JsonProperty("GasPremium") BigInteger gasPremium, - final @JsonProperty("Method") UInt64 method, - final @JsonProperty("Params") String params) { - this.version = version; - this.to = to; - this.from = from; - this.nonce = nonce; - this.value = value; - this.gasLimit = gasLimit; - this.gasFeeCap = gasFeeCap; - this.gasPremium = gasPremium; - - this.method = method; - this.params = Bytes.fromBase64String(params); - } - - public UInt64 getVersion() { - return version; - } - - public String getTo() { - return to; - } - - public String getFrom() { - return from; - } - - public UInt64 getNonce() { - return nonce; - } - - public BigInteger getValue() { - return value; - } - - public long getGasLimit() { - return gasLimit; - } - - public BigInteger getGasFeeCap() { - return gasFeeCap; - } - - public BigInteger getGasPremium() { - return gasPremium; - } - - public UInt64 getMethod() { - return method; - } - - @JsonGetter("Params") - public String getParams() { - return params.toBase64String(); - } -} diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinMessageMsgMeta.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinMessageMsgMeta.java deleted file mode 100644 index 56ec64fa1..000000000 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinMessageMsgMeta.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.core.service.jsonrpc; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.tuweni.bytes.Bytes; - -public class FilecoinMessageMsgMeta { - - @JsonProperty("Type") - private final FilecoinMsgMetaType type; - - @JsonProperty("Extra") - private final Bytes extra; - - public FilecoinMessageMsgMeta( - @JsonProperty("Type") final FilecoinMsgMetaType type, - @JsonProperty("Extra") final Bytes extra) { - this.type = type; - this.extra = extra; - } - - public FilecoinMsgMetaType getType() { - return type; - } - - public Bytes getExtra() { - return extra; - } -} diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinMsgMetaType.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinMsgMetaType.java deleted file mode 100644 index fe168cfd3..000000000 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinMsgMetaType.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.core.service.jsonrpc; - -public enum FilecoinMsgMetaType { - UNKNOWN, - MESSAGE, - BLOCK, - DEALPROPOSAL -} diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinSignature.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinSignature.java deleted file mode 100644 index b7a8647c0..000000000 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinSignature.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.core.service.jsonrpc; - -import java.util.Objects; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class FilecoinSignature { - - @JsonProperty("Type") - private final int type; - - @JsonProperty("Data") - private final String data; - - @JsonCreator - public FilecoinSignature( - @JsonProperty("Type") final int type, @JsonProperty("Data") final String data) { - this.type = type; - this.data = data; - } - - public int getType() { - return type; - } - - public String getData() { - return data; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final FilecoinSignature that = (FilecoinSignature) o; - return type == that.type && data.equals(that.data); - } - - @Override - public int hashCode() { - return Objects.hash(type, data); - } -} diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinSignedMessage.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinSignedMessage.java deleted file mode 100644 index a8d987526..000000000 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/FilecoinSignedMessage.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.core.service.jsonrpc; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class FilecoinSignedMessage { - - @JsonProperty("Message") - private final FilecoinMessage message; - - @JsonProperty("Signature") - private final FilecoinSignature signature; - - @JsonCreator - public FilecoinSignedMessage( - final @JsonProperty("Message") FilecoinMessage message, - final @JsonProperty("Signature") FilecoinSignature signature) { - this.message = message; - this.signature = signature; - } - - public FilecoinMessage getMessage() { - return message; - } - - public FilecoinSignature getSignature() { - return signature; - } -} diff --git a/core/src/main/resources/openapi-specs/filecoin/web3signer.yaml b/core/src/main/resources/openapi-specs/filecoin/web3signer.yaml deleted file mode 100644 index dd598c3cc..000000000 --- a/core/src/main/resources/openapi-specs/filecoin/web3signer.yaml +++ /dev/null @@ -1,90 +0,0 @@ -openapi: 3.0.0 -info: - title: 'Web3Signer Filecoin' - description: 'Upcheck' - version: '@VERSION@' - license: - name: 'Apache 2.0' - url: 'http://www.apache.org/licenses/LICENSE-2.0.html' - -servers: - - url: / - - url: http://localhost:9000/ - -paths: - /reload: - post: - tags: - - 'Reload Signer Keys' - summary: 'Reload signer keys asynchronously' - description: 'Reload signer keys asynchronously' - operationId: 'RELOAD' - responses: - '200': - description: 'Call is successful' - '500': - description: 'Internal Web3Signer server error' - /upcheck: - get: - tags: - - 'Server Status' - summary: 'Server Status' - description: 'Web3Signer server status' - operationId: 'UPCHECK' - responses: - '200': - description: 'OK' - content: - text/plain; charset=utf-8: - schema: - type: string - example: 'OK' - '500': - description: 'Internal Web3Signer server error' - /healthcheck: - get: - tags: - - 'Server Health Status' - summary: 'Server Health Status' - description: 'Web3Signer server health status' - operationId: 'HEALTHCHECK' - responses: - '200': - description: 'System is healthy' - content: - application/json: - schema: - "$ref": "#/components/schemas/HealthCheck" - '503': - description: 'At least one procedure is unhealthy' - content: - application/json: - schema: - "$ref": "#/components/schemas/HealthCheck" - -components: - schemas: - HealthCheck: - type: object - properties: - status: - type: string - description: 'health status' - checks: - type: array - description: 'list of status checks' - items: - properties: - id: - type: string - description: 'status id' - status: - type: string - description: 'health status' - outcome: - type: string - description: 'the overall outcome of health check' - -externalDocs: - description: 'Web3Signer User Documentation' - url: 'https://docs.web3signer.consensys.net/' diff --git a/core/src/main/resources/openapi-specs/index.html b/core/src/main/resources/openapi-specs/index.html index c7dc89c0b..e1c00deca 100644 --- a/core/src/main/resources/openapi-specs/index.html +++ b/core/src/main/resources/openapi-specs/index.html @@ -17,7 +17,6 @@ urls: [ {url: "/swagger-ui/eth2/web3signer.yaml", name: "Eth2"}, {url: "/swagger-ui/eth1/web3signer.yaml", name: "Eth1"}, - {url: "/swagger-ui/filecoin/web3signer.yaml", name: "Filecoin"}, ], dom_id: '#swagger-ui', deepLinking: true, diff --git a/core/src/test/java/tech/pegasys/web3signer/core/service/http/SwaggerUIRouteTest.java b/core/src/test/java/tech/pegasys/web3signer/core/service/http/SwaggerUIRouteTest.java index c1a9c0181..1165a03f1 100644 --- a/core/src/test/java/tech/pegasys/web3signer/core/service/http/SwaggerUIRouteTest.java +++ b/core/src/test/java/tech/pegasys/web3signer/core/service/http/SwaggerUIRouteTest.java @@ -52,7 +52,6 @@ void contentsAreLoaded(final Vertx vertx) throws IOException { assertThat(swaggerUIWebRoot).containsKey(Path.of("/swagger-ui")); assertThat(swaggerUIWebRoot).containsKey(Path.of("/swagger-ui/")); assertThat(swaggerUIWebRoot).containsKey(Path.of("/swagger-ui/eth2/web3signer.yaml")); - assertThat(swaggerUIWebRoot).containsKey(Path.of("/swagger-ui/filecoin/web3signer.yaml")); assertThat(swaggerUIWebRoot).containsKey(Path.of("/swagger-ui/eth1/web3signer.yaml")); } } diff --git a/core/src/test/java/tech/pegasys/web3signer/core/util/OpenApiSpecsExtractorTest.java b/core/src/test/java/tech/pegasys/web3signer/core/util/OpenApiSpecsExtractorTest.java index c5204b3bc..21db1c579 100644 --- a/core/src/test/java/tech/pegasys/web3signer/core/util/OpenApiSpecsExtractorTest.java +++ b/core/src/test/java/tech/pegasys/web3signer/core/util/OpenApiSpecsExtractorTest.java @@ -26,8 +26,7 @@ class OpenApiSpecsExtractorTest { @ParameterizedTest - @ValueSource( - strings = {"eth1/web3signer.yaml", "eth2/web3signer.yaml", "filecoin/web3signer.yaml"}) + @ValueSource(strings = {"eth1/web3signer.yaml", "eth2/web3signer.yaml"}) void openapiSpecsAreExtractedAndLoaded(final String spec) throws Exception { final OpenApiSpecsExtractor openApiSpecsExtractor = new OpenApiSpecsExtractor.OpenApiSpecsExtractorBuilder() diff --git a/signing/src/main/java/tech/pegasys/web3signer/signing/FcBlsArtifactSigner.java b/signing/src/main/java/tech/pegasys/web3signer/signing/FcBlsArtifactSigner.java deleted file mode 100644 index 306bad712..000000000 --- a/signing/src/main/java/tech/pegasys/web3signer/signing/FcBlsArtifactSigner.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing; - -import tech.pegasys.teku.bls.BLS; -import tech.pegasys.teku.bls.BLSKeyPair; -import tech.pegasys.teku.bls.BLSSignature; -import tech.pegasys.web3signer.signing.filecoin.FilecoinAddress; -import tech.pegasys.web3signer.signing.filecoin.FilecoinNetwork; - -import java.util.Objects; - -import org.apache.tuweni.bytes.Bytes; - -public class FcBlsArtifactSigner implements ArtifactSigner { - public static final String FC_DST = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_"; - - private final BLSKeyPair keyPair; - private final FilecoinNetwork filecoinNetwork; - - public FcBlsArtifactSigner(final BLSKeyPair keyPair, final FilecoinNetwork filecoinNetwork) { - this.keyPair = keyPair; - this.filecoinNetwork = filecoinNetwork; - } - - @Override - public String getIdentifier() { - return FilecoinAddress.blsAddress(keyPair.getPublicKey().toBytesCompressed()) - .encode(filecoinNetwork); - } - - @Override - public BlsArtifactSignature sign(final Bytes message) { - final BLSSignature blsSignature = BLS.sign(keyPair.getSecretKey(), message, FC_DST); - return new BlsArtifactSignature(blsSignature); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - FcBlsArtifactSigner that = (FcBlsArtifactSigner) o; - return keyPair.equals(that.keyPair); - } - - @Override - public int hashCode() { - return Objects.hash(keyPair); - } -} diff --git a/signing/src/main/java/tech/pegasys/web3signer/signing/FcSecpArtifactSigner.java b/signing/src/main/java/tech/pegasys/web3signer/signing/FcSecpArtifactSigner.java deleted file mode 100644 index d9b1d643c..000000000 --- a/signing/src/main/java/tech/pegasys/web3signer/signing/FcSecpArtifactSigner.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing; - -import tech.pegasys.web3signer.signing.filecoin.FilecoinAddress; -import tech.pegasys.web3signer.signing.filecoin.FilecoinNetwork; -import tech.pegasys.web3signer.signing.secp256k1.Signature; -import tech.pegasys.web3signer.signing.secp256k1.Signer; -import tech.pegasys.web3signer.signing.util.Blake2b; - -import java.math.BigInteger; -import java.security.interfaces.ECPublicKey; -import java.util.Objects; - -import org.apache.tuweni.bytes.Bytes; -import org.bouncycastle.asn1.ASN1Sequence; -import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; - -public class FcSecpArtifactSigner implements ArtifactSigner { - private static final int ETHEREUM_V_OFFSET = 27; - private final Signer signer; - private final FilecoinNetwork filecoinNetwork; - - public FcSecpArtifactSigner(final Signer signer, final FilecoinNetwork filecoinNetwork) { - this.signer = signer; - this.filecoinNetwork = filecoinNetwork; - } - - @Override - public String getIdentifier() { - final ECPublicKey publicKey = signer.getPublicKey(); - final SubjectPublicKeyInfo subjectPublicKeyInfo = - SubjectPublicKeyInfo.getInstance(ASN1Sequence.getInstance(publicKey.getEncoded())); - final Bytes encodedPublicKey = Bytes.wrap(subjectPublicKeyInfo.getPublicKeyData().getBytes()); - return FilecoinAddress.secpAddress(encodedPublicKey).encode(filecoinNetwork); - } - - @Override - public SecpArtifactSignature sign(final Bytes message) { - final Bytes dataHash = Blake2b.sum256(message); - final Signature ethSignature = signer.sign(dataHash.toArray()); - - // signer performs an Ethereum signing - thus the "V" value is 27 or 28 (not 0 or 1). - final Signature fcSignature = - new Signature( - ethSignature.getV().subtract(BigInteger.valueOf(ETHEREUM_V_OFFSET)), - ethSignature.getR(), - ethSignature.getS()); - - return new SecpArtifactSignature(fcSignature); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - EthSecpArtifactSigner that = (EthSecpArtifactSigner) o; - return getIdentifier().equals(that.getIdentifier()); - } - - @Override - public int hashCode() { - return Objects.hash(getIdentifier()); - } -} diff --git a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinAddress.java b/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinAddress.java deleted file mode 100644 index 77a068be5..000000000 --- a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinAddress.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing.filecoin; - -import static tech.pegasys.web3signer.signing.filecoin.FilecoinProtocol.BLS; -import static tech.pegasys.web3signer.signing.filecoin.FilecoinProtocol.ID; -import static tech.pegasys.web3signer.signing.filecoin.FilecoinProtocol.SECP256K1; - -import tech.pegasys.web3signer.signing.filecoin.exceptions.InvalidAddressChecksumException; -import tech.pegasys.web3signer.signing.filecoin.exceptions.InvalidAddressLengthException; -import tech.pegasys.web3signer.signing.filecoin.exceptions.InvalidAddressPayloadException; -import tech.pegasys.web3signer.signing.filecoin.exceptions.InvalidFilecoinProtocolException; -import tech.pegasys.web3signer.signing.util.Blake2b; -import tech.pegasys.web3signer.signing.util.ByteUtils; - -import java.math.BigInteger; - -import com.google.common.io.BaseEncoding; -import org.apache.tuweni.bytes.Bytes; - -public class FilecoinAddress { - - private static final int CHECKSUM_BYTE_SIZE = 4; - private static final BaseEncoding BASE_32_ENCODING = - BaseEncoding.base32().lowerCase().omitPadding(); - private final FilecoinProtocol protocol; - private final Bytes payload; - - public static FilecoinAddress blsAddress(final Bytes publicKey) { - return new FilecoinAddress(BLS, publicKey); - } - - public static FilecoinAddress secpAddress(final Bytes publicKey) { - return new FilecoinAddress(SECP256K1, Blake2b.sum160(publicKey)); - } - - public static FilecoinAddress fromString(final String address) { - return decode(address); - } - - private FilecoinAddress(final FilecoinProtocol protocol, final Bytes payload) { - this.protocol = protocol; - this.payload = payload; - } - - public Bytes getPayload() { - return payload; - } - - public FilecoinProtocol getProtocol() { - return protocol; - } - - public String encode(final FilecoinNetwork network) { - if (protocol == ID) { - final String payload = ByteUtils.fromUVariant(this.payload).toString(); - return network.getNetworkValue() + protocol.getAddrValue() + payload; - } else { - return network.getNetworkValue() - + protocol.getAddrValue() - + BASE_32_ENCODING.encode(Bytes.concatenate(payload, checksum(this)).toArrayUnsafe()); - } - } - - public static FilecoinAddress decode(final String address) { - if (address == null || address.length() < 3) { - throw new InvalidAddressLengthException(); - } - - FilecoinNetwork.findByNetworkValue(address.substring(0, 1)); - final FilecoinProtocol protocol = FilecoinProtocol.findByAddrValue(address.substring(1, 2)); - - final String rawPayload = address.substring(2); - - if (protocol == ID) { - final Bytes payload = ByteUtils.putUVariant(new BigInteger(rawPayload)); - return new FilecoinAddress(protocol, payload); - } else { - - if (!BASE_32_ENCODING.canDecode(rawPayload)) { - throw new InvalidAddressPayloadException(); - } - } - final Bytes value = Bytes.wrap(BASE_32_ENCODING.decode(rawPayload)); - final Bytes payload = value.slice(0, value.size() - CHECKSUM_BYTE_SIZE); - final Bytes checksum = value.slice(value.size() - CHECKSUM_BYTE_SIZE); - final FilecoinAddress filecoinAddress = new FilecoinAddress(protocol, payload); - if (!validateChecksum(filecoinAddress, checksum)) { - throw new InvalidAddressChecksumException(); - } - return filecoinAddress; - } - - private static Bytes checksum(final FilecoinAddress address) { - try { - final Integer protocolValue = Integer.valueOf(address.protocol.getAddrValue()); - return Blake2b.sum32(Bytes.concatenate(Bytes.of(protocolValue), address.getPayload())); - } catch (NumberFormatException nfe) { - throw new InvalidFilecoinProtocolException(); - } - } - - public static boolean validateChecksum( - final FilecoinAddress address, final Bytes expectedChecksum) { - final Bytes checksum = checksum(address); - return expectedChecksum.equals(checksum); - } -} diff --git a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinNetwork.java b/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinNetwork.java deleted file mode 100644 index 7902d0fb9..000000000 --- a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinNetwork.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing.filecoin; - -import tech.pegasys.web3signer.signing.filecoin.exceptions.InvalidFilecoinNetworkException; - -import java.util.Arrays; - -public enum FilecoinNetwork { - MAINNET("f"), - TESTNET("t"); - - private final String networkValue; - - FilecoinNetwork(final String addrValue) { - this.networkValue = addrValue; - } - - public String getNetworkValue() { - return networkValue; - } - - public static FilecoinNetwork findByNetworkValue(final String networkValue) { - return Arrays.stream(values()) - .filter(p -> p.networkValue.equals(networkValue)) - .findFirst() - .orElseThrow(InvalidFilecoinNetworkException::new); - } -} diff --git a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinProtocol.java b/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinProtocol.java deleted file mode 100644 index 52667d707..000000000 --- a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinProtocol.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing.filecoin; - -import tech.pegasys.web3signer.signing.filecoin.exceptions.InvalidFilecoinProtocolException; - -import java.util.Arrays; - -public enum FilecoinProtocol { - ID("0"), - SECP256K1("1"), - ACTOR("2"), - BLS("3"); - - private final String addrValue; - - FilecoinProtocol(final String addrValue) { - this.addrValue = addrValue; - } - - public String getAddrValue() { - return addrValue; - } - - public static FilecoinProtocol findByAddrValue(final String addrValue) { - return Arrays.stream(values()) - .filter(p -> p.addrValue.equals(addrValue)) - .findFirst() - .orElseThrow(InvalidFilecoinProtocolException::new); - } -} diff --git a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinVerify.java b/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinVerify.java deleted file mode 100644 index 5ac24202f..000000000 --- a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/FilecoinVerify.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing.filecoin; - -import static tech.pegasys.web3signer.signing.FcBlsArtifactSigner.FC_DST; - -import tech.pegasys.teku.bls.BLS; -import tech.pegasys.teku.bls.BLSPublicKey; -import tech.pegasys.web3signer.signing.BlsArtifactSignature; -import tech.pegasys.web3signer.signing.SecpArtifactSignature; -import tech.pegasys.web3signer.signing.secp256k1.Signature; -import tech.pegasys.web3signer.signing.util.Blake2b; - -import java.math.BigInteger; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes48; -import org.web3j.crypto.ECDSASignature; -import org.web3j.crypto.Sign; -import org.web3j.utils.Numeric; - -public class FilecoinVerify { - private static final Logger LOG = LogManager.getLogger(); - - public static boolean verify( - final FilecoinAddress address, - final Bytes message, - final BlsArtifactSignature artifactSignature) { - final BLSPublicKey blsPublicKey = - BLSPublicKey.fromBytesCompressed(Bytes48.wrap(address.getPayload())); - return BLS.verify(blsPublicKey, message, artifactSignature.getSignatureData(), FC_DST); - } - - public static boolean verify( - final FilecoinAddress address, - final Bytes message, - final SecpArtifactSignature artifactSignature) { - final byte[] digest = Blake2b.sum256(message).toArrayUnsafe(); - final BigInteger signaturePublicKey = recoverSignature(artifactSignature, digest); - if (signaturePublicKey == null) { - LOG.error("Unable to recover public key from signature"); - return false; - } else { - final Bytes publicKeyBytes = - Bytes.concatenate( - Bytes.of(0x4), Bytes.wrap(Numeric.toBytesPadded(signaturePublicKey, 64))); - final FilecoinAddress filecoinAddress = FilecoinAddress.secpAddress(publicKeyBytes); - return address.getPayload().equals(filecoinAddress.getPayload()); - } - } - - private static BigInteger recoverSignature( - final SecpArtifactSignature artifactSignature, final byte[] digest) { - final Signature signatureData = artifactSignature.getSignatureData(); - final ECDSASignature signature = new ECDSASignature(signatureData.getR(), signatureData.getS()); - final ECDSASignature canonicalSignature = signature.toCanonicalised(); - final int recId = signatureData.getV().intValue(); - return Sign.recoverFromSignature(recId, canonicalSignature, digest); - } -} diff --git a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/FilecoinSignerNotFoundException.java b/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/FilecoinSignerNotFoundException.java deleted file mode 100644 index f622f730c..000000000 --- a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/FilecoinSignerNotFoundException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing.filecoin.exceptions; - -import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; - -@JsonRpcError(code = -32700, message = FilecoinSignerNotFoundException.MESSAGE) -public class FilecoinSignerNotFoundException extends RuntimeException { - static final String MESSAGE = "No keys associated with supplied address"; - - public FilecoinSignerNotFoundException() { - super(MESSAGE); - } -} diff --git a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidAddressChecksumException.java b/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidAddressChecksumException.java deleted file mode 100644 index 5159a0c86..000000000 --- a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidAddressChecksumException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing.filecoin.exceptions; - -import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; - -@JsonRpcError(code = -32700, message = InvalidAddressChecksumException.MESSAGE) -public class InvalidAddressChecksumException extends RuntimeException { - static final String MESSAGE = "Filecoin address checksum doesn't match"; - - public InvalidAddressChecksumException() { - super(MESSAGE); - } -} diff --git a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidAddressLengthException.java b/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidAddressLengthException.java deleted file mode 100644 index c4692befa..000000000 --- a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidAddressLengthException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing.filecoin.exceptions; - -import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; - -@JsonRpcError(code = -32700, message = InvalidAddressLengthException.MESSAGE) -public class InvalidAddressLengthException extends RuntimeException { - static final String MESSAGE = "Invalid Address length"; - - public InvalidAddressLengthException() { - super(MESSAGE); - } -} diff --git a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidAddressPayloadException.java b/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidAddressPayloadException.java deleted file mode 100644 index dc9fd991d..000000000 --- a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidAddressPayloadException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing.filecoin.exceptions; - -import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; - -@JsonRpcError(code = -32700, message = InvalidAddressPayloadException.MESSAGE) -public class InvalidAddressPayloadException extends RuntimeException { - static final String MESSAGE = "Invalid payload must be base32 encoded"; - - public InvalidAddressPayloadException() { - super(MESSAGE); - } -} diff --git a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidFilecoinNetworkException.java b/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidFilecoinNetworkException.java deleted file mode 100644 index ba1a7cda0..000000000 --- a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidFilecoinNetworkException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing.filecoin.exceptions; - -import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; - -@JsonRpcError(code = -32700, message = InvalidFilecoinNetworkException.MESSAGE) -public class InvalidFilecoinNetworkException extends RuntimeException { - static final String MESSAGE = "Unknown Filecoin network"; - - public InvalidFilecoinNetworkException() { - super(MESSAGE); - } -} diff --git a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidFilecoinProtocolException.java b/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidFilecoinProtocolException.java deleted file mode 100644 index 119daccf2..000000000 --- a/signing/src/main/java/tech/pegasys/web3signer/signing/filecoin/exceptions/InvalidFilecoinProtocolException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing.filecoin.exceptions; - -import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; - -@JsonRpcError(code = -32700, message = InvalidFilecoinProtocolException.MESSAGE) -public class InvalidFilecoinProtocolException extends RuntimeException { - static final String MESSAGE = "Unknown Filecoin protocol"; - - public InvalidFilecoinProtocolException() { - super(MESSAGE); - } -} diff --git a/signing/src/test/java/tech/pegasys/web3signer/signing/FcBlsArtifactSignerTest.java b/signing/src/test/java/tech/pegasys/web3signer/signing/FcBlsArtifactSignerTest.java deleted file mode 100644 index c82bf0716..000000000 --- a/signing/src/test/java/tech/pegasys/web3signer/signing/FcBlsArtifactSignerTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing; - -import static org.assertj.core.api.Assertions.assertThat; - -import tech.pegasys.teku.bls.BLSKeyPair; -import tech.pegasys.teku.bls.BLSSecretKey; -import tech.pegasys.web3signer.signing.filecoin.FilecoinNetwork; - -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; - -class FcBlsArtifactSignerTest { - private static final String FC_BLS_PRIVATE_KEY = "z38sVnSEnswoEHFC9e4g/aPk96c1NvXt425UKv/tKz0="; - - private FcBlsArtifactSigner fcBlsArtifactSigner; - - @BeforeEach - public void setup() { - final Bytes fcPrivateKey = Bytes.fromBase64String(FC_BLS_PRIVATE_KEY); - // Filecoin private keys are serialised in little endian so must convert to big endian - final Bytes32 privateKey = Bytes32.wrap(fcPrivateKey.reverse()); - final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(privateKey)); - fcBlsArtifactSigner = new FcBlsArtifactSigner(keyPair, FilecoinNetwork.TESTNET); - } - - @Test - void identifierReturnsBlsAddress() { - final String identifier = fcBlsArtifactSigner.getIdentifier(); - final String expectedBlsAddress = - "t3sjhgtrk5fdio52k5lzanh7yy4mj4rqbiowd6odddzprrxejgbjbl2irr3gmpbf7epigf45oy7asljj3v3lva"; - assertThat(identifier).isEqualTo(expectedBlsAddress); - } - - @ParameterizedTest - @CsvSource({ - "'',qqsXe9+kDAGOh8uKmI6+oGN90ydJ0jRELvxvf2VwAd+g3WRKT/bi65RlhiGTrzzCFP4gY0BiAMe3+ghInVFLs1CXBcYGol+RiPoFUew7UZ6ON1zq5Tjhs5F2vWFj1qt8", - "NDI=,p/LeJS8KPzuOco2qpqjhvJxFrA5qj++LpeVoActWkDRQTLhuGsnwAvY1kluQ6PntAqISjvR/RU0kzgkR38F8Hm5NuNPsu9/BEiU+IQheNeD7OoG8THq4OuZMbISg7uR/" - }) - void signsData(final String message, final String expectedSignature) { - final BlsArtifactSignature signature = - fcBlsArtifactSigner.sign(Bytes.fromBase64String(message)); - assertThat(signature).isInstanceOf(BlsArtifactSignature.class); - assertThat(signature.getSignatureData().toBytesCompressed().toBase64String()) - .isEqualTo(expectedSignature); - } -} diff --git a/signing/src/test/java/tech/pegasys/web3signer/signing/FcSecpArtifactSignerTest.java b/signing/src/test/java/tech/pegasys/web3signer/signing/FcSecpArtifactSignerTest.java deleted file mode 100644 index 0865ba818..000000000 --- a/signing/src/test/java/tech/pegasys/web3signer/signing/FcSecpArtifactSignerTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing; - -import static org.assertj.core.api.Assertions.assertThat; - -import tech.pegasys.web3signer.signing.filecoin.FilecoinNetwork; -import tech.pegasys.web3signer.signing.secp256k1.Signature; -import tech.pegasys.web3signer.signing.secp256k1.filebased.CredentialSigner; -import tech.pegasys.web3signer.signing.util.ByteUtils; - -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; -import org.web3j.crypto.Credentials; - -class FcSecpArtifactSignerTest { - private static final String FC_SECP_PRIVATE_KEY = "WrwTNNmNFDIVDfMQ+dL9UXgKK4p0iYkfXUq5535vsWk="; - - private FcSecpArtifactSigner fcSecpArtifactSigner; - - @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); - } - - @Test - void identifierReturnsSecpAddress() { - final String identifier = fcSecpArtifactSigner.getIdentifier(); - final String expectedAddress = "t1656rklyebnscuzs5dee3zwh2xknlqsy7r2ypxei"; - assertThat(identifier).isEqualTo(expectedAddress); - } - - @ParameterizedTest - @CsvSource({ - "'',E+f4UauYmVPEL7+PUr/GL819Euww2Qy6/WJ2AQd5x8okioQiu8UbhRwUNjtLxw6ukdTBdLKwA3KkkkghqwSgxAA=", - "NDI=,4ZDlbvzXtjFnGAnkmnAXImN7KmE+OdW3KbCn+UIHJwY3hEbodjS0VIVBiPUxRWbhJOMao3Sx7GWb4myEsYouJgA=" - }) - void signsData(final String message, final String expectedSignature) { - final SecpArtifactSignature signature = - fcSecpArtifactSigner.sign(Bytes.fromBase64String(message)); - assertThat(signature).isInstanceOf(SecpArtifactSignature.class); - - final Signature signatureData = signature.getSignatureData(); - final Bytes signatureValue = - Bytes.concatenate( - Bytes32.leftPad(Bytes.wrap(ByteUtils.bigIntegerToBytes(signatureData.getR()))), - Bytes32.leftPad(Bytes.wrap(ByteUtils.bigIntegerToBytes(signatureData.getS()))), - Bytes.wrap(ByteUtils.bigIntegerToBytes(signatureData.getV()))); - assertThat(signatureValue.toBase64String()).isEqualTo(expectedSignature); - } -} diff --git a/signing/src/test/java/tech/pegasys/web3signer/signing/FilecoinAddressTest.java b/signing/src/test/java/tech/pegasys/web3signer/signing/FilecoinAddressTest.java deleted file mode 100644 index f148de50e..000000000 --- a/signing/src/test/java/tech/pegasys/web3signer/signing/FilecoinAddressTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import tech.pegasys.web3signer.signing.filecoin.FilecoinAddress; -import tech.pegasys.web3signer.signing.filecoin.FilecoinNetwork; -import tech.pegasys.web3signer.signing.filecoin.FilecoinProtocol; -import tech.pegasys.web3signer.signing.filecoin.exceptions.InvalidAddressChecksumException; -import tech.pegasys.web3signer.signing.filecoin.exceptions.InvalidAddressLengthException; -import tech.pegasys.web3signer.signing.filecoin.exceptions.InvalidAddressPayloadException; -import tech.pegasys.web3signer.signing.filecoin.exceptions.InvalidFilecoinNetworkException; -import tech.pegasys.web3signer.signing.filecoin.exceptions.InvalidFilecoinProtocolException; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvFileSource; - -class FilecoinAddressTest { - - @ParameterizedTest - @CsvFileSource(resources = "bls_testvectors.csv") - void referenceTestsForBlsAddresses(final String address, final String payload) { - verifyAddress(address, payload, FilecoinProtocol.BLS); - } - - @ParameterizedTest - @CsvFileSource(resources = "secp_testvectors.csv") - void referenceTestsForSecpAddresses(final String address, final String payload) { - verifyAddress(address, payload, FilecoinProtocol.SECP256K1); - } - - @ParameterizedTest - @CsvFileSource(resources = "id_testvectors.csv") - void referenceTestsForIdAddresses(final String address, final String payload) { - verifyAddress(address, payload, FilecoinProtocol.ID); - } - - @ParameterizedTest - @CsvFileSource(resources = "actor_testvectors.csv") - void referenceTestsForActorAddresses(final String address, final String payload) { - verifyAddress(address, payload, FilecoinProtocol.ACTOR); - } - - @Test - void addressWithInvalidChecksumThrowsError() { - assertThatThrownBy(() -> FilecoinAddress.decode("f17uoq6tp427uzv7fztkbsnn64iwotfrristwpr")) - .isInstanceOf(InvalidAddressChecksumException.class) - .hasMessage("Filecoin address checksum doesn't match"); - } - - @Test - void addressWithInvalidNetworkThrowsError() { - assertThatThrownBy(() -> FilecoinAddress.decode("Q17uoq6tp427uzv7fztkbsnn64iwotfrristwpryy")) - .isInstanceOf(InvalidFilecoinNetworkException.class) - .hasMessage("Unknown Filecoin network"); - } - - @Test - void addressWithInvalidProtocolThrowsError() { - assertThatThrownBy(() -> FilecoinAddress.decode("f57uoq6tp427uzv7fztkbsnn64iwotfrristwpryy")) - .isInstanceOf(InvalidFilecoinProtocolException.class) - .hasMessage("Unknown Filecoin protocol"); - } - - @Test - void addressWithInvalidPayloadThrowsError() { - assertThatThrownBy(() -> FilecoinAddress.decode("f17uoq6tp427uzT7fztkbsnn64iwot!rristwpryy")) - .isInstanceOf(InvalidAddressPayloadException.class) - .hasMessage("Invalid payload must be base32 encoded"); - } - - @Test - void addressWithInvalidLengthThrowsError() { - assertThatThrownBy(() -> FilecoinAddress.decode("f1")) - .isInstanceOf(InvalidAddressLengthException.class) - .hasMessage("Invalid Address length"); - } - - private void verifyAddress( - final String address, final String payload, final FilecoinProtocol bls) { - final FilecoinAddress filecoinAddress = FilecoinAddress.fromString(address); - final String expectedPayload = payload.substring(2); - assertThat(filecoinAddress.getPayload().toUnprefixedHexString()).isEqualTo(expectedPayload); - assertThat(filecoinAddress.getProtocol()).isEqualTo(bls); - - String encodedAddress = filecoinAddress.encode(FilecoinNetwork.MAINNET); - assertThat(encodedAddress).isEqualTo(address); - } -} diff --git a/signing/src/test/java/tech/pegasys/web3signer/signing/filecoin/FilecoinVerifyTest.java b/signing/src/test/java/tech/pegasys/web3signer/signing/filecoin/FilecoinVerifyTest.java deleted file mode 100644 index 242aee280..000000000 --- a/signing/src/test/java/tech/pegasys/web3signer/signing/filecoin/FilecoinVerifyTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2020 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.signing.filecoin; - -import static org.assertj.core.api.Assertions.assertThat; - -import tech.pegasys.teku.bls.BLSSignature; -import tech.pegasys.web3signer.signing.BlsArtifactSignature; -import tech.pegasys.web3signer.signing.SecpArtifactSignature; -import tech.pegasys.web3signer.signing.secp256k1.Signature; - -import org.apache.tuweni.bytes.Bytes; -import org.junit.jupiter.api.Test; -import org.web3j.utils.Numeric; - -class FilecoinVerifyTest { - private static final String DATA = "NDI="; - private static final String BLS_SIGNATURE = - "p/LeJS8KPzuOco2qpqjhvJxFrA5qj++LpeVoActWkDRQTLhuGsnwAvY1kluQ6PntAqISjvR/RU0kzgkR38F8Hm5NuNPsu9/BEiU+IQheNeD7OoG8THq4OuZMbISg7uR/"; - private static final String SECP_SIGNATURE = - "4ZDlbvzXtjFnGAnkmnAXImN7KmE+OdW3KbCn+UIHJwY3hEbodjS0VIVBiPUxRWbhJOMao3Sx7GWb4myEsYouJgA="; - - @Test - void verifiesBlsSignatureWasSignedWithKey() { - final Bytes message = Bytes.fromBase64String(DATA); - - final BlsArtifactSignature artifactSignature = - new BlsArtifactSignature( - BLSSignature.fromBytesCompressed(Bytes.fromBase64String(BLS_SIGNATURE))); - final FilecoinAddress filecoinAddress = - FilecoinAddress.fromString( - "t3sjhgtrk5fdio52k5lzanh7yy4mj4rqbiowd6odddzprrxejgbjbl2irr3gmpbf7epigf45oy7asljj3v3lva"); - assertThat(FilecoinVerify.verify(filecoinAddress, message, artifactSignature)).isTrue(); - } - - @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(); - } - - 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()))); - } -}