diff --git a/uma/test/uma_test.go b/uma/test/uma_test.go index a3a7501..b0afa05 100644 --- a/uma/test/uma_test.go +++ b/uma/test/uma_test.go @@ -93,6 +93,17 @@ func TestIsUmaQueryInvalidPath(t *testing.T) { require.False(t, uma.IsUmaLnurlpQuery(*urlObj)) } +func TestIsUmaQueryUnsupportedVersion(t *testing.T) { + urlString := "https://vasp2.com/.well-known/lnurlp/bob?signature=signature&nonce=12345&vaspDomain=vasp1.com&umaVersion=10.0&isSubjectToTravelRule=true×tamp=12345678" + urlObj, _ := url.Parse(urlString) + assert.True(t, uma.IsUmaLnurlpQuery(*urlObj)) + + // Imagine if we removed the travel rule field and nonce field in a future version: + urlString = "https://vasp2.com/.well-known/lnurlp/bob?signature=signature&vaspDomain=vasp1.com&umaVersion=10.0×tamp=12345678" + urlObj, _ = url.Parse(urlString) + assert.True(t, uma.IsUmaLnurlpQuery(*urlObj)) +} + func TestSignAndVerifyLnurlpRequest(t *testing.T) { privateKey, err := secp256k1.GeneratePrivateKey() require.NoError(t, err) diff --git a/uma/uma.go b/uma/uma.go index d4bcd19..3badd82 100644 --- a/uma/uma.go +++ b/uma/uma.go @@ -214,6 +214,12 @@ func GetSignedLnurlpRequestUrl( // You should try to process the request as a regular LNURLp request to fall back to LNURL-PAY. func IsUmaLnurlpQuery(url url.URL) bool { query, err := ParseLnurlpRequest(url) + // If err is an UnsupportedVersionError, the request is still an UMA request, but the version is not supported. + // The version negotiation should be handled by the VASP when parsing the request. + var unsupportedVersionError UnsupportedVersionError + if errors.As(err, &unsupportedVersionError) { + return true + } return err == nil && query != nil && query.IsUmaRequest() } @@ -239,6 +245,10 @@ func ParseLnurlpRequest(url url.URL) (*protocol.LnurlpRequest, error) { timestampAsTime = ×tampAsTimeVal } + if umaVersion != "" && !IsVersionSupported(umaVersion) { + return nil, UnsupportedVersionError{} + } + if vaspDomain == "" || signature == "" || nonce == "" || timestamp == "" || umaVersion == "" { return nil, errors.New("missing uma query parameters. vaspDomain, umaVersion, signature, nonce, and timestamp are required") } @@ -249,10 +259,6 @@ func ParseLnurlpRequest(url url.URL) (*protocol.LnurlpRequest, error) { } receiverAddress := pathParts[3] + "@" + url.Host - if !IsVersionSupported(umaVersion) { - return nil, UnsupportedVersionError{} - } - nilIfEmpty := func(s string) *string { if s == "" { return nil