diff --git a/include/pro/pro.hpp b/include/pro/pro.hpp index 71bfbee..4f7a62f 100644 --- a/include/pro/pro.hpp +++ b/include/pro/pro.hpp @@ -9,6 +9,7 @@ #include "../meta/meta_base_wrapper.hpp" #include "../utilities.hpp" #include "meta/meta_base_wrapper.hpp" +#include "session/pro_backend.hpp" #include "session/session_protocol.hpp" namespace session::nodeapi { @@ -31,6 +32,10 @@ class ProWrapper : public Napi::ObjectWrap { "proFeaturesForMessage", static_cast( napi_writable | napi_configurable)), + StaticMethod<&ProWrapper::proProofRequestBody>( + "proProofRequestBody", + static_cast( + napi_writable | napi_configurable)), }); } @@ -89,6 +94,53 @@ class ProWrapper : public Napi::ObjectWrap { return obj; }); }; + + static Napi::Value proProofRequestBody(const Napi::CallbackInfo& info) { + return wrapResult(info, [&] { + // we expect arguments that match: + // first: { + // "requestVersion": string, + // "masterPrivkey": Uint8Array, + // "rotatingPrivkey": Uint8Array, + // "unixTsMs": number, + // } + + assertInfoLength(info, 1); + assertIsObject(info[0]); + auto env = info.Env(); + + auto first = info[0].As(); + + if (first.IsEmpty()) + throw std::invalid_argument("proProofRequestBody first received empty"); + + assertIsNumber(first.Get("requestVersion"), "proProofRequestBody.requestVersion"); + assertIsNumber(first.Get("unixTsMs"), "proProofRequestBody.unixTsMs"); + auto requestVersion = first.Get("requestVersion").As(); + auto unix_ts_ms = toCppSysMs(first.Get("unixTsMs"), "proProofRequestBody.unixTsMs"); + + assertIsUInt8Array(first.Get("masterPrivkey"), "proProofRequestBody.masterPrivkey"); + assertIsUInt8Array(first.Get("rotatingPrivkey"), "proProofRequestBody.rotatingPrivkey"); + + auto master_privkey_js = first.Get("masterPrivkey"); + auto rotating_privkey_js = first.Get("rotatingPrivkey"); + auto master_privkey = + toCppBuffer(master_privkey_js, "proProofRequestBody.masterPrivkey"); + auto rotating_privkey = + toCppBuffer(rotating_privkey_js, "proProofRequestBody.rotatingPrivkey"); + + assert_length(master_privkey, 64, "master_privkey"); + assert_length(rotating_privkey, 64, "rotating_prevkey"); + + auto json = pro_backend::GetProProofRequest::build_to_json( + static_cast(requestVersion.Int32Value()), + master_privkey, + rotating_privkey, + unix_ts_ms); + + return json; + }); + }; }; }; // namespace session::nodeapi diff --git a/include/utilities.hpp b/include/utilities.hpp index 886935b..e98085f 100644 --- a/include/utilities.hpp +++ b/include/utilities.hpp @@ -60,6 +60,7 @@ auto getStringArgs(const Napi::CallbackInfo& info) { } std::string toCppString(Napi::Value x, const std::string& identifier); +std::span toCppBufferView(Napi::Value x, const std::string& identifier); std::vector toCppBuffer(Napi::Value x, const std::string& identifier); int64_t toCppInteger(Napi::Value x, const std::string& identifier, bool allowUndefined = false); diff --git a/types/pro/pro.d.ts b/types/pro/pro.d.ts index b9d7a6d..806c15c 100644 --- a/types/pro/pro.d.ts +++ b/types/pro/pro.d.ts @@ -74,9 +74,16 @@ declare module 'libsession_util_nodejs' { */ proFeatures: ProFeatures; }) => WithProFeatures & { success: boolean; error: string | null; codepointCount: number }; + proProofRequestBody: (args: { + requestVersion: string, + masterPrivkey: Uint8Array, + rotatingPrivkey: Uint8Array, + unixTsMs: number, + } + ) => string; }; - export type ProActionsCalls = MakeWrapperActionCalls; + export type ProActionsCalls = MakeWrapperActionCalls; /**