Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify to work with non-BLS code pruned away #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ linters:
- asciicheck
- bodyclose
- deadcode
- depguard
#- depguard
- dogsled
- dupl
- errcheck
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ install: install-bls

.PHONY: all

include test/Makefile
#include test/Makefile

###############################################################################
### Build/Install BLS library ###
Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Build & Test

```sh
git submodule init
git submodule update

make build-bls

sudo cp \
./third_party/bls-signatures/build/depends/mimalloc/libmimalloc-secure.a \
./third_party/bls-signatures/build/depends/relic/lib/librelic_s.a \
./third_party/bls-signatures/build/src/libdashbls.a \
/usr/local/lib/

sudo cp -R \
./third_party/bls-signatures/src/include/dashbls \
/usr/local/include/

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/
```

# TODO

```text
~/.local/opt/relic/lib/
~/.local/opt/relic/include/
~/.local/opt/dashbls/lib/
~/.local/opt/dashbls/include/
~/.local/opt/mimalloc/lib/
```
42 changes: 42 additions & 0 deletions cmd/tenderbls/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"encoding/hex"
"fmt"
"log"

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

func main() {
secret := []byte("it's a secret")
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")
}
6 changes: 0 additions & 6 deletions crypto/bls12381/bls12381.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
bls "github.com/dashpay/bls-signatures/go-bindings"

"github.com/dashpay/tenderdash/crypto"
"github.com/dashpay/tenderdash/internal/jsontypes"
tmbytes "github.com/dashpay/tenderdash/libs/bytes"
)

Expand Down Expand Up @@ -49,11 +48,6 @@ var (
schema = bls.NewBasicSchemeMPL()
)

func init() {
jsontypes.MustRegister(PubKey{})
jsontypes.MustRegister(PrivKey{})
}

// BasicScheme returns basic bls scheme
func BasicScheme() *bls.BasicSchemeMPL {
return schema
Expand Down
41 changes: 0 additions & 41 deletions crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/dashpay/dashd-go/btcjson"

"github.com/dashpay/tenderdash/internal/jsontypes"
tmbytes "github.com/dashpay/tenderdash/libs/bytes"
)

Expand Down Expand Up @@ -127,41 +126,6 @@ type quorumKeysJSON struct {
ThresholdPublicKey json.RawMessage `json:"threshold_public_key"`
}

func (pvKey QuorumKeys) MarshalJSON() ([]byte, error) {
var keys quorumKeysJSON
var err error
keys.PrivKey, err = jsontypes.Marshal(pvKey.PrivKey)
if err != nil {
return nil, err
}
keys.PubKey, err = jsontypes.Marshal(pvKey.PubKey)
if err != nil {
return nil, err
}
keys.ThresholdPublicKey, err = jsontypes.Marshal(pvKey.ThresholdPublicKey)
if err != nil {
return nil, err
}
return json.Marshal(keys)
}

func (pvKey *QuorumKeys) UnmarshalJSON(data []byte) error {
var keys quorumKeysJSON
err := json.Unmarshal(data, &keys)
if err != nil {
return err
}
err = jsontypes.Unmarshal(keys.PrivKey, &pvKey.PrivKey)
if err != nil {
return err
}
err = jsontypes.Unmarshal(keys.PubKey, &pvKey.PubKey)
if err != nil {
return err
}
return jsontypes.Unmarshal(keys.ThresholdPublicKey, &pvKey.ThresholdPublicKey)
}

// Validator is a validator interface
type Validator interface {
Validate() error
Expand All @@ -175,8 +139,6 @@ type PubKey interface {
Equals(PubKey) bool
Type() string

// Implementations must support tagged encoding in JSON.
jsontypes.Tagged
fmt.Stringer
HexStringer
}
Expand All @@ -188,9 +150,6 @@ type PrivKey interface {
PubKey() PubKey
Equals(PrivKey) bool
Type() string

// Implementations must support tagged encoding in JSON.
jsontypes.Tagged
}

type Symmetric interface {
Expand Down
121 changes: 0 additions & 121 deletions internal/jsontypes/jsontypes.go

This file was deleted.

Loading