diff --git a/Cargo.lock b/Cargo.lock index 1b8fa3d..7353350 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2013,7 +2013,7 @@ dependencies = [ [[package]] name = "vss-rust-client-ffi" -version = "0.5.21" +version = "0.5.23" dependencies = [ "bip39", "bitcoin", diff --git a/Cargo.toml b/Cargo.toml index 3b0bdfb..b2aad89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "vss-rust-client-ffi" -version = "0.5.21" +version = "0.5.23" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/Package.swift b/Package.swift index a6c6f4d..9ac8b7e 100644 --- a/Package.swift +++ b/Package.swift @@ -3,8 +3,8 @@ import PackageDescription -let tag = "v0.5.21" -let checksum = "c1d89da95372e29023775787e6cd843f71ceb5a41b0f85cf1cb2e1fb2265b344" +let tag = "v0.5.23" +let checksum = "655f78dfce27e58ae37ab448e03d36186182cc9066d7bcf0341a5e6787330b7a" let url = "https://github.com/synonymdev/vss-rust-client-ffi/releases/download/\(tag)/VssRustClientFfi.xcframework.zip" let package = Package( diff --git a/README.md b/README.md index 3362248..8e5fd5d 100644 --- a/README.md +++ b/README.md @@ -284,7 +284,8 @@ vssShutdownLdkClient() ### Client Management #### `vssNewClient(baseUrl: String, storeId: String) -> Void` -Initialize the global VSS client connection without authentication. +This constructor is rejected and always returns `AuthError`. Unauthenticated VSS does not +have a seed-derived encryption key. Use `vssNewClientWithLnurlAuth` instead. - `baseUrl`: VSS server URL (e.g., "https://vss.example.com") - `storeId`: Unique identifier for your storage namespace diff --git a/bindings/android/gradle.properties b/bindings/android/gradle.properties index 78e0256..e89a8f6 100644 --- a/bindings/android/gradle.properties +++ b/bindings/android/gradle.properties @@ -3,4 +3,4 @@ android.useAndroidX=true android.nonTransitiveRClass=true kotlin.code.style=official # project settings: -version=0.5.21 +version=0.5.23 diff --git a/bindings/android/src/main/jniLibs/arm64-v8a/libvss_rust_client_ffi.so b/bindings/android/src/main/jniLibs/arm64-v8a/libvss_rust_client_ffi.so index 0dcabb6..ab62aa0 100755 Binary files a/bindings/android/src/main/jniLibs/arm64-v8a/libvss_rust_client_ffi.so and b/bindings/android/src/main/jniLibs/arm64-v8a/libvss_rust_client_ffi.so differ diff --git a/bindings/android/src/main/jniLibs/armeabi-v7a/libvss_rust_client_ffi.so b/bindings/android/src/main/jniLibs/armeabi-v7a/libvss_rust_client_ffi.so index 4508b51..ed74735 100755 Binary files a/bindings/android/src/main/jniLibs/armeabi-v7a/libvss_rust_client_ffi.so and b/bindings/android/src/main/jniLibs/armeabi-v7a/libvss_rust_client_ffi.so differ diff --git a/bindings/android/src/main/jniLibs/x86/libvss_rust_client_ffi.so b/bindings/android/src/main/jniLibs/x86/libvss_rust_client_ffi.so index e6cead0..cf447e4 100755 Binary files a/bindings/android/src/main/jniLibs/x86/libvss_rust_client_ffi.so and b/bindings/android/src/main/jniLibs/x86/libvss_rust_client_ffi.so differ diff --git a/bindings/android/src/main/jniLibs/x86_64/libvss_rust_client_ffi.so b/bindings/android/src/main/jniLibs/x86_64/libvss_rust_client_ffi.so index de46797..874cd8b 100755 Binary files a/bindings/android/src/main/jniLibs/x86_64/libvss_rust_client_ffi.so and b/bindings/android/src/main/jniLibs/x86_64/libvss_rust_client_ffi.so differ diff --git a/bindings/android/src/main/kotlin/com/synonym/vssclient/vss_rust_client_ffi.kt b/bindings/android/src/main/kotlin/com/synonym/vssclient/vss_rust_client_ffi.kt index ad51481..b3d456a 100644 --- a/bindings/android/src/main/kotlin/com/synonym/vssclient/vss_rust_client_ffi.kt +++ b/bindings/android/src/main/kotlin/com/synonym/vssclient/vss_rust_client_ffi.kt @@ -17,26 +17,26 @@ package com.synonym.vssclient // compile the Rust component. The easiest way to ensure this is to bundle the Kotlin // helpers directly inline like we're doing here. -import com.sun.jna.Callback -import com.sun.jna.IntegerType import com.sun.jna.Library +import com.sun.jna.IntegerType import com.sun.jna.Native import com.sun.jna.Pointer import com.sun.jna.Structure +import com.sun.jna.Callback import com.sun.jna.ptr.* -import kotlinx.coroutines.CancellableContinuation -import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.Job -import kotlinx.coroutines.launch -import kotlinx.coroutines.suspendCancellableCoroutine import java.nio.ByteBuffer import java.nio.ByteOrder import java.nio.CharBuffer import java.nio.charset.CodingErrorAction -import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.atomic.AtomicLong +import java.util.concurrent.ConcurrentHashMap import kotlin.coroutines.resume +import kotlinx.coroutines.CancellableContinuation +import kotlinx.coroutines.DelicateCoroutinesApi +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.Job +import kotlinx.coroutines.launch +import kotlinx.coroutines.suspendCancellableCoroutine // This is a helper for safely working with byte buffers returned from the Rust code. // A rust-owned buffer is represented by its capacity, its current length, and a @@ -50,41 +50,29 @@ open class RustBuffer : Structure() { // Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values. // When dealing with these fields, make sure to call `toULong()`. @JvmField var capacity: Long = 0 - @JvmField var len: Long = 0 - @JvmField var data: Pointer? = null - class ByValue : - RustBuffer(), - Structure.ByValue + class ByValue: RustBuffer(), Structure.ByValue + class ByReference: RustBuffer(), Structure.ByReference - class ByReference : - RustBuffer(), - Structure.ByReference - - internal fun setValue(other: RustBuffer) { + internal fun setValue(other: RustBuffer) { capacity = other.capacity len = other.len data = other.data } companion object { - internal fun alloc(size: ULong = 0UL) = - uniffiRustCall { status -> - // Note: need to convert the size to a `Long` value to make this work with JVM. - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rustbuffer_alloc(size.toLong(), status) - }.also { - if (it.data == null) { - throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=$size)") - } - } + internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status -> + // Note: need to convert the size to a `Long` value to make this work with JVM. + UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rustbuffer_alloc(size.toLong(), status) + }.also { + if(it.data == null) { + throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})") + } + } - internal fun create( - capacity: ULong, - len: ULong, - data: Pointer?, - ): RustBuffer.ByValue { + internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue { var buf = RustBuffer.ByValue() buf.capacity = capacity.toLong() buf.len = len.toLong() @@ -92,10 +80,9 @@ open class RustBuffer : Structure() { return buf } - internal fun free(buf: RustBuffer.ByValue) = - uniffiRustCall { status -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rustbuffer_free(buf, status) - } + internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status -> + UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rustbuffer_free(buf, status) + } } @Suppress("TooGenericExceptionThrown") @@ -148,14 +135,10 @@ class RustBufferByReference : ByReference(16) { @Structure.FieldOrder("len", "data") internal open class ForeignBytes : Structure() { @JvmField var len: Int = 0 - @JvmField var data: Pointer? = null - class ByValue : - ForeignBytes(), - Structure.ByValue + class ByValue : ForeignBytes(), Structure.ByValue } - /** * The FfiConverter interface handles converter types to and from the FFI * @@ -185,10 +168,7 @@ public interface FfiConverter { fun allocationSize(value: KotlinType): ULong // Write a Kotlin type to a `ByteBuffer` - fun write( - value: KotlinType, - buf: ByteBuffer, - ) + fun write(value: KotlinType, buf: ByteBuffer) // Lower a value into a `RustBuffer` // @@ -199,10 +179,9 @@ public interface FfiConverter { fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue { val rbuf = RustBuffer.alloc(allocationSize(value)) try { - val bbuf = - rbuf.data!!.getByteBuffer(0, rbuf.capacity).also { - it.order(ByteOrder.BIG_ENDIAN) - } + val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also { + it.order(ByteOrder.BIG_ENDIAN) + } write(value, bbuf) rbuf.writeField("len", bbuf.position().toLong()) return rbuf @@ -219,11 +198,11 @@ public interface FfiConverter { fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType { val byteBuf = rbuf.asByteBuffer()!! try { - val item = read(byteBuf) - if (byteBuf.hasRemaining()) { - throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!") - } - return item + val item = read(byteBuf) + if (byteBuf.hasRemaining()) { + throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!") + } + return item } finally { RustBuffer.free(rbuf) } @@ -235,9 +214,8 @@ public interface FfiConverter { * * @suppress */ -public interface FfiConverterRustBuffer : FfiConverter { +public interface FfiConverterRustBuffer: FfiConverter { override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value) - override fun lower(value: KotlinType) = lowerIntoRustBuffer(value) } // A handful of classes and functions to support the generated data structures. @@ -250,24 +228,24 @@ internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte() @Structure.FieldOrder("code", "error_buf") internal open class UniffiRustCallStatus : Structure() { @JvmField var code: Byte = 0 - @JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue() - class ByValue : - UniffiRustCallStatus(), - Structure.ByValue + class ByValue: UniffiRustCallStatus(), Structure.ByValue - fun isSuccess(): Boolean = code == UNIFFI_CALL_SUCCESS + fun isSuccess(): Boolean { + return code == UNIFFI_CALL_SUCCESS + } - fun isError(): Boolean = code == UNIFFI_CALL_ERROR + fun isError(): Boolean { + return code == UNIFFI_CALL_ERROR + } - fun isPanic(): Boolean = code == UNIFFI_CALL_UNEXPECTED_ERROR + fun isPanic(): Boolean { + return code == UNIFFI_CALL_UNEXPECTED_ERROR + } companion object { - fun create( - code: Byte, - errorBuf: RustBuffer.ByValue, - ): UniffiRustCallStatus.ByValue { + fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue { val callStatus = UniffiRustCallStatus.ByValue() callStatus.code = code callStatus.error_buf = errorBuf @@ -276,9 +254,7 @@ internal open class UniffiRustCallStatus : Structure() { } } -class InternalException( - message: String, -) : kotlin.Exception(message) +class InternalException(message: String) : kotlin.Exception(message) /** * Each top-level error class has a companion object that can lift the error from the call status's rust buffer @@ -286,7 +262,7 @@ class InternalException( * @suppress */ interface UniffiRustCallStatusErrorHandler { - fun lift(error_buf: RustBuffer.ByValue): E + fun lift(error_buf: RustBuffer.ByValue): E; } // Helpers for calling Rust @@ -294,10 +270,7 @@ interface UniffiRustCallStatusErrorHandler { // synchronize itself // Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err -private inline fun uniffiRustCallWithError( - errorHandler: UniffiRustCallStatusErrorHandler, - callback: (UniffiRustCallStatus) -> U, -): U { +private inline fun uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler, callback: (UniffiRustCallStatus) -> U): U { var status = UniffiRustCallStatus() val return_value = callback(status) uniffiCheckCallStatus(errorHandler, status) @@ -305,10 +278,7 @@ private inline fun uniffiRustCallWithError( } // Check UniffiRustCallStatus and throw an error if the call wasn't successful -private fun uniffiCheckCallStatus( - errorHandler: UniffiRustCallStatusErrorHandler, - status: UniffiRustCallStatus, -) { +private fun uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler, status: UniffiRustCallStatus) { if (status.isSuccess()) { return } else if (status.isError()) { @@ -332,7 +302,7 @@ private fun uniffiCheckCallStatus( * * @suppress */ -object UniffiNullRustCallStatusErrorHandler : UniffiRustCallStatusErrorHandler { +object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler { override fun lift(error_buf: RustBuffer.ByValue): InternalException { RustBuffer.free(error_buf) return InternalException("Unexpected CALL_ERROR") @@ -340,31 +310,32 @@ object UniffiNullRustCallStatusErrorHandler : UniffiRustCallStatusErrorHandler uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U = - uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback) +private inline fun uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U { + return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback) +} -internal inline fun uniffiTraitInterfaceCall( +internal inline fun uniffiTraitInterfaceCall( callStatus: UniffiRustCallStatus, makeCall: () -> T, writeReturn: (T) -> Unit, ) { try { writeReturn(makeCall()) - } catch (e: kotlin.Exception) { + } catch(e: kotlin.Exception) { callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR callStatus.error_buf = FfiConverterString.lower(e.toString()) } } -internal inline fun uniffiTraitInterfaceCallWithError( +internal inline fun uniffiTraitInterfaceCallWithError( callStatus: UniffiRustCallStatus, makeCall: () -> T, writeReturn: (T) -> Unit, - lowerError: (E) -> RustBuffer.ByValue, + lowerError: (E) -> RustBuffer.ByValue ) { try { writeReturn(makeCall()) - } catch (e: kotlin.Exception) { + } catch(e: kotlin.Exception) { if (e is E) { callStatus.code = UNIFFI_CALL_ERROR callStatus.error_buf = lowerError(e) @@ -374,15 +345,12 @@ internal inline fun uniffiTraitInterfaceCallWithError } } } - // Map handles to objects // // This is used pass an opaque 64-bit handle representing a foreign object to the Rust code. -internal class UniffiHandleMap { +internal class UniffiHandleMap { private val map = ConcurrentHashMap() - private val counter = - java.util.concurrent.atomic - .AtomicLong(0) + private val counter = java.util.concurrent.atomic.AtomicLong(0) val size: Int get() = map.size @@ -395,10 +363,14 @@ internal class UniffiHandleMap { } // Get an object from the handle map - fun get(handle: Long): T = map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle") + fun get(handle: Long): T { + return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle") + } // Remove an entry from the handlemap and get the Kotlin object back - fun remove(handle: Long): T = map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle") + fun remove(handle: Long): T { + return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle") + } } // Contains loading, initialization code, @@ -412,25 +384,22 @@ private fun findLibraryName(componentName: String): String { return "vss_rust_client_ffi" } -private inline fun loadIndirect(componentName: String): Lib = - Native.load(findLibraryName(componentName), Lib::class.java) +private inline fun loadIndirect( + componentName: String +): Lib { + return Native.load(findLibraryName(componentName), Lib::class.java) +} // Define FFI callback types internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback { - fun callback( - `data`: Long, - `pollResult`: Byte, - ) + fun callback(`data`: Long,`pollResult`: Byte,) } - internal interface UniffiForeignFutureFree : com.sun.jna.Callback { - fun callback(`handle`: Long) + fun callback(`handle`: Long,) } - internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback { - fun callback(`handle`: Long) + fun callback(`handle`: Long,) } - @Structure.FieldOrder("handle", "free") internal open class UniffiForeignFuture( @JvmField internal var `handle`: Long = 0.toLong(), @@ -439,15 +408,14 @@ internal open class UniffiForeignFuture( class UniffiByValue( `handle`: Long = 0.toLong(), `free`: UniffiForeignFutureFree? = null, - ) : UniffiForeignFuture(`handle`, `free`), - Structure.ByValue + ): UniffiForeignFuture(`handle`,`free`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFuture) { + internal fun uniffiSetValue(other: UniffiForeignFuture) { `handle` = other.`handle` `free` = other.`free` } -} +} @Structure.FieldOrder("returnValue", "callStatus") internal open class UniffiForeignFutureStructU8( @JvmField internal var `returnValue`: Byte = 0.toByte(), @@ -456,22 +424,17 @@ internal open class UniffiForeignFutureStructU8( class UniffiByValue( `returnValue`: Byte = 0.toByte(), `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ) : UniffiForeignFutureStructU8(`returnValue`, `callStatus`), - Structure.ByValue + ): UniffiForeignFutureStructU8(`returnValue`,`callStatus`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFutureStructU8) { + internal fun uniffiSetValue(other: UniffiForeignFutureStructU8) { `returnValue` = other.`returnValue` `callStatus` = other.`callStatus` } -} +} internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback { - fun callback( - `callbackData`: Long, - `result`: UniffiForeignFutureStructU8.UniffiByValue, - ) + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU8.UniffiByValue,) } - @Structure.FieldOrder("returnValue", "callStatus") internal open class UniffiForeignFutureStructI8( @JvmField internal var `returnValue`: Byte = 0.toByte(), @@ -480,22 +443,17 @@ internal open class UniffiForeignFutureStructI8( class UniffiByValue( `returnValue`: Byte = 0.toByte(), `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ) : UniffiForeignFutureStructI8(`returnValue`, `callStatus`), - Structure.ByValue + ): UniffiForeignFutureStructI8(`returnValue`,`callStatus`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFutureStructI8) { + internal fun uniffiSetValue(other: UniffiForeignFutureStructI8) { `returnValue` = other.`returnValue` `callStatus` = other.`callStatus` } -} +} internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback { - fun callback( - `callbackData`: Long, - `result`: UniffiForeignFutureStructI8.UniffiByValue, - ) + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI8.UniffiByValue,) } - @Structure.FieldOrder("returnValue", "callStatus") internal open class UniffiForeignFutureStructU16( @JvmField internal var `returnValue`: Short = 0.toShort(), @@ -504,22 +462,17 @@ internal open class UniffiForeignFutureStructU16( class UniffiByValue( `returnValue`: Short = 0.toShort(), `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ) : UniffiForeignFutureStructU16(`returnValue`, `callStatus`), - Structure.ByValue + ): UniffiForeignFutureStructU16(`returnValue`,`callStatus`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFutureStructU16) { + internal fun uniffiSetValue(other: UniffiForeignFutureStructU16) { `returnValue` = other.`returnValue` `callStatus` = other.`callStatus` } -} +} internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback { - fun callback( - `callbackData`: Long, - `result`: UniffiForeignFutureStructU16.UniffiByValue, - ) + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU16.UniffiByValue,) } - @Structure.FieldOrder("returnValue", "callStatus") internal open class UniffiForeignFutureStructI16( @JvmField internal var `returnValue`: Short = 0.toShort(), @@ -528,22 +481,17 @@ internal open class UniffiForeignFutureStructI16( class UniffiByValue( `returnValue`: Short = 0.toShort(), `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ) : UniffiForeignFutureStructI16(`returnValue`, `callStatus`), - Structure.ByValue + ): UniffiForeignFutureStructI16(`returnValue`,`callStatus`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFutureStructI16) { + internal fun uniffiSetValue(other: UniffiForeignFutureStructI16) { `returnValue` = other.`returnValue` `callStatus` = other.`callStatus` } -} +} internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback { - fun callback( - `callbackData`: Long, - `result`: UniffiForeignFutureStructI16.UniffiByValue, - ) + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI16.UniffiByValue,) } - @Structure.FieldOrder("returnValue", "callStatus") internal open class UniffiForeignFutureStructU32( @JvmField internal var `returnValue`: Int = 0, @@ -552,22 +500,17 @@ internal open class UniffiForeignFutureStructU32( class UniffiByValue( `returnValue`: Int = 0, `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ) : UniffiForeignFutureStructU32(`returnValue`, `callStatus`), - Structure.ByValue + ): UniffiForeignFutureStructU32(`returnValue`,`callStatus`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFutureStructU32) { + internal fun uniffiSetValue(other: UniffiForeignFutureStructU32) { `returnValue` = other.`returnValue` `callStatus` = other.`callStatus` } -} +} internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback { - fun callback( - `callbackData`: Long, - `result`: UniffiForeignFutureStructU32.UniffiByValue, - ) + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU32.UniffiByValue,) } - @Structure.FieldOrder("returnValue", "callStatus") internal open class UniffiForeignFutureStructI32( @JvmField internal var `returnValue`: Int = 0, @@ -576,22 +519,17 @@ internal open class UniffiForeignFutureStructI32( class UniffiByValue( `returnValue`: Int = 0, `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ) : UniffiForeignFutureStructI32(`returnValue`, `callStatus`), - Structure.ByValue + ): UniffiForeignFutureStructI32(`returnValue`,`callStatus`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFutureStructI32) { + internal fun uniffiSetValue(other: UniffiForeignFutureStructI32) { `returnValue` = other.`returnValue` `callStatus` = other.`callStatus` } -} +} internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback { - fun callback( - `callbackData`: Long, - `result`: UniffiForeignFutureStructI32.UniffiByValue, - ) + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI32.UniffiByValue,) } - @Structure.FieldOrder("returnValue", "callStatus") internal open class UniffiForeignFutureStructU64( @JvmField internal var `returnValue`: Long = 0.toLong(), @@ -600,22 +538,17 @@ internal open class UniffiForeignFutureStructU64( class UniffiByValue( `returnValue`: Long = 0.toLong(), `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ) : UniffiForeignFutureStructU64(`returnValue`, `callStatus`), - Structure.ByValue + ): UniffiForeignFutureStructU64(`returnValue`,`callStatus`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFutureStructU64) { + internal fun uniffiSetValue(other: UniffiForeignFutureStructU64) { `returnValue` = other.`returnValue` `callStatus` = other.`callStatus` } -} +} internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback { - fun callback( - `callbackData`: Long, - `result`: UniffiForeignFutureStructU64.UniffiByValue, - ) + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU64.UniffiByValue,) } - @Structure.FieldOrder("returnValue", "callStatus") internal open class UniffiForeignFutureStructI64( @JvmField internal var `returnValue`: Long = 0.toLong(), @@ -624,22 +557,17 @@ internal open class UniffiForeignFutureStructI64( class UniffiByValue( `returnValue`: Long = 0.toLong(), `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ) : UniffiForeignFutureStructI64(`returnValue`, `callStatus`), - Structure.ByValue + ): UniffiForeignFutureStructI64(`returnValue`,`callStatus`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFutureStructI64) { + internal fun uniffiSetValue(other: UniffiForeignFutureStructI64) { `returnValue` = other.`returnValue` `callStatus` = other.`callStatus` } -} +} internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback { - fun callback( - `callbackData`: Long, - `result`: UniffiForeignFutureStructI64.UniffiByValue, - ) + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI64.UniffiByValue,) } - @Structure.FieldOrder("returnValue", "callStatus") internal open class UniffiForeignFutureStructF32( @JvmField internal var `returnValue`: Float = 0.0f, @@ -648,22 +576,17 @@ internal open class UniffiForeignFutureStructF32( class UniffiByValue( `returnValue`: Float = 0.0f, `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ) : UniffiForeignFutureStructF32(`returnValue`, `callStatus`), - Structure.ByValue + ): UniffiForeignFutureStructF32(`returnValue`,`callStatus`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFutureStructF32) { + internal fun uniffiSetValue(other: UniffiForeignFutureStructF32) { `returnValue` = other.`returnValue` `callStatus` = other.`callStatus` } -} +} internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback { - fun callback( - `callbackData`: Long, - `result`: UniffiForeignFutureStructF32.UniffiByValue, - ) + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF32.UniffiByValue,) } - @Structure.FieldOrder("returnValue", "callStatus") internal open class UniffiForeignFutureStructF64( @JvmField internal var `returnValue`: Double = 0.0, @@ -672,22 +595,17 @@ internal open class UniffiForeignFutureStructF64( class UniffiByValue( `returnValue`: Double = 0.0, `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ) : UniffiForeignFutureStructF64(`returnValue`, `callStatus`), - Structure.ByValue + ): UniffiForeignFutureStructF64(`returnValue`,`callStatus`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFutureStructF64) { + internal fun uniffiSetValue(other: UniffiForeignFutureStructF64) { `returnValue` = other.`returnValue` `callStatus` = other.`callStatus` } -} +} internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback { - fun callback( - `callbackData`: Long, - `result`: UniffiForeignFutureStructF64.UniffiByValue, - ) + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF64.UniffiByValue,) } - @Structure.FieldOrder("returnValue", "callStatus") internal open class UniffiForeignFutureStructPointer( @JvmField internal var `returnValue`: Pointer = Pointer.NULL, @@ -696,22 +614,17 @@ internal open class UniffiForeignFutureStructPointer( class UniffiByValue( `returnValue`: Pointer = Pointer.NULL, `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ) : UniffiForeignFutureStructPointer(`returnValue`, `callStatus`), - Structure.ByValue + ): UniffiForeignFutureStructPointer(`returnValue`,`callStatus`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFutureStructPointer) { + internal fun uniffiSetValue(other: UniffiForeignFutureStructPointer) { `returnValue` = other.`returnValue` `callStatus` = other.`callStatus` } -} +} internal interface UniffiForeignFutureCompletePointer : com.sun.jna.Callback { - fun callback( - `callbackData`: Long, - `result`: UniffiForeignFutureStructPointer.UniffiByValue, - ) + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructPointer.UniffiByValue,) } - @Structure.FieldOrder("returnValue", "callStatus") internal open class UniffiForeignFutureStructRustBuffer( @JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(), @@ -720,416 +633,366 @@ internal open class UniffiForeignFutureStructRustBuffer( class UniffiByValue( `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(), `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ) : UniffiForeignFutureStructRustBuffer(`returnValue`, `callStatus`), - Structure.ByValue + ): UniffiForeignFutureStructRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFutureStructRustBuffer) { + internal fun uniffiSetValue(other: UniffiForeignFutureStructRustBuffer) { `returnValue` = other.`returnValue` `callStatus` = other.`callStatus` } -} +} internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback { - fun callback( - `callbackData`: Long, - `result`: UniffiForeignFutureStructRustBuffer.UniffiByValue, - ) + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructRustBuffer.UniffiByValue,) } - @Structure.FieldOrder("callStatus") internal open class UniffiForeignFutureStructVoid( @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), ) : Structure() { class UniffiByValue( `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ) : UniffiForeignFutureStructVoid(`callStatus`), - Structure.ByValue + ): UniffiForeignFutureStructVoid(`callStatus`,), Structure.ByValue - internal fun uniffiSetValue(other: UniffiForeignFutureStructVoid) { + internal fun uniffiSetValue(other: UniffiForeignFutureStructVoid) { `callStatus` = other.`callStatus` } -} +} internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback { - fun callback( - `callbackData`: Long, - `result`: UniffiForeignFutureStructVoid.UniffiByValue, - ) + fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructVoid.UniffiByValue,) } -// For large crates we prevent `MethodTooLargeException` (see #2340) -// N.B. the name of the extension is very misleading, since it is -// rather `InterfaceTooLargeException`, caused by too many methods -// in the interface for large crates. -// -// By splitting the otherwise huge interface into two parts -// * UniffiLib -// * IntegrityCheckingUniffiLib (this) -// we allow for ~2x as many methods in the UniffiLib interface. -// -// The `ffi_uniffi_contract_version` method and all checksum methods are put -// into `IntegrityCheckingUniffiLib` and these methods are called only once, -// when the library is loaded. -internal interface IntegrityCheckingUniffiLib : Library { - // Integrity check functions only - fun uniffi_vss_rust_client_ffi_checksum_func_vss_delete(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_derive_store_id(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_get(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_ldk_delete(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_ldk_get(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_ldk_list_all_keys(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_ldk_list_keys(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_ldk_store(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_list(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_list_keys(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_new_client(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_new_client_with_lnurl_auth(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_new_ldk_client_with_lnurl_auth(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_put_with_key_prefix(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_shutdown_client(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_shutdown_ldk_client(): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_store(): Short - fun ffi_vss_rust_client_ffi_uniffi_contract_version(): Int -} -// A JNA Library to expose the extern-C FFI definitions. -// This is an implementation detail which will be called internally by the public API. -internal interface UniffiLib : Library { - companion object { - internal val INSTANCE: UniffiLib by lazy { - val componentName = "vss_rust_client_ffi" - // For large crates we prevent `MethodTooLargeException` (see #2340) - // N.B. the name of the extension is very misleading, since it is - // rather `InterfaceTooLargeException`, caused by too many methods - // in the interface for large crates. - // - // By splitting the otherwise huge interface into two parts - // * UniffiLib (this) - // * IntegrityCheckingUniffiLib - // And all checksum methods are put into `IntegrityCheckingUniffiLib` - // we allow for ~2x as many methods in the UniffiLib interface. - // - // Thus we first load the library with `loadIndirect` as `IntegrityCheckingUniffiLib` - // so that we can (optionally!) call `uniffiCheckApiChecksums`... - loadIndirect(componentName) - .also { lib: IntegrityCheckingUniffiLib -> - uniffiCheckContractApiVersion(lib) - uniffiCheckApiChecksums(lib) - } - // ... and then we load the library as `UniffiLib` - // N.B. we cannot use `loadIndirect` once and then try to cast it to `UniffiLib` - // => results in `java.lang.ClassCastException: com.sun.proxy.$Proxy cannot be cast to ...` - // error. So we must call `loadIndirect` twice. For crates large enough - // to trigger this issue, the performance impact is negligible, running on - // a macOS M1 machine the `loadIndirect` call takes ~50ms. - val lib = loadIndirect(componentName) - // No need to check the contract version and checksums, since - // we already did that with `IntegrityCheckingUniffiLib` above. - // Loading of library with integrity check done. - lib - } - } - // FFI functions - fun uniffi_vss_rust_client_ffi_fn_func_vss_delete(`key`: RustBuffer.ByValue): Long - - fun uniffi_vss_rust_client_ffi_fn_func_vss_derive_store_id( - `prefix`: RustBuffer.ByValue, - `mnemonic`: RustBuffer.ByValue, - `passphrase`: RustBuffer.ByValue, - uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - - fun uniffi_vss_rust_client_ffi_fn_func_vss_get(`key`: RustBuffer.ByValue): Long - fun uniffi_vss_rust_client_ffi_fn_func_vss_ldk_delete( - `key`: RustBuffer.ByValue, - `namespace`: RustBuffer.ByValue, - ): Long - - fun uniffi_vss_rust_client_ffi_fn_func_vss_ldk_get( - `key`: RustBuffer.ByValue, - `namespace`: RustBuffer.ByValue, - ): Long - - fun uniffi_vss_rust_client_ffi_fn_func_vss_ldk_list_all_keys(): Long - - fun uniffi_vss_rust_client_ffi_fn_func_vss_ldk_list_keys(`namespace`: RustBuffer.ByValue): Long - - fun uniffi_vss_rust_client_ffi_fn_func_vss_ldk_store( - `key`: RustBuffer.ByValue, - `value`: RustBuffer.ByValue, - `namespace`: RustBuffer.ByValue, - ): Long - fun uniffi_vss_rust_client_ffi_fn_func_vss_list(`prefix`: RustBuffer.ByValue): Long - fun uniffi_vss_rust_client_ffi_fn_func_vss_list_keys(`prefix`: RustBuffer.ByValue): Long - fun uniffi_vss_rust_client_ffi_fn_func_vss_new_client( - `baseUrl`: RustBuffer.ByValue, - `storeId`: RustBuffer.ByValue, - ): Long - - fun uniffi_vss_rust_client_ffi_fn_func_vss_new_client_with_lnurl_auth( - `baseUrl`: RustBuffer.ByValue, - `storeId`: RustBuffer.ByValue, - `mnemonic`: RustBuffer.ByValue, - `passphrase`: RustBuffer.ByValue, - `lnurlAuthServerUrl`: RustBuffer.ByValue, - ): Long - fun uniffi_vss_rust_client_ffi_fn_func_vss_new_ldk_client_with_lnurl_auth( - `baseUrl`: RustBuffer.ByValue, - `storeId`: RustBuffer.ByValue, - `mnemonic`: RustBuffer.ByValue, - `passphrase`: RustBuffer.ByValue, - `lnurlAuthServerUrl`: RustBuffer.ByValue, - ): Long - fun uniffi_vss_rust_client_ffi_fn_func_vss_put_with_key_prefix(`items`: RustBuffer.ByValue): Long - fun uniffi_vss_rust_client_ffi_fn_func_vss_shutdown_client(uniffi_out_err: UniffiRustCallStatus): Unit - fun uniffi_vss_rust_client_ffi_fn_func_vss_shutdown_ldk_client(uniffi_out_err: UniffiRustCallStatus): Unit - fun uniffi_vss_rust_client_ffi_fn_func_vss_store( - `key`: RustBuffer.ByValue, - `value`: RustBuffer.ByValue, - ): Long - fun ffi_vss_rust_client_ffi_rustbuffer_alloc( - `size`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun ffi_vss_rust_client_ffi_rustbuffer_from_bytes( - `bytes`: ForeignBytes.ByValue, - uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun ffi_vss_rust_client_ffi_rustbuffer_free( - `buf`: RustBuffer.ByValue, - uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun ffi_vss_rust_client_ffi_rustbuffer_reserve( - `buf`: RustBuffer.ByValue, - `additional`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun ffi_vss_rust_client_ffi_rust_future_poll_u8( - `handle`: Long, - `callback`: UniffiRustFutureContinuationCallback, - `callbackData`: Long, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_u8(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_u8(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_u8( - `handle`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): Byte - fun ffi_vss_rust_client_ffi_rust_future_poll_i8( - `handle`: Long, - `callback`: UniffiRustFutureContinuationCallback, - `callbackData`: Long, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_i8(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_i8(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_i8( - `handle`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): Byte - fun ffi_vss_rust_client_ffi_rust_future_poll_u16( - `handle`: Long, - `callback`: UniffiRustFutureContinuationCallback, - `callbackData`: Long, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_u16(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_u16(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_u16( - `handle`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): Short - fun ffi_vss_rust_client_ffi_rust_future_poll_i16( - `handle`: Long, - `callback`: UniffiRustFutureContinuationCallback, - `callbackData`: Long, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_i16(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_i16(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_i16( - `handle`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): Short - fun ffi_vss_rust_client_ffi_rust_future_poll_u32( - `handle`: Long, - `callback`: UniffiRustFutureContinuationCallback, - `callbackData`: Long, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_u32(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_u32(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_u32( - `handle`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): Int - fun ffi_vss_rust_client_ffi_rust_future_poll_i32( - `handle`: Long, - `callback`: UniffiRustFutureContinuationCallback, - `callbackData`: Long, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_i32(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_i32(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_i32( - `handle`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): Int - fun ffi_vss_rust_client_ffi_rust_future_poll_u64( - `handle`: Long, - `callback`: UniffiRustFutureContinuationCallback, - `callbackData`: Long, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_u64(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_u64(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_u64( - `handle`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): Long - fun ffi_vss_rust_client_ffi_rust_future_poll_i64( - `handle`: Long, - `callback`: UniffiRustFutureContinuationCallback, - `callbackData`: Long, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_i64(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_i64(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_i64( - `handle`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): Long - fun ffi_vss_rust_client_ffi_rust_future_poll_f32( - `handle`: Long, - `callback`: UniffiRustFutureContinuationCallback, - `callbackData`: Long, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_f32(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_f32(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_f32( - `handle`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): Float - fun ffi_vss_rust_client_ffi_rust_future_poll_f64( - `handle`: Long, - `callback`: UniffiRustFutureContinuationCallback, - `callbackData`: Long, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_f64(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_f64(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_f64( - `handle`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): Double - fun ffi_vss_rust_client_ffi_rust_future_poll_pointer( - `handle`: Long, - `callback`: UniffiRustFutureContinuationCallback, - `callbackData`: Long, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_pointer(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_pointer(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_pointer( - `handle`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer( - `handle`: Long, - `callback`: UniffiRustFutureContinuationCallback, - `callbackData`: Long, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_rust_buffer(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer( - `handle`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun ffi_vss_rust_client_ffi_rust_future_poll_void( - `handle`: Long, - `callback`: UniffiRustFutureContinuationCallback, - `callbackData`: Long, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_void(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_void(`handle`: Long): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_void( - `handle`: Long, - uniffi_out_err: UniffiRustCallStatus, - ): Unit + + + + + + + +// For large crates we prevent `MethodTooLargeException` (see #2340) +// N.B. the name of the extension is very misleading, since it is +// rather `InterfaceTooLargeException`, caused by too many methods +// in the interface for large crates. +// +// By splitting the otherwise huge interface into two parts +// * UniffiLib +// * IntegrityCheckingUniffiLib (this) +// we allow for ~2x as many methods in the UniffiLib interface. +// +// The `ffi_uniffi_contract_version` method and all checksum methods are put +// into `IntegrityCheckingUniffiLib` and these methods are called only once, +// when the library is loaded. +internal interface IntegrityCheckingUniffiLib : Library { + // Integrity check functions only + fun uniffi_vss_rust_client_ffi_checksum_func_vss_delete( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_derive_store_id( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_get( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_ldk_delete( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_ldk_get( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_ldk_list_all_keys( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_ldk_list_keys( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_ldk_store( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_list( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_list_keys( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_new_client( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_new_client_with_lnurl_auth( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_new_ldk_client_with_lnurl_auth( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_put_with_key_prefix( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_shutdown_client( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_shutdown_ldk_client( +): Short +fun uniffi_vss_rust_client_ffi_checksum_func_vss_store( +): Short +fun ffi_vss_rust_client_ffi_uniffi_contract_version( +): Int + +} + +// A JNA Library to expose the extern-C FFI definitions. +// This is an implementation detail which will be called internally by the public API. +internal interface UniffiLib : Library { + companion object { + internal val INSTANCE: UniffiLib by lazy { + val componentName = "vss_rust_client_ffi" + // For large crates we prevent `MethodTooLargeException` (see #2340) + // N.B. the name of the extension is very misleading, since it is + // rather `InterfaceTooLargeException`, caused by too many methods + // in the interface for large crates. + // + // By splitting the otherwise huge interface into two parts + // * UniffiLib (this) + // * IntegrityCheckingUniffiLib + // And all checksum methods are put into `IntegrityCheckingUniffiLib` + // we allow for ~2x as many methods in the UniffiLib interface. + // + // Thus we first load the library with `loadIndirect` as `IntegrityCheckingUniffiLib` + // so that we can (optionally!) call `uniffiCheckApiChecksums`... + loadIndirect(componentName) + .also { lib: IntegrityCheckingUniffiLib -> + uniffiCheckContractApiVersion(lib) + uniffiCheckApiChecksums(lib) + } + // ... and then we load the library as `UniffiLib` + // N.B. we cannot use `loadIndirect` once and then try to cast it to `UniffiLib` + // => results in `java.lang.ClassCastException: com.sun.proxy.$Proxy cannot be cast to ...` + // error. So we must call `loadIndirect` twice. For crates large enough + // to trigger this issue, the performance impact is negligible, running on + // a macOS M1 machine the `loadIndirect` call takes ~50ms. + val lib = loadIndirect(componentName) + // No need to check the contract version and checksums, since + // we already did that with `IntegrityCheckingUniffiLib` above. + // Loading of library with integrity check done. + lib + } + + } + + // FFI functions + fun uniffi_vss_rust_client_ffi_fn_func_vss_delete(`key`: RustBuffer.ByValue, +): Long +fun uniffi_vss_rust_client_ffi_fn_func_vss_derive_store_id(`prefix`: RustBuffer.ByValue,`mnemonic`: RustBuffer.ByValue,`passphrase`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +fun uniffi_vss_rust_client_ffi_fn_func_vss_get(`key`: RustBuffer.ByValue, +): Long +fun uniffi_vss_rust_client_ffi_fn_func_vss_ldk_delete(`key`: RustBuffer.ByValue,`namespace`: RustBuffer.ByValue, +): Long +fun uniffi_vss_rust_client_ffi_fn_func_vss_ldk_get(`key`: RustBuffer.ByValue,`namespace`: RustBuffer.ByValue, +): Long +fun uniffi_vss_rust_client_ffi_fn_func_vss_ldk_list_all_keys( +): Long +fun uniffi_vss_rust_client_ffi_fn_func_vss_ldk_list_keys(`namespace`: RustBuffer.ByValue, +): Long +fun uniffi_vss_rust_client_ffi_fn_func_vss_ldk_store(`key`: RustBuffer.ByValue,`value`: RustBuffer.ByValue,`namespace`: RustBuffer.ByValue, +): Long +fun uniffi_vss_rust_client_ffi_fn_func_vss_list(`prefix`: RustBuffer.ByValue, +): Long +fun uniffi_vss_rust_client_ffi_fn_func_vss_list_keys(`prefix`: RustBuffer.ByValue, +): Long +fun uniffi_vss_rust_client_ffi_fn_func_vss_new_client(`baseUrl`: RustBuffer.ByValue,`storeId`: RustBuffer.ByValue, +): Long +fun uniffi_vss_rust_client_ffi_fn_func_vss_new_client_with_lnurl_auth(`baseUrl`: RustBuffer.ByValue,`storeId`: RustBuffer.ByValue,`mnemonic`: RustBuffer.ByValue,`passphrase`: RustBuffer.ByValue,`lnurlAuthServerUrl`: RustBuffer.ByValue, +): Long +fun uniffi_vss_rust_client_ffi_fn_func_vss_new_ldk_client_with_lnurl_auth(`baseUrl`: RustBuffer.ByValue,`storeId`: RustBuffer.ByValue,`mnemonic`: RustBuffer.ByValue,`passphrase`: RustBuffer.ByValue,`lnurlAuthServerUrl`: RustBuffer.ByValue, +): Long +fun uniffi_vss_rust_client_ffi_fn_func_vss_put_with_key_prefix(`items`: RustBuffer.ByValue, +): Long +fun uniffi_vss_rust_client_ffi_fn_func_vss_shutdown_client(uniffi_out_err: UniffiRustCallStatus, +): Unit +fun uniffi_vss_rust_client_ffi_fn_func_vss_shutdown_ldk_client(uniffi_out_err: UniffiRustCallStatus, +): Unit +fun uniffi_vss_rust_client_ffi_fn_func_vss_store(`key`: RustBuffer.ByValue,`value`: RustBuffer.ByValue, +): Long +fun ffi_vss_rust_client_ffi_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +fun ffi_vss_rust_client_ffi_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +fun ffi_vss_rust_client_ffi_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Unit +fun ffi_vss_rust_client_ffi_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +fun ffi_vss_rust_client_ffi_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_cancel_u8(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_free_u8(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Byte +fun ffi_vss_rust_client_ffi_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_cancel_i8(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_free_i8(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Byte +fun ffi_vss_rust_client_ffi_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_cancel_u16(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_free_u16(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Short +fun ffi_vss_rust_client_ffi_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_cancel_i16(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_free_i16(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Short +fun ffi_vss_rust_client_ffi_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_cancel_u32(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_free_u32(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Int +fun ffi_vss_rust_client_ffi_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_cancel_i32(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_free_i32(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Int +fun ffi_vss_rust_client_ffi_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_cancel_u64(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_free_u64(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Long +fun ffi_vss_rust_client_ffi_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_cancel_i64(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_free_i64(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Long +fun ffi_vss_rust_client_ffi_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_cancel_f32(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_free_f32(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Float +fun ffi_vss_rust_client_ffi_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_cancel_f64(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_free_f64(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Double +fun ffi_vss_rust_client_ffi_rust_future_poll_pointer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_cancel_pointer(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_free_pointer(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_complete_pointer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Pointer +fun ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_cancel_rust_buffer(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +fun ffi_vss_rust_client_ffi_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_cancel_void(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_free_void(`handle`: Long, +): Unit +fun ffi_vss_rust_client_ffi_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, +): Unit + } private fun uniffiCheckContractApiVersion(lib: IntegrityCheckingUniffiLib) { @@ -1141,7 +1004,6 @@ private fun uniffiCheckContractApiVersion(lib: IntegrityCheckingUniffiLib) { throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project") } } - @Suppress("UNUSED_PARAMETER") private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_delete() != 13005.toShort()) { @@ -1174,7 +1036,7 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_list_keys() != 21638.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_new_client() != 63115.toShort()) { + if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_new_client() != 27788.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_new_client_with_lnurl_auth() != 13999.toShort()) { @@ -1213,37 +1075,33 @@ internal const val UNIFFI_RUST_FUTURE_POLL_MAYBE_READY = 1.toByte() internal val uniffiContinuationHandleMap = UniffiHandleMap>() // FFI type for Rust future continuations -internal object uniffiRustFutureContinuationCallbackImpl : UniffiRustFutureContinuationCallback { - override fun callback( - data: Long, - pollResult: Byte, - ) { +internal object uniffiRustFutureContinuationCallbackImpl: UniffiRustFutureContinuationCallback { + override fun callback(data: Long, pollResult: Byte) { uniffiContinuationHandleMap.remove(data).resume(pollResult) } } -internal suspend fun uniffiRustCallAsync( +internal suspend fun uniffiRustCallAsync( rustFuture: Long, pollFunc: (Long, UniffiRustFutureContinuationCallback, Long) -> Unit, completeFunc: (Long, UniffiRustCallStatus) -> F, freeFunc: (Long) -> Unit, liftFunc: (F) -> T, - errorHandler: UniffiRustCallStatusErrorHandler, + errorHandler: UniffiRustCallStatusErrorHandler ): T { try { do { - val pollResult = - suspendCancellableCoroutine { continuation -> - pollFunc( - rustFuture, - uniffiRustFutureContinuationCallbackImpl, - uniffiContinuationHandleMap.insert(continuation), - ) - } - } while (pollResult != UNIFFI_RUST_FUTURE_POLL_READY) + val pollResult = suspendCancellableCoroutine { continuation -> + pollFunc( + rustFuture, + uniffiRustFutureContinuationCallbackImpl, + uniffiContinuationHandleMap.insert(continuation) + ) + } + } while (pollResult != UNIFFI_RUST_FUTURE_POLL_READY); return liftFunc( - uniffiRustCallWithError(errorHandler, { status -> completeFunc(rustFuture, status) }), + uniffiRustCallWithError(errorHandler, { status -> completeFunc(rustFuture, status) }) ) } finally { freeFunc(rustFuture) @@ -1252,6 +1110,7 @@ internal suspend fun uniffiRustCallAsync( // Public interface members begin here. + // Interface implemented by anything that can contain an object reference. // // Such types expose a `destroy()` method that must be called to cleanly @@ -1262,15 +1121,11 @@ internal suspend fun uniffiRustCallAsync( // helper method to execute a block and destroy the object at the end. interface Disposable { fun destroy() - companion object { fun destroy(vararg args: Any?) { for (arg in args) { when (arg) { - is Disposable -> { - arg.destroy() - } - + is Disposable -> arg.destroy() is ArrayList<*> -> { for (idx in arg.indices) { val element = arg[idx] @@ -1279,7 +1134,6 @@ interface Disposable { } } } - is Map<*, *> -> { for (element in arg.values) { if (element is Disposable) { @@ -1287,7 +1141,6 @@ interface Disposable { } } } - is Iterable<*> -> { for (element in arg) { if (element is Disposable) { @@ -1316,7 +1169,7 @@ inline fun T.use(block: (T) -> R) = } } -/** +/** * Used to instantiate an interface without an actual pointer, for fakes in tests, mostly. * * @suppress @@ -1326,19 +1179,22 @@ object NoPointer /** * @suppress */ -public object FfiConverterLong : FfiConverter { - override fun lift(value: Long): Long = value +public object FfiConverterLong: FfiConverter { + override fun lift(value: Long): Long { + return value + } - override fun read(buf: ByteBuffer): Long = buf.getLong() + override fun read(buf: ByteBuffer): Long { + return buf.getLong() + } - override fun lower(value: Long): Long = value + override fun lower(value: Long): Long { + return value + } override fun allocationSize(value: Long) = 8UL - override fun write( - value: Long, - buf: ByteBuffer, - ) { + override fun write(value: Long, buf: ByteBuffer) { buf.putLong(value) } } @@ -1346,19 +1202,22 @@ public object FfiConverterLong : FfiConverter { /** * @suppress */ -public object FfiConverterBoolean : FfiConverter { - override fun lift(value: Byte): Boolean = value.toInt() != 0 +public object FfiConverterBoolean: FfiConverter { + override fun lift(value: Byte): Boolean { + return value.toInt() != 0 + } - override fun read(buf: ByteBuffer): Boolean = lift(buf.get()) + override fun read(buf: ByteBuffer): Boolean { + return lift(buf.get()) + } - override fun lower(value: Boolean): Byte = if (value) 1.toByte() else 0.toByte() + override fun lower(value: Boolean): Byte { + return if (value) 1.toByte() else 0.toByte() + } override fun allocationSize(value: Boolean) = 1UL - override fun write( - value: Boolean, - buf: ByteBuffer, - ) { + override fun write(value: Boolean, buf: ByteBuffer) { buf.put(lower(value)) } } @@ -1366,7 +1225,7 @@ public object FfiConverterBoolean : FfiConverter { /** * @suppress */ -public object FfiConverterString : FfiConverter { +public object FfiConverterString: FfiConverter { // Note: we don't inherit from FfiConverterRustBuffer, because we use a // special encoding when lowering/lifting. We can use `RustBuffer.len` to // store our length and avoid writing it out to the buffer. @@ -1413,10 +1272,7 @@ public object FfiConverterString : FfiConverter { return sizeForLength + sizeForString } - override fun write( - value: String, - buf: ByteBuffer, - ) { + override fun write(value: String, buf: ByteBuffer) { val byteBuf = toUtf8(value) buf.putInt(byteBuf.limit()) buf.put(byteBuf) @@ -1426,251 +1282,232 @@ public object FfiConverterString : FfiConverter { /** * @suppress */ -public object FfiConverterByteArray : FfiConverterRustBuffer { +public object FfiConverterByteArray: FfiConverterRustBuffer { override fun read(buf: ByteBuffer): ByteArray { val len = buf.getInt() val byteArr = ByteArray(len) buf.get(byteArr) return byteArr } - - override fun allocationSize(value: ByteArray): ULong = 4UL + value.size.toULong() - - override fun write( - value: ByteArray, - buf: ByteBuffer, - ) { + override fun allocationSize(value: ByteArray): ULong { + return 4UL + value.size.toULong() + } + override fun write(value: ByteArray, buf: ByteBuffer) { buf.putInt(value.size) buf.put(value) } } -data class KeyValue( - var `key`: kotlin.String, - var `value`: kotlin.ByteArray, + + +data class KeyValue ( + var `key`: kotlin.String, + var `value`: kotlin.ByteArray ) { + companion object } /** * @suppress */ -public object FfiConverterTypeKeyValue : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): KeyValue = - KeyValue( +public object FfiConverterTypeKeyValue: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): KeyValue { + return KeyValue( FfiConverterString.read(buf), FfiConverterByteArray.read(buf), ) + } - override fun allocationSize(value: KeyValue) = - ( + override fun allocationSize(value: KeyValue) = ( FfiConverterString.allocationSize(value.`key`) + - FfiConverterByteArray.allocationSize(value.`value`) - ) + FfiConverterByteArray.allocationSize(value.`value`) + ) - override fun write( - value: KeyValue, - buf: ByteBuffer, - ) { - FfiConverterString.write(value.`key`, buf) - FfiConverterByteArray.write(value.`value`, buf) + override fun write(value: KeyValue, buf: ByteBuffer) { + FfiConverterString.write(value.`key`, buf) + FfiConverterByteArray.write(value.`value`, buf) } } -data class KeyVersion( - var `key`: kotlin.String, - var `version`: kotlin.Long, + + +data class KeyVersion ( + var `key`: kotlin.String, + var `version`: kotlin.Long ) { + companion object } /** * @suppress */ -public object FfiConverterTypeKeyVersion : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): KeyVersion = - KeyVersion( +public object FfiConverterTypeKeyVersion: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): KeyVersion { + return KeyVersion( FfiConverterString.read(buf), FfiConverterLong.read(buf), ) + } - override fun allocationSize(value: KeyVersion) = - ( + override fun allocationSize(value: KeyVersion) = ( FfiConverterString.allocationSize(value.`key`) + - FfiConverterLong.allocationSize(value.`version`) - ) + FfiConverterLong.allocationSize(value.`version`) + ) - override fun write( - value: KeyVersion, - buf: ByteBuffer, - ) { - FfiConverterString.write(value.`key`, buf) - FfiConverterLong.write(value.`version`, buf) + override fun write(value: KeyVersion, buf: ByteBuffer) { + FfiConverterString.write(value.`key`, buf) + FfiConverterLong.write(value.`version`, buf) } } -data class ListKeyVersionsResponse( - var `keyVersions`: List, + + +data class ListKeyVersionsResponse ( + var `keyVersions`: List ) { + companion object } /** * @suppress */ -public object FfiConverterTypeListKeyVersionsResponse : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): ListKeyVersionsResponse = - ListKeyVersionsResponse( +public object FfiConverterTypeListKeyVersionsResponse: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): ListKeyVersionsResponse { + return ListKeyVersionsResponse( FfiConverterSequenceTypeKeyVersion.read(buf), ) + } - override fun allocationSize(value: ListKeyVersionsResponse) = - ( + override fun allocationSize(value: ListKeyVersionsResponse) = ( FfiConverterSequenceTypeKeyVersion.allocationSize(value.`keyVersions`) - ) + ) - override fun write( - value: ListKeyVersionsResponse, - buf: ByteBuffer, - ) { - FfiConverterSequenceTypeKeyVersion.write(value.`keyVersions`, buf) + override fun write(value: ListKeyVersionsResponse, buf: ByteBuffer) { + FfiConverterSequenceTypeKeyVersion.write(value.`keyVersions`, buf) } } -data class VssItem( - var `key`: kotlin.String, - var `value`: kotlin.ByteArray, - var `version`: kotlin.Long, + + +data class VssItem ( + var `key`: kotlin.String, + var `value`: kotlin.ByteArray, + var `version`: kotlin.Long ) { + companion object } /** * @suppress */ -public object FfiConverterTypeVssItem : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): VssItem = - VssItem( +public object FfiConverterTypeVssItem: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): VssItem { + return VssItem( FfiConverterString.read(buf), FfiConverterByteArray.read(buf), FfiConverterLong.read(buf), ) + } - override fun allocationSize(value: VssItem) = - ( + override fun allocationSize(value: VssItem) = ( FfiConverterString.allocationSize(value.`key`) + - FfiConverterByteArray.allocationSize(value.`value`) + - FfiConverterLong.allocationSize(value.`version`) - ) + FfiConverterByteArray.allocationSize(value.`value`) + + FfiConverterLong.allocationSize(value.`version`) + ) - override fun write( - value: VssItem, - buf: ByteBuffer, - ) { - FfiConverterString.write(value.`key`, buf) - FfiConverterByteArray.write(value.`value`, buf) - FfiConverterLong.write(value.`version`, buf) + override fun write(value: VssItem, buf: ByteBuffer) { + FfiConverterString.write(value.`key`, buf) + FfiConverterByteArray.write(value.`value`, buf) + FfiConverterLong.write(value.`version`, buf) } } + + sealed class LdkNamespace { + object Default : LdkNamespace() - + + object Monitors : LdkNamespace() - + + data class MonitorUpdates( - val `monitorId`: kotlin.String, - ) : LdkNamespace() { + val `monitorId`: kotlin.String) : LdkNamespace() { companion object } - + object ArchivedMonitors : LdkNamespace() + + + companion object } /** * @suppress */ -public object FfiConverterTypeLdkNamespace : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): LdkNamespace = - when (buf.getInt()) { - 1 -> { - LdkNamespace.Default - } - - 2 -> { - LdkNamespace.Monitors - } - - 3 -> { - LdkNamespace.MonitorUpdates( - FfiConverterString.read(buf), +public object FfiConverterTypeLdkNamespace : FfiConverterRustBuffer{ + override fun read(buf: ByteBuffer): LdkNamespace { + return when(buf.getInt()) { + 1 -> LdkNamespace.Default + 2 -> LdkNamespace.Monitors + 3 -> LdkNamespace.MonitorUpdates( + FfiConverterString.read(buf), ) - } - - 4 -> { - LdkNamespace.ArchivedMonitors - } - - else -> { - throw RuntimeException("invalid enum value, something is very wrong!!") - } + 4 -> LdkNamespace.ArchivedMonitors + else -> throw RuntimeException("invalid enum value, something is very wrong!!") } + } - override fun allocationSize(value: LdkNamespace) = - when (value) { - is LdkNamespace.Default -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - ) - } - - is LdkNamespace.Monitors -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - ) - } - - is LdkNamespace.MonitorUpdates -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL + - FfiConverterString.allocationSize(value.`monitorId`) - ) - } - - is LdkNamespace.ArchivedMonitors -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - ) - } + override fun allocationSize(value: LdkNamespace) = when(value) { + is LdkNamespace.Default -> { + // Add the size for the Int that specifies the variant plus the size needed for all fields + ( + 4UL + ) + } + is LdkNamespace.Monitors -> { + // Add the size for the Int that specifies the variant plus the size needed for all fields + ( + 4UL + ) } + is LdkNamespace.MonitorUpdates -> { + // Add the size for the Int that specifies the variant plus the size needed for all fields + ( + 4UL + + FfiConverterString.allocationSize(value.`monitorId`) + ) + } + is LdkNamespace.ArchivedMonitors -> { + // Add the size for the Int that specifies the variant plus the size needed for all fields + ( + 4UL + ) + } + } - override fun write( - value: LdkNamespace, - buf: ByteBuffer, - ) { - when (value) { + override fun write(value: LdkNamespace, buf: ByteBuffer) { + when(value) { is LdkNamespace.Default -> { buf.putInt(1) Unit } - is LdkNamespace.Monitors -> { buf.putInt(2) Unit } - is LdkNamespace.MonitorUpdates -> { buf.putInt(3) FfiConverterString.write(value.`monitorId`, buf) Unit } - is LdkNamespace.ArchivedMonitors -> { buf.putInt(4) Unit @@ -1679,275 +1516,246 @@ public object FfiConverterTypeLdkNamespace : FfiConverterRustBuffer { override fun lift(error_buf: RustBuffer.ByValue): VssException = FfiConverterTypeVssError.lift(error_buf) } + + } /** * @suppress */ public object FfiConverterTypeVssError : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): VssException = - when (buf.getInt()) { - 1 -> { - VssException.ConnectionException( - FfiConverterString.read(buf), - ) - } + override fun read(buf: ByteBuffer): VssException { + - 2 -> { - VssException.AuthException( - FfiConverterString.read(buf), + return when(buf.getInt()) { + 1 -> VssException.ConnectionException( + FfiConverterString.read(buf), ) - } - - 3 -> { - VssException.StoreException( - FfiConverterString.read(buf), + 2 -> VssException.AuthException( + FfiConverterString.read(buf), ) - } - - 4 -> { - VssException.GetException( - FfiConverterString.read(buf), + 3 -> VssException.StoreException( + FfiConverterString.read(buf), ) - } - - 5 -> { - VssException.ListException( - FfiConverterString.read(buf), + 4 -> VssException.GetException( + FfiConverterString.read(buf), ) - } - - 6 -> { - VssException.PutException( - FfiConverterString.read(buf), + 5 -> VssException.ListException( + FfiConverterString.read(buf), ) - } - - 7 -> { - VssException.DeleteException( - FfiConverterString.read(buf), + 6 -> VssException.PutException( + FfiConverterString.read(buf), ) - } - - 8 -> { - VssException.InvalidData( - FfiConverterString.read(buf), + 7 -> VssException.DeleteException( + FfiConverterString.read(buf), ) - } - - 9 -> { - VssException.NetworkException( - FfiConverterString.read(buf), + 8 -> VssException.InvalidData( + FfiConverterString.read(buf), ) - } - - 10 -> { - VssException.UnknownException( - FfiConverterString.read(buf), + 9 -> VssException.NetworkException( + FfiConverterString.read(buf), ) - } - - else -> { - throw RuntimeException("invalid error enum value, something is very wrong!!") - } + 10 -> VssException.UnknownException( + FfiConverterString.read(buf), + ) + else -> throw RuntimeException("invalid error enum value, something is very wrong!!") } + } - override fun allocationSize(value: VssException): ULong = - when (value) { + override fun allocationSize(value: VssException): ULong { + return when(value) { is VssException.ConnectionException -> ( // Add the size for the Int that specifies the variant plus the size needed for all fields - 4UL + - FfiConverterString.allocationSize(value.`errorDetails`) + 4UL + + FfiConverterString.allocationSize(value.`errorDetails`) ) - is VssException.AuthException -> ( // Add the size for the Int that specifies the variant plus the size needed for all fields - 4UL + - FfiConverterString.allocationSize(value.`errorDetails`) + 4UL + + FfiConverterString.allocationSize(value.`errorDetails`) ) - is VssException.StoreException -> ( // Add the size for the Int that specifies the variant plus the size needed for all fields - 4UL + - FfiConverterString.allocationSize(value.`errorDetails`) + 4UL + + FfiConverterString.allocationSize(value.`errorDetails`) ) - is VssException.GetException -> ( // Add the size for the Int that specifies the variant plus the size needed for all fields - 4UL + - FfiConverterString.allocationSize(value.`errorDetails`) + 4UL + + FfiConverterString.allocationSize(value.`errorDetails`) ) - is VssException.ListException -> ( // Add the size for the Int that specifies the variant plus the size needed for all fields - 4UL + - FfiConverterString.allocationSize(value.`errorDetails`) + 4UL + + FfiConverterString.allocationSize(value.`errorDetails`) ) - is VssException.PutException -> ( // Add the size for the Int that specifies the variant plus the size needed for all fields - 4UL + - FfiConverterString.allocationSize(value.`errorDetails`) + 4UL + + FfiConverterString.allocationSize(value.`errorDetails`) ) - is VssException.DeleteException -> ( // Add the size for the Int that specifies the variant plus the size needed for all fields - 4UL + - FfiConverterString.allocationSize(value.`errorDetails`) + 4UL + + FfiConverterString.allocationSize(value.`errorDetails`) ) - is VssException.InvalidData -> ( // Add the size for the Int that specifies the variant plus the size needed for all fields - 4UL + - FfiConverterString.allocationSize(value.`errorDetails`) + 4UL + + FfiConverterString.allocationSize(value.`errorDetails`) ) - is VssException.NetworkException -> ( // Add the size for the Int that specifies the variant plus the size needed for all fields - 4UL + - FfiConverterString.allocationSize(value.`errorDetails`) + 4UL + + FfiConverterString.allocationSize(value.`errorDetails`) ) - is VssException.UnknownException -> ( // Add the size for the Int that specifies the variant plus the size needed for all fields - 4UL + - FfiConverterString.allocationSize(value.`errorDetails`) + 4UL + + FfiConverterString.allocationSize(value.`errorDetails`) ) } + } - override fun write( - value: VssException, - buf: ByteBuffer, - ) { - when (value) { + override fun write(value: VssException, buf: ByteBuffer) { + when(value) { is VssException.ConnectionException -> { buf.putInt(1) FfiConverterString.write(value.`errorDetails`, buf) Unit } - is VssException.AuthException -> { buf.putInt(2) FfiConverterString.write(value.`errorDetails`, buf) Unit } - is VssException.StoreException -> { buf.putInt(3) FfiConverterString.write(value.`errorDetails`, buf) Unit } - is VssException.GetException -> { buf.putInt(4) FfiConverterString.write(value.`errorDetails`, buf) Unit } - is VssException.ListException -> { buf.putInt(5) FfiConverterString.write(value.`errorDetails`, buf) Unit } - is VssException.PutException -> { buf.putInt(6) FfiConverterString.write(value.`errorDetails`, buf) Unit } - is VssException.DeleteException -> { buf.putInt(7) FfiConverterString.write(value.`errorDetails`, buf) Unit } - is VssException.InvalidData -> { buf.putInt(8) FfiConverterString.write(value.`errorDetails`, buf) Unit } - is VssException.NetworkException -> { buf.putInt(9) FfiConverterString.write(value.`errorDetails`, buf) Unit } - is VssException.UnknownException -> { buf.putInt(10) FfiConverterString.write(value.`errorDetails`, buf) @@ -1955,41 +1763,46 @@ public object FfiConverterTypeVssError : FfiConverterRustBuffer { } }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } } + } + + + enum class VssFilterType { + PREFIX, - EXACT, - ; - + EXACT; companion object } + /** * @suppress */ -public object FfiConverterTypeVssFilterType : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer) = - try { - VssFilterType.values()[buf.getInt() - 1] - } catch (e: IndexOutOfBoundsException) { - throw RuntimeException("invalid enum value, something is very wrong!!", e) - } +public object FfiConverterTypeVssFilterType: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer) = try { + VssFilterType.values()[buf.getInt() - 1] + } catch (e: IndexOutOfBoundsException) { + throw RuntimeException("invalid enum value, something is very wrong!!", e) + } override fun allocationSize(value: VssFilterType) = 4UL - override fun write( - value: VssFilterType, - buf: ByteBuffer, - ) { + override fun write(value: VssFilterType, buf: ByteBuffer) { buf.putInt(value.ordinal + 1) } } + + + + + /** * @suppress */ -public object FfiConverterOptionalString : FfiConverterRustBuffer { +public object FfiConverterOptionalString: FfiConverterRustBuffer { override fun read(buf: ByteBuffer): kotlin.String? { if (buf.get().toInt() == 0) { return null @@ -2005,10 +1818,7 @@ public object FfiConverterOptionalString : FfiConverterRustBuffer { +public object FfiConverterOptionalTypeVssItem: FfiConverterRustBuffer { override fun read(buf: ByteBuffer): VssItem? { if (buf.get().toInt() == 0) { return null @@ -2037,10 +1850,7 @@ public object FfiConverterOptionalTypeVssItem : FfiConverterRustBuffer } } - override fun write( - value: VssItem?, - buf: ByteBuffer, - ) { + override fun write(value: VssItem?, buf: ByteBuffer) { if (value == null) { buf.put(0) } else { @@ -2050,10 +1860,13 @@ public object FfiConverterOptionalTypeVssItem : FfiConverterRustBuffer } } + + + /** * @suppress */ -public object FfiConverterSequenceTypeKeyValue : FfiConverterRustBuffer> { +public object FfiConverterSequenceTypeKeyValue: FfiConverterRustBuffer> { override fun read(buf: ByteBuffer): List { val len = buf.getInt() return List(len) { @@ -2067,10 +1880,7 @@ public object FfiConverterSequenceTypeKeyValue : FfiConverterRustBuffer, - buf: ByteBuffer, - ) { + override fun write(value: List, buf: ByteBuffer) { buf.putInt(value.size) value.iterator().forEach { FfiConverterTypeKeyValue.write(it, buf) @@ -2078,10 +1888,13 @@ public object FfiConverterSequenceTypeKeyValue : FfiConverterRustBuffer> { +public object FfiConverterSequenceTypeKeyVersion: FfiConverterRustBuffer> { override fun read(buf: ByteBuffer): List { val len = buf.getInt() return List(len) { @@ -2095,10 +1908,7 @@ public object FfiConverterSequenceTypeKeyVersion : FfiConverterRustBuffer, - buf: ByteBuffer, - ) { + override fun write(value: List, buf: ByteBuffer) { buf.putInt(value.size) value.iterator().forEach { FfiConverterTypeKeyVersion.write(it, buf) @@ -2106,10 +1916,13 @@ public object FfiConverterSequenceTypeKeyVersion : FfiConverterRustBuffer> { +public object FfiConverterSequenceTypeVssItem: FfiConverterRustBuffer> { override fun read(buf: ByteBuffer): List { val len = buf.getInt() return List(len) { @@ -2123,10 +1936,7 @@ public object FfiConverterSequenceTypeVssItem : FfiConverterRustBuffer, - buf: ByteBuffer, - ) { + override fun write(value: List, buf: ByteBuffer) { buf.putInt(value.size) value.iterator().forEach { FfiConverterTypeVssItem.write(it, buf) @@ -2134,41 +1944,42 @@ public object FfiConverterSequenceTypeVssItem : FfiConverterRustBuffer - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_i8(future, callback, continuation) - }, + + + + + + + + /** + * Deletes a key-value pair from the VSS server. + * + * This function removes the specified key and its associated data from storage. + * The operation is idempotent - deleting a non-existent key will not cause an error. + * + * # Parameters + * - `key`: The key to delete + * + * # Returns + * `true` if the key was found and deleted, `false` if the key didn't exist, + * or a VssError if the operation fails. + * + * # Example + * ``` + * let was_deleted = vss_delete("temp-data".to_string()).await?; + * if was_deleted { + * println!("Key was successfully deleted"); + * } else { + * println!("Key did not exist"); + * } + * ``` + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssDelete`(`key`: kotlin.String) : kotlin.Boolean { + return uniffiRustCallAsync( + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_delete(FfiConverterString.lower(`key`),), + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_i8(future, callback, continuation) }, { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_i8(future, continuation) }, { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_i8(future) }, // lift function @@ -2176,82 +1987,70 @@ suspend fun `vssDelete`(`key`: kotlin.String): kotlin.Boolean = // Error FFI converter VssException.ErrorHandler, ) + } -/** - * Derives a deterministic VSS store ID from a mnemonic and optional passphrase. - * - * This function creates a consistent store ID that can be used across devices for the same wallet. - * The store ID is derived using BIP32 key derivation at a specific VSS path, ensuring it's - * cryptographically secure and deterministic. - * - * # Parameters - * - `prefix`: A prefix to include in the store ID (e.g., "bitkit_v1_regtest") - * - `mnemonic`: BIP39 mnemonic phrase (12 or 24 words) - * - `passphrase`: Optional BIP39 passphrase - * - * # Returns - * A deterministic store ID string that combines the prefix with a derived identifier. - * - * # Example - * ``` - * let store_id = vss_derive_store_id( - * "bitkit_v1_regtest".to_string(), - * "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about".to_string(), - * None - * )?; - * println!("Store ID: {}", store_id); - * ``` - */ -@Throws(VssException::class) -fun `vssDeriveStoreId`( - `prefix`: kotlin.String, - `mnemonic`: kotlin.String, - `passphrase`: kotlin.String?, -): kotlin.String = - FfiConverterString.lift( - uniffiRustCallWithError(VssException) { _status -> - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_derive_store_id( - FfiConverterString.lower(`prefix`), - FfiConverterString.lower(`mnemonic`), - FfiConverterOptionalString.lower(`passphrase`), - _status, - ) - }, + /** + * Derives a deterministic VSS store ID from a mnemonic and optional passphrase. + * + * This function creates a consistent store ID that can be used across devices for the same wallet. + * The store ID is derived using BIP32 key derivation at a specific VSS path, ensuring it's + * cryptographically secure and deterministic. + * + * # Parameters + * - `prefix`: A prefix to include in the store ID (e.g., "bitkit_v1_regtest") + * - `mnemonic`: BIP39 mnemonic phrase (12 or 24 words) + * - `passphrase`: Optional BIP39 passphrase + * + * # Returns + * A deterministic store ID string that combines the prefix with a derived identifier. + * + * # Example + * ``` + * let store_id = vss_derive_store_id( + * "bitkit_v1_regtest".to_string(), + * "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about".to_string(), + * None + * )?; + * println!("Store ID: {}", store_id); + * ``` + */ + @Throws(VssException::class) fun `vssDeriveStoreId`(`prefix`: kotlin.String, `mnemonic`: kotlin.String, `passphrase`: kotlin.String?): kotlin.String { + return FfiConverterString.lift( + uniffiRustCallWithError(VssException) { _status -> + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_derive_store_id( + FfiConverterString.lower(`prefix`),FfiConverterString.lower(`mnemonic`),FfiConverterOptionalString.lower(`passphrase`),_status) +} ) - -/** - * Retrieves a value by key from the VSS server. - * - * This function fetches the current version of the data associated with the given key. - * Returns None if the key does not exist. - * - * # Parameters - * - `key`: The key to retrieve - * - * # Returns - * An Option containing the VssItem if found, None if the key doesn't exist, - * or a VssError if the operation fails. - * - * # Example - * ``` - * match vss_get("user-settings".to_string()).await? { - * Some(item) => println!("Found data with version: {}", item.version), - * None => println!("Key not found") - * } - * ``` - */ -@Throws(VssException::class) -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssGet`(`key`: kotlin.String): VssItem? = - uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_get(FfiConverterString.lower(`key`)), - { - future, - callback, - continuation, - -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) - }, + } + + + /** + * Retrieves a value by key from the VSS server. + * + * This function fetches the current version of the data associated with the given key. + * Returns None if the key does not exist. + * + * # Parameters + * - `key`: The key to retrieve + * + * # Returns + * An Option containing the VssItem if found, None if the key doesn't exist, + * or a VssError if the operation fails. + * + * # Example + * ``` + * match vss_get("user-settings".to_string()).await? { + * Some(item) => println!("Found data with version: {}", item.version), + * None => println!("Key not found") + * } + * ``` + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssGet`(`key`: kotlin.String) : VssItem? { + return uniffiRustCallAsync( + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_get(FfiConverterString.lower(`key`),), + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) }, { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, // lift function @@ -2259,28 +2058,17 @@ suspend fun `vssGet`(`key`: kotlin.String): VssItem? = // Error FFI converter VssException.ErrorHandler, ) + } -/** - * Deletes a key-value pair using the dedicated LDK client. - */ -@Throws(VssException::class) -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssLdkDelete`( - `key`: kotlin.String, - `namespace`: LdkNamespace, -): kotlin.Boolean = - uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_ldk_delete( - FfiConverterString.lower(`key`), - FfiConverterTypeLdkNamespace.lower(`namespace`), - ), - { - future, - callback, - continuation, - -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_i8(future, callback, continuation) - }, + /** + * Deletes a key-value pair using the dedicated LDK client. + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssLdkDelete`(`key`: kotlin.String, `namespace`: LdkNamespace) : kotlin.Boolean { + return uniffiRustCallAsync( + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_ldk_delete(FfiConverterString.lower(`key`),FfiConverterTypeLdkNamespace.lower(`namespace`),), + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_i8(future, callback, continuation) }, { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_i8(future, continuation) }, { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_i8(future) }, // lift function @@ -2288,28 +2076,17 @@ suspend fun `vssLdkDelete`( // Error FFI converter VssException.ErrorHandler, ) + } -/** - * Retrieves a value by key using the dedicated LDK client. - */ -@Throws(VssException::class) -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssLdkGet`( - `key`: kotlin.String, - `namespace`: LdkNamespace, -): VssItem? = - uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_ldk_get( - FfiConverterString.lower(`key`), - FfiConverterTypeLdkNamespace.lower(`namespace`), - ), - { - future, - callback, - continuation, - -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) - }, + /** + * Retrieves a value by key using the dedicated LDK client. + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssLdkGet`(`key`: kotlin.String, `namespace`: LdkNamespace) : VssItem? { + return uniffiRustCallAsync( + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_ldk_get(FfiConverterString.lower(`key`),FfiConverterTypeLdkNamespace.lower(`namespace`),), + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) }, { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, // lift function @@ -2317,22 +2094,17 @@ suspend fun `vssLdkGet`( // Error FFI converter VssException.ErrorHandler, ) + } -/** - * Lists all LDK keys across all namespaces using the dedicated LDK client. - */ -@Throws(VssException::class) -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssLdkListAllKeys`(): List = - uniffiRustCallAsync( + /** + * Lists all LDK keys across all namespaces using the dedicated LDK client. + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssLdkListAllKeys`() : List { + return uniffiRustCallAsync( UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_ldk_list_all_keys(), - { - future, - callback, - continuation, - -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) - }, + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) }, { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, // lift function @@ -2340,22 +2112,17 @@ suspend fun `vssLdkListAllKeys`(): List = // Error FFI converter VssException.ErrorHandler, ) + } -/** - * Lists keys in a namespace using the dedicated LDK client. - */ -@Throws(VssException::class) -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssLdkListKeys`(`namespace`: LdkNamespace): List = - uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_ldk_list_keys(FfiConverterTypeLdkNamespace.lower(`namespace`)), - { - future, - callback, - continuation, - -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) - }, + /** + * Lists keys in a namespace using the dedicated LDK client. + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssLdkListKeys`(`namespace`: LdkNamespace) : List { + return uniffiRustCallAsync( + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_ldk_list_keys(FfiConverterTypeLdkNamespace.lower(`namespace`),), + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) }, { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, // lift function @@ -2363,30 +2130,17 @@ suspend fun `vssLdkListKeys`(`namespace`: LdkNamespace): List = // Error FFI converter VssException.ErrorHandler, ) + } -/** - * Stores a key-value pair using the dedicated LDK client. - */ -@Throws(VssException::class) -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssLdkStore`( - `key`: kotlin.String, - `value`: kotlin.ByteArray, - `namespace`: LdkNamespace, -): VssItem = - uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_ldk_store( - FfiConverterString.lower(`key`), - FfiConverterByteArray.lower(`value`), - FfiConverterTypeLdkNamespace.lower(`namespace`), - ), - { - future, - callback, - continuation, - -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) - }, + /** + * Stores a key-value pair using the dedicated LDK client. + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssLdkStore`(`key`: kotlin.String, `value`: kotlin.ByteArray, `namespace`: LdkNamespace) : VssItem { + return uniffiRustCallAsync( + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_ldk_store(FfiConverterString.lower(`key`),FfiConverterByteArray.lower(`value`),FfiConverterTypeLdkNamespace.lower(`namespace`),), + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) }, { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, // lift function @@ -2394,42 +2148,37 @@ suspend fun `vssLdkStore`( // Error FFI converter VssException.ErrorHandler, ) + } -/** - * Lists all items in the store, optionally filtered by key prefix. - * - * This function retrieves both keys and their associated values/versions. - * It's useful for browsing stored data but can be expensive for large datasets. - * - * # Parameters - * - `prefix`: Optional key prefix filter (e.g., "user/" to get all user keys). - * If None or empty, returns all items. - * - * # Returns - * A vector of VssItems containing all matching key-value pairs, - * or a VssError if the operation fails. - * - * # Example - * ``` - * // List all items with keys starting with "config/" - * let items = vss_list(Some("config/".to_string())).await?; - * for item in items { - * println!("Key: {}, Version: {}", item.key, item.version); - * } - * ``` - */ -@Throws(VssException::class) -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssList`(`prefix`: kotlin.String?): List = - uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_list(FfiConverterOptionalString.lower(`prefix`)), - { - future, - callback, - continuation, - -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) - }, + /** + * Lists all items in the store, optionally filtered by key prefix. + * + * This function retrieves both keys and their associated values/versions. + * It's useful for browsing stored data but can be expensive for large datasets. + * + * # Parameters + * - `prefix`: Optional key prefix filter (e.g., "user/" to get all user keys). + * If None or empty, returns all items. + * + * # Returns + * A vector of VssItems containing all matching key-value pairs, + * or a VssError if the operation fails. + * + * # Example + * ``` + * // List all items with keys starting with "config/" + * let items = vss_list(Some("config/".to_string())).await?; + * for item in items { + * println!("Key: {}, Version: {}", item.key, item.version); + * } + * ``` + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssList`(`prefix`: kotlin.String?) : List { + return uniffiRustCallAsync( + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_list(FfiConverterOptionalString.lower(`prefix`),), + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) }, { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, // lift function @@ -2437,42 +2186,37 @@ suspend fun `vssList`(`prefix`: kotlin.String?): List = // Error FFI converter VssException.ErrorHandler, ) + } -/** - * Lists keys and their versions without retrieving the actual values. - * - * This function is more efficient than `vss_list` when you only need to know - * what keys exist and their versions, without downloading the actual data. - * - * # Parameters - * - `prefix`: Optional key prefix filter (e.g., "user/" to get all user keys). - * If None or empty, returns all keys. - * - * # Returns - * A vector of KeyVersion structs containing key names and version numbers, - * or a VssError if the operation fails. - * - * # Example - * ``` - * // List all keys starting with "temp/" - * let keys = vss_list_keys(Some("temp/".to_string())).await?; - * for kv in keys { - * println!("Key: {} is at version: {}", kv.key, kv.version); - * } - * ``` - */ -@Throws(VssException::class) -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssListKeys`(`prefix`: kotlin.String?): List = - uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_list_keys(FfiConverterOptionalString.lower(`prefix`)), - { - future, - callback, - continuation, - -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) - }, + /** + * Lists keys and their versions without retrieving the actual values. + * + * This function is more efficient than `vss_list` when you only need to know + * what keys exist and their versions, without downloading the actual data. + * + * # Parameters + * - `prefix`: Optional key prefix filter (e.g., "user/" to get all user keys). + * If None or empty, returns all keys. + * + * # Returns + * A vector of KeyVersion structs containing key names and version numbers, + * or a VssError if the operation fails. + * + * # Example + * ``` + * // List all keys starting with "temp/" + * let keys = vss_list_keys(Some("temp/".to_string())).await?; + * for kv in keys { + * println!("Key: {} is at version: {}", kv.key, kv.version); + * } + * ``` + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssListKeys`(`prefix`: kotlin.String?) : List { + return uniffiRustCallAsync( + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_list_keys(FfiConverterOptionalString.lower(`prefix`),), + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) }, { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, // lift function @@ -2480,183 +2224,129 @@ suspend fun `vssListKeys`(`prefix`: kotlin.String?): List = // Error FFI converter VssException.ErrorHandler, ) + } -/** - * Creates a new VSS (Versioned Storage Service) client without authentication. - * - * This function establishes a connection to a VSS server and initializes - * the global client for subsequent VSS operations. - * - * # Parameters - * - `base_url`: The base URL of the VSS server (e.g., "https://vss.example.com") - * - `store_id`: A unique identifier for the storage namespace/keyspace - * - * # Returns - * Ok(()) if the client was created successfully, or a VssError if the client creation fails. - * - * # Example - * ``` - * vss_new_client( - * "https://vss.example.com".to_string(), - * "my-app-store".to_string() - * ).await?; - * ``` - */ -@Throws(VssException::class) -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssNewClient`( - `baseUrl`: kotlin.String, - `storeId`: kotlin.String, -) = uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_new_client( - FfiConverterString.lower(`baseUrl`), - FfiConverterString.lower(`storeId`), - ), - { - future, - callback, - continuation, - -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_void(future, callback, continuation) - }, - { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_void(future, continuation) }, - { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_void(future) }, - // lift function - { Unit }, - // Error FFI converter - VssException.ErrorHandler, -) + /** + * Creates a new VSS client without authentication. + * + * This constructor is rejected. Unauthenticated VSS previously encrypted + * application data with a public all-zero key, which provides no confidentiality. + * Use [`vss_new_client_with_lnurl_auth`] so backup data is encrypted with a + * seed-derived key. + * + * # Returns + * Always returns [`VssError::AuthError`]. + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssNewClient`(`baseUrl`: kotlin.String, `storeId`: kotlin.String) { + return uniffiRustCallAsync( + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_new_client(FfiConverterString.lower(`baseUrl`),FfiConverterString.lower(`storeId`),), + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_void(future, callback, continuation) }, + { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_void(future, continuation) }, + { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_void(future) }, + // lift function + { Unit }, + + // Error FFI converter + VssException.ErrorHandler, + ) + } -/** - * Creates a new VSS (Versioned Storage Service) client with LNURL-auth using a BIP39 mnemonic. - * - * This function establishes a connection to a VSS server using LNURL-auth - * for authentication. - * - * # Parameters - * - `base_url`: The base URL of the VSS server - * - `store_id`: A unique identifier for the storage namespace/keyspace - * - `mnemonic`: BIP39 mnemonic phrase (12 or 24 words) - * - `passphrase`: Optional BIP39 passphrase - * - `lnurl_auth_server_url`: The LNURL-auth server URL for authentication - * - * # Returns - * Ok(()) if the client was created successfully, or a VssError if the client creation fails. - * - * # Example - * ``` - * vss_new_client_with_lnurl_auth( - * "https://vss.example.com".to_string(), - * "my-app-store".to_string(), - * "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about".to_string(), - * None, - * "https://auth.example.com/lnurl".to_string() - * ).await?; - * ``` - */ -@Throws(VssException::class) -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssNewClientWithLnurlAuth`( - `baseUrl`: kotlin.String, - `storeId`: kotlin.String, - `mnemonic`: kotlin.String, - `passphrase`: kotlin.String?, - `lnurlAuthServerUrl`: kotlin.String, -) = uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_new_client_with_lnurl_auth( - FfiConverterString.lower(`baseUrl`), - FfiConverterString.lower(`storeId`), - FfiConverterString.lower(`mnemonic`), - FfiConverterOptionalString.lower(`passphrase`), - FfiConverterString.lower(`lnurlAuthServerUrl`), - ), - { - future, - callback, - continuation, - -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_void(future, callback, continuation) - }, - { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_void(future, continuation) }, - { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_void(future) }, - // lift function - { Unit }, - // Error FFI converter - VssException.ErrorHandler, -) + /** + * Creates a new VSS (Versioned Storage Service) client with LNURL-auth using a BIP39 mnemonic. + * + * This function establishes a connection to a VSS server using LNURL-auth + * for authentication. + * + * # Parameters + * - `base_url`: The base URL of the VSS server + * - `store_id`: A unique identifier for the storage namespace/keyspace + * - `mnemonic`: BIP39 mnemonic phrase (12 or 24 words) + * - `passphrase`: Optional BIP39 passphrase + * - `lnurl_auth_server_url`: The LNURL-auth server URL for authentication + * + * # Returns + * Ok(()) if the client was created successfully, or a VssError if the client creation fails. + * + * # Example + * ``` + * vss_new_client_with_lnurl_auth( + * "https://vss.example.com".to_string(), + * "my-app-store".to_string(), + * "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about".to_string(), + * None, + * "https://auth.example.com/lnurl".to_string() + * ).await?; + * ``` + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssNewClientWithLnurlAuth`(`baseUrl`: kotlin.String, `storeId`: kotlin.String, `mnemonic`: kotlin.String, `passphrase`: kotlin.String?, `lnurlAuthServerUrl`: kotlin.String) { + return uniffiRustCallAsync( + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_new_client_with_lnurl_auth(FfiConverterString.lower(`baseUrl`),FfiConverterString.lower(`storeId`),FfiConverterString.lower(`mnemonic`),FfiConverterOptionalString.lower(`passphrase`),FfiConverterString.lower(`lnurlAuthServerUrl`),), + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_void(future, callback, continuation) }, + { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_void(future, continuation) }, + { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_void(future) }, + // lift function + { Unit }, + + // Error FFI converter + VssException.ErrorHandler, + ) + } -/** - * Creates a new dedicated LDK VSS client with LNURL-auth. - * - * This client uses ONLY ldk-node's key derivation chain (full 64-byte seed), - * completely separate from the app backup client. - */ -@Throws(VssException::class) -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssNewLdkClientWithLnurlAuth`( - `baseUrl`: kotlin.String, - `storeId`: kotlin.String, - `mnemonic`: kotlin.String, - `passphrase`: kotlin.String?, - `lnurlAuthServerUrl`: kotlin.String, -) = uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_new_ldk_client_with_lnurl_auth( - FfiConverterString.lower(`baseUrl`), - FfiConverterString.lower(`storeId`), - FfiConverterString.lower(`mnemonic`), - FfiConverterOptionalString.lower(`passphrase`), - FfiConverterString.lower(`lnurlAuthServerUrl`), - ), - { - future, - callback, - continuation, - -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_void(future, callback, continuation) - }, - { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_void(future, continuation) }, - { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_void(future) }, - // lift function - { Unit }, - // Error FFI converter - VssException.ErrorHandler, -) + /** + * Creates a new dedicated LDK VSS client with LNURL-auth. + * + * This client uses ONLY ldk-node's key derivation chain (full 64-byte seed), + * completely separate from the app backup client. + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssNewLdkClientWithLnurlAuth`(`baseUrl`: kotlin.String, `storeId`: kotlin.String, `mnemonic`: kotlin.String, `passphrase`: kotlin.String?, `lnurlAuthServerUrl`: kotlin.String) { + return uniffiRustCallAsync( + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_new_ldk_client_with_lnurl_auth(FfiConverterString.lower(`baseUrl`),FfiConverterString.lower(`storeId`),FfiConverterString.lower(`mnemonic`),FfiConverterOptionalString.lower(`passphrase`),FfiConverterString.lower(`lnurlAuthServerUrl`),), + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_void(future, callback, continuation) }, + { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_void(future, continuation) }, + { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_void(future) }, + // lift function + { Unit }, + + // Error FFI converter + VssException.ErrorHandler, + ) + } -/** - * Stores multiple key-value pairs in a single atomic transaction. - * - * This function allows batch storage of multiple items. All items will be - * stored together or the entire operation will fail, ensuring data consistency. - * - * # Parameters - * - `items`: A vector of KeyValue pairs to store - * - * # Returns - * A vector of VssItems representing the stored data with their assigned versions, - * or a VssError if the operation fails. - * - * # Example - * ``` - * let items_to_store = vec![ - * KeyValue { key: "config/theme".to_string(), value: vec![1, 0] }, - * KeyValue { key: "config/lang".to_string(), value: vec![2, 0] }, - * ]; - * let stored_items = vss_put_with_key_prefix(items_to_store).await?; - * println!("Stored {} items", stored_items.len()); - * ``` - */ -@Throws(VssException::class) -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssPutWithKeyPrefix`(`items`: List): List = - uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_put_with_key_prefix(FfiConverterSequenceTypeKeyValue.lower(`items`)), - { - future, - callback, - continuation, - -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) - }, + /** + * Stores multiple key-value pairs in a single atomic transaction. + * + * This function allows batch storage of multiple items. All items will be + * stored together or the entire operation will fail, ensuring data consistency. + * + * # Parameters + * - `items`: A vector of KeyValue pairs to store + * + * # Returns + * A vector of VssItems representing the stored data with their assigned versions, + * or a VssError if the operation fails. + * + * # Example + * ``` + * let items_to_store = vec![ + * KeyValue { key: "config/theme".to_string(), value: vec![1, 0] }, + * KeyValue { key: "config/lang".to_string(), value: vec![2, 0] }, + * ]; + * let stored_items = vss_put_with_key_prefix(items_to_store).await?; + * println!("Stored {} items", stored_items.len()); + * ``` + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssPutWithKeyPrefix`(`items`: List) : List { + return uniffiRustCallAsync( + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_put_with_key_prefix(FfiConverterSequenceTypeKeyValue.lower(`items`),), + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) }, { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, // lift function @@ -2664,72 +2354,67 @@ suspend fun `vssPutWithKeyPrefix`(`items`: List): List = // Error FFI converter VssException.ErrorHandler, ) - -/** - * Shuts down the VSS client and clears the global client state. - * - * This function is optional but recommended for clean shutdown in applications - * that want to explicitly release resources. - * - * # Example - * ``` - * vss_shutdown_client(); - * ``` - */ -fun `vssShutdownClient`() = - uniffiRustCall { _status -> - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_shutdown_client(_status) - } - -/** - * Shuts down the dedicated LDK VSS client. - */ -fun `vssShutdownLdkClient`() = - uniffiRustCall { _status -> - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_shutdown_ldk_client(_status) } -/** - * Stores a key-value pair in the VSS server. - * - * This function writes data to the VSS server. The server automatically - * manages versioning, incrementing the version number with each update. - * - * # Parameters - * - `key`: The unique key identifier for the data - * - `value`: The binary data to store - * - * # Returns - * A VssItem containing the stored key, value, and version number, - * or a VssError if the operation fails. - * - * # Example - * ``` - * let item = vss_store( - * "user-settings".to_string(), - * vec![1, 2, 3, 4] - * ).await?; - * println!("Stored at version: {}", item.version); - * ``` - */ -@Throws(VssException::class) -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssStore`( - `key`: kotlin.String, - `value`: kotlin.ByteArray, -): VssItem = - uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_store( - FfiConverterString.lower(`key`), - FfiConverterByteArray.lower(`value`), - ), - { - future, - callback, - continuation, - -> - UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) - }, + /** + * Shuts down the VSS client and clears the global client state. + * + * This function is optional but recommended for clean shutdown in applications + * that want to explicitly release resources. + * + * # Example + * ``` + * vss_shutdown_client(); + * ``` + */ fun `vssShutdownClient`() + = + uniffiRustCall() { _status -> + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_shutdown_client( + _status) +} + + + + /** + * Shuts down the dedicated LDK VSS client. + */ fun `vssShutdownLdkClient`() + = + uniffiRustCall() { _status -> + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_shutdown_ldk_client( + _status) +} + + + + /** + * Stores a key-value pair in the VSS server. + * + * This function writes data to the VSS server. The server automatically + * manages versioning, incrementing the version number with each update. + * + * # Parameters + * - `key`: The unique key identifier for the data + * - `value`: The binary data to store + * + * # Returns + * A VssItem containing the stored key, value, and version number, + * or a VssError if the operation fails. + * + * # Example + * ``` + * let item = vss_store( + * "user-settings".to_string(), + * vec![1, 2, 3, 4] + * ).await?; + * println!("Stored at version: {}", item.version); + * ``` + */ + @Throws(VssException::class) + @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") + suspend fun `vssStore`(`key`: kotlin.String, `value`: kotlin.ByteArray) : VssItem { + return uniffiRustCallAsync( + UniffiLib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_store(FfiConverterString.lower(`key`),FfiConverterByteArray.lower(`value`),), + { future, callback, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, callback, continuation) }, { future, continuation -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, { future -> UniffiLib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, // lift function @@ -2737,3 +2422,6 @@ suspend fun `vssStore`( // Error FFI converter VssException.ErrorHandler, ) + } + + diff --git a/bindings/ios/VssRustClientFfi.xcframework.zip b/bindings/ios/VssRustClientFfi.xcframework.zip index 8b56b42..4b11d74 100644 Binary files a/bindings/ios/VssRustClientFfi.xcframework.zip and b/bindings/ios/VssRustClientFfi.xcframework.zip differ diff --git a/bindings/ios/VssRustClientFfi.xcframework/ios-arm64-simulator/vss_rust_client_ffiFFI.framework/vss_rust_client_ffiFFI b/bindings/ios/VssRustClientFfi.xcframework/ios-arm64-simulator/vss_rust_client_ffiFFI.framework/vss_rust_client_ffiFFI index eb955b6..d5760bb 100644 Binary files a/bindings/ios/VssRustClientFfi.xcframework/ios-arm64-simulator/vss_rust_client_ffiFFI.framework/vss_rust_client_ffiFFI and b/bindings/ios/VssRustClientFfi.xcframework/ios-arm64-simulator/vss_rust_client_ffiFFI.framework/vss_rust_client_ffiFFI differ diff --git a/bindings/ios/VssRustClientFfi.xcframework/ios-arm64/vss_rust_client_ffiFFI.framework/vss_rust_client_ffiFFI b/bindings/ios/VssRustClientFfi.xcframework/ios-arm64/vss_rust_client_ffiFFI.framework/vss_rust_client_ffiFFI index 1a12f1e..0f3a0af 100644 Binary files a/bindings/ios/VssRustClientFfi.xcframework/ios-arm64/vss_rust_client_ffiFFI.framework/vss_rust_client_ffiFFI and b/bindings/ios/VssRustClientFfi.xcframework/ios-arm64/vss_rust_client_ffiFFI.framework/vss_rust_client_ffiFFI differ diff --git a/bindings/ios/vss_rust_client_ffi.swift b/bindings/ios/vss_rust_client_ffi.swift index faafc3b..3851460 100644 --- a/bindings/ios/vss_rust_client_ffi.swift +++ b/bindings/ios/vss_rust_client_ffi.swift @@ -1533,25 +1533,15 @@ public func vssListKeys(prefix: String?)async throws -> [KeyVersion] { ) } /** - * Creates a new VSS (Versioned Storage Service) client without authentication. + * Creates a new VSS client without authentication. * - * This function establishes a connection to a VSS server and initializes - * the global client for subsequent VSS operations. - * - * # Parameters - * - `base_url`: The base URL of the VSS server (e.g., "https://vss.example.com") - * - `store_id`: A unique identifier for the storage namespace/keyspace + * This constructor is rejected. Unauthenticated VSS previously encrypted + * application data with a public all-zero key, which provides no confidentiality. + * Use [`vss_new_client_with_lnurl_auth`] so backup data is encrypted with a + * seed-derived key. * * # Returns - * Ok(()) if the client was created successfully, or a VssError if the client creation fails. - * - * # Example - * ``` - * vss_new_client( - * "https://vss.example.com".to_string(), - * "my-app-store".to_string() - * ).await?; - * ``` + * Always returns [`VssError::AuthError`]. */ public func vssNewClient(baseUrl: String, storeId: String)async throws { return @@ -1772,7 +1762,7 @@ private let initializationResult: InitializationResult = { if (uniffi_vss_rust_client_ffi_checksum_func_vss_list_keys() != 21638) { return InitializationResult.apiChecksumMismatch } - if (uniffi_vss_rust_client_ffi_checksum_func_vss_new_client() != 63115) { + if (uniffi_vss_rust_client_ffi_checksum_func_vss_new_client() != 27788) { return InitializationResult.apiChecksumMismatch } if (uniffi_vss_rust_client_ffi_checksum_func_vss_new_client_with_lnurl_auth() != 13999) { diff --git a/bindings/python/README.md b/bindings/python/README.md index af6165d..02a1402 100644 --- a/bindings/python/README.md +++ b/bindings/python/README.md @@ -11,16 +11,23 @@ pip install . ## Usage ```python +import asyncio + from vss_rust_client_ffi import * -# Initialize VSS client -vss_new_client( - "https://vss.example.com", - "my-store", - None -) +async def main(): + # Initialize VSS with LNURL-auth so backups use a seed-derived encryption key + await vss_new_client_with_lnurl_auth( + "https://vss.example.com", + "my-store", + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", + None, + "https://auth.example.com/lnurl", + ) + + # Store data + item = await vss_store("my-key", b"my-data") + print(f"Stored at version: {item.version}") -# Store data -item = vss_store("my-key", b"my-data") -print(f"Stored at version: {item.version}") +asyncio.run(main()) ``` diff --git a/bindings/python/vss_rust_client_ffi/libvss_rust_client_ffi.dylib b/bindings/python/vss_rust_client_ffi/libvss_rust_client_ffi.dylib index 3197239..f812498 100755 Binary files a/bindings/python/vss_rust_client_ffi/libvss_rust_client_ffi.dylib and b/bindings/python/vss_rust_client_ffi/libvss_rust_client_ffi.dylib differ diff --git a/bindings/python/vss_rust_client_ffi/vss_rust_client_ffi.py b/bindings/python/vss_rust_client_ffi/vss_rust_client_ffi.py index ab4d317..707cec6 100644 --- a/bindings/python/vss_rust_client_ffi/vss_rust_client_ffi.py +++ b/bindings/python/vss_rust_client_ffi/vss_rust_client_ffi.py @@ -481,7 +481,7 @@ def _uniffi_check_api_checksums(lib): raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_vss_rust_client_ffi_checksum_func_vss_list_keys() != 21638: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_vss_rust_client_ffi_checksum_func_vss_new_client() != 63115: + if lib.uniffi_vss_rust_client_ffi_checksum_func_vss_new_client() != 27788: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_vss_rust_client_ffi_checksum_func_vss_new_client_with_lnurl_auth() != 13999: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") @@ -2167,25 +2167,15 @@ async def vss_list_keys(prefix: "typing.Optional[str]") -> "typing.List[KeyVersi async def vss_new_client(base_url: "str",store_id: "str") -> None: """ - Creates a new VSS (Versioned Storage Service) client without authentication. + Creates a new VSS client without authentication. - This function establishes a connection to a VSS server and initializes - the global client for subsequent VSS operations. - - # Parameters - - `base_url`: The base URL of the VSS server (e.g., "https://vss.example.com") - - `store_id`: A unique identifier for the storage namespace/keyspace + This constructor is rejected. Unauthenticated VSS previously encrypted + application data with a public all-zero key, which provides no confidentiality. + Use [`vss_new_client_with_lnurl_auth`] so backup data is encrypted with a + seed-derived key. # Returns - Ok(()) if the client was created successfully, or a VssError if the client creation fails. - - # Example - ``` - vss_new_client( - "https://vss.example.com".to_string(), - "my-app-store".to_string() - ).await?; - ``` + Always returns [`VssError::AuthError`]. """ _UniffiConverterString.check_lower(base_url) diff --git a/build_python.sh b/build_python.sh index ba4b52a..3751b64 100755 --- a/build_python.sh +++ b/build_python.sh @@ -136,18 +136,25 @@ pip install . ## Usage \`\`\`python -from vss_rust_client_ffi import * +import asyncio -# Initialize VSS client -vss_new_client( - "https://vss.example.com", - "my-store", - None -) +from vss_rust_client_ffi import * -# Store data -item = vss_store("my-key", b"my-data") -print(f"Stored at version: {item.version}") +async def main(): + # Initialize VSS with LNURL-auth so backups use a seed-derived encryption key + await vss_new_client_with_lnurl_auth( + "https://vss.example.com", + "my-store", + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", + None, + "https://auth.example.com/lnurl", + ) + + # Store data + item = await vss_store("my-key", b"my-data") + print(f"Stored at version: {item.version}") + +asyncio.run(main()) \`\`\` EOL @@ -166,4 +173,4 @@ case "$(uname)" in esac echo "Python build process completed successfully!" -echo "To install the package, cd into $BASE_DIR and run: pip install ." \ No newline at end of file +echo "To install the package, cd into $BASE_DIR and run: pip install ." diff --git a/src/ffi_tests.rs b/src/ffi_tests.rs index c8c277f..a88505b 100644 --- a/src/ffi_tests.rs +++ b/src/ffi_tests.rs @@ -1,74 +1,55 @@ #[cfg(test)] mod ffi_tests { use crate::*; - + // Unit tests for the FFI interface const MOCK_BASE_URL: &str = "https://vss.example.com"; const TEST_STORE_ID: &str = "test-store-ffi"; - + #[tokio::test] async fn test_ffi_client_lifecycle() { // Test that we can create and shutdown client without errors - let result = vss_new_client( - MOCK_BASE_URL.to_string(), - TEST_STORE_ID.to_string() - ).await; - - assert!(result.is_ok()); - - // Shutdown client - vss_shutdown_client(); + let result = vss_new_client(MOCK_BASE_URL.to_string(), TEST_STORE_ID.to_string()).await; + + assert!(matches!(result, Err(VssError::AuthError { .. }))); } - + #[tokio::test] async fn test_ffi_client() { - let result = vss_new_client( - MOCK_BASE_URL.to_string(), - TEST_STORE_ID.to_string() - ).await; - - assert!(result.is_ok()); - vss_shutdown_client(); + let result = vss_new_client(MOCK_BASE_URL.to_string(), TEST_STORE_ID.to_string()).await; + + assert!(matches!(result, Err(VssError::AuthError { .. }))); } - + #[tokio::test] async fn test_ffi_error_no_client() { // Don't initialize client, should get error let result = vss_get("any-key".to_string()).await; - + assert!(result.is_err()); match result { Err(VssError::ConnectionError { error_details }) => { assert!(error_details.contains("not initialized")); + assert!(error_details.contains("vss_new_client_with_lnurl_auth()")); } _ => panic!("Expected ConnectionError for uninitialized client"), } } - + #[tokio::test] async fn test_ffi_client_reinitialize() { - // Test that we can create, shutdown, and recreate client - vss_new_client( - MOCK_BASE_URL.to_string(), - TEST_STORE_ID.to_string() - ).await.expect("Failed to create first client"); - - vss_shutdown_client(); - - // Should be able to create again - let result = vss_new_client( - MOCK_BASE_URL.to_string(), - format!("{}-2", TEST_STORE_ID) - ).await; - - assert!(result.is_ok()); - vss_shutdown_client(); + let first = vss_new_client(MOCK_BASE_URL.to_string(), TEST_STORE_ID.to_string()).await; + assert!(matches!(first, Err(VssError::AuthError { .. }))); + + let second = + vss_new_client(MOCK_BASE_URL.to_string(), format!("{}-2", TEST_STORE_ID)).await; + assert!(matches!(second, Err(VssError::AuthError { .. }))); } - + /* // Integration tests for FFI functions would go here // These require a live VSS server - see tests.rs for setup instructions - + #[tokio::test] #[ignore = "requires live VSS server"] async fn integration_test_ffi_store_and_get() { @@ -77,26 +58,26 @@ mod ffi_tests { "your-store-id".to_string(), None ).await.expect("Failed to create client"); - + let key = format!("ffi-test-{}", std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .unwrap() .as_millis()); let value = b"ffi-test-value".to_vec(); - + let stored = vss_store(key.clone(), value.clone()).await .expect("Failed to store item"); - + assert_eq!(stored.key, key); assert_eq!(stored.value, value); - + let retrieved = vss_get(key).await .expect("Failed to get item") .expect("Item should exist"); - + assert_eq!(retrieved.value, value); - + vss_shutdown_client(); } */ -} \ No newline at end of file +} diff --git a/src/implementation.rs b/src/implementation.rs index 8fc9410..ab29992 100644 --- a/src/implementation.rs +++ b/src/implementation.rs @@ -1,5 +1,6 @@ use super::errors::VssError; use super::types::*; +use bip39::Mnemonic; use bitcoin::bip32::{ChildNumber, Xpriv}; use bitcoin::hashes::{sha256, Hash, HashEngine, Hmac, HmacEngine}; use bitcoin::secp256k1::Secp256k1; @@ -7,10 +8,11 @@ use bitcoin::Network; use prost::Message; use rand::RngCore; use std::collections::HashMap; +use std::str::FromStr; use std::sync::Arc; use vss_client_ng::client::VssClient as ExternalVssClient; use vss_client_ng::error::VssError as ExternalVssError; -use vss_client_ng::headers::{FixedHeaders, LnurlAuthToJwtProvider, VssHeaderProvider}; +use vss_client_ng::headers::{LnurlAuthToJwtProvider, VssHeaderProvider}; use vss_client_ng::types::{ DeleteObjectRequest, GetObjectRequest, KeyValue as ExternalKeyValue, ListKeyVersionsRequest, PutObjectRequest, Storable, @@ -21,8 +23,6 @@ use vss_client_ng::util::retry::{ MaxAttemptsRetryPolicy, MaxTotalDelayRetryPolicy, RetryPolicy, }; use vss_client_ng::util::storable_builder::{EntropySource, StorableBuilder}; -use bip39::Mnemonic; -use std::str::FromStr; pub(crate) const VSS_HARDENED_CHILD_INDEX: u32 = 877; pub(crate) const VSS_LNURL_AUTH_HARDENED_CHILD_INDEX: u32 = 138; @@ -68,8 +68,12 @@ pub fn derive_vss_store_id( .derive_priv( &secp, &[ - ChildNumber::Hardened { index: VSS_HARDENED_CHILD_INDEX }, - ChildNumber::Hardened { index: VSS_STORE_ID_HARDENED_CHILD_INDEX }, + ChildNumber::Hardened { + index: VSS_HARDENED_CHILD_INDEX, + }, + ChildNumber::Hardened { + index: VSS_STORE_ID_HARDENED_CHILD_INDEX, + }, ], ) .map_err(|e| VssError::ConnectionError { @@ -114,18 +118,13 @@ pub struct VssClient { } impl VssClient { - /// Creates a new VSS client instance. - /// - /// # Parameters - /// - `base_url`: The VSS server URL - /// - `store_id`: The storage namespace identifier - /// - /// # Returns - /// A new VssClient instance or VssError on failure + /// Unauthenticated VSS is rejected. Use [`Self::new_with_lnurl_auth`] so backup + /// data is encrypted with a seed-derived key. pub async fn new(base_url: String, store_id: String) -> Result { - let header_provider = Arc::new(FixedHeaders::new(HashMap::new())); - - Self::new_with_header_provider(base_url, store_id, header_provider, None).await + let _ = (base_url, store_id); + Err(VssError::AuthError { + error_details: "Unauthenticated VSS is not supported. Use LNURL-auth so backup data is encrypted with a seed-derived key.".to_string(), + }) } /// Creates a new VSS client instance with LNURL-auth. @@ -222,13 +221,12 @@ impl VssClient { let storable_builder = Arc::new(StorableBuilder::new(RandEntropySource)); - let (app_data_encryption_key, app_key_obfuscator) = if let Some(seed) = app_vss_seed { - let (dek, obfuscation_master_key) = - derive_data_encryption_and_obfuscation_keys(&seed); - (dek, Some(Arc::new(KeyObfuscator::new(obfuscation_master_key)))) - } else { - ([0u8; 32], None) - }; + let app_vss_seed = app_vss_seed.ok_or_else(|| VssError::AuthError { + error_details: "VSS encryption requires a seed-derived key.".to_string(), + })?; + let (app_data_encryption_key, obfuscation_master_key) = + derive_data_encryption_and_obfuscation_keys(&app_vss_seed); + let app_key_obfuscator = Some(Arc::new(KeyObfuscator::new(obfuscation_master_key))); Ok(VssClient { inner: Arc::new(client), @@ -288,10 +286,15 @@ impl VssClient { pub async fn get(&self, key: String) -> Result, VssError> { let storage_key = self.build_key(&key); - if let Some((value, version)) = - self.try_get_raw(&storage_key, &self.app_data_encryption_key).await? + if let Some((value, version)) = self + .try_get_raw(&storage_key, &self.app_data_encryption_key) + .await? { - return Ok(Some(VssItem { key, value, version })); + return Ok(Some(VssItem { + key, + value, + version, + })); } Ok(None) @@ -324,7 +327,8 @@ impl VssClient { /// Vector of KeyVersion structs (more efficient than list()) pub async fn list_keys(&self, prefix: Option) -> Result, VssError> { let storage_prefix = prefix.as_ref().map(|p| self.build_key(p)); - self.list_key_versions(storage_prefix, &self.app_key_obfuscator).await + self.list_key_versions(storage_prefix, &self.app_key_obfuscator) + .await } /// Stores multiple key-value pairs in an atomic transaction. @@ -408,10 +412,9 @@ impl VssClient { storage_key: &str, ) -> Result { if let Some(ref obfuscator) = key_obfuscator { - Self::try_deobfuscate(obfuscator, storage_key) - .ok_or_else(|| VssError::ListError { - error_details: "Failed to deobfuscate key".to_string(), - }) + Self::try_deobfuscate(obfuscator, storage_key).ok_or_else(|| VssError::ListError { + error_details: "Failed to deobfuscate key".to_string(), + }) } else { Ok(storage_key.to_string()) } @@ -536,7 +539,9 @@ impl VssClient { } /// Derives data encryption and obfuscation keys from VSS seed -pub(crate) fn derive_data_encryption_and_obfuscation_keys(vss_seed: &[u8; 32]) -> ([u8; 32], [u8; 32]) { +pub(crate) fn derive_data_encryption_and_obfuscation_keys( + vss_seed: &[u8; 32], +) -> ([u8; 32], [u8; 32]) { let hkdf = |initial_key_material: &[u8], salt: &[u8]| -> [u8; 32] { let mut engine = HmacEngine::::new(salt); engine.input(initial_key_material); @@ -559,11 +564,15 @@ pub(crate) fn derive_data_encryption_and_obfuscation_keys(vss_seed: &[u8; 32]) - /// Internal VssError with appropriate error details pub(crate) fn convert_error(error: ExternalVssError, _operation: &str) -> VssError { match error { - ExternalVssError::NoSuchKeyError(msg) => VssError::GetError { error_details: format!("Not found: {}", msg) }, + ExternalVssError::NoSuchKeyError(msg) => VssError::GetError { + error_details: format!("Not found: {}", msg), + }, ExternalVssError::InternalServerError(msg) => VssError::NetworkError { error_details: msg }, ExternalVssError::InvalidRequestError(msg) => VssError::InvalidData { error_details: msg }, ExternalVssError::InternalError(msg) => VssError::UnknownError { error_details: msg }, - ExternalVssError::ConflictError(msg) => VssError::StoreError { error_details: format!("Conflict: {}", msg) }, + ExternalVssError::ConflictError(msg) => VssError::StoreError { + error_details: format!("Conflict: {}", msg), + }, ExternalVssError::AuthError(msg) => VssError::AuthError { error_details: msg }, } } diff --git a/src/lib.rs b/src/lib.rs index 12d93c0..b65b419 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ mod tests; mod types; pub use errors::*; -pub use implementation::{VssClient, derive_vss_store_id}; +pub use implementation::{derive_vss_store_id, VssClient}; pub use ldk_client::LdkVssClient; pub use types::*; @@ -56,30 +56,22 @@ fn try_get_client() -> Result { guard .as_ref() .ok_or(VssError::ConnectionError { - error_details: "VSS client not initialized. Call vss_new_client() first.".to_string(), + error_details: + "VSS client not initialized. Call vss_new_client_with_lnurl_auth() first." + .to_string(), }) .cloned() } -/// Creates a new VSS (Versioned Storage Service) client without authentication. +/// Creates a new VSS client without authentication. /// -/// This function establishes a connection to a VSS server and initializes -/// the global client for subsequent VSS operations. -/// -/// # Parameters -/// - `base_url`: The base URL of the VSS server (e.g., "https://vss.example.com") -/// - `store_id`: A unique identifier for the storage namespace/keyspace +/// This constructor is rejected. Unauthenticated VSS previously encrypted +/// application data with a public all-zero key, which provides no confidentiality. +/// Use [`vss_new_client_with_lnurl_auth`] so backup data is encrypted with a +/// seed-derived key. /// /// # Returns -/// Ok(()) if the client was created successfully, or a VssError if the client creation fails. -/// -/// # Example -/// ``` -/// vss_new_client( -/// "https://vss.example.com".to_string(), -/// "my-app-store".to_string() -/// ).await?; -/// ``` +/// Always returns [`VssError::AuthError`]. #[uniffi::export] pub async fn vss_new_client(base_url: String, store_id: String) -> Result<(), VssError> { execute_async!(async move { @@ -138,8 +130,7 @@ pub async fn vss_new_client_with_lnurl_auth( }; let client = - VssClient::new_with_lnurl_auth(base_url, store_id, seed, lnurl_auth_server_url) - .await?; + VssClient::new_with_lnurl_auth(base_url, store_id, seed, lnurl_auth_server_url).await?; let storage = get_vss_client(); let mut guard = storage.lock().unwrap(); @@ -172,10 +163,7 @@ pub async fn vss_new_client_with_lnurl_auth( /// println!("Stored at version: {}", item.version); /// ``` #[uniffi::export] -pub async fn vss_store( - key: String, - value: Vec -) -> Result { +pub async fn vss_store(key: String, value: Vec) -> Result { execute_async!(async move { let client = try_get_client()?; client.store(key, value).await @@ -202,9 +190,7 @@ pub async fn vss_store( /// } /// ``` #[uniffi::export] -pub async fn vss_get( - key: String -) -> Result, VssError> { +pub async fn vss_get(key: String) -> Result, VssError> { execute_async!(async move { let client = try_get_client()?; client.get(key).await @@ -233,9 +219,7 @@ pub async fn vss_get( /// } /// ``` #[uniffi::export] -pub async fn vss_list( - prefix: Option -) -> Result, VssError> { +pub async fn vss_list(prefix: Option) -> Result, VssError> { execute_async!(async move { let client = try_get_client()?; client.list(prefix).await @@ -264,9 +248,7 @@ pub async fn vss_list( /// } /// ``` #[uniffi::export] -pub async fn vss_list_keys( - prefix: Option -) -> Result, VssError> { +pub async fn vss_list_keys(prefix: Option) -> Result, VssError> { execute_async!(async move { let client = try_get_client()?; client.list_keys(prefix).await @@ -295,9 +277,7 @@ pub async fn vss_list_keys( /// println!("Stored {} items", stored_items.len()); /// ``` #[uniffi::export] -pub async fn vss_put_with_key_prefix( - items: Vec -) -> Result, VssError> { +pub async fn vss_put_with_key_prefix(items: Vec) -> Result, VssError> { execute_async!(async move { let client = try_get_client()?; client.put_with_key_prefix(items).await @@ -326,9 +306,7 @@ pub async fn vss_put_with_key_prefix( /// } /// ``` #[uniffi::export] -pub async fn vss_delete( - key: String -) -> Result { +pub async fn vss_delete(key: String) -> Result { execute_async!(async move { let client = try_get_client()?; client.delete(key).await @@ -384,7 +362,6 @@ pub fn vss_shutdown_client() { } } - // --- Dedicated LDK client --- fn get_ldk_client() -> &'static Arc>> { @@ -397,7 +374,9 @@ fn try_get_ldk_client() -> Result { guard .as_ref() .ok_or(VssError::ConnectionError { - error_details: "LDK VSS client not initialized. Call vss_new_ldk_client_with_lnurl_auth() first.".to_string(), + error_details: + "LDK VSS client not initialized. Call vss_new_ldk_client_with_lnurl_auth() first." + .to_string(), }) .cloned() } @@ -473,10 +452,7 @@ pub async fn vss_ldk_store( /// Deletes a key-value pair using the dedicated LDK client. #[uniffi::export] -pub async fn vss_ldk_delete( - key: String, - namespace: LdkNamespace, -) -> Result { +pub async fn vss_ldk_delete(key: String, namespace: LdkNamespace) -> Result { execute_async!(async move { let client = try_get_ldk_client()?; client.delete(key, &namespace).await @@ -485,9 +461,7 @@ pub async fn vss_ldk_delete( /// Lists keys in a namespace using the dedicated LDK client. #[uniffi::export] -pub async fn vss_ldk_list_keys( - namespace: LdkNamespace, -) -> Result, VssError> { +pub async fn vss_ldk_list_keys(namespace: LdkNamespace) -> Result, VssError> { execute_async!(async move { let client = try_get_ldk_client()?; client.list_keys(&namespace).await @@ -502,5 +476,3 @@ pub async fn vss_ldk_list_all_keys() -> Result, VssError> { client.list_all_keys().await }) } - - diff --git a/src/tests.rs b/src/tests.rs index eac239f..a40e52c 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -12,34 +12,23 @@ mod tests { #[tokio::test] async fn test_vss_client_creation() { - let result = VssClient::new( - MOCK_BASE_URL.to_string(), - TEST_STORE_ID.to_string() - ).await; + let result = VssClient::new(MOCK_BASE_URL.to_string(), TEST_STORE_ID.to_string()).await; - assert!(result.is_ok()); + assert!(matches!(result, Err(VssError::AuthError { .. }))); } #[tokio::test] async fn test_vss_client_creation_empty_base_url() { - let result = VssClient::new( - "".to_string(), - TEST_STORE_ID.to_string(), - ).await; + let result = VssClient::new("".to_string(), TEST_STORE_ID.to_string()).await; - // Should still create client successfully, errors happen on actual operations - assert!(result.is_ok()); + assert!(matches!(result, Err(VssError::AuthError { .. }))); } #[tokio::test] async fn test_vss_client_creation_empty_store_id() { - let result = VssClient::new( - MOCK_BASE_URL.to_string(), - "".to_string(), - ).await; + let result = VssClient::new(MOCK_BASE_URL.to_string(), "".to_string()).await; - // Should still create client successfully, errors happen on actual operations - assert!(result.is_ok()); + assert!(matches!(result, Err(VssError::AuthError { .. }))); } #[tokio::test] @@ -49,8 +38,9 @@ mod tests { MOCK_BASE_URL.to_string(), TEST_STORE_ID.to_string(), seed, - "https://auth.example.com/lnurl".to_string() - ).await; + "https://auth.example.com/lnurl".to_string(), + ) + .await; // Should create client successfully (auth errors happen on actual requests) assert!(result.is_ok()); @@ -62,13 +52,13 @@ mod tests { // Test that our error types can be created let connection_err = VssError::ConnectionError { - error_details: "Test connection error".to_string() + error_details: "Test connection error".to_string(), }; let store_err = VssError::StoreError { - error_details: "Test store error".to_string() + error_details: "Test store error".to_string(), }; let get_err = VssError::GetError { - error_details: "Test get error".to_string() + error_details: "Test get error".to_string(), }; // Test error display @@ -91,7 +81,9 @@ mod tests { assert!(store_id1.starts_with("test_")); // Test passphrase handling - let with_passphrase = vss_derive_store_id(prefix.clone(), mnemonic.clone(), Some("pass".to_string())).unwrap(); + let with_passphrase = + vss_derive_store_id(prefix.clone(), mnemonic.clone(), Some("pass".to_string())) + .unwrap(); assert_ne!(store_id1, with_passphrase); // Test invalid mnemonic @@ -100,10 +92,10 @@ mod tests { #[tokio::test] async fn test_key_derivation_app_differs_from_ldk() { + use crate::implementation::derive_data_encryption_and_obfuscation_keys; use bitcoin::bip32::{ChildNumber, Xpriv}; use bitcoin::secp256k1::Secp256k1; use bitcoin::Network; - use crate::implementation::derive_data_encryption_and_obfuscation_keys; let full_seed: [u8; 64] = [42u8; 64]; let truncated_seed: [u8; 32] = full_seed[..32].try_into().unwrap(); @@ -149,15 +141,10 @@ mod tests { } #[tokio::test] - async fn test_client_without_auth_has_no_keys() { - let client = VssClient::new( - MOCK_BASE_URL.to_string(), - TEST_STORE_ID.to_string(), - ) - .await - .unwrap(); + async fn test_unauthenticated_client_is_rejected() { + let result = VssClient::new(MOCK_BASE_URL.to_string(), TEST_STORE_ID.to_string()).await; - assert!(client.app_key_obfuscator.is_none()); + assert!(matches!(result, Err(VssError::AuthError { .. }))); } #[tokio::test] @@ -196,10 +183,10 @@ mod tests { #[test] fn test_ldk_seed_derivation_is_network_independent() { + use bip39::Mnemonic; use bitcoin::bip32::{ChildNumber, Xpriv}; use bitcoin::secp256k1::Secp256k1; use bitcoin::Network; - use bip39::Mnemonic; use std::str::FromStr; let mnemonic = Mnemonic::from_str( @@ -229,11 +216,11 @@ mod tests { #[test] fn test_ldk_obfuscation_roundtrip() { + use crate::implementation::derive_data_encryption_and_obfuscation_keys; + use bip39::Mnemonic; use bitcoin::bip32::{ChildNumber, Xpriv}; use bitcoin::secp256k1::Secp256k1; use bitcoin::Network; - use bip39::Mnemonic; - use crate::implementation::derive_data_encryption_and_obfuscation_keys; use std::str::FromStr; use vss_client_ng::util::key_obfuscator::KeyObfuscator; @@ -289,7 +276,7 @@ mod tests { #[test] fn test_types_creation() { - use crate::{VssItem, KeyValue, KeyVersion}; + use crate::{KeyValue, KeyVersion, VssItem}; // Test creating VssItem let item = VssItem { @@ -331,9 +318,11 @@ mod tests { #[tokio::test] #[ignore = "requires live VSS server"] async fn integration_test_store_and_get() { - let client = VssClient::new( + let client = VssClient::new_with_lnurl_auth( INTEGRATION_BASE_URL.to_string(), INTEGRATION_STORE_ID.to_string(), + [42u8; 64], + "https://your-lnurl-auth-server.com".to_string(), ).await.expect("Failed to create client"); let key = format!("integration-test-{}", std::time::SystemTime::now()