shesek / spark-wallet

⚡️ A minimalistic wallet GUI for c-lightning, accessible over the web or through mobile and desktop apps.
MIT License
344 stars 76 forks source link

Allow looking up the price through tor #78

Closed jonasnick closed 5 years ago

jonasnick commented 5 years ago

Hey, I've been trying to wrap spark-wallet in torsocks to only allow outbound connections through tor, in particular getting the price from bitstamp. However, I'm getting the following error:

$ torsocks spark-wallet --ln-path /var/lib/clightning/
1556879472 WARNING torsocks[31447]: [syscall] Unsupported syscall number 293. Denying the call (in tsocks_syscall() at syscall.c:568)
1556879472 WARNING torsocks[31447]: [syscall] Unsupported syscall number 292. Denying the call (in tsocks_syscall() at syscall.c:568)
Connected to c-lightning v0.7.0 with id 03c6467e1eeb4076cf22c44ffefbe8cd9ea32513be7886bb7e2677934c353dfcf2 on network bitcoin at /var/lib/clightning/lightning-rpc
Loading login credentials from /root/.spark-wallet/cookie

HTTP server running on http://localhost:9737
Error: Forbidden
    at Request.callback (/nix/store/3mghavqs65nqckif57py60ws1v2vpij7-node-spark-wallet-0.2.5/lib/node_modules/spark-wallet/node_modules/superagent/lib/node/index.js:706:15)
    at IncomingMessage.parser (/nix/store/3mghavqs65nqckif57py60ws1v2vpij7-node-spark-wallet-0.2.5/lib/node_modules/spark-wallet/node_modules/superagent/lib/node/index.js:916:18)
    at IncomingMessage.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Spark wallet works as usual, but my wallet balance (in usd) remains n/a. I've been trying to debug this, but I have no idea why it shouldn't just work. So I'm wondering if superagent does something fancy in the background.

shesek commented 5 years ago

How about I add support for a configurable proxy (via superagent-proxy) instead of using a transparent proxy?

shesek commented 5 years ago

So... I added support for setting explicit proxy configuration (https://github.com/shesek/spark-wallet/commit/e5cd4e5a23a70e2f0fd3ce2b825e496a41c413a8, using the HTTPS_PROXY/ALL_PROXY environment variables), but the cause of this issue is that Bitstamp are apparently blocking requests from Tor.

This is what I get when trying to access https://www.bitstamp.net/api/v2/ticker/btcusd using the Tor browser:

canvas

It looks like the only solution is to fetch rates from someplace else, that doesn't block tor. Any suggestions?

jonasnick commented 5 years ago

Thanks! And wow, how annoying... kraken requires cloudflare authentication too.

curl -X POST -d "pair=XBTUSD" https://api.kraken.com/0/public/Ticker | jq -r ".result .XXBTZUSD .c [0]"

doesn't work if you prepend torsocks. Perhaps another service to add to blockstream.info? :)

jonasnick commented 5 years ago

Wasabi Wallet provides an API for the USD rate :grimacing:

torsocks curl -X GET "http://wasabiukrxmkdgve5kynjztuovbg43uxcbcxn6y2okcrsg7gb6jdmbad.onion/api/v3/btc/Offchain/exchange-rates" -H "accept: application/json"                                                                                                                                                  
[{"ticker":"USD","rate":7272.75}]

(see https://wasabiwallet.io/swagger/index.html)

shesek commented 5 years ago

Great find! Implemented in 485b0c13792c8f812e6c12110e0518992a1b9953, should work if you start spark with spark-wallet --rate-provider wasabi --all-proxy socks5h://127.0.0.1:9150 (or use a transparent proxy with torsocks instead of all-proxy).

Still not released, though. I hope to release a new version sometime in the next few days (requires fixing #79 first).

jonasnick commented 5 years ago

Thanks! will try this out once released.

shesek commented 5 years ago

v0.2.6 was released with support for wasabi as the exchange rate provider and for setting a proxy. I also aliased --all-proxy as simply --proxy.

jonasnick commented 5 years ago

Thank you