Skip to content

Commit 7b126e5

Browse files
committed
Merge remote-tracking branch 'upstream/main' into groups-chunk-2
2 parents 81e191c + 278d0cd commit 7b126e5

20 files changed

+361
-93
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ jobs:
2020

2121

2222
matrix:
23-
os: [windows-latest, macos-latest, ubuntu-latest]
24-
23+
os: [windows-2022, macos-12, ubuntu-20.04]
2524
env:
2625
SIGNAL_ENV: production
2726
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
/build/
2-
/.vscode/
1+
# ide files
32
/.vscrof/
3+
/.vscode/
4+
/.idea/
5+
6+
/build/
47
/node_modules/
58
/*.tar.gz
69
/package-lock.json

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "libsession-util"]
22
path = libsession-util
3-
url = https://github.com/Bilb/libsession-util.git
3+
url = https://github.com/oxen-io/libsession-util.git

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ if(MSVC)
4747
endif()
4848

4949
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
50-
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC} "src/" "node_modules/node-addon-api" "../../node_modules/node-addon-api")
50+
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC} "node_modules/node-addon-api" "../../node_modules/node-addon-api" "node_modules/node-api-headers/include" "../../node_modules/node-api-headers/include")
5151

5252
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
5353
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_JS_LIB} ${LIBSESSION_STATIC_BUNDLE_LIBS})

Readme.md renamed to README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ Note: The `electron` property in the `config` object will need to be updated in
3535

3636
### Making a Release and updating Session-desktop
3737

38-
First, make sure all your changes are commited and pushed to the `libsession-util-nodejs` project from your `[FOLDER_NOT_IN_SESSION_DESKTOP]` folder.
39-
Then, bump the version in the package.json of the nodejs wrapper.
38+
1. First, make sure all your changes are commited and pushed to the `libsession-util-nodejs` project from your `[FOLDER_NOT_IN_SESSION_DESKTOP]` folder.
4039

41-
- A **patch** version bump is required only if you have changed the implementation of an existing function or doing a hot fix for libsession version used by `session-desktop`.
40+
2. Then make sure the `libsession-util` is using the latest `dev` branch (unless there is a reason not to).
4241

43-
- A **minor** version bump is required if you have added a new function or changed the signature of an existing one.
42+
3. Then, bump the version in the package.json of the nodejs wrapper.
43+
44+
- A **patch** version bump is required only if you have changed the implementation of an existing function or doing a hot fix for libsession version used by `session-desktop`.
45+
46+
- A **minor** version bump is required if you have added a new function or changed the signature of an existing one.
4447

4548
Then, run these commands:
4649

index.d.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
/// <reference path="./types/shared.d.ts" />
2-
/// <reference path="./types/user/index.d.ts" />
3-
/// <reference path="./types/groups/index.d.ts" />
4-
/// <reference path="./types/multi_encrypt/index.d.ts" />
1+
2+
/// <reference path="./types/index.d.ts" />
53

64
declare module 'libsession_util_nodejs' {
75
/**
@@ -11,7 +9,7 @@ declare module 'libsession_util_nodejs' {
119
* - one side are calls made by the webworker directly to the wrapper
1210
* - the other side are calls made by the renderer to the webworker (which should forward them to the wrapper)
1311
*
14-
* We cannot pass unserializable data between those two, so we need to have a serializable way of calling one
12+
* We cannot pass non serializable data between those two, so we need to have a serializable way of calling one
1513
* method of a wrapper with the required arguments.
1614
* Those serializable data, are `UserConfigActionsType` or just any of the `*ActionsType`. They are defined with a tuple of what each methods accepts on which wrapper with which argument.
1715
*

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
"email": "[email protected]"
1010
},
1111
"scripts": {
12-
"install": "cmake-js compile --runtime=electron --runtime-version=25.8.4 --CDLOCAL_MIRROR=https://oxen.rocks/deps --CDENABLE_ONIONREQ=OFF --CDWITH_TESTS=OFF"
12+
"clean": "rimraf .cache build",
13+
"install": "cmake-js compile --runtime=electron --runtime-version=25.8.4 --CDSUBMODULE_CHECK=OFF --CDLOCAL_MIRROR=https://oxen.rocks/deps --CDENABLE_ONIONREQ=OFF --CDWITH_TESTS=OFF"
1314
},
1415
"devDependencies": {
15-
"clang-format": "^1.8.0"
16+
"clang-format": "^1.8.0",
17+
"rimraf": "2.6.2"
1618
},
1719
"dependencies": {
1820
"cmake-js": "7.2.1",

src/addon.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <napi.h>
22

3+
#include "blinding/blinding.hpp"
4+
#include "constants.hpp"
35
#include "contacts_config.hpp"
46
#include "convo_info_volatile_config.hpp"
57
#include "groups/meta_group_wrapper.hpp"
@@ -9,6 +11,8 @@
911

1012
Napi::Object InitAll(Napi::Env env, Napi::Object exports) {
1113
using namespace session::nodeapi;
14+
ConstantsWrapper::Init(env, exports);
15+
1216
// Group wrappers init
1317
MetaGroupWrapper::Init(env, exports);
1418

@@ -20,6 +24,7 @@ Napi::Object InitAll(Napi::Env env, Napi::Object exports) {
2024

2125
// Fully static wrappers init
2226
MultiEncryptWrapper::Init(env, exports);
27+
BlindingWrapper::Init(env, exports);
2328

2429
return exports;
2530
}

src/blinding/blinding.hpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#pragma once
2+
3+
#include <napi.h>
4+
5+
#include <algorithm>
6+
7+
#include "../meta/meta_base_wrapper.hpp"
8+
#include "../utilities.hpp"
9+
#include "oxenc/hex.h"
10+
#include "session/blinding.hpp"
11+
#include "session/config/user_profile.hpp"
12+
#include "session/platform.hpp"
13+
#include "session/random.hpp"
14+
15+
namespace session::nodeapi {
16+
17+
class BlindingWrapper : public Napi::ObjectWrap<BlindingWrapper> {
18+
19+
public:
20+
BlindingWrapper(const Napi::CallbackInfo& info) : Napi::ObjectWrap<BlindingWrapper>{info} {
21+
throw std::invalid_argument(
22+
"BlindingWrapper is all static and don't need to be constructed");
23+
}
24+
25+
static void Init(Napi::Env env, Napi::Object exports) {
26+
MetaBaseWrapper::NoBaseClassInitHelper<BlindingWrapper>(
27+
env,
28+
exports,
29+
"BlindingWrapperNode",
30+
{
31+
StaticMethod<&BlindingWrapper::blindVersionPubkey>(
32+
"blindVersionPubkey",
33+
static_cast<napi_property_attributes>(
34+
napi_writable | napi_configurable)),
35+
StaticMethod<&BlindingWrapper::blindVersionSign>(
36+
"blindVersionSign",
37+
static_cast<napi_property_attributes>(
38+
napi_writable | napi_configurable)),
39+
40+
});
41+
}
42+
43+
private:
44+
static Napi::Value blindVersionPubkey(const Napi::CallbackInfo& info) {
45+
return wrapResult(info, [&] {
46+
assertInfoLength(info, 1);
47+
assertIsObject(info[0]);
48+
auto obj = info[0].As<Napi::Object>();
49+
50+
if (obj.IsEmpty())
51+
throw std::invalid_argument("blindVersionPubkey received empty");
52+
53+
assertIsUInt8Array(obj.Get("ed25519SecretKey"), "BlindingWrapper::blindVersionPubkey");
54+
auto ed25519_secret_key =
55+
toCppBuffer(obj.Get("ed25519SecretKey"), "blindVersionPubkey.ed25519SecretKey");
56+
57+
auto keypair = session::blind_version_key_pair(ed25519_secret_key);
58+
session::uc32 pk_arr = std::get<0>(keypair);
59+
ustring blinded_pk = session::ustring(
60+
session::to_unsigned_sv(std::string(pk_arr.begin(), pk_arr.end())));
61+
std::string blinded_pk_hex;
62+
blinded_pk_hex.reserve(66);
63+
blinded_pk_hex += "07";
64+
oxenc::to_hex(blinded_pk.begin(), blinded_pk.end(), std::back_inserter(blinded_pk_hex));
65+
66+
return blinded_pk_hex;
67+
});
68+
};
69+
70+
static Napi::Value blindVersionSign(const Napi::CallbackInfo& info) {
71+
return wrapResult(info, [&] {
72+
assertInfoLength(info, 1);
73+
assertIsObject(info[0]);
74+
auto obj = info[0].As<Napi::Object>();
75+
76+
if (obj.IsEmpty())
77+
throw std::invalid_argument("blindVersionSign received empty");
78+
79+
assertIsUInt8Array(obj.Get("ed25519SecretKey"), "BlindingWrapper::blindVersionSign");
80+
auto ed25519_secret_key =
81+
toCppBuffer(obj.Get("ed25519SecretKey"), "blindVersionSign.ed25519SecretKey");
82+
83+
assertIsNumber(obj.Get("sigTimestampSeconds"), "BlindingWrapper::blindVersionSign");
84+
auto sig_timestamp = toCppInteger(
85+
obj.Get("sigTimestampSeconds"), "blindVersionSign.sigTimestampSeconds", false);
86+
87+
return session::blind_version_sign(
88+
ed25519_secret_key, Platform::desktop, sig_timestamp);
89+
});
90+
};
91+
};
92+
93+
} // namespace session::nodeapi

src/constants.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "constants.hpp"
2+
3+
#include "session/config/contacts.hpp"
4+
#include "session/config/groups/info.hpp"
5+
#include "session/config/user_groups.hpp"
6+
7+
namespace session::nodeapi {
8+
ConstantsWrapper::ConstantsWrapper(const Napi::CallbackInfo& info) :
9+
Napi::ObjectWrap<ConstantsWrapper>(info) {}
10+
11+
Napi::Object ConstantsWrapper::Init(Napi::Env env, Napi::Object exports) {
12+
const char* class_name = "CONSTANTS";
13+
14+
// construct javascript constants object
15+
Napi::Function cls = DefineClass(
16+
env,
17+
class_name,
18+
{ObjectWrap::StaticValue(
19+
"CONTACT_MAX_NAME_LENGTH",
20+
Napi::Number::New(env, session::config::contact_info::MAX_NAME_LENGTH),
21+
napi_enumerable),
22+
ObjectWrap::StaticValue(
23+
"BASE_GROUP_MAX_NAME_LENGTH",
24+
Napi::Number::New(env, session::config::base_group_info::NAME_MAX_LENGTH),
25+
napi_enumerable),
26+
ObjectWrap::StaticValue(
27+
"GROUP_INFO_MAX_NAME_LENGTH",
28+
Napi::Number::New(env, session::config::groups::Info::NAME_MAX_LENGTH),
29+
napi_enumerable),
30+
ObjectWrap::StaticValue(
31+
"COMMUNITY_FULL_URL_MAX_LENGTH",
32+
Napi::Number::New(env, session::config::community::FULL_URL_MAX_LENGTH),
33+
napi_enumerable)});
34+
35+
// export object as javascript module
36+
exports.Set(class_name, cls);
37+
return exports;
38+
}
39+
40+
} // namespace session::nodeapi

0 commit comments

Comments
 (0)