> 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/sdk-reference.md).

# SDK Reference

## Overview

Sudo Typescript syntax is used to express API. Any parameter that could be undefined is optional in Kotlin and React Native, due to limitations with Swift code generation not all Swift function have default parameters when a value is optional and will need to have `nil` provided explicitly. A function using the `await` keyword is async in React Native and Swift and suspend in Kotlin.

## Agent

***

### async agent.start(): void

Starts the agent and connect to default mediator if provided

```typescript
await agent.start(
    timeout: 10_000 // Optional -- time limit in MS to connect to mediator
)
```

### async agent.stop(): void

Stops the agent cleanly so it can be used later

```typescript
await agent.stop()
```

### async agent.delete(): void

Deletes the agent and all data associated with it, essentially resetting the wallet

```typescript
await agent.delete()
```

## DidExchange

***

### async didExchange.acceptOutOfBandInvitation(): DidExchangeRecord

Sends a didExchange request to the agent associate with the provided out of band record

```typescript
const didExchangeRecord = await agent.didExchange.acceptOutOfBandInvitation(
    outOfBandRecord: OutOfBandRecord, // Record id (String) in React Native
    autoAcceptConnection: Boolean | undefined,
    label: String | undefined, 
    alias: String | undefined, 
    routingParam: Routing | undefined // Not available in React Native
)
```

### async didExchange.acceptResponse(): DidExchangeRecord

Completes the didExchange handshake by sending a complete message to agent associated with the provided didExchangeId

```typescript
const didExchangeRecord = await agent.didExchange.acceptResponse(
    didExchangeId: String
)
```

### async didExchange.requestConnection(): DidExchangeRecord

Used when auto accept connection is disabled on the agent. This function is used to complete the started didExchange process once an out of band invitation has been processed and a didExchange record is created but not auto accepted

```typescript
const didExchangeRecord = await agent.didExchange(
    didExchangeId: String,
    outOfBandId: String,
    routingParam: Routing | undefined // Not available in React Native
)
```

### async didExchange.sendPing(): TrustPingMessage

Used to send a trust ping to another agent to ensure we can reach the agent.

```typescript
const trustPingMessage = await agent.didExchange.sendPing(
    exchangeId: String,
    responseRequested: Boolean,
    returnRouting: Boolean
)
```

### async didExchange.returnWhenIsConnected(): DidExchangeStateChangedEvent?

Waits until the provided didExchangeId reaches a state of Done or until the provided timeout is reached.

```typescript
const didExchangeStateChangedEvent: DidExchangeStateChangedEvent? = await agent.didExchange.returnWhenIsConnected(
    didExchangeId: String,
    timeOutMs: Number | Long
)
```

### async didExchange.getAll(): Array\[DidExchangeRecord]

Gets all didExchange Records

```typescript
const records: Array<DidExchangeRecord> = await agent.didExchange.getAll()
```

### async didExchange.findAllByQuery(): Array\[DidExchangeRecord]

Finds all records that have tags matching the given query.

```typescript
const records: Array<DidExchangeRecord> = await agent.didExchange.findAllByQuery(
    query: Query // Record<String, String> in React Native. Malformed Query will throw
)
```

### async didExchange.getById(): DidExchangeRecord

Gets the record with the provided Id or throws if not found.

```typescript
const record = await agent.didExchange.getById(
    didExchangeId: String
)
```

### async didExchange.findById(): DidExchangeRecord?

Finds the record with the given Id or returns null if not found.

```typescript
const record: DidExchangeRecord? = await agent.didExchange.findById(
    didExchangeId: String
)
```

### async didExchange.deleteById(): void

Deletes the record with the given Id or throws if it does not exist.

```typescript
await agent.didExchange.deleteById(
    didExchangeId: String
)
```

### async didExchange.findAllByOutOfBandId(): Array\[DidExchangeRecord]

Finds all records associated with the given out of band Id.

```typescript
const records: Array<DidExchangeRecord> = await agent.didExchange.getAllByOutOfBandId(
   outOfBandId: String
)
```

### async didExchange.findByDid(): DidExchangeRecord?

Finds the record associated with the provided Did.

```typescript
const record: DidExchangeRecord? = await agent.didExchange.findByDid(
    did: String
)
```

### async didExchange.findByInvitationDid(): DidExchangeRecord?

Finds the record whose invitation contained the provided Did.

```typescript
const record: DidExchangeRecord? = await agent.didExchange.findByInvitationDid(
    did: String
)
```

## Out Of Band

***

### async outOfBand.createInvitation(): OutOfBandRecord

Creates an out of band invitation and corresponding out of band record that is returned.

```typescript
const record = await agent.outOfBand.createInvitation(
    label: String | undefined,
    alias: String | undefined,
    goalCode: String | undefined,
    goal: String | undefined,
    handShake: Boolean | undefined,
    messages: Array<BaseMessage> | undefined,
    multiUseInvitation: Boolean | undefined,
    autoAcceptConnection: Boolean | undefined,
    routingParam: Routing | undefined, // Not available in React Native
    appendedAttachment: Array<Attachment> | undefined
)
```

### outOfBand.parseInvitation(): OutOfBandInvitationMessage

Parses a url encoded invitation into an `OutOfBandInvitationMessage`.

```typescript
const message = agent.outOfBand.parseInvitation(
    invitationUrl: String
)
```

### async outOfBand.receiveInvitation(): AcceptInvitationResponse

Processes the provided invitation and potentially starts or completes didExchange protocol.

```typescript
const invitationResponse = await agent.outOfBand.receiveInvitation(
    invitation: OutOfBandInvitationMessage,
    label: String | undefined,
    alias: String | undefined,
    autoAcceptConnection: Boolean | undefined,
    reuseConnection: Boolean | undefined,
    routingParam: Routing | undefined, // Not available in React Native
    acceptInvitationTimeOutMs = Number | Long | undefined
)
```

### async outOfBand.receiveImplicitInvitation(): AcceptInvitationResponse

Processes and invitation where the invitation message is not present and the agent is implicitly invited.

```typescript
const invitationResponse = await agent.outOfBand.receiveImplicitInvitation(
    label: String | undefined,
    alias: String | undefined,
    autoAcceptConnection: Boolean | undefined,
    reuseConnection: Boolean | undefined,
    routingParam: Routing | undefined, // Not available in React Native
    acceptInvitationTimeOutMs: Number | Long | null,
    did: String,
    handShakeProtocol: Array<String> | null
)
```

### async outOfBand.acceptInvitation(): AcceptInvitationResponse

Accepts the invitation of an existing Out of Band record. Not commonly used.

```typescript
const invitationResponse = await agent.outOfBand.acceptInvitation(
    outOfBand: String,
    autoAcceptConnection: Boolean,
    reuseConnection: Boolean,
    label: String,
    alias: String | null,
    routingParam: Routing | null,
    timeOutMs: Number | undefined
)
```

### async outOfBand.findByInvitationId(): OutOfBandRecord?

Finds the out of band record with the corresponding invitation id, or returns null.

```typescript
const record: OutOfBandRecord? = await agent.outOfBand.findByReceivedInvitationId(
    receivedInvitationId: String
)
```

### async outOfBand.findByCreatedInvitationId(): OutOfBandRecord?

Finds the out of band record that corresponds to the invitation with the given id that we have created, or returns null.

```typescript
const record: OutOfBandRecord? = await agent.outOfBand.findByCreatedInvitationId(
    createdInvitationId: String
)
```

### async outOfBand.getAll(): Array\[OutOfBandRecord]

Gets all of the out of band records held by the agent.

```typescript
const records: Array<OutOfBandRecord> = await agent.outOfBand.getAll()
```

### async outOfBand.getAllByQuery(): Array\[OutOfBandRecord]

Gets all out of band records that match the provided query.

```typescript
const records: Array<OutOfBandRecord> = await agent.outOfBand.getAllByQuery(
    query: Query // Record<String, String> in React Native. Malformed Query will throw
)
```

### async outOfBand.getById(): OutOfBandRecord

Get the record with the provided id or throws if not found.

```typescript
const record = await agent.outOfBand.getById(
    outOfBandId: String
)
```

### async outOfBand.findById(): OutOfBandRecord?

Tries to find the record with the given id or returns null.

```typescript
const record: OutOfBandRecord? = await agent.outOfBand.findById(
    outOfBandId: String
)
```

### async outOfBand.deleteById(): void

Deletes the record with the given id or throws if no such record exists.

```typescript
await agent.outOfBand.deleteById(
    outOfBandId: String
)
```

## Credentials

***

### async credentials.findAllCredentialsBySchemaId(): Array\[CredentialRecord]

Finds all credentials whose schema id matches the provided schema id.

```typescript
const records: Array<CredentialRecord> = await agent.credentials.findAllCredentialsBySchemaId(
    schemaId: String
)
```

### async credentials.proposeCredential(): CredentialExchangeRecord

sends a proposal to the connection with the associated didExchangeId that we want the specified credential from them.

```typescript
const record = await agent.credential.proposeCredential(
    didExchangeId: String,
    formatServices: FormatServices,
    autoAcceptCredential: Boolean | undefined,
    comment: String | null | undefined
)
```

### async credentials.acceptOffer(): CredentialExchangeRecord

Accepts the offer associated with the provided credential exchange record.

```typescript
const record = await agent.credentials.acceptOffer(
    credentialExchangeId: String,
    autoAcceptCredential: Boolean | undefined,
    comment: String | null | undefined
)
```

### async credentials.acceptCredential(): CredentialExchangeRecord

Accepts the issue credential and saves it to the agent's wallet.

```typescript
const record = agent.credentials.acceptCredential(
    credentialExchangeId: String
)
```

### async credentials.findByRecordId(): CredentialExchangeRecord?

Tries to find the record with the given id or returns null.

```typescript
const record: CredentialExchangeRecord? = await agent.credentials.findByRecordId(
    credentialExchangeId: String
)
```

### async credentials.findAllByState(): Array\[CredentialExchangeRecord]

Finds all credentials whose exchange state match the provided state.

```typescript
const records: Array<CredentialExchangeRecord> = await agent.credentials.findAllByState(
    state: CredentialState
)
```

### async credentials.findAllByStateAndDidExchangeId(): Array\[CredentialExchangeRecord]

Finds all records whose state matches the given state and came from the connection associated with the given didExchangeId

```typescript
const records: Array<CredentialExchangeRecord> = await agent.credentials.findAllByStateAndDidExchangeId(
    state: CredentialState,
    didExchangeId: String
)
```

### async credentials.getAll(): Array\[CredentialExchangeRecord]

Gets all of the credentialExchangeRecords

```typescript
const records: Array<CredentialExchangeRecord> = await agent.credentials.getAll()
```

### async credentials.findByThreadIdAndDidExchangeId(): CredentialExchangeRecord?

Tries to find the credential exchange record that has matching thread id and didExchange id (optional), or returns null.

```typescript
const record = await agent.credentials.findByThreadIdAndDidExchangeId(
    threadId: String,
    didExchangeId: String | null
)
```

### async credentials.getByThreadIdAndDidExchangeId(): CredentialExchangeRecord

Gets the credential exchange record that has matching thread id and didExchange id (optional). Throws if not records found

```typescript
const record = await agent.credentials.getByThreadIdAndDidExchangeId(
    threadId: String,
    didExchangeId: String | null
)
```

## Proofs

***

### async proofs.autoAcceptProof(): ProofRecord

Attempts to auto accept the proof with the provided id from the provided didExchange connection. Will throw if the proof cannot be satisfied.

```typescript
const record = await agent.proofs.autoAcceptProof(
    proofId: String,
    exchangeId: String
)
```

### async proofs.acceptProof(): ProofRecord

Attempts to accept the given proof using the provided credential selections. Will throw if credential selection is invalid or insufficient.

```typescript
const record = await agent.proofs.acceptProof(
    proofData: PresentationData
)
```

### async proofs.getCredentialsForProofRequest(): PresentationData

Gets a mapping of proof requests to valid credentials for the request that require further selection. Throws if the proof cannot be satisfied with the agent's current credentials.

```typescript
const creds = await agent.proofs.getCredentialsForProofRequest(
    proofId: String,
    exchangeId: String,
    nonRevoked: Boolean | undefined
)
```

### async proofs.autoSelectCredentialsForProofRequest(): PresentationData

Finds credentials that satisfy the proof request and automatically selects valid credentials if there are multiple options.Throws if the proof cannot be satisfied with the agent's current credentials.

```typescript
const creds = await agent.proofs.autoSelectCredentialsForProofRequest(
    proofId: String,
    exchangeId: String,
    nonRevoked: Boolean | undefined
)
```

### async proofs.getProofRequestsForConnection(): Array\[ProofRecord]

Gets the proof records for a given connection from the didExchange id.

```typescript
const records: Array<ProofRecord> = await agent.proofs.getProofRequestsForConnection(
    didExchangeId: String
)
```

## Routing

***

### async routing.initialize(): void

Starts or resumes the mediation to the default mediator. Called in `agent.start` by default.

```typescript
await agent.routing.initialize()
```

### async routing.initiateMessagePickup(): void

Instructs the agent to attempt to pick up messages from the provided mediator record or the default mediator if not provided.

```typescript
await agent.routing.initiateMessagePickup(
    mediator: MediationRecord | null | undefined // Record id is used in React Native
)
```

### async routing.findDefaultMediator(): MediationRecord?

Finds the default mediator if one is set, otherwise returns null.

```typescript
const record: MediationRecord? = await agent.routing.findDefaultMediator()
```

### async routing.discoverMediation(): MediationRecord?

Tries to find the default mediators record. If the default mediator is found but not granted this will throw.

```typescript
const record: MediationRecord? = await agent.routing.discoverMediation()
```

### async routing.setDefaultMediator(): MediationRecord

Set the default mediator.

```typescript
const record = await agent.routing.setDefaultMediator(
    mediation: MediationRecord | String // Provide the record or the record id. React native only uses Id
)
```

### async routing.requestMediation(): MediationRecord

Request mediation from the given didExchange connection

```typescript
const record = await agent.routing.requestMediation(
    didExchange: DidExchangeRecord | String // Provide the record or the record id. React native only uses Id
)
```

### async routing.getByExchangeId(): MediationRecord

Gets the mediation record with the provided didExchange id or throws if not found.

```typescript
const record = await agent.routing.getByExchangeId(
    exchangeId: String
)
```

### async routing.findByExchangeId(): MediationRecord

Tries to find the mediation record with the given didExchange id or returns null if not found.

```typescript
const record: MediationRecord? = await agent.routing.findByExchangeId(
    exchangeId: String
)
```

### async routing.getMediators(): Array\[MediationRecord]

Gets all of the meditation records.

```typescript
const records: Array<MediationRecord> = await agent.routing.getMediators()
```

### async routing.findDefaultMediatorExchange(): DidExchangeRecord?

Tries to find the didExchange record for the default mediator or returns null.

```typescript
const record: DidExchangeRecord? = await agent.routing.findDefaultMediatorExchange()
```

### async routing.provision(): MediationRecord?

Attempts to complete mediation request from the provided didExchange record in the given time.

```typescript
const record: MediationRecord? = await agent.routing.provision(
    didExchangeRecord: DidExchangeRecord,
    timeOutMs: Number | Long | undefined
)
```

### async routing.getRouting(): Routing

Gets the routing for this mediator. Not available in React Native.

```typescript
const routing = await agent.routing.getRouting(
    mediatorId: String,
    useDefaultMediator: Boolean | undefined
)
```

## Basic Messaging

***

### async basicMessages.send(): BasicMessageRecord

Sends a basic message to another connection

```typescript
const sentMessageRecord = await agent.basicMessages.send(
    didExchangeId: String, // ID of target
    content: String, // Message content to be sent
    locale: String = "en", // L10nDecorator version (defaults to "en")
    comment: String? // Comment on message
)
```

### async basicMessages.findById(): BasicMessageRecord

Find basic message record by ID

```typescript
const basicMessage = await agent.basicMessages.findById(
    basicMessageRecordId: String // Record ID to be retrieved
)
```

### async basicMessages.getAll(): Array

Get all basic messages

```typescript
const basicMessages = await agent.basicMessages.getAll()
```

### async basicMessages.findByComment(): Array\[BasicMessageRecord]

Find all basic messages with matching comments

```typescript
const basicMessages = await agent.basicMessages.findByComment(
    comment: String // Comment to search for
)
```

### async basicMessages.findByDidExchangeId(): Array\[BasicMessageRecord]

Find all basic messages from recipient

```typescript
const basicMessages = await agent.basicMessages.findByDidExchangeId(
    didExchangeId: String // Exchange ID to look for
)
```

### async basicMessages.findByRole(): Array\[BasicMessageRecord]

Find all basic messages that match the role

```typescript
const basicMessages = await agent.basicMessages.findByRole(
    role: BasicMessageRole // Role to look for
)
```

## Events

***

#### React Native

***

React Native events all take a call back function and return a function to remove the callback.

Example:

```typescript
const remove = agent.events.registerDidExchangeHandler((event) => {
    console.log("Got a didExchange event")
})

remove() // cancels the event callback
```

The events that can have a handler registered are: `registerDidExchangeHandler`, `registerProofsHandler`, `registerCredentialsHandler`, `registerAgentHandler`, `registerBasicMessageHandler`, `registerRecordHandler`, and `registerWebSocketHandler`

#### Kotlin

***

In Kotlin the events API allows you to directly retrieve the event flow and use Kotlin's flow API. There is also a provided coroutine context on the events object.

Example:

```kotlin
// May not be defined if there were issues with agent initialization
val didExchange: DidExchangeEvents? = agent.events.getDidExchangeEvents()

agent.events.scope.launch {
    didExchange.events.onEach{
        println("Got a didExchange event")
    }.collect() // Make sure to call collect or events will not be processed
}
```

The events that can be retrieved in Kotlin are the following: `getDidExchangeEvents`, `getAgentEvents`, `getCredentialEvents`, `getEventBusEvents`(Record update events), `getMessageEvents`(Events for all messages), `getProofEvents`, `getBasicMessageEvents`, `getTrustPingEvents`, and `getWebSocketEvents`

#### Swift

***

We also wrapped events with the following methods so you can easily listen to events without a third party library or with Objective-C:

* onDidExchangeStateChanged
* onCredentialStateChanged
* onTrustPingEvent
* onAgentEvent
* onRecordEvent
* onProofEvent
* onWebsocketEvent
* onBasicMessageEvent

**Swift**

```swift
let removeListener = agent.events.onDidExchangeStateChanged { event in
   // Handle DidExchangeStateChangedEvent here
}
// Remove listener when no longer needed
removeListener(nil)
```


---

# 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/sdk-reference.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.
