diff --git a/cmd/clef/extapi_changelog.md b/cmd/clef/extapi_changelog.md index 2014e90ae4..3629727b00 100644 --- a/cmd/clef/extapi_changelog.md +++ b/cmd/clef/extapi_changelog.md @@ -1,6 +1,11 @@ ### Changelog for external API +### 3.0.0 + +* The external `accounts_List`-method was changed to not expose `url`, which contained information about the local machine. It now returns a set of addresses: `[]common.Address`. +* The method was also renamed into `accounts_listAccounts`. + #### 2.0.0 diff --git a/cmd/clef/intapi_changelog.md b/cmd/clef/intapi_changelog.md index 7d2a897ea2..aa7087cd0c 100644 --- a/cmd/clef/intapi_changelog.md +++ b/cmd/clef/intapi_changelog.md @@ -1,5 +1,9 @@ ### Changelog for internal API (ui-api) +### 3.0.0 + +* The external `accounts_List`-method was changed to not expose `url`, which contained information about the local machine. Thus, the internal method `approveListing` was changed correspondingly, to contain only a set of addresses: `[]common.Address` + ### 2.0.0 * Modify how `call_info` on a transaction is conveyed. New format: diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index f4ace2b3ef..d1e6eeefb0 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -225,9 +225,7 @@ func (s *PrivateAccountAPI) ListAccounts() []common.Address { addresses := make([]common.Address, 0) // return [] instead of nil if empty if s.extapi != nil { if accounts, err := s.extapi.listAccounts(); err == nil { - for _, account := range accounts { - addresses = append(addresses, account.Address) - } + return accounts } return addresses } @@ -1553,9 +1551,9 @@ func (api *ExternalSignerAPI) signTransaction(ctx context.Context, args SendTxAr } return res.Tx, nil } -func (api *ExternalSignerAPI) listAccounts() ([]accounts.Account, error) { - var res []accounts.Account - if err := api.client.Call(&res, "account_list"); err != nil { +func (api *ExternalSignerAPI) listAccounts() ([]common.Address, error) { + var res []common.Address + if err := api.client.Call(&res, "account_listAccounts"); err != nil { return nil, err } return res, nil diff --git a/signer/core/api.go b/signer/core/api.go index 9a2a49ccc6..eda1537fac 100644 --- a/signer/core/api.go +++ b/signer/core/api.go @@ -38,8 +38,8 @@ import ( // ExternalAPI defines the external API through which signing requests are made. type ExternalAPI interface { - // List available accounts - List(ctx context.Context) (Accounts, error) + // ListAccounts lists available accounts (addresses) + ListAccounts(ctx context.Context) ([]common.Address, error) // New request to create a new account New(ctx context.Context) (accounts.Account, error) // SignTransaction request to sign the specified transaction @@ -66,7 +66,7 @@ type SignerUI interface { ApproveImport(request *ImportRequest) (ImportResponse, error) // ApproveListing prompt the user for confirmation to list accounts // the list of accounts to list can be modified by the UI - ApproveListing(request *ListRequest) (ListResponse, error) + ApproveListing(request *ListAccountsRequest) (ListAccountsResponse, error) // ApproveNewAccount prompt the user for confirmation to create new Account, and reveal to caller ApproveNewAccount(request *NewAccountRequest) (NewAccountResponse, error) // ShowError displays error message to user @@ -172,12 +172,12 @@ type ( Approved bool `json:"approved"` Password string `json:"password"` } - ListRequest struct { - Accounts []Account `json:"accounts"` + ListAccountsRequest struct { + Accounts []common.Address `json:"accounts"` Meta Metadata `json:"meta"` } - ListResponse struct { - Accounts []Account `json:"accounts"` + ListAccountsResponse struct { + Accounts []common.Address `json:"accounts"` } Message struct { Text string `json:"text"` @@ -225,17 +225,16 @@ func NewSignerAPI(chainID int64, ksLocation string, noUSB bool, ui SignerUI, abi return &SignerAPI{big.NewInt(chainID), accounts.NewManager(backends...), ui, NewValidator(abidb)} } -// List returns the set of wallet this signer manages. Each wallet can contain +// ListAccounts returns the set of wallet this signer manages. Each wallet can contain // multiple accounts. -func (api *SignerAPI) List(ctx context.Context) (Accounts, error) { - var accs []Account +func (api *SignerAPI) ListAccounts(ctx context.Context) ([]common.Address, error) { + addresses := make([]common.Address, 0) // return [] instead of nil if empty for _, wallet := range api.am.Wallets() { - for _, acc := range wallet.Accounts() { - acc := Account{Typ: "Account", URL: wallet.URL(), Address: acc.Address} - accs = append(accs, acc) + for _, account := range wallet.Accounts() { + addresses = append(addresses, account.Address) } } - result, err := api.UI.ApproveListing(&ListRequest{Accounts: accs, Meta: MetadataFromContext(ctx)}) + result, err := api.UI.ApproveListing(&ListAccountsRequest{Accounts: addresses, Meta: MetadataFromContext(ctx)}) if err != nil { return nil, err } diff --git a/signer/core/api_test.go b/signer/core/api_test.go index 50ad021987..bc15d16d44 100644 --- a/signer/core/api_test.go +++ b/signer/core/api_test.go @@ -80,17 +80,17 @@ func (ui *HeadlessUI) ApproveImport(request *ImportRequest) (ImportResponse, err } return ImportResponse{false, "", ""}, nil } -func (ui *HeadlessUI) ApproveListing(request *ListRequest) (ListResponse, error) { +func (ui *HeadlessUI) ApproveListing(request *ListRequest) (ListAccountsResponse, error) { switch <-ui.controller { case "A": - return ListResponse{request.Accounts}, nil + return ListAccountsResponse{request.Accounts}, nil case "1": l := make([]Account, 1) l[0] = request.Accounts[1] - return ListResponse{l}, nil + return ListAccountsResponse{l}, nil default: - return ListResponse{nil}, nil + return ListAccountsResponse{nil}, nil } } func (ui *HeadlessUI) ApproveNewAccount(request *NewAccountRequest) (NewAccountResponse, error) { diff --git a/signer/core/auditlog.go b/signer/core/auditlog.go index d0ba733d2f..6ba99d4497 100644 --- a/signer/core/auditlog.go +++ b/signer/core/auditlog.go @@ -33,12 +33,10 @@ type AuditLogger struct { api ExternalAPI } -func (l *AuditLogger) List(ctx context.Context) (Accounts, error) { - l.log.Info("List", "type", "request", "metadata", MetadataFromContext(ctx).String()) - res, e := l.api.List(ctx) - - l.log.Info("List", "type", "response", "data", res.String()) - +func (l *AuditLogger) ListAccounts(ctx context.Context) ([]common.Address, error) { + l.log.Info("ListAccounts", "type", "request", "metadata", MetadataFromContext(ctx).String()) + res, e := l.api.ListAccounts(ctx) + l.log.Info("ListAccounts", "type", "response", "data", res) return res, e } diff --git a/signer/core/cliui.go b/signer/core/cliui.go index 7b75ceefa1..3cbbe57959 100644 --- a/signer/core/cliui.go +++ b/signer/core/cliui.go @@ -190,7 +190,7 @@ func (ui *CommandlineUI) ApproveImport(request *ImportRequest) (ImportResponse, // ApproveListing prompt the user for confirmation to list accounts // the list of accounts to list can be modified by the UI -func (ui *CommandlineUI) ApproveListing(request *ListRequest) (ListResponse, error) { +func (ui *CommandlineUI) ApproveListing(request *ListRequest) (ListAccountsResponse, error) { ui.mu.Lock() defer ui.mu.Unlock() @@ -204,9 +204,9 @@ func (ui *CommandlineUI) ApproveListing(request *ListRequest) (ListResponse, err fmt.Printf("-------------------------------------------\n") showMetadata(request.Meta) if !ui.confirm() { - return ListResponse{nil}, nil + return ListAccountsResponse{nil}, nil } - return ListResponse{request.Accounts}, nil + return ListAccountsResponse{request.Accounts}, nil } // ApproveNewAccount prompt the user for confirmation to create new Account, and reveal to caller diff --git a/signer/core/stdioui.go b/signer/core/stdioui.go index 5640ed03bd..d240e46267 100644 --- a/signer/core/stdioui.go +++ b/signer/core/stdioui.go @@ -73,8 +73,8 @@ func (ui *StdIOUI) ApproveImport(request *ImportRequest) (ImportResponse, error) return result, err } -func (ui *StdIOUI) ApproveListing(request *ListRequest) (ListResponse, error) { - var result ListResponse +func (ui *StdIOUI) ApproveListing(request *ListRequest) (ListAccountsResponse, error) { + var result ListAccountsResponse err := ui.dispatch("ApproveListing", request, &result) return result, err } diff --git a/signer/rules/rules.go b/signer/rules/rules.go index 711e2dddec..4c6983763f 100644 --- a/signer/rules/rules.go +++ b/signer/rules/rules.go @@ -194,7 +194,7 @@ func (r *rulesetUI) ApproveImport(request *core.ImportRequest) (core.ImportRespo return r.next.ApproveImport(request) } -func (r *rulesetUI) ApproveListing(request *core.ListRequest) (core.ListResponse, error) { +func (r *rulesetUI) ApproveListing(request *core.ListRequest) (core.ListAccountsResponse, error) { jsonreq, err := json.Marshal(request) approved, err := r.checkApproval("ApproveListing", jsonreq, err) if err != nil { @@ -202,9 +202,9 @@ func (r *rulesetUI) ApproveListing(request *core.ListRequest) (core.ListResponse return r.next.ApproveListing(request) } if approved { - return core.ListResponse{Accounts: request.Accounts}, nil + return core.ListAccountsResponse{Accounts: request.Accounts}, nil } - return core.ListResponse{}, err + return core.ListAccountsResponse{}, err } func (r *rulesetUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) { diff --git a/signer/rules/rules_test.go b/signer/rules/rules_test.go index b6060eba73..65d26e0a70 100644 --- a/signer/rules/rules_test.go +++ b/signer/rules/rules_test.go @@ -93,8 +93,8 @@ func (alwaysDenyUI) ApproveImport(request *core.ImportRequest) (core.ImportRespo return core.ImportResponse{Approved: false, OldPassword: "", NewPassword: ""}, nil } -func (alwaysDenyUI) ApproveListing(request *core.ListRequest) (core.ListResponse, error) { - return core.ListResponse{Accounts: nil}, nil +func (alwaysDenyUI) ApproveListing(request *core.ListRequest) (core.ListAccountsResponse, error) { + return core.ListAccountsResponse{Accounts: nil}, nil } func (alwaysDenyUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) { @@ -220,9 +220,9 @@ func (d *dummyUI) ApproveImport(request *core.ImportRequest) (core.ImportRespons return core.ImportResponse{}, core.ErrRequestDenied } -func (d *dummyUI) ApproveListing(request *core.ListRequest) (core.ListResponse, error) { +func (d *dummyUI) ApproveListing(request *core.ListRequest) (core.ListAccountsResponse, error) { d.calls = append(d.calls, "ApproveListing") - return core.ListResponse{}, core.ErrRequestDenied + return core.ListAccountsResponse{}, core.ErrRequestDenied } func (d *dummyUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) { @@ -532,9 +532,9 @@ func (d *dontCallMe) ApproveImport(request *core.ImportRequest) (core.ImportResp return core.ImportResponse{}, core.ErrRequestDenied } -func (d *dontCallMe) ApproveListing(request *core.ListRequest) (core.ListResponse, error) { +func (d *dontCallMe) ApproveListing(request *core.ListRequest) (core.ListAccountsResponse, error) { d.t.Fatalf("Did not expect next-handler to be called") - return core.ListResponse{}, core.ErrRequestDenied + return core.ListAccountsResponse{}, core.ErrRequestDenied } func (d *dontCallMe) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) {