github.com/line/ostracon@v1.0.10-0.20230328032236-7f20145f065d/crypto/vrf/vrf_r2ishiguro_test.go (about) 1 //go:build !libsodium && !coniks 2 // +build !libsodium,!coniks 3 4 package vrf 5 6 import ( 7 "crypto/ed25519" 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestVrfEd25519R2ishiguro_ProofToHash(t *testing.T) { 14 secret := [SEEDBYTES]byte{} 15 privateKey := ed25519.NewKeyFromSeed(secret[:]) 16 message := []byte("hello, world") 17 18 vrfr2ishiguro := newVrfEd25519r2ishiguro() 19 20 t.Run("to hash r2ishiguro proof", func(t *testing.T) { 21 proof, err := vrfr2ishiguro.Prove(privateKey, message) 22 require.NoError(t, err) 23 require.NotNil(t, proof) 24 25 output, err := vrfr2ishiguro.ProofToHash(proof) 26 require.NoError(t, err) 27 require.NotNil(t, output) 28 }) 29 30 t.Run("to hash other algo proof", func(t *testing.T) { 31 proof := []byte("proof of test") 32 output, err := vrfr2ishiguro.ProofToHash(proof) 33 require.Error(t, err) 34 require.Nil(t, output) 35 }) 36 } 37 38 func TestProveAndVerifyR2ishiguroByCryptoEd25519(t *testing.T) { 39 secret := [SEEDBYTES]byte{} 40 privateKey := ed25519.NewKeyFromSeed(secret[:]) 41 publicKey := privateKey.Public().(ed25519.PublicKey) 42 43 verified, err := proveAndVerify(t, privateKey, publicKey) 44 // 45 // verified when using crypto ed25519 46 // 47 require.NoError(t, err) 48 require.True(t, verified) 49 }