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

Commit

Permalink
Merge pull request #7 from gnarula/non_secrets
Browse files Browse the repository at this point in the history
Add non_secrets API
  • Loading branch information
jakubkoci committed Feb 7, 2020
2 parents dc302ad + b84e510 commit 09227a6
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 0 deletions.
129 changes: 129 additions & 0 deletions android/src/main/java/com/reactlibrary/IndySdkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.hyperledger.indy.sdk.did.DidResults;
import org.hyperledger.indy.sdk.ledger.Ledger;
import org.hyperledger.indy.sdk.ledger.LedgerResults;
import org.hyperledger.indy.sdk.non_secrets.WalletRecord;
import org.hyperledger.indy.sdk.non_secrets.WalletSearch;
import org.hyperledger.indy.sdk.pairwise.Pairwise;
import org.hyperledger.indy.sdk.pool.Pool;
import org.hyperledger.indy.sdk.wallet.Wallet;
Expand All @@ -52,12 +54,14 @@ public class IndySdkModule extends ReactContextBaseJavaModule {

private Map<Integer, Wallet> walletMap;
private Map<Integer, Pool> poolMap;
private Map<Integer, WalletSearch> searchMap;

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

@Override
Expand Down Expand Up @@ -517,6 +521,131 @@ public void proverGetCredentials(int walletHandle, String filter, Promise promis
}
}

// non_secrets

@ReactMethod
public void addWalletRecord(int walletHandle, String type, String id, String value, String tagsJson, Promise promise) {
try {
Wallet wallet = walletMap.get(walletHandle);
WalletRecord.add(wallet, type, id, value, tagsJson).get();
promise.resolve(null);
} catch (Exception e) {
IndyBridgeRejectResponse rejectResponse = new IndyBridgeRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void updateWalletRecordValue(int walletHandle, String type, String id, String value, Promise promise) {
try {
Wallet wallet = walletMap.get(walletHandle);
WalletRecord.updateValue(wallet, type, id, value).get();
promise.resolve(null);
} catch (Exception e) {
IndyBridgeRejectResponse rejectResponse = new IndyBridgeRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void updateWalletRecordTags(int walletHandle, String type, String id, String tagsJson, Promise promise) {
try {
Wallet wallet = walletMap.get(walletHandle);
WalletRecord.updateTags(wallet, type, id, tagsJson).get();
promise.resolve(null);
} catch (Exception e) {
IndyBridgeRejectResponse rejectResponse = new IndyBridgeRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void addWalletRecordTags(int walletHandle, String type, String id, String tagsJson, Promise promise) {
try {
Wallet wallet = walletMap.get(walletHandle);
WalletRecord.addTags(wallet, type, id, tagsJson).get();
promise.resolve(null);
} catch (Exception e) {
IndyBridgeRejectResponse rejectResponse = new IndyBridgeRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void deleteWalletRecordTags(int walletHandle, String type, String id, String tagNamesJson, Promise promise) {
try {
Wallet wallet = walletMap.get(walletHandle);
WalletRecord.deleteTags(wallet, type, id, tagNamesJson).get();
promise.resolve(null);
} catch (Exception e) {
IndyBridgeRejectResponse rejectResponse = new IndyBridgeRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void deleteWalletRecord(int walletHandle, String type, String id, Promise promise) {
try {
Wallet wallet = walletMap.get(walletHandle);
WalletRecord.delete(wallet, type, id).get();
promise.resolve(null);
} catch (Exception e) {
IndyBridgeRejectResponse rejectResponse = new IndyBridgeRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void getWalletRecord(int walletHandle, String type, String id, String optionsJson, Promise promise) {
try {
Wallet wallet = walletMap.get(walletHandle);
String record = WalletRecord.get(wallet, type, id, optionsJson).get();
promise.resolve(record);
} catch (Exception e) {
IndyBridgeRejectResponse rejectResponse = new IndyBridgeRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void openWalletSearch(int walletHandle, String type, String queryJson, String optionsJson, Promise promise) {
try {
Wallet wallet = walletMap.get(walletHandle);
WalletSearch search = WalletSearch.open(wallet, type, queryJson, optionsJson).get();
searchMap.put(search.getSearchHandle(), search);
promise.resolve(search.getSearchHandle());
} catch (Exception e) {
IndyBridgeRejectResponse rejectResponse = new IndyBridgeRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void fetchWalletSearchNextRecords(int walletHandle, int walletSearchHandle, int count, Promise promise) {
try {
Wallet wallet = walletMap.get(walletHandle);
WalletSearch search = searchMap.get(walletSearchHandle);
String recordsJson = WalletSearch.searchFetchNextRecords(wallet, search, count).get();
promise.resolve(recordsJson);
} catch (Exception e) {
IndyBridgeRejectResponse rejectResponse = new IndyBridgeRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void closeWalletSearch(int walletSearchHandle, Promise promise) {
try {
WalletSearch search = searchMap.get(walletSearchHandle);
WalletSearch.closeSearch(search);
searchMap.remove(walletSearchHandle);
promise.resolve(null);
} catch (Exception e) {
IndyBridgeRejectResponse rejectResponse = new IndyBridgeRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

class IndyBridgeRejectResponse {
private String code;
private String message;
Expand Down
87 changes: 87 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@ export type Verkey = string
export type WalletHandle = number
export type PoolHandle = number

export type WalletRecord = {
id: string,
type: string,
value: string,
tags: {},
}

export type WalletSearchHandle = number

export type WalletRecrods = {
totalCount?: string,
records?: WalletRecord[],
}

const { IndyBridge } = NativeModules

export default {
Expand Down Expand Up @@ -527,4 +541,77 @@ export default {
}
throw new Error(`Not implemented for platfrom: ${Platform.OS}`)
},

// non_secrets

async addWalletRecord(wh: WalletHandle, type: string, id: string, value: string, tags: {}): Promise<void> {
if (Platform.OS == 'ios') {
throw new Error(`Unsupported platform! ${Platform.OS}`)
}
return IndyBridge.addWalletRecord(wh, type, id, value, JSON.stringify(tags));
},

async updateWalletRecordValue(wh: WalletHandle, type: string, id: string, value: string): Promise<void> {
if (Platform.OS == 'ios') {
throw new Error(`Unsupported platform! ${Platform.OS}`)
}
return IndyBridge.updateWalletRecordValue(wh, type, id, value);
},

async updateWalletRecordTags(wh: WalletHandle, type: string, id: string, tags: {}): Promise<void> {
if (Platform.OS == 'ios') {
throw new Error(`Unsupported platform! ${Platform.OS}`)
}
return IndyBridge.updateWalletRecordTags(wh, type, id, JSON.stringify(tags))
},

async addWalletRecordTags(wh: WalletHandle, type: string, id: string, tags: {}): Promise<void> {
if (Platform.OS == 'ios') {
throw new Error(`Unsupported platform! ${Platform.OS}`)
}
return IndyBridge.addWalletRecordTags(wh, type, id, JSON.stringify(tags))
},

async deleteWalletRecordTags(wh: WalletHandle, type: string, id: string, tagNames: []): Promise<void> {
if (Platform.OS == 'ios') {
throw new Error(`Unsupported platform! ${Platform.OS}`)
}
return IndyBridge.deleteWalletRecordTags(wh, type, id, JSON.stringify(tagNames))
},

async deleteWalletRecord(wh: WalletHandle, type: string, id: string): Promise<void> {
if (Platform.OS == 'ios') {
throw new Error(`Unsupported platform! ${Platform.OS}`)
}
return IndyBridge.deleteWalletRecord(wh, type, id)
},

async getWalletRecord(wh: WalletHandle, type: string, id: string): Promise<WalletRecord> {
if (Platform.OS == 'ios') {
throw new Error(`Unsupported platform! ${Platform.OS}`)
}
return JSON.parse(await IndyBridge.getWalletRecord(wh, type, id))
},

async openWalletSearch(wh: WalletHandle, type: string, query: {}, options: {}): Promise<number> {
if (Platform.OS == 'ios') {
throw new Error(`Unsupported platform! ${Platform.OS}`)
}
return IndyBridge.openWalletSearch(wh, type, JSON.stringify(query), JSON.stringify(options))
},

async fetchWalletSearchNextRecords(wh: WalletHandle, sh: WalletSearchHandle, count: number): Promise<WalletRecords> {
if (Platform.OS == 'ios') {
throw new Error(`Unsupported platform! ${Platform.OS}`)
}
return JSON.parse(await IndyBridge.fetchWalletSearchNextRecords(wh, sh, count))
},

async closeWalletSearch(sh: WalletSearchHandle): Promise<void> {
if (Platform.OS == 'ios') {
throw new Error(`Unsupported platform! ${Platform.OS}`)
}
return IndyBridge.closeWalletSearch(sh)
},

}

0 comments on commit 09227a6

Please sign in to comment.