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

Add EIP-1193 support #414

Merged
merged 14 commits into from
Dec 7, 2020
Merged

Add EIP-1193 support #414

merged 14 commits into from
Dec 7, 2020

Conversation

enolan
Copy link
Contributor

@enolan enolan commented Nov 28, 2020

I added support for EIP-1193 and got the library working in the browser. This will be easier to review commit-by-commit.

For an example of the new functionality in use, you can check out the eip-1193-with-example branch from my fork. To run: wasm-pack build -- --no-default-features --features eip-1193 && cd www && npm install && npm run start. Then open http://127.0.0.1:8080 in a browser with MetaMask installed. Reject the transaction when prompted unless you enjoy burning 1 ETH for no reason.

This is my first substantial Rust code, feedback is very appreciated.

@enolan enolan changed the title Eip 1193 pr Add EIP-1193 support Nov 28, 2020
libsecp256k1 doesn't compile with the WASM target, and you don't need to sign
transactions or messages in the browser anyway, since your wallet usually
manages the keys.
@enolan enolan force-pushed the eip-1193-pr branch 2 times, most recently from 18c96f2 to a44881a Compare November 28, 2020 19:46
Copy link
Owner

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this! There is a couple of fixes I'd like to see, but functionality-wise it looks complete and extremely useful.

src/api/accounts.rs Outdated Show resolved Hide resolved
@@ -1,12 +1,17 @@
//! Ethereum Contract Interface

use crate::api::{Accounts, Eth, Namespace};
#[cfg(feature = "signing")]
Copy link
Owner

Choose a reason for hiding this comment

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

Same here an in other places, please group signing-related functionality in a single mod block and only feature gate that block.

Copy link
Owner

Choose a reason for hiding this comment

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

Could you please group all signing related things into a submodule here as well? Basically I'd like a single #[cfg(feature = "signing")] stament instead of sprinkling it all around.

src/transports/eip_1193.rs Outdated Show resolved Hide resolved
src/transports/eip_1193.rs Outdated Show resolved Hide resolved
src/transports/eip_1193.rs Show resolved Hide resolved
src/transports/eip_1193.rs Outdated Show resolved Hide resolved
http = ["hyper", "hyper-proxy", "url", "base64", "typed-headers"]
http-tls = ["hyper-tls", "native-tls", "http"]
signing = ["secp256k1"]
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of disabling signing capabilities in JS it's actually possible to use libsecpk256k1 which compiles to WASM. See how it's done in ethsign. That said, it might be pretty involved and would rather review that separately in a follow up PR, so we can just create an issue for now.

src/transports/eip_1193.rs Show resolved Hide resolved
src/transports/mod.rs Show resolved Hide resolved

/// EIP-1193 transport
#[derive(Clone, Debug)]
pub struct Eip1193 {
Copy link
Owner

Choose a reason for hiding this comment

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

To be fair I prefer this notation over one with dash or an underscore. So I'd prefer the feature and the enclosing module to be both called eip1193 and that would align with the struct as well. I'm not super strong on this, so if the - notation is more correct, so be it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm following the standardized conventions. I don't have a strong preference either, but given that there exists a standard I'd prefer the consistency.

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, I'm not objecting to the standard, both eip_1993 and eip1993 are valid module names and both adhere to the standard. It's just they come from different "source strings" EIP-1993 and EIP1993.
As I said I'm not super strong on this, if EIP-1993 is the only correct EIP name, so bit it, I can live with eip_1993 module name :)

@enolan
Copy link
Contributor Author

enolan commented Dec 4, 2020

I think I got everything you asked for. Added support for some of the browser-specific events as well.

Copy link
Owner

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Looks really good already, I'd still like to minimize the number of feature-gated lines though (ideally just one sub-module per file).

}
}

/// A transaction used for RLP encoding, hashing and signing.
#[cfg(feature = "signing")]
struct Transaction {
Copy link
Owner

Choose a reason for hiding this comment

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

If Transaction is only used in case of signing, why not move it to the mod signing along with all the use statements? The goal is to minimize the number of #[cfg(feature = "signing")] :)

@@ -1,12 +1,17 @@
//! Ethereum Contract Interface

use crate::api::{Accounts, Eth, Namespace};
#[cfg(feature = "signing")]
Copy link
Owner

Choose a reason for hiding this comment

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

Could you please group all signing related things into a submodule here as well? Basically I'd like a single #[cfg(feature = "signing")] stament instead of sprinkling it all around.

src/signing.rs Outdated
use std::ops::Deref;

#[cfg(feature = "signing")]
Copy link
Owner

Choose a reason for hiding this comment

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

And here as well. Perhaps it's better to simply disable the entire signing.rs file?

@enolan
Copy link
Contributor Author

enolan commented Dec 6, 2020

Done. I decided against disabling the whole signing.rs file, since it has the keccak256 function which doesn't need secp256k1 and I didn't see an obvious place to move it to.

Copy link
Owner

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

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.

2 participants