nextStage

suspend fun nextStage()(source)

Proceeds to the next stage of the credential issuance process.

If the current stage is PROPOSE:

  • If propose is null, sets the stage to REFUSED and returns.

If the current stage is OFFER:

  • If offer is null, sets the stage to REFUSED and returns.

Based on the current stage, performs the following actions:

  • PROPOSE:

  • Creates an OfferCredential from the proposed credential using the method makeOfferFromProposedCredential().

  • Sends the offer message over the connector's connection using sendMessage().

  • Sets the messageId to the ID of the sent message.

  • OFFER:

  • Creates a RequestCredential from the offer credential using the method makeRequestFromOfferCredential().

  • Sends the request message over the connector's connection using sendMessage().

  • Sets the messageId to the ID of the sent message.

Based on the value of messageId, performs the following actions:

  • If messageId is null, returns.

  • Otherwise, awaits a response message with the specified messageId using awaitMessageResponse(). If no response message is received, returns.

Based on the received response message, performs the following actions:

  • If the response is an IssueCredential message, sets the stage to COMPLETED.

  • If the response is an OfferCredential message, sets the stage to OFFER and assigns the received offer to this.offer.

  • If the response is a RequestCredential message, sets the stage to REQUEST and assigns the received request to this.request.

Throws

If there is an error in processing the messages.