@orieg/expanse-wasm

中文文档
0.17.0发布于 2026/11/02MIT OR Apache-2.0TypeScriptES Module零依赖构建来源已验证

WebAssembly bindings for Expanse: clean-room, pure-Rust Judy arrays for browser and edge runtimes

原始使用文档
文档目录4 节
  1. Installation
  2. Quickstart
  3. WebAssembly Memory64 ( wasm64-unknown-unknown ) Support
  4. Interactive In-Browser Speed Arena

@orieg/expanse-wasm

WebAssembly bindings for expanse-trie. Suitable for Edge runtimes (Cloudflare Workers, Fastly, Deno Deploy, Vercel) and modern browsers.

Installation

npm install @orieg/expanse-wasm

Quickstart

import { WasmExpanseSet, init_panic_hook } from '@orieg/expanse-wasm';

// Initialize panic hook for better error messages
init_panic_hook();

const set = new WasmExpanseSet();
set.add(42n);
console.log(set.contains(42n)); // true

Backed by the digital trie:

  • WasmExpanseSet32: 32-bit digital trie set with batch execution methods
  • WasmExpanseMap32: 32-bit digital trie map with batch execution methods
  • WasmExpanseSet, WasmExpanseMap: the 64-bit engine on wasm64; a BTreeMap / BTreeSet fallback on wasm32, where the 64-bit engine does not exist

Not backed by the engine — BTreeMap placeholders (#757):

  • WasmExpanseStrMap: String to u64 map
  • WasmExpanseBytesMap: &[u8] to u64 map
  • WasmExpanseBlobMap: u64 to &[u8] map with hot metadata

These three carry Expanse* names but are std::collections::BTreeMap. They have none of the trie's memory profile, mem_used accounting or node structure, and a figure measured through them says nothing about the engine. Nothing published depends on them: every WASM row in docs/BINDINGS_BENCHMARKS.md and every arm in scripts/wasm_fuel.py is scoped to WasmExpanseMap32 / WasmExpanseSet32.

They are placeholders rather than wrappers because the engine types they are named for — ExpanseStrMap, ExpanseBytesMap, ExpanseBlobMap — are #[cfg(target_pointer_width = "64")] and have no 32-bit twin, so they do not exist on wasm32. ExpanseBlobMap32 does exist, but takes no chunk size and uses 32-bit keys, so adopting it would narrow this class's published API without gaining the arena the name implies.

WasmExpanseBlobMap's constructor rejects a chunk_size argument rather than accepting and discarding it: there is no arena to size.

WebAssembly Memory64 (wasm64-unknown-unknown) Support

Expanse supports 64-bit WebAssembly linear memory (Memory64), allowing the full 64-bit raw pointer engine (ExpanseMap, ExpanseSet, 16-byte Edge descriptors) to run directly inside WebAssembly runtimes supporting 64-bit memory spaces (e.g. Node.js with --experimental-wasm-memory64 or modern V8 / Wasm runtimes).

To build for wasm64-unknown-unknown:

cargo +nightly build -p expanse-wasm --target wasm64-unknown-unknown -Z build-std=std,panic_abort

To run the Node.js Memory64 runtime smoke test:

node crates/expanse-wasm/tests/test_wasm64_smoke.js

Interactive In-Browser Speed Arena

An interactive client-side benchmark comparing WasmExpanseMap32 against Rust BTreeMap and native JavaScript Map is included in examples/speed_arena.html.

To run locally:

wasm-pack build crates/expanse-wasm --target web --out-dir crates/expanse-wasm/examples/pkg
python3 -m http.server 8080 --directory crates/expanse-wasm/examples

Open http://localhost:8080/speed_arena.html.

版本与发布记录

@orieg/expanse-wasm 共发布 24 个版本,首次发布于 2026/08/26;过去 12 个月发布了 24 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.17.0latest2026/11/021 天前
0.16.02026/10/268 天前
0.15.02026/10/2014 天前
0.14.02026/10/1816 天前
0.13.02026/10/1519 天前
0.12.02026/10/1321 天前

关于 @orieg/expanse-wasm 的常见问题

@orieg/expanse-wasm 是什么?

用于以太坊的WebAssembly绑定:用于浏览器和边缘运行时的纯rust Judy数组

如何安装 @orieg/expanse-wasm?

在项目目录运行 npm install @orieg/expanse-wasm,或使用 pnpm add / yarn add / bun add。

@orieg/expanse-wasm 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@orieg/expanse-wasm 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@orieg/expanse-wasm 可以商用吗?

@orieg/expanse-wasm 使用 MIT OR Apache-2.0 许可。可在 MIT、Apache-2.0 中任选其一遵守。选择 MIT 时,宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@orieg/expanse-wasm 还在维护吗?

最新版本 0.17.0 发布于 2026/11/02(1 天前);至今共发布 24 个版本,其中过去 12 个月发布了 24 个;首次发布于 2026/08/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。