Skip to content

fix: exceptions when compiling with emscripten #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ else()
set(static_default ON)
endif()

if(EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -sNO_DISABLE_EXCEPTION_CATCHING ")
endif()

option(BUILD_STATIC_DEPS "Build all dependencies statically rather than trying to link to them on the system" ${static_default})
option(STATIC_BUNDLE "Build a single static .a containing everything (both code and dependencies)" ${static_default})

Expand Down
2 changes: 2 additions & 0 deletions include/session/config/community.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct community {
// Same as above, but takes pubkey as an encoded (hex or base32z or base64) string.
community(std::string_view base_url, std::string_view room, std::string_view pubkey_encoded);

community(std::string full_url);

// Takes a combined room URL (e.g. https://whatever.com/r/Room?public_key=01234....), either
// new style (with /r/) or old style (without /r/). Note that the URL gets canonicalized so
// the resulting `base_url()` and `room()` values may not be exactly equal to what is given.
Expand Down
6 changes: 6 additions & 0 deletions include/session/config/groups/keys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,12 @@ class Keys : public ConfigSig {
std::span<const unsigned char> signing_value,
bool binary = false) const;

static swarm_auth swarm_subaccount_sign_as_user(
std::span<const unsigned char> user_ed25519_sk,
std::span<const unsigned char> msg,
std::span<const unsigned char> sign_val,
bool binary = false);

/// API: groups/Keys::swarm_subaccount_token
///
/// Constructs the subaccount token for a session id. The main use of this is to submit a swarm
Expand Down
4 changes: 4 additions & 0 deletions src/config/community.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ community::community(
set_pubkey(pubkey_encoded);
}

community::community(std::string full_url) {
set_full_url(full_url);
}

void community::set_full_url(std::string_view full_url) {
auto [b_url, r_token, s_pubkey] = parse_full_url(full_url);
base_url_ = std::move(b_url);
Expand Down
20 changes: 15 additions & 5 deletions src/config/groups/keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,16 +653,15 @@ std::vector<unsigned char> Keys::swarm_subaccount_token(
return out;
}

Keys::swarm_auth Keys::swarm_subaccount_sign(
Keys::swarm_auth Keys::swarm_subaccount_sign_as_user(
std::span<const unsigned char> user_ed25519_sk,
std::span<const unsigned char> msg,
std::span<const unsigned char> sign_val,
bool binary) const {
bool binary) {

if (sign_val.size() != 100)
throw std::logic_error{"Invalid signing value: size is wrong"};

if (!_sign_pk)
throw std::logic_error{"Unable to verify: group pubkey is not set (!?)"};

Keys::swarm_auth result;
auto& [token, sub_sig, sig] = result;

Expand Down Expand Up @@ -775,6 +774,17 @@ Keys::swarm_auth Keys::swarm_subaccount_sign(
return result;
}

Keys::swarm_auth Keys::swarm_subaccount_sign(
std::span<const unsigned char> msg,
std::span<const unsigned char> sign_val,
bool binary) const {
const unsigned char* user_ed25519_sk_buf = this->user_ed25519_sk.data();
std::span<const unsigned char> user_ed25519_sk(
user_ed25519_sk_buf, this->user_ed25519_sk.size());

return Keys::swarm_subaccount_sign_as_user(user_ed25519_sk, msg, sign_val, binary);
}

bool Keys::swarm_verify_subaccount(
std::span<const unsigned char> sign_val, bool write, bool del) const {
if (!_sign_pk)
Expand Down