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: implement Pairing API #3

Merged
merged 81 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
0e8b8c3
implement rpc methods
borngraced Aug 30, 2024
900f72f
implement pairing-uri generation from pairing
borngraced Aug 30, 2024
3096073
save dev state
borngraced Aug 30, 2024
9679ee4
save dev state
borngraced Aug 30, 2024
9f73ef1
implement pairing unit test
borngraced Sep 1, 2024
3ab024c
scope mutex guard operation
borngraced Sep 1, 2024
dedf579
move rpc related to rpc crate and some refactorings
borngraced Sep 2, 2024
84febe9
git add files
borngraced Sep 2, 2024
0fe5eff
use async mutex
borngraced Sep 2, 2024
b13def3
minor changes
borngraced Sep 2, 2024
1d540af
minor changes and add doc comment
borngraced Sep 3, 2024
7079def
add more unit tests
borngraced Sep 3, 2024
43057cc
minor changes
borngraced Sep 3, 2024
548a821
cargo clippy
borngraced Sep 3, 2024
c3d8f4e
improve pairing client implementation
borngraced Sep 4, 2024
b4f8b43
use expected message_id for wallet response
borngraced Sep 4, 2024
ab51d8e
print connectino uri
borngraced Sep 4, 2024
656d945
implement pair method
borngraced Sep 4, 2024
1bfb7e2
cargo fmt
borngraced Sep 4, 2024
36e015b
commit uri_parser.rs
borngraced Sep 4, 2024
d0d5118
create common lib
borngraced Sep 5, 2024
8c0c215
commit pairing, uri mod
borngraced Sep 5, 2024
2395848
minor changes
borngraced Sep 6, 2024
e9107b7
cargo clippy fmt
borngraced Sep 6, 2024
f4db2a3
improve pairing code
borngraced Sep 6, 2024
528219f
impl session params
borngraced Sep 6, 2024
ddaf123
commit session files
borngraced Sep 6, 2024
0926bcc
save dev state
borngraced Sep 9, 2024
b955bbb
save dev state
borngraced Sep 9, 2024
3f82d7b
commit wc_common
borngraced Sep 9, 2024
f57b631
refactoring request and response params
borngraced Sep 11, 2024
6757cda
update expiry derivation
borngraced Sep 11, 2024
a85bc6a
minor changes
borngraced Sep 16, 2024
1f1044a
minor changes and fix failing tests
borngraced Sep 16, 2024
76bdbad
delegate pairing topic subscription to client
borngraced Sep 16, 2024
c8f06e0
minor changes
borngraced Sep 18, 2024
8efb1da
fix review notes
borngraced Sep 18, 2024
37c929d
fix cargo clippy
borngraced Sep 19, 2024
71acc1a
use idiomatic code for sym_key gen
borngraced Sep 20, 2024
98211ed
use macro for default impl in PairingClient struct
borngraced Sep 20, 2024
f7bde84
don't append methods to url if empty
borngraced Sep 23, 2024
6740313
Merge branch 'kdf' of github.com:KomodoPlatform/WalletConnectRust int…
borngraced Sep 23, 2024
2af7e1a
fix generate url fn
borngraced Sep 23, 2024
3bfcc41
fix connection uri generator fn
borngraced Sep 26, 2024
c02d999
use Default to initialize PairingClient and minor fix
borngraced Oct 1, 2024
14e9726
fix review notes
borngraced Oct 9, 2024
052ea1d
fix clippy
borngraced Oct 10, 2024
17b1e31
fix disconnect bug
borngraced Oct 10, 2024
974907e
minor changes
borngraced Oct 10, 2024
9836e93
fix pairing delete
borngraced Oct 10, 2024
8175331
use rustls for tokio wss
borngraced Oct 10, 2024
61add9a
remove tokio-rustls dep
borngraced Oct 10, 2024
3ea808b
add sessionProperties to SettleSettle structure
borngraced Oct 11, 2024
91cb115
abstract timestamp check into a function
borngraced Oct 16, 2024
423c67c
revert mod import deletion
borngraced Oct 16, 2024
fd8c7be
extend Params enums with Arbitrary response variant and fix review notes
borngraced Oct 24, 2024
994db68
fix sym_key len check
borngraced Oct 24, 2024
174d386
fix review notes and add caip validation for settle namespaces
borngraced Oct 27, 2024
a271959
export connection_event_loop
borngraced Oct 31, 2024
5c974ad
handle pairing SymKey exporting properly/securely
borngraced Nov 4, 2024
f766404
fix pairing test
borngraced Nov 4, 2024
b427ff0
cargo fmt!!
borngraced Nov 4, 2024
2372fa5
refactor Client new_unmanged and update rand crate
borngraced Nov 6, 2024
90d4008
add doc to PairingClient struct and explicity take Topic as arg
borngraced Nov 8, 2024
f9d9952
handle possible out of bounds error
borngraced Nov 8, 2024
b8040e1
rename expiry, reuse sym_key
borngraced Nov 9, 2024
a7e7339
use DashMap for perfomance
borngraced Nov 9, 2024
cdf38a5
use try_fill_bytes
borngraced Nov 9, 2024
4e09437
debug ws socket dirty close
borngraced Nov 11, 2024
d643b29
fix doc test
borngraced Nov 11, 2024
4a78c4b
debug connection closed
borngraced Nov 12, 2024
95da428
debug ws send
borngraced Nov 12, 2024
9b78f48
debug
borngraced Nov 12, 2024
edd96c9
remove debug log
borngraced Nov 12, 2024
d208b54
nits
borngraced Nov 12, 2024
aab0f30
reuse activate pairing fn
borngraced Nov 19, 2024
eb384d6
fix review notes
borngraced Nov 27, 2024
848d100
don't build example features
borngraced Nov 27, 2024
897cf78
replace dashmap with RwLock
borngraced Nov 28, 2024
99674a0
fix cargo clippy
borngraced Nov 28, 2024
0bd862f
debug ci
borngraced Nov 29, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

.idea
12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@ authors = ["WalletConnect Team"]
license = "Apache-2.0"

[workspace]
members = ["blockchain_api", "relay_client", "relay_rpc"]
members = [
"blockchain_api",
"wc_common",
"pairing_api",
"relay_client",
"relay_rpc",
]

[features]
default = ["full"]
full = ["client", "rpc", "http"]
client = ["dep:relay_client"]
http = ["relay_client/http"]
rpc = ["dep:relay_rpc"]
pairing_api = ["dep:pairing_api"]

[dependencies]
relay_client = { path = "./relay_client", optional = true }
relay_rpc = { path = "./relay_rpc", optional = true }
pairing_api = { path = "./pairing_api", optional = true }

[dev-dependencies]
anyhow = "1"
Expand All @@ -40,7 +48,7 @@ name = "http_client"
required-features = ["client", "rpc", "http"]

[[example]]
name = "ws_unmanaged"
name = "websocket_client_with_callback"
required-features = ["client", "rpc"]

[[example]]
Expand Down
130 changes: 130 additions & 0 deletions examples/websocket_client_with_callback.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
use {
relay_client::{
error::ClientError,
websocket::{
connection_event_loop,
Client,
CloseFrame,
ConnectionHandler,
PublishedMessage,
},
ConnectionOptions,
},
relay_rpc::{
auth::{ed25519_dalek::SigningKey, AuthToken},
domain::Topic,
},
std::{sync::Arc, time::Duration},
structopt::StructOpt,
tokio::spawn,
};

#[derive(StructOpt)]
struct Args {
/// Specify WebSocket address.
#[structopt(short, long, default_value = "wss://relay.walletconnect.org")]
address: String,

/// Specify WalletConnect project ID.
#[structopt(short, long, default_value = "86e916bcbacee7f98225dde86b697f5b")]
project_id: String,
}

struct Handler {
name: &'static str,
}

impl Handler {
fn new(name: &'static str) -> Self {
Self { name }
}
}

impl ConnectionHandler for Handler {
fn connected(&mut self) {
println!("[{}] connection open", self.name);
}

fn disconnected(&mut self, frame: Option<CloseFrame<'static>>) {
println!("[{}] connection closed: frame={frame:?}", self.name);
}

fn message_received(&mut self, message: PublishedMessage) {
println!(
"[{}] inbound message: topic={} message={}",
self.name, message.topic, message.message
);
}

fn inbound_error(&mut self, error: ClientError) {
println!("[{}] inbound error: {error}", self.name);
}

fn outbound_error(&mut self, error: ClientError) {
println!("[{}] outbound error: {error}", self.name);
}
}

fn create_conn_opts(address: &str, project_id: &str) -> ConnectionOptions {
let key = SigningKey::generate(&mut rand::thread_rng());

let auth = AuthToken::new("http://example.com")
.aud(address)
.ttl(Duration::from_secs(60 * 60))
.as_jwt(&key)
.unwrap();

ConnectionOptions::new(project_id, auth).with_address(address)
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args = Args::from_args();

let handler = Handler::new("ws_test");
let (client1, _) = Client::new_with_callback(handler, |rx, handler| {
spawn(connection_event_loop(rx, handler))
});

client1
.connect(&create_conn_opts(&args.address, &args.project_id))
.await?;

let handler = Handler::new("ws_test2");
let (client2, _) = Client::new_with_callback(handler, |rx, handler| {
spawn(connection_event_loop(rx, handler))
});

client2
.connect(&create_conn_opts(&args.address, &args.project_id))
.await?;

let topic = Topic::generate();

let subscription_id = client1.subscribe(topic.clone()).await?;
println!("[client1] subscribed: topic={topic} subscription_id={subscription_id}");

client2
.publish(
topic.clone(),
Arc::from("Hello WalletConnect!"),
None,
0,
Duration::from_secs(60),
false,
)
.await?;

println!("[client2] published message with topic: {topic}",);

tokio::time::sleep(Duration::from_millis(500)).await;

drop(client1);
drop(client2);

tokio::time::sleep(Duration::from_millis(100)).await;

println!("clients disconnected");

Ok(())
}
140 changes: 0 additions & 140 deletions examples/ws_unmanaged.rs

This file was deleted.

45 changes: 45 additions & 0 deletions pairing_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "pairing_api"
version = "0.1.0"
edition = "2021"

[features]
example = ["dep:structopt", "dep:tokio", "dep:getrandom"]

[dependencies]
chrono = { version = "0.4", default-features = false, features = [
"std",
"clock",
] }
anyhow = "1.0.86"
hex = "0.4.2"
lazy_static = "1.4"
paste = "1.0.15"
rand = "0.8.5"
regex = "1.7"
relay_client = { path = "../relay_client" }
relay_rpc = { path = "../relay_rpc" }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive", "rc"] }
structopt = { version = "0.3", default-features = false, optional = true }
thiserror = "1.0"
url = "2.3"
wc_common = { path = "../wc_common" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.22", features = [
"rt",
"rt-multi-thread",
"sync",
"macros",
"time",
"signal",
], optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"], optional = true }
tokio = { version = "1.22", features = ["sync", "macros"], optional = true }

[[example]]
name = "pairing"
required-features = ["example"]
Loading
Loading