vechain / go-ecvrf Goto Github PK
View Code? Open in Web Editor NEWElliptic Curve Verifiable Radom Function(ECVRF) library written in Go
License: MIT License
Elliptic Curve Verifiable Radom Function(ECVRF) library written in Go
License: MIT License
Thanks for your contributions of the implementation of ecvrf.
When I'm using ecvrf.Secp256k1Sha256Tai.Prove in my code, a panic comes:
`panic: math/big: buffer too small to fit value
goroutine 1 [running]:
math/big.nat.bytes(...)
/usr/local/go1.18/src/math/big/nat.go:1166
math/big.(*Int).FillBytes(0xc00007c8e0, {0xc000022961, 0x20, 0x20})
/usr/local/go1.18/src/math/big/int.go:466 +0xf8
crypto/elliptic.MarshalCompressed({0x63dbf8?, 0x6e7558?}, 0xc0000b3d30?, 0x47fcbb?)
/usr/local/go1.18/src/crypto/elliptic/elliptic.go:382 +0xb6
github.com/vechain/go-ecvrf.(*core).Marshal(...)
/home/flybear/go/pkg/mod/github.com/vechain/[email protected]/core.go:46
github.com/vechain/go-ecvrf.(*core).HashToCurveTryAndIncrement(0xc0000b3e28, 0xc0000b3e18, {0xc0000242e0, 0x20, 0x20})
/home/flybear/go/pkg/mod/github.com/vechain/[email protected]/core.go:94 +0xca
github.com/vechain/go-ecvrf.(*vrf).Prove(0x63d640?, 0xc0000a0720, {0xc0000242e0, 0x20, 0x20})
/home/flybear/go/pkg/mod/github.com/vechain/[email protected]/vrf.go:92 +0xd5
main.main()
/home/flybear/Code/new/main.go:73 +0x137
exit status 2`
I am confused whether there is any wrong operations in my code.
ecdsa private key
-----BEGIN PRIVATE KEY----- MIGkAgEBBDCwC9t6gX86b+U3LhLQb87W+B6HSSq7+oXXcd2Arya0s0Fxf6kS/zbv R3al96T8QxigBwYFK4EEACKhZANiAAQMv937zAcd6ZnrU//ZivqFMuoScQ4+vKP8 7P/6MLPXpzh53fHDdyHim815OHU7adCN/lT8ARZO2TXEoxYezZojqPsUdCS6LSVe eIEfJ7qdf+E2oLiLubzKamwpxj0b2WI= -----END PRIVATE KEY-----
data(string form) for prove
\xd7\x03\xb2\xfb\x04\xda\x1c\x03
\xab\xa0dI\x96\x98\xc5Uru \xb5V\xdasWͽ\xa4\xf5k\xa5\xbdN`
It does not work for me.
package main
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"fmt"
"reflect"
"github.com/vechain/go-ecvrf"
)
type VRFResult struct {
Proof []byte
RandomValue []byte
}
func GenerateVRF(privateKey *ecdsa.PrivateKey, input []byte) *VRFResult {
output, proof, err := ecvrf.Secp256k1Sha256Tai.Prove(privateKey, input)
if err != nil {
// log.Error("GenerateVRF fail", "err", err)
fmt.Printf("GenerateVRF fail, err: %v\n", err)
}
return &VRFResult{
Proof: proof,
RandomValue: output,
}
}
func VerifyVRF(publicKey *ecdsa.PublicKey, input []byte, vrfResult *VRFResult) bool {
output, err := ecvrf.Secp256k1Sha256Tai.Verify(publicKey, input, vrfResult.Proof)
if err != nil {
// log.Error("VerifyVRF fail", "err", err)
fmt.Printf("VerifyVRF fail, err: %v\n", err)
}
return reflect.DeepEqual(output, vrfResult.RandomValue)
}
func main() {
curve := elliptic.P256()
privateKey, err := ecdsa.GenerateKey(curve, rand.Reader)
if err != nil {
// log.Error("generate private key fail", "err", err)
}
inputData := []byte("This is some input data.")
vrfResult := GenerateVRF(privateKey, inputData)
fmt.Printf("VRF Proof: %x\n", vrfResult.Proof)
fmt.Printf("Random Value: %x\n", vrfResult.RandomValue)
isValid := VerifyVRF(&privateKey.PublicKey, inputData, vrfResult)
fmt.Println("VRF Verification:", isValid)
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.