Documentation
¶
Overview ¶
Package xposedornot provides a Go client for the XposedOrNot API, which allows checking whether email addresses and passwords have been exposed in known data breaches.
The client supports both the free API and the commercial Plus API. Use NewClient with functional options to configure the client:
// Free API usage
client, err := xposedornot.NewClient()
if err != nil {
log.Fatal(err)
}
// Plus API usage with API key
client, err := xposedornot.NewClient(
xposedornot.WithAPIKey("your-api-key"),
xposedornot.WithTimeout(30 * time.Second),
)
if err != nil {
log.Fatal(err)
}
All methods accept a context.Context for cancellation and timeout control.
The free API is rate-limited to 1 request per second on the client side. Plus API users with an API key bypass this rate limit.
The client automatically retries on HTTP 429 (Too Many Requests) responses with exponential backoff (1s, 2s, 4s) up to 3 retries by default.
Error handling uses typed errors that can be checked with errors.Is and errors.As:
_, _, err := client.CheckEmail(ctx, "test@example.com")
var notFound *xposedornot.ErrNotFound
if errors.As(err, ¬Found) {
// email not found in any breaches
}
Index ¶
- type BreachAnalyticsResponse
- type BreachDetail
- type BreachMetrics
- type BreachesSummary
- type CheckEmailFreeResponse
- type CheckEmailPlusResponse
- type CheckPasswordResponse
- type Client
- func (c *Client) BreachAnalytics(ctx context.Context, email string) (*BreachAnalyticsResponse, error)
- func (c *Client) CheckEmail(ctx context.Context, email string) (*CheckEmailFreeResponse, *CheckEmailPlusResponse, error)
- func (c *Client) CheckPassword(ctx context.Context, password string) (*CheckPasswordResponse, error)
- func (c *Client) GetBreaches(ctx context.Context, domain string) (*GetBreachesResponse, error)
- type ClientOption
- func WithAPIKey(key string) ClientOption
- func WithAllowInsecure() ClientOption
- func WithBaseURL(url string) ClientOption
- func WithCustomHeaders(headers map[string]string) ClientOption
- func WithMaxRetries(n int) ClientOption
- func WithPasswordBaseURL(url string) ClientOption
- func WithPlusBaseURL(url string) ClientOption
- func WithTimeout(d time.Duration) ClientOption
- type ErrAPI
- type ErrAuthentication
- type ErrNetwork
- type ErrNotFound
- type ErrRateLimit
- type ErrValidation
- type ExposedBreach
- type ExposedBreachesWrapper
- type GetBreachesResponse
- type PasswordAnonResult
- type PasteSummary
- type PlusBreach
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BreachAnalyticsResponse ¶
type BreachAnalyticsResponse struct {
ExposedBreaches ExposedBreachesWrapper `json:"ExposedBreaches"`
BreachesSummary BreachesSummary `json:"BreachesSummary"`
BreachMetrics BreachMetrics `json:"BreachMetrics"`
PastesSummary PasteSummary `json:"PastesSummary"`
ExposedPastes []interface{} `json:"ExposedPastes"`
}
BreachAnalyticsResponse is the response from the breach-analytics endpoint.
type BreachDetail ¶
type BreachDetail struct {
Breach string `json:"breach"`
Details string `json:"details"`
Domain string `json:"domain"`
Industry string `json:"industry"`
Logo string `json:"logo"`
PasswordRisk string `json:"password_risk"`
References string `json:"references"`
Searchable string `json:"searchable"`
Verified string `json:"verified"`
XposedData string `json:"xposed_data"`
XposedDate string `json:"xposed_date"`
XposedRecords int `json:"xposed_records"`
}
BreachDetail represents a single breach detail in breach analytics.
type BreachMetrics ¶
type BreachMetrics struct {
Industry []interface{} `json:"industry"`
PasswordStrength []interface{} `json:"passwords_strength"`
YearlyBreaches []interface{} `json:"yearwise_details"`
XposedData []interface{} `json:"xposed_data"`
}
BreachMetrics contains metrics derived from breach analytics.
type BreachesSummary ¶
type BreachesSummary struct {
Site string `json:"site"`
TotalBreaches string `json:"total_breaches,omitempty"`
MostRecentBreach string `json:"most_recent_breach,omitempty"`
FirstBreach string `json:"first_breach,omitempty"`
ExposedData string `json:"exposed_data,omitempty"`
PasswordRisk string `json:"password_risk,omitempty"`
}
BreachesSummary contains summary information about an email's breaches.
type CheckEmailFreeResponse ¶
type CheckEmailFreeResponse struct {
Breaches [][]string `json:"breaches"`
}
CheckEmailFreeResponse is the response from the free check-email endpoint.
type CheckEmailPlusResponse ¶
type CheckEmailPlusResponse struct {
Status string `json:"status"`
Email string `json:"email"`
Breaches []PlusBreach `json:"breaches"`
}
CheckEmailPlusResponse is the response from the Plus API check-email endpoint.
type CheckPasswordResponse ¶
type CheckPasswordResponse struct {
SearchPassAnon PasswordAnonResult `json:"SearchPassAnon"`
}
CheckPasswordResponse is the response from the password check endpoint.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an API client for the XposedOrNot service.
func NewClient ¶
func NewClient(opts ...ClientOption) (*Client, error)
NewClient creates a new XposedOrNot API client with the given options. It returns an error if any base URL does not use HTTPS, unless WithAllowInsecure() is set.
func (*Client) BreachAnalytics ¶
func (c *Client) BreachAnalytics(ctx context.Context, email string) (*BreachAnalyticsResponse, error)
BreachAnalytics retrieves detailed breach analytics for the given email address, including breach details, summary, metrics, and paste information.
func (*Client) CheckEmail ¶
func (c *Client) CheckEmail(ctx context.Context, email string) (*CheckEmailFreeResponse, *CheckEmailPlusResponse, error)
CheckEmail checks whether the given email address has been exposed in any known data breaches. If the client has an API key configured, it uses the Plus API and returns a detailed response; otherwise it uses the free API.
For the free API, only CheckEmailFreeResponse is populated (second return value is nil). For the Plus API, only CheckEmailPlusResponse is populated (first return value is nil).
func (*Client) CheckPassword ¶
func (c *Client) CheckPassword(ctx context.Context, password string) (*CheckPasswordResponse, error)
CheckPassword checks whether the given password has been exposed in known data breaches. The password is hashed locally using the original Keccak-512 algorithm, and only the first 10 characters of the hex digest are sent to the API, preserving privacy through k-anonymity.
func (*Client) GetBreaches ¶
GetBreaches retrieves a list of known data breaches. If domain is non-empty, results are filtered to breaches affecting that domain.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is a functional option for configuring the Client.
func WithAPIKey ¶
func WithAPIKey(key string) ClientOption
WithAPIKey sets the API key for the Plus API. When set, requests to the Plus API include the x-api-key header and client-side rate limiting is disabled.
func WithAllowInsecure ¶
func WithAllowInsecure() ClientOption
WithAllowInsecure disables the HTTPS enforcement check on base URLs. This is intended for testing purposes only.
func WithBaseURL ¶
func WithBaseURL(url string) ClientOption
WithBaseURL overrides the default free API base URL.
func WithCustomHeaders ¶
func WithCustomHeaders(headers map[string]string) ClientOption
WithCustomHeaders sets additional headers to include in every request.
func WithMaxRetries ¶
func WithMaxRetries(n int) ClientOption
WithMaxRetries sets the maximum number of retries on 429 responses. Default is 3.
func WithPasswordBaseURL ¶
func WithPasswordBaseURL(url string) ClientOption
WithPasswordBaseURL overrides the default password API base URL.
func WithPlusBaseURL ¶
func WithPlusBaseURL(url string) ClientOption
WithPlusBaseURL overrides the default Plus API base URL.
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
WithTimeout sets the HTTP client timeout.
type ErrAPI ¶
ErrAPI is returned when the API returns an unexpected error response that does not map to a more specific error type.
type ErrAuthentication ¶
type ErrAuthentication struct {
Message string
}
ErrAuthentication is returned when the API returns a 401 or 403 response, typically due to a missing or invalid API key.
func (*ErrAuthentication) Error ¶
func (e *ErrAuthentication) Error() string
type ErrNetwork ¶
type ErrNetwork struct {
Err error
}
ErrNetwork is returned when a network-level error occurs, such as a connection timeout or DNS resolution failure.
func (*ErrNetwork) Error ¶
func (e *ErrNetwork) Error() string
func (*ErrNetwork) Unwrap ¶
func (e *ErrNetwork) Unwrap() error
type ErrNotFound ¶
type ErrNotFound struct {
Resource string
}
ErrNotFound is returned when the requested resource is not found (404).
func (*ErrNotFound) Error ¶
func (e *ErrNotFound) Error() string
type ErrRateLimit ¶
type ErrRateLimit struct {
Message string
}
ErrRateLimit is returned when the API returns a 429 Too Many Requests response after all retries have been exhausted.
func (*ErrRateLimit) Error ¶
func (e *ErrRateLimit) Error() string
type ErrValidation ¶
ErrValidation is returned when input validation fails on the client side, such as an invalid email address format.
func (*ErrValidation) Error ¶
func (e *ErrValidation) Error() string
type ExposedBreach ¶
type ExposedBreach struct {
BreachID string `json:"breachID"`
BreachedDate string `json:"breachedDate"`
Domain string `json:"domain"`
Industry string `json:"industry"`
ExposedData []string `json:"exposedData"`
ExposedRecords int `json:"exposedRecords"`
Verified bool `json:"verified"`
Logo string `json:"logo"`
References string `json:"references"`
Details string `json:"details"`
PasswordRisk string `json:"password_risk"`
}
ExposedBreach represents a single breach from the breaches listing endpoint.
type ExposedBreachesWrapper ¶
type ExposedBreachesWrapper struct {
BreachesDetails []BreachDetail `json:"breaches_details"`
}
ExposedBreachesWrapper wraps breach details in the analytics response.
type GetBreachesResponse ¶
type GetBreachesResponse struct {
ExposedBreaches []ExposedBreach `json:"exposedBreaches"`
}
GetBreachesResponse is the response from the breaches listing endpoint.
type PasswordAnonResult ¶
type PasswordAnonResult struct {
Anon string `json:"anon"`
Char string `json:"char"`
Count string `json:"count"`
}
PasswordAnonResult contains the anonymized password check result.
type PasteSummary ¶
type PasteSummary struct {
Count int `json:"cnt"`
Domain string `json:"domain"`
FirstSeen string `json:"first_seen,omitempty"`
LastSeen string `json:"last_seen,omitempty"`
}
PasteSummary contains paste-related summary information.
type PlusBreach ¶
type PlusBreach struct {
BreachID string `json:"breach_id"`
BreachedDate string `json:"breached_date"`
Logo string `json:"logo"`
PasswordRisk string `json:"password_risk"`
Searchable string `json:"searchable"`
XposedData string `json:"xposed_data"`
XposedRecords int `json:"xposed_records"`
XposureDesc string `json:"xposure_desc"`
Domain string `json:"domain"`
}
PlusBreach represents a single breach entry from the Plus API.