Skip to content

Android: Peer Answer

The answer client is used to respond to a remote client’s offer. The remote client will have sent an offer to the answer client, which will then respond with an answer.

Who is this for?

  • Mobile Apps that want to leverage liquid-auth to connect to other mobile apps

Signaling

val requestID = SignalClient.generateRequestId() // Create a new Request ID
val origin = "https://my-liquid-service.com" // Specify the origin of the service
val client = SignalClient(origin, context, httpClient) // Create the Client
// Display the QR Code
val qrCode = client.qrCode(requestId, BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round))
// Wait for peer to scan the QR Code
val dc = client.peer(requestId, "offer" )

Data Channel

Handling the Datachannel can be done with the foundation.algorand.provider library.

Example.kt
// AVM Encoder
val encoder = foundation.algorand.crypto.avm.Encoder()
// Create a list of transactions that are the msgpack bytes represented as Base64URL strings
val transactionsToSign: List<String> = createTransactions()
// Crete the Params
val params = SignTransactionsParams(
providerId, transactionsToSign
)
// Create the Request
val request = RequestMessage("UUID_OF_MESSAGE", "arc0027:sign_transactions:request", params)
// Send the request
dc.send(Base64.UrlSafe.encode(request.toByteArray(EncoderType.CBOR)))
// Handle Response Messages
client.handleDataChannel(dc, {
// Decode Message
val response = encoder.decode<ResponseMessage>(Base64.UrlSafe.decode($it), EncoderType.CBOR)
when (response.reference) {
"arc0027:sign_transactions:response" -> {
// Decode the Result
val result = encoder.decode<SignTransactionsResult>(
encoder.encode(message.params, EncoderType.NONE), EncoderType.NONE
)
// Process the signatures in your project,
// they will be keyed to the original request
processSignatureResult(result)
}
else -> {
throw IllegalArgumentException("Invalid reference: ${message.reference}")
}
}
}, {
Log.d(TAG, "onStateChange($it)")
})
// Send Message to Peer
client.send("Hello World!")