github.com/trustbloc/kms-go@v1.1.2/crypto/tinkcrypto/primitive/bbs/bbs_key_template_test.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package bbs 8 9 import ( 10 "crypto/rand" 11 "testing" 12 13 "github.com/google/tink/go/keyset" 14 "github.com/stretchr/testify/require" 15 ) 16 17 func TestBBSKeyTemplateSuccess(t *testing.T) { 18 kt := BLS12381G2KeyTemplate() 19 20 kh, err := keyset.NewHandle(kt) 21 require.NoError(t, err) 22 23 pubKH, err := kh.Public() 24 require.NoError(t, err) 25 26 // now test the BBS primitives with these keyset handles 27 signer, err := NewSigner(kh) 28 require.NoError(t, err) 29 30 messages := [][]byte{[]byte("msg abc"), []byte("msg def"), []byte("msg ghi")} 31 32 sig, err := signer.Sign(messages) 33 require.NoError(t, err) 34 35 verifier, err := NewVerifier(pubKH) 36 require.NoError(t, err) 37 38 err = verifier.Verify(messages, sig) 39 require.NoError(t, err) 40 41 revealedIndexes := []int{1, 2} 42 nonce := make([]byte, 10) 43 44 _, err = rand.Read(nonce) 45 require.NoError(t, err) 46 47 proof, err := verifier.DeriveProof(messages, sig, nonce, revealedIndexes) 48 require.NoError(t, err) 49 50 revealedMsgs := [][]byte{messages[1], messages[2]} 51 52 err = verifier.VerifyProof(revealedMsgs, proof, nonce) 53 require.NoError(t, err) 54 }