Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

refactor(build): move the build:wasm one-liner into scripts/build-wasm.mjs

nirholas00a5d156fe6f
diff --git a/crates/vanity-grinder/README.md b/crates/vanity-grinder/README.md
index befb4e335..5abe8a07d 100644
--- a/crates/vanity-grinder/README.md
+++ b/crates/vanity-grinder/README.md
@@ -37,13 +37,29 @@ struct roughly doubles throughput in WASM.
```bash
cargo install wasm-pack # once
-wasm-pack build --release --target web
+npm run build:wasm # from the repo root
```
-Copy the artifacts from `pkg/` into `src/solana/vanity/wasm/` to update the
-module the site ships. The release profile pins `lto = "fat"`, a single
-codegen unit, and `wasm-opt -O3 --enable-simd`: keep those; the grinder's
-value is throughput.
+`npm run build:wasm` ([scripts/build-wasm.mjs](../../scripts/build-wasm.mjs))
+writes the artifacts straight into `src/solana/vanity/wasm/`, builds with
+`RUSTFLAGS='-C target-feature=+simd128'`, and restores that directory's
+README and `.gitignore`, both of which a bare `wasm-pack build` clobbers.
+The release profile pins `lto = "fat"`, a single codegen unit, and
+`wasm-opt -O3 --enable-simd`: keep those; the grinder's value is throughput.
`publish = false` is intentional: this crate is an internal build input, not a
published library.
+
+## Tests
+
+```bash
+cargo test
+```
+
+The native suite proves the "bit-for-bit identical" claim above against
+`ed25519-dalek` (dev-dependency only), and covers the secret-key layout,
+prefix/suffix/ignore-case matching, batch misses, and seed-counter
+wraparound. The JS side of the contract is covered by
+[tests/vanity-wasm-grinder.test.js](../../tests/vanity-wasm-grinder.test.js),
+which loads the checked-in artifact and cross-checks it against
+`@noble/curves`.
diff --git a/package.json b/package.json
index 0aaa6e45f..9d8c00b27 100644
--- a/package.json
+++ b/package.json
@@ -233,7 +233,7 @@
"prebuild": "node scripts/copy-three-decoders.mjs && (node scripts/build-news.mjs & node scripts/build-skill-metadata.mjs & node scripts/build-local-skill-packs.mjs & node scripts/build-discovery-cards.mjs & node scripts/build-guards.mjs & node scripts/build-atlas-index.mjs & node scripts/build-mcp-catalog.mjs & npm run build:examples & npm run build:docs-search & npm run build:club-assets & npm run build:walk-environments & wait) && node scripts/inject-blog-seo.mjs --write && node scripts/inject-hidden-guard.mjs --write && (node scripts/build-page-index.mjs && node scripts/audit-page-index.mjs --strict && node scripts/audit-empty-handlers.mjs && node scripts/audit-hidden-guard.mjs) && node scripts/i18n-annotate.mjs --apply --pages=\"public/news/*.html\" && node scripts/inject-seo-meta.mjs --write && node scripts/inject-theme-boot.mjs --write",
"seo:meta": "node scripts/inject-blog-seo.mjs --write && node scripts/build-page-index.mjs && node scripts/inject-seo-meta.mjs --write",
"build": "NODE_OPTIONS='--no-deprecation --max-old-space-size=6144' vite build && node scripts/strip-sw-from-embeds.mjs && node scripts/inject-tour-boot.mjs && node scripts/inject-atlas.mjs && node scripts/inject-inline-behaviors.mjs",
- "build:wasm": "PATH=\"$HOME/.cargo/bin:$PATH\" RUSTFLAGS='-C target-feature=+simd128' wasm-pack build crates/vanity-grinder --target web --release --out-dir ../../src/solana/vanity/wasm && printf '%s\\n' '# wasm-pack writes a default `*` gitignore that excludes everything.' '# Override it: the generated files in this directory ARE checked in so the' '# app builds without requiring a Rust toolchain at install time. Run' '# `npm run build:wasm` after editing /crates/vanity-grinder/src/lib.rs to' '# refresh these artifacts.' '!*' > src/solana/vanity/wasm/.gitignore",
+ "build:wasm": "node scripts/build-wasm.mjs",
"build:animations": "node scripts/build-animations.mjs && node scripts/sync-animation-registry.mjs && node scripts/build-motion-signatures.mjs",
"sync:animation-registry": "node scripts/sync-animation-registry.mjs",
"build:motion-signatures": "node scripts/build-motion-signatures.mjs",
diff --git a/scripts/build-wasm.mjs b/scripts/build-wasm.mjs
new file mode 100644
index 000000000..f38697a6b
--- /dev/null
+++ b/scripts/build-wasm.mjs
@@ -0,0 +1,114 @@
+#!/usr/bin/env node
+/**
+ * Build the Rust vanity-grinder crate to WASM and normalize the output dir.
+ *
+ * `npm run build:wasm` runs this. It wraps `wasm-pack build` and then fixes
+ * two things wasm-pack gets wrong for our layout, so the checked-in artifacts
+ * in src/solana/vanity/wasm/ are fully reproducible from one command:
+ *
+ * 1. wasm-pack writes a default `*` .gitignore that excludes everything.
+ * The artifacts ARE checked in (the app must build without a Rust
+ * toolchain at install time), so we override it with `!*`.
+ * 2. wasm-pack copies the crate's README.md into the out dir verbatim. That
+ * README's relative links only resolve from crates/vanity-grinder/, so we
+ * replace it with a README written for the out dir's actual location.
+ */
+
+import { spawnSync } from 'node:child_process';
+import { writeFileSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { join, delimiter } from 'node:path';
+
+const repoRoot = join(fileURLToPath(import.meta.url), '..', '..');
+const outDir = join(repoRoot, 'src', 'solana', 'vanity', 'wasm');
+
+const result = spawnSync(
+ 'wasm-pack',
+ [
+ 'build',
+ join(repoRoot, 'crates', 'vanity-grinder'),
+ '--target',
+ 'web',
+ '--release',
+ '--out-dir',
+ outDir,
+ ],
+ {
+ stdio: 'inherit',
+ env: {
+ ...process.env,
+ PATH: `${join(process.env.HOME || '', '.cargo', 'bin')}${delimiter}${process.env.PATH}`,
+ // simd128 must be enabled at rustc level too, not just in wasm-opt,
+ // or the hot loop compiles without SIMD and grinding throughput drops.
+ RUSTFLAGS: '-C target-feature=+simd128',
+ },
+ },
+);
+if (result.error) {
+ console.error('failed to launch wasm-pack (is it installed? `cargo install wasm-pack`)');
+ console.error(String(result.error));
+ process.exit(1);
+}
+if (result.status !== 0) process.exit(result.status ?? 1);
+
+writeFileSync(
+ join(outDir, '.gitignore'),
+ [
+ '# wasm-pack writes a default `*` gitignore that excludes everything.',
+ '# Override it: the generated files in this directory ARE checked in so the',
+ '# app builds without requiring a Rust toolchain at install time. Run',
+ '# `npm run build:wasm` after editing /crates/vanity-grinder/src/lib.rs to',
+ '# refresh these artifacts.',
+ '!*',
+ '',
+ ].join('\n'),
+);
+
+writeFileSync(
+ join(outDir, 'README.md'),
+ `# Generated WASM grinder
+
+This directory contains the wasm-bindgen output of [\`/crates/vanity-grinder\`](../../../../crates/vanity-grinder).
+
+**Do not edit by hand.** Edit the Rust source at \`crates/vanity-grinder/src/lib.rs\`,
+then regenerate with:
+
+\`\`\`bash
+npm run build:wasm
+\`\`\`
+
+The artifacts are checked into the repo so the app builds without a Rust
+toolchain at install time. CI only needs \`npm install\` + \`npm run build\`.
+This README and the \`.gitignore\` are rewritten by
+[scripts/build-wasm.mjs](../../../../scripts/build-wasm.mjs) after every
+build, because wasm-pack would otherwise clobber them.
+
+## Files
+
+- \`vanity_grinder.js\`: wasm-bindgen glue (default export \`init\`, named exports \`grind\`, \`initSync\`)
+- \`vanity_grinder_bg.wasm\`: the compiled WebAssembly module
+- \`vanity_grinder.d.ts\`: TypeScript declarations
+- \`vanity_grinder_bg.wasm.d.ts\`: low-level wasm imports declarations
+- \`package.json\`: generated package metadata (not published)
+
+## API
+
+\`\`\`ts
+import init, { grind } from './vanity_grinder.js';
+import wasmUrl from './vanity_grinder_bg.wasm?url';
+
+await init({ module_or_path: wasmUrl });
+
+const seed = new Uint8Array(32);
+crypto.getRandomValues(seed);
+const hit = grind(prefix, suffix, ignoreCase, batchSize, seed);
+// hit is either null or { secretKey: Uint8Array(64), publicKey: string }
+\`\`\`
+
+The 64-byte \`secretKey\` is Solana's standard layout
+(\`[32-byte seed][32-byte public key]\`), compatible with
+\`Keypair.fromSecretKey()\` in \`@solana/web3.js\`.
+`,
+);
+
+console.log('build:wasm done: artifacts, README, and .gitignore refreshed in src/solana/vanity/wasm/');