Documentation
¶
Overview ¶
Package sdkey is the official Go client for SDKey license authentication.
It implements the sealed session protocol (Ed25519-verified handshake, HKDF session keys, AES-256-GCM validate envelopes) and plaintext register/login/upgrade client auth. See PROTOCOL.md.
Index ¶
- type Client
- func (c *Client) ClearSession()
- func (c *Client) GetSession() *SessionState
- func (c *Client) Init(ctx context.Context) (*SessionState, error)
- func (c *Client) Login(ctx context.Context, opts LoginOptions) (*ClientAuthResult, error)
- func (c *Client) Register(ctx context.Context, opts RegisterOptions) (*ClientAuthResult, error)
- func (c *Client) Session() *SessionState
- func (c *Client) Upgrade(ctx context.Context, opts UpgradeOptions) (*ClientAuthResult, error)
- func (c *Client) Validate(ctx context.Context, licenseKey, hwid string) (*ValidateResult, error)
- type ClientAuthResult
- type ClientLicense
- type ClientOptions
- type ClientSessionInfo
- type ClientUser
- type Error
- type ErrorCode
- type HTTPPost
- type LoginOptions
- type RegisterOptions
- type SessionState
- type UpgradeOptions
- type ValidateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the SDKey license client.
Flow: Init (session handshake) → Validate (sealed request). Validate calls Init automatically when no session exists. Register / Login / Upgrade are plaintext JSON client-auth helpers (not sealed).
func NewClient ¶
func NewClient(opts ClientOptions) *Client
NewClient constructs a Client from options.
func (*Client) ClearSession ¶
func (c *Client) ClearSession()
ClearSession drops the current session (next Validate will re-init).
func (*Client) GetSession ¶
func (c *Client) GetSession() *SessionState
GetSession is an alias for Session (API parity with Python get_session).
func (*Client) Init ¶
func (c *Client) Init(ctx context.Context) (*SessionState, error)
Init performs the challenge handshake, verifies the signed hello, and derives the AES session key. Sends clientVersion from AppVersion. Failures surface the server error string and code.
func (*Client) Login ¶ added in v0.2.0
func (c *Client) Login(ctx context.Context, opts LoginOptions) (*ClientAuthResult, error)
Login authenticates via POST /api/v1/client/login (plaintext JSON).
func (*Client) Register ¶ added in v0.2.0
func (c *Client) Register(ctx context.Context, opts RegisterOptions) (*ClientAuthResult, error)
Register creates a user account via POST /api/v1/client/register (plaintext JSON). Business failures return ClientAuthResult with Success=false and server Error/Code.
func (*Client) Session ¶
func (c *Client) Session() *SessionState
Session returns the active session, if any.
func (*Client) Upgrade ¶ added in v0.2.0
func (c *Client) Upgrade(ctx context.Context, opts UpgradeOptions) (*ClientAuthResult, error)
Upgrade links a higher-tier license via POST /api/v1/client/upgrade. Sends username + licenseKey only (no password).
type ClientAuthResult ¶ added in v0.2.0
type ClientAuthResult struct {
Success bool
SessionToken string
ExpiresAt string
User *ClientUser
License *ClientLicense
Session *ClientSessionInfo
// Code and Error are set on failure (server code + customizable error text).
Code string
Error string
}
ClientAuthResult is a plaintext register/login/upgrade response. Success has no customizable message. Failures put server text in Error (not Message).
type ClientLicense ¶ added in v0.2.0
ClientLicense is the linked license on an auth success (may be nil).
type ClientOptions ¶
type ClientOptions struct {
// APIBaseURL is the API origin (trailing slashes are stripped).
APIBaseURL string
// AppID is the application UUID from the SDKey dashboard.
AppID string
// AppVersion is the exact application version string. Sent as clientVersion
// on session init and client auth; must match applications.version or the
// server returns APP_OUTDATED.
AppVersion string
// AppPublicKeyB64 is the raw Ed25519 public key (32 bytes), standard or URL-safe base64.
AppPublicKeyB64 string
// HTTPPost optionally overrides the default HTTPS JSON transport (tests / custom agents).
HTTPPost HTTPPost
}
ClientOptions configures NewClient.
type ClientSessionInfo ¶ added in v0.2.0
ClientSessionInfo is IP/HWID metadata from an auth success.
type ClientUser ¶ added in v0.2.0
ClientUser is the authenticated user returned by register/login/upgrade.
type Error ¶
type Error struct {
Code ErrorCode
Message string
ServerCode string // API response "code" when present (e.g. APP_OUTDATED)
Cause error
}
Error is a protocol or transport failure. License denials (banned, HWID mismatch, etc.) return ValidateResult, not Error. Client auth business failures return ClientAuthResult with Success=false, not Error.
type ErrorCode ¶
type ErrorCode string
ErrorCode identifies protocol / transport failures (not license denials).
const ( ErrInitFailed ErrorCode = "INIT_FAILED" ErrHelloSignatureInvalid ErrorCode = "HELLO_SIGNATURE_INVALID" ErrValidateResponseInvalid ErrorCode = "VALIDATE_RESPONSE_INVALID" ErrResponseSignatureInvalid ErrorCode = "RESPONSE_SIGNATURE_INVALID" ErrSessionMismatch ErrorCode = "SESSION_MISMATCH" ErrClockSkew ErrorCode = "CLOCK_SKEW" ErrAuthFailed ErrorCode = "AUTH_FAILED" ErrNetwork ErrorCode = "NETWORK" ErrUnknown ErrorCode = "UNKNOWN" )
type HTTPPost ¶
type HTTPPost func(ctx context.Context, url string, body map[string]any) (status int, response map[string]any, err error)
HTTPPost posts a JSON body and returns status code plus parsed JSON object. Used for injectable transport in tests and custom HTTP stacks.
type LoginOptions ¶ added in v0.2.0
LoginOptions is the plaintext login request. HWID is omitted from JSON when empty.
type RegisterOptions ¶ added in v0.2.0
type RegisterOptions struct {
Username string
Password string
Email string
LicenseKey string
HWID string
}
RegisterOptions is the plaintext register request (password required). Optional fields are omitted from JSON when empty.
type SessionState ¶
type SessionState struct {
SessionID string
AESKey []byte
ServerNonceB64 string
HKDFSaltB64 string
}
SessionState is the active sealed session after a successful Init.
type UpgradeOptions ¶ added in v0.2.0
UpgradeOptions upgrades a user's linked license (username + license key only; no password). HWID is omitted from JSON when empty.
type ValidateResult ¶
type ValidateResult struct {
Success bool
Code string
Message string
Status *string
ExpiresAt *string
SubscriptionTier int
Timestamp int64
}
ValidateResult is a decrypted, signature-verified license validate response. License denials use Success=false with a code; they are not SdkeyError. User-facing text for both success and failure is in Message (not Error).