Skip to content
Open
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
34 changes: 34 additions & 0 deletions include/session/session_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,16 @@ typedef enum SESSION_PROTOCOL_PRO_FEATURES_FOR_MSG_STATUS { // See session::Pro
typedef enum SESSION_PROTOCOL_DESTINATION_TYPE { // See session::DestinationType
SESSION_PROTOCOL_DESTINATION_TYPE_SYNC_OR_1O1,
SESSION_PROTOCOL_DESTINATION_TYPE_GROUP,

// Old-style community messages that is content encrypted using the blinding protocol or
// plaintext content respectively (inbox vs non-inbox).
SESSION_PROTOCOL_DESTINATION_TYPE_COMMUNITY_INBOX,
SESSION_PROTOCOL_DESTINATION_TYPE_COMMUNITY,

// New-style community messages that are sent as envelopes, encrypted using the blinding
// protocol or plaintext content respectively (inbox vs non-inbox).
SESSION_PROTOCOL_DESTINATION_TYPE_ENVELOPE_COMMUNITY_INBOX,
SESSION_PROTOCOL_DESTINATION_TYPE_ENVELOPE_COMMUNITY,
} SESSION_PROTOCOL_DESTINATION_TYPE;

typedef struct session_protocol_destination session_protocol_destination;
Expand Down Expand Up @@ -709,6 +717,32 @@ session_protocol_encoded_for_destination session_protocol_encode_for_destination
LIBSESSION_EXPORT void session_protocol_encode_for_destination_free(
session_protocol_encoded_for_destination* encrypt);

/// API: session_protocol/decode_for_community_inbox
///
/// Given a blinded encrypted content or envelope payload extract the content and any associated pro
/// metadata if there was any in the message.
///
/// This function is the same as calling `decrypt_from_blinded_recipient` to decrypt the payload and
/// then decode with `decode_for_community`. See those functions for more information. On failure
/// this function throws as per `decrypt_from_blinded_recipient`
LIBSESSION_EXPORT session_protocol_decoded_community_message
session_protocol_decode_for_community_inbox(
const unsigned char* ed25519_privkey,
size_t ed25519_privkey_len,
const unsigned char* community_pubkey,
size_t community_pubkey_len,
const unsigned char* sender_id,
size_t sender_id_len,
const unsigned char* recipient_id,
size_t recipient_id_len,
const unsigned char* ciphertext,
size_t ciphertext_len,
uint64_t unix_ts_ms,
OPTIONAL const void* pro_backend_pubkey,
OPTIONAL size_t pro_backend_pubkey_len,
OPTIONAL char* error,
size_t error_len);

/// API: session_protocol/session_protocol_decode_envelope
///
/// Given an envelope payload (i.e.: protobuf encoded stream of `WebsocketRequestMessage` which
Expand Down
19 changes: 19 additions & 0 deletions include/session/session_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ enum class DestinationType {
Group = SESSION_PROTOCOL_DESTINATION_TYPE_GROUP,
CommunityInbox = SESSION_PROTOCOL_DESTINATION_TYPE_COMMUNITY_INBOX,
Community = SESSION_PROTOCOL_DESTINATION_TYPE_COMMUNITY,
EnvelopeCommunityInbox = SESSION_PROTOCOL_DESTINATION_TYPE_ENVELOPE_COMMUNITY_INBOX,
EnvelopeCommunity = SESSION_PROTOCOL_DESTINATION_TYPE_ENVELOPE_COMMUNITY,
};

struct Destination {
Expand Down Expand Up @@ -606,6 +608,23 @@ DecodedEnvelope decode_envelope(
std::span<const uint8_t> envelope_payload,
const array_uc32& pro_backend_pubkey);

/// API: session_protocol/decode_for_community_inbox
///
/// Given a blinded encrypted content or envelope payload extract the plaintext to the content and
/// any associated pro metadata if there was any in the message.
///
/// This function is the same as calling `decrypt_from_blinded_recipient` to decrypt the payload and
/// then decode with `decode_for_community`. See those functions for more information. On failure
/// this function throws as per `decrypt_from_blinded_recipient`
DecodedCommunityMessage decode_for_community_inbox(
std::span<const unsigned char> ed25519_privkey,
std::span<const unsigned char> community_pubkey,
std::span<const unsigned char> sender_id,
std::span<const unsigned char> recipient_id,
std::span<const unsigned char> ciphertext,
std::chrono::sys_time<std::chrono::milliseconds> unix_ts,
const array_uc32& pro_backend_pubkey);

/// API: session_protocol/decode_for_community
///
/// Given an unencrypted content or envelope payload extract the plaintext to the content and any
Expand Down
Loading