2
2
3
3
import com .google .gson .Gson ;
4
4
import java8 .util .concurrent .CompletableFuture ;
5
+ import okhttp3 .internal .http2 .Header ;
5
6
import org .bouncycastle .jce .ECNamedCurveTable ;
6
7
import org .bouncycastle .jce .provider .BouncyCastleProvider ;
7
8
import org .bouncycastle .jce .spec .ECNamedCurveParameterSpec ;
@@ -35,6 +36,7 @@ public class TorusUtils {
35
36
private final BigInteger secp256k1N = new BigInteger ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141" , 16 );
36
37
private final String metadataHost ;
37
38
private final String allowHost ;
39
+ private final String origin ;
38
40
ConcurrentHashMap <String , BigInteger > metadataCache = new ConcurrentHashMap <>();
39
41
ConcurrentHashMap <String , ReentrantReadWriteLock > locks = new ConcurrentHashMap <>();
40
42
@@ -46,9 +48,18 @@ public TorusUtils() {
46
48
this ("https://metadata.tor.us" , "https://signer.tor.us/api/allow" );
47
49
}
48
50
51
+ public TorusUtils (String origin ) {
52
+ this ("https://metadata.tor.us" , "https://signer.tor.us/api/allow" , origin );
53
+ }
54
+
49
55
public TorusUtils (String metadataHost , String allowHost ) {
56
+ this (metadataHost , allowHost , "Custom" );
57
+ }
58
+
59
+ public TorusUtils (String metadataHost , String allowHost , String origin ) {
50
60
this .metadataHost = metadataHost ;
51
61
this .allowHost = allowHost ;
62
+ this .origin = origin ;
52
63
}
53
64
54
65
public static void setAPIKey (String apiKey ) {
@@ -128,9 +139,10 @@ private void setupBouncyCastle() {
128
139
Security .insertProviderAt (new BouncyCastleProvider (), 1 );
129
140
}
130
141
131
- public CompletableFuture <RetrieveSharesResponse > retrieveShares (String [] endpoints , BigInteger [] indexes , String verifier , HashMap <String , Object > verifierParams , String idToken ) throws TorusException {
142
+ public CompletableFuture <RetrieveSharesResponse > retrieveShares (String [] endpoints , BigInteger [] indexes , String verifier ,
143
+ HashMap <String , Object > verifierParams , String idToken , HashMap <String , Object > extraParams ) throws TorusException {
132
144
try {
133
- APIUtils .get (this .allowHost , true ).join ();
145
+ APIUtils .get (this .allowHost , new Header []{ new Header ( "Origin" , this . origin )}, true ).join ();
134
146
List <CompletableFuture <String >> promiseArr = new ArrayList <>();
135
147
// generate temporary private and public key that is used to secure receive shares
136
148
ECKeyPair tmpKey = Keys .createEcKeyPair ();
@@ -156,7 +168,7 @@ public CompletableFuture<RetrieveSharesResponse> retrieveShares(String[] endpoin
156
168
completableFuture .complete (completedRequests );
157
169
return completableFuture ;
158
170
} else {
159
- throw new PredicateFailedException ("insufficient responses" );
171
+ throw new PredicateFailedException ("insufficient responses for commitments " );
160
172
}
161
173
})
162
174
.getCompletableFuture ()
@@ -180,6 +192,9 @@ public CompletableFuture<RetrieveSharesResponse> retrieveShares(String[] endpoin
180
192
verifierParams .put ("idtoken" , idToken );
181
193
verifierParams .put ("nodesignatures" , nodeSignatures );
182
194
verifierParams .put ("verifieridentifier" , verifier );
195
+ if (extraParams != null ) {
196
+ verifierParams .putAll (extraParams );
197
+ }
183
198
List <HashMap <String , Object >> shareRequestItems = new ArrayList <HashMap <String , Object >>() {{
184
199
add (verifierParams );
185
200
}};
@@ -258,7 +273,7 @@ public CompletableFuture<RetrieveSharesResponse> retrieveShares(String[] endpoin
258
273
new BigInteger (derivedPubKeyY , 16 ).compareTo (new BigInteger (thresholdPubKey .getY (), 16 )) == 0
259
274
) {
260
275
privateKey = derivedPrivateKey ;
261
- // ethAddress = "0x" + Hash.sha3(derivedECKeyPair.getPublicKey().toString(16)).substring(64 - 38);
276
+ // ethAddress = "0x" + Hash.sha3(derivedECKeyPair.getPublicKey().toString(16)).substring(64 - 38);
262
277
break ;
263
278
}
264
279
}
@@ -289,6 +304,11 @@ public CompletableFuture<RetrieveSharesResponse> retrieveShares(String[] endpoin
289
304
}
290
305
}
291
306
307
+ public CompletableFuture <RetrieveSharesResponse > retrieveShares (String [] endpoints , BigInteger [] indexes , String verifier ,
308
+ HashMap <String , Object > verifierParams , String idToken ) throws TorusException {
309
+ return this .retrieveShares (endpoints , indexes , verifier , verifierParams , idToken , null );
310
+ }
311
+
292
312
public CompletableFuture <BigInteger > getMetadata (MetadataPubKey data ) {
293
313
Gson gson = new Gson ();
294
314
String metadata = gson .toJson (data , MetadataPubKey .class );
0 commit comments