From 04ea6cd6d7432c14c00e2e3d529a157157f79d20 Mon Sep 17 00:00:00 2001 From: peterlimg Date: Tue, 9 Apr 2024 16:04:10 +1000 Subject: [PATCH 1/9] Add zauth cmd to split keys and setup zauth server --- cmd/zauth.go | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 11 ++++-- go.sum | 55 +++++++++++++++++++++++++--- 3 files changed, 158 insertions(+), 9 deletions(-) create mode 100644 cmd/zauth.go diff --git a/cmd/zauth.go b/cmd/zauth.go new file mode 100644 index 00000000..4832cbb9 --- /dev/null +++ b/cmd/zauth.go @@ -0,0 +1,101 @@ +package cmd + +import ( + "bytes" + "encoding/json" + "log" + "net/http" + + "github.com/0chain/gosdk/zcncore" + "github.com/pkg/errors" + "github.com/spf13/cobra" +) + +type splitWallet struct { + ClientID string `json:"client_id"` + ClientKey string `json:"client_key"` + PublicKey string `json:"public_key"` + PrivateKey string `json:"private_key"` + PeerPublicKey string `json:"peer_public_key"` +} + +func callZauthSetup(serverAddr string, splitWallet splitWallet) error { + // Add your code here + endpoint := serverAddr + "/setup" + wData, err := json.Marshal(splitWallet) + if err != nil { + return errors.Wrap(err, "failed to marshal split wallet") + } + + req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(wData)) + if err != nil { + return errors.Wrap(err, "failed to create HTTP request") + } + + req.Header.Set("Content-Type", "application/json") + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return errors.Wrap(err, "failed to send HTTP request") + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return errors.Errorf("unexpected status code: %d", resp.StatusCode) + } + + return nil +} + +var zauthCmd = &cobra.Command{ + Use: "zauth", + Short: "Enable zauth", + Long: `Enable zauth to sign transactions and messages, setup split keys and configure the zauth service.`, + Run: func(cmd *cobra.Command, args []string) { + // Add your code here + serverAddr, err := cmd.Flags().GetString("server") + if err != nil { + log.Fatalf("Could not find zauth server address") + } + + // update or setup the zauth server address + cfgConfig.Set("zauth.server", serverAddr) + if err := cfgConfig.WriteConfig(); err != nil { + log.Fatalf("Could not save config: %v", err) + } + + // figure out what is the private key to use + // from the web-apps, we can see the private key is the first key's private key + if clientWallet == nil { + log.Fatalf("Wallet is initialized yet") + } + + sw, err := zcncore.SplitKeysWallet(clientWallet.Keys[0].PrivateKey, 2) + if err != nil { + log.Fatalf("Failed to split keys: %v", err) + } + + // call gosdk to connect and setup the split keys + // zcncore.SplitKeys() + if err := callZauthSetup(serverAddr, splitWallet{ + ClientID: sw.ClientID, + ClientKey: sw.ClientKey, + PublicKey: sw.Keys[1].PublicKey, + PrivateKey: sw.Keys[1].PrivateKey, + PeerPublicKey: sw.Keys[0].PublicKey, + }); err != nil { + log.Fatalf("Failed to setup zauth server: %v", err) + } + + // TODO: remove the private key from the local wallet + + log.Printf("Setup zauth server successfully") + }, +} + +func init() { + rootCmd.AddCommand(zauthCmd) + zauthCmd.PersistentFlags().String("server", "s", "The zauth server address") + zauthCmd.MarkFlagRequired("server") +} diff --git a/go.mod b/go.mod index 8e68a45c..f86b29c7 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/0chain/zwalletcli go 1.21 require ( - github.com/0chain/gosdk v1.12.1 + github.com/0chain/gosdk v1.13.4-0.20240409054333-ccc75a18e0b6 github.com/ethereum/go-ethereum v1.13.2 github.com/icza/bitio v1.1.0 github.com/olekukonko/tablewriter v0.0.5 @@ -20,6 +20,7 @@ require ( github.com/DataDog/zstd v1.5.2 // indirect github.com/Luzifer/go-openssl/v3 v3.1.0 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/andybalholm/brotli v1.0.5 // indirect github.com/benbjohnson/clock v1.3.0 // indirect github.com/bits-and-blooms/bitset v1.9.0 // indirect github.com/btcsuite/btcd v0.23.4 // indirect @@ -49,9 +50,10 @@ require ( github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/herumi/bls-go-binary v1.31.0 // indirect + github.com/hitenjain14/fasthttp v0.0.0-20240229173600-722723e15e17 // indirect github.com/holiman/uint256 v1.2.3 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/klauspost/compress v1.16.7 // indirect + github.com/klauspost/compress v1.17.0 // indirect github.com/klauspost/cpuid/v2 v2.2.6 // indirect github.com/klauspost/reedsolomon v1.11.8 // indirect github.com/lithammer/shortuuid/v3 v3.0.7 // indirect @@ -83,6 +85,9 @@ require ( github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/tyler-smith/go-bip39 v1.1.0 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasthttp v1.51.0 // indirect + github.com/ybbus/jsonrpc/v3 v3.1.5 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect go.dedis.ch/fixbuf v1.0.3 // indirect go.dedis.ch/kyber/v3 v3.1.0 // indirect @@ -90,7 +95,7 @@ require ( go.uber.org/goleak v1.2.1 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.16.0 // indirect + golang.org/x/crypto v0.17.0 // indirect golang.org/x/exp v0.0.0-20230810033253-352e893a4cad // indirect golang.org/x/mod v0.14.0 // indirect golang.org/x/sync v0.5.0 // indirect diff --git a/go.sum b/go.sum index 255165b7..f272901c 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20 h1:c46aB5l0xbD7nc/ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20/go.mod h1:gbmUdgY4Gu2jKmnYnHr8533gcokviV3MDMs8wNk74sk= github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM= github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc= -github.com/0chain/gosdk v1.12.1 h1:U4XX87tao+J7rqiOdVBa1bWh/SKz+kiSvxGbVjdvWwE= -github.com/0chain/gosdk v1.12.1/go.mod h1:ew7kU2Cf1Y/CzoxMqtnmflD1CuSPaOI5TukoXA26Sz4= +github.com/0chain/gosdk v1.13.4-0.20240409054333-ccc75a18e0b6 h1:P6YXY4DlyVBiomAzJBL03nNR5BbewXYHodHb7lBe/i8= +github.com/0chain/gosdk v1.13.4-0.20240409054333-ccc75a18e0b6/go.mod h1:P8ha0wz3B43sDKD0AxqFDI8EyqLghcvY8g29xFJrBsg= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= @@ -56,14 +56,18 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0= github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= +github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= +github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= +github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bits-and-blooms/bitset v1.9.0 h1:g1YivPG8jOtrN013Fe8OBXubkiTwvm7/vG2vXz03ANU= github.com/bits-and-blooms/bitset v1.9.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= @@ -94,8 +98,10 @@ github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtE github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk= +github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -110,6 +116,7 @@ github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f/go.mod h1:Vz9D github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06 h1:T+Np/xtzIjYM/P5NAw0e2Rf1FGvzDau1h54MKvx8G7w= +github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06/go.mod h1:bynZ3gvVyhlvjLI7PT6dmZ7g76xzJ7HpxfjgkzCGz6s= github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ= github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= @@ -135,6 +142,7 @@ github.com/deckarep/golang-set/v2 v2.2.0 h1:2pMQd3Soi6qfw7E5MMKaEh5W5ES18bW3AbFF github.com/deckarep/golang-set/v2 v2.2.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= 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= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= @@ -157,15 +165,19 @@ github.com/ethereum/go-ethereum v1.13.2 h1:g9mCpfPWqCA1OL4e6C98PeVttb0HadfBRuKTG github.com/ethereum/go-ethereum v1.13.2/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw= github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c= +github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= +github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= 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 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc= github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI= +github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/getsentry/sentry-go v0.12.0/go.mod h1:NSap0JBYWzHND8oMbyi0+XZhUalc1TBdRL1M71JZW2c= github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= @@ -185,6 +197,7 @@ github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22 github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= +github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -222,8 +235,10 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/gomodule/redigo v1.7.1-0.20190724094224-574c33c3df38/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -238,6 +253,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= @@ -271,10 +287,12 @@ github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg= github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= +github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-hclog v1.2.0 h1:La19f8d7WIlm4ogzNHB0JGqs5AUDAZ2UfCY4sJXcJdM= +github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0= github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= @@ -286,12 +304,17 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/herumi/bls-go-binary v1.31.0 h1:L1goQ2tMtGgpXCg5AwHAdJQpLs/pfnWWEc3Wog6OhmI= github.com/herumi/bls-go-binary v1.31.0/go.mod h1:O4Vp1AfR4raRGwFeQpr9X/PQtncEicMoOe6BQt1oX0Y= +github.com/hitenjain14/fasthttp v0.0.0-20240229173600-722723e15e17 h1:FbyIK0BfvXVZTOxKOe2dlxJqSPSF2ZXOv2Mc7dvS7sc= +github.com/hitenjain14/fasthttp v0.0.0-20240229173600-722723e15e17/go.mod h1:RZMcXy7u4S+E97IXYTe7WHZ3+mCYOh4vys8PkIGZeXk= github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZKHF9GxxWKDJGj8I0IqOUol//sw= +github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= +github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o= github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= +github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= @@ -309,6 +332,7 @@ github.com/iris-contrib/jade v1.1.3/go.mod h1:H/geBymxJhShH5kecoiOCSssPX7QWYH7Ua github.com/iris-contrib/pongo2 v0.0.1/go.mod h1:Ssh+00+3GAZqSQb30AvBRNxBx7rf0GqwkjqxNd0u65g= github.com/iris-contrib/schema v0.0.1/go.mod h1:urYA3uvUNG1TIIjOSCzHr9/LmbQo8LrOcOqfqxa4hXw= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= +github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= @@ -328,8 +352,8 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= -github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM= +github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= @@ -339,14 +363,17 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/labstack/echo/v4 v4.5.0/go.mod h1:czIriw4a0C1dFun+ObrXp7ok03xON0N1awStJ6ArI7Y= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= +github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/lithammer/shortuuid/v3 v3.0.7 h1:trX0KTHy4Pbwo/6ia8fscyHoGA+mf1jWbPJVuvyJQQ8= github.com/lithammer/shortuuid/v3 v3.0.7/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts= github.com/machinebox/graphql v0.2.2 h1:dWKpJligYKhYKO5A2gvNhkJdQMNZeChZYyBbrZkBZfo= @@ -355,10 +382,12 @@ github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ= +github.com/matryer/is v1.4.1/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= @@ -371,6 +400,7 @@ github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWV github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= +github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/mediocregopher/radix/v3 v3.4.2/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8= github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc= github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= @@ -381,6 +411,7 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= +github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= @@ -423,6 +454,7 @@ github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= +github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= github.com/prometheus/common v0.39.0 h1:oOyhkDq05hPZKItWVBkJ6g6AtGxi+fy7F4JvUV8uhsI= github.com/prometheus/common v0.39.0/go.mod h1:6XBZ7lYdLCbkAVhwRsWTZn+IN5AB9F/NXd5w0BbEX0Y= github.com/prometheus/procfs v0.11.0 h1:5EAgkfkMl659uZPbe9AS2N68a7Cc1TJbPEuGzFuRbyk= @@ -472,6 +504,7 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= +github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/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 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= @@ -504,9 +537,13 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= +github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w= +github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA= +github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= @@ -515,7 +552,10 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1: github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI= +github.com/ybbus/jsonrpc/v3 v3.1.5 h1:0cC/QzS8OCuXYqqDbYnKKhsEe+IZLrNlDx8KPCieeW0= +github.com/ybbus/jsonrpc/v3 v3.1.5/go.mod h1:U1QbyNfL5Pvi2roT0OpRbJeyvGxfWYSgKJHjxWdAEeE= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= @@ -567,8 +607,8 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -750,6 +790,7 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= +golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -911,6 +952,7 @@ 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-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.28 h1:n1tBJnnK2r7g9OW2btFH91V92STTUevLXYFb8gy9EMk= gopkg.in/cheggaaa/pb.v1 v1.0.28/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= @@ -930,6 +972,7 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 082874009f61a0e7e4ab788a0f980720584913fe Mon Sep 17 00:00:00 2001 From: peterlimg Date: Tue, 9 Apr 2024 19:31:07 +1000 Subject: [PATCH 2/9] Remove primary keys from local wallet after spliting keys --- cmd/zauth.go | 11 +++++++++-- go.mod | 2 +- go.sum | 2 -- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/zauth.go b/cmd/zauth.go index 4832cbb9..75d94500 100644 --- a/cmd/zauth.go +++ b/cmd/zauth.go @@ -88,7 +88,12 @@ var zauthCmd = &cobra.Command{ log.Fatalf("Failed to setup zauth server: %v", err) } - // TODO: remove the private key from the local wallet + // remove the keys[1] + sw.Keys = sw.Keys[:1] + clientWallet.SetSplitKeys(sw) + if err := clientWallet.SaveTo(cfgWallet); err != nil { + log.Fatalf("Failed to save wallet: %v", err) + } log.Printf("Setup zauth server successfully") }, @@ -97,5 +102,7 @@ var zauthCmd = &cobra.Command{ func init() { rootCmd.AddCommand(zauthCmd) zauthCmd.PersistentFlags().String("server", "s", "The zauth server address") - zauthCmd.MarkFlagRequired("server") + if err := zauthCmd.MarkFlagRequired("server"); err != nil { + log.Fatalf("Could not mark 'server' flag required: %v", err) + } } diff --git a/go.mod b/go.mod index f86b29c7..acdabcc4 100644 --- a/go.mod +++ b/go.mod @@ -110,4 +110,4 @@ require ( ) // temporary, for development -// replace github.com/0chain/gosdk => ../gosdk +replace github.com/0chain/gosdk => ../gosdk diff --git a/go.sum b/go.sum index f272901c..c9e7e41a 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,6 @@ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20 h1:c46aB5l0xbD7nc/ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20/go.mod h1:gbmUdgY4Gu2jKmnYnHr8533gcokviV3MDMs8wNk74sk= github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM= github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc= -github.com/0chain/gosdk v1.13.4-0.20240409054333-ccc75a18e0b6 h1:P6YXY4DlyVBiomAzJBL03nNR5BbewXYHodHb7lBe/i8= -github.com/0chain/gosdk v1.13.4-0.20240409054333-ccc75a18e0b6/go.mod h1:P8ha0wz3B43sDKD0AxqFDI8EyqLghcvY8g29xFJrBsg= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= From 2dac27f3974796aec0487eb083de2bba7e360b4e Mon Sep 17 00:00:00 2001 From: peterlimg Date: Tue, 9 Apr 2024 19:35:55 +1000 Subject: [PATCH 3/9] Update gosdk --- go.mod | 4 ++-- go.sum | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index acdabcc4..1861133c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/0chain/zwalletcli go 1.21 require ( - github.com/0chain/gosdk v1.13.4-0.20240409054333-ccc75a18e0b6 + github.com/0chain/gosdk v1.13.4-0.20240409093142-02dc138404bd github.com/ethereum/go-ethereum v1.13.2 github.com/icza/bitio v1.1.0 github.com/olekukonko/tablewriter v0.0.5 @@ -110,4 +110,4 @@ require ( ) // temporary, for development -replace github.com/0chain/gosdk => ../gosdk +// replace github.com/0chain/gosdk => ../gosdk diff --git a/go.sum b/go.sum index c9e7e41a..561bb0b0 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,8 @@ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20 h1:c46aB5l0xbD7nc/ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20/go.mod h1:gbmUdgY4Gu2jKmnYnHr8533gcokviV3MDMs8wNk74sk= github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM= github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc= +github.com/0chain/gosdk v1.13.4-0.20240409093142-02dc138404bd h1:Ev2NJDOg//E/vuJXi9XuGfybQAqtn9cudM76X1KHSIo= +github.com/0chain/gosdk v1.13.4-0.20240409093142-02dc138404bd/go.mod h1:P8ha0wz3B43sDKD0AxqFDI8EyqLghcvY8g29xFJrBsg= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= From 50e35194db184ecf8497c698b13b9d27a8e9f440 Mon Sep 17 00:00:00 2001 From: peterlimg Date: Tue, 9 Apr 2024 20:23:14 +1000 Subject: [PATCH 4/9] Set wallet isSplit field after setup --- cmd/root.go | 13 ++++++++----- cmd/zauth.go | 8 +------- go.mod | 2 +- go.sum | 2 -- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 80194d14..94701aa4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -102,7 +102,9 @@ func initZCNCore() { zcncore.WithMinSubmit(minSubmit), zcncore.WithMinConfirmation(minCfm), zcncore.WithConfirmationChainLength(CfmChainLength), - zcncore.WithEthereumNode(ethereumNodeURL)) + zcncore.WithEthereumNode(ethereumNodeURL), + zcncore.WithIsSplitWallet(clientWallet.IsSplit), + ) if err != nil { ExitWithError(err.Error()) } @@ -112,6 +114,7 @@ func initZCNCore() { if len(miners) > 0 && len(sharders) > 0 { zcncore.SetNetwork(miners, sharders) } + } func loadConfigs() { @@ -169,14 +172,14 @@ var walletIsLoaded bool func initCmdContext(cmd *cobra.Command, args []string) { - _, ok := withoutZCNCoreCmds[cmd] + _, ok := withoutWalletCmds[cmd] if !ok { - initZCNCoreContext() + initZwalletContext() } - _, ok = withoutWalletCmds[cmd] + _, ok = withoutZCNCoreCmds[cmd] if !ok { - initZwalletContext() + initZCNCoreContext() } } diff --git a/cmd/zauth.go b/cmd/zauth.go index 75d94500..6a5a39cd 100644 --- a/cmd/zauth.go +++ b/cmd/zauth.go @@ -65,8 +65,6 @@ var zauthCmd = &cobra.Command{ log.Fatalf("Could not save config: %v", err) } - // figure out what is the private key to use - // from the web-apps, we can see the private key is the first key's private key if clientWallet == nil { log.Fatalf("Wallet is initialized yet") } @@ -76,8 +74,6 @@ var zauthCmd = &cobra.Command{ log.Fatalf("Failed to split keys: %v", err) } - // call gosdk to connect and setup the split keys - // zcncore.SplitKeys() if err := callZauthSetup(serverAddr, splitWallet{ ClientID: sw.ClientID, ClientKey: sw.ClientKey, @@ -102,7 +98,5 @@ var zauthCmd = &cobra.Command{ func init() { rootCmd.AddCommand(zauthCmd) zauthCmd.PersistentFlags().String("server", "s", "The zauth server address") - if err := zauthCmd.MarkFlagRequired("server"); err != nil { - log.Fatalf("Could not mark 'server' flag required: %v", err) - } + zauthCmd.MarkFlagRequired("server") } diff --git a/go.mod b/go.mod index 1861133c..6133b06c 100644 --- a/go.mod +++ b/go.mod @@ -110,4 +110,4 @@ require ( ) // temporary, for development -// replace github.com/0chain/gosdk => ../gosdk +replace github.com/0chain/gosdk => ../gosdk diff --git a/go.sum b/go.sum index 561bb0b0..c9e7e41a 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,6 @@ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20 h1:c46aB5l0xbD7nc/ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20/go.mod h1:gbmUdgY4Gu2jKmnYnHr8533gcokviV3MDMs8wNk74sk= github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM= github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc= -github.com/0chain/gosdk v1.13.4-0.20240409093142-02dc138404bd h1:Ev2NJDOg//E/vuJXi9XuGfybQAqtn9cudM76X1KHSIo= -github.com/0chain/gosdk v1.13.4-0.20240409093142-02dc138404bd/go.mod h1:P8ha0wz3B43sDKD0AxqFDI8EyqLghcvY8g29xFJrBsg= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= From 9f81431938c790b4c60a649c985731eba2bb6409 Mon Sep 17 00:00:00 2001 From: peterlimg Date: Tue, 9 Apr 2024 22:07:21 +1000 Subject: [PATCH 5/9] Support send with auth --- cmd/root.go | 8 ++++++++ cmd/zauth.go | 38 ++++++++++++++++++++++++++++++++++++++ go.mod | 4 ++-- go.sum | 2 ++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 94701aa4..231859b2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,7 +9,9 @@ import ( "strings" "sync" + "github.com/0chain/gosdk/core/sys" "github.com/0chain/gosdk/core/zcncrypto" + "github.com/0chain/gosdk/zboxcore/client" "github.com/0chain/gosdk/zboxcore/sdk" bridge "github.com/0chain/gosdk/zcnbridge/http" "github.com/0chain/gosdk/zcncore" @@ -96,6 +98,7 @@ func initZCNCore() { blockWorker := cfgConfig.GetString("block_worker") chainID := cfgConfig.GetString("chain_id") ethereumNodeURL := cfgConfig.GetString("ethereum_node_url") + zauthServer := cfgConfig.GetString("zauth.server") err := zcncore.InitZCNSDK(blockWorker, signatureScheme, zcncore.WithChainID(chainID), @@ -109,6 +112,11 @@ func initZCNCore() { ExitWithError(err.Error()) } + if zauthServer != "" { + sys.SetAuthorize(zauthSignTxn(zauthServer)) + client.SetClient(clientWallet, signatureScheme, getTxnFee()) + } + miners := cfgNetwork.GetStringSlice("miners") sharders := cfgNetwork.GetStringSlice("sharders") if len(miners) > 0 && len(sharders) > 0 { diff --git a/cmd/zauth.go b/cmd/zauth.go index 6a5a39cd..c8ef4bc5 100644 --- a/cmd/zauth.go +++ b/cmd/zauth.go @@ -3,9 +3,12 @@ package cmd import ( "bytes" "encoding/json" + "fmt" + "io" "log" "net/http" + "github.com/0chain/gosdk/core/sys" "github.com/0chain/gosdk/zcncore" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -48,6 +51,40 @@ func callZauthSetup(serverAddr string, splitWallet splitWallet) error { return nil } +func zauthSignTxn(serverAddr string) sys.AuthorizeFunc { + return func(msg string) (string, error) { + fmt.Println("send message to:", serverAddr+"/sign/txn") + fmt.Println("data:", string(msg)) + req, err := http.NewRequest("POST", serverAddr+"/sign/txn", bytes.NewBuffer([]byte(msg))) + if err != nil { + return "", errors.Wrap(err, "failed to create HTTP request") + } + req.Header.Set("Content-Type", "application/json") + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return "", errors.Wrap(err, "failed to send HTTP request") + } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + rsp, err := io.ReadAll(resp.Body) + if err != nil { + return "", errors.Wrap(err, "failed to read response body") + } + + return "", errors.Errorf("unexpected status code: %d, res: %s", resp.StatusCode, string(rsp)) + } + + d, err := io.ReadAll(resp.Body) + if err != nil { + return "", errors.Wrap(err, "failed to read response body") + } + + fmt.Println("response:", string(d)) + return string(d), nil + } +} + var zauthCmd = &cobra.Command{ Use: "zauth", Short: "Enable zauth", @@ -85,6 +122,7 @@ var zauthCmd = &cobra.Command{ } // remove the keys[1] + sw.PeerPublicKey = sw.Keys[1].PublicKey sw.Keys = sw.Keys[:1] clientWallet.SetSplitKeys(sw) if err := clientWallet.SaveTo(cfgWallet); err != nil { diff --git a/go.mod b/go.mod index 6133b06c..c21bf625 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/0chain/zwalletcli go 1.21 require ( - github.com/0chain/gosdk v1.13.4-0.20240409093142-02dc138404bd + github.com/0chain/gosdk v1.13.4-0.20240409120546-8d3abd1be59f github.com/ethereum/go-ethereum v1.13.2 github.com/icza/bitio v1.1.0 github.com/olekukonko/tablewriter v0.0.5 @@ -110,4 +110,4 @@ require ( ) // temporary, for development -replace github.com/0chain/gosdk => ../gosdk +// replace github.com/0chain/gosdk => ../gosdk diff --git a/go.sum b/go.sum index c9e7e41a..2e04b671 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,8 @@ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20 h1:c46aB5l0xbD7nc/ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20/go.mod h1:gbmUdgY4Gu2jKmnYnHr8533gcokviV3MDMs8wNk74sk= github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM= github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc= +github.com/0chain/gosdk v1.13.4-0.20240409120546-8d3abd1be59f h1:V4tIFIuevypLkG4CpO0LWO9/YOeVvdUmWrxxZBMVDyI= +github.com/0chain/gosdk v1.13.4-0.20240409120546-8d3abd1be59f/go.mod h1:P8ha0wz3B43sDKD0AxqFDI8EyqLghcvY8g29xFJrBsg= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= From 149267e15b7706345caa1ec88052ff1d9982ecb8 Mon Sep 17 00:00:00 2001 From: peterlimg Date: Fri, 12 Apr 2024 09:46:11 +1000 Subject: [PATCH 6/9] Move the zauth functions to gosdk --- cmd/root.go | 2 +- cmd/zauth.go | 149 ++++++++++++++++++++++++--------------------------- go.mod | 2 +- go.sum | 2 - 4 files changed, 73 insertions(+), 82 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 231859b2..6d443385 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -113,7 +113,7 @@ func initZCNCore() { } if zauthServer != "" { - sys.SetAuthorize(zauthSignTxn(zauthServer)) + sys.SetAuthorize(zcncore.ZauthSignTxn(zauthServer)) client.SetClient(clientWallet, signatureScheme, getTxnFee()) } diff --git a/cmd/zauth.go b/cmd/zauth.go index c8ef4bc5..4b14ac5e 100644 --- a/cmd/zauth.go +++ b/cmd/zauth.go @@ -1,89 +1,82 @@ package cmd import ( - "bytes" - "encoding/json" - "fmt" - "io" "log" - "net/http" - "github.com/0chain/gosdk/core/sys" "github.com/0chain/gosdk/zcncore" - "github.com/pkg/errors" "github.com/spf13/cobra" ) -type splitWallet struct { - ClientID string `json:"client_id"` - ClientKey string `json:"client_key"` - PublicKey string `json:"public_key"` - PrivateKey string `json:"private_key"` - PeerPublicKey string `json:"peer_public_key"` -} - -func callZauthSetup(serverAddr string, splitWallet splitWallet) error { - // Add your code here - endpoint := serverAddr + "/setup" - wData, err := json.Marshal(splitWallet) - if err != nil { - return errors.Wrap(err, "failed to marshal split wallet") - } - - req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(wData)) - if err != nil { - return errors.Wrap(err, "failed to create HTTP request") - } - - req.Header.Set("Content-Type", "application/json") - - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - return errors.Wrap(err, "failed to send HTTP request") - } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - return errors.Errorf("unexpected status code: %d", resp.StatusCode) - } - - return nil -} - -func zauthSignTxn(serverAddr string) sys.AuthorizeFunc { - return func(msg string) (string, error) { - fmt.Println("send message to:", serverAddr+"/sign/txn") - fmt.Println("data:", string(msg)) - req, err := http.NewRequest("POST", serverAddr+"/sign/txn", bytes.NewBuffer([]byte(msg))) - if err != nil { - return "", errors.Wrap(err, "failed to create HTTP request") - } - req.Header.Set("Content-Type", "application/json") - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - return "", errors.Wrap(err, "failed to send HTTP request") - } - defer resp.Body.Close() - if resp.StatusCode != http.StatusOK { - rsp, err := io.ReadAll(resp.Body) - if err != nil { - return "", errors.Wrap(err, "failed to read response body") - } - - return "", errors.Errorf("unexpected status code: %d, res: %s", resp.StatusCode, string(rsp)) - } - - d, err := io.ReadAll(resp.Body) - if err != nil { - return "", errors.Wrap(err, "failed to read response body") - } - - fmt.Println("response:", string(d)) - return string(d), nil - } -} +// type splitWallet struct { +// ClientID string `json:"client_id"` +// ClientKey string `json:"client_key"` +// PublicKey string `json:"public_key"` +// PrivateKey string `json:"private_key"` +// PeerPublicKey string `json:"peer_public_key"` +// } + +// func callZauthSetup(serverAddr string, splitWallet splitWallet) error { +// // Add your code here +// endpoint := serverAddr + "/setup" +// wData, err := json.Marshal(splitWallet) +// if err != nil { +// return errors.Wrap(err, "failed to marshal split wallet") +// } + +// req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(wData)) +// if err != nil { +// return errors.Wrap(err, "failed to create HTTP request") +// } + +// req.Header.Set("Content-Type", "application/json") + +// client := &http.Client{} +// resp, err := client.Do(req) +// if err != nil { +// return errors.Wrap(err, "failed to send HTTP request") +// } +// defer resp.Body.Close() + +// if resp.StatusCode != http.StatusOK { +// return errors.Errorf("unexpected status code: %d", resp.StatusCode) +// } + +// return nil +// } + +// func zauthSignTxn(serverAddr string) sys.AuthorizeFunc { +// return func(msg string) (string, error) { +// fmt.Println("send message to:", serverAddr+"/sign/txn") +// fmt.Println("data:", string(msg)) +// req, err := http.NewRequest("POST", serverAddr+"/sign/txn", bytes.NewBuffer([]byte(msg))) +// if err != nil { +// return "", errors.Wrap(err, "failed to create HTTP request") +// } +// req.Header.Set("Content-Type", "application/json") +// client := &http.Client{} +// resp, err := client.Do(req) +// if err != nil { +// return "", errors.Wrap(err, "failed to send HTTP request") +// } +// defer resp.Body.Close() +// if resp.StatusCode != http.StatusOK { +// rsp, err := io.ReadAll(resp.Body) +// if err != nil { +// return "", errors.Wrap(err, "failed to read response body") +// } + +// return "", errors.Errorf("unexpected status code: %d, res: %s", resp.StatusCode, string(rsp)) +// } + +// d, err := io.ReadAll(resp.Body) +// if err != nil { +// return "", errors.Wrap(err, "failed to read response body") +// } + +// fmt.Println("response:", string(d)) +// return string(d), nil +// } +// } var zauthCmd = &cobra.Command{ Use: "zauth", @@ -111,7 +104,7 @@ var zauthCmd = &cobra.Command{ log.Fatalf("Failed to split keys: %v", err) } - if err := callZauthSetup(serverAddr, splitWallet{ + if err := zcncore.CallZauthSetup(serverAddr, zcncore.SplitWallet{ ClientID: sw.ClientID, ClientKey: sw.ClientKey, PublicKey: sw.Keys[1].PublicKey, diff --git a/go.mod b/go.mod index c21bf625..275c7a28 100644 --- a/go.mod +++ b/go.mod @@ -110,4 +110,4 @@ require ( ) // temporary, for development -// replace github.com/0chain/gosdk => ../gosdk +replace github.com/0chain/gosdk => ../gosdk diff --git a/go.sum b/go.sum index 2e04b671..c9e7e41a 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,6 @@ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20 h1:c46aB5l0xbD7nc/ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20/go.mod h1:gbmUdgY4Gu2jKmnYnHr8533gcokviV3MDMs8wNk74sk= github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM= github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc= -github.com/0chain/gosdk v1.13.4-0.20240409120546-8d3abd1be59f h1:V4tIFIuevypLkG4CpO0LWO9/YOeVvdUmWrxxZBMVDyI= -github.com/0chain/gosdk v1.13.4-0.20240409120546-8d3abd1be59f/go.mod h1:P8ha0wz3B43sDKD0AxqFDI8EyqLghcvY8g29xFJrBsg= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= From 2f7cb190ff460a041636cbfa4e13c0d8b17b722c Mon Sep 17 00:00:00 2001 From: peterlimg Date: Tue, 16 Apr 2024 19:43:11 +1000 Subject: [PATCH 7/9] Clean up unused code --- cmd/zauth.go | 71 ---------------------------------------------------- go.mod | 2 +- go.sum | 4 +-- 3 files changed, 3 insertions(+), 74 deletions(-) diff --git a/cmd/zauth.go b/cmd/zauth.go index 4b14ac5e..13d1b9ac 100644 --- a/cmd/zauth.go +++ b/cmd/zauth.go @@ -7,77 +7,6 @@ import ( "github.com/spf13/cobra" ) -// type splitWallet struct { -// ClientID string `json:"client_id"` -// ClientKey string `json:"client_key"` -// PublicKey string `json:"public_key"` -// PrivateKey string `json:"private_key"` -// PeerPublicKey string `json:"peer_public_key"` -// } - -// func callZauthSetup(serverAddr string, splitWallet splitWallet) error { -// // Add your code here -// endpoint := serverAddr + "/setup" -// wData, err := json.Marshal(splitWallet) -// if err != nil { -// return errors.Wrap(err, "failed to marshal split wallet") -// } - -// req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(wData)) -// if err != nil { -// return errors.Wrap(err, "failed to create HTTP request") -// } - -// req.Header.Set("Content-Type", "application/json") - -// client := &http.Client{} -// resp, err := client.Do(req) -// if err != nil { -// return errors.Wrap(err, "failed to send HTTP request") -// } -// defer resp.Body.Close() - -// if resp.StatusCode != http.StatusOK { -// return errors.Errorf("unexpected status code: %d", resp.StatusCode) -// } - -// return nil -// } - -// func zauthSignTxn(serverAddr string) sys.AuthorizeFunc { -// return func(msg string) (string, error) { -// fmt.Println("send message to:", serverAddr+"/sign/txn") -// fmt.Println("data:", string(msg)) -// req, err := http.NewRequest("POST", serverAddr+"/sign/txn", bytes.NewBuffer([]byte(msg))) -// if err != nil { -// return "", errors.Wrap(err, "failed to create HTTP request") -// } -// req.Header.Set("Content-Type", "application/json") -// client := &http.Client{} -// resp, err := client.Do(req) -// if err != nil { -// return "", errors.Wrap(err, "failed to send HTTP request") -// } -// defer resp.Body.Close() -// if resp.StatusCode != http.StatusOK { -// rsp, err := io.ReadAll(resp.Body) -// if err != nil { -// return "", errors.Wrap(err, "failed to read response body") -// } - -// return "", errors.Errorf("unexpected status code: %d, res: %s", resp.StatusCode, string(rsp)) -// } - -// d, err := io.ReadAll(resp.Body) -// if err != nil { -// return "", errors.Wrap(err, "failed to read response body") -// } - -// fmt.Println("response:", string(d)) -// return string(d), nil -// } -// } - var zauthCmd = &cobra.Command{ Use: "zauth", Short: "Enable zauth", diff --git a/go.mod b/go.mod index 275c7a28..60d0b0eb 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect - github.com/h2non/filetype v1.1.3 // indirect + github.com/h2non/filetype v1.1.4-0.20231228185113-6469358c2bcb // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-retryablehttp v0.7.2 // indirect github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect diff --git a/go.sum b/go.sum index c9e7e41a..0230c053 100644 --- a/go.sum +++ b/go.sum @@ -282,8 +282,8 @@ github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWS github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg= -github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= +github.com/h2non/filetype v1.1.4-0.20231228185113-6469358c2bcb h1:GlQyMv2C48qmfPItvAXFoyN341Swxp9JNVeUZxnmbJw= +github.com/h2non/filetype v1.1.4-0.20231228185113-6469358c2bcb/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= From dc63e83ffc508f377f78c2e3f918c043e7e5b26a Mon Sep 17 00:00:00 2001 From: peterlimg Date: Tue, 16 Apr 2024 19:44:48 +1000 Subject: [PATCH 8/9] Avoid duplicate split --- cmd/zauth.go | 4 ++++ go.sum | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/zauth.go b/cmd/zauth.go index 13d1b9ac..10b123ad 100644 --- a/cmd/zauth.go +++ b/cmd/zauth.go @@ -28,6 +28,10 @@ var zauthCmd = &cobra.Command{ log.Fatalf("Wallet is initialized yet") } + if clientWallet.IsSplit { + log.Fatalln("Wallet is already split") + } + sw, err := zcncore.SplitKeysWallet(clientWallet.Keys[0].PrivateKey, 2) if err != nil { log.Fatalf("Failed to split keys: %v", err) diff --git a/go.sum b/go.sum index 5dd669ac..0230c053 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,6 @@ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20 h1:c46aB5l0xbD7nc/ github.com/0chain/common v0.0.7-0.20231108122201-3e2bad6b9d20/go.mod h1:gbmUdgY4Gu2jKmnYnHr8533gcokviV3MDMs8wNk74sk= github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM= github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc= -github.com/0chain/gosdk v1.14.0-RC1 h1:FaQIXMDtchKjJqhpxMh4dA52QUe46DKixibrZXcFS+o= -github.com/0chain/gosdk v1.14.0-RC1/go.mod h1:tgAiVAuIy+Vs1tGfKCPEuuWWARwNQBEw32y950LrqrU= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= From 8510aef4f31c6b5e381802437bf749f1926057a3 Mon Sep 17 00:00:00 2001 From: peterlimg Date: Tue, 16 Apr 2024 19:46:05 +1000 Subject: [PATCH 9/9] Add zauth token option --- cmd/zauth.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/zauth.go b/cmd/zauth.go index 10b123ad..bc967a94 100644 --- a/cmd/zauth.go +++ b/cmd/zauth.go @@ -18,6 +18,11 @@ var zauthCmd = &cobra.Command{ log.Fatalf("Could not find zauth server address") } + token, err := cmd.Flags().GetString("token") + if err != nil { + log.Fatalf("Could not find zauth server setup access token") + } + // update or setup the zauth server address cfgConfig.Set("zauth.server", serverAddr) if err := cfgConfig.WriteConfig(); err != nil { @@ -37,7 +42,7 @@ var zauthCmd = &cobra.Command{ log.Fatalf("Failed to split keys: %v", err) } - if err := zcncore.CallZauthSetup(serverAddr, zcncore.SplitWallet{ + if err := zcncore.CallZauthSetup(serverAddr, token, zcncore.SplitWallet{ ClientID: sw.ClientID, ClientKey: sw.ClientKey, PublicKey: sw.Keys[1].PublicKey, @@ -62,5 +67,6 @@ var zauthCmd = &cobra.Command{ func init() { rootCmd.AddCommand(zauthCmd) zauthCmd.PersistentFlags().String("server", "s", "The zauth server address") + zauthCmd.PersistentFlags().String("token", "t", "The zauth server setup access token") zauthCmd.MarkFlagRequired("server") }