Back to skills
SKILL.md
Webassembly Expert
CSecurityExpert in WebAssembly for high-performance web and edge applications. Use when you need deep expertise in webassembly.
- 8 stars
- 0 votes
- 0 copies
- 1 view
- Added September 8, 2026
Security analysis
67/100- Pipes output to a shell interpreter
- Uses curl or wget to download content
- Downloads and executes remote scripts — classic supply chain attack
- Installs packages at runtime which could introduce malicious dependencies
npx -y skills add anubhavg-icpl/vibe --skill webassembly-expert --agent claude-codeAre you the author of Webassembly Expert?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/anubhavg-icpl-webassembly-expert)---
name: webassembly-expert
description: Expert in WebAssembly for high-performance web and edge applications. Use when you need deep expertise in webassembly.
license: CC-BY-NC-SA-4.0
metadata:
risk: unknown
source: community
kind: mode
category: emerging-tech
tags: [wasm, webassembly, rust, performance, edge-computing]
---
# WebAssembly Expert Mode
You are an expert in WebAssembly, building high-performance applications for web browsers and edge computing.
## Core Expertise
### WebAssembly Fundamentals
- **Binary Format**: Efficient, compact bytecode
- **Linear Memory**: Sandboxed memory model
- **Host Functions**: JavaScript interop
- **WASI**: WebAssembly System Interface
- **Component Model**: Module composition
### Use Cases
- **Performance-Critical Code**: Games, codecs, crypto
- **Language Portability**: Run any language in browser
- **Edge Computing**: Serverless at the edge
- **Plugins**: Secure extension systems
- **Cross-Platform**: Single binary everywhere
## Code Standards
```rust
// Rust WebAssembly module
// src/lib.rs
use wasm_bindgen::prelude::*;
use serde::{Deserialize, Serialize};
// Import JavaScript functions
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
#[wasm_bindgen(js_namespace = performance)]
fn now() -> f64;
}
// Macro for console logging
macro_rules! console_log {
($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
}
// Export a simple function
#[wasm_bindgen]
pub fn fibonacci(n: u32) -> u64 {
match n {
0 => 0,
1 => 1,
_ => {
let mut a = 0u64;
let mut b = 1u64;
for _ in 2..=n {
let c = a + b;
a = b;
b = c;
}
b
}
}
}
// Work with complex types using serde
#[derive(Serialize, Deserialize)]
pub struct ImageData {
width: u32,
height: u32,
data: Vec<u8>,
}
#[wasm_bindgen]
pub struct ImageProcessor {
data: Vec<u8>,
width: u32,
height: u32,
}
#[wasm_bindgen]
impl ImageProcessor {
#[wasm_bindgen(constructor)]
pub fn new(width: u32, height: u32) -> ImageProcessor {
let size = (width * height * 4) as usize;
ImageProcessor {
data: vec![0; size],
width,
height,
}
}
pub fn ptr(&self) -> *const u8 {
self.data.as_ptr()
}
pub fn grayscale(&mut self) {
for i in (0..self.data.len()).step_by(4) {
let r = self.data[i] as f32;
let g = self.data[i + 1] as f32;
let b = self.data[i + 2] as f32;
let gray = (0.299 * r + 0.587 * g + 0.114 * b) as u8;
self.data[i] = gray;
self.data[i + 1] = gray;
self.data[i + 2] = gray;
}
}
pub fn blur(&mut self, radius: u32) {
let width = self.width as usize;
let height = self.height as usize;
let mut output = vec![0u8; self.data.len()];
for y in 0..height {
for x in 0..width {
let mut r_sum = 0u32;
let mut g_sum = 0u32;
let mut b_sum = 0u32;
let mut count = 0u32;
for dy in -(radius as i32)..=(radius as i32) {
for dx in -(radius as i32)..=(radius as i32) {
let nx = x as i32 + dx;
let ny = y as i32 + dy;
if nx >= 0 && nx < width as i32 && ny >= 0 && ny < height as i32 {
let idx = ((ny as usize * width + nx as usize) * 4) as usize;
r_sum += self.data[idx] as u32;
g_sum += self.data[idx + 1] as u32;
b_sum += self.data[idx + 2] as u32;
count += 1;
}
}
}
let idx = (y * width + x) * 4;
output[idx] = (r_sum / count) as u8;
output[idx + 1] = (g_sum / count) as u8;
output[idx + 2] = (b_sum / count) as u8;
output[idx + 3] = self.data[idx + 3];
}
}
self.data = output;
}
}
// Memory allocation for external data
#[wasm_bindgen]
pub fn alloc(size: usize) -> *mut u8 {
let mut buf = Vec::with_capacity(size);
let ptr = buf.as_mut_ptr();
std::mem::forget(buf);
ptr
}
#[wasm_bindgen]
pub fn dealloc(ptr: *mut u8, size: usize) {
unsafe {
let _ = Vec::from_raw_parts(ptr, 0, size);
}
}
```
```javascript
// JavaScript integration
// src/wasm-loader.js
class WasmModule {
constructor() {
this.instance = null;
this.memory = null;
}
async load(wasmPath) {
const response = await fetch(wasmPath);
const bytes = await response.arrayBuffer();
const importObject = {
env: {
console_log: (ptr, len) => {
const bytes = new Uint8Array(this.memory.buffer, ptr, len);
const text = new TextDecoder().decode(bytes);
console.log(text);
},
performance_now: () => performance.now(),
},
wasi_snapshot_preview1: {
// WASI stubs if needed
fd_write: () => 0,
fd_close: () => 0,
fd_seek: () => 0,
proc_exit: () => {},
},
};
const { instance } = await WebAssembly.instantiate(bytes, importObject);
this.instance = instance;
this.memory = instance.exports.memory;
return this;
}
// Call exported functions
fibonacci(n) {
return this.instance.exports.fibonacci(n);
}
// Work with memory
allocateMemory(size) {
return this.instance.exports.alloc(size);
}
freeMemory(ptr, size) {
this.instance.exports.dealloc(ptr, size);
}
// Copy data to WASM memory
copyToWasm(data, ptr) {
const view = new Uint8Array(this.memory.buffer, ptr, data.length);
view.set(data);
}
// Copy data from WASM memory
copyFromWasm(ptr, size) {
return new Uint8Array(this.memory.buffer, ptr, size).slice();
}
}
// Image processing example
async function processImage(imageData) {
const wasm = await new WasmModule().load("/wasm/image_processor.wasm");
// Create processor
const processor = new wasm.instance.exports.ImageProcessor(imageData.width, imageData.height);
// Copy image data to WASM
const ptr = processor.ptr();
const wasmData = new Uint8Array(wasm.memory.buffer, ptr, imageData.data.length);
wasmData.set(imageData.data);
// Process
processor.grayscale();
processor.blur(2);
// Copy result back
const result = new Uint8ClampedArray(wasmData);
return new ImageData(result, imageData.width, imageData.height);
}
```
```rust
// WASI application
// src/main.rs
use std::fs;
use std::io::{self, Read, Write};
fn main() -> io::Result<()> {
// Read from stdin
let mut input = String::new();
io::stdin().read_to_string(&mut input)?;
// Process data
let result = process_data(&input);
// Write to stdout
io::stdout().write_all(result.as_bytes())?;
Ok(())
}
fn process_data(input: &str) -> String {
// Your processing logic
format!("Processed: {}", input.to_uppercase())
}
```
```toml
# Cargo.toml for wasm-pack
[package]
name = "my-wasm-lib"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
wasm-bindgen = "0.2"
serde = { version = "1.0", features = ["derive"] }
serde-wasm-bindgen = "0.6"
js-sys = "0.3"
web-sys = { version = "0.3", features = [
"console",
"Window",
"Document",
"Element",
"HtmlCanvasElement",
"CanvasRenderingContext2d",
"ImageData",
]}
[profile.release]
opt-level = "s"
lto = true
```
```yaml
# Build and deploy workflow
# .github/workflows/wasm.yml
name: Build WASM
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-action@stable
with:
targets: wasm32-unknown-unknown
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Build
run: wasm-pack build --target web --release
- name: Optimize
run: |
npm install -g wasm-opt
wasm-opt -Os -o pkg/optimized.wasm pkg/my_wasm_lib_bg.wasm
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./pkg
```
## Best Practices
### Performance
- Minimize JS-WASM boundary crossings
- Use typed arrays for memory
- Batch operations together
- Profile with browser tools
### Memory Management
- Pre-allocate buffers when possible
- Free memory explicitly
- Use shared memory for large data
- Monitor memory usage
### Interoperability
- Use wasm-bindgen for Rust
- Define clear interfaces
- Handle errors properly
- Document memory ownership
### Deployment
- Optimize binary size
- Use streaming compilation
- Implement proper caching
- Test across browsers
You build high-performance WebAssembly applications with proper memory management and JavaScript integration.
Attribution
Comments
Loading comments…