@ -0,0 +1,8 @@ |
|||
module github.com/arnaucube/slowlorisdb |
|||
|
|||
go 1.12 |
|||
|
|||
require ( |
|||
github.com/stretchr/testify v1.3.0 |
|||
github.com/syndtr/goleveldb v1.0.0 |
|||
) |
@ -0,0 +1,25 @@ |
|||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= |
|||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
|||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= |
|||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= |
|||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= |
|||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= |
|||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= |
|||
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= |
|||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= |
|||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
|||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= |
|||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= |
|||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= |
|||
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= |
|||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= |
|||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= |
|||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= |
|||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= |
|||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
|||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
|||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= |
|||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= |
|||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
@ -0,0 +1,35 @@ |
|||
package node |
|||
|
|||
import ( |
|||
"crypto/ecdsa" |
|||
|
|||
"github.com/arnaucube/slowlorisdb/core" |
|||
"github.com/arnaucube/slowlorisdb/db" |
|||
) |
|||
|
|||
type Node struct { |
|||
PrivK *ecdsa.PrivateKey |
|||
Addr core.Address |
|||
Bc *core.Blockchain |
|||
} |
|||
|
|||
func NewNode(db *db.Db) (*Node, error) { |
|||
privK, err := core.NewKey() |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
addr := core.AddressFromPrivK(privK) |
|||
|
|||
bc := core.NewBlockchain(db) |
|||
|
|||
node := &Node{ |
|||
PrivK: privK, |
|||
Addr: addr, |
|||
Bc: bc, |
|||
} |
|||
return node, nil |
|||
} |
|||
|
|||
func (node *Node) Sign(m []byte) (*core.Signature, error) { |
|||
return core.Sign(node.PrivK, m) |
|||
} |
@ -0,0 +1,38 @@ |
|||
package node |
|||
|
|||
import ( |
|||
"io/ioutil" |
|||
"testing" |
|||
|
|||
"github.com/arnaucube/slowlorisdb/core" |
|||
"github.com/arnaucube/slowlorisdb/db" |
|||
"github.com/stretchr/testify/assert" |
|||
) |
|||
|
|||
func TestNode(t *testing.T) { |
|||
dir, err := ioutil.TempDir("", "db") |
|||
assert.Nil(t, err) |
|||
db, err := db.New(dir) |
|||
assert.Nil(t, err) |
|||
|
|||
node, err := NewNode(db) |
|||
assert.Nil(t, err) |
|||
|
|||
assert.Equal(t, node.Addr, core.AddressFromPrivK(node.PrivK)) |
|||
} |
|||
|
|||
func TestNodeSignature(t *testing.T) { |
|||
dir, err := ioutil.TempDir("", "db") |
|||
assert.Nil(t, err) |
|||
db, err := db.New(dir) |
|||
assert.Nil(t, err) |
|||
|
|||
node, err := NewNode(db) |
|||
assert.Nil(t, err) |
|||
|
|||
m := []byte("test") |
|||
sig, err := node.Sign(m) |
|||
assert.Nil(t, err) |
|||
pubK := node.PrivK.PublicKey |
|||
assert.True(t, core.VerifySignature(&pubK, m, *sig)) |
|||
} |