diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5f86dae1..1f971d5b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,7 +21,7 @@ ktlint = "11.3.1" ktor = "2.3.7" lightsparkCore = "0.6.0" lightsparkCrypto = "0.6.0" -uma = "1.1.1" +uma = "1.2.1" mavenPublish = "0.25.2" mockitoCore = "5.5.0" taskTree = "2.1.1" diff --git a/umaserverdemo/src/main/kotlin/com/lightspark/LightsparkClientUmaInvoiceCreator.kt b/umaserverdemo/src/main/kotlin/com/lightspark/LightsparkClientUmaInvoiceCreator.kt index e2ea906c..4a041a5e 100644 --- a/umaserverdemo/src/main/kotlin/com/lightspark/LightsparkClientUmaInvoiceCreator.kt +++ b/umaserverdemo/src/main/kotlin/com/lightspark/LightsparkClientUmaInvoiceCreator.kt @@ -8,14 +8,38 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.future.future import me.uma.UmaInvoiceCreator -class LightsparkClientUmaInvoiceCreator( +/** + * Creates UMA invoices using the Lightspark client. + * + * @constructor Creates an instance of [LightsparkClientUmaInvoiceCreator]. + * + * @param client The [LightsparkCoroutinesClient] used to create invoices. + * @param nodeId The ID of the node for which to create the invoice. + * @param expirySecs The number of seconds before the invoice expires. + * @param enableUmaAnalytics A flag indicating whether UMA analytics should be enabled. If `true`, + * the receiver identifier will be hashed using a monthly-rotated seed and used for anonymized + * analysis. + * @param signingPrivateKey Optional, the receiver's signing private key. Used to hash the receiver + * identifier if UMA analytics is enabled. + */ +class LightsparkClientUmaInvoiceCreator @JvmOverloads constructor( private val client: LightsparkCoroutinesClient, private val nodeId: String, private val expirySecs: Int, + private val enableUmaAnalytics: Boolean = false, + private val signingPrivateKey: ByteArray? = null, ) : UmaInvoiceCreator { private val coroutineScope = CoroutineScope(Dispatchers.IO) - constructor(apiClientId: String, apiClientSecret: String, nodeId: String, expirySecs: Int) : this( + @JvmOverloads + constructor( + apiClientId: String, + apiClientSecret: String, + nodeId: String, + expirySecs: Int, + enableUmaAnalytics: Boolean = false, + signingPrivateKey: ByteArray? = null, + ) : this( LightsparkCoroutinesClient( ClientConfig( authProvider = AccountApiTokenAuthProvider(apiClientId, apiClientSecret), @@ -23,9 +47,15 @@ class LightsparkClientUmaInvoiceCreator( ), nodeId, expirySecs, + enableUmaAnalytics, + signingPrivateKey, ) - override fun createUmaInvoice(amountMsats: Long, metadata: String) = coroutineScope.future { - client.createUmaInvoice(nodeId, amountMsats, metadata, expirySecs).data.encodedPaymentRequest + override fun createUmaInvoice(amountMsats: Long, metadata: String, receiverIdentifier: String?) = coroutineScope.future { + if (enableUmaAnalytics && signingPrivateKey != null) { + client.createUmaInvoice(nodeId, amountMsats, metadata, expirySecs, signingPrivateKey, receiverIdentifier) + } else { + client.createUmaInvoice(nodeId, amountMsats, metadata, expirySecs) + }.data.encodedPaymentRequest } } diff --git a/umaserverdemo/src/main/kotlin/com/lightspark/Vasp2.kt b/umaserverdemo/src/main/kotlin/com/lightspark/Vasp2.kt index d2a0e296..61fd37c9 100644 --- a/umaserverdemo/src/main/kotlin/com/lightspark/Vasp2.kt +++ b/umaserverdemo/src/main/kotlin/com/lightspark/Vasp2.kt @@ -246,7 +246,13 @@ class Vasp2( val response = try { uma.getPayReqResponse( query = request, - invoiceCreator = LightsparkClientUmaInvoiceCreator(client, config.nodeID, expirySecs), + invoiceCreator = LightsparkClientUmaInvoiceCreator( + client = client, + nodeId = config.nodeID, + expirySecs = expirySecs, + enableUmaAnalytics = true, + signingPrivateKey = config.umaSigningPrivKey, + ), metadata = getEncodedMetadata(), receivingCurrencyCode = receivingCurrency.code, receivingCurrencyDecimals = receivingCurrency.decimals,