Skip to content

Commit

Permalink
Merge pull request #24 from torusresearch/feat/updates
Browse files Browse the repository at this point in the history
Feat/updates
  • Loading branch information
chaitanyapotti authored Jul 8, 2024
2 parents 38f2f76 + ce9f73c commit b4032fd
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
plugins {
id 'java-library'
id 'maven-publish'
}

apply plugin: 'maven'

group 'org.torusresearch'
version '3.1.2'
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 2 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
37 changes: 32 additions & 5 deletions src/main/java/org/torusresearch/torusutils/TorusUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -94,7 +120,8 @@ private void setupBouncyCastle() {

public CompletableFuture<RetrieveSharesResponse> retrieveShares(String[] endpoints, BigInteger[] indexes, String verifier, HashMap<String, Object> verifierParams, String idToken, HashMap<String, Object> 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<CompletableFuture<String>> promiseArr = new ArrayList<>();
// generate temporary private and public key that is used to secure receive shares
ECKeyPair tmpKey = Keys.createEcKeyPair();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
15 changes: 11 additions & 4 deletions src/test/java/org/torusresearch/torusutilstest/AquaTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
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;
import org.torusresearch.fetchnodedetails.FetchNodeDetails;
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;
Expand All @@ -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;
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
22 changes: 15 additions & 7 deletions src/test/java/org/torusresearch/torusutilstest/CyanTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
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;
import org.torusresearch.fetchnodedetails.FetchNodeDetails;
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;
Expand All @@ -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;
Expand All @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/torusresearch/torusutilstest/MainnetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand All @@ -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")
Expand Down
16 changes: 12 additions & 4 deletions src/test/java/org/torusresearch/torusutilstest/OneKeyTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
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;
import org.torusresearch.fetchnodedetails.FetchNodeDetails;
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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
16 changes: 12 additions & 4 deletions src/test/java/org/torusresearch/torusutilstest/TorusUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
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;
import org.torusresearch.fetchnodedetails.FetchNodeDetails;
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;
Expand All @@ -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;
Expand All @@ -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");
Expand Down

0 comments on commit b4032fd

Please sign in to comment.