tlsn_prover/
config.rs

1use std::sync::Arc;
2
3use mpc_tls::Config;
4use tlsn_common::config::ProtocolConfig;
5use tlsn_core::{connection::ServerName, CryptoProvider};
6
7/// Configuration for the prover
8#[derive(Debug, Clone, derive_builder::Builder)]
9pub struct ProverConfig {
10    /// The server DNS name.
11    #[builder(setter(into))]
12    server_name: ServerName,
13    /// Protocol configuration to be checked with the verifier.
14    protocol_config: ProtocolConfig,
15    /// Whether the `deferred decryption` feature is toggled on from the start
16    /// of the MPC-TLS connection.
17    #[builder(default = "true")]
18    defer_decryption_from_start: bool,
19    /// Cryptography provider.
20    #[builder(default, setter(into))]
21    crypto_provider: Arc<CryptoProvider>,
22}
23
24impl ProverConfig {
25    /// Create a new builder for `ProverConfig`.
26    pub fn builder() -> ProverConfigBuilder {
27        ProverConfigBuilder::default()
28    }
29
30    /// Returns the server DNS name.
31    pub fn server_name(&self) -> &ServerName {
32        &self.server_name
33    }
34
35    /// Returns the crypto provider.
36    pub fn crypto_provider(&self) -> &CryptoProvider {
37        &self.crypto_provider
38    }
39
40    /// Returns the protocol configuration.
41    pub fn protocol_config(&self) -> &ProtocolConfig {
42        &self.protocol_config
43    }
44
45    /// Returns whether the `deferred decryption` feature is toggled on from the
46    /// start of the MPC-TLS connection.
47    pub fn defer_decryption_from_start(&self) -> bool {
48        self.defer_decryption_from_start
49    }
50
51    pub(crate) fn build_mpc_tls_config(&self) -> Config {
52        let mut builder = Config::builder();
53
54        builder
55            .defer_decryption(self.defer_decryption_from_start)
56            .max_sent(self.protocol_config.max_sent_data())
57            .max_recv_online(self.protocol_config.max_recv_data_online())
58            .max_recv(self.protocol_config.max_recv_data());
59
60        if let Some(max_sent_records) = self.protocol_config.max_sent_records() {
61            builder.max_sent_records(max_sent_records);
62        }
63
64        if let Some(max_recv_records) = self.protocol_config.max_recv_records() {
65            builder.max_recv_records(max_recv_records);
66        }
67
68        builder.build().unwrap()
69    }
70}