Skip to content

Commit

Permalink
Merge branch 'main' into release/v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jklein24 committed Mar 21, 2024
2 parents d922229 + 9d3cf55 commit a2bcb4d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 11 additions & 0 deletions uma/test/uma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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&timestamp=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&timestamp=12345678"
urlObj, _ = url.Parse(urlString)
assert.True(t, uma.IsUmaLnurlpQuery(*urlObj))
}

func TestSignAndVerifyLnurlpRequest(t *testing.T) {
privateKey, err := secp256k1.GeneratePrivateKey()
require.NoError(t, err)
Expand Down
14 changes: 10 additions & 4 deletions uma/uma.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -239,6 +245,10 @@ func ParseLnurlpRequest(url url.URL) (*protocol.LnurlpRequest, error) {
timestampAsTime = &timestampAsTimeVal
}

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")
}
Expand All @@ -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
Expand Down

0 comments on commit a2bcb4d

Please sign in to comment.