Skip to content

feat: add support for wasm#36

Open
HerringtonDarkholme wants to merge 1 commit intoelliottech:mainfrom
HerringtonDarkholme:main
Open

feat: add support for wasm#36
HerringtonDarkholme wants to merge 1 commit intoelliottech:mainfrom
HerringtonDarkholme:main

Conversation

@HerringtonDarkholme
Copy link
Copy Markdown
Contributor

Hi lighter team, this pull request enables wasm build for host like JavaScript to use.

The change is mainly

  • type cast change
  • argument addition, matching the sharelib implementation

Other than that, the wasm build also introduces a new global variable chainId that reflects the same architecture of sharelib version.

That means the wasm user will have to use the lib in a single-threaded way, which is quite common in JS world

@alexvelea
Copy link
Copy Markdown
Collaborator

@Bvvvp009 could you take a look at this please?
also @HerringtonDarkholme , feel free to ping on Discord in the api-trading-chat as well if you have not.

@alexvelea
Copy link
Copy Markdown
Collaborator

I think your changes make sense @HerringtonDarkholme
I'd reffer to @Bvvvp009 if he has anything else to add to make the wasm spot-ready
The memo change, to support hex encoded which I've added recently would be an example
Unsure if other things have changed TBH

lavrric pushed a commit that referenced this pull request Mar 12, 2026
* add support for wasm

* feat: complete WASM support to match CGO/sharedlib implementation

- Add global chainId variable and use it in messageToSign for L2TransferTxInfo
- Add encoding/hex import for memo hex decoding
- Update SignTransfer: add argument validation, complete memo hex encoding support
- Fix SignCancelOrder: use safeInt16 for MarketIndex type safety
- Ensure all MarketIndex uses int16 (not uint8) to support spot markets (2048+)
- Match sharedlib implementation exactly for full WASM parity

This completes PR #36 by adding the remaining changes needed for full WASM support
that matches the CGO/sharedlib implementation.

* fix: complete WASM type fixes to match CGO exactly

- Add safeUint64() and safeUint16() helper functions for type-safe extraction
- Fix SignCreatePublicPool: minOperatorShareRate now uses uint16 (was int64)
- Fix SignUpdatePublicPool: publicPoolIndex now uses int64 (was uint8) and minOperatorShareRate uses uint16 (was int64)
- Optimize SignWithdraw: use direct uint64 extraction instead of int64 conversion

All type conversions now match CGO/sharedlib implementation exactly.
All 19 exported functions verified and correct.

* fix nonce handling

* Revert "fix nonce handling"

This reverts commit 0d49812.

---------

Co-authored-by: HerringtonDarkholme <2883231+HerringtonDarkholme@users.noreply.github.com>
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