Skip to content

Commit

Permalink
feat(keystore): Add SignerAddress (#4)
Browse files Browse the repository at this point in the history
* feat(keystore): Add SignerAddress

* lint

* simplify
  • Loading branch information
ATMackay committed May 2, 2024
1 parent e8ff178 commit 14bd5bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions keystore/geth/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
keystore "github.com/kilnfi/go-utils/keystore"
)

var _ keystore.Store = &KeyStore{}

type KeyStore struct {
cfg *Config
keys *gethkeystore.KeyStore
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 14bd5bf

Please sign in to comment.