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
6 changes: 3 additions & 3 deletions include/pro/pro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ std::string_view proBackendEnumToString(SESSION_PRO_BACKEND_PAYMENT_PROVIDER v);
std::string_view proBackendEnumToString(SESSION_PRO_BACKEND_PAYMENT_STATUS v);
std::string_view proBackendEnumToString(SESSION_PRO_BACKEND_PLAN v);
std::string_view proBackendEnumToString(SESSION_PRO_BACKEND_USER_PRO_STATUS v);
std::string_view proBackendEnumToString(SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT v);
std::string_view proBackendEnumToString(SESSION_PRO_BACKEND_GET_PRO_DETAILS_ERROR_REPORT v);
std::string_view proBackendEnumToString(session::ProFeaturesForMsgStatus v);

template <typename T>
Expand Down Expand Up @@ -193,7 +193,7 @@ class ProWrapper : public Napi::ObjectWrap<ProWrapper> {
auto master_privkey_decoded = from_hex(master_privkey);
auto rotating_privkey_decoded = from_hex(rotating_privkey);

std::string json = pro_backend::GetProProofRequest::build_to_json(
std::string json = pro_backend::GenerateProProofRequest::build_to_json(
static_cast<uint8_t>(requestVersion.Int32Value()),
to_span(master_privkey_decoded),
to_span(rotating_privkey_decoded),
Expand Down Expand Up @@ -267,7 +267,7 @@ class ProWrapper : public Napi::ObjectWrap<ProWrapper> {

auto master_privkey_decoded = from_hex(master_privkey);

auto json = pro_backend::GetProStatusRequest::build_to_json(
auto json = pro_backend::GetProDetailsRequest::build_to_json(
static_cast<uint8_t>(requestVersion.Int32Value()),
to_span(master_privkey_decoded),
unix_ts_ms,
Expand Down
5 changes: 1 addition & 4 deletions include/pro/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ struct toJs_impl<session::Envelope> {

obj["timestampMs"] = toJs(env, envelope.timestamp.count());
obj["source"] = envelope.source.size() ? toJs(env, envelope.source) : env.Null();
obj["proSigHex"] =
envelope.pro_sig.size() ? toJs(env, oxenc::to_hex(envelope.pro_sig)) : env.Null();

return obj;
}
Expand Down Expand Up @@ -75,8 +73,7 @@ struct toJs_impl<session::DecodedPro> {
toJs(env,
decoded_pro.status == ProStatus::InvalidProBackendSig ? "InvalidProBackendSig"
: decoded_pro.status == ProStatus::InvalidUserSig ? "InvalidUserSig"
: decoded_pro.status == ProStatus::Valid ? "Valid"
: "Expired");
: "Valid");
obj["proProof"] = toJs(env, decoded_pro.proof);
obj["proFeaturesBitset"] = proFeaturesToJsBitset(env, decoded_pro.features);

Expand Down
9 changes: 4 additions & 5 deletions include/user_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ class UserConfigWrapper : public ConfigBaseImpl, public Napi::ObjectWrap<UserCon
explicit UserConfigWrapper(const Napi::CallbackInfo& info);

private:
// FIXME: wrap those in the extra data field of UserConfig instead
std::optional<config::ProConfig> pro_config;
int64_t pro_user_features = 0;

config::UserProfile& config{get_config<config::UserProfile>()};

Napi::Value getPriority(const Napi::CallbackInfo& info);
Expand All @@ -42,8 +38,11 @@ class UserConfigWrapper : public ConfigBaseImpl, public Napi::ObjectWrap<UserCon

Napi::Value getProConfig(const Napi::CallbackInfo& info);
void setProConfig(const Napi::CallbackInfo& info);
Napi::Value removeProConfig(const Napi::CallbackInfo& info);

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

Napi::Value generateProMasterKey(const Napi::CallbackInfo& info);
Napi::Value generateRotatingPrivKeyHex(const Napi::CallbackInfo& info);
Expand Down
18 changes: 9 additions & 9 deletions include/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,10 @@ template <std::size_t N>
std::array<uint8_t, N> from_hex_to_array(std::string x) {
std::string as_hex = oxenc::from_hex(x);
if (as_hex.size() != N) {
throw std::invalid_argument(
fmt::format(
"from_hex_to_array: Decoded hex size mismatch: expected {}, got {}",
N,
as_hex.size()));
throw std::invalid_argument(fmt::format(
"from_hex_to_array: Decoded hex size mismatch: expected {}, got {}",
N,
as_hex.size()));
}

std::array<uint8_t, N> result;
Expand All @@ -433,15 +432,16 @@ std::vector<unsigned char> from_base64_to_vector(std::string_view x);
// Concept to match containers with a size() method
template <typename T>
concept HasSize = requires(T t) {
{t.size()}->std::convertible_to<size_t>;
{
t.size()
} -> std::convertible_to<size_t>;
};

template <HasSize T>
void assert_length(const T& x, size_t n, std::string_view base_identifier) {
if (x.size() != n) {
throw std::invalid_argument(
fmt::format(
"assert_length: expected {}, got {} for {}", n, x.size(), base_identifier));
throw std::invalid_argument(fmt::format(
"assert_length: expected {}, got {} for {}", n, x.size(), base_identifier));
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ Napi::Object ConstantsWrapper::Init(Napi::Env env, Napi::Object exports) {
env,
SESSION_PRO_BACKEND_PAYMENT_PROVIDER_METADATA[SESSION_PRO_BACKEND_PAYMENT_PROVIDER_NIL]
.platform_account);
pro_provider_nil["refund_url"] = toJs(
pro_provider_nil["refund_support_url"] = toJs(
env,
SESSION_PRO_BACKEND_PAYMENT_PROVIDER_METADATA[SESSION_PRO_BACKEND_PAYMENT_PROVIDER_NIL]
.refund_url);
pro_provider_nil["refund_after_platform_deadline_url"] = toJs(
.refund_support_url);
pro_provider_nil["refund_platform_url"] = toJs(
env,
SESSION_PRO_BACKEND_PAYMENT_PROVIDER_METADATA[SESSION_PRO_BACKEND_PAYMENT_PROVIDER_NIL]
.refund_after_platform_deadline_url);
.refund_platform_url);
pro_provider_nil["update_subscription_url"] = toJs(
env,
SESSION_PRO_BACKEND_PAYMENT_PROVIDER_METADATA[SESSION_PRO_BACKEND_PAYMENT_PROVIDER_NIL]
Expand Down Expand Up @@ -82,16 +82,16 @@ Napi::Object ConstantsWrapper::Init(Napi::Env env, Napi::Object exports) {
SESSION_PRO_BACKEND_PAYMENT_PROVIDER_METADATA
[SESSION_PRO_BACKEND_PAYMENT_PROVIDER_GOOGLE_PLAY_STORE]
.platform_account);
pro_provider_google["refund_url"] =
pro_provider_google["refund_support_url"] =
toJs(env,
SESSION_PRO_BACKEND_PAYMENT_PROVIDER_METADATA
[SESSION_PRO_BACKEND_PAYMENT_PROVIDER_GOOGLE_PLAY_STORE]
.refund_url);
pro_provider_google["refund_after_platform_deadline_url"] =
.refund_support_url);
pro_provider_google["refund_platform_url"] =
toJs(env,
SESSION_PRO_BACKEND_PAYMENT_PROVIDER_METADATA
[SESSION_PRO_BACKEND_PAYMENT_PROVIDER_GOOGLE_PLAY_STORE]
.refund_after_platform_deadline_url);
.refund_platform_url);
pro_provider_google["update_subscription_url"] =
toJs(env,
SESSION_PRO_BACKEND_PAYMENT_PROVIDER_METADATA
Expand Down Expand Up @@ -129,16 +129,16 @@ Napi::Object ConstantsWrapper::Init(Napi::Env env, Napi::Object exports) {
SESSION_PRO_BACKEND_PAYMENT_PROVIDER_METADATA
[SESSION_PRO_BACKEND_PAYMENT_PROVIDER_IOS_APP_STORE]
.platform_account);
pro_provider_ios["refund_url"] =
pro_provider_ios["refund_support_url"] =
toJs(env,
SESSION_PRO_BACKEND_PAYMENT_PROVIDER_METADATA
[SESSION_PRO_BACKEND_PAYMENT_PROVIDER_IOS_APP_STORE]
.refund_url);
pro_provider_ios["refund_after_platform_deadline_url"] =
.refund_support_url);
pro_provider_ios["refund_platform_url"] =
toJs(env,
SESSION_PRO_BACKEND_PAYMENT_PROVIDER_METADATA
[SESSION_PRO_BACKEND_PAYMENT_PROVIDER_IOS_APP_STORE]
.refund_after_platform_deadline_url);
.refund_platform_url);
pro_provider_ios["update_subscription_url"] =
toJs(env,
SESSION_PRO_BACKEND_PAYMENT_PROVIDER_METADATA
Expand Down
18 changes: 6 additions & 12 deletions src/encrypt_decrypt/encrypt_decrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,8 @@ Napi::Value MultiEncryptWrapper::decryptForCommunity(const Napi::CallbackInfo& i

auto contentOrEnvelope =
extractContentOrEnvelope(obj, "decryptForCommunity.obj.contentOrEnvelope");
decrypted.push_back(
session::decode_for_community(
contentOrEnvelope, nowMs, proBackendPubkeyHex));
decrypted.push_back(session::decode_for_community(
contentOrEnvelope, nowMs, proBackendPubkeyHex));
decryptedServerIds.push_back(serverId);

} catch (const std::exception& e) {
Expand All @@ -661,9 +660,6 @@ Napi::Value MultiEncryptWrapper::decryptForCommunity(const Napi::CallbackInfo& i
to_insert.Set("contentPlaintextUnpadded", toJs(info.Env(), d.content_plaintext));
to_insert.Set("serverId", toJs(info.Env(), decryptedServerIds[i]));

to_insert.Set(
"proSigHex",
d.pro_sig ? toJs(info.Env(), oxenc::to_hex(*d.pro_sig)) : info.Env().Null());
to_insert.Set("decodedPro", d.pro ? toJs(info.Env(), d.pro) : info.Env().Null());

ret.Set(i, to_insert);
Expand Down Expand Up @@ -731,9 +727,8 @@ Napi::Value MultiEncryptWrapper::decryptFor1o1(const Napi::CallbackInfo& info) {

auto envelopePayload =
extractEnvelopePayload(obj, "decryptFor1o1.obj.envelopePayload");
decrypted.push_back(
session::decode_envelope(
keys, envelopePayload, nowMs, proBackendPubkeyHex));
decrypted.push_back(session::decode_envelope(
keys, envelopePayload, nowMs, proBackendPubkeyHex));
decryptedMessageHashes.push_back(messageHash);
} catch (const std::exception& e) {
log::warning(
Expand Down Expand Up @@ -835,9 +830,8 @@ Napi::Value MultiEncryptWrapper::decryptForGroup(const Napi::CallbackInfo& info)

auto envelopePayload =
extractEnvelopePayload(obj, "decryptForGroup.obj.envelopePayload");
decrypted.push_back(
session::decode_envelope(
keys, envelopePayload, nowMs, proBackendPubkeyHex));
decrypted.push_back(session::decode_envelope(
keys, envelopePayload, nowMs, proBackendPubkeyHex));
decryptedMessageHashes.push_back(messageHash);
} catch (const std::exception& e) {
log::warning(
Expand Down
10 changes: 5 additions & 5 deletions src/pro/pro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ std::string_view proBackendEnumToString(SESSION_PRO_BACKEND_USER_PRO_STATUS v) {
UNREACHABLE();
}

std::string_view ProBackendEnumToString(SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT v) {
std::string_view ProBackendEnumToString(SESSION_PRO_BACKEND_GET_PRO_DETAILS_ERROR_REPORT v) {
switch (v) {
case SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT_SUCCESS: return "SUCCESS";
case SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT_GENERIC_ERROR: return "GENERIC_ERROR";
case SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT_COUNT:
throw std::invalid_argument("SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT_COUNT");
case SESSION_PRO_BACKEND_GET_PRO_DETAILS_ERROR_REPORT_SUCCESS: return "SUCCESS";
case SESSION_PRO_BACKEND_GET_PRO_DETAILS_ERROR_REPORT_GENERIC_ERROR: return "GENERIC_ERROR";
case SESSION_PRO_BACKEND_GET_PRO_DETAILS_ERROR_REPORT_COUNT:
throw std::invalid_argument("SESSION_PRO_BACKEND_GET_PRO_DETAILS_ERROR_REPORT");
}
UNREACHABLE();
}
Expand Down
59 changes: 29 additions & 30 deletions src/user_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

#include <napi.h>

#include <iostream>

#include "base_config.hpp"
#include "oxen/log.hpp"
#include "oxenc/hex.h"
#include "pro/types.hpp"
#include "profile_pic.hpp"
#include "session/config/base.hpp"
#include "session/config/user_profile.hpp"
#include "session/ed25519.hpp"
#include "utilities.hpp"
Expand Down Expand Up @@ -107,8 +103,9 @@ void UserConfigWrapper::Init(Napi::Env env, Napi::Object exports) {
InstanceMethod("setNoteToSelfExpiry", &UserConfigWrapper::setNoteToSelfExpiry),
InstanceMethod("getProConfig", &UserConfigWrapper::getProConfig),
InstanceMethod("setProConfig", &UserConfigWrapper::setProConfig),
InstanceMethod(
"setProFeaturesBitset", &UserConfigWrapper::setProFeaturesBitset),
InstanceMethod("removeProConfig", &UserConfigWrapper::removeProConfig),
InstanceMethod("setProBadge", &UserConfigWrapper::setProBadge),
InstanceMethod("setAnimatedAvatar", &UserConfigWrapper::setAnimatedAvatar),
InstanceMethod(
"getProFeaturesBitset", &UserConfigWrapper::getProFeaturesBitset),
InstanceMethod(
Expand Down Expand Up @@ -266,11 +263,8 @@ void UserConfigWrapper::setNoteToSelfExpiry(const Napi::CallbackInfo& info) {

Napi::Value UserConfigWrapper::getProConfig(const Napi::CallbackInfo& info) {
return wrapResult(info, [&] {
// TODO fixme once extra_data is implemented

oxen::log::warning(cat, "getProConfig() is not wrapped to libsession");
if (this->pro_config.has_value()) {
return toJs(info.Env(), this->pro_config);
if (config.get_pro_config().has_value()) {
return toJs(info.Env(), config.get_pro_config().value());
}

return info.Env().Null();
Expand All @@ -285,38 +279,43 @@ void UserConfigWrapper::setProConfig(const Napi::CallbackInfo& info) {

session::config::ProConfig pro_config =
pro_config_from_object(pro_config_js.As<Napi::Object>());
// TODO fixme once extra_data is implemented

// config.set_pro_config(pro_config);
this->pro_config = pro_config;
config.set_pro_config(pro_config);
});
}

Napi::Value UserConfigWrapper::getProFeaturesBitset(const Napi::CallbackInfo& info) {
Napi::Value UserConfigWrapper::removeProConfig(const Napi::CallbackInfo& info) {
return wrapResult(info, [&] {
// TODO fixme once extra_data is implemented
// config.get_pro_features_bitset();
oxen::log::warning(cat, "getProFeaturesBitset() is not wrapped to libsession");
return proFeaturesToJsBitset(info.Env(), this->pro_user_features);
assertInfoLength(info, 0);

return config.remove_pro_config();
});
}

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

void UserConfigWrapper::setProBadge(const Napi::CallbackInfo& info) {
wrapExceptions(info, [&] {
assertInfoLength(info, 1);
auto pro_features = info[0];
assertIsObject(info[0]);
auto obj = info[0].As<Napi::Object>();
assertIsBigint(obj.Get("proFeaturesBitset"), "UserConfigWrapper::setProFeaturesBitset");
assertIsBoolean(info[0], "setProBadge");

auto enabled = toCppBoolean(info[0], "UserConfigWrapper::setProBadge");

auto pro_user_features_js = obj.Get("proFeaturesBitset");
auto pro_user_features_cpp = toCppIntegerB(
pro_user_features_js, "UserConfigWrapper::setProFeaturesBitset", false);
config.set_pro_badge(enabled);
});
}

void UserConfigWrapper::setAnimatedAvatar(const Napi::CallbackInfo& info) {
wrapExceptions(info, [&] {
assertInfoLength(info, 1);
assertIsBoolean(info[0], "setAnimatedAvatar");

// TODO fixme once extra_data is implemented
auto enabled = toCppBoolean(info[0], "UserConfigWrapper::setAnimatedAvatar");

// config.set_pro_features_bitset(pro_user_features_cpp);
this->pro_user_features = pro_user_features_cpp;
config.set_animated_avatar(enabled);
});
}

Expand Down
14 changes: 4 additions & 10 deletions types/multi_encrypt/multi_encrypt.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,20 @@ declare module 'libsession_util_nodejs' {
type WithDecodedPro = {
decodedPro: DecodedPro | null;
};
type WithProSigHex = {
/**
* HexString
*/
proSigHex: string | null;
};

type Envelope = {
timestampMs: number;
/**
* HexString, 33 bytes, 66 chars
*/
source: string | null;
/**
* HexString
*/
proSigHex: string | null;
};

type WithEnvelope = {
/**
* The envelope payload, if present. For communities, the envelope is not currently included, but will eventually be.
* We want to support both cases, hence why we use this type for decryptForCommunity, instead of WithNonNullableEnvelope
*/
envelope: Envelope | null;
};

Expand Down
7 changes: 3 additions & 4 deletions types/pro/pro.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare module 'libsession_util_nodejs' {
proBackendPubkeyHex: string;
};

type ProStatus = 'InvalidProBackendSig' | 'InvalidUserSig' | 'Valid' | 'Expired';
type ProStatus = 'InvalidProBackendSig' | 'InvalidUserSig' | 'Valid';
type WithProFeaturesBitset = { proFeaturesBitset: bigint };
type WithGenIndexHash = { genIndexHashB64: string };

Expand Down Expand Up @@ -42,7 +42,6 @@ declare module 'libsession_util_nodejs' {
rotatingPrivKeyHex: string;
};


type ProConfig = WithRotatingPrivKeyHex & {
proProof: ProProof;
};
Expand All @@ -55,8 +54,8 @@ declare module 'libsession_util_nodejs' {
store_other: string;
platform: string;
platform_account: string;
refund_url: string;
refund_after_platform_deadline_url: string;
refund_support_url: string;
refund_platform_url: string;
update_subscription_url: string;
cancel_subscription_url: string;
};
Expand Down
Loading
Loading