Skip to content

Commit 14d9c60

Browse files
authored
Update User Preferences (#145)
* dump in the new rust stuff * rename pppp and transition to new rust
1 parent 09a4da1 commit 14d9c60

File tree

7 files changed

+33
-33
lines changed

7 files changed

+33
-33
lines changed

library/src/main/java/org/xmtp/android/library/Contacts.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ConsentList(val client: Client) {
6060
val preferences: MutableList<PrivatePreferencesAction> = mutableListOf()
6161

6262
for (envelope in envelopes.envelopesList) {
63-
val payload = uniffi.xmtp_dh.eciesDecryptK256Sha3256(
63+
val payload = uniffi.xmtp_dh.userPreferencesDecrypt(
6464
publicKey.toByteArray().toUByteArray().toList(),
6565
privateKey.toByteArray().toUByteArray().toList(),
6666
envelope.message.toByteArray().toUByteArray().toList()
@@ -101,7 +101,7 @@ class ConsentList(val client: Client) {
101101
}
102102
}.build()
103103

104-
val message = uniffi.xmtp_dh.eciesEncryptK256Sha3256(
104+
val message = uniffi.xmtp_dh.userPreferencesEncrypt(
105105
publicKey.toByteArray().toUByteArray().toList(),
106106
privateKey.toByteArray().toUByteArray().toList(),
107107
payload.toByteArray().toUByteArray().toList()

library/src/main/java/org/xmtp/android/library/messages/Topic.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ sealed class Topic {
2323
}
2424

2525
is directMessageV2 -> wrap("m-$addresses")
26-
is preferenceList -> wrap("pppp-$identifier")
26+
is preferenceList -> wrap("userpreferences-$identifier")
2727
}
2828
}
2929

library/src/main/java/xmtp_dh.kt

+30-30
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.sun.jna.IntegerType
2222
import com.sun.jna.Native
2323
import com.sun.jna.Pointer
2424
import com.sun.jna.Structure
25+
import com.sun.jna.Callback
2526
import com.sun.jna.ptr.*
2627
import java.nio.ByteBuffer
2728
import java.nio.ByteOrder
@@ -106,7 +107,6 @@ class RustBufferByReference : ByReference(16) {
106107
open class ForeignBytes : Structure() {
107108
@JvmField
108109
var len: Int = 0
109-
110110
@JvmField
111111
var data: Pointer? = null
112112

@@ -192,7 +192,6 @@ public interface FfiConverterRustBuffer<KotlinType> : FfiConverter<KotlinType, R
192192
internal open class RustCallStatus : Structure() {
193193
@JvmField
194194
var code: Byte = 0
195-
196195
@JvmField
197196
var error_buf: RustBuffer.ByValue = RustBuffer.ByValue()
198197

@@ -387,14 +386,14 @@ internal interface _UniFFILib : Library {
387386
_uniffi_out_err: RustCallStatus,
388387
): RustBuffer.ByValue
389388

390-
fun uniffi_xmtp_dh_fn_func_ecies_encrypt_k256_sha3_256(
389+
fun uniffi_xmtp_dh_fn_func_user_preferences_encrypt(
391390
`publicKeyBytes`: RustBuffer.ByValue,
392391
`privateKeyBytes`: RustBuffer.ByValue,
393392
`messageBytes`: RustBuffer.ByValue,
394393
_uniffi_out_err: RustCallStatus,
395394
): RustBuffer.ByValue
396395

397-
fun uniffi_xmtp_dh_fn_func_ecies_decrypt_k256_sha3_256(
396+
fun uniffi_xmtp_dh_fn_func_user_preferences_decrypt(
398397
`publicKeyBytes`: RustBuffer.ByValue,
399398
`privateKeyBytes`: RustBuffer.ByValue,
400399
`messageBytes`: RustBuffer.ByValue,
@@ -432,10 +431,10 @@ internal interface _UniFFILib : Library {
432431
fun uniffi_xmtp_dh_checksum_func_diffie_hellman_k256(
433432
): Short
434433

435-
fun uniffi_xmtp_dh_checksum_func_ecies_encrypt_k256_sha3_256(
434+
fun uniffi_xmtp_dh_checksum_func_user_preferences_encrypt(
436435
): Short
437436

438-
fun uniffi_xmtp_dh_checksum_func_ecies_decrypt_k256_sha3_256(
437+
fun uniffi_xmtp_dh_checksum_func_user_preferences_decrypt(
439438
): Short
440439

441440
fun uniffi_xmtp_dh_checksum_func_generate_private_preferences_topic_identifier(
@@ -464,13 +463,13 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
464463
if (lib.uniffi_xmtp_dh_checksum_func_diffie_hellman_k256() != 64890.toShort()) {
465464
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
466465
}
467-
if (lib.uniffi_xmtp_dh_checksum_func_ecies_encrypt_k256_sha3_256() != 28010.toShort()) {
466+
if (lib.uniffi_xmtp_dh_checksum_func_user_preferences_encrypt() != 59502.toShort()) {
468467
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
469468
}
470-
if (lib.uniffi_xmtp_dh_checksum_func_ecies_decrypt_k256_sha3_256() != 45037.toShort()) {
469+
if (lib.uniffi_xmtp_dh_checksum_func_user_preferences_decrypt() != 60388.toShort()) {
471470
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
472471
}
473-
if (lib.uniffi_xmtp_dh_checksum_func_generate_private_preferences_topic_identifier() != 65141.toShort()) {
472+
if (lib.uniffi_xmtp_dh_checksum_func_generate_private_preferences_topic_identifier() != 48427.toShort()) {
474473
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
475474
}
476475
if (lib.uniffi_xmtp_dh_checksum_func_verify_k256_sha256() != 45969.toShort()) {
@@ -606,35 +605,36 @@ public object FfiConverterTypeDiffieHellmanError : FfiConverterRustBuffer<Diffie
606605
}
607606

608607

609-
sealed class EciesException(message: String) : Exception(message) {
608+
sealed class UserPreferencesException(message: String) : Exception(message) {
610609
// Each variant is a nested class
611610
// Flat enums carries a string error message, so no special implementation is necessary.
612-
class GenericException(message: String) : EciesException(message)
611+
class GenericException(message: String) : UserPreferencesException(message)
613612

614613

615-
companion object ErrorHandler : CallStatusErrorHandler<EciesException> {
616-
override fun lift(error_buf: RustBuffer.ByValue): EciesException =
617-
FfiConverterTypeEciesError.lift(error_buf)
614+
companion object ErrorHandler : CallStatusErrorHandler<UserPreferencesException> {
615+
override fun lift(error_buf: RustBuffer.ByValue): UserPreferencesException =
616+
FfiConverterTypeUserPreferencesError.lift(error_buf)
618617
}
619618
}
620619

621-
public object FfiConverterTypeEciesError : FfiConverterRustBuffer<EciesException> {
622-
override fun read(buf: ByteBuffer): EciesException {
620+
public object FfiConverterTypeUserPreferencesError :
621+
FfiConverterRustBuffer<UserPreferencesException> {
622+
override fun read(buf: ByteBuffer): UserPreferencesException {
623623

624624
return when (buf.getInt()) {
625-
1 -> EciesException.GenericException(FfiConverterString.read(buf))
625+
1 -> UserPreferencesException.GenericException(FfiConverterString.read(buf))
626626
else -> throw RuntimeException("invalid error enum value, something is very wrong!!")
627627
}
628628

629629
}
630630

631-
override fun allocationSize(value: EciesException): Int {
631+
override fun allocationSize(value: UserPreferencesException): Int {
632632
return 4
633633
}
634634

635-
override fun write(value: EciesException, buf: ByteBuffer) {
635+
override fun write(value: UserPreferencesException, buf: ByteBuffer) {
636636
when (value) {
637-
is EciesException.GenericException -> {
637+
is UserPreferencesException.GenericException -> {
638638
buf.putInt(1)
639639
Unit
640640
}
@@ -720,16 +720,16 @@ fun `diffieHellmanK256`(
720720
})
721721
}
722722

723-
@Throws(EciesException::class)
723+
@Throws(UserPreferencesException::class)
724724

725-
fun `eciesEncryptK256Sha3256`(
725+
fun `userPreferencesEncrypt`(
726726
`publicKeyBytes`: List<UByte>,
727727
`privateKeyBytes`: List<UByte>,
728728
`messageBytes`: List<UByte>,
729729
): List<UByte> {
730730
return FfiConverterSequenceUByte.lift(
731-
rustCallWithError(EciesException) { _status ->
732-
_UniFFILib.INSTANCE.uniffi_xmtp_dh_fn_func_ecies_encrypt_k256_sha3_256(
731+
rustCallWithError(UserPreferencesException) { _status ->
732+
_UniFFILib.INSTANCE.uniffi_xmtp_dh_fn_func_user_preferences_encrypt(
733733
FfiConverterSequenceUByte.lower(`publicKeyBytes`),
734734
FfiConverterSequenceUByte.lower(`privateKeyBytes`),
735735
FfiConverterSequenceUByte.lower(`messageBytes`),
@@ -738,16 +738,16 @@ fun `eciesEncryptK256Sha3256`(
738738
})
739739
}
740740

741-
@Throws(EciesException::class)
741+
@Throws(UserPreferencesException::class)
742742

743-
fun `eciesDecryptK256Sha3256`(
743+
fun `userPreferencesDecrypt`(
744744
`publicKeyBytes`: List<UByte>,
745745
`privateKeyBytes`: List<UByte>,
746746
`messageBytes`: List<UByte>,
747747
): List<UByte> {
748748
return FfiConverterSequenceUByte.lift(
749-
rustCallWithError(EciesException) { _status ->
750-
_UniFFILib.INSTANCE.uniffi_xmtp_dh_fn_func_ecies_decrypt_k256_sha3_256(
749+
rustCallWithError(UserPreferencesException) { _status ->
750+
_UniFFILib.INSTANCE.uniffi_xmtp_dh_fn_func_user_preferences_decrypt(
751751
FfiConverterSequenceUByte.lower(`publicKeyBytes`),
752752
FfiConverterSequenceUByte.lower(`privateKeyBytes`),
753753
FfiConverterSequenceUByte.lower(`messageBytes`),
@@ -756,11 +756,11 @@ fun `eciesDecryptK256Sha3256`(
756756
})
757757
}
758758

759-
@Throws(EciesException::class)
759+
@Throws(UserPreferencesException::class)
760760

761761
fun `generatePrivatePreferencesTopicIdentifier`(`privateKeyBytes`: List<UByte>): String {
762762
return FfiConverterString.lift(
763-
rustCallWithError(EciesException) { _status ->
763+
rustCallWithError(UserPreferencesException) { _status ->
764764
_UniFFILib.INSTANCE.uniffi_xmtp_dh_fn_func_generate_private_preferences_topic_identifier(
765765
FfiConverterSequenceUByte.lower(`privateKeyBytes`),
766766
_status
Binary file not shown.
Binary file not shown.
-1.13 MB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)