Skip to content

Commit 5ee590e

Browse files
committed
docs: add WebAssembly README file
1 parent 49e04a9 commit 5ee590e

File tree

2 files changed

+86
-30
lines changed

2 files changed

+86
-30
lines changed

README.md

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,25 @@ A collection of cryptography primitives written in Rust.
1111
This library contains primarily the following cryptographic primitives:
1212

1313
- The Tip5 hash function
14-
- [The Tip5 Hash Function for Recursive STARKs](https://eprint.iacr.org/2023/107)
14+
- [The Tip5 Hash Function for Recursive STARKs](https://eprint.iacr.org/2023/107)
1515
- Lattice-crypto
16-
- arithmetic for the quotient ring $\mathbb{F}_ p[X] / \langle X^{64} + 1 \rangle$
17-
- arithmetic for modules over this quotient ring
18-
- a IND-CCA2-secure key encapsulation mechanism
19-
- [Lattice-Based Cryptography in Miden VM](https://eprint.iacr.org/2022/1041)
16+
- arithmetic for the quotient ring $\mathbb{F}_ p[X] / \langle X^{64} + 1 \rangle$
17+
- arithmetic for modules over this quotient ring
18+
- a IND-CCA2-secure key encapsulation mechanism
19+
- [Lattice-Based Cryptography in Miden VM](https://eprint.iacr.org/2022/1041)
2020
- `BFieldElement`, `XFieldElement`
21-
- The prime-field type $\mathbb{F}_p$ where $p = 2^{64} - 2^{32} + 1$
22-
- The extension field $\mathbb{F}_p[x]/(x^3 - x + 1)$
23-
- A codec trait for encoding and decoding structs as `Vec`s of `BFieldElement`
24-
- [An efficient prime for number-theoretic transforms](https://cp4space.hatsya.com/2021/09/01/an-efficient-prime-for-number-theoretic-transforms/)
21+
- The prime-field type $\mathbb{F}_p$ where $p = 2^{64} - 2^{32} + 1$
22+
- The extension field $\mathbb{F}_p[x]/(x^3 - x + 1)$
23+
- A codec trait for encoding and decoding structs as `Vec`s of `BFieldElement`
24+
- [An efficient prime for number-theoretic transforms](https://cp4space.hatsya.com/2021/09/01/an-efficient-prime-for-number-theoretic-transforms/)
2525
- NTT
26-
- Number Theoretic Transform (discrete Fast Fourier Transform)
27-
- [Anatomy of a STARK, Part 6: Speeding Things Up](https://neptune.cash/learn/stark-anatomy/faster/)
28-
- Univariate and multivariate polynomials
26+
- Number Theoretic Transform (discrete Fast Fourier Transform)
27+
- [Anatomy of a STARK, Part 6: Speeding Things Up](https://neptune.cash/learn/stark-anatomy/faster/)
28+
- Univariate polynomials
2929
- Merkle Trees
3030
- Merkle Mountain Ranges
3131

32-
## Release protocol
32+
## Wasm support
3333

34-
While twenty-first's version is `0.x.y`, releasing a new version:
35-
36-
1. Is the release backwards-compatible?
37-
Then the new version is `0.x.y+1`. Otherwise the new version is `0.x+1.0`.
38-
2. Checkout the last commit on Mjolnir, and run `make bench-publish`. Save the benchmark's result
39-
and verify that there is no performance degradation.
40-
3. Create a commit that increases `version = "0.x.y"` in twenty-first/Cargo.toml.
41-
The commit message should give a one-line summary of each release change. Include the benchmark
42-
result at the bottom.
43-
4. Have a `v0.x.y` [git tag][tag] on this commit created. (`git tag v0.x.y [sha]`, `git push upstream --tags`)
44-
5. Have this commit `cargo publish`ed on [crates.io][crates] and in GitHub [tags][tags].
45-
46-
[tag]: https://git-scm.com/book/en/v2/Git-Basics-Tagging
47-
[tags]: https://github.com/Neptune-Crypto/twenty-first/tags
48-
[crates]: https://crates.io/crates/twenty-first/versions
49-
50-
If you do not have the privilege to create git tags or run `cargo publish`, submit a PR and the merger will take care of these.
34+
The `twenty-first` library can be built for WebAssembly. See the [dedicated readme](twenty-first/README-wasm32.md) for
35+
further information.

twenty-first/README-wasm32.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Building and Testing `twenty-first` for wasm32
2+
3+
This document provides instructions on how to build and test the `twenty-first` crate for the `wasm32-unknown-unknown`
4+
target, which allows the library to run in WebAssembly environments.
5+
6+
## What is wasm32?
7+
8+
WebAssembly (Wasm) is a binary instruction format for a stack-based virtual machine. The `wasm32-unknown-unknown` target
9+
allows Rust code to be compiled into Wasm, enabling high-performance applications to run directly in web browsers and
10+
other Wasm-compatible environments. This is ideal for bringing computationally intensive tasks, like the cryptographic
11+
operations in `twenty-first`, to the web without sacrificing performance.
12+
13+
For more detailed information, see the official [WebAssembly website](https://webassembly.org/).
14+
15+
## Required Tools and Setup
16+
17+
To build and test for `wasm32`, you need to set up your Rust environment with the correct target and tooling.
18+
19+
### Add the `wasm32` Target
20+
21+
First, add the `wasm32-unknown-unknown` target to your Rust toolchain using `rustup`:
22+
23+
```shell
24+
rustup target add wasm32-unknown-unknown
25+
```
26+
27+
### Install `wasm-pack`
28+
29+
`wasm-pack` is the primary tool for building, testing, and publishing Rust-generated WebAssembly. It coordinates the
30+
build process and handles the interaction with other tools like `wasm-bindgen`.
31+
32+
Install `wasm-pack` using `cargo`:
33+
34+
```shell
35+
cargo install wasm-pack
36+
```
37+
38+
### Install Node.js (for Testing)
39+
40+
Running the `wasm32` test suite requires a JavaScript runtime. `wasm-pack` uses Node.js for this purpose.
41+
42+
You must have Node.js v20 (LTS) or later installed. The `getrandom` crate, a dependency for our tests, requires the Web
43+
Crypto API, which is stable and fully supported in all modern LTS releases of Node.js.
44+
45+
You can download Node.js from the [official Node.js website](https://nodejs.org/) or install it using a version manager
46+
like `nvm`.
47+
48+
## Build and Test Commands
49+
50+
With the environment configured, you can now build and test the crate. Make sure your current working directory is
51+
`twenty-first/twenty-first` before executing any of the commands below.
52+
53+
### Build the Crate
54+
55+
To compile the `twenty-first` crate for WebAssembly, run the following command:
56+
57+
```shell
58+
wasm-pack build --target nodejs
59+
```
60+
61+
This command compiles the crate and generates the necessary JavaScript bindings, placing the output in a `pkg/`
62+
directory.
63+
64+
### Run Tests
65+
66+
To run the test suite for the `wasm32` target, use the `test` command from `wasm-pack`. This command will compile the
67+
tests and execute them using your installed Node.js runtime.
68+
69+
```shell
70+
wasm-pack test --node
71+
```

0 commit comments

Comments
 (0)