tcpip 0.3.3 → 0.3.4
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/LICENSE +21 -0
- package/dist/chunk-DVPTIOIV.cjs +2 -0
- package/dist/chunk-DVPTIOIV.cjs.map +1 -0
- package/dist/chunk-T54CGJHW.js +2 -0
- package/dist/chunk-T54CGJHW.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -121
- package/dist/index.d.ts +20 -121
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.cjs +2 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +120 -0
- package/dist/types.d.ts +120 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +30 -20
- package/tcpip.wasm +0 -0
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { MacAddress, IPv4Address, IPv4Cidr } from '@tcpip/wire';
|
|
2
|
+
|
|
3
|
+
type DuplexStream<R = unknown> = {
|
|
4
|
+
readable: ReadableStream<R>;
|
|
5
|
+
writable: WritableStream<R>;
|
|
6
|
+
};
|
|
7
|
+
type UdpDatagram = {
|
|
8
|
+
host: string;
|
|
9
|
+
port: number;
|
|
10
|
+
data: Uint8Array;
|
|
11
|
+
};
|
|
12
|
+
type UdpSocketOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* The local host to bind to.
|
|
15
|
+
*
|
|
16
|
+
* If not provided, the socket will bind to all available interfaces.
|
|
17
|
+
*/
|
|
18
|
+
host?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The local port to bind to.
|
|
21
|
+
*
|
|
22
|
+
* If not provided, the socket will bind to a random port.
|
|
23
|
+
*/
|
|
24
|
+
port?: number;
|
|
25
|
+
};
|
|
26
|
+
type UdpSocket = {
|
|
27
|
+
readable: ReadableStream<UdpDatagram>;
|
|
28
|
+
writable: WritableStream<UdpDatagram>;
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
[Symbol.asyncIterator](): AsyncIterator<UdpDatagram>;
|
|
31
|
+
};
|
|
32
|
+
type TcpListenerOptions = {
|
|
33
|
+
host?: string;
|
|
34
|
+
port: number;
|
|
35
|
+
};
|
|
36
|
+
type TcpConnectionOptions = {
|
|
37
|
+
host: string;
|
|
38
|
+
port: number;
|
|
39
|
+
};
|
|
40
|
+
type TcpConnection = {
|
|
41
|
+
readable: ReadableStream<Uint8Array>;
|
|
42
|
+
writable: WritableStream<Uint8Array>;
|
|
43
|
+
close(): Promise<void>;
|
|
44
|
+
[Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
|
|
45
|
+
};
|
|
46
|
+
type TcpListener = {
|
|
47
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<TcpConnection>;
|
|
48
|
+
};
|
|
49
|
+
type LoopbackInterfaceOptions = {
|
|
50
|
+
ip?: IPv4Cidr;
|
|
51
|
+
};
|
|
52
|
+
type LoopbackInterface = {
|
|
53
|
+
readonly type: 'loopback';
|
|
54
|
+
readonly ip?: IPv4Address;
|
|
55
|
+
readonly netmask?: IPv4Address;
|
|
56
|
+
};
|
|
57
|
+
type TunInterfaceOptions = {
|
|
58
|
+
ip?: IPv4Cidr;
|
|
59
|
+
};
|
|
60
|
+
type TunInterface = {
|
|
61
|
+
readonly type: 'tun';
|
|
62
|
+
readonly ip?: IPv4Address;
|
|
63
|
+
readonly netmask?: IPv4Address;
|
|
64
|
+
readable: ReadableStream<Uint8Array>;
|
|
65
|
+
writable: WritableStream<Uint8Array>;
|
|
66
|
+
listen(): AsyncIterableIterator<Uint8Array>;
|
|
67
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Uint8Array>;
|
|
68
|
+
};
|
|
69
|
+
type TapInterfaceOptions = {
|
|
70
|
+
mac?: MacAddress;
|
|
71
|
+
ip?: IPv4Cidr;
|
|
72
|
+
};
|
|
73
|
+
type TapInterface = {
|
|
74
|
+
readonly type: 'tap';
|
|
75
|
+
readonly mac: MacAddress;
|
|
76
|
+
readonly ip?: IPv4Address;
|
|
77
|
+
readonly netmask?: IPv4Address;
|
|
78
|
+
readable: ReadableStream<Uint8Array>;
|
|
79
|
+
writable: WritableStream<Uint8Array>;
|
|
80
|
+
listen(): AsyncIterableIterator<Uint8Array>;
|
|
81
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Uint8Array>;
|
|
82
|
+
};
|
|
83
|
+
type BridgeInterfaceOptions = {
|
|
84
|
+
ports: TapInterface[];
|
|
85
|
+
mac?: MacAddress;
|
|
86
|
+
ip?: IPv4Cidr;
|
|
87
|
+
};
|
|
88
|
+
type BridgeInterface = {
|
|
89
|
+
readonly type: 'bridge';
|
|
90
|
+
readonly mac: MacAddress;
|
|
91
|
+
readonly ip?: IPv4Address;
|
|
92
|
+
readonly netmask?: IPv4Address;
|
|
93
|
+
};
|
|
94
|
+
type NetworkInterface = LoopbackInterface | TunInterface | TapInterface | BridgeInterface;
|
|
95
|
+
type NetworkStack = {
|
|
96
|
+
readonly ready: Promise<void>;
|
|
97
|
+
readonly interfaces: Iterable<NetworkInterface>;
|
|
98
|
+
createLoopbackInterface(options: LoopbackInterfaceOptions): Promise<LoopbackInterface>;
|
|
99
|
+
createTunInterface(options: TunInterfaceOptions): Promise<TunInterface>;
|
|
100
|
+
createTapInterface(options?: TapInterfaceOptions): Promise<TapInterface>;
|
|
101
|
+
createBridgeInterface(options: BridgeInterfaceOptions): Promise<BridgeInterface>;
|
|
102
|
+
removeInterface(netInterface: LoopbackInterface | TunInterface | TapInterface): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Listens for incoming TCP connections on the specified host/port.
|
|
105
|
+
*/
|
|
106
|
+
listenTcp(options: TcpListenerOptions): Promise<TcpListener>;
|
|
107
|
+
/**
|
|
108
|
+
* Establishes an outbound TCP connection to a remote host/port.
|
|
109
|
+
*/
|
|
110
|
+
connectTcp(options: TcpConnectionOptions): Promise<TcpConnection>;
|
|
111
|
+
/**
|
|
112
|
+
* Opens a UDP socket for sending and receiving datagrams.
|
|
113
|
+
*
|
|
114
|
+
* If no local host is provided, the socket will bind to all available interfaces.
|
|
115
|
+
* If no local port is provided, the socket will bind to a random port.
|
|
116
|
+
*/
|
|
117
|
+
openUdp(options?: UdpSocketOptions): Promise<UdpSocket>;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export type { BridgeInterface, BridgeInterfaceOptions, DuplexStream, LoopbackInterface, LoopbackInterfaceOptions, NetworkInterface, NetworkStack, TapInterface, TapInterfaceOptions, TcpConnection, TcpConnectionOptions, TcpListener, TcpListenerOptions, TunInterface, TunInterfaceOptions, UdpDatagram, UdpSocket, UdpSocketOptions };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { MacAddress, IPv4Address, IPv4Cidr } from '@tcpip/wire';
|
|
2
|
+
|
|
3
|
+
type DuplexStream<R = unknown> = {
|
|
4
|
+
readable: ReadableStream<R>;
|
|
5
|
+
writable: WritableStream<R>;
|
|
6
|
+
};
|
|
7
|
+
type UdpDatagram = {
|
|
8
|
+
host: string;
|
|
9
|
+
port: number;
|
|
10
|
+
data: Uint8Array;
|
|
11
|
+
};
|
|
12
|
+
type UdpSocketOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* The local host to bind to.
|
|
15
|
+
*
|
|
16
|
+
* If not provided, the socket will bind to all available interfaces.
|
|
17
|
+
*/
|
|
18
|
+
host?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The local port to bind to.
|
|
21
|
+
*
|
|
22
|
+
* If not provided, the socket will bind to a random port.
|
|
23
|
+
*/
|
|
24
|
+
port?: number;
|
|
25
|
+
};
|
|
26
|
+
type UdpSocket = {
|
|
27
|
+
readable: ReadableStream<UdpDatagram>;
|
|
28
|
+
writable: WritableStream<UdpDatagram>;
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
[Symbol.asyncIterator](): AsyncIterator<UdpDatagram>;
|
|
31
|
+
};
|
|
32
|
+
type TcpListenerOptions = {
|
|
33
|
+
host?: string;
|
|
34
|
+
port: number;
|
|
35
|
+
};
|
|
36
|
+
type TcpConnectionOptions = {
|
|
37
|
+
host: string;
|
|
38
|
+
port: number;
|
|
39
|
+
};
|
|
40
|
+
type TcpConnection = {
|
|
41
|
+
readable: ReadableStream<Uint8Array>;
|
|
42
|
+
writable: WritableStream<Uint8Array>;
|
|
43
|
+
close(): Promise<void>;
|
|
44
|
+
[Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
|
|
45
|
+
};
|
|
46
|
+
type TcpListener = {
|
|
47
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<TcpConnection>;
|
|
48
|
+
};
|
|
49
|
+
type LoopbackInterfaceOptions = {
|
|
50
|
+
ip?: IPv4Cidr;
|
|
51
|
+
};
|
|
52
|
+
type LoopbackInterface = {
|
|
53
|
+
readonly type: 'loopback';
|
|
54
|
+
readonly ip?: IPv4Address;
|
|
55
|
+
readonly netmask?: IPv4Address;
|
|
56
|
+
};
|
|
57
|
+
type TunInterfaceOptions = {
|
|
58
|
+
ip?: IPv4Cidr;
|
|
59
|
+
};
|
|
60
|
+
type TunInterface = {
|
|
61
|
+
readonly type: 'tun';
|
|
62
|
+
readonly ip?: IPv4Address;
|
|
63
|
+
readonly netmask?: IPv4Address;
|
|
64
|
+
readable: ReadableStream<Uint8Array>;
|
|
65
|
+
writable: WritableStream<Uint8Array>;
|
|
66
|
+
listen(): AsyncIterableIterator<Uint8Array>;
|
|
67
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Uint8Array>;
|
|
68
|
+
};
|
|
69
|
+
type TapInterfaceOptions = {
|
|
70
|
+
mac?: MacAddress;
|
|
71
|
+
ip?: IPv4Cidr;
|
|
72
|
+
};
|
|
73
|
+
type TapInterface = {
|
|
74
|
+
readonly type: 'tap';
|
|
75
|
+
readonly mac: MacAddress;
|
|
76
|
+
readonly ip?: IPv4Address;
|
|
77
|
+
readonly netmask?: IPv4Address;
|
|
78
|
+
readable: ReadableStream<Uint8Array>;
|
|
79
|
+
writable: WritableStream<Uint8Array>;
|
|
80
|
+
listen(): AsyncIterableIterator<Uint8Array>;
|
|
81
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Uint8Array>;
|
|
82
|
+
};
|
|
83
|
+
type BridgeInterfaceOptions = {
|
|
84
|
+
ports: TapInterface[];
|
|
85
|
+
mac?: MacAddress;
|
|
86
|
+
ip?: IPv4Cidr;
|
|
87
|
+
};
|
|
88
|
+
type BridgeInterface = {
|
|
89
|
+
readonly type: 'bridge';
|
|
90
|
+
readonly mac: MacAddress;
|
|
91
|
+
readonly ip?: IPv4Address;
|
|
92
|
+
readonly netmask?: IPv4Address;
|
|
93
|
+
};
|
|
94
|
+
type NetworkInterface = LoopbackInterface | TunInterface | TapInterface | BridgeInterface;
|
|
95
|
+
type NetworkStack = {
|
|
96
|
+
readonly ready: Promise<void>;
|
|
97
|
+
readonly interfaces: Iterable<NetworkInterface>;
|
|
98
|
+
createLoopbackInterface(options: LoopbackInterfaceOptions): Promise<LoopbackInterface>;
|
|
99
|
+
createTunInterface(options: TunInterfaceOptions): Promise<TunInterface>;
|
|
100
|
+
createTapInterface(options?: TapInterfaceOptions): Promise<TapInterface>;
|
|
101
|
+
createBridgeInterface(options: BridgeInterfaceOptions): Promise<BridgeInterface>;
|
|
102
|
+
removeInterface(netInterface: LoopbackInterface | TunInterface | TapInterface): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Listens for incoming TCP connections on the specified host/port.
|
|
105
|
+
*/
|
|
106
|
+
listenTcp(options: TcpListenerOptions): Promise<TcpListener>;
|
|
107
|
+
/**
|
|
108
|
+
* Establishes an outbound TCP connection to a remote host/port.
|
|
109
|
+
*/
|
|
110
|
+
connectTcp(options: TcpConnectionOptions): Promise<TcpConnection>;
|
|
111
|
+
/**
|
|
112
|
+
* Opens a UDP socket for sending and receiving datagrams.
|
|
113
|
+
*
|
|
114
|
+
* If no local host is provided, the socket will bind to all available interfaces.
|
|
115
|
+
* If no local port is provided, the socket will bind to a random port.
|
|
116
|
+
*/
|
|
117
|
+
openUdp(options?: UdpSocketOptions): Promise<UdpSocket>;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export type { BridgeInterface, BridgeInterfaceOptions, DuplexStream, LoopbackInterface, LoopbackInterfaceOptions, NetworkInterface, NetworkStack, TapInterface, TapInterfaceOptions, TcpConnection, TcpConnectionOptions, TcpListener, TcpListenerOptions, TunInterface, TunInterfaceOptions, UdpDatagram, UdpSocket, UdpSocketOptions };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,48 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tcpip",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Virtual TCP/IP stack that can run anywhere",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/chipmk/tcpip.js.git",
|
|
9
|
+
"directory": "packages/tcpip"
|
|
10
|
+
},
|
|
6
11
|
"type": "module",
|
|
7
12
|
"main": "dist/index.cjs",
|
|
8
13
|
"types": "dist/index.d.ts",
|
|
9
14
|
"sideEffects": false,
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "npm run build:js && npm run build:wasm",
|
|
12
|
-
"build:js": "tsup --clean",
|
|
13
|
-
"build:wasm": "npm run make build",
|
|
14
|
-
"prepublishOnly": "npm run build",
|
|
15
|
-
"test": "vitest",
|
|
16
|
-
"clean": "rm -rf dist",
|
|
17
|
-
"make": "CC='docker compose run --rm wasi-sdk /opt/wasi-sdk/bin/clang' AR='docker compose run --rm wasi-sdk /opt/wasi-sdk/bin/ar' make",
|
|
18
|
-
"wasm-objdump": "docker compose run --rm wabt wasm-objdump",
|
|
19
|
-
"wasm-opt": "docker compose run --rm binaryen wasm-opt -Oz --enable-bulk-memory wasm/tcpip.wasm -o wasm/tcpip.min.wasm"
|
|
20
|
-
},
|
|
21
15
|
"files": [
|
|
22
16
|
"dist/**/*",
|
|
23
17
|
"tcpip.wasm"
|
|
24
18
|
],
|
|
25
19
|
"exports": {
|
|
26
20
|
".": {
|
|
27
|
-
"import": "./dist/index.js",
|
|
28
21
|
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js",
|
|
29
23
|
"default": "./dist/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./types": {
|
|
26
|
+
"types": "./dist/types.d.ts",
|
|
27
|
+
"import": "./dist/types.js",
|
|
28
|
+
"default": "./dist/types.cjs"
|
|
30
29
|
}
|
|
31
30
|
},
|
|
32
31
|
"dependencies": {
|
|
33
32
|
"@bjorn3/browser_wasi_shim": "^0.3.0",
|
|
34
|
-
"@tcpip/dns": "0.2",
|
|
35
|
-
"@tcpip/wire": "0.1"
|
|
33
|
+
"@tcpip/dns": "0.2.2",
|
|
34
|
+
"@tcpip/wire": "0.1.3"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
38
37
|
"@playwright/test": "^1.52.0",
|
|
39
38
|
"@total-typescript/tsconfig": "^1.0.4",
|
|
40
|
-
"@types/node": "^22.
|
|
39
|
+
"@types/node": "^22.15.19",
|
|
41
40
|
"@vitest/browser": "^3.1.2",
|
|
42
|
-
"prettier": "^3.3.3",
|
|
43
41
|
"tsup": "^8.3.5",
|
|
44
42
|
"tsx": "^4.19.2",
|
|
45
|
-
"typescript": "^5.
|
|
46
|
-
"vitest": "^3.1.
|
|
43
|
+
"typescript": "^5.8.3",
|
|
44
|
+
"vitest": "^3.1.4"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "pnpm run build:js && pnpm run build:wasm",
|
|
48
|
+
"build:js": "tsup --clean",
|
|
49
|
+
"build:wasm": "pnpm run make build",
|
|
50
|
+
"test": "vitest",
|
|
51
|
+
"test:node": "vitest --project node",
|
|
52
|
+
"test:browser": "vitest --project browser",
|
|
53
|
+
"clean": "rm -rf dist",
|
|
54
|
+
"make": "CC='docker compose run --rm wasi-sdk /opt/wasi-sdk/bin/clang' AR='docker compose run --rm wasi-sdk /opt/wasi-sdk/bin/ar' make",
|
|
55
|
+
"wasm-objdump": "docker compose run --rm wabt wasm-objdump",
|
|
56
|
+
"wasm-opt": "docker compose run --rm binaryen wasm-opt -Oz --enable-bulk-memory wasm/tcpip.wasm -o wasm/tcpip.min.wasm"
|
|
47
57
|
}
|
|
48
|
-
}
|
|
58
|
+
}
|
package/tcpip.wasm
CHANGED
|
Binary file
|