1use crate::common::{EncryptedBroadcastRequest, NodeIdentityKey, Response, UrlPrefix};
2use crate::{SdkError, SdkResult};
3use lit_node_core::{
4 AuthMethod, AuthSigItem, CurveType, NodeSet,
5 request::JsonSignSessionKeyRequestV2,
6 response::{GenericResponse, JsonSignSessionKeyResponseV2},
7};
8use std::{collections::HashMap, marker::PhantomData};
9use uuid::Uuid;
10
11pub type SignSessionKeyResponse = Response<GenericResponse<JsonSignSessionKeyResponseV2>>;
13
14pub type SignSessionKeyRequest = EncryptedBroadcastRequest<
16 SignSessionKeyRequestBuilder,
17 JsonSignSessionKeyRequestV2,
18 GenericResponse<JsonSignSessionKeyResponseV2>,
19>;
20
21encrypted_builder!(
22 SignSessionKeyRequestBuilder,
23 JsonSignSessionKeyRequestV2,
24 GenericResponse<JsonSignSessionKeyResponseV2>,
25 "web/sign_session_key/v2"
26);
27
28impl SignSessionKeyRequestBuilder {
29 builder_setter!(
30 session_key,
31 session_key,
32 String,
33 JsonSignSessionKeyRequestV2,
34 session_key
35 );
36 builder_setter!(
37 auth_methods,
38 auth_methods,
39 Vec<AuthMethod>,
40 JsonSignSessionKeyRequestV2,
41 auth_methods
42 );
43 builder_setter!(
44 pkp_public_key,
45 pkp_public_key,
46 Option<String>,
47 JsonSignSessionKeyRequestV2,
48 pkp_public_key
49 );
50 builder_setter!(
51 auth_sig,
52 auth_sig,
53 Option<AuthSigItem>,
54 JsonSignSessionKeyRequestV2,
55 auth_sig
56 );
57 builder_setter!(
58 siwe_message,
59 siwe_message,
60 String,
61 JsonSignSessionKeyRequestV2,
62 siwe_message
63 );
64 builder_setter!(
65 curve_type,
66 curve_type,
67 CurveType,
68 JsonSignSessionKeyRequestV2,
69 curve_type
70 );
71 builder_setter!(
72 code,
73 code,
74 Option<String>,
75 JsonSignSessionKeyRequestV2,
76 code
77 );
78 builder_setter!(
79 lit_action_ipfs_id,
80 lit_action_ipfs_id,
81 Option<String>,
82 JsonSignSessionKeyRequestV2,
83 lit_action_ipfs_id
84 );
85 builder_setter!(
86 js_params,
87 js_params,
88 Option<serde_json::Value>,
89 JsonSignSessionKeyRequestV2,
90 js_params
91 );
92 builder_setter!(epoch, epoch, u64, JsonSignSessionKeyRequestV2, epoch);
93 builder_setter!(
94 inner_node_set,
95 node_set,
96 Vec<NodeSet>,
97 JsonSignSessionKeyRequestV2,
98 node_set
99 );
100
101 fn request_checks(&self) -> SdkResult<()> {
103 let Some(request) = &self.request else {
104 return Ok(());
105 };
106 if request.session_key.is_empty() {
107 return Err(SdkError::Build("No session_key is specified".to_string()));
108 }
109 Ok(())
110 }
111}