Skip to content

Commit

Permalink
Allow non-UMA lnurl in demo vasp (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyav authored Apr 23, 2024
1 parent 1f00287 commit dd5b264
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/uma-server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/gin-gonic/gin v1.9.1
github.com/google/uuid v1.3.1
github.com/lightsparkdev/go-sdk v0.10.0
github.com/uma-universal-money-address/uma-go-sdk v1.0.0
github.com/uma-universal-money-address/uma-go-sdk v1.0.1
)

require (
Expand Down
2 changes: 2 additions & 0 deletions examples/uma-server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4d
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/uma-universal-money-address/uma-go-sdk v1.0.0 h1:HaIsygLK2UovO5gXje4TCoHCW2O1Ab+gWjCNzm/ahvc=
github.com/uma-universal-money-address/uma-go-sdk v1.0.0/go.mod h1:OimSKjRNT7Wm2lA0Q9C0DmxsMvqBickucUjtQmB8Cl8=
github.com/uma-universal-money-address/uma-go-sdk v1.0.1 h1:vPSR7w4gkY7GVG6NlruhPw/gyHA914MuIh70AQInFzI=
github.com/uma-universal-money-address/uma-go-sdk v1.0.1/go.mod h1:OimSKjRNT7Wm2lA0Q9C0DmxsMvqBickucUjtQmB8Cl8=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/urfave/cli/v2 v2.10.2/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhAyPlwvo=
github.com/urfave/cli/v2 v2.24.1/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
Expand Down
36 changes: 34 additions & 2 deletions examples/uma-server/vasp1.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,28 @@ func (v *Vasp1) handleClientUmaLookup(context *gin.Context) {
receiverId := addressParts[0]
receiverVasp := addressParts[1]
signingKey, err := v.config.UmaSigningPrivKeyBytes()
if err != nil {
context.JSON(http.StatusInternalServerError, gin.H{
"status": "ERROR",
"reason": err.Error(),
})
return
}

lnurlpRequest, err := uma.GetSignedLnurlpRequestUrl(
signingKey, receiverAddress, v.getVaspDomain(context), true, nil)
var lnurlpRequest *url.URL
if strings.HasPrefix(receiverVasp, "$") {
lnurlpRequest, err = uma.GetSignedLnurlpRequestUrl(
signingKey, receiverAddress, v.getVaspDomain(context), true, nil)
if err != nil {
context.JSON(http.StatusInternalServerError, gin.H{
"status": "ERROR",
"reason": err.Error(),
})
return
}
} else {
lnurlpRequest = v.getNonUmaLnurlRequestUrl(receiverId, receiverVasp, context.Request.Host)
}

resp, err := http.Get(lnurlpRequest.String())
if err != nil {
Expand Down Expand Up @@ -143,6 +162,19 @@ func (v *Vasp1) handleClientUmaLookup(context *gin.Context) {
})
}

func (v *Vasp1) getNonUmaLnurlRequestUrl(receiverId string, receiverVasp string, domain string) *url.URL {
scheme := "https"
if umautils.IsDomainLocalhost(domain) {
scheme = "http"
}

return &url.URL{
Scheme: scheme,
Host: receiverVasp,
Path: fmt.Sprintf("/.well-known/lnurlp/%s", receiverId),
}
}

func (v *Vasp1) handleUnsupportedVersionResponse(response *http.Response, signingKey []byte, receiverAddress string, context *gin.Context) (*http.Response, bool) {
responseBodyBytes, err := io.ReadAll(response.Body)
if err != nil {
Expand Down

0 comments on commit dd5b264

Please sign in to comment.