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

Support WASM #90

Open
danielgranhao opened this issue Feb 19, 2025 · 9 comments · May be fixed by #91
Open

Support WASM #90

danielgranhao opened this issue Feb 19, 2025 · 9 comments · May be fixed by #91

Comments

@danielgranhao
Copy link
Contributor

danielgranhao commented Feb 19, 2025

At Breez, we are interested in supporting WASM in the Nodeless SDK. The SDK depends on boltz-rust, which isn't compatible right now due to dependencies on:

  • ureq to access Boltz API
  • electrum-client for accessing blockchain data
  • tungstenite for the WebSocket status stream
  • secp256k1-zkp

We’d like to discuss possible approaches to enable WASM support while keeping the existing functionality intact.

Potential solutions:

  • Accessing Boltz API
    • Solution can be as simple as switching to reqwest. It implements WASM support by simply mapping requests to the browser's fetch API. We could switch to reqwest or allow the selection of the http client through features.
  • Access to blockchain data
    • This seems like the most challenging part. One option is for the crate to offload communication to the client. An alternative is to add esplora as a possible backend since it's based on http.
  • Status stream
    • There are several crates that could be used for websockets on WASM. gloo-net seems like a good option.
  • secp256k1-zkp
    • The fix here is simple and can be applied directly on the fork currently in use. Just needs the changes from this PR and from this commit.

Would love to hear your thoughts on these approaches to see if we can proceed with the corresponding contributions.

@danielgranhao
Copy link
Contributor Author

To support WASM, the crate's API will need to become async due to the browser being natively async. AFAICT there is no good way of bridging it to the current (blocking) interface. Is there a known, specific need for a blocking interface from existing users of boltz-rust? If there is, one solution might be to offer a separate blocking version (similar to reqwest).

@michael1011
Copy link
Collaborator

michael1011 commented Feb 21, 2025

Why would it have to be async? You can WASM bind blocking functions just fine: https://github.com/BoltzExchange/bolt12-wasm/blob/master/src/lib.rs#L28

@danielgranhao
Copy link
Contributor Author

The issue isn't exposing binds for blocking functions. It's about using the browser's fetch API to make HTTP requests.

@michael1011
Copy link
Collaborator

Yes, everything network related will have to be made async, which I thought was implied by your suggestion to switch from ureq to reqwest. I am fine with that, but what about the Dart bindings @i5hi?

@i5hi
Copy link
Collaborator

i5hi commented Feb 22, 2025

async should not be an issue for the dart bindings.

@i5hi
Copy link
Collaborator

i5hi commented Feb 22, 2025

Regarding secp256k1-zkp, we are currently using a specific branch for Musig* structures:

secp256k1-zkp = {git = "https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git", rev = "60e631c24588a0c9e271badd61959294848c665d"}

Not sure if this has been merged yet.

@i5hi
Copy link
Collaborator

i5hi commented Feb 22, 2025

Regarding Access to Blockchain data - we can indeed separate all electrum calls from the core methods. Rather than offloading to the client we can move it to a separate file under a feature and let it return the specific types required by the core swap methods.

@i5hi
Copy link
Collaborator

i5hi commented Feb 22, 2025

Changing the the websocket server is not an issue at all.

@michael1011
Copy link
Collaborator

Regarding secp256k1-zkp, we are currently using a specific branch for Musig* structures:
Not sure if this has been merged yet.

@danielgranhao could you try to upstream your changes to secp256k1-zkp? I would like to avoid having to maintain a fork where we cherry pick the changes we need

@danielgranhao danielgranhao linked a pull request Feb 26, 2025 that will close this issue
2 tasks
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 a pull request may close this issue.

3 participants