Skip to content

Commit

Permalink
Update the demo vasp to use uma 1.0 (#74)
Browse files Browse the repository at this point in the history
* WIP: Update the demo vasp to use uma 1.0

- Switch to new counterparty data format
- Add the payeedata fields
- Add required new signature fields

* Switch to the new LUD-21 spec

* Add improved non-UMA LNURL compatibility

* Update demo vasp for v0 backwards compatibility.

* Go get

* Add posttxhooks to the demo vasp

* Use certs in demo vasp (#91)

* Change receiving currency param name to match other vasps

* Unifying the sending vasp demo api surface

* Bump sdk ref

* Update to released version

---------

Co-authored-by: Shreya Vissamsetti <[email protected]>
  • Loading branch information
jklein24 and shreyav authored Apr 2, 2024
1 parent 06f318f commit a19cd2e
Show file tree
Hide file tree
Showing 13 changed files with 512 additions and 1,460 deletions.
2 changes: 2 additions & 0 deletions examples/uma-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ LIGHTSPARK_API_TOKEN_CLIENT_ID=<your lightspark API token client ID from https:/
LIGHTSPARK_API_TOKEN_CLIENT_SECRET=<your lightspark API token client secret from https://app.lightspark.com/api-config>
LIGHTSPARK_UMA_NODE_ID=<your lightspark node ID. ex: LightsparkNodeWithOSKLND:018b24d0-1c45-f96b-0000-1ed0328b72cc>
LIGHTSPARK_UMA_RECEIVER_USER=<receiver UMA>
LIGHTSPARK_UMA_ENCRYPTION_CERT_CHAIN=<pem-encoded x509 certificate chain containing encryption pubkey>
LIGHTSPARK_UMA_ENCRYPTION_PUBKEY=<hex-encoded encryption pubkey>
LIGHTSPARK_UMA_ENCRYPTION_PRIVKEY=<hex-encoded encryption privkey>
LIGHTSPARK_UMA_SIGNING_CERT_CHAIN=<pem-encoded x509 certificate chain containing signing pubkey>
LIGHTSPARK_UMA_SIGNING_PUBKEY=<hex-encoded signing pubkey>
LIGHTSPARK_UMA_SIGNING_PRIVKEY=<hex-encoded signing privkey>

Expand Down
16 changes: 6 additions & 10 deletions examples/uma-server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,22 @@ type UmaConfig struct {
NodeUUID string
Username string
UserID string
UmaEncryptionCertChain string
UmaEncryptionPubKeyHex string
UmaEncryptionPrivKeyHex string
UmaSigningCertChain string
UmaSigningPubKeyHex string
UmaSigningPrivKeyHex string
RemoteSigningNodeMasterSeedHex string
OskNodeSigningKeyPassword string
ClientBaseURL *string
SenderVaspDomain string
}

func (c *UmaConfig) UmaEncryptionPubKeyBytes() ([]byte, error) {
return hex.DecodeString(c.UmaEncryptionPubKeyHex)
OwnVaspDomain string
}

func (c *UmaConfig) UmaEncryptionPrivKeyBytes() ([]byte, error) {
return hex.DecodeString(c.UmaEncryptionPrivKeyHex)
}

func (c *UmaConfig) UmaSigningPubKeyBytes() ([]byte, error) {
return hex.DecodeString(c.UmaSigningPubKeyHex)
}

func (c *UmaConfig) UmaSigningPrivKeyBytes() ([]byte, error) {
return hex.DecodeString(c.UmaSigningPrivKeyHex)
}
Expand Down Expand Up @@ -80,13 +74,15 @@ func NewConfig() UmaConfig {
Username: username,
// Static UUID so that callback URLs are always the same.
UserID: "4b41ae03-01b8-4974-8d26-26a35d28851b",
UmaEncryptionCertChain: os.Getenv("LIGHTSPARK_UMA_ENCRYPTION_CERT_CHAIN"),
UmaEncryptionPubKeyHex: os.Getenv("LIGHTSPARK_UMA_ENCRYPTION_PUBKEY"),
UmaEncryptionPrivKeyHex: os.Getenv("LIGHTSPARK_UMA_ENCRYPTION_PRIVKEY"),
UmaSigningCertChain: os.Getenv("LIGHTSPARK_UMA_SIGNING_CERT_CHAIN"),
UmaSigningPubKeyHex: os.Getenv("LIGHTSPARK_UMA_SIGNING_PUBKEY"),
UmaSigningPrivKeyHex: os.Getenv("LIGHTSPARK_UMA_SIGNING_PRIVKEY"),
RemoteSigningNodeMasterSeedHex: os.Getenv("LIGHTSPARK_UMA_REMOTE_SIGNING_NODE_MASTER_SEED"),
OskNodeSigningKeyPassword: os.Getenv("LIGHTSPARK_UMA_OSK_NODE_SIGNING_KEY_PASSWORD"),
ClientBaseURL: baseUrl,
SenderVaspDomain: os.Getenv("LIGHTSPARK_UMA_VASP_DOMAIN"),
OwnVaspDomain: os.Getenv("LIGHTSPARK_UMA_VASP_DOMAIN"),
}
}
29 changes: 29 additions & 0 deletions examples/uma-server/currencies.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
umaprotocol "github.com/uma-universal-money-address/uma-go-sdk/uma/protocol"
)

var SatsCurrency = umaprotocol.Currency{
Code: "SAT",
Name: "Satoshis",
Symbol: "SAT",
MillisatoshiPerUnit: 1000,
Convertible: umaprotocol.ConvertibleCurrency{
MinSendable: 1,
MaxSendable: 100_000_000,
},
Decimals: 0,
}

var UsdCurrency = umaprotocol.Currency{
Code: "USD",
Name: "US Dollars",
Symbol: "$",
MillisatoshiPerUnit: MillisatoshiPerUsd,
Convertible: umaprotocol.ConvertibleCurrency{
MinSendable: 1,
MaxSendable: 1_000,
},
Decimals: 2,
}
6 changes: 4 additions & 2 deletions examples/uma-server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ go 1.21
toolchain go1.21.0

require (
github.com/ethereum/go-ethereum v1.13.8
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 v0.6.4
github.com/uma-universal-money-address/uma-go-sdk v1.0.0
)

require (
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/ecies/go/v2 v2.0.9 // indirect
github.com/ethereum/go-ethereum v1.13.8 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
Expand All @@ -35,6 +36,7 @@ require (
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
15 changes: 6 additions & 9 deletions examples/uma-server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7/go.mod h1:5GuXa7vkL8
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU=
github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huin/goupnp v1.0.3/go.mod h1:ZxNlw5WqJj6wSsRK5+YfflQGXYfccj5VgQsMNixHM7Y=
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
Expand Down Expand Up @@ -707,14 +709,8 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/uma-universal-money-address/uma-go-sdk v0.6.2 h1:9hRq7NWN/0sjbapNBN19it0XokvnnZTIhasKL8hp9WY=
github.com/uma-universal-money-address/uma-go-sdk v0.6.2/go.mod h1:OimSKjRNT7Wm2lA0Q9C0DmxsMvqBickucUjtQmB8Cl8=
github.com/uma-universal-money-address/uma-go-sdk v0.6.3 h1:xs96/PxvWVCjXUfbybJCDSBbINj1qU1FZlQoBfaWnFk=
github.com/uma-universal-money-address/uma-go-sdk v0.6.3/go.mod h1:OimSKjRNT7Wm2lA0Q9C0DmxsMvqBickucUjtQmB8Cl8=
github.com/uma-universal-money-address/uma-go-sdk v0.6.4-0.20240321004618-174ef3115001 h1:8uzBwmwhR0AOPBQlFlAND0vz2HVbmNdztxE2mWTSRSU=
github.com/uma-universal-money-address/uma-go-sdk v0.6.4-0.20240321004618-174ef3115001/go.mod h1:OimSKjRNT7Wm2lA0Q9C0DmxsMvqBickucUjtQmB8Cl8=
github.com/uma-universal-money-address/uma-go-sdk v0.6.4 h1:wAqh2xzt+lAPEzqS67b65tk6PFGZmrWLlH+SJp7e91E=
github.com/uma-universal-money-address/uma-go-sdk v0.6.4/go.mod h1:OimSKjRNT7Wm2lA0Q9C0DmxsMvqBickucUjtQmB8Cl8=
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/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 Expand Up @@ -800,6 +796,8 @@ golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMk
golang.org/x/exp v0.0.0-20220426173459-3bcf042a4bf5/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ=
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
Expand Down Expand Up @@ -1202,7 +1200,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
Expand Down
14 changes: 0 additions & 14 deletions examples/uma-server/raw_lnurl.go

This file was deleted.

5 changes: 5 additions & 0 deletions examples/uma-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func main() {
vasp2.handlePubKeyRequest(c)
})

engine.GET("api/uma/utxocallback", func(c *gin.Context) {
// It doesn't matter which vasp protocol handles this since they share a config and cache.
vasp2.handleUtxoCallback(c)
})

port := os.Getenv("PORT")
if port == "" {
port = "8081"
Expand Down
4 changes: 2 additions & 2 deletions examples/uma-server/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"errors"
"github.com/uma-universal-money-address/uma-go-sdk/uma"
umautils "github.com/uma-universal-money-address/uma-go-sdk/uma/utils"
"regexp"
"strings"
)
Expand Down Expand Up @@ -35,7 +35,7 @@ func ValidateUserName(userName string) error {

func ValidateDomain(domain string) error {
hostWithoutPort := strings.Split(domain, ":")[0]
isLocalDomain := uma.IsDomainLocalhost(hostWithoutPort)
isLocalDomain := umautils.IsDomainLocalhost(hostWithoutPort)
localHostWithPortRegex := regexp.MustCompile(`^localhost(:[0-9]+)?$`)
domainRegex := regexp.MustCompile(`^([a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*[._]?$`)
if !domainRegex.MatchString(domain) && !localHostWithPortRegex.MatchString(domain) && !isLocalDomain {
Expand Down
Loading

0 comments on commit a19cd2e

Please sign in to comment.