1use crate::types::Endpoints;
2
3#[derive(Clone, Debug)]
4pub struct Endpoint {
5 pub path: &'static str,
6 pub version: &'static str,
7}
8
9#[derive(Clone, Debug)]
10pub struct NagaEndpoints {
11 pub handshake: Endpoint,
12 pub sign_session_key: Endpoint,
13 pub execute_js: Endpoint,
14 pub pkp_sign: Endpoint,
15 pub pkp_claim: Endpoint,
16 pub encryption_sign: Endpoint,
17}
18
19pub const NAGA_ENDPOINTS: NagaEndpoints = NagaEndpoints {
20 handshake: Endpoint {
21 path: "/web/handshake",
22 version: "/",
23 },
24 sign_session_key: Endpoint {
25 path: "/web/sign_session_key",
26 version: "/v2",
27 },
28 execute_js: Endpoint {
29 path: "/web/execute",
30 version: "/v2",
31 },
32 pkp_sign: Endpoint {
33 path: "/web/pkp/sign",
34 version: "/v2",
35 },
36 pkp_claim: Endpoint {
37 path: "/web/pkp/claim",
38 version: "/",
39 },
40 encryption_sign: Endpoint {
41 path: "/web/encryption/sign",
42 version: "/v2",
43 },
44};
45
46#[derive(Clone, Debug)]
47pub struct NetworkConfig {
48 pub network: &'static str,
49 pub rpc_url: Option<String>,
50 pub http_protocol: &'static str,
51 pub bootstrap_urls: Vec<String>,
52 pub minimum_threshold: usize,
53 pub required_attestation: bool,
54 pub abort_timeout_ms: u64,
55 pub endpoints: NagaEndpoints,
56}
57
58impl NetworkConfig {
59 pub fn endpoints(&self) -> Endpoints {
60 Endpoints {
61 naga: self.endpoints.clone(),
62 }
63 }
64
65 pub fn with_bootstrap_urls<I, S>(mut self, urls: I) -> Self
66 where
67 I: IntoIterator<Item = S>,
68 S: Into<String>,
69 {
70 self.bootstrap_urls = urls.into_iter().map(Into::into).collect();
71 self
72 }
73
74 pub fn with_rpc_url(mut self, rpc_url: impl Into<String>) -> Self {
75 self.rpc_url = Some(rpc_url.into());
76 self
77 }
78}
79
80pub fn naga_dev() -> NetworkConfig {
81 NetworkConfig {
82 network: "naga-dev",
83 rpc_url: None,
84 http_protocol: "https://",
85 bootstrap_urls: vec![],
86 minimum_threshold: 3,
87 required_attestation: false,
88 abort_timeout_ms: 20_000,
89 endpoints: NAGA_ENDPOINTS,
90 }
91}
92
93pub fn naga_test() -> NetworkConfig {
94 NetworkConfig {
95 network: "naga-test",
96 rpc_url: None,
97 http_protocol: "https://",
98 bootstrap_urls: vec![],
99 minimum_threshold: 3,
100 required_attestation: true,
101 abort_timeout_ms: 20_000,
102 endpoints: NAGA_ENDPOINTS,
103 }
104}
105
106pub fn naga_staging() -> NetworkConfig {
107 NetworkConfig {
108 network: "naga-staging",
109 rpc_url: None,
110 http_protocol: "https://",
111 bootstrap_urls: vec![],
112 minimum_threshold: 3,
113 required_attestation: true,
114 abort_timeout_ms: 20_000,
115 endpoints: NAGA_ENDPOINTS,
116 }
117}
118
119pub fn naga_proto() -> NetworkConfig {
120 NetworkConfig {
121 network: "naga-proto",
122 rpc_url: None,
123 http_protocol: "https://",
124 bootstrap_urls: vec![],
125 minimum_threshold: 3,
126 required_attestation: true,
127 abort_timeout_ms: 20_000,
128 endpoints: NAGA_ENDPOINTS,
129 }
130}
131
132pub fn naga_mainnet() -> NetworkConfig {
133 NetworkConfig {
134 network: "naga",
135 rpc_url: None,
136 http_protocol: "https://",
137 bootstrap_urls: vec![],
138 minimum_threshold: 3,
139 required_attestation: true,
140 abort_timeout_ms: 20_000,
141 endpoints: NAGA_ENDPOINTS,
142 }
143}
144
145pub fn naga_local() -> NetworkConfig {
146 NetworkConfig {
147 network: "naga-local",
148 rpc_url: None,
149 http_protocol: "http://",
150 bootstrap_urls: vec![],
151 minimum_threshold: 3,
152 required_attestation: false,
153 abort_timeout_ms: 20_000,
154 endpoints: NAGA_ENDPOINTS,
155 }
156}