Skip to main content

polymarket_relayer/auth/
mod.rs

1pub mod builder;
2pub mod relayer_key;
3
4use reqwest::header::HeaderMap;
5
6/// Authentication method for the relayer.
7#[derive(Debug, Clone)]
8pub enum AuthMethod {
9    /// Builder Program HMAC-SHA256 authentication.
10    Builder(BuilderConfig),
11    /// Simple Relayer API key authentication.
12    RelayerKey { api_key: String, address: String },
13}
14
15impl AuthMethod {
16    /// Create a Builder auth method.
17    pub fn builder(key: &str, secret: &str, passphrase: &str) -> Self {
18        AuthMethod::Builder(BuilderConfig {
19            key: key.to_string(),
20            secret: secret.to_string(),
21            passphrase: passphrase.to_string(),
22        })
23    }
24
25    /// Create a Relayer Key auth method.
26    pub fn relayer_key(api_key: &str, address: &str) -> Self {
27        AuthMethod::RelayerKey {
28            api_key: api_key.to_string(),
29            address: address.to_string(),
30        }
31    }
32
33    /// Generate auth headers for a request.
34    pub fn headers(
35        &self,
36        method: &str,
37        path: &str,
38        body: &str,
39    ) -> crate::error::Result<HeaderMap> {
40        match self {
41            AuthMethod::Builder(config) => builder::build_headers(config, method, path, body),
42            AuthMethod::RelayerKey { api_key, address } => {
43                relayer_key::build_headers(api_key, address)
44            }
45        }
46    }
47}
48
49/// Builder Program API key credentials.
50#[derive(Debug, Clone)]
51pub struct BuilderConfig {
52    pub key: String,
53    pub secret: String,
54    pub passphrase: String,
55}