All pages
Powered by GitBook
1 of 1

Loading...

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

await agent.delete()

DidExchange


async didExchange.acceptOutOfBandInvitation(): DidExchangeRecord

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

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

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

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

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

Gets all didExchange Records

Finds all records that have tags matching the given query.

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

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

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

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

Finds the record associated with the provided Did.

Finds the record whose invitation contained the provided Did.


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

Parses a url encoded invitation into an OutOfBandInvitationMessage.

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

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

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

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

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

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

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

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

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

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


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

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

Accepts the offer associated with the provided credential exchange record.

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

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

Finds all credentials whose exchange state match the provided state.

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

Gets all of the credentialExchangeRecords

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

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


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

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

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.

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.

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


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

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

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

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

Set the default mediator.

Request mediation from the given didExchange connection

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

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

Gets all of the meditation records.

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

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

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


Sends a basic message to another connection

Find basic message record by ID

Get all basic messages

Find all basic messages with matching comments

Find all basic messages from recipient

Find all basic messages that match the role



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


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


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

Swift

onRecordEvent
  • onProofEvent

  • onWebsocketEvent

  • onBasicMessageEvent

  • async didExchange.sendPing(): TrustPingMessage

    async didExchange.returnWhenIsConnected(): DidExchangeStateChangedEvent?

    async didExchange.getAll(): Array[DidExchangeRecord]

    async didExchange.findAllByQuery(): Array[DidExchangeRecord]

    async didExchange.getById(): DidExchangeRecord

    async didExchange.findById(): DidExchangeRecord?

    async didExchange.deleteById(): void

    async didExchange.findAllByOutOfBandId(): Array[DidExchangeRecord]

    async didExchange.findByDid(): DidExchangeRecord?

    async didExchange.findByInvitationDid(): DidExchangeRecord?

    Out Of Band

    async outOfBand.createInvitation(): OutOfBandRecord

    outOfBand.parseInvitation(): OutOfBandInvitationMessage

    async outOfBand.receiveInvitation(): AcceptInvitationResponse

    async outOfBand.receiveImplicitInvitation(): AcceptInvitationResponse

    async outOfBand.acceptInvitation(): AcceptInvitationResponse

    async outOfBand.findByInvitationId(): OutOfBandRecord?

    async outOfBand.findByCreatedInvitationId(): OutOfBandRecord?

    async outOfBand.getAll(): Array[OutOfBandRecord]

    async outOfBand.getAllByQuery(): Array[OutOfBandRecord]

    async outOfBand.getById(): OutOfBandRecord

    async outOfBand.findById(): OutOfBandRecord?

    async outOfBand.deleteById(): void

    Credentials

    async credentials.findAllCredentialsBySchemaId(): Array[CredentialRecord]

    async credentials.proposeCredential(): CredentialExchangeRecord

    async credentials.acceptOffer(): CredentialExchangeRecord

    async credentials.acceptCredential(): CredentialExchangeRecord

    async credentials.findByRecordId(): CredentialExchangeRecord?

    async credentials.findAllByState(): Array[CredentialExchangeRecord]

    async credentials.findAllByStateAndDidExchangeId(): Array[CredentialExchangeRecord]

    async credentials.getAll(): Array[CredentialExchangeRecord]

    async credentials.findByThreadIdAndDidExchangeId(): CredentialExchangeRecord?

    async credentials.getByThreadIdAndDidExchangeId(): CredentialExchangeRecord

    Proofs

    async proofs.autoAcceptProof(): ProofRecord

    async proofs.acceptProof(): ProofRecord

    async proofs.getCredentialsForProofRequest(): PresentationData

    async proofs.autoSelectCredentialsForProofRequest(): PresentationData

    async proofs.getProofRequestsForConnection(): Array[ProofRecord]

    Routing

    async routing.initialize(): void

    async routing.initiateMessagePickup(): void

    async routing.findDefaultMediator(): MediationRecord?

    async routing.discoverMediation(): MediationRecord?

    async routing.setDefaultMediator(): MediationRecord

    async routing.requestMediation(): MediationRecord

    async routing.getByExchangeId(): MediationRecord

    async routing.findByExchangeId(): MediationRecord

    async routing.getMediators(): Array[MediationRecord]

    async routing.findDefaultMediatorExchange(): DidExchangeRecord?

    async routing.provision(): MediationRecord?

    async routing.getRouting(): Routing

    Basic Messaging

    async basicMessages.send(): BasicMessageRecord

    async basicMessages.findById(): BasicMessageRecord

    async basicMessages.getAll(): Array

    async basicMessages.findByComment(): Array[BasicMessageRecord]

    async basicMessages.findByDidExchangeId(): Array[BasicMessageRecord]

    async basicMessages.findByRole(): Array[BasicMessageRecord]

    Events

    React Native

    Kotlin

    Swift

    const didExchangeRecord = await agent.didExchange(
        didExchangeId: String,
        outOfBandId: String,
        routingParam: Routing | undefined // Not available in React Native
    )
    const trustPingMessage = await agent.didExchange.sendPing(
        exchangeId: String,
        responseRequested: Boolean,
        returnRouting: Boolean
    )
    const didExchangeStateChangedEvent: DidExchangeStateChangedEvent? = await agent.didExchange.returnWhenIsConnected(
        didExchangeId: String,
        timeOutMs: Number | Long
    )
    const records: Array<DidExchangeRecord> = await agent.didExchange.getAll()
    const records: Array<DidExchangeRecord> = await agent.didExchange.findAllByQuery(
        query: Query // Record<String, String> in React Native. Malformed Query will throw
    )
    const record = await agent.didExchange.getById(
        didExchangeId: String
    )
    const record: DidExchangeRecord? = await agent.didExchange.findById(
        didExchangeId: String
    )
    await agent.didExchange.deleteById(
        didExchangeId: String
    )
    const records: Array<DidExchangeRecord> = await agent.didExchange.getAllByOutOfBandId(
       outOfBandId: String
    )
    const record: DidExchangeRecord? = await agent.didExchange.findByDid(
        did: String
    )
    const record: DidExchangeRecord? = await agent.didExchange.findByInvitationDid(
        did: String
    )
    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
    )
    const message = agent.outOfBand.parseInvitation(
        invitationUrl: String
    )
    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
    )
    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
    )
    const invitationResponse = await agent.outOfBand.acceptInvitation(
        outOfBand: String,
        autoAcceptConnection: Boolean,
        reuseConnection: Boolean,
        label: String,
        alias: String | null,
        routingParam: Routing | null,
        timeOutMs: Number | undefined
    )
    const record: OutOfBandRecord? = await agent.outOfBand.findByReceivedInvitationId(
        receivedInvitationId: String
    )
    const record: OutOfBandRecord? = await agent.outOfBand.findByCreatedInvitationId(
        createdInvitationId: String
    )
    const records: Array<OutOfBandRecord> = await agent.outOfBand.getAll()
    const records: Array<OutOfBandRecord> = await agent.outOfBand.getAllByQuery(
        query: Query // Record<String, String> in React Native. Malformed Query will throw
    )
    const record = await agent.outOfBand.getById(
        outOfBandId: String
    )
    const record: OutOfBandRecord? = await agent.outOfBand.findById(
        outOfBandId: String
    )
    await agent.outOfBand.deleteById(
        outOfBandId: String
    )
    const records: Array<CredentialRecord> = await agent.credentials.findAllCredentialsBySchemaId(
        schemaId: String
    )
    const record = await agent.credential.proposeCredential(
        didExchangeId: String,
        formatServices: FormatServices,
        autoAcceptCredential: Boolean | undefined,
        comment: String | null | undefined
    )
    const record = await agent.credentials.acceptOffer(
        credentialExchangeId: String,
        autoAcceptCredential: Boolean | undefined,
        comment: String | null | undefined
    )
    const record = agent.credentials.acceptCredential(
        credentialExchangeId: String
    )
    const record: CredentialExchangeRecord? = await agent.credentials.findByRecordId(
        credentialExchangeId: String
    )
    const records: Array<CredentialExchangeRecord> = await agent.credentials.findAllByState(
        state: CredentialState
    )
    const records: Array<CredentialExchangeRecord> = await agent.credentials.findAllByStateAndDidExchangeId(
        state: CredentialState,
        didExchangeId: String
    )
    const records: Array<CredentialExchangeRecord> = await agent.credentials.getAll()
    const record = await agent.credentials.findByThreadIdAndDidExchangeId(
        threadId: String,
        didExchangeId: String | null
    )
    const record = await agent.credentials.getByThreadIdAndDidExchangeId(
        threadId: String,
        didExchangeId: String | null
    )
    const record = await agent.proofs.autoAcceptProof(
        proofId: String,
        exchangeId: String
    )
    const record = await agent.proofs.acceptProof(
        proofData: PresentationData
    )
    const creds = await agent.proofs.getCredentialsForProofRequest(
        proofId: String,
        exchangeId: String,
        nonRevoked: Boolean | undefined
    )
    const creds = await agent.proofs.autoSelectCredentialsForProofRequest(
        proofId: String,
        exchangeId: String,
        nonRevoked: Boolean | undefined
    )
    const records: Array<ProofRecord> = await agent.proofs.getProofRequestsForConnection(
        didExchangeId: String
    )
    await agent.routing.initialize()
    await agent.routing.initiateMessagePickup(
        mediator: MediationRecord | null | undefined // Record id is used in React Native
    )
    const record: MediationRecord? = await agent.routing.findDefaultMediator()
    const record: MediationRecord? = await agent.routing.discoverMediation()
    const record = await agent.routing.setDefaultMediator(
        mediation: MediationRecord | String // Provide the record or the record id. React native only uses Id
    )
    const record = await agent.routing.requestMediation(
        didExchange: DidExchangeRecord | String // Provide the record or the record id. React native only uses Id
    )
    const record = await agent.routing.getByExchangeId(
        exchangeId: String
    )
    const record: MediationRecord? = await agent.routing.findByExchangeId(
        exchangeId: String
    )
    const records: Array<MediationRecord> = await agent.routing.getMediators()
    const record: DidExchangeRecord? = await agent.routing.findDefaultMediatorExchange()
    const record: MediationRecord? = await agent.routing.provision(
        didExchangeRecord: DidExchangeRecord,
        timeOutMs: Number | Long | undefined
    )
    const routing = await agent.routing.getRouting(
        mediatorId: String,
        useDefaultMediator: Boolean | undefined
    )
    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
    )
    const basicMessage = await agent.basicMessages.findById(
        basicMessageRecordId: String // Record ID to be retrieved
    )
    const basicMessages = await agent.basicMessages.getAll()
    const basicMessages = await agent.basicMessages.findByComment(
        comment: String // Comment to search for
    )
    const basicMessages = await agent.basicMessages.findByDidExchangeId(
        didExchangeId: String // Exchange ID to look for
    )
    const basicMessages = await agent.basicMessages.findByRole(
        role: BasicMessageRole // Role to look for
    )
    const remove = agent.events.registerDidExchangeHandler((event) => {
        console.log("Got a didExchange event")
    })
    
    remove() // cancels the event callback
    // 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
    }
    let removeListener = agent.events.onDidExchangeStateChanged { event in
       // Handle DidExchangeStateChangedEvent here
    }
    // Remove listener when no longer needed
    removeListener(nil)