Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 6492 Kotlin #58

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ Utilities/InstalledSwiftPMConfiguration/config.json
/crates/kotlin-ffi/jniLibs
/crates/kotlin-ffi/bindings/com/reown/kotlin/ffi/yttrium
/kotlin-bindings
/yttrium/kotlin-bindings/
4 changes: 4 additions & 0 deletions crates/kotlin-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ yttrium = { path = "../yttrium", features = ["uniffi"] }
uniffi = { version = "0.28.1", features = ["tokio", "cli"] }
openssl = { version = "0.10", features = ["vendored"] }
openssl-sys = { version = "0.9.103", features = ["vendored"] }
erc6492.workspace = true
alloy.workspace = true


# Errors
eyre.workspace = true
Expand All @@ -32,6 +35,7 @@ reqwest.workspace = true
# Logging
log.workspace = true
thiserror.workspace = true
url = "2.5.2"

[[bin]]
name = "uniffi-bindgen"
Expand Down
60 changes: 60 additions & 0 deletions crates/kotlin-ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
uniffi::setup_scaffolding!();

use alloy::{
network::Ethereum,
primitives::{Address as YAddress, Bytes, B256},
providers::ReqwestProvider,
};
use yttrium::config::Config;
use yttrium::transaction::send::safe_test::{
Address, OwnerSignature as YOwnerSignature, PrimitiveSignature,
Expand Down Expand Up @@ -53,6 +58,61 @@ pub enum Error {
Unknown(String),
}

#[derive(uniffi::Object)]
pub struct Erc6492Client {
provider: ReqwestProvider<Ethereum>,
}

#[derive(Debug, thiserror::Error, uniffi::Error)]
pub enum Erc6492Error {
#[error("InvalidSignature")]
InvalidSignature(String),
#[error("InvalidAddress")]
InvalidAddress(String),
#[error("InvalidMessageHash")]
InvalidMessageHash(String),
#[error("Verification")]
Verification(String),
}

#[uniffi::export(async_runtime = "tokio")]
impl Erc6492Client {
#[uniffi::constructor]
pub fn new(rpc_url: String) -> Self {
let url = rpc_url.parse().expect("Invalid RPC URL");
let provider = ReqwestProvider::<Ethereum>::new_http(url);
Self { provider }
}

pub async fn verify_signature(
&self,
signature: String,
address: String,
message_hash: String,
) -> Result<bool, Erc6492Error> {
let signature = signature
.parse::<Bytes>()
.map_err(|e| Erc6492Error::InvalidSignature(e.to_string()))?;
let address = address
.parse::<YAddress>()
.map_err(|e| Erc6492Error::InvalidAddress(e.to_string()))?;
let message_hash = message_hash
.parse::<B256>()
.map_err(|e| Erc6492Error::InvalidMessageHash(e.to_string()))?;

let verification = erc6492::verify_signature(
signature,
address,
message_hash,
&self.provider,
)
.await
.map_err(|e| Erc6492Error::Verification(e.to_string()))?;

Ok(verification.is_valid())
}
}

#[uniffi::export(async_runtime = "tokio")]
impl AccountClient {
#[uniffi::constructor]
Expand Down
3 changes: 3 additions & 0 deletions crates/yttrium/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ wiremock = "0.6.0"

# Networking
reqwest.workspace = true

[build-dependencies]
serde_json = "1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's unnecessary - will remove it before merging