99#include " ../meta/meta_base_wrapper.hpp"
1010#include " ../utilities.hpp"
1111#include " meta/meta_base_wrapper.hpp"
12+ #include " session/pro_backend.hpp"
1213#include " session/session_protocol.hpp"
1314
1415namespace session ::nodeapi {
@@ -31,6 +32,10 @@ class ProWrapper : public Napi::ObjectWrap<ProWrapper> {
3132 " proFeaturesForMessage" ,
3233 static_cast <napi_property_attributes>(
3334 napi_writable | napi_configurable)),
35+ StaticMethod<&ProWrapper::proProofRequestBody>(
36+ " proProofRequestBody" ,
37+ static_cast <napi_property_attributes>(
38+ napi_writable | napi_configurable)),
3439 });
3540 }
3641
@@ -89,6 +94,53 @@ class ProWrapper : public Napi::ObjectWrap<ProWrapper> {
8994 return obj;
9095 });
9196 };
97+
98+ static Napi::Value proProofRequestBody (const Napi::CallbackInfo& info) {
99+ return wrapResult (info, [&] {
100+ // we expect arguments that match:
101+ // first: {
102+ // "requestVersion": string,
103+ // "masterPrivkey": Uint8Array,
104+ // "rotatingPrivkey": Uint8Array,
105+ // "unixTsMs": number,
106+ // }
107+
108+ assertInfoLength (info, 1 );
109+ assertIsObject (info[0 ]);
110+ auto env = info.Env ();
111+
112+ auto first = info[0 ].As <Napi::Object>();
113+
114+ if (first.IsEmpty ())
115+ throw std::invalid_argument (" proProofRequestBody first received empty" );
116+
117+ assertIsNumber (first.Get (" requestVersion" ), " proProofRequestBody.requestVersion" );
118+ assertIsNumber (first.Get (" unixTsMs" ), " proProofRequestBody.unixTsMs" );
119+ auto requestVersion = first.Get (" requestVersion" ).As <Napi::Number>();
120+ auto unix_ts_ms = toCppSysMs (first.Get (" unixTsMs" ), " proProofRequestBody.unixTsMs" );
121+
122+ assertIsUInt8Array (first.Get (" masterPrivkey" ), " proProofRequestBody.masterPrivkey" );
123+ assertIsUInt8Array (first.Get (" rotatingPrivkey" ), " proProofRequestBody.rotatingPrivkey" );
124+
125+ auto master_privkey_js = first.Get (" masterPrivkey" );
126+ auto rotating_privkey_js = first.Get (" rotatingPrivkey" );
127+ auto master_privkey =
128+ toCppBuffer (master_privkey_js, " proProofRequestBody.masterPrivkey" );
129+ auto rotating_privkey =
130+ toCppBuffer (rotating_privkey_js, " proProofRequestBody.rotatingPrivkey" );
131+
132+ assert_length (master_privkey, 64 , " master_privkey" );
133+ assert_length (rotating_privkey, 64 , " rotating_prevkey" );
134+
135+ auto json = pro_backend::GetProProofRequest::build_to_json (
136+ static_cast <uint8_t >(requestVersion.Int32Value ()),
137+ master_privkey,
138+ rotating_privkey,
139+ unix_ts_ms);
140+
141+ return json;
142+ });
143+ };
92144};
93145
94146}; // namespace session::nodeapi
0 commit comments