Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OID4VCI Integration #24

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MobileSdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ android {
}

dependencies {
api("com.spruceid.mobile.sdk.rs:mobilesdkrs:0.0.28")
api("com.spruceid.mobile.sdk.rs:mobilesdkrs:0.0.30")
//noinspection GradleCompatible
implementation("com.android.support:appcompat-v7:28.0.0")
/* Begin UI dependencies */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class BLESessionManager {
this.uuid,
"BLE",
"Central",
sessionData.bleIdent.toByteArray(),
sessionData.bleIdent,
::updateRequestData,
callback
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CredentialsViewModel : ViewModel() {
_uuid.value,
"BLE",
"Central",
_session.value!!.bleIdent.toByteArray(),
_session.value!!.bleIdent,
::updateRequestData,
null
)
Expand Down Expand Up @@ -146,4 +146,4 @@ class CredentialsViewModel : ViewModel() {
throw e
}
}
}
}
81 changes: 81 additions & 0 deletions MobileSdk/src/main/java/com/spruceid/mobile/sdk/OID4VCI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.spruceid.mobile.sdk

import com.spruceid.mobile.sdk.rs.AsyncHttpClient
import com.spruceid.mobile.sdk.rs.HttpRequest
import com.spruceid.mobile.sdk.rs.HttpResponse
import com.spruceid.mobile.sdk.rs.SyncHttpClient
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.BufferedInputStream
import java.io.DataOutputStream
import java.net.URL
import javax.net.ssl.HttpsURLConnection

class Oid4vciSyncHttpClient: SyncHttpClient {
override fun httpClient(request: HttpRequest): HttpResponse {
val connection: HttpsURLConnection = URL(request.url).openConnection() as HttpsURLConnection

connection.requestMethod = request.method
for ((k, v) in request.headers) {
connection.setRequestProperty(k, v)
}
connection.doOutput = true
connection.doInput = true

val wr = DataOutputStream(connection.outputStream)
wr.write(request.body)
wr.flush()
wr.close()

val statusCode = connection.responseCode
val stream = BufferedInputStream(connection.inputStream)
val body = stream.readBytes()
stream.close()

val headers = connection.headerFields.mapValues { it.value.joinToString(",") }

return HttpResponse(
statusCode = statusCode.toUShort(),
headers = headers,
body = body,
)
}
}

class Oid4vciAsyncHttpClient: AsyncHttpClient {
override suspend fun httpClient(request: HttpRequest): HttpResponse {
val connection: HttpsURLConnection =
withContext(Dispatchers.IO) {
URL(request.url).openConnection()
} as HttpsURLConnection

connection.requestMethod = request.method
for ((k, v) in request.headers) {
connection.setRequestProperty(k, v)
}
connection.doOutput = true
connection.doInput = true

val wr = DataOutputStream(connection.outputStream)
withContext(Dispatchers.IO) {
wr.write(request.body)
wr.flush()
wr.close()
}

val statusCode = connection.responseCode
val body: ByteArray
withContext(Dispatchers.IO) {
val stream = BufferedInputStream(connection.inputStream)
body = stream.readBytes()
stream.close()
}
val headers = connection.headerFields.mapValues { it.value.joinToString(",") }

return HttpResponse(
statusCode = statusCode.toUShort(),
headers = headers,
body = body,
)
}
}
Loading
Loading