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 envelopes) for validate and client auth (register / login / upgrade). See PROTOCOL.md.
Index ¶
- func GetHardwareID() (string, error)
- 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 ¶
func GetHardwareID ¶ added in v0.3.0
GetHardwareID returns a SHA-256 hex digest of a stable OS machine identifier.
It reads a platform-specific machine ID (Windows MachineGuid, Linux machine-id, or macOS IOPlatformUUID), trims whitespace, hashes the UTF-8 bytes with SHA-256, and returns lowercase hex (64 characters).
Opt-in only — pass the result to Validate / Register / Login / Upgrade when binding a license to a machine. Omit (empty string) for web clients.
Returns *Error with Code HWID_UNAVAILABLE if the platform is unsupported or the machine ID is missing/empty. Does not invent a random ID.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the SDKey license client.
Flow: Init (session handshake) → sealed Validate / Register / Login / Upgrade. Sealed operations call Init automatically when no session exists.
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 sealed call 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 sealed POST /api/v1/client/login.
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 sealed POST /api/v1/client/register. Business failures return ClientAuthResult with Success=false and server Code/Error (from message).
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 sealed 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 + sealed plaintext message).
Code string
Error string
}
ClientAuthResult is a sealed register/login/upgrade response. Failures map sealed plaintext message into Error (API field name unchanged).
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; must match applications.version or the server returns APP_OUTDATED.
// Sealed client-auth binds the app via the crypto session (no appId/clientVersion in inner body).
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 sealed login inner body. HWID is omitted from the sealed 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 sealed register inner body (password required). Optional fields are omitted from the sealed 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 the sealed 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).