Skip to content

Commit bc362c1

Browse files
authored
Merge pull request #21 from mpretty-cyro/fix/libsession-1-3-0-support
Retyped the libSession wrapper code in preparation of the 1.3.0 changes
2 parents 7a27a0a + 50b4c96 commit bc362c1

File tree

15 files changed

+89
-95
lines changed

15 files changed

+89
-95
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ jobs:
4444
uses: microsoft/setup-msbuild@v1.3.1
4545
if: runner.os == 'Windows'
4646

47-
# Note: we will be able to get rid of this once the whole tree of submodules has the latest version of oxen-logging
48-
# We'd need oxen-libquic to be updated to have the commit `bc7167f90e71643b43c2ea9cf7d1fefa5045f8d4`, but we don't want to
49-
# update libquic that late.
50-
# We will soon, though :tm:
51-
- name: Apply patches
52-
if: runner.os == 'Windows'
53-
shell: bash
54-
run: |
55-
yarn naughty-patch
56-
5747
- name: generate fake src/version.h so we can try to build
5848
shell: bash
5949
run: yarn update_version

libsession-util

Submodule libsession-util updated 94 files

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"update_version": "sh update_version.sh",
1313
"clean": "rimraf .cache build",
1414
"install": "cmake-js compile --runtime=electron --runtime-version=34.2.0 --CDSUBMODULE_CHECK=OFF --CDLOCAL_MIRROR=https://oxen.rocks/deps --CDENABLE_ONIONREQ=OFF --CDWITH_TESTS=OFF",
15-
"naughty-patch": "git apply patches/oxen-libquic.patch",
1615
"prepare_release": "sh prepare_release.sh"
1716
},
1817
"devDependencies": {

patches/oxen-libquic.patch

Lines changed: 0 additions & 16 deletions
This file was deleted.

prepare_release.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ rm -f ./libsession_util_nodejs*.tar.gz
1313
python -m venv .venv
1414
. .venv/bin/activate
1515
pip install git-archive-all
16-
# see .github/workflows/test.yml for more info
17-
yarn naughty-patch || true
1816
PACKAGE_VERSION=$(node -p "require('./package.json').version")
1917
yarn update_version
2018
echo "PACKAGE_VERSION: $PACKAGE_VERSION"

src/base_config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Napi::Value ConfigBaseImpl::merge(const Napi::CallbackInfo& info) {
6161
assertIsArray(info[0]);
6262
Napi::Array asArray = info[0].As<Napi::Array>();
6363

64-
std::vector<std::pair<std::string, ustring_view>> conf_strs;
64+
std::vector<std::pair<std::string, std::span<const unsigned char>>> conf_strs;
6565
conf_strs.reserve(asArray.Length());
6666

6767
for (uint32_t i = 0; i < asArray.Length(); i++) {

src/base_config.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <cassert>
77
#include <memory>
8+
#include <span>
89
#include <stdexcept>
910
#include <unordered_set>
1011

@@ -13,8 +14,6 @@
1314
#include "session/types.hpp"
1415
#include "utilities.hpp"
1516

16-
using ustring_view = std::basic_string_view<unsigned char>;
17-
1817
namespace session::nodeapi {
1918

2019
class ConfigBaseImpl;
@@ -95,9 +94,9 @@ class ConfigBaseImpl {
9594
// we should get secret key as first arg and optional dumped as second argument
9695
assertIsUInt8Array(info[0], "base construct");
9796
assertIsUInt8ArrayOrNull(info[1]);
98-
ustring_view secretKey = toCppBufferView(info[0], class_name + ".new");
97+
std::span<const unsigned char> secretKey = toCppBufferView(info[0], class_name + ".new");
9998

100-
std::optional<ustring_view> dump;
99+
std::optional<std::span<const unsigned char>> dump;
101100
auto second = info[1];
102101
if (!second.IsEmpty() && !second.IsNull() && !second.IsUndefined())
103102
dump = toCppBufferView(second, class_name + ".new");

src/blinding/blinding.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <napi.h>
44

55
#include <algorithm>
6+
#include <vector>
67

78
#include "../meta/meta_base_wrapper.hpp"
89
#include "../utilities.hpp"
@@ -58,8 +59,7 @@ class BlindingWrapper : public Napi::ObjectWrap<BlindingWrapper> {
5859

5960
auto keypair = session::blind_version_key_pair(ed25519_secret_key);
6061
session::uc32 pk_arr = std::get<0>(keypair);
61-
ustring blinded_pk = session::ustring(
62-
session::to_unsigned_sv(std::string(pk_arr.begin(), pk_arr.end())));
62+
std::vector<unsigned char> blinded_pk = session::to_vector(pk_arr);
6363
std::string blinded_pk_hex;
6464
blinded_pk_hex.reserve(66);
6565
blinded_pk_hex += "07";

src/groups/meta_group.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <napi.h>
4+
#include <vector>
45

56
#include "session/config/groups/info.hpp"
67
#include "session/config/groups/keys.hpp"
@@ -32,12 +33,12 @@ class MetaGroup {
3233
shared_ptr<config::groups::Info> info,
3334
shared_ptr<config::groups::Members> members,
3435
shared_ptr<config::groups::Keys> keys,
35-
session::ustring edGroupPubKey,
36-
std::optional<session::ustring> edGroupSecKey) :
37-
info{info}, members{members}, keys{keys}, edGroupPubKey{oxenc::to_hex(edGroupPubKey)} {
36+
std::vector<unsigned char> edGroupPubKey,
37+
std::optional<std::vector<unsigned char>> edGroupSecKey) :
38+
info{info}, members{members}, keys{keys}, edGroupPubKey{oxenc::to_hex(edGroupPubKey.begin(), edGroupPubKey.end())} {
3839

3940
if (edGroupSecKey.has_value()) {
40-
this->edGroupSecKey = oxenc::to_hex(*edGroupSecKey);
41+
this->edGroupSecKey = oxenc::to_hex(edGroupSecKey->begin(), edGroupSecKey->end());
4142
} else {
4243
this->edGroupSecKey = std::nullopt;
4344
}

src/groups/meta_group_wrapper.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <napi.h>
44

55
#include <memory>
6+
#include <span>
7+
#include <vector>
68

79
#include "oxenc/bt_producer.h"
810
#include "session/types.hpp"
@@ -208,12 +210,12 @@ Napi::Value MetaGroupWrapper::metaDump(const Napi::CallbackInfo& info) {
208210
oxenc::bt_dict_producer combined;
209211

210212
// NOTE: the keys have to be in ascii-sorted order:
211-
combined.append("info", session::from_unsigned_sv(this->meta_group->info->dump()));
212-
combined.append("keys", session::from_unsigned_sv(this->meta_group->keys->dump()));
213-
combined.append("members", session::from_unsigned_sv(this->meta_group->members->dump()));
213+
combined.append("info", session::to_string(this->meta_group->info->dump()));
214+
combined.append("keys", session::to_string(this->meta_group->keys->dump()));
215+
combined.append("members", session::to_string(this->meta_group->members->dump()));
214216
auto to_dump = std::move(combined).str();
215217

216-
return session::ustring{to_unsigned_sv(to_dump)};
218+
return session::to_vector(to_dump);
217219
});
218220
}
219221

@@ -222,13 +224,13 @@ Napi::Value MetaGroupWrapper::metaMakeDump(const Napi::CallbackInfo& info) {
222224
oxenc::bt_dict_producer combined;
223225

224226
// NOTE: the keys have to be in ascii-sorted order:
225-
combined.append("info", session::from_unsigned_sv(this->meta_group->info->make_dump()));
226-
combined.append("keys", session::from_unsigned_sv(this->meta_group->keys->make_dump()));
227+
combined.append("info", session::to_string(this->meta_group->info->make_dump()));
228+
combined.append("keys", session::to_string(this->meta_group->keys->make_dump()));
227229
combined.append(
228-
"members", session::from_unsigned_sv(this->meta_group->members->make_dump()));
230+
"members", session::to_string(this->meta_group->members->make_dump()));
229231
auto to_dump = std::move(combined).str();
230232

231-
return ustring{to_unsigned_sv(to_dump)};
233+
return session::to_vector(to_dump);
232234
});
233235
}
234236

@@ -326,7 +328,7 @@ Napi::Value MetaGroupWrapper::metaMerge(const Napi::CallbackInfo& info) {
326328
assertIsArray(groupInfo);
327329
auto asArr = groupInfo.As<Napi::Array>();
328330

329-
std::vector<std::pair<std::string, ustring_view>> conf_strs;
331+
std::vector<std::pair<std::string, std::span<const unsigned char>>> conf_strs;
330332
conf_strs.reserve(asArr.Length());
331333

332334
for (uint32_t i = 0; i < asArr.Length(); i++) {
@@ -353,7 +355,7 @@ Napi::Value MetaGroupWrapper::metaMerge(const Napi::CallbackInfo& info) {
353355
assertIsArray(groupMember);
354356
auto asArr = groupMember.As<Napi::Array>();
355357

356-
std::vector<std::pair<std::string, ustring_view>> conf_strs;
358+
std::vector<std::pair<std::string, std::span<const unsigned char>>> conf_strs;
357359
conf_strs.reserve(asArr.Length());
358360

359361
for (uint32_t i = 0; i < asArr.Length(); i++) {
@@ -790,7 +792,7 @@ Napi::Value MetaGroupWrapper::encryptMessages(const Napi::CallbackInfo& info) {
790792

791793
auto plaintextsJS = info[0].As<Napi::Array>();
792794
uint32_t arrayLength = plaintextsJS.Length();
793-
std::vector<session::ustring> encryptedMessages;
795+
std::vector<std::vector<unsigned char>> encryptedMessages;
794796
encryptedMessages.reserve(arrayLength);
795797

796798
for (uint32_t i = 0; i < plaintextsJS.Length(); i++) {
@@ -820,10 +822,10 @@ Napi::Value MetaGroupWrapper::makeSwarmSubAccount(const Napi::CallbackInfo& info
820822
assertIsString(info[0]);
821823

822824
auto memberPk = toCppString(info[0], "makeSwarmSubAccount");
823-
ustring subaccount = this->meta_group->keys->swarm_make_subaccount(memberPk);
825+
std::vector<unsigned char> subaccount = this->meta_group->keys->swarm_make_subaccount(memberPk);
824826

825827
session::nodeapi::checkOrThrow(
826-
subaccount.length() == 100, "expected subaccount to be 100 bytes long");
828+
subaccount.size() == 100, "expected subaccount to be 100 bytes long");
827829

828830
return subaccount;
829831
});
@@ -835,12 +837,12 @@ Napi::Value MetaGroupWrapper::swarmSubAccountToken(const Napi::CallbackInfo& inf
835837
assertIsString(info[0]);
836838

837839
auto memberPk = toCppString(info[0], "swarmSubAccountToken");
838-
ustring subaccount = this->meta_group->keys->swarm_subaccount_token(memberPk);
840+
std::vector<unsigned char> subaccount = this->meta_group->keys->swarm_subaccount_token(memberPk);
839841

840842
session::nodeapi::checkOrThrow(
841-
subaccount.length() == 36, "expected subaccount token to be 36 bytes long");
843+
subaccount.size() == 36, "expected subaccount token to be 36 bytes long");
842844

843-
return oxenc::to_hex(subaccount);
845+
return oxenc::to_hex(subaccount.begin(), subaccount.end());
844846
});
845847
}
846848

0 commit comments

Comments
 (0)