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
14 changes: 4 additions & 10 deletions include/pro/pro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ class ProWrapper : public Napi::ObjectWrap<ProWrapper> {
private:
static Napi::Value proFeaturesForMessage(const Napi::CallbackInfo& info) {
return wrapResult(info, [&] {
// we expect two arguments that match:
// we expect one argument that matches:
// first: {
// "utf16": string,
// "proFeaturesBitset": bigint,
// }

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

assertIsBigint(
first.Get("proFeaturesBitset"), "proFeaturesForMessage.proFeaturesBitset");

auto lossless = true;
SESSION_PROTOCOL_PRO_FEATURES flags =
first.Get("proFeaturesBitset").As<Napi::BigInt>().Uint64Value(&lossless);

assertIsString(first.Get("utf16"), "proFeaturesForMessage.utf16");
std::u16string utf16 = first.Get("utf16").As<Napi::String>().Utf16Value();
auto pro_features_msg =
session::pro_features_for_utf16((utf16.data()), utf16.length(), flags);
ProFeaturesForMsg pro_features_msg =
session::pro_features_for_utf16((utf16.data()), utf16.length());

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

obj["status"] = toJs(env, proBackendEnumToString(pro_features_msg.status));
obj["error"] =
pro_features_msg.error.size() ? toJs(env, pro_features_msg.error) : env.Null();
obj["codepointCount"] = toJs(env, pro_features_msg.codepoint_count);
obj["proFeaturesBitset"] = proFeaturesToJsBitset(env, pro_features_msg.features);
obj["proMessageBitset"] = proMessageBitsetToJS(env, pro_features_msg.bitset);

return obj;
});
Expand Down
3 changes: 2 additions & 1 deletion include/pro/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ struct toJs_impl<session::DecodedPro> {
: decoded_pro.status == ProStatus::InvalidUserSig ? "InvalidUserSig"
: "Valid");
obj["proProof"] = toJs(env, decoded_pro.proof);
obj["proFeaturesBitset"] = proFeaturesToJsBitset(env, decoded_pro.features);
obj["proProfileBitset"] = proProfileBitsetToJS(env, decoded_pro.profile_bitset);
obj["proMessageBitset"] = proMessageBitsetToJS(env, decoded_pro.msg_bitset);

return obj;
}
Expand Down
2 changes: 1 addition & 1 deletion include/user_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class UserConfigWrapper : public ConfigBaseImpl, public Napi::ObjectWrap<UserCon
void setProConfig(const Napi::CallbackInfo& info);
Napi::Value removeProConfig(const Napi::CallbackInfo& info);

Napi::Value getProFeaturesBitset(const Napi::CallbackInfo& info);
Napi::Value getProProfileBitset(const Napi::CallbackInfo& info);
void setProBadge(const Napi::CallbackInfo& info);
void setAnimatedAvatar(const Napi::CallbackInfo& info);

Expand Down
7 changes: 4 additions & 3 deletions include/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "oxenc/hex.h"
#include "session/config/namespaces.hpp"
#include "session/config/profile_pic.hpp"
#include "session/session_protocol.h"
#include "session/session_protocol.hpp"
#include "session/types.h"
#include "session/types.hpp"

Expand Down Expand Up @@ -401,8 +401,9 @@ Napi::Object decrypt_result_to_JS(

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

Napi::BigInt proFeaturesToJsBitset(
const Napi::Env& env, const SESSION_PROTOCOL_PRO_FEATURES bitset);
Napi::BigInt proProfileBitsetToJS(const Napi::Env& env, const ProProfileBitset bitset);

Napi::BigInt proMessageBitsetToJS(const Napi::Env& env, const ProMessageBitset bitset);

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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"main": "index.js",
"name": "libsession_util_nodejs",
"description": "Wrappers for the Session Util Library",
"version": "0.6.4",
"version": "0.6.5",
"license": "GPL-3.0",
"author": {
"name": "Oxen Project",
Expand Down
7 changes: 3 additions & 4 deletions src/user_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ void UserConfigWrapper::Init(Napi::Env env, Napi::Object exports) {
InstanceMethod("removeProConfig", &UserConfigWrapper::removeProConfig),
InstanceMethod("setProBadge", &UserConfigWrapper::setProBadge),
InstanceMethod("setAnimatedAvatar", &UserConfigWrapper::setAnimatedAvatar),
InstanceMethod(
"getProFeaturesBitset", &UserConfigWrapper::getProFeaturesBitset),
InstanceMethod("getProProfileBitset", &UserConfigWrapper::getProProfileBitset),
InstanceMethod(
"generateProMasterKey", &UserConfigWrapper::generateProMasterKey),
InstanceMethod(
Expand Down Expand Up @@ -292,9 +291,9 @@ Napi::Value UserConfigWrapper::removeProConfig(const Napi::CallbackInfo& info) {
});
}

Napi::Value UserConfigWrapper::getProFeaturesBitset(const Napi::CallbackInfo& info) {
Napi::Value UserConfigWrapper::getProProfileBitset(const Napi::CallbackInfo& info) {
return wrapResult(
info, [&] { return proFeaturesToJsBitset(info.Env(), config.get_pro_features()); });
info, [&] { return proProfileBitsetToJS(info.Env(), config.get_profile_bitset()); });
}

void UserConfigWrapper::setProBadge(const Napi::CallbackInfo& info) {
Expand Down
9 changes: 6 additions & 3 deletions src/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,12 @@ confirm_pushed_entry_t confirm_pushed_entry_from_JS(const Napi::Env& env, const
return confirmed_pushed_entry;
}

Napi::BigInt proFeaturesToJsBitset(
const Napi::Env& env, const SESSION_PROTOCOL_PRO_FEATURES bitset) {
return Napi::BigInt::New(env, bitset);
Napi::BigInt proProfileBitsetToJS(const Napi::Env& env, const ProProfileBitset bitset) {
return Napi::BigInt::New(env, bitset.data);
}

Napi::BigInt proMessageBitsetToJS(const Napi::Env& env, const ProMessageBitset bitset) {
return Napi::BigInt::New(env, bitset.data);
}

std::span<const uint8_t> from_hex_to_span(std::string_view x) {
Expand Down
2 changes: 1 addition & 1 deletion types/multi_encrypt/multi_encrypt.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ declare module 'libsession_util_nodejs' {
};
type WithNowMs = { nowMs: number };

type DecodedPro = WithProFeaturesBitset & {
type DecodedPro = WithProProfileBitset & WithProMessageBitset & {
proStatus: ProStatus;
proProof: ProProof;
};
Expand Down
9 changes: 3 additions & 6 deletions types/pro/pro.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ declare module 'libsession_util_nodejs' {
};

type ProStatus = 'InvalidProBackendSig' | 'InvalidUserSig' | 'Valid';
type WithProFeaturesBitset = { proFeaturesBitset: bigint };
type WithProProfileBitset = { proProfileBitset: bigint };
type WithProMessageBitset = { proMessageBitset: bigint };
type WithGenIndexHash = { genIndexHashB64: string };

type WithRequestVersion = { requestVersion: number };
Expand Down Expand Up @@ -157,11 +158,7 @@ declare module 'libsession_util_nodejs' {
};

type ProWrapper = {
proFeaturesForMessage: (
args: WithProFeaturesBitset & {
utf16: string;
}
) => WithProFeaturesBitset & {
proFeaturesForMessage: (args: { utf16: string }) => WithProMessageBitset & {
status: 'SUCCESS' | 'UTF_DECODING_ERROR' | 'EXCEEDS_CHARACTER_LIMIT';
};
proProofRequestBody: (
Expand Down
6 changes: 3 additions & 3 deletions types/user/userconfig.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ declare module 'libsession_util_nodejs' {
*
* @returns 0 if no pro user features are enabled, the bitset of pro features enabled otherwise
*/
getProFeaturesBitset: () => bigint;
getProProfileBitset: () => bigint;

generateProMasterKey: ({
ed25519SeedHex,
Expand Down Expand Up @@ -94,7 +94,7 @@ declare module 'libsession_util_nodejs' {
public getProConfig: UserConfigWrapper['getProConfig'];
public setProConfig: UserConfigWrapper['setProConfig'];
public removeProConfig: UserConfigWrapper['removeProConfig'];
public getProFeaturesBitset: UserConfigWrapper['getProFeaturesBitset'];
public getProProfileBitset: UserConfigWrapper['getProProfileBitset'];
public setAnimatedAvatar: UserConfigWrapper['setAnimatedAvatar'];
public setProBadge: UserConfigWrapper['setProBadge'];

Expand Down Expand Up @@ -126,7 +126,7 @@ declare module 'libsession_util_nodejs' {
| MakeActionCall<UserConfigWrapper, 'getProConfig'>
| MakeActionCall<UserConfigWrapper, 'setProConfig'>
| MakeActionCall<UserConfigWrapper, 'removeProConfig'>
| MakeActionCall<UserConfigWrapper, 'getProFeaturesBitset'>
| MakeActionCall<UserConfigWrapper, 'getProProfileBitset'>
| MakeActionCall<UserConfigWrapper, 'setAnimatedAvatar'>
| MakeActionCall<UserConfigWrapper, 'setProBadge'>
| MakeActionCall<UserConfigWrapper, 'generateProMasterKey'>
Expand Down
Loading