Skip to content

Commit

Permalink
wip: test tenderbls sign/verify
Browse files Browse the repository at this point in the history
  • Loading branch information
coolaj86 committed Jan 18, 2024
1 parent 92fda5d commit 2d54291
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ sudo cp -R \
./third_party/bls-signatures/src/depends/relic/include \
/usr/local/include/relic

sudo cp -R \
./third_party/bls-signatures/build/depends/relic/include/relic_conf.h \
./third_party/bls-signatures/src/depends/relic/include/*.h \
/usr/local/include/dashbls/

go test -count 1 ./crypto/bls12381/
```

Expand Down
30 changes: 26 additions & 4 deletions cmd/tenderbls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,40 @@ package main
import (
"encoding/hex"
"fmt"
"log"

"github.com/dashpay/tenderdash/crypto/bls12381"
)

func main() {
secret := []byte("it's a secret")
priv := bls12381.GenPrivKeyFromSecret(secret)
pub := priv.PubKey()
privStr := hex.EncodeToString(priv)
pubStr := hex.EncodeToString(pub.Bytes())
message := []byte("Hello, World!")

privKey := bls12381.GenPrivKeyFromSecret(secret)
privStr := hex.EncodeToString(privKey)
pubKey := privKey.PubKey()
pubBytes := pubKey.Bytes()
pubStr := hex.EncodeToString(pubBytes)

fmt.Printf("\n")
fmt.Printf("Secret: %q\n", secret)
fmt.Printf("Private: %#v\n", privStr)
fmt.Printf("Pub: %#v\n", pubStr)

sigBytes, err := privKey.Sign(message)
if err != nil {
panic(err)
}
sigStr := hex.EncodeToString(sigBytes)

fmt.Printf("\n")
fmt.Printf("Message: %s\n", message)
fmt.Printf("Signature: %#v\n", sigStr)
verify := pubKey.VerifySignature(message, sigBytes)
if !verify {
log.Fatal("bad signature using pubkey")
}
fmt.Printf("Verified: %#v\n", verify)

fmt.Printf("\n")
}

0 comments on commit 2d54291

Please sign in to comment.