@@ -35,10 +35,8 @@ import java.util.concurrent.ConcurrentHashMap
35
35
open class RustBuffer : Structure () {
36
36
@JvmField
37
37
var capacity: Int = 0
38
-
39
38
@JvmField
40
39
var len: Int = 0
41
-
42
40
@JvmField
43
41
var data: Pointer ? = null
44
42
@@ -407,6 +405,14 @@ internal interface _UniFFILib : Library {
407
405
`privateKeyBytes`: RustBuffer .ByValue , _uniffi_out_err : RustCallStatus ,
408
406
): RustBuffer .ByValue
409
407
408
+ fun uniffi_xmtp_dh_fn_func_verify_k256_sha256 (
409
+ `signedBy`: RustBuffer .ByValue ,
410
+ `message`: RustBuffer .ByValue ,
411
+ `signature`: RustBuffer .ByValue ,
412
+ `recoveryId`: Byte ,
413
+ _uniffi_out_err : RustCallStatus ,
414
+ ): Byte
415
+
410
416
fun ffi_xmtp_dh_rustbuffer_alloc (
411
417
`size`: Int , _uniffi_out_err : RustCallStatus ,
412
418
): RustBuffer .ByValue
@@ -435,6 +441,9 @@ internal interface _UniFFILib : Library {
435
441
fun uniffi_xmtp_dh_checksum_func_generate_private_preferences_topic_identifier (
436
442
): Short
437
443
444
+ fun uniffi_xmtp_dh_checksum_func_verify_k256_sha256 (
445
+ ): Short
446
+
438
447
fun ffi_xmtp_dh_uniffi_contract_version (
439
448
): Int
440
449
@@ -464,6 +473,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
464
473
if (lib.uniffi_xmtp_dh_checksum_func_generate_private_preferences_topic_identifier() != 65141 .toShort()) {
465
474
throw RuntimeException (" UniFFI API checksum mismatch: try cleaning and rebuilding your project" )
466
475
}
476
+ if (lib.uniffi_xmtp_dh_checksum_func_verify_k256_sha256() != 45969 .toShort()) {
477
+ throw RuntimeException (" UniFFI API checksum mismatch: try cleaning and rebuilding your project" )
478
+ }
467
479
}
468
480
469
481
// Public interface members begin here.
@@ -489,6 +501,26 @@ public object FfiConverterUByte : FfiConverter<UByte, Byte> {
489
501
}
490
502
}
491
503
504
+ public object FfiConverterBoolean : FfiConverter<Boolean, Byte> {
505
+ override fun lift (value : Byte ): Boolean {
506
+ return value.toInt() != 0
507
+ }
508
+
509
+ override fun read (buf : ByteBuffer ): Boolean {
510
+ return lift(buf.get())
511
+ }
512
+
513
+ override fun lower (value : Boolean ): Byte {
514
+ return if (value) 1 .toByte() else 0 .toByte()
515
+ }
516
+
517
+ override fun allocationSize (value : Boolean ) = 1
518
+
519
+ override fun write (value : Boolean , buf : ByteBuffer ) {
520
+ buf.put(lower(value))
521
+ }
522
+ }
523
+
492
524
public object FfiConverterString : FfiConverter<String, RustBuffer.ByValue> {
493
525
// Note: we don't inherit from FfiConverterRustBuffer, because we use a
494
526
// special encoding when lowering/lifting. We can use `RustBuffer.len` to
@@ -612,6 +644,44 @@ public object FfiConverterTypeEciesError : FfiConverterRustBuffer<EciesException
612
644
}
613
645
614
646
647
+ sealed class VerifyException (message : String ) : Exception(message) {
648
+ // Each variant is a nested class
649
+ // Flat enums carries a string error message, so no special implementation is necessary.
650
+ class GenericException (message : String ) : VerifyException(message)
651
+
652
+
653
+ companion object ErrorHandler : CallStatusErrorHandler<VerifyException> {
654
+ override fun lift (error_buf : RustBuffer .ByValue ): VerifyException =
655
+ FfiConverterTypeVerifyError .lift(error_buf)
656
+ }
657
+ }
658
+
659
+ public object FfiConverterTypeVerifyError : FfiConverterRustBuffer<VerifyException> {
660
+ override fun read (buf : ByteBuffer ): VerifyException {
661
+
662
+ return when (buf.getInt()) {
663
+ 1 -> VerifyException .GenericException (FfiConverterString .read(buf))
664
+ else -> throw RuntimeException (" invalid error enum value, something is very wrong!!" )
665
+ }
666
+
667
+ }
668
+
669
+ override fun allocationSize (value : VerifyException ): Int {
670
+ return 4
671
+ }
672
+
673
+ override fun write (value : VerifyException , buf : ByteBuffer ) {
674
+ when (value) {
675
+ is VerifyException .GenericException -> {
676
+ buf.putInt(1 )
677
+ Unit
678
+ }
679
+ }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
680
+ }
681
+
682
+ }
683
+
684
+
615
685
public object FfiConverterSequenceUByte : FfiConverterRustBuffer<List<UByte>> {
616
686
override fun read (buf : ByteBuffer ): List <UByte > {
617
687
val len = buf.getInt()
@@ -698,4 +768,26 @@ fun `generatePrivatePreferencesTopicIdentifier`(`privateKeyBytes`: List<UByte>):
698
768
})
699
769
}
700
770
771
+ @Throws(VerifyException ::class )
772
+
773
+ fun `verifyK256Sha256` (
774
+ `signedBy`: List <UByte >,
775
+ `message`: List <UByte >,
776
+ `signature`: List <UByte >,
777
+ `recoveryId`: UByte ,
778
+ ): Boolean {
779
+ return FfiConverterBoolean .lift(
780
+ rustCallWithError(VerifyException ) { _status ->
781
+ _UniFFILib .INSTANCE .uniffi_xmtp_dh_fn_func_verify_k256_sha256(
782
+ FfiConverterSequenceUByte .lower(
783
+ `signedBy`
784
+ ),
785
+ FfiConverterSequenceUByte .lower(`message`),
786
+ FfiConverterSequenceUByte .lower(`signature`),
787
+ FfiConverterUByte .lower(`recoveryId`),
788
+ _status
789
+ )
790
+ })
791
+ }
792
+
701
793
0 commit comments