Skip to content

Commit 6bccce6

Browse files
committed
feat: break bitsets into one for msg, and for profile
1 parent 870767d commit 6bccce6

File tree

10 files changed

+37
-41
lines changed

10 files changed

+37
-41
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: 13 additions & 12 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

@@ -413,10 +414,11 @@ template <std::size_t N>
413414
std::array<uint8_t, N> from_hex_to_array(std::string x) {
414415
std::string as_hex = oxenc::from_hex(x);
415416
if (as_hex.size() != N) {
416-
throw std::invalid_argument(fmt::format(
417-
"from_hex_to_array: Decoded hex size mismatch: expected {}, got {}",
418-
N,
419-
as_hex.size()));
417+
throw std::invalid_argument(
418+
fmt::format(
419+
"from_hex_to_array: Decoded hex size mismatch: expected {}, got {}",
420+
N,
421+
as_hex.size()));
420422
}
421423

422424
std::array<uint8_t, N> result;
@@ -432,16 +434,15 @@ std::vector<unsigned char> from_base64_to_vector(std::string_view x);
432434
// Concept to match containers with a size() method
433435
template <typename T>
434436
concept HasSize = requires(T t) {
435-
{
436-
t.size()
437-
} -> std::convertible_to<size_t>;
437+
{t.size()}->std::convertible_to<size_t>;
438438
};
439439

440440
template <HasSize T>
441441
void assert_length(const T& x, size_t n, std::string_view base_identifier) {
442442
if (x.size() != n) {
443-
throw std::invalid_argument(fmt::format(
444-
"assert_length: expected {}, got {} for {}", n, x.size(), base_identifier));
443+
throw std::invalid_argument(
444+
fmt::format(
445+
"assert_length: expected {}, got {} for {}", n, x.size(), base_identifier));
445446
}
446447
}
447448

src/user_config.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void UserConfigWrapper::Init(Napi::Env env, Napi::Object exports) {
107107
InstanceMethod("setProBadge", &UserConfigWrapper::setProBadge),
108108
InstanceMethod("setAnimatedAvatar", &UserConfigWrapper::setAnimatedAvatar),
109109
InstanceMethod(
110-
"getProFeaturesBitset", &UserConfigWrapper::getProFeaturesBitset),
110+
"getProProfileBitset", &UserConfigWrapper::getProProfileBitset),
111111
InstanceMethod(
112112
"generateProMasterKey", &UserConfigWrapper::generateProMasterKey),
113113
InstanceMethod(
@@ -292,9 +292,9 @@ Napi::Value UserConfigWrapper::removeProConfig(const Napi::CallbackInfo& info) {
292292
});
293293
}
294294

295-
Napi::Value UserConfigWrapper::getProFeaturesBitset(const Napi::CallbackInfo& info) {
295+
Napi::Value UserConfigWrapper::getProProfileBitset(const Napi::CallbackInfo& info) {
296296
return wrapResult(
297-
info, [&] { return proFeaturesToJsBitset(info.Env(), config.get_pro_features()); });
297+
info, [&] { return proProfileBitsetToJS(info.Env(), config.get_profile_bitset()); });
298298
}
299299

300300
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: (

types/user/userconfig.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ declare module 'libsession_util_nodejs' {
4848
*
4949
* @returns 0 if no pro user features are enabled, the bitset of pro features enabled otherwise
5050
*/
51-
getProFeaturesBitset: () => bigint;
51+
getProProfileBitset: () => bigint;
5252

5353
generateProMasterKey: ({
5454
ed25519SeedHex,
@@ -94,7 +94,7 @@ declare module 'libsession_util_nodejs' {
9494
public getProConfig: UserConfigWrapper['getProConfig'];
9595
public setProConfig: UserConfigWrapper['setProConfig'];
9696
public removeProConfig: UserConfigWrapper['removeProConfig'];
97-
public getProFeaturesBitset: UserConfigWrapper['getProFeaturesBitset'];
97+
public getProProfileBitset: UserConfigWrapper['getProProfileBitset'];
9898
public setAnimatedAvatar: UserConfigWrapper['setAnimatedAvatar'];
9999
public setProBadge: UserConfigWrapper['setProBadge'];
100100

@@ -126,7 +126,7 @@ declare module 'libsession_util_nodejs' {
126126
| MakeActionCall<UserConfigWrapper, 'getProConfig'>
127127
| MakeActionCall<UserConfigWrapper, 'setProConfig'>
128128
| MakeActionCall<UserConfigWrapper, 'removeProConfig'>
129-
| MakeActionCall<UserConfigWrapper, 'getProFeaturesBitset'>
129+
| MakeActionCall<UserConfigWrapper, 'getProProfileBitset'>
130130
| MakeActionCall<UserConfigWrapper, 'setAnimatedAvatar'>
131131
| MakeActionCall<UserConfigWrapper, 'setProBadge'>
132132
| MakeActionCall<UserConfigWrapper, 'generateProMasterKey'>

0 commit comments

Comments
 (0)