diff --git a/android/src/main/java/com/reactlibrary/IndySdkModule.java b/android/src/main/java/com/reactlibrary/IndySdkModule.java index ca82ea4..37ae90f 100644 --- a/android/src/main/java/com/reactlibrary/IndySdkModule.java +++ b/android/src/main/java/com/reactlibrary/IndySdkModule.java @@ -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; @@ -62,6 +63,10 @@ public class IndySdkModule extends ReactContextBaseJavaModule { private Map walletMap; private Map poolMap; private Map searchMap; + private Map credentialSearchMap; + + // Java wrapper does not expose credentialSearchHandle + private int credentialSearchIterator = 0; public IndySdkModule(ReactApplicationContext reactContext) { super(reactContext); @@ -69,6 +74,7 @@ public IndySdkModule(ReactApplicationContext reactContext) { this.walletMap = new ConcurrentHashMap<>(); this.poolMap = new ConcurrentHashMap<>(); this.searchMap = new ConcurrentHashMap<>(); + this.credentialSearchMap = new ConcurrentHashMap<>(); } @Override @@ -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; diff --git a/src/index.js b/src/index.js index 9703c0b..2760f30 100644 --- a/src/index.js +++ b/src/index.js @@ -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,