diff --git a/build.gradle b/build.gradle index d8b47bb..c535cc8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ plugins { id 'java-library' + id 'maven-publish' } -apply plugin: 'maven' group 'org.torusresearch' version '3.1.2' diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 87b738c..7454180 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e616a30..ffed3a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Wed Mar 25 11:16:25 SGT 2020 -distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/src/main/java/org/torusresearch/torusutils/TorusUtils.java b/src/main/java/org/torusresearch/torusutils/TorusUtils.java index 374e082..2a651e1 100644 --- a/src/main/java/org/torusresearch/torusutils/TorusUtils.java +++ b/src/main/java/org/torusresearch/torusutils/TorusUtils.java @@ -3,15 +3,39 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonSyntaxException; -import okhttp3.internal.http2.Header; + import org.bouncycastle.jce.ECNamedCurveTable; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; import org.bouncycastle.math.ec.ECPoint; import org.torusresearch.fetchnodedetails.types.TorusNodePub; -import org.torusresearch.torusutils.apis.*; -import org.torusresearch.torusutils.helpers.*; -import org.torusresearch.torusutils.types.*; +import org.torusresearch.torusutils.apis.APIUtils; +import org.torusresearch.torusutils.apis.CommitmentRequestParams; +import org.torusresearch.torusutils.apis.JsonRPCResponse; +import org.torusresearch.torusutils.apis.KeyAssignResult; +import org.torusresearch.torusutils.apis.KeyAssignment; +import org.torusresearch.torusutils.apis.NodeSignature; +import org.torusresearch.torusutils.apis.PubKey; +import org.torusresearch.torusutils.apis.ShareRequestParams; +import org.torusresearch.torusutils.apis.VerifierLookupItem; +import org.torusresearch.torusutils.apis.VerifierLookupRequestResult; +import org.torusresearch.torusutils.helpers.AES256CBC; +import org.torusresearch.torusutils.helpers.Base64; +import org.torusresearch.torusutils.helpers.PredicateFailedException; +import org.torusresearch.torusutils.helpers.Some; +import org.torusresearch.torusutils.helpers.Utils; +import org.torusresearch.torusutils.types.DecryptedShare; +import org.torusresearch.torusutils.types.GetOrSetNonceError; +import org.torusresearch.torusutils.types.GetOrSetNonceResult; +import org.torusresearch.torusutils.types.MetadataParams; +import org.torusresearch.torusutils.types.MetadataPubKey; +import org.torusresearch.torusutils.types.MetadataResponse; +import org.torusresearch.torusutils.types.RetrieveSharesResponse; +import org.torusresearch.torusutils.types.TorusCtorOptions; +import org.torusresearch.torusutils.types.TorusException; +import org.torusresearch.torusutils.types.TorusPublicKey; +import org.torusresearch.torusutils.types.TypeOfUser; +import org.torusresearch.torusutils.types.VerifierArgs; import org.web3j.crypto.ECDSASignature; import org.web3j.crypto.ECKeyPair; import org.web3j.crypto.Hash; @@ -27,6 +51,8 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; +import okhttp3.internal.http2.Header; + public class TorusUtils { public final TorusCtorOptions options; @@ -94,7 +120,8 @@ private void setupBouncyCastle() { public CompletableFuture retrieveShares(String[] endpoints, BigInteger[] indexes, String verifier, HashMap verifierParams, String idToken, HashMap extraParams) { try { - APIUtils.get(this.options.getAllowHost(), new Header[]{new Header("Origin", this.options.getOrigin()), new Header("verifier", verifier), new Header("verifier_id", verifierParams.get("verifier_id").toString()), new Header("network", this.options.getNetwork())}, true).get(); + APIUtils.get(this.options.getAllowHost(), new Header[]{new Header("Origin", this.options.getOrigin()), new Header("verifier", verifier), new Header("verifier_id", verifierParams.get("verifier_id").toString()), new Header("network", this.options.getNetwork()), new Header("clientid", this.options.getClientId()), + new Header("enablegating", "true")}, true).get(); List> promiseArr = new ArrayList<>(); // generate temporary private and public key that is used to secure receive shares ECKeyPair tmpKey = Keys.createEcKeyPair(); diff --git a/src/main/java/org/torusresearch/torusutils/types/TorusCtorOptions.java b/src/main/java/org/torusresearch/torusutils/types/TorusCtorOptions.java index 680be38..b419328 100644 --- a/src/main/java/org/torusresearch/torusutils/types/TorusCtorOptions.java +++ b/src/main/java/org/torusresearch/torusutils/types/TorusCtorOptions.java @@ -13,9 +13,11 @@ public class TorusCtorOptions { private String network = "mainnet"; private boolean legacyNonce = false; + private String clientId; - public TorusCtorOptions(String origin) { + public TorusCtorOptions(String origin, String clientid) { this.origin = origin; + this.clientId = clientid; } public String getNetwork() { @@ -81,4 +83,12 @@ public boolean isLegacyNonce() { public void setLegacyNonce(boolean legacyNonce) { this.legacyNonce = legacyNonce; } + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } } diff --git a/src/test/java/org/torusresearch/torusutilstest/AquaTest.java b/src/test/java/org/torusresearch/torusutilstest/AquaTest.java index 29df470..4239a89 100644 --- a/src/test/java/org/torusresearch/torusutilstest/AquaTest.java +++ b/src/test/java/org/torusresearch/torusutilstest/AquaTest.java @@ -1,6 +1,11 @@ package org.torusresearch.torusutilstest; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import com.auth0.jwt.algorithms.Algorithm; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -8,7 +13,11 @@ import org.torusresearch.fetchnodedetails.types.NodeDetails; import org.torusresearch.fetchnodedetails.types.TorusNetwork; import org.torusresearch.torusutils.TorusUtils; -import org.torusresearch.torusutils.types.*; +import org.torusresearch.torusutils.types.RetrieveSharesResponse; +import org.torusresearch.torusutils.types.TorusCtorOptions; +import org.torusresearch.torusutils.types.TorusException; +import org.torusresearch.torusutils.types.TorusPublicKey; +import org.torusresearch.torusutils.types.VerifierArgs; import org.torusresearch.torusutilstest.utils.JwtUtils; import org.torusresearch.torusutilstest.utils.PemUtils; import org.torusresearch.torusutilstest.utils.VerifyParams; @@ -25,8 +34,6 @@ import java.util.HashMap; import java.util.concurrent.ExecutionException; -import static org.junit.jupiter.api.Assertions.*; - public class AquaTest { static FetchNodeDetails fetchNodeDetails; @@ -43,7 +50,7 @@ public class AquaTest { static void setup() throws ExecutionException, InterruptedException, IOException, NoSuchAlgorithmException, InvalidKeySpecException { System.out.println("Setup Starting"); fetchNodeDetails = new FetchNodeDetails(TorusNetwork.AQUA, FetchNodeDetails.PROXY_ADDRESS_AQUA); - TorusCtorOptions opts = new TorusCtorOptions("Custom"); + TorusCtorOptions opts = new TorusCtorOptions("Custom", "YOUR_CLIENT_ID"); opts.setNetwork("aqua"); opts.setSignerHost("https://signer-polygon.tor.us/api/sign"); opts.setAllowHost("https://signer-polygon.tor.us/api/allow"); diff --git a/src/test/java/org/torusresearch/torusutilstest/CelesteTest.java b/src/test/java/org/torusresearch/torusutilstest/CelesteTest.java index 2646e50..d44a1ce 100644 --- a/src/test/java/org/torusresearch/torusutilstest/CelesteTest.java +++ b/src/test/java/org/torusresearch/torusutilstest/CelesteTest.java @@ -51,7 +51,7 @@ public class CelesteTest { static void setup() throws ExecutionException, InterruptedException, IOException, NoSuchAlgorithmException, InvalidKeySpecException { System.out.println("Setup Startingg"); fetchNodeDetails = new FetchNodeDetails(TorusNetwork.CELESTE, FetchNodeDetails.PROXY_ADDRESS_CELESTE); - TorusCtorOptions opts = new TorusCtorOptions("Custom"); + TorusCtorOptions opts = new TorusCtorOptions("Custom", "YOUR_CLIENT_ID"); opts.setNetwork("celeste"); opts.setSignerHost("https://signer-polygon.tor.us/api/sign"); opts.setAllowHost("https://signer-polygon.tor.us/api/allow"); diff --git a/src/test/java/org/torusresearch/torusutilstest/CyanTest.java b/src/test/java/org/torusresearch/torusutilstest/CyanTest.java index 069dfea..953e0ba 100644 --- a/src/test/java/org/torusresearch/torusutilstest/CyanTest.java +++ b/src/test/java/org/torusresearch/torusutilstest/CyanTest.java @@ -1,6 +1,11 @@ package org.torusresearch.torusutilstest; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import com.auth0.jwt.algorithms.Algorithm; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -8,7 +13,12 @@ import org.torusresearch.fetchnodedetails.types.NodeDetails; import org.torusresearch.fetchnodedetails.types.TorusNetwork; import org.torusresearch.torusutils.TorusUtils; -import org.torusresearch.torusutils.types.*; +import org.torusresearch.torusutils.types.RetrieveSharesResponse; +import org.torusresearch.torusutils.types.TorusCtorOptions; +import org.torusresearch.torusutils.types.TorusException; +import org.torusresearch.torusutils.types.TorusPublicKey; +import org.torusresearch.torusutils.types.TypeOfUser; +import org.torusresearch.torusutils.types.VerifierArgs; import org.torusresearch.torusutilstest.utils.JwtUtils; import org.torusresearch.torusutilstest.utils.PemUtils; import org.torusresearch.torusutilstest.utils.VerifyParams; @@ -25,8 +35,6 @@ import java.util.HashMap; import java.util.concurrent.ExecutionException; -import static org.junit.jupiter.api.Assertions.*; - public class CyanTest { static FetchNodeDetails fetchNodeDetails; @@ -43,7 +51,7 @@ public class CyanTest { static void setup() throws ExecutionException, InterruptedException, IOException, NoSuchAlgorithmException, InvalidKeySpecException { System.out.println("Setup Starting"); fetchNodeDetails = new FetchNodeDetails(TorusNetwork.CYAN, FetchNodeDetails.PROXY_ADDRESS_CYAN); - TorusCtorOptions opts = new TorusCtorOptions("Custom"); + TorusCtorOptions opts = new TorusCtorOptions("Custom", "YOUR_CLIENT_ID"); opts.setNetwork("cyan"); opts.setSignerHost("https://signer-polygon.tor.us/api/sign"); opts.setAllowHost("https://signer-polygon.tor.us/api/allow"); @@ -68,8 +76,8 @@ public void shouldFetchUserTypeAndPublicAddress() throws ExecutionException, Int VerifierArgs args = new VerifierArgs("tkey-google-cyan", TORUS_TEST_EMAIL); NodeDetails nodeDetails = fetchNodeDetails.getNodeDetails(args.getVerifier(), args.getVerifierId()).get(); TorusPublicKey key = torusUtils.getUserTypeAndAddress(nodeDetails.getTorusNodeEndpoints(), nodeDetails.getTorusNodePub(), args).get(); - assertEquals("0xA3767911A84bE6907f26C572bc89426dDdDB2825", key.getAddress()); - assertEquals(TypeOfUser.v1, key.getTypeOfUser()); + assertEquals("0x3507F0d192a44E436B8a6C32a37d57D022861b1a", key.getAddress()); + assertEquals(TypeOfUser.v2, key.getTypeOfUser()); String v2Verifier = "tkey-google-cyan"; // 1/1 user @@ -106,7 +114,7 @@ public void shouldLogin() throws ExecutionException, InterruptedException, Torus System.out.println(retrieveSharesResponse.getPrivKey()); BigInteger requiredPrivateKey = new BigInteger("1e0c955d73e73558f46521da55cc66de7b8fcb56c5b24e851616849b6a1278c8", 16); assert (requiredPrivateKey.equals(retrieveSharesResponse.getPrivKey())); - assertEquals("0x8AA6C8ddCD868873120aA265Fc63E3a2180375BA", retrieveSharesResponse.getEthAddress()); + assertEquals("0xC615aA03Dd8C9b2dc6F7c43cBDfF2c34bBa47Ec9", retrieveSharesResponse.getEthAddress()); } @DisplayName("Aggregate Login test") diff --git a/src/test/java/org/torusresearch/torusutilstest/MainnetTest.java b/src/test/java/org/torusresearch/torusutilstest/MainnetTest.java index 9808c1d..702c069 100644 --- a/src/test/java/org/torusresearch/torusutilstest/MainnetTest.java +++ b/src/test/java/org/torusresearch/torusutilstest/MainnetTest.java @@ -51,7 +51,7 @@ public class MainnetTest { static void setup() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { System.out.println("Setup Starting"); fetchNodeDetails = new FetchNodeDetails(TorusNetwork.MAINNET, FetchNodeDetails.PROXY_ADDRESS_MAINNET); - TorusCtorOptions opts = new TorusCtorOptions("Custom"); + TorusCtorOptions opts = new TorusCtorOptions("Custom", "YOUR_CLIENT_ID"); opts.setNetwork("mainnet"); torusUtils = new TorusUtils(opts); ECPrivateKey privateKey = (ECPrivateKey) PemUtils.readPrivateKeyFromFile("src/test/java/org/torusresearch/torusutilstest/keys/key.pem", "EC"); @@ -75,8 +75,8 @@ public void shouldFetchUserTypeAndPublicAddress() throws ExecutionException, Int VerifierArgs args = new VerifierArgs("google", TORUS_TEST_EMAIL); NodeDetails nodeDetails = fetchNodeDetails.getNodeDetails(args.getVerifier(), args.getVerifierId()).get(); TorusPublicKey key = torusUtils.getUserTypeAndAddress(nodeDetails.getTorusNodeEndpoints(), nodeDetails.getTorusNodePub(), args).get(); - assertEquals("0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A", key.getAddress()); - assertEquals(TypeOfUser.v1, key.getTypeOfUser()); + assertEquals("0xb2e1c3119f8D8E73de7eaF7A535FB39A3Ae98C5E", key.getAddress());//0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A + assertEquals(TypeOfUser.v2, key.getTypeOfUser()); String v2Verifier = "tkey-google"; // 1/1 user @@ -88,8 +88,8 @@ public void shouldFetchUserTypeAndPublicAddress() throws ExecutionException, Int // v1 user String v2nTestEmail = "caspertorus@gmail.com"; TorusPublicKey key3 = torusUtils.getUserTypeAndAddress(nodeDetails.getTorusNodeEndpoints(), nodeDetails.getTorusNodePub(), new VerifierArgs(v2Verifier, v2nTestEmail)).get(); - assertEquals("0x61E52B6e488EC3dD6FDc0F5ed04a62Bb9c6BeF53", key3.getAddress()); - assertEquals(TypeOfUser.v1, key3.getTypeOfUser()); + assertEquals("0x40A4A04fDa1f29a3667152C8830112FBd6A77BDD", key3.getAddress()); + assertEquals(TypeOfUser.v2, key3.getTypeOfUser()); } @DisplayName("Key Assign test") diff --git a/src/test/java/org/torusresearch/torusutilstest/OneKeyTest.java b/src/test/java/org/torusresearch/torusutilstest/OneKeyTest.java index bebffb7..4643305 100644 --- a/src/test/java/org/torusresearch/torusutilstest/OneKeyTest.java +++ b/src/test/java/org/torusresearch/torusutilstest/OneKeyTest.java @@ -1,6 +1,11 @@ package org.torusresearch.torusutilstest; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import com.auth0.jwt.algorithms.Algorithm; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -8,7 +13,12 @@ import org.torusresearch.fetchnodedetails.types.NodeDetails; import org.torusresearch.fetchnodedetails.types.TorusNetwork; import org.torusresearch.torusutils.TorusUtils; -import org.torusresearch.torusutils.types.*; +import org.torusresearch.torusutils.types.RetrieveSharesResponse; +import org.torusresearch.torusutils.types.TorusCtorOptions; +import org.torusresearch.torusutils.types.TorusException; +import org.torusresearch.torusutils.types.TorusPublicKey; +import org.torusresearch.torusutils.types.TypeOfUser; +import org.torusresearch.torusutils.types.VerifierArgs; import org.torusresearch.torusutilstest.utils.JwtUtils; import org.torusresearch.torusutilstest.utils.PemUtils; import org.torusresearch.torusutilstest.utils.VerifyParams; @@ -25,8 +35,6 @@ import java.util.HashMap; import java.util.concurrent.ExecutionException; -import static org.junit.jupiter.api.Assertions.*; - public class OneKeyTest { static FetchNodeDetails fetchNodeDetails; @@ -43,7 +51,7 @@ public class OneKeyTest { static void setup() throws ExecutionException, InterruptedException, IOException, NoSuchAlgorithmException, InvalidKeySpecException { System.out.println("Setup Starting"); fetchNodeDetails = new FetchNodeDetails(TorusNetwork.TESTNET, FetchNodeDetails.PROXY_ADDRESS_TESTNET); - TorusCtorOptions opts = new TorusCtorOptions("Custom"); + TorusCtorOptions opts = new TorusCtorOptions("Custom", "YOUR_CLIENT_ID"); opts.setNetwork("testnet"); opts.setEnableOneKey(true); torusUtils = new TorusUtils(opts); diff --git a/src/test/java/org/torusresearch/torusutilstest/TorusUtilsTest.java b/src/test/java/org/torusresearch/torusutilstest/TorusUtilsTest.java index afe46af..bb93390 100644 --- a/src/test/java/org/torusresearch/torusutilstest/TorusUtilsTest.java +++ b/src/test/java/org/torusresearch/torusutilstest/TorusUtilsTest.java @@ -1,6 +1,11 @@ package org.torusresearch.torusutilstest; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import com.auth0.jwt.algorithms.Algorithm; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -8,7 +13,12 @@ import org.torusresearch.fetchnodedetails.types.NodeDetails; import org.torusresearch.fetchnodedetails.types.TorusNetwork; import org.torusresearch.torusutils.TorusUtils; -import org.torusresearch.torusutils.types.*; +import org.torusresearch.torusutils.types.RetrieveSharesResponse; +import org.torusresearch.torusutils.types.TorusCtorOptions; +import org.torusresearch.torusutils.types.TorusException; +import org.torusresearch.torusutils.types.TorusPublicKey; +import org.torusresearch.torusutils.types.TypeOfUser; +import org.torusresearch.torusutils.types.VerifierArgs; import org.torusresearch.torusutilstest.utils.JwtUtils; import org.torusresearch.torusutilstest.utils.PemUtils; import org.torusresearch.torusutilstest.utils.VerifyParams; @@ -25,8 +35,6 @@ import java.util.HashMap; import java.util.concurrent.ExecutionException; -import static org.junit.jupiter.api.Assertions.*; - public class TorusUtilsTest { static FetchNodeDetails fetchNodeDetails; @@ -43,7 +51,7 @@ public class TorusUtilsTest { static void setup() throws ExecutionException, InterruptedException, IOException, NoSuchAlgorithmException, InvalidKeySpecException { System.out.println("Setup Starting"); fetchNodeDetails = new FetchNodeDetails(TorusNetwork.TESTNET, FetchNodeDetails.PROXY_ADDRESS_TESTNET); - TorusCtorOptions opts = new TorusCtorOptions("Custom"); + TorusCtorOptions opts = new TorusCtorOptions("Custom", "YOUR_CLIENT_ID"); opts.setNetwork("testnet"); torusUtils = new TorusUtils(opts); ECPrivateKey privateKey = (ECPrivateKey) PemUtils.readPrivateKeyFromFile("src/test/java/org/torusresearch/torusutilstest/keys/key.pem", "EC");