Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions include/pro/pro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -31,6 +32,10 @@ class ProWrapper : public Napi::ObjectWrap<ProWrapper> {
"proFeaturesForMessage",
static_cast<napi_property_attributes>(
napi_writable | napi_configurable)),
StaticMethod<&ProWrapper::proProofRequestBody>(
"proProofRequestBody",
static_cast<napi_property_attributes>(
napi_writable | napi_configurable)),
});
}

Expand Down Expand Up @@ -89,6 +94,53 @@ class ProWrapper : public Napi::ObjectWrap<ProWrapper> {
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<Napi::Object>();

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<Napi::Number>();
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<uint8_t>(requestVersion.Int32Value()),
master_privkey,
rotating_privkey,
unix_ts_ms);

return json;
});
};
};

}; // namespace session::nodeapi
1 change: 1 addition & 0 deletions include/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ auto getStringArgs(const Napi::CallbackInfo& info) {
}

std::string toCppString(Napi::Value x, const std::string& identifier);
std::span<const unsigned char> toCppBufferView(Napi::Value x, const std::string& identifier);
std::vector<unsigned char> toCppBuffer(Napi::Value x, const std::string& identifier);

int64_t toCppInteger(Napi::Value x, const std::string& identifier, bool allowUndefined = false);
Expand Down
9 changes: 8 additions & 1 deletion types/pro/pro.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProWrapper>;
export type ProActionsCalls = MakeWrapperActionCalls<ProWrapper>;


/**
Expand Down
Loading