@mtkruto/browser 0.133.0 → 0.135.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.
Files changed (133) hide show
  1. package/esm/0_deps.d.ts +1 -0
  2. package/esm/0_deps.d.ts.map +1 -1
  3. package/esm/0_deps.js +1 -0
  4. package/esm/1_utilities.d.ts +1 -0
  5. package/esm/1_utilities.d.ts.map +1 -1
  6. package/esm/1_utilities.js +1 -0
  7. package/esm/2_connection.d.ts +1 -0
  8. package/esm/2_connection.d.ts.map +1 -1
  9. package/esm/2_connection.js +1 -0
  10. package/esm/3_transport.d.ts +1 -0
  11. package/esm/3_transport.d.ts.map +1 -1
  12. package/esm/3_transport.js +1 -0
  13. package/esm/3_types.d.ts +1 -0
  14. package/esm/3_types.d.ts.map +1 -1
  15. package/esm/3_types.js +1 -0
  16. package/esm/client/0_params.d.ts +24 -2
  17. package/esm/client/0_params.d.ts.map +1 -1
  18. package/esm/client/0_utilities.d.ts +1 -1
  19. package/esm/client/0_utilities.d.ts.map +1 -1
  20. package/esm/client/1_client_generic.d.ts +11 -3
  21. package/esm/client/1_client_generic.d.ts.map +1 -1
  22. package/esm/client/3_message_manager.d.ts.map +1 -1
  23. package/esm/client/3_message_manager.js +13 -9
  24. package/esm/client/4_gift_manager.d.ts +3 -2
  25. package/esm/client/4_gift_manager.d.ts.map +1 -1
  26. package/esm/client/4_gift_manager.js +9 -0
  27. package/esm/client/4_poll_manager.js +1 -1
  28. package/esm/client/6_client.d.ts +11 -3
  29. package/esm/client/6_client.d.ts.map +1 -1
  30. package/esm/client/6_client.js +11 -1
  31. package/esm/client/6_client_dispatcher.d.ts +11 -3
  32. package/esm/client/6_client_dispatcher.d.ts.map +1 -1
  33. package/esm/client/6_client_dispatcher.js +11 -1
  34. package/esm/connection/1_connection_socks5.d.ts +36 -0
  35. package/esm/connection/1_connection_socks5.d.ts.map +1 -0
  36. package/esm/connection/1_connection_socks5.js +192 -0
  37. package/esm/connection/1_connection_socks5.node.d.ts +35 -0
  38. package/esm/connection/1_connection_socks5.node.d.ts.map +1 -0
  39. package/esm/connection/1_connection_socks5.node.js +214 -0
  40. package/esm/connection/1_connection_tcp.d.ts.map +1 -1
  41. package/esm/connection/1_connection_tcp.js +0 -1
  42. package/esm/deps/jsr.io/@std/net/1.0.6/unstable_ip.d.ts +103 -0
  43. package/esm/deps/jsr.io/@std/net/1.0.6/unstable_ip.d.ts.map +1 -0
  44. package/esm/deps/jsr.io/@std/net/1.0.6/unstable_ip.js +296 -0
  45. package/esm/tl/1_telegram_api.d.ts +1616 -10
  46. package/esm/tl/1_telegram_api.d.ts.map +1 -1
  47. package/esm/tl/1_telegram_api.js +333 -48
  48. package/esm/transport/2_transport_provider_mtproxy.d.ts +1 -1
  49. package/esm/transport/2_transport_provider_mtproxy.d.ts.map +1 -1
  50. package/esm/transport/2_transport_provider_mtproxy.js +3 -3
  51. package/esm/transport/2_transport_provider_socks5.d.ts +27 -0
  52. package/esm/transport/2_transport_provider_socks5.d.ts.map +1 -0
  53. package/esm/transport/2_transport_provider_socks5.js +45 -0
  54. package/esm/types/0_premium_subscription_duration.d.ts +21 -0
  55. package/esm/types/0_premium_subscription_duration.d.ts.map +1 -0
  56. package/esm/types/0_premium_subscription_duration.js +20 -0
  57. package/esm/types/3_poll_option.d.ts +1 -1
  58. package/esm/types/3_poll_option.d.ts.map +1 -1
  59. package/esm/types/3_poll_option.js +2 -1
  60. package/esm/types/4_poll.d.ts +3 -3
  61. package/esm/types/4_poll.d.ts.map +1 -1
  62. package/esm/types/4_poll.js +5 -3
  63. package/esm/types/5_star_transaction.js +2 -2
  64. package/esm/utilities/0_ip.d.ts +22 -0
  65. package/esm/utilities/0_ip.d.ts.map +1 -0
  66. package/esm/utilities/0_ip.js +73 -0
  67. package/package.json +1 -1
  68. package/script/0_deps.d.ts +1 -0
  69. package/script/0_deps.d.ts.map +1 -1
  70. package/script/0_deps.js +4 -1
  71. package/script/1_utilities.d.ts +1 -0
  72. package/script/1_utilities.d.ts.map +1 -1
  73. package/script/1_utilities.js +1 -0
  74. package/script/2_connection.d.ts +1 -0
  75. package/script/2_connection.d.ts.map +1 -1
  76. package/script/2_connection.js +1 -0
  77. package/script/3_transport.d.ts +1 -0
  78. package/script/3_transport.d.ts.map +1 -1
  79. package/script/3_transport.js +1 -0
  80. package/script/3_types.d.ts +1 -0
  81. package/script/3_types.d.ts.map +1 -1
  82. package/script/3_types.js +1 -0
  83. package/script/client/0_params.d.ts +24 -2
  84. package/script/client/0_params.d.ts.map +1 -1
  85. package/script/client/0_utilities.d.ts +1 -1
  86. package/script/client/0_utilities.d.ts.map +1 -1
  87. package/script/client/1_client_generic.d.ts +11 -3
  88. package/script/client/1_client_generic.d.ts.map +1 -1
  89. package/script/client/3_message_manager.d.ts.map +1 -1
  90. package/script/client/3_message_manager.js +13 -9
  91. package/script/client/4_gift_manager.d.ts +3 -2
  92. package/script/client/4_gift_manager.d.ts.map +1 -1
  93. package/script/client/4_gift_manager.js +9 -0
  94. package/script/client/4_poll_manager.js +1 -1
  95. package/script/client/6_client.d.ts +11 -3
  96. package/script/client/6_client.d.ts.map +1 -1
  97. package/script/client/6_client.js +11 -1
  98. package/script/client/6_client_dispatcher.d.ts +11 -3
  99. package/script/client/6_client_dispatcher.d.ts.map +1 -1
  100. package/script/client/6_client_dispatcher.js +11 -1
  101. package/script/connection/1_connection_socks5.d.ts +36 -0
  102. package/script/connection/1_connection_socks5.d.ts.map +1 -0
  103. package/script/connection/1_connection_socks5.js +196 -0
  104. package/script/connection/1_connection_socks5.node.d.ts +35 -0
  105. package/script/connection/1_connection_socks5.node.d.ts.map +1 -0
  106. package/script/connection/1_connection_socks5.node.js +218 -0
  107. package/script/connection/1_connection_tcp.d.ts.map +1 -1
  108. package/script/connection/1_connection_tcp.js +0 -1
  109. package/script/deps/jsr.io/@std/net/1.0.6/unstable_ip.d.ts +103 -0
  110. package/script/deps/jsr.io/@std/net/1.0.6/unstable_ip.d.ts.map +1 -0
  111. package/script/deps/jsr.io/@std/net/1.0.6/unstable_ip.js +303 -0
  112. package/script/tl/1_telegram_api.d.ts +1616 -10
  113. package/script/tl/1_telegram_api.d.ts.map +1 -1
  114. package/script/tl/1_telegram_api.js +333 -48
  115. package/script/transport/2_transport_provider_mtproxy.d.ts +1 -1
  116. package/script/transport/2_transport_provider_mtproxy.d.ts.map +1 -1
  117. package/script/transport/2_transport_provider_mtproxy.js +3 -3
  118. package/script/transport/2_transport_provider_socks5.d.ts +27 -0
  119. package/script/transport/2_transport_provider_socks5.d.ts.map +1 -0
  120. package/script/transport/2_transport_provider_socks5.js +48 -0
  121. package/script/types/0_premium_subscription_duration.d.ts +21 -0
  122. package/script/types/0_premium_subscription_duration.d.ts.map +1 -0
  123. package/script/types/0_premium_subscription_duration.js +21 -0
  124. package/script/types/3_poll_option.d.ts +1 -1
  125. package/script/types/3_poll_option.d.ts.map +1 -1
  126. package/script/types/3_poll_option.js +2 -1
  127. package/script/types/4_poll.d.ts +3 -3
  128. package/script/types/4_poll.d.ts.map +1 -1
  129. package/script/types/4_poll.js +5 -3
  130. package/script/types/5_star_transaction.js +1 -1
  131. package/script/utilities/0_ip.d.ts +22 -0
  132. package/script/utilities/0_ip.d.ts.map +1 -0
  133. package/script/utilities/0_ip.js +77 -0
@@ -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
+ }