~edwargix/tallyard

1349e560b342ce574e194ffbb394c3fa96606b57 — David Florness 3 years ago 9032775
Delete old Nonce implementation

This was left over from the libp2p implementation.
3 files changed, 0 insertions(+), 32 deletions(-)

M election/merkle.go
M go.mod
M go.sum
M election/merkle.go => election/merkle.go +0 -29
@@ 1,11 1,9 @@
package election

import (
	"crypto/rand"
	"crypto/sha256"

	"github.com/cbergoon/merkletree"
	"github.com/mr-tron/base58/base58"
)

type Candidate string


@@ 21,30 19,3 @@ func (eo Candidate) CalculateHash() ([]byte, error) {
func (eo Candidate) Equals(other merkletree.Content) (bool, error) {
	return eo == other.(Candidate), nil
}

type Nonce string

func NewNonce() Nonce {
	randBytes := make([]byte, 128)
	_, err := rand.Read(randBytes)
	if err != nil {
		panic(err)
	}
	return Nonce(base58.Encode(randBytes))
}

func (n Nonce) CalculateHash() ([]byte, error) {
	h := sha256.New()
	b, err := base58.Decode(string(n))
	if err != nil {
		return nil, err
	}
	if _, err = h.Write(b); err != nil {
		return nil, err
	}
	return h.Sum(nil), nil
}

func (n Nonce) Equals(other merkletree.Content) (bool, error) {
	return n == other.(Nonce), nil
}

M go.mod => go.mod +0 -1
@@ 9,7 9,6 @@ require (
	github.com/kyoh86/xdg v1.2.0
	github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
	github.com/magefile/mage v1.11.0 // indirect
	github.com/mr-tron/base58 v1.2.0
	github.com/rivo/tview v0.0.0-20210217110421-8a8f78a6dd01
	github.com/sirupsen/logrus v1.8.0
	golang.org/x/crypto v0.0.0-20210218145215-b8e89b74b9df

M go.sum => go.sum +0 -2
@@ 53,8 53,6 @@ github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRR
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA=
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=