-
Notifications
You must be signed in to change notification settings - Fork 13
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: create a simple Sign API example on top of the WS client #48
base: main
Are you sure you want to change the base?
feat: create a simple Sign API example on top of the WS client #48
Conversation
//! The crate exports common types used when interacting with messages between | ||
//! clients. This also includes communication over HTTP between relays. |
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.
Bad Copy/Paste, should be changed to an appropriate description.
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 is this module copy-pasted from relay_rpc
? I think we should somehow reuse the existing one
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 is a good point. In fact the way I initially started working on this change, was copy paste the entire rpc.rs
and then change bits and pieces that I need for sign_api
.
I ran into some issues, and wasn't sure how to appropriate certain traits, errors, etc.. for my use-case.
In the end I decided it will be easier for me to loosely base it on the relay rpc.rs
, and see if some common functionality can be refactored post fact after this change lands in the follow-ups. It should be easier, rather than doing two things at once - will probably result in some code, files shifting around.
pub fn validate(&self) -> Result<(), ValidationError> { | ||
match self { | ||
Self::Request(request) => request.validate(), | ||
Self::Response(response) => response.validate(), | ||
} | ||
} |
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.
Should add more request/response specific validations.
968a167
to
0a1df16
Compare
@heilhead , apologies for names dropping! The repository doesn't look very active, so this is my attempt to get some attention to the PR. Would you please be able to give this change a quick review, or maybe assign someone? Thanks! |
Hi @silvestrst-crypto, thanks for the PR! Sorry we didn't see it earlier. We'll try to review it in the next few days hopefully. |
gentle ping |
@silvestrst-crypto Hey! Apologies for not getting back with the review, as I'm on holidays right now. @xDarksome @farazdagi @chris13524 Can one of you guys please have a look at this? |
@silvestrst-crypto can you please also share your use case of how you're intending of using this? 🙏 |
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.
Absolutely marvellous work, thank you!
I will do another review pass today -- but overall looks really great. I had some minor comments.
NB: Sorry for keeping you waiting for review for so long, will make sure we progress swiftly from this point on :)
sign_api/src/crypto/payload.rs
Outdated
}, | ||
}) | ||
} | ||
_ => anyhow::bail!("Invalid envelope type: {}", envelope_type), |
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.
Generally we use typed errors and avoid using anyhow::bail
. For instance, relay_client/src/error.rs is the way we typically define errors, so for consistency's sake please consider defining Sign API error types.
NB: More or less, error types in pairing_uri
is what I am after here.
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, here and in all other sign_api
submodules.
pub struct SessionSettleRequest { | ||
pub relay: Relay, | ||
pub controller: Controller, | ||
pub namespaces: SettleNamespaces, |
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.
The optional specialNamespaces
are omitted here. Not a big deal though.
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.
Putting my 5 cents
I started to review, but then got distracted.
sign_api/src/crypto/session.rs
Outdated
impl Debug for SessionKey { | ||
/// Custom debug to hide the symmetrical key. | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("WalletConnectUrl") |
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 presume this is a refactoring artifact 😄
Also, consider using https://crates.io/crates/secrecy
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.
Indeed, bad copy paste from pairing_uri.rs
.
That's a good point, I will look into that crate, haven't yet one so.
sign_api/src/pairing_uri.rs
Outdated
url::Url, | ||
}; | ||
|
||
lazy_static! { |
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 think lazy_static
is somewhat deprecated in favor of once_cell::Lazy
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.
Moved inside parse_topic_and_version
. This function will not be called to often, so "caching" the regex it is not that important.
Done.
//! The crate exports common types used when interacting with messages between | ||
//! clients. This also includes communication over HTTP between relays. |
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 is this module copy-pasted from relay_rpc
? I think we should somehow reuse the existing one
Thank you guys for your reviews! I will hopefully aim to go through the comments properly tomorrow and fix them up. |
We have an internal Rust project, where we are planning on using WalletConnect v2 to do DeFI operations, which is the main reason for tackling the Sign API at this point 🙂 |
0a1df16
to
cd232c6
Compare
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.
Thank you guys for your reviews!
This is the first pass where I have tackled some of the review comments, I will handle the rest in next few passes.
Summary:
- Switches to typed errors rather than
anyhow::Error
- Changed
Namespace
memebrs fromVec
toBTreeSet
- Fixed-up some naming comments in
payload.rs
- Noticed that I had logic errors in the
payload.rs
when parsing decoded data (was wrong in a way that it still worked). Fixed it now.
I have also realised that Namespace
needs more validation logic in accordance to the spec.
When you got through comments, could you guys only resolve those that you are happy with, but keep open those that you think are still "not there yet". This should make the review process a bit easier for both parties. Thanks!
sign_api/src/crypto/payload.rs
Outdated
}, | ||
}) | ||
} | ||
_ => anyhow::bail!("Invalid envelope type: {}", envelope_type), |
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, here and in all other sign_api
submodules.
sign_api/src/crypto/session.rs
Outdated
impl Debug for SessionKey { | ||
/// Custom debug to hide the symmetrical key. | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("WalletConnectUrl") |
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.
Indeed, bad copy paste from pairing_uri.rs
.
That's a good point, I will look into that crate, haven't yet one so.
//! The crate exports common types used when interacting with messages between | ||
//! clients. This also includes communication over HTTP between relays. |
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 is a good point. In fact the way I initially started working on this change, was copy paste the entire rpc.rs
and then change bits and pieces that I need for sign_api
.
I ran into some issues, and wasn't sure how to appropriate certain traits, errors, etc.. for my use-case.
In the end I decided it will be easier for me to loosely base it on the relay rpc.rs
, and see if some common functionality can be refactored post fact after this change lands in the follow-ups. It should be easier, rather than doing two things at once - will probably result in some code, files shifting around.
cd232c6
to
7296dc8
Compare
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 is a second part of the review comments addressing:
- Fixed
SessionRequestRequest
to match the spec (was missing an optional field, andparams
were changed toserde_json::Value
) - Fixed
SessionEventRequest
to match the spec (data
was changed toserde_json::Value
) - Simple serealize/deserialize unittests were added for the above two bullet-points
- Some other minor comment were fixed
Will try to address the remaining comments by the end of the week.
sign_api/src/pairing_uri.rs
Outdated
url::Url, | ||
}; | ||
|
||
lazy_static! { |
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.
Moved inside parse_topic_and_version
. This function will not be called to often, so "caching" the regex it is not that important.
Done.
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.
First of all, thanks for the contribution! We really appreciate it 🥇
Second, can you add a section to the root README for the sign_api
crate? We also need to add a warning to that; the Rust team doesn't work on the client SDKs so the amount of rigor here is far less than e.g. our JavaScript, Kotlin, or Swift SDKs have gone through. Those SDKs are also continually improved with new features and fixes, so the Rust version will likely not be getting any of these updates unless a community member contributes it. This could change in the future if there is sufficient interest in the Rust SDK, but for now we cannot dedicate resources to keep this maintained. Can you add a note to the readme like:
Warning: this Rust Sign API SDK is community-maintained and may be lacking features and stability or security fixes that other versions of the Sign API SDK receive. We strongly recommend using the JavaScript or other Sign API SDKs instead.
Good idea, I understand, thanks! |
7296dc8
to
04b51d5
Compare
In the latest push I have:
|
04b51d5
to
fc737a0
Compare
In the latest push:
|
This change adds WalletConnect v2 Sign API, as per: https://specs.walletconnect.com/2.0/specs/clients/sign/ Please note that although the specification is fairly thorough, there are some inconsistencies. This implementation is derived from specs, analyzing ws traffic in browsers devtools, as well as the original WalletConnect JavaScript client at: https://github.com/WalletConnect/walletconnect-monorepo Design decisions: Modularity: - RPC and crypto modules are not dependent on each other, so client implementations don't have to use their own crypto implementation. Closes: reown-com#47
This client implements pairing and session flows: https://specs.walletconnect.com/2.0/specs/clients/core/pairing https://specs.walletconnect.com/2.0/specs/clients/sign/session-proposal Supported actions: - pairing - session establishment - session delete - ping This example could be expanded to handle multiple sessions. Caution: The purpose of this example is demonstration of core Sign API functionality. However, it shouldn't be used in production, as might exhibit some race conditions such as with session deletion, etc...
5046727
to
489e2e3
Compare
In the latest push:
|
Hi @silvestrst-crypto, thank you for your hard work on this PR 💪 . I was wondering if you had made any progress addressing the feedback from my colleagues and if you'd like to continue working on this issue? |
Hi @nopestack , lately I am quite busy, so put it on hold, but if anyone is planning on using it, I can slowly start moving it forward in spare time. Thanks! |
@nopestack I think it is best to move this code to an isolated repo, and depend on wallet-connect-rust . |
Marking this as draft in the meantime as work is paused and we cannot prioritize it at the moment. Worth revisiting it later @xDarksome @chris13524 |
Description
This change adds Sign API framework, and a simple example client to demonstrate pairing and session creation capabilities.
This change introduces the following functionality:
Resolves #47
How Has This Been Tested?
- Click on "Goerli" and then "connect"
- In a new pop-up, click "New Pairing"
- Copy the Pairing URI
- In the terminal,
cd path/to/WalletConnectRust
-
.../WalletConnectRust$ cargo run --example session "<copied URI>"
- DApp should now display the session window
- In the DApp click disconnect
Due Diligence
TODO
README.md
crypto/session.rs
refactorAdditional information
WCv2 uses layered approach. The relay protocol messages (currently only IRN, but there might be other in future), are used to carry the useful payload. In terms of this change the useful payload is Sign API messages.
Useful materials:
https://specs.walletconnect.com/2.0/specs/clients/core/pairing
https://specs.walletconnect.com/2.0/specs/clients/sign/session-proposal
https://specs.walletconnect.com/2.0/specs/servers/relay/relay-server-rpc
https://specs.walletconnect.com/2.0/specs/clients/sign/rpc-methods