pub struct Connection { /* private fields */ }
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn new(
rpc: &str,
jwt_rpc: &str,
project_id: &str,
client_seed: [u8; 32],
metadata: Metadata,
) -> Self
pub fn new( rpc: &str, jwt_rpc: &str, project_id: &str, client_seed: [u8; 32], metadata: Metadata, ) -> Self
Examples found in repository?
examples/connect-settle.rs (lines 19-29)
8async fn main() {
9 env_logger::init();
10
11 // ProjectId is required to prevent DOS on the relay. In case following
12 // cause rate limits, you can create your own from https://cloud.reown.com
13 let project_id = "35d44d49c2dee217a3eb24bb4410acc7";
14
15 // Used to sign JWTs. Must be generated and stored by client. Same seed
16 // should be reused for all connections.
17 let client_seed = [123u8; 32];
18
19 let conn = Connection::new(
20 "https://relay.walletconnect.org/rpc",
21 "https://relay.walletconnect.org",
22 project_id,
23 client_seed, Metadata {
24 name: "WalletConnect Rust SDK".to_string(),
25 description: "WalletConnect Rust SDK enables to connect to relay and interact with dapp".to_string(),
26 url: "https://github.com/zemse/walletconnect-sdk".to_string(),
27 icons: vec![],
28 },
29 );
30
31 // WalletConnect URI - you can get it by visiting any dApp and clicking on
32 // "Connect Wallet" and select WalletConnect
33 let uri_from_dapp = "wc:e4b9eb7a1372bf88abc46c37acac3687301afdfd0d2a4c2355945d66a1164464@2?relay-protocol=irn&symKey=d7430284e1b70853829a010518a088cde0e163bcad5f24425e3b17578b2b402d&expiryTimestamp=1749783095&methods=wc_sessionAuthenticate";
34
35 let (mut pairing, _) = conn
36 .init_pairing(uri_from_dapp)
37 .await
38 .expect("pairing failed");
39
40 pairing
41 .approve_with_session_settle(
42 "0x0000000000000000000000000000000000000123"
43 .parse()
44 .unwrap(),
45 )
46 .await
47 .expect("approve failed");
48
49 loop {
50 let result =
51 pairing.watch_messages(Topic::Derived, None).await.unwrap();
52
53 println!("result: {result:?}");
54 }
55}
More examples
examples/connect-auth.rs (lines 21-31)
10async fn main() {
11 env_logger::init();
12
13 // ProjectId is required to prevent DOS on the relay. In case following
14 // cause rate limits, you can create your own from https://cloud.reown.com
15 let project_id = "35d44d49c2dee217a3eb24bb4410acc7";
16
17 // Used to sign JWTs. Must be generated and stored by client. Same seed
18 // should be reused for all connections.
19 let client_seed = [123u8; 32];
20
21 let conn = Connection::new(
22 "https://relay.walletconnect.org/rpc",
23 "https://relay.walletconnect.org",
24 project_id,
25 client_seed, Metadata {
26 name: "WalletConnect Rust SDK".to_string(),
27 description: "WalletConnect Rust SDK enables to connect to relay and interact with dapp".to_string(),
28 url: "https://github.com/zemse/walletconnect-sdk".to_string(),
29 icons: vec![],
30 },
31 );
32
33 // WalletConnect URI - you can get it by visiting any dApp and clicking on
34 // "Connect Wallet" and select WalletConnect
35 let uri_from_dapp = "wc:60b429580a4c390b05661a1921a806abe0fa9891c6f38b303a519367d3aafba0@2?relay-protocol=irn&symKey=d08415aff3fb5b387b4a607ad20d5431e81e54dad759f9a658d99353a6815775&expiryTimestamp=1744387698&methods=wc_sessionAuthenticate";
36
37 let (pairing, _) = conn
38 .init_pairing(uri_from_dapp)
39 .await
40 .expect("pairing failed");
41
42 let private_key = SigningKey::random(&mut OsRng);
43 let signer = PrivateKeySigner::from(private_key);
44
45 // inspect pairing requests if it looks good
46 let (mut cacao, proposal, auth) =
47 pairing.get_proposal_old(signer.address(), 1).unwrap();
48 println!("cacao: {cacao:?}");
49 println!("proposal: {proposal:?}");
50 println!("auth: {auth:?}");
51
52 let message = cacao.caip122_message().unwrap();
53 let signature = signer.sign_message_sync(message.as_bytes()).unwrap();
54 cacao.insert_signature(signature).unwrap();
55
56 pairing.approve_with_cacao(cacao).await.unwrap();
57 // TODO there's error from dApp side "Signature verification failed"
58}
pub fn metadata(&self) -> &Metadata
Sourcepub async fn init_pairing(self, uri: &str) -> Result<(Pairing, WcMessage)>
pub async fn init_pairing(self, uri: &str) -> Result<(Pairing, WcMessage)>
Examples found in repository?
examples/connect-settle.rs (line 36)
8async fn main() {
9 env_logger::init();
10
11 // ProjectId is required to prevent DOS on the relay. In case following
12 // cause rate limits, you can create your own from https://cloud.reown.com
13 let project_id = "35d44d49c2dee217a3eb24bb4410acc7";
14
15 // Used to sign JWTs. Must be generated and stored by client. Same seed
16 // should be reused for all connections.
17 let client_seed = [123u8; 32];
18
19 let conn = Connection::new(
20 "https://relay.walletconnect.org/rpc",
21 "https://relay.walletconnect.org",
22 project_id,
23 client_seed, Metadata {
24 name: "WalletConnect Rust SDK".to_string(),
25 description: "WalletConnect Rust SDK enables to connect to relay and interact with dapp".to_string(),
26 url: "https://github.com/zemse/walletconnect-sdk".to_string(),
27 icons: vec![],
28 },
29 );
30
31 // WalletConnect URI - you can get it by visiting any dApp and clicking on
32 // "Connect Wallet" and select WalletConnect
33 let uri_from_dapp = "wc:e4b9eb7a1372bf88abc46c37acac3687301afdfd0d2a4c2355945d66a1164464@2?relay-protocol=irn&symKey=d7430284e1b70853829a010518a088cde0e163bcad5f24425e3b17578b2b402d&expiryTimestamp=1749783095&methods=wc_sessionAuthenticate";
34
35 let (mut pairing, _) = conn
36 .init_pairing(uri_from_dapp)
37 .await
38 .expect("pairing failed");
39
40 pairing
41 .approve_with_session_settle(
42 "0x0000000000000000000000000000000000000123"
43 .parse()
44 .unwrap(),
45 )
46 .await
47 .expect("approve failed");
48
49 loop {
50 let result =
51 pairing.watch_messages(Topic::Derived, None).await.unwrap();
52
53 println!("result: {result:?}");
54 }
55}
More examples
examples/connect-auth.rs (line 38)
10async fn main() {
11 env_logger::init();
12
13 // ProjectId is required to prevent DOS on the relay. In case following
14 // cause rate limits, you can create your own from https://cloud.reown.com
15 let project_id = "35d44d49c2dee217a3eb24bb4410acc7";
16
17 // Used to sign JWTs. Must be generated and stored by client. Same seed
18 // should be reused for all connections.
19 let client_seed = [123u8; 32];
20
21 let conn = Connection::new(
22 "https://relay.walletconnect.org/rpc",
23 "https://relay.walletconnect.org",
24 project_id,
25 client_seed, Metadata {
26 name: "WalletConnect Rust SDK".to_string(),
27 description: "WalletConnect Rust SDK enables to connect to relay and interact with dapp".to_string(),
28 url: "https://github.com/zemse/walletconnect-sdk".to_string(),
29 icons: vec![],
30 },
31 );
32
33 // WalletConnect URI - you can get it by visiting any dApp and clicking on
34 // "Connect Wallet" and select WalletConnect
35 let uri_from_dapp = "wc:60b429580a4c390b05661a1921a806abe0fa9891c6f38b303a519367d3aafba0@2?relay-protocol=irn&symKey=d08415aff3fb5b387b4a607ad20d5431e81e54dad759f9a658d99353a6815775&expiryTimestamp=1744387698&methods=wc_sessionAuthenticate";
36
37 let (pairing, _) = conn
38 .init_pairing(uri_from_dapp)
39 .await
40 .expect("pairing failed");
41
42 let private_key = SigningKey::random(&mut OsRng);
43 let signer = PrivateKeySigner::from(private_key);
44
45 // inspect pairing requests if it looks good
46 let (mut cacao, proposal, auth) =
47 pairing.get_proposal_old(signer.address(), 1).unwrap();
48 println!("cacao: {cacao:?}");
49 println!("proposal: {proposal:?}");
50 println!("auth: {auth:?}");
51
52 let message = cacao.caip122_message().unwrap();
53 let signature = signer.sign_message_sync(message.as_bytes()).unwrap();
54 cacao.insert_signature(signature).unwrap();
55
56 pairing.approve_with_cacao(cacao).await.unwrap();
57 // TODO there's error from dApp side "Signature verification failed"
58}
pub async fn irn_subscribe(&self, topic: &str) -> Result<String>
pub async fn irn_fetch_messages( &self, topic: &str, ) -> Result<Vec<EncryptedMessage>>
pub async fn irn_publish( &self, encrypted_message: EncryptedMessage, ) -> Result<Value>
Trait Implementations§
Source§impl Clone for Connection
impl Clone for Connection
Source§fn clone(&self) -> Connection
fn clone(&self) -> Connection
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Connection
impl Debug for Connection
Source§impl PartialEq for Connection
impl PartialEq for Connection
impl StructuralPartialEq for Connection
Auto Trait Implementations§
impl Freeze for Connection
impl RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnwindSafe for Connection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more