> For the complete documentation index, see [llms.txt](https://docs.indicio.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.indicio.tech/developer/mobile-solutions/mobile-sdk/credentials.md).

# Credentials

Depending on the configuration of the Agent that has been created, credentials will be auto-accepted and added to the wallet or they will have to be manually accepted. Credentials are generally offered by an external Agent upon connection or other business action; in some rare cases the receiving Agent will request a credential.

If credentials are not auto accepted, you can use the credential events to determine when a credential has been offered.

{% hint style="info" %}
The issuer typically offers the credential. In some configurations the Agent may auto-accept; otherwise present offers to the user for manual acceptance.
{% endhint %}

{% stepper %}
{% step %}

### Accepting an offered credential

The below code accepts the offer coming from an external issuing Agent. The issuer will then send a credential issuance message that needs final confirmation before the credential is saved and the issuer is notified of completion of issuance.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val credEvents = agent.events.getCredentialEvents()!! // Assuming agent initialized normally

val offers = credEvents.events.filter { 
    it.credentialExchangeRecord.state == CredentialState.OfferReceived
}

offers.onEach{
    // present to user
    if(userAccept)
        agent.credentials.acceptOffer(it.credentialExchangeRecord.id)
}.collect()
```

{% endtab %}

{% tab title="React Native" %}

```typescript
agent.events.registerCredentialHandler((event) => {
    if(event.credentialExchangeRecord.state === CredentialState.OfferReceived)
        // Present to user somehow
        if(userAccept)
            await agent.credentials.acceptOffer(event.credentialExchangeRecord.id)
})
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

### Confirming receipt of the issued credential

After the issuer sends the credential issuance message, your Agent must confirm that it accepts the issued credential. This second confirmation ensures the credential you were offered matches what you actually received. Accepting notifies the issuing Agent that the credential has been stored and the transaction should be recorded on the ledger.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val receivedCredentials = credEvents.events.filter{
    it.credentialExchangeRecord.state == CredentialState.CredentialReceived
}

receivedCredentials.onEach{
    val attributes = it.credentialExchangeRecord.attributes        

    // User reviews the attributes of the credential
    if(userAccept)
        agent.credentials.acceptCredential(it.credentialExchangeRecord.id)
    else
        agent.credentials.rejectCredential(it.credentialExchangeRecord.id)
}.collect()
```

{% endtab %}

{% tab title="React Native" %}

```typescript
agent.events.registerCredentialHandler((event) => {
    const attributes = event.credentialExchangeRecord.attributes
    // Have user review credential
    if(userAccept)
        await agent.credentials.acceptCredential(event.credentialExchangeRecord.id)
    else 
        await agent.credentials.rejectCredential(event.credentialExchangeRecord.id)
})
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

### Accessing stored credentials

Once the credential has been accepted it is stored in the wallet. The credentials module on the Agent has several accessor functions to get credential exchange records. The records have the previewed attributes and after being accepted will have a populated credential attribute that contains information about the accepted credential (for example: credential definition id or schema id).

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val record = agent.credentials.findByRecordId("Some id")
```

{% endtab %}

{% tab title="React Native" %}

```typescript
const record = await agent.credential.findByRecordId("Some id")
```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.indicio.tech/developer/mobile-solutions/mobile-sdk/credentials.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
