github.com/line/ostracon@v1.0.10-0.20230328032236-7f20145f065d/crypto/vrf/vrf.go (about)

     1  package vrf
     2  
     3  import (
     4  	"math/big"
     5  )
     6  
     7  // defaultVrf is assigned to vrfEd25519r2ishiguro by init() of vrf_r2ishguro.go
     8  // If you want to use libsodium for vrf implementation, then you should put build option like this
     9  // `make build LIBSODIUM=1`
    10  // Please refer https://github.com/line/ostracon/pull/41 for more detail
    11  var defaultVrf vrfEd25519
    12  
    13  type Proof []byte
    14  type Output []byte
    15  
    16  type vrfEd25519 interface {
    17  	Prove(privateKey []byte, message []byte) (Proof, error)
    18  	Verify(publicKey []byte, proof Proof, message []byte) (bool, error)
    19  	ProofToHash(proof Proof) (Output, error)
    20  }
    21  
    22  func (op Output) ToInt() *big.Int {
    23  	i := big.Int{}
    24  	i.SetBytes(op)
    25  	return &i
    26  }
    27  
    28  func Prove(privateKey []byte, message []byte) (Proof, error) {
    29  	return defaultVrf.Prove(privateKey, message)
    30  }
    31  
    32  func Verify(publicKey []byte, proof Proof, message []byte) (bool, error) {
    33  	return defaultVrf.Verify(publicKey, proof, message)
    34  }
    35  
    36  func ProofToHash(proof Proof) (Output, error) {
    37  	return defaultVrf.ProofToHash(proof)
    38  }