Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ Requires a working Haskell environment and RocksDB development files:
cabal install
```

## WASM Outputs With Nix

The flake exports both the combined WASM bundle and the individual modules:

```bash
nix build .#wasm-artifacts
nix build .#csmt-verify-wasm
nix build .#csmt-write-wasm
nix build .#mpf-verify-wasm
nix build .#mpf-write-wasm
```

It also exports runnable local preview commands for the static demo bundles:

```bash
PORT=8000 nix run .#csmt-verify-wasm-demo
PORT=8001 nix run .#csmt-wasm-write-demo
PORT=8002 nix run .#mpf-wasm-write-demo
PORT=8003 nix run .#docs
```

## CLI Tool

The `mts` executable provides an interactive CLI for CSMT operations:
Expand Down
22 changes: 22 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ Or via cabal provided you have a working Haskell environment and rocksdb develop
cabal install
```

## WASM Outputs And Preview Commands

The flake exports the combined browser-WASM bundle plus one package per
module:

```bash
nix build .#wasm-artifacts
nix build .#csmt-verify-wasm
nix build .#csmt-write-wasm
nix build .#mpf-verify-wasm
nix build .#mpf-write-wasm
```

It also exports local preview commands for each static bundle:

```bash
PORT=8000 nix run .#csmt-verify-wasm-demo
PORT=8001 nix run .#csmt-wasm-write-demo
PORT=8002 nix run .#mpf-wasm-write-demo
PORT=8003 nix run .#docs
```

## Start With The Tutorials

Once the project builds, the fastest way to understand the current
Expand Down
2 changes: 2 additions & 0 deletions docs/wasm-demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ exit code `1` means it does not (or the input was malformed).
## Build it yourself

```bash
nix build .#csmt-verify-wasm
nix build .#csmt-verify-wasm-demo
PORT=8000 nix run .#csmt-verify-wasm-demo
```

The output is a plain tree of static files suitable for copying
Expand Down
12 changes: 12 additions & 0 deletions docs/wasm-mpf-demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ That matches the merged Aiken-parity exclusion-proof work: the browser
transport reuses the canonical proof-step format instead of introducing
a second exclusion-proof encoding.

## What the demo ships

- `mpf-write.wasm` - the write entry point exported via
`nix build .#mpf-write-wasm`
- `mpf-verify.wasm` - the pure Aiken-compatible verifier exported via
`nix build .#mpf-verify-wasm`
- `index.html` + `write.js` - the static page that runs both modules
under `@bjorn3/browser_wasi_shim`

## Workflow

1. Insert or delete key/value pairs and watch the MPF root update.
Expand Down Expand Up @@ -73,7 +82,10 @@ do not carry the query context:
## Build it yourself

```bash
nix build .#mpf-write-wasm
nix build .#mpf-verify-wasm
nix build .#mpf-wasm-write-demo
PORT=8002 nix run .#mpf-wasm-write-demo
```

The result is a static directory containing `index.html`, `write.js`,
Expand Down
8 changes: 6 additions & 2 deletions docs/wasm-write-demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ them against the root - happens inside sandboxed WASM.
## What the demo ships

- `csmt-write.wasm` - the write entry point produced by
`wasm32-wasi-cabal` via `nix build .#csmt-wasm-write-demo`. It takes
`wasm32-wasi-cabal` via `nix build .#csmt-write-wasm`. It takes
a prior `InMemoryDB` blob, a batch of inserts/deletes, and a query
key; it returns the updated blob, the post-mutation root, and either
an inclusion proof or an exclusion proof.
- `csmt-verify.wasm` - the existing verifier, reused by the page to
independently re-check each proof it produces.
independently re-check each proof it produces, exported via
`nix build .#csmt-verify-wasm`.
- `index.html` + `write.js` - the static page that drives both modules
under `@bjorn3/browser_wasi_shim`.

Expand Down Expand Up @@ -63,7 +64,10 @@ no host-side translation is needed.
## Build it yourself

```bash
nix build .#csmt-write-wasm
nix build .#csmt-verify-wasm
nix build .#csmt-wasm-write-demo
PORT=8001 nix run .#csmt-wasm-write-demo
```

The output is a plain tree of static files suitable for any static
Expand Down
48 changes: 19 additions & 29 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,24 @@
null;

wasmPackages = if wasmBuild != null then
let
demo = import ./nix/wasm-demo.nix {
inherit pkgs;
wasm = wasmBuild.wasm;
fixtures = ./verifiers/typescript/test/fixtures.json;
};
writeDemo = import ./nix/wasm-write-demo.nix {
inherit pkgs;
wasm = wasmBuild.wasm;
};
mpfWriteDemo = import ./nix/mpf-wasm-write-demo.nix {
inherit pkgs;
wasm = wasmBuild.wasm;
};
composedDocs = import ./nix/docs.nix {
inherit pkgs;
src = ./.;
mkdocsAssets = mkdocs.outPath;
verifyDemo = demo;
writeDemo = writeDemo;
mpfWriteDemo = mpfWriteDemo;
};
in {
csmt-verify-wasm = wasmBuild.wasm;
csmt-verify-wasm-deps = wasmBuild.deps;
csmt-verify-wasm-demo = demo;
csmt-wasm-write-demo = writeDemo;
mpf-wasm-write-demo = mpfWriteDemo;
docs = composedDocs;
import ./nix/wasm-packages.nix {
inherit pkgs wasmBuild;
src = ./.;
mkdocsAssets = mkdocs.outPath;
fixtures = ./verifiers/typescript/test/fixtures.json;
}
else
{ };

wasmApps = if wasmBuild != null then
import ./nix/apps.nix {
inherit pkgs;
demos = lib.getAttrs [
"docs"
"csmt-verify-wasm-demo"
"csmt-wasm-write-demo"
"mpf-wasm-write-demo"
] wasmPackages;
}
else
{ };
Expand All @@ -122,6 +111,7 @@

in {
packages = fullPackages // { default = fullPackages.mts; };
apps = wasmApps;
inherit (project) devShells;
};

Expand Down
27 changes: 27 additions & 0 deletions nix/apps.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ pkgs, demos }:
let
mkStaticSiteApp = name: root:
let
server = pkgs.writeShellApplication {
name = "serve-${name}";
runtimeInputs = [ pkgs.python3 ];
text = ''
host=''${HOST:-127.0.0.1}
port=''${PORT:-8000}
echo "Serving ${name} at http://$host:$port/"
exec python -m http.server "$port" --bind "$host" --directory ${root}
'';
};
in {
type = "app";
program = pkgs.lib.getExe server;
};
in {
docs = mkStaticSiteApp "docs" demos.docs;
csmt-verify-wasm-demo =
mkStaticSiteApp "csmt-verify-wasm-demo" demos.csmt-verify-wasm-demo;
csmt-wasm-write-demo =
mkStaticSiteApp "csmt-wasm-write-demo" demos.csmt-wasm-write-demo;
mpf-wasm-write-demo =
mkStaticSiteApp "mpf-wasm-write-demo" demos.mpf-wasm-write-demo;
}
41 changes: 41 additions & 0 deletions nix/wasm-packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{ pkgs, src, mkdocsAssets, fixtures, wasmBuild }:
let
mkWasmModule = pname: file:
pkgs.runCommand pname {
preferLocalBuild = true;
} ''
mkdir -p $out
cp ${wasmBuild.wasm}/${file} $out/${file}
'';

verifyDemo = import ./wasm-demo.nix {
inherit pkgs fixtures;
wasm = wasmBuild.wasm;
};
writeDemo = import ./wasm-write-demo.nix {
inherit pkgs;
wasm = wasmBuild.wasm;
};
mpfWriteDemo = import ./mpf-wasm-write-demo.nix {
inherit pkgs;
wasm = wasmBuild.wasm;
};
docs = import ./docs.nix {
inherit pkgs src;
inherit mkdocsAssets;
inherit verifyDemo writeDemo mpfWriteDemo;
};
in {
wasm-artifacts = wasmBuild.wasm;
wasm-artifacts-deps = wasmBuild.deps;

csmt-verify-wasm = mkWasmModule "csmt-verify-wasm" "csmt-verify.wasm";
csmt-write-wasm = mkWasmModule "csmt-write-wasm" "csmt-write.wasm";
mpf-verify-wasm = mkWasmModule "mpf-verify-wasm" "mpf-verify.wasm";
mpf-write-wasm = mkWasmModule "mpf-write-wasm" "mpf-write.wasm";

csmt-verify-wasm-demo = verifyDemo;
csmt-wasm-write-demo = writeDemo;
mpf-wasm-write-demo = mpfWriteDemo;
inherit docs;
}
Loading