Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ data class LnurlpRequest(
if (urlBuilder.protocol != URLProtocol.HTTP && urlBuilder.protocol != URLProtocol.HTTPS) {
throw IllegalArgumentException("Invalid URL schema: $url")
}
if (urlBuilder.pathSegments.size != 3
|| urlBuilder.pathSegments[0] != ".well-known"
|| urlBuilder.pathSegments[1] != "lnurlp"
if (urlBuilder.pathSegments.size != 4
|| urlBuilder.pathSegments[1] != ".well-known"
|| urlBuilder.pathSegments[2] != "lnurlp"
) {
throw IllegalArgumentException("Invalid uma request path: $url")
}
val receiverAddress = "${urlBuilder.host}@${urlBuilder.pathSegments[2]}"
val receiverAddress = "${urlBuilder.host}@${urlBuilder.pathSegments[3]}"
val vaspDomain = urlBuilder.parameters["vaspDomain"]
val nonce = urlBuilder.parameters["nonce"]
val signature = urlBuilder.parameters["signature"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.encoding.CompositeDecoder
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.Json
Expand Down Expand Up @@ -47,7 +46,7 @@ data class PayerDataOptions(

// Custom serializer for PayerDataOptions
class PayerDataOptionsSerializer : KSerializer<PayerDataOptions> {
override val descriptor = PrimitiveSerialDescriptor("PayerDataOptions", PrimitiveKind.STRING)
override val descriptor = PrimitiveSerialDescriptor("payerData", PrimitiveKind.STRING)

override fun serialize(encoder: Encoder, value: PayerDataOptions) {
val jsonOutput = """{
Expand All @@ -60,28 +59,14 @@ class PayerDataOptionsSerializer : KSerializer<PayerDataOptions> {
}

override fun deserialize(decoder: Decoder): PayerDataOptions {
val compositeInput = decoder.beginStructure(descriptor)
var nameRequired = false
var emailRequired = false
var complianceRequired = false
loop@ while (true) {
when (val index = compositeInput.decodeElementIndex(descriptor)) {
CompositeDecoder.Companion.DECODE_DONE -> break@loop
0 -> {
val jsonInput = compositeInput.decodeStringElement(descriptor, index)
val json = Json.parseToJsonElement(jsonInput)
val name = json.jsonObject["name"]?.jsonObject
val email = json.jsonObject["email"]?.jsonObject
val compliance = json.jsonObject["compliance"]?.jsonObject
nameRequired = name?.get("mandatory")?.jsonPrimitive?.boolean ?: false
emailRequired = email?.get("mandatory")?.jsonPrimitive?.boolean ?: false
complianceRequired = compliance?.get("mandatory")?.jsonPrimitive?.boolean ?: false
}

else -> throw IllegalArgumentException("Invalid index $index")
}
}
compositeInput.endStructure(descriptor)
val jsonInput = decoder.decodeString()
val json = Json.parseToJsonElement(jsonInput)
val name = json.jsonObject["name"]?.jsonObject
val email = json.jsonObject["email"]?.jsonObject
val compliance = json.jsonObject["compliance"]?.jsonObject
val nameRequired = name?.get("mandatory")?.jsonPrimitive?.boolean ?: false
val emailRequired = email?.get("mandatory")?.jsonPrimitive?.boolean ?: false
val complianceRequired = compliance?.get("mandatory")?.jsonPrimitive?.boolean ?: false
return PayerDataOptions(nameRequired, emailRequired, complianceRequired)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class UmaProtocolHelper(
return cached
}

val response = umaRequester.makeGetRequest("https://$vaspDomain/.well-known/uma-public-key")
val scheme = if (vaspDomain.startsWith("localhost:")) "http" else "https"
val response = umaRequester.makeGetRequest("$scheme://$vaspDomain/.well-known/lnurlpubkey")
val pubKeyResponse = serializerFormat.decodeFromString<PubKeyResponse>(response)
publicKeyCache.addPublicKeysForVasp(vaspDomain, pubKeyResponse)
return pubKeyResponse
Expand Down
1 change: 1 addition & 0 deletions umaserverdemo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
implementation("io.ktor:ktor-server-default-headers-jvm")
implementation("io.ktor:ktor-server-call-logging-jvm")
implementation("io.ktor:ktor-server-content-negotiation-jvm")
implementation("io.ktor:ktor-client-content-negotiation-jvm")
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm")
implementation("io.ktor:ktor-server-auth-jvm")
implementation("io.ktor:ktor-server-compression-jvm")
Expand Down
7 changes: 7 additions & 0 deletions umaserverdemo/src/main/kotlin/com/lightspark/Logging.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.lightspark

import io.ktor.server.application.ApplicationCall

fun ApplicationCall.debugLog(message: String) {
application.environment.log.debug(message)
}
19 changes: 19 additions & 0 deletions umaserverdemo/src/main/kotlin/com/lightspark/PubKeyHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.lightspark

import com.lightspark.sdk.uma.PubKeyResponse
import io.ktor.server.application.ApplicationCall
import io.ktor.server.response.respond

suspend fun handlePubKeyRequest(call: ApplicationCall, config: UmaConfig): String {
val twoWeeksFromNowMs = System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 14

val response = PubKeyResponse(
signingPubKey = config.umaSigningPubKey,
encryptionPubKey = config.umaEncryptionPubKey,
expirationTimestamp = twoWeeksFromNowMs / 1000,
)

call.respond(response)

return "OK"
}
Loading