diff --git a/keystore/geth/keystore.go b/keystore/geth/keystore.go index 9f779f6..95cc3d1 100644 --- a/keystore/geth/keystore.go +++ b/keystore/geth/keystore.go @@ -13,6 +13,8 @@ import ( keystore "github.com/kilnfi/go-utils/keystore" ) +var _ keystore.Store = &KeyStore{} + type KeyStore struct { cfg *Config keys *gethkeystore.KeyStore @@ -70,3 +72,15 @@ func (s *KeyStore) SignTx(_ context.Context, addr gethcommon.Address, tx *gethty func (s *KeyStore) HasAccount(_ context.Context, addr gethcommon.Address) (bool, error) { return s.keys.HasAddress(addr), nil } + +func (s *KeyStore) SignerAddress(_ context.Context) (gethcommon.Address, error) { + if s.keys == nil { + return gethcommon.Address{}, fmt.Errorf("no cached keys") + } + accs := s.keys.Accounts() + if len(accs) < 1 { + return gethcommon.Address{}, fmt.Errorf("keystore has no accounts") + } + // select first (primary account) address + return accs[0].Address, nil +} diff --git a/keystore/keystore.go b/keystore/keystore.go index 568b574..a0f40dc 100644 --- a/keystore/keystore.go +++ b/keystore/keystore.go @@ -19,4 +19,5 @@ type Store interface { HasAccount(ctx context.Context, addr gethcommon.Address) (bool, error) SignTx(ctx context.Context, addr gethcommon.Address, tx *gethtypes.Transaction, chainID *big.Int) (*gethtypes.Transaction, error) Import(ctx context.Context, hexkey string) (*Account, error) + SignerAddress(context.Context) (gethcommon.Address, error) }