-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat(agent): Implementation Onboarding invitation on Agent #18
Changes from all commits
b81f786
cfe1a42
e576df8
99b0350
7792f13
bf2c421
5e62e75
ee716b0
450e03d
f2d2513
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.iohk.atala.prism.domain.models | ||
|
||
import io.ktor.client.statement.HttpResponse | ||
import io.ktor.client.statement.HttpStatement | ||
import io.ktor.http.HttpMethod | ||
import io.ktor.http.Url | ||
import io.ktor.client.HttpClient as KtorClient | ||
|
||
interface Api { | ||
val client: KtorClient | ||
suspend fun prepareRequest( | ||
httpMethod: HttpMethod, | ||
url: Url, | ||
urlParameters: Map<String, String> = mapOf(), | ||
httpHeaders: Map<String, String> = mapOf(), | ||
body: Any? = null | ||
): HttpStatement | ||
|
||
suspend fun request( | ||
httpMethod: HttpMethod, | ||
url: Url, | ||
urlParameters: Map<String, String> = mapOf(), | ||
httpHeaders: Map<String, String> = mapOf(), | ||
body: Any? = null | ||
): HttpResponse | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,35 +71,60 @@ kotlin { | |
implementation(project(":domain")) | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4") | ||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1") | ||
|
||
implementation("io.ktor:ktor-client-core:2.1.3") | ||
implementation("io.ktor:ktor-client-content-negotiation:2.1.3") | ||
implementation("io.ktor:ktor-serialization-kotlinx-json:2.1.3") | ||
implementation("io.ktor:ktor-client-logging:2.1.3") | ||
} | ||
} | ||
val commonTest by getting { | ||
dependencies { | ||
implementation(project(":domain")) | ||
implementation(kotlin("test")) | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4") | ||
implementation("io.ktor:ktor-client-mock:2.1.3") | ||
} | ||
} | ||
val jvmMain by getting { | ||
dependencies { | ||
implementation("io.ktor:ktor-client-okhttp:2.1.3") | ||
} | ||
} | ||
val jvmMain by getting | ||
val jvmTest by getting { | ||
dependencies { | ||
implementation("junit:junit:4.13.2") | ||
implementation("io.ktor:ktor-client-mock:2.1.3") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need to reimport this one here as you already imported it in 'commonTest' |
||
implementation(kotlin("test")) | ||
} | ||
} | ||
val androidMain by getting { | ||
kotlin { | ||
srcDir("src/jvmMain/kotlin") | ||
} | ||
dependencies { | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4") | ||
implementation("io.ktor:ktor-client-okhttp:2.1.3") | ||
} | ||
} | ||
val androidTest by getting { | ||
dependencies { | ||
implementation("junit:junit:4.13.2") | ||
} | ||
} | ||
val jsMain by getting | ||
val jsMain by getting { | ||
dependencies { | ||
implementation("io.ktor:ktor-client-js:2.1.3") | ||
implementation("io.ktor:ktor-client-content-negotiation:2.1.3") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to reimport it here as it already was imported in 'commonMain' |
||
implementation("io.ktor:ktor-serialization-kotlinx-json:2.1.3") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to reimport it here as it already was imported in 'commonMain' |
||
implementation(npm("abort-controller", "3.0.0")) | ||
implementation(npm("node-fetch", "2.6.7")) | ||
} | ||
} | ||
val jsTest by getting | ||
|
||
all { | ||
languageSettings.optIn("kotlin.js.ExperimentalJsExport") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't add this compiler flag. As this will disable so many helpful warnings that are very useful during our development of the JS target |
||
languageSettings.optIn("kotlin.RequiresOptIn") | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.iohk.atala.prism.walletsdk.prismagent.helpers | ||
|
||
import io.iohk.atala.prism.domain.models.Api | ||
import io.ktor.client.request.prepareRequest | ||
import io.ktor.client.request.setBody | ||
import io.ktor.client.statement.HttpResponse | ||
import io.ktor.client.statement.HttpStatement | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.http.HttpMethod | ||
import io.ktor.http.Url | ||
import io.ktor.http.contentType | ||
import io.ktor.http.path | ||
import kotlinx.coroutines.DelicateCoroutinesApi | ||
import io.ktor.client.HttpClient as KtorClient | ||
|
||
@DelicateCoroutinesApi | ||
open class ApiImpl(override val client: KtorClient) : Api { | ||
|
||
override suspend fun prepareRequest( | ||
httpMethod: HttpMethod, | ||
url: Url, | ||
urlParameters: Map<String, String>, | ||
httpHeaders: Map<String, String>, | ||
body: Any? | ||
): HttpStatement { | ||
|
||
return client.prepareRequest { | ||
for (header in httpHeaders) { | ||
if ( | ||
httpMethod == HttpMethod.Get && | ||
header.key == HttpHeaders.ContentType && | ||
header.value.contains(ContentType.Application.Json.contentSubtype) | ||
) { | ||
continue | ||
} | ||
headers.append(header.key, header.value) | ||
} | ||
|
||
contentType(ContentType.Application.Json) | ||
|
||
body?.let { | ||
setBody(body) | ||
} | ||
|
||
url { | ||
method = httpMethod | ||
protocol = url.protocol | ||
host = url.host | ||
port = url.specifiedPort | ||
|
||
path(url.encodedPath) | ||
|
||
for (parameter in urlParameters) { | ||
parameters.append(parameter.key, parameter.value) | ||
} | ||
} | ||
} | ||
} | ||
|
||
override suspend fun request( | ||
httpMethod: HttpMethod, | ||
url: Url, | ||
urlParameters: Map<String, String>, | ||
httpHeaders: Map<String, String>, | ||
body: Any? | ||
): HttpResponse { | ||
return prepareRequest(httpMethod, url, urlParameters, httpHeaders, body).execute() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.iohk.atala.prism.walletsdk.prismagent.helpers | ||
|
||
import io.ktor.client.HttpClientConfig | ||
import io.ktor.client.HttpClient as KtorClient | ||
|
||
@Suppress("NO_ACTUAL_FOR_EXPECT") | ||
internal expect fun HttpClient(config: HttpClientConfig<*>.() -> Unit = {}): KtorClient |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.iohk.atala.prism.walletsdk.prismagent.protocols.prismOnboarding | ||
|
||
import io.iohk.atala.prism.domain.models.PrismAgentError | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.decodeFromString | ||
import kotlinx.serialization.json.Json | ||
|
||
class PrismOnboardingInvitation(jsonString: String) { | ||
|
||
@Serializable | ||
data class Body( | ||
val type: String, | ||
val onboardEndpoint: String, | ||
val from: String | ||
) | ||
|
||
var body: Body | ||
|
||
init { | ||
val json = Json { | ||
ignoreUnknownKeys = true | ||
prettyPrint = true | ||
isLenient = true | ||
} | ||
body = try { | ||
json.decodeFromString(jsonString) | ||
} catch (e: Throwable) { | ||
throw PrismAgentError.invitationIsInvalidError() | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong package name here