Files
dasy/crypto/crypto.go
Dean Eigenmann ae2fb13f53 feature/payloads (#7)
* started working on payload concept

* added crypto

* moved into new package, added feed

* added nicer feed stuff

* minor readme for now

* subscribe implemented badly

* doc

* doc block

* cleaned up a little

* making a mutex

* mock, empty test

* test wrapper

* started playing around

* updated mock

* formatted

* updated

* updated interface

* updated

* updated

* updated mock, rewrote test stuff

* todos

* added tests

* reuse

* dont need var
2019-08-07 14:31:32 +02:00

29 lines
555 B
Go

package crypto
import (
"crypto/ecdsa"
"github.com/ethereum/go-ethereum/crypto"
"github.com/vacp2p/dasy/protobuf"
"github.com/vacp2p/mvds/state"
)
func PublicKeyToPeerID(k ecdsa.PublicKey) state.PeerID {
var p state.PeerID
copy(p[:], crypto.FromECDSAPub(&k))
return p
}
// Sign signs generates a signature of the message and adds it to the message.
func Sign(identity *ecdsa.PrivateKey, m *protobuf.Message) error {
hash := m.ID()
sig, err := crypto.Sign(hash[:], identity)
if err != nil {
return err
}
m.Signature = sig
return nil
}