Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Add examples/hosted-wallet-kt (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe authored Jul 3, 2024
1 parent b207638 commit 4c1ddfb
Show file tree
Hide file tree
Showing 77 changed files with 1,998 additions and 282 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ Cargo.lock

# ---

.hermit/
.hermit/
build/
.gradle/
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ license-file = "LICENSE"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
thiserror = "1.0.50"
web5 = { git = "https://github.com/TBD54566975/web5-rs", rev = "a73efd745036861a03bdf33984af6ae10536e6f4" }
web5 = { git = "https://github.com/TBD54566975/web5-rs", rev = "ede4a64286cfaa3c4b5fcad71445c319488b892a" }
1 change: 1 addition & 0 deletions bin/.gradle-8.8.pkg
1 change: 1 addition & 0 deletions bin/.maven-3.9.8.pkg
1 change: 1 addition & 0 deletions bin/.openjdk@11.pkg
1 change: 1 addition & 0 deletions bin/gradle
1 change: 1 addition & 0 deletions bin/jaotc
1 change: 1 addition & 0 deletions bin/jar
1 change: 1 addition & 0 deletions bin/jarsigner
1 change: 1 addition & 0 deletions bin/java
1 change: 1 addition & 0 deletions bin/javac
1 change: 1 addition & 0 deletions bin/javadoc
1 change: 1 addition & 0 deletions bin/javap
1 change: 1 addition & 0 deletions bin/jcmd
1 change: 1 addition & 0 deletions bin/jconsole
1 change: 1 addition & 0 deletions bin/jdb
1 change: 1 addition & 0 deletions bin/jdeprscan
1 change: 1 addition & 0 deletions bin/jdeps
1 change: 1 addition & 0 deletions bin/jfr
1 change: 1 addition & 0 deletions bin/jhsdb
1 change: 1 addition & 0 deletions bin/jimage
1 change: 1 addition & 0 deletions bin/jinfo
1 change: 1 addition & 0 deletions bin/jjs
1 change: 1 addition & 0 deletions bin/jlink
1 change: 1 addition & 0 deletions bin/jmap
1 change: 1 addition & 0 deletions bin/jmod
1 change: 1 addition & 0 deletions bin/jps
1 change: 1 addition & 0 deletions bin/jrunscript
1 change: 1 addition & 0 deletions bin/jshell
1 change: 1 addition & 0 deletions bin/jstack
1 change: 1 addition & 0 deletions bin/jstat
1 change: 1 addition & 0 deletions bin/jstatd
1 change: 1 addition & 0 deletions bin/keytool
1 change: 1 addition & 0 deletions bin/mvn
1 change: 1 addition & 0 deletions bin/mvnDebug
1 change: 1 addition & 0 deletions bin/pack200
1 change: 1 addition & 0 deletions bin/rmic
1 change: 1 addition & 0 deletions bin/rmid
1 change: 1 addition & 0 deletions bin/rmiregistry
1 change: 1 addition & 0 deletions bin/serialver
1 change: 1 addition & 0 deletions bin/unpack200
2 changes: 1 addition & 1 deletion bindings/tbdex_uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "a73efd745036861a03bdf33984af6ae10536e6f4" }
web5_uniffi_wrapper = { git = "https://github.com/TBD54566975/web5-rs", rev = "ede4a64286cfaa3c4b5fcad71445c319488b892a" }

[build-dependencies]
uniffi = { version = "0.27.1", features = ["build"] }
Expand Down
27 changes: 26 additions & 1 deletion bindings/tbdex_uniffi/src/http_client/exchanges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use crate::{
messages::{close::Close, order::Order, order_status::OrderStatus, quote::Quote, rfq::Rfq},
};
use std::sync::{Arc, RwLock};
use tbdex::http_client::exchanges::Exchange as InnerExchange;
use tbdex::http_client::exchanges::{
CreateExchangeRequestBody as InnerCreateExchangeRequestBody, Exchange as InnerExchange,
};
use web5_uniffi_wrapper::dids::bearer_did::BearerDid;

pub struct Exchange {
Expand Down Expand Up @@ -73,3 +75,26 @@ pub fn get_exchanges(pfi_did_uri: String, bearer_did: Arc<BearerDid>) -> Result<
tbdex::http_client::exchanges::get_exchanges(&pfi_did_uri, &bearer_did.0.clone())?;
Ok(exchange_ids)
}

#[derive(Clone)]
pub struct CreateExchangeRequestBodyData {
pub rfq: Arc<Rfq>,
pub reply_to: Option<String>,
}

pub struct CreateExchangeRequestBody(pub CreateExchangeRequestBodyData);

impl CreateExchangeRequestBody {
pub fn from_json_string(json: &str) -> Result<Self> {
let inner = InnerCreateExchangeRequestBody::from_json_string(json)?;
let rfq = Rfq::from_inner(inner.rfq);
Ok(Self(CreateExchangeRequestBodyData {
rfq: Arc::new(rfq),
reply_to: inner.reply_to,
}))
}

pub fn get_data(&self) -> CreateExchangeRequestBodyData {
self.0.clone()
}
}
8 changes: 6 additions & 2 deletions bindings/tbdex_uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
balances::get_balances,
exchanges::{
create_exchange, get_exchange, get_exchanges, submit_close, submit_order,
Exchange as ExchangeData,
CreateExchangeRequestBody, CreateExchangeRequestBodyData, Exchange as ExchangeData,
},
offerings::get_offerings,
},
Expand Down Expand Up @@ -50,12 +50,16 @@ 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},
dids::{
bearer_did::{BearerDid, BearerDidData},
portable_did::PortableDid,
},
errors::RustCoreError as Web5RustCoreError,
};

Expand Down
4 changes: 4 additions & 0 deletions bindings/tbdex_uniffi/src/messages/rfq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ impl Rfq {
Ok(Self(Arc::new(RwLock::new(rfq))))
}

pub fn from_inner(inner_rfq: InnerRfq) -> Self {
Self(Arc::new(RwLock::new(inner_rfq)))
}

pub fn from_json_string(json: &str, require_all_private_data: bool) -> Result<Self> {
let inner_rfq = InnerRfq::from_json_string(json, require_all_private_data)?;

Expand Down
23 changes: 23 additions & 0 deletions bindings/tbdex_uniffi/src/tbdex.udl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,16 @@ dictionary ExchangeData {
Close? close;
};

dictionary CreateExchangeRequestBodyData {
Rfq rfq;
string? reply_to;
};

interface CreateExchangeRequestBody {
[Name=from_json_string, Throws=RustCoreError]
constructor([ByRef] string json);
CreateExchangeRequestBodyData get_data();
};



Expand Down Expand Up @@ -311,6 +320,18 @@ interface InMemoryKeyManager {
KeyManager get_as_key_manager();
};

dictionary PortableDidData {
string did_uri;
DocumentData document;
sequence<JwkData> private_jwks;
};

interface PortableDid {
[Throws=Web5RustCoreError]
constructor([ByRef] string json);
PortableDidData get_data();
};

dictionary BearerDidData {
DidData did;
DocumentData document;
Expand All @@ -320,6 +341,8 @@ dictionary BearerDidData {
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);
Expand Down
13 changes: 13 additions & 0 deletions bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Exchanges.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import tbdex.sdk.rust.submitOrder as rustCoreSubmitOrder
import tbdex.sdk.rust.submitClose as rustCoreSubmitClose
import tbdex.sdk.rust.getExchange as rustCoreGetExchange
import tbdex.sdk.rust.getExchanges as rustCoreGetExchanges
import tbdex.sdk.rust.CreateExchangeRequestBody as RustCoreCreateExchangeRequestBody

data class Exchange(
val rfq: Rfq,
Expand Down Expand Up @@ -48,4 +49,16 @@ fun getExchange(pfiDidUri: String, bearerDid: BearerDid, exchangeId: String): Ex

fun getExchanges(pfiDidUri: String, bearerDid: BearerDid): List<String> {
return rustCoreGetExchanges(pfiDidUri, bearerDid.rustCoreBearerDid)
}

class CreateExchangeRequestBody {
val rfq: Rfq
val replyTo: String?

constructor(json: String) {
val rustCoreCreateExchangeRequestBody = RustCoreCreateExchangeRequestBody.fromJsonString(json)
val data = rustCoreCreateExchangeRequestBody.getData()
this.rfq = Rfq(data.rfq)
this.replyTo = data.replyTo
}
}
7 changes: 3 additions & 4 deletions bound/kt/src/main/kotlin/tbdex/sdk/messages/Rfq.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package tbdex.sdk.messages

import com.fasterxml.jackson.databind.JsonNode
import tbdex.sdk.Json
import tbdex.sdk.resources.Offering
import tbdex.sdk.web5.BearerDid
Expand Down Expand Up @@ -80,13 +79,13 @@ data class CreateRfqData(

data class CreateSelectedPayinMethod(
val kind: String,
val paymentDetails: JsonNode? = null,
val paymentDetails: Map<String, Any?>? = null,
val amount: String
)

data class CreateSelectedPayoutMethod(
val kind: String,
val paymentDetails: JsonNode? = null
val paymentDetails: Map<String, Any?>? = null
)

data class RfqData(
Expand Down Expand Up @@ -115,5 +114,5 @@ data class RfqPrivateData(
)

data class PrivatePaymentDetails(
val paymentDetails: JsonNode? = null
val paymentDetails: Map<String, Any?>? = null
)
5 changes: 2 additions & 3 deletions bound/kt/src/main/kotlin/tbdex/sdk/resources/Offering.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package tbdex.sdk.resources

import com.fasterxml.jackson.databind.JsonNode
import tbdex.sdk.Json
import tbdex.sdk.web5.BearerDid
import tbdex.sdk.web5.PresentationDefinition
Expand Down Expand Up @@ -68,7 +67,7 @@ data class PayinMethod(
val name: String? = null,
val description: String? = null,
val group: String? = null,
val requiredPaymentDetails: JsonNode? = null,
val requiredPaymentDetails: Map<String, Any?>? = null,
val fee: String? = null,
val min: String? = null,
val max: String? = null
Expand All @@ -86,7 +85,7 @@ data class PayoutMethod(
val name: String? = null,
val description: String? = null,
val group: String? = null,
val requiredPaymentDetails: JsonNode? = null,
val requiredPaymentDetails: Map<String, Any?>? = null,
val fee: String? = null,
val min: String? = null,
val max: String? = null,
Expand Down
Loading

0 comments on commit 4c1ddfb

Please sign in to comment.