From e6e3d668cee81b5492fbea599affa2132f1e5e08 Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Wed, 20 Mar 2024 15:25:24 -0700 Subject: [PATCH 1/2] Fix version future-proofing with is_uma_lnurlp_query. Future versions of UMA may change fields in this request, etc. so treating a parse failure as "non-uma" isn't the right behavior. We should allow the parsing to spit up the proper UnsupportedVersion exception later. This was causing the demo vasp to treat v1 requests as regular lnurl, rather than negotiating a lower UMA version. --- .../commonMain/kotlin/me/uma/protocol/LnurlpRequest.kt | 8 ++++---- uma-sdk/src/commonTest/kotlin/me/uma/UmaTests.kt | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/uma-sdk/src/commonMain/kotlin/me/uma/protocol/LnurlpRequest.kt b/uma-sdk/src/commonMain/kotlin/me/uma/protocol/LnurlpRequest.kt index 4d815b6..0bb34ca 100644 --- a/uma-sdk/src/commonMain/kotlin/me/uma/protocol/LnurlpRequest.kt +++ b/uma-sdk/src/commonMain/kotlin/me/uma/protocol/LnurlpRequest.kt @@ -83,6 +83,10 @@ data class LnurlpRequest( val timestamp = urlBuilder.parameters["timestamp"]?.toLong() val umaVersion = urlBuilder.parameters["umaVersion"] + if (umaVersion != null && !isVersionSupported(umaVersion)) { + throw UnsupportedVersionException(umaVersion) + } + if (vaspDomain == null || nonce == null || signature == null || @@ -93,10 +97,6 @@ data class LnurlpRequest( throw IllegalArgumentException("Invalid URL. Missing param: $url") } - if (!isVersionSupported(umaVersion)) { - throw UnsupportedVersionException(umaVersion) - } - return LnurlpRequest( receiverAddress, nonce, diff --git a/uma-sdk/src/commonTest/kotlin/me/uma/UmaTests.kt b/uma-sdk/src/commonTest/kotlin/me/uma/UmaTests.kt index 88d218c..07b491d 100644 --- a/uma-sdk/src/commonTest/kotlin/me/uma/UmaTests.kt +++ b/uma-sdk/src/commonTest/kotlin/me/uma/UmaTests.kt @@ -55,4 +55,10 @@ class UmaTests { String(Secp256k1.decryptEcies(encryptedTravelRuleInfo.hexToByteArray(), keys.privateKey)), ) } + + @Test + fun `test isUmaLnurlpQuery future-proofing`() { + val umaLnurlpQuery = "https://example.com/.well-known/lnurlp/\$bob?vaspDomain=example.com&nonce=123&signature=123&isSubjectToTravelRule=true×tamp=123&umaVersion=100.0" + assertEquals(true, UmaProtocolHelper().isUmaLnurlpQuery(umaLnurlpQuery)) + } } From b760fc0823fa561e239d464fc19713325f3ce0ad Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Wed, 20 Mar 2024 15:31:14 -0700 Subject: [PATCH 2/2] ktlint --- uma-sdk/src/commonTest/kotlin/me/uma/UmaTests.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uma-sdk/src/commonTest/kotlin/me/uma/UmaTests.kt b/uma-sdk/src/commonTest/kotlin/me/uma/UmaTests.kt index 07b491d..4fb101d 100644 --- a/uma-sdk/src/commonTest/kotlin/me/uma/UmaTests.kt +++ b/uma-sdk/src/commonTest/kotlin/me/uma/UmaTests.kt @@ -58,7 +58,9 @@ class UmaTests { @Test fun `test isUmaLnurlpQuery future-proofing`() { - val umaLnurlpQuery = "https://example.com/.well-known/lnurlp/\$bob?vaspDomain=example.com&nonce=123&signature=123&isSubjectToTravelRule=true×tamp=123&umaVersion=100.0" + val umaLnurlpQuery = + "https://example.com/.well-known/lnurlp/\$bob?vaspDomain=example.com&nonce=123&signature=123&" + + "isSubjectToTravelRule=true×tamp=123&umaVersion=100.0" assertEquals(true, UmaProtocolHelper().isUmaLnurlpQuery(umaLnurlpQuery)) } }