lit_node_core/models/
response.rs

1use super::{DynamicPaymentItem, SignableOutput, SignedData, default_epoch};
2use lit_rust_crypto::blsful::{Bls12381G2Impl, SignatureShare};
3use serde::{Deserialize, Serialize, de::DeserializeOwned};
4use serde_json::Value;
5use std::collections::HashMap;
6
7#[derive(Clone, Debug, Default, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct JsonSDKHandshakeResponse {
10    pub server_public_key: String,
11    pub subnet_public_key: String,
12    pub network_public_key: String,
13    pub network_public_key_set: String,
14    pub client_sdk_version: String,
15    pub hd_root_pubkeys: Vec<String>,
16    pub attestation: Option<Value>,
17    pub latest_blockhash: String,
18    pub node_version: String,
19    pub node_identity_key: String,
20    #[serde(default = "default_epoch")]
21    pub epoch: u64,
22    pub git_commit_hash: String,
23}
24
25#[derive(Clone, Debug, Serialize, Deserialize)]
26#[serde(rename_all = "camelCase")]
27pub struct EncryptionSignResponse {
28    pub result: String,
29    pub signature_share: SignatureShare<Bls12381G2Impl>,
30    pub share_id: String,
31}
32
33#[derive(Clone, Debug, Serialize, Deserialize)]
34#[serde(bound = "T: Serialize + DeserializeOwned")]
35pub struct GenericResponse<T>
36where
37    T: Serialize + DeserializeOwned,
38{
39    pub ok: bool,
40    pub error: Option<String>,
41    #[serde(rename = "errorObject")]
42    pub error_object: Option<String>,
43    pub data: Option<T>,
44}
45
46impl<T> GenericResponse<T>
47where
48    T: Serialize + DeserializeOwned,
49{
50    pub fn ok(data: T) -> Self {
51        Self {
52            ok: true,
53            error: None,
54            error_object: None,
55            data: Some(data),
56        }
57    }
58}
59
60impl GenericResponse<String> {
61    pub fn err(error: String) -> Self {
62        Self {
63            ok: false,
64            error: Some(error),
65            error_object: None,
66            data: None,
67        }
68    }
69    pub fn err_and_data(error: String, object: String) -> Self {
70        Self {
71            ok: false,
72            error: Some(error),
73            error_object: Some(object),
74            data: None,
75        }
76    }
77
78    pub fn err_and_data_json<E: Serialize + DeserializeOwned>(error: String, object: E) -> Self {
79        Self::err_and_data(
80            error,
81            serde_json::to_string(&object).expect("to serialize to string"),
82        )
83    }
84}
85
86#[derive(Clone, Debug, Serialize, Deserialize)]
87#[serde(rename_all = "camelCase")]
88pub struct JsonSignSessionKeyResponseV2 {
89    pub result: String,
90    pub signature_share: SignatureShare<Bls12381G2Impl>,
91    pub share_id: String,
92    pub curve_type: String,
93    pub siwe_message: String,
94    pub data_signed: String,
95    pub bls_root_pubkey: String,
96}
97
98#[derive(Debug, Serialize, Deserialize, Clone)]
99#[serde(rename_all = "camelCase")]
100pub struct JsonPKPSigningResponse {
101    pub success: bool,
102    pub signed_data: Vec<u8>,
103    pub signature_share: SignableOutput,
104}
105
106#[derive(Serialize, Deserialize, Clone, Debug)]
107#[serde(rename_all = "camelCase")]
108pub struct JsonExecutionResponse {
109    pub success: bool,
110    pub signed_data: HashMap<String, SignedData>,
111    pub decrypted_data: Value,
112    pub claim_data: HashMap<String, JsonPKPClaimKeyResponse>,
113    pub response: String,
114    pub logs: String,
115    pub payment_detail: Option<Vec<DynamicPaymentItem>>,
116}
117
118#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
119#[serde(rename_all = "camelCase")]
120pub struct JsonPKPClaimKeyResponse {
121    pub signature: String,
122    pub derived_key_id: String,
123}