diff --git a/CMakeLists.txt b/CMakeLists.txt index de29b5c..d54ada0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/include/session/config/community.hpp b/include/session/config/community.hpp index 232e53e..c067c85 100644 --- a/include/session/config/community.hpp +++ b/include/session/config/community.hpp @@ -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. diff --git a/include/session/config/groups/keys.hpp b/include/session/config/groups/keys.hpp index 3e20c9b..05f1da9 100644 --- a/include/session/config/groups/keys.hpp +++ b/include/session/config/groups/keys.hpp @@ -491,6 +491,12 @@ class Keys : public ConfigSig { std::span signing_value, bool binary = false) const; + static swarm_auth swarm_subaccount_sign_as_user( + std::span user_ed25519_sk, + std::span msg, + std::span 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 diff --git a/src/config/community.cpp b/src/config/community.cpp index 1832f6f..e893a6c 100644 --- a/src/config/community.cpp +++ b/src/config/community.cpp @@ -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); diff --git a/src/config/groups/keys.cpp b/src/config/groups/keys.cpp index 2fe6a15..1048f4e 100644 --- a/src/config/groups/keys.cpp +++ b/src/config/groups/keys.cpp @@ -653,16 +653,15 @@ std::vector Keys::swarm_subaccount_token( return out; } -Keys::swarm_auth Keys::swarm_subaccount_sign( +Keys::swarm_auth Keys::swarm_subaccount_sign_as_user( + std::span user_ed25519_sk, std::span msg, std::span 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; @@ -775,6 +774,17 @@ Keys::swarm_auth Keys::swarm_subaccount_sign( return result; } +Keys::swarm_auth Keys::swarm_subaccount_sign( + std::span msg, + std::span sign_val, + bool binary) const { + const unsigned char* user_ed25519_sk_buf = this->user_ed25519_sk.data(); + std::span 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 sign_val, bool write, bool del) const { if (!_sign_pk)