IPFRS WebAssembly Bindings
WebAssembly bindings for IPFRS (Inter-Planetary File Rust System) - enabling content-addressed storage with semantic search and logic programming in the browser.
Features
- Browser-Native: Run IPFRS directly in web browsers
- Content-Addressed Storage: Store and retrieve data using cryptographic identifiers
- Logic Programming: TensorLogic inference engine in the browser
- Semantic Search: Vector similarity search (limited in browser)
- TypeScript Support: Full type definitions included
- Zero Dependencies: Compiled to WebAssembly for maximum compatibility
Installation
# or
Quick Start
Basic Usage (ES Modules)
import init from '@ipfrs/wasm';
.;
TypeScript Example
import init, { Node, NodeConfig } from '@ipfrs/wasm';
interface Fact {
name: string;
args: Array<{ kind: string; value: string }>;
}
async function logicExample() {
await init();
const config = new NodeConfig()
.setEnableTensorlogic(true);
const node = new Node(config);
// Type-safe fact
const fact: Fact = {
name: 'likes',
args: [
{ kind: 'string', value: 'Alice' },
{ kind: 'string', value: 'programming' }
]
};
node.addFact(fact);
const stats = node.kbStats();
console.log(`Facts: ${stats.num_facts}, Rules: ${stats.num_rules}`);
}
logicExample();
HTML Usage
IPFRS WASM Demo
IPFRS in the Browser
API Reference
NodeConfig
Configuration for IPFRS node.
Methods:
new NodeConfig()- Create new configurationsetStoragePath(path: string): NodeConfig- Set storage path (not used in browser)setEnableSemantic(enable: boolean): NodeConfig- Enable semantic searchsetEnableTensorlogic(enable: boolean): NodeConfig- Enable logic programming
Node
Main IPFRS interface.
Constructor:
new Node(config?: NodeConfig)- Create new node
Methods:
Lifecycle:
start(): void- Start the node (no-op in browser)stop(): void- Stop the node
Block Operations (Limited in Browser):
putBlock(data: Uint8Array): string- Store block, returns CIDhasBlock(cid: string): boolean- Check if block exists
Logic Programming:
addFact(fact: Predicate): void- Add a factaddRule(rule: Rule): void- Add a ruleinfer(goal: Predicate): string[]- Run inferencekbStats(): KbStats- Get KB statistics
Types
Term:
interface Term {
kind: 'int' | 'float' | 'string' | 'bool' | 'var';
value: string;
}
Predicate:
interface Predicate {
name: string;
args: Term[];
}
Rule:
interface Rule {
head: Predicate;
body: Predicate[];
}
KbStats:
interface KbStats {
num_facts: number;
num_rules: number;
}
Building from Source
# Install wasm-pack
# Build for web
# Build for Node.js
# Build for bundlers (webpack, etc.)
# Run tests
Browser Compatibility
- Modern browsers with WebAssembly support
- Chrome/Edge 57+
- Firefox 52+
- Safari 11+
- Opera 44+
Limitations
Due to browser environment constraints:
- No File System: Storage path is not used in browser
- Simplified Async: Some async operations are synchronous in WASM
- Limited Semantic Search: Full HNSW index may be too large for browser memory
- No Network: Distributed features not available in browser
Use Cases
- Education: Interactive logic programming tutorials
- Demos: Showcase IPFRS capabilities without backend
- Client-Side: Local data processing and reasoning
- Prototyping: Quick experiments with content-addressed storage
Size Optimization
The WASM binary is optimized for size:
- Release build: ~800KB (compressed)
- Gzip: ~250KB
- Brotli: ~180KB
License
Apache-2.0