Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Nov 24, 2020
2 parents ecb855d + ca64330 commit c5bbaef
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/org/torusresearch/torusutils/TorusUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import com.google.gson.Gson;
import java8.util.concurrent.CompletableFuture;

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.*;
Expand Down Expand Up @@ -51,7 +55,6 @@ public static void setAPIKey(String apiKey) {
APIUtils.setApiKey(apiKey);
}


// public static void main(String[] args) {
// String[] endpoints = {"https://lrc-test-13-a.torusnode.com/jrpc", "https://lrc-test-13-b.torusnffode.com/jrpc", "https://lrc-test-13-c.torusnode.com/jrpc", "https://lrc-test-13-d.torusnode.com/jrpc", "https://lrc-test-13-e.torusnode.com/jrpc"};
// TorusNodePub[] nodePubKeys = {
Expand Down Expand Up @@ -360,9 +363,15 @@ CompletableFuture<TorusPublicKey> _getPublicAddress(String[] endpoints, TorusNod
return null;
}
BigInteger metadataNonce = this.getMetadata(new MetadataPubKey(verifierLookupItem.getPub_key_X(), verifierLookupItem.getPub_key_Y())).join();
String pubKey = Utils.padLeft(verifierLookupItem.getPub_key_X(), '0', 64) + Utils.padLeft(verifierLookupItem.getPub_key_Y(), '0', 64);
ECKeyPair metadataKeyPair = ECKeyPair.create(metadataNonce);
String finalPubKey = new BigInteger(pubKey, 16).add(metadataKeyPair.getPublicKey()).toString(16);
// String pubKey = Utils.padLeft(verifierLookupItem.getPub_key_X(), '0', 64) + Utils.padLeft(verifierLookupItem.getPub_key_Y(), '0', 64);

// curve point addition
ECNamedCurveParameterSpec curve = ECNamedCurveTable.getParameterSpec("secp256k1");
ECPoint metadataPoint = curve.getG().multiply(metadataNonce);
ECPoint rawPoint = curve.getCurve().createPoint(new BigInteger(verifierLookupItem.getPub_key_X(), 16), new BigInteger(verifierLookupItem.getPub_key_Y(), 16));
ECPoint finalPoint = rawPoint.add(metadataPoint).normalize();
String finalPubKey = Utils.padLeft(finalPoint.getAffineXCoord().toString(), '0', 64) + Utils.padLeft(finalPoint.getAffineYCoord().toString(), '0', 64);

String address = Keys.toChecksumAddress(Hash.sha3(finalPubKey).substring(64 - 38));
if (!isExtended) {
completableFuture.complete(new TorusPublicKey(address));
Expand Down

0 comments on commit c5bbaef

Please sign in to comment.