diff options
Diffstat (limited to 'whisper')
-rw-r--r-- | whisper/whisper.go | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/whisper/whisper.go b/whisper/whisper.go index ece2dd6d4..76cfe34a4 100644 --- a/whisper/whisper.go +++ b/whisper/whisper.go @@ -60,7 +60,7 @@ type Whisper struct { quit chan struct{} - keys []*ecdsa.PrivateKey + keys map[string]*ecdsa.PrivateKey } func New() *Whisper { @@ -69,6 +69,7 @@ func New() *Whisper { filters: filter.New(), expiry: make(map[uint32]*set.SetNonTS), quit: make(chan struct{}), + keys: make(map[string]*ecdsa.PrivateKey), } whisper.filters.Start() @@ -101,18 +102,18 @@ func (self *Whisper) NewIdentity() *ecdsa.PrivateKey { if err != nil { panic(err) } - self.keys = append(self.keys, key) + + self.keys[string(crypto.FromECDSAPub(&key.PublicKey))] = key return key } -func (self *Whisper) HasIdentity(key *ecdsa.PrivateKey) bool { - for _, key := range self.keys { - if key.D.Cmp(key.D) == 0 { - return true - } - } - return false +func (self *Whisper) HasIdentity(key *ecdsa.PublicKey) bool { + return self.keys[string(crypto.FromECDSAPub(key))] != nil +} + +func (self *Whisper) GetIdentity(key *ecdsa.PublicKey) *ecdsa.PrivateKey { + return self.keys[string(crypto.FromECDSAPub(key))] } func (self *Whisper) Watch(opts Filter) int { |