From 48c4dc0c3b8557b47062e41904efb6aaf2d0d85d Mon Sep 17 00:00:00 2001 From: Zhen Lu Date: Mon, 16 Sep 2024 13:59:17 -0700 Subject: [PATCH 1/5] Add create invoice --- examples/uma-server/go.mod | 32 ++++++------ examples/uma-server/go.sum | 70 +++++++++++++------------ examples/uma-server/server.go | 10 ++-- examples/uma-server/vasp1.go | 15 +++--- examples/uma-server/vasp2.go | 96 +++++++++++++++++++++++++++++++++++ 5 files changed, 165 insertions(+), 58 deletions(-) diff --git a/examples/uma-server/go.mod b/examples/uma-server/go.mod index 4c548cd..128b613 100644 --- a/examples/uma-server/go.mod +++ b/examples/uma-server/go.mod @@ -6,43 +6,45 @@ toolchain go1.21.0 require ( github.com/ethereum/go-ethereum v1.13.15 - github.com/gin-gonic/gin v1.9.1 + github.com/gin-gonic/gin v1.10.0 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.2.0 + github.com/lightsparkdev/go-sdk v0.15.1 + github.com/uma-universal-money-address/uma-go-sdk v1.3.1 ) 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/bytedance/sonic v1.11.6 // indirect + github.com/bytedance/sonic/loader v0.1.1 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/iasm v0.2.0 // 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 + github.com/gabriel-vasile/mimetype v1.4.3 // 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/go-playground/validator/v10 v10.20.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 + github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/leodido/go-urn v1.4.0 // indirect github.com/lightsparkdev/lightspark-crypto-uniffi/lightspark-crypto-go v0.4.1 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.11 // indirect - golang.org/x/arch v0.3.0 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + golang.org/x/arch v0.8.0 // indirect golang.org/x/crypto v0.23.0 // indirect golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect - golang.org/x/net v0.21.0 // indirect + golang.org/x/net v0.25.0 // indirect golang.org/x/sys v0.20.0 // indirect golang.org/x/text v0.15.0 // indirect - google.golang.org/protobuf v1.30.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/uma-server/go.sum b/examples/uma-server/go.sum index 07cfcad..c9c7e87 100644 --- a/examples/uma-server/go.sum +++ b/examples/uma-server/go.sum @@ -124,9 +124,10 @@ github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= -github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= -github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= +github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= +github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= @@ -134,9 +135,6 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= @@ -146,6 +144,10 @@ github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMn github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cloudflare-go v0.14.0/go.mod h1:EnwdgGMaFOruiPZRFSgn+TsQ3hQ7C/YWzIGLeu5c304= github.com/cloudflare/cloudflare-go v0.79.0/go.mod h1:gkHQf9xEubaQPEuerBuoinR9P8bf8a05Lq0X6WKy1Oc= +github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= +github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cockroachdb/datadriven v1.0.0/go.mod h1:5Ib8Meh+jk1RlHIXej6Pzevx/NLlNvQB9pmSBZErGA4= github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= @@ -236,8 +238,8 @@ github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzP github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= -github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= -github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61/go.mod h1:Q0X6pkwTILDlzrGEckF6HKjXe48EgsY/l7K7vhY4MW8= github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc= github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= @@ -250,8 +252,8 @@ github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NB github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM= -github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= -github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE= github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24= github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= @@ -285,8 +287,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= -github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= +github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -485,10 +487,11 @@ github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9 github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= -github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/klauspost/crc32 v0.0.0-20161016154125-cb6bfca970f6/go.mod h1:+ZoRqAPRLkC4NPOvfYeR5KNOrY6TD+/sAC3HXPZgDYg= github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -507,8 +510,8 @@ github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvf github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= -github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= -github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lightsparkdev/lightspark-crypto-uniffi/lightspark-crypto-go v0.4.1 h1:tf7gkzIJKJuVGGheP+2hrJe/638BXVr9fjf7XiQhXXQ= github.com/lightsparkdev/lightspark-crypto-uniffi/lightspark-crypto-go v0.4.1/go.mod h1:iecorZruwbWKa6I5vjGQrAR9Smie8Rke4Vy6Pg8h0NU= @@ -533,8 +536,8 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -588,8 +591,8 @@ github.com/opentracing/opentracing-go v1.0.3-0.20180606204148-bd9c31933947/go.mo github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/paulbellamy/ratecounter v0.2.0/go.mod h1:Hfx1hDpSGoqxkVVpBi/IlYD7kChlfo5C6hzIHwPqfFE= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= -github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/peterh/liner v1.0.1-0.20180619022028-8c1271fcf47f/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= @@ -682,6 +685,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -693,9 +697,9 @@ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1F github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/supranational/blst v0.3.8-0.20220526154634-513d2456b344/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= @@ -711,10 +715,10 @@ github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:s github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= 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.2.0 h1:2PgAxHCu8txCaPs17nVKhNjfAlKsekdp40Z6EbitwMg= -github.com/uma-universal-money-address/uma-go-sdk v1.2.0/go.mod h1:dXNOwmUxZzJ6szhn8Cj3ajwnuUrr27rYIIRntWbynaU= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/uma-universal-money-address/uma-go-sdk v1.3.1 h1:4VN+jzzr3d0GMyrH5kGG1CUSRvVFLWMrjpGWtFN4IRw= +github.com/uma-universal-money-address/uma-go-sdk v1.3.1/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= @@ -756,8 +760,8 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/ go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= -golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= +golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -894,8 +898,8 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20170207211851-4464e7848382/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -987,7 +991,6 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1199,8 +1202,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -1239,6 +1242,7 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= diff --git a/examples/uma-server/server.go b/examples/uma-server/server.go index c70ffef..51de90b 100644 --- a/examples/uma-server/server.go +++ b/examples/uma-server/server.go @@ -2,13 +2,14 @@ package main import ( "fmt" - "github.com/gin-gonic/gin" - "github.com/uma-universal-money-address/uma-go-sdk/uma" - umautils "github.com/uma-universal-money-address/uma-go-sdk/uma/utils" "log" "net/http" "os" "time" + + "github.com/gin-gonic/gin" + "github.com/uma-universal-money-address/uma-go-sdk/uma" + umautils "github.com/uma-universal-money-address/uma-go-sdk/uma/utils" ) /** @@ -66,6 +67,9 @@ func main() { engine.POST("/api/uma/payreq/:uuid", func(c *gin.Context) { vasp2.handleUmaPayreq(c) }) + engine.POST("/api/uma/create_invoice/:uuid", func(c *gin.Context) { + vasp2.handleCreateInvoice(c) + }) // End VASP2 Routes // Shared: diff --git a/examples/uma-server/vasp1.go b/examples/uma-server/vasp1.go index ce7db09..7c898bc 100644 --- a/examples/uma-server/vasp1.go +++ b/examples/uma-server/vasp1.go @@ -5,13 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/gin-gonic/gin" - "github.com/lightsparkdev/go-sdk/objects" - "github.com/lightsparkdev/go-sdk/services" - "github.com/lightsparkdev/go-sdk/utils" - "github.com/uma-universal-money-address/uma-go-sdk/uma" - umaprotocol "github.com/uma-universal-money-address/uma-go-sdk/uma/protocol" - umautils "github.com/uma-universal-money-address/uma-go-sdk/uma/utils" "io" "log" "net/http" @@ -20,6 +13,14 @@ import ( "strconv" "strings" "time" + + "github.com/gin-gonic/gin" + "github.com/lightsparkdev/go-sdk/objects" + "github.com/lightsparkdev/go-sdk/services" + "github.com/lightsparkdev/go-sdk/utils" + "github.com/uma-universal-money-address/uma-go-sdk/uma" + umaprotocol "github.com/uma-universal-money-address/uma-go-sdk/uma/protocol" + umautils "github.com/uma-universal-money-address/uma-go-sdk/uma/utils" ) // Vasp1 is an implementation of the sending VASP in the UMA protocol. diff --git a/examples/uma-server/vasp2.go b/examples/uma-server/vasp2.go index 421795b..bea1d12 100644 --- a/examples/uma-server/vasp2.go +++ b/examples/uma-server/vasp2.go @@ -14,6 +14,7 @@ import ( "github.com/lightsparkdev/go-sdk/objects" "github.com/lightsparkdev/go-sdk/services" "github.com/uma-universal-money-address/uma-go-sdk/uma" + "github.com/uma-universal-money-address/uma-go-sdk/uma/protocol" umaprotocol "github.com/uma-universal-money-address/uma-go-sdk/uma/protocol" umautils "github.com/uma-universal-money-address/uma-go-sdk/uma/utils" ) @@ -486,6 +487,101 @@ func (v *Vasp2) handleUtxoCallback(context *gin.Context) { context.Status(http.StatusOK) } +func (v *Vasp2) handleCreateInvoice(context *gin.Context) { + uuid := context.Param("uuid") + if uuid != v.config.UserID { + context.JSON(http.StatusNotFound, gin.H{ + "status": "ERROR", + "reason": fmt.Sprintf("User not found: %s", uuid), + }) + return + } + + var requestBody struct { + Amount int64 `json:"amount"` + CurrencyCode string `json:"currency_code"` + } + if err := context.BindJSON(&requestBody); err != nil { + context.JSON(http.StatusBadRequest, gin.H{ + "status": "ERROR", + "reason": fmt.Sprintf("Invalid request body: %v", err), + }) + return + } + + if requestBody.CurrencyCode == "" { + requestBody.CurrencyCode = "SAT" + } + + receiverCurrencies := []umaprotocol.Currency{} + currencies := []umaprotocol.Currency{UsdCurrency, SatsCurrency} + for _, currency := range currencies { + if currency.Code == requestBody.CurrencyCode { + receiverCurrencies = append(receiverCurrencies, currency) + } + } + if len(receiverCurrencies) == 0 { + context.JSON(http.StatusBadRequest, gin.H{ + "status": "ERROR", + "reason": fmt.Sprintf("User does not support currency %s", requestBody.CurrencyCode), + }) + return + } + currency := receiverCurrencies[0] + + twoDaysFromNow := time.Now().Add(48 * time.Hour) + callback := v.getLnurlpCallback(context) + + payerDataOptions := umaprotocol.CounterPartyDataOptions{ + umaprotocol.CounterPartyDataFieldName.String(): {Mandatory: false}, + umaprotocol.CounterPartyDataFieldEmail.String(): {Mandatory: false}, + umaprotocol.CounterPartyDataFieldIdentifier.String(): {Mandatory: true}, + umaprotocol.CounterPartyDataFieldCompliance.String(): {Mandatory: true}, + } + + privateKey, err := v.config.UmaSigningPrivKeyBytes() + if err != nil { + context.JSON(http.StatusInternalServerError, gin.H{ + "status": "ERROR", + "reason": fmt.Sprintf("Failed to get UMA signing private key: %v", err), + }) + return + } + + invoice, err := uma.CreateUmaInvoice( + "$" + v.config.Username+"@"+v.getVaspDomain(context), + uint64(requestBody.Amount), + protocol.InvoiceCurrency{ + Code: currency.Code, + Decimals: uint8(currency.Decimals), + Symbol: currency.Symbol, + Name: currency.Name, + }, + uint64(twoDaysFromNow.Unix()), + callback, + true, + &payerDataOptions, + nil, + nil, + nil, + nil, + privateKey, + ) + + invoiceString, err := invoice.ToBech32String() + if err != nil { + context.JSON(http.StatusInternalServerError, gin.H{ + "status": "ERROR", + "reason": fmt.Sprintf("Failed to convert invoice to bech32 string: %v", err), + }) + return + } + + context.JSON(http.StatusOK, gin.H{ + "invoice": invoiceString, + }) +} + func (v *Vasp2) getVaspDomain(context *gin.Context) string { envVaspDomain := v.config.OwnVaspDomain if envVaspDomain != "" { From 7bf0e1fb04f54d509bab8276dd098c64f008b67c Mon Sep 17 00:00:00 2001 From: Zhen Lu Date: Wed, 18 Sep 2024 11:09:21 -0700 Subject: [PATCH 2/5] Request vasp2 --- examples/uma-server/server.go | 4 + examples/uma-server/vasp2.go | 184 ++++++++++++++++++++++++++++------ 2 files changed, 157 insertions(+), 31 deletions(-) diff --git a/examples/uma-server/server.go b/examples/uma-server/server.go index 51de90b..5fc0632 100644 --- a/examples/uma-server/server.go +++ b/examples/uma-server/server.go @@ -70,6 +70,10 @@ func main() { engine.POST("/api/uma/create_invoice/:uuid", func(c *gin.Context) { vasp2.handleCreateInvoice(c) }) + engine.POST("/api/uma/create_and_send_invoice/:uuid", func(c *gin.Context) { + vasp2.handleCreateAndSendInvoice(c) + }) + // End VASP2 Routes // Shared: diff --git a/examples/uma-server/vasp2.go b/examples/uma-server/vasp2.go index bea1d12..5465ec7 100644 --- a/examples/uma-server/vasp2.go +++ b/examples/uma-server/vasp2.go @@ -1,9 +1,11 @@ package main import ( + "bytes" "encoding/json" "errors" "fmt" + "io" "net/http" "os" "strings" @@ -14,7 +16,6 @@ import ( "github.com/lightsparkdev/go-sdk/objects" "github.com/lightsparkdev/go-sdk/services" "github.com/uma-universal-money-address/uma-go-sdk/uma" - "github.com/uma-universal-money-address/uma-go-sdk/uma/protocol" umaprotocol "github.com/uma-universal-money-address/uma-go-sdk/uma/protocol" umautils "github.com/uma-universal-money-address/uma-go-sdk/uma/utils" ) @@ -136,6 +137,14 @@ func (v *Vasp2) handleNonUmaLnurlRequest(context *gin.Context, lnurlpRequest uma nil, ) + if err != nil { + context.JSON(http.StatusInternalServerError, gin.H{ + "status": "ERROR", + "reason": err.Error(), + }) + return + } + context.JSON(http.StatusOK, response) } @@ -281,6 +290,14 @@ func (v *Vasp2) handleLnurlPayreq(context *gin.Context) { nil, ) + if err != nil { + context.JSON(http.StatusInternalServerError, gin.H{ + "status": "ERROR", + "reason": err.Error(), + }) + return + } + context.JSON(http.StatusOK, payreqResponse) } @@ -488,25 +505,145 @@ func (v *Vasp2) handleUtxoCallback(context *gin.Context) { } func (v *Vasp2) handleCreateInvoice(context *gin.Context) { - uuid := context.Param("uuid") - if uuid != v.config.UserID { - context.JSON(http.StatusNotFound, gin.H{ + invoice, err := v.createInvoice(context, false) + if err != nil { + context.JSON(http.StatusInternalServerError, gin.H{ "status": "ERROR", - "reason": fmt.Sprintf("User not found: %s", uuid), + "reason": fmt.Sprintf("Failed to create invoice: %v", err), + }) + return + } + + invoiceString, err := invoice.ToBech32String() + if err != nil { + context.JSON(http.StatusInternalServerError, gin.H{ + "status": "ERROR", + "reason": fmt.Sprintf("Failed to convert invoice to bech32 string: %v", err), + }) + return + } + + context.JSON(http.StatusOK, invoiceString) +} + +func (v *Vasp2) handleCreateAndSendInvoice(context *gin.Context) { + invoice, err := v.createInvoice(context, true) + if err != nil { + context.JSON(http.StatusInternalServerError, gin.H{ + "status": "ERROR", + "reason": fmt.Sprintf("Failed to create invoice: %v", err), + }) + return + } + + // Send the invoice to the sender. + + // Step 1: Get the sender's domain from sender's UMA address. + senderUma := *invoice.SenderUma + senderVaspDomain, err := uma.GetVaspDomainFromUmaAddress(senderUma) + if strings.Contains(senderVaspDomain, "local") { + senderVaspDomain = "http://" + senderVaspDomain + } else { + senderVaspDomain = "https://" + senderVaspDomain + } + if err != nil { + context.JSON(http.StatusInternalServerError, gin.H{ + "status": "ERROR", + "reason": fmt.Sprintf("Failed to get sender's VASP domain: %v", err), }) return } + // Step 2: Query sender's domain /.well-known/uma-configruration to get sender's request URL. + // Make a GET request to the sender's /.well-known/uma-configuration endpoint. + url := senderVaspDomain + "/.well-known/uma-configuration" + + resp, err := http.Get(url) + if err != nil { + fmt.Println("Error making GET request:", err) + return + } + defer resp.Body.Close() + + type UmaConfig struct { + UmaRequestEndpoint string `json:"uma_request_endpoint"` + } + + var config UmaConfig + + // Read the response body + body, err := io.ReadAll(resp.Body) + if err != nil { + fmt.Println("Error reading response body:", err) + return + } + + // Parse the JSON response + err = json.Unmarshal(body, &config) + if err != nil { + fmt.Println("Error parsing JSON response:", err) + return + } + + requestEndpoint := config.UmaRequestEndpoint + + requestURL := senderVaspDomain + requestEndpoint + + // Step 3: Send the invoice to the sender's request URL. + // Make a POST request to the sender's request URL. + // The invoice is sent in the request body json "invoice" field. + + invoiceString, err := invoice.ToBech32String() + if err != nil { + context.JSON(http.StatusInternalServerError, gin.H{ + "status": "ERROR", + "reason": fmt.Sprintf("Failed to convert invoice to bech32 string: %v", err), + }) + return + } + + requestBody, err := json.Marshal(map[string]string{ + "invoice": invoiceString, + }) + + if err != nil { + context.JSON(http.StatusInternalServerError, gin.H{ + "status": "ERROR", + "reason": fmt.Sprintf("Error marshalling request body: %v", err), + }) + return + } + + resp, err = http.Post(requestURL, "application/json", bytes.NewBuffer(requestBody)) + if err != nil { + context.JSON(http.StatusInternalServerError, gin.H{ + "status": "ERROR", + "reason": fmt.Sprintf("Error making POST request: %v", err), + }) + return + } + defer resp.Body.Close() + + context.Status(http.StatusOK) +} + +func (v *Vasp2) createInvoice(context *gin.Context, request bool) (*umaprotocol.UmaInvoice, error) { + uuid := context.Param("uuid") + if uuid != v.config.UserID { + return nil, fmt.Errorf("user not found: %s", uuid) + } + var requestBody struct { Amount int64 `json:"amount"` CurrencyCode string `json:"currency_code"` + SenderUma *string `json:"sender_uma"` } if err := context.BindJSON(&requestBody); err != nil { - context.JSON(http.StatusBadRequest, gin.H{ - "status": "ERROR", - "reason": fmt.Sprintf("Invalid request body: %v", err), - }) - return + return nil, err + } + + if requestBody.SenderUma == nil && request { + return nil, fmt.Errorf("sender_uma is required") } if requestBody.CurrencyCode == "" { @@ -521,11 +658,7 @@ func (v *Vasp2) handleCreateInvoice(context *gin.Context) { } } if len(receiverCurrencies) == 0 { - context.JSON(http.StatusBadRequest, gin.H{ - "status": "ERROR", - "reason": fmt.Sprintf("User does not support currency %s", requestBody.CurrencyCode), - }) - return + return nil, fmt.Errorf("user does not support currency %s", requestBody.CurrencyCode) } currency := receiverCurrencies[0] @@ -541,17 +674,13 @@ func (v *Vasp2) handleCreateInvoice(context *gin.Context) { privateKey, err := v.config.UmaSigningPrivKeyBytes() if err != nil { - context.JSON(http.StatusInternalServerError, gin.H{ - "status": "ERROR", - "reason": fmt.Sprintf("Failed to get UMA signing private key: %v", err), - }) - return + return nil, err } invoice, err := uma.CreateUmaInvoice( "$" + v.config.Username+"@"+v.getVaspDomain(context), uint64(requestBody.Amount), - protocol.InvoiceCurrency{ + umaprotocol.InvoiceCurrency{ Code: currency.Code, Decimals: uint8(currency.Decimals), Symbol: currency.Symbol, @@ -564,22 +693,15 @@ func (v *Vasp2) handleCreateInvoice(context *gin.Context) { nil, nil, nil, - nil, + requestBody.SenderUma, privateKey, ) - invoiceString, err := invoice.ToBech32String() if err != nil { - context.JSON(http.StatusInternalServerError, gin.H{ - "status": "ERROR", - "reason": fmt.Sprintf("Failed to convert invoice to bech32 string: %v", err), - }) - return + return nil, err } - context.JSON(http.StatusOK, gin.H{ - "invoice": invoiceString, - }) + return invoice, nil } func (v *Vasp2) getVaspDomain(context *gin.Context) string { From 51ceb24a41852b30b68d2336b60301a4442a1f31 Mon Sep 17 00:00:00 2001 From: Zhen Lu Date: Wed, 18 Sep 2024 14:32:47 -0700 Subject: [PATCH 3/5] Directly use request endpoint. --- examples/uma-server/vasp2.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/uma-server/vasp2.go b/examples/uma-server/vasp2.go index 5465ec7..7568074 100644 --- a/examples/uma-server/vasp2.go +++ b/examples/uma-server/vasp2.go @@ -586,9 +586,7 @@ func (v *Vasp2) handleCreateAndSendInvoice(context *gin.Context) { } requestEndpoint := config.UmaRequestEndpoint - - requestURL := senderVaspDomain + requestEndpoint - + // Step 3: Send the invoice to the sender's request URL. // Make a POST request to the sender's request URL. // The invoice is sent in the request body json "invoice" field. @@ -614,7 +612,7 @@ func (v *Vasp2) handleCreateAndSendInvoice(context *gin.Context) { return } - resp, err = http.Post(requestURL, "application/json", bytes.NewBuffer(requestBody)) + resp, err = http.Post(requestEndpoint, "application/json", bytes.NewBuffer(requestBody)) if err != nil { context.JSON(http.StatusInternalServerError, gin.H{ "status": "ERROR", From 5d610cee46646f0a39ccbb5209d72416cd669a86 Mon Sep 17 00:00:00 2001 From: Zhen Lu Date: Wed, 18 Sep 2024 16:31:30 -0700 Subject: [PATCH 4/5] Fmt --- examples/uma-server/vasp2.go | 52 ++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/examples/uma-server/vasp2.go b/examples/uma-server/vasp2.go index 7568074..4abe7a0 100644 --- a/examples/uma-server/vasp2.go +++ b/examples/uma-server/vasp2.go @@ -559,34 +559,34 @@ func (v *Vasp2) handleCreateAndSendInvoice(context *gin.Context) { url := senderVaspDomain + "/.well-known/uma-configuration" resp, err := http.Get(url) - if err != nil { - fmt.Println("Error making GET request:", err) - return - } + if err != nil { + fmt.Println("Error making GET request:", err) + return + } defer resp.Body.Close() - type UmaConfig struct { - UmaRequestEndpoint string `json:"uma_request_endpoint"` - } + type UmaConfig struct { + UmaRequestEndpoint string `json:"uma_request_endpoint"` + } - var config UmaConfig + var config UmaConfig // Read the response body body, err := io.ReadAll(resp.Body) - if err != nil { - fmt.Println("Error reading response body:", err) - return - } - - // Parse the JSON response - err = json.Unmarshal(body, &config) - if err != nil { - fmt.Println("Error parsing JSON response:", err) - return - } + if err != nil { + fmt.Println("Error reading response body:", err) + return + } + + // Parse the JSON response + err = json.Unmarshal(body, &config) + if err != nil { + fmt.Println("Error parsing JSON response:", err) + return + } requestEndpoint := config.UmaRequestEndpoint - + // Step 3: Send the invoice to the sender's request URL. // Make a POST request to the sender's request URL. // The invoice is sent in the request body json "invoice" field. @@ -632,9 +632,9 @@ func (v *Vasp2) createInvoice(context *gin.Context, request bool) (*umaprotocol. } var requestBody struct { - Amount int64 `json:"amount"` - CurrencyCode string `json:"currency_code"` - SenderUma *string `json:"sender_uma"` + Amount int64 `json:"amount"` + CurrencyCode string `json:"currency_code"` + SenderUma *string `json:"sender_uma"` } if err := context.BindJSON(&requestBody); err != nil { return nil, err @@ -676,13 +676,13 @@ func (v *Vasp2) createInvoice(context *gin.Context, request bool) (*umaprotocol. } invoice, err := uma.CreateUmaInvoice( - "$" + v.config.Username+"@"+v.getVaspDomain(context), + "$"+v.config.Username+"@"+v.getVaspDomain(context), uint64(requestBody.Amount), umaprotocol.InvoiceCurrency{ Code: currency.Code, Decimals: uint8(currency.Decimals), - Symbol: currency.Symbol, - Name: currency.Name, + Symbol: currency.Symbol, + Name: currency.Name, }, uint64(twoDaysFromNow.Unix()), callback, From d7e08567869b26cd0df7441d11d5a618d99b5ed0 Mon Sep 17 00:00:00 2001 From: Zhen Lu Date: Wed, 18 Sep 2024 16:32:00 -0700 Subject: [PATCH 5/5] Fix --- examples/uma-server/vasp2.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/uma-server/vasp2.go b/examples/uma-server/vasp2.go index 4abe7a0..2f03b9c 100644 --- a/examples/uma-server/vasp2.go +++ b/examples/uma-server/vasp2.go @@ -560,7 +560,7 @@ func (v *Vasp2) handleCreateAndSendInvoice(context *gin.Context) { resp, err := http.Get(url) if err != nil { - fmt.Println("Error making GET request:", err) + fmt.Println("Error fetching sending VASP configuration:", err) return } defer resp.Body.Close()