aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/message.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-10 21:17:32 +0800
committerobscuren <geffobscura@gmail.com>2014-12-10 21:17:32 +0800
commitdda778eda7ad9b94acf14c3c91c1c29e711e170f (patch)
treedfbb71a45399455fd2c2bb77ce72c8ce9d79ba45 /whisper/message.go
parent0f5c6c5e2daa9fbf3a0bb753debd8989a872823c (diff)
downloadgo-tangerine-dda778eda7ad9b94acf14c3c91c1c29e711e170f.tar.gz
go-tangerine-dda778eda7ad9b94acf14c3c91c1c29e711e170f.tar.zst
go-tangerine-dda778eda7ad9b94acf14c3c91c1c29e711e170f.zip
Updated whisper messages to new crypto api + added tests
Diffstat (limited to 'whisper/message.go')
-rw-r--r--whisper/message.go18
1 files changed, 12 insertions, 6 deletions
diff --git a/whisper/message.go b/whisper/message.go
index 408b9f7df..8ce5d880b 100644
--- a/whisper/message.go
+++ b/whisper/message.go
@@ -1,6 +1,7 @@
package whisper
import (
+ "crypto/ecdsa"
"time"
"github.com/ethereum/go-ethereum/crypto"
@@ -20,13 +21,17 @@ func (self *Message) hash() []byte {
return crypto.Sha3(append([]byte{self.Flags}, self.Payload...))
}
-func (self *Message) sign(key []byte) (err error) {
+func (self *Message) sign(key *ecdsa.PrivateKey) (err error) {
self.Flags = 1
self.Signature, err = crypto.Sign(self.hash(), key)
return
}
-func (self *Message) Encrypt(from, to []byte) (err error) {
+func (self *Message) Recover() *ecdsa.PublicKey {
+ return crypto.SigToPub(self.hash(), self.Signature)
+}
+
+func (self *Message) Encrypt(from *ecdsa.PrivateKey, to *ecdsa.PublicKey) (err error) {
err = self.sign(from)
if err != nil {
return err
@@ -45,13 +50,14 @@ func (self *Message) Bytes() []byte {
}
type Opts struct {
- From, To []byte // private(sender), public(receiver) key
- Ttl time.Duration
- Topics [][]byte
+ From *ecdsa.PrivateKey
+ To *ecdsa.PublicKey
+ Ttl time.Duration
+ Topics [][]byte
}
func (self *Message) Seal(pow time.Duration, opts Opts) (*Envelope, error) {
- if len(opts.To) > 0 && len(opts.From) > 0 {
+ if opts.To != nil && opts.From != nil {
if err := self.Encrypt(opts.From, opts.To); err != nil {
return nil, err
}