diff --git a/ethapi/private_account.go b/ethapi/private_account.go new file mode 100644 index 00000000..8d51fd31 --- /dev/null +++ b/ethapi/private_account.go @@ -0,0 +1,26 @@ +package ethapi + +import ( + "context" + + "github.com/ethereum/go-ethereum/accounts" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/internal/ethapi" +) + +type LimitedPersonalAPI struct { + privateAPI *ethapi.PrivateAccountAPI +} + +func NewLimitedPersonalAPI(am *accounts.Manager) *LimitedPersonalAPI { + return &LimitedPersonalAPI{ethapi.NewSubsetOfPrivateAccountAPI(am)} +} + +func (s *LimitedPersonalAPI) Sign(ctx context.Context, data hexutil.Bytes, addr common.Address, passwd string) (hexutil.Bytes, error) { + return s.privateAPI.Sign(ctx, data, addr, passwd) +} + +func (s *LimitedPersonalAPI) EcRecover(ctx context.Context, data, sig hexutil.Bytes) (common.Address, error) { + return s.privateAPI.EcRecover(ctx, data, sig) +} diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 31408633..3cee8753 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -214,6 +214,14 @@ func NewPrivateAccountAPI(b Backend, nonceLock *AddrLocker) *PrivateAccountAPI { } } +func NewSubsetOfPrivateAccountAPI(am *accounts.Manager) *PrivateAccountAPI { + return &PrivateAccountAPI{ + am: am, + nonceLock: nil, + b: nil, + } +} + // ListAccounts will return a list of addresses for accounts this node manages. func (s *PrivateAccountAPI) ListAccounts() []common.Address { addresses := make([]common.Address, 0) // return [] instead of nil if empty @@ -426,7 +434,7 @@ func (s *PrivateAccountAPI) Sign(ctx context.Context, data hexutil.Bytes, addr c // Look up the wallet containing the requested signer account := accounts.Account{Address: addr} - wallet, err := s.b.AccountManager().Find(account) + wallet, err := s.am.Find(account) if err != nil { return nil, err }