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 a2bcb4d + e34f55d commit 12b975a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
13 changes: 13 additions & 0 deletions uma/test/uma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ func TestSignAndVerifyLnurlpRequest(t *testing.T) {
require.NoError(t, err)
}

func TestParseLnurlpRequestUnsupportedVersion(t *testing.T) {
privateKey, err := secp256k1.GeneratePrivateKey()
require.NoError(t, err)
version := "1000.0"
queryUrl, err := uma.GetSignedLnurlpRequestUrl(privateKey.Serialize(), "[email protected]", "vasp1.com", true, &version)
require.NoError(t, err)
_, err = uma.ParseLnurlpRequest(*queryUrl)
var unsupportedVersionError uma.UnsupportedVersionError
require.ErrorAs(t, err, &unsupportedVersionError)
require.Equal(t, unsupportedVersionError.UnsupportedVersion, version)
require.Equal(t, unsupportedVersionError.SupportedMajorVersions, []int{1, 0})
}

func TestSignAndVerifyLnurlpRequestInvalidSignature(t *testing.T) {
privateKey, err := secp256k1.GeneratePrivateKey()
require.NoError(t, err)
Expand Down
5 changes: 4 additions & 1 deletion uma/uma.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ func ParseLnurlpRequest(url url.URL) (*protocol.LnurlpRequest, error) {
}

if umaVersion != "" && !IsVersionSupported(umaVersion) {
return nil, UnsupportedVersionError{}
return nil, UnsupportedVersionError{
UnsupportedVersion: umaVersion,
SupportedMajorVersions: GetSupportedMajorVersions(),
}
}

if vaspDomain == "" || signature == "" || nonce == "" || timestamp == "" || umaVersion == "" {
Expand Down
26 changes: 19 additions & 7 deletions uma/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,30 @@ func GetSupportedMajorVersionsFromErrorResponseBody(errorResponseBody []byte) ([
return vasp2SupportedMajorVersionsIntList, nil
}

func GetSupportedMajorVersions() map[int]struct{} {
versions := make(map[int]struct{})
versions[MAJOR_VERSION] = struct{}{}
func getSupportedMajorVersionsMap() map[int]struct{} {
// NOTE: In the future, we may want to support multiple major versions in the same SDK, but for now, this keeps
// things simple.
list := GetSupportedMajorVersions()
m := make(map[int]struct{})
for _, v := range list {
m[v] = struct{}{}
}
return m
}

func GetSupportedMajorVersions() []int {
// NOTE: In the future, we may want to support multiple major versions in the same SDK, but for now, this keeps
// things simple.
majorVersions := []int{MAJOR_VERSION}
for _, version := range backcompatVersions {
parsedVersion, err := ParseVersion(version)
if err != nil {
continue
}
versions[parsedVersion.Major] = struct{}{}
majorVersions = append(majorVersions, parsedVersion.Major)
}

return versions
return majorVersions
}

func GetHighestSupportedVersionForMajorVersion(majorVersion int) *ParsedVersion {
Expand All @@ -78,7 +90,7 @@ func GetHighestSupportedVersionForMajorVersion(majorVersion int) *ParsedVersion

func SelectHighestSupportedVersion(otherVaspSupportedMajorVersions []int) *string {
var highestVersion *ParsedVersion
supportedMajorVersions := GetSupportedMajorVersions()
supportedMajorVersions := getSupportedMajorVersionsMap()
for _, otherVaspMajorVersion := range otherVaspSupportedMajorVersions {
_, supportsMajorVersion := supportedMajorVersions[otherVaspMajorVersion]
if !supportsMajorVersion {
Expand Down Expand Up @@ -122,7 +134,7 @@ func IsVersionSupported(version string) bool {
if err != nil || parsedVersion == nil {
return false
}
_, supportsMajorVersion := GetSupportedMajorVersions()[parsedVersion.Major]
_, supportsMajorVersion := getSupportedMajorVersionsMap()[parsedVersion.Major]
return supportsMajorVersion
}

Expand Down

0 comments on commit 12b975a

Please sign in to comment.