Skip to content

Commit 29699f6

Browse files
authored
Merge pull request #41 from session-foundation/feat/pro-backend-wrappers
feat: create pro backend wrapper for getting pro proofs
2 parents 655738a + 195eda7 commit 29699f6

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

include/pro/pro.hpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
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

1415
namespace 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

include/utilities.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ auto getStringArgs(const Napi::CallbackInfo& info) {
6060
}
6161

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

6566
int64_t toCppInteger(Napi::Value x, const std::string& identifier, bool allowUndefined = false);

types/pro/pro.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,16 @@ declare module 'libsession_util_nodejs' {
7474
*/
7575
proFeatures: ProFeatures;
7676
}) => WithProFeatures & { success: boolean; error: string | null; codepointCount: number };
77+
proProofRequestBody: (args: {
78+
requestVersion: string,
79+
masterPrivkey: Uint8Array,
80+
rotatingPrivkey: Uint8Array,
81+
unixTsMs: number,
82+
}
83+
) => string;
7784
};
7885

79-
export type ProActionsCalls = MakeWrapperActionCalls<ProWrapper>;
86+
export type ProActionsCalls = MakeWrapperActionCalls<ProWrapper>;
8087

8188

8289
/**

0 commit comments

Comments
 (0)