@aegis-fluxion/core 0.3.0 → 0.5.0
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 +173 -0
- package/dist/index.cjs +584 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -3
- package/dist/index.d.ts +27 -3
- package/dist/index.js +584 -45
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# @aegis-fluxion/core
|
|
2
|
+
|
|
3
|
+
Low-level E2E-encrypted WebSocket primitives for the `aegis-fluxion` ecosystem.
|
|
4
|
+
|
|
5
|
+
If you prefer a single user-facing package, use [`aegis-fluxion`](../aegis-fluxion/README.md).
|
|
6
|
+
|
|
7
|
+
Version: **0.5.0**
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Highlights
|
|
12
|
+
|
|
13
|
+
- Ephemeral ECDH handshake (`prime256v1`)
|
|
14
|
+
- AES-256-GCM encrypted envelopes
|
|
15
|
+
- Encrypted ACK request/response (`Promise` and callback)
|
|
16
|
+
- Secure room routing (`join`, `leave`, `leaveAll`, `to(room).emit`)
|
|
17
|
+
- Heartbeat and zombie socket cleanup
|
|
18
|
+
- Auto-reconnect with fresh re-handshake
|
|
19
|
+
- **Binary payload support**: `Buffer`, `Uint8Array`, `Blob`
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @aegis-fluxion/core ws
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Binary Data Support
|
|
32
|
+
|
|
33
|
+
`@aegis-fluxion/core` supports encrypted binary payload transfer while preserving type fidelity.
|
|
34
|
+
|
|
35
|
+
Supported send/receive types:
|
|
36
|
+
|
|
37
|
+
- `Buffer`
|
|
38
|
+
- `Uint8Array`
|
|
39
|
+
- `Blob`
|
|
40
|
+
|
|
41
|
+
Binary values can be nested in regular objects and arrays.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Example: Encrypted Binary Event
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { SecureClient, SecureServer } from "@aegis-fluxion/core";
|
|
49
|
+
|
|
50
|
+
const server = new SecureServer({ host: "127.0.0.1", port: 8080 });
|
|
51
|
+
const client = new SecureClient("ws://127.0.0.1:8080");
|
|
52
|
+
|
|
53
|
+
server.on("image:chunk", (data, socket) => {
|
|
54
|
+
const chunk = data as Buffer;
|
|
55
|
+
|
|
56
|
+
if (!Buffer.isBuffer(chunk)) {
|
|
57
|
+
throw new Error("Expected Buffer payload.");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
socket.emit("image:chunk:ack", chunk);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
client.on("ready", () => {
|
|
64
|
+
const imageChunk = Buffer.from("89504e470d0a", "hex");
|
|
65
|
+
client.emit("image:chunk", imageChunk);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
client.on("image:chunk:ack", (payload) => {
|
|
69
|
+
const echoedChunk = payload as Buffer;
|
|
70
|
+
console.log("Echoed bytes:", echoedChunk.byteLength);
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Example: ACK Roundtrip with Mixed Binary Types
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
server.on("binary:inspect", async (payload) => {
|
|
80
|
+
const { file, bytes, blob } = payload as {
|
|
81
|
+
file: Buffer;
|
|
82
|
+
bytes: Uint8Array;
|
|
83
|
+
blob: Blob;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
fileBytes: file.byteLength,
|
|
88
|
+
bytesBytes: bytes.byteLength,
|
|
89
|
+
blobBytes: blob.size
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
client.on("ready", async () => {
|
|
94
|
+
const result = await client.emit(
|
|
95
|
+
"binary:inspect",
|
|
96
|
+
{
|
|
97
|
+
file: Buffer.from("file-binary"),
|
|
98
|
+
bytes: Uint8Array.from([1, 2, 3, 4]),
|
|
99
|
+
blob: new Blob([Buffer.from("blob-binary")], {
|
|
100
|
+
type: "application/octet-stream"
|
|
101
|
+
})
|
|
102
|
+
},
|
|
103
|
+
{ timeoutMs: 1500 }
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
console.log(result);
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## API Snapshot
|
|
113
|
+
|
|
114
|
+
### `SecureServer`
|
|
115
|
+
|
|
116
|
+
- `on("connection" | "ready" | "disconnect" | "error", handler)`
|
|
117
|
+
- `on("custom:event", (data, client) => unknown | Promise<unknown>)`
|
|
118
|
+
- `emit(event, data): SecureServer`
|
|
119
|
+
- `emitTo(clientId, event, data): boolean`
|
|
120
|
+
- `emitTo(clientId, event, data, callback): boolean`
|
|
121
|
+
- `emitTo(clientId, event, data, options): Promise<unknown>`
|
|
122
|
+
- `emitTo(clientId, event, data, options, callback): boolean`
|
|
123
|
+
- `to(room).emit(event, data): SecureServer`
|
|
124
|
+
- `close(code?, reason?): void`
|
|
125
|
+
|
|
126
|
+
### `SecureServerClient`
|
|
127
|
+
|
|
128
|
+
- `id: string`
|
|
129
|
+
- `socket: WebSocket`
|
|
130
|
+
- `emit(event, data, ...ackArgs): boolean | Promise<unknown>`
|
|
131
|
+
- `join(room): boolean`
|
|
132
|
+
- `leave(room): boolean`
|
|
133
|
+
- `leaveAll(): number`
|
|
134
|
+
|
|
135
|
+
### `SecureClient`
|
|
136
|
+
|
|
137
|
+
- `connect(): void`
|
|
138
|
+
- `disconnect(code?, reason?): void`
|
|
139
|
+
- `isConnected(): boolean`
|
|
140
|
+
- `readyState: number | null`
|
|
141
|
+
- `emit(event, data): boolean`
|
|
142
|
+
- `emit(event, data, callback): boolean`
|
|
143
|
+
- `emit(event, data, options): Promise<unknown>`
|
|
144
|
+
- `emit(event, data, options, callback): boolean`
|
|
145
|
+
- `on("connect" | "ready" | "disconnect" | "error", handler)`
|
|
146
|
+
- `on("custom:event", handler)`
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Security Notes
|
|
151
|
+
|
|
152
|
+
- All payloads (including binary) are encrypted end-to-end with AES-256-GCM.
|
|
153
|
+
- Authentication tags are verified on every packet (tampered packets are dropped).
|
|
154
|
+
- Internal transport events are reserved (`__handshake`, `__rpc:req`, `__rpc:res`).
|
|
155
|
+
- Pending ACK requests are rejected on timeout/disconnect.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Development
|
|
160
|
+
|
|
161
|
+
From repository root:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
npm run typecheck -w @aegis-fluxion/core
|
|
165
|
+
npm run test -w @aegis-fluxion/core
|
|
166
|
+
npm run build -w @aegis-fluxion/core
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
MIT
|