willow-wasm
v0.1.1
Published
WebAssembly bindings for Willow25 protocol
Readme
willow-wasm
WebAssembly bindings for the Willow protocol.
Installation
npm i -S willow-wasmUsage
For Bundlers (esbuild, Vite, Rollup, etc.)
import * as wasm from 'willow-wasm';
// or
import * as wasm from 'willow-wasm/bundler';
const path = new wasm.WillowPath();
console.log(path.component_count()); // 0For Node.js
const wasm = require('willow-wasm');
// or
const wasm = require('willow-wasm/nodejs');
const path = new wasm.WillowPath();
console.log(path.component_count()); // 0For Web (No Bundler)
<script type="module">
import init, * as wasm from 'willow-wasm/web';
async function run() {
await init();
const path = new wasm.WillowPath();
console.log(path.component_count()); // 0
}
run();
</script>API
See the TypeScript definitions (.d.ts files) for full API documentation.
Available Functions
get_max_component_count()- Get maximum component countget_max_component_length()- Get maximum component lengthget_max_path_length()- Get maximum path lengthcompare_paths(a, b)- Compare two pathspath_from_string(str)- Create path from string
Classes
WillowPath
const path = new WillowPath();
const pathFromComponent = WillowPath.from_component(bytes);
const pathFromComponents = WillowPath.from_components(componentsArray);
const pathFromBytes = WillowPath.from_bytes(bytes);
path.component_count(): number
path.is_prefix_of(other): boolean
path.is_empty(): boolean
path.to_bytes(): Uint8Array
path.get_component(index): Uint8Array | undefined
path.append_component(bytes): WillowPathWillowComponent
const component = new WillowComponent(bytes);
component.as_bytes(): Uint8Array
component.len(): number
component.is_empty(): booleanMemory Management
Remember to call .free() on objects when you're done with them to prevent memory leaks:
const path = new WillowPath();
try {
// Use path...
} finally {
path.free();
}License
MIT
