Config revamp WIP

This commit is contained in:
SessionHero01
2024-09-26 15:43:45 +10:00
parent 7eb615f8dc
commit 771d63e902
58 changed files with 1831 additions and 2532 deletions

View File

@@ -34,7 +34,9 @@ set(SOURCES
util.cpp
group_members.cpp
group_keys.cpp
group_info.cpp)
group_info.cpp
config_common.cpp
)
add_library( # Sets the name of the library.
session_util

View File

@@ -0,0 +1,39 @@
#include <jni.h>
#include "util.h"
#include "jni_utils.h"
#include <session/config/contacts.hpp>
#include <session/config/user_groups.hpp>
#include <session/config/user_profile.hpp>
#include <session/config/convo_info_volatile.hpp>
extern "C"
JNIEXPORT jlong JNICALL
Java_network_loki_messenger_libsession_1util_ConfigKt_createConfigObject(
JNIEnv *env,
jclass _clazz,
jstring java_config_name,
jbyteArray ed25519_secret_key,
jbyteArray initial_dump) {
return jni_utils::run_catching_cxx_exception_or_throws<jlong>(env, [=] {
auto config_name = util::string_from_jstring(env, java_config_name);
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto initial = initial_dump
? std::optional(util::ustring_from_bytes(env, initial_dump))
: std::nullopt;
std::lock_guard lock{util::util_mutex_};
if (config_name == "Contacts") {
return reinterpret_cast<jlong>(new session::config::Contacts(secret_key, initial));
} else if (config_name == "UserProfile") {
return reinterpret_cast<jlong>(new session::config::UserProfile(secret_key, initial));
} else if (config_name == "UserGroups") {
return reinterpret_cast<jlong>(new session::config::UserGroups(secret_key, initial));
} else if (config_name == "ConversationVolatileConfig") {
return reinterpret_cast<jlong>(new session::config::ConvoInfoVolatile(secret_key, initial));
} else {
throw std::invalid_argument("Unknown config name: " + config_name);
}
});
}

View File

@@ -62,46 +62,7 @@ Java_network_loki_messenger_libsession_1util_Contacts_erase(JNIEnv *env, jobject
return result;
});
}
extern "C"
#pragma clang diagnostic push
#pragma ide diagnostic ignored "bugprone-reserved-identifier"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_Contacts_00024Companion_newInstance___3B(JNIEnv *env,
jobject thiz,
jbyteArray ed25519_secret_key) {
return jni_utils::run_catching_cxx_exception_or_throws<jobject>(env, [=] {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto *contacts = new session::config::Contacts(secret_key, std::nullopt);
jclass contactsClass = env->FindClass("network/loki/messenger/libsession_util/Contacts");
jmethodID constructor = env->GetMethodID(contactsClass, "<init>", "(J)V");
jobject newConfig = env->NewObject(contactsClass, constructor,
reinterpret_cast<jlong>(contacts));
return newConfig;
});
}
extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_Contacts_00024Companion_newInstance___3B_3B(
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key, jbyteArray initial_dump) {
return jni_utils::run_catching_cxx_exception_or_throws<jobject>(env, [=] {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto initial = util::ustring_from_bytes(env, initial_dump);
auto *contacts = new session::config::Contacts(secret_key, initial);
jclass contactsClass = env->FindClass("network/loki/messenger/libsession_util/Contacts");
jmethodID constructor = env->GetMethodID(contactsClass, "<init>", "(J)V");
jobject newConfig = env->NewObject(contactsClass, constructor,
reinterpret_cast<jlong>(contacts));
return newConfig;
});
}
#pragma clang diagnostic pop
extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_Contacts_all(JNIEnv *env, jobject thiz) {
@@ -118,4 +79,4 @@ Java_network_loki_messenger_libsession_1util_Contacts_all(JNIEnv *env, jobject t
}
return our_stack;
});
}
}

View File

@@ -1,41 +1,6 @@
#include <jni.h>
#include "conversation.h"
#pragma clang diagnostic push
extern "C"
#pragma ide diagnostic ignored "bugprone-reserved-identifier"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_00024Companion_newInstance___3B(
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key) {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto* convo_info_volatile = new session::config::ConvoInfoVolatile(secret_key, std::nullopt);
jclass convoClass = env->FindClass("network/loki/messenger/libsession_util/ConversationVolatileConfig");
jmethodID constructor = env->GetMethodID(convoClass, "<init>", "(J)V");
jobject newConfig = env->NewObject(convoClass, constructor, reinterpret_cast<jlong>(convo_info_volatile));
return newConfig;
}
extern "C"
#pragma ide diagnostic ignored "bugprone-reserved-identifier"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_00024Companion_newInstance___3B_3B(
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key, jbyteArray initial_dump) {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto initial = util::ustring_from_bytes(env, initial_dump);
auto* convo_info_volatile = new session::config::ConvoInfoVolatile(secret_key, initial);
jclass convoClass = env->FindClass("network/loki/messenger/libsession_util/ConversationVolatileConfig");
jmethodID constructor = env->GetMethodID(convoClass, "<init>", "(J)V");
jobject newConfig = env->NewObject(convoClass, constructor, reinterpret_cast<jlong>(convo_info_volatile));
return newConfig;
}
extern "C"
JNIEXPORT jint JNICALL
@@ -46,7 +11,6 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_sizeOneT
return conversations->size_1to1();
}
#pragma clang diagnostic pop
extern "C"
JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseAll(JNIEnv *env,
@@ -406,4 +370,4 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseClo
auto erased = config->erase_group(session_id_bytes);
env->ReleaseStringUTFChars(session_id, session_id_bytes);
return erased;
}
}

View File

@@ -3,7 +3,7 @@
#include "session/config/groups/info.hpp"
extern "C"
JNIEXPORT jobject JNICALL
JNIEXPORT jlong JNICALL
Java_network_loki_messenger_libsession_1util_GroupInfoConfig_00024Companion_newInstance(JNIEnv *env,
jobject thiz,
jbyteArray pub_key,
@@ -17,18 +17,13 @@ Java_network_loki_messenger_libsession_1util_GroupInfoConfig_00024Companion_newI
auto secret_key_bytes = util::ustring_from_bytes(env, secret_key);
secret_key_optional = secret_key_bytes;
}
if (env->GetArrayLength(initial_dump) > 0) {
if (initial_dump && env->GetArrayLength(initial_dump) > 0) {
auto initial_dump_bytes = util::ustring_from_bytes(env, initial_dump);
initial_dump_optional = initial_dump_bytes;
}
auto* group_info = new session::config::groups::Info(pub_key_bytes, secret_key_optional, initial_dump_optional);
jclass groupInfoClass = env->FindClass("network/loki/messenger/libsession_util/GroupInfoConfig");
jmethodID constructor = env->GetMethodID(groupInfoClass, "<init>", "(J)V");
jobject newConfig = env->NewObject(groupInfoClass, constructor, reinterpret_cast<jlong>(group_info));
return newConfig;
return reinterpret_cast<jlong>(group_info);
}
extern "C"

View File

@@ -10,15 +10,15 @@ JNIEXPORT jint JNICALL
}
extern "C"
JNIEXPORT jobject JNICALL
JNIEXPORT jlong JNICALL
Java_network_loki_messenger_libsession_1util_GroupKeysConfig_00024Companion_newInstance(JNIEnv *env,
jobject thiz,
jbyteArray user_secret_key,
jbyteArray group_public_key,
jbyteArray group_secret_key,
jbyteArray initial_dump,
jobject info_jobject,
jobject members_jobject) {
jlong info_pointer,
jlong members_pointer) {
std::lock_guard lock{util::util_mutex_};
auto user_key_bytes = util::ustring_from_bytes(env, user_secret_key);
auto pub_key_bytes = util::ustring_from_bytes(env, group_public_key);
@@ -35,8 +35,8 @@ Java_network_loki_messenger_libsession_1util_GroupKeysConfig_00024Companion_newI
initial_dump_optional = initial_dump_bytes;
}
auto info = ptrToInfo(env, info_jobject);
auto members = ptrToMembers(env, members_jobject);
auto info = reinterpret_cast<session::config::groups::Info*>(info_pointer);
auto members = reinterpret_cast<session::config::groups::Members*>(members_pointer);
auto* keys = new session::config::groups::Keys(user_key_bytes,
pub_key_bytes,
@@ -45,11 +45,7 @@ Java_network_loki_messenger_libsession_1util_GroupKeysConfig_00024Companion_newI
*info,
*members);
jclass groupKeysConfig = env->FindClass("network/loki/messenger/libsession_util/GroupKeysConfig");
jmethodID constructor = env->GetMethodID(groupKeysConfig, "<init>", "(J)V");
jobject newConfig = env->NewObject(groupKeysConfig, constructor, reinterpret_cast<jlong>(keys));
return newConfig;
return reinterpret_cast<jlong>(keys);
}
extern "C"
@@ -75,14 +71,14 @@ Java_network_loki_messenger_libsession_1util_GroupKeysConfig_loadKey(JNIEnv *env
jbyteArray message,
jstring hash,
jlong timestamp_ms,
jobject info_jobject,
jobject members_jobject) {
jlong info_ptr,
jlong members_ptr) {
std::lock_guard lock{util::util_mutex_};
auto keys = ptrToKeys(env, thiz);
auto message_bytes = util::ustring_from_bytes(env, message);
auto hash_bytes = env->GetStringUTFChars(hash, nullptr);
auto info = ptrToInfo(env, info_jobject);
auto members = ptrToMembers(env, members_jobject);
auto info = reinterpret_cast<session::config::groups::Info*>(info_ptr);
auto members = reinterpret_cast<session::config::groups::Members*>(members_ptr);
bool processed = keys->load_key_message(hash_bytes, message_bytes, timestamp_ms, *info, *members);
env->ReleaseStringUTFChars(hash, hash_bytes);
@@ -137,11 +133,11 @@ Java_network_loki_messenger_libsession_1util_GroupKeysConfig_pendingConfig(JNIEn
extern "C"
JNIEXPORT jbyteArray JNICALL
Java_network_loki_messenger_libsession_1util_GroupKeysConfig_rekey(JNIEnv *env, jobject thiz,
jobject info_jobject, jobject members_jobject) {
jlong info_ptr, jlong members_ptr) {
std::lock_guard lock{util::util_mutex_};
auto keys = ptrToKeys(env, thiz);
auto info = ptrToInfo(env, info_jobject);
auto members = ptrToMembers(env, members_jobject);
auto info = reinterpret_cast<session::config::groups::Info*>(info_ptr);
auto members = reinterpret_cast<session::config::groups::Members*>(members_ptr);
auto rekey = keys->rekey(*info, *members);
auto rekey_bytes = util::bytes_from_ustring(env, rekey.data());
return rekey_bytes;

View File

@@ -1,7 +1,7 @@
#include "group_members.h"
extern "C"
JNIEXPORT jobject JNICALL
JNIEXPORT jlong JNICALL
Java_network_loki_messenger_libsession_1util_GroupMembersConfig_00024Companion_newInstance(
JNIEnv *env, jobject thiz, jbyteArray pub_key, jbyteArray secret_key,
jbyteArray initial_dump) {
@@ -13,18 +13,13 @@ Java_network_loki_messenger_libsession_1util_GroupMembersConfig_00024Companion_n
auto secret_key_bytes = util::ustring_from_bytes(env, secret_key);
secret_key_optional = secret_key_bytes;
}
if (env->GetArrayLength(initial_dump) > 0) {
if (initial_dump && env->GetArrayLength(initial_dump) > 0) {
auto initial_dump_bytes = util::ustring_from_bytes(env, initial_dump);
initial_dump_optional = initial_dump_bytes;
}
auto* group_members = new session::config::groups::Members(pub_key_bytes, secret_key_optional, initial_dump_optional);
jclass groupMemberClass = env->FindClass("network/loki/messenger/libsession_util/GroupMembersConfig");
jmethodID constructor = env->GetMethodID(groupMemberClass, "<init>", "(J)V");
jobject newConfig = env->NewObject(groupMemberClass, constructor, reinterpret_cast<jlong>(group_members));
return newConfig;
return reinterpret_cast<jlong>(group_members);
}
extern "C"

View File

@@ -1,44 +1,6 @@
#pragma clang diagnostic push
#pragma ide diagnostic ignored "bugprone-reserved-identifier"
#include "user_groups.h"
#include "oxenc/hex.h"
#pragma clang diagnostic push
#pragma ide diagnostic ignored "bugprone-reserved-identifier"
extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_00024Companion_newInstance___3B(
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key) {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto* user_groups = new session::config::UserGroups(secret_key, std::nullopt);
jclass contactsClass = env->FindClass("network/loki/messenger/libsession_util/UserGroupsConfig");
jmethodID constructor = env->GetMethodID(contactsClass, "<init>", "(J)V");
jobject newConfig = env->NewObject(contactsClass, constructor, reinterpret_cast<jlong>(user_groups));
return newConfig;
}
extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_00024Companion_newInstance___3B_3B(
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key, jbyteArray initial_dump) {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto initial = util::ustring_from_bytes(env, initial_dump);
auto* user_groups = new session::config::UserGroups(secret_key, initial);
jclass contactsClass = env->FindClass("network/loki/messenger/libsession_util/UserGroupsConfig");
jmethodID constructor = env->GetMethodID(contactsClass, "<init>", "(J)V");
jobject newConfig = env->NewObject(contactsClass, constructor, reinterpret_cast<jlong>(user_groups));
return newConfig;
}
#pragma clang diagnostic pop
extern "C"
JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_util_GroupInfo_00024LegacyGroupInfo_00024Companion_NAME_1MAX_1LENGTH(
@@ -361,4 +323,4 @@ Java_network_loki_messenger_libsession_1util_UserGroupsConfig_eraseClosedGroup(J
bool return_value = config->erase_group(session_id_bytes);
env->ReleaseStringUTFChars(session_id, session_id_bytes);
return return_value;
}
}

View File

@@ -2,39 +2,6 @@
#include "util.h"
extern "C" {
#pragma clang diagnostic push
#pragma ide diagnostic ignored "bugprone-reserved-identifier"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_00024Companion_newInstance___3B_3B(
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key, jbyteArray initial_dump) {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto initial = util::ustring_from_bytes(env, initial_dump);
auto* profile = new session::config::UserProfile(secret_key, std::optional(initial));
jclass userClass = env->FindClass("network/loki/messenger/libsession_util/UserProfile");
jmethodID constructor = env->GetMethodID(userClass, "<init>", "(J)V");
jobject newConfig = env->NewObject(userClass, constructor, reinterpret_cast<jlong>(profile));
return newConfig;
}
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_00024Companion_newInstance___3B(
JNIEnv* env,
jobject,
jbyteArray secretKey) {
std::lock_guard lock{util::util_mutex_};
auto* profile = new session::config::UserProfile(util::ustring_from_bytes(env, secretKey), std::nullopt);
jclass userClass = env->FindClass("network/loki/messenger/libsession_util/UserProfile");
jmethodID constructor = env->GetMethodID(userClass, "<init>", "(J)V");
jobject newConfig = env->NewObject(userClass, constructor, reinterpret_cast<jlong>(profile));
return newConfig;
}
#pragma clang diagnostic pop
JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_setName(
JNIEnv* env,
@@ -149,4 +116,4 @@ Java_network_loki_messenger_libsession_1util_UserProfile_isBlockCommunityMessage
std::lock_guard lock{util::util_mutex_};
auto profile = ptrToProfile(env, thiz);
return profile->get_blinded_msgreqs().has_value();
}
}

View File

@@ -16,15 +16,43 @@ import org.session.libsignal.utilities.Namespace
import java.io.Closeable
import java.util.Stack
sealed class Config(protected val pointer: Long): Closeable {
sealed class Config(initialPointer: Long): Closeable {
var pointer = initialPointer
private set
init {
check(pointer != 0L) { "Pointer is null" }
}
abstract fun namespace(): Int
external fun free()
override fun close() {
free()
private external fun free()
final override fun close() {
if (pointer != 0L) {
free()
pointer = 0L
}
}
}
sealed class ConfigBase(pointer: Long): Config(pointer) {
interface ReadableConfig {
fun namespace(): Int
fun needsPush(): Boolean
fun needsDump(): Boolean
fun currentHashes(): List<String>
}
interface MutableConfig : ReadableConfig {
fun push(): ConfigPush
fun dump(): ByteArray
fun encryptionDomain(): String
fun confirmPushed(seqNo: Long, newHash: String)
fun merge(toMerge: Array<Pair<String,ByteArray>>): Stack<String>
fun dirty(): Boolean
}
sealed class ConfigBase(pointer: Long): Config(pointer), MutableConfig {
companion object {
init {
System.loadLibrary("session_util")
@@ -46,42 +74,35 @@ sealed class ConfigBase(pointer: Long): Config(pointer) {
}
external fun dirty(): Boolean
external fun needsPush(): Boolean
external fun needsDump(): Boolean
external fun push(): ConfigPush
external fun dump(): ByteArray
external fun encryptionDomain(): String
external fun confirmPushed(seqNo: Long, newHash: String)
external fun merge(toMerge: Array<Pair<String,ByteArray>>): Stack<String>
external fun currentHashes(): List<String>
external override fun dirty(): Boolean
external override fun needsPush(): Boolean
external override fun needsDump(): Boolean
external override fun push(): ConfigPush
external override fun dump(): ByteArray
external override fun encryptionDomain(): String
external override fun confirmPushed(seqNo: Long, newHash: String)
external override fun merge(toMerge: Array<Pair<String,ByteArray>>): Stack<String>
external override fun currentHashes(): List<String>
// Singular merge
external fun merge(toMerge: Pair<String,ByteArray>): Stack<String>
}
class Contacts(pointer: Long) : ConfigBase(pointer) {
companion object {
init {
System.loadLibrary("session_util")
}
external fun newInstance(ed25519SecretKey: ByteArray): Contacts
external fun newInstance(ed25519SecretKey: ByteArray, initialDump: ByteArray): Contacts
}
override fun namespace() = Namespace.CONTACTS()
interface ReadableContacts: ReadableConfig {
fun get(accountId: String): Contact?
fun all(): List<Contact>
}
external fun get(accountId: String): Contact?
external fun getOrConstruct(accountId: String): Contact
external fun all(): List<Contact>
external fun set(contact: Contact)
external fun erase(accountId: String): Boolean
interface MutableContacts : ReadableContacts, MutableConfig {
fun getOrConstruct(accountId: String): Contact
fun set(contact: Contact)
fun erase(accountId: String): Boolean
/**
* Similar to [updateIfExists], but will create the underlying contact if it doesn't exist before passing to [updateFunction]
*/
fun upsertContact(accountId: String, updateFunction: Contact.()->Unit = {}) {
fun upsertContact(accountId: String, updateFunction: Contact.() -> Unit = {}) {
when {
accountId.startsWith(IdPrefix.BLINDED.value) -> Log.w("Loki", "Trying to create a contact with a blinded ID prefix")
accountId.startsWith(IdPrefix.UN_BLINDED.value) -> Log.w("Loki", "Trying to create a contact with an un-blinded ID prefix")
@@ -92,251 +113,403 @@ class Contacts(pointer: Long) : ConfigBase(pointer) {
}
}
}
/**
* Updates the contact by accountId with a given [updateFunction], and applies to the underlying config.
* the [updateFunction] doesn't run if there is no contact
*/
private fun updateIfExists(accountId: String, updateFunction: Contact.()->Unit) {
when {
accountId.startsWith(IdPrefix.BLINDED.value) -> Log.w("Loki", "Trying to create a contact with a blinded ID prefix")
accountId.startsWith(IdPrefix.UN_BLINDED.value) -> Log.w("Loki", "Trying to create a contact with an un-blinded ID prefix")
accountId.startsWith(IdPrefix.BLINDEDV2.value) -> Log.w("Loki", "Trying to create a contact with a blindedv2 ID prefix")
else -> get(accountId)?.let {
updateFunction(it)
set(it)
}
}
}
}
class UserProfile(pointer: Long) : ConfigBase(pointer) {
companion object {
init {
System.loadLibrary("session_util")
}
external fun newInstance(ed25519SecretKey: ByteArray): UserProfile
external fun newInstance(ed25519SecretKey: ByteArray, initialDump: ByteArray): UserProfile
}
class Contacts private constructor(pointer: Long) : ConfigBase(pointer), MutableContacts {
constructor(ed25519SecretKey: ByteArray, initialDump: ByteArray? = null) : this(
createConfigObject(
"Contacts",
ed25519SecretKey,
initialDump
)
)
override fun namespace() = Namespace.CONTACTS()
external override fun get(accountId: String): Contact?
external override fun getOrConstruct(accountId: String): Contact
external override fun all(): List<Contact>
external override fun set(contact: Contact)
external override fun erase(accountId: String): Boolean
}
interface ReadableUserProfile: ReadableConfig {
fun getName(): String?
fun getPic(): UserPic
fun getNtsPriority(): Long
fun getNtsExpiry(): ExpiryMode
fun getCommunityMessageRequests(): Boolean
fun isBlockCommunityMessageRequestsSet(): Boolean
}
interface MutableUserProfile : ReadableUserProfile, MutableConfig {
fun setName(newName: String)
fun setPic(userPic: UserPic)
fun setNtsPriority(priority: Long)
fun setNtsExpiry(expiryMode: ExpiryMode)
fun setCommunityMessageRequests(blocks: Boolean)
}
class UserProfile private constructor(pointer: Long) : ConfigBase(pointer), MutableUserProfile {
constructor(ed25519SecretKey: ByteArray, initialDump: ByteArray? = null) : this(
createConfigObject(
"UserProfile",
ed25519SecretKey,
initialDump
)
)
override fun namespace() = Namespace.USER_PROFILE()
external fun setName(newName: String)
external fun getName(): String?
external fun getPic(): UserPic
external fun setPic(userPic: UserPic)
external fun setNtsPriority(priority: Long)
external fun getNtsPriority(): Long
external fun setNtsExpiry(expiryMode: ExpiryMode)
external fun getNtsExpiry(): ExpiryMode
external fun getCommunityMessageRequests(): Boolean
external fun setCommunityMessageRequests(blocks: Boolean)
external fun isBlockCommunityMessageRequestsSet(): Boolean
external override fun setName(newName: String)
external override fun getName(): String?
external override fun getPic(): UserPic
external override fun setPic(userPic: UserPic)
external override fun setNtsPriority(priority: Long)
external override fun getNtsPriority(): Long
external override fun setNtsExpiry(expiryMode: ExpiryMode)
external override fun getNtsExpiry(): ExpiryMode
external override fun getCommunityMessageRequests(): Boolean
external override fun setCommunityMessageRequests(blocks: Boolean)
external override fun isBlockCommunityMessageRequestsSet(): Boolean
}
class ConversationVolatileConfig(pointer: Long): ConfigBase(pointer) {
companion object {
init {
System.loadLibrary("session_util")
}
external fun newInstance(ed25519SecretKey: ByteArray): ConversationVolatileConfig
external fun newInstance(ed25519SecretKey: ByteArray, initialDump: ByteArray): ConversationVolatileConfig
}
interface ReadableConversationVolatileConfig: ReadableConfig {
fun getOneToOne(pubKeyHex: String): Conversation.OneToOne?
fun getCommunity(baseUrl: String, room: String): Conversation.Community?
fun getLegacyClosedGroup(groupId: String): Conversation.LegacyGroup?
fun getClosedGroup(sessionId: String): Conversation.ClosedGroup?
fun sizeOneToOnes(): Int
fun sizeCommunities(): Int
fun sizeLegacyClosedGroups(): Int
fun size(): Int
fun empty(): Boolean
fun allOneToOnes(): List<Conversation.OneToOne>
fun allCommunities(): List<Conversation.Community>
fun allLegacyClosedGroups(): List<Conversation.LegacyGroup>
fun allClosedGroups(): List<Conversation.ClosedGroup>
fun all(): List<Conversation?>
}
interface MutableConversationVolatileConfig : ReadableConversationVolatileConfig, MutableConfig {
fun getOrConstructOneToOne(pubKeyHex: String): Conversation.OneToOne
fun eraseOneToOne(pubKeyHex: String): Boolean
fun getOrConstructCommunity(baseUrl: String, room: String, pubKeyHex: String): Conversation.Community
fun getOrConstructCommunity(baseUrl: String, room: String, pubKey: ByteArray): Conversation.Community
fun eraseCommunity(community: Conversation.Community): Boolean
fun eraseCommunity(baseUrl: String, room: String): Boolean
fun getOrConstructLegacyGroup(groupId: String): Conversation.LegacyGroup
fun eraseLegacyClosedGroup(groupId: String): Boolean
fun getOrConstructClosedGroup(sessionId: String): Conversation.ClosedGroup
fun eraseClosedGroup(sessionId: String): Boolean
fun erase(conversation: Conversation): Boolean
fun set(toStore: Conversation)
fun eraseAll(predicate: (Conversation) -> Boolean): Int
}
class ConversationVolatileConfig private constructor(pointer: Long): ConfigBase(pointer), MutableConversationVolatileConfig {
constructor(ed25519SecretKey: ByteArray, initialDump: ByteArray? = null) : this(
createConfigObject(
"ConvoInfoVolatile",
ed25519SecretKey,
initialDump
)
)
override fun namespace() = Namespace.CONVO_INFO_VOLATILE()
external fun getOneToOne(pubKeyHex: String): Conversation.OneToOne?
external fun getOrConstructOneToOne(pubKeyHex: String): Conversation.OneToOne
external fun eraseOneToOne(pubKeyHex: String): Boolean
external override fun getOneToOne(pubKeyHex: String): Conversation.OneToOne?
external override fun getOrConstructOneToOne(pubKeyHex: String): Conversation.OneToOne
external override fun eraseOneToOne(pubKeyHex: String): Boolean
external fun getCommunity(baseUrl: String, room: String): Conversation.Community?
external fun getOrConstructCommunity(baseUrl: String, room: String, pubKeyHex: String): Conversation.Community
external fun getOrConstructCommunity(baseUrl: String, room: String, pubKey: ByteArray): Conversation.Community
external fun eraseCommunity(community: Conversation.Community): Boolean
external fun eraseCommunity(baseUrl: String, room: String): Boolean
external override fun getCommunity(baseUrl: String, room: String): Conversation.Community?
external override fun getOrConstructCommunity(baseUrl: String, room: String, pubKeyHex: String): Conversation.Community
external override fun getOrConstructCommunity(baseUrl: String, room: String, pubKey: ByteArray): Conversation.Community
external override fun eraseCommunity(community: Conversation.Community): Boolean
external override fun eraseCommunity(baseUrl: String, room: String): Boolean
external fun getLegacyClosedGroup(groupId: String): Conversation.LegacyGroup?
external fun getOrConstructLegacyGroup(groupId: String): Conversation.LegacyGroup
external fun eraseLegacyClosedGroup(groupId: String): Boolean
external override fun getLegacyClosedGroup(groupId: String): Conversation.LegacyGroup?
external override fun getOrConstructLegacyGroup(groupId: String): Conversation.LegacyGroup
external override fun eraseLegacyClosedGroup(groupId: String): Boolean
external fun getClosedGroup(sessionId: String): Conversation.ClosedGroup?
external fun getOrConstructClosedGroup(sessionId: String): Conversation.ClosedGroup
external fun eraseClosedGroup(sessionId: String): Boolean
external override fun getClosedGroup(sessionId: String): Conversation.ClosedGroup?
external override fun getOrConstructClosedGroup(sessionId: String): Conversation.ClosedGroup
external override fun eraseClosedGroup(sessionId: String): Boolean
external fun erase(conversation: Conversation): Boolean
external fun set(toStore: Conversation)
external override fun erase(conversation: Conversation): Boolean
external override fun set(toStore: Conversation)
/**
* Erase all conversations that do not satisfy the `predicate`, similar to [MutableList.removeAll]
*/
external fun eraseAll(predicate: (Conversation) -> Boolean): Int
external override fun eraseAll(predicate: (Conversation) -> Boolean): Int
external fun sizeOneToOnes(): Int
external fun sizeCommunities(): Int
external fun sizeLegacyClosedGroups(): Int
external fun size(): Int
external override fun sizeOneToOnes(): Int
external override fun sizeCommunities(): Int
external override fun sizeLegacyClosedGroups(): Int
external override fun size(): Int
external fun empty(): Boolean
external fun allOneToOnes(): List<Conversation.OneToOne>
external fun allCommunities(): List<Conversation.Community>
external fun allLegacyClosedGroups(): List<Conversation.LegacyGroup>
external fun allClosedGroups(): List<Conversation.ClosedGroup>
external fun all(): List<Conversation?>
external override fun empty(): Boolean
external override fun allOneToOnes(): List<Conversation.OneToOne>
external override fun allCommunities(): List<Conversation.Community>
external override fun allLegacyClosedGroups(): List<Conversation.LegacyGroup>
external override fun allClosedGroups(): List<Conversation.ClosedGroup>
external override fun all(): List<Conversation?>
}
class UserGroupsConfig(pointer: Long): ConfigBase(pointer) {
companion object {
init {
System.loadLibrary("session_util")
}
external fun newInstance(ed25519SecretKey: ByteArray): UserGroupsConfig
external fun newInstance(ed25519SecretKey: ByteArray, initialDump: ByteArray): UserGroupsConfig
}
interface ReadableUserGroupsConfig : ReadableConfig {
fun getCommunityInfo(baseUrl: String, room: String): GroupInfo.CommunityGroupInfo?
fun getLegacyGroupInfo(accountId: String): GroupInfo.LegacyGroupInfo?
fun getClosedGroup(accountId: String): GroupInfo.ClosedGroupInfo?
fun sizeCommunityInfo(): Long
fun sizeLegacyGroupInfo(): Long
fun sizeClosedGroup(): Long
fun size(): Long
fun all(): List<GroupInfo>
fun allCommunityInfo(): List<GroupInfo.CommunityGroupInfo>
fun allLegacyGroupInfo(): List<GroupInfo.LegacyGroupInfo>
fun allClosedGroupInfo(): List<GroupInfo.ClosedGroupInfo>
}
interface MutableUserGroupsConfig : ReadableUserGroupsConfig, MutableConfig {
fun getOrConstructCommunityInfo(baseUrl: String, room: String, pubKeyHex: String): GroupInfo.CommunityGroupInfo
fun getOrConstructLegacyGroupInfo(accountId: String): GroupInfo.LegacyGroupInfo
fun getOrConstructClosedGroup(accountId: String): GroupInfo.ClosedGroupInfo
fun set(groupInfo: GroupInfo)
fun erase(groupInfo: GroupInfo)
fun eraseCommunity(baseCommunityInfo: BaseCommunityInfo): Boolean
fun eraseCommunity(server: String, room: String): Boolean
fun eraseLegacyGroup(accountId: String): Boolean
fun eraseClosedGroup(accountId: String): Boolean
fun createGroup(): GroupInfo.ClosedGroupInfo
}
class UserGroupsConfig private constructor(pointer: Long): ConfigBase(pointer), MutableUserGroupsConfig {
constructor(ed25519SecretKey: ByteArray, initialDump: ByteArray? = null) : this(
createConfigObject(
"UserGroups",
ed25519SecretKey,
initialDump
)
)
override fun namespace() = Namespace.GROUPS()
external fun getCommunityInfo(baseUrl: String, room: String): GroupInfo.CommunityGroupInfo?
external fun getLegacyGroupInfo(accountId: String): GroupInfo.LegacyGroupInfo?
external fun getClosedGroup(accountId: String): GroupInfo.ClosedGroupInfo?
external fun getOrConstructCommunityInfo(baseUrl: String, room: String, pubKeyHex: String): GroupInfo.CommunityGroupInfo
external fun getOrConstructLegacyGroupInfo(accountId: String): GroupInfo.LegacyGroupInfo
external fun getOrConstructClosedGroup(accountId: String): GroupInfo.ClosedGroupInfo
external fun set(groupInfo: GroupInfo)
external fun erase(groupInfo: GroupInfo)
external fun eraseCommunity(baseCommunityInfo: BaseCommunityInfo): Boolean
external fun eraseCommunity(server: String, room: String): Boolean
external fun eraseLegacyGroup(accountId: String): Boolean
external fun eraseClosedGroup(accountId: String): Boolean
external fun sizeCommunityInfo(): Long
external fun sizeLegacyGroupInfo(): Long
external fun sizeClosedGroup(): Long
external fun size(): Long
external fun all(): List<GroupInfo>
external fun allCommunityInfo(): List<GroupInfo.CommunityGroupInfo>
external fun allLegacyGroupInfo(): List<GroupInfo.LegacyGroupInfo>
external fun allClosedGroupInfo(): List<GroupInfo.ClosedGroupInfo>
external fun createGroup(): GroupInfo.ClosedGroupInfo
external override fun getCommunityInfo(baseUrl: String, room: String): GroupInfo.CommunityGroupInfo?
external override fun getLegacyGroupInfo(accountId: String): GroupInfo.LegacyGroupInfo?
external override fun getClosedGroup(accountId: String): GroupInfo.ClosedGroupInfo?
external override fun getOrConstructCommunityInfo(baseUrl: String, room: String, pubKeyHex: String): GroupInfo.CommunityGroupInfo
external override fun getOrConstructLegacyGroupInfo(accountId: String): GroupInfo.LegacyGroupInfo
external override fun getOrConstructClosedGroup(accountId: String): GroupInfo.ClosedGroupInfo
external override fun set(groupInfo: GroupInfo)
external override fun erase(groupInfo: GroupInfo)
external override fun eraseCommunity(baseCommunityInfo: BaseCommunityInfo): Boolean
external override fun eraseCommunity(server: String, room: String): Boolean
external override fun eraseLegacyGroup(accountId: String): Boolean
external override fun eraseClosedGroup(accountId: String): Boolean
external override fun sizeCommunityInfo(): Long
external override fun sizeLegacyGroupInfo(): Long
external override fun sizeClosedGroup(): Long
external override fun size(): Long
external override fun all(): List<GroupInfo>
external override fun allCommunityInfo(): List<GroupInfo.CommunityGroupInfo>
external override fun allLegacyGroupInfo(): List<GroupInfo.LegacyGroupInfo>
external override fun allClosedGroupInfo(): List<GroupInfo.ClosedGroupInfo>
external override fun createGroup(): GroupInfo.ClosedGroupInfo
}
class GroupInfoConfig(pointer: Long): ConfigBase(pointer), Closeable {
companion object {
init {
System.loadLibrary("session_util")
}
interface ReadableGroupInfoConfig: ReadableConfig {
fun id(): AccountId
fun getDeleteAttachmentsBefore(): Long?
fun getDeleteBefore(): Long?
fun getExpiryTimer(): Long
fun getName(): String
fun getCreated(): Long?
fun getProfilePic(): UserPic
fun isDestroyed(): Boolean
fun getDescription(): String
fun storageNamespace(): Long
}
external fun newInstance(
pubKey: ByteArray?,
secretKey: ByteArray? = null,
initialDump: ByteArray = byteArrayOf()
): GroupInfoConfig
interface MutableGroupInfoConfig : ReadableGroupInfoConfig, MutableConfig {
fun setCreated(createdAt: Long)
fun setDeleteAttachmentsBefore(deleteBefore: Long)
fun setDeleteBefore(deleteBefore: Long)
fun setExpiryTimer(expireSeconds: Long)
fun setName(newName: String)
fun setDescription(newDescription: String)
fun setProfilePic(newProfilePic: UserPic)
fun destroyGroup()
}
class GroupInfoConfig private constructor(pointer: Long): ConfigBase(pointer), MutableGroupInfoConfig {
constructor(groupPubKey: ByteArray, groupAdminKey: ByteArray?, initialDump: ByteArray?)
: this(newInstance(groupPubKey, groupAdminKey, initialDump))
companion object {
private external fun newInstance(
pubKey: ByteArray,
secretKey: ByteArray?,
initialDump: ByteArray?
): Long
}
override fun namespace() = Namespace.CLOSED_GROUP_INFO()
external fun id(): AccountId
external fun destroyGroup()
external fun getCreated(): Long?
external fun getDeleteAttachmentsBefore(): Long?
external fun getDeleteBefore(): Long?
external fun getExpiryTimer(): Long
external fun getName(): String
external fun getProfilePic(): UserPic
external fun isDestroyed(): Boolean
external fun setCreated(createdAt: Long)
external fun setDeleteAttachmentsBefore(deleteBefore: Long)
external fun setDeleteBefore(deleteBefore: Long)
external fun setExpiryTimer(expireSeconds: Long)
external fun setName(newName: String)
external fun getDescription(): String
external fun setDescription(newDescription: String)
external fun setProfilePic(newProfilePic: UserPic)
external fun storageNamespace(): Long
override fun close() {
free()
}
external override fun id(): AccountId
external override fun destroyGroup()
external override fun getCreated(): Long?
external override fun getDeleteAttachmentsBefore(): Long?
external override fun getDeleteBefore(): Long?
external override fun getExpiryTimer(): Long
external override fun getName(): String
external override fun getProfilePic(): UserPic
external override fun isDestroyed(): Boolean
external override fun setCreated(createdAt: Long)
external override fun setDeleteAttachmentsBefore(deleteBefore: Long)
external override fun setDeleteBefore(deleteBefore: Long)
external override fun setExpiryTimer(expireSeconds: Long)
external override fun setName(newName: String)
external override fun getDescription(): String
external override fun setDescription(newDescription: String)
external override fun setProfilePic(newProfilePic: UserPic)
external override fun storageNamespace(): Long
}
class GroupMembersConfig(pointer: Long): ConfigBase(pointer), Closeable {
interface ReadableGroupMembersConfig: ReadableConfig {
fun all(): List<GroupMember>
fun get(pubKeyHex: String): GroupMember?
}
interface MutableGroupMembersConfig : ReadableGroupMembersConfig, MutableConfig {
fun getOrConstruct(pubKeyHex: String): GroupMember
fun set(groupMember: GroupMember)
fun erase(groupMember: GroupMember): Boolean
fun erase(pubKeyHex: String): Boolean
}
class GroupMembersConfig private constructor(pointer: Long): ConfigBase(pointer), MutableGroupMembersConfig {
companion object {
init {
System.loadLibrary("session_util")
}
external fun newInstance(
private external fun newInstance(
pubKey: ByteArray,
secretKey: ByteArray? = null,
initialDump: ByteArray = byteArrayOf()
): GroupMembersConfig
secretKey: ByteArray?,
initialDump: ByteArray?
): Long
}
constructor(groupPubKey: ByteArray, groupAdminKey: ByteArray?, initialDump: ByteArray?)
: this(newInstance(groupPubKey, groupAdminKey, initialDump))
override fun namespace() = Namespace.CLOSED_GROUP_MEMBERS()
external fun all(): Stack<GroupMember>
external fun erase(groupMember: GroupMember): Boolean
external fun erase(pubKeyHex: String): Boolean
external fun get(pubKeyHex: String): GroupMember?
external fun getOrConstruct(pubKeyHex: String): GroupMember
external fun set(groupMember: GroupMember)
override fun close() {
free()
}
external override fun all(): Stack<GroupMember>
external override fun erase(groupMember: GroupMember): Boolean
external override fun erase(pubKeyHex: String): Boolean
external override fun get(pubKeyHex: String): GroupMember?
external override fun getOrConstruct(pubKeyHex: String): GroupMember
external override fun set(groupMember: GroupMember)
}
sealed class ConfigSig(pointer: Long) : Config(pointer)
class GroupKeysConfig(pointer: Long): ConfigSig(pointer) {
interface ReadableGroupKeysConfig {
fun groupKeys(): Stack<ByteArray>
fun needsDump(): Boolean
fun dump(): ByteArray
fun needsRekey(): Boolean
fun pendingKey(): ByteArray?
fun supplementFor(userSessionId: String): ByteArray
fun pendingConfig(): ByteArray?
fun currentHashes(): List<String>
fun encrypt(plaintext: ByteArray): ByteArray
fun decrypt(ciphertext: ByteArray): Pair<ByteArray, AccountId>?
fun keys(): Stack<ByteArray>
fun subAccountSign(message: ByteArray, signingValue: ByteArray): GroupKeysConfig.SwarmAuth
fun getSubAccountToken(sessionId: AccountId, canWrite: Boolean = true, canDelete: Boolean = false): ByteArray
fun currentGeneration(): Int
}
interface MutableGroupKeysConfig : ReadableGroupKeysConfig {
fun makeSubAccount(sessionId: AccountId, canWrite: Boolean = true, canDelete: Boolean = false): ByteArray
}
class GroupKeysConfig private constructor(pointer: Long): ConfigSig(pointer), MutableGroupKeysConfig {
companion object {
init {
System.loadLibrary("session_util")
}
external fun newInstance(
private external fun newInstance(
userSecretKey: ByteArray,
groupPublicKey: ByteArray,
groupSecretKey: ByteArray? = null,
initialDump: ByteArray = byteArrayOf(),
info: GroupInfoConfig,
members: GroupMembersConfig
): GroupKeysConfig
initialDump: ByteArray?,
infoPtr: Long,
members: Long
): Long
}
constructor(
userSecretKey: ByteArray,
groupPublicKey: ByteArray,
groupAdminKey: ByteArray?,
initialDump: ByteArray?,
info: GroupInfoConfig,
members: GroupMembersConfig
) : this(
newInstance(
userSecretKey,
groupPublicKey,
groupAdminKey,
initialDump,
info.pointer,
members.pointer
)
)
override fun namespace() = Namespace.ENCRYPTION_KEYS()
external fun groupKeys(): Stack<ByteArray>
external fun needsDump(): Boolean
external fun dump(): ByteArray
external override fun groupKeys(): Stack<ByteArray>
external override fun needsDump(): Boolean
external override fun dump(): ByteArray
external fun loadKey(message: ByteArray,
hash: String,
timestampMs: Long,
info: GroupInfoConfig,
members: GroupMembersConfig): Boolean
external fun needsRekey(): Boolean
external fun pendingKey(): ByteArray?
external fun supplementFor(userSessionId: String): ByteArray
external fun pendingConfig(): ByteArray?
external fun currentHashes(): List<String>
external fun rekey(info: GroupInfoConfig, members: GroupMembersConfig): ByteArray
override fun close() {
free()
}
infoPtr: Long,
membersPtr: Long): Boolean
external override fun needsRekey(): Boolean
external override fun pendingKey(): ByteArray?
external override fun supplementFor(userSessionId: String): ByteArray
external override fun pendingConfig(): ByteArray?
external override fun currentHashes(): List<String>
external fun rekey(infoPtr: Long, membersPtr: Long): ByteArray
external fun encrypt(plaintext: ByteArray): ByteArray
external fun decrypt(ciphertext: ByteArray): Pair<ByteArray, AccountId>?
external override fun encrypt(plaintext: ByteArray): ByteArray
external override fun decrypt(ciphertext: ByteArray): Pair<ByteArray, AccountId>?
external fun keys(): Stack<ByteArray>
external override fun keys(): Stack<ByteArray>
external fun makeSubAccount(sessionId: AccountId, canWrite: Boolean = true, canDelete: Boolean = false): ByteArray
external fun getSubAccountToken(sessionId: AccountId, canWrite: Boolean = true, canDelete: Boolean = false): ByteArray
external override fun makeSubAccount(sessionId: AccountId, canWrite: Boolean, canDelete: Boolean): ByteArray
external override fun getSubAccountToken(sessionId: AccountId, canWrite: Boolean, canDelete: Boolean): ByteArray
external fun subAccountSign(message: ByteArray, signingValue: ByteArray): SwarmAuth
external override fun subAccountSign(message: ByteArray, signingValue: ByteArray): SwarmAuth
external fun currentGeneration(): Int
external override fun currentGeneration(): Int
data class SwarmAuth(
val subAccount: String,
val subAccountSig: String,
val signature: String
)
}
}
private external fun createConfigObject(
configName: String,
ed25519SecretKey: ByteArray,
initialDump: ByteArray?
): Long