---
# System prepended metadata

title: Gadi Mobile Agent

---

# Gadi Mobile Agent
This documentation covers the basic interface of methods which will be exposed by the SDK and can be consumed by the apps which integrate it.

# Requirements
* Android Studio - 3.0 and above.
* Xcode - 10.0 and above.

## Installation
**TODO**

## Method Guide

**NOTE** - Below guide for methods is not platform specific

**1 init(context);-> Void**
---
The init() method is triggered once before any other methods are get called.
It initialise Realm (just once per application) and create database for app.

**Example**
```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
 GadiAgentModule.init(context);
```


**2. createDigitalAddress( String apiEndpoint, ArrayList<String> userDocuments ) -> String**
---
This method sends an api request to `DAP` to create a digital address for the `Holder`.
This method will return response in `String`

`apiEndpoint`: String - endpoint specifying the route where the holder should request the `DAP` for creation of digital address.
`userDocument`: JSONArray - an array of holder documents to be sent to `DAP` as a post request payload. (**NOTE** Please send the `userDocument` as an empty arraylist i.e, `ArrayList<String> userDocuments=new ArrayList<>();`)

**Example**
```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
 GadiAgentModule.createDigitalAddress(
        "https://dap-service.dev.digitaltrust.net/api/digital-address",
        userDocuments, new NetworkModule.NetworkModuleListener() {
            @Override
            public void createDigitalAddressStatus(String digitalAddress) {
                Log.d(TAG, "DigitalAddress: result: " + digitalAddress);
            }
        }
);
```

**3. saveDigitalAddress(String digitalAddress) -> String**
---
This method saves the digital address generated by `DAP` agent into local database.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
String digitalAddressStatus = GadiAgentModule.saveDigitalAddress(digitalAddress);
```


**4. getDigitalAddress() -> String**
---
This method returns the digital address generated by DAP and saved in local database by createDigitalAddress method.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
String digitalAddress = GadiAgentModule.getDigitalAddress();
Log.d(TAG, "Digital Address: " + digitalAddress);
```

**5. storeCredentials(ArrayList<String> userDocument String tag) -> String**
---
This method saves the user credentials/user document generated by the scan of physical identity (i.e. passport, pan card, driving licence..etc) into the local database-
                                                                                                                                             Realm DB

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
  String storeCredentialsResponse = GadiAgentModule.storeCredentials(jsonObject.toString());
  Log.d(TAG, "storeCredentialsResponse: " + storeCredentialsResponse);
```

**6. getCredentials() -> ArrayList<JSONObject>**
---
This method returns all credentials that saved in local database.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
ArrayList<JSONObject> getAllCredentailResponse = GadiAgentModule.getCredentials();
Log.d(TAG, "Get all Credential: " + getAllCredentailResponse);
```

**7. deleteCredential(String credId) -> String**
---
This method includes an credId ( i.e. credential id) parameter of string type because it just needs an credId to delete a record. 
It fetches an existing Credential from the database that matches with the specified credId and then marks its status as deleted. 
This will delete a Credential from the database.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
String deleteCredentialResponse = GadiAgentModule.deleteCredential(credentialId);
Log.d(TAG, "Delete Credential: " + deleteCredentialResponse);
```
**8. decodeQRcode(String encodedString) -> HashMap<String, String>**
---
This method decodes the values inside qr code and returns details.
In return details, we can also see the token register with the wallet or not.
                                                                         
**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
   GadiAgentModule.decodeQRcode("ENCODED_VALUE", new RegisterWIthHolderListener() {
                @Override
                public void registerStatus(HashMap<String, String> result) {
                    Log.d(TAG, "Decoded Value:: " + result);
                }
            });
```

**9. saveFcmToken(String fcmToken) -> String**
---
This method saves the fcm token generated by `holder` into local database.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
 String saveFcmTokenResponse= GadiAgentModule.saveFcmToken("FCM_TOKEN");
 Log.d(TAG, "saveFcmTokenResponse: " + saveFcmTokenResponse);
```

**10. getFcmToken() -> String**
---
This method returns the fcm token generated by holder and saved in local database by saveFcmToken method.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
 String getFCMTokenResponse= GadiAgentModule.getFcmToken();
 Log.d(TAG, "getFCMTokenResponse: " + getFCMTokenResponse);
```

**11. storeIssuer(JSONObject issuer)-> String**
---
This method stores details of issuer in local DB.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
 String storeIssuerResponse= GadiAgentModule.storeIssuer(issuerDetails);
 Log.d(TAG, "storeIssuerResponse: " + storeIssuerResponse);
```

**12. getIssuers() -> ArrayList<String>**
---
This method returns a list of issuers stored in local DB.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
 ArrayList<String> getIssuers= GadiAgentModule.getIssuers();
 Log.d(TAG, "getIssuers: " + getIssuers);
```

**13. fetchCredentials(String digitalAddress) -> ArrayList<HashMap<String,String>>**
---
This method sends an api request to `Shared Agent` to get list of Credential for the `Holder`.
This method will return response in `ArrayList<HashMap<String,String>>`

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
 GadiAgentModule.fetchCredential(digitalAddress, new FetchCredentialListener() {
  @Override
      Log.d(TAG, "fetchCredentialResponse:result: " + result);
     }
   });
```

**14.getCredentialDetailsFromRecordID(String recordId, String digitalAddress, String endPointUrl) -> JSONObject**
---
recordId: String - recordId will be received in a payload of notification.
digitalAddress: String- digitalAddress will be received in a response of decodeQRcode() method or getDigitalAddress() method.
endPointUrl: String - endPointUrl will be received in a payload of notification as `CREDENTIAL_ENDPOINT`.

This method requests the API to receive credential details. And this will be executed when the holder receives a notification of type as CREDENTIAL_OFFER in notification payload.

The response of this method is credential details that have to pass to storeCredentials() as jSONObject to store credentials in the local DB.

Example

import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
 GadiAgentModule.getCredentialDetailsFromRecordID(recordId, digitalAddress, endPointUrl, new   GetCredentialDetailsListener() {
           @Override
           public void getCredentialDetails(JSONObject result) {
               Log.d(TAG, "getCredentialDetailsFromRecordID: result : " + result);
           }
 });

**15. decodeQRCodeForInvitation(String encodeInvitationLink) -> String**
---
This method decodes the values inside qr code and returns details.
                                                                       
**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
  String invitationLink= GadiAgentModule.decodeQRcodeForInvitation("ENCODED_VALUE");
  Log.d(TAG, "invitationLink: " + invitationLink);
```

**16. acceptConnectionInvitation(String invitationLink, String digitalAddress,int userId) -> JSONObject**
---
`invitationLink`: String- invitationLink will be received in a response of scan QR code.
`digitalAddress`: String- digitalAddress will be received in a response of decodeQRcode() method.
`userId`: int- userId will be received in a response of scan QR code.

This method accepts a connection invitation by using the `Shared Agent` API. And same time store connection in local DB using storeConnection() method.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
   GadiAgentModule.acceptConnectionInvitation(invitationLink, digitalAddress, userId new AcceptInvitationListener() {
           @Override
           public void acceptInvitation(JSONObject result) {
               Log.d(TAG, "acceptConnectionInvitation:result: " + result);
           }
       });
```

**17. storeConnection(HashMap<String, String> connection)-> String**
---
This method stores details of connection in local DB.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
String storeConnectionResponse= GadiAgentModule.storeConnection(connection);
Log.d(TAG, "storeConnectionResponse: " + storeConnectionResponse);
```

**18. getConnections() -> ArrayList<HashMap<String, String>>**
---
This method returns a list of connections stored in local DB.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
ArrayList<HashMap<String, String>> getConnections= GadiAgentModule.getConnections();
Log.d(TAG, "getConnections: " + getConnections);
```

**15. sendConsentForCredentialRequest(String endPointUrl, String recordId, String digitalAddress, boolean isAcceptConsent) -> JSONObject**
---

`endPointUrl`: String - endPointUrl specifying `Shared Agent` API, which will be receiving in a payload of notification as `CONSENT_ENDPOINT` .
`recordId`: String - recordId will be receiving in a payload of notification.
`digitalAddress`: String- digitalAddress will be receiving in a response of decodeQRcode() method.
`isAcceptConsent`: boolean - boolean specifying an accept/decline consent.

This method sends consent to `Shared Agent` for issued Credential for the `Holder`.
This method will return response in `JSONObject`


**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
   GadiAgentModule.sendConsentForCredentialRequest(endPointUrl, recordId, digitalAddress, false, new SendConsentOfferListener() {
            @Override
            public void sendConsentStatus(JSONObject result) {
                Log.d(TAG, "sendConsentStatus: JSONObject: " + result);
            }
        });
```
**23. sendConsentForProofRequest(String endPointUrl, String recordId, String digitalAddress) -> JSONObject**
---

`endPointUrl`: String - endPointUrl specifying `Shared Agent` API, which will be receiving in a payload of notification as `PROOF_REQUEST` .
`recordId`: String - recordId will be receiving in a payload of notification.
`digitalAddress`: String- digitalAddress will be receiving in a response of decodeQRcode() method.

This method sends consent to `Shared Agent` for proof request.
This method will return response in `JSONObject`


**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
   GadiAgentModule.sendConsentForProofRequest(endPointUrl, recordId, digitalAddress, new SendConsentProofListener() {
            @Override
            public void sendConsentProofStatus(JSONObject result) {
                Log.d(TAG, "sendConsentProofStatus:result: " + result);
            }
        });
```

**24. deleteDigitalAddress() -> String**
---
 This will delete a digital address and its related record (i.e credential, connection etc) from the database.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
String deleteDigitalAddressResponse = GadiAgentModule.deleteDigitalAddress();
Log.d(TAG, "Response: " + deleteDigitalAddressResponse);
```
**25. deleteConnection(String connectionId, String digitalAddress) -> String**
---
`connectionId`: String - connectionId which to be deleted.
`digitalAddress`: String- digitalAddress will be received in a response of decodeQRcode() method.

This method sends an api request to `Shared Agent` to delete a connection. Also, delete it from the local database.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
GadiAgentModule.deleteConnection(connectionId, digitalAddress, new DeleteConnectionListener() {
           @Override
           public void deleteConnectionStatus(String result) {
               Log.d(TAG, "deleteConnectionStatus:: " + result);
           }
       });
```
**9. getConnectionInvitation(String endPointUrl, String recordId, String digitalAddress, String orgName, int consent, int allowDuplicate,) -> JSONObject**
---
`endPointUrl`: String - endPointUrl specifying `Shared Agent` API, which will be receiving in a payload of notification as `CONNECTION_REQUEST` .
`recordId`: String - recordId will be receiving in a payload of notification.
`digitalAddress`: String- digitalAddress will be receiving in a response of decodeQRcode() or getDigitalAddress() method.
`orgName`: String - orgName is or will be receiving in a payload of notification.
`consent`: int - int specifying an accept/decline consent. Here, `1` for `accept` a consent and `0` for `decline` a consent.
`allowDuplicate`: int- allowDuplicate will be received. Here, `1` for `allow duplicate` and `0` for `not allow duplicate` .
(**NOTE** Please set a default `1` for `allowDuplicate` )


This method accepts a connection invitation by using the `Shared Agent` API. And same time store connection in local DB using storeConnection() method.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
        GadiAgentModule.getConnectionInvitation(sharedAgentURL, recordId, digitalAddress, orgName, consent, allowDuplicate, new AcceptInvitationListener() {
            @Override
            public void acceptInvitation(JSONObject result) {
                Log.d(TAG, "acceptConnectionInvitation:result: " + result);
            }
        });

```


**9. registerFcmToken(String digitalAddress, String fcmToken) -> JSONObject**
---

`digitalAddress`: String- digitalAddress will be received in a response of decodeQRcode() or getDigitalAddress() method.
`fcmToken`: String - will be received in a response of getFcmToken() method.

This method registers a FCM token by using the `Shared Agent` API. This will help to receive a notification for issue credential, proof verification and etc.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
   GadiAgentModule.registerFcmToken(digitalAddress, fcmToken, new RegisterWIthHolderListener() {
             @Override
             public void registerStatus(JSONObject result) {
                 Log.d(TAG, "Register status:result: " + result);
             }
         });

```

**22. getCreateConnectionInvitation() -> JSONObject**
---

This method creates a connection invitation by using the `Shared Agent` API.
And return an invitation url to accept the connection. 

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
      GadiAgentModule.getCreateConnectionInvitation(new CreateConnectionInvitationListener() {
          @Override
          public void connectionInvitationResponse(JSONObject result) {
            Log.d(TAG, "Response: result: " + result);
                        
         }
   });

```
**23. getProofQuestions() -> JSONArray**
---

This method lists out proof questions by using the `Provider Service` API. 

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
  GadiAgentModule.getProofQuestions(new ProofQuestionsListener() {
            @Override
            public void proofQuestionsResponse(JSONArray result) {
                Log.d(TAG, "Response: " + result);

            }
        });

```

**24. acceptProofConnectionInvitation(String digitalAddress, String invitationUrl, String proofQuestionId) -> JSONObject**
---

`digitalAddress`: String- digitalAddress will be for which we create an invitation.
`invitationUrl`: String - will be received in a response of getCreateConnectionInvitation() method.
`proofQuestionId`: String - It will be `proofQuestionId`  of proof questions received in a response of getProofQuestions() method.

This method accepts proof invitations for selected proof questions.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
            GadiAgentModule.acceptProofConnectionInvitation(digitalAddress, invitationUrl, proofQuestionId, new ProofConnectionInvitationListener() {
                @Override
                public void proofConnectionInvitationResponse(JSONObject result) {
                    Log.d(TAG, "Response: " + result);
                }
            });;

```

**25. getProofStatus(String connectionId) -> JSONObject**
---

`connectionId`: String - will be received in a response of acceptProofConnectionInvitation() method.

This method checks the proof status once the user accepts using acceptProofConnectionInvitation() method. In response there will be an attribute `verified`  which gives a status and  `proofStatus` gives a proof message.


**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
       GadiAgentModule.getProofStatus(connectionId, new ProofStatusListener() {
            @Override
            public void proofStatusResponse(JSONObject result) {
                Log.d(TAG, "Response: result: " + result);
            }
        });

```


**26. getStoredCredentials() -> ArrayList<JSONObject>**
---

This method returns a list of all issued credentials.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
    GadiAgentModule.getStoredCredentials(new GetCredentialsListener() {
        @Override
        public void allCredentialResponse(ArrayList<JSONObject> result) {
             Log.d(TAG, "Response: result: " + result);
         }
    );

```

**27. getStoredConnections() -> ArrayList<JSONObject>**
---

This method returns a list of all issued connections.

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...
     GadiAgentModule.getStoredConnections(new GetConnectionsListener() {
        @Override
        public void allConnectionResponse(ArrayList<JSONObject> result) {
            Log.d(TAG, "Response: result: " + result);
                 
            }
     });

```

**28. deleteCredential(String credentialId) -> String**

---

`credentialId`: String - credentialId which to be deleted.

This method sends an api request to Shared Agent to delete a credential. Also, delete it from the local database.
(**NOTE** - Before execute this method, digital address must be saved using  saveDigitalAddress() )

**Example**

```
import com.digitaltrust.gadiandroidagent.GadiAgentModule;
...

    GadiAgentModule.deleteCredential(credentialId, new DeleteCredentialListener() {
                @Override
                public void deleteCredentialStatus(String result) {
                   Log.d(TAG, "deleteCredentialStatus:: " + result);
               }
    });
    
```    
    
    