danhper / eclair

A Solidity interpreter
https://eclair.so
MIT License
50 stars 1 forks source link

Support extension wallets by serving a website on localhost #18

Open artistic709 opened 2 months ago

artistic709 commented 2 months ago

Added a way to connect extension wallets: using a localhost web server to forward signature requests to the browser.

danhper commented 2 months ago

Hi @artistic709 , Could you elaborate a bit on the use case you have in mind please? There is a plan to run anvil on localhost to be able to fork etc, which would make it possible to connect eclair and the browser wallet to the same development node. Is it what you have in mind?

artistic709 commented 2 months ago

Hi @danhper , this is the scenario I'm considering: I want to send transactions in production environment via command line. Rather than using a hardware wallet or importing a private key, I would prefer to use, say, a MetaMask account to sign transactions.

danhper commented 2 months ago

Ahhh, I see, that makes sense! In theory this is definitely doable but it might be a bit of work, especially given that alloy does not seem to support anything like this out of the box.

I think that the flow could look like:

  1. Spin up an http server to serve a very simple webpage (the page doesn't really need to do anything)
  2. Spin up a websocket server to communicate between eclair and the webpage
  3. Connect from the webpage to eclair's websocket server
  4. When eclair needs to sign something, send a request to the webpage via ws
  5. Request the signature from metamask and sent it back to eclair via ws
  6. Send the signed tx in eclair

This does look like a fun little project but there are a few things I'll be prioritising before it, so I can't really give a timeline for when I think it might be ready. If you'd like to give it a shot, I'm of course more than open to contributions! Thanks again for the idea!

artistic709 commented 2 months ago

Yeah I think that will be really helpful for advanced users. Unfortunately I don't write Rust, but I can make a proof of concept in Python + vanilla JS.

BTW the 5th and 6th steps might not work because it's very difficult (if not impossible) to ask MetaMask to sign a raw transaction. Instead, we'll just let MetaMask broadcast the tx and wait for the txid to come back.

danhper commented 2 months ago

I see, thanks for the explanation! Yeah, then the transaction would be sent by metamask and the txid would be sent back to eclair via websocket. A proof-of-concept would be super helpful and the JS part could be used directly, so that would definitely be very welcome, thanks!