From 9c2618a7edbaa125aa703686144519ff3de3c256 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Sun, 18 Aug 2024 12:16:10 +1000 Subject: [PATCH 1/4] fix: exceptions when compiling with emscripten --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index de29b5c7..d54ada06 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}) From d6a48ed034d21dc71ba0a1d46b45d78db23db505 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 26 Jun 2025 12:48:30 +1000 Subject: [PATCH 2/4] feat: allow subaccount_sign to be called with provided user_ed_sk --- include/session/config/groups/keys.hpp | 6 ++++++ src/config/groups/keys.cpp | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/session/config/groups/keys.hpp b/include/session/config/groups/keys.hpp index 3e20c9b7..4917ec01 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 Keys::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/groups/keys.cpp b/src/config/groups/keys.cpp index 2fe6a156..5b3f3ea6 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 { + 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,14 @@ 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 { + auto user_ed25519_sk_buf = this->user_ed25519_sk.data(); + return Keys::swarm_subaccount_sign_as_user(user_ed25519_sk_buf, msg, sign_val, binary); +} + bool Keys::swarm_verify_subaccount( std::span sign_val, bool write, bool del) const { if (!_sign_pk) From 63035a11e88f8f05213780684b85568bc7fd12f6 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 26 Jun 2025 12:51:06 +1000 Subject: [PATCH 3/4] fix: keys sign_as_user header --- include/session/config/groups/keys.hpp | 2 +- src/config/groups/keys.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/session/config/groups/keys.hpp b/include/session/config/groups/keys.hpp index 4917ec01..05f1da9f 100644 --- a/include/session/config/groups/keys.hpp +++ b/include/session/config/groups/keys.hpp @@ -491,7 +491,7 @@ class Keys : public ConfigSig { std::span signing_value, bool binary = false) const; - static Keys::swarm_auth swarm_subaccount_sign_as_user( + static swarm_auth swarm_subaccount_sign_as_user( std::span user_ed25519_sk, std::span msg, std::span sign_val, diff --git a/src/config/groups/keys.cpp b/src/config/groups/keys.cpp index 5b3f3ea6..cb5b4f8f 100644 --- a/src/config/groups/keys.cpp +++ b/src/config/groups/keys.cpp @@ -779,7 +779,8 @@ Keys::swarm_auth Keys::swarm_subaccount_sign( std::span sign_val, bool binary) const { auto user_ed25519_sk_buf = this->user_ed25519_sk.data(); - return Keys::swarm_subaccount_sign_as_user(user_ed25519_sk_buf, msg, sign_val, binary); + + return Keys::swarm_subaccount_sign_as_user(to_span(user_ed25519_sk_buf), msg, sign_val, binary); } bool Keys::swarm_verify_subaccount( From c146cfbcab617fc89ec05e1dad333fd4ac9aeac8 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 3 Jul 2025 12:53:55 +1000 Subject: [PATCH 4/4] fix: changes needed for convo volatile wrapping --- include/session/config/community.hpp | 2 ++ src/config/community.cpp | 4 ++++ src/config/groups/keys.cpp | 8 +++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/session/config/community.hpp b/include/session/config/community.hpp index 232e53e3..c067c85d 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/src/config/community.cpp b/src/config/community.cpp index 1832f6f6..e893a6c2 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 cb5b4f8f..1048f4e4 100644 --- a/src/config/groups/keys.cpp +++ b/src/config/groups/keys.cpp @@ -657,7 +657,7 @@ 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"}; @@ -778,9 +778,11 @@ Keys::swarm_auth Keys::swarm_subaccount_sign( std::span msg, std::span sign_val, bool binary) const { - auto user_ed25519_sk_buf = this->user_ed25519_sk.data(); + 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(to_span(user_ed25519_sk_buf), msg, sign_val, binary); + return Keys::swarm_subaccount_sign_as_user(user_ed25519_sk, msg, sign_val, binary); } bool Keys::swarm_verify_subaccount(