From dda778eda7ad9b94acf14c3c91c1c29e711e170f Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 10 Dec 2014 14:17:32 +0100 Subject: Updated whisper messages to new crypto api + added tests --- whisper/message.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'whisper/message.go') 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 } -- cgit