Skip to content

Commit

Permalink
Add support for getAggregateTorusKey
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Mar 12, 2021
1 parent c83e775 commit e1642dc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion torusdirect/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.2.0"
versionName "1.3.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.torusresearch.torusdirect.types.TorusKey;
import org.torusresearch.torusdirect.types.TorusLoginResponse;
import org.torusresearch.torusdirect.types.TorusNetwork;
import org.torusresearch.torusdirect.types.TorusSubVerifierInfo;
import org.torusresearch.torusdirect.types.TorusVerifierResponse;
import org.torusresearch.torusdirect.types.TorusVerifierUnionResponse;
import org.torusresearch.torusdirect.utils.Helpers;
Expand Down Expand Up @@ -158,4 +159,29 @@ public CompletableFuture<TorusKey> getTorusKey(String verifier, String verifierI
return new TorusKey(shareResponse.getPrivKey(), shareResponse.getEthAddress());
});
}

public CompletableFuture<TorusKey> getAggregateTorusKey(String verifier, String verifierId, TorusSubVerifierInfo[] subVerifierInfoArray) {
AggregateVerifierParams aggregateVerifierParams = new AggregateVerifierParams();
aggregateVerifierParams.setVerify_params(new AggregateVerifierParams.VerifierParams[subVerifierInfoArray.length]);
aggregateVerifierParams.setSub_verifier_ids(new String[subVerifierInfoArray.length]);
List<String> aggregateIdTokenSeeds = new ArrayList<>();
String aggregateVerifierId = "";
for (int i = 0; i < subVerifierInfoArray.length; i++) {
TorusSubVerifierInfo userInfo = subVerifierInfoArray[i];
String finalToken = userInfo.getIdToken();
aggregateVerifierParams.setVerifyParamItem(new AggregateVerifierParams.VerifierParams(verifierId, finalToken), i);
aggregateVerifierParams.setSubVerifierIdItem(userInfo.getVerifier(), i);
aggregateIdTokenSeeds.add(finalToken);
aggregateVerifierId = verifierId;
}
Collections.sort(aggregateIdTokenSeeds);
String aggregateTokenString = TextUtils.join(Character.toString((char) 29), aggregateIdTokenSeeds);
String aggregateIdToken = Hash.sha3String(aggregateTokenString).substring(2);
aggregateVerifierParams.setVerifier_id(aggregateVerifierId);
HashMap<String, Object> aggregateVerifierParamsHashMap = new HashMap<>();
aggregateVerifierParamsHashMap.put("verify_params", aggregateVerifierParams.getVerify_params());
aggregateVerifierParamsHashMap.put("sub_verifier_ids", aggregateVerifierParams.getSub_verifier_ids());
aggregateVerifierParamsHashMap.put("verifier_id", aggregateVerifierParams.getVerifier_id());
return this.getTorusKey(verifier, aggregateVerifierId, aggregateVerifierParamsHashMap, aggregateIdToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.torusresearch.torusdirect.types;

public class TorusSubVerifierInfo {
String verifier;
String idToken;

public TorusSubVerifierInfo(String verifier, String idToken) {
this.verifier = verifier;
this.idToken = idToken;
}

public String getVerifier() {
return verifier;
}

public String getIdToken() {
return idToken;
}
}

0 comments on commit e1642dc

Please sign in to comment.