Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (48 sloc) 1.12 KB
package bliss
import (
"fmt"
"testing"
"github.com/HcashOrg/bliss/params"
"github.com/HcashOrg/bliss/sampler"
)
func TestDemo(t *testing.T) {
version := params.BLISS_B_0
seed := []uint8{
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7,
}
msg := "Hello world"
entropy, err := sampler.NewEntropy(seed)
if err != nil {
t.Errorf("Error in creating entropy: %s\n", err.Error())
return
}
key, err := GeneratePrivateKey(version, entropy)
if err != nil {
t.Errorf("Error in generating private key: %s\n", err.Error())
return
} else {
fmt.Errorf("Private Key: %s\n", key.String())
}
pub := key.PublicKey()
fmt.Printf("Public Key: %s\n", pub.String())
sig, err := key.Sign([]byte(msg), entropy)
if err != nil {
t.Errorf("Error in signing: %s\n", err.Error())
return
} else {
fmt.Printf("Signature: %s\n", sig.String())
}
res, err := pub.Verify([]byte(msg), sig)
if res {
fmt.Printf("Verified!\n")
} else {
t.Errorf("Error: %s\n", err.Error())
}
}
You can’t perform that action at this time.