polyauth

package
v1.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeAPISecret

func DecodeAPISecret(secret string) ([]byte, error)

DecodeAPISecret decodes a URL-safe base64 Polymarket API secret.

func GenerateKey

func GenerateKey() (string, error)

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 L1Headers

func L1Headers(signer *Signer, chainID, timestamp, nonce int64) (map[string]string, error)

L1Headers returns Polymarket L1 headers for API-key creation and derivation.

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.

func SignHash added in v1.1.5

func SignHash(signer *Signer, digest []byte) (string, error)

SignHash signs a 32-byte digest and returns a 0x-prefixed Ethereum signature.

func SignTypedData

func SignTypedData(signer *Signer, typedData apitypes.TypedData) (string, error)

SignTypedData signs EIP-712 typed data with signer.

Types

type Signer

type Signer struct {
	// contains filtered or unexported fields
}

func ParsePrivateKey

func ParsePrivateKey(raw string) (*Signer, error)

ParsePrivateKey parses a hex-encoded secp256k1 private key.

func (*Signer) Address

func (s *Signer) Address() common.Address

Address returns the Ethereum address for the signer.

func (*Signer) PrivateKey

func (s *Signer) PrivateKey() *ecdsa.PrivateKey

PrivateKey returns the underlying ECDSA private key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL