@mtkruto/node 0.132.0 → 0.132.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.
Files changed (83) hide show
  1. package/esm/0_deps.d.ts +2 -2
  2. package/esm/0_deps.d.ts.map +1 -1
  3. package/esm/0_deps.js +2 -2
  4. package/esm/2_connection.d.ts +2 -0
  5. package/esm/2_connection.d.ts.map +1 -1
  6. package/esm/2_connection.js +2 -0
  7. package/esm/3_transport.d.ts +1 -0
  8. package/esm/3_transport.d.ts.map +1 -1
  9. package/esm/3_transport.js +1 -0
  10. package/esm/connection/0_get_tls_header.d.ts +2 -0
  11. package/esm/connection/0_get_tls_header.d.ts.map +1 -0
  12. package/esm/connection/0_get_tls_header.js +152 -0
  13. package/esm/connection/1_connection_tcp.node.d.ts.map +1 -1
  14. package/esm/connection/1_connection_tcp.node.js +4 -4
  15. package/esm/connection/1_connection_tls.node.d.ts +31 -0
  16. package/esm/connection/1_connection_tls.node.d.ts.map +1 -0
  17. package/esm/connection/1_connection_tls.node.js +199 -0
  18. package/esm/deps/jsr.io/@std/io/0.225.3/write_all.d.ts +52 -0
  19. package/esm/deps/jsr.io/@std/io/0.225.3/write_all.d.ts.map +1 -0
  20. package/esm/deps/jsr.io/@std/io/0.225.3/write_all.js +61 -0
  21. package/esm/session/2_session_encrypted.d.ts.map +1 -1
  22. package/esm/session/2_session_encrypted.js +4 -1
  23. package/esm/transport/0_obfuscation.d.ts +5 -1
  24. package/esm/transport/0_obfuscation.d.ts.map +1 -1
  25. package/esm/transport/0_obfuscation.js +17 -4
  26. package/esm/transport/1_transport_intermediate.d.ts +7 -20
  27. package/esm/transport/1_transport_intermediate.d.ts.map +1 -1
  28. package/esm/transport/1_transport_intermediate.js +18 -7
  29. package/esm/transport/2_transport_provider_mtproxy.d.ts +23 -0
  30. package/esm/transport/2_transport_provider_mtproxy.d.ts.map +1 -0
  31. package/esm/transport/2_transport_provider_mtproxy.js +51 -0
  32. package/esm/transport/2_transport_provider_web_socket.js +1 -1
  33. package/esm/utilities/1_crypto.d.ts +1 -0
  34. package/esm/utilities/1_crypto.d.ts.map +1 -1
  35. package/esm/utilities/1_crypto.js +4 -0
  36. package/package.json +1 -1
  37. package/script/0_deps.d.ts +2 -2
  38. package/script/0_deps.d.ts.map +1 -1
  39. package/script/0_deps.js +4 -3
  40. package/script/2_connection.d.ts +2 -0
  41. package/script/2_connection.d.ts.map +1 -1
  42. package/script/2_connection.js +2 -0
  43. package/script/3_transport.d.ts +1 -0
  44. package/script/3_transport.d.ts.map +1 -1
  45. package/script/3_transport.js +1 -0
  46. package/script/connection/0_get_tls_header.d.ts +2 -0
  47. package/script/connection/0_get_tls_header.d.ts.map +1 -0
  48. package/script/connection/0_get_tls_header.js +188 -0
  49. package/script/connection/1_connection_tcp.node.d.ts.map +1 -1
  50. package/script/connection/1_connection_tcp.node.js +4 -4
  51. package/script/connection/1_connection_tls.node.d.ts +31 -0
  52. package/script/connection/1_connection_tls.node.d.ts.map +1 -0
  53. package/script/connection/1_connection_tls.node.js +203 -0
  54. package/script/deps/jsr.io/@std/io/0.225.3/write_all.d.ts +52 -0
  55. package/script/deps/jsr.io/@std/io/0.225.3/write_all.d.ts.map +1 -0
  56. package/script/deps/jsr.io/@std/io/0.225.3/write_all.js +65 -0
  57. package/script/session/2_session_encrypted.d.ts.map +1 -1
  58. package/script/session/2_session_encrypted.js +4 -1
  59. package/script/transport/0_obfuscation.d.ts +5 -1
  60. package/script/transport/0_obfuscation.d.ts.map +1 -1
  61. package/script/transport/0_obfuscation.js +16 -3
  62. package/script/transport/1_transport_intermediate.d.ts +7 -20
  63. package/script/transport/1_transport_intermediate.d.ts.map +1 -1
  64. package/script/transport/1_transport_intermediate.js +52 -8
  65. package/script/transport/2_transport_provider_mtproxy.d.ts +23 -0
  66. package/script/transport/2_transport_provider_mtproxy.d.ts.map +1 -0
  67. package/script/transport/2_transport_provider_mtproxy.js +54 -0
  68. package/script/transport/2_transport_provider_web_socket.js +1 -1
  69. package/script/utilities/1_crypto.d.ts +1 -0
  70. package/script/utilities/1_crypto.d.ts.map +1 -1
  71. package/script/utilities/1_crypto.js +5 -0
  72. package/esm/deps/jsr.io/@std/io/0.225.3/_constants.d.ts +0 -3
  73. package/esm/deps/jsr.io/@std/io/0.225.3/_constants.d.ts.map +0 -1
  74. package/esm/deps/jsr.io/@std/io/0.225.3/_constants.js +0 -4
  75. package/esm/deps/jsr.io/@std/io/0.225.3/iterate_reader.d.ts +0 -80
  76. package/esm/deps/jsr.io/@std/io/0.225.3/iterate_reader.d.ts.map +0 -1
  77. package/esm/deps/jsr.io/@std/io/0.225.3/iterate_reader.js +0 -96
  78. package/script/deps/jsr.io/@std/io/0.225.3/_constants.d.ts +0 -3
  79. package/script/deps/jsr.io/@std/io/0.225.3/_constants.d.ts.map +0 -1
  80. package/script/deps/jsr.io/@std/io/0.225.3/_constants.js +0 -7
  81. package/script/deps/jsr.io/@std/io/0.225.3/iterate_reader.d.ts +0 -80
  82. package/script/deps/jsr.io/@std/io/0.225.3/iterate_reader.d.ts.map +0 -1
  83. package/script/deps/jsr.io/@std/io/0.225.3/iterate_reader.js +0 -100
package/esm/0_deps.d.ts CHANGED
@@ -33,11 +33,11 @@ export { concat } from "./deps/jsr.io/@std/bytes/1.0.6/concat.js";
33
33
  export { equals } from "./deps/jsr.io/@std/bytes/1.0.6/equals.js";
34
34
  export { startsWith } from "./deps/jsr.io/@std/bytes/1.0.6/starts_with.js";
35
35
  export { LruCache } from "./deps/jsr.io/@std/cache/0.2.2/lru_cache.js";
36
- export { iterateReader } from "./deps/jsr.io/@std/io/0.225.3/iterate_reader.js";
36
+ export { writeAll } from "./deps/jsr.io/@std/io/0.225.3/write_all.js";
37
37
  export { format } from "./deps/jsr.io/@std/datetime/0.225.7/format.js";
38
38
  export { MINUTE, SECOND } from "./deps/jsr.io/@std/datetime/0.225.7/constants.js";
39
39
  export { toArrayBuffer } from "./deps/jsr.io/@std/streams/1.0.17/to_array_buffer.js";
40
- export { encodeHex } from "./deps/jsr.io/@std/encoding/1.0.10/hex.js";
40
+ export { decodeHex, encodeHex } from "./deps/jsr.io/@std/encoding/1.0.10/hex.js";
41
41
  export { decodeBase64, encodeBase64 } from "./deps/jsr.io/@std/encoding/1.0.10/base64.js";
42
42
  import { contentType as contentType_ } from "./deps/jsr.io/@std/media-types/1.1.0/content_type.js";
43
43
  export declare const contentType: typeof contentType_;
@@ -1 +1 @@
1
- {"version":3,"file":"0_deps.d.ts","sourceRoot":"","sources":["../src/0_deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,4CAA4C,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,iDAAiD,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAErF,OAAO,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,0CAA0C,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,8CAA8C,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAE1E,OAAO,EAAE,KAAK,EAAE,MAAM,yCAAyC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAEnE,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,+CAA+C,CAAC;AAE3E,OAAO,EAAE,QAAQ,EAAE,MAAM,6CAA6C,CAAC;AAEvE,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAEhF,OAAO,EAAE,MAAM,EAAE,MAAM,+CAA+C,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kDAAkD,CAAC;AAElF,OAAO,EAAE,aAAa,EAAE,MAAM,sDAAsD,CAAC;AAErF,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,8CAA8C,CAAC;AAE1F,OAAO,EAAE,WAAW,IAAI,YAAY,EAAE,MAAM,sDAAsD,CAAC;AACnG,eAAO,MAAM,WAAW,EAAE,OAAO,YAMhC,CAAC;AAEF,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,UAMzC;AAED,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM,+CAA+C,CAAC"}
1
+ {"version":3,"file":"0_deps.d.ts","sourceRoot":"","sources":["../src/0_deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,4CAA4C,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,iDAAiD,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAErF,OAAO,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,0CAA0C,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,8CAA8C,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAE1E,OAAO,EAAE,KAAK,EAAE,MAAM,yCAAyC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAEnE,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,+CAA+C,CAAC;AAE3E,OAAO,EAAE,QAAQ,EAAE,MAAM,6CAA6C,CAAC;AAEvE,OAAO,EAAE,QAAQ,EAAE,MAAM,4CAA4C,CAAC;AAEtE,OAAO,EAAE,MAAM,EAAE,MAAM,+CAA+C,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kDAAkD,CAAC;AAElF,OAAO,EAAE,aAAa,EAAE,MAAM,sDAAsD,CAAC;AAErF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,8CAA8C,CAAC;AAE1F,OAAO,EAAE,WAAW,IAAI,YAAY,EAAE,MAAM,sDAAsD,CAAC;AACnG,eAAO,MAAM,WAAW,EAAE,OAAO,YAMhC,CAAC;AAEF,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,UAMzC;AAED,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM,+CAA+C,CAAC"}
package/esm/0_deps.js CHANGED
@@ -33,11 +33,11 @@ export { concat } from "./deps/jsr.io/@std/bytes/1.0.6/concat.js";
33
33
  export { equals } from "./deps/jsr.io/@std/bytes/1.0.6/equals.js";
34
34
  export { startsWith } from "./deps/jsr.io/@std/bytes/1.0.6/starts_with.js";
35
35
  export { LruCache } from "./deps/jsr.io/@std/cache/0.2.2/lru_cache.js";
36
- export { iterateReader } from "./deps/jsr.io/@std/io/0.225.3/iterate_reader.js";
36
+ export { writeAll } from "./deps/jsr.io/@std/io/0.225.3/write_all.js";
37
37
  export { format } from "./deps/jsr.io/@std/datetime/0.225.7/format.js";
38
38
  export { MINUTE, SECOND } from "./deps/jsr.io/@std/datetime/0.225.7/constants.js";
39
39
  export { toArrayBuffer } from "./deps/jsr.io/@std/streams/1.0.17/to_array_buffer.js";
40
- export { encodeHex } from "./deps/jsr.io/@std/encoding/1.0.10/hex.js";
40
+ export { decodeHex, encodeHex } from "./deps/jsr.io/@std/encoding/1.0.10/hex.js";
41
41
  export { decodeBase64, encodeBase64 } from "./deps/jsr.io/@std/encoding/1.0.10/base64.js";
42
42
  import { contentType as contentType_ } from "./deps/jsr.io/@std/media-types/1.1.0/content_type.js";
43
43
  export const contentType = (extentionOrType) => {
@@ -18,5 +18,7 @@
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
20
  export * from "./connection/0_connection.js";
21
+ export * from "./connection/1_connection_tcp.node.js";
22
+ export * from "./connection/1_connection_tls.node.js";
21
23
  export * from "./connection/1_connection_web_socket.js";
22
24
  //# sourceMappingURL=2_connection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"2_connection.d.ts","sourceRoot":"","sources":["../src/2_connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yCAAyC,CAAC"}
1
+ {"version":3,"file":"2_connection.d.ts","sourceRoot":"","sources":["../src/2_connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uCAAuC,CAAC;AACtD,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC"}
@@ -18,4 +18,6 @@
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
20
  export * from "./connection/0_connection.js";
21
+ export * from "./connection/1_connection_tcp.node.js";
22
+ export * from "./connection/1_connection_tls.node.js";
21
23
  export * from "./connection/1_connection_web_socket.js";
@@ -21,6 +21,7 @@ export * from "./transport/0_transport.js";
21
21
  export * from "./transport/1_transport_abridged.js";
22
22
  export * from "./transport/1_transport_intermediate.js";
23
23
  export * from "./transport/1_transport_provider.js";
24
+ export * from "./transport/2_transport_provider_mtproxy.js";
24
25
  export * from "./transport/2_transport_provider_tcp.js";
25
26
  export * from "./transport/2_transport_provider_web_socket.js";
26
27
  //# sourceMappingURL=3_transport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"3_transport.d.ts","sourceRoot":"","sources":["../src/3_transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,yCAAyC,CAAC;AACxD,cAAc,qCAAqC,CAAC;AACpD,cAAc,yCAAyC,CAAC;AACxD,cAAc,gDAAgD,CAAC"}
1
+ {"version":3,"file":"3_transport.d.ts","sourceRoot":"","sources":["../src/3_transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,yCAAyC,CAAC;AACxD,cAAc,qCAAqC,CAAC;AACpD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,yCAAyC,CAAC;AACxD,cAAc,gDAAgD,CAAC"}
@@ -21,5 +21,6 @@ export * from "./transport/0_transport.js";
21
21
  export * from "./transport/1_transport_abridged.js";
22
22
  export * from "./transport/1_transport_intermediate.js";
23
23
  export * from "./transport/1_transport_provider.js";
24
+ export * from "./transport/2_transport_provider_mtproxy.js";
24
25
  export * from "./transport/2_transport_provider_tcp.js";
25
26
  export * from "./transport/2_transport_provider_web_socket.js";
@@ -0,0 +1,2 @@
1
+ export declare function getTlsHeader(secret: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>>;
2
+ //# sourceMappingURL=0_get_tls_header.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"0_get_tls_header.d.ts","sourceRoot":"","sources":["../../src/connection/0_get_tls_header.ts"],"names":[],"mappings":"AAIA,wBAAsB,YAAY,CAAC,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,oCASjE"}
@@ -0,0 +1,152 @@
1
+ import * as dntShim from "../_dnt.shims.js";
2
+ import { concat, decodeHex } from "../0_deps.js";
3
+ import { hmacSha256, intFromBytes, intToBytes, modExp } from "../1_utilities.js";
4
+ export async function getTlsHeader(secret) {
5
+ const array = serializeOps(ops, secret.slice(16));
6
+ secret = secret.slice(0, 16);
7
+ secret = await hmacSha256(array, secret);
8
+ array.set(secret.slice(0), 11);
9
+ const dataView = new DataView(array.buffer);
10
+ const old = dataView.getInt32(39, true);
11
+ dataView.setInt32(39, old ^ Math.floor(Date.now() / 1000), true);
12
+ return array;
13
+ }
14
+ const ops = [
15
+ { type: "string", data: new Uint8Array([0x16, 0x03, 0x01, 0x02, 0x00, 0x01, 0x00, 0x01, 0xfc, 0x03, 0x03]) },
16
+ { type: "zero", length: 32 },
17
+ { type: "string", data: new Uint8Array([0x20]) },
18
+ { type: "random", length: 32 },
19
+ { type: "string", data: new Uint8Array([0x00, 0x2a]) },
20
+ { type: "grease", seed: 0 },
21
+ { type: "string", data: new Uint8Array([0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0, 0x2b, 0xcc, 0xa9, 0xc0, 0x30, 0xc0, 0x2f, 0xcc, 0xa8, 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x9d, 0x00, 0x9c, 0x00, 0x35, 0x00, 0x2f, 0xc0, 0x08, 0xc0, 0x12, 0x00, 0x0a, 0x01, 0x00, 0x01, 0x89]) },
22
+ { type: "grease", seed: 2 },
23
+ { type: "string", data: new Uint8Array([0x00, 0x00, 0x00, 0x00]) },
24
+ { type: "beginScope" },
25
+ { type: "beginScope" },
26
+ { type: "string", data: new Uint8Array([0x00]) },
27
+ { type: "beginScope" },
28
+ { type: "domain" },
29
+ { type: "endScope" },
30
+ { type: "endScope" },
31
+ { type: "endScope" },
32
+ { type: "string", data: new Uint8Array([0x00, 0x17, 0x00, 0x00, 0xff, 0x01, 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x0a]) },
33
+ { type: "grease", seed: 4 },
34
+ { type: "string", data: new Uint8Array([0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x0c, 0x02, 0x68, 0x32, 0x08, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x16, 0x00, 0x14, 0x04, 0x03, 0x08, 0x04, 0x04, 0x01, 0x05, 0x03, 0x08, 0x05, 0x08, 0x05, 0x05, 0x01, 0x08, 0x06, 0x06, 0x01, 0x02, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x33, 0x00, 0x2b, 0x00, 0x29]) },
35
+ { type: "grease", seed: 4 },
36
+ { type: "string", data: new Uint8Array([0x00, 0x01, 0x00, 0x00, 0x1d, 0x00, 0x20]) },
37
+ { type: "key" },
38
+ { type: "string", data: new Uint8Array([0x00, 0x2d, 0x00, 0x02, 0x01, 0x01, 0x00, 0x2b, 0x00, 0x0b, 0x0a]) },
39
+ { type: "grease", seed: 6 },
40
+ { type: "string", data: new Uint8Array([0x03, 0x04, 0x03, 0x03, 0x03, 0x02, 0x03, 0x01, 0x00, 0x1b, 0x00, 0x03, 0x02, 0x00, 0x01]) },
41
+ { type: "grease", seed: 3 },
42
+ { type: "string", data: new Uint8Array([0x00, 0x01, 0x00]) },
43
+ { type: "padding" },
44
+ ];
45
+ function getGrease() {
46
+ const res = dntShim.crypto.getRandomValues(new Uint8Array(7));
47
+ for (let i = 0; i < res.length; ++i) {
48
+ res[i] = (res[i] & 0xF0) + 0x0A;
49
+ }
50
+ for (let i = 1; i < res.length; i += 2) {
51
+ if (res[i] === res[i - 1]) {
52
+ res[i] ^= 0x10;
53
+ }
54
+ }
55
+ return res;
56
+ }
57
+ function getY2(x, mod) {
58
+ let y = (x + 486662n) % mod;
59
+ y = y * x % mod;
60
+ y = (y + 1n) % mod;
61
+ return y * x % mod;
62
+ }
63
+ function getDoubleX(x, mod) {
64
+ const y2 = getY2(x, mod);
65
+ const denominator = (4n * y2) % mod;
66
+ let numerator = (x * x % mod - 1n + mod) % mod;
67
+ numerator = (numerator * numerator) % mod;
68
+ const denominatorInv = modExp(denominator, mod - 2n, mod);
69
+ numerator = (numerator * denominatorInv) % mod;
70
+ return numerator;
71
+ }
72
+ function isQuadraticResidue(a) {
73
+ const mod = 2n ** 255n - 19n;
74
+ const pow = 2n ** 254n - 10n;
75
+ const r = modExp(a, pow, mod);
76
+ return r === 1n;
77
+ }
78
+ function serializeOps(ops, domain) {
79
+ const GREASE = getGrease();
80
+ let buffer = new Uint8Array();
81
+ const scopes = new Array();
82
+ function serializeOp(op) {
83
+ switch (op.type) {
84
+ case "string":
85
+ buffer = concat([buffer, op.data]);
86
+ break;
87
+ case "random":
88
+ buffer = concat([
89
+ buffer,
90
+ dntShim.crypto.getRandomValues(new Uint8Array(op.length)),
91
+ ]);
92
+ break;
93
+ case "zero":
94
+ buffer = concat([buffer, new Uint8Array(op.length)]);
95
+ break;
96
+ case "domain":
97
+ buffer = concat([buffer, domain]);
98
+ break;
99
+ case "grease": {
100
+ const grease = GREASE[op.seed];
101
+ buffer = concat([buffer, new Uint8Array([grease, grease])]);
102
+ break;
103
+ }
104
+ case "key": {
105
+ const mod = intFromBytes(decodeHex("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"), { byteOrder: "big", isSigned: false });
106
+ let key = new Uint8Array(32);
107
+ while (true) {
108
+ dntShim.crypto.getRandomValues(key);
109
+ key[31] &= 127;
110
+ let x = intFromBytes(key, { byteOrder: "big", isSigned: false });
111
+ const y = getY2(x, mod);
112
+ if (isQuadraticResidue(y)) {
113
+ for (let i = 0; i < 3; ++i) {
114
+ x = getDoubleX(x, mod);
115
+ }
116
+ key = intToBytes(x, 32, { byteOrder: "little", isSigned: false });
117
+ break;
118
+ }
119
+ }
120
+ buffer = concat([buffer, key]);
121
+ break;
122
+ }
123
+ case "beginScope":
124
+ scopes.push(buffer.length);
125
+ buffer = concat([buffer, new Uint8Array([0, 0])]);
126
+ break;
127
+ case "endScope": {
128
+ const beginOffset = scopes.pop();
129
+ if (beginOffset === undefined) {
130
+ throw new TypeError("Invalid endScope");
131
+ }
132
+ const endOffset = buffer.length;
133
+ const size = endOffset - beginOffset - 2;
134
+ new DataView(buffer.buffer).setUint16(beginOffset, size);
135
+ break;
136
+ }
137
+ case "padding": {
138
+ const size = 513 - buffer.length;
139
+ if (size > 0) {
140
+ serializeOp({ type: "string", data: new Uint8Array([0x00, 0x15]) });
141
+ serializeOp({ type: "beginScope" });
142
+ serializeOp({ type: "zero", length: size });
143
+ serializeOp({ type: "endScope" });
144
+ }
145
+ }
146
+ }
147
+ }
148
+ for (const op of ops) {
149
+ serializeOp(op);
150
+ }
151
+ return buffer;
152
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"1_connection_tcp.node.d.ts","sourceRoot":"","sources":["../../src/connection/1_connection_tcp.node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,qBAAa,aAAc,YAAW,UAAU;;IAW9C,kBAAkB,CAAC,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC;gBAE1C,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAY1C,IAAI;IA2CJ,IAAI,WAAW,YAEd;IAQK,IAAI,CAAC,CAAC,EAAE,UAAU;IAclB,KAAK,CAAC,CAAC,EAAE,UAAU;IA0BzB,KAAK;CAKN"}
1
+ {"version":3,"file":"1_connection_tcp.node.d.ts","sourceRoot":"","sources":["../../src/connection/1_connection_tcp.node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,qBAAa,aAAc,YAAW,UAAU;;IAW9C,kBAAkB,CAAC,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC;gBAE1C,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAY1C,IAAI;IA0CJ,IAAI,WAAW,YAEd;IAQK,IAAI,CAAC,CAAC,EAAE,UAAU;IAclB,KAAK,CAAC,CAAC,EAAE,UAAU;IA0BzB,KAAK;CAKN"}
@@ -50,9 +50,10 @@ export class ConnectionTCP {
50
50
  this.#rejectRead();
51
51
  this.stateChangeHandler?.(false);
52
52
  });
53
- const mutex = new Mutex();
54
- this.#socket.on("data", async (data) => {
55
- const unlock = await mutex.lock();
53
+ this.#socket.on("data", (data) => {
54
+ if (typeof data === "string") {
55
+ return;
56
+ }
56
57
  for (const byte of data) {
57
58
  this.#buffer.push(byte);
58
59
  }
@@ -61,7 +62,6 @@ export class ConnectionTCP {
61
62
  this.#nextResolve = null;
62
63
  resolve();
63
64
  }
64
- unlock();
65
65
  });
66
66
  return new Promise((resolve, reject) => {
67
67
  this.#socket.connect(this.#port, this.#hostname);
@@ -0,0 +1,31 @@
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 { Connection } from "./0_connection.js";
21
+ export declare class ConnectionTLS implements Connection {
22
+ #private;
23
+ stateChangeHandler?: Connection["stateChangeHandler"];
24
+ constructor(hostname: string, port: number, secret: Uint8Array<ArrayBuffer>);
25
+ open(): Promise<void>;
26
+ get isConnected(): boolean;
27
+ read(p: Uint8Array): Promise<void>;
28
+ write(p: Uint8Array): Promise<void>;
29
+ close(): void;
30
+ }
31
+ //# sourceMappingURL=1_connection_tls.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"1_connection_tls.node.d.ts","sourceRoot":"","sources":["../../src/connection/1_connection_tls.node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AASpD,qBAAa,aAAc,YAAW,UAAU;;IAY9C,kBAAkB,CAAC,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC;gBAE1C,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC;IAarE,IAAI;IAyFV,IAAI,WAAW,YAEd;IAsDK,IAAI,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAclC,KAAK,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBzC,KAAK;CAKN"}
@@ -0,0 +1,199 @@
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 { Socket } from "node:net";
21
+ import { concat, equals, startsWith } from "../0_deps.js";
22
+ import { ConnectionError } from "../0_errors.js";
23
+ import { getLogger, hmacSha256, Mutex } from "../1_utilities.js";
24
+ import { getTlsHeader } from "./0_get_tls_header.js";
25
+ const HEADER_LENGTH = 5;
26
+ const MAX_PACKET_LENGTH = 2878;
27
+ const L = getLogger("ConnectionTCP");
28
+ const errConnectionNotOpen = new ConnectionError("The connection is not open.");
29
+ export class ConnectionTLS {
30
+ #hostname;
31
+ #port;
32
+ #secret;
33
+ #socket;
34
+ #rMutex = new Mutex();
35
+ #wMutex = new Mutex();
36
+ #buffer = new Array();
37
+ #nextResolve = null;
38
+ stateChangeHandler;
39
+ constructor(hostname, port, secret) {
40
+ this.#hostname = hostname;
41
+ this.#port = port;
42
+ this.#secret = (secret[0] === 0xDD || secret[0] === 0xEE) ? secret.slice(1) : secret;
43
+ }
44
+ #rejectRead() {
45
+ if (this.#nextResolve !== null) {
46
+ this.#nextResolve[1].reject(errConnectionNotOpen);
47
+ this.#nextResolve = null;
48
+ }
49
+ }
50
+ async open() {
51
+ if (this.isConnected) {
52
+ return;
53
+ }
54
+ this.#socket = new Socket();
55
+ this.#socket.on("close", () => {
56
+ this.#rejectRead();
57
+ this.stateChangeHandler?.(false);
58
+ });
59
+ this.#socket.on("data", (data) => {
60
+ if (typeof data === "string") {
61
+ return;
62
+ }
63
+ for (const byte of data) {
64
+ this.#buffer.push(byte);
65
+ }
66
+ if (this.#nextResolve !== null && this.#buffer.length >= this.#nextResolve[0]) {
67
+ const resolve = this.#nextResolve[1].resolve;
68
+ this.#nextResolve = null;
69
+ resolve();
70
+ }
71
+ });
72
+ await new Promise((resolve, reject) => {
73
+ this.#socket.connect(this.#port, this.#hostname);
74
+ this.#socket.once("error", reject);
75
+ this.#socket.once("connect", () => {
76
+ this.#socket.off("error", reject);
77
+ resolve();
78
+ this.stateChangeHandler?.(true);
79
+ L.debug("connected to", this.#hostname, "port", this.#port);
80
+ });
81
+ });
82
+ const header = await getTlsHeader(this.#secret);
83
+ const helloRand = header.subarray(11, 43);
84
+ await this.#write(header);
85
+ let offset = 0;
86
+ let read = new Uint8Array();
87
+ for (const prefix of [
88
+ new Uint8Array([0x16, 0x03, 0x03]),
89
+ new Uint8Array([0x14, 0x03, 0x03, 0x00, 0x01, 0x01, 0x17, 0x03, 0x03]),
90
+ ]) {
91
+ while (true) {
92
+ if ((read.byteLength - offset) >= (prefix.byteLength + 2)) {
93
+ if (!startsWith(read.subarray(offset), prefix)) {
94
+ throw new TypeError("Received an invalid prefix.");
95
+ }
96
+ const dataView = new DataView(read.buffer, read.byteOffset, read.byteLength);
97
+ const size = dataView.getUint16(offset + prefix.byteLength, false);
98
+ const total = prefix.byteLength + 2 + size;
99
+ if ((read.byteLength - offset) >= total) {
100
+ offset += total;
101
+ break;
102
+ }
103
+ }
104
+ await new Promise((resolve, reject) => this.#nextResolve = [0, { resolve, reject }]);
105
+ read = concat([read, new Uint8Array(this.#buffer.splice(0, this.#buffer.length))]);
106
+ }
107
+ }
108
+ const response = read.subarray(0, offset);
109
+ const actual = response.slice(11, 43);
110
+ const zeroed = response.slice();
111
+ zeroed.fill(0, 11, 43);
112
+ const expected = await hmacSha256(concat([helloRand, zeroed]), this.#secret.slice(0, 16));
113
+ if (!equals(actual, expected)) {
114
+ throw new TypeError("Failed to initialize TLS connection.");
115
+ }
116
+ L.debug(`initialized TLS connection with ${this.#hostname}`);
117
+ }
118
+ get isConnected() {
119
+ return this.#socket?.readyState === "open";
120
+ }
121
+ #assertConnected() {
122
+ if (!this.isConnected) {
123
+ throw errConnectionNotOpen;
124
+ }
125
+ }
126
+ #packetBuffer = new Uint8Array();
127
+ async #readPacket() {
128
+ const header = new Uint8Array(HEADER_LENGTH);
129
+ await this.#read(header);
130
+ if (!startsWith(header, new Uint8Array([0x17, 0x03, 0x03]))) {
131
+ throw new TypeError("Failed to read TLS packet.");
132
+ }
133
+ const length = new DataView(header.buffer).getUint16(3);
134
+ const packet = new Uint8Array(length);
135
+ await this.#read(packet);
136
+ this.#packetBuffer = concat([this.#packetBuffer, packet]);
137
+ }
138
+ #isFirstWrite = false;
139
+ async #writePacket(packet) {
140
+ const header = new Uint8Array([0x17, 0x03, 0x03, 0x00, 0x00]);
141
+ new DataView(header.buffer).setUint16(3, packet.byteLength);
142
+ let data = concat([header, packet]);
143
+ if (this.#isFirstWrite) {
144
+ this.#isFirstWrite = false;
145
+ data = concat([new Uint8Array([0x14, 0x03, 0x03, 0x00, 0x01, 0x01]), data]);
146
+ }
147
+ await this.#write(data);
148
+ }
149
+ async #read(p) {
150
+ if (this.#buffer.length < p.length) {
151
+ await new Promise((resolve, reject) => this.#nextResolve = [p.length, { resolve, reject }]);
152
+ }
153
+ p.set(this.#buffer.splice(0, p.length));
154
+ }
155
+ async #write(p) {
156
+ await new Promise((resolve, reject) => {
157
+ this.#socket.write(p, (err) => {
158
+ (err === undefined || err === null) ? resolve() : reject(err);
159
+ });
160
+ });
161
+ }
162
+ async read(p) {
163
+ this.#assertConnected();
164
+ const unlock = await this.#rMutex.lock();
165
+ try {
166
+ while (this.#packetBuffer.byteLength < p.byteLength) {
167
+ await this.#readPacket();
168
+ }
169
+ p.set(this.#packetBuffer.subarray(0, p.byteLength));
170
+ this.#packetBuffer = this.#packetBuffer.slice(p.byteLength);
171
+ }
172
+ finally {
173
+ unlock();
174
+ }
175
+ }
176
+ async write(p) {
177
+ this.#assertConnected();
178
+ const unlock = await this.#wMutex.lock();
179
+ try {
180
+ let offset = 0;
181
+ while (true) {
182
+ const packet = p.subarray(offset, offset + MAX_PACKET_LENGTH - HEADER_LENGTH);
183
+ if (packet.byteLength === 0) {
184
+ break;
185
+ }
186
+ await this.#writePacket(packet);
187
+ offset += packet.byteLength;
188
+ }
189
+ }
190
+ finally {
191
+ unlock();
192
+ }
193
+ }
194
+ close() {
195
+ this.#assertConnected();
196
+ this.#socket.destroy();
197
+ this.#socket = undefined;
198
+ }
199
+ }
@@ -0,0 +1,52 @@
1
+ import type { Writer, WriterSync } from "./types.js";
2
+ export type { Writer, WriterSync } from "./types.js";
3
+ /**
4
+ * Write all the content of the array buffer (`arr`) to the writer (`w`).
5
+ *
6
+ * @example Writing to stdout
7
+ * ```ts no-assert
8
+ * import { writeAll } from "@std/io/write-all";
9
+ *
10
+ * const contentBytes = new TextEncoder().encode("Hello World");
11
+ * await writeAll(Deno.stdout, contentBytes);
12
+ * ```
13
+ *
14
+ * @example Writing to file
15
+ * ```ts ignore no-assert
16
+ * import { writeAll } from "@std/io/write-all";
17
+ *
18
+ * const contentBytes = new TextEncoder().encode("Hello World");
19
+ * using file = await Deno.open('test.file', { write: true });
20
+ * await writeAll(file, contentBytes);
21
+ * ```
22
+ *
23
+ * @param writer The writer to write to
24
+ * @param data The data to write
25
+ */
26
+ export declare function writeAll(writer: Writer, data: Uint8Array): Promise<void>;
27
+ /**
28
+ * Synchronously write all the content of the array buffer (`arr`) to the
29
+ * writer (`w`).
30
+ *
31
+ * @example "riting to stdout
32
+ * ```ts no-assert
33
+ * import { writeAllSync } from "@std/io/write-all";
34
+ *
35
+ * const contentBytes = new TextEncoder().encode("Hello World");
36
+ * writeAllSync(Deno.stdout, contentBytes);
37
+ * ```
38
+ *
39
+ * @example Writing to file
40
+ * ```ts ignore no-assert
41
+ * import { writeAllSync } from "@std/io/write-all";
42
+ *
43
+ * const contentBytes = new TextEncoder().encode("Hello World");
44
+ * using file = Deno.openSync("test.file", { write: true });
45
+ * writeAllSync(file, contentBytes);
46
+ * ```
47
+ *
48
+ * @param writer The writer to write to
49
+ * @param data The data to write
50
+ */
51
+ export declare function writeAllSync(writer: WriterSync, data: Uint8Array): void;
52
+ //# sourceMappingURL=write_all.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write_all.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/io/0.225.3/write_all.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAErD,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,iBAK9D;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,QAKhE"}
@@ -0,0 +1,61 @@
1
+ // Copyright 2018-2026 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ /**
4
+ * Write all the content of the array buffer (`arr`) to the writer (`w`).
5
+ *
6
+ * @example Writing to stdout
7
+ * ```ts no-assert
8
+ * import { writeAll } from "@std/io/write-all";
9
+ *
10
+ * const contentBytes = new TextEncoder().encode("Hello World");
11
+ * await writeAll(Deno.stdout, contentBytes);
12
+ * ```
13
+ *
14
+ * @example Writing to file
15
+ * ```ts ignore no-assert
16
+ * import { writeAll } from "@std/io/write-all";
17
+ *
18
+ * const contentBytes = new TextEncoder().encode("Hello World");
19
+ * using file = await Deno.open('test.file', { write: true });
20
+ * await writeAll(file, contentBytes);
21
+ * ```
22
+ *
23
+ * @param writer The writer to write to
24
+ * @param data The data to write
25
+ */
26
+ export async function writeAll(writer, data) {
27
+ let nwritten = 0;
28
+ while (nwritten < data.length) {
29
+ nwritten += await writer.write(data.subarray(nwritten));
30
+ }
31
+ }
32
+ /**
33
+ * Synchronously write all the content of the array buffer (`arr`) to the
34
+ * writer (`w`).
35
+ *
36
+ * @example "riting to stdout
37
+ * ```ts no-assert
38
+ * import { writeAllSync } from "@std/io/write-all";
39
+ *
40
+ * const contentBytes = new TextEncoder().encode("Hello World");
41
+ * writeAllSync(Deno.stdout, contentBytes);
42
+ * ```
43
+ *
44
+ * @example Writing to file
45
+ * ```ts ignore no-assert
46
+ * import { writeAllSync } from "@std/io/write-all";
47
+ *
48
+ * const contentBytes = new TextEncoder().encode("Hello World");
49
+ * using file = Deno.openSync("test.file", { write: true });
50
+ * writeAllSync(file, contentBytes);
51
+ * ```
52
+ *
53
+ * @param writer The writer to write to
54
+ * @param data The data to write
55
+ */
56
+ export function writeAllSync(writer, data) {
57
+ let nwritten = 0;
58
+ while (nwritten < data.length) {
59
+ nwritten += writer.writeSync(data.subarray(nwritten));
60
+ }
61
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"2_session_encrypted.d.ts","sourceRoot":"","sources":["../../src/session/2_session_encrypted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,EAAwD,OAAO,EAAuC,MAAM,YAAY,CAAC;AAChI,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAI5C,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAa7D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACtC,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACxD,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC;IACtC,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC;IAC5D,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CACxD;AAED,qBAAa,gBAAiB,SAAQ,OAAQ,YAAW,OAAO;;IAI9D,QAAQ,EAAE,QAAQ,CAAM;gBAiBZ,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,aAAa;IAQpC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC;IAM7C,IAAI,OAAO,IAAI,UAAU,CAAC,WAAW,CAAC,CAErC;IAEc,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAe9B,UAAU,IAAI,IAAI;IA6ErB,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAwX3D"}
1
+ {"version":3,"file":"2_session_encrypted.d.ts","sourceRoot":"","sources":["../../src/session/2_session_encrypted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,EAAwD,OAAO,EAAuC,MAAM,YAAY,CAAC;AAChI,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAI5C,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAa7D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACtC,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACxD,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC;IACtC,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC;IAC5D,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CACxD;AAED,qBAAa,gBAAiB,SAAQ,OAAQ,YAAW,OAAO;;IAI9D,QAAQ,EAAE,QAAQ,CAAM;gBAiBZ,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,aAAa;IAQpC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC;IAM7C,IAAI,OAAO,IAAI,UAAU,CAAC,WAAW,CAAC,CAErC;IAEc,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAe9B,UAAU,IAAI,IAAI;IA6ErB,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CA4X3D"}
@@ -190,10 +190,13 @@ export class SessionEncrypted extends Session {
190
190
  return messageWriter.buffer;
191
191
  }
192
192
  async #decryptMessage(buffer) {
193
- const reader = new TLReader(buffer);
193
+ let reader = new TLReader(buffer);
194
194
  assertEquals(reader.readInt64(), this.#authKeyId);
195
195
  const messageKey_ = reader.readInt128();
196
196
  const messageKey = intToBytes(messageKey_, 16);
197
+ if (reader.buffer.length % 16 !== 0) {
198
+ reader = new TLReader(reader.buffer.subarray(0, -(reader.buffer.length % 16)));
199
+ }
197
200
  const a = await sha256(concat([messageKey, this.#authKey.subarray(8, 44)]));
198
201
  const b = await sha256(concat([this.#authKey.subarray(48, 84), messageKey]));
199
202
  const aesKey = concat([a.subarray(0, 8), b.subarray(8, 24), a.subarray(24, 32)]);