Documentation
¶
Overview ¶
Package polyauth provides EIP-712 signing and authentication header generation for the Polymarket CLOB API.
Signer ¶
Signer wraps a secp256k1 ECDSA private key and produces EIP-712 typed-data signatures. Create one via ParsePrivateKey(hexKey) or from an existing *ecdsa.PrivateKey. Use Address() to get the associated wallet address.
L1 Headers — API Key Creation ¶
L1Headers returns POLY_ADDRESS, POLY_SIGNATURE, POLY_TIMESTAMP, and POLY_NONCE headers for wallet-signed requests used to create or derive API keys (CreateAPIKey / DeriveAPIKey endpoints).
L2 Headers — Full Trading Auth ¶
L2Headers returns headers for all order/trade endpoints. It requires an API key, a decoded HMAC secret (see DecodeAPISecret), a passphrase, and the request method/path/body to compute the HMAC signature.
Key Handling ¶
GenerateKey produces a new hex-encoded secp256k1 private key. ParsePrivateKey parses a hex-encoded key (with or without "0x" prefix) into a Signer. DecodeAPISecret decodes a URL-safe base64 Polymarket API secret into raw bytes for HMAC signing.
Index ¶
- func DecodeAPISecret(secret string) ([]byte, error)
- func GenerateKey() (string, error)
- func HMACSignature(secret string, timestamp int64, method, requestPath string, body []byte) (string, error)
- func HMACSignatureBytes(secret []byte, timestamp int64, method, requestPath string, body []byte) string
- func L1Headers(signer *Signer, chainID, timestamp, nonce int64) (map[string]string, error)
- func L2Headers(signer *Signer, key string, secret []byte, passphrase string, timestamp int64, ...) (map[string]string, error)
- func SignHash(signer *Signer, digest []byte) (string, error)
- func SignTypedData(signer *Signer, typedData apitypes.TypedData) (string, error)
- type Signer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeAPISecret ¶
DecodeAPISecret decodes a URL-safe base64 Polymarket API secret.
func GenerateKey ¶
GenerateKey creates a new secp256k1 private key and returns it as hex.
func HMACSignature ¶
func HMACSignature(secret string, timestamp int64, method, requestPath string, body []byte) (string, error)
HMACSignature signs a request with a base64-encoded Polymarket API secret.
func HMACSignatureBytes ¶
func HMACSignatureBytes(secret []byte, timestamp int64, method, requestPath string, body []byte) string
HMACSignatureBytes signs a request with a decoded Polymarket API secret.
func L2Headers ¶
func L2Headers(signer *Signer, key string, secret []byte, passphrase string, timestamp int64, method, path string, body []byte) (map[string]string, error)
L2Headers returns Polymarket L2 headers for API-key authenticated requests.
Types ¶
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
func ParsePrivateKey ¶
ParsePrivateKey parses a hex-encoded secp256k1 private key.
func (*Signer) PrivateKey ¶
func (s *Signer) PrivateKey() *ecdsa.PrivateKey
PrivateKey returns the underlying ECDSA private key.