crypto

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// todo: 作为参数写入到创世区块
	ConsensusFloor = 0.0 // 共识要求的最低概率
)

Variables

This section is empty.

Functions

func BigPow

func BigPow(a, b int64) *big.Int

BigPow 返回 a^b

func Bytes2PublicKey

func Bytes2PublicKey(pub []byte) *ecdsa.PublicKey

func CalculatorInitialization

func CalculatorInitialization(pp *big.Int, order *big.Int, t int64)

func DecodePrivateKeyFromHexString

func DecodePrivateKeyFromHexString(hexString string) (*ecdsa.PrivateKey,
	error)

func GenerateGenesisParams

func GenerateGenesisParams() (*common.GenesisParams, error)

GenerateGenesisParams 打包 VDF 计算参数

func GenerateParams

func GenerateParams() (*big.Int, *big.Int, error)

GenerateParams 用于生成计算参数,返回 order(n), proof_param

func PublicKey2Bytes

func PublicKey2Bytes(pub *ecdsa.PublicKey) []byte

func PublicKeyBytes2Address

func PublicKeyBytes2Address(pubBytes [33]byte) [20]byte

func VRFCalculate

func VRFCalculate(curve elliptic.Curve, msg []byte) ([]byte, *big.Int, *big.Int, error)

func VRFCheckLocalConsensus

func VRFCheckLocalConsensus(vdfOutput []byte) (bool, error)

VRFCheckLocalConsensus 检查当前节点是否是一个共识节点

func VRFCheckOutputConsensus

func VRFCheckOutputConsensus(randomOutput []byte, local bool) bool

VRFCheckOutputConsensus 检查一个 VRF 的输出是否满足共识

func VRFCheckRemoteConsensus

func VRFCheckRemoteConsensus(key *ecdsa.PublicKey, vdfMsg []byte, s *big.Int, t *big.Int, value []byte) (bool, error)

VRFCheckRemoteConsensus 检查一个其他节点的输出是否满足共识条件

func VRFVerify

func VRFVerify(curve elliptic.Curve, key *ecdsa.PublicKey, msg []byte, s *big.Int, t *big.Int, value []byte) (bool, error)

Types

type Calculator

type Calculator struct {
	// contains filtered or unexported fields
}

func GetCalculatorInstance

func GetCalculatorInstance() *Calculator

GetCalculatorInstance 所有的对 VDF 计算类的操作必须从这里获取实例

func (*Calculator) AppendNewSeed

func (c *Calculator) AppendNewSeed(seed *big.Int, proof *big.Int)

AppendNewSeed 在计算运行时修改此时的运行参数

func (*Calculator) GetSeedParams

func (c *Calculator) GetSeedParams(bufferFull bool) (*big.Int, *big.Int)

GetSeedParams 读取计算信息,如果channel中有数据则优先获取

func (*Calculator) Verify

func (c *Calculator) Verify(seed *big.Int, pi *big.Int, result *big.Int) bool

Verify 验证 VDF 计算结果 result == pi^l * seed^s 具体细节见论文 - Simple Verifiable Delay Functions

func (*Calculator) VerifyBlockVDF

func (c *Calculator) VerifyBlockVDF(seed *big.Int, proof *big.Int) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL