Skip to content

Commit

Permalink
Add EIP-1193 support (#414)
Browse files Browse the repository at this point in the history
* Put signing behind an optional feature

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.

* Add EIP-1193 support

* Add eth_requestAccounts method

* 'cargo check' EIP-1193 code in Travis

* Clean up the feature gates a little

* Style cleanup in eip_1193.rs

* remove meaningless #[wasm_bindgen] attribute

* Refactor translating events from JS

* Replace some Error::Internals with panics with useful messages

* rename get_default -> default

* Refactor error handling in request_wrapped

* clean up EIP-1193 listeners on Drop

* Add support for more EIP-1193 events

* Reduce the number of #[cfg(feature = "signing")] attributes a bit more
  • Loading branch information
enolan authored Dec 7, 2020
1 parent 9bcfa4b commit 1818294
Show file tree
Hide file tree
Showing 8 changed files with 688 additions and 336 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ before_script:
- if [[ "${TRAVIS_RUST_VERSION}" == stable ]]; then
rustup component add rustfmt && cargo install cargo-deny;
fi
- rustup target add wasm32-unknown-unknown

script:
- if [[ "${TRAVIS_RUST_VERSION}" == "stable" ]]; then
Expand All @@ -42,6 +43,7 @@ script:
- cargo build
- cargo test
- cargo check --no-default-features
- cargo check --target wasm32-unknown-unknown --no-default-features --features eip-1193
- cargo check --no-default-features --features http
- cargo check --no-default-features --features http-tls
- cargo check --no-default-features --features ws-tokio
Expand Down
12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ log = "0.4.6"
parking_lot = "0.11.0"
rlp = "0.4"
rustc-hex = "2.1.0"
secp256k1 = { version = "0.19", features = ["recovery"] }
secp256k1 = { version = "0.19", features = ["recovery"], optional = true }
serde = { version = "1.0.90", features = ["derive"] }
serde_json = "1.0.39"
tiny-keccak = { version = "2.0.1", features = ["keccak"] }
Expand All @@ -44,16 +44,24 @@ soketto = { version = "0.4.1", optional = true }
## Shared (WS, HTTP)
native-tls = { version = "0.2", optional = true }
url = { version = "2.1", optional = true }
## EIP-1193
js-sys = { version = "0.3.45", optional = true }
### This is a transitive dependency, only here so we can turn on its wasm_bindgen feature
rand = { version = "0.7.3", optional = true }
wasm-bindgen = { version = "0.2.68", optional = true, features = ["serde-serialize"] }
wasm-bindgen-futures = { version = "0.4.18", optional = true }

[dev-dependencies]
# For examples
env_logger = "0.8"
tokio = { version = "0.2", features = ["full"] }

[features]
default = ["http-tls", "ws-tls-tokio"]
default = ["http-tls", "signing", "ws-tls-tokio"]
eip-1193 = ["js-sys", "wasm-bindgen", "wasm-bindgen-futures", "futures-timer/wasm-bindgen", "rand/wasm-bindgen"]
http = ["hyper", "hyper-proxy", "url", "base64", "typed-headers"]
http-tls = ["hyper-tls", "native-tls", "http"]
signing = ["secp256k1"]
ws-tokio = ["soketto", "url", "tokio", "tokio-util"]
ws-async-std = ["soketto", "url", "async-std"]
ws-tls-tokio = ["async-native-tls", "native-tls", "async-native-tls/runtime-tokio", "ws-tokio"]
Expand Down
Loading

0 comments on commit 1818294

Please sign in to comment.