diff --git a/umaserverdemo/src/main/kotlin/com/lightspark/Vasp2.kt b/umaserverdemo/src/main/kotlin/com/lightspark/ReceivingVasp.kt similarity index 94% rename from umaserverdemo/src/main/kotlin/com/lightspark/Vasp2.kt rename to umaserverdemo/src/main/kotlin/com/lightspark/ReceivingVasp.kt index 61fd37c9..31a57d88 100644 --- a/umaserverdemo/src/main/kotlin/com/lightspark/Vasp2.kt +++ b/umaserverdemo/src/main/kotlin/com/lightspark/ReceivingVasp.kt @@ -38,7 +38,7 @@ import me.uma.protocol.createCounterPartyDataOptions import me.uma.protocol.createPayeeData import me.uma.protocol.identifier -class Vasp2( +class ReceivingVasp( private val config: UmaConfig, private val uma: UmaProtocolHelper, private val lightsparkClient: LightsparkCoroutinesClient, @@ -47,6 +47,14 @@ class Vasp2( private val coroutineScope = CoroutineScope(Dispatchers.IO) private lateinit var senderUmaVersion: String + suspend fun createInvoice(call: ApplicationCall): String { + return "OK" + } + + suspend fun createAndSendInvoice(call: ApplicationCall): String { + return "OK" + } + suspend fun handleLnurlp(call: ApplicationCall): String { val username = call.parameters["username"] @@ -155,7 +163,7 @@ class Vasp2( } val lnurlInvoiceCreator = object : UmaInvoiceCreator { - override fun createUmaInvoice(amountMsats: Long, metadata: String): CompletableFuture { + override fun createUmaInvoice(amountMsats: Long, metadata: String, receiverIdentifier: String?,): CompletableFuture { return coroutineScope.future { lightsparkClient.createLnurlInvoice(config.nodeID, amountMsats, metadata).data.encodedPaymentRequest } @@ -334,17 +342,25 @@ class Vasp2( private fun getReceivingVaspDomain(call: ApplicationCall) = config.vaspDomain ?: call.originWithPort() } -fun Routing.registerVasp2Routes(vasp2: Vasp2) { +fun Routing.registerReceivingVaspRoutes(receivingVasp: ReceivingVasp) { get("/.well-known/lnurlp/{username}") { - call.debugLog(vasp2.handleLnurlp(call)) + call.debugLog(receivingVasp.handleLnurlp(call)) } - get("/api/uma/payreq/{uuid}") { - call.debugLog(vasp2.handleLnurlPayreq(call)) + get("/api/lnurl/payreq/{uuid}") { + call.debugLog(receivingVasp.handleLnurlPayreq(call)) } post("/api/uma/payreq/{uuid}") { - call.debugLog(vasp2.handleUmaPayreq(call)) + call.debugLog(receivingVasp.handleUmaPayreq(call)) + } + + get("/api/uma/create_invoice") { + call.debugLog(receivingVasp.createInvoice(call)); + } + + get("/api/uma/create_and_send_invoice") { + call.debugLog(receivingVasp.createAndSendInvoice(call)) } } diff --git a/umaserverdemo/src/main/kotlin/com/lightspark/Vasp1.kt b/umaserverdemo/src/main/kotlin/com/lightspark/SendingVasp.kt similarity index 97% rename from umaserverdemo/src/main/kotlin/com/lightspark/Vasp1.kt rename to umaserverdemo/src/main/kotlin/com/lightspark/SendingVasp.kt index 9f9fecb9..060a3a33 100644 --- a/umaserverdemo/src/main/kotlin/com/lightspark/Vasp1.kt +++ b/umaserverdemo/src/main/kotlin/com/lightspark/SendingVasp.kt @@ -57,7 +57,7 @@ import me.uma.protocol.createPayerData import me.uma.selectHighestSupportedVersion import me.uma.utils.serialFormat -class Vasp1( +class SendingVasp( private val config: UmaConfig, private val uma: UmaProtocolHelper, private val lightsparkClient: LightsparkCoroutinesClient, @@ -75,6 +75,14 @@ class Vasp1( private val nonceCache = InMemoryNonceCache(Clock.System.now().epochSeconds) private lateinit var receiverUmaVersion: String + suspend fun payInvoice(call: ApplicationCall): String { + return "OK" + } + + suspend fun requestInvoicePayment(call: ApplicationCall): String { + return "OK" + } + suspend fun handleClientUmaLookup(call: ApplicationCall): String { val receiverAddress = call.parameters["receiver"] if (receiverAddress == null) { @@ -500,17 +508,25 @@ class Vasp1( } } -fun Routing.registerVasp1Routes(vasp1: Vasp1) { +fun Routing.registerSendingVaspRoutes(sendingVasp: SendingVasp) { get("/api/umalookup/{receiver}") { - call.debugLog(vasp1.handleClientUmaLookup(call)) + call.debugLog(sendingVasp.handleClientUmaLookup(call)) } get("/api/umapayreq/{callbackUuid}") { - call.debugLog(vasp1.handleClientUmaPayReq(call)) + call.debugLog(sendingVasp.handleClientUmaPayReq(call)) } post("/api/sendpayment/{callbackUuid}") { - call.debugLog(vasp1.handleClientSendPayment(call)) + call.debugLog(sendingVasp.handleClientSendPayment(call)) + } + + post("/api/uma/pay_invoice") { + call.debugLog(sendingVasp.payInvoice(call)) + } + + post("/api/uma/request_invoice_payment") { + call.debugLog(sendingVasp.requestInvoicePayment(call)) } } diff --git a/umaserverdemo/src/main/kotlin/com/lightspark/plugins/Routing.kt b/umaserverdemo/src/main/kotlin/com/lightspark/plugins/Routing.kt index 6d8954ac..2d2b3eb3 100644 --- a/umaserverdemo/src/main/kotlin/com/lightspark/plugins/Routing.kt +++ b/umaserverdemo/src/main/kotlin/com/lightspark/plugins/Routing.kt @@ -1,33 +1,29 @@ package com.lightspark.plugins import com.lightspark.UmaConfig -import com.lightspark.Vasp1 -import com.lightspark.Vasp2 +import com.lightspark.SendingVasp +import com.lightspark.ReceivingVasp import com.lightspark.debugLog import com.lightspark.handlePubKeyRequest import com.lightspark.isDomainLocalhost import com.lightspark.originWithPort -import com.lightspark.registerVasp1Routes -import com.lightspark.registerVasp2Routes +import com.lightspark.registerSendingVaspRoutes +import com.lightspark.registerReceivingVaspRoutes import com.lightspark.sdk.ClientConfig import com.lightspark.sdk.LightsparkCoroutinesClient import com.lightspark.sdk.auth.AccountApiTokenAuthProvider import io.ktor.http.HttpStatusCode import io.ktor.server.application.Application import io.ktor.server.application.call -import io.ktor.server.request.ContentTransformationException -import io.ktor.server.request.receive import io.ktor.server.request.receiveText import io.ktor.server.response.respond import io.ktor.server.routing.get import io.ktor.server.routing.post import io.ktor.server.routing.routing import kotlinx.datetime.Clock -import kotlinx.serialization.json.JsonObject import me.uma.InMemoryNonceCache import me.uma.InMemoryPublicKeyCache import me.uma.UmaProtocolHelper -import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.add import kotlinx.serialization.json.buildJsonArray import kotlinx.serialization.json.buildJsonObject @@ -44,12 +40,12 @@ fun Application.configureRouting( authProvider = AccountApiTokenAuthProvider(config.apiClientID, config.apiClientSecret), ), ) - val vasp1 = Vasp1(config, uma, client) - val vasp2 = Vasp2(config, uma, client) + val sendingVasp = SendingVasp(config, uma, client) + val receivingVasp = ReceivingVasp(config, uma, client) routing { - registerVasp1Routes(vasp1) - registerVasp2Routes(vasp2) + registerSendingVaspRoutes(sendingVasp) + registerReceivingVaspRoutes(receivingVasp) get("/.well-known/lnurlpubkey") { call.debugLog(handlePubKeyRequest(call, config))