Skip to content

Commit 0efc996

Browse files
authored
Merge pull request #51 from session-foundation/chore/split-bitsets
feat: break bitsets into one for msg, and for profile
2 parents 870767d + 4ddea0b commit 0efc996

File tree

11 files changed

+29
-34
lines changed

11 files changed

+29
-34
lines changed

include/pro/pro.hpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ class ProWrapper : public Napi::ObjectWrap<ProWrapper> {
117117
private:
118118
static Napi::Value proFeaturesForMessage(const Napi::CallbackInfo& info) {
119119
return wrapResult(info, [&] {
120-
// we expect two arguments that match:
120+
// we expect one argument that matches:
121121
// first: {
122122
// "utf16": string,
123-
// "proFeaturesBitset": bigint,
124123
// }
125124

126125
assertInfoLength(info, 1);
@@ -132,25 +131,20 @@ class ProWrapper : public Napi::ObjectWrap<ProWrapper> {
132131
if (first.IsEmpty())
133132
throw std::invalid_argument("proFeaturesForMessage first received empty");
134133

135-
assertIsBigint(
136-
first.Get("proFeaturesBitset"), "proFeaturesForMessage.proFeaturesBitset");
137-
138134
auto lossless = true;
139-
SESSION_PROTOCOL_PRO_FEATURES flags =
140-
first.Get("proFeaturesBitset").As<Napi::BigInt>().Uint64Value(&lossless);
141135

142136
assertIsString(first.Get("utf16"), "proFeaturesForMessage.utf16");
143137
std::u16string utf16 = first.Get("utf16").As<Napi::String>().Utf16Value();
144-
auto pro_features_msg =
145-
session::pro_features_for_utf16((utf16.data()), utf16.length(), flags);
138+
ProFeaturesForMsg pro_features_msg =
139+
session::pro_features_for_utf16((utf16.data()), utf16.length());
146140

147141
auto obj = Napi::Object::New(env);
148142

149143
obj["status"] = toJs(env, proBackendEnumToString(pro_features_msg.status));
150144
obj["error"] =
151145
pro_features_msg.error.size() ? toJs(env, pro_features_msg.error) : env.Null();
152146
obj["codepointCount"] = toJs(env, pro_features_msg.codepoint_count);
153-
obj["proFeaturesBitset"] = proFeaturesToJsBitset(env, pro_features_msg.features);
147+
obj["proMessageBitset"] = proMessageBitsetToJS(env, pro_features_msg.bitset);
154148

155149
return obj;
156150
});

include/pro/types.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ struct toJs_impl<session::DecodedPro> {
7575
: decoded_pro.status == ProStatus::InvalidUserSig ? "InvalidUserSig"
7676
: "Valid");
7777
obj["proProof"] = toJs(env, decoded_pro.proof);
78-
obj["proFeaturesBitset"] = proFeaturesToJsBitset(env, decoded_pro.features);
78+
obj["proProfileBitset"] = proProfileBitsetToJS(env, decoded_pro.profile_bitset);
79+
obj["proMessageBitset"] = proMessageBitsetToJS(env, decoded_pro.msg_bitset);
7980

8081
return obj;
8182
}

include/user_config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class UserConfigWrapper : public ConfigBaseImpl, public Napi::ObjectWrap<UserCon
4040
void setProConfig(const Napi::CallbackInfo& info);
4141
Napi::Value removeProConfig(const Napi::CallbackInfo& info);
4242

43-
Napi::Value getProFeaturesBitset(const Napi::CallbackInfo& info);
43+
Napi::Value getProProfileBitset(const Napi::CallbackInfo& info);
4444
void setProBadge(const Napi::CallbackInfo& info);
4545
void setAnimatedAvatar(const Napi::CallbackInfo& info);
4646

include/utilities.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "oxenc/hex.h"
1717
#include "session/config/namespaces.hpp"
1818
#include "session/config/profile_pic.hpp"
19-
#include "session/session_protocol.h"
19+
#include "session/session_protocol.hpp"
2020
#include "session/types.h"
2121
#include "session/types.hpp"
2222

@@ -401,8 +401,9 @@ Napi::Object decrypt_result_to_JS(
401401

402402
confirm_pushed_entry_t confirm_pushed_entry_from_JS(const Napi::Env& env, const Napi::Object& obj);
403403

404-
Napi::BigInt proFeaturesToJsBitset(
405-
const Napi::Env& env, const SESSION_PROTOCOL_PRO_FEATURES bitset);
404+
Napi::BigInt proProfileBitsetToJS(const Napi::Env& env, const ProProfileBitset bitset);
405+
406+
Napi::BigInt proMessageBitsetToJS(const Napi::Env& env, const ProMessageBitset bitset);
406407

407408
std::span<const uint8_t> from_hex_to_span(std::string_view x);
408409

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"main": "index.js",
33
"name": "libsession_util_nodejs",
44
"description": "Wrappers for the Session Util Library",
5-
"version": "0.6.4",
5+
"version": "0.6.5",
66
"license": "GPL-3.0",
77
"author": {
88
"name": "Oxen Project",

src/user_config.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ void UserConfigWrapper::Init(Napi::Env env, Napi::Object exports) {
106106
InstanceMethod("removeProConfig", &UserConfigWrapper::removeProConfig),
107107
InstanceMethod("setProBadge", &UserConfigWrapper::setProBadge),
108108
InstanceMethod("setAnimatedAvatar", &UserConfigWrapper::setAnimatedAvatar),
109-
InstanceMethod(
110-
"getProFeaturesBitset", &UserConfigWrapper::getProFeaturesBitset),
109+
InstanceMethod("getProProfileBitset", &UserConfigWrapper::getProProfileBitset),
111110
InstanceMethod(
112111
"generateProMasterKey", &UserConfigWrapper::generateProMasterKey),
113112
InstanceMethod(
@@ -292,9 +291,9 @@ Napi::Value UserConfigWrapper::removeProConfig(const Napi::CallbackInfo& info) {
292291
});
293292
}
294293

295-
Napi::Value UserConfigWrapper::getProFeaturesBitset(const Napi::CallbackInfo& info) {
294+
Napi::Value UserConfigWrapper::getProProfileBitset(const Napi::CallbackInfo& info) {
296295
return wrapResult(
297-
info, [&] { return proFeaturesToJsBitset(info.Env(), config.get_pro_features()); });
296+
info, [&] { return proProfileBitsetToJS(info.Env(), config.get_profile_bitset()); });
298297
}
299298

300299
void UserConfigWrapper::setProBadge(const Napi::CallbackInfo& info) {

src/utilities.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,12 @@ confirm_pushed_entry_t confirm_pushed_entry_from_JS(const Napi::Env& env, const
362362
return confirmed_pushed_entry;
363363
}
364364

365-
Napi::BigInt proFeaturesToJsBitset(
366-
const Napi::Env& env, const SESSION_PROTOCOL_PRO_FEATURES bitset) {
367-
return Napi::BigInt::New(env, bitset);
365+
Napi::BigInt proProfileBitsetToJS(const Napi::Env& env, const ProProfileBitset bitset) {
366+
return Napi::BigInt::New(env, bitset.data);
367+
}
368+
369+
Napi::BigInt proMessageBitsetToJS(const Napi::Env& env, const ProMessageBitset bitset) {
370+
return Napi::BigInt::New(env, bitset.data);
368371
}
369372

370373
std::span<const uint8_t> from_hex_to_span(std::string_view x) {

types/multi_encrypt/multi_encrypt.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ declare module 'libsession_util_nodejs' {
5353
};
5454
type WithNowMs = { nowMs: number };
5555

56-
type DecodedPro = WithProFeaturesBitset & {
56+
type DecodedPro = WithProProfileBitset & WithProMessageBitset & {
5757
proStatus: ProStatus;
5858
proProof: ProProof;
5959
};

types/pro/pro.d.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ declare module 'libsession_util_nodejs' {
1111
};
1212

1313
type ProStatus = 'InvalidProBackendSig' | 'InvalidUserSig' | 'Valid';
14-
type WithProFeaturesBitset = { proFeaturesBitset: bigint };
14+
type WithProProfileBitset = { proProfileBitset: bigint };
15+
type WithProMessageBitset = { proMessageBitset: bigint };
1516
type WithGenIndexHash = { genIndexHashB64: string };
1617

1718
type WithRequestVersion = { requestVersion: number };
@@ -157,11 +158,7 @@ declare module 'libsession_util_nodejs' {
157158
};
158159

159160
type ProWrapper = {
160-
proFeaturesForMessage: (
161-
args: WithProFeaturesBitset & {
162-
utf16: string;
163-
}
164-
) => WithProFeaturesBitset & {
161+
proFeaturesForMessage: (args: { utf16: string }) => WithProMessageBitset & {
165162
status: 'SUCCESS' | 'UTF_DECODING_ERROR' | 'EXCEEDS_CHARACTER_LIMIT';
166163
};
167164
proProofRequestBody: (

0 commit comments

Comments
 (0)