Skip to content

Commit

Permalink
[uma] Update invoice creators (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyav authored Jul 19, 2024
1 parent 3fc1af1 commit e7b0618
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
5 changes: 3 additions & 2 deletions examples/uma-server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ toolchain go1.21.0
require (
github.com/ethereum/go-ethereum v1.13.15
github.com/gin-gonic/gin v1.9.1
github.com/google/uuid v1.3.1
github.com/google/uuid v1.6.0
github.com/lightsparkdev/go-sdk v0.10.0
github.com/uma-universal-money-address/uma-go-sdk v1.0.2
github.com/uma-universal-money-address/uma-go-sdk v1.2.0
)

require (
github.com/DataDog/zstd v1.5.5 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/decred/dcrd/bech32 v1.1.4 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/ecies/go/v2 v2.0.9 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
Expand Down
10 changes: 6 additions & 4 deletions examples/uma-server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo=
github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/decred/dcrd/bech32 v1.1.4 h1:wFlLM7Oic0MlIhQZdCQhdIqVc4CNaQ0vNR9fgCoWfe0=
github.com/decred/dcrd/bech32 v1.1.4/go.mod h1:jliqHZmCbVfT06Lh1mQywEKFVidRclbBJIUmwdoKhu0=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
Expand Down Expand Up @@ -386,8 +388,8 @@ github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go v0.0.0-20161107002406-da06d194a00e/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
Expand Down Expand Up @@ -711,8 +713,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 v1.0.2 h1:d0XYTcsc665v3b8nLSTrhS1Am+4oWB6QQzv3BnMaM8g=
github.com/uma-universal-money-address/uma-go-sdk v1.0.2/go.mod h1:OimSKjRNT7Wm2lA0Q9C0DmxsMvqBickucUjtQmB8Cl8=
github.com/uma-universal-money-address/uma-go-sdk v1.2.0 h1:2PgAxHCu8txCaPs17nVKhNjfAlKsekdp40Z6EbitwMg=
github.com/uma-universal-money-address/uma-go-sdk v1.2.0/go.mod h1:dXNOwmUxZzJ6szhn8Cj3ajwnuUrr27rYIIRntWbynaU=
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
20 changes: 17 additions & 3 deletions examples/uma-server/vasp2.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/ethereum/go-ethereum/log"
"github.com/gin-gonic/gin"
"github.com/lightsparkdev/go-sdk/objects"
"github.com/lightsparkdev/go-sdk/services"
"github.com/uma-universal-money-address/uma-go-sdk/uma"
umaprotocol "github.com/uma-universal-money-address/uma-go-sdk/uma/protocol"
Expand Down Expand Up @@ -531,10 +532,23 @@ type LightsparkClientUmaInvoiceCreator struct {
NodeId string
// ExpirySecs: the number of seconds until the invoice expires.
ExpirySecs *int32
// EnableUmaAnalytics: A flag indicating whether UMA analytics should be enabled. If `true`,
// the receiver identifier will be hashed using a monthly-rotated seed and used for anonymized
// analysis.
EnableUmaAnalytics bool
// SigningPrivateKey: Optional, the receiver's signing private key. Used to hash the receiver
// identifier if UMA analytics is enabled.
SigningPrivateKey *[]byte
}

func (l LightsparkClientUmaInvoiceCreator) CreateInvoice(amountMsats int64, metadata string) (*string, error) {
invoice, err := l.LightsparkClient.CreateUmaInvoice(l.NodeId, amountMsats, metadata, l.ExpirySecs)
func (l LightsparkClientUmaInvoiceCreator) CreateInvoice(amountMsats int64, metadata string, receiverIdentifier *string) (*string, error) {
var invoice *objects.Invoice
var err error
if l.EnableUmaAnalytics && l.SigningPrivateKey != nil {
invoice, err = l.LightsparkClient.CreateUmaInvoiceWithReceiverIdentifier(l.NodeId, amountMsats, metadata, l.ExpirySecs, l.SigningPrivateKey, receiverIdentifier)
} else {
invoice, err = l.LightsparkClient.CreateUmaInvoice(l.NodeId, amountMsats, metadata, l.ExpirySecs)
}
if err != nil {
return nil, err
}
Expand All @@ -549,7 +563,7 @@ type LightsparkClientLnurlInvoiceCreator struct {
ExpirySecs *int32
}

func (l LightsparkClientLnurlInvoiceCreator) CreateInvoice(amountMsats int64, metadata string) (*string, error) {
func (l LightsparkClientLnurlInvoiceCreator) CreateInvoice(amountMsats int64, metadata string, receiverIdentifier *string) (*string, error) {
invoice, err := l.LightsparkClient.CreateLnurlInvoice(l.NodeId, amountMsats, metadata, l.ExpirySecs)
if err != nil {
return nil, err
Expand Down
18 changes: 16 additions & 2 deletions uma/uma.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package uma

import (
"github.com/lightsparkdev/go-sdk/objects"
"github.com/lightsparkdev/go-sdk/services"
)

Expand All @@ -14,10 +15,23 @@ type LightsparkClientUmaInvoiceCreator struct {
NodeId string
// ExpirySecs: the number of seconds until the invoice expires.
ExpirySecs *int32
// EnableUmaAnalytics: A flag indicating whether UMA analytics should be enabled. If `true`,
// the receiver identifier will be hashed using a monthly-rotated seed and used for anonymized
// analysis.
EnableUmaAnalytics bool
// SigningPrivateKey: Optional, the receiver's signing private key. Used to hash the receiver
// identifier if UMA analytics is enabled.
SigningPrivateKey *[]byte
}

func (l LightsparkClientUmaInvoiceCreator) CreateUmaInvoice(amountMsats int64, metadata string) (*string, error) {
invoice, err := l.LightsparkClient.CreateUmaInvoice(l.NodeId, amountMsats, metadata, l.ExpirySecs)
func (l LightsparkClientUmaInvoiceCreator) CreateInvoice(amountMsats int64, metadata string, receiverIdentifier *string) (*string, error) {
var invoice *objects.Invoice
var err error
if l.EnableUmaAnalytics && l.SigningPrivateKey != nil {
invoice, err = l.LightsparkClient.CreateUmaInvoiceWithReceiverIdentifier(l.NodeId, amountMsats, metadata, l.ExpirySecs, l.SigningPrivateKey, receiverIdentifier)
} else {
invoice, err = l.LightsparkClient.CreateUmaInvoice(l.NodeId, amountMsats, metadata, l.ExpirySecs)
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e7b0618

Please sign in to comment.