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 IDval origin = "https://my-liquid-service.com" // Specify the origin of the serviceval client = SignalClient(origin, context, httpClient) // Create the Client
// Display the QR Codeval qrCode = client.qrCode(requestId, BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round))
// Wait for peer to scan the QR Codeval dc = client.peer(requestId, "offer" )
Data Channel
Handling the Datachannel can be done with the foundation.algorand.provider
library.
// AVM Encoderval encoder = foundation.algorand.crypto.avm.Encoder()
// Create a list of transactions that are the msgpack bytes represented as Base64URL stringsval transactionsToSign: List<String> = createTransactions()
// Crete the Paramsval params = SignTransactionsParams( providerId, transactionsToSign)
// Create the Requestval request = RequestMessage("UUID_OF_MESSAGE", "arc0027:sign_transactions:request", params)
// Send the requestdc.send(Base64.UrlSafe.encode(request.toByteArray(EncoderType.CBOR)))
// Handle Response Messagesclient.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 Peerclient.send("Hello World!")