-
Notifications
You must be signed in to change notification settings - Fork 98
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(walletconnect): walletconnect integration #2223
base: dev
Are you sure you want to change the base?
Conversation
let irn_metadata = param.irn_metadata(); | ||
let ttl = irn_metadata.ttl; |
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.
we can use a timed/expirable map for this case. we do that for electrum and eth also i think. this is to avoid network-induced memory leaks.
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.
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 mainly went over some of old comments and resolved the ones which i can see have been updated (could use a helping hand in the remaining ones by pointing where the updates are).
my estimation right now is i would need one more all-over iteration for approval (+ old comments), but i don't wanna promise since break my promises :D
Thanks for that huge work!
|
||
self.validate_chain_id(&session, chain_id)?; | ||
|
||
// TODO: uncomment when WalletConnect wallets start listening to chainChanged event |
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.
So nothing happens(I mean wallets don't listen to this event) if we send such request
so what about just sending it for now and when wallets listen to it later we get this feat for free
Two reasons I didn't want to, this will add extra latency and corresponding wallet will return error as they wont't recognize such session request |
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.
Thanks for the changes! Here are my last notes.
Will follow up with the changes and approve once we covered/discussed all the important comments.
let (topic, url) = self.pairing.create(self.metadata.clone(), None)?; | ||
|
||
info!("[{topic}] Subscribing to topic"); |
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.
let's leave a todo here about cleaning up expired pairings that were abandoned.
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.
what if we leave deleting expired session to the users? more decentralizations...xd
|
||
pub(crate) fn get_sessions_full(&self) -> impl Iterator<Item = Session> { self.read().clone().into_values() } | ||
|
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.
nit: we can return only the pairs of session topics and controllers
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.
idea, I will come back to this...
update: c697e3c
mm2src/kdf_walletconnect/src/lib.rs
Outdated
message_id_generator: MessageIdGenerator, | ||
pending_requests: Mutex<HashMap<MessageId, oneshot::Sender<SessionMessageType>>>, | ||
abortable_system: AbortableQueue, |
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.
we should really make pending_requests
a timed map.
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.
why?
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.
request handles which we don't get a response for will reside in the map forever
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 will required updating structures in WalletConnect rust lib with some trait bounds.. I guess this can be postponed
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.
will it really?
ok let's leave a todo for it then.
mm2src/coins_activation/src/tendermint_with_assets_activation.rs
Outdated
Show resolved
Hide resolved
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.
Nearly done :)
}, | ||
) | ||
.await | ||
Ok(accounts[0].clone()) |
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.
might panic
let use .first().ok_or_err()
mm2src/kdf_walletconnect/Cargo.toml
Outdated
mm2_err_handle = { path = "../mm2_err_handle" } | ||
mm2_test_helpers = { path = "../mm2_test_helpers" } |
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.
what's this for?
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.
not needed anymore, removed
mm2src/coins/eth/wallet_connect.rs
Outdated
let data = wc | ||
.send_session_request_and_wait( | ||
session_topic, | ||
&chain_id, | ||
WcRequestMethods::PersonalSign, | ||
params, | ||
|data: String| { | ||
extract_pubkey_from_signature(&data, message, &account_str) | ||
.mm_err(|err| WalletConnectError::SessionError(err.to_string())) | ||
}, | ||
) | ||
.send_session_request_and_wait::<String>(session_topic, &chain_id, WcRequestMethods::PersonalSign, params) |
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.
nit: let data: String = ...
> let data = send_session_request::<String>(...
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 only makes a difference if send_session_request
has some complex type annotations
let all_sessions = ctx.session_manager.get_sessions_full(); | ||
for session in all_sessions { | ||
if session.controller == settle.controller && session.topic.as_ref() != topic.as_ref() { | ||
if session_controller_exists && session.topic.as_ref() != topic.as_ref() { | ||
ctx.drop_session(&session.topic).await?; | ||
debug!("[{}] session deleted", session.topic); | ||
} |
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.
that doens't make sense. if session_controller_exists
is true, that will delete all the sessions sessions with other topics.
we should be checking each session's controller.
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.
thanks for the catch!
if n <= 255 { | ||
if n <= 0xff { |
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.
that's more confusing tbh, i would rather revert back to 255 😂
or u8::MAX with casting (.into, as u64, etc..)
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.
it's for aestethics 😆 ..reverted to 255
.session_topic() | ||
.expect("TODO: handle after updating tendermint coin init"); |
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.
it's easy to return an error here? no?
let's not panic.
.iter() | ||
.enumerate() | ||
.map(|(_, (_, value))| { | ||
.map(|(_, value)| { |
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.
nit: map.value().map(|value| {})
> map.iter().map(|(_unused_key, value)| {})
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.
value.map.iter().map(|(_unused_key, value)| {})
> value.1.map.value().map(|value| {})
:p
mm2src/kdf_walletconnect/src/lib.rs
Outdated
message_id_generator: MessageIdGenerator, | ||
pending_requests: Mutex<HashMap<MessageId, oneshot::Sender<SessionMessageType>>>, | ||
abortable_system: AbortableQueue, |
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.
will it really?
ok let's leave a todo for it then.
#1543
This PR introduces the integration of WalletConnect into the Komodo DeFi Framework (KDF), enabling secure wallet connections for Cosmos and EVM-based chains. KDF acts as the DApp(in this PR), allowing users to initiate and manage transactions securely with external wallets e.g via Metamask.
Key changes include:
Tendermint
andEVM
.Tendermint
andEVM
https://specs.walletconnect.com/2.0/specs/clients/sign/
https://specs.walletconnect.com/2.0/specs/clients/core/pairing/
https://specs.walletconnect.com/2.0/specs/clients/core/crypto/
https://specs.walletconnect.com/2.0/specs/servers/relay/
https://docs.reown.com/advanced/multichain/rpc-reference/ethereum-rpc
Additional improvements include cleanup of unused dependencies, minor code refinements, and WASM compatibility
Updated deps:
Added deps:
Removed deps:
How to test using EVM coin e.g
ETH
(Native && WASM)cargo run
)ETH
coin (set"priv_key_policy": "WalletConnect",
in activation params).Note: To add more
eip155
chains, modify the chains array like this:["eip155:1", "eip155:250"]