github.com/turingchain2020/turingchain@v1.1.21/common/vrf/vrf.go (about)

     1  // Copyright Turing Corp. 2018 All Rights Reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Copyright 2016 Google Inc. All Rights Reserved.
     6  //
     7  // Licensed under the Apache License, Version 2.0 (the "License");
     8  // you may not use this file except in compliance with the License.
     9  // You may obtain a copy of the License at
    10  //
    11  //     http://www.apache.org/licenses/LICENSE-2.0
    12  //
    13  // Unless required by applicable law or agreed to in writing, software
    14  // distributed under the License is distributed on an "AS IS" BASIS,
    15  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  // See the License for the specific language governing permissions and
    17  // limitations under the License.
    18  
    19  // Package vrf defines the interface to a verifiable random function.
    20  package vrf
    21  
    22  import (
    23  	"crypto"
    24  )
    25  
    26  // A VRF is a pseudorandom function f_k from a secret key k, such that that
    27  // knowledge of k not only enables one to evaluate f_k at for any message m,
    28  // but also to provide an NP-proof that the value f_k(m) is indeed correct
    29  // without compromising the unpredictability of f_k for any m' != m.
    30  
    31  // PrivateKey supports evaluating the VRF function.
    32  type PrivateKey interface {
    33  	// Evaluate returns the output of H(f_k(m)) and its proof.
    34  	Evaluate(m []byte) (index [32]byte, proof []byte)
    35  	// Public returns the corresponding public key.
    36  	Public() crypto.PublicKey
    37  }
    38  
    39  // PublicKey supports verifying output from the VRF function.
    40  type PublicKey interface {
    41  	// ProofToHash verifies the NP-proof supplied by Proof and outputs Index.
    42  	ProofToHash(m, proof []byte) (index [32]byte, err error)
    43  }