forked from reown-com/reown-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Open
borngraced
wants to merge
81
commits into
kdf
Choose a base branch
from
pairing-api
base: kdf
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 78 commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
0e8b8c3
implement rpc methods
borngraced 900f72f
implement pairing-uri generation from pairing
borngraced 3096073
save dev state
borngraced 9679ee4
save dev state
borngraced 9f73ef1
implement pairing unit test
borngraced 3ab024c
scope mutex guard operation
borngraced dedf579
move rpc related to rpc crate and some refactorings
borngraced 84febe9
git add files
borngraced 0fe5eff
use async mutex
borngraced b13def3
minor changes
borngraced 1d540af
minor changes and add doc comment
borngraced 7079def
add more unit tests
borngraced 43057cc
minor changes
borngraced 548a821
cargo clippy
borngraced c3d8f4e
improve pairing client implementation
borngraced b4f8b43
use expected message_id for wallet response
borngraced ab51d8e
print connectino uri
borngraced 656d945
implement pair method
borngraced 1bfb7e2
cargo fmt
borngraced 36e015b
commit uri_parser.rs
borngraced d0d5118
create common lib
borngraced 8c0c215
commit pairing, uri mod
borngraced 2395848
minor changes
borngraced e9107b7
cargo clippy fmt
borngraced f4db2a3
improve pairing code
borngraced 528219f
impl session params
borngraced ddaf123
commit session files
borngraced 0926bcc
save dev state
borngraced b955bbb
save dev state
borngraced 3f82d7b
commit wc_common
borngraced f57b631
refactoring request and response params
borngraced 6757cda
update expiry derivation
borngraced a85bc6a
minor changes
borngraced 1f1044a
minor changes and fix failing tests
borngraced 76bdbad
delegate pairing topic subscription to client
borngraced c8f06e0
minor changes
borngraced 8efb1da
fix review notes
borngraced 37c929d
fix cargo clippy
borngraced 71acc1a
use idiomatic code for sym_key gen
borngraced 98211ed
use macro for default impl in PairingClient struct
borngraced f7bde84
don't append methods to url if empty
borngraced 6740313
Merge branch 'kdf' of github.com:KomodoPlatform/WalletConnectRust int…
borngraced 2af7e1a
fix generate url fn
borngraced 3bfcc41
fix connection uri generator fn
borngraced c02d999
use Default to initialize PairingClient and minor fix
borngraced 14e9726
fix review notes
borngraced 052ea1d
fix clippy
borngraced 17b1e31
fix disconnect bug
borngraced 974907e
minor changes
borngraced 9836e93
fix pairing delete
borngraced 8175331
use rustls for tokio wss
borngraced 61add9a
remove tokio-rustls dep
borngraced 3ea808b
add sessionProperties to SettleSettle structure
borngraced 91cb115
abstract timestamp check into a function
borngraced 423c67c
revert mod import deletion
borngraced fd8c7be
extend Params enums with Arbitrary response variant and fix review notes
borngraced 994db68
fix sym_key len check
borngraced 174d386
fix review notes and add caip validation for settle namespaces
borngraced a271959
export connection_event_loop
borngraced 5c974ad
handle pairing SymKey exporting properly/securely
borngraced f766404
fix pairing test
borngraced b427ff0
cargo fmt!!
borngraced 2372fa5
refactor Client new_unmanged and update rand crate
borngraced 90d4008
add doc to PairingClient struct and explicity take Topic as arg
borngraced f9d9952
handle possible out of bounds error
borngraced b8040e1
rename expiry, reuse sym_key
borngraced a7e7339
use DashMap for perfomance
borngraced cdf38a5
use try_fill_bytes
borngraced 4e09437
debug ws socket dirty close
borngraced d643b29
fix doc test
borngraced 4a78c4b
debug connection closed
borngraced 95da428
debug ws send
borngraced 9b78f48
debug
borngraced edd96c9
remove debug log
borngraced d208b54
nits
borngraced aab0f30
reuse activate pairing fn
borngraced eb384d6
fix review notes
borngraced 848d100
don't build example features
borngraced 897cf78
replace dashmap with RwLock
borngraced 99674a0
fix cargo clippy
borngraced 0bd862f
debug ci
borngraced File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ Cargo.lock | |
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[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" | ||
dashmap = "6.1.0" | ||
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"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the need of using dashmap, we will not have that many pairings to need a new dep for high concurrent operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has not been addressed yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done