Skip to content

Commit

Permalink
Merge pull request #1 from MatusKysel/master
Browse files Browse the repository at this point in the history
Add test and fix error msg
  • Loading branch information
pavelkrolevets authored Sep 6, 2024
2 parents adea224 + 530d6d5 commit 786063f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions crypto/rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ func EncodeRSAPublicKey(pk *rsa.PublicKey) ([]byte, error) {
func Encrypt(pub *rsa.PublicKey, msg []byte) ([]byte, error) {
return rsa.EncryptPKCS1v15(rand.Reader, pub, msg)
}

func Decrypt(pk *rsa.PrivateKey, msg []byte) ([]byte, error) {
return rsa.DecryptPKCS1v15(rand.Reader, pk, msg)
}
2 changes: 1 addition & 1 deletion crypto/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func VerifySignedMessageByOwner(
address := eth_crypto.PubkeyToAddress(*pk)

if common.Address(owner).Cmp(address) != 0 {
return fmt.Errorf("invalid signed reshare signature")
return fmt.Errorf("signature invalid")
}
} else {
// EIP 1271 signature
Expand Down
2 changes: 1 addition & 1 deletion crypto/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestVerifySignedReshare(t *testing.T) {
require.EqualError(t, VerifySignedMessageByOwner(stubClient,
[20]byte{},
plain,
sig), "invalid signed reshare signature")
sig), "signature invalid")
})

t.Run("valid contract signature", func(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion testing/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ethereum/go-ethereum/common"
spec "github.com/ssvlabs/dkg-spec"
spec_crypto "github.com/ssvlabs/dkg-spec/crypto"
"github.com/ssvlabs/dkg-spec/testing/fixtures"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -34,8 +35,10 @@ func TestBuildResult(t *testing.T) {
fixtures.TestNonce,
result,
))
decryptedShare, err := spec_crypto.Decrypt(fixtures.OperatorSK(fixtures.TestOperator1SK), result.SignedProof.Proof.EncryptedShare)
require.NoError(t, err)
require.EqualValues(t, []byte(fixtures.ShareSK(fixtures.TestValidator4OperatorsShare1).SerializeToHexStr()), decryptedShare)
})

}

func TestValidateResults(t *testing.T) {
Expand Down

0 comments on commit 786063f

Please sign in to comment.