From 2a5a3e94e39b9d1650ecdeb09f0e146df801c38b Mon Sep 17 00:00:00 2001 From: programmer10110 Date: Tue, 20 Oct 2020 18:42:55 +0300 Subject: [PATCH] check signature on prysm compatibility --- client/flow_test.go | 11 ++--------- cmd/airgapped/main.go | 7 ++++++- cmd/prysm_compatibility_checker/main.go | 10 +++++----- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/client/flow_test.go b/client/flow_test.go index b9b8b5a..ec8ef8b 100644 --- a/client/flow_test.go +++ b/client/flow_test.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "crypto/md5" - "crypto/rand" + "encoding/hex" "encoding/json" "fmt" "io/ioutil" @@ -15,7 +15,6 @@ import ( "testing" "time" - bls12381 "github.com/corestario/kyber/pairing/bls12381" "github.com/depools/dc4bc/airgapped" "github.com/depools/dc4bc/client/types" "github.com/depools/dc4bc/fsm/state_machines/dkg_proposal_fsm" @@ -111,14 +110,8 @@ func (n *node) run(t *testing.T) { if err = json.Unmarshal(msg.Data, &pubKeyReq); err != nil { t.Fatalf("failed to unmarshal pubKey request: %v", err) } - seed := make([]byte, 32) - _, _ = rand.Read(seed) - pubKey := bls12381.NewBLS12381Suite(seed).Point() - if err = pubKey.UnmarshalBinary(pubKeyReq.MasterKey); err != nil { - t.Fatalf("failed to unmarshal pubkey: %v", err) - } if err = ioutil.WriteFile(fmt.Sprintf("/tmp/participant_%d.pubkey", - pubKeyReq.ParticipantId), []byte(pubKey.String()), 0666); err != nil { + pubKeyReq.ParticipantId), []byte(hex.EncodeToString(pubKeyReq.MasterKey)), 0666); err != nil { t.Fatalf("failed to write pubkey to temp file: %v", err) } } diff --git a/cmd/airgapped/main.go b/cmd/airgapped/main.go index 6add31a..52d5910 100644 --- a/cmd/airgapped/main.go +++ b/cmd/airgapped/main.go @@ -116,7 +116,12 @@ func (t *terminal) showFinishedDKGCommand() error { } for dkgID, keyring := range keyrings { fmt.Printf("DKG identifier: %s\n", dkgID) - fmt.Printf("PubKey: %s\n", keyring.PubPoly.Commit().String()) + pubkeyBz, err := keyring.PubPoly.Commit().MarshalBinary() + if err != nil { + fmt.Println("failed to marshal pubkey: %w", err) + continue + } + fmt.Printf("PubKey: %s\n", base64.StdEncoding.EncodeToString(pubkeyBz)) fmt.Println("-----------------------------------------------------") } return nil diff --git a/cmd/prysm_compatibility_checker/main.go b/cmd/prysm_compatibility_checker/main.go index bbb7e2a..baa1883 100644 --- a/cmd/prysm_compatibility_checker/main.go +++ b/cmd/prysm_compatibility_checker/main.go @@ -1,7 +1,7 @@ package main import ( - "encoding/hex" + "encoding/base64" "fmt" prysmBLS "github.com/prysmaticlabs/prysm/shared/bls" "github.com/spf13/cobra" @@ -15,7 +15,7 @@ func checkSignature() *cobra.Command { Short: "checks a signature on prysm compatibility", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { - sig, err := hex.DecodeString(args[0]) + sig, err := base64.StdEncoding.DecodeString(args[0]) if err != nil { log.Fatalf("failed to decode signature bytes from string: %v", err) } @@ -33,7 +33,7 @@ func checkPubKey() *cobra.Command { Short: "checks a pubkey on prysm compatibility", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { - pubkey, err := hex.DecodeString(args[0]) + pubkey, err := base64.StdEncoding.DecodeString(args[0]) if err != nil { log.Fatalf("failed to decode pubkey bytes from string: %v", err) } @@ -51,7 +51,7 @@ func verify() *cobra.Command { Short: "verify signature with Prysm", Args: cobra.ExactArgs(3), Run: func(cmd *cobra.Command, args []string) { - sig, err := hex.DecodeString(args[0]) + sig, err := base64.StdEncoding.DecodeString(args[0]) if err != nil { log.Fatalf("failed to decode signature bytes from string: %v", err) } @@ -59,7 +59,7 @@ func verify() *cobra.Command { if err != nil { log.Fatalf("failed to get prysm sig from bytes: %v", err) } - pubkey, err := hex.DecodeString(args[1]) + pubkey, err := base64.StdEncoding.DecodeString(args[1]) if err != nil { log.Fatalf("failed to decode pubkey bytes from string: %v", err) }