aboutsummaryrefslogtreecommitdiffstats
path: root/core/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'core/crypto')
-rw-r--r--core/crypto/dkg/dkg.go27
-rw-r--r--core/crypto/dkg/dkg_test.go16
2 files changed, 43 insertions, 0 deletions
diff --git a/core/crypto/dkg/dkg.go b/core/crypto/dkg/dkg.go
index f6b3e0e..425d96b 100644
--- a/core/crypto/dkg/dkg.go
+++ b/core/crypto/dkg/dkg.go
@@ -131,6 +131,33 @@ func (prvs *PrivateKeyShares) Equal(other *PrivateKeyShares) bool {
return true
}
+// EncodeRLP implements rlp.Encoder
+func (prvs *PrivateKeyShares) EncodeRLP(w io.Writer) error {
+ mpks := make([][]byte, len(prvs.masterPrivateKey))
+ for i, m := range prvs.masterPrivateKey {
+ mpks[i] = m.GetLittleEndian()
+ }
+ return rlp.Encode(w, mpks)
+}
+
+// DecodeRLP implements rlp.Decoder
+func (prvs *PrivateKeyShares) DecodeRLP(s *rlp.Stream) error {
+ var dec [][]byte
+ if err := s.Decode(&dec); err != nil {
+ return err
+ }
+
+ for _, k := range dec {
+ var key bls.SecretKey
+ if err := key.SetLittleEndian(k); err != nil {
+ return err
+ }
+ prvs.masterPrivateKey = append(prvs.masterPrivateKey, key)
+ }
+
+ return nil
+}
+
// PublicKeyShares represents a public key shares for DKG protocol.
type PublicKeyShares struct {
shareCaches []PublicKey
diff --git a/core/crypto/dkg/dkg_test.go b/core/crypto/dkg/dkg_test.go
index e097bdb..20dd908 100644
--- a/core/crypto/dkg/dkg_test.go
+++ b/core/crypto/dkg/dkg_test.go
@@ -328,6 +328,22 @@ func (s *DKGTestSuite) TestPublicKeySharesRLPEncodeDecode() {
s.Require().True(reflect.DeepEqual(b, bb))
}
+func (s *DKGTestSuite) TestPrivateKeySharesRLPEncodeDecode() {
+ privShares, _ := NewPrivateKeyShares(10)
+
+ b, err := rlp.EncodeToBytes(privShares)
+ s.Require().NoError(err)
+
+ var newPrivShares PrivateKeyShares
+ err = rlp.DecodeBytes(b, &newPrivShares)
+ s.Require().NoError(err)
+
+ bb, err := rlp.EncodeToBytes(&newPrivShares)
+ s.Require().NoError(err)
+
+ s.Require().True(reflect.DeepEqual(b, bb))
+}
+
func (s *DKGTestSuite) TestPublicKeySharesEquality() {
var req = s.Require()
IDs := s.genID(2)