PolymarketClob.Auth.L2 (PolymarketClob v0.2.0)

Copy Markdown View Source

Level 2 HMAC authentication for authenticated CLOB API requests.

L2 auth signs timestamp <> method <> request_path <> body with the API secret returned by CLOB API-key derivation.

Summary

Functions

Builds L2 auth headers using the current Unix timestamp.

Builds L2 auth headers with an explicit, caller-supplied timestamp.

Computes the CLOB HMAC-SHA256 request signature.

Functions

headers(address, api_key, api_secret, api_passphrase, method, request_path, body \\ nil)

@spec headers(
  String.t(),
  String.t(),
  String.t(),
  String.t(),
  String.t(),
  String.t(),
  String.t() | nil
) :: map()

Builds L2 auth headers using the current Unix timestamp.

To supply your own timestamp, use headers_at/8. This arity intentionally omits the timestamp so a caller-supplied one can never be silently bound to the method positional and replaced by system time.

headers_at(address, api_key, api_secret, api_passphrase, timestamp, method, request_path, body)

@spec headers_at(
  String.t(),
  String.t(),
  String.t(),
  String.t(),
  String.t() | integer(),
  String.t(),
  String.t(),
  String.t() | nil
) :: map()

Builds L2 auth headers with an explicit, caller-supplied timestamp.

Prefer this over headers/7 whenever you need a specific timestamp: every positional argument has a stable meaning here, so the timestamp can never be mistaken for the HTTP method.

sign(api_secret, timestamp, method, request_path, body \\ nil)

@spec sign(
  String.t(),
  String.t() | integer(),
  String.t(),
  String.t(),
  String.t() | nil
) :: String.t()

Computes the CLOB HMAC-SHA256 request signature.

The API secret is URL-safe base64 encoded. The returned signature is also URL-safe base64 encoded with padding, matching the official Python client.