Skip to content

Commit

Permalink
Tweak the UMA demo vasp to unify the api and make it compatible with …
Browse files Browse the repository at this point in the history
…others (#57)
  • Loading branch information
jklein24 authored Jan 20, 2024
2 parents 22e422b + dd41ee1 commit f49bb51
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
11 changes: 9 additions & 2 deletions examples/uma-server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type UmaConfig struct {
UmaSigningPrivKeyHex string
RemoteSigningNodeMasterSeedHex string
OskNodeSigningKeyPassword string
ClientBaseURL string
ClientBaseURL *string
SenderVaspDomain string
}

Expand Down Expand Up @@ -66,6 +66,13 @@ func NewConfig() UmaConfig {
username = "ls_test"
}

baseUrlEnv := os.Getenv("LIGHTSPARK_EXAMPLE_BASE_URL")
baseUrlStr := fmt.Sprintf("https://%s/graphql/server/rc", baseUrlEnv)
baseUrl := &baseUrlStr
if baseUrlEnv == "" {
baseUrl = nil
}

return UmaConfig{
ApiClientID: os.Getenv("LIGHTSPARK_API_TOKEN_CLIENT_ID"),
ApiClientSecret: os.Getenv("LIGHTSPARK_API_TOKEN_CLIENT_SECRET"),
Expand All @@ -79,7 +86,7 @@ func NewConfig() UmaConfig {
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: fmt.Sprintf("https://%s/graphql/server/rc", os.Getenv("LIGHTSPARK_EXAMPLE_BASE_URL")),
ClientBaseURL: baseUrl,
SenderVaspDomain: os.Getenv("LIGHTSPARK_UMA_VASP_DOMAIN"),
}
}
21 changes: 11 additions & 10 deletions examples/uma-server/vasp1.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewVasp1(config *UmaConfig, pubKeyCache uma.PublicKeyCache) *Vasp1 {
pubKeyCache: pubKeyCache,
requestCache: NewVasp1RequestCache(),
nonceCache: uma.NewInMemoryNonceCache(oneDayAgo),
client: services.NewLightsparkClient(config.ApiClientID, config.ApiClientSecret, &config.ClientBaseURL),
client: services.NewLightsparkClient(config.ApiClientID, config.ApiClientSecret, config.ClientBaseURL),
}
}

Expand Down Expand Up @@ -135,11 +135,11 @@ func (v *Vasp1) handleClientUmaLookup(context *gin.Context) {
// have anything to do with that data in this demo, though.

context.JSON(http.StatusOK, gin.H{
"currencies": lnurlpResponse.Currencies,
"minSendSats": lnurlpResponse.MinSendable,
"maxSendSats": lnurlpResponse.MaxSendable,
"callbackUuid": callbackUuid,
"receiverKYCStatus": lnurlpResponse.Compliance.KycStatus, // You might not actually send this to a client in practice.
"receiverCurrencies": lnurlpResponse.Currencies,
"minSendSats": lnurlpResponse.MinSendable,
"maxSendSats": lnurlpResponse.MaxSendable,
"callbackUuid": callbackUuid,
"receiverKYCStatus": lnurlpResponse.Compliance.KycStatus, // You might not actually send this to a client in practice.
})
}

Expand Down Expand Up @@ -273,10 +273,11 @@ func (v *Vasp1) handleClientPayReq(context *gin.Context) {
return
}

payerInfo := getPayerInfo(initialRequestData.umaLnurlpResponse.RequiredPayerData)
payerInfo := v.getPayerInfo(initialRequestData.umaLnurlpResponse.RequiredPayerData, context)
trInfo := "Here is some fake travel rule info. It's up to you to actually implement this."
senderUtxos, err := v.client.GetNodeChannelUtxos(v.config.NodeUUID)
if err != nil {
log.Printf("Failed to get prescreening UTXOs: %v", err)
context.JSON(http.StatusInternalServerError, gin.H{
"status": "ERROR",
"reason": "Failed to get prescreening UTXOs",
Expand Down Expand Up @@ -654,18 +655,18 @@ type PayerInfo struct {

// NOTE: In a real application, you'd want to use the authentication context to pull out this information. It's not actually
// always Alice sending the money ;-).
func getPayerInfo(options uma.PayerDataOptions) PayerInfo {
func (v *Vasp1) getPayerInfo(options uma.PayerDataOptions, context *gin.Context) PayerInfo {
var name string
if options.NameRequired {
name = "Alice FakeName"
}
var email string
if options.EmailRequired {
email = "$alice@vasp1.com"
email = "$alice@" + v.getVaspDomain(context)
}
return PayerInfo{
Name: &name,
Email: &email,
Identifier: "$alice@vasp1.com",
Identifier: "$alice@" + v.getVaspDomain(context),
}
}
4 changes: 2 additions & 2 deletions examples/uma-server/vasp2.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (v *Vasp2) handleLnurlPayreq(context *gin.Context) {
return
}

lsClient := services.NewLightsparkClient(v.config.ApiClientID, v.config.ApiClientSecret, &v.config.ClientBaseURL)
lsClient := services.NewLightsparkClient(v.config.ApiClientID, v.config.ApiClientSecret, v.config.ClientBaseURL)
lsInvoice, err := lsClient.CreateLnurlInvoice(v.config.NodeUUID, int64(amountMsats), metadata, nil)

if err != nil {
Expand Down Expand Up @@ -358,7 +358,7 @@ func (v *Vasp2) handleUmaPayreq(context *gin.Context) {
return
}

lsClient := services.NewLightsparkClient(v.config.ApiClientID, v.config.ApiClientSecret, &v.config.ClientBaseURL)
lsClient := services.NewLightsparkClient(v.config.ApiClientID, v.config.ApiClientSecret, v.config.ClientBaseURL)
expirySecs := int32(600) // Expire in 10 minutes
invoiceCreator := lsuma.LightsparkClientUmaInvoiceCreator{
LightsparkClient: *lsClient,
Expand Down

0 comments on commit f49bb51

Please sign in to comment.