diff --git a/client/client.go b/client/client.go index 529ce2d..6e19217 100644 --- a/client/client.go +++ b/client/client.go @@ -19,24 +19,15 @@ import ( type Client struct { http.Client - URL string - PubKey []byte - Sign SignFunc - Validate ValidateFunc - Log slog.Logger + URL string + PubKey []byte + // Sign is a function which must be provided to an instance of Client so + // that it can sign request bodies using the PrivKey of the specified + // address. + Sign func(context.Context, string, stdaddr.Address) ([]byte, error) + Log slog.Logger } -// SignFunc is the signature of a function must be provided to an instance of -// Client so that it can sign request bodies using the PrivKey of the specified -// address. -type SignFunc func(context.Context, string, stdaddr.Address) ([]byte, error) - -// ValidateFunc is the signature of a function which must be provided to an -// instance of Client so that it can validate that HTTP responses are signed -// with the provided pubkey. This package provides a default implementation of -// ValidateFunc named ValidateServerResponse. -type ValidateFunc func(resp *http.Response, body []byte, serverPubkey []byte) error - func (c *Client) VspInfo(ctx context.Context) (*types.VspInfoResponse, error) { var resp *types.VspInfoResponse err := c.get(ctx, "/api/v3/vspinfo", &resp) @@ -223,7 +214,7 @@ func (c *Client) do(ctx context.Context, method, path string, addr stdaddr.Addre status, http.StatusText(status), respBody) } - err = c.Validate(reply, respBody, c.PubKey) + err = ValidateServerSignature(reply, respBody, c.PubKey) if err != nil { return fmt.Errorf("authenticate server response: %v", err) } diff --git a/client/client_test.go b/client/client_test.go index 8543caa..2f1f809 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -7,19 +7,10 @@ import ( "net/http/httptest" "testing" - "github.com/decred/dcrd/txscript/v4/stdaddr" "github.com/decred/slog" "github.com/decred/vspd/types" ) -func NoopSign(ctx context.Context, message string, address stdaddr.Address) ([]byte, error) { - return nil, nil -} - -func NoopValidate(resp *http.Response, body []byte, serverPubkey []byte) error { - return nil -} - // TestErrorDetails ensures errors returned by client.do contain adequate // information for debugging (HTTP status and response body). func TestErrorDetails(t *testing.T) { @@ -68,11 +59,9 @@ func TestErrorDetails(t *testing.T) { })) client := Client{ - URL: testServer.URL, - PubKey: []byte("fake pubkey"), - Sign: NoopSign, - Validate: NoopValidate, - Log: slog.Disabled, + URL: testServer.URL, + PubKey: []byte("fake pubkey"), + Log: slog.Disabled, } var resp interface{}