Skip to content
This repository has been archived by the owner on Aug 3, 2021. It is now read-only.

Commit

Permalink
added java wrapper functionailty for prover search credentials (#42)
Browse files Browse the repository at this point in the history
Signed-off-by: blu3beri <berend@animo.id>
  • Loading branch information
berendsliedrecht authored Mar 10, 2021
1 parent 909c92f commit 427db88
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
45 changes: 45 additions & 0 deletions android/src/main/java/com/reactlibrary/IndySdkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.hyperledger.indy.sdk.pairwise.Pairwise;
import org.hyperledger.indy.sdk.pool.Pool;
import org.hyperledger.indy.sdk.wallet.Wallet;
import org.hyperledger.indy.sdk.anoncreds.CredentialsSearchForProofReq;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -62,13 +63,18 @@ public class IndySdkModule extends ReactContextBaseJavaModule {
private Map<Integer, Wallet> walletMap;
private Map<Integer, Pool> poolMap;
private Map<Integer, WalletSearch> searchMap;
private Map<Integer, CredentialsSearchForProofReq> credentialSearchMap;

// Java wrapper does not expose credentialSearchHandle
private int credentialSearchIterator = 0;

public IndySdkModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
this.walletMap = new ConcurrentHashMap<>();
this.poolMap = new ConcurrentHashMap<>();
this.searchMap = new ConcurrentHashMap<>();
this.credentialSearchMap = new ConcurrentHashMap<>();
}

@Override
Expand Down Expand Up @@ -884,6 +890,45 @@ public void closeWalletSearch(int walletSearchHandle, Promise promise) {
}
}

@ReactMethod
public void proverSearchCredentialsForProofReq(int walletHandle, String proofRequest, String extraQuery, Promise promise) {
try {
int searchHandle = credentialSearchIterator++;
Wallet wallet = walletMap.get(walletHandle);
CredentialsSearchForProofReq search = CredentialsSearchForProofReq.open(wallet, proofRequest, extraQuery).get();
credentialSearchMap.put(searchHandle, search);
promise.resolve(searchHandle);
} catch (Exception e) {
IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void proverFetchCredentialsForProofReq(int searchHandle, String itemReferent, int count, Promise promise) {
try {
CredentialsSearchForProofReq search = credentialSearchMap.get(searchHandle);
String recordsJson = search.fetchNextCredentials(itemReferent, count).get();
promise.resolve(recordsJson);
} catch (Exception e) {
IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void proverCloseCredentialsSearchForProofReq(int searchHandle, Promise promise) {
try {
CredentialsSearchForProofReq search = credentialSearchMap.get(searchHandle);
search.close();
credentialSearchMap.remove(searchHandle);
promise.resolve(null);
} catch (Exception e) {
IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

class IndySdkRejectResponse {
private String name = "IndyError";
private int indyCode;
Expand Down
25 changes: 25 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,31 @@ const indy = {
return JSON.parse(await IndySdk.proverGetCredentialsForProofReq(wh, JSON.stringify(proofRequest)))
},

async proverSearchCredentialsForProofReq(wh: WalletHandle, proofRequest: ProofRequest, extraQuery: {}) {
if (Platform.OS === 'ios') {
throw new Error(`Unsupported operation! Platform: ${Platform.OS}`)
}
return await IndySdk.proverSearchCredentialsForProofReq(
wh,
JSON.stringify(proofRequest),
JSON.stringify(extraQuery)
)
},

async proverFetchCredentialsForProofReq(sh: number, itemReferent: string, count: number) {
if (Platform.OS === 'ios') {
throw new Error(`Unsupported operation! Platform: ${Platform.OS}`)
}
return JSON.parse(await IndySdk.proverFetchCredentialsForProofReq(sh, itemReferent, count))
},

async proverCloseCredentialsSearchForProofReq(sh: number) {
if (Platform.OS === 'ios') {
throw new Error(`Unsupported operation! Platform: ${Platform.OS}`)
}
return await IndySdk.proverCloseCredentialsSearchForProofReq(sh)
},

async proverCreateProof(
wh: WalletHandle,
proofReq: ProofRequest,
Expand Down

0 comments on commit 427db88

Please sign in to comment.