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: create a simple Sign API example on top of the WS client #1

Closed
wants to merge 3 commits into from

Conversation

silvestrst-crypto
Copy link
Owner

@silvestrst-crypto silvestrst-crypto commented Oct 25, 2023

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:

  • Sign API payload serializable/deserializable data types
  • Payload encryption and decryption
  • Session Diffie–Hellman key derivation
  • Pairing URI parsing
  • Simple WS based client

Resolves reown-com#47

How Has This Been Tested?

  • Use example client to pair and establish the session with an example (DApp)[https://react-app.walletconnect.com/]:
    - 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

image

  • Unittests

Due Diligence

  • Breaking change
  • Requires a documentation update
  • Requires a e2e/integration test update

TODO

  • Typed errors instead of unnamed anyhow errors
  • More unittests
  • Better documentation, code comments and fuction descriptions
  • crypto/session.rs refactor

Additional 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

@silvestrst-crypto
Copy link
Owner Author

silvestrst-crypto commented Oct 25, 2023

During the last refactoring I have introduced a regression, so session is not establishing at the moment, will investigate.

Solved: needed to untag the success and error response parameters.

Comment on lines +1 to +2
//! The crate exports common types used when interacting with messages between
//! clients. This also includes communication over HTTP between relays.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad copy/paste

}
}

/// Validates the request payload.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add more validations.

}

/// Validates the parameters.
pub fn validate(&self) -> Result<(), ValidationError> {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add more validations


impl Payload {
/// Returns the message ID contained within the payload.
pub fn id(&self) -> u64 {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really used anywhere, should remove?

@silvestrst-crypto silvestrst-crypto force-pushed the silvestrs/sign-api-latest branch 2 times, most recently from 17baa3e to 3a06da3 Compare October 25, 2023 12:55
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...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Sign API
1 participant