From bb46a937eae02fde52055bcf8a3c986bafb47347 Mon Sep 17 00:00:00 2001 From: Kendall Weihe Date: Wed, 4 Sep 2024 18:07:09 -0400 Subject: [PATCH] Remove web5 shim (#115) --- Cargo.toml | 3 +- bindings/tbdex_uniffi/Cargo.toml | 2 +- bindings/tbdex_uniffi/src/lib.rs | 10 +- bindings/tbdex_uniffi/src/tbdex.udl | 58 +- bound/kt/pom.xml | 10 + .../kotlin/tbdex/sdk/httpclient/Balances.kt | 4 +- .../kotlin/tbdex/sdk/httpclient/Exchanges.kt | 6 +- .../main/kotlin/tbdex/sdk/messages/Cancel.kt | 4 +- .../main/kotlin/tbdex/sdk/messages/Close.kt | 4 +- .../main/kotlin/tbdex/sdk/messages/Order.kt | 4 +- .../tbdex/sdk/messages/OrderInstructions.kt | 4 +- .../kotlin/tbdex/sdk/messages/OrderStatus.kt | 4 +- .../main/kotlin/tbdex/sdk/messages/Quote.kt | 4 +- .../src/main/kotlin/tbdex/sdk/messages/Rfq.kt | 4 +- .../kotlin/tbdex/sdk/resources/Balance.kt | 4 +- .../kotlin/tbdex/sdk/resources/Offering.kt | 4 +- .../src/main/kotlin/tbdex/sdk/rust/UniFFI.kt | 1373 +++++------------ .../kt/src/main/kotlin/tbdex/sdk/rust/Web5.kt | 109 ++ .../sdk/crypto/keys/InMemoryKeyManager.kt | 29 - .../kotlin/web5/sdk/crypto/keys/KeyManager.kt | 23 - .../kotlin/web5/sdk/crypto/signers/Signer.kt | 19 - .../main/kotlin/web5/sdk/dids/BearerDid.kt | 43 - .../main/kotlin/web5/sdk/dids/PortableDid.kt | 20 - .../web5/sdk/vc/pex/PresentationDefinition.kt | 54 - crates/tbdex/Cargo.toml | 2 +- crates/tbdex/src/http_client/mod.rs | 19 +- crates/tbdex/src/jose.rs | 13 +- crates/tbdex/src/messages/mod.rs | 4 +- crates/tbdex/src/messages/rfq.rs | 20 +- crates/tbdex/src/resources/mod.rs | 4 +- crates/tbdex/src/resources/offering.rs | 18 +- crates/tbdex/src/signature.rs | 14 +- .../hosted-wallet-kt/pfi/build.gradle.kts | 2 +- .../pfi/src/main/kotlin/Main.kt | 2 +- .../hosted-wallet-kt/wallet/build.gradle.kts | 2 +- .../wallet/src/main/kotlin/Main.kt | 2 +- 36 files changed, 559 insertions(+), 1342 deletions(-) create mode 100644 bound/kt/src/main/kotlin/tbdex/sdk/rust/Web5.kt delete mode 100644 bound/kt/src/main/kotlin/web5/sdk/crypto/keys/InMemoryKeyManager.kt delete mode 100644 bound/kt/src/main/kotlin/web5/sdk/crypto/keys/KeyManager.kt delete mode 100644 bound/kt/src/main/kotlin/web5/sdk/crypto/signers/Signer.kt delete mode 100644 bound/kt/src/main/kotlin/web5/sdk/dids/BearerDid.kt delete mode 100644 bound/kt/src/main/kotlin/web5/sdk/dids/PortableDid.kt delete mode 100644 bound/kt/src/main/kotlin/web5/sdk/vc/pex/PresentationDefinition.kt diff --git a/Cargo.toml b/Cargo.toml index 3be26376..13e80200 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,5 @@ license-file = "LICENSE" serde = { version = "1.0.193", features = ["derive", "rc"] } serde_json = "1.0.108" thiserror = "1.0.50" -web5 = { git = "https://github.com/TBD54566975/web5-rs", rev = "76adcba82bc2547f09cb70435b5528b7b64090bd" } +web5 = { git = "https://github.com/TBD54566975/web5-rs", rev = "e2851a074c46c9891810bb32ab4b5f93ae7c807c" } +web5_uniffi_wrapper = { git = "https://github.com/TBD54566975/web5-rs", rev = "e2851a074c46c9891810bb32ab4b5f93ae7c807c" } diff --git a/bindings/tbdex_uniffi/Cargo.toml b/bindings/tbdex_uniffi/Cargo.toml index 531b4e06..879773a5 100644 --- a/bindings/tbdex_uniffi/Cargo.toml +++ b/bindings/tbdex_uniffi/Cargo.toml @@ -12,7 +12,7 @@ tbdex = { path = "../../crates/tbdex" } thiserror = { workspace = true } uniffi = { version = "0.27.1", features = ["cli"] } web5 = { workspace = true } -web5_uniffi_wrapper = { git = "https://github.com/TBD54566975/web5-rs", rev = "76adcba82bc2547f09cb70435b5528b7b64090bd" } +web5_uniffi_wrapper = { workspace = true } [build-dependencies] uniffi = { version = "0.27.1", features = ["build"] } diff --git a/bindings/tbdex_uniffi/src/lib.rs b/bindings/tbdex_uniffi/src/lib.rs index 58f06440..16e59ffb 100644 --- a/bindings/tbdex_uniffi/src/lib.rs +++ b/bindings/tbdex_uniffi/src/lib.rs @@ -72,17 +72,13 @@ use web5::{ verification_method::VerificationMethod as VerificationMethodData, }, did::Did as DidData, - portable_did::PortableDid as PortableDidData, }, }; use web5_uniffi_wrapper::{ credentials::presentation_definition::PresentationDefinition, - crypto::{dsa::Signer, in_memory_key_manager::InMemoryKeyManager, key_manager::KeyManager}, - dids::{ - bearer_did::{BearerDid, BearerDidData}, - portable_did::PortableDid, - }, - errors::RustCoreError as Web5RustCoreError, + crypto::{dsa::Signer, key_manager::KeyManager}, + dids::bearer_did::BearerDid, + errors::Web5Error, }; uniffi::include_scaffolding!("tbdex"); diff --git a/bindings/tbdex_uniffi/src/tbdex.udl b/bindings/tbdex_uniffi/src/tbdex.udl index b780b9eb..5a441d73 100644 --- a/bindings/tbdex_uniffi/src/tbdex.udl +++ b/bindings/tbdex_uniffi/src/tbdex.udl @@ -460,7 +460,10 @@ dictionary GetExchangeIdsQueryParamsData { - +[Error] +interface Web5Error { + Error(string variant, string msg); +}; dictionary JwkData { string? alg; @@ -509,59 +512,28 @@ dictionary ServiceData { sequence service_endpoint; }; -[Error] -interface Web5RustCoreError { - Error(string type, string variant, string msg); -}; - [Trait, WithForeign] interface Signer { - [Throws=Web5RustCoreError] + [Throws=Web5Error] bytes sign(bytes payload); }; [Trait, WithForeign] interface KeyManager { - [Throws=Web5RustCoreError] - Signer get_signer(JwkData public_jwk); -}; - -interface InMemoryKeyManager { - constructor(); - [Throws=Web5RustCoreError] + [Throws=Web5Error] + JwkData import_private_jwk(JwkData private_jwk); + [Throws=Web5Error] Signer get_signer(JwkData public_jwk); - [Throws=Web5RustCoreError] - JwkData import_private_jwk(JwkData private_key); - KeyManager get_as_key_manager(); }; -dictionary PortableDidData { - string did_uri; - DocumentData document; - sequence private_jwks; +interface BearerDid { + constructor(DidData did, DocumentData document, KeyManager key_manager); + [Throws=Web5Error] + Signer get_signer(string verification_method_id); }; -interface PortableDid { - [Throws=Web5RustCoreError] - constructor([ByRef] string json); - PortableDidData get_data(); -}; -dictionary BearerDidData { - DidData did; - DocumentData document; - KeyManager key_manager; -}; -interface BearerDid { - [Throws=Web5RustCoreError] - constructor([ByRef] string uri, KeyManager key_manager); - [Throws=Web5RustCoreError, Name=from_portable_did] - constructor(PortableDid portable_did); - BearerDidData get_data(); - [Throws=Web5RustCoreError] - Signer get_signer(string key_id); -}; @@ -569,10 +541,10 @@ interface BearerDid { interface PresentationDefinition { - [Throws=Web5RustCoreError] + [Throws=Web5Error] constructor(string json_serialized_presentation_definition); - [Throws=Web5RustCoreError] + [Throws=Web5Error] string get_json_serialized_presentation_definition(); - [Throws=Web5RustCoreError] + [Throws=Web5Error] sequence select_credentials([ByRef] sequence vc_jwts); }; \ No newline at end of file diff --git a/bound/kt/pom.xml b/bound/kt/pom.xml index 05ecb7f5..38bbc722 100644 --- a/bound/kt/pom.xml +++ b/bound/kt/pom.xml @@ -102,6 +102,7 @@ 2.17.0 5.12.0 1.8.1 + commit-f28d90c-SNAPSHOT 5.10.1 @@ -188,6 +189,11 @@ kotlinx-coroutines-core ${version.org.jetbrains.kotlinx.kotlinx.coroutines.core} + + xyz.block + web5 + ${version.xyz.block.web5} + @@ -231,6 +237,10 @@ org.jetbrains.kotlin kotlin-stdlib-jdk8 + + xyz.block + web5 + diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Balances.kt b/bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Balances.kt index 21a33a65..f1433936 100644 --- a/bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Balances.kt +++ b/bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Balances.kt @@ -2,9 +2,11 @@ package tbdex.sdk.httpclient import tbdex.sdk.resources.Balance import tbdex.sdk.rust.getBalances as rustCoreGetBalances +import tbdex.sdk.rust.fromWeb5 +import tbdex.sdk.rust.BearerDid as RustCoreBearerDid import web5.sdk.dids.BearerDid fun getBalances(pfiDidUri: String, bearerDid: BearerDid): List { - val rustCoreBalances = rustCoreGetBalances(pfiDidUri, bearerDid.rustCoreBearerDid) + val rustCoreBalances = rustCoreGetBalances(pfiDidUri, RustCoreBearerDid.fromWeb5(bearerDid)) return rustCoreBalances.map { Balance.fromRustCoreBalance(it) } } \ No newline at end of file diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Exchanges.kt b/bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Exchanges.kt index c1d5a907..a937d86b 100644 --- a/bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Exchanges.kt +++ b/bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Exchanges.kt @@ -8,6 +8,8 @@ import tbdex.sdk.rust.submitOrder as rustCoreSubmitOrder import tbdex.sdk.rust.submitCancel as rustCoreSubmitCancel import tbdex.sdk.rust.getExchange as rustCoreGetExchange import tbdex.sdk.rust.getExchangeIds as rustCoreGetExchangeIds +import tbdex.sdk.rust.fromWeb5 +import tbdex.sdk.rust.BearerDid as RustCoreBearerDid import web5.sdk.dids.BearerDid data class Exchange( @@ -47,14 +49,14 @@ fun submitCancel(cancel: Cancel) { } fun getExchange(pfiDidUri: String, bearerDid: BearerDid, exchangeId: String): Exchange { - val rustCoreExchange = rustCoreGetExchange(pfiDidUri, bearerDid.rustCoreBearerDid, exchangeId) + val rustCoreExchange = rustCoreGetExchange(pfiDidUri, RustCoreBearerDid.fromWeb5(bearerDid), exchangeId) return Exchange.fromRustCore(rustCoreExchange) } typealias GetExchangeIdsQueryParams = RustCoreGetExchangeIdsQueryParams fun getExchangeIds(pfiDidUri: String, bearerDid: BearerDid, queryParams: GetExchangeIdsQueryParams? = null): List { - return rustCoreGetExchangeIds(pfiDidUri, bearerDid.rustCoreBearerDid, queryParams) + return rustCoreGetExchangeIds(pfiDidUri, RustCoreBearerDid.fromWeb5(bearerDid), queryParams) } diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/messages/Cancel.kt b/bound/kt/src/main/kotlin/tbdex/sdk/messages/Cancel.kt index 43b326bd..bdbcf228 100644 --- a/bound/kt/src/main/kotlin/tbdex/sdk/messages/Cancel.kt +++ b/bound/kt/src/main/kotlin/tbdex/sdk/messages/Cancel.kt @@ -3,6 +3,8 @@ package tbdex.sdk.messages import tbdex.sdk.http.WalletUpdateMessage import tbdex.sdk.rust.Cancel as RustCoreCancel import tbdex.sdk.rust.CancelDataData as RustCoreCancelData +import tbdex.sdk.rust.fromWeb5 +import tbdex.sdk.rust.BearerDid as RustCoreBearerDid import web5.sdk.dids.BearerDid typealias CancelData = RustCoreCancelData @@ -44,7 +46,7 @@ class Cancel private constructor( } fun sign(bearerDid: BearerDid) { - this.rustCoreCancel.sign(bearerDid.rustCoreBearerDid) + this.rustCoreCancel.sign(RustCoreBearerDid.fromWeb5(bearerDid)) } fun verify() { diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/messages/Close.kt b/bound/kt/src/main/kotlin/tbdex/sdk/messages/Close.kt index 8bc7cffb..6fe61929 100644 --- a/bound/kt/src/main/kotlin/tbdex/sdk/messages/Close.kt +++ b/bound/kt/src/main/kotlin/tbdex/sdk/messages/Close.kt @@ -3,6 +3,8 @@ package tbdex.sdk.messages import tbdex.sdk.http.ReplyToMessage import tbdex.sdk.rust.Close as RustCoreClose import tbdex.sdk.rust.CloseDataData as RustCoreCloseData +import tbdex.sdk.rust.fromWeb5 +import tbdex.sdk.rust.BearerDid as RustCoreBearerDid import web5.sdk.dids.BearerDid typealias CloseData = RustCoreCloseData @@ -44,7 +46,7 @@ class Close private constructor( } fun sign(bearerDid: BearerDid) { - this.rustCoreClose.sign(bearerDid.rustCoreBearerDid) + this.rustCoreClose.sign(RustCoreBearerDid.fromWeb5(bearerDid)) } fun verify() { diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/messages/Order.kt b/bound/kt/src/main/kotlin/tbdex/sdk/messages/Order.kt index b0ccd9c5..f63c0b18 100644 --- a/bound/kt/src/main/kotlin/tbdex/sdk/messages/Order.kt +++ b/bound/kt/src/main/kotlin/tbdex/sdk/messages/Order.kt @@ -2,6 +2,8 @@ package tbdex.sdk.messages import tbdex.sdk.http.WalletUpdateMessage import tbdex.sdk.rust.Order as RustCoreOrder +import tbdex.sdk.rust.fromWeb5 +import tbdex.sdk.rust.BearerDid as RustCoreBearerDid import web5.sdk.dids.BearerDid class Order private constructor( @@ -39,7 +41,7 @@ class Order private constructor( } fun sign(bearerDid: BearerDid) { - this.rustCoreOrder.sign(bearerDid.rustCoreBearerDid) + this.rustCoreOrder.sign(RustCoreBearerDid.fromWeb5(bearerDid)) } fun verify() { diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/messages/OrderInstructions.kt b/bound/kt/src/main/kotlin/tbdex/sdk/messages/OrderInstructions.kt index 2951cde3..497da3e8 100644 --- a/bound/kt/src/main/kotlin/tbdex/sdk/messages/OrderInstructions.kt +++ b/bound/kt/src/main/kotlin/tbdex/sdk/messages/OrderInstructions.kt @@ -2,6 +2,8 @@ package tbdex.sdk.messages import tbdex.sdk.http.ReplyToMessage import tbdex.sdk.rust.OrderInstructionsDataData as RustCoreOrderInstructionsData +import tbdex.sdk.rust.fromWeb5 +import tbdex.sdk.rust.BearerDid as RustCoreBearerDid import web5.sdk.dids.BearerDid typealias OrderInstructionsData = RustCoreOrderInstructionsData @@ -44,7 +46,7 @@ class OrderInstructions private constructor( } fun sign(bearerDid: BearerDid) { - this.rustCoreOrderInstructions.sign(bearerDid.rustCoreBearerDid) + this.rustCoreOrderInstructions.sign(RustCoreBearerDid.fromWeb5(bearerDid)) } fun verify() { diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/messages/OrderStatus.kt b/bound/kt/src/main/kotlin/tbdex/sdk/messages/OrderStatus.kt index cc9e5346..49449a29 100644 --- a/bound/kt/src/main/kotlin/tbdex/sdk/messages/OrderStatus.kt +++ b/bound/kt/src/main/kotlin/tbdex/sdk/messages/OrderStatus.kt @@ -4,6 +4,8 @@ import tbdex.sdk.http.ReplyToMessage import tbdex.sdk.rust.OrderStatusStatus as RustCoreStatus import tbdex.sdk.rust.OrderStatus as RustCoreOrderStatus import tbdex.sdk.rust.OrderStatusDataData as RustCoreOrderStatusData +import tbdex.sdk.rust.fromWeb5 +import tbdex.sdk.rust.BearerDid as RustCoreBearerDid import web5.sdk.dids.BearerDid typealias OrderStatusData = RustCoreOrderStatusData @@ -46,7 +48,7 @@ class OrderStatus private constructor( } fun sign(bearerDid: BearerDid) { - this.rustCoreOrderStatus.sign(bearerDid.rustCoreBearerDid) + this.rustCoreOrderStatus.sign(RustCoreBearerDid.fromWeb5(bearerDid)) } fun verify() { diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/messages/Quote.kt b/bound/kt/src/main/kotlin/tbdex/sdk/messages/Quote.kt index 1d22bb8f..22d995d1 100644 --- a/bound/kt/src/main/kotlin/tbdex/sdk/messages/Quote.kt +++ b/bound/kt/src/main/kotlin/tbdex/sdk/messages/Quote.kt @@ -5,6 +5,8 @@ import tbdex.sdk.rust.PaymentInstructionData as RustCorePaymentInstruction import tbdex.sdk.rust.QuoteDetailsData as RustCoreQuoteDetails import tbdex.sdk.rust.Quote as RustCoreQuote import tbdex.sdk.rust.QuoteDataData as RustCoreQuoteData +import tbdex.sdk.rust.fromWeb5 +import tbdex.sdk.rust.BearerDid as RustCoreBearerDid import web5.sdk.dids.BearerDid typealias QuoteData = RustCoreQuoteData @@ -48,7 +50,7 @@ class Quote private constructor( } fun sign(bearerDid: BearerDid) { - this.rustCoreQuote.sign(bearerDid.rustCoreBearerDid) + this.rustCoreQuote.sign(RustCoreBearerDid.fromWeb5(bearerDid)) } fun verify() { diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/messages/Rfq.kt b/bound/kt/src/main/kotlin/tbdex/sdk/messages/Rfq.kt index 5797b84f..71b65ff1 100644 --- a/bound/kt/src/main/kotlin/tbdex/sdk/messages/Rfq.kt +++ b/bound/kt/src/main/kotlin/tbdex/sdk/messages/Rfq.kt @@ -2,7 +2,9 @@ package tbdex.sdk.messages import tbdex.sdk.Json import tbdex.sdk.resources.Offering +import tbdex.sdk.rust.fromWeb5 import tbdex.sdk.rust.Rfq as RustCoreRfq +import tbdex.sdk.rust.BearerDid as RustCoreBearerDid import web5.sdk.dids.BearerDid class Rfq private constructor( @@ -61,7 +63,7 @@ class Rfq private constructor( } fun sign(bearerDid: BearerDid) { - this.rustCoreRfq.sign(bearerDid.rustCoreBearerDid) + this.rustCoreRfq.sign(RustCoreBearerDid.fromWeb5(bearerDid)) } fun verify() { diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/resources/Balance.kt b/bound/kt/src/main/kotlin/tbdex/sdk/resources/Balance.kt index a52fb331..6d3c846a 100644 --- a/bound/kt/src/main/kotlin/tbdex/sdk/resources/Balance.kt +++ b/bound/kt/src/main/kotlin/tbdex/sdk/resources/Balance.kt @@ -2,6 +2,8 @@ package tbdex.sdk.resources import tbdex.sdk.rust.Balance as RustCoreBalance import tbdex.sdk.rust.BalanceDataData as RustCoreBalanceData +import tbdex.sdk.rust.fromWeb5 +import tbdex.sdk.rust.BearerDid as RustCoreBearerDid import web5.sdk.dids.BearerDid typealias BalanceData = RustCoreBalanceData @@ -40,7 +42,7 @@ class Balance private constructor( } fun sign(bearerDid: BearerDid) { - this.rustCoreBalance.sign(bearerDid.rustCoreBearerDid) + this.rustCoreBalance.sign(RustCoreBearerDid.fromWeb5(bearerDid)) } fun verify() { diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/resources/Offering.kt b/bound/kt/src/main/kotlin/tbdex/sdk/resources/Offering.kt index 82ac4bda..d9734da7 100644 --- a/bound/kt/src/main/kotlin/tbdex/sdk/resources/Offering.kt +++ b/bound/kt/src/main/kotlin/tbdex/sdk/resources/Offering.kt @@ -2,6 +2,8 @@ package tbdex.sdk.resources import tbdex.sdk.Json import tbdex.sdk.rust.Offering as RustCoreOffering +import tbdex.sdk.rust.fromWeb5 +import tbdex.sdk.rust.BearerDid as RustCoreBearerDid import web5.sdk.dids.BearerDid import web5.sdk.vc.pex.PresentationDefinition @@ -47,7 +49,7 @@ class Offering private constructor( } fun sign(bearerDid: BearerDid) { - this.rustCoreOffering.sign(bearerDid.rustCoreBearerDid) + this.rustCoreOffering.sign(RustCoreBearerDid.fromWeb5(bearerDid)) } fun verify() { diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/rust/UniFFI.kt b/bound/kt/src/main/kotlin/tbdex/sdk/rust/UniFFI.kt index 55f1c24f..245972ff 100644 --- a/bound/kt/src/main/kotlin/tbdex/sdk/rust/UniFFI.kt +++ b/bound/kt/src/main/kotlin/tbdex/sdk/rust/UniFFI.kt @@ -636,21 +636,27 @@ internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback { internal interface UniffiCallbackInterfaceKeyManagerMethod0 : com.sun.jna.Callback { fun callback(`uniffiHandle`: Long,`publicJwk`: RustBuffer.ByValue,`uniffiOutReturn`: PointerByReference,uniffiCallStatus: UniffiRustCallStatus,) } +internal interface UniffiCallbackInterfaceKeyManagerMethod1 : com.sun.jna.Callback { + fun callback(`uniffiHandle`: Long,`privateJwk`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) +} internal interface UniffiCallbackInterfaceSignerMethod0 : com.sun.jna.Callback { fun callback(`uniffiHandle`: Long,`payload`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) } -@Structure.FieldOrder("getSigner", "uniffiFree") +@Structure.FieldOrder("getSigner", "importPrivateJwk", "uniffiFree") internal open class UniffiVTableCallbackInterfaceKeyManager( @JvmField internal var `getSigner`: UniffiCallbackInterfaceKeyManagerMethod0? = null, + @JvmField internal var `importPrivateJwk`: UniffiCallbackInterfaceKeyManagerMethod1? = null, @JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null, ) : Structure() { class UniffiByValue( `getSigner`: UniffiCallbackInterfaceKeyManagerMethod0? = null, + `importPrivateJwk`: UniffiCallbackInterfaceKeyManagerMethod1? = null, `uniffiFree`: UniffiCallbackInterfaceFree? = null, - ): UniffiVTableCallbackInterfaceKeyManager(`getSigner`,`uniffiFree`,), Structure.ByValue + ): UniffiVTableCallbackInterfaceKeyManager(`getSigner`,`importPrivateJwk`,`uniffiFree`,), Structure.ByValue internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceKeyManager) { `getSigner` = other.`getSigner` + `importPrivateJwk` = other.`importPrivateJwk` `uniffiFree` = other.`uniffiFree` } @@ -962,24 +968,6 @@ internal open class UniffiVTableCallbackInterfaceSigner( - - - - - - - - - - - - - - - - - - @@ -1040,13 +1028,9 @@ internal interface UniffiLib : Library { ): Pointer fun uniffi_tbdex_uniffi_fn_free_bearerdid(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Unit - fun uniffi_tbdex_uniffi_fn_constructor_bearerdid_from_portable_did(`portableDid`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_tbdex_uniffi_fn_constructor_bearerdid_new(`uri`: RustBuffer.ByValue,`keyManager`: Pointer,uniffi_out_err: UniffiRustCallStatus, + fun uniffi_tbdex_uniffi_fn_constructor_bearerdid_new(`did`: RustBuffer.ByValue,`document`: RustBuffer.ByValue,`keyManager`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Pointer - fun uniffi_tbdex_uniffi_fn_method_bearerdid_get_data(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_tbdex_uniffi_fn_method_bearerdid_get_signer(`ptr`: Pointer,`keyId`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, + fun uniffi_tbdex_uniffi_fn_method_bearerdid_get_signer(`ptr`: Pointer,`verificationMethodId`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, ): Pointer fun uniffi_tbdex_uniffi_fn_clone_cancel(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Pointer @@ -1152,18 +1136,6 @@ internal interface UniffiLib : Library { ): RustBuffer.ByValue fun uniffi_tbdex_uniffi_fn_method_getofferingsresponsebody_to_json_string(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue - fun uniffi_tbdex_uniffi_fn_clone_inmemorykeymanager(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_tbdex_uniffi_fn_free_inmemorykeymanager(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_tbdex_uniffi_fn_constructor_inmemorykeymanager_new(uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_tbdex_uniffi_fn_method_inmemorykeymanager_get_as_key_manager(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_tbdex_uniffi_fn_method_inmemorykeymanager_get_signer(`ptr`: Pointer,`publicJwk`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_tbdex_uniffi_fn_method_inmemorykeymanager_import_private_jwk(`ptr`: Pointer,`privateKey`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue fun uniffi_tbdex_uniffi_fn_clone_keymanager(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Pointer fun uniffi_tbdex_uniffi_fn_free_keymanager(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, @@ -1172,6 +1144,8 @@ internal interface UniffiLib : Library { ): Unit fun uniffi_tbdex_uniffi_fn_method_keymanager_get_signer(`ptr`: Pointer,`publicJwk`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, ): Pointer + fun uniffi_tbdex_uniffi_fn_method_keymanager_import_private_jwk(`ptr`: Pointer,`privateJwk`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, + ): RustBuffer.ByValue fun uniffi_tbdex_uniffi_fn_clone_offering(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Pointer fun uniffi_tbdex_uniffi_fn_free_offering(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, @@ -1236,14 +1210,6 @@ internal interface UniffiLib : Library { ): RustBuffer.ByValue fun uniffi_tbdex_uniffi_fn_method_orderstatus_verify(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Unit - fun uniffi_tbdex_uniffi_fn_clone_portabledid(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_tbdex_uniffi_fn_free_portabledid(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_tbdex_uniffi_fn_constructor_portabledid_new(`json`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_tbdex_uniffi_fn_method_portabledid_get_data(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue fun uniffi_tbdex_uniffi_fn_clone_presentationdefinition(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Pointer fun uniffi_tbdex_uniffi_fn_free_presentationdefinition(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, @@ -1472,8 +1438,6 @@ internal interface UniffiLib : Library { ): Short fun uniffi_tbdex_uniffi_checksum_method_balance_verify( ): Short - fun uniffi_tbdex_uniffi_checksum_method_bearerdid_get_data( - ): Short fun uniffi_tbdex_uniffi_checksum_method_bearerdid_get_signer( ): Short fun uniffi_tbdex_uniffi_checksum_method_cancel_get_data( @@ -1516,14 +1480,10 @@ internal interface UniffiLib : Library { ): Short fun uniffi_tbdex_uniffi_checksum_method_getofferingsresponsebody_to_json_string( ): Short - fun uniffi_tbdex_uniffi_checksum_method_inmemorykeymanager_get_as_key_manager( - ): Short - fun uniffi_tbdex_uniffi_checksum_method_inmemorykeymanager_get_signer( - ): Short - fun uniffi_tbdex_uniffi_checksum_method_inmemorykeymanager_import_private_jwk( - ): Short fun uniffi_tbdex_uniffi_checksum_method_keymanager_get_signer( ): Short + fun uniffi_tbdex_uniffi_checksum_method_keymanager_import_private_jwk( + ): Short fun uniffi_tbdex_uniffi_checksum_method_offering_get_data( ): Short fun uniffi_tbdex_uniffi_checksum_method_offering_sign( @@ -1556,8 +1516,6 @@ internal interface UniffiLib : Library { ): Short fun uniffi_tbdex_uniffi_checksum_method_orderstatus_verify( ): Short - fun uniffi_tbdex_uniffi_checksum_method_portabledid_get_data( - ): Short fun uniffi_tbdex_uniffi_checksum_method_presentationdefinition_get_json_serialized_presentation_definition( ): Short fun uniffi_tbdex_uniffi_checksum_method_presentationdefinition_select_credentials( @@ -1598,8 +1556,6 @@ internal interface UniffiLib : Library { ): Short fun uniffi_tbdex_uniffi_checksum_constructor_balance_from_json_string( ): Short - fun uniffi_tbdex_uniffi_checksum_constructor_bearerdid_from_portable_did( - ): Short fun uniffi_tbdex_uniffi_checksum_constructor_bearerdid_new( ): Short fun uniffi_tbdex_uniffi_checksum_constructor_cancel_create( @@ -1634,8 +1590,6 @@ internal interface UniffiLib : Library { ): Short fun uniffi_tbdex_uniffi_checksum_constructor_getofferingsresponsebody_new( ): Short - fun uniffi_tbdex_uniffi_checksum_constructor_inmemorykeymanager_new( - ): Short fun uniffi_tbdex_uniffi_checksum_constructor_offering_create( ): Short fun uniffi_tbdex_uniffi_checksum_constructor_offering_from_json_string( @@ -1652,8 +1606,6 @@ internal interface UniffiLib : Library { ): Short fun uniffi_tbdex_uniffi_checksum_constructor_orderstatus_from_json_string( ): Short - fun uniffi_tbdex_uniffi_checksum_constructor_portabledid_new( - ): Short fun uniffi_tbdex_uniffi_checksum_constructor_presentationdefinition_new( ): Short fun uniffi_tbdex_uniffi_checksum_constructor_quote_create( @@ -1722,10 +1674,7 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) { if (lib.uniffi_tbdex_uniffi_checksum_method_balance_verify() != 64077.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_tbdex_uniffi_checksum_method_bearerdid_get_data() != 7101.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_tbdex_uniffi_checksum_method_bearerdid_get_signer() != 22456.toShort()) { + if (lib.uniffi_tbdex_uniffi_checksum_method_bearerdid_get_signer() != 23173.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_tbdex_uniffi_checksum_method_cancel_get_data() != 105.toShort()) { @@ -1788,16 +1737,10 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) { if (lib.uniffi_tbdex_uniffi_checksum_method_getofferingsresponsebody_to_json_string() != 15472.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_tbdex_uniffi_checksum_method_inmemorykeymanager_get_as_key_manager() != 181.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_tbdex_uniffi_checksum_method_inmemorykeymanager_get_signer() != 36148.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_tbdex_uniffi_checksum_method_inmemorykeymanager_import_private_jwk() != 3278.toShort()) { + if (lib.uniffi_tbdex_uniffi_checksum_method_keymanager_get_signer() != 18555.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_tbdex_uniffi_checksum_method_keymanager_get_signer() != 55674.toShort()) { + if (lib.uniffi_tbdex_uniffi_checksum_method_keymanager_import_private_jwk() != 7852.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_tbdex_uniffi_checksum_method_offering_get_data() != 20546.toShort()) { @@ -1848,13 +1791,10 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) { if (lib.uniffi_tbdex_uniffi_checksum_method_orderstatus_verify() != 56745.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_tbdex_uniffi_checksum_method_portabledid_get_data() != 16147.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_tbdex_uniffi_checksum_method_presentationdefinition_get_json_serialized_presentation_definition() != 16906.toShort()) { + if (lib.uniffi_tbdex_uniffi_checksum_method_presentationdefinition_get_json_serialized_presentation_definition() != 14815.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_tbdex_uniffi_checksum_method_presentationdefinition_select_credentials() != 31180.toShort()) { + if (lib.uniffi_tbdex_uniffi_checksum_method_presentationdefinition_select_credentials() != 50229.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_tbdex_uniffi_checksum_method_quote_get_data() != 53459.toShort()) { @@ -1896,7 +1836,7 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) { if (lib.uniffi_tbdex_uniffi_checksum_method_rfq_verify_present_private_data() != 8587.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_tbdex_uniffi_checksum_method_signer_sign() != 42600.toShort()) { + if (lib.uniffi_tbdex_uniffi_checksum_method_signer_sign() != 51023.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_tbdex_uniffi_checksum_method_updateexchangerequestbody_get_data() != 53389.toShort()) { @@ -1911,10 +1851,7 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) { if (lib.uniffi_tbdex_uniffi_checksum_constructor_balance_from_json_string() != 25520.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_tbdex_uniffi_checksum_constructor_bearerdid_from_portable_did() != 56314.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_tbdex_uniffi_checksum_constructor_bearerdid_new() != 33593.toShort()) { + if (lib.uniffi_tbdex_uniffi_checksum_constructor_bearerdid_new() != 30823.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_tbdex_uniffi_checksum_constructor_cancel_create() != 5690.toShort()) { @@ -1965,9 +1902,6 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) { if (lib.uniffi_tbdex_uniffi_checksum_constructor_getofferingsresponsebody_new() != 63306.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_tbdex_uniffi_checksum_constructor_inmemorykeymanager_new() != 52263.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } if (lib.uniffi_tbdex_uniffi_checksum_constructor_offering_create() != 49339.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } @@ -1992,10 +1926,7 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) { if (lib.uniffi_tbdex_uniffi_checksum_constructor_orderstatus_from_json_string() != 7621.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_tbdex_uniffi_checksum_constructor_portabledid_new() != 39125.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_tbdex_uniffi_checksum_constructor_presentationdefinition_new() != 62739.toShort()) { + if (lib.uniffi_tbdex_uniffi_checksum_constructor_presentationdefinition_new() != 41313.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_tbdex_uniffi_checksum_constructor_quote_create() != 25928.toShort()) { @@ -2631,9 +2562,7 @@ public object FfiConverterTypeBalance: FfiConverter { public interface BearerDidInterface { - fun `getData`(): BearerDidData - - fun `getSigner`(`keyId`: kotlin.String): Signer + fun `getSigner`(`verificationMethodId`: kotlin.String): Signer companion object } @@ -2655,11 +2584,11 @@ open class BearerDid: Disposable, AutoCloseable, BearerDidInterface { this.pointer = null this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) } - constructor(`uri`: kotlin.String, `keyManager`: KeyManager) : + constructor(`did`: DidData, `document`: DocumentData, `keyManager`: KeyManager) : this( - uniffiRustCallWithError(Web5RustCoreException) { _status -> + uniffiRustCall() { _status -> UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_bearerdid_new( - FfiConverterString.lower(`uri`),FfiConverterTypeKeyManager.lower(`keyManager`),_status) + FfiConverterTypeDidData.lower(`did`),FfiConverterTypeDocumentData.lower(`document`),FfiConverterTypeKeyManager.lower(`keyManager`),_status) } ) @@ -2726,25 +2655,13 @@ open class BearerDid: Disposable, AutoCloseable, BearerDidInterface { } } - override fun `getData`(): BearerDidData { - return FfiConverterTypeBearerDidData.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_bearerdid_get_data( - it, _status) -} - } - ) - } - - - @Throws(Web5RustCoreException::class)override fun `getSigner`(`keyId`: kotlin.String): Signer { + @Throws(Web5Exception::class)override fun `getSigner`(`verificationMethodId`: kotlin.String): Signer { return FfiConverterTypeSigner.lift( callWithPointer { - uniffiRustCallWithError(Web5RustCoreException) { _status -> + uniffiRustCallWithError(Web5Exception) { _status -> UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_bearerdid_get_signer( - it, FfiConverterString.lower(`keyId`),_status) + it, FfiConverterString.lower(`verificationMethodId`),_status) } } ) @@ -2754,20 +2671,8 @@ open class BearerDid: Disposable, AutoCloseable, BearerDidInterface { - companion object { - - @Throws(Web5RustCoreException::class) fun `fromPortableDid`(`portableDid`: PortableDid): BearerDid { - return FfiConverterTypeBearerDid.lift( - uniffiRustCallWithError(Web5RustCoreException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_bearerdid_from_portable_did( - FfiConverterTypePortableDid.lower(`portableDid`),_status) -} - ) - } - - - } + companion object } @@ -5089,18 +4994,16 @@ public object FfiConverterTypeGetOfferingsResponseBody: FfiConverter - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_inmemorykeymanager_new( - _status) -} - ) protected val pointer: Pointer? protected val cleanable: UniffiCleaner.Cleanable @@ -5176,7 +5072,7 @@ open class InMemoryKeyManager: Disposable, AutoCloseable, InMemoryKeyManagerInte override fun run() { pointer?.let { ptr -> uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_free_inmemorykeymanager(ptr, status) + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_free_keymanager(ptr, status) } } } @@ -5184,28 +5080,16 @@ open class InMemoryKeyManager: Disposable, AutoCloseable, InMemoryKeyManagerInte fun uniffiClonePointer(): Pointer { return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_clone_inmemorykeymanager(pointer!!, status) + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_clone_keymanager(pointer!!, status) } } - override fun `getAsKeyManager`(): KeyManager { - return FfiConverterTypeKeyManager.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_inmemorykeymanager_get_as_key_manager( - it, _status) -} - } - ) - } - - - @Throws(Web5RustCoreException::class)override fun `getSigner`(`publicJwk`: JwkData): Signer { + @Throws(Web5Exception::class)override fun `getSigner`(`publicJwk`: JwkData): Signer { return FfiConverterTypeSigner.lift( callWithPointer { - uniffiRustCallWithError(Web5RustCoreException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_inmemorykeymanager_get_signer( + uniffiRustCallWithError(Web5Exception) { _status -> + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_keymanager_get_signer( it, FfiConverterTypeJwkData.lower(`publicJwk`),_status) } } @@ -5214,12 +5098,12 @@ open class InMemoryKeyManager: Disposable, AutoCloseable, InMemoryKeyManagerInte - @Throws(Web5RustCoreException::class)override fun `importPrivateJwk`(`privateKey`: JwkData): JwkData { + @Throws(Web5Exception::class)override fun `importPrivateJwk`(`privateJwk`: JwkData): JwkData { return FfiConverterTypeJwkData.lift( callWithPointer { - uniffiRustCallWithError(Web5RustCoreException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_inmemorykeymanager_import_private_jwk( - it, FfiConverterTypeJwkData.lower(`privateKey`),_status) + uniffiRustCallWithError(Web5Exception) { _status -> + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_keymanager_import_private_jwk( + it, FfiConverterTypeJwkData.lower(`privateJwk`),_status) } } ) @@ -5233,26 +5117,112 @@ open class InMemoryKeyManager: Disposable, AutoCloseable, InMemoryKeyManagerInte companion object } +// Magic number for the Rust proxy to call using the same mechanism as every other method, +// to free the callback once it's dropped by Rust. +internal const val IDX_CALLBACK_FREE = 0 +// Callback return codes +internal const val UNIFFI_CALLBACK_SUCCESS = 0 +internal const val UNIFFI_CALLBACK_ERROR = 1 +internal const val UNIFFI_CALLBACK_UNEXPECTED_ERROR = 2 -public object FfiConverterTypeInMemoryKeyManager: FfiConverter { +public abstract class FfiConverterCallbackInterface: FfiConverter { + internal val handleMap = UniffiHandleMap() - override fun lower(value: InMemoryKeyManager): Pointer { - return value.uniffiClonePointer() + internal fun drop(handle: Long) { + handleMap.remove(handle) + } + + override fun lift(value: Long): CallbackInterface { + return handleMap.get(value) + } + + override fun read(buf: ByteBuffer) = lift(buf.getLong()) + + override fun lower(value: CallbackInterface) = handleMap.insert(value) + + override fun allocationSize(value: CallbackInterface) = 8UL + + override fun write(value: CallbackInterface, buf: ByteBuffer) { + buf.putLong(lower(value)) + } +} + +// Put the implementation in an object so we don't pollute the top-level namespace +internal object uniffiCallbackInterfaceKeyManager { + internal object `getSigner`: UniffiCallbackInterfaceKeyManagerMethod0 { + override fun callback(`uniffiHandle`: Long,`publicJwk`: RustBuffer.ByValue,`uniffiOutReturn`: PointerByReference,uniffiCallStatus: UniffiRustCallStatus,) { + val uniffiObj = FfiConverterTypeKeyManager.handleMap.get(uniffiHandle) + val makeCall = { -> + uniffiObj.`getSigner`( + FfiConverterTypeJwkData.lift(`publicJwk`), + ) + } + val writeReturn = { value: Signer -> uniffiOutReturn.setValue(FfiConverterTypeSigner.lower(value)) } + uniffiTraitInterfaceCallWithError( + uniffiCallStatus, + makeCall, + writeReturn, + { e: Web5Exception -> FfiConverterTypeWeb5Error.lower(e) } + ) + } + } + internal object `importPrivateJwk`: UniffiCallbackInterfaceKeyManagerMethod1 { + override fun callback(`uniffiHandle`: Long,`privateJwk`: RustBuffer.ByValue,`uniffiOutReturn`: RustBuffer,uniffiCallStatus: UniffiRustCallStatus,) { + val uniffiObj = FfiConverterTypeKeyManager.handleMap.get(uniffiHandle) + val makeCall = { -> + uniffiObj.`importPrivateJwk`( + FfiConverterTypeJwkData.lift(`privateJwk`), + ) + } + val writeReturn = { value: JwkData -> uniffiOutReturn.setValue(FfiConverterTypeJwkData.lower(value)) } + uniffiTraitInterfaceCallWithError( + uniffiCallStatus, + makeCall, + writeReturn, + { e: Web5Exception -> FfiConverterTypeWeb5Error.lower(e) } + ) + } + } + + internal object uniffiFree: UniffiCallbackInterfaceFree { + override fun callback(handle: Long) { + FfiConverterTypeKeyManager.handleMap.remove(handle) + } + } + + internal var vtable = UniffiVTableCallbackInterfaceKeyManager.UniffiByValue( + `getSigner`, + `importPrivateJwk`, + uniffiFree, + ) + + // Registers the foreign callback with the Rust side. + // This method is generated for each callback interface. + internal fun register(lib: UniffiLib) { + lib.uniffi_tbdex_uniffi_fn_init_callback_vtable_keymanager(vtable) + } +} + +public object FfiConverterTypeKeyManager: FfiConverter { + internal val handleMap = UniffiHandleMap() + + override fun lower(value: KeyManager): Pointer { + return Pointer(handleMap.insert(value)) } - override fun lift(value: Pointer): InMemoryKeyManager { - return InMemoryKeyManager(value) + override fun lift(value: Pointer): KeyManager { + return KeyManagerImpl(value) } - override fun read(buf: ByteBuffer): InMemoryKeyManager { + 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: InMemoryKeyManager) = 8UL + override fun allocationSize(value: KeyManager) = 8UL - override fun write(value: InMemoryKeyManager, buf: ByteBuffer) { + 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))) @@ -5358,14 +5328,20 @@ public object FfiConverterTypeInMemoryKeyManager: FfiConverter uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_free_keymanager(ptr, status) + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_free_offering(ptr, status) } } } @@ -5442,17 +5418,17 @@ open class KeyManagerImpl: Disposable, AutoCloseable, KeyManager { fun uniffiClonePointer(): Pointer { return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_clone_keymanager(pointer!!, status) + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_clone_offering(pointer!!, status) } } - @Throws(Web5RustCoreException::class)override fun `getSigner`(`publicJwk`: JwkData): Signer { - return FfiConverterTypeSigner.lift( + @Throws(TbdexSdkException::class)override fun `getData`(): OfferingData { + return FfiConverterTypeOfferingData.lift( callWithPointer { - uniffiRustCallWithError(Web5RustCoreException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_keymanager_get_signer( - it, FfiConverterTypeJwkData.lower(`publicJwk`),_status) + uniffiRustCallWithError(TbdexSdkException) { _status -> + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_offering_get_data( + it, _status) } } ) @@ -5460,668 +5436,62 @@ open class KeyManagerImpl: Disposable, AutoCloseable, KeyManager { - + @Throws(TbdexSdkException::class)override fun `sign`(`bearerDid`: BearerDid) + = + callWithPointer { + uniffiRustCallWithError(TbdexSdkException) { _status -> + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_offering_sign( + it, FfiConverterTypeBearerDid.lower(`bearerDid`),_status) +} + } - companion object + + @Throws(TbdexSdkException::class)override fun `toJsonString`(): kotlin.String { + return FfiConverterString.lift( + callWithPointer { + uniffiRustCallWithError(TbdexSdkException) { _status -> + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_offering_to_json_string( + it, _status) } -// Magic number for the Rust proxy to call using the same mechanism as every other method, -// to free the callback once it's dropped by Rust. -internal const val IDX_CALLBACK_FREE = 0 -// Callback return codes -internal const val UNIFFI_CALLBACK_SUCCESS = 0 -internal const val UNIFFI_CALLBACK_ERROR = 1 -internal const val UNIFFI_CALLBACK_UNEXPECTED_ERROR = 2 - -public abstract class FfiConverterCallbackInterface: FfiConverter { - internal val handleMap = UniffiHandleMap() - - internal fun drop(handle: Long) { - handleMap.remove(handle) } - - override fun lift(value: Long): CallbackInterface { - return handleMap.get(value) + ) } + - override fun read(buf: ByteBuffer) = lift(buf.getLong()) - - override fun lower(value: CallbackInterface) = handleMap.insert(value) + + @Throws(TbdexSdkException::class)override fun `verify`() + = + callWithPointer { + uniffiRustCallWithError(TbdexSdkException) { _status -> + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_offering_verify( + it, _status) +} + } + + - override fun allocationSize(value: CallbackInterface) = 8UL - - override fun write(value: CallbackInterface, buf: ByteBuffer) { - buf.putLong(lower(value)) - } -} - -// Put the implementation in an object so we don't pollute the top-level namespace -internal object uniffiCallbackInterfaceKeyManager { - internal object `getSigner`: UniffiCallbackInterfaceKeyManagerMethod0 { - override fun callback(`uniffiHandle`: Long,`publicJwk`: RustBuffer.ByValue,`uniffiOutReturn`: PointerByReference,uniffiCallStatus: UniffiRustCallStatus,) { - val uniffiObj = FfiConverterTypeKeyManager.handleMap.get(uniffiHandle) - val makeCall = { -> - uniffiObj.`getSigner`( - FfiConverterTypeJwkData.lift(`publicJwk`), - ) - } - val writeReturn = { value: Signer -> uniffiOutReturn.setValue(FfiConverterTypeSigner.lower(value)) } - uniffiTraitInterfaceCallWithError( - uniffiCallStatus, - makeCall, - writeReturn, - { e: Web5RustCoreException -> FfiConverterTypeWeb5RustCoreError.lower(e) } - ) - } - } - - internal object uniffiFree: UniffiCallbackInterfaceFree { - override fun callback(handle: Long) { - FfiConverterTypeKeyManager.handleMap.remove(handle) - } - } - - internal var vtable = UniffiVTableCallbackInterfaceKeyManager.UniffiByValue( - `getSigner`, - uniffiFree, - ) - - // Registers the foreign callback with the Rust side. - // This method is generated for each callback interface. - internal fun register(lib: UniffiLib) { - lib.uniffi_tbdex_uniffi_fn_init_callback_vtable_keymanager(vtable) - } -} - -public object FfiConverterTypeKeyManager: FfiConverter { - internal val handleMap = UniffiHandleMap() - - override fun lower(value: KeyManager): Pointer { - return Pointer(handleMap.insert(value)) - } - - override fun lift(value: Pointer): KeyManager { - return KeyManagerImpl(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 OfferingInterface { - - fun `getData`(): OfferingData - - fun `sign`(`bearerDid`: BearerDid) - - fun `toJsonString`(): kotlin.String - - fun `verify`() - - companion object -} - -open class Offering: Disposable, AutoCloseable, OfferingInterface { - - 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_tbdex_uniffi_fn_free_offering(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_clone_offering(pointer!!, status) - } - } - - - @Throws(TbdexSdkException::class)override fun `getData`(): OfferingData { - return FfiConverterTypeOfferingData.lift( - callWithPointer { - uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_offering_get_data( - it, _status) -} - } - ) - } - - - - @Throws(TbdexSdkException::class)override fun `sign`(`bearerDid`: BearerDid) - = - callWithPointer { - uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_offering_sign( - it, FfiConverterTypeBearerDid.lower(`bearerDid`),_status) -} - } - - - - - @Throws(TbdexSdkException::class)override fun `toJsonString`(): kotlin.String { - return FfiConverterString.lift( - callWithPointer { - uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_offering_to_json_string( - it, _status) -} - } - ) - } - - - - @Throws(TbdexSdkException::class)override fun `verify`() - = - callWithPointer { - uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_offering_verify( - it, _status) -} - } - - - - - - - companion object { - - @Throws(TbdexSdkException::class) fun `create`(`from`: kotlin.String, `jsonSerializedData`: kotlin.String, `protocol`: kotlin.String?): Offering { - return FfiConverterTypeOffering.lift( - uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_offering_create( - FfiConverterString.lower(`from`),FfiConverterString.lower(`jsonSerializedData`),FfiConverterOptionalString.lower(`protocol`),_status) -} - ) - } - - - - @Throws(TbdexSdkException::class) fun `fromJsonString`(`json`: kotlin.String): Offering { - return FfiConverterTypeOffering.lift( - uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_offering_from_json_string( - FfiConverterString.lower(`json`),_status) -} - ) - } - - - - } - -} - -public object FfiConverterTypeOffering: FfiConverter { - - override fun lower(value: Offering): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): Offering { - return Offering(value) - } - - override fun read(buf: ByteBuffer): Offering { - // 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: Offering) = 8UL - - override fun write(value: Offering, 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 OrderInterface { - - fun `getData`(): OrderData - - fun `sign`(`bearerDid`: BearerDid) - - fun `toJsonString`(): kotlin.String - - fun `verify`() - - companion object -} - -open class Order: Disposable, AutoCloseable, OrderInterface { - - 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_tbdex_uniffi_fn_free_order(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_clone_order(pointer!!, status) - } - } - - - @Throws(TbdexSdkException::class)override fun `getData`(): OrderData { - return FfiConverterTypeOrderData.lift( - callWithPointer { - uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_order_get_data( - it, _status) -} - } - ) - } - - - - @Throws(TbdexSdkException::class)override fun `sign`(`bearerDid`: BearerDid) - = - callWithPointer { - uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_order_sign( - it, FfiConverterTypeBearerDid.lower(`bearerDid`),_status) -} - } - - - - - @Throws(TbdexSdkException::class)override fun `toJsonString`(): kotlin.String { - return FfiConverterString.lift( - callWithPointer { - uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_order_to_json_string( - it, _status) -} - } - ) - } - - - - @Throws(TbdexSdkException::class)override fun `verify`() - = - callWithPointer { - uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_order_verify( - it, _status) -} - } - - - - + companion object { - @Throws(TbdexSdkException::class) fun `create`(`to`: kotlin.String, `from`: kotlin.String, `exchangeId`: kotlin.String, `protocol`: kotlin.String?, `externalId`: kotlin.String?): Order { - return FfiConverterTypeOrder.lift( + @Throws(TbdexSdkException::class) fun `create`(`from`: kotlin.String, `jsonSerializedData`: kotlin.String, `protocol`: kotlin.String?): Offering { + return FfiConverterTypeOffering.lift( uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_order_create( - FfiConverterString.lower(`to`),FfiConverterString.lower(`from`),FfiConverterString.lower(`exchangeId`),FfiConverterOptionalString.lower(`protocol`),FfiConverterOptionalString.lower(`externalId`),_status) + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_offering_create( + FfiConverterString.lower(`from`),FfiConverterString.lower(`jsonSerializedData`),FfiConverterOptionalString.lower(`protocol`),_status) } ) } - @Throws(TbdexSdkException::class) fun `fromJsonString`(`json`: kotlin.String): Order { - return FfiConverterTypeOrder.lift( + @Throws(TbdexSdkException::class) fun `fromJsonString`(`json`: kotlin.String): Offering { + return FfiConverterTypeOffering.lift( uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_order_from_json_string( + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_offering_from_json_string( FfiConverterString.lower(`json`),_status) } ) @@ -6133,25 +5503,25 @@ open class Order: Disposable, AutoCloseable, OrderInterface { } -public object FfiConverterTypeOrder: FfiConverter { +public object FfiConverterTypeOffering: FfiConverter { - override fun lower(value: Order): Pointer { + override fun lower(value: Offering): Pointer { return value.uniffiClonePointer() } - override fun lift(value: Pointer): Order { - return Order(value) + override fun lift(value: Pointer): Offering { + return Offering(value) } - override fun read(buf: ByteBuffer): Order { + override fun read(buf: ByteBuffer): Offering { // 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: Order) = 8UL + override fun allocationSize(value: Offering) = 8UL - override fun write(value: Order, buf: ByteBuffer) { + override fun write(value: Offering, 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))) @@ -6257,9 +5627,9 @@ public object FfiConverterTypeOrder: FfiConverter { // -public interface OrderInstructionsInterface { +public interface OrderInterface { - fun `getData`(): OrderInstructionsData + fun `getData`(): OrderData fun `sign`(`bearerDid`: BearerDid) @@ -6270,7 +5640,7 @@ public interface OrderInstructionsInterface { companion object } -open class OrderInstructions: Disposable, AutoCloseable, OrderInstructionsInterface { +open class Order: Disposable, AutoCloseable, OrderInterface { constructor(pointer: Pointer) { this.pointer = pointer @@ -6339,7 +5709,7 @@ open class OrderInstructions: Disposable, AutoCloseable, OrderInstructionsInterf override fun run() { pointer?.let { ptr -> uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_free_orderinstructions(ptr, status) + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_free_order(ptr, status) } } } @@ -6347,16 +5717,16 @@ open class OrderInstructions: Disposable, AutoCloseable, OrderInstructionsInterf fun uniffiClonePointer(): Pointer { return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_clone_orderinstructions(pointer!!, status) + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_clone_order(pointer!!, status) } } - @Throws(TbdexSdkException::class)override fun `getData`(): OrderInstructionsData { - return FfiConverterTypeOrderInstructionsData.lift( + @Throws(TbdexSdkException::class)override fun `getData`(): OrderData { + return FfiConverterTypeOrderData.lift( callWithPointer { uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderinstructions_get_data( + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_order_get_data( it, _status) } } @@ -6369,7 +5739,7 @@ open class OrderInstructions: Disposable, AutoCloseable, OrderInstructionsInterf = callWithPointer { uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderinstructions_sign( + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_order_sign( it, FfiConverterTypeBearerDid.lower(`bearerDid`),_status) } } @@ -6381,7 +5751,7 @@ open class OrderInstructions: Disposable, AutoCloseable, OrderInstructionsInterf return FfiConverterString.lift( callWithPointer { uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderinstructions_to_json_string( + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_order_to_json_string( it, _status) } } @@ -6394,7 +5764,7 @@ open class OrderInstructions: Disposable, AutoCloseable, OrderInstructionsInterf = callWithPointer { uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderinstructions_verify( + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_order_verify( it, _status) } } @@ -6406,21 +5776,21 @@ open class OrderInstructions: Disposable, AutoCloseable, OrderInstructionsInterf companion object { - @Throws(TbdexSdkException::class) fun `create`(`to`: kotlin.String, `from`: kotlin.String, `exchangeId`: kotlin.String, `data`: OrderInstructionsDataData, `protocol`: kotlin.String?, `externalId`: kotlin.String?): OrderInstructions { - return FfiConverterTypeOrderInstructions.lift( + @Throws(TbdexSdkException::class) fun `create`(`to`: kotlin.String, `from`: kotlin.String, `exchangeId`: kotlin.String, `protocol`: kotlin.String?, `externalId`: kotlin.String?): Order { + return FfiConverterTypeOrder.lift( uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_orderinstructions_create( - FfiConverterString.lower(`to`),FfiConverterString.lower(`from`),FfiConverterString.lower(`exchangeId`),FfiConverterTypeOrderInstructionsDataData.lower(`data`),FfiConverterOptionalString.lower(`protocol`),FfiConverterOptionalString.lower(`externalId`),_status) + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_order_create( + FfiConverterString.lower(`to`),FfiConverterString.lower(`from`),FfiConverterString.lower(`exchangeId`),FfiConverterOptionalString.lower(`protocol`),FfiConverterOptionalString.lower(`externalId`),_status) } ) } - @Throws(TbdexSdkException::class) fun `fromJsonString`(`json`: kotlin.String): OrderInstructions { - return FfiConverterTypeOrderInstructions.lift( + @Throws(TbdexSdkException::class) fun `fromJsonString`(`json`: kotlin.String): Order { + return FfiConverterTypeOrder.lift( uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_orderinstructions_from_json_string( + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_order_from_json_string( FfiConverterString.lower(`json`),_status) } ) @@ -6432,25 +5802,25 @@ open class OrderInstructions: Disposable, AutoCloseable, OrderInstructionsInterf } -public object FfiConverterTypeOrderInstructions: FfiConverter { +public object FfiConverterTypeOrder: FfiConverter { - override fun lower(value: OrderInstructions): Pointer { + override fun lower(value: Order): Pointer { return value.uniffiClonePointer() } - override fun lift(value: Pointer): OrderInstructions { - return OrderInstructions(value) + override fun lift(value: Pointer): Order { + return Order(value) } - override fun read(buf: ByteBuffer): OrderInstructions { + override fun read(buf: ByteBuffer): Order { // 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: OrderInstructions) = 8UL + override fun allocationSize(value: Order) = 8UL - override fun write(value: OrderInstructions, buf: ByteBuffer) { + override fun write(value: Order, 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))) @@ -6556,9 +5926,9 @@ public object FfiConverterTypeOrderInstructions: FfiConverter uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_free_orderstatus(ptr, status) + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_free_orderinstructions(ptr, status) } } } @@ -6646,16 +6016,16 @@ open class OrderStatus: Disposable, AutoCloseable, OrderStatusInterface { fun uniffiClonePointer(): Pointer { return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_clone_orderstatus(pointer!!, status) + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_clone_orderinstructions(pointer!!, status) } } - @Throws(TbdexSdkException::class)override fun `getData`(): OrderStatusData { - return FfiConverterTypeOrderStatusData.lift( + @Throws(TbdexSdkException::class)override fun `getData`(): OrderInstructionsData { + return FfiConverterTypeOrderInstructionsData.lift( callWithPointer { uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderstatus_get_data( + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderinstructions_get_data( it, _status) } } @@ -6668,7 +6038,7 @@ open class OrderStatus: Disposable, AutoCloseable, OrderStatusInterface { = callWithPointer { uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderstatus_sign( + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderinstructions_sign( it, FfiConverterTypeBearerDid.lower(`bearerDid`),_status) } } @@ -6680,7 +6050,7 @@ open class OrderStatus: Disposable, AutoCloseable, OrderStatusInterface { return FfiConverterString.lift( callWithPointer { uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderstatus_to_json_string( + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderinstructions_to_json_string( it, _status) } } @@ -6693,7 +6063,7 @@ open class OrderStatus: Disposable, AutoCloseable, OrderStatusInterface { = callWithPointer { uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderstatus_verify( + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderinstructions_verify( it, _status) } } @@ -6705,21 +6075,21 @@ open class OrderStatus: Disposable, AutoCloseable, OrderStatusInterface { companion object { - @Throws(TbdexSdkException::class) fun `create`(`to`: kotlin.String, `from`: kotlin.String, `exchangeId`: kotlin.String, `data`: OrderStatusDataData, `protocol`: kotlin.String?, `externalId`: kotlin.String?): OrderStatus { - return FfiConverterTypeOrderStatus.lift( + @Throws(TbdexSdkException::class) fun `create`(`to`: kotlin.String, `from`: kotlin.String, `exchangeId`: kotlin.String, `data`: OrderInstructionsDataData, `protocol`: kotlin.String?, `externalId`: kotlin.String?): OrderInstructions { + return FfiConverterTypeOrderInstructions.lift( uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_orderstatus_create( - FfiConverterString.lower(`to`),FfiConverterString.lower(`from`),FfiConverterString.lower(`exchangeId`),FfiConverterTypeOrderStatusDataData.lower(`data`),FfiConverterOptionalString.lower(`protocol`),FfiConverterOptionalString.lower(`externalId`),_status) + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_orderinstructions_create( + FfiConverterString.lower(`to`),FfiConverterString.lower(`from`),FfiConverterString.lower(`exchangeId`),FfiConverterTypeOrderInstructionsDataData.lower(`data`),FfiConverterOptionalString.lower(`protocol`),FfiConverterOptionalString.lower(`externalId`),_status) } ) } - @Throws(TbdexSdkException::class) fun `fromJsonString`(`json`: kotlin.String): OrderStatus { - return FfiConverterTypeOrderStatus.lift( + @Throws(TbdexSdkException::class) fun `fromJsonString`(`json`: kotlin.String): OrderInstructions { + return FfiConverterTypeOrderInstructions.lift( uniffiRustCallWithError(TbdexSdkException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_orderstatus_from_json_string( + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_orderinstructions_from_json_string( FfiConverterString.lower(`json`),_status) } ) @@ -6731,25 +6101,25 @@ open class OrderStatus: Disposable, AutoCloseable, OrderStatusInterface { } -public object FfiConverterTypeOrderStatus: FfiConverter { +public object FfiConverterTypeOrderInstructions: FfiConverter { - override fun lower(value: OrderStatus): Pointer { + override fun lower(value: OrderInstructions): Pointer { return value.uniffiClonePointer() } - override fun lift(value: Pointer): OrderStatus { - return OrderStatus(value) + override fun lift(value: Pointer): OrderInstructions { + return OrderInstructions(value) } - override fun read(buf: ByteBuffer): OrderStatus { + override fun read(buf: ByteBuffer): OrderInstructions { // 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: OrderStatus) = 8UL + override fun allocationSize(value: OrderInstructions) = 8UL - override fun write(value: OrderStatus, buf: ByteBuffer) { + override fun write(value: OrderInstructions, 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))) @@ -6855,14 +6225,20 @@ public object FfiConverterTypeOrderStatus: FfiConverter { // -public interface PortableDidInterface { +public interface OrderStatusInterface { + + fun `getData`(): OrderStatusData + + fun `sign`(`bearerDid`: BearerDid) + + fun `toJsonString`(): kotlin.String - fun `getData`(): PortableDidData + fun `verify`() companion object } -open class PortableDid: Disposable, AutoCloseable, PortableDidInterface { +open class OrderStatus: Disposable, AutoCloseable, OrderStatusInterface { constructor(pointer: Pointer) { this.pointer = pointer @@ -6879,13 +6255,6 @@ open class PortableDid: Disposable, AutoCloseable, PortableDidInterface { this.pointer = null this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) } - constructor(`json`: kotlin.String) : - this( - uniffiRustCallWithError(Web5RustCoreException) { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_portabledid_new( - FfiConverterString.lower(`json`),_status) -} - ) protected val pointer: Pointer? protected val cleanable: UniffiCleaner.Cleanable @@ -6938,7 +6307,7 @@ open class PortableDid: Disposable, AutoCloseable, PortableDidInterface { override fun run() { pointer?.let { ptr -> uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_free_portabledid(ptr, status) + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_free_orderstatus(ptr, status) } } } @@ -6946,15 +6315,41 @@ open class PortableDid: Disposable, AutoCloseable, PortableDidInterface { fun uniffiClonePointer(): Pointer { return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_clone_portabledid(pointer!!, status) + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_clone_orderstatus(pointer!!, status) } } - override fun `getData`(): PortableDidData { - return FfiConverterTypePortableDidData.lift( + + @Throws(TbdexSdkException::class)override fun `getData`(): OrderStatusData { + return FfiConverterTypeOrderStatusData.lift( callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_portabledid_get_data( + uniffiRustCallWithError(TbdexSdkException) { _status -> + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderstatus_get_data( + it, _status) +} + } + ) + } + + + + @Throws(TbdexSdkException::class)override fun `sign`(`bearerDid`: BearerDid) + = + callWithPointer { + uniffiRustCallWithError(TbdexSdkException) { _status -> + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderstatus_sign( + it, FfiConverterTypeBearerDid.lower(`bearerDid`),_status) +} + } + + + + + @Throws(TbdexSdkException::class)override fun `toJsonString`(): kotlin.String { + return FfiConverterString.lift( + callWithPointer { + uniffiRustCallWithError(TbdexSdkException) { _status -> + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderstatus_to_json_string( it, _status) } } @@ -6963,32 +6358,67 @@ open class PortableDid: Disposable, AutoCloseable, PortableDidInterface { + @Throws(TbdexSdkException::class)override fun `verify`() + = + callWithPointer { + uniffiRustCallWithError(TbdexSdkException) { _status -> + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_orderstatus_verify( + it, _status) +} + } + + + + + companion object { + + @Throws(TbdexSdkException::class) fun `create`(`to`: kotlin.String, `from`: kotlin.String, `exchangeId`: kotlin.String, `data`: OrderStatusDataData, `protocol`: kotlin.String?, `externalId`: kotlin.String?): OrderStatus { + return FfiConverterTypeOrderStatus.lift( + uniffiRustCallWithError(TbdexSdkException) { _status -> + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_orderstatus_create( + FfiConverterString.lower(`to`),FfiConverterString.lower(`from`),FfiConverterString.lower(`exchangeId`),FfiConverterTypeOrderStatusDataData.lower(`data`),FfiConverterOptionalString.lower(`protocol`),FfiConverterOptionalString.lower(`externalId`),_status) +} + ) + } - companion object + + + @Throws(TbdexSdkException::class) fun `fromJsonString`(`json`: kotlin.String): OrderStatus { + return FfiConverterTypeOrderStatus.lift( + uniffiRustCallWithError(TbdexSdkException) { _status -> + UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_orderstatus_from_json_string( + FfiConverterString.lower(`json`),_status) +} + ) + } + + + + } } -public object FfiConverterTypePortableDid: FfiConverter { +public object FfiConverterTypeOrderStatus: FfiConverter { - override fun lower(value: PortableDid): Pointer { + override fun lower(value: OrderStatus): Pointer { return value.uniffiClonePointer() } - override fun lift(value: Pointer): PortableDid { - return PortableDid(value) + override fun lift(value: Pointer): OrderStatus { + return OrderStatus(value) } - override fun read(buf: ByteBuffer): PortableDid { + override fun read(buf: ByteBuffer): OrderStatus { // 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: PortableDid) = 8UL + override fun allocationSize(value: OrderStatus) = 8UL - override fun write(value: PortableDid, buf: ByteBuffer) { + override fun write(value: OrderStatus, 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))) @@ -7122,7 +6552,7 @@ open class PresentationDefinition: Disposable, AutoCloseable, PresentationDefini } constructor(`jsonSerializedPresentationDefinition`: kotlin.String) : this( - uniffiRustCallWithError(Web5RustCoreException) { _status -> + uniffiRustCallWithError(Web5Exception) { _status -> UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_constructor_presentationdefinition_new( FfiConverterString.lower(`jsonSerializedPresentationDefinition`),_status) } @@ -7192,10 +6622,10 @@ open class PresentationDefinition: Disposable, AutoCloseable, PresentationDefini } - @Throws(Web5RustCoreException::class)override fun `getJsonSerializedPresentationDefinition`(): kotlin.String { + @Throws(Web5Exception::class)override fun `getJsonSerializedPresentationDefinition`(): kotlin.String { return FfiConverterString.lift( callWithPointer { - uniffiRustCallWithError(Web5RustCoreException) { _status -> + uniffiRustCallWithError(Web5Exception) { _status -> UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_presentationdefinition_get_json_serialized_presentation_definition( it, _status) } @@ -7205,10 +6635,10 @@ open class PresentationDefinition: Disposable, AutoCloseable, PresentationDefini - @Throws(Web5RustCoreException::class)override fun `selectCredentials`(`vcJwts`: List): List { + @Throws(Web5Exception::class)override fun `selectCredentials`(`vcJwts`: List): List { return FfiConverterSequenceString.lift( callWithPointer { - uniffiRustCallWithError(Web5RustCoreException) { _status -> + uniffiRustCallWithError(Web5Exception) { _status -> UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_presentationdefinition_select_credentials( it, FfiConverterSequenceString.lower(`vcJwts`),_status) } @@ -8344,10 +7774,10 @@ open class SignerImpl: Disposable, AutoCloseable, Signer { } - @Throws(Web5RustCoreException::class)override fun `sign`(`payload`: kotlin.ByteArray): kotlin.ByteArray { + @Throws(Web5Exception::class)override fun `sign`(`payload`: kotlin.ByteArray): kotlin.ByteArray { return FfiConverterByteArray.lift( callWithPointer { - uniffiRustCallWithError(Web5RustCoreException) { _status -> + uniffiRustCallWithError(Web5Exception) { _status -> UniffiLib.INSTANCE.uniffi_tbdex_uniffi_fn_method_signer_sign( it, FfiConverterByteArray.lower(`payload`),_status) } @@ -8380,7 +7810,7 @@ internal object uniffiCallbackInterfaceSigner { uniffiCallStatus, makeCall, writeReturn, - { e: Web5RustCoreException -> FfiConverterTypeWeb5RustCoreError.lower(e) } + { e: Web5Exception -> FfiConverterTypeWeb5Error.lower(e) } ) } } @@ -8759,48 +8189,6 @@ public object FfiConverterTypeBalanceDataData: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): BearerDidData { - return BearerDidData( - FfiConverterTypeDidData.read(buf), - FfiConverterTypeDocumentData.read(buf), - FfiConverterTypeKeyManager.read(buf), - ) - } - - override fun allocationSize(value: BearerDidData) = ( - FfiConverterTypeDidData.allocationSize(value.`did`) + - FfiConverterTypeDocumentData.allocationSize(value.`document`) + - FfiConverterTypeKeyManager.allocationSize(value.`keyManager`) - ) - - override fun write(value: BearerDidData, buf: ByteBuffer) { - FfiConverterTypeDidData.write(value.`did`, buf) - FfiConverterTypeDocumentData.write(value.`document`, buf) - FfiConverterTypeKeyManager.write(value.`keyManager`, buf) - } -} - - - data class CancelData ( var `metadata`: MessageMetadataData, var `data`: CancelDataData, @@ -9714,39 +9102,6 @@ public object FfiConverterTypePaymentInstructionData: FfiConverterRustBuffer -) { - - companion object -} - -public object FfiConverterTypePortableDidData: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): PortableDidData { - return PortableDidData( - FfiConverterString.read(buf), - FfiConverterTypeDocumentData.read(buf), - FfiConverterSequenceTypeJwkData.read(buf), - ) - } - - override fun allocationSize(value: PortableDidData) = ( - FfiConverterString.allocationSize(value.`didUri`) + - FfiConverterTypeDocumentData.allocationSize(value.`document`) + - FfiConverterSequenceTypeJwkData.allocationSize(value.`privateJwks`) - ) - - override fun write(value: PortableDidData, buf: ByteBuffer) { - FfiConverterString.write(value.`didUri`, buf) - FfiConverterTypeDocumentData.write(value.`document`, buf) - FfiConverterSequenceTypeJwkData.write(value.`privateJwks`, buf) - } -} - - - data class QuoteData ( var `metadata`: MessageMetadataData, var `data`: QuoteDataData, @@ -10229,35 +9584,32 @@ public object FfiConverterTypeTbdexSdkError : FfiConverterRustBuffer { - override fun lift(error_buf: RustBuffer.ByValue): Web5RustCoreException = FfiConverterTypeWeb5RustCoreError.lift(error_buf) + companion object ErrorHandler : UniffiRustCallStatusErrorHandler { + override fun lift(error_buf: RustBuffer.ByValue): Web5Exception = FfiConverterTypeWeb5Error.lift(error_buf) } } -public object FfiConverterTypeWeb5RustCoreError : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): Web5RustCoreException { +public object FfiConverterTypeWeb5Error : FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): Web5Exception { return when(buf.getInt()) { - 1 -> Web5RustCoreException.Exception( - FfiConverterString.read(buf), + 1 -> Web5Exception.Exception( FfiConverterString.read(buf), FfiConverterString.read(buf), ) @@ -10265,23 +9617,21 @@ public object FfiConverterTypeWeb5RustCoreError : FfiConverterRustBuffer ( + is Web5Exception.Exception -> ( // Add the size for the Int that specifies the variant plus the size needed for all fields 4UL - + FfiConverterString.allocationSize(value.`type`) + FfiConverterString.allocationSize(value.`variant`) + FfiConverterString.allocationSize(value.`msg`) ) } } - override fun write(value: Web5RustCoreException, buf: ByteBuffer) { + override fun write(value: Web5Exception, buf: ByteBuffer) { when(value) { - is Web5RustCoreException.Exception -> { + is Web5Exception.Exception -> { buf.putInt(1) - FfiConverterString.write(value.`type`, buf) FfiConverterString.write(value.`variant`, buf) FfiConverterString.write(value.`msg`, buf) Unit @@ -10850,31 +10200,6 @@ public object FfiConverterSequenceTypeGetExchangeResponseBodyDataSerializedMessa -public object FfiConverterSequenceTypeJwkData: FfiConverterRustBuffer> { - override fun read(buf: ByteBuffer): List { - val len = buf.getInt() - return List(len) { - FfiConverterTypeJwkData.read(buf) - } - } - - override fun allocationSize(value: List): ULong { - val sizeForLength = 4UL - val sizeForItems = value.map { FfiConverterTypeJwkData.allocationSize(it) }.sum() - return sizeForLength + sizeForItems - } - - override fun write(value: List, buf: ByteBuffer) { - buf.putInt(value.size) - value.iterator().forEach { - FfiConverterTypeJwkData.write(it, buf) - } - } -} - - - - public object FfiConverterSequenceTypeServiceData: FfiConverterRustBuffer> { override fun read(buf: ByteBuffer): List { val len = buf.getInt() diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/rust/Web5.kt b/bound/kt/src/main/kotlin/tbdex/sdk/rust/Web5.kt new file mode 100644 index 00000000..e16fc8b6 --- /dev/null +++ b/bound/kt/src/main/kotlin/tbdex/sdk/rust/Web5.kt @@ -0,0 +1,109 @@ +package tbdex.sdk.rust + +import web5.sdk.crypto.keys.Jwk +import web5.sdk.crypto.keys.KeyManager +import web5.sdk.crypto.signers.Signer +import web5.sdk.dids.* +import tbdex.sdk.rust.BearerDid as RustCoreBearerDid +import tbdex.sdk.rust.DidData as RustCoreDid +import tbdex.sdk.rust.DocumentData as RustCoreDocument +import tbdex.sdk.rust.KeyManager as RustCoreKeyManager +import tbdex.sdk.rust.VerificationMethodData as RustCoreVerificationMethod +import tbdex.sdk.rust.JwkData as RustCoreJwk +import tbdex.sdk.rust.ServiceData as RustCoreService +import tbdex.sdk.rust.Signer as RustCoreSigner + +internal fun RustCoreDid.Companion.fromWeb5(did: Did): RustCoreDid { + return RustCoreDid( + did.uri, + did.url, + did.method, + did.id, + did.params, + did.path, + did.query, + did.fragment + ) +} + +internal fun RustCoreDocument.Companion.fromWeb5(document: Document): RustCoreDocument { + return RustCoreDocument( + document.id, + document.context, + document.controller, + document.alsoKnownAs, + document.verificationMethod.map { RustCoreVerificationMethod.fromWeb5(it) }, + document.authentication, + document.assertionMethod, + document.keyAgreement, + document.capabilityInvocation, + document.capabilityDelegation, + document.service?.map { RustCoreService.fromWeb5(it) }, + ) +} + +internal fun RustCoreVerificationMethod.Companion.fromWeb5(verificationMethod: VerificationMethod): RustCoreVerificationMethod { + return RustCoreVerificationMethod( + verificationMethod.id, + verificationMethod.type, + verificationMethod.controller, + RustCoreJwk.fromWeb5(verificationMethod.publicKeyJwk) + ) +} + +internal fun RustCoreJwk.Companion.fromWeb5(jwk: Jwk): RustCoreJwk { + return RustCoreJwk( + jwk.alg, + jwk.kty, + jwk.crv, + jwk.d, + jwk.x, + jwk.y + ) +} + +internal fun RustCoreService.Companion.fromWeb5(service: Service): RustCoreService { + return RustCoreService( + service.id, + service.type, + service.serviceEndpoint + ) +} + +internal fun RustCoreJwk.toWeb5(): Jwk { + return Jwk( + this.alg, + this.kty, + this.crv, + this.x, + this.y, + this.d, + ) +} + +internal class ToInnerSigner(private val signer: Signer) : RustCoreSigner { + override fun sign(payload: ByteArray): ByteArray { + return signer.sign(payload) + } +} + +internal class ToInnerKeyManager(private val keyManager: KeyManager) : RustCoreKeyManager { + override fun importPrivateJwk(privateJwk: RustCoreJwk): RustCoreJwk { + val jwk = keyManager.importPrivateJwk(privateJwk.toWeb5()) + return RustCoreJwk.fromWeb5(jwk) + } + + override fun getSigner(publicJwk: RustCoreJwk): RustCoreSigner { + val signer = keyManager.getSigner(publicJwk.toWeb5()) + val innerSigner = ToInnerSigner(signer) + return innerSigner + } +} + +internal fun RustCoreBearerDid.Companion.fromWeb5(bearerDid: BearerDid): RustCoreBearerDid { + val did = RustCoreDid.fromWeb5(bearerDid.did) + val document = RustCoreDocument.fromWeb5(bearerDid.document) + val keyManager = ToInnerKeyManager(bearerDid.keyManager) + + return RustCoreBearerDid(did, document, keyManager) +} \ No newline at end of file diff --git a/bound/kt/src/main/kotlin/web5/sdk/crypto/keys/InMemoryKeyManager.kt b/bound/kt/src/main/kotlin/web5/sdk/crypto/keys/InMemoryKeyManager.kt deleted file mode 100644 index b4056435..00000000 --- a/bound/kt/src/main/kotlin/web5/sdk/crypto/keys/InMemoryKeyManager.kt +++ /dev/null @@ -1,29 +0,0 @@ -package web5.sdk.crypto.keys - -import web5.sdk.crypto.signers.Signer -import web5.sdk.crypto.signers.ToOuterSigner -import tbdex.sdk.rust.InMemoryKeyManager as RustCoreInMemoryKeyManager -import tbdex.sdk.rust.KeyManager as RustCoreKeyManager - -internal class InMemoryKeyManager : KeyManager { - private val rustCoreInMemoryKeyManager = RustCoreInMemoryKeyManager() - - constructor(privateJwks: List) { - privateJwks.forEach { - this.rustCoreInMemoryKeyManager.importPrivateJwk(it) - } - } - - override fun getSigner(publicJwk: Jwk): Signer { - val innerSigner = this.rustCoreInMemoryKeyManager.getSigner(publicJwk) - return ToOuterSigner(innerSigner) - } - - override fun getRustCoreKeyManager(): RustCoreKeyManager { - return this.rustCoreInMemoryKeyManager.getAsKeyManager() - } - - fun importPrivateJwk(privateJwk: Jwk): Jwk { - return this.rustCoreInMemoryKeyManager.importPrivateJwk(privateJwk) - } -} \ No newline at end of file diff --git a/bound/kt/src/main/kotlin/web5/sdk/crypto/keys/KeyManager.kt b/bound/kt/src/main/kotlin/web5/sdk/crypto/keys/KeyManager.kt deleted file mode 100644 index fb2add6b..00000000 --- a/bound/kt/src/main/kotlin/web5/sdk/crypto/keys/KeyManager.kt +++ /dev/null @@ -1,23 +0,0 @@ -package web5.sdk.crypto.keys - -import web5.sdk.crypto.signers.Signer -import web5.sdk.crypto.signers.ToOuterSigner -import tbdex.sdk.rust.JwkData as RustCoreJwk -import tbdex.sdk.rust.KeyManager as RustCoreKeyManager - -internal typealias Jwk = RustCoreJwk - -interface KeyManager { - fun getSigner(publicJwk: Jwk): Signer - fun getRustCoreKeyManager(): RustCoreKeyManager -} - -internal class ToOuterKeyManager(private val innerKeyManager: RustCoreKeyManager): KeyManager { - override fun getSigner(publicJwk: Jwk): Signer { - return ToOuterSigner(innerKeyManager.getSigner(publicJwk)) - } - - override fun getRustCoreKeyManager(): RustCoreKeyManager { - return this.innerKeyManager - } -} \ No newline at end of file diff --git a/bound/kt/src/main/kotlin/web5/sdk/crypto/signers/Signer.kt b/bound/kt/src/main/kotlin/web5/sdk/crypto/signers/Signer.kt deleted file mode 100644 index cae8dc35..00000000 --- a/bound/kt/src/main/kotlin/web5/sdk/crypto/signers/Signer.kt +++ /dev/null @@ -1,19 +0,0 @@ -package web5.sdk.crypto.signers - -import tbdex.sdk.rust.Signer as RustCoreSigner - -interface Signer { - fun sign(payload: ByteArray): ByteArray -} - -internal class ToOuterSigner : Signer { - private val rustCoreSigner: RustCoreSigner - - constructor(rustCoreSigner: RustCoreSigner) { - this.rustCoreSigner = rustCoreSigner - } - - override fun sign(payload: ByteArray): ByteArray { - return this.rustCoreSigner.sign(payload) - } -} \ No newline at end of file diff --git a/bound/kt/src/main/kotlin/web5/sdk/dids/BearerDid.kt b/bound/kt/src/main/kotlin/web5/sdk/dids/BearerDid.kt deleted file mode 100644 index 0654922f..00000000 --- a/bound/kt/src/main/kotlin/web5/sdk/dids/BearerDid.kt +++ /dev/null @@ -1,43 +0,0 @@ -package web5.sdk.dids - -import web5.sdk.crypto.keys.KeyManager -import web5.sdk.crypto.keys.ToOuterKeyManager -import web5.sdk.crypto.signers.Signer -import web5.sdk.crypto.signers.ToOuterSigner -import tbdex.sdk.rust.DidData as RustCoreDid -import tbdex.sdk.rust.DocumentData as RustCoreDocument -import tbdex.sdk.rust.BearerDid as RustCoreBearerDid - -typealias Did = RustCoreDid -typealias Document = RustCoreDocument - -class BearerDid { - val did: Did - val document: Document - val keyManager: KeyManager - - internal val rustCoreBearerDid: RustCoreBearerDid - - constructor(uri: String, keyManager: KeyManager) { - this.rustCoreBearerDid = RustCoreBearerDid(uri, keyManager.getRustCoreKeyManager()) - - this.did = this.rustCoreBearerDid.getData().did - this.document = this.rustCoreBearerDid.getData().document - this.keyManager = keyManager - } - - constructor(portableDid: PortableDid) { - this.rustCoreBearerDid = RustCoreBearerDid.fromPortableDid(portableDid.rustCorePortableDid) - - this.did = this.rustCoreBearerDid.getData().did - this.document = this.rustCoreBearerDid.getData().document - this.keyManager = ToOuterKeyManager(this.rustCoreBearerDid.getData().keyManager) - } - - fun getSigner(): Signer { - // TODO currently hardcoding to first VM - val keyId = this.document.verificationMethod.first().id - val innerSigner = this.rustCoreBearerDid.getSigner(keyId) - return ToOuterSigner(innerSigner) - } -} \ No newline at end of file diff --git a/bound/kt/src/main/kotlin/web5/sdk/dids/PortableDid.kt b/bound/kt/src/main/kotlin/web5/sdk/dids/PortableDid.kt deleted file mode 100644 index 5302d876..00000000 --- a/bound/kt/src/main/kotlin/web5/sdk/dids/PortableDid.kt +++ /dev/null @@ -1,20 +0,0 @@ -package web5.sdk.dids - -import web5.sdk.crypto.keys.Jwk -import tbdex.sdk.rust.PortableDid as RustCorePortableDid - -class PortableDid { - val didUri: String - val document: Document - val privateKeys: List - - internal val rustCorePortableDid: RustCorePortableDid - - constructor(json: String) { - this.rustCorePortableDid = RustCorePortableDid(json) - - this.didUri = rustCorePortableDid.getData().didUri - this.document = rustCorePortableDid.getData().document - this.privateKeys = rustCorePortableDid.getData().privateJwks - } -} \ No newline at end of file diff --git a/bound/kt/src/main/kotlin/web5/sdk/vc/pex/PresentationDefinition.kt b/bound/kt/src/main/kotlin/web5/sdk/vc/pex/PresentationDefinition.kt deleted file mode 100644 index 234e368e..00000000 --- a/bound/kt/src/main/kotlin/web5/sdk/vc/pex/PresentationDefinition.kt +++ /dev/null @@ -1,54 +0,0 @@ -package web5.sdk.vc.pex - -import com.fasterxml.jackson.annotation.JsonProperty -import tbdex.sdk.Json -import tbdex.sdk.rust.PresentationDefinition as RustCorePresentationDefinition - -data class PresentationDefinition( - val id: String, - val name: String?, - val purpose: String?, - @JsonProperty("input_descriptors") - val inputDescriptors: List -) { - internal val rustCorePresentationDefinition = RustCorePresentationDefinition( - Json.stringify(this) - ) - - fun selectCredentials(vcJwts: List): List { - return this.rustCorePresentationDefinition.selectCredentials(vcJwts) - } -} - -data class InputDescriptor( - val id: String, - val name: String? = null, - val purpose: String? = null, - val constraints: Constraints, -) - -data class Constraints( - val fields: List -) - -data class Field( - val id: String? = null, - val name: String? = null, - val path: List, - val purpose: String? = null, - val filter: Filter? = null, - val optional: Boolean? = false, - val predicate: Optionality? = null -) - -enum class Optionality { - Required, - Preferred -} - -data class Filter( - val type: String? = null, - val pattern: String? = null, - val const: String? = null, - val contains: Filter? = null -) \ No newline at end of file diff --git a/crates/tbdex/Cargo.toml b/crates/tbdex/Cargo.toml index c63ad921..d5f34614 100644 --- a/crates/tbdex/Cargo.toml +++ b/crates/tbdex/Cargo.toml @@ -10,7 +10,7 @@ build = "build.rs" [dependencies] base64 = "0.22.0" chrono = "0.4.38" -josekit = { version = "0.8.6", features = ["vendored"] } +josekit = { version = "0.8.7", features = ["vendored"] } jsonschema = { version = "0.18.0", features = ["draft201909", "draft202012"] } lazy_static = "1.5.0" rand = "0.8.5" diff --git a/crates/tbdex/src/http_client/mod.rs b/crates/tbdex/src/http_client/mod.rs index 9dccf970..556eba8c 100644 --- a/crates/tbdex/src/http_client/mod.rs +++ b/crates/tbdex/src/http_client/mod.rs @@ -11,11 +11,14 @@ use serde::{de::DeserializeOwned, Serialize}; use serde_json::Error as SerdeJsonError; use std::time::{Duration, SystemTime}; use uuid::Uuid; -use web5::dids::{ - bearer_did::{BearerDid, BearerDidError}, - resolution::{ - resolution_metadata::ResolutionMetadataError, resolution_result::ResolutionResult, +use web5::{ + dids::{ + bearer_did::BearerDid, + resolution::{ + resolution_metadata::ResolutionMetadataError, resolution_result::ResolutionResult, + }, }, + errors::Web5Error, }; #[derive(thiserror::Error, Debug, Clone, PartialEq)] @@ -24,11 +27,11 @@ pub enum HttpClientError { ReqwestError(String), #[error("serde json error {0}")] SerdeJson(String), - #[error(transparent)] - BearerDid(#[from] BearerDidError), #[error("jose error {0}")] Jose(String), #[error(transparent)] + Web5Error(#[from] Web5Error), + #[error(transparent)] Resource(#[from] ResourceError), #[error(transparent)] Message(#[from] MessageError), @@ -77,7 +80,7 @@ fn generate_access_token(pfi_did_uri: &str, bearer_did: &BearerDid) -> Result Result Result { - let resolution_result = ResolutionResult::new(pfi_did_uri); + let resolution_result = ResolutionResult::resolve(pfi_did_uri); let endpoint = match &resolution_result.document { None => { diff --git a/crates/tbdex/src/jose.rs b/crates/tbdex/src/jose.rs index cffd152f..686caf50 100644 --- a/crates/tbdex/src/jose.rs +++ b/crates/tbdex/src/jose.rs @@ -14,7 +14,7 @@ use std::{ }; use web5::{ crypto::{ - dsa::{ed25519::Ed25519Verifier, DsaError, Signer as Web5Signer, Verifier as Web5Verifier}, + dsa::{ed25519::Ed25519Verifier, Signer as Web5Signer, Verifier as Web5Verifier}, jwk::Jwk, }, dids::data_model::document::Document, @@ -89,17 +89,10 @@ impl JwsVerifier for Verifier { fn verify(&self, message: &[u8], signature: &[u8]) -> core::result::Result<(), JosekitError> { let verifier = Ed25519Verifier::new(self.public_jwk.clone()); - let result = verifier + verifier .verify(message, signature) .map_err(|e| JosekitError::InvalidSignature(e.into()))?; - - match result { - true => Ok(()), - false => Err(JosekitError::InvalidSignature( - // 🚧 improve error message semantics - DsaError::VerificationFailure("ed25519 verification failed".to_string()).into(), - )), - } + Ok(()) } fn box_clone(&self) -> Box { diff --git a/crates/tbdex/src/messages/mod.rs b/crates/tbdex/src/messages/mod.rs index 816685bf..d75becff 100644 --- a/crates/tbdex/src/messages/mod.rs +++ b/crates/tbdex/src/messages/mod.rs @@ -22,7 +22,7 @@ use serde::{de::Visitor, Deserialize, Deserializer, Serialize}; use serde_json::Error as SerdeJsonError; use std::{str::FromStr, sync::Arc}; use type_safe_id::{DynamicType, Error as TypeIdError, TypeSafeId}; -use web5::dids::bearer_did::BearerDidError; +use web5::errors::Web5Error; #[derive(thiserror::Error, Debug, Clone, PartialEq)] pub enum MessageError { @@ -31,7 +31,7 @@ pub enum MessageError { #[error("typeid error {0}")] TypeId(String), #[error(transparent)] - BearerDid(#[from] BearerDidError), + Web5Error(#[from] Web5Error), #[error(transparent)] Signature(#[from] SignatureError), #[error("unknown kind {0}")] diff --git a/crates/tbdex/src/messages/rfq.rs b/crates/tbdex/src/messages/rfq.rs index f9abf985..accfc650 100644 --- a/crates/tbdex/src/messages/rfq.rs +++ b/crates/tbdex/src/messages/rfq.rs @@ -239,7 +239,7 @@ impl Rfq { } for vc_jwt in vc_jwts { - VerifiableCredential::verify(&vc_jwt).map_err(|_| { + VerifiableCredential::from_vc_jwt(&vc_jwt, true).map_err(|_| { MessageError::OfferingVerification(format!( "vc_jwt failed verifiction {}", vc_jwt @@ -521,27 +521,15 @@ fn digest_private_data(salt: &str, value: &T) -> Result { #[cfg(test)] mod tests { use super::*; - use std::sync::Arc; - use web5::{ - crypto::{ - dsa::ed25519::Ed25519Generator, key_managers::in_memory_key_manager::InMemoryKeyManager, - }, - dids::methods::did_jwk::DidJwk, - }; + use web5::dids::methods::did_jwk::DidJwk; #[test] fn can_create_and_sign() { - let key_manager = InMemoryKeyManager::new(); - let public_jwk = key_manager - .import_private_jwk(Ed25519Generator::generate()) - .unwrap(); - let did_jwk = DidJwk::from_public_jwk(public_jwk).unwrap(); - - let bearer_did = BearerDid::new(&did_jwk.did.uri, Arc::new(key_manager)).unwrap(); + let bearer_did = DidJwk::create(None).unwrap(); let mut rfq = Rfq::create( "did:test:pfi", - &did_jwk.did.uri, + &bearer_did.did.uri, &CreateRfqData { offering_id: "offering_123".to_string(), payin: CreateSelectedPayinMethod { diff --git a/crates/tbdex/src/resources/mod.rs b/crates/tbdex/src/resources/mod.rs index de89cce9..203260ce 100644 --- a/crates/tbdex/src/resources/mod.rs +++ b/crates/tbdex/src/resources/mod.rs @@ -5,7 +5,7 @@ use crate::{json_schemas::JsonSchemaError, signature::SignatureError}; use serde::{Deserialize, Serialize}; use serde_json::Error as SerdeJsonError; use type_safe_id::{DynamicType, Error as TypeIdError, TypeSafeId}; -use web5::dids::bearer_did::BearerDidError; +use web5::errors::Web5Error; #[derive(thiserror::Error, Debug, Clone, PartialEq)] pub enum ResourceError { @@ -14,7 +14,7 @@ pub enum ResourceError { #[error("typeid error {0}")] TypeId(String), #[error(transparent)] - BearerDid(#[from] BearerDidError), + Web5Error(#[from] Web5Error), #[error(transparent)] Signature(#[from] SignatureError), #[error(transparent)] diff --git a/crates/tbdex/src/resources/offering.rs b/crates/tbdex/src/resources/offering.rs index b9afdbaa..60d0e65c 100644 --- a/crates/tbdex/src/resources/offering.rs +++ b/crates/tbdex/src/resources/offering.rs @@ -158,26 +158,14 @@ pub struct CancellationDetails { #[cfg(test)] mod tests { use super::*; - use std::sync::Arc; - use web5::{ - crypto::{ - dsa::ed25519::Ed25519Generator, key_managers::in_memory_key_manager::InMemoryKeyManager, - }, - dids::methods::did_jwk::DidJwk, - }; + use web5::dids::methods::did_jwk::DidJwk; #[test] fn can_create_and_sign_and_verify() { - let key_manager = InMemoryKeyManager::new(); - let public_jwk = key_manager - .import_private_jwk(Ed25519Generator::generate()) - .unwrap(); - let did_jwk = DidJwk::from_public_jwk(public_jwk).unwrap(); - - let bearer_did = BearerDid::new(&did_jwk.did.uri, Arc::new(key_manager)).unwrap(); + let bearer_did = DidJwk::create(None).unwrap(); let mut offering = Offering::create( - &did_jwk.did.uri, + &bearer_did.did.uri, &OfferingData { description: "Selling BTC for USD".to_string(), payout_units_per_payin_unit: "1.5".to_string(), diff --git a/crates/tbdex/src/signature.rs b/crates/tbdex/src/signature.rs index 097d2f9e..c3a6dceb 100644 --- a/crates/tbdex/src/signature.rs +++ b/crates/tbdex/src/signature.rs @@ -6,12 +6,10 @@ use serde_json::{Map, Value}; use sha2::{Digest, Sha256}; use std::fmt::Debug; use web5::dids::bearer_did::BearerDid; -use web5::dids::{ - bearer_did::BearerDidError, - resolution::{ - resolution_metadata::ResolutionMetadataError, resolution_result::ResolutionResult, - }, +use web5::dids::resolution::{ + resolution_metadata::ResolutionMetadataError, resolution_result::ResolutionResult, }; +use web5::errors::Web5Error; #[derive(thiserror::Error, Debug, Clone, PartialEq)] pub enum SignatureError { @@ -20,7 +18,7 @@ pub enum SignatureError { #[error(transparent)] ResolutionMetadata(#[from] ResolutionMetadataError), #[error(transparent)] - BearerDid(#[from] BearerDidError), + Web5Error(#[from] Web5Error), #[error("serde json error {0}")] SerdeJson(String), } @@ -55,7 +53,7 @@ pub fn sign(bearer_did: &BearerDid, metadata: &Value, data: &Value) -> Result Err(SignatureError::ResolutionMetadata(e)), None => { diff --git a/examples/hosted-wallet-kt/pfi/build.gradle.kts b/examples/hosted-wallet-kt/pfi/build.gradle.kts index 5cfc05ab..11a42e18 100644 --- a/examples/hosted-wallet-kt/pfi/build.gradle.kts +++ b/examples/hosted-wallet-kt/pfi/build.gradle.kts @@ -27,7 +27,7 @@ dependencies { // For a snapshot from maven // Update the short git commit SHA below - implementation("xyz.block:tbdex:commit-cc93a9c-SNAPSHOT") + implementation("xyz.block:tbdex:commit-21dd3cc-SNAPSHOT") // For the official release on maven central // implementation("xyz.block:tbdex:3.0.0") diff --git a/examples/hosted-wallet-kt/pfi/src/main/kotlin/Main.kt b/examples/hosted-wallet-kt/pfi/src/main/kotlin/Main.kt index a5b05fba..e4025a70 100644 --- a/examples/hosted-wallet-kt/pfi/src/main/kotlin/Main.kt +++ b/examples/hosted-wallet-kt/pfi/src/main/kotlin/Main.kt @@ -17,7 +17,7 @@ fun readEnv() { fun main() { readEnv() - val bearerDid = BearerDid(PortableDid(System.getProperty("PFI_PORTABLE_DID"))) + val bearerDid = BearerDid.fromPortableDid(PortableDid.fromJsonString(System.getProperty("PFI_PORTABLE_DID"))) port(8082) diff --git a/examples/hosted-wallet-kt/wallet/build.gradle.kts b/examples/hosted-wallet-kt/wallet/build.gradle.kts index 37c8983e..44837b51 100644 --- a/examples/hosted-wallet-kt/wallet/build.gradle.kts +++ b/examples/hosted-wallet-kt/wallet/build.gradle.kts @@ -26,7 +26,7 @@ dependencies { // For a snapshot from maven // Update the short git commit SHA below - implementation("xyz.block:tbdex:commit-cc93a9c-SNAPSHOT") + implementation("xyz.block:tbdex:commit-21dd3cc-SNAPSHOT") // For the official release on maven central // implementation("xyz.block:tbdex:3.0.0") diff --git a/examples/hosted-wallet-kt/wallet/src/main/kotlin/Main.kt b/examples/hosted-wallet-kt/wallet/src/main/kotlin/Main.kt index ca630f8a..00c84f25 100644 --- a/examples/hosted-wallet-kt/wallet/src/main/kotlin/Main.kt +++ b/examples/hosted-wallet-kt/wallet/src/main/kotlin/Main.kt @@ -30,7 +30,7 @@ fun main() { val pfiDidUri = System.getProperty("PFI_DID_URI") val verifiableCredential = System.getProperty("HOSTED_WALLET_VERIFIABLE_CREDENTIAL") - val bearerDid = BearerDid(PortableDid(System.getProperty("HOSTED_WALLET_PORTABLE_DID_JSON"))) + val bearerDid = BearerDid.fromPortableDid(PortableDid.fromJsonString(System.getProperty("HOSTED_WALLET_PORTABLE_DID_JSON"))) val replyToUrl = System.getProperty("REPLY_TO_URL") when (FLOW_TYPE) {