frameassembly-wasm 1.2.1 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,54 @@
1
- # frameassembly-wasm
1
+ # FrameAssembly WebAssembly Compiler (`frameassembly-wasm` v1.4.1)
2
2
 
3
- WebAssembly compiler, frame inspector, and UTF-16 IDE diagnostics for **FrameAssembly (`.fasm`)** — a deterministic domain-specific language for synthesizing standards-compliant network packets (L2–L7) and PCAPNG captures. *(Note: FrameAssembly is a network protocol DSL, not x86 Flat Assembler).*
3
+ High-performance WebAssembly compiler, frame inspector, and UTF-16 IDE diagnostics for **FrameAssembly (`.fasm`)** — the deterministic domain-specific language for synthesizing standards-compliant network packets (L2–L7) and PCAPNG captures in browser applications, web playgrounds, and Node.js runtimes. *(Note: FrameAssembly is a network protocol DSL, not x86 Flat Assembler).*
4
+
5
+ ---
6
+
7
+ ## Client-Side `.fasm` to `.pcapng` Compilation in the Browser & Node.js
8
+
9
+ `frameassembly-wasm` compiles the complete FrameAssembly Rust compiler directly to WebAssembly, generating deterministic, nanosecond-precision `.pcapng` byte streams and real-time Monaco/CodeMirror syntax diagnostics entirely in the browser or Node.js—with no backend server, Python runtime, or native `libpcap` dependencies required:
10
+
11
+ ```ts
12
+ import init, {
13
+ compile_fasm_to_pcapng,
14
+ validate_fasm,
15
+ inspect_fasm,
16
+ } from "frameassembly-wasm";
17
+
18
+ // Initialize WASM module once at startup
19
+ await init();
20
+
21
+ const source = `HOST client { IP 192.168.1.10 MAC 00:11:22:33:44:55 }
22
+ HOST server { IP 8.8.8.8 MAC aa:bb:cc:dd:ee:ff }
23
+
24
+ FLOW dns_query(c, s) {
25
+ c -> s DNS QUERY TXID 0x1234 QNAME "example.com" QTYPE "A" WAIT 1ms
26
+ c <- s DNS RESPONSE TXID 0x1234 QNAME "example.com" QTYPE "A" RDATA "93.184.216.34" WAIT 1ms
27
+ }
28
+
29
+ COMPILE {
30
+ dns_query(client, server)
31
+ }`;
32
+
33
+ // 1. Validate syntax & semantics for Monaco / CodeMirror editor markers
34
+ const diagnostics = validate_fasm(source);
35
+ if (diagnostics.length === 0) {
36
+ // 2. Inspect individual packet headers and hex payloads
37
+ const previews = inspect_fasm(source);
38
+ console.log(`Synthesized ${previews.length} frames.`);
39
+
40
+ // 3. Compile to binary PCAPNG Uint8Array
41
+ const pcapngBytes = compile_fasm_to_pcapng(source);
42
+ const blob = new Blob([pcapngBytes], { type: "application/vnd.tcpdump.pcap" });
43
+ console.log(`Generated PCAPNG: ${blob.size} bytes`);
44
+ }
45
+ ```
46
+
47
+ ```bash
48
+ npm install frameassembly-wasm
49
+ ```
50
+
51
+ ---
4
52
 
5
53
  ## Installation
6
54
 
@@ -8,9 +56,26 @@ WebAssembly compiler, frame inspector, and UTF-16 IDE diagnostics for **FrameAss
8
56
  npm install frameassembly-wasm
9
57
  ```
10
58
 
11
- ## Initialization (Vite / React / Google AI Studio)
59
+ ### Browser CDN Usage (No Bundler)
12
60
 
13
- Import the WebAssembly binary URL explicitly with `?url` so Vite serves the `.wasm` asset cleanly in both dev and production builds:
61
+ ```html
62
+ <script type="module">
63
+ import init, {
64
+ validate_fasm,
65
+ inspect_fasm,
66
+ compile_fasm_to_pcapng,
67
+ } from "https://cdn.jsdelivr.net/npm/frameassembly-wasm@1.4.1/frameassembly_wasm.js";
68
+
69
+ await init();
70
+ console.log("FrameAssembly WebAssembly engine loaded successfully.");
71
+ </script>
72
+ ```
73
+
74
+ ---
75
+
76
+ ## Initialization (Vite, React, Next.js & Google AI Studio)
77
+
78
+ Import the WebAssembly binary URL explicitly with `?url` so Vite, Webpack 5, and Next.js serve the `.wasm` asset cleanly in both development and production builds:
14
79
 
15
80
  ```ts
16
81
  import init, {
@@ -22,44 +87,85 @@ import init, {
22
87
  } from "frameassembly-wasm";
23
88
  import wasmUrl from "frameassembly-wasm/frameassembly_wasm_bg.wasm?url";
24
89
 
25
- // Call once at app startup (idempotent)
90
+ // Call once at application startup (idempotent)
26
91
  await init({ module_or_path: wasmUrl });
27
92
  ```
28
93
 
29
- ### Browser CDN Usage (No Bundler)
94
+ ---
30
95
 
31
- ```ts
32
- import init, {
33
- validate_fasm,
34
- inspect_fasm,
35
- compile_fasm_to_pcapng,
36
- } from "[https://cdn.jsdelivr.net/npm/frameassembly-wasm@1.2.1/frameassembly_wasm.js](https://cdn.jsdelivr.net/npm/frameassembly-wasm@1.2.1/frameassembly_wasm.js)";
96
+ ## API Reference
37
97
 
38
- await init();
98
+ ### `validate_fasm(source: string): IdeDiagnostic[]`
99
+ Parses and validates `.fasm` source code, returning zero-based UTF-16 line and column spans ready for Monaco Editor or CodeMirror 6 diagnostic markers. Returns an empty array `[]` when the source compiles cleanly.
100
+
101
+ ```ts
102
+ interface IdeDiagnostic {
103
+ start_line: number; // 0-based UTF-16 line index
104
+ start_col: number; // 0-based UTF-16 character column
105
+ end_line: number; // 0-based UTF-16 line index
106
+ end_col: number; // 0-based UTF-16 character column
107
+ message: string; // Human-readable diagnostic message
108
+ help?: string; // Actionable "Did you mean...?" remediation hint
109
+ }
39
110
  ```
40
111
 
41
- ## API Reference
112
+ ### `inspect_fasm(source: string): PacketPreview[]`
113
+ Compiles `.fasm` source code into an array of packet inspection summaries, including relative nanosecond timestamps, frame lengths, and lowercase space-delimited hex byte dumps. Throws a JavaScript `Error` if compilation fails.
42
114
 
43
- - `validate_fasm(source: string): IdeDiagnostic[]` — Parses and compiles `.fasm` source, returning zero-based UTF-16 line/column spans (`start_line`, `start_col`, `end_line`, `end_col`, `message`, `help?`) ready for Monaco or CodeMirror markers. Returns `[]` when valid.
44
- - `inspect_fasm(source: string): PacketPreview[]` — Compiles `.fasm` source and returns frame previews (`index`, zero-based `timestamp_ms`, byte `length`, space-separated lowercase `hex`). Throws `Error` if source is invalid.
45
- - `compile_fasm_to_pcapng(source: string): Uint8Array` — Compiles `.fasm` source into a Wireshark-ready PCAPNG byte array with nanosecond resolution. Throws `Error` if source is invalid.
115
+ ```ts
116
+ interface PacketPreview {
117
+ index: number; // 0-based frame index
118
+ timestamp_ms: number; // Relative timestamp in milliseconds
119
+ length: number; // Total packet length in bytes
120
+ hex: string; // Space-separated lowercase hex byte dump
121
+ }
122
+ ```
46
123
 
47
- ## Minimal `.fasm` Example & PCAPNG Download
124
+ ### `compile_fasm_to_pcapng(source: string): Uint8Array`
125
+ Compiles `.fasm` source code into a binary `Uint8Array` containing a valid, standards-compliant PCAPNG byte stream with nanosecond timestamp precision (`IfTsResol = 9`). Throws a JavaScript `Error` with rich diagnostic context if compilation fails.
48
126
 
49
- ```ts
50
- const source = `HOST client = 00:11:22:33:44:55 / 192.168.1.10
51
- HOST server = aa:bb:cc:dd:ee:ff / 192.168.1.20
127
+ ---
52
128
 
53
- client -> server : TCP SYN DSTPORT=443
54
- server -> client : TCP SYN ACK SRCPORT=443
55
- client -> server : TCP ACK DSTPORT=443`;
129
+ ## Complete Browser Playground & Download Example
56
130
 
57
- const diagnostics = validate_fasm(source);
58
- if (diagnostics.length === 0) {
59
- const frames = inspect_fasm(source);
60
- const pcapngBytes = compile_fasm_to_pcapng(source);
61
- const blob = new Blob([pcapngBytes], { type: "application/vnd.tcpdump.pcap" });
131
+ ```ts
132
+ import init, { compile_fasm_to_pcapng, validate_fasm } from "frameassembly-wasm";
133
+
134
+ export async function downloadCapture(fasmCode: string, filename = "capture.pcapng") {
135
+ await init();
136
+
137
+ const errors = validate_fasm(fasmCode);
138
+ if (errors.length > 0) {
139
+ throw new Error(`Compilation error: ${errors[0].message}`);
140
+ }
141
+
142
+ const pcapng = compile_fasm_to_pcapng(fasmCode);
143
+ const blob = new Blob([pcapng], { type: "application/vnd.tcpdump.pcap" });
144
+ const url = URL.createObjectURL(blob);
145
+
146
+ const a = document.createElement("a");
147
+ a.href = url;
148
+ a.download = filename;
149
+ document.body.appendChild(a);
150
+ a.click();
151
+ document.body.removeChild(a);
152
+ URL.revokeObjectURL(url);
62
153
  }
63
154
  ```
64
155
 
65
- Full grammar and protocol reference: https://github.com/SteveWinschel/FrameAssembly/blob/main/llms.txt
156
+ ---
157
+
158
+ ## Features & Engine Capabilities
159
+
160
+ - **Zero Server Dependencies**: Executes 100% locally in WebAssembly inside Chrome, Firefox, Safari, Edge, Web Workers, and Node.js.
161
+ - **81 Native Protocols**: Complete coverage across L2–L7 (Ethernet, 802.1Q VLAN, QinQ, MPLS, ARP, IPv4/IPv6, ICMP, TCP, UDP, SCTP, SNMPv1/v2c/v3 USM, DNS, DHCP, HTTP, TLS, Modbus, DNP3, and more).
162
+ - **Nanosecond Fidelity**: Compiles deterministic PCAPNG captures with nanosecond-resolution Section and Interface Description Blocks (`IfTsResol(9)`).
163
+ - **Sub-Millisecond Compilation**: Small to medium captures compile in `< 5ms`, making real-time live typing diagnostics instantaneous in web editors.
164
+
165
+ ---
166
+
167
+ ## Disambiguation: FrameAssembly vs. Flat Assembler
168
+
169
+ **FrameAssembly** (`.fasm`, media type `text/vnd.frameassembly`) is a domain-specific network protocol specification language for synthesizing deterministic `.pcap` and `.pcapng` packet captures. It is completely unrelated to x86 Flat Assembler (`fasm.net`) and SymbiFlow / F4PGA FPGA bitstream FASM tools.
170
+
171
+ Full documentation, grammar specifications, and 2,611 verified examples: https://github.com/SteveWinschel/FrameAssembly
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Steve Winschel"
6
6
  ],
7
7
  "description": "WebAssembly compiler, packet inspector, and IDE diagnostics for the FrameAssembly (.fasm) network packet synthesis DSL",
8
- "version": "1.2.1",
8
+ "version": "1.4.1",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",