mirror of
https://github.com/luxfi/mpc.git
synced 2026-09-24 00:26:24 +00:00
make waiting all parties work
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
root = "."
|
||||
testdata_dir = "testdata"
|
||||
tmp_dir = "tmp"
|
||||
|
||||
[build]
|
||||
args_bin = ["--name="node0""]
|
||||
bin = "./tmp/main"
|
||||
cmd = "make build"
|
||||
delay = 0
|
||||
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
|
||||
exclude_file = []
|
||||
exclude_regex = ["_test.go"]
|
||||
exclude_unchanged = false
|
||||
follow_symlink = false
|
||||
full_bin = ""
|
||||
include_dir = []
|
||||
include_ext = ["go", "tpl", "tmpl", "html"]
|
||||
include_file = []
|
||||
kill_delay = "0s"
|
||||
log = "build-errors.log"
|
||||
poll = false
|
||||
poll_interval = 0
|
||||
rerun = false
|
||||
rerun_delay = 500
|
||||
send_interrupt = false
|
||||
stop_on_error = false
|
||||
|
||||
[color]
|
||||
app = ""
|
||||
build = "yellow"
|
||||
main = "magenta"
|
||||
runner = "green"
|
||||
watcher = "cyan"
|
||||
|
||||
[log]
|
||||
main_only = false
|
||||
time = false
|
||||
|
||||
[misc]
|
||||
clean_on_exit = false
|
||||
|
||||
[screen]
|
||||
clear_on_rebuild = false
|
||||
keep_scroll = true
|
||||
@@ -1,7 +1,23 @@
|
||||
WINDOW_NAME := $(shell tmux list-windows -F "#{window_name}" | grep "mpcium")
|
||||
|
||||
|
||||
generate-id:
|
||||
go run cmd/generate-id/main.go
|
||||
genmock:
|
||||
mockgen -source=./pkg/messaging/point2point.go -destination=artifacts/mocks/point2point.go -package=mock
|
||||
|
||||
clean:
|
||||
rm -rf tmp
|
||||
run:
|
||||
go run cmd/main.go
|
||||
|
||||
build:
|
||||
go build -o tmp/main cmd/main.go
|
||||
|
||||
|
||||
clean:
|
||||
ifeq ($(WINDOW_NAME),mpcium)
|
||||
tmux kill-window -t mpcium;
|
||||
endif
|
||||
|
||||
new:
|
||||
make clean && tmuxifier load-window mpcium
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ func loadPeersFromConsul(kv *api.KV, prefix string) ([]string, error) {
|
||||
return peers, nil
|
||||
}
|
||||
|
||||
func storePeersToJSON(peers []string) {
|
||||
func storePeersToJSON(peers any) {
|
||||
// Encode the peers to JSON
|
||||
peersJSON, err := json.MarshalIndent(peers, "", " ")
|
||||
if err != nil {
|
||||
@@ -134,11 +134,13 @@ func main() {
|
||||
|
||||
// Store node IDs with the "peers" prefix
|
||||
|
||||
var keys []string
|
||||
pairs := make(map[string]string)
|
||||
for id, nodeID := range nodeIDs {
|
||||
key := fmt.Sprintf("%snode%d-%s", prefix, id, nodeID)
|
||||
p := &api.KVPair{Key: key, Value: []byte("ok")}
|
||||
keys = append(keys, fmt.Sprintf("%d-%s", id, nodeID))
|
||||
key := fmt.Sprintf("%snode%d", prefix, id)
|
||||
p := &api.KVPair{Key: key, Value: []byte(nodeID)}
|
||||
|
||||
pairs[fmt.Sprintf("node%d", id)] = nodeID
|
||||
|
||||
// Store the key-value pair
|
||||
_, err := kv.Put(p, nil)
|
||||
if err != nil {
|
||||
@@ -148,7 +150,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
storePeersToJSON(keys)
|
||||
storePeersToJSON(pairs)
|
||||
|
||||
}
|
||||
|
||||
|
||||
+71
-4
@@ -1,33 +1,73 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/cryptoniumX/mpcium/pkg/config"
|
||||
"github.com/cryptoniumX/mpcium/pkg/messaging"
|
||||
"github.com/cryptoniumX/mpcium/pkg/mpc"
|
||||
"github.com/hashicorp/consul/api"
|
||||
"github.com/nats-io/nats.go"
|
||||
)
|
||||
|
||||
func main() {
|
||||
natsConn, err := nats.Connect(nats.DefaultURL)
|
||||
nodeName := flag.String("name", "", "Node name")
|
||||
flag.Parse()
|
||||
|
||||
if *nodeName == "" {
|
||||
log.Fatal("Name is required")
|
||||
}
|
||||
|
||||
// Create a new Consul client
|
||||
client, err := api.NewClient(api.DefaultConfig())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Create a Key-Value store client
|
||||
kv := client.KV()
|
||||
peers, err := config.LoadPeersFromConsul(kv, "mpc-peers/")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
nodeID := config.GetNodeID(*nodeName, peers)
|
||||
if nodeID == "" {
|
||||
log.Fatal("Node not found")
|
||||
}
|
||||
|
||||
fmt.Printf("NODE ID is running = %+v\n", nodeID)
|
||||
natsConn, err := nats.Connect(nats.DefaultURL, nats.Name("Nats NoEcho"), nats.NoEcho())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
natsPubSub := messaging.NewNATSPubSub(natsConn)
|
||||
handler(natsPubSub)
|
||||
directMessaging := messaging.NewNatsDirectMessaging(natsConn)
|
||||
|
||||
defer natsConn.Close()
|
||||
|
||||
var peersIDs []string
|
||||
for _, peer := range peers {
|
||||
peersIDs = append(peersIDs, peer.ID)
|
||||
}
|
||||
|
||||
mpcNode := mpc.NewNode(nodeID, peersIDs, natsPubSub, directMessaging)
|
||||
|
||||
handler(natsPubSub, mpcNode)
|
||||
|
||||
go func() {
|
||||
select {}
|
||||
|
||||
}()
|
||||
|
||||
// Create a channel to receive signals
|
||||
|
||||
signals := make(chan os.Signal, 1)
|
||||
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
@@ -36,10 +76,37 @@ func main() {
|
||||
|
||||
}
|
||||
|
||||
func handler(pubsub messaging.PubSub) {
|
||||
func handler(pubsub messaging.PubSub, mpcNode *mpc.Node) {
|
||||
fmt.Println("Subscribing to topic 'mpc:generate'")
|
||||
// ...
|
||||
pubsub.Subscribe("mpc:generate", func(msg []byte) {
|
||||
fmt.Printf("msg = %+v\n", string(msg))
|
||||
|
||||
walletID := string(msg)
|
||||
threshold := 3
|
||||
session, err := mpcNode.CreateKeyGenSession(walletID, threshold)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("session = %+v\n", session)
|
||||
|
||||
err = session.Init()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case err := <-session.ErrCh:
|
||||
fmt.Printf("err = %+v\n", err)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}()
|
||||
|
||||
go session.GenerateKey()
|
||||
session.ListenToIncomingMessage()
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,11 +4,12 @@ go 1.21.0
|
||||
|
||||
require (
|
||||
github.com/bnb-chain/tss-lib v1.5.0
|
||||
github.com/ethereum/go-ethereum v1.13.4
|
||||
github.com/google/uuid v1.4.0
|
||||
github.com/hashicorp/consul/api v1.26.1
|
||||
github.com/nats-io/nats.go v1.31.0
|
||||
github.com/rs/zerolog v1.31.0
|
||||
github.com/stretchr/testify v1.8.3
|
||||
github.com/stretchr/testify v1.8.4
|
||||
go.uber.org/mock v0.3.0
|
||||
)
|
||||
|
||||
@@ -16,10 +17,12 @@ require (
|
||||
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 // indirect
|
||||
github.com/armon/go-metrics v0.4.1 // indirect
|
||||
github.com/btcsuite/btcd v0.0.0-20190629003639-c26ffa870fd8 // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.0 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/gogo/protobuf v1.2.1 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||
github.com/hashicorp/go-hclog v1.5.0 // indirect
|
||||
@@ -28,6 +31,7 @@ require (
|
||||
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
|
||||
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||
github.com/hashicorp/serf v0.10.1 // indirect
|
||||
github.com/holiman/uint256 v1.2.3 // indirect
|
||||
github.com/ipfs/go-log v0.0.1 // indirect
|
||||
github.com/klauspost/compress v1.17.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
@@ -37,11 +41,12 @@ require (
|
||||
github.com/nats-io/nkeys v0.4.5 // indirect
|
||||
github.com/nats-io/nuid v1.0.1 // indirect
|
||||
github.com/opentracing/opentracing-go v1.1.0 // indirect
|
||||
github.com/otiai10/primes v0.0.0-20180210170552-f6d2a1ba97c4 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc // indirect
|
||||
golang.org/x/crypto v0.6.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
|
||||
golang.org/x/crypto v0.14.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
google.golang.org/protobuf v1.27.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
bou.ke/monkey v1.0.1 h1:zEMLInw9xvNakzUUPjfS4Ds6jYPqCFx3m7bRmG5NH2U=
|
||||
bou.ke/monkey v1.0.1/go.mod h1:FgHuK96Rv2Nlf+0u1OOVDpCMdsWyOFmeeketDHE7LIg=
|
||||
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
|
||||
@@ -21,6 +22,8 @@ github.com/bnb-chain/tss-lib v1.5.0 h1:fuP69k0c4K9kaWCrG+FPH4GDdGZpMRhLyAaA+TyGn
|
||||
github.com/bnb-chain/tss-lib v1.5.0/go.mod h1:o3zAAo7A88ZJnCE1qpjy1hTqPn+GPQlxRsj8soz14UU=
|
||||
github.com/btcsuite/btcd v0.0.0-20190629003639-c26ffa870fd8 h1:mOg8/RgDSHTQ1R0IR+LMDuW4TDShPv+JzYHuR4GLoNA=
|
||||
github.com/btcsuite/btcd v0.0.0-20190629003639-c26ffa870fd8/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
|
||||
@@ -37,8 +40,14 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
|
||||
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.0 h1:E5KszxGgpjpmW8vN811G6rBAZg0/S/DftdGqN4FW5x4=
|
||||
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.0/go.mod h1:d0H8xGMWbiIQP7gN3v2rByWUcuZPm9YsgmnfoxgbINc=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
|
||||
github.com/ethereum/go-ethereum v1.13.4 h1:25HJnaWVg3q1O7Z62LaaI6S9wVq8QCw3K88g8wEzrcM=
|
||||
github.com/ethereum/go-ethereum v1.13.4/go.mod h1:I0U5VewuuTzvBtVzKo7b3hJzDhXOUtn9mJW7SsIPB0Q=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
|
||||
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
||||
@@ -52,8 +61,9 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
|
||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
@@ -113,6 +123,8 @@ github.com/hashicorp/memberlist v0.5.0 h1:EtYPN8DpAURiapus508I4n9CzHs2W+8NZGbmmR
|
||||
github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0=
|
||||
github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY=
|
||||
github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4=
|
||||
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/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc=
|
||||
github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM=
|
||||
@@ -122,14 +134,16 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
||||
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
|
||||
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
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=
|
||||
@@ -181,7 +195,9 @@ github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFSt
|
||||
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
|
||||
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
|
||||
github.com/otiai10/mint v1.2.4 h1:DxYL0itZyPaR5Z9HILdxSoHx+gNs6Yx+neOGS3IVUk0=
|
||||
github.com/otiai10/mint v1.2.4/go.mod h1:d+b7n/0R3tdyUYYylALXpWQ/kTN+QobSq/4SRGBkR3M=
|
||||
github.com/otiai10/primes v0.0.0-20180210170552-f6d2a1ba97c4 h1:blMAhTXF6uL1+e3eVSajjLT43Cc0U8mU1gcigbbolJM=
|
||||
github.com/otiai10/primes v0.0.0-20180210170552-f6d2a1ba97c4/go.mod h1:UmSP7QeU3XmAdGu5+dnrTJqjBc+IscpVZkQzk473cjM=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
|
||||
@@ -206,8 +222,8 @@ github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8b
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||
github.com/rakyll/gotest v0.0.6 h1:hBTqkO3jiuwYW/M9gL4bu0oTYcm8J6knQAAPUsJsz1I=
|
||||
github.com/rakyll/gotest v0.0.6/go.mod h1:SkoesdNCWmiD4R2dljIUcfSnNdVZ12y8qK4ojDkc2Sc=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
|
||||
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
@@ -224,21 +240,27 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
|
||||
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/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
|
||||
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo=
|
||||
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo=
|
||||
go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
|
||||
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
||||
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
|
||||
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ=
|
||||
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190227160552-c95aed5357e7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
@@ -246,6 +268,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
@@ -255,6 +279,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -262,6 +287,7 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -270,6 +296,7 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -290,8 +317,13 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
[
|
||||
"0-dc354115-1e98-437f-bfbe-12a34ad0f669",
|
||||
"1-9852c124-9cdb-4451-8e88-a4fe3d160061",
|
||||
"2-ff7318c5-130f-405f-9f63-989effb212d4"
|
||||
]
|
||||
{
|
||||
"node0": "4d8cb873-dc86-4776-b6f6-cf5c668f6468",
|
||||
"node1": "3cba5dc1-96a1-4f31-ab53-82d9586a4a6d",
|
||||
"node2": "3879df1d-8696-42ac-979c-d296c276ddd1"
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/consul/api"
|
||||
)
|
||||
|
||||
type Peer struct {
|
||||
ID string
|
||||
Name string
|
||||
}
|
||||
|
||||
func LoadPeersFromConsul(kv *api.KV, prefix string) ([]Peer, error) {
|
||||
// Retrieve node IDs with the "peers" prefix
|
||||
pairs, _, err := kv.List(prefix, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fmt.Println("Node IDs with the 'peers' prefix:")
|
||||
peers := make([]Peer, 0, 10)
|
||||
for _, pair := range pairs {
|
||||
peers = append(peers, Peer{
|
||||
ID: string(pair.Value),
|
||||
// remove prefix from key
|
||||
Name: pair.Key[len(prefix):],
|
||||
})
|
||||
|
||||
fmt.Printf("Key: %s, Value: %s\n", pair.Key, pair.Value)
|
||||
}
|
||||
|
||||
return peers, nil
|
||||
}
|
||||
|
||||
func GetNodeID(nodeName string, peers []Peer) string {
|
||||
for _, peer := range peers {
|
||||
if peer.Name == nodeName {
|
||||
return peer.ID
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
@@ -17,7 +17,7 @@ type natsDirectMessaging struct {
|
||||
ch chan []byte
|
||||
}
|
||||
|
||||
func newNatsDirectMessaging(natsConn *nats.Conn) DirectMessaging {
|
||||
func NewNatsDirectMessaging(natsConn *nats.Conn) DirectMessaging {
|
||||
return &natsDirectMessaging{
|
||||
natsConn: natsConn,
|
||||
ch: make(chan []byte),
|
||||
@@ -25,6 +25,7 @@ func newNatsDirectMessaging(natsConn *nats.Conn) DirectMessaging {
|
||||
}
|
||||
|
||||
func (d *natsDirectMessaging) Send(id string, message []byte) error {
|
||||
fmt.Println("SEND DIRECT REQUEST", id)
|
||||
msg, err := d.natsConn.Request(id, message, time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -20,7 +20,6 @@ func NewNATSPubSub(natsConn *nats.Conn) PubSub {
|
||||
|
||||
func (n *natsPubSub) Publish(topic string, message []byte) error {
|
||||
log.Info().Msgf("Publishing to topic %s", topic)
|
||||
log.Info().Msgf("Message: %s", string(message))
|
||||
return n.natsConn.Publish(topic, message)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
// The Licensed Work is (c) 2022 Sygma
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
package mpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"github.com/bnb-chain/tss-lib/tss"
|
||||
)
|
||||
|
||||
type TssMessage struct {
|
||||
WalletID string `json:"sessionID"`
|
||||
MsgBytes []byte `json:"msgBytes"`
|
||||
IsBroadcast bool `json:"isBroadcast"`
|
||||
From *tss.PartyID `json:"from"`
|
||||
To []*tss.PartyID `json:"to"`
|
||||
|
||||
IsToOldCommittee bool `json:"isToOldCommittee"`
|
||||
IsToOldAndNewCommittees bool `json:"isToOldAndNewCommittees"`
|
||||
}
|
||||
|
||||
func MarshalTssMessage(
|
||||
walletID string,
|
||||
msgBytes []byte,
|
||||
isBroadcast bool,
|
||||
from *tss.PartyID,
|
||||
to []*tss.PartyID,
|
||||
) ([]byte, error) {
|
||||
tssMsg := &TssMessage{
|
||||
WalletID: walletID,
|
||||
IsBroadcast: isBroadcast,
|
||||
MsgBytes: msgBytes,
|
||||
From: from,
|
||||
To: to,
|
||||
}
|
||||
|
||||
msgBytes, err := json.Marshal(tssMsg)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
return msgBytes, nil
|
||||
}
|
||||
|
||||
func MarshalTssResharingMessage(
|
||||
msgBytes []byte,
|
||||
isToOldCommittee bool,
|
||||
isBroadcast bool,
|
||||
isToOldAndNewCommittees bool,
|
||||
from *tss.PartyID,
|
||||
to []*tss.PartyID,
|
||||
) ([]byte, error) {
|
||||
tssMsg := &TssMessage{
|
||||
IsToOldCommittee: isToOldCommittee,
|
||||
IsToOldAndNewCommittees: isToOldAndNewCommittees,
|
||||
IsBroadcast: isBroadcast,
|
||||
MsgBytes: msgBytes,
|
||||
From: from,
|
||||
To: to,
|
||||
}
|
||||
msgBytes, err := json.Marshal(tssMsg)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
return msgBytes, nil
|
||||
}
|
||||
|
||||
func UnmarshalTssMessage(msgBytes []byte) (*TssMessage, error) {
|
||||
msg := &TssMessage{}
|
||||
err := json.Unmarshal(msgBytes, msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
type StartMessage struct {
|
||||
Params []byte `json:"params"`
|
||||
}
|
||||
|
||||
func MarshalStartMessage(params []byte) ([]byte, error) {
|
||||
startSignMessage := &StartMessage{
|
||||
Params: params,
|
||||
}
|
||||
|
||||
msgBytes, err := json.Marshal(startSignMessage)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
return msgBytes, nil
|
||||
}
|
||||
|
||||
func UnmarshalStartMessage(msgBytes []byte) (*StartMessage, error) {
|
||||
msg := &StartMessage{}
|
||||
err := json.Unmarshal(msgBytes, msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
func SaveStructToJsonFile(s interface{}, filename string) error {
|
||||
data, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.WriteFile(filename, data, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
+24
-5
@@ -1,6 +1,8 @@
|
||||
package mpc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/bnb-chain/tss-lib/tss"
|
||||
@@ -24,6 +26,15 @@ func CreatePartyID(nodeID string, label string) *tss.PartyID {
|
||||
return tss.NewPartyID(partyID, label, key)
|
||||
}
|
||||
|
||||
func PartyIDToNodeID(partyID *tss.PartyID) string {
|
||||
return string(partyID.KeyInt().Bytes())
|
||||
}
|
||||
|
||||
func ArePartyIDsEqual(partyID1, partyID2 *tss.PartyID) bool {
|
||||
return bytes.Equal(partyID1.KeyInt().Bytes(), partyID2.KeyInt().Bytes())
|
||||
|
||||
}
|
||||
|
||||
func NewNode(
|
||||
nodeID string,
|
||||
peerIDs []string,
|
||||
@@ -42,10 +53,12 @@ func (p *Node) ID() string {
|
||||
return p.nodeID
|
||||
}
|
||||
|
||||
func (p *Node) CreateKeyGenSession() (*Session, error) { // generate pre params
|
||||
func (p *Node) CreateKeyGenSession(walletID string, threshold int) (*Session, error) { // generate pre params
|
||||
var selfPartyID *tss.PartyID
|
||||
partyIDs := make([]*tss.PartyID, len(p.peerIDs))
|
||||
|
||||
mapPartyIdToNodeId := make(map[string]string)
|
||||
|
||||
for i, peerID := range p.peerIDs {
|
||||
if peerID == p.nodeID {
|
||||
selfPartyID = CreatePartyID(peerID, "keygen")
|
||||
@@ -55,13 +68,19 @@ func (p *Node) CreateKeyGenSession() (*Session, error) { // generate pre params
|
||||
partyIDs[i] = CreatePartyID(peerID, "keygen")
|
||||
}
|
||||
}
|
||||
fmt.Printf("selfPartyID = %+v\n", selfPartyID)
|
||||
|
||||
sortedPartyIds := tss.SortPartyIDs(partyIDs, 0)
|
||||
|
||||
session := &Session{
|
||||
selfPartyID: selfPartyID,
|
||||
partyIDs: sortedPartyIds,
|
||||
}
|
||||
session := NewSession(
|
||||
walletID,
|
||||
p.pubSub,
|
||||
p.direct,
|
||||
selfPartyID,
|
||||
sortedPartyIds,
|
||||
threshold,
|
||||
mapPartyIdToNodeId,
|
||||
)
|
||||
|
||||
return session, nil
|
||||
}
|
||||
|
||||
+26
-23
@@ -3,36 +3,39 @@ package mpc
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cryptoniumX/mpcium/artifacts/mock"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
func TestCreateKeyGenSession(t *testing.T) {
|
||||
nodeID := uuid.NewString()
|
||||
// func TestCreateKeyGenSession(t *testing.T) {
|
||||
// nodeID := uuid.NewString()
|
||||
|
||||
peerIDs := []string{
|
||||
nodeID,
|
||||
uuid.NewString(),
|
||||
uuid.NewString(),
|
||||
}
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
pubsub := mock.NewMockPubSub(ctrl)
|
||||
direct := mock.NewMockDirectMessaging(ctrl)
|
||||
// peerIDs := []string{
|
||||
// nodeID,
|
||||
// uuid.NewString(),
|
||||
// uuid.NewString(),
|
||||
// }
|
||||
// ctrl := gomock.NewController(t)
|
||||
// defer ctrl.Finish()
|
||||
// pubsub := mock.NewMockPubSub(ctrl)
|
||||
// direct := mock.NewMockDirectMessaging(ctrl)
|
||||
|
||||
node := NewNode(nodeID, peerIDs, pubsub, direct)
|
||||
// node := NewNode(nodeID, peerIDs, pubsub, direct)
|
||||
|
||||
session, err := node.CreateKeyGenSession()
|
||||
// session, err := node.CreateKeyGenSession()
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, session.PartyIDs(), 3, "Length of partyIDs should be equal")
|
||||
assert.NotNil(t, session.PartyID())
|
||||
// assert.NoError(t, err)
|
||||
// assert.Len(t, session.PartyIDs(), 3, "Length of partyIDs should be equal")
|
||||
// assert.NotNil(t, session.PartyID())
|
||||
|
||||
for i, partyID := range session.PartyIDs() {
|
||||
// check sortedID
|
||||
assert.Equal(t, partyID.Index, i, "Index should be equal")
|
||||
}
|
||||
// for i, partyID := range session.PartyIDs() {
|
||||
// // check sortedID
|
||||
// assert.Equal(t, partyID.Index, i, "Index should be equal")
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
func TestPartyIDToNodeID(t *testing.T) {
|
||||
partyID := CreatePartyID("4d8cb873-dc86-4776-b6f6-cf5c668f6468", "keygen")
|
||||
nodeID := PartyIDToNodeID(partyID)
|
||||
assert.Equal(t, nodeID, "4d8cb873-dc86-4776-b6f6-cf5c668f6468", "NodeID should be equal")
|
||||
}
|
||||
|
||||
+223
-2
@@ -1,12 +1,62 @@
|
||||
package mpc
|
||||
|
||||
import "github.com/bnb-chain/tss-lib/tss"
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/bnb-chain/tss-lib/ecdsa/keygen"
|
||||
"github.com/bnb-chain/tss-lib/tss"
|
||||
"github.com/cryptoniumX/mpcium/pkg/messaging"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type Session struct {
|
||||
walletID string
|
||||
pubSub messaging.PubSub
|
||||
direct messaging.DirectMessaging
|
||||
|
||||
threshold int
|
||||
selfPartyID *tss.PartyID
|
||||
|
||||
// IDs of all parties in the session including self
|
||||
partyIDs []*tss.PartyID
|
||||
mapPartyIdToNodeId map[string]string
|
||||
partyIDs []*tss.PartyID
|
||||
outCh chan tss.Message
|
||||
endCh chan keygen.LocalPartySaveData
|
||||
ErrCh chan error
|
||||
|
||||
party tss.Party
|
||||
|
||||
// its ready when alls party emit ready
|
||||
readyCh chan string
|
||||
}
|
||||
|
||||
func NewSession(
|
||||
walletID string,
|
||||
pubSub messaging.PubSub,
|
||||
direct messaging.DirectMessaging,
|
||||
selfID *tss.PartyID,
|
||||
partyIDs []*tss.PartyID,
|
||||
threshold int,
|
||||
mapPartyIdToNodeId map[string]string,
|
||||
) *Session {
|
||||
fmt.Printf("mapPartyIdToNodeId = %+v\n", mapPartyIdToNodeId)
|
||||
return &Session{
|
||||
walletID: walletID,
|
||||
pubSub: pubSub,
|
||||
direct: direct,
|
||||
threshold: threshold,
|
||||
selfPartyID: selfID,
|
||||
partyIDs: partyIDs,
|
||||
outCh: make(chan tss.Message),
|
||||
endCh: make(chan keygen.LocalPartySaveData),
|
||||
ErrCh: make(chan error),
|
||||
readyCh: make(chan string, 3),
|
||||
mapPartyIdToNodeId: mapPartyIdToNodeId,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) PartyID() *tss.PartyID {
|
||||
@@ -17,6 +67,177 @@ func (s *Session) PartyIDs() []*tss.PartyID {
|
||||
return s.partyIDs
|
||||
}
|
||||
|
||||
func (s *Session) PartyCount() int {
|
||||
return len(s.partyIDs)
|
||||
}
|
||||
|
||||
func (s *Session) composeReadyTopic(nodeID string) string {
|
||||
return fmt.Sprintf("%s-%s-%s", s.walletID, nodeID, "ready")
|
||||
}
|
||||
|
||||
func (s *Session) Init() error {
|
||||
for _, partyID := range s.partyIDs {
|
||||
if ArePartyIDsEqual(partyID, s.selfPartyID) {
|
||||
continue
|
||||
}
|
||||
|
||||
go func(partyID *tss.PartyID) {
|
||||
topic := s.composeReadyTopic(PartyIDToNodeID(partyID))
|
||||
fmt.Println("Subscribing to topic", topic)
|
||||
s.pubSub.Subscribe(topic, func(data []byte) {
|
||||
fmt.Printf("string(data) = %+v\n", string(data))
|
||||
log.Info().Msgf("Received ready message for %s from %s", topic, string(data))
|
||||
s.readyCh <- PartyIDToNodeID(partyID)
|
||||
})
|
||||
}(partyID)
|
||||
|
||||
}
|
||||
|
||||
preParams, err := keygen.GeneratePreParams(1 * time.Minute)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info().Msgf("Initializing session with partyID: %s, peerIDs %s", s.selfPartyID, s.partyIDs)
|
||||
ctx := tss.NewPeerContext(s.partyIDs)
|
||||
params := tss.NewParameters(tss.S256(), ctx, s.selfPartyID, len(s.partyIDs), s.threshold)
|
||||
s.party = keygen.NewLocalParty(params, s.outCh, s.endCh, *preParams)
|
||||
log.Info().Msg("Initialized session successfully")
|
||||
|
||||
s.pubSub.Publish(s.composeReadyTopic(PartyIDToNodeID(s.selfPartyID)), []byte(PartyIDToNodeID(s.selfPartyID)))
|
||||
s.readyCh <- PartyIDToNodeID(s.selfPartyID)
|
||||
|
||||
for i := 0; i < len(s.partyIDs); i++ {
|
||||
nodeID := <-s.readyCh
|
||||
fmt.Printf("nodeID is ready = %+v\n", nodeID)
|
||||
}
|
||||
|
||||
log.Info().Msg("All parties are ready")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Session) composeTargetID(nodeID string) string {
|
||||
return fmt.Sprintf("%s-%s", s.walletID, nodeID)
|
||||
}
|
||||
|
||||
func (s *Session) handleMessage(keyshare tss.Message) {
|
||||
data, routing, err := keyshare.WireBytes()
|
||||
fmt.Printf("routing = %+v\n", routing)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to marshal message")
|
||||
s.ErrCh <- err
|
||||
return
|
||||
}
|
||||
|
||||
msg, err := MarshalTssMessage(s.walletID, data, routing.IsBroadcast, routing.From, routing.To)
|
||||
if err != nil {
|
||||
s.ErrCh <- err
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("PREPARE TO SEND MESSAGE TO %v, is broadcast %v", routing.To, routing.IsBroadcast)
|
||||
fmt.Printf("walletID: %s\n", s.walletID)
|
||||
|
||||
if routing.IsBroadcast && len(routing.To) == 0 {
|
||||
err := s.pubSub.Publish(s.walletID, msg)
|
||||
if err != nil {
|
||||
s.ErrCh <- err
|
||||
return
|
||||
}
|
||||
} else {
|
||||
for _, to := range routing.To {
|
||||
nodeID := PartyIDToNodeID(to)
|
||||
err := s.direct.Send(s.composeTargetID(nodeID), msg)
|
||||
if err != nil {
|
||||
s.ErrCh <- err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) GenerateKey() {
|
||||
fmt.Println("Waiting all parties to be ready")
|
||||
<-s.readyCh
|
||||
fmt.Println("All parties are ready, start generating key")
|
||||
|
||||
go func() {
|
||||
if err := s.party.Start(); err != nil {
|
||||
s.ErrCh <- err
|
||||
}
|
||||
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case msg := <-s.outCh:
|
||||
fmt.Printf("msg = %+v\n", msg)
|
||||
s.handleMessage(msg)
|
||||
case saveData := <-s.endCh:
|
||||
|
||||
publicKey := saveData.ECDSAPub
|
||||
|
||||
pubKey := &ecdsa.PublicKey{
|
||||
Curve: publicKey.Curve(),
|
||||
X: publicKey.X(),
|
||||
Y: publicKey.Y(),
|
||||
}
|
||||
|
||||
address := crypto.PubkeyToAddress(*pubKey)
|
||||
fmt.Printf("address = %+v\n", address)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *Session) ListenToIncomingMessage() {
|
||||
go func() {
|
||||
s.pubSub.Subscribe(s.walletID, func(msg []byte) {
|
||||
s.receiveMessage(msg)
|
||||
})
|
||||
|
||||
}()
|
||||
|
||||
nodeID := s.mapPartyIdToNodeId[s.selfPartyID.String()]
|
||||
s.direct.Listen(s.composeTargetID(nodeID), func(msg []byte) {
|
||||
s.receiveMessage(msg)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (s *Session) receiveMessage(rawMsg []byte) {
|
||||
fmt.Println("receive message")
|
||||
msg, err := UnmarshalTssMessage(rawMsg)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to unmarshal message")
|
||||
s.ErrCh <- err
|
||||
return
|
||||
}
|
||||
|
||||
isBroadcast := msg.IsBroadcast && len(msg.To) == 0
|
||||
isToSelf := len(msg.To) == 1 && msg.To[0].Id == s.selfPartyID.Id
|
||||
|
||||
if isBroadcast || isToSelf {
|
||||
go func() {
|
||||
fmt.Println("SHOULD UPDATE myself")
|
||||
ok, err := s.party.UpdateFromBytes(msg.MsgBytes, msg.From, msg.IsBroadcast)
|
||||
if !ok || err != nil {
|
||||
fmt.Printf("err = %+v\n", err)
|
||||
log.Error().Err(err).Msg("failed to update party")
|
||||
s.ErrCh <- err
|
||||
return
|
||||
}
|
||||
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
// Close and clean up
|
||||
func (s *Session) Close() {
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user