mirror of
https://github.com/selfxyz/self.git
synced 2026-04-27 03:01:15 -04:00
Align KMP callback/result contract with canonical VerificationResult (#1834)
* Align KMP verification result contract * formatting * pr feedback
This commit is contained in:
@@ -100,12 +100,12 @@ internal object VerificationResultSerializer : KSerializer<VerificationResult> {
|
||||
|
||||
return VerificationResult(
|
||||
success = payload["success"]?.jsonPrimitive?.booleanOrNull ?: false,
|
||||
userId = payload["userId"]?.jsonPrimitive?.contentOrNull,
|
||||
verificationId = payload["verificationId"]?.jsonPrimitive?.contentOrNull,
|
||||
proof = payload["proof"]?.let(::jsonElementToProofString),
|
||||
claims = payload["claims"]?.jsonObject?.mapValues { (_, value) -> value.toKotlinValue() },
|
||||
userId = payload["userId"]?.takeUnless { it is JsonNull }?.jsonPrimitive?.contentOrNull,
|
||||
verificationId = payload["verificationId"]?.takeUnless { it is JsonNull }?.jsonPrimitive?.contentOrNull,
|
||||
proof = payload["proof"]?.takeUnless { it is JsonNull }?.let(::jsonElementToProofString),
|
||||
claims = payload["claims"]?.takeUnless { it is JsonNull }?.jsonObject?.mapValues { (_, value) -> value.toKotlinValue() },
|
||||
error =
|
||||
payload["error"]?.let { error ->
|
||||
payload["error"]?.takeUnless { it is JsonNull }?.let { error ->
|
||||
decoder.json.decodeFromJsonElement(SelfSdkError.serializer(), error)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -8,6 +8,7 @@ import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import kotlinx.serialization.json.JsonNull
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.contentOrNull
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
@@ -26,14 +27,15 @@ internal fun deserializeVerificationResult(json: String): VerificationResult =
|
||||
internal fun verificationResultFromLifecycleParams(params: Map<String, JsonElement>): VerificationResult =
|
||||
VerificationResult(
|
||||
success = true,
|
||||
userId = params["userId"]?.jsonPrimitive?.contentOrNull,
|
||||
verificationId = params["verificationId"]?.jsonPrimitive?.contentOrNull,
|
||||
proof = params["proof"]?.let(::lifecycleProofString),
|
||||
userId = runCatching { params["userId"]?.jsonPrimitive?.contentOrNull }.getOrNull(),
|
||||
verificationId = runCatching { params["verificationId"]?.jsonPrimitive?.contentOrNull }.getOrNull(),
|
||||
proof = params["proof"]?.takeUnless { it is JsonNull }?.let(::lifecycleProofString),
|
||||
claims = (params["claims"] as? JsonObject)?.mapValues { (_, value) -> value.toKotlinValue() },
|
||||
)
|
||||
|
||||
private fun lifecycleProofString(element: JsonElement): String? =
|
||||
when (element) {
|
||||
JsonNull -> null
|
||||
is JsonObject -> element.toString()
|
||||
else -> runCatching { element.jsonPrimitive.contentOrNull }.getOrNull() ?: element.toString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user