github.com/line/ostracon@v1.0.10-0.20230328032236-7f20145f065d/crypto/vrf/vrf_r2ishiguro.go (about) 1 //go:build !libsodium && !coniks 2 // +build !libsodium,!coniks 3 4 package vrf 5 6 import ( 7 "crypto/ed25519" 8 9 r2ishiguro "github.com/r2ishiguro/vrf/go/vrf_ed25519" 10 ) 11 12 type vrfEd25519r2ishiguro struct { 13 } 14 15 func init() { 16 // if you use build option for other implementation, defaultVrf is overridden by other implementation. 17 if defaultVrf == nil { 18 defaultVrf = newVrfEd25519r2ishiguro() 19 } 20 } 21 22 const ( 23 ProofSize int = 81 24 OutputSize int = 32 25 ) 26 27 func newVrfEd25519r2ishiguro() vrfEd25519r2ishiguro { 28 return vrfEd25519r2ishiguro{} 29 } 30 31 func (base vrfEd25519r2ishiguro) Prove(privateKey []byte, message []byte) (Proof, error) { 32 publicKey := ed25519.PrivateKey(privateKey).Public().(ed25519.PublicKey) 33 return r2ishiguro.ECVRF_prove(publicKey, privateKey, message) 34 } 35 36 func (base vrfEd25519r2ishiguro) Verify(publicKey []byte, proof Proof, message []byte) (bool, error) { 37 return r2ishiguro.ECVRF_verify(publicKey, proof, message) 38 } 39 40 func (base vrfEd25519r2ishiguro) ProofToHash(proof Proof) (Output, error) { 41 // validate proof with ECVRF_decode_proof 42 _, _, _, err := r2ishiguro.ECVRF_decode_proof(proof) 43 if err != nil { 44 return nil, err 45 } 46 return r2ishiguro.ECVRF_proof2hash(proof), nil 47 }