@mtkruto/browser 0.132.1 → 0.134.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/esm/0_deps.d.ts +1 -0
- package/esm/0_deps.d.ts.map +1 -1
- package/esm/0_deps.js +1 -0
- package/esm/1_utilities.d.ts +1 -0
- package/esm/1_utilities.d.ts.map +1 -1
- package/esm/1_utilities.js +1 -0
- package/esm/2_connection.d.ts +1 -0
- package/esm/2_connection.d.ts.map +1 -1
- package/esm/2_connection.js +1 -0
- package/esm/3_transport.d.ts +1 -0
- package/esm/3_transport.d.ts.map +1 -1
- package/esm/3_transport.js +1 -0
- package/esm/connection/1_connection_socks5.d.ts +36 -0
- package/esm/connection/1_connection_socks5.d.ts.map +1 -0
- package/esm/connection/1_connection_socks5.js +192 -0
- package/esm/connection/1_connection_socks5.node.d.ts +35 -0
- package/esm/connection/1_connection_socks5.node.d.ts.map +1 -0
- package/esm/connection/1_connection_socks5.node.js +214 -0
- package/esm/connection/1_connection_tcp.d.ts.map +1 -1
- package/esm/connection/1_connection_tcp.js +0 -1
- package/esm/connection/1_connection_tls.js +1 -1
- package/esm/deps/jsr.io/@std/net/1.0.6/unstable_ip.d.ts +103 -0
- package/esm/deps/jsr.io/@std/net/1.0.6/unstable_ip.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/net/1.0.6/unstable_ip.js +296 -0
- package/esm/transport/2_transport_provider_mtproxy.d.ts +1 -1
- package/esm/transport/2_transport_provider_mtproxy.d.ts.map +1 -1
- package/esm/transport/2_transport_provider_mtproxy.js +3 -3
- package/esm/transport/2_transport_provider_socks5.d.ts +27 -0
- package/esm/transport/2_transport_provider_socks5.d.ts.map +1 -0
- package/esm/transport/2_transport_provider_socks5.js +45 -0
- package/esm/types/5_star_transaction.js +2 -2
- package/esm/utilities/0_ip.d.ts +22 -0
- package/esm/utilities/0_ip.d.ts.map +1 -0
- package/esm/utilities/0_ip.js +73 -0
- package/package.json +1 -1
- package/script/0_deps.d.ts +1 -0
- package/script/0_deps.d.ts.map +1 -1
- package/script/0_deps.js +4 -1
- package/script/1_utilities.d.ts +1 -0
- package/script/1_utilities.d.ts.map +1 -1
- package/script/1_utilities.js +1 -0
- package/script/2_connection.d.ts +1 -0
- package/script/2_connection.d.ts.map +1 -1
- package/script/2_connection.js +1 -0
- package/script/3_transport.d.ts +1 -0
- package/script/3_transport.d.ts.map +1 -1
- package/script/3_transport.js +1 -0
- package/script/connection/1_connection_socks5.d.ts +36 -0
- package/script/connection/1_connection_socks5.d.ts.map +1 -0
- package/script/connection/1_connection_socks5.js +196 -0
- package/script/connection/1_connection_socks5.node.d.ts +35 -0
- package/script/connection/1_connection_socks5.node.d.ts.map +1 -0
- package/script/connection/1_connection_socks5.node.js +218 -0
- package/script/connection/1_connection_tcp.d.ts.map +1 -1
- package/script/connection/1_connection_tcp.js +0 -1
- package/script/connection/1_connection_tls.js +1 -1
- package/script/deps/jsr.io/@std/net/1.0.6/unstable_ip.d.ts +103 -0
- package/script/deps/jsr.io/@std/net/1.0.6/unstable_ip.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/net/1.0.6/unstable_ip.js +303 -0
- package/script/transport/2_transport_provider_mtproxy.d.ts +1 -1
- package/script/transport/2_transport_provider_mtproxy.d.ts.map +1 -1
- package/script/transport/2_transport_provider_mtproxy.js +3 -3
- package/script/transport/2_transport_provider_socks5.d.ts +27 -0
- package/script/transport/2_transport_provider_socks5.d.ts.map +1 -0
- package/script/transport/2_transport_provider_socks5.js +48 -0
- package/script/types/5_star_transaction.js +1 -1
- package/script/utilities/0_ip.d.ts +22 -0
- package/script/utilities/0_ip.d.ts.map +1 -0
- package/script/utilities/0_ip.js +77 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates whether a given string is a valid IPv4 address.
|
|
3
|
+
*
|
|
4
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
5
|
+
*
|
|
6
|
+
* @param addr IPv4 address in a string format (e.g., "192.168.0.1").
|
|
7
|
+
* @returns A boolean indicating if the string is a valid IPv4 address.
|
|
8
|
+
*
|
|
9
|
+
* @example Check if the address is a IPv4
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { isIPv4 } from "@std/net/unstable-ip"
|
|
12
|
+
* import { assert, assertFalse } from "@std/assert"
|
|
13
|
+
*
|
|
14
|
+
* const correctIp = "192.168.0.1"
|
|
15
|
+
* const incorrectIp = "192.168.0.256"
|
|
16
|
+
*
|
|
17
|
+
* assert(isIPv4(correctIp))
|
|
18
|
+
* assertFalse(isIPv4(incorrectIp))
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function isIPv4(addr: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Validates whether a given string is a IPv6 address.
|
|
24
|
+
*
|
|
25
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
26
|
+
*
|
|
27
|
+
* @param addr IPv6 address in a string format (e.g., "2001:db8::1").
|
|
28
|
+
* @returns A boolean indicating if the string is a valid IPv6 address.
|
|
29
|
+
*
|
|
30
|
+
* @example Check if the address is a IPv6
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { isIPv6 } from "@std/net/unstable-ip"
|
|
33
|
+
* import { assert, assertFalse } from "@std/assert"
|
|
34
|
+
*
|
|
35
|
+
* const correctIp = "2001::db8:0:1"
|
|
36
|
+
* const incorrectIp = "2001::db8::1"
|
|
37
|
+
*
|
|
38
|
+
* assert(isIPv6(correctIp))
|
|
39
|
+
* assertFalse(isIPv6(incorrectIp))
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function isIPv6(addr: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if an IP address matches a subnet or specific IP address.
|
|
45
|
+
*
|
|
46
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
47
|
+
*
|
|
48
|
+
* @param addr The IP address to check (IPv4 or IPv6)
|
|
49
|
+
* @param subnetOrIps The subnet in CIDR notation (e.g., "192.168.1.0/24") or a specific IP address
|
|
50
|
+
* @returns true if the IP address matches the subnet or IP, false otherwise
|
|
51
|
+
* @example Check if the address is a IPv6
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { matchSubnets } from "@std/net/unstable-ip"
|
|
55
|
+
* import { assert, assertFalse } from "@std/assert"
|
|
56
|
+
*
|
|
57
|
+
* assert(matchSubnets("192.168.1.10", ["192.168.1.0/24"]));
|
|
58
|
+
* assertFalse(matchSubnets("192.168.2.10", ["192.168.1.0/24"]));
|
|
59
|
+
*
|
|
60
|
+
* assert(matchSubnets("2001:db8::ffff", ["2001:db8::/64"]));
|
|
61
|
+
* assertFalse(matchSubnets("2001:db9::1", ["2001:db8::/64"]));
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function matchSubnets(addr: string, subnetOrIps: string[]): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Checks if an IPv4 address matches a subnet or specific IPv4 address.
|
|
67
|
+
*
|
|
68
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
69
|
+
*
|
|
70
|
+
* @param addr The IP address to check (IPv4)
|
|
71
|
+
* @param subnet The subnet in CIDR notation (e.g., "192.168.1.0/24") or a specific IP address
|
|
72
|
+
* @returns true if the IP address matches the subnet or IP, false otherwise
|
|
73
|
+
* @example Check if the address is a IPv6
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { matchIPv4Subnet } from "@std/net/unstable-ip"
|
|
77
|
+
* import { assert, assertFalse } from "@std/assert"
|
|
78
|
+
*
|
|
79
|
+
* assert(matchIPv4Subnet("192.168.1.10", "192.168.1.0/24"));
|
|
80
|
+
* assertFalse(matchIPv4Subnet("192.168.2.10", "192.168.1.0/24"));
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function matchIPv4Subnet(addr: string, subnet: string): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Checks if an IPv6 address matches a subnet or specific IPv6 address.
|
|
86
|
+
*
|
|
87
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
88
|
+
*
|
|
89
|
+
* @param addr The IP address to check (IPv6)
|
|
90
|
+
* @param subnet The subnet in CIDR notation (e.g., "2001:db8::/64") or a specific IP address
|
|
91
|
+
* @returns true if the IP address matches the subnet or IP, false otherwise
|
|
92
|
+
* @example Check if the address is a IPv6
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { matchIPv6Subnet } from "@std/net/unstable-ip"
|
|
96
|
+
* import { assert, assertFalse } from "@std/assert"
|
|
97
|
+
*
|
|
98
|
+
* assert(matchIPv6Subnet("2001:db8::ffff", "2001:db8::/64"));
|
|
99
|
+
* assertFalse(matchIPv6Subnet("2001:db9::1", "2001:db8::/64"));
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function matchIPv6Subnet(addr: string, subnet: string): boolean;
|
|
103
|
+
//# sourceMappingURL=unstable_ip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unstable_ip.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/net/1.0.6/unstable_ip.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAU5C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAiC5C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAYzE;AAwCD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CA6CrE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAoDrE"}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isIPv4 = isIPv4;
|
|
5
|
+
exports.isIPv6 = isIPv6;
|
|
6
|
+
exports.matchSubnets = matchSubnets;
|
|
7
|
+
exports.matchIPv4Subnet = matchIPv4Subnet;
|
|
8
|
+
exports.matchIPv6Subnet = matchIPv6Subnet;
|
|
9
|
+
/**
|
|
10
|
+
* Validates whether a given string is a valid IPv4 address.
|
|
11
|
+
*
|
|
12
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
13
|
+
*
|
|
14
|
+
* @param addr IPv4 address in a string format (e.g., "192.168.0.1").
|
|
15
|
+
* @returns A boolean indicating if the string is a valid IPv4 address.
|
|
16
|
+
*
|
|
17
|
+
* @example Check if the address is a IPv4
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { isIPv4 } from "@std/net/unstable-ip"
|
|
20
|
+
* import { assert, assertFalse } from "@std/assert"
|
|
21
|
+
*
|
|
22
|
+
* const correctIp = "192.168.0.1"
|
|
23
|
+
* const incorrectIp = "192.168.0.256"
|
|
24
|
+
*
|
|
25
|
+
* assert(isIPv4(correctIp))
|
|
26
|
+
* assertFalse(isIPv4(incorrectIp))
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function isIPv4(addr) {
|
|
30
|
+
const octets = addr.split(".");
|
|
31
|
+
return (octets.length === 4 &&
|
|
32
|
+
octets.every((octet) => {
|
|
33
|
+
const n = Number(octet);
|
|
34
|
+
return n >= 0 && n <= 255 && !isNaN(n);
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validates whether a given string is a IPv6 address.
|
|
39
|
+
*
|
|
40
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
41
|
+
*
|
|
42
|
+
* @param addr IPv6 address in a string format (e.g., "2001:db8::1").
|
|
43
|
+
* @returns A boolean indicating if the string is a valid IPv6 address.
|
|
44
|
+
*
|
|
45
|
+
* @example Check if the address is a IPv6
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { isIPv6 } from "@std/net/unstable-ip"
|
|
48
|
+
* import { assert, assertFalse } from "@std/assert"
|
|
49
|
+
*
|
|
50
|
+
* const correctIp = "2001::db8:0:1"
|
|
51
|
+
* const incorrectIp = "2001::db8::1"
|
|
52
|
+
*
|
|
53
|
+
* assert(isIPv6(correctIp))
|
|
54
|
+
* assertFalse(isIPv6(incorrectIp))
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
function isIPv6(addr) {
|
|
58
|
+
// more than one use of ::
|
|
59
|
+
if (addr.split("::").length > 2)
|
|
60
|
+
return false;
|
|
61
|
+
const hextets = addr.split(":");
|
|
62
|
+
// x:x:x:x:x:x:d.d.d.d (https://www.rfc-editor.org/rfc/rfc4291#section-2.2)
|
|
63
|
+
// check if has ipv4 on
|
|
64
|
+
if (addr.includes(".")) {
|
|
65
|
+
// is just an ipv4
|
|
66
|
+
if (hextets.length === 1)
|
|
67
|
+
return false;
|
|
68
|
+
const last = hextets.pop();
|
|
69
|
+
if (!last || !isIPv4(last))
|
|
70
|
+
return false;
|
|
71
|
+
// just to maintain the length to 8
|
|
72
|
+
hextets.push("");
|
|
73
|
+
}
|
|
74
|
+
// expand ::
|
|
75
|
+
while (hextets.length < 8) {
|
|
76
|
+
const idx = hextets.indexOf("");
|
|
77
|
+
if (idx === -1)
|
|
78
|
+
break;
|
|
79
|
+
hextets.splice(idx, 0, "");
|
|
80
|
+
}
|
|
81
|
+
return (hextets.length === 8 &&
|
|
82
|
+
hextets.every((hextet) => {
|
|
83
|
+
const n = hextet === "" ? 0 : parseInt(hextet, 16);
|
|
84
|
+
return n >= 0 && n <= 65535 && !isNaN(n);
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Checks if an IP address matches a subnet or specific IP address.
|
|
89
|
+
*
|
|
90
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
91
|
+
*
|
|
92
|
+
* @param addr The IP address to check (IPv4 or IPv6)
|
|
93
|
+
* @param subnetOrIps The subnet in CIDR notation (e.g., "192.168.1.0/24") or a specific IP address
|
|
94
|
+
* @returns true if the IP address matches the subnet or IP, false otherwise
|
|
95
|
+
* @example Check if the address is a IPv6
|
|
96
|
+
*
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { matchSubnets } from "@std/net/unstable-ip"
|
|
99
|
+
* import { assert, assertFalse } from "@std/assert"
|
|
100
|
+
*
|
|
101
|
+
* assert(matchSubnets("192.168.1.10", ["192.168.1.0/24"]));
|
|
102
|
+
* assertFalse(matchSubnets("192.168.2.10", ["192.168.1.0/24"]));
|
|
103
|
+
*
|
|
104
|
+
* assert(matchSubnets("2001:db8::ffff", ["2001:db8::/64"]));
|
|
105
|
+
* assertFalse(matchSubnets("2001:db9::1", ["2001:db8::/64"]));
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
function matchSubnets(addr, subnetOrIps) {
|
|
109
|
+
if (!isValidIP(addr)) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
for (const subnetOrIp of subnetOrIps) {
|
|
113
|
+
if (matchSubnet(addr, subnetOrIp)) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
function matchSubnet(addr, subnet) {
|
|
120
|
+
// If the subnet doesn't contain "/", treat it as a specific IP address
|
|
121
|
+
if (!subnet.includes("/")) {
|
|
122
|
+
return addr === subnet;
|
|
123
|
+
}
|
|
124
|
+
// Parse subnet into IP address and prefix length
|
|
125
|
+
const [subnetIP, prefixLengthStr] = subnet.split("/");
|
|
126
|
+
if (!subnetIP ||
|
|
127
|
+
subnetIP === "" ||
|
|
128
|
+
!prefixLengthStr ||
|
|
129
|
+
prefixLengthStr === "") {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
// Check if both IP and subnet are the same type (IPv4 or IPv6)
|
|
133
|
+
const ipIsV4 = isIPv4(addr);
|
|
134
|
+
const subnetIsV4 = isIPv4(subnetIP);
|
|
135
|
+
// IP and subnet must be the same version (both IPv4 or both IPv6)
|
|
136
|
+
if (ipIsV4 !== subnetIsV4) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
// Delegate to the appropriate subnet matching function
|
|
140
|
+
if (ipIsV4) {
|
|
141
|
+
return matchIPv4Subnet(addr, subnet);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return matchIPv6Subnet(addr, subnet);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function isValidIP(ip) {
|
|
148
|
+
return isIPv4(ip) || isIPv6(ip);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Checks if an IPv4 address matches a subnet or specific IPv4 address.
|
|
152
|
+
*
|
|
153
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
154
|
+
*
|
|
155
|
+
* @param addr The IP address to check (IPv4)
|
|
156
|
+
* @param subnet The subnet in CIDR notation (e.g., "192.168.1.0/24") or a specific IP address
|
|
157
|
+
* @returns true if the IP address matches the subnet or IP, false otherwise
|
|
158
|
+
* @example Check if the address is a IPv6
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* import { matchIPv4Subnet } from "@std/net/unstable-ip"
|
|
162
|
+
* import { assert, assertFalse } from "@std/assert"
|
|
163
|
+
*
|
|
164
|
+
* assert(matchIPv4Subnet("192.168.1.10", "192.168.1.0/24"));
|
|
165
|
+
* assertFalse(matchIPv4Subnet("192.168.2.10", "192.168.1.0/24"));
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
function matchIPv4Subnet(addr, subnet) {
|
|
169
|
+
const [subnetIP, prefixLengthStr] = subnet.split("/");
|
|
170
|
+
const prefix = parseInt(prefixLengthStr, 10);
|
|
171
|
+
if (isNaN(prefix)) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
if (!subnetIP ||
|
|
175
|
+
subnetIP === "" ||
|
|
176
|
+
!prefixLengthStr ||
|
|
177
|
+
prefixLengthStr === "") {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
if (prefix < 0 || prefix > 32) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
// Special case: /0 matches all IPv4 addresses
|
|
184
|
+
if (prefix === 0) {
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
const ipBytes = addr.split(".").map(Number);
|
|
188
|
+
const subnetBytes = subnetIP.split(".").map(Number);
|
|
189
|
+
if (ipBytes.length !== 4 || subnetBytes.length !== 4) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
const mask = (0xffffffff << (32 - prefix)) >>> 0;
|
|
193
|
+
const ipInt = (ipBytes[0] << 24) |
|
|
194
|
+
(ipBytes[1] << 16) |
|
|
195
|
+
(ipBytes[2] << 8) |
|
|
196
|
+
ipBytes[3];
|
|
197
|
+
const subnetInt = (subnetBytes[0] << 24) |
|
|
198
|
+
(subnetBytes[1] << 16) |
|
|
199
|
+
(subnetBytes[2] << 8) |
|
|
200
|
+
subnetBytes[3];
|
|
201
|
+
return ((ipInt >>> 0) & mask) === ((subnetInt >>> 0) & mask);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Checks if an IPv6 address matches a subnet or specific IPv6 address.
|
|
205
|
+
*
|
|
206
|
+
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
207
|
+
*
|
|
208
|
+
* @param addr The IP address to check (IPv6)
|
|
209
|
+
* @param subnet The subnet in CIDR notation (e.g., "2001:db8::/64") or a specific IP address
|
|
210
|
+
* @returns true if the IP address matches the subnet or IP, false otherwise
|
|
211
|
+
* @example Check if the address is a IPv6
|
|
212
|
+
*
|
|
213
|
+
* ```ts
|
|
214
|
+
* import { matchIPv6Subnet } from "@std/net/unstable-ip"
|
|
215
|
+
* import { assert, assertFalse } from "@std/assert"
|
|
216
|
+
*
|
|
217
|
+
* assert(matchIPv6Subnet("2001:db8::ffff", "2001:db8::/64"));
|
|
218
|
+
* assertFalse(matchIPv6Subnet("2001:db9::1", "2001:db8::/64"));
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
function matchIPv6Subnet(addr, subnet) {
|
|
222
|
+
const [subnetIP, prefixLengthStr] = subnet.split("/");
|
|
223
|
+
const prefix = parseInt(prefixLengthStr, 10);
|
|
224
|
+
if (isNaN(prefix)) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
if (!subnetIP ||
|
|
228
|
+
subnetIP === "" ||
|
|
229
|
+
!prefixLengthStr ||
|
|
230
|
+
prefixLengthStr === "") {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
if (prefix < 0 || prefix > 128) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
if (prefix === 0) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
const ipExpanded = expandIPv6(addr);
|
|
240
|
+
const subnetExpanded = expandIPv6(subnetIP);
|
|
241
|
+
if (!ipExpanded || !subnetExpanded) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
const ipBytes = ipv6ToBytes(ipExpanded);
|
|
245
|
+
const subnetBytes = ipv6ToBytes(subnetExpanded);
|
|
246
|
+
const fullBytes = Math.floor(prefix / 8);
|
|
247
|
+
const remainingBits = prefix % 8;
|
|
248
|
+
for (let i = 0; i < fullBytes; i++) {
|
|
249
|
+
if (ipBytes[i] !== subnetBytes[i]) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (remainingBits > 0) {
|
|
254
|
+
const mask = 0xff << (8 - remainingBits);
|
|
255
|
+
const ipByte = ipBytes[fullBytes];
|
|
256
|
+
const subnetByte = subnetBytes[fullBytes];
|
|
257
|
+
return (ipByte & mask) === (subnetByte & mask);
|
|
258
|
+
}
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
function expandIPv6(addr) {
|
|
262
|
+
if (addr.includes(".")) {
|
|
263
|
+
const parts = addr.split(":");
|
|
264
|
+
const ipv4Part = parts.pop();
|
|
265
|
+
if (!ipv4Part) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
const ipv4Bytes = ipv4Part.split(".").map(Number);
|
|
269
|
+
if (ipv4Bytes.length !== 4) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
const ipv4Hex = ((ipv4Bytes[0] << 8) | ipv4Bytes[1]).toString(16).padStart(4, "0") +
|
|
273
|
+
":" +
|
|
274
|
+
((ipv4Bytes[2] << 8) | ipv4Bytes[3]).toString(16).padStart(4, "0");
|
|
275
|
+
addr = parts.join(":") + ":" + ipv4Hex;
|
|
276
|
+
}
|
|
277
|
+
let expanded = addr;
|
|
278
|
+
// Handle ::
|
|
279
|
+
if (expanded.includes("::")) {
|
|
280
|
+
const parts = expanded.split("::");
|
|
281
|
+
const leftParts = parts[0] ? parts[0].split(":") : [];
|
|
282
|
+
const rightParts = parts[1] ? parts[1].split(":") : [];
|
|
283
|
+
const missingParts = 8 - leftParts.length - rightParts.length;
|
|
284
|
+
expanded = leftParts
|
|
285
|
+
.concat(new Array(missingParts).fill("0"))
|
|
286
|
+
.concat(rightParts)
|
|
287
|
+
.join(":");
|
|
288
|
+
}
|
|
289
|
+
// Pad each hextet to 4 digits
|
|
290
|
+
return expanded
|
|
291
|
+
.split(":")
|
|
292
|
+
.map((hextet) => hextet.padStart(4, "0"))
|
|
293
|
+
.join(":");
|
|
294
|
+
}
|
|
295
|
+
function ipv6ToBytes(expandedIPv6) {
|
|
296
|
+
const hextets = expandedIPv6.split(":");
|
|
297
|
+
const bytes = [];
|
|
298
|
+
for (const hextet of hextets) {
|
|
299
|
+
const value = parseInt(hextet, 16);
|
|
300
|
+
bytes.push((value >> 8) & 0xff, value & 0xff);
|
|
301
|
+
}
|
|
302
|
+
return bytes;
|
|
303
|
+
}
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
20
|
import { type TransportProvider } from "./1_transport_provider.js";
|
|
21
|
-
export declare function transportProviderMtproxy(
|
|
21
|
+
export declare function transportProviderMtproxy(url: string): TransportProvider;
|
|
22
22
|
export declare function transportProviderMtproxy(hostname: string, port: number, secret: Uint8Array<ArrayBuffer>): TransportProvider;
|
|
23
23
|
//# sourceMappingURL=2_transport_provider_mtproxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"2_transport_provider_mtproxy.d.ts","sourceRoot":"","sources":["../../src/transport/2_transport_provider_mtproxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,EAAW,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE5E,wBAAgB,wBAAwB,CAAC,
|
|
1
|
+
{"version":3,"file":"2_transport_provider_mtproxy.d.ts","sourceRoot":"","sources":["../../src/transport/2_transport_provider_mtproxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,EAAW,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE5E,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAAC;AACzE,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,iBAAiB,CAAC"}
|
|
@@ -25,10 +25,10 @@ const _1_connection_tcp_js_1 = require("../connection/1_connection_tcp.js");
|
|
|
25
25
|
const _1_connection_tls_js_1 = require("../connection/1_connection_tls.js");
|
|
26
26
|
const _1_transport_intermediate_js_1 = require("./1_transport_intermediate.js");
|
|
27
27
|
const _1_transport_provider_js_1 = require("./1_transport_provider.js");
|
|
28
|
-
function transportProviderMtproxy(
|
|
29
|
-
let hostname =
|
|
28
|
+
function transportProviderMtproxy(urlOrHostname, port, secret) {
|
|
29
|
+
let hostname = urlOrHostname;
|
|
30
30
|
if (port === undefined && secret === undefined) {
|
|
31
|
-
const url = new URL(
|
|
31
|
+
const url = new URL(urlOrHostname);
|
|
32
32
|
const hostname_ = url.searchParams.get("server");
|
|
33
33
|
const port_ = url.searchParams.get("port");
|
|
34
34
|
const secret_ = url.searchParams.get("secret");
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
3
|
+
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
4
|
+
*
|
|
5
|
+
* This file is part of MTKruto.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU Lesser General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
18
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
import { type TransportProvider } from "./1_transport_provider.js";
|
|
21
|
+
export interface TransportProviderSocks5Params {
|
|
22
|
+
username: string;
|
|
23
|
+
password: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function transportProviderSocks5(url: string): TransportProvider;
|
|
26
|
+
export declare function transportProviderSocks5(hostname: string, port: number, params?: TransportProviderSocks5Params): TransportProvider;
|
|
27
|
+
//# sourceMappingURL=2_transport_provider_socks5.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"2_transport_provider_socks5.d.ts","sourceRoot":"","sources":["../../src/transport/2_transport_provider_socks5.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAEtF,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAAC;AACxE,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,6BAA6B,GAAG,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
4
|
+
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
5
|
+
*
|
|
6
|
+
* This file is part of MTKruto.
|
|
7
|
+
*
|
|
8
|
+
* This program is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU Lesser General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
19
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.transportProviderSocks5 = transportProviderSocks5;
|
|
23
|
+
const _1_connection_socks5_node_js_1 = require("../connection/1_connection_socks5.node.js");
|
|
24
|
+
const _0_deps_js_1 = require("../0_deps.js");
|
|
25
|
+
const _1_transport_abridged_js_1 = require("./1_transport_abridged.js");
|
|
26
|
+
const _1_transport_provider_js_1 = require("./1_transport_provider.js");
|
|
27
|
+
function transportProviderSocks5(urlOrHostname, port, params) {
|
|
28
|
+
let hostname = urlOrHostname;
|
|
29
|
+
if (port === undefined && params === undefined) {
|
|
30
|
+
const url = new URL(urlOrHostname);
|
|
31
|
+
const hostname_ = url.hostname;
|
|
32
|
+
const port_ = url.port || "1080";
|
|
33
|
+
const username = url.username;
|
|
34
|
+
const password = url.password;
|
|
35
|
+
if (!hostname_ || !port_) {
|
|
36
|
+
throw new TypeError("Invalid SOCKS5 URL.");
|
|
37
|
+
}
|
|
38
|
+
hostname = hostname_;
|
|
39
|
+
port = parseInt(port_);
|
|
40
|
+
params = { ...(params ?? {}), username, password };
|
|
41
|
+
}
|
|
42
|
+
return ({ dc, isCdn }) => {
|
|
43
|
+
const dcId = (0, _1_transport_provider_js_1.getDcId)(dc, isCdn);
|
|
44
|
+
const connection = new _1_connection_socks5_node_js_1.ConnectionSocks5((0, _1_transport_provider_js_1.getDcIps)(dc, (0, _0_deps_js_1.isIPv6)(hostname) ? "ipv6" : "ipv4")[0], 80, hostname, port, params);
|
|
45
|
+
const transport = new _1_transport_abridged_js_1.TransportAbridged(connection, false);
|
|
46
|
+
return { connection, transport, dcId };
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -57,7 +57,7 @@ function constructStarTransaction(starTransaction, getPeer) {
|
|
|
57
57
|
description: starTransaction.description,
|
|
58
58
|
transactionDate: starTransaction.transaction_date,
|
|
59
59
|
transactionUrl: starTransaction.transaction_url,
|
|
60
|
-
botPayload:
|
|
60
|
+
botPayload: starTransaction.bot_payload ? (0, _1_utilities_js_1.decodeText)(starTransaction.bot_payload) : undefined,
|
|
61
61
|
messageId: starTransaction.msg_id,
|
|
62
62
|
subscriptionPeriod: starTransaction.subscription_period,
|
|
63
63
|
giveawayMessageId: starTransaction.giveaway_post_id,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
3
|
+
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
4
|
+
*
|
|
5
|
+
* This file is part of MTKruto.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU Lesser General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
18
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
export declare function ipv4ToBytes(ipv4: string): number[];
|
|
21
|
+
export declare function ipv6ToBytes(ipv6: string): number[];
|
|
22
|
+
//# sourceMappingURL=0_ip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"0_ip.d.ts","sourceRoot":"","sources":["../../src/utilities/0_ip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAElD;AAGD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAOlD"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
4
|
+
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
5
|
+
*
|
|
6
|
+
* This file is part of MTKruto.
|
|
7
|
+
*
|
|
8
|
+
* This program is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU Lesser General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
19
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.ipv4ToBytes = ipv4ToBytes;
|
|
23
|
+
exports.ipv6ToBytes = ipv6ToBytes;
|
|
24
|
+
function ipv4ToBytes(ipv4) {
|
|
25
|
+
return ipv4.split(".").map(Number);
|
|
26
|
+
}
|
|
27
|
+
// https://jsr.io/@std/net/1.0.6/unstable_ip.ts
|
|
28
|
+
function ipv6ToBytes(ipv6) {
|
|
29
|
+
const expandedIpv6 = expandIpv6(ipv6);
|
|
30
|
+
if (expandedIpv6 === null) {
|
|
31
|
+
throw new TypeError("Invalid IPv6");
|
|
32
|
+
}
|
|
33
|
+
return expandedIpv6ToBytes(expandedIpv6);
|
|
34
|
+
}
|
|
35
|
+
function expandIpv6(addr) {
|
|
36
|
+
if (addr.includes(".")) {
|
|
37
|
+
const parts = addr.split(":");
|
|
38
|
+
const ipv4Part = parts.pop();
|
|
39
|
+
if (!ipv4Part) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const ipv4Bytes = ipv4Part.split(".").map(Number);
|
|
43
|
+
if (ipv4Bytes.length !== 4) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const ipv4Hex = ((ipv4Bytes[0] << 8) | ipv4Bytes[1]).toString(16).padStart(4, "0") +
|
|
47
|
+
":" +
|
|
48
|
+
((ipv4Bytes[2] << 8) | ipv4Bytes[3]).toString(16).padStart(4, "0");
|
|
49
|
+
addr = parts.join(":") + ":" + ipv4Hex;
|
|
50
|
+
}
|
|
51
|
+
let expanded = addr;
|
|
52
|
+
// Handle ::
|
|
53
|
+
if (expanded.includes("::")) {
|
|
54
|
+
const parts = expanded.split("::");
|
|
55
|
+
const leftParts = parts[0] ? parts[0].split(":") : [];
|
|
56
|
+
const rightParts = parts[1] ? parts[1].split(":") : [];
|
|
57
|
+
const missingParts = 8 - leftParts.length - rightParts.length;
|
|
58
|
+
expanded = leftParts
|
|
59
|
+
.concat(new Array(missingParts).fill("0"))
|
|
60
|
+
.concat(rightParts)
|
|
61
|
+
.join(":");
|
|
62
|
+
}
|
|
63
|
+
// Pad each hextet to 4 digits
|
|
64
|
+
return expanded
|
|
65
|
+
.split(":")
|
|
66
|
+
.map((hextet) => hextet.padStart(4, "0"))
|
|
67
|
+
.join(":");
|
|
68
|
+
}
|
|
69
|
+
function expandedIpv6ToBytes(expandedIPv6) {
|
|
70
|
+
const hextets = expandedIPv6.split(":");
|
|
71
|
+
const bytes = [];
|
|
72
|
+
for (const hextet of hextets) {
|
|
73
|
+
const value = parseInt(hextet, 16);
|
|
74
|
+
bytes.push((value >> 8) & 0xff, value & 0xff);
|
|
75
|
+
}
|
|
76
|
+
return bytes;
|
|
77
|
+
}
|