Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
7ea26d7
Add Session Pro master key derivation
Doy-lee Jul 31, 2025
bb1c606
Only give 64b skey from session pro keygen
Doy-lee Aug 1, 2025
f389098
Apply _hex_u changes to rest of ed25519 tests
Doy-lee Aug 1, 2025
3f7b161
Use cleared_u32 and 64 from sodium_array header
Doy-lee Aug 1, 2025
99cb280
Linting fix
Doy-lee Aug 1, 2025
445c7f3
Add basic pro proof verification functions
Doy-lee Jul 31, 2025
d222dd8
Reformat the string split in test_config_userprofile
Doy-lee Aug 4, 2025
b719549
Add pro proof and rotating key pair to user profile
Doy-lee Aug 4, 2025
8ac19ba
Add c wrappers for Session Pro and proofs
Doy-lee Aug 5, 2025
aab2209
Update protobufs for Pro and pro proofs
Doy-lee Aug 5, 2025
d4233d1
Typedef array u8x32, add it to types.hpp anad use it in new code
Doy-lee Aug 5, 2025
4c4847c
Add Pro message to Content and decrypt it
Doy-lee Aug 6, 2025
a0bb388
Update Session protobuf files to session-ios at 084e58f
Doy-lee Aug 8, 2025
e899ef6
Revise the PRO protobuf structures
Doy-lee Aug 8, 2025
d1c3f58
Port encrypt for namespace into libsession
Doy-lee Aug 8, 2025
855da09
Update decrypt function to return the envelope and the metadata
Doy-lee Aug 8, 2025
030f072
Add documentation for new session protocol functions
Doy-lee Aug 8, 2025
21e4438
Add c bindings for new encryption functions
Doy-lee Aug 11, 2025
1ad719c
Revise docs for session protocol c header
Doy-lee Aug 11, 2025
58df586
Fix incorrect detection of higher char limits and non-optional pro sigs
Doy-lee Aug 12, 2025
9b33f67
Note that closed groups handles both legacy/non-legacy keys
Doy-lee Aug 12, 2025
4f5c8e5
Avoid required files in pro messages, handle non-encrypted contents i…
Doy-lee Aug 13, 2025
17fcc1f
Regen the protobufs w/ non required fields for pro structures
Doy-lee Aug 13, 2025
171e078
Allow envelope decrypt to handle encrypted v2 group envelopes
Doy-lee Aug 14, 2025
7571f30
Do not enforce library types in C interface
Doy-lee Aug 14, 2025
ed2bd5a
Pro version field should use a key that sorts to the top
Doy-lee Aug 14, 2025
33e90b5
Fix C session protocol using std::span and missing comments
Doy-lee Aug 14, 2025
9fd6643
Fixup some comments, add missing x25519 pubkey from C decrypted envelope
Doy-lee Aug 14, 2025
8279c30
Linting
Doy-lee Aug 14, 2025
429e8e8
Fix pro tests breaking due to version change to @
Doy-lee Aug 14, 2025
01b29cc
Move group msg encryption primitive into session encrypt, avoids circ…
Doy-lee Aug 15, 2025
69dfa99
Move group encryption into session encrypt
Doy-lee Aug 18, 2025
8d9dd5b
Update nomenclamenture, Closed/OpenGroup to Group/Community respectively
Doy-lee Aug 18, 2025
0ea3ee3
Add some missing typedefs on C structs
Doy-lee Aug 18, 2025
cd5ec26
Document the free-eing requirement on the C interface for session pro…
Doy-lee Aug 18, 2025
b15ab04
We cannot enforce the presence of a pro signature
Doy-lee Aug 18, 2025
a261f96
Don't use assert in test key-gen which breaks in release mode
Doy-lee Aug 19, 2025
d5d10d6
Add error logging to C apis
Doy-lee Aug 19, 2025
5dbaa06
Add TODO on the purpose of PUBKEY in pro_backend
Doy-lee Aug 20, 2025
a7b701f
Add note that character limit is UTF16 code units for now
Doy-lee Aug 20, 2025
9811ecd
Remove outdated comment, these encrypt dests just receive plaintext
Doy-lee Aug 20, 2025
182d02a
Remove the CPP session protocol tests, keep C API
Doy-lee Aug 20, 2025
e8cf5f8
Fix groups message not encrypting correctly
Doy-lee Aug 20, 2025
71372f6
Remove envelope type, it is inferred from the namespace
Doy-lee Aug 20, 2025
6db93b5
Encapsulate the freeing of session protocol encrypt/decrypt funcs
Doy-lee Aug 20, 2025
df1e021
Prohibit the creation of legacy groups messages, no longer supported
Doy-lee Aug 20, 2025
8c877c8
Fix linting
Doy-lee Aug 20, 2025
1a50111
Remove the need for ProStatus::Nil by using std::optional
Doy-lee Aug 21, 2025
01545b7
Add docs to pro config
Doy-lee Aug 21, 2025
c03d138
Add helper functions for getting PRO_STATUS from proof standalone fro…
Doy-lee Aug 21, 2025
cac29fb
Re-add missing wrapping of 1o1 messages
Doy-lee Aug 25, 2025
ca00f8e
Mitigate snprintf error prone return value
Doy-lee Aug 25, 2025
30986c2
Address some outdated doc comments
Doy-lee Aug 25, 2025
42cd44f
Use bytes32/64/33 in session protocol, add wrapper encrypt for {1o1,g…
Doy-lee Aug 29, 2025
10aebde
Remove destinations that don't encrypt
Doy-lee Aug 29, 2025
4752062
Remove namespace from encrypt for destination
Doy-lee Aug 29, 2025
42c288a
Linting
Doy-lee Aug 29, 2025
4e4a833
Add missing memory header for zstd
Doy-lee Sep 24, 2025
975a611
Move ProProof into session_protocol.hpp
Doy-lee Sep 24, 2025
fa4a11a
Add pro proof and rotating key pair to user profile
Doy-lee Aug 4, 2025
b8b4819
Add Pro message to Content and decrypt it
Doy-lee Aug 6, 2025
7d6d7cb
Port encrypt for namespace into libsession
Doy-lee Aug 8, 2025
9f0907e
Linting
Doy-lee Aug 14, 2025
04321d2
Move group msg encryption primitive into session encrypt, avoids circ…
Doy-lee Aug 15, 2025
3f35b52
Add docs to pro config
Doy-lee Aug 21, 2025
c2a05ba
Polish C++ pro backend APIs and add C variants
Doy-lee Aug 22, 2025
eaa40fd
Document the new c helper functions
Doy-lee Aug 25, 2025
c04ebf3
Document the dev flow for pro backend
Doy-lee Aug 25, 2025
e7d239b
Test pro backend against local dev server
Doy-lee Aug 27, 2025
cc88289
Add revocation tests, guard CURL tests behind CMake option
Doy-lee Aug 27, 2025
8d881d0
Update readme with new instructions for pro backend dev mode tests
Doy-lee Aug 27, 2025
58f8428
Add more notes on role/usage of protocol.hpp
Doy-lee Aug 27, 2025
deb2ba4
Add payment provider to the pro payments items
Doy-lee Aug 27, 2025
be48a6f
Add Session Pro payment provider metadata, e.g. links to support pages
Doy-lee Aug 27, 2025
4875bee
Fix formatting
Doy-lee Aug 27, 2025
7fcbc19
Make parsing a static function
Doy-lee Aug 28, 2025
686eb0a
Remove duplicated recipient pubkey field
Doy-lee Aug 29, 2025
2b2ee15
Add UTF8/UTF16 codepoint count via new simdutf submodule
Doy-lee Aug 29, 2025
fb969ac
Add type annotations in the C interface
Doy-lee Aug 29, 2025
f218509
Update pro_features_for_utf* naming scheme, add read-only note on err…
Doy-lee Sep 3, 2025
c819da4
Update pro backend layer with changes to API
Doy-lee Sep 17, 2025
1259400
Update pro payments to pro status endpoint
Doy-lee Sep 18, 2025
6a73637
Update pro backend to use millisecond timestamps
Doy-lee Sep 19, 2025
4108213
Update pro backend status API to handle new grace ts response
Doy-lee Sep 23, 2025
1a7fde0
Fix broken tests due to mismatched timestamp magnitude
Doy-lee Sep 23, 2025
49df9fe
Fix broken tests after rebase
Doy-lee Sep 25, 2025
f59b16b
Formatting
Doy-lee Sep 25, 2025
4880fb0
Use non-SSH url for simdutf
Doy-lee Sep 25, 2025
a4dfe6f
Remove null-checks for args marked NON-NULL
Doy-lee Sep 25, 2025
16757f4
Use format macro to dump proof expiry
Doy-lee Sep 25, 2025
13aa74b
Add community message parsing to handle pro signature from content or…
Doy-lee Sep 25, 2025
425afbb
Add encode/decode for community messages
Doy-lee Sep 25, 2025
a7eda05
Rename encrypt/decrypt_for to encode/decode_for for consistency
Doy-lee Sep 25, 2025
050159f
Rename encrypt->encode and implement 1o1 padding/unpadding
Doy-lee Sep 25, 2025
30f0df1
Simplify encrypt_for_destination because we do not need to support le…
Doy-lee Sep 27, 2025
cb68083
Correctly prefix pro structures in session protocol
Doy-lee Sep 27, 2025
391a42b
Encode/decode protocol messages now take the pro key and sign the mes…
Doy-lee Sep 27, 2025
5574985
Merge community encoding to single function, support inbox messages
Doy-lee Sep 27, 2025
dc6dc91
Allow configurable session pro backend URL in unit tests
Doy-lee Sep 29, 2025
bc4fe8a
Formatting
Doy-lee Sep 29, 2025
e6ec4aa
Implement C wrappers for encode_for_community/inbox
Doy-lee Sep 29, 2025
cee1201
Add missing stdint include for uint64_t in blinding.h
Doy-lee Sep 29, 2025
1a1d91c
Clarify padding requirement in interface
Doy-lee Sep 29, 2025
35fc097
Fix outdated reference to pro data instead of pro config
Doy-lee Sep 29, 2025
4472210
Update outdated doc comments for session encrypt
Doy-lee Sep 30, 2025
3a96f8c
Correctly handle envelope source from ios/android and parse timestamps
Doy-lee Oct 2, 2025
17e6cd5
Verify the timestamp is decoded in unit tests
Doy-lee Oct 2, 2025
5914635
Update payment provider metadata table with new required fields
Doy-lee Oct 3, 2025
0bc7787
Switch to forward declared typedefs, remove illegal number separator …
Doy-lee Oct 15, 2025
5c5575a
Ensure simdutf is included in the static library bundler
Doy-lee Oct 15, 2025
8210d1b
Make pro rotating ed25519 span in high-level interface optional
Doy-lee Oct 15, 2025
c86d052
Disambiguate a group ed25519 privkey from the pubkey arg by labelling…
Doy-lee Oct 15, 2025
a3c36f2
Groups v2 key is not ed25519, it's a xchacha20-poly1305 aead construc…
Doy-lee Oct 16, 2025
1bdc4e9
Update envelop decode keys reference to ed25519 privkeys
Doy-lee Oct 16, 2025
2e5c1ee
Add get bulk group enc keys in the C api
Doy-lee Oct 16, 2025
9b73591
Remove extraneous group prefix on bulk get keys api
Doy-lee Oct 16, 2025
f73c50b
Update outdated doc name for group_keys_get_keys
Doy-lee Oct 16, 2025
8131df6
Fix GroupsV2 decoded deriving incorrect x25519 key bytes
Doy-lee Oct 16, 2025
0342879
Update pro backend to accomodate new API changes from the server
Doy-lee Oct 17, 2025
b9dbc01
Update documentation for the pro backend
Doy-lee Oct 17, 2025
6743c1d
Outdated reference to AddProPayment in docs
Doy-lee Oct 17, 2025
78024d3
Revise the hardcoded platform strings w/ latest additions
Doy-lee Oct 22, 2025
c5d9b65
Use fwd declared typedefs which are better and match all other pro code
Doy-lee Oct 22, 2025
f73e229
Parse the new error_report value from the user pro status endpoint
Doy-lee Oct 22, 2025
7257218
s/terms_and_conditions/terms_of_service
Doy-lee Oct 23, 2025
d5bc1ea
Add missing initialisings for the nil payment platform URLs
Doy-lee Oct 23, 2025
2efa5de
Fix ProConfig proofs not deserialising version correctly
Doy-lee Oct 23, 2025
3b45f22
Fix inconsistent utf8/16 pro_features_for arguments
Doy-lee Oct 24, 2025
251df16
Use west-const and fix mismatched utf16 parameter for pro_features_fo…
Doy-lee Oct 24, 2025
5fd7882
Add one-shot functions to directly generate JSON from request params …
Doy-lee Oct 28, 2025
17026fa
Update ed25519 session pro key naming convention to privkey
Doy-lee Oct 28, 2025
48eacaf
Add missing string_view from config/encrypt.hpp
Doy-lee Oct 29, 2025
38c26a7
Add missing dllexport via LIBSESSION_EXPORT to protocol API; fix inco…
Doy-lee Oct 29, 2025
51cc7fa
Identify when message exceeds max limits in pro_features_for_utf8/16
Doy-lee Oct 31, 2025
010a2e4
Add constant for the max number of pinned convos for non-pro users
Doy-lee Oct 31, 2025
0d6f9ec
Move C helper functions that throw into C++ land
Doy-lee Oct 31, 2025
32bda61
Change get_pro_status history to accept a count
Doy-lee Nov 3, 2025
8cfa064
Add missing order ID to the payment tx for the pro backend
Doy-lee Nov 7, 2025
19f4601
Unpad the decoded community message on behalf of the caller
Doy-lee Nov 7, 2025
75e48ae
Add the custom status codes for AddProPayment responses
Doy-lee Nov 7, 2025
3808050
Formatting
Doy-lee Nov 7, 2025
6134c47
Remove Session Pro from the user config
Doy-lee Nov 7, 2025
66ecf92
Add new parse-error status code to pro backend responses
Doy-lee Nov 7, 2025
6c38f2c
Merge EXTRA_PRO_FEATURES into PRO_FEATURES to simplify interface
Doy-lee Nov 10, 2025
de29ec0
Document protobufs sigTimestamp and pro proof fields
Doy-lee Nov 11, 2025
0fd3d5c
Fix 10k character flag check in pro_features_for_utf
Doy-lee Nov 12, 2025
4945c20
Update Session Pro naming scheme for some apis
Doy-lee Nov 14, 2025
456cb16
Added syncing for Session Pro profile values
mpretty-cyro Nov 17, 2025
fc42369
Comment tweak
mpretty-cyro Nov 18, 2025
a8ba4d7
Updated some url variable names
mpretty-cyro Nov 18, 2025
6d9441c
Fixed a couple of bugs with the pro config syncing
mpretty-cyro Nov 18, 2025
4785493
Addressed PR comments
mpretty-cyro Nov 19, 2025
156fb11
Additional PR feedback
mpretty-cyro Nov 19, 2025
e0357e2
Add utf16_len_for_codepoints
Nov 19, 2025
a84edee
Add C API
Nov 19, 2025
2d910d7
Update C header
Nov 19, 2025
8a3da7b
Fixed failing tests
mpretty-cyro Nov 19, 2025
e16a22b
Merge pull request #2 from mpretty-cyro/feature/pro-config-syncing
Doy-lee Nov 19, 2025
4c3e879
Fix pro backend tests which now require DEV. prefix on faux payments …
Doy-lee Nov 20, 2025
609bef6
Merge remote-tracking branch 'doyle/doyle-pro-backend-polish' into ad…
Nov 20, 2025
a1f2909
Address PR feedback
Nov 20, 2025
7d70e55
PR feedback
Nov 20, 2025
e552632
Add comments and test
Nov 20, 2025
9f6f80d
Merge pull request #3 from SessionHero01/add-utf16-truncate
Doy-lee Nov 20, 2025
09d2a37
Added syncing for a 'pro_access_expiry_ts' value
mpretty-cyro Nov 20, 2025
0667fe6
Merge pull request #4 from mpretty-cyro/feature/sync-pro-access-expir…
Doy-lee Nov 20, 2025
660c4c5
Avoid char16_t in the C interface, requires C11
Doy-lee Nov 21, 2025
3731a9f
Fix compile issue for Android
Nov 21, 2025
6473bf4
Merge pull request #5 from SessionHero01/fix-compilation
Doy-lee Nov 21, 2025
193eb69
Add mission symbol export for user_profile_remove_pro_config
Doy-lee Nov 21, 2025
a75482b
Formatting
Doy-lee Nov 21, 2025
0aadb44
fix: add get_pro_features body
Bilb Nov 23, 2025
1e44231
Merge pull request #6 from Bilb/fix/add-get_pro_features
Doy-lee Nov 23, 2025
b4e90ef
Add set payment refund requested endpoint support
Doy-lee Nov 24, 2025
47acb57
Zero initialise arena memory in pro backend
Doy-lee Nov 24, 2025
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
[submodule "external/oxen-logging"]
path = external/oxen-logging
url = https://github.com/oxen-io/oxen-logging.git
[submodule "external/simdutf"]
path = external/simdutf
url = https://github.com/simdutf/simdutf.git
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Session utility library

## Build

```
# Configure the build
#
# Options
# Enable APIs for creating onion-requests with:
#
# -D ENABLE_ONIONERQ
#
# Enable testing of a Session Pro Backend by defining on the configure line:
#
# -D TEST_PRO_BACKEND_WITH_DEV_SERVER=1
#
# These tests require the Session Pro Backend running in development mode (SESH_PRO_BACKEND_DEV=1)
# to be running and tests the request and response flow of registering, updating and revoking
# Session Pro from the development backend. You must also have a libcurl available such that
# `find_package(CURL)` succeeds (e.g. a system installed libcurl) for this to compile
# successfully.
#
# By default, it contacts http://127.0.0.1:5000 but this URL can be changed using the CLI arg
# --pro-backend-dev-server-url="<url>" when invoking the test suite.
#
cmake -G Ninja -S . -B Build

# Build
cmake --build Build --parallel --verbose
```

## Docs

C Library: https://api.oxen.io/libsession-util-c/#/
Expand Down
12 changes: 12 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,15 @@ libsession_static_bundle(libzstd_static)
set(JSON_BuildTests OFF CACHE INTERNAL "")
set(JSON_Install ON CACHE INTERNAL "") # Required to export targets that we use
libsession_system_or_submodule(NLOHMANN nlohmann_json nlohmann_json>=3.7.0 nlohmann-json)

set(JSON_BuildTests OFF CACHE INTERNAL "")
set(JSON_Install ON CACHE INTERNAL "") # Required to export targets that we use

function(simdutf_subdir)
set(SIMDUTF_TESTS OFF CACHE BOOL "")
set(SIMDUTF_TOOLS OFF CACHE BOOL "")
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(simdutf)
endfunction()
simdutf_subdir()
libsession_static_bundle(simdutf)
1 change: 1 addition & 0 deletions external/simdutf
Submodule simdutf added at 7b3f5a
11 changes: 6 additions & 5 deletions include/session/blinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern "C" {
#endif

#include <stddef.h>
#include <stdint.h>

#include "export.h"
#include "platform.h"
Expand All @@ -15,7 +16,7 @@ extern "C" {
///
/// Inputs:
/// - `ed25519_seckey` -- [in] the Ed25519 private key of the sender (64 bytes).
/// - `server_pk` -- [in] the public key of the open group server to generate the
/// - `server_pk` -- [in] the public key of the community server to generate the
/// blinded id for (32 bytes).
/// - `blinded_pk_out` -- [out] pointer to a buffer of at least 32 bytes where the blinded_pk will
/// be written if generation was successful.
Expand All @@ -36,7 +37,7 @@ LIBSESSION_EXPORT bool session_blind15_key_pair(
///
/// Inputs:
/// - `ed25519_seckey` -- [in] the Ed25519 private key of the sender (64 bytes).
/// - `server_pk` -- [in] the public key of the open group server to generate the
/// - `server_pk` -- [in] the public key of the community server to generate the
/// blinded id for (32 bytes).
/// - `blinded_pk_out` -- [out] pointer to a buffer of at least 32 bytes where the blinded_pk will
/// be written if generation was successful.
Expand Down Expand Up @@ -75,7 +76,7 @@ LIBSESSION_EXPORT bool session_blind_version_key_pair(
///
/// Inputs:
/// - `ed25519_seckey` -- [in] the Ed25519 private key of the sender (64 bytes).
/// - `server_pk` -- [in] the public key of the open group server to generate the
/// - `server_pk` -- [in] the public key of the community server to generate the
/// blinded id for (32 bytes).
/// - `msg` -- [in] Pointer to a data buffer containing the message to generate a signature for.
/// - `msg_len` -- [in] Length of `msg`
Expand All @@ -97,7 +98,7 @@ LIBSESSION_EXPORT bool session_blind15_sign(
///
/// Inputs:
/// - `ed25519_seckey` -- [in] the Ed25519 private key of the sender (64 bytes).
/// - `server_pk` -- [in] the public key of the open group server to generate the
/// - `server_pk` -- [in] the public key of the community server to generate the
/// blinded id for (32 bytes).
/// - `msg` -- [in] Pointer to a data buffer containing the message to generate a signature for.
/// - `msg_len` -- [in] Length of `msg`
Expand Down Expand Up @@ -145,7 +146,7 @@ LIBSESSION_EXPORT bool session_blind_version_sign(
/// Inputs:
/// - `session_id` -- [in] the session_id to compare (66 bytes with a 05 prefix).
/// - `blinded_id` -- [in] the blinded_id to compare, can be either 15 or 25 blinded (66 bytes).
/// - `server_pk` -- [in] the public key of the open group server to the blinded id came from (64
/// - `server_pk` -- [in] the public key of the community server to the blinded id came from (64
/// bytes).
///
/// Outputs:
Expand Down
6 changes: 2 additions & 4 deletions include/session/config/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <list>
#include <memory>
#include <session/config.hpp>
#include <session/types.hpp>
#include <session/util.hpp>
#include <span>
#include <type_traits>
Expand All @@ -29,9 +30,6 @@ class bt_dict_consumer;

namespace session::config {

template <typename T, typename... U>
static constexpr bool is_one_of = (std::is_same_v<T, U> || ...);

/// True for a dict_value direct subtype, but not scalar sub-subtypes.
template <typename T>
static constexpr bool is_dict_subtype = is_one_of<T, config::scalar, config::set, config::dict>;
Expand Down Expand Up @@ -944,7 +942,7 @@ class ConfigBase : public ConfigSig {
/// API: base/ConfigBase::load_key
///
/// Called to load an ed25519 key for encryption; this is meant for use by single-ownership
/// config types, like UserProfile, but not shared config types (closed groups).
/// config types, like UserProfile, but not shared config types (groups).
///
/// Takes a binary string which is either the 32-byte seed, or 64-byte libsodium secret (which
/// is just the seed and pubkey concatenated together), and then calls `key(...)` with the seed.
Expand Down
5 changes: 5 additions & 0 deletions include/session/config/contacts.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {
#include "base.h"
#include "expiring.h"
#include "notify.h"
#include "pro.h"
#include "profile_pic.h"
#include "util.h"

Expand Down Expand Up @@ -35,6 +36,8 @@ typedef struct contacts_contact {

int64_t created; // unix timestamp (seconds)

SESSION_PROTOCOL_PRO_FEATURES pro_features;

} contacts_contact;

typedef struct contacts_blinded_contact {
Expand All @@ -52,6 +55,8 @@ typedef struct contacts_blinded_contact {
bool legacy_blinding;
int64_t created; // unix timestamp (seconds)

SESSION_PROTOCOL_PRO_FEATURES pro_features;

} contacts_blinded_contact;

/// Struct containing a list of contacts_blinded_contact structs. Typically where this is returned
Expand Down
56 changes: 56 additions & 0 deletions include/session/config/contacts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "expiring.hpp"
#include "namespaces.hpp"
#include "notify.hpp"
#include "pro.hpp"
#include "profile_pic.hpp"

extern "C" struct contacts_contact;
Expand Down Expand Up @@ -47,6 +48,7 @@ namespace session::config {
/// j - Unix timestamp (seconds) when the contact was created ("j" to match user_groups
/// equivalent "j"oined field). Omitted if 0.
/// t - The `profile_updated` unix timestamp (seconds) for this contacts profile information.
/// f - session pro features bitset for this contact
///
/// b - dict of blinded contacts. This is a nested dict where the outer keys are the BASE_URL of
/// the community the blinded contact originated from and the outer value is a dict containing:
Expand All @@ -68,6 +70,7 @@ namespace session::config {
/// j - Unix timestamp (seconds) when the contact was created ("j" to match user_groups
/// equivalent "j"oined field). Omitted if 0.
/// y - flag indicating whether the blinded message request is using legac"y" blinding.
/// f - session pro features bitset for this blinded contact

struct contact_info {
static constexpr size_t MAX_NAME_LENGTH = 100;
Expand All @@ -93,6 +96,8 @@ struct contact_info {
std::chrono::seconds exp_timer{0}; // The expiration timer (in seconds)
int64_t created = 0; // Unix timestamp (seconds) when this contact was added

SESSION_PROTOCOL_PRO_FEATURES pro_features = SESSION_PROTOCOL_PRO_FEATURES_NIL;

explicit contact_info(std::string sid);

// Internal ctor/method for C API implementations:
Expand All @@ -117,6 +122,25 @@ struct contact_info {
void set_nickname(std::string nickname);
void set_nickname_truncated(std::string nickname);

/// API: contacts/contact_info::get_pro_features
///
/// Retrieves the bitset indicating which pro features the user currently has enabled.
///
/// Inputs: None
///
/// Outputs:
/// - `SESSION_PROTOCOL_PRO_FEATURES` - bitset indicating which pro features are enabled.
SESSION_PROTOCOL_PRO_FEATURES get_pro_features() const;

/// API: contacts/contact_info::set_pro_features
///
/// Updates the pro features bitset for this contact. Note: If the bitset provided contains the
/// '10K_CHARACTER_LIMIT' feature then it will be removed.
///
/// Inputs:
/// - `features` -- The updated pro features bitset to use.
void set_pro_features(SESSION_PROTOCOL_PRO_FEATURES features);

private:
friend class Contacts;
void load(const dict& info_dict);
Expand All @@ -136,6 +160,8 @@ struct blinded_contact_info {
bool legacy_blinding;
std::chrono::sys_seconds created{}; // Unix timestamp (seconds) when this contact was added

SESSION_PROTOCOL_PRO_FEATURES pro_features = SESSION_PROTOCOL_PRO_FEATURES_NIL;

blinded_contact_info() = default;
explicit blinded_contact_info(
std::string_view community_base_url,
Expand Down Expand Up @@ -193,6 +219,25 @@ struct blinded_contact_info {
/// - `std::string` -- Returns the pubkey
std::string community_pubkey_hex() const { return comm.pubkey_hex(); }

/// API: contacts/blinded_contact_info::get_pro_features
///
/// Retrieves the bitset indicating which pro features the user currently has enabled.
///
/// Inputs: None
///
/// Outputs:
/// - `SESSION_PROTOCOL_PRO_FEATURES` - bitset indicating which pro features are enabled.
SESSION_PROTOCOL_PRO_FEATURES get_pro_features() const;

/// API: contacts/blinded_contact_info::set_pro_features
///
/// Updates the pro features bitset for this contact. Note: If the bitset provided contains the
/// '10K_CHARACTER_LIMIT' feature then it will be removed.
///
/// Inputs:
/// - `features` -- The updated pro features bitset to use.
void set_pro_features(SESSION_PROTOCOL_PRO_FEATURES features);

private:
friend class Contacts;
friend struct session::config::comm_iterator_helper;
Expand Down Expand Up @@ -428,6 +473,17 @@ class Contacts : public ConfigBase {
/// - `timestamp` -- standard unix timestamp of the time contact was created
void set_created(std::string_view session_id, int64_t timestamp);

/// API: contacts/contacts::set_pro_features
///
/// Alternative to `set()` for setting a single field. (If setting multiple fields at once you
/// should use `set()` instead).
///
/// Inputs:
/// - `session_id` -- hex string of the session id
/// - `features` -- The updated pro features bitset to use. Note: If the bitset provided
/// contains the '10K_CHARACTER_LIMIT' feature then it will be removed.
void set_pro_features(std::string_view session_id, SESSION_PROTOCOL_PRO_FEATURES features);

/// API: contacts/contacts::erase
///
/// Removes a contact, if present. Returns true if it was found and removed, false otherwise.
Expand Down
11 changes: 11 additions & 0 deletions include/session/config/convo_info_volatile.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ extern "C" {

#include "base.h"
#include "profile_pic.h"
#include "session/types.h"

typedef struct convo_info_volatile_1to1 {
char session_id[67]; // in hex; 66 hex chars + null terminator.

int64_t last_read; // milliseconds since unix epoch
bool unread; // true if the conversation is explicitly marked unread

bool has_pro_gen_index_hash; // Flag indicating if hash is set
bytes32 pro_gen_index_hash; // Hash of the generation index set by the Session Pro Backend
uint64_t pro_expiry_unix_ts_ms; // Unix epoch timestamp to which this contacts entitlement to
// Session Pro features is valid to
} convo_info_volatile_1to1;

typedef struct convo_info_volatile_community {
Expand Down Expand Up @@ -44,6 +50,11 @@ typedef struct convo_info_volatile_blinded_1to1 {

int64_t last_read; // ms since unix epoch
bool unread; // true if the conversation is explicitly marked unread

bool has_pro_gen_index_hash; // Flag indicating if hash is set
bytes32 pro_gen_index_hash; // Hash of the generation index set by the Session Pro Backend
uint64_t pro_expiry_unix_ts_ms; // Unix epoch timestamp to which this contacts entitlement to
// Session Pro features is valid to
} convo_info_volatile_blinded_1to1;

/// API: convo_info_volatile/convo_info_volatile_init
Expand Down
22 changes: 20 additions & 2 deletions include/session/config/convo_info_volatile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class val_loader;
///
/// 1 - dict of one-to-one conversations. Each key is the Session ID of the contact (in hex).
/// Values are dicts with keys:
/// e - contacts pro expiry unix timestamp (in milliseconds)
/// g - contacts pro gen_index_hash
/// r - the unix timestamp (in integer milliseconds) of the last-read message. Always
/// included, but will be 0 if no messages are read.
/// u - will be present and set to 1 if this conversation is specifically marked unread.
Expand All @@ -44,13 +46,13 @@ class val_loader;
/// included, but will be 0 if no messages are read.
/// u - will be present and set to 1 if this conversation is specifically marked unread.
///
/// g - group conversations (aka new, non-legacy closed groups). The key is the group identifier
/// g - group conversations (aka new, non-legacy groups). The key is the group identifier
/// (beginning with 03). Values are dicts with keys:
/// r - the unix timestamp (in integer milliseconds) of the last-read message. Always
/// included, but will be 0 if no messages are read.
/// u - will be present and set to 1 if this conversation is specifically marked unread.
///
/// C - legacy group conversations (aka closed groups). The key is the group identifier (which
/// C - legacy group conversations (aka groups). The key is the group identifier (which
/// looks indistinguishable from a Session ID, but isn't really a proper Session ID). Values
/// are dicts with keys:
/// r - the unix timestamp (integer milliseconds) of the last-read message. Always included,
Expand All @@ -59,6 +61,8 @@ class val_loader;
///
/// b - outgoing blinded message request conversations. The key is the blinded Session ID without
/// the prefix. Values are dicts with keys:
/// e - contacts pro expiry unix timestamp (in milliseconds)
/// g - contacts pro gen_index_hash
/// r - the unix timestamp (integer milliseconds) of the last-read message. Always included,
/// but will be 0 if no messages are read.
/// u - will be present and set to 1 if this conversation is specifically marked unread.
Expand All @@ -79,6 +83,13 @@ namespace convo {
struct one_to_one : base {
std::string session_id; // in hex

/// Hash of the generation index set by the Session Pro Backend
std::optional<array_uc32> pro_gen_index_hash;

/// Unix epoch timestamp to which this proof's entitlement to Session Pro features is valid
/// to
std::chrono::sys_time<std::chrono::milliseconds> pro_expiry_unix_ts{};

/// API: convo_info_volatile/one_to_one::one_to_one
///
/// Constructs an empty one_to_one from a session_id. Session ID can be either bytes (33)
Expand Down Expand Up @@ -161,6 +172,13 @@ namespace convo {
std::string blinded_session_id; // in hex
bool legacy_blinding;

/// Hash of the generation index set by the Session Pro Backend
std::optional<array_uc32> pro_gen_index_hash;

/// Unix epoch timestamp to which this proof's entitlement to Session Pro features is valid
/// to
std::chrono::sys_time<std::chrono::milliseconds> pro_expiry_unix_ts{};

/// API: convo_info_volatile/blinded_one_to_one::blinded_one_to_one
///
/// Constructs an empty blinded_one_to_one from a blinded_session_id. Session ID can be
Expand Down
3 changes: 1 addition & 2 deletions include/session/config/encrypt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

#include <span>
#include <stdexcept>
#include <string_view>
#include <vector>

#include "../types.hpp"

namespace session::config {

/// API: encrypt/encrypt
Expand Down
Loading