diff --git a/Cargo.toml b/Cargo.toml index a235dd9d..641186a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [workspace] members = [ - "crates/*", - "bindings/uniffi", + "crates/web5", + "bindings/uniffi", ] default-members = [ - "crates/*", + "crates/web5", ] resolver = "2" diff --git a/binded/kt/src/main/kotlin/web5/sdk/web5.kt b/binded/kt/src/main/kotlin/web5/sdk/web5.kt index 2809826a..09580f1a 100644 --- a/binded/kt/src/main/kotlin/web5/sdk/web5.kt +++ b/binded/kt/src/main/kotlin/web5/sdk/web5.kt @@ -30,14 +30,6 @@ import java.nio.CharBuffer import java.nio.charset.CodingErrorAction import java.util.concurrent.atomic.AtomicLong import java.util.concurrent.ConcurrentHashMap -import java.util.concurrent.atomic.AtomicBoolean -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 import java.nio.file.Files // This is a helper for safely working with byte buffers returned from the Rust code. @@ -64,7 +56,7 @@ open class RustBuffer : Structure() { 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_web5_rustbuffer_alloc(size.toLong(), status) + UniffiLib.INSTANCE.ffi_web5_uniffi_rustbuffer_alloc(size.toLong(), status) }.also { if(it.data == null) { throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})") @@ -80,7 +72,7 @@ open class RustBuffer : Structure() { } internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status -> - UniffiLib.INSTANCE.ffi_web5_rustbuffer_free(buf, status) + UniffiLib.INSTANCE.ffi_web5_uniffi_rustbuffer_free(buf, status) } } @@ -641,279 +633,6 @@ internal open class UniffiForeignFutureStructVoid( internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback { fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructVoid.UniffiByValue,) } -internal interface UniffiCallbackInterfaceKeyMethod0 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfaceKeyMethod1 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`uniffiOutReturn`: PointerByReference,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfaceKeyManagerMethod0 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfaceKeyManagerMethod1 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`curve`: RustBuffer.ByValue,`keyAlias`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfaceKeyManagerMethod2 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`keyAlias`: RustBuffer.ByValue,`uniffiOutReturn`: PointerByReference,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfaceKeyManagerMethod3 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`privateKeys`: RustBuffer.ByValue,`uniffiOutReturn`: Pointer,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfaceKeyManagerMethod4 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`keyAlias`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfaceKeyStoreMethod0 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfaceKeyStoreMethod1 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`curve`: RustBuffer.ByValue,`keyAlias`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfaceKeyStoreMethod2 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfaceKeyStoreMethod3 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`keyAlias`: RustBuffer.ByValue,`uniffiOutReturn`: PointerByReference,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfaceKeyStoreMethod4 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`privateKeys`: RustBuffer.ByValue,`uniffiOutReturn`: Pointer,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfaceKeyStoreMethod5 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`keyAlias`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfacePrivateKeyMethod0 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`payload`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfacePrivateKeyMethod1 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`uniffiOutReturn`: PointerByReference,uniffiCallStatus: UniffiRustCallStatus,) -} -internal interface UniffiCallbackInterfacePublicKeyMethod0 : com.sun.jna.Callback { - fun callback(`uniffiHandle`: Long,`payload`: RustBuffer.ByValue,`signature`: RustBuffer.ByValue,`uniffiOutReturn`: Pointer,uniffiCallStatus: UniffiRustCallStatus,) -} -@Structure.FieldOrder("alias", "jwk", "uniffiFree") -internal open class UniffiVTableCallbackInterfaceKey( - @JvmField internal var `alias`: UniffiCallbackInterfaceKeyMethod0? = null, - @JvmField internal var `jwk`: UniffiCallbackInterfaceKeyMethod1? = null, - @JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null, -) : Structure() { - class UniffiByValue( - `alias`: UniffiCallbackInterfaceKeyMethod0? = null, - `jwk`: UniffiCallbackInterfaceKeyMethod1? = null, - `uniffiFree`: UniffiCallbackInterfaceFree? = null, - ): UniffiVTableCallbackInterfaceKey(`alias`,`jwk`,`uniffiFree`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceKey) { - `alias` = other.`alias` - `jwk` = other.`jwk` - `uniffiFree` = other.`uniffiFree` - } - -} -@Structure.FieldOrder("exportPrivateKeys", "generatePrivateKey", "getPublicKey", "importPrivateKeys", "sign", "uniffiFree") -internal open class UniffiVTableCallbackInterfaceKeyManager( - @JvmField internal var `exportPrivateKeys`: UniffiCallbackInterfaceKeyManagerMethod0? = null, - @JvmField internal var `generatePrivateKey`: UniffiCallbackInterfaceKeyManagerMethod1? = null, - @JvmField internal var `getPublicKey`: UniffiCallbackInterfaceKeyManagerMethod2? = null, - @JvmField internal var `importPrivateKeys`: UniffiCallbackInterfaceKeyManagerMethod3? = null, - @JvmField internal var `sign`: UniffiCallbackInterfaceKeyManagerMethod4? = null, - @JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null, -) : Structure() { - class UniffiByValue( - `exportPrivateKeys`: UniffiCallbackInterfaceKeyManagerMethod0? = null, - `generatePrivateKey`: UniffiCallbackInterfaceKeyManagerMethod1? = null, - `getPublicKey`: UniffiCallbackInterfaceKeyManagerMethod2? = null, - `importPrivateKeys`: UniffiCallbackInterfaceKeyManagerMethod3? = null, - `sign`: UniffiCallbackInterfaceKeyManagerMethod4? = null, - `uniffiFree`: UniffiCallbackInterfaceFree? = null, - ): UniffiVTableCallbackInterfaceKeyManager(`exportPrivateKeys`,`generatePrivateKey`,`getPublicKey`,`importPrivateKeys`,`sign`,`uniffiFree`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceKeyManager) { - `exportPrivateKeys` = other.`exportPrivateKeys` - `generatePrivateKey` = other.`generatePrivateKey` - `getPublicKey` = other.`getPublicKey` - `importPrivateKeys` = other.`importPrivateKeys` - `sign` = other.`sign` - `uniffiFree` = other.`uniffiFree` - } - -} -@Structure.FieldOrder("exportPrivateKeys", "generateNew", "getAllAliases", "getPublicKey", "importPrivateKeys", "sign", "uniffiFree") -internal open class UniffiVTableCallbackInterfaceKeyStore( - @JvmField internal var `exportPrivateKeys`: UniffiCallbackInterfaceKeyStoreMethod0? = null, - @JvmField internal var `generateNew`: UniffiCallbackInterfaceKeyStoreMethod1? = null, - @JvmField internal var `getAllAliases`: UniffiCallbackInterfaceKeyStoreMethod2? = null, - @JvmField internal var `getPublicKey`: UniffiCallbackInterfaceKeyStoreMethod3? = null, - @JvmField internal var `importPrivateKeys`: UniffiCallbackInterfaceKeyStoreMethod4? = null, - @JvmField internal var `sign`: UniffiCallbackInterfaceKeyStoreMethod5? = null, - @JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null, -) : Structure() { - class UniffiByValue( - `exportPrivateKeys`: UniffiCallbackInterfaceKeyStoreMethod0? = null, - `generateNew`: UniffiCallbackInterfaceKeyStoreMethod1? = null, - `getAllAliases`: UniffiCallbackInterfaceKeyStoreMethod2? = null, - `getPublicKey`: UniffiCallbackInterfaceKeyStoreMethod3? = null, - `importPrivateKeys`: UniffiCallbackInterfaceKeyStoreMethod4? = null, - `sign`: UniffiCallbackInterfaceKeyStoreMethod5? = null, - `uniffiFree`: UniffiCallbackInterfaceFree? = null, - ): UniffiVTableCallbackInterfaceKeyStore(`exportPrivateKeys`,`generateNew`,`getAllAliases`,`getPublicKey`,`importPrivateKeys`,`sign`,`uniffiFree`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceKeyStore) { - `exportPrivateKeys` = other.`exportPrivateKeys` - `generateNew` = other.`generateNew` - `getAllAliases` = other.`getAllAliases` - `getPublicKey` = other.`getPublicKey` - `importPrivateKeys` = other.`importPrivateKeys` - `sign` = other.`sign` - `uniffiFree` = other.`uniffiFree` - } - -} -@Structure.FieldOrder("sign", "toPublic", "uniffiFree") -internal open class UniffiVTableCallbackInterfacePrivateKey( - @JvmField internal var `sign`: UniffiCallbackInterfacePrivateKeyMethod0? = null, - @JvmField internal var `toPublic`: UniffiCallbackInterfacePrivateKeyMethod1? = null, - @JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null, -) : Structure() { - class UniffiByValue( - `sign`: UniffiCallbackInterfacePrivateKeyMethod0? = null, - `toPublic`: UniffiCallbackInterfacePrivateKeyMethod1? = null, - `uniffiFree`: UniffiCallbackInterfaceFree? = null, - ): UniffiVTableCallbackInterfacePrivateKey(`sign`,`toPublic`,`uniffiFree`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiVTableCallbackInterfacePrivateKey) { - `sign` = other.`sign` - `toPublic` = other.`toPublic` - `uniffiFree` = other.`uniffiFree` - } - -} -@Structure.FieldOrder("verify", "uniffiFree") -internal open class UniffiVTableCallbackInterfacePublicKey( - @JvmField internal var `verify`: UniffiCallbackInterfacePublicKeyMethod0? = null, - @JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null, -) : Structure() { - class UniffiByValue( - `verify`: UniffiCallbackInterfacePublicKeyMethod0? = null, - `uniffiFree`: UniffiCallbackInterfaceFree? = null, - ): UniffiVTableCallbackInterfacePublicKey(`verify`,`uniffiFree`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiVTableCallbackInterfacePublicKey) { - `verify` = other.`verify` - `uniffiFree` = other.`uniffiFree` - } - -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -992,353 +711,125 @@ internal interface UniffiLib : Library { } } - // The Cleaner for the whole library - internal val CLEANER: UniffiCleaner by lazy { - UniffiCleaner.create() - } } - fun uniffi_web5_fn_clone_bearerdid(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_free_bearerdid(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_method_bearerdid_sign(`ptr`: Pointer,`keySelector`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_clone_claims(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_free_claims(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_constructor_claims_new(`issuer`: RustBuffer.ByValue,`subject`: RustBuffer.ByValue,`audience`: RustBuffer.ByValue,`expiration`: RustBuffer.ByValue,`notBefore`: RustBuffer.ByValue,`issuedAt`: RustBuffer.ByValue,`jti`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_method_claims_encode(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_claims_sign(`ptr`: Pointer,`bearerDid`: Pointer,`keySelector`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_clone_inmemorykeystore(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_free_inmemorykeystore(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_constructor_inmemorykeystore_new(uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_method_inmemorykeystore_export_private_keys(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_inmemorykeystore_generate_new(`ptr`: Pointer,`curve`: RustBuffer.ByValue,`keyAlias`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_inmemorykeystore_get_all_aliases(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_inmemorykeystore_get_public_key(`ptr`: Pointer,`keyAlias`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_method_inmemorykeystore_import_private_keys(`ptr`: Pointer,`privateKeys`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_method_inmemorykeystore_sign(`ptr`: Pointer,`keyAlias`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_clone_jwk(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_free_jwk(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_method_jwk_alias(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_jwk_compute_thumbprint(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_jwk_jwk(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_method_jwk_sign(`ptr`: Pointer,`payload`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_jwk_to_public(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_method_jwk_verify(`ptr`: Pointer,`payload`: RustBuffer.ByValue,`signature`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_clone_key(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_free_key(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_method_key_alias(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_key_jwk(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_clone_keymanager(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_free_keymanager(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_method_keymanager_export_private_keys(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_keymanager_generate_private_key(`ptr`: Pointer,`curve`: RustBuffer.ByValue,`keyAlias`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_keymanager_get_public_key(`ptr`: Pointer,`keyAlias`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_method_keymanager_import_private_keys(`ptr`: Pointer,`privateKeys`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_method_keymanager_sign(`ptr`: Pointer,`keyAlias`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_clone_keystore(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_free_keystore(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, + fun uniffi_web5_uniffi_fn_func_hello_world(uniffi_out_err: UniffiRustCallStatus, ): Unit - fun uniffi_web5_fn_method_keystore_export_private_keys(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue - fun uniffi_web5_fn_method_keystore_generate_new(`ptr`: Pointer,`curve`: RustBuffer.ByValue,`keyAlias`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue - fun uniffi_web5_fn_method_keystore_get_all_aliases(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_keystore_get_public_key(`ptr`: Pointer,`keyAlias`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_method_keystore_import_private_keys(`ptr`: Pointer,`privateKeys`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_method_keystore_sign(`ptr`: Pointer,`keyAlias`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_clone_localkeymanager(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_free_localkeymanager(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_constructor_localkeymanager_new(`keyStore`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_constructor_localkeymanager_new_in_memory(uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_method_localkeymanager_export_private_keys(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_localkeymanager_generate_private_key(`ptr`: Pointer,`curve`: RustBuffer.ByValue,`keyAlias`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_localkeymanager_get_public_key(`ptr`: Pointer,`keyAlias`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_method_localkeymanager_import_private_keys(`ptr`: Pointer,`privateKeys`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_method_localkeymanager_sign(`ptr`: Pointer,`keyAlias`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_clone_privatekey(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_free_privatekey(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_method_privatekey_sign(`ptr`: Pointer,`payload`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_method_privatekey_to_public(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_clone_publickey(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_free_publickey(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_method_publickey_verify(`ptr`: Pointer,`payload`: RustBuffer.ByValue,`signature`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_clone_verifiablecredential(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_free_verifiablecredential(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_web5_fn_constructor_verifiablecredential_new(`context`: RustBuffer.ByValue,`id`: RustBuffer.ByValue,`type`: RustBuffer.ByValue,`issuer`: RustBuffer.ByValue,`issuanceDate`: Long,`expirationDate`: RustBuffer.ByValue,`credentialSubject`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_web5_fn_method_verifiablecredential_sign(`ptr`: Pointer,`bearerDid`: Pointer,`keySelector`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_func_bearer_did_from_key_manager(`didUri`: RustBuffer.ByValue,`keyManager`: Pointer, - ): Long - fun uniffi_web5_fn_func_sign_jwt(`bearerDid`: Pointer,`keySelector`: RustBuffer.ByValue,`encodedHeader`: RustBuffer.ByValue,`encodedPayload`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_web5_fn_func_verify_jwt(`jwt`: RustBuffer.ByValue, - ): Long - fun uniffi_web5_fn_func_verify_vcjwt(`jwt`: RustBuffer.ByValue, - ): Long - fun ffi_web5_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun ffi_web5_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun ffi_web5_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, ): Unit - fun ffi_web5_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue - fun ffi_web5_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, + fun ffi_web5_uniffi_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, ): Unit - fun ffi_web5_rust_future_cancel_u8(`handle`: Long, + fun ffi_web5_uniffi_rust_future_cancel_u8(`handle`: Long, ): Unit - fun ffi_web5_rust_future_free_u8(`handle`: Long, + fun ffi_web5_uniffi_rust_future_free_u8(`handle`: Long, ): Unit - fun ffi_web5_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, ): Byte - fun ffi_web5_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, + fun ffi_web5_uniffi_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, ): Unit - fun ffi_web5_rust_future_cancel_i8(`handle`: Long, + fun ffi_web5_uniffi_rust_future_cancel_i8(`handle`: Long, ): Unit - fun ffi_web5_rust_future_free_i8(`handle`: Long, + fun ffi_web5_uniffi_rust_future_free_i8(`handle`: Long, ): Unit - fun ffi_web5_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, ): Byte - fun ffi_web5_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, + fun ffi_web5_uniffi_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, ): Unit - fun ffi_web5_rust_future_cancel_u16(`handle`: Long, + fun ffi_web5_uniffi_rust_future_cancel_u16(`handle`: Long, ): Unit - fun ffi_web5_rust_future_free_u16(`handle`: Long, + fun ffi_web5_uniffi_rust_future_free_u16(`handle`: Long, ): Unit - fun ffi_web5_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, ): Short - fun ffi_web5_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, + fun ffi_web5_uniffi_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, ): Unit - fun ffi_web5_rust_future_cancel_i16(`handle`: Long, + fun ffi_web5_uniffi_rust_future_cancel_i16(`handle`: Long, ): Unit - fun ffi_web5_rust_future_free_i16(`handle`: Long, + fun ffi_web5_uniffi_rust_future_free_i16(`handle`: Long, ): Unit - fun ffi_web5_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, ): Short - fun ffi_web5_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, + fun ffi_web5_uniffi_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, ): Unit - fun ffi_web5_rust_future_cancel_u32(`handle`: Long, + fun ffi_web5_uniffi_rust_future_cancel_u32(`handle`: Long, ): Unit - fun ffi_web5_rust_future_free_u32(`handle`: Long, + fun ffi_web5_uniffi_rust_future_free_u32(`handle`: Long, ): Unit - fun ffi_web5_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, ): Int - fun ffi_web5_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, + fun ffi_web5_uniffi_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, ): Unit - fun ffi_web5_rust_future_cancel_i32(`handle`: Long, + fun ffi_web5_uniffi_rust_future_cancel_i32(`handle`: Long, ): Unit - fun ffi_web5_rust_future_free_i32(`handle`: Long, + fun ffi_web5_uniffi_rust_future_free_i32(`handle`: Long, ): Unit - fun ffi_web5_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, ): Int - fun ffi_web5_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, + fun ffi_web5_uniffi_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, ): Unit - fun ffi_web5_rust_future_cancel_u64(`handle`: Long, + fun ffi_web5_uniffi_rust_future_cancel_u64(`handle`: Long, ): Unit - fun ffi_web5_rust_future_free_u64(`handle`: Long, + fun ffi_web5_uniffi_rust_future_free_u64(`handle`: Long, ): Unit - fun ffi_web5_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, ): Long - fun ffi_web5_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, + fun ffi_web5_uniffi_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, ): Unit - fun ffi_web5_rust_future_cancel_i64(`handle`: Long, + fun ffi_web5_uniffi_rust_future_cancel_i64(`handle`: Long, ): Unit - fun ffi_web5_rust_future_free_i64(`handle`: Long, + fun ffi_web5_uniffi_rust_future_free_i64(`handle`: Long, ): Unit - fun ffi_web5_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, ): Long - fun ffi_web5_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, + fun ffi_web5_uniffi_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, ): Unit - fun ffi_web5_rust_future_cancel_f32(`handle`: Long, + fun ffi_web5_uniffi_rust_future_cancel_f32(`handle`: Long, ): Unit - fun ffi_web5_rust_future_free_f32(`handle`: Long, + fun ffi_web5_uniffi_rust_future_free_f32(`handle`: Long, ): Unit - fun ffi_web5_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, ): Float - fun ffi_web5_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, + fun ffi_web5_uniffi_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, ): Unit - fun ffi_web5_rust_future_cancel_f64(`handle`: Long, + fun ffi_web5_uniffi_rust_future_cancel_f64(`handle`: Long, ): Unit - fun ffi_web5_rust_future_free_f64(`handle`: Long, + fun ffi_web5_uniffi_rust_future_free_f64(`handle`: Long, ): Unit - fun ffi_web5_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, ): Double - fun ffi_web5_rust_future_poll_pointer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, + fun ffi_web5_uniffi_rust_future_poll_pointer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, ): Unit - fun ffi_web5_rust_future_cancel_pointer(`handle`: Long, + fun ffi_web5_uniffi_rust_future_cancel_pointer(`handle`: Long, ): Unit - fun ffi_web5_rust_future_free_pointer(`handle`: Long, + fun ffi_web5_uniffi_rust_future_free_pointer(`handle`: Long, ): Unit - fun ffi_web5_rust_future_complete_pointer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rust_future_complete_pointer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, ): Pointer - fun ffi_web5_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, + fun ffi_web5_uniffi_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, ): Unit - fun ffi_web5_rust_future_cancel_rust_buffer(`handle`: Long, + fun ffi_web5_uniffi_rust_future_cancel_rust_buffer(`handle`: Long, ): Unit - fun ffi_web5_rust_future_free_rust_buffer(`handle`: Long, + fun ffi_web5_uniffi_rust_future_free_rust_buffer(`handle`: Long, ): Unit - fun ffi_web5_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue - fun ffi_web5_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, + fun ffi_web5_uniffi_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, ): Unit - fun ffi_web5_rust_future_cancel_void(`handle`: Long, + fun ffi_web5_uniffi_rust_future_cancel_void(`handle`: Long, ): Unit - fun ffi_web5_rust_future_free_void(`handle`: Long, + fun ffi_web5_uniffi_rust_future_free_void(`handle`: Long, ): Unit - fun ffi_web5_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, + fun ffi_web5_uniffi_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, ): Unit - fun uniffi_web5_checksum_func_bearer_did_from_key_manager( - ): Short - fun uniffi_web5_checksum_func_sign_jwt( - ): Short - fun uniffi_web5_checksum_func_verify_jwt( - ): Short - fun uniffi_web5_checksum_func_verify_vcjwt( - ): Short - fun uniffi_web5_checksum_method_bearerdid_sign( - ): Short - fun uniffi_web5_checksum_method_claims_encode( - ): Short - fun uniffi_web5_checksum_method_claims_sign( - ): Short - fun uniffi_web5_checksum_method_inmemorykeystore_export_private_keys( - ): Short - fun uniffi_web5_checksum_method_inmemorykeystore_generate_new( - ): Short - fun uniffi_web5_checksum_method_inmemorykeystore_get_all_aliases( - ): Short - fun uniffi_web5_checksum_method_inmemorykeystore_get_public_key( - ): Short - fun uniffi_web5_checksum_method_inmemorykeystore_import_private_keys( - ): Short - fun uniffi_web5_checksum_method_inmemorykeystore_sign( - ): Short - fun uniffi_web5_checksum_method_jwk_alias( - ): Short - fun uniffi_web5_checksum_method_jwk_compute_thumbprint( - ): Short - fun uniffi_web5_checksum_method_jwk_jwk( - ): Short - fun uniffi_web5_checksum_method_jwk_sign( - ): Short - fun uniffi_web5_checksum_method_jwk_to_public( - ): Short - fun uniffi_web5_checksum_method_jwk_verify( - ): Short - fun uniffi_web5_checksum_method_key_alias( - ): Short - fun uniffi_web5_checksum_method_key_jwk( - ): Short - fun uniffi_web5_checksum_method_keymanager_export_private_keys( - ): Short - fun uniffi_web5_checksum_method_keymanager_generate_private_key( - ): Short - fun uniffi_web5_checksum_method_keymanager_get_public_key( - ): Short - fun uniffi_web5_checksum_method_keymanager_import_private_keys( - ): Short - fun uniffi_web5_checksum_method_keymanager_sign( - ): Short - fun uniffi_web5_checksum_method_keystore_export_private_keys( - ): Short - fun uniffi_web5_checksum_method_keystore_generate_new( - ): Short - fun uniffi_web5_checksum_method_keystore_get_all_aliases( - ): Short - fun uniffi_web5_checksum_method_keystore_get_public_key( - ): Short - fun uniffi_web5_checksum_method_keystore_import_private_keys( - ): Short - fun uniffi_web5_checksum_method_keystore_sign( - ): Short - fun uniffi_web5_checksum_method_localkeymanager_export_private_keys( - ): Short - fun uniffi_web5_checksum_method_localkeymanager_generate_private_key( - ): Short - fun uniffi_web5_checksum_method_localkeymanager_get_public_key( + fun uniffi_web5_uniffi_checksum_func_hello_world( ): Short - fun uniffi_web5_checksum_method_localkeymanager_import_private_keys( - ): Short - fun uniffi_web5_checksum_method_localkeymanager_sign( - ): Short - fun uniffi_web5_checksum_method_privatekey_sign( - ): Short - fun uniffi_web5_checksum_method_privatekey_to_public( - ): Short - fun uniffi_web5_checksum_method_publickey_verify( - ): Short - fun uniffi_web5_checksum_method_verifiablecredential_sign( - ): Short - fun uniffi_web5_checksum_constructor_claims_new( - ): Short - fun uniffi_web5_checksum_constructor_inmemorykeystore_new( - ): Short - fun uniffi_web5_checksum_constructor_localkeymanager_new( - ): Short - fun uniffi_web5_checksum_constructor_localkeymanager_new_in_memory( - ): Short - fun uniffi_web5_checksum_constructor_verifiablecredential_new( - ): Short - fun ffi_web5_uniffi_contract_version( + fun ffi_web5_uniffi_uniffi_contract_version( ): Int } @@ -1347,7 +838,7 @@ private fun uniffiCheckContractApiVersion(lib: UniffiLib) { // Get the bindings contract version from our ComponentInterface val bindings_contract_version = 26 // Get the scaffolding contract version by calling the into the dylib - val scaffolding_contract_version = lib.ffi_web5_uniffi_contract_version() + val scaffolding_contract_version = lib.ffi_web5_uniffi_uniffi_contract_version() if (bindings_contract_version != scaffolding_contract_version) { throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project") } @@ -1355,187 +846,12 @@ private fun uniffiCheckContractApiVersion(lib: UniffiLib) { @Suppress("UNUSED_PARAMETER") private fun uniffiCheckApiChecksums(lib: UniffiLib) { - if (lib.uniffi_web5_checksum_func_bearer_did_from_key_manager() != 49693.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_func_sign_jwt() != 3714.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_func_verify_jwt() != 15697.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_func_verify_vcjwt() != 20360.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_bearerdid_sign() != 16617.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_claims_encode() != 57871.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_claims_sign() != 25723.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_inmemorykeystore_export_private_keys() != 39747.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_inmemorykeystore_generate_new() != 38125.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_inmemorykeystore_get_all_aliases() != 5037.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_inmemorykeystore_get_public_key() != 29662.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_inmemorykeystore_import_private_keys() != 30093.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_inmemorykeystore_sign() != 16944.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_jwk_alias() != 49978.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_jwk_compute_thumbprint() != 48815.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_jwk_jwk() != 5992.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_jwk_sign() != 61337.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_jwk_to_public() != 29912.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_jwk_verify() != 11302.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_key_alias() != 42841.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_key_jwk() != 56821.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_keymanager_export_private_keys() != 21330.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_keymanager_generate_private_key() != 37489.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_keymanager_get_public_key() != 33063.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_keymanager_import_private_keys() != 17034.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_keymanager_sign() != 60994.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_keystore_export_private_keys() != 51959.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_keystore_generate_new() != 11193.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_keystore_get_all_aliases() != 38081.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_keystore_get_public_key() != 2805.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_keystore_import_private_keys() != 4940.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_keystore_sign() != 52791.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_localkeymanager_export_private_keys() != 123.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_localkeymanager_generate_private_key() != 44974.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_localkeymanager_get_public_key() != 10967.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_localkeymanager_import_private_keys() != 16228.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_localkeymanager_sign() != 33139.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_privatekey_sign() != 45053.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_privatekey_to_public() != 39125.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_publickey_verify() != 12448.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_method_verifiablecredential_sign() != 29352.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_constructor_claims_new() != 1059.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_constructor_inmemorykeystore_new() != 52462.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_constructor_localkeymanager_new() != 2661.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_constructor_localkeymanager_new_in_memory() != 62693.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_web5_checksum_constructor_verifiablecredential_new() != 54017.toShort()) { + if (lib.uniffi_web5_uniffi_checksum_func_hello_world() != 5356.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } } // Async support -// Async return type handlers - -internal const val UNIFFI_RUST_FUTURE_POLL_READY = 0.toByte() -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) { - uniffiContinuationHandleMap.remove(data).resume(pollResult) - } -} - -internal suspend fun uniffiRustCallAsync( - rustFuture: Long, - pollFunc: (Long, UniffiRustFutureContinuationCallback, Long) -> Unit, - completeFunc: (Long, UniffiRustCallStatus) -> F, - freeFunc: (Long) -> Unit, - liftFunc: (F) -> T, - errorHandler: UniffiRustCallStatusErrorHandler -): T { - try { - do { - 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) }) - ) - } finally { - freeFunc(rustFuture) - } -} // Public interface members begin here. @@ -1573,46 +889,6 @@ inline fun T.use(block: (T) -> R) = /** Used to instantiate an interface without an actual pointer, for fakes in tests, mostly. */ object NoPointer -public object FfiConverterUByte: FfiConverter { - override fun lift(value: Byte): UByte { - return value.toUByte() - } - - override fun read(buf: ByteBuffer): UByte { - return lift(buf.get()) - } - - override fun lower(value: UByte): Byte { - return value.toByte() - } - - override fun allocationSize(value: UByte) = 1UL - - override fun write(value: UByte, buf: ByteBuffer) { - buf.put(value.toByte()) - } -} - -public object FfiConverterLong: FfiConverter { - override fun lift(value: Long): Long { - return value - } - - override fun read(buf: ByteBuffer): Long { - return buf.getLong() - } - - override fun lower(value: Long): Long { - return value - } - - override fun allocationSize(value: Long) = 8UL - - override fun write(value: Long, buf: ByteBuffer) { - buf.putLong(value) - } -} - 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 @@ -1665,3900 +941,13 @@ public object FfiConverterString: FfiConverter { buf.putInt(byteBuf.limit()) buf.put(byteBuf) } +} fun `helloWorld`() + = + uniffiRustCall() { _status -> + UniffiLib.INSTANCE.uniffi_web5_uniffi_fn_func_hello_world( + _status) } - -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 { - return 4UL + value.size.toULong() - } - override fun write(value: ByteArray, buf: ByteBuffer) { - buf.putInt(value.size) - buf.put(value) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -// The cleaner interface for Object finalization code to run. -// This is the entry point to any implementation that we're using. -// -// The cleaner registers objects and returns cleanables, so now we are -// defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the -// different implmentations available at compile time. -interface UniffiCleaner { - interface Cleanable { - fun clean() - } - - fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable - - companion object -} - -// The fallback Jna cleaner, which is available for both Android, and the JVM. -private class UniffiJnaCleaner : UniffiCleaner { - private val cleaner = com.sun.jna.internal.Cleaner.getCleaner() - - override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable = - UniffiJnaCleanable(cleaner.register(value, cleanUpTask)) -} - -private class UniffiJnaCleanable( - private val cleanable: com.sun.jna.internal.Cleaner.Cleanable, -) : UniffiCleaner.Cleanable { - override fun clean() = cleanable.clean() -} - -// We decide at uniffi binding generation time whether we were -// using Android or not. -// There are further runtime checks to chose the correct implementation -// of the cleaner. -private fun UniffiCleaner.Companion.create(): UniffiCleaner = - try { - // For safety's sake: if the library hasn't been run in android_cleaner = true - // mode, but is being run on Android, then we still need to think about - // Android API versions. - // So we check if java.lang.ref.Cleaner is there, and use that… - java.lang.Class.forName("java.lang.ref.Cleaner") - JavaLangRefCleaner() - } catch (e: ClassNotFoundException) { - // … otherwise, fallback to the JNA cleaner. - UniffiJnaCleaner() - } - -private class JavaLangRefCleaner : UniffiCleaner { - val cleaner = java.lang.ref.Cleaner.create() - - override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable = - JavaLangRefCleanable(cleaner.register(value, cleanUpTask)) -} - -private class JavaLangRefCleanable( - val cleanable: java.lang.ref.Cleaner.Cleanable -) : UniffiCleaner.Cleanable { - override fun clean() = cleanable.clean() -} -public interface BearerDidInterface { - - fun `sign`(`keySelector`: KeySelector, `payload`: List): kotlin.ByteArray - - companion object -} - -open class BearerDid: Disposable, AutoCloseable, BearerDidInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_free_bearerdid(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_clone_bearerdid(pointer!!, status) - } - } - - - @Throws(BearerDidException::class)override fun `sign`(`keySelector`: KeySelector, `payload`: List): kotlin.ByteArray { - return FfiConverterByteArray.lift( - callWithPointer { - uniffiRustCallWithError(BearerDidException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_bearerdid_sign( - it, FfiConverterTypeKeySelector.lower(`keySelector`),FfiConverterSequenceUByte.lower(`payload`),_status) -} - } - ) - } - - - - - - companion object -} - -public object FfiConverterTypeBearerDid: FfiConverter { - - override fun lower(value: BearerDid): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): BearerDid { - return BearerDid(value) - } - - override fun read(buf: ByteBuffer): BearerDid { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: BearerDid) = 8UL - - override fun write(value: BearerDid, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -public interface ClaimsInterface { - - fun `encode`(): kotlin.String - - fun `sign`(`bearerDid`: BearerDid, `keySelector`: KeySelector): kotlin.String - - companion object -} - -open class Claims: Disposable, AutoCloseable, ClaimsInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - constructor(`issuer`: kotlin.String?, `subject`: kotlin.String?, `audience`: kotlin.String?, `expiration`: kotlin.Long?, `notBefore`: kotlin.Long?, `issuedAt`: kotlin.Long?, `jti`: kotlin.String?) : - this( - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_constructor_claims_new( - FfiConverterOptionalString.lower(`issuer`),FfiConverterOptionalString.lower(`subject`),FfiConverterOptionalString.lower(`audience`),FfiConverterOptionalLong.lower(`expiration`),FfiConverterOptionalLong.lower(`notBefore`),FfiConverterOptionalLong.lower(`issuedAt`),FfiConverterOptionalString.lower(`jti`),_status) -} - ) - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_free_claims(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_clone_claims(pointer!!, status) - } - } - - - @Throws(JwtException::class)override fun `encode`(): kotlin.String { - return FfiConverterString.lift( - callWithPointer { - uniffiRustCallWithError(JwtException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_claims_encode( - it, _status) -} - } - ) - } - - - - @Throws(JwtException::class)override fun `sign`(`bearerDid`: BearerDid, `keySelector`: KeySelector): kotlin.String { - return FfiConverterString.lift( - callWithPointer { - uniffiRustCallWithError(JwtException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_claims_sign( - it, FfiConverterTypeBearerDid.lower(`bearerDid`),FfiConverterTypeKeySelector.lower(`keySelector`),_status) -} - } - ) - } - - - - - - - companion object - -} - -public object FfiConverterTypeClaims: FfiConverter { - - override fun lower(value: Claims): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): Claims { - return Claims(value) - } - - override fun read(buf: ByteBuffer): Claims { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: Claims) = 8UL - - override fun write(value: Claims, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -public interface InMemoryKeyStoreInterface { - - fun `exportPrivateKeys`(): List - - fun `generateNew`(`curve`: Curve, `keyAlias`: kotlin.String?): kotlin.String - - fun `getAllAliases`(): List - - fun `getPublicKey`(`keyAlias`: kotlin.String): PublicKey - - fun `importPrivateKeys`(`privateKeys`: List) - - fun `sign`(`keyAlias`: kotlin.String, `payload`: List): kotlin.ByteArray - - companion object -} - -open class InMemoryKeyStore: Disposable, AutoCloseable, InMemoryKeyStoreInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - constructor() : - this( - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_constructor_inmemorykeystore_new( - _status) -} - ) - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_free_inmemorykeystore(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_clone_inmemorykeystore(pointer!!, status) - } - } - - - @Throws(KeyStoreException::class)override fun `exportPrivateKeys`(): List { - return FfiConverterSequenceTypePrivateKey.lift( - callWithPointer { - uniffiRustCallWithError(KeyStoreException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_inmemorykeystore_export_private_keys( - it, _status) -} - } - ) - } - - - - @Throws(KeyStoreException::class)override fun `generateNew`(`curve`: Curve, `keyAlias`: kotlin.String?): kotlin.String { - return FfiConverterString.lift( - callWithPointer { - uniffiRustCallWithError(KeyStoreException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_inmemorykeystore_generate_new( - it, FfiConverterTypeCurve.lower(`curve`),FfiConverterOptionalString.lower(`keyAlias`),_status) -} - } - ) - } - - - - @Throws(KeyStoreException::class)override fun `getAllAliases`(): List { - return FfiConverterSequenceString.lift( - callWithPointer { - uniffiRustCallWithError(KeyStoreException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_inmemorykeystore_get_all_aliases( - it, _status) -} - } - ) - } - - - - @Throws(KeyStoreException::class)override fun `getPublicKey`(`keyAlias`: kotlin.String): PublicKey { - return FfiConverterTypePublicKey.lift( - callWithPointer { - uniffiRustCallWithError(KeyStoreException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_inmemorykeystore_get_public_key( - it, FfiConverterString.lower(`keyAlias`),_status) -} - } - ) - } - - - - @Throws(KeyStoreException::class)override fun `importPrivateKeys`(`privateKeys`: List) - = - callWithPointer { - uniffiRustCallWithError(KeyStoreException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_inmemorykeystore_import_private_keys( - it, FfiConverterSequenceTypePrivateKey.lower(`privateKeys`),_status) -} - } - - - - - @Throws(KeyStoreException::class)override fun `sign`(`keyAlias`: kotlin.String, `payload`: List): kotlin.ByteArray { - return FfiConverterByteArray.lift( - callWithPointer { - uniffiRustCallWithError(KeyStoreException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_inmemorykeystore_sign( - it, FfiConverterString.lower(`keyAlias`),FfiConverterSequenceUByte.lower(`payload`),_status) -} - } - ) - } - - - - - - - companion object - -} - -public object FfiConverterTypeInMemoryKeyStore: FfiConverter { - - override fun lower(value: InMemoryKeyStore): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): InMemoryKeyStore { - return InMemoryKeyStore(value) - } - - override fun read(buf: ByteBuffer): InMemoryKeyStore { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: InMemoryKeyStore) = 8UL - - override fun write(value: InMemoryKeyStore, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -public interface JwkInterface { - - fun `alias`(): kotlin.String - - fun `computeThumbprint`(): kotlin.String - - fun `jwk`(): Jwk - - fun `sign`(`payload`: List): kotlin.ByteArray - - fun `toPublic`(): PublicKey - - fun `verify`(`payload`: List, `signature`: List) - - companion object -} - -open class Jwk: Disposable, AutoCloseable, JwkInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_free_jwk(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_clone_jwk(pointer!!, status) - } - } - - - @Throws(KeyException::class)override fun `alias`(): kotlin.String { - return FfiConverterString.lift( - callWithPointer { - uniffiRustCallWithError(KeyException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_jwk_alias( - it, _status) -} - } - ) - } - - - - @Throws(JwkException::class)override fun `computeThumbprint`(): kotlin.String { - return FfiConverterString.lift( - callWithPointer { - uniffiRustCallWithError(JwkException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_jwk_compute_thumbprint( - it, _status) -} - } - ) - } - - - - @Throws(KeyException::class)override fun `jwk`(): Jwk { - return FfiConverterTypeJwk.lift( - callWithPointer { - uniffiRustCallWithError(KeyException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_jwk_jwk( - it, _status) -} - } - ) - } - - - - @Throws(KeyException::class)override fun `sign`(`payload`: List): kotlin.ByteArray { - return FfiConverterByteArray.lift( - callWithPointer { - uniffiRustCallWithError(KeyException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_jwk_sign( - it, FfiConverterSequenceUByte.lower(`payload`),_status) -} - } - ) - } - - - - @Throws(KeyException::class)override fun `toPublic`(): PublicKey { - return FfiConverterTypePublicKey.lift( - callWithPointer { - uniffiRustCallWithError(KeyException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_jwk_to_public( - it, _status) -} - } - ) - } - - - - @Throws(KeyException::class)override fun `verify`(`payload`: List, `signature`: List) - = - callWithPointer { - uniffiRustCallWithError(KeyException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_jwk_verify( - it, FfiConverterSequenceUByte.lower(`payload`),FfiConverterSequenceUByte.lower(`signature`),_status) -} - } - - - - - - - - companion object - -} - -public object FfiConverterTypeJwk: FfiConverter { - - override fun lower(value: Jwk): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): Jwk { - return Jwk(value) - } - - override fun read(buf: ByteBuffer): Jwk { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: Jwk) = 8UL - - override fun write(value: Jwk, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -public interface KeyInterface { - - fun `alias`(): kotlin.String - - fun `jwk`(): Jwk - - companion object -} - -open class Key: Disposable, AutoCloseable, KeyInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_free_key(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_clone_key(pointer!!, status) - } - } - - - @Throws(KeyException::class)override fun `alias`(): kotlin.String { - return FfiConverterString.lift( - callWithPointer { - uniffiRustCallWithError(KeyException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_key_alias( - it, _status) -} - } - ) - } - - - - @Throws(KeyException::class)override fun `jwk`(): Jwk { - return FfiConverterTypeJwk.lift( - callWithPointer { - uniffiRustCallWithError(KeyException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_key_jwk( - it, _status) -} - } - ) - } - - - - - - - companion object - -} - -public object FfiConverterTypeKey: FfiConverter { - - override fun lower(value: Key): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): Key { - return Key(value) - } - - override fun read(buf: ByteBuffer): Key { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: Key) = 8UL - - override fun write(value: Key, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -public interface KeyManagerInterface { - - fun `exportPrivateKeys`(): List - - fun `generatePrivateKey`(`curve`: Curve, `keyAlias`: kotlin.String?): kotlin.String - - fun `getPublicKey`(`keyAlias`: kotlin.String): PublicKey - - fun `importPrivateKeys`(`privateKeys`: List) - - fun `sign`(`keyAlias`: kotlin.String, `payload`: List): kotlin.ByteArray - - companion object -} - -open class KeyManager: Disposable, AutoCloseable, KeyManagerInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_free_keymanager(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_clone_keymanager(pointer!!, status) - } - } - - - @Throws(KeyManagerException::class)override fun `exportPrivateKeys`(): List { - return FfiConverterSequenceTypePrivateKey.lift( - callWithPointer { - uniffiRustCallWithError(KeyManagerException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_keymanager_export_private_keys( - it, _status) -} - } - ) - } - - - - @Throws(KeyManagerException::class)override fun `generatePrivateKey`(`curve`: Curve, `keyAlias`: kotlin.String?): kotlin.String { - return FfiConverterString.lift( - callWithPointer { - uniffiRustCallWithError(KeyManagerException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_keymanager_generate_private_key( - it, FfiConverterTypeCurve.lower(`curve`),FfiConverterOptionalString.lower(`keyAlias`),_status) -} - } - ) - } - - - - @Throws(KeyManagerException::class)override fun `getPublicKey`(`keyAlias`: kotlin.String): PublicKey { - return FfiConverterTypePublicKey.lift( - callWithPointer { - uniffiRustCallWithError(KeyManagerException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_keymanager_get_public_key( - it, FfiConverterString.lower(`keyAlias`),_status) -} - } - ) - } - - - - @Throws(KeyManagerException::class)override fun `importPrivateKeys`(`privateKeys`: List) - = - callWithPointer { - uniffiRustCallWithError(KeyManagerException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_keymanager_import_private_keys( - it, FfiConverterSequenceTypePrivateKey.lower(`privateKeys`),_status) -} - } - - - - - @Throws(KeyManagerException::class)override fun `sign`(`keyAlias`: kotlin.String, `payload`: List): kotlin.ByteArray { - return FfiConverterByteArray.lift( - callWithPointer { - uniffiRustCallWithError(KeyManagerException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_keymanager_sign( - it, FfiConverterString.lower(`keyAlias`),FfiConverterSequenceUByte.lower(`payload`),_status) -} - } - ) - } - - - - - - - companion object - -} - -public object FfiConverterTypeKeyManager: FfiConverter { - - override fun lower(value: KeyManager): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): KeyManager { - return KeyManager(value) - } - - override fun read(buf: ByteBuffer): KeyManager { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: KeyManager) = 8UL - - override fun write(value: KeyManager, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -public interface KeyStoreInterface { - - fun `exportPrivateKeys`(): List - - fun `generateNew`(`curve`: Curve, `keyAlias`: kotlin.String?): kotlin.String - - fun `getAllAliases`(): List - - fun `getPublicKey`(`keyAlias`: kotlin.String): PublicKey - - fun `importPrivateKeys`(`privateKeys`: List) - - fun `sign`(`keyAlias`: kotlin.String, `payload`: List): kotlin.ByteArray - - companion object -} - -open class KeyStore: Disposable, AutoCloseable, KeyStoreInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_free_keystore(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_clone_keystore(pointer!!, status) - } - } - - - @Throws(KeyStoreException::class)override fun `exportPrivateKeys`(): List { - return FfiConverterSequenceTypePrivateKey.lift( - callWithPointer { - uniffiRustCallWithError(KeyStoreException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_keystore_export_private_keys( - it, _status) -} - } - ) - } - - - - @Throws(KeyStoreException::class)override fun `generateNew`(`curve`: Curve, `keyAlias`: kotlin.String?): kotlin.String { - return FfiConverterString.lift( - callWithPointer { - uniffiRustCallWithError(KeyStoreException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_keystore_generate_new( - it, FfiConverterTypeCurve.lower(`curve`),FfiConverterOptionalString.lower(`keyAlias`),_status) -} - } - ) - } - - - - @Throws(KeyStoreException::class)override fun `getAllAliases`(): List { - return FfiConverterSequenceString.lift( - callWithPointer { - uniffiRustCallWithError(KeyStoreException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_keystore_get_all_aliases( - it, _status) -} - } - ) - } - - - - @Throws(KeyStoreException::class)override fun `getPublicKey`(`keyAlias`: kotlin.String): PublicKey { - return FfiConverterTypePublicKey.lift( - callWithPointer { - uniffiRustCallWithError(KeyStoreException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_keystore_get_public_key( - it, FfiConverterString.lower(`keyAlias`),_status) -} - } - ) - } - - - - @Throws(KeyStoreException::class)override fun `importPrivateKeys`(`privateKeys`: List) - = - callWithPointer { - uniffiRustCallWithError(KeyStoreException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_keystore_import_private_keys( - it, FfiConverterSequenceTypePrivateKey.lower(`privateKeys`),_status) -} - } - - - - - @Throws(KeyStoreException::class)override fun `sign`(`keyAlias`: kotlin.String, `payload`: List): kotlin.ByteArray { - return FfiConverterByteArray.lift( - callWithPointer { - uniffiRustCallWithError(KeyStoreException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_keystore_sign( - it, FfiConverterString.lower(`keyAlias`),FfiConverterSequenceUByte.lower(`payload`),_status) -} - } - ) - } - - - - - - - companion object - -} - -public object FfiConverterTypeKeyStore: FfiConverter { - - override fun lower(value: KeyStore): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): KeyStore { - return KeyStore(value) - } - - override fun read(buf: ByteBuffer): KeyStore { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: KeyStore) = 8UL - - override fun write(value: KeyStore, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -public interface LocalKeyManagerInterface { - - fun `exportPrivateKeys`(): List - - fun `generatePrivateKey`(`curve`: Curve, `keyAlias`: kotlin.String?): kotlin.String - - fun `getPublicKey`(`keyAlias`: kotlin.String): PublicKey - - fun `importPrivateKeys`(`privateKeys`: List) - - fun `sign`(`keyAlias`: kotlin.String, `payload`: List): kotlin.ByteArray - - companion object -} - -open class LocalKeyManager: Disposable, AutoCloseable, LocalKeyManagerInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - constructor(`keyStore`: KeyStore) : - this( - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_constructor_localkeymanager_new( - FfiConverterTypeKeyStore.lower(`keyStore`),_status) -} - ) - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_free_localkeymanager(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_clone_localkeymanager(pointer!!, status) - } - } - - - @Throws(KeyManagerException::class)override fun `exportPrivateKeys`(): List { - return FfiConverterSequenceTypePrivateKey.lift( - callWithPointer { - uniffiRustCallWithError(KeyManagerException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_localkeymanager_export_private_keys( - it, _status) -} - } - ) - } - - - - @Throws(KeyManagerException::class)override fun `generatePrivateKey`(`curve`: Curve, `keyAlias`: kotlin.String?): kotlin.String { - return FfiConverterString.lift( - callWithPointer { - uniffiRustCallWithError(KeyManagerException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_localkeymanager_generate_private_key( - it, FfiConverterTypeCurve.lower(`curve`),FfiConverterOptionalString.lower(`keyAlias`),_status) -} - } - ) - } - - - - @Throws(KeyManagerException::class)override fun `getPublicKey`(`keyAlias`: kotlin.String): PublicKey { - return FfiConverterTypePublicKey.lift( - callWithPointer { - uniffiRustCallWithError(KeyManagerException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_localkeymanager_get_public_key( - it, FfiConverterString.lower(`keyAlias`),_status) -} - } - ) - } - - - - @Throws(KeyManagerException::class)override fun `importPrivateKeys`(`privateKeys`: List) - = - callWithPointer { - uniffiRustCallWithError(KeyManagerException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_localkeymanager_import_private_keys( - it, FfiConverterSequenceTypePrivateKey.lower(`privateKeys`),_status) -} - } - - - - - @Throws(KeyManagerException::class)override fun `sign`(`keyAlias`: kotlin.String, `payload`: List): kotlin.ByteArray { - return FfiConverterByteArray.lift( - callWithPointer { - uniffiRustCallWithError(KeyManagerException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_localkeymanager_sign( - it, FfiConverterString.lower(`keyAlias`),FfiConverterSequenceUByte.lower(`payload`),_status) -} - } - ) - } - - - - - - companion object { - fun `newInMemory`(): LocalKeyManager { - return FfiConverterTypeLocalKeyManager.lift( - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_constructor_localkeymanager_new_in_memory( - _status) -} - ) - } - - - - } - -} - -public object FfiConverterTypeLocalKeyManager: FfiConverter { - - override fun lower(value: LocalKeyManager): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): LocalKeyManager { - return LocalKeyManager(value) - } - - override fun read(buf: ByteBuffer): LocalKeyManager { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: LocalKeyManager) = 8UL - - override fun write(value: LocalKeyManager, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -public interface PrivateKeyInterface { - - fun `sign`(`payload`: List): kotlin.ByteArray - - fun `toPublic`(): PublicKey - - companion object -} - -open class PrivateKey: Disposable, AutoCloseable, PrivateKeyInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_free_privatekey(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_clone_privatekey(pointer!!, status) - } - } - - - @Throws(KeyException::class)override fun `sign`(`payload`: List): kotlin.ByteArray { - return FfiConverterByteArray.lift( - callWithPointer { - uniffiRustCallWithError(KeyException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_privatekey_sign( - it, FfiConverterSequenceUByte.lower(`payload`),_status) -} - } - ) - } - - - - @Throws(KeyException::class)override fun `toPublic`(): PublicKey { - return FfiConverterTypePublicKey.lift( - callWithPointer { - uniffiRustCallWithError(KeyException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_privatekey_to_public( - it, _status) -} - } - ) - } - - - - - - - companion object - -} - -public object FfiConverterTypePrivateKey: FfiConverter { - - override fun lower(value: PrivateKey): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): PrivateKey { - return PrivateKey(value) - } - - override fun read(buf: ByteBuffer): PrivateKey { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: PrivateKey) = 8UL - - override fun write(value: PrivateKey, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -public interface PublicKeyInterface { - - fun `verify`(`payload`: List, `signature`: List) - - companion object -} - -open class PublicKey: Disposable, AutoCloseable, PublicKeyInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_free_publickey(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_clone_publickey(pointer!!, status) - } - } - - - @Throws(KeyException::class)override fun `verify`(`payload`: List, `signature`: List) - = - callWithPointer { - uniffiRustCallWithError(KeyException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_publickey_verify( - it, FfiConverterSequenceUByte.lower(`payload`),FfiConverterSequenceUByte.lower(`signature`),_status) -} - } - - - - - - - - companion object - -} - -public object FfiConverterTypePublicKey: FfiConverter { - - override fun lower(value: PublicKey): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): PublicKey { - return PublicKey(value) - } - - override fun read(buf: ByteBuffer): PublicKey { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: PublicKey) = 8UL - - override fun write(value: PublicKey, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -public interface VerifiableCredentialInterface { - - fun `sign`(`bearerDid`: BearerDid, `keySelector`: KeySelector): kotlin.String - - companion object -} - -open class VerifiableCredential: Disposable, AutoCloseable, VerifiableCredentialInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - constructor(`context`: List, `id`: kotlin.String, `type`: List, `issuer`: kotlin.String, `issuanceDate`: kotlin.Long, `expirationDate`: kotlin.Long?, `credentialSubject`: CredentialSubject) : - this( - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_constructor_verifiablecredential_new( - FfiConverterSequenceString.lower(`context`),FfiConverterString.lower(`id`),FfiConverterSequenceString.lower(`type`),FfiConverterString.lower(`issuer`),FfiConverterLong.lower(`issuanceDate`),FfiConverterOptionalLong.lower(`expirationDate`),FfiConverterTypeCredentialSubject.lower(`credentialSubject`),_status) -} - ) - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_free_verifiablecredential(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_web5_fn_clone_verifiablecredential(pointer!!, status) - } - } - - - @Throws(CredentialException::class)override fun `sign`(`bearerDid`: BearerDid, `keySelector`: KeySelector): kotlin.String { - return FfiConverterString.lift( - callWithPointer { - uniffiRustCallWithError(CredentialException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_method_verifiablecredential_sign( - it, FfiConverterTypeBearerDid.lower(`bearerDid`),FfiConverterTypeKeySelector.lower(`keySelector`),_status) -} - } - ) - } - - - - - - - companion object - -} - -public object FfiConverterTypeVerifiableCredential: FfiConverter { - - override fun lower(value: VerifiableCredential): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): VerifiableCredential { - return VerifiableCredential(value) - } - - override fun read(buf: ByteBuffer): VerifiableCredential { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: VerifiableCredential) = 8UL - - override fun write(value: VerifiableCredential, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - - -data class CredentialSubject ( - var `id`: kotlin.String, - var `params`: Map? -) { - - companion object -} - -public object FfiConverterTypeCredentialSubject: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): CredentialSubject { - return CredentialSubject( - FfiConverterString.read(buf), - FfiConverterOptionalMapStringString.read(buf), - ) - } - - override fun allocationSize(value: CredentialSubject) = ( - FfiConverterString.allocationSize(value.`id`) + - FfiConverterOptionalMapStringString.allocationSize(value.`params`) - ) - - override fun write(value: CredentialSubject, buf: ByteBuffer) { - FfiConverterString.write(value.`id`, buf) - FfiConverterOptionalMapStringString.write(value.`params`, buf) - } -} - - - - - -sealed class BearerDidException(message: String): Exception(message) { - - class VerificationMethodNotFound(message: String) : BearerDidException(message) - - class KeyManagerException(message: String) : BearerDidException(message) - - class KeyException(message: String) : BearerDidException(message) - - class DocumentException(message: String) : BearerDidException(message) - - class ResolutionException(message: String) : BearerDidException(message) - - class IdentifierException(message: String) : BearerDidException(message) - - - companion object ErrorHandler : UniffiRustCallStatusErrorHandler { - override fun lift(error_buf: RustBuffer.ByValue): BearerDidException = FfiConverterTypeBearerDidError.lift(error_buf) - } -} - -public object FfiConverterTypeBearerDidError : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): BearerDidException { - - return when(buf.getInt()) { - 1 -> BearerDidException.VerificationMethodNotFound(FfiConverterString.read(buf)) - 2 -> BearerDidException.KeyManagerException(FfiConverterString.read(buf)) - 3 -> BearerDidException.KeyException(FfiConverterString.read(buf)) - 4 -> BearerDidException.DocumentException(FfiConverterString.read(buf)) - 5 -> BearerDidException.ResolutionException(FfiConverterString.read(buf)) - 6 -> BearerDidException.IdentifierException(FfiConverterString.read(buf)) - else -> throw RuntimeException("invalid error enum value, something is very wrong!!") - } - - } - - override fun allocationSize(value: BearerDidException): ULong { - return 4UL - } - - override fun write(value: BearerDidException, buf: ByteBuffer) { - when(value) { - is BearerDidException.VerificationMethodNotFound -> { - buf.putInt(1) - Unit - } - is BearerDidException.KeyManagerException -> { - buf.putInt(2) - Unit - } - is BearerDidException.KeyException -> { - buf.putInt(3) - Unit - } - is BearerDidException.DocumentException -> { - buf.putInt(4) - Unit - } - is BearerDidException.ResolutionException -> { - buf.putInt(5) - Unit - } - is BearerDidException.IdentifierException -> { - buf.putInt(6) - Unit - } - }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } - } - -} - - - - - -sealed class CredentialException(message: String): Exception(message) { - - class JwtException(message: String) : CredentialException(message) - - class JwsException(message: String) : CredentialException(message) - - - companion object ErrorHandler : UniffiRustCallStatusErrorHandler { - override fun lift(error_buf: RustBuffer.ByValue): CredentialException = FfiConverterTypeCredentialError.lift(error_buf) - } -} - -public object FfiConverterTypeCredentialError : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): CredentialException { - - return when(buf.getInt()) { - 1 -> CredentialException.JwtException(FfiConverterString.read(buf)) - 2 -> CredentialException.JwsException(FfiConverterString.read(buf)) - else -> throw RuntimeException("invalid error enum value, something is very wrong!!") - } - - } - - override fun allocationSize(value: CredentialException): ULong { - return 4UL - } - - override fun write(value: CredentialException, buf: ByteBuffer) { - when(value) { - is CredentialException.JwtException -> { - buf.putInt(1) - Unit - } - is CredentialException.JwsException -> { - buf.putInt(2) - Unit - } - }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } - } - -} - - - - -enum class Curve { - - SECP256K1, - ED25519; - companion object -} - - -public object FfiConverterTypeCurve: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer) = try { - Curve.values()[buf.getInt() - 1] - } catch (e: IndexOutOfBoundsException) { - throw RuntimeException("invalid enum value, something is very wrong!!", e) - } - - override fun allocationSize(value: Curve) = 4UL - - override fun write(value: Curve, buf: ByteBuffer) { - buf.putInt(value.ordinal + 1) - } -} - - - - - - - -sealed class JwkException(message: String): Exception(message) { - - class ThumbprintFailed(message: String) : JwkException(message) - - - companion object ErrorHandler : UniffiRustCallStatusErrorHandler { - override fun lift(error_buf: RustBuffer.ByValue): JwkException = FfiConverterTypeJwkError.lift(error_buf) - } -} - -public object FfiConverterTypeJwkError : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): JwkException { - - return when(buf.getInt()) { - 1 -> JwkException.ThumbprintFailed(FfiConverterString.read(buf)) - else -> throw RuntimeException("invalid error enum value, something is very wrong!!") - } - - } - - override fun allocationSize(value: JwkException): ULong { - return 4UL - } - - override fun write(value: JwkException, buf: ByteBuffer) { - when(value) { - is JwkException.ThumbprintFailed -> { - buf.putInt(1) - Unit - } - }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } - } - -} - - - - - -sealed class JwtException(message: String): Exception(message) { - - class JwsException(message: String) : JwtException(message) - - class SerializationException(message: String) : JwtException(message) - - class DeserializationException(message: String) : JwtException(message) - - - companion object ErrorHandler : UniffiRustCallStatusErrorHandler { - override fun lift(error_buf: RustBuffer.ByValue): JwtException = FfiConverterTypeJwtError.lift(error_buf) - } -} - -public object FfiConverterTypeJwtError : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): JwtException { - - return when(buf.getInt()) { - 1 -> JwtException.JwsException(FfiConverterString.read(buf)) - 2 -> JwtException.SerializationException(FfiConverterString.read(buf)) - 3 -> JwtException.DeserializationException(FfiConverterString.read(buf)) - else -> throw RuntimeException("invalid error enum value, something is very wrong!!") - } - - } - - override fun allocationSize(value: JwtException): ULong { - return 4UL - } - - override fun write(value: JwtException, buf: ByteBuffer) { - when(value) { - is JwtException.JwsException -> { - buf.putInt(1) - Unit - } - is JwtException.SerializationException -> { - buf.putInt(2) - Unit - } - is JwtException.DeserializationException -> { - buf.putInt(3) - Unit - } - }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } - } - -} - - - - - -sealed class KeyException(message: String): Exception(message) { - - class KeyGenerationFailed(message: String) : KeyException(message) - - class SerializationFailed(message: String) : KeyException(message) - - class CurveNotFound(message: String) : KeyException(message) - - class AlgorithmNotFound(message: String) : KeyException(message) - - class JwkException(message: String) : KeyException(message) - - class CryptoException(message: String) : KeyException(message) - - - companion object ErrorHandler : UniffiRustCallStatusErrorHandler { - override fun lift(error_buf: RustBuffer.ByValue): KeyException = FfiConverterTypeKeyError.lift(error_buf) - } -} - -public object FfiConverterTypeKeyError : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): KeyException { - - return when(buf.getInt()) { - 1 -> KeyException.KeyGenerationFailed(FfiConverterString.read(buf)) - 2 -> KeyException.SerializationFailed(FfiConverterString.read(buf)) - 3 -> KeyException.CurveNotFound(FfiConverterString.read(buf)) - 4 -> KeyException.AlgorithmNotFound(FfiConverterString.read(buf)) - 5 -> KeyException.JwkException(FfiConverterString.read(buf)) - 6 -> KeyException.CryptoException(FfiConverterString.read(buf)) - else -> throw RuntimeException("invalid error enum value, something is very wrong!!") - } - - } - - override fun allocationSize(value: KeyException): ULong { - return 4UL - } - - override fun write(value: KeyException, buf: ByteBuffer) { - when(value) { - is KeyException.KeyGenerationFailed -> { - buf.putInt(1) - Unit - } - is KeyException.SerializationFailed -> { - buf.putInt(2) - Unit - } - is KeyException.CurveNotFound -> { - buf.putInt(3) - Unit - } - is KeyException.AlgorithmNotFound -> { - buf.putInt(4) - Unit - } - is KeyException.JwkException -> { - buf.putInt(5) - Unit - } - is KeyException.CryptoException -> { - buf.putInt(6) - Unit - } - }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } - } - -} - - - - - -sealed class KeyManagerException(message: String): Exception(message) { - - class KeyGenerationFailed(message: String) : KeyManagerException(message) - - class SigningKeyNotFound(message: String) : KeyManagerException(message) - - class KeyException(message: String) : KeyManagerException(message) - - class KeyStoreException(message: String) : KeyManagerException(message) - - - companion object ErrorHandler : UniffiRustCallStatusErrorHandler { - override fun lift(error_buf: RustBuffer.ByValue): KeyManagerException = FfiConverterTypeKeyManagerError.lift(error_buf) - } -} - -public object FfiConverterTypeKeyManagerError : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): KeyManagerException { - - return when(buf.getInt()) { - 1 -> KeyManagerException.KeyGenerationFailed(FfiConverterString.read(buf)) - 2 -> KeyManagerException.SigningKeyNotFound(FfiConverterString.read(buf)) - 3 -> KeyManagerException.KeyException(FfiConverterString.read(buf)) - 4 -> KeyManagerException.KeyStoreException(FfiConverterString.read(buf)) - else -> throw RuntimeException("invalid error enum value, something is very wrong!!") - } - - } - - override fun allocationSize(value: KeyManagerException): ULong { - return 4UL - } - - override fun write(value: KeyManagerException, buf: ByteBuffer) { - when(value) { - is KeyManagerException.KeyGenerationFailed -> { - buf.putInt(1) - Unit - } - is KeyManagerException.SigningKeyNotFound -> { - buf.putInt(2) - Unit - } - is KeyManagerException.KeyException -> { - buf.putInt(3) - Unit - } - is KeyManagerException.KeyStoreException -> { - buf.putInt(4) - Unit - } - }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } - } - -} - - - -sealed class KeySelector { - - data class KeyId( - val `keyId`: kotlin.String) : KeySelector() { - companion object - } - - data class MethodType( - val `verificationMethodType`: VerificationMethodType) : KeySelector() { - companion object - } - - - - companion object -} - -public object FfiConverterTypeKeySelector : FfiConverterRustBuffer{ - override fun read(buf: ByteBuffer): KeySelector { - return when(buf.getInt()) { - 1 -> KeySelector.KeyId( - FfiConverterString.read(buf), - ) - 2 -> KeySelector.MethodType( - FfiConverterTypeVerificationMethodType.read(buf), - ) - else -> throw RuntimeException("invalid enum value, something is very wrong!!") - } - } - - override fun allocationSize(value: KeySelector) = when(value) { - is KeySelector.KeyId -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - + FfiConverterString.allocationSize(value.`keyId`) - ) - } - is KeySelector.MethodType -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - + FfiConverterTypeVerificationMethodType.allocationSize(value.`verificationMethodType`) - ) - } - } - - override fun write(value: KeySelector, buf: ByteBuffer) { - when(value) { - is KeySelector.KeyId -> { - buf.putInt(1) - FfiConverterString.write(value.`keyId`, buf) - Unit - } - is KeySelector.MethodType -> { - buf.putInt(2) - FfiConverterTypeVerificationMethodType.write(value.`verificationMethodType`, buf) - Unit - } - }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } - } -} - - - - - - - -sealed class KeyStoreException(message: String): Exception(message) { - - class InternalKeyStoreException(message: String) : KeyStoreException(message) - - class KeyException(message: String) : KeyStoreException(message) - - class KeyNotFound(message: String) : KeyStoreException(message) - - class CryptoException(message: String) : KeyStoreException(message) - - class JwkException(message: String) : KeyStoreException(message) - - class UnsupportedOperation(message: String) : KeyStoreException(message) - - - companion object ErrorHandler : UniffiRustCallStatusErrorHandler { - override fun lift(error_buf: RustBuffer.ByValue): KeyStoreException = FfiConverterTypeKeyStoreError.lift(error_buf) - } -} - -public object FfiConverterTypeKeyStoreError : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): KeyStoreException { - - return when(buf.getInt()) { - 1 -> KeyStoreException.InternalKeyStoreException(FfiConverterString.read(buf)) - 2 -> KeyStoreException.KeyException(FfiConverterString.read(buf)) - 3 -> KeyStoreException.KeyNotFound(FfiConverterString.read(buf)) - 4 -> KeyStoreException.CryptoException(FfiConverterString.read(buf)) - 5 -> KeyStoreException.JwkException(FfiConverterString.read(buf)) - 6 -> KeyStoreException.UnsupportedOperation(FfiConverterString.read(buf)) - else -> throw RuntimeException("invalid error enum value, something is very wrong!!") - } - - } - - override fun allocationSize(value: KeyStoreException): ULong { - return 4UL - } - - override fun write(value: KeyStoreException, buf: ByteBuffer) { - when(value) { - is KeyStoreException.InternalKeyStoreException -> { - buf.putInt(1) - Unit - } - is KeyStoreException.KeyException -> { - buf.putInt(2) - Unit - } - is KeyStoreException.KeyNotFound -> { - buf.putInt(3) - Unit - } - is KeyStoreException.CryptoException -> { - buf.putInt(4) - Unit - } - is KeyStoreException.JwkException -> { - buf.putInt(5) - Unit - } - is KeyStoreException.UnsupportedOperation -> { - buf.putInt(6) - Unit - } - }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } - } - -} - - - - -enum class VerificationMethodType { - - VERIFICATION_METHOD, - ASSERTION_METHOD, - AUTHENTICATION, - CAPABILITY_DELEGATION, - CAPABILITY_INVOCATION; - companion object -} - - -public object FfiConverterTypeVerificationMethodType: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer) = try { - VerificationMethodType.values()[buf.getInt() - 1] - } catch (e: IndexOutOfBoundsException) { - throw RuntimeException("invalid enum value, something is very wrong!!", e) - } - - override fun allocationSize(value: VerificationMethodType) = 4UL - - override fun write(value: VerificationMethodType, buf: ByteBuffer) { - buf.putInt(value.ordinal + 1) - } -} - - - - - - -public object FfiConverterOptionalLong: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): kotlin.Long? { - if (buf.get().toInt() == 0) { - return null - } - return FfiConverterLong.read(buf) - } - - override fun allocationSize(value: kotlin.Long?): ULong { - if (value == null) { - return 1UL - } else { - return 1UL + FfiConverterLong.allocationSize(value) - } - } - - override fun write(value: kotlin.Long?, buf: ByteBuffer) { - if (value == null) { - buf.put(0) - } else { - buf.put(1) - FfiConverterLong.write(value, buf) - } - } -} - - - - -public object FfiConverterOptionalString: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): kotlin.String? { - if (buf.get().toInt() == 0) { - return null - } - return FfiConverterString.read(buf) - } - - override fun allocationSize(value: kotlin.String?): ULong { - if (value == null) { - return 1UL - } else { - return 1UL + FfiConverterString.allocationSize(value) - } - } - - override fun write(value: kotlin.String?, buf: ByteBuffer) { - if (value == null) { - buf.put(0) - } else { - buf.put(1) - FfiConverterString.write(value, buf) - } - } -} - - - - -public object FfiConverterOptionalMapStringString: FfiConverterRustBuffer?> { - override fun read(buf: ByteBuffer): Map? { - if (buf.get().toInt() == 0) { - return null - } - return FfiConverterMapStringString.read(buf) - } - - override fun allocationSize(value: Map?): ULong { - if (value == null) { - return 1UL - } else { - return 1UL + FfiConverterMapStringString.allocationSize(value) - } - } - - override fun write(value: Map?, buf: ByteBuffer) { - if (value == null) { - buf.put(0) - } else { - buf.put(1) - FfiConverterMapStringString.write(value, buf) - } - } -} - - - - -public object FfiConverterSequenceUByte: FfiConverterRustBuffer> { - override fun read(buf: ByteBuffer): List { - val len = buf.getInt() - return List(len) { - FfiConverterUByte.read(buf) - } - } - - override fun allocationSize(value: List): ULong { - val sizeForLength = 4UL - val sizeForItems = value.map { FfiConverterUByte.allocationSize(it) }.sum() - return sizeForLength + sizeForItems - } - - override fun write(value: List, buf: ByteBuffer) { - buf.putInt(value.size) - value.iterator().forEach { - FfiConverterUByte.write(it, buf) - } - } -} - - - - -public object FfiConverterSequenceString: FfiConverterRustBuffer> { - override fun read(buf: ByteBuffer): List { - val len = buf.getInt() - return List(len) { - FfiConverterString.read(buf) - } - } - - override fun allocationSize(value: List): ULong { - val sizeForLength = 4UL - val sizeForItems = value.map { FfiConverterString.allocationSize(it) }.sum() - return sizeForLength + sizeForItems - } - - override fun write(value: List, buf: ByteBuffer) { - buf.putInt(value.size) - value.iterator().forEach { - FfiConverterString.write(it, buf) - } - } -} - - - - -public object FfiConverterSequenceTypePrivateKey: FfiConverterRustBuffer> { - override fun read(buf: ByteBuffer): List { - val len = buf.getInt() - return List(len) { - FfiConverterTypePrivateKey.read(buf) - } - } - - override fun allocationSize(value: List): ULong { - val sizeForLength = 4UL - val sizeForItems = value.map { FfiConverterTypePrivateKey.allocationSize(it) }.sum() - return sizeForLength + sizeForItems - } - - override fun write(value: List, buf: ByteBuffer) { - buf.putInt(value.size) - value.iterator().forEach { - FfiConverterTypePrivateKey.write(it, buf) - } - } -} - - - -public object FfiConverterMapStringString: FfiConverterRustBuffer> { - override fun read(buf: ByteBuffer): Map { - val len = buf.getInt() - return buildMap(len) { - repeat(len) { - val k = FfiConverterString.read(buf) - val v = FfiConverterString.read(buf) - this[k] = v - } - } - } - - override fun allocationSize(value: Map): ULong { - val spaceForMapSize = 4UL - val spaceForChildren = value.map { (k, v) -> - FfiConverterString.allocationSize(k) + - FfiConverterString.allocationSize(v) - }.sum() - return spaceForMapSize + spaceForChildren - } - - override fun write(value: Map, buf: ByteBuffer) { - buf.putInt(value.size) - // The parens on `(k, v)` here ensure we're calling the right method, - // which is important for compatibility with older android devices. - // Ref https://blog.danlew.net/2017/03/16/kotlin-puzzler-whose-line-is-it-anyways/ - value.forEach { (k, v) -> - FfiConverterString.write(k, buf) - FfiConverterString.write(v, buf) - } - } -} - - - - - - - - - @Throws(BearerDidException::class) - @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") - suspend fun `bearerDidFromKeyManager`(`didUri`: kotlin.String, `keyManager`: KeyManager) : BearerDid { - return uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_web5_fn_func_bearer_did_from_key_manager(FfiConverterString.lower(`didUri`),FfiConverterTypeKeyManager.lower(`keyManager`),), - { future, callback, continuation -> UniffiLib.INSTANCE.ffi_web5_rust_future_poll_pointer(future, callback, continuation) }, - { future, continuation -> UniffiLib.INSTANCE.ffi_web5_rust_future_complete_pointer(future, continuation) }, - { future -> UniffiLib.INSTANCE.ffi_web5_rust_future_free_pointer(future) }, - // lift function - { FfiConverterTypeBearerDid.lift(it) }, - // Error FFI converter - BearerDidException.ErrorHandler, - ) - } - - @Throws(JwtException::class) fun `signJwt`(`bearerDid`: BearerDid, `keySelector`: KeySelector, `encodedHeader`: kotlin.String, `encodedPayload`: kotlin.String): kotlin.String { - return FfiConverterString.lift( - uniffiRustCallWithError(JwtException) { _status -> - UniffiLib.INSTANCE.uniffi_web5_fn_func_sign_jwt( - FfiConverterTypeBearerDid.lower(`bearerDid`),FfiConverterTypeKeySelector.lower(`keySelector`),FfiConverterString.lower(`encodedHeader`),FfiConverterString.lower(`encodedPayload`),_status) -} - ) - } - - - @Throws(JwtException::class) - @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") - suspend fun `verifyJwt`(`jwt`: kotlin.String) { - return uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_web5_fn_func_verify_jwt(FfiConverterString.lower(`jwt`),), - { future, callback, continuation -> UniffiLib.INSTANCE.ffi_web5_rust_future_poll_void(future, callback, continuation) }, - { future, continuation -> UniffiLib.INSTANCE.ffi_web5_rust_future_complete_void(future, continuation) }, - { future -> UniffiLib.INSTANCE.ffi_web5_rust_future_free_void(future) }, - // lift function - { Unit }, - - // Error FFI converter - JwtException.ErrorHandler, - ) - } - - @Throws(CredentialException::class) - @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") - suspend fun `verifyVcjwt`(`jwt`: kotlin.String) : VerifiableCredential { - return uniffiRustCallAsync( - UniffiLib.INSTANCE.uniffi_web5_fn_func_verify_vcjwt(FfiConverterString.lower(`jwt`),), - { future, callback, continuation -> UniffiLib.INSTANCE.ffi_web5_rust_future_poll_pointer(future, callback, continuation) }, - { future, continuation -> UniffiLib.INSTANCE.ffi_web5_rust_future_complete_pointer(future, continuation) }, - { future -> UniffiLib.INSTANCE.ffi_web5_rust_future_free_pointer(future) }, - // lift function - { FfiConverterTypeVerifiableCredential.lift(it) }, - // Error FFI converter - CredentialException.ErrorHandler, - ) - } diff --git a/binded/kt/src/main/resources/natives/libweb5.dylib b/binded/kt/src/main/resources/natives/libweb5.dylib index 913d857c..e3538e23 100755 Binary files a/binded/kt/src/main/resources/natives/libweb5.dylib and b/binded/kt/src/main/resources/natives/libweb5.dylib differ diff --git a/binded/swift/Sources/UniFFI/web5.swift b/binded/swift/Sources/UniFFI/web5.swift index c945b6f4..c5022179 100644 --- a/binded/swift/Sources/UniFFI/web5.swift +++ b/binded/swift/Sources/UniFFI/web5.swift @@ -381,32 +381,6 @@ fileprivate class UniffiHandleMap { // Public interface members begin here. -fileprivate struct FfiConverterUInt8: FfiConverterPrimitive { - typealias FfiType = UInt8 - typealias SwiftType = UInt8 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt8 { - return try lift(readInt(&buf)) - } - - public static func write(_ value: UInt8, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - -fileprivate struct FfiConverterInt64: FfiConverterPrimitive { - typealias FfiType = Int64 - typealias SwiftType = Int64 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Int64 { - return try lift(readInt(&buf)) - } - - public static func write(_ value: Int64, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - fileprivate struct FfiConverterString: FfiConverter { typealias SwiftType = String typealias FfiType = RustBuffer @@ -445,2464 +419,10 @@ fileprivate struct FfiConverterString: FfiConverter { } } -fileprivate struct FfiConverterData: FfiConverterRustBuffer { - typealias SwiftType = Data - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data { - let len: Int32 = try readInt(&buf) - return Data(try readBytes(&buf, count: Int(len))) - } - - public static func write(_ value: Data, into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - writeBytes(&buf, value) - } -} - - - - -public protocol BearerDidProtocol : AnyObject { - - func sign(keySelector: KeySelector, payload: [UInt8]) throws -> Data - -} - -open class BearerDid: - BearerDidProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - /// - /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer: NoPointer) { - self.pointer = nil - } - - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_web5_fn_clone_bearerdid(self.pointer, $0) } - } - // No primary constructor declared for this class. - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_web5_fn_free_bearerdid(pointer, $0) } - } - - - - -open func sign(keySelector: KeySelector, payload: [UInt8])throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeBearerDidError.lift) { - uniffi_web5_fn_method_bearerdid_sign(self.uniffiClonePointer(), - FfiConverterTypeKeySelector.lower(keySelector), - FfiConverterSequenceUInt8.lower(payload),$0 - ) -}) -} - - -} - -public struct FfiConverterTypeBearerDid: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = BearerDid - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> BearerDid { - return BearerDid(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: BearerDid) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> BearerDid { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: BearerDid, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -public func FfiConverterTypeBearerDid_lift(_ pointer: UnsafeMutableRawPointer) throws -> BearerDid { - return try FfiConverterTypeBearerDid.lift(pointer) -} - -public func FfiConverterTypeBearerDid_lower(_ value: BearerDid) -> UnsafeMutableRawPointer { - return FfiConverterTypeBearerDid.lower(value) -} - - - - -public protocol ClaimsProtocol : AnyObject { - - func encode() throws -> String - - func sign(bearerDid: BearerDid, keySelector: KeySelector) throws -> String - -} - -open class Claims: - ClaimsProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - /// - /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer: NoPointer) { - self.pointer = nil - } - - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_web5_fn_clone_claims(self.pointer, $0) } - } -public convenience init(issuer: String?, subject: String?, audience: String?, expiration: Int64?, notBefore: Int64?, issuedAt: Int64?, jti: String?) { - let pointer = - try! rustCall() { - uniffi_web5_fn_constructor_claims_new( - FfiConverterOptionString.lower(issuer), - FfiConverterOptionString.lower(subject), - FfiConverterOptionString.lower(audience), - FfiConverterOptionInt64.lower(expiration), - FfiConverterOptionInt64.lower(notBefore), - FfiConverterOptionInt64.lower(issuedAt), - FfiConverterOptionString.lower(jti),$0 - ) -} - self.init(unsafeFromRawPointer: pointer) -} - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_web5_fn_free_claims(pointer, $0) } - } - - - - -open func encode()throws -> String { - return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeJwtError.lift) { - uniffi_web5_fn_method_claims_encode(self.uniffiClonePointer(),$0 - ) -}) -} - -open func sign(bearerDid: BearerDid, keySelector: KeySelector)throws -> String { - return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeJwtError.lift) { - uniffi_web5_fn_method_claims_sign(self.uniffiClonePointer(), - FfiConverterTypeBearerDid.lower(bearerDid), - FfiConverterTypeKeySelector.lower(keySelector),$0 - ) -}) -} - - -} - -public struct FfiConverterTypeClaims: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = Claims - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Claims { - return Claims(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: Claims) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Claims { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: Claims, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -public func FfiConverterTypeClaims_lift(_ pointer: UnsafeMutableRawPointer) throws -> Claims { - return try FfiConverterTypeClaims.lift(pointer) -} - -public func FfiConverterTypeClaims_lower(_ value: Claims) -> UnsafeMutableRawPointer { - return FfiConverterTypeClaims.lower(value) -} - - - - -public protocol InMemoryKeyStoreProtocol : AnyObject { - - func exportPrivateKeys() throws -> [PrivateKey] - - func generateNew(curve: Curve, keyAlias: String?) throws -> String - - func getAllAliases() throws -> [String] - - func getPublicKey(keyAlias: String) throws -> PublicKey - - func importPrivateKeys(privateKeys: [PrivateKey]) throws - - func sign(keyAlias: String, payload: [UInt8]) throws -> Data - -} - -open class InMemoryKeyStore: - InMemoryKeyStoreProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - /// - /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer: NoPointer) { - self.pointer = nil - } - - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_web5_fn_clone_inmemorykeystore(self.pointer, $0) } - } -public convenience init() { - let pointer = - try! rustCall() { - uniffi_web5_fn_constructor_inmemorykeystore_new($0 - ) -} - self.init(unsafeFromRawPointer: pointer) -} - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_web5_fn_free_inmemorykeystore(pointer, $0) } - } - - - - -open func exportPrivateKeys()throws -> [PrivateKey] { - return try FfiConverterSequenceTypePrivateKey.lift(try rustCallWithError(FfiConverterTypeKeyStoreError.lift) { - uniffi_web5_fn_method_inmemorykeystore_export_private_keys(self.uniffiClonePointer(),$0 - ) -}) -} - -open func generateNew(curve: Curve, keyAlias: String?)throws -> String { - return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeKeyStoreError.lift) { - uniffi_web5_fn_method_inmemorykeystore_generate_new(self.uniffiClonePointer(), - FfiConverterTypeCurve.lower(curve), - FfiConverterOptionString.lower(keyAlias),$0 - ) -}) -} - -open func getAllAliases()throws -> [String] { - return try FfiConverterSequenceString.lift(try rustCallWithError(FfiConverterTypeKeyStoreError.lift) { - uniffi_web5_fn_method_inmemorykeystore_get_all_aliases(self.uniffiClonePointer(),$0 - ) -}) -} - -open func getPublicKey(keyAlias: String)throws -> PublicKey { - return try FfiConverterTypePublicKey.lift(try rustCallWithError(FfiConverterTypeKeyStoreError.lift) { - uniffi_web5_fn_method_inmemorykeystore_get_public_key(self.uniffiClonePointer(), - FfiConverterString.lower(keyAlias),$0 - ) -}) -} - -open func importPrivateKeys(privateKeys: [PrivateKey])throws {try rustCallWithError(FfiConverterTypeKeyStoreError.lift) { - uniffi_web5_fn_method_inmemorykeystore_import_private_keys(self.uniffiClonePointer(), - FfiConverterSequenceTypePrivateKey.lower(privateKeys),$0 - ) -} -} - -open func sign(keyAlias: String, payload: [UInt8])throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeKeyStoreError.lift) { - uniffi_web5_fn_method_inmemorykeystore_sign(self.uniffiClonePointer(), - FfiConverterString.lower(keyAlias), - FfiConverterSequenceUInt8.lower(payload),$0 - ) -}) -} - - -} - -public struct FfiConverterTypeInMemoryKeyStore: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = InMemoryKeyStore - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> InMemoryKeyStore { - return InMemoryKeyStore(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: InMemoryKeyStore) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> InMemoryKeyStore { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: InMemoryKeyStore, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -public func FfiConverterTypeInMemoryKeyStore_lift(_ pointer: UnsafeMutableRawPointer) throws -> InMemoryKeyStore { - return try FfiConverterTypeInMemoryKeyStore.lift(pointer) -} - -public func FfiConverterTypeInMemoryKeyStore_lower(_ value: InMemoryKeyStore) -> UnsafeMutableRawPointer { - return FfiConverterTypeInMemoryKeyStore.lower(value) -} - - - - -public protocol JwkProtocol : AnyObject { - - func alias() throws -> String - - func computeThumbprint() throws -> String - - func jwk() throws -> Jwk - - func sign(payload: [UInt8]) throws -> Data - - func toPublic() throws -> PublicKey - - func verify(payload: [UInt8], signature: [UInt8]) throws - -} - -open class Jwk: - JwkProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - /// - /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer: NoPointer) { - self.pointer = nil - } - - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_web5_fn_clone_jwk(self.pointer, $0) } - } - // No primary constructor declared for this class. - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_web5_fn_free_jwk(pointer, $0) } - } - - - - -open func alias()throws -> String { - return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeKeyError.lift) { - uniffi_web5_fn_method_jwk_alias(self.uniffiClonePointer(),$0 - ) -}) -} - -open func computeThumbprint()throws -> String { - return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeJwkError.lift) { - uniffi_web5_fn_method_jwk_compute_thumbprint(self.uniffiClonePointer(),$0 - ) -}) -} - -open func jwk()throws -> Jwk { - return try FfiConverterTypeJwk.lift(try rustCallWithError(FfiConverterTypeKeyError.lift) { - uniffi_web5_fn_method_jwk_jwk(self.uniffiClonePointer(),$0 - ) -}) -} - -open func sign(payload: [UInt8])throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeKeyError.lift) { - uniffi_web5_fn_method_jwk_sign(self.uniffiClonePointer(), - FfiConverterSequenceUInt8.lower(payload),$0 - ) -}) -} - -open func toPublic()throws -> PublicKey { - return try FfiConverterTypePublicKey.lift(try rustCallWithError(FfiConverterTypeKeyError.lift) { - uniffi_web5_fn_method_jwk_to_public(self.uniffiClonePointer(),$0 - ) -}) -} - -open func verify(payload: [UInt8], signature: [UInt8])throws {try rustCallWithError(FfiConverterTypeKeyError.lift) { - uniffi_web5_fn_method_jwk_verify(self.uniffiClonePointer(), - FfiConverterSequenceUInt8.lower(payload), - FfiConverterSequenceUInt8.lower(signature),$0 - ) -} -} - - -} - -public struct FfiConverterTypeJwk: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = Jwk - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Jwk { - return Jwk(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: Jwk) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Jwk { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: Jwk, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -public func FfiConverterTypeJwk_lift(_ pointer: UnsafeMutableRawPointer) throws -> Jwk { - return try FfiConverterTypeJwk.lift(pointer) -} - -public func FfiConverterTypeJwk_lower(_ value: Jwk) -> UnsafeMutableRawPointer { - return FfiConverterTypeJwk.lower(value) -} - - - - -public protocol KeyProtocol : AnyObject { - - func alias() throws -> String - - func jwk() throws -> Jwk - -} - -open class Key: - KeyProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - /// - /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer: NoPointer) { - self.pointer = nil - } - - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_web5_fn_clone_key(self.pointer, $0) } - } - // No primary constructor declared for this class. - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_web5_fn_free_key(pointer, $0) } - } - - - - -open func alias()throws -> String { - return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeKeyError.lift) { - uniffi_web5_fn_method_key_alias(self.uniffiClonePointer(),$0 - ) -}) -} - -open func jwk()throws -> Jwk { - return try FfiConverterTypeJwk.lift(try rustCallWithError(FfiConverterTypeKeyError.lift) { - uniffi_web5_fn_method_key_jwk(self.uniffiClonePointer(),$0 - ) -}) -} - - -} - -public struct FfiConverterTypeKey: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = Key - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Key { - return Key(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: Key) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Key { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: Key, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -public func FfiConverterTypeKey_lift(_ pointer: UnsafeMutableRawPointer) throws -> Key { - return try FfiConverterTypeKey.lift(pointer) -} - -public func FfiConverterTypeKey_lower(_ value: Key) -> UnsafeMutableRawPointer { - return FfiConverterTypeKey.lower(value) -} - - - - -public protocol KeyManagerProtocol : AnyObject { - - func exportPrivateKeys() throws -> [PrivateKey] - - func generatePrivateKey(curve: Curve, keyAlias: String?) throws -> String - - func getPublicKey(keyAlias: String) throws -> PublicKey - - func importPrivateKeys(privateKeys: [PrivateKey]) throws - - func sign(keyAlias: String, payload: [UInt8]) throws -> Data - -} - -open class KeyManager: - KeyManagerProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - /// - /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer: NoPointer) { - self.pointer = nil - } - - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_web5_fn_clone_keymanager(self.pointer, $0) } - } - // No primary constructor declared for this class. - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_web5_fn_free_keymanager(pointer, $0) } - } - - - - -open func exportPrivateKeys()throws -> [PrivateKey] { - return try FfiConverterSequenceTypePrivateKey.lift(try rustCallWithError(FfiConverterTypeKeyManagerError.lift) { - uniffi_web5_fn_method_keymanager_export_private_keys(self.uniffiClonePointer(),$0 - ) -}) -} - -open func generatePrivateKey(curve: Curve, keyAlias: String?)throws -> String { - return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeKeyManagerError.lift) { - uniffi_web5_fn_method_keymanager_generate_private_key(self.uniffiClonePointer(), - FfiConverterTypeCurve.lower(curve), - FfiConverterOptionString.lower(keyAlias),$0 - ) -}) -} - -open func getPublicKey(keyAlias: String)throws -> PublicKey { - return try FfiConverterTypePublicKey.lift(try rustCallWithError(FfiConverterTypeKeyManagerError.lift) { - uniffi_web5_fn_method_keymanager_get_public_key(self.uniffiClonePointer(), - FfiConverterString.lower(keyAlias),$0 - ) -}) -} - -open func importPrivateKeys(privateKeys: [PrivateKey])throws {try rustCallWithError(FfiConverterTypeKeyManagerError.lift) { - uniffi_web5_fn_method_keymanager_import_private_keys(self.uniffiClonePointer(), - FfiConverterSequenceTypePrivateKey.lower(privateKeys),$0 - ) -} -} - -open func sign(keyAlias: String, payload: [UInt8])throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeKeyManagerError.lift) { - uniffi_web5_fn_method_keymanager_sign(self.uniffiClonePointer(), - FfiConverterString.lower(keyAlias), - FfiConverterSequenceUInt8.lower(payload),$0 - ) -}) -} - - -} - -public struct FfiConverterTypeKeyManager: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = KeyManager - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> KeyManager { - return KeyManager(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: KeyManager) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeyManager { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: KeyManager, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -public func FfiConverterTypeKeyManager_lift(_ pointer: UnsafeMutableRawPointer) throws -> KeyManager { - return try FfiConverterTypeKeyManager.lift(pointer) -} - -public func FfiConverterTypeKeyManager_lower(_ value: KeyManager) -> UnsafeMutableRawPointer { - return FfiConverterTypeKeyManager.lower(value) -} - - - - -public protocol KeyStoreProtocol : AnyObject { - - func exportPrivateKeys() throws -> [PrivateKey] - - func generateNew(curve: Curve, keyAlias: String?) throws -> String - - func getAllAliases() throws -> [String] - - func getPublicKey(keyAlias: String) throws -> PublicKey - - func importPrivateKeys(privateKeys: [PrivateKey]) throws - - func sign(keyAlias: String, payload: [UInt8]) throws -> Data - -} - -open class KeyStore: - KeyStoreProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - /// - /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer: NoPointer) { - self.pointer = nil - } - - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_web5_fn_clone_keystore(self.pointer, $0) } - } - // No primary constructor declared for this class. - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_web5_fn_free_keystore(pointer, $0) } - } - - - - -open func exportPrivateKeys()throws -> [PrivateKey] { - return try FfiConverterSequenceTypePrivateKey.lift(try rustCallWithError(FfiConverterTypeKeyStoreError.lift) { - uniffi_web5_fn_method_keystore_export_private_keys(self.uniffiClonePointer(),$0 - ) -}) -} - -open func generateNew(curve: Curve, keyAlias: String?)throws -> String { - return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeKeyStoreError.lift) { - uniffi_web5_fn_method_keystore_generate_new(self.uniffiClonePointer(), - FfiConverterTypeCurve.lower(curve), - FfiConverterOptionString.lower(keyAlias),$0 - ) -}) -} - -open func getAllAliases()throws -> [String] { - return try FfiConverterSequenceString.lift(try rustCallWithError(FfiConverterTypeKeyStoreError.lift) { - uniffi_web5_fn_method_keystore_get_all_aliases(self.uniffiClonePointer(),$0 - ) -}) -} - -open func getPublicKey(keyAlias: String)throws -> PublicKey { - return try FfiConverterTypePublicKey.lift(try rustCallWithError(FfiConverterTypeKeyStoreError.lift) { - uniffi_web5_fn_method_keystore_get_public_key(self.uniffiClonePointer(), - FfiConverterString.lower(keyAlias),$0 - ) -}) -} - -open func importPrivateKeys(privateKeys: [PrivateKey])throws {try rustCallWithError(FfiConverterTypeKeyStoreError.lift) { - uniffi_web5_fn_method_keystore_import_private_keys(self.uniffiClonePointer(), - FfiConverterSequenceTypePrivateKey.lower(privateKeys),$0 - ) -} -} - -open func sign(keyAlias: String, payload: [UInt8])throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeKeyStoreError.lift) { - uniffi_web5_fn_method_keystore_sign(self.uniffiClonePointer(), - FfiConverterString.lower(keyAlias), - FfiConverterSequenceUInt8.lower(payload),$0 - ) -}) -} - - -} - -public struct FfiConverterTypeKeyStore: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = KeyStore - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> KeyStore { - return KeyStore(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: KeyStore) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeyStore { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: KeyStore, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -public func FfiConverterTypeKeyStore_lift(_ pointer: UnsafeMutableRawPointer) throws -> KeyStore { - return try FfiConverterTypeKeyStore.lift(pointer) -} - -public func FfiConverterTypeKeyStore_lower(_ value: KeyStore) -> UnsafeMutableRawPointer { - return FfiConverterTypeKeyStore.lower(value) -} - - - - -public protocol LocalKeyManagerProtocol : AnyObject { - - func exportPrivateKeys() throws -> [PrivateKey] - - func generatePrivateKey(curve: Curve, keyAlias: String?) throws -> String - - func getPublicKey(keyAlias: String) throws -> PublicKey - - func importPrivateKeys(privateKeys: [PrivateKey]) throws - - func sign(keyAlias: String, payload: [UInt8]) throws -> Data - -} - -open class LocalKeyManager: - LocalKeyManagerProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - /// - /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer: NoPointer) { - self.pointer = nil - } - - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_web5_fn_clone_localkeymanager(self.pointer, $0) } - } -public convenience init(keyStore: KeyStore) { - let pointer = - try! rustCall() { - uniffi_web5_fn_constructor_localkeymanager_new( - FfiConverterTypeKeyStore.lower(keyStore),$0 - ) -} - self.init(unsafeFromRawPointer: pointer) -} - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_web5_fn_free_localkeymanager(pointer, $0) } - } - - -public static func newInMemory() -> LocalKeyManager { - return try! FfiConverterTypeLocalKeyManager.lift(try! rustCall() { - uniffi_web5_fn_constructor_localkeymanager_new_in_memory($0 - ) -}) -} - - - -open func exportPrivateKeys()throws -> [PrivateKey] { - return try FfiConverterSequenceTypePrivateKey.lift(try rustCallWithError(FfiConverterTypeKeyManagerError.lift) { - uniffi_web5_fn_method_localkeymanager_export_private_keys(self.uniffiClonePointer(),$0 - ) -}) -} - -open func generatePrivateKey(curve: Curve, keyAlias: String?)throws -> String { - return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeKeyManagerError.lift) { - uniffi_web5_fn_method_localkeymanager_generate_private_key(self.uniffiClonePointer(), - FfiConverterTypeCurve.lower(curve), - FfiConverterOptionString.lower(keyAlias),$0 - ) -}) -} - -open func getPublicKey(keyAlias: String)throws -> PublicKey { - return try FfiConverterTypePublicKey.lift(try rustCallWithError(FfiConverterTypeKeyManagerError.lift) { - uniffi_web5_fn_method_localkeymanager_get_public_key(self.uniffiClonePointer(), - FfiConverterString.lower(keyAlias),$0 - ) -}) -} - -open func importPrivateKeys(privateKeys: [PrivateKey])throws {try rustCallWithError(FfiConverterTypeKeyManagerError.lift) { - uniffi_web5_fn_method_localkeymanager_import_private_keys(self.uniffiClonePointer(), - FfiConverterSequenceTypePrivateKey.lower(privateKeys),$0 - ) -} -} - -open func sign(keyAlias: String, payload: [UInt8])throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeKeyManagerError.lift) { - uniffi_web5_fn_method_localkeymanager_sign(self.uniffiClonePointer(), - FfiConverterString.lower(keyAlias), - FfiConverterSequenceUInt8.lower(payload),$0 - ) -}) -} - - -} - -public struct FfiConverterTypeLocalKeyManager: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = LocalKeyManager - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> LocalKeyManager { - return LocalKeyManager(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: LocalKeyManager) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> LocalKeyManager { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: LocalKeyManager, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -public func FfiConverterTypeLocalKeyManager_lift(_ pointer: UnsafeMutableRawPointer) throws -> LocalKeyManager { - return try FfiConverterTypeLocalKeyManager.lift(pointer) -} - -public func FfiConverterTypeLocalKeyManager_lower(_ value: LocalKeyManager) -> UnsafeMutableRawPointer { - return FfiConverterTypeLocalKeyManager.lower(value) -} - - - - -public protocol PrivateKeyProtocol : AnyObject { - - func sign(payload: [UInt8]) throws -> Data - - func toPublic() throws -> PublicKey - -} - -open class PrivateKey: - PrivateKeyProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - /// - /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer: NoPointer) { - self.pointer = nil - } - - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_web5_fn_clone_privatekey(self.pointer, $0) } - } - // No primary constructor declared for this class. - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_web5_fn_free_privatekey(pointer, $0) } - } - - - - -open func sign(payload: [UInt8])throws -> Data { - return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeKeyError.lift) { - uniffi_web5_fn_method_privatekey_sign(self.uniffiClonePointer(), - FfiConverterSequenceUInt8.lower(payload),$0 - ) -}) -} - -open func toPublic()throws -> PublicKey { - return try FfiConverterTypePublicKey.lift(try rustCallWithError(FfiConverterTypeKeyError.lift) { - uniffi_web5_fn_method_privatekey_to_public(self.uniffiClonePointer(),$0 - ) -}) -} - - -} - -public struct FfiConverterTypePrivateKey: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = PrivateKey - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> PrivateKey { - return PrivateKey(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: PrivateKey) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PrivateKey { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: PrivateKey, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -public func FfiConverterTypePrivateKey_lift(_ pointer: UnsafeMutableRawPointer) throws -> PrivateKey { - return try FfiConverterTypePrivateKey.lift(pointer) -} - -public func FfiConverterTypePrivateKey_lower(_ value: PrivateKey) -> UnsafeMutableRawPointer { - return FfiConverterTypePrivateKey.lower(value) -} - - - - -public protocol PublicKeyProtocol : AnyObject { - - func verify(payload: [UInt8], signature: [UInt8]) throws - -} - -open class PublicKey: - PublicKeyProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - /// - /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer: NoPointer) { - self.pointer = nil - } - - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_web5_fn_clone_publickey(self.pointer, $0) } - } - // No primary constructor declared for this class. - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_web5_fn_free_publickey(pointer, $0) } - } - - - - -open func verify(payload: [UInt8], signature: [UInt8])throws {try rustCallWithError(FfiConverterTypeKeyError.lift) { - uniffi_web5_fn_method_publickey_verify(self.uniffiClonePointer(), - FfiConverterSequenceUInt8.lower(payload), - FfiConverterSequenceUInt8.lower(signature),$0 - ) -} -} - - -} - -public struct FfiConverterTypePublicKey: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = PublicKey - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> PublicKey { - return PublicKey(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: PublicKey) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PublicKey { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: PublicKey, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -public func FfiConverterTypePublicKey_lift(_ pointer: UnsafeMutableRawPointer) throws -> PublicKey { - return try FfiConverterTypePublicKey.lift(pointer) -} - -public func FfiConverterTypePublicKey_lower(_ value: PublicKey) -> UnsafeMutableRawPointer { - return FfiConverterTypePublicKey.lower(value) -} - - - - -public protocol VerifiableCredentialProtocol : AnyObject { - - func sign(bearerDid: BearerDid, keySelector: KeySelector) throws -> String - -} - -open class VerifiableCredential: - VerifiableCredentialProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - /// This constructor can be used to instantiate a fake object. - /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - /// - /// - Warning: - /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. - public init(noPointer: NoPointer) { - self.pointer = nil - } - - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_web5_fn_clone_verifiablecredential(self.pointer, $0) } - } -public convenience init(context: [String], id: String, type: [String], issuer: String, issuanceDate: Int64, expirationDate: Int64?, credentialSubject: CredentialSubject) { - let pointer = - try! rustCall() { - uniffi_web5_fn_constructor_verifiablecredential_new( - FfiConverterSequenceString.lower(context), - FfiConverterString.lower(id), - FfiConverterSequenceString.lower(type), - FfiConverterString.lower(issuer), - FfiConverterInt64.lower(issuanceDate), - FfiConverterOptionInt64.lower(expirationDate), - FfiConverterTypeCredentialSubject.lower(credentialSubject),$0 - ) -} - self.init(unsafeFromRawPointer: pointer) -} - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_web5_fn_free_verifiablecredential(pointer, $0) } - } - - - - -open func sign(bearerDid: BearerDid, keySelector: KeySelector)throws -> String { - return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeCredentialError.lift) { - uniffi_web5_fn_method_verifiablecredential_sign(self.uniffiClonePointer(), - FfiConverterTypeBearerDid.lower(bearerDid), - FfiConverterTypeKeySelector.lower(keySelector),$0 - ) -}) -} - - -} - -public struct FfiConverterTypeVerifiableCredential: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = VerifiableCredential - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> VerifiableCredential { - return VerifiableCredential(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: VerifiableCredential) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> VerifiableCredential { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: VerifiableCredential, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -public func FfiConverterTypeVerifiableCredential_lift(_ pointer: UnsafeMutableRawPointer) throws -> VerifiableCredential { - return try FfiConverterTypeVerifiableCredential.lift(pointer) -} - -public func FfiConverterTypeVerifiableCredential_lower(_ value: VerifiableCredential) -> UnsafeMutableRawPointer { - return FfiConverterTypeVerifiableCredential.lower(value) -} - - -public struct CredentialSubject { - public var id: String - public var params: [String: String]? - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(id: String, params: [String: String]?) { - self.id = id - self.params = params - } -} - - - -extension CredentialSubject: Equatable, Hashable { - public static func ==(lhs: CredentialSubject, rhs: CredentialSubject) -> Bool { - if lhs.id != rhs.id { - return false - } - if lhs.params != rhs.params { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(id) - hasher.combine(params) - } -} - - -public struct FfiConverterTypeCredentialSubject: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CredentialSubject { - return - try CredentialSubject( - id: FfiConverterString.read(from: &buf), - params: FfiConverterOptionDictionaryStringString.read(from: &buf) - ) - } - - public static func write(_ value: CredentialSubject, into buf: inout [UInt8]) { - FfiConverterString.write(value.id, into: &buf) - FfiConverterOptionDictionaryStringString.write(value.params, into: &buf) - } -} - - -public func FfiConverterTypeCredentialSubject_lift(_ buf: RustBuffer) throws -> CredentialSubject { - return try FfiConverterTypeCredentialSubject.lift(buf) -} - -public func FfiConverterTypeCredentialSubject_lower(_ value: CredentialSubject) -> RustBuffer { - return FfiConverterTypeCredentialSubject.lower(value) -} - - -public enum BearerDidError { - - - - case VerificationMethodNotFound(message: String) - - case KeyManagerError(message: String) - - case KeyError(message: String) - - case DocumentError(message: String) - - case ResolutionError(message: String) - - case IdentifierError(message: String) - -} - - -public struct FfiConverterTypeBearerDidError: FfiConverterRustBuffer { - typealias SwiftType = BearerDidError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> BearerDidError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .VerificationMethodNotFound( - message: try FfiConverterString.read(from: &buf) - ) - - case 2: return .KeyManagerError( - message: try FfiConverterString.read(from: &buf) - ) - - case 3: return .KeyError( - message: try FfiConverterString.read(from: &buf) - ) - - case 4: return .DocumentError( - message: try FfiConverterString.read(from: &buf) - ) - - case 5: return .ResolutionError( - message: try FfiConverterString.read(from: &buf) - ) - - case 6: return .IdentifierError( - message: try FfiConverterString.read(from: &buf) - ) - - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: BearerDidError, into buf: inout [UInt8]) { - switch value { - - - - - case .VerificationMethodNotFound(_ /* message is ignored*/): - writeInt(&buf, Int32(1)) - case .KeyManagerError(_ /* message is ignored*/): - writeInt(&buf, Int32(2)) - case .KeyError(_ /* message is ignored*/): - writeInt(&buf, Int32(3)) - case .DocumentError(_ /* message is ignored*/): - writeInt(&buf, Int32(4)) - case .ResolutionError(_ /* message is ignored*/): - writeInt(&buf, Int32(5)) - case .IdentifierError(_ /* message is ignored*/): - writeInt(&buf, Int32(6)) - - - } - } -} - - -extension BearerDidError: Equatable, Hashable {} - -extension BearerDidError: Error { } - - -public enum CredentialError { - - - - case JwtError(message: String) - - case JwsError(message: String) - -} - - -public struct FfiConverterTypeCredentialError: FfiConverterRustBuffer { - typealias SwiftType = CredentialError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CredentialError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .JwtError( - message: try FfiConverterString.read(from: &buf) - ) - - case 2: return .JwsError( - message: try FfiConverterString.read(from: &buf) - ) - - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: CredentialError, into buf: inout [UInt8]) { - switch value { - - - - - case .JwtError(_ /* message is ignored*/): - writeInt(&buf, Int32(1)) - case .JwsError(_ /* message is ignored*/): - writeInt(&buf, Int32(2)) - - - } - } -} - - -extension CredentialError: Equatable, Hashable {} - -extension CredentialError: Error { } - -// Note that we don't yet support `indirect` for enums. -// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. - -public enum Curve { - - case secp256k1 - case ed25519 -} - - -public struct FfiConverterTypeCurve: FfiConverterRustBuffer { - typealias SwiftType = Curve - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Curve { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .secp256k1 - - case 2: return .ed25519 - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: Curve, into buf: inout [UInt8]) { - switch value { - - - case .secp256k1: - writeInt(&buf, Int32(1)) - - - case .ed25519: - writeInt(&buf, Int32(2)) - - } - } -} - - -public func FfiConverterTypeCurve_lift(_ buf: RustBuffer) throws -> Curve { - return try FfiConverterTypeCurve.lift(buf) -} - -public func FfiConverterTypeCurve_lower(_ value: Curve) -> RustBuffer { - return FfiConverterTypeCurve.lower(value) -} - - - -extension Curve: Equatable, Hashable {} - - - - -public enum JwkError { - - - - case ThumbprintFailed(message: String) - -} - - -public struct FfiConverterTypeJwkError: FfiConverterRustBuffer { - typealias SwiftType = JwkError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> JwkError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .ThumbprintFailed( - message: try FfiConverterString.read(from: &buf) - ) - - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: JwkError, into buf: inout [UInt8]) { - switch value { - - - - - case .ThumbprintFailed(_ /* message is ignored*/): - writeInt(&buf, Int32(1)) - - - } - } -} - - -extension JwkError: Equatable, Hashable {} - -extension JwkError: Error { } - - -public enum JwtError { - - - - case JwsError(message: String) - - case SerializationError(message: String) - - case DeserializationError(message: String) - -} - - -public struct FfiConverterTypeJwtError: FfiConverterRustBuffer { - typealias SwiftType = JwtError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> JwtError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .JwsError( - message: try FfiConverterString.read(from: &buf) - ) - - case 2: return .SerializationError( - message: try FfiConverterString.read(from: &buf) - ) - - case 3: return .DeserializationError( - message: try FfiConverterString.read(from: &buf) - ) - - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: JwtError, into buf: inout [UInt8]) { - switch value { - - - - - case .JwsError(_ /* message is ignored*/): - writeInt(&buf, Int32(1)) - case .SerializationError(_ /* message is ignored*/): - writeInt(&buf, Int32(2)) - case .DeserializationError(_ /* message is ignored*/): - writeInt(&buf, Int32(3)) - - - } - } -} - - -extension JwtError: Equatable, Hashable {} - -extension JwtError: Error { } - - -public enum KeyError { - - - - case KeyGenerationFailed(message: String) - - case SerializationFailed(message: String) - - case CurveNotFound(message: String) - - case AlgorithmNotFound(message: String) - - case JwkError(message: String) - - case CryptoError(message: String) - -} - - -public struct FfiConverterTypeKeyError: FfiConverterRustBuffer { - typealias SwiftType = KeyError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeyError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .KeyGenerationFailed( - message: try FfiConverterString.read(from: &buf) - ) - - case 2: return .SerializationFailed( - message: try FfiConverterString.read(from: &buf) - ) - - case 3: return .CurveNotFound( - message: try FfiConverterString.read(from: &buf) - ) - - case 4: return .AlgorithmNotFound( - message: try FfiConverterString.read(from: &buf) - ) - - case 5: return .JwkError( - message: try FfiConverterString.read(from: &buf) - ) - - case 6: return .CryptoError( - message: try FfiConverterString.read(from: &buf) - ) - - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: KeyError, into buf: inout [UInt8]) { - switch value { - - - - - case .KeyGenerationFailed(_ /* message is ignored*/): - writeInt(&buf, Int32(1)) - case .SerializationFailed(_ /* message is ignored*/): - writeInt(&buf, Int32(2)) - case .CurveNotFound(_ /* message is ignored*/): - writeInt(&buf, Int32(3)) - case .AlgorithmNotFound(_ /* message is ignored*/): - writeInt(&buf, Int32(4)) - case .JwkError(_ /* message is ignored*/): - writeInt(&buf, Int32(5)) - case .CryptoError(_ /* message is ignored*/): - writeInt(&buf, Int32(6)) - - - } - } -} - - -extension KeyError: Equatable, Hashable {} - -extension KeyError: Error { } - - -public enum KeyManagerError { - - - - case KeyGenerationFailed(message: String) - - case SigningKeyNotFound(message: String) - - case KeyError(message: String) - - case KeyStoreError(message: String) - -} - - -public struct FfiConverterTypeKeyManagerError: FfiConverterRustBuffer { - typealias SwiftType = KeyManagerError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeyManagerError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .KeyGenerationFailed( - message: try FfiConverterString.read(from: &buf) - ) - - case 2: return .SigningKeyNotFound( - message: try FfiConverterString.read(from: &buf) - ) - - case 3: return .KeyError( - message: try FfiConverterString.read(from: &buf) - ) - - case 4: return .KeyStoreError( - message: try FfiConverterString.read(from: &buf) - ) - - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: KeyManagerError, into buf: inout [UInt8]) { - switch value { - - - - - case .KeyGenerationFailed(_ /* message is ignored*/): - writeInt(&buf, Int32(1)) - case .SigningKeyNotFound(_ /* message is ignored*/): - writeInt(&buf, Int32(2)) - case .KeyError(_ /* message is ignored*/): - writeInt(&buf, Int32(3)) - case .KeyStoreError(_ /* message is ignored*/): - writeInt(&buf, Int32(4)) - - - } - } -} - - -extension KeyManagerError: Equatable, Hashable {} - -extension KeyManagerError: Error { } - -// Note that we don't yet support `indirect` for enums. -// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. - -public enum KeySelector { - - case keyId(keyId: String - ) - case methodType(verificationMethodType: VerificationMethodType - ) -} - - -public struct FfiConverterTypeKeySelector: FfiConverterRustBuffer { - typealias SwiftType = KeySelector - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeySelector { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .keyId(keyId: try FfiConverterString.read(from: &buf) - ) - - case 2: return .methodType(verificationMethodType: try FfiConverterTypeVerificationMethodType.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: KeySelector, into buf: inout [UInt8]) { - switch value { - - - case let .keyId(keyId): - writeInt(&buf, Int32(1)) - FfiConverterString.write(keyId, into: &buf) - - - case let .methodType(verificationMethodType): - writeInt(&buf, Int32(2)) - FfiConverterTypeVerificationMethodType.write(verificationMethodType, into: &buf) - - } - } -} - - -public func FfiConverterTypeKeySelector_lift(_ buf: RustBuffer) throws -> KeySelector { - return try FfiConverterTypeKeySelector.lift(buf) -} - -public func FfiConverterTypeKeySelector_lower(_ value: KeySelector) -> RustBuffer { - return FfiConverterTypeKeySelector.lower(value) -} - - - -extension KeySelector: Equatable, Hashable {} - - - - -public enum KeyStoreError { - - - - case InternalKeyStoreError(message: String) - - case KeyError(message: String) - - case KeyNotFound(message: String) - - case CryptoError(message: String) - - case JwkError(message: String) - - case UnsupportedOperation(message: String) - -} - - -public struct FfiConverterTypeKeyStoreError: FfiConverterRustBuffer { - typealias SwiftType = KeyStoreError - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeyStoreError { - let variant: Int32 = try readInt(&buf) - switch variant { - - - - - case 1: return .InternalKeyStoreError( - message: try FfiConverterString.read(from: &buf) - ) - - case 2: return .KeyError( - message: try FfiConverterString.read(from: &buf) - ) - - case 3: return .KeyNotFound( - message: try FfiConverterString.read(from: &buf) - ) - - case 4: return .CryptoError( - message: try FfiConverterString.read(from: &buf) - ) - - case 5: return .JwkError( - message: try FfiConverterString.read(from: &buf) - ) - - case 6: return .UnsupportedOperation( - message: try FfiConverterString.read(from: &buf) - ) - - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: KeyStoreError, into buf: inout [UInt8]) { - switch value { - - - - - case .InternalKeyStoreError(_ /* message is ignored*/): - writeInt(&buf, Int32(1)) - case .KeyError(_ /* message is ignored*/): - writeInt(&buf, Int32(2)) - case .KeyNotFound(_ /* message is ignored*/): - writeInt(&buf, Int32(3)) - case .CryptoError(_ /* message is ignored*/): - writeInt(&buf, Int32(4)) - case .JwkError(_ /* message is ignored*/): - writeInt(&buf, Int32(5)) - case .UnsupportedOperation(_ /* message is ignored*/): - writeInt(&buf, Int32(6)) - - - } - } -} - - -extension KeyStoreError: Equatable, Hashable {} - -extension KeyStoreError: Error { } - -// Note that we don't yet support `indirect` for enums. -// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. - -public enum VerificationMethodType { - - case verificationMethod - case assertionMethod - case authentication - case capabilityDelegation - case capabilityInvocation -} - - -public struct FfiConverterTypeVerificationMethodType: FfiConverterRustBuffer { - typealias SwiftType = VerificationMethodType - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> VerificationMethodType { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .verificationMethod - - case 2: return .assertionMethod - - case 3: return .authentication - - case 4: return .capabilityDelegation - - case 5: return .capabilityInvocation - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: VerificationMethodType, into buf: inout [UInt8]) { - switch value { - - - case .verificationMethod: - writeInt(&buf, Int32(1)) - - - case .assertionMethod: - writeInt(&buf, Int32(2)) - - - case .authentication: - writeInt(&buf, Int32(3)) - - - case .capabilityDelegation: - writeInt(&buf, Int32(4)) - - - case .capabilityInvocation: - writeInt(&buf, Int32(5)) - - } - } -} - - -public func FfiConverterTypeVerificationMethodType_lift(_ buf: RustBuffer) throws -> VerificationMethodType { - return try FfiConverterTypeVerificationMethodType.lift(buf) -} - -public func FfiConverterTypeVerificationMethodType_lower(_ value: VerificationMethodType) -> RustBuffer { - return FfiConverterTypeVerificationMethodType.lower(value) -} - - - -extension VerificationMethodType: Equatable, Hashable {} - - - -fileprivate struct FfiConverterOptionInt64: FfiConverterRustBuffer { - typealias SwiftType = Int64? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterInt64.write(value, into: &buf) - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { - switch try readInt(&buf) as Int8 { - case 0: return nil - case 1: return try FfiConverterInt64.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer { - typealias SwiftType = String? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterString.write(value, into: &buf) - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { - switch try readInt(&buf) as Int8 { - case 0: return nil - case 1: return try FfiConverterString.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -fileprivate struct FfiConverterOptionDictionaryStringString: FfiConverterRustBuffer { - typealias SwiftType = [String: String]? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterDictionaryStringString.write(value, into: &buf) - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { - switch try readInt(&buf) as Int8 { - case 0: return nil - case 1: return try FfiConverterDictionaryStringString.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -fileprivate struct FfiConverterSequenceUInt8: FfiConverterRustBuffer { - typealias SwiftType = [UInt8] - - public static func write(_ value: [UInt8], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterUInt8.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [UInt8] { - let len: Int32 = try readInt(&buf) - var seq = [UInt8]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterUInt8.read(from: &buf)) - } - return seq - } -} - -fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer { - typealias SwiftType = [String] - - public static func write(_ value: [String], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterString.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String] { - let len: Int32 = try readInt(&buf) - var seq = [String]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterString.read(from: &buf)) - } - return seq - } -} - -fileprivate struct FfiConverterSequenceTypePrivateKey: FfiConverterRustBuffer { - typealias SwiftType = [PrivateKey] - - public static func write(_ value: [PrivateKey], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterTypePrivateKey.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [PrivateKey] { - let len: Int32 = try readInt(&buf) - var seq = [PrivateKey]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterTypePrivateKey.read(from: &buf)) - } - return seq - } -} - -fileprivate struct FfiConverterDictionaryStringString: FfiConverterRustBuffer { - public static func write(_ value: [String: String], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for (key, value) in value { - FfiConverterString.write(key, into: &buf) - FfiConverterString.write(value, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: String] { - let len: Int32 = try readInt(&buf) - var dict = [String: String]() - dict.reserveCapacity(Int(len)) - for _ in 0..>() - -fileprivate func uniffiRustCallAsync( - rustFutureFunc: () -> UInt64, - pollFunc: (UInt64, @escaping UniffiRustFutureContinuationCallback, UInt64) -> (), - completeFunc: (UInt64, UnsafeMutablePointer) -> F, - freeFunc: (UInt64) -> (), - liftFunc: (F) throws -> T, - errorHandler: ((RustBuffer) throws -> Error)? -) async throws -> T { - // Make sure to call uniffiEnsureInitialized() since future creation doesn't have a - // RustCallStatus param, so doesn't use makeRustCall() - uniffiEnsureInitialized() - let rustFuture = rustFutureFunc() - defer { - freeFunc(rustFuture) - } - var pollResult: Int8; - repeat { - pollResult = await withUnsafeContinuation { - pollFunc( - rustFuture, - uniffiFutureContinuationCallback, - uniffiContinuationHandleMap.insert(obj: $0) - ) - } - } while pollResult != UNIFFI_RUST_FUTURE_POLL_READY - - return try liftFunc(makeRustCall( - { completeFunc(rustFuture, $0) }, - errorHandler: errorHandler - )) -} - -// Callback handlers for an async calls. These are invoked by Rust when the future is ready. They -// lift the return value or error and resume the suspended function. -fileprivate func uniffiFutureContinuationCallback(handle: UInt64, pollResult: Int8) { - if let continuation = try? uniffiContinuationHandleMap.remove(handle: handle) { - continuation.resume(returning: pollResult) - } else { - print("uniffiFutureContinuationCallback invalid handle") - } -} -public func bearerDidFromKeyManager(didUri: String, keyManager: KeyManager)async throws -> BearerDid { - return - try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_web5_fn_func_bearer_did_from_key_manager(FfiConverterString.lower(didUri),FfiConverterTypeKeyManager.lower(keyManager) - ) - }, - pollFunc: ffi_web5_rust_future_poll_pointer, - completeFunc: ffi_web5_rust_future_complete_pointer, - freeFunc: ffi_web5_rust_future_free_pointer, - liftFunc: FfiConverterTypeBearerDid.lift, - errorHandler: FfiConverterTypeBearerDidError.lift - ) -} -public func signJwt(bearerDid: BearerDid, keySelector: KeySelector, encodedHeader: String, encodedPayload: String)throws -> String { - return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeJwtError.lift) { - uniffi_web5_fn_func_sign_jwt( - FfiConverterTypeBearerDid.lower(bearerDid), - FfiConverterTypeKeySelector.lower(keySelector), - FfiConverterString.lower(encodedHeader), - FfiConverterString.lower(encodedPayload),$0 - ) -}) -} -public func verifyJwt(jwt: String)async throws { - return - try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_web5_fn_func_verify_jwt(FfiConverterString.lower(jwt) - ) - }, - pollFunc: ffi_web5_rust_future_poll_void, - completeFunc: ffi_web5_rust_future_complete_void, - freeFunc: ffi_web5_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: FfiConverterTypeJwtError.lift - ) -} -public func verifyVcjwt(jwt: String)async throws -> VerifiableCredential { - return - try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_web5_fn_func_verify_vcjwt(FfiConverterString.lower(jwt) - ) - }, - pollFunc: ffi_web5_rust_future_poll_pointer, - completeFunc: ffi_web5_rust_future_complete_pointer, - freeFunc: ffi_web5_rust_future_free_pointer, - liftFunc: FfiConverterTypeVerifiableCredential.lift, - errorHandler: FfiConverterTypeCredentialError.lift - ) -} - -private enum InitializationResult { - case ok - case contractVersionMismatch - case apiChecksumMismatch +private enum InitializationResult { + case ok + case contractVersionMismatch + case apiChecksumMismatch } // Use a global variables to perform the versioning checks. Swift ensures that // the code inside is only computed once. @@ -2914,144 +434,6 @@ private var initializationResult: InitializationResult { if bindings_contract_version != scaffolding_contract_version { return InitializationResult.contractVersionMismatch } - if (uniffi_web5_checksum_func_bearer_did_from_key_manager() != 49693) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_func_sign_jwt() != 3714) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_func_verify_jwt() != 15697) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_func_verify_vcjwt() != 20360) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_bearerdid_sign() != 16617) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_claims_encode() != 57871) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_claims_sign() != 25723) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_inmemorykeystore_export_private_keys() != 39747) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_inmemorykeystore_generate_new() != 38125) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_inmemorykeystore_get_all_aliases() != 5037) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_inmemorykeystore_get_public_key() != 29662) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_inmemorykeystore_import_private_keys() != 30093) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_inmemorykeystore_sign() != 16944) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_jwk_alias() != 49978) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_jwk_compute_thumbprint() != 48815) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_jwk_jwk() != 5992) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_jwk_sign() != 61337) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_jwk_to_public() != 29912) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_jwk_verify() != 11302) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_key_alias() != 42841) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_key_jwk() != 56821) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_keymanager_export_private_keys() != 21330) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_keymanager_generate_private_key() != 37489) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_keymanager_get_public_key() != 33063) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_keymanager_import_private_keys() != 17034) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_keymanager_sign() != 60994) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_keystore_export_private_keys() != 51959) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_keystore_generate_new() != 11193) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_keystore_get_all_aliases() != 38081) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_keystore_get_public_key() != 2805) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_keystore_import_private_keys() != 4940) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_keystore_sign() != 52791) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_localkeymanager_export_private_keys() != 123) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_localkeymanager_generate_private_key() != 44974) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_localkeymanager_get_public_key() != 10967) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_localkeymanager_import_private_keys() != 16228) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_localkeymanager_sign() != 33139) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_privatekey_sign() != 45053) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_privatekey_to_public() != 39125) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_publickey_verify() != 12448) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_method_verifiablecredential_sign() != 29352) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_constructor_claims_new() != 1059) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_constructor_inmemorykeystore_new() != 52462) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_constructor_localkeymanager_new() != 2661) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_constructor_localkeymanager_new_in_memory() != 62693) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_web5_checksum_constructor_verifiablecredential_new() != 54017) { - return InitializationResult.apiChecksumMismatch - } return InitializationResult.ok } diff --git a/binded/swift/libweb5-rs.xcframework/macos-arm64/Headers/web5FFI.h b/binded/swift/libweb5-rs.xcframework/macos-arm64/Headers/web5FFI.h index 4abb14dd..430107a6 100644 --- a/binded/swift/libweb5-rs.xcframework/macos-arm64/Headers/web5FFI.h +++ b/binded/swift/libweb5-rs.xcframework/macos-arm64/Headers/web5FFI.h @@ -250,511 +250,6 @@ typedef struct UniffiForeignFutureStructVoid { typedef void (*UniffiForeignFutureCompleteVoid)(uint64_t, UniffiForeignFutureStructVoid ); -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_METHOD0 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_METHOD0 -typedef void (*UniffiCallbackInterfaceKeyMethod0)(uint64_t, RustBuffer* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_METHOD1 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_METHOD1 -typedef void (*UniffiCallbackInterfaceKeyMethod1)(uint64_t, void*_Nonnull* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_MANAGER_METHOD0 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_MANAGER_METHOD0 -typedef void (*UniffiCallbackInterfaceKeyManagerMethod0)(uint64_t, RustBuffer* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_MANAGER_METHOD1 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_MANAGER_METHOD1 -typedef void (*UniffiCallbackInterfaceKeyManagerMethod1)(uint64_t, RustBuffer, RustBuffer, RustBuffer* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_MANAGER_METHOD2 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_MANAGER_METHOD2 -typedef void (*UniffiCallbackInterfaceKeyManagerMethod2)(uint64_t, RustBuffer, void*_Nonnull* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_MANAGER_METHOD3 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_MANAGER_METHOD3 -typedef void (*UniffiCallbackInterfaceKeyManagerMethod3)(uint64_t, RustBuffer, void* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_MANAGER_METHOD4 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_MANAGER_METHOD4 -typedef void (*UniffiCallbackInterfaceKeyManagerMethod4)(uint64_t, RustBuffer, RustBuffer, RustBuffer* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_STORE_METHOD0 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_STORE_METHOD0 -typedef void (*UniffiCallbackInterfaceKeyStoreMethod0)(uint64_t, RustBuffer* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_STORE_METHOD1 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_STORE_METHOD1 -typedef void (*UniffiCallbackInterfaceKeyStoreMethod1)(uint64_t, RustBuffer, RustBuffer, RustBuffer* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_STORE_METHOD2 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_STORE_METHOD2 -typedef void (*UniffiCallbackInterfaceKeyStoreMethod2)(uint64_t, RustBuffer* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_STORE_METHOD3 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_STORE_METHOD3 -typedef void (*UniffiCallbackInterfaceKeyStoreMethod3)(uint64_t, RustBuffer, void*_Nonnull* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_STORE_METHOD4 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_STORE_METHOD4 -typedef void (*UniffiCallbackInterfaceKeyStoreMethod4)(uint64_t, RustBuffer, void* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_STORE_METHOD5 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_KEY_STORE_METHOD5 -typedef void (*UniffiCallbackInterfaceKeyStoreMethod5)(uint64_t, RustBuffer, RustBuffer, RustBuffer* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_PRIVATE_KEY_METHOD0 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_PRIVATE_KEY_METHOD0 -typedef void (*UniffiCallbackInterfacePrivateKeyMethod0)(uint64_t, RustBuffer, RustBuffer* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_PRIVATE_KEY_METHOD1 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_PRIVATE_KEY_METHOD1 -typedef void (*UniffiCallbackInterfacePrivateKeyMethod1)(uint64_t, void*_Nonnull* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_PUBLIC_KEY_METHOD0 -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_PUBLIC_KEY_METHOD0 -typedef void (*UniffiCallbackInterfacePublicKeyMethod0)(uint64_t, RustBuffer, RustBuffer, void* _Nonnull, - RustCallStatus *_Nonnull uniffiCallStatus - ); - -#endif -#ifndef UNIFFI_FFIDEF_V_TABLE_CALLBACK_INTERFACE_KEY -#define UNIFFI_FFIDEF_V_TABLE_CALLBACK_INTERFACE_KEY -typedef struct UniffiVTableCallbackInterfaceKey { - UniffiCallbackInterfaceKeyMethod0 _Nonnull alias; - UniffiCallbackInterfaceKeyMethod1 _Nonnull jwk; - UniffiCallbackInterfaceFree _Nonnull uniffiFree; -} UniffiVTableCallbackInterfaceKey; - -#endif -#ifndef UNIFFI_FFIDEF_V_TABLE_CALLBACK_INTERFACE_KEY_MANAGER -#define UNIFFI_FFIDEF_V_TABLE_CALLBACK_INTERFACE_KEY_MANAGER -typedef struct UniffiVTableCallbackInterfaceKeyManager { - UniffiCallbackInterfaceKeyManagerMethod0 _Nonnull exportPrivateKeys; - UniffiCallbackInterfaceKeyManagerMethod1 _Nonnull generatePrivateKey; - UniffiCallbackInterfaceKeyManagerMethod2 _Nonnull getPublicKey; - UniffiCallbackInterfaceKeyManagerMethod3 _Nonnull importPrivateKeys; - UniffiCallbackInterfaceKeyManagerMethod4 _Nonnull sign; - UniffiCallbackInterfaceFree _Nonnull uniffiFree; -} UniffiVTableCallbackInterfaceKeyManager; - -#endif -#ifndef UNIFFI_FFIDEF_V_TABLE_CALLBACK_INTERFACE_KEY_STORE -#define UNIFFI_FFIDEF_V_TABLE_CALLBACK_INTERFACE_KEY_STORE -typedef struct UniffiVTableCallbackInterfaceKeyStore { - UniffiCallbackInterfaceKeyStoreMethod0 _Nonnull exportPrivateKeys; - UniffiCallbackInterfaceKeyStoreMethod1 _Nonnull generateNew; - UniffiCallbackInterfaceKeyStoreMethod2 _Nonnull getAllAliases; - UniffiCallbackInterfaceKeyStoreMethod3 _Nonnull getPublicKey; - UniffiCallbackInterfaceKeyStoreMethod4 _Nonnull importPrivateKeys; - UniffiCallbackInterfaceKeyStoreMethod5 _Nonnull sign; - UniffiCallbackInterfaceFree _Nonnull uniffiFree; -} UniffiVTableCallbackInterfaceKeyStore; - -#endif -#ifndef UNIFFI_FFIDEF_V_TABLE_CALLBACK_INTERFACE_PRIVATE_KEY -#define UNIFFI_FFIDEF_V_TABLE_CALLBACK_INTERFACE_PRIVATE_KEY -typedef struct UniffiVTableCallbackInterfacePrivateKey { - UniffiCallbackInterfacePrivateKeyMethod0 _Nonnull sign; - UniffiCallbackInterfacePrivateKeyMethod1 _Nonnull toPublic; - UniffiCallbackInterfaceFree _Nonnull uniffiFree; -} UniffiVTableCallbackInterfacePrivateKey; - -#endif -#ifndef UNIFFI_FFIDEF_V_TABLE_CALLBACK_INTERFACE_PUBLIC_KEY -#define UNIFFI_FFIDEF_V_TABLE_CALLBACK_INTERFACE_PUBLIC_KEY -typedef struct UniffiVTableCallbackInterfacePublicKey { - UniffiCallbackInterfacePublicKeyMethod0 _Nonnull verify; - UniffiCallbackInterfaceFree _Nonnull uniffiFree; -} UniffiVTableCallbackInterfacePublicKey; - -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_BEARERDID -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_BEARERDID -void*_Nonnull uniffi_web5_fn_clone_bearerdid(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_BEARERDID -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_BEARERDID -void uniffi_web5_fn_free_bearerdid(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_BEARERDID_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_BEARERDID_SIGN -RustBuffer uniffi_web5_fn_method_bearerdid_sign(void*_Nonnull ptr, RustBuffer key_selector, RustBuffer payload, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_CLAIMS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_CLAIMS -void*_Nonnull uniffi_web5_fn_clone_claims(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_CLAIMS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_CLAIMS -void uniffi_web5_fn_free_claims(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CONSTRUCTOR_CLAIMS_NEW -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CONSTRUCTOR_CLAIMS_NEW -void*_Nonnull uniffi_web5_fn_constructor_claims_new(RustBuffer issuer, RustBuffer subject, RustBuffer audience, RustBuffer expiration, RustBuffer not_before, RustBuffer issued_at, RustBuffer jti, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_CLAIMS_ENCODE -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_CLAIMS_ENCODE -RustBuffer uniffi_web5_fn_method_claims_encode(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_CLAIMS_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_CLAIMS_SIGN -RustBuffer uniffi_web5_fn_method_claims_sign(void*_Nonnull ptr, void*_Nonnull bearer_did, RustBuffer key_selector, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_INMEMORYKEYSTORE -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_INMEMORYKEYSTORE -void*_Nonnull uniffi_web5_fn_clone_inmemorykeystore(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_INMEMORYKEYSTORE -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_INMEMORYKEYSTORE -void uniffi_web5_fn_free_inmemorykeystore(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CONSTRUCTOR_INMEMORYKEYSTORE_NEW -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CONSTRUCTOR_INMEMORYKEYSTORE_NEW -void*_Nonnull uniffi_web5_fn_constructor_inmemorykeystore_new(RustCallStatus *_Nonnull out_status - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_INMEMORYKEYSTORE_EXPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_INMEMORYKEYSTORE_EXPORT_PRIVATE_KEYS -RustBuffer uniffi_web5_fn_method_inmemorykeystore_export_private_keys(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_INMEMORYKEYSTORE_GENERATE_NEW -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_INMEMORYKEYSTORE_GENERATE_NEW -RustBuffer uniffi_web5_fn_method_inmemorykeystore_generate_new(void*_Nonnull ptr, RustBuffer curve, RustBuffer key_alias, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_INMEMORYKEYSTORE_GET_ALL_ALIASES -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_INMEMORYKEYSTORE_GET_ALL_ALIASES -RustBuffer uniffi_web5_fn_method_inmemorykeystore_get_all_aliases(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_INMEMORYKEYSTORE_GET_PUBLIC_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_INMEMORYKEYSTORE_GET_PUBLIC_KEY -void*_Nonnull uniffi_web5_fn_method_inmemorykeystore_get_public_key(void*_Nonnull ptr, RustBuffer key_alias, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_INMEMORYKEYSTORE_IMPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_INMEMORYKEYSTORE_IMPORT_PRIVATE_KEYS -void uniffi_web5_fn_method_inmemorykeystore_import_private_keys(void*_Nonnull ptr, RustBuffer private_keys, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_INMEMORYKEYSTORE_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_INMEMORYKEYSTORE_SIGN -RustBuffer uniffi_web5_fn_method_inmemorykeystore_sign(void*_Nonnull ptr, RustBuffer key_alias, RustBuffer payload, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_JWK -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_JWK -void*_Nonnull uniffi_web5_fn_clone_jwk(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_JWK -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_JWK -void uniffi_web5_fn_free_jwk(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_JWK_ALIAS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_JWK_ALIAS -RustBuffer uniffi_web5_fn_method_jwk_alias(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_JWK_COMPUTE_THUMBPRINT -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_JWK_COMPUTE_THUMBPRINT -RustBuffer uniffi_web5_fn_method_jwk_compute_thumbprint(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_JWK_JWK -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_JWK_JWK -void*_Nonnull uniffi_web5_fn_method_jwk_jwk(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_JWK_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_JWK_SIGN -RustBuffer uniffi_web5_fn_method_jwk_sign(void*_Nonnull ptr, RustBuffer payload, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_JWK_TO_PUBLIC -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_JWK_TO_PUBLIC -void*_Nonnull uniffi_web5_fn_method_jwk_to_public(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_JWK_VERIFY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_JWK_VERIFY -void uniffi_web5_fn_method_jwk_verify(void*_Nonnull ptr, RustBuffer payload, RustBuffer signature, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_KEY -void*_Nonnull uniffi_web5_fn_clone_key(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_KEY -void uniffi_web5_fn_free_key(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEY_ALIAS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEY_ALIAS -RustBuffer uniffi_web5_fn_method_key_alias(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEY_JWK -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEY_JWK -void*_Nonnull uniffi_web5_fn_method_key_jwk(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_KEYMANAGER -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_KEYMANAGER -void*_Nonnull uniffi_web5_fn_clone_keymanager(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_KEYMANAGER -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_KEYMANAGER -void uniffi_web5_fn_free_keymanager(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYMANAGER_EXPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYMANAGER_EXPORT_PRIVATE_KEYS -RustBuffer uniffi_web5_fn_method_keymanager_export_private_keys(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYMANAGER_GENERATE_PRIVATE_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYMANAGER_GENERATE_PRIVATE_KEY -RustBuffer uniffi_web5_fn_method_keymanager_generate_private_key(void*_Nonnull ptr, RustBuffer curve, RustBuffer key_alias, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYMANAGER_GET_PUBLIC_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYMANAGER_GET_PUBLIC_KEY -void*_Nonnull uniffi_web5_fn_method_keymanager_get_public_key(void*_Nonnull ptr, RustBuffer key_alias, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYMANAGER_IMPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYMANAGER_IMPORT_PRIVATE_KEYS -void uniffi_web5_fn_method_keymanager_import_private_keys(void*_Nonnull ptr, RustBuffer private_keys, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYMANAGER_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYMANAGER_SIGN -RustBuffer uniffi_web5_fn_method_keymanager_sign(void*_Nonnull ptr, RustBuffer key_alias, RustBuffer payload, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_KEYSTORE -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_KEYSTORE -void*_Nonnull uniffi_web5_fn_clone_keystore(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_KEYSTORE -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_KEYSTORE -void uniffi_web5_fn_free_keystore(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYSTORE_EXPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYSTORE_EXPORT_PRIVATE_KEYS -RustBuffer uniffi_web5_fn_method_keystore_export_private_keys(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYSTORE_GENERATE_NEW -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYSTORE_GENERATE_NEW -RustBuffer uniffi_web5_fn_method_keystore_generate_new(void*_Nonnull ptr, RustBuffer curve, RustBuffer key_alias, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYSTORE_GET_ALL_ALIASES -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYSTORE_GET_ALL_ALIASES -RustBuffer uniffi_web5_fn_method_keystore_get_all_aliases(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYSTORE_GET_PUBLIC_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYSTORE_GET_PUBLIC_KEY -void*_Nonnull uniffi_web5_fn_method_keystore_get_public_key(void*_Nonnull ptr, RustBuffer key_alias, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYSTORE_IMPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYSTORE_IMPORT_PRIVATE_KEYS -void uniffi_web5_fn_method_keystore_import_private_keys(void*_Nonnull ptr, RustBuffer private_keys, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYSTORE_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_KEYSTORE_SIGN -RustBuffer uniffi_web5_fn_method_keystore_sign(void*_Nonnull ptr, RustBuffer key_alias, RustBuffer payload, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_LOCALKEYMANAGER -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_LOCALKEYMANAGER -void*_Nonnull uniffi_web5_fn_clone_localkeymanager(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_LOCALKEYMANAGER -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_LOCALKEYMANAGER -void uniffi_web5_fn_free_localkeymanager(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CONSTRUCTOR_LOCALKEYMANAGER_NEW -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CONSTRUCTOR_LOCALKEYMANAGER_NEW -void*_Nonnull uniffi_web5_fn_constructor_localkeymanager_new(void*_Nonnull key_store, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CONSTRUCTOR_LOCALKEYMANAGER_NEW_IN_MEMORY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CONSTRUCTOR_LOCALKEYMANAGER_NEW_IN_MEMORY -void*_Nonnull uniffi_web5_fn_constructor_localkeymanager_new_in_memory(RustCallStatus *_Nonnull out_status - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_LOCALKEYMANAGER_EXPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_LOCALKEYMANAGER_EXPORT_PRIVATE_KEYS -RustBuffer uniffi_web5_fn_method_localkeymanager_export_private_keys(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_LOCALKEYMANAGER_GENERATE_PRIVATE_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_LOCALKEYMANAGER_GENERATE_PRIVATE_KEY -RustBuffer uniffi_web5_fn_method_localkeymanager_generate_private_key(void*_Nonnull ptr, RustBuffer curve, RustBuffer key_alias, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_LOCALKEYMANAGER_GET_PUBLIC_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_LOCALKEYMANAGER_GET_PUBLIC_KEY -void*_Nonnull uniffi_web5_fn_method_localkeymanager_get_public_key(void*_Nonnull ptr, RustBuffer key_alias, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_LOCALKEYMANAGER_IMPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_LOCALKEYMANAGER_IMPORT_PRIVATE_KEYS -void uniffi_web5_fn_method_localkeymanager_import_private_keys(void*_Nonnull ptr, RustBuffer private_keys, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_LOCALKEYMANAGER_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_LOCALKEYMANAGER_SIGN -RustBuffer uniffi_web5_fn_method_localkeymanager_sign(void*_Nonnull ptr, RustBuffer key_alias, RustBuffer payload, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_PRIVATEKEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_PRIVATEKEY -void*_Nonnull uniffi_web5_fn_clone_privatekey(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_PRIVATEKEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_PRIVATEKEY -void uniffi_web5_fn_free_privatekey(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_PRIVATEKEY_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_PRIVATEKEY_SIGN -RustBuffer uniffi_web5_fn_method_privatekey_sign(void*_Nonnull ptr, RustBuffer payload, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_PRIVATEKEY_TO_PUBLIC -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_PRIVATEKEY_TO_PUBLIC -void*_Nonnull uniffi_web5_fn_method_privatekey_to_public(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_PUBLICKEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_PUBLICKEY -void*_Nonnull uniffi_web5_fn_clone_publickey(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_PUBLICKEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_PUBLICKEY -void uniffi_web5_fn_free_publickey(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_PUBLICKEY_VERIFY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_PUBLICKEY_VERIFY -void uniffi_web5_fn_method_publickey_verify(void*_Nonnull ptr, RustBuffer payload, RustBuffer signature, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_VERIFIABLECREDENTIAL -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CLONE_VERIFIABLECREDENTIAL -void*_Nonnull uniffi_web5_fn_clone_verifiablecredential(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_VERIFIABLECREDENTIAL -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FREE_VERIFIABLECREDENTIAL -void uniffi_web5_fn_free_verifiablecredential(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CONSTRUCTOR_VERIFIABLECREDENTIAL_NEW -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_CONSTRUCTOR_VERIFIABLECREDENTIAL_NEW -void*_Nonnull uniffi_web5_fn_constructor_verifiablecredential_new(RustBuffer context, RustBuffer id, RustBuffer type, RustBuffer issuer, int64_t issuance_date, RustBuffer expiration_date, RustBuffer credential_subject, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_VERIFIABLECREDENTIAL_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_METHOD_VERIFIABLECREDENTIAL_SIGN -RustBuffer uniffi_web5_fn_method_verifiablecredential_sign(void*_Nonnull ptr, void*_Nonnull bearer_did, RustBuffer key_selector, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FUNC_BEARER_DID_FROM_KEY_MANAGER -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FUNC_BEARER_DID_FROM_KEY_MANAGER -uint64_t uniffi_web5_fn_func_bearer_did_from_key_manager(RustBuffer did_uri, void*_Nonnull key_manager -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FUNC_SIGN_JWT -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FUNC_SIGN_JWT -RustBuffer uniffi_web5_fn_func_sign_jwt(void*_Nonnull bearer_did, RustBuffer key_selector, RustBuffer encoded_header, RustBuffer encoded_payload, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FUNC_VERIFY_JWT -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FUNC_VERIFY_JWT -uint64_t uniffi_web5_fn_func_verify_jwt(RustBuffer jwt -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FUNC_VERIFY_VCJWT -#define UNIFFI_FFIDEF_UNIFFI_WEB5_FN_FUNC_VERIFY_VCJWT -uint64_t uniffi_web5_fn_func_verify_vcjwt(RustBuffer jwt -); #endif #ifndef UNIFFI_FFIDEF_FFI_WEB5_RUSTBUFFER_ALLOC #define UNIFFI_FFIDEF_FFI_WEB5_RUSTBUFFER_ALLOC @@ -1034,282 +529,6 @@ void ffi_web5_rust_future_free_void(uint64_t handle #ifndef UNIFFI_FFIDEF_FFI_WEB5_RUST_FUTURE_COMPLETE_VOID #define UNIFFI_FFIDEF_FFI_WEB5_RUST_FUTURE_COMPLETE_VOID void ffi_web5_rust_future_complete_void(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_FUNC_BEARER_DID_FROM_KEY_MANAGER -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_FUNC_BEARER_DID_FROM_KEY_MANAGER -uint16_t uniffi_web5_checksum_func_bearer_did_from_key_manager(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_FUNC_SIGN_JWT -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_FUNC_SIGN_JWT -uint16_t uniffi_web5_checksum_func_sign_jwt(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_FUNC_VERIFY_JWT -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_FUNC_VERIFY_JWT -uint16_t uniffi_web5_checksum_func_verify_jwt(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_FUNC_VERIFY_VCJWT -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_FUNC_VERIFY_VCJWT -uint16_t uniffi_web5_checksum_func_verify_vcjwt(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_BEARERDID_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_BEARERDID_SIGN -uint16_t uniffi_web5_checksum_method_bearerdid_sign(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_CLAIMS_ENCODE -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_CLAIMS_ENCODE -uint16_t uniffi_web5_checksum_method_claims_encode(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_CLAIMS_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_CLAIMS_SIGN -uint16_t uniffi_web5_checksum_method_claims_sign(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_INMEMORYKEYSTORE_EXPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_INMEMORYKEYSTORE_EXPORT_PRIVATE_KEYS -uint16_t uniffi_web5_checksum_method_inmemorykeystore_export_private_keys(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_INMEMORYKEYSTORE_GENERATE_NEW -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_INMEMORYKEYSTORE_GENERATE_NEW -uint16_t uniffi_web5_checksum_method_inmemorykeystore_generate_new(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_INMEMORYKEYSTORE_GET_ALL_ALIASES -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_INMEMORYKEYSTORE_GET_ALL_ALIASES -uint16_t uniffi_web5_checksum_method_inmemorykeystore_get_all_aliases(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_INMEMORYKEYSTORE_GET_PUBLIC_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_INMEMORYKEYSTORE_GET_PUBLIC_KEY -uint16_t uniffi_web5_checksum_method_inmemorykeystore_get_public_key(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_INMEMORYKEYSTORE_IMPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_INMEMORYKEYSTORE_IMPORT_PRIVATE_KEYS -uint16_t uniffi_web5_checksum_method_inmemorykeystore_import_private_keys(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_INMEMORYKEYSTORE_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_INMEMORYKEYSTORE_SIGN -uint16_t uniffi_web5_checksum_method_inmemorykeystore_sign(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_JWK_ALIAS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_JWK_ALIAS -uint16_t uniffi_web5_checksum_method_jwk_alias(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_JWK_COMPUTE_THUMBPRINT -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_JWK_COMPUTE_THUMBPRINT -uint16_t uniffi_web5_checksum_method_jwk_compute_thumbprint(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_JWK_JWK -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_JWK_JWK -uint16_t uniffi_web5_checksum_method_jwk_jwk(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_JWK_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_JWK_SIGN -uint16_t uniffi_web5_checksum_method_jwk_sign(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_JWK_TO_PUBLIC -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_JWK_TO_PUBLIC -uint16_t uniffi_web5_checksum_method_jwk_to_public(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_JWK_VERIFY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_JWK_VERIFY -uint16_t uniffi_web5_checksum_method_jwk_verify(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEY_ALIAS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEY_ALIAS -uint16_t uniffi_web5_checksum_method_key_alias(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEY_JWK -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEY_JWK -uint16_t uniffi_web5_checksum_method_key_jwk(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYMANAGER_EXPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYMANAGER_EXPORT_PRIVATE_KEYS -uint16_t uniffi_web5_checksum_method_keymanager_export_private_keys(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYMANAGER_GENERATE_PRIVATE_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYMANAGER_GENERATE_PRIVATE_KEY -uint16_t uniffi_web5_checksum_method_keymanager_generate_private_key(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYMANAGER_GET_PUBLIC_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYMANAGER_GET_PUBLIC_KEY -uint16_t uniffi_web5_checksum_method_keymanager_get_public_key(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYMANAGER_IMPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYMANAGER_IMPORT_PRIVATE_KEYS -uint16_t uniffi_web5_checksum_method_keymanager_import_private_keys(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYMANAGER_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYMANAGER_SIGN -uint16_t uniffi_web5_checksum_method_keymanager_sign(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYSTORE_EXPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYSTORE_EXPORT_PRIVATE_KEYS -uint16_t uniffi_web5_checksum_method_keystore_export_private_keys(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYSTORE_GENERATE_NEW -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYSTORE_GENERATE_NEW -uint16_t uniffi_web5_checksum_method_keystore_generate_new(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYSTORE_GET_ALL_ALIASES -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYSTORE_GET_ALL_ALIASES -uint16_t uniffi_web5_checksum_method_keystore_get_all_aliases(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYSTORE_GET_PUBLIC_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYSTORE_GET_PUBLIC_KEY -uint16_t uniffi_web5_checksum_method_keystore_get_public_key(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYSTORE_IMPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYSTORE_IMPORT_PRIVATE_KEYS -uint16_t uniffi_web5_checksum_method_keystore_import_private_keys(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYSTORE_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_KEYSTORE_SIGN -uint16_t uniffi_web5_checksum_method_keystore_sign(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_LOCALKEYMANAGER_EXPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_LOCALKEYMANAGER_EXPORT_PRIVATE_KEYS -uint16_t uniffi_web5_checksum_method_localkeymanager_export_private_keys(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_LOCALKEYMANAGER_GENERATE_PRIVATE_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_LOCALKEYMANAGER_GENERATE_PRIVATE_KEY -uint16_t uniffi_web5_checksum_method_localkeymanager_generate_private_key(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_LOCALKEYMANAGER_GET_PUBLIC_KEY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_LOCALKEYMANAGER_GET_PUBLIC_KEY -uint16_t uniffi_web5_checksum_method_localkeymanager_get_public_key(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_LOCALKEYMANAGER_IMPORT_PRIVATE_KEYS -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_LOCALKEYMANAGER_IMPORT_PRIVATE_KEYS -uint16_t uniffi_web5_checksum_method_localkeymanager_import_private_keys(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_LOCALKEYMANAGER_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_LOCALKEYMANAGER_SIGN -uint16_t uniffi_web5_checksum_method_localkeymanager_sign(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_PRIVATEKEY_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_PRIVATEKEY_SIGN -uint16_t uniffi_web5_checksum_method_privatekey_sign(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_PRIVATEKEY_TO_PUBLIC -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_PRIVATEKEY_TO_PUBLIC -uint16_t uniffi_web5_checksum_method_privatekey_to_public(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_PUBLICKEY_VERIFY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_PUBLICKEY_VERIFY -uint16_t uniffi_web5_checksum_method_publickey_verify(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_VERIFIABLECREDENTIAL_SIGN -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_METHOD_VERIFIABLECREDENTIAL_SIGN -uint16_t uniffi_web5_checksum_method_verifiablecredential_sign(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_CONSTRUCTOR_CLAIMS_NEW -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_CONSTRUCTOR_CLAIMS_NEW -uint16_t uniffi_web5_checksum_constructor_claims_new(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_CONSTRUCTOR_INMEMORYKEYSTORE_NEW -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_CONSTRUCTOR_INMEMORYKEYSTORE_NEW -uint16_t uniffi_web5_checksum_constructor_inmemorykeystore_new(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_CONSTRUCTOR_LOCALKEYMANAGER_NEW -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_CONSTRUCTOR_LOCALKEYMANAGER_NEW -uint16_t uniffi_web5_checksum_constructor_localkeymanager_new(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_CONSTRUCTOR_LOCALKEYMANAGER_NEW_IN_MEMORY -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_CONSTRUCTOR_LOCALKEYMANAGER_NEW_IN_MEMORY -uint16_t uniffi_web5_checksum_constructor_localkeymanager_new_in_memory(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_CONSTRUCTOR_VERIFIABLECREDENTIAL_NEW -#define UNIFFI_FFIDEF_UNIFFI_WEB5_CHECKSUM_CONSTRUCTOR_VERIFIABLECREDENTIAL_NEW -uint16_t uniffi_web5_checksum_constructor_verifiablecredential_new(void - ); #endif #ifndef UNIFFI_FFIDEF_FFI_WEB5_UNIFFI_CONTRACT_VERSION diff --git a/binded/swift/libweb5-rs.xcframework/macos-arm64/libweb5.dylib b/binded/swift/libweb5-rs.xcframework/macos-arm64/libweb5.dylib index 913d857c..e3538e23 100755 Binary files a/binded/swift/libweb5-rs.xcframework/macos-arm64/libweb5.dylib and b/binded/swift/libweb5-rs.xcframework/macos-arm64/libweb5.dylib differ diff --git a/bindings/uniffi/Cargo.toml b/bindings/uniffi/Cargo.toml index d6dc684d..a9223f1c 100644 --- a/bindings/uniffi/Cargo.toml +++ b/bindings/uniffi/Cargo.toml @@ -7,12 +7,7 @@ repository.workspace = true license-file.workspace = true [dependencies] -credentials = { path = "../../crates/credentials" } -crypto = { path = "../../crates/crypto" } -dids = { path = "../../crates/dids" } -jwk = { path = "../../crates/jwk" } -jwt = { path = "../../crates/jwt" } -keys = { path = "../../crates/keys" } +web5 = { path = "../../crates/web5" } uniffi = { version = "0.27.1", features = ["cli"] } [build-dependencies] @@ -20,7 +15,6 @@ uniffi = { version = "0.27.1", features = ["build"] } [lib] crate-type = ["cdylib"] -name = "web5" [[bin]] name = "uniffi-bindgen" diff --git a/crates/crypto/Cargo.toml b/crates/crypto/Cargo.toml deleted file mode 100644 index 261962ed..00000000 --- a/crates/crypto/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "crypto" -version = "0.1.0" -edition = "2021" -homepage.workspace = true -repository.workspace = true -license-file.workspace = true - -[dependencies] -base64 = { workspace = true } -ed25519-dalek = { version = "2.1.1", features = ["rand_core"] } -getrandom = { version = "0.2.12", features = ["js"] } -jwk = { path = "../jwk" } -k256 = { version = "0.13.3", features = ["ecdsa", "jwk"] } -rand = { workspace = true } -thiserror = { workspace = true } \ No newline at end of file diff --git a/crates/dids/Cargo.toml b/crates/dids/Cargo.toml deleted file mode 100644 index 6e6b7298..00000000 --- a/crates/dids/Cargo.toml +++ /dev/null @@ -1,29 +0,0 @@ -[package] -name = "dids" -version = "0.1.0" -edition = "2021" -homepage.workspace = true -repository.workspace = true -license-file.workspace = true - -[dependencies] -base64 = { workspace = true } -byteorder = "1.5.0" -crypto = { path = "../crypto" } -did-jwk = "0.1.1" -did-web = "0.2.2" -jwk = { path = "../jwk" } -keys = { path = "../keys" } -regex = "1.10.4" -serde = { workspace = true } -serde_json = { workspace = true } -simple-dns = "0.7.0" -ssi-core = "0.1.0" -ssi-dids = "0.1.1" -ssi-jwk = "0.1.2" -thiserror = { workspace = true } -url = "2.5.0" - -[dev-dependencies] -chrono = { workspace = true } -tokio = { version = "1.34.0", features = ["macros", "test-util"] } diff --git a/crates/jwk/Cargo.toml b/crates/jwk/Cargo.toml deleted file mode 100644 index 6f32f214..00000000 --- a/crates/jwk/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "jwk" -version = "0.1.0" -edition = "2021" -homepage.workspace = true -repository.workspace = true -license-file.workspace = true - -[dependencies] -base64 = { workspace = true } -serde = { workspace = true } -serde_json = { workspace = true } -sha2 = "0.10.8" -thiserror = { workspace = true } \ No newline at end of file diff --git a/crates/jws/Cargo.toml b/crates/jws/Cargo.toml deleted file mode 100644 index 5e19187a..00000000 --- a/crates/jws/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "jws" -version = "0.1.0" -edition = "2021" -homepage.workspace = true -repository.workspace = true -license-file.workspace = true - -[dependencies] -base64 = { workspace = true } -crypto = { path = "../crypto" } -dids = { path = "../dids" } -serde = { workspace = true } -serde_json = { workspace = true } -thiserror = { workspace = true } - -[dev-dependencies] -keys = { path = "../keys" } -tokio = { version = "1.34.0", features = ["macros", "test-util"] } \ No newline at end of file diff --git a/crates/jwt/Cargo.toml b/crates/jwt/Cargo.toml deleted file mode 100644 index 974a4e41..00000000 --- a/crates/jwt/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "jwt" -version = "0.1.0" -edition = "2021" -homepage.workspace = true -repository.workspace = true -license-file.workspace = true - -[dependencies] -base64 = { workspace = true } -dids = { path = "../dids" } -jws = { path = "../jws" } -serde = { workspace = true } -serde_json = { workspace = true } -thiserror = { workspace = true } - -[dev-dependencies] -crypto = { path = "../crypto" } -keys = { path = "../keys" } -tokio = { version = "1.34.0", features = ["macros", "test-util"] } \ No newline at end of file diff --git a/crates/keys/Cargo.toml b/crates/keys/Cargo.toml deleted file mode 100644 index 002b7222..00000000 --- a/crates/keys/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "keys" -version = "0.1.0" -edition = "2021" -homepage.workspace = true -repository.workspace = true -license-file.workspace = true - -[dependencies] -crypto = { path = "../crypto" } -jwk = { path = "../jwk" } -serde_json = { workspace = true } -thiserror = { workspace = true } \ No newline at end of file diff --git a/crates/test-helpers/Cargo.toml b/crates/test-helpers/Cargo.toml deleted file mode 100644 index db29fc1a..00000000 --- a/crates/test-helpers/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "test-helpers" -version = "0.1.0" -edition = "2021" -homepage.workspace = true -repository.workspace = true -license-file.workspace = true - -[dependencies] -serde = { workspace = true } -serde_json = { workspace = true } -serde_with = { workspace = true } \ No newline at end of file diff --git a/crates/credentials/Cargo.toml b/crates/web5/Cargo.toml similarity index 59% rename from crates/credentials/Cargo.toml rename to crates/web5/Cargo.toml index 9e949500..6216e223 100644 --- a/crates/credentials/Cargo.toml +++ b/crates/web5/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "credentials" +name = "web5" version = "0.1.0" edition = "2021" homepage.workspace = true @@ -8,23 +8,31 @@ license-file.workspace = true [dependencies] base64 = { workspace = true } +byteorder = "1.5.0" chrono = { workspace = true } -keys = { path = "../keys" } -dids = { path = "../dids" } +did-jwk = "0.1.1" +did-web = "0.2.2" +ed25519-dalek = { version = "2.1.1", features = ["rand_core"] } +getrandom = { version = "0.2.12", features = ["js"] } hex = "0.4" jsonpath-rust = "0.5.1" jsonschema = "0.17.1" -jwt = { path = "../jwt" } -jws = { path = "../jws" } +k256 = { version = "0.13.3", features = ["ecdsa", "jwk"] } rand = { workspace = true } +regex = "1.10.4" serde = { workspace = true } serde_json = { workspace = true } serde_with = { workspace = true } +sha2 = "0.10.8" +simple-dns = "0.7.0" +ssi-core = "0.1.0" +ssi-dids = "0.1.1" +ssi-jwk = "0.1.2" thiserror = { workspace = true } +url = "2.5.0" uuid = { version = "1.8.0", features = ["v4"] } [dev-dependencies] -crypto = { path = "../crypto" } +chrono = { workspace = true } serde_canonical_json = "1.0.0" -tokio = { version = "1.34.0", features = ["macros", "test-util"] } -test-helpers = { path = "../test-helpers" } +tokio = { version = "1.34.0", features = ["macros", "test-util"] } \ No newline at end of file diff --git a/crates/credentials/src/lib.rs b/crates/web5/src/credentials/mod.rs similarity index 100% rename from crates/credentials/src/lib.rs rename to crates/web5/src/credentials/mod.rs diff --git a/crates/credentials/src/presentation_definition.rs b/crates/web5/src/credentials/presentation_definition.rs similarity index 99% rename from crates/credentials/src/presentation_definition.rs rename to crates/web5/src/credentials/presentation_definition.rs index 620690b5..db211bb7 100644 --- a/crates/credentials/src/presentation_definition.rs +++ b/crates/web5/src/credentials/presentation_definition.rs @@ -1,11 +1,11 @@ use std::collections::HashSet; +use crate::jws::{CompactJws, JwsError}; use jsonpath_rust::{ JsonPathFinder, JsonPathValue::{NewValue, NoValue, Slice}, }; use jsonschema::JSONSchema; -use jws::{CompactJws, JwsError}; use serde::{Deserialize, Serialize}; use serde_json::{json, to_value, Map, Value}; use uuid::Uuid; @@ -237,7 +237,7 @@ impl JsonSchemaBuilder { mod tests { use std::collections::HashSet; - use test_helpers::TestVectorFile; + use crate::test_helpers::TestVectorFile; use super::PresentationDefinition; diff --git a/crates/credentials/src/verifiable_credential.rs b/crates/web5/src/credentials/verifiable_credential.rs similarity index 99% rename from crates/credentials/src/verifiable_credential.rs rename to crates/web5/src/credentials/verifiable_credential.rs index 019f991f..ee230dd2 100644 --- a/crates/credentials/src/verifiable_credential.rs +++ b/crates/web5/src/credentials/verifiable_credential.rs @@ -1,10 +1,10 @@ -use chrono::{DateTime, TimeZone, Utc}; -use core::fmt; -use dids::{bearer::BearerDid, document::KeySelector}; -use jwt::{ +use crate::dids::{bearer::BearerDid, document::KeySelector}; +use crate::jwt::{ jws::Jwt, {Claims, JwtError, RegisteredClaims}, }; +use chrono::{DateTime, TimeZone, Utc}; +use core::fmt; use serde::{Deserialize, Serialize}; use std::{ collections::HashMap, @@ -411,15 +411,15 @@ impl Claims for VcJwtClaims {} #[cfg(test)] mod test { use super::*; - use crypto::Curve; - use dids::{ + use crate::crypto::Curve; + use crate::dids::{ document::VerificationMethodType, methods::{ jwk::{DidJwk, DidJwkCreateOptions}, Create, }, }; - use keys::key_manager::local_key_manager::LocalKeyManager; + use crate::keys::key_manager::local_key_manager::LocalKeyManager; use std::sync::Arc; use uuid::Uuid; diff --git a/crates/crypto/src/ed25519.rs b/crates/web5/src/crypto/ed25519.rs similarity index 98% rename from crates/crypto/src/ed25519.rs rename to crates/web5/src/crypto/ed25519.rs index 10b72f62..c89333fd 100644 --- a/crates/crypto/src/ed25519.rs +++ b/crates/web5/src/crypto/ed25519.rs @@ -1,10 +1,10 @@ -use crate::{CryptoError, CurveOperations}; +use super::{CryptoError, CurveOperations}; +use crate::jwk::Jwk; use base64::{engine::general_purpose, Engine as _}; use ed25519_dalek::{ Signature, Signer, SigningKey, Verifier, VerifyingKey, PUBLIC_KEY_LENGTH, SECRET_KEY_LENGTH, SIGNATURE_LENGTH, }; -use jwk::Jwk; use rand::rngs::OsRng; pub struct Ed25519; diff --git a/crates/crypto/src/lib.rs b/crates/web5/src/crypto/mod.rs similarity index 99% rename from crates/crypto/src/lib.rs rename to crates/web5/src/crypto/mod.rs index 449739ff..40825445 100644 --- a/crates/crypto/src/lib.rs +++ b/crates/web5/src/crypto/mod.rs @@ -7,7 +7,8 @@ use std::{ }; use base64::DecodeError; -use jwk::Jwk; + +use crate::jwk::Jwk; #[derive(thiserror::Error, Debug, Clone, PartialEq)] pub enum CryptoError { diff --git a/crates/crypto/src/secp256k1.rs b/crates/web5/src/crypto/secp256k1.rs similarity index 98% rename from crates/crypto/src/secp256k1.rs rename to crates/web5/src/crypto/secp256k1.rs index e99caec1..dd2d8f58 100644 --- a/crates/crypto/src/secp256k1.rs +++ b/crates/web5/src/crypto/secp256k1.rs @@ -1,6 +1,6 @@ -use crate::{CryptoError, CurveOperations}; +use super::{CryptoError, CurveOperations}; +use crate::jwk::Jwk; use base64::{engine::general_purpose, Engine as _}; -use jwk::Jwk; use k256::{ ecdsa::{ signature::{Signer, Verifier}, diff --git a/crates/dids/src/bearer.rs b/crates/web5/src/dids/bearer.rs similarity index 95% rename from crates/dids/src/bearer.rs rename to crates/web5/src/dids/bearer.rs index 3a562558..d85b2605 100644 --- a/crates/dids/src/bearer.rs +++ b/crates/web5/src/dids/bearer.rs @@ -1,9 +1,9 @@ -use crate::{ +use crate::dids::{ document::{Document, DocumentError, KeyIdFragment, KeySelector}, identifier::{Identifier, IdentifierError}, resolver::{ResolutionError, Resolver}, }; -use keys::{ +use crate::keys::{ key::KeyError, key_manager::{KeyManager, KeyManagerError}, }; @@ -65,15 +65,15 @@ impl BearerDid { #[cfg(test)] mod test { use super::*; - use crate::{ + use crate::crypto::Curve; + use crate::dids::{ document::VerificationMethodType, methods::{ jwk::{DidJwk, DidJwkCreateOptions}, Create, }, }; - use crypto::Curve; - use keys::{key::PublicKey, key_manager::local_key_manager::LocalKeyManager}; + use crate::keys::{key::PublicKey, key_manager::local_key_manager::LocalKeyManager}; #[tokio::test] async fn test_from_key_manager() { diff --git a/crates/dids/src/document.rs b/crates/web5/src/dids/document.rs similarity index 99% rename from crates/dids/src/document.rs rename to crates/web5/src/dids/document.rs index b32de26e..7988cef6 100644 --- a/crates/dids/src/document.rs +++ b/crates/web5/src/dids/document.rs @@ -1,4 +1,4 @@ -use jwk::Jwk; +use crate::jwk::Jwk; use serde::{Deserialize, Serialize}; #[derive(Debug, Default, PartialEq, Serialize, Deserialize)] diff --git a/crates/dids/src/identifier.rs b/crates/web5/src/dids/identifier.rs similarity index 100% rename from crates/dids/src/identifier.rs rename to crates/web5/src/dids/identifier.rs diff --git a/crates/dids/src/methods/dht/bep44.rs b/crates/web5/src/dids/methods/dht/bep44.rs similarity index 97% rename from crates/dids/src/methods/dht/bep44.rs rename to crates/web5/src/dids/methods/dht/bep44.rs index ebcee7f9..553a37d8 100644 --- a/crates/dids/src/methods/dht/bep44.rs +++ b/crates/web5/src/dids/methods/dht/bep44.rs @@ -3,9 +3,9 @@ use std::{ time::{SystemTime, SystemTimeError, UNIX_EPOCH}, }; +use crate::crypto::CryptoError; +use crate::keys::key::{KeyError, PublicKey}; use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; -use crypto::CryptoError; -use keys::key::{KeyError, PublicKey}; /// Minimum size of a bep44 encoded message /// Signature is 64 bytes and seq is 8 byets @@ -136,8 +136,8 @@ impl Bep44Message { #[cfg(test)] mod tests { - use crypto::{ed25519::Ed25519, CurveOperations}; - use keys::key::PrivateKey; + use crate::crypto::{ed25519::Ed25519, CurveOperations}; + use crate::keys::key::PrivateKey; use super::*; diff --git a/crates/dids/src/methods/dht/document_packet/also_known_as.rs b/crates/web5/src/dids/methods/dht/document_packet/also_known_as.rs similarity index 96% rename from crates/dids/src/methods/dht/document_packet/also_known_as.rs rename to crates/web5/src/dids/methods/dht/document_packet/also_known_as.rs index daac2aa0..9864cbb7 100644 --- a/crates/dids/src/methods/dht/document_packet/also_known_as.rs +++ b/crates/web5/src/dids/methods/dht/document_packet/also_known_as.rs @@ -46,7 +46,7 @@ impl AlsoKnownAs { #[cfg(test)] mod test { - use crate::methods::dht::document_packet::controller::Controller; + use crate::dids::methods::dht::document_packet::controller::Controller; use super::*; diff --git a/crates/dids/src/methods/dht/document_packet/controller.rs b/crates/web5/src/dids/methods/dht/document_packet/controller.rs similarity index 97% rename from crates/dids/src/methods/dht/document_packet/controller.rs rename to crates/web5/src/dids/methods/dht/document_packet/controller.rs index 48bda60e..574d4e71 100644 --- a/crates/dids/src/methods/dht/document_packet/controller.rs +++ b/crates/web5/src/dids/methods/dht/document_packet/controller.rs @@ -44,7 +44,7 @@ impl Controller { #[cfg(test)] mod tests { - use crate::methods::dht::document_packet::also_known_as::AlsoKnownAs; + use crate::dids::methods::dht::document_packet::also_known_as::AlsoKnownAs; use super::*; diff --git a/crates/dids/src/methods/dht/document_packet/mod.rs b/crates/web5/src/dids/methods/dht/document_packet/mod.rs similarity index 98% rename from crates/dids/src/methods/dht/document_packet/mod.rs rename to crates/web5/src/dids/methods/dht/document_packet/mod.rs index 726a3e3e..f52017e4 100644 --- a/crates/dids/src/methods/dht/document_packet/mod.rs +++ b/crates/web5/src/dids/methods/dht/document_packet/mod.rs @@ -1,11 +1,11 @@ -use crypto::CryptoError; -use jwk::JwkError; +use crate::crypto::CryptoError; +use crate::jwk::JwkError; use simple_dns::SimpleDnsError; use std::collections::HashMap; use simple_dns::{Packet, ResourceRecord}; -use crate::document::{Document, Service, VerificationMethod}; +use crate::dids::document::{Document, Service, VerificationMethod}; use self::{also_known_as::AlsoKnownAs, controller::Controller, root_record::RootRecord}; @@ -325,9 +325,9 @@ impl Document { mod tests { use std::sync::Arc; - use crypto::Curve; - use keys::key_manager::local_key_manager::LocalKeyManager; - use keys::key_manager::KeyManager; + use crate::crypto::Curve; + use crate::keys::key_manager::local_key_manager::LocalKeyManager; + use crate::keys::key_manager::KeyManager; use super::*; diff --git a/crates/dids/src/methods/dht/document_packet/rdata_encoder.rs b/crates/web5/src/dids/methods/dht/document_packet/rdata_encoder.rs similarity index 100% rename from crates/dids/src/methods/dht/document_packet/rdata_encoder.rs rename to crates/web5/src/dids/methods/dht/document_packet/rdata_encoder.rs diff --git a/crates/dids/src/methods/dht/document_packet/root_record.rs b/crates/web5/src/dids/methods/dht/document_packet/root_record.rs similarity index 100% rename from crates/dids/src/methods/dht/document_packet/root_record.rs rename to crates/web5/src/dids/methods/dht/document_packet/root_record.rs diff --git a/crates/dids/src/methods/dht/document_packet/service.rs b/crates/web5/src/dids/methods/dht/document_packet/service.rs similarity index 99% rename from crates/dids/src/methods/dht/document_packet/service.rs rename to crates/web5/src/dids/methods/dht/document_packet/service.rs index db15930c..a27e4745 100644 --- a/crates/dids/src/methods/dht/document_packet/service.rs +++ b/crates/web5/src/dids/methods/dht/document_packet/service.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use crate::document::Service; +use crate::dids::document::Service; use simple_dns::{ rdata::{RData, TXT}, diff --git a/crates/dids/src/methods/dht/document_packet/verification_method.rs b/crates/web5/src/dids/methods/dht/document_packet/verification_method.rs similarity index 98% rename from crates/dids/src/methods/dht/document_packet/verification_method.rs rename to crates/web5/src/dids/methods/dht/document_packet/verification_method.rs index 40af8b0a..f8cfa1de 100644 --- a/crates/dids/src/methods/dht/document_packet/verification_method.rs +++ b/crates/web5/src/dids/methods/dht/document_packet/verification_method.rs @@ -1,9 +1,9 @@ use std::{collections::HashMap, str::FromStr}; -use crate::document::VerificationMethod; +use crate::dids::document::VerificationMethod; +use crate::crypto::{ed25519::Ed25519, secp256k1::Secp256k1, Curve}; use base64::{engine::general_purpose, Engine as _}; -use crypto::{ed25519::Ed25519, secp256k1::Secp256k1, Curve}; use simple_dns::{ rdata::{RData, TXT}, Name, ResourceRecord, @@ -169,7 +169,7 @@ impl VerificationMethod { #[cfg(test)] mod tests { - use crypto::CurveOperations; + use crate::crypto::CurveOperations; use simple_dns::rdata::A; use super::*; diff --git a/crates/dids/src/methods/dht/mod.rs b/crates/web5/src/dids/methods/dht/mod.rs similarity index 100% rename from crates/dids/src/methods/dht/mod.rs rename to crates/web5/src/dids/methods/dht/mod.rs diff --git a/crates/dids/src/methods/jwk.rs b/crates/web5/src/dids/methods/jwk.rs similarity index 93% rename from crates/dids/src/methods/jwk.rs rename to crates/web5/src/dids/methods/jwk.rs index 86f7da04..c7468b4f 100644 --- a/crates/dids/src/methods/jwk.rs +++ b/crates/web5/src/dids/methods/jwk.rs @@ -1,16 +1,16 @@ use std::sync::Arc; -use crate::identifier::Identifier; -use crate::methods::{MethodError, Resolve}; -use crate::resolver::ResolutionResult; -use crate::{bearer::BearerDid, methods::Create}; -use crate::{ +use crate::crypto::Curve; +use crate::dids::identifier::Identifier; +use crate::dids::methods::{MethodError, Resolve}; +use crate::dids::resolver::ResolutionResult; +use crate::dids::{bearer::BearerDid, methods::Create}; +use crate::dids::{ document::{Document, VerificationMethod}, methods::Method, }; -use crypto::Curve; +use crate::keys::key_manager::KeyManager; use did_jwk::DIDJWK as SpruceDidJwkMethod; -use keys::key_manager::KeyManager; use serde_json::from_str; use ssi_dids::did_resolve::{DIDResolver, ResolutionInputMetadata}; use ssi_dids::{DIDMethod, Source}; @@ -101,8 +101,8 @@ impl Resolve for DidJwk { #[cfg(test)] mod tests { use super::*; - use crate::resolver::ResolutionError; - use keys::key_manager::local_key_manager::LocalKeyManager; + use crate::dids::resolver::ResolutionError; + use crate::keys::key_manager::local_key_manager::LocalKeyManager; fn create_did_jwk() -> BearerDid { let key_manager = Arc::new(LocalKeyManager::new()); diff --git a/crates/dids/src/methods/mod.rs b/crates/web5/src/dids/methods/mod.rs similarity index 93% rename from crates/dids/src/methods/mod.rs rename to crates/web5/src/dids/methods/mod.rs index bcea0382..ce688ae5 100644 --- a/crates/dids/src/methods/mod.rs +++ b/crates/web5/src/dids/methods/mod.rs @@ -3,8 +3,8 @@ pub mod jwk; pub mod spruce_mappers; pub mod web; -use crate::resolver::ResolutionResult; -use keys::{ +use crate::dids::resolver::ResolutionResult; +use crate::keys::{ key::KeyError, key_manager::{KeyManager, KeyManagerError}, }; @@ -35,7 +35,7 @@ pub trait Create { fn create( key_manager: Arc, opts: O, - ) -> Result; + ) -> Result; } /// Method is the trait for DID methods overall that can be resolved. Methods can also implement diff --git a/crates/dids/src/methods/spruce_mappers/document.rs b/crates/web5/src/dids/methods/spruce_mappers/document.rs similarity index 99% rename from crates/dids/src/methods/spruce_mappers/document.rs rename to crates/web5/src/dids/methods/spruce_mappers/document.rs index 0f2eea56..39434cef 100644 --- a/crates/dids/src/methods/spruce_mappers/document.rs +++ b/crates/web5/src/dids/methods/spruce_mappers/document.rs @@ -1,5 +1,5 @@ -use crate::document::{Document, Service, VerificationMethod}; -use jwk::Jwk; +use crate::dids::document::{Document, Service, VerificationMethod}; +use crate::jwk::Jwk; use ssi_core::one_or_many::OneOrMany; use ssi_dids::{ Context as SpruceContext, Contexts as SpruceContexts, Document as SpruceDocument, diff --git a/crates/dids/src/methods/spruce_mappers/document_metadata.rs b/crates/web5/src/dids/methods/spruce_mappers/document_metadata.rs similarity index 99% rename from crates/dids/src/methods/spruce_mappers/document_metadata.rs rename to crates/web5/src/dids/methods/spruce_mappers/document_metadata.rs index 3051dcbc..3542cdcd 100644 --- a/crates/dids/src/methods/spruce_mappers/document_metadata.rs +++ b/crates/web5/src/dids/methods/spruce_mappers/document_metadata.rs @@ -1,4 +1,4 @@ -use crate::resolver::DocumentMetadata; +use crate::dids::resolver::DocumentMetadata; use ssi_dids::did_resolve::DocumentMetadata as SpruceDocumentMetadata; impl DocumentMetadata { diff --git a/crates/dids/src/methods/spruce_mappers/mod.rs b/crates/web5/src/dids/methods/spruce_mappers/mod.rs similarity index 100% rename from crates/dids/src/methods/spruce_mappers/mod.rs rename to crates/web5/src/dids/methods/spruce_mappers/mod.rs diff --git a/crates/dids/src/methods/spruce_mappers/resolution_metadata.rs b/crates/web5/src/dids/methods/spruce_mappers/resolution_metadata.rs similarity index 97% rename from crates/dids/src/methods/spruce_mappers/resolution_metadata.rs rename to crates/web5/src/dids/methods/spruce_mappers/resolution_metadata.rs index 5749c556..13973a60 100644 --- a/crates/dids/src/methods/spruce_mappers/resolution_metadata.rs +++ b/crates/web5/src/dids/methods/spruce_mappers/resolution_metadata.rs @@ -1,4 +1,4 @@ -use crate::resolver::{ResolutionError, ResolutionMetadata}; +use crate::dids::resolver::{ResolutionError, ResolutionMetadata}; use ssi_dids::did_resolve::{ ResolutionMetadata as SpruceResolutionMetadata, ERROR_INVALID_DID, ERROR_METHOD_NOT_SUPPORTED, ERROR_NOT_FOUND, ERROR_REPRESENTATION_NOT_SUPPORTED, diff --git a/crates/dids/src/methods/spruce_mappers/resolution_result.rs b/crates/web5/src/dids/methods/spruce_mappers/resolution_result.rs similarity index 90% rename from crates/dids/src/methods/spruce_mappers/resolution_result.rs rename to crates/web5/src/dids/methods/spruce_mappers/resolution_result.rs index a6ee43af..23b23820 100644 --- a/crates/dids/src/methods/spruce_mappers/resolution_result.rs +++ b/crates/web5/src/dids/methods/spruce_mappers/resolution_result.rs @@ -1,5 +1,7 @@ -use crate::document::Document; -use crate::resolver::{DocumentMetadata, ResolutionError, ResolutionMetadata, ResolutionResult}; +use crate::dids::document::Document; +use crate::dids::resolver::{ + DocumentMetadata, ResolutionError, ResolutionMetadata, ResolutionResult, +}; use ssi_dids::did_resolve::{ DocumentMetadata as SpruceDocumentMetadata, ResolutionMetadata as SpruceResolutionMetadata, }; diff --git a/crates/dids/src/methods/web.rs b/crates/web5/src/dids/methods/web.rs similarity index 95% rename from crates/dids/src/methods/web.rs rename to crates/web5/src/dids/methods/web.rs index 86336ccf..ca9d6fa6 100644 --- a/crates/dids/src/methods/web.rs +++ b/crates/web5/src/dids/methods/web.rs @@ -1,4 +1,4 @@ -use crate::methods::{Method, ResolutionResult, Resolve}; +use crate::dids::methods::{Method, ResolutionResult, Resolve}; use did_web::DIDWeb as SpruceDidWebMethod; use ssi_dids::did_resolve::{DIDResolver, ResolutionInputMetadata}; diff --git a/crates/dids/src/lib.rs b/crates/web5/src/dids/mod.rs similarity index 100% rename from crates/dids/src/lib.rs rename to crates/web5/src/dids/mod.rs diff --git a/crates/dids/src/resolver.rs b/crates/web5/src/dids/resolver.rs similarity index 96% rename from crates/dids/src/resolver.rs rename to crates/web5/src/dids/resolver.rs index 4ab6b9d0..a20de1db 100644 --- a/crates/dids/src/resolver.rs +++ b/crates/web5/src/dids/resolver.rs @@ -1,8 +1,8 @@ -use crate::document::Document; -use crate::identifier::Identifier; -use crate::methods::jwk::DidJwk; -use crate::methods::web::DidWeb; -use crate::methods::{Method, Resolve}; +use crate::dids::document::Document; +use crate::dids::identifier::Identifier; +use crate::dids::methods::jwk::DidJwk; +use crate::dids::methods::web::DidWeb; +use crate::dids::methods::{Method, Resolve}; use serde::{Deserialize, Serialize}; #[derive(Debug)] diff --git a/crates/jwk/src/lib.rs b/crates/web5/src/jwk.rs similarity index 100% rename from crates/jwk/src/lib.rs rename to crates/web5/src/jwk.rs diff --git a/crates/jws/src/lib.rs b/crates/web5/src/jws.rs similarity index 98% rename from crates/jws/src/lib.rs rename to crates/web5/src/jws.rs index a018230a..0d315125 100644 --- a/crates/jws/src/lib.rs +++ b/crates/web5/src/jws.rs @@ -1,10 +1,10 @@ -use base64::{engine::general_purpose, DecodeError, Engine as _}; -use crypto::{ed25519::Ed25519, secp256k1::Secp256k1, CryptoError, CurveOperations}; -use dids::{ +use crate::crypto::{ed25519::Ed25519, secp256k1::Secp256k1, CryptoError, CurveOperations}; +use crate::dids::{ bearer::{BearerDid, BearerDidError}, document::{DocumentError, KeyIdFragment, KeySelector}, resolver::{ResolutionError, Resolver}, }; +use base64::{engine::general_purpose, DecodeError, Engine as _}; use serde::{Deserialize, Serialize}; use serde_json::Error as SerdeJsonError; @@ -138,12 +138,12 @@ impl CompactJws { #[cfg(test)] mod tests { use super::*; - use crypto::Curve; - use dids::methods::{ + use crate::crypto::Curve; + use crate::dids::methods::{ jwk::{DidJwk, DidJwkCreateOptions}, Create, }; - use keys::key_manager::local_key_manager::LocalKeyManager; + use crate::keys::key_manager::local_key_manager::LocalKeyManager; use serde_json::json; use std::sync::Arc; diff --git a/crates/jwt/src/jwe.rs b/crates/web5/src/jwt/jwe.rs similarity index 87% rename from crates/jwt/src/jwe.rs rename to crates/web5/src/jwt/jwe.rs index 3bc05173..7b5ad2a3 100644 --- a/crates/jwt/src/jwe.rs +++ b/crates/web5/src/jwt/jwe.rs @@ -1,6 +1,6 @@ -use crate::{Claims, JwtError}; -use dids::{bearer::BearerDid, document::KeySelector}; -use jws::JwsHeader; +use super::{Claims, JwtError}; +use crate::dids::{bearer::BearerDid, document::KeySelector}; +use crate::jws::JwsHeader; // A JWT can be implemented as either a JWS or JWE, this module is the implementation of a JWT as a JWE diff --git a/crates/jwt/src/jws.rs b/crates/web5/src/jwt/jws.rs similarity index 91% rename from crates/jwt/src/jws.rs rename to crates/web5/src/jwt/jws.rs index f9256c37..86bd752e 100644 --- a/crates/jwt/src/jws.rs +++ b/crates/web5/src/jwt/jws.rs @@ -1,6 +1,6 @@ -use crate::{Claims, JwtError}; -use ::jws::{CompactJws, JwsHeader}; -use dids::{bearer::BearerDid, document::KeySelector}; +use super::{Claims, JwtError}; +use crate::dids::{bearer::BearerDid, document::KeySelector}; +use crate::jws::{CompactJws, JwsHeader}; // A JWT can be implemented as either a JWS or JWE, this module is the implementation of a JWT as a JWS @@ -70,16 +70,16 @@ impl Jwt { #[cfg(test)] mod tests { use super::*; - use crate::RegisteredClaims; - use crypto::Curve; - use dids::{ + use crate::crypto::Curve; + use crate::dids::{ document::KeySelector, methods::{ jwk::{DidJwk, DidJwkCreateOptions}, Create, }, }; - use keys::key_manager::local_key_manager::LocalKeyManager; + use crate::jwt::RegisteredClaims; + use crate::keys::key_manager::local_key_manager::LocalKeyManager; use std::sync::Arc; #[tokio::test] diff --git a/crates/jwt/src/lib.rs b/crates/web5/src/jwt/mod.rs similarity index 95% rename from crates/jwt/src/lib.rs rename to crates/web5/src/jwt/mod.rs index e469f848..75ca2c52 100644 --- a/crates/jwt/src/lib.rs +++ b/crates/web5/src/jwt/mod.rs @@ -1,8 +1,8 @@ pub mod jwe; pub mod jws; -use ::jws::JwsError; -use dids::document::DocumentError; +use crate::dids::document::DocumentError; +use crate::jws::JwsError; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde_json::Error as SerdeJsonError; diff --git a/crates/keys/src/key.rs b/crates/web5/src/keys/key.rs similarity index 95% rename from crates/keys/src/key.rs rename to crates/web5/src/keys/key.rs index d3777d79..42665609 100644 --- a/crates/keys/src/key.rs +++ b/crates/web5/src/keys/key.rs @@ -1,5 +1,5 @@ -use crypto::{ed25519::Ed25519, secp256k1::Secp256k1, CryptoError, CurveOperations}; -use jwk::{Jwk, JwkError}; +use crate::crypto::{ed25519::Ed25519, secp256k1::Secp256k1, CryptoError, CurveOperations}; +use crate::jwk::{Jwk, JwkError}; use std::sync::Arc; #[derive(thiserror::Error, Debug, Clone, PartialEq)] @@ -77,7 +77,7 @@ impl PrivateKey for Jwk { #[cfg(test)] mod tests { - use crypto::{ed25519::Ed25519, CurveOperations}; + use crate::crypto::{ed25519::Ed25519, CurveOperations}; use super::*; diff --git a/crates/keys/src/key_manager/local_key_manager.rs b/crates/web5/src/keys/key_manager/local_key_manager.rs similarity index 96% rename from crates/keys/src/key_manager/local_key_manager.rs rename to crates/web5/src/keys/key_manager/local_key_manager.rs index 653ed21f..b8a42766 100644 --- a/crates/keys/src/key_manager/local_key_manager.rs +++ b/crates/web5/src/keys/key_manager/local_key_manager.rs @@ -1,8 +1,8 @@ -use crate::key::{PrivateKey, PublicKey}; -use crate::key_manager::{KeyManager, KeyManagerError}; -use crypto::ed25519::Ed25519; -use crypto::secp256k1::Secp256k1; -use crypto::{Curve, CurveOperations}; +use crate::crypto::ed25519::Ed25519; +use crate::crypto::secp256k1::Secp256k1; +use crate::crypto::{Curve, CurveOperations}; +use crate::keys::key::{PrivateKey, PublicKey}; +use crate::keys::key_manager::{KeyManager, KeyManagerError}; use std::collections::HashMap; use std::sync::{Arc, RwLock}; @@ -106,7 +106,7 @@ impl Default for LocalKeyManager { #[cfg(test)] mod tests { - use crate::key::Key; + use crate::keys::key::Key; use super::*; diff --git a/crates/keys/src/key_manager/mod.rs b/crates/web5/src/keys/key_manager/mod.rs similarity index 94% rename from crates/keys/src/key_manager/mod.rs rename to crates/web5/src/keys/key_manager/mod.rs index b84b66c5..d8ae8100 100644 --- a/crates/keys/src/key_manager/mod.rs +++ b/crates/web5/src/keys/key_manager/mod.rs @@ -1,8 +1,8 @@ pub mod local_key_manager; -use crate::key::{KeyError, PrivateKey, PublicKey}; -use crypto::{CryptoError, Curve}; -use jwk::JwkError; +use crate::crypto::{CryptoError, Curve}; +use crate::jwk::JwkError; +use crate::keys::key::{KeyError, PrivateKey, PublicKey}; use std::sync::Arc; #[derive(thiserror::Error, Debug, Clone, PartialEq)] diff --git a/crates/keys/src/lib.rs b/crates/web5/src/keys/mod.rs similarity index 100% rename from crates/keys/src/lib.rs rename to crates/web5/src/keys/mod.rs diff --git a/crates/web5/src/lib.rs b/crates/web5/src/lib.rs new file mode 100644 index 00000000..13f93b82 --- /dev/null +++ b/crates/web5/src/lib.rs @@ -0,0 +1,10 @@ +pub mod credentials; +pub mod crypto; +pub mod dids; +pub mod jwk; +pub mod jws; +pub mod jwt; +pub mod keys; + +#[cfg(test)] +mod test_helpers; diff --git a/crates/test-helpers/src/lib.rs b/crates/web5/src/test_helpers.rs similarity index 100% rename from crates/test-helpers/src/lib.rs rename to crates/web5/src/test_helpers.rs