github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/valkeystore/sync.go (about) 1 package valkeystore 2 3 import ( 4 "sync" 5 6 "github.com/unicornultrafoundation/go-u2u/native/validatorpk" 7 "github.com/unicornultrafoundation/go-u2u/valkeystore/encryption" 8 ) 9 10 type SyncedKeystore struct { 11 backend KeystoreI 12 mu sync.Mutex 13 } 14 15 func NewSyncedKeystore(backend KeystoreI) *SyncedKeystore { 16 return &SyncedKeystore{ 17 backend: backend, 18 } 19 } 20 21 func (s *SyncedKeystore) Unlocked(pubkey validatorpk.PubKey) bool { 22 s.mu.Lock() 23 defer s.mu.Unlock() 24 return s.backend.Unlocked(pubkey) 25 } 26 27 func (s *SyncedKeystore) Has(pubkey validatorpk.PubKey) bool { 28 s.mu.Lock() 29 defer s.mu.Unlock() 30 return s.backend.Has(pubkey) 31 } 32 33 func (s *SyncedKeystore) Unlock(pubkey validatorpk.PubKey, auth string) error { 34 s.mu.Lock() 35 defer s.mu.Unlock() 36 return s.backend.Unlock(pubkey, auth) 37 } 38 39 func (s *SyncedKeystore) GetUnlocked(pubkey validatorpk.PubKey) (*encryption.PrivateKey, error) { 40 s.mu.Lock() 41 defer s.mu.Unlock() 42 return s.backend.GetUnlocked(pubkey) 43 } 44 45 func (s *SyncedKeystore) Add(pubkey validatorpk.PubKey, key []byte, auth string) error { 46 s.mu.Lock() 47 defer s.mu.Unlock() 48 return s.backend.Add(pubkey, key, auth) 49 } 50 51 func (s *SyncedKeystore) Get(pubkey validatorpk.PubKey, auth string) (*encryption.PrivateKey, error) { 52 s.mu.Lock() 53 defer s.mu.Unlock() 54 return s.backend.Get(pubkey, auth) 55 }