Skip to content

Commit f432973

Browse files
SessionHero01SessionHero01
authored andcommitted
Renamed
1 parent 9818bf7 commit f432973

File tree

7 files changed

+84
-51
lines changed

7 files changed

+84
-51
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
plugins {
33
alias(libs.plugins.android.library) apply false
44
alias(libs.plugins.kotlin.android) apply false
5+
alias(libs.plugins.kotlinx.serialization) apply false
56
}

gradle/libs.versions.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
agp = "8.13.0"
2+
agp = "8.13.1"
33
kotlin = "2.2.20"
44

55
[libraries]
@@ -8,8 +8,9 @@ androidx-test-runner = { module = "androidx.test:runner", version = "1.7.0" }
88
androidx-test-rules = { module = "androidx.test:rules", version = "1.7.0" }
99
androidx-test-ext = { module = "androidx.test.ext:junit", version = "1.3.0" }
1010
androidx-annotations = { module = "androidx.annotation:annotation", version = "1.9.1" }
11+
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version = "1.9.0" }
1112

1213
[plugins]
1314
android-library = { id = "com.android.library", version.ref = "agp" }
1415
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
15-
16+
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }

library/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
33
plugins {
44
alias(libs.plugins.android.library)
55
alias(libs.plugins.kotlin.android)
6+
alias(libs.plugins.kotlinx.serialization)
67
id("maven-publish")
78
}
89

@@ -119,4 +120,5 @@ dependencies {
119120
androidTestImplementation(libs.androidx.test.ext)
120121

121122
implementation(libs.androidx.annotations)
123+
implementation(libs.kotlinx.serialization.core)
122124
}

library/src/main/cpp/pro_backend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Java_network_loki_messenger_libsession_1util_pro_BackendRequests_buildAddProPaym
2727

2828
extern "C"
2929
JNIEXPORT jstring JNICALL
30-
Java_network_loki_messenger_libsession_1util_pro_BackendRequests_buildGetProProofRequestJson(
30+
Java_network_loki_messenger_libsession_1util_pro_BackendRequests_buildGenerateProProofRequestJson(
3131
JNIEnv *env, jobject thiz, jint version, jbyteArray master_private_key,
3232
jbyteArray rotating_private_key, jlong now_ms) {
3333
return run_catching_cxx_exception_or_throws<jstring>(env, [=]() {
@@ -46,7 +46,7 @@ Java_network_loki_messenger_libsession_1util_pro_BackendRequests_buildGetProProo
4646

4747
extern "C"
4848
JNIEXPORT jstring JNICALL
49-
Java_network_loki_messenger_libsession_1util_pro_BackendRequests_buildGetProStatusRequestJson(
49+
Java_network_loki_messenger_libsession_1util_pro_BackendRequests_buildGetProDetailsRequestJson(
5050
JNIEnv *env, jobject thiz, jint version, jbyteArray pro_master_private_key, jlong now_ms,
5151
jint count) {
5252
return run_catching_cxx_exception_or_throws<jstring>(env, [=]() {

library/src/main/cpp/pro_proof.cpp

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,18 @@ using namespace jni_utils;
1010

1111
extern "C"
1212
JNIEXPORT jint JNICALL
13-
Java_network_loki_messenger_libsession_1util_pro_ProProof_status(JNIEnv *env, jobject thiz,
14-
jbyteArray verify_pub_key,
15-
jlong now_unix_ts,
16-
jbyteArray signed_message_data,
17-
jbyteArray signed_message_signature) {
13+
Java_network_loki_messenger_libsession_1util_pro_ProProof_00024Companion_nativeStatus(JNIEnv *env,
14+
jobject thiz,
15+
jint version,
16+
jbyteArray gen_index_hash,
17+
jbyteArray rotating_pub_key,
18+
jlong expiry_ms,
19+
jbyteArray signature,
20+
jlong now_unix_ts,
21+
jbyteArray verify_pub_key,
22+
jbyteArray signed_message_data,
23+
jbyteArray signed_message_signature) {
1824
return run_catching_cxx_exception_or_throws<jint>(env, [=]() {
19-
JavaLocalRef<jclass> clazz(env, env->GetObjectClass(thiz));
20-
auto get_version_method = env->GetMethodID(clazz.get(), "getVersion", "()I");
21-
auto get_gen_index_hash_method = env->GetMethodID(clazz.get(), "getGenIndexHash", "()[B");
22-
auto get_rotating_pub_key_method = env->GetMethodID(clazz.get(), "getRotatingPubKey",
23-
"()[B");
24-
auto get_expiry_method = env->GetMethodID(clazz.get(), "getExpiryMs", "()J");
25-
auto get_signature_method = env->GetMethodID(clazz.get(), "getSignature", "()[B");
26-
27-
auto version = env->CallIntMethod(thiz, get_version_method);
28-
JavaLocalRef<jbyteArray> gen_index_hash_bytes_obj(env,
29-
static_cast<jbyteArray>(env->CallObjectMethod(
30-
thiz,
31-
get_gen_index_hash_method)));
32-
JavaLocalRef<jbyteArray> rotating_pub_key_bytes_obj(env,
33-
static_cast<jbyteArray>(env->CallObjectMethod(
34-
thiz,
35-
get_rotating_pub_key_method)));
36-
auto expiry_ms = env->CallLongMethod(thiz, get_expiry_method);
37-
JavaLocalRef<jbyteArray> signature_bytes_obj(env,
38-
static_cast<jbyteArray>(env->CallObjectMethod(
39-
thiz, get_signature_method)));
40-
4125
std::optional<session::ProSignedMessage> signed_msg;
4226
JavaByteArrayRef signed_message_data_ref(env, signed_message_data);
4327
JavaByteArrayRef signed_message_signature_ref(env, signed_message_signature);
@@ -51,11 +35,11 @@ Java_network_loki_messenger_libsession_1util_pro_ProProof_status(JNIEnv *env, jo
5135

5236
session::ProProof pro_proof {
5337
.version = static_cast<std::uint8_t>(version),
54-
.gen_index_hash = *java_to_cpp_array<32>(env, gen_index_hash_bytes_obj.get()),
55-
.rotating_pubkey = *java_to_cpp_array<32>(env, rotating_pub_key_bytes_obj.get()),
38+
.gen_index_hash = *java_to_cpp_array<32>(env, gen_index_hash),
39+
.rotating_pubkey = *java_to_cpp_array<32>(env, rotating_pub_key),
5640
.expiry_unix_ts = std::chrono::sys_time<std::chrono::milliseconds>(
5741
std::chrono::milliseconds(expiry_ms)),
58-
.sig = *java_to_cpp_array<64>(env, signature_bytes_obj.get()),
42+
.sig = *java_to_cpp_array<64>(env, signature),
5943
};
6044

6145
return static_cast<jint>(pro_proof.status(

library/src/main/java/network/loki/messenger/libsession_util/pro/BackendRequests.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ object BackendRequests : LibSessionUtilCApi() {
1717
orderId: String,
1818
): String
1919

20-
external fun buildGetProProofRequestJson(
20+
external fun buildGenerateProProofRequestJson(
2121
version: Int,
2222
masterPrivateKey: ByteArray,
2323
rotatingPrivateKey: ByteArray,
2424
nowMs: Long,
2525
): String
2626

27-
external fun buildGetProStatusRequestJson(
27+
external fun buildGetProDetailsRequestJson(
2828
version: Int,
2929
proMasterPrivateKey: ByteArray,
3030
nowMs: Long,

library/src/main/java/network/loki/messenger/libsession_util/pro/ProProof.kt

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,52 @@
11
package network.loki.messenger.libsession_util.pro
22

3+
import androidx.annotation.Keep
4+
import kotlinx.serialization.SerialName
5+
import kotlinx.serialization.Serializable
36
import java.time.Instant
47

5-
class ProProof(
8+
/**
9+
* Represents a proof of Pro. This class is marked as @Serializable to represent the JSON structure
10+
* received from the Pro Backend.
11+
*/
12+
@Serializable
13+
data class ProProof(
614
val version: Int,
7-
val genIndexHash: ByteArray,
8-
val rotatingPubKey: ByteArray,
15+
16+
@SerialName("gen_index_hash")
17+
val genIndexHashHex: String,
18+
19+
@SerialName("rotating_pkey")
20+
val rotatingPubKeyHex: String,
21+
22+
@SerialName("expiry_unix_ts_ms")
923
val expiryMs: Long,
10-
val signature: ByteArray
24+
25+
@SerialName("sig")
26+
val signatureHex: String
1127
) {
28+
@Keep
29+
constructor(
30+
version: Int,
31+
genIndexHash: ByteArray,
32+
rotatingPubKey: ByteArray,
33+
expiryMs: Long,
34+
signature: ByteArray
35+
): this(
36+
version = version,
37+
genIndexHashHex = genIndexHash.toHexString(),
38+
rotatingPubKeyHex = rotatingPubKey.toHexString(),
39+
expiryMs = expiryMs,
40+
signatureHex = signature.toHexString()
41+
)
42+
43+
1244
init {
13-
check(rotatingPubKey.size == 32) {
45+
check(rotatingPubKeyHex.length == 64) {
1446
"Rotating public key must be 32 bytes"
1547
}
1648

17-
check(signature.size == 64) {
49+
check(signatureHex.length == 128) {
1850
"Signature must be 64 bytes"
1951
}
2052
}
@@ -37,13 +69,6 @@ class ProProof(
3769
}
3870
}
3971

40-
private external fun status(
41-
verifyPubKey: ByteArray,
42-
nowUnixTs: Long,
43-
signedMessageData: ByteArray?,
44-
signedMessageSignature: ByteArray?
45-
): Int
46-
4772
class ProSignedMessage(
4873
val data: ByteArray,
4974
val signature: ByteArray,
@@ -56,12 +81,32 @@ class ProProof(
5681
): Status {
5782
val signedMessageData = signedMessage?.data
5883
val signedMessageSignature = signedMessage?.signature
59-
val statusValue = status(
84+
val statusValue = nativeStatus(
85+
version = version,
86+
genIndexHash = genIndexHashHex.hexToByteArray(),
87+
rotatingPubKey = rotatingPubKeyHex.hexToByteArray(),
88+
expiryMs = expiryMs,
89+
signature = signatureHex.hexToByteArray(),
90+
nowUnixTs = now.toEpochMilli(),
6091
verifyPubKey = verifyPubKey,
61-
nowUnixTs = now.epochSecond,
6292
signedMessageData = signedMessageData,
6393
signedMessageSignature = signedMessageSignature
6494
)
95+
6596
return Status.fromNativeValue(statusValue)
6697
}
98+
99+
companion object {
100+
private external fun nativeStatus(
101+
version: Int,
102+
genIndexHash: ByteArray,
103+
rotatingPubKey: ByteArray,
104+
expiryMs: Long,
105+
signature: ByteArray,
106+
nowUnixTs: Long,
107+
verifyPubKey: ByteArray,
108+
signedMessageData: ByteArray?,
109+
signedMessageSignature: ByteArray?
110+
): Int
111+
}
67112
}

0 commit comments

Comments
 (0)