forked from nanu-c/zkgroup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
44 lines (36 loc) · 3.29 KB
/
server_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package zkgroup_test
import (
"encoding/hex"
"testing"
"github.com/coming-chat/zkgroup"
"github.com/stretchr/testify/require"
)
func TestServerSignatures(t *testing.T) {
serverSecretParams, err := zkgroup.GenerateServerSecretParamsDeterministic(test32)
require.NoError(t, err)
serverPublicParams, err := serverSecretParams.PublicParams()
require.NoError(t, err)
message := test32_1
signature, err := serverSecretParams.SignDeterministic(test32_2, message)
require.NoError(t, err)
err = serverPublicParams.VerifySignature(message, signature)
require.NoError(t, err)
signatureExpected, _ := hex.DecodeString("87d354564d35ef91edba851e0815612e864c227a0471d50c270698604406d003a55473f576cf241fc6b41c6b16e5e63b333c02fe4a33858022fdd7a4ab367b06")
require.Equal(t, zkgroup.NotarySignature(signatureExpected), signature)
altered := make([]byte, len(message))
copy(altered, message)
altered[0] ^= 1
err = serverPublicParams.VerifySignature(altered, signature)
require.EqualError(t, err, "verification failed")
}
func TestNewServerSecretParams(t *testing.T) {
sk, _ := hex.DecodeString("74b60ae309e47af828f46c504ab6788ea1ee7afb76fe116dad051a27f9350ce8")
zkSecretParams, err := zkgroup.GenerateServerSecretParamsDeterministic(sk)
require.NoError(t, err)
expected := "00036486531c32d8773a040528e670664844a836ab94983739e70dcb77c527b20e46eb7e0fdec319a1bc89aebed330d660b19b4efd28a1d40b5f65419c681b620198f3462963d20219904582522b32833114890a526bbf0b1997cc407b8b246a703ed3d57b3abebb212156e014355848aa83d7caa0d16acbf241cb28fd94c4620d49405ac23c16bec8e6a0340be318acfcf2be5451065d2d5043537cfa3368d209e979df54530d8076f8a1e5e680de75b7f2823649f39e5b00d81faf10b9cd250392aff4f2779c8d902429f661ec3356ade74d9250f2dbc2fcca34e2109e75bb07e5e6e4e5dd735effc3ed4abda19e09f343609f2a5f43cd300efccb6748d0ae0a51ff0128baf982ec96a94cc85f2cb41dd30ede83b11b62fee899b1919f365302ec663f4c732e393bbf6cd46eabf1c84c9bc3504e307eb471992d8c5d23960137866e12e9cf878cf9198bbb1dd7163f19f4289588c2e186f27c024a4e4f9b84629d6f9474f1afa819bf372bf0b10ffe8e9c70bae1db0920ead7d8a776fc3caf01fe9b10b2b1a72f40fd370d738c7ccd3f79289a42190c854dce6b117ed369870804439b3d4c059fd1d0cc6269aa3723a1e9fe9de4b312896f4ef5814d85638c68cbfcdaeff5fc13d8f6ef2e72fe7eab215e56a868440c225b5977faf1a968f30bfc18aac9dd5a38ddd9d5d13d027cbe3f34dd969f75639624d3933fbaff4af00fef12fd1669d040af863f31c5c15290b04dd1125c60c38ce299d9383f3b8b770d8d6b20e8ad309cbbe6b58d65f2569653392e54d33b8ad7838dd6249c988b550383dc39902f5c4b757c1d764a2e9a446ec5bce30c47ff899d113631e13eb1be0be89880e61bc10ea44f9d6eb7b99487fd92351563613b527f0231592e1215e606682c6a6dc9b6e35891b8c0e26f960fbead42740b86fd25df00db1f9136933b4bca6d98fa2948abb708ffb5cd7a917e4442638cdf2274e11079119ce791852872bafff7458f91cbc605996086e70217da6af813bb9e20c7dcf8b649f032e0c704b012f049126b666ca1273509be5e0b13fc89c5918ce3cb75f06b1496b564ee5d"
require.Equal(t, expected, hex.EncodeToString(zkSecretParams))
zkPublicParams, err := zkSecretParams.PublicParams()
require.NoError(t, err)
expected = "00ec663f4c732e393bbf6cd46eabf1c84c9bc3504e307eb471992d8c5d23960137866e12e9cf878cf9198bbb1dd7163f19f4289588c2e186f27c024a4e4f9b8462682c6a6dc9b6e35891b8c0e26f960fbead42740b86fd25df00db1f9136933b4bca6d98fa2948abb708ffb5cd7a917e4442638cdf2274e11079119ce791852872b012f049126b666ca1273509be5e0b13fc89c5918ce3cb75f06b1496b564ee5d"
require.Equal(t, expected, hex.EncodeToString(zkPublicParams))
}