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

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

await agent.stop()

async agent.delete(): void

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

DidExchange


async didExchange.acceptOutOfBandInvitation(): DidExchangeRecord

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

async didExchange.acceptResponse(): DidExchangeRecord

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

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

async didExchange.sendPing(): TrustPingMessage

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

async didExchange.returnWhenIsConnected(): DidExchangeStateChangedEvent?

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

async didExchange.getAll(): Array[DidExchangeRecord]

Gets all didExchange Records

async didExchange.findAllByQuery(): Array[DidExchangeRecord]

Finds all records that have tags matching the given query.

async didExchange.getById(): DidExchangeRecord

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

async didExchange.findById(): DidExchangeRecord?

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

async didExchange.deleteById(): void

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

async didExchange.findAllByOutOfBandId(): Array[DidExchangeRecord]

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

async didExchange.findByDid(): DidExchangeRecord?

Finds the record associated with the provided Did.

async didExchange.findByInvitationDid(): DidExchangeRecord?

Finds the record whose invitation contained the provided Did.

Out Of Band


async outOfBand.createInvitation(): OutOfBandRecord

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

outOfBand.parseInvitation(): OutOfBandInvitationMessage

Parses a url encoded invitation into an OutOfBandInvitationMessage.

async outOfBand.receiveInvitation(): AcceptInvitationResponse

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

async outOfBand.receiveImplicitInvitation(): AcceptInvitationResponse

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

async outOfBand.acceptInvitation(): AcceptInvitationResponse

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

async outOfBand.findByInvitationId(): OutOfBandRecord?

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

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.

async outOfBand.getAll(): Array[OutOfBandRecord]

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

async outOfBand.getAllByQuery(): Array[OutOfBandRecord]

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

async outOfBand.getById(): OutOfBandRecord

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

async outOfBand.findById(): OutOfBandRecord?

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

async outOfBand.deleteById(): void

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

Credentials


async credentials.findAllCredentialsBySchemaId(): Array[CredentialRecord]

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

async credentials.proposeCredential(): CredentialExchangeRecord

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

async credentials.acceptOffer(): CredentialExchangeRecord

Accepts the offer associated with the provided credential exchange record.

async credentials.acceptCredential(): CredentialExchangeRecord

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

async credentials.findByRecordId(): CredentialExchangeRecord?

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

async credentials.findAllByState(): Array[CredentialExchangeRecord]

Finds all credentials whose exchange state match the provided state.

async credentials.findAllByStateAndDidExchangeId(): Array[CredentialExchangeRecord]

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

async credentials.getAll(): Array[CredentialExchangeRecord]

Gets all of the credentialExchangeRecords

async credentials.findByThreadIdAndDidExchangeId(): CredentialExchangeRecord?

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

async credentials.getByThreadIdAndDidExchangeId(): CredentialExchangeRecord

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

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.

async proofs.acceptProof(): ProofRecord

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

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.

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.

async proofs.getProofRequestsForConnection(): Array[ProofRecord]

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

Routing


async routing.initialize(): void

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

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.

async routing.findDefaultMediator(): MediationRecord?

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

async routing.discoverMediation(): MediationRecord?

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

async routing.setDefaultMediator(): MediationRecord

Set the default mediator.

async routing.requestMediation(): MediationRecord

Request mediation from the given didExchange connection

async routing.getByExchangeId(): MediationRecord

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

async routing.findByExchangeId(): MediationRecord

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

async routing.getMediators(): Array[MediationRecord]

Gets all of the meditation records.

async routing.findDefaultMediatorExchange(): DidExchangeRecord?

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

async routing.provision(): MediationRecord?

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

async routing.getRouting(): Routing

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

Basic Messaging


async basicMessages.send(): BasicMessageRecord

Sends a basic message to another connection

async basicMessages.findById(): BasicMessageRecord

Find basic message record by ID

async basicMessages.getAll(): Array

Get all basic messages

async basicMessages.findByComment(): Array[BasicMessageRecord]

Find all basic messages with matching comments

async basicMessages.findByDidExchangeId(): Array[BasicMessageRecord]

Find all basic messages from recipient

async basicMessages.findByRole(): Array[BasicMessageRecord]

Find all basic messages that match the role

Events


React Native


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

Example:

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:

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

Last updated

Was this helpful?