Skip to content

[wip] feat: Add WASM build target for browser integration#6

Closed
lukehalasy-anchorage wants to merge 14 commits intoanchorageoss:mainfrom
lukehalasy-anchorage:wasm-integration
Closed

[wip] feat: Add WASM build target for browser integration#6
lukehalasy-anchorage wants to merge 14 commits intoanchorageoss:mainfrom
lukehalasy-anchorage:wasm-integration

Conversation

@lukehalasy-anchorage
Copy link

@lukehalasy-anchorage lukehalasy-anchorage commented Dec 27, 2025

Summary

Testing

Browser test:

make clean-wasm
make build-wasm
cd cpp/wasm && python3 -m http.server 8000 ( or whatever port )
# Open http://localhost:8000/poc/test.html
image ```

🤖 Generated with Claude Code

- Add cmd/wasm/main.go with JavaScript-callable parseTransaction function
- Implement wasm/key_provider.go for in-memory credential management
- Implement wasm/http_client.go using JavaScript fetch API
- Compile to turnkey_client.wasm (6.1MB) for browser use

This enables calling Turnkey's VisualSign API directly from the browser
by compiling the turnkeyclient to WebAssembly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@lukehalasy-anchorage lukehalasy-anchorage changed the title feat: Add WASM build target for browser integration [wip] feat: Add WASM build target for browser integration Dec 27, 2025
lukehalasy-anchorage and others added 8 commits December 27, 2025 21:43
Replace the Go WASM implementation with a minimal C++ build using wasi-sdk,
reducing binary size from 6.1MB to <100KB while maintaining full functionality.

Changes:
- Remove Go WASM files (cmd/wasm/main.go, wasm/*.go)
- Add C++ WASM implementation in cpp/wasm/ directory
- Add Makefile targets for building and cleaning WASM artifacts
- Update README with WASM documentation and usage examples

The C++ approach uses wasi-sdk to produce a minimal WASI-compliant binary
without JavaScript runtime bloat, inspired by minimal WASM projects like
MiniLisp C++.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive proof-of-concept test suite for the C++ WASM module:
- Interactive browser test page (test.html)
- Node.js command-line test (test.js)
- Complete documentation (TEST_POC.md)
- ES6 module exports for browser compatibility

Testing shows successful WASM loading:
- File size: 413.67 KB (vs 6.1 MB Go WASM)
- Load time: ~4ms
- Memory: 16 MB linear memory allocation
- All exports validated including parseTransaction

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
lukehalasy-anchorage and others added 5 commits December 27, 2025 23:27
This change enables C++ code to call async JavaScript functions (fetch, crypto APIs)
as if they were synchronous by using Asyncify transformation.

Changes:
- build.sh: Apply asyncify transformation via wasm-opt before optimization
- js_glue.js: Convert js_fetch, js_sign_message, js_sha256 to async/await
- test.html: Fix WASM path to load from parent directory

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Replace hardcoded values throughout WASM code with compile-time constants for better maintainability and type safety.

- Add buffer size constants (SIGNATURE_BUFFER_SIZE, HTTP_RESPONSE_BUFFER_SIZE, etc.)
- Add API endpoint constants (API_BASE_URL, CREATE_SIGNABLE_PAYLOAD_PATH)
- Add JSON field name constants (UNSIGNED_PAYLOAD, CHAIN, SIGNABLE_PAYLOAD)
- Add crypto separator constants (STAMP_SEPARATOR, STAMP_FORMAT_SEPARATOR)
- Add HTTP header name constants (CONTENT_TYPE, X_ORG_ID, X_STAMP)
- Update all files to use new constants instead of magic numbers/strings

Benefits:
- Zero runtime cost (resolved at compile-time)
- Single source of truth for configuration
- Type-safe string literals
- Self-documenting code

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Replace remaining magic numbers and compile-time constants with constexpr
for better code clarity and optimization opportunities:
- Error message strings in main.cpp
- HTTP status codes and method names
- Hex encoding constants (width, chars per byte, base)
- JS fetch return codes

Fixes namespace qualification issues for json_fields constants.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Update POC test files to import from parent directory's js_glue.js
instead of maintaining a duplicate copy. This reduces code duplication
and PR line count by 260 lines.

Changes:
- Remove cpp/wasm/poc/js_glue.js (duplicate)
- Update test.js and test.html to import from ../js_glue.js
- Verified build still works with make build-wasm

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Move build logic from build.sh directly into Makefile to reduce
code duplication and PR line count. This saves 75 lines while
maintaining identical functionality.

Changes:
- Remove cpp/wasm/build.sh
- Inline all build commands into Makefile build-wasm target
- Add prerequisite documentation in comments (wasi-sdk, wasm-opt)
- Verified build works with make build-wasm (produces 809KB WASM)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@prasanna-anchorage prasanna-anchorage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually you can do the http calls using standard JavaScript and only verification needs to be done with WASM. This is re-implementing everything in C++ instead of compiling to WASM target from the same Go codebase that I had in #2

@lukehalasy-anchorage lukehalasy-anchorage deleted the wasm-integration branch December 28, 2025 03:34
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