Skip to content
This repository was archived by the owner on Aug 17, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
bracketSpacing: false,
bracketSpacing: true,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
semi: false,
};
95 changes: 54 additions & 41 deletions android/src/main/java/com/arnimasdk/ArnimaSdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@

public class ArnimaSdk extends ReactContextBaseJavaModule {

private final ReactApplicationContext reactContext;
public static final int PROTOCOL_VERSION = 2;
private final ReactApplicationContext reactContext;
private final Map<Integer, Wallet> walletMap;
private Map<Integer, CredentialsSearchForProofReq> credentialSearchMap;
private final Map<Integer, CredentialsSearchForProofReq> credentialSearchMap;
private int credentialSearchIterator = 0;

public ArnimaSdk(ReactApplicationContext reactContext) {
Expand Down Expand Up @@ -126,7 +126,6 @@ protected void onPreExecute() {
}
}


@ReactMethod
public void openInitWallet(String walletConfig, String walletCredentials, Promise promise) {
Wallet wallet = null;
Expand Down Expand Up @@ -162,6 +161,19 @@ public Wallet openWallet(String walletConfig, String walletCredentials, Promise
}
}

@ReactMethod
public Wallet getWalletHandle(Promise promise) {
Wallet wallet = null;
try {
wallet = walletMap.get(1);
} catch (Exception e) {
IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
} finally {
return wallet;
}
}

public Pool openPoolLedger(String poolName, String poolConfig, Promise promise) {
Pool pool = null;
try {
Expand All @@ -173,6 +185,7 @@ public Pool openPoolLedger(String poolName, String poolConfig, Promise promise)
return null;
}
}

public void closePoolLedger(Pool pool) {
try {
pool.closePoolLedger().get();
Expand All @@ -187,10 +200,10 @@ public void closePoolLedger(Pool pool) {

@ReactMethod
public void createAndStoreMyDid(String walletConfig, String walletCredentials, String didJson,
Boolean createMasterSecret, Promise promise) {
Boolean createMasterSecret, Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = openWallet(walletConfig, walletCredentials ,promise);
if (wallet != null) {
DidResults.CreateAndStoreMyDidResult createMyDidResult = Did
.createAndStoreMyDid(wallet, didJson).get();
Expand All @@ -200,7 +213,7 @@ public void createAndStoreMyDid(String walletConfig, String walletCredentials, S
JSONObject config = new JSONObject(walletConfig);
response.pushString(myDid);
response.pushString(myVerkey);
if ((Boolean) createMasterSecret) {
if (createMasterSecret) {
String outputMasterSecretId = Anoncreds
.proverCreateMasterSecret(wallet, config.get("id").toString()).get();
response.pushString(outputMasterSecretId);
Expand All @@ -214,11 +227,11 @@ public void createAndStoreMyDid(String walletConfig, String walletCredentials, S
}

@ReactMethod
public void addWalletRecord(String walletConfig, String walletCredentials, String recordType, String id, String value, String tags,
public void addWalletRecord(String recordType, String id, String value, String tags,
Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
WalletRecord.add(wallet, recordType, id, value, tags).get();
promise.resolve("true");
Expand All @@ -230,17 +243,17 @@ public void addWalletRecord(String walletConfig, String walletCredentials, Strin
}

@ReactMethod
public void updateWalletRecord(String walletConfig, String walletCredentials, String recordType, String id, String value, String tags,
public void updateWalletRecord(String recordType, String id, String value, String tags,
Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
WalletRecord.updateValue(wallet, recordType, id, value)
.get();

if (!tags.equalsIgnoreCase("{}")) {
WalletRecord.updateTags(wallet, recordType, id,tags);
WalletRecord.updateTags(wallet, recordType, id, tags);
}
promise.resolve("true");
}
Expand All @@ -251,11 +264,11 @@ public void updateWalletRecord(String walletConfig, String walletCredentials, St
}

@ReactMethod
public void deleteWalletRecord(String walletConfig, String walletCredentials, String recordType, String id,
public void deleteWalletRecord(String recordType, String id,
Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
WalletRecord.delete(wallet, recordType, id)
.get();
Expand All @@ -268,11 +281,11 @@ public void deleteWalletRecord(String walletConfig, String walletCredentials, St
}

@ReactMethod
public void getWalletRecordFromQuery(String walletConfig, String walletCredentials, String recordType, String query,
Promise promise) {
public void getWalletRecordFromQuery(String recordType, String query,
Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
WalletSearch search = WalletSearch.open(wallet, recordType, query, "{\"retrieveTags\":true,\"retrieveType \":true, \"retrieveType\": true }")
.get();
Expand All @@ -287,15 +300,15 @@ public void getWalletRecordFromQuery(String walletConfig, String walletCredentia
}

@ReactMethod
public void packMessage(String walletConfig, String walletCredentials, ReadableArray message,
public void packMessage(ReadableArray message,
ReadableArray receiverKeyArray, String senderVk, Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
byte[] buffer = readableArrayToBuffer((ReadableArray) message);
byte[] buffer = readableArrayToBuffer(message);

ReadableArray receiverKeys = (ReadableArray) receiverKeyArray;
ReadableArray receiverKeys = receiverKeyArray;
String[] keys = new String[receiverKeys.size()];
for (int i = 0; i < receiverKeys.size(); i++) {
keys[i] = receiverKeys.getString(i);
Expand All @@ -318,10 +331,10 @@ public void packMessage(String walletConfig, String walletCredentials, ReadableA
}

@ReactMethod
public void unpackMessage(String walletConfig, String walletCredentials, ReadableArray jwe, Promise promise) {
public void unpackMessage(ReadableArray jwe, Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
byte[] buffer = readableArrayToBuffer(jwe);
byte[] res = Crypto.unpackMessage(wallet, buffer).get();
Expand All @@ -339,11 +352,11 @@ public void unpackMessage(String walletConfig, String walletCredentials, Readabl
}

@ReactMethod
public void cryptoSign(String walletConfig, String walletCredentials, String signerVk, ReadableArray messageRaw,
public void cryptoSign(String signerVk, ReadableArray messageRaw,
Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
byte[] messageBuf = readableArrayToBuffer(messageRaw);
byte[] signature = Crypto.cryptoSign(wallet, signerVk, messageBuf).get();
Expand All @@ -360,11 +373,11 @@ public void cryptoSign(String walletConfig, String walletCredentials, String sig
}

@ReactMethod
public void cryptoVerify(String walletConfig, String walletCredentials, String signerVk, ReadableArray messageRaw,
public void cryptoVerify(String signerVk, ReadableArray messageRaw,
ReadableArray signatureRaw, Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
byte[] messageBuf = readableArrayToBuffer(messageRaw);
byte[] sigBuf = readableArrayToBuffer(signatureRaw);
Expand All @@ -378,11 +391,11 @@ public void cryptoVerify(String walletConfig, String walletCredentials, String s
}

@ReactMethod
public void proverCreateCredentialReq(String walletConfig, String walletCredentials, String proverDid,
public void proverCreateCredentialReq(String proverDid,
String credentialOfferJson, String credentialDefJson, String masterSecret, Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
AnoncredsResults.ProverCreateCredentialRequestResult credentialRequestResult = Anoncreds
.proverCreateCredentialReq(wallet, proverDid, credentialOfferJson,
Expand All @@ -400,14 +413,14 @@ public void proverCreateCredentialReq(String walletConfig, String walletCredenti
}

@ReactMethod
public void proverStoreCredential(String walletConfig, String walletCredentials, String credId,
public void proverStoreCredential(String credId,
String credReqMetadataJson, String credJson, String credDefJson, String revRegDefJson, Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
String newCredId = Anoncreds.proverStoreCredential(wallet, credId, credReqMetadataJson,
credJson, credDefJson, revRegDefJson).get();
String newCredId = Anoncreds.proverStoreCredential(wallet, credId, credReqMetadataJson,
credJson, credDefJson, revRegDefJson).get();
promise.resolve(newCredId);
}
} catch (Exception e) {
Expand Down Expand Up @@ -467,10 +480,10 @@ public void verifierVerifyProof(String proofRequest, String proof,
}

@ReactMethod
public void proverGetCredentials(String walletConfig, String walletCredentials, String filter, Promise promise) {
public void proverGetCredentials(String filter, Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
String credentials = Anoncreds.proverGetCredentials(wallet, filter).get();
promise.resolve(credentials);
Expand All @@ -482,10 +495,10 @@ public void proverGetCredentials(String walletConfig, String walletCredentials,
}

@ReactMethod
public void proverGetCredential(String walletConfig, String walletCredentials, String credId, Promise promise) {
public void proverGetCredential(String credId, Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
String credential = Anoncreds.proverGetCredential(wallet, credId).get();
promise.resolve(credential);
Expand All @@ -503,7 +516,7 @@ public void getCredDef(String submitterDid, String id, String poolName, String p
String credDefRequest = Ledger.buildGetCredDefRequest(submitterDid, id).get();
pool = openPoolLedger(poolName, poolConfig, promise);
if (pool != null) {
String credDefResponse = Ledger.submitRequest(pool, credDefRequest).get();
String credDefResponse = Ledger.submitRequest(pool, credDefRequest).get();

LedgerResults.ParseResponseResult responseResult = Ledger.parseGetCredDefResponse(credDefResponse).get();
promise.resolve(responseResult.getObjectJson());
Expand Down Expand Up @@ -577,11 +590,11 @@ public void getSchemasJson(String poolName, String poolConfig, String submitterD
}

@ReactMethod
public void proverCreateProof(String walletConfig, String walletCredentials, String proofRequest,
public void proverCreateProof(String proofRequest,
String requestedCredentials, String masterSecret, String schemas, String credentialDefs, String revocObject, Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
String cred_proof = Anoncreds.proverCreateProof(wallet, proofRequest,
String.valueOf(requestedCredentials), masterSecret, String.valueOf(schemas),
Expand Down Expand Up @@ -753,10 +766,10 @@ public void createRevocationStateObject(String poolName, String poolConfig, Stri
}

@ReactMethod
public void exportWallet(String walletConfig, String walletCredentials, String config, Promise promise) {
public void exportWallet(String config, Promise promise) {
Wallet wallet = null;
try {
wallet = openWallet(walletConfig, walletCredentials, promise);
wallet = getWalletHandle(promise);
if (wallet != null) {
Wallet.exportWallet(wallet, config).get();
promise.resolve("true");
Expand Down
Loading