@mtkruto/node 0.0.6

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 (167) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +1 -0
  3. package/esm/_dnt.shims.js +68 -0
  4. package/esm/client/client.js +169 -0
  5. package/esm/client/client_abstract.js +51 -0
  6. package/esm/client/client_plain.js +112 -0
  7. package/esm/connection/connection.js +2 -0
  8. package/esm/connection/connection_web_socket.js +90 -0
  9. package/esm/constants.js +60 -0
  10. package/esm/deps/deno.land/std@0.186.0/fmt/colors.js +474 -0
  11. package/esm/deps/deno.land/std@0.186.0/testing/_diff.js +311 -0
  12. package/esm/deps/deno.land/std@0.186.0/testing/_format.js +23 -0
  13. package/esm/deps/deno.land/std@0.186.0/testing/asserts.js +633 -0
  14. package/esm/deps/deno.land/x/crc32@v0.2.0/mod.js +105 -0
  15. package/esm/deps/deno.land/x/tgcrypto@0.1.1/mod.js +68 -0
  16. package/esm/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.js +1127 -0
  17. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js +239 -0
  18. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.js +10 -0
  19. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.js +139 -0
  20. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.js +176 -0
  21. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.js +2 -0
  22. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.js +19 -0
  23. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.js +25 -0
  24. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.js +1941 -0
  25. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.js +85 -0
  26. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.js +321 -0
  27. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.js +1658 -0
  28. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.js +355 -0
  29. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.js +11 -0
  30. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.js +42 -0
  31. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.js +1107 -0
  32. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.js +86 -0
  33. package/esm/deps.js +4 -0
  34. package/esm/mod.js +4 -0
  35. package/esm/package.json +3 -0
  36. package/esm/tl/0_tl_raw_reader.js +62 -0
  37. package/esm/tl/0_tl_raw_writer.js +60 -0
  38. package/esm/tl/1_tl_object.js +149 -0
  39. package/esm/tl/2_types.js +48220 -0
  40. package/esm/tl/3_functions.js +19856 -0
  41. package/esm/tl/3_tl_object_deserializer.js +72 -0
  42. package/esm/tl/3_tl_reader.js +16 -0
  43. package/esm/tl/3_tl_writer.js +7 -0
  44. package/esm/tl/4_rpc_result.js +27 -0
  45. package/esm/tl/5_message.js +54 -0
  46. package/esm/tl/6_message_container.js +35 -0
  47. package/esm/transport/transport.js +32 -0
  48. package/esm/transport/transport_intermediate.js +56 -0
  49. package/esm/transport/transport_provider.js +23 -0
  50. package/esm/types.js +1 -0
  51. package/esm/utilities/0_bigint.js +37 -0
  52. package/esm/utilities/0_buffer.js +33 -0
  53. package/esm/utilities/0_crypto.js +35 -0
  54. package/esm/utilities/0_hash.js +7 -0
  55. package/esm/utilities/1_auth.js +29 -0
  56. package/esm/utilities/1_message.js +94 -0
  57. package/esm/utilities/1_obfuscation.js +33 -0
  58. package/package.json +40 -0
  59. package/script/_dnt.shims.js +77 -0
  60. package/script/client/client.js +173 -0
  61. package/script/client/client_abstract.js +55 -0
  62. package/script/client/client_plain.js +116 -0
  63. package/script/connection/connection.js +6 -0
  64. package/script/connection/connection_web_socket.js +117 -0
  65. package/script/constants.js +63 -0
  66. package/script/deps/deno.land/std@0.186.0/fmt/colors.js +548 -0
  67. package/script/deps/deno.land/std@0.186.0/testing/_diff.js +317 -0
  68. package/script/deps/deno.land/std@0.186.0/testing/_format.js +50 -0
  69. package/script/deps/deno.land/std@0.186.0/testing/asserts.js +659 -0
  70. package/script/deps/deno.land/x/crc32@v0.2.0/mod.js +113 -0
  71. package/script/deps/deno.land/x/tgcrypto@0.1.1/mod.js +82 -0
  72. package/script/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.js +1152 -0
  73. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js +271 -0
  74. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.js +14 -0
  75. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.js +172 -0
  76. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.js +208 -0
  77. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.js +18 -0
  78. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.js +22 -0
  79. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.js +30 -0
  80. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.js +1976 -0
  81. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.js +88 -0
  82. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.js +324 -0
  83. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.js +1674 -0
  84. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.js +358 -0
  85. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.js +14 -0
  86. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.js +44 -0
  87. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.js +1115 -0
  88. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.js +89 -0
  89. package/script/deps.js +30 -0
  90. package/script/mod.js +32 -0
  91. package/script/package.json +3 -0
  92. package/script/tl/0_tl_raw_reader.js +66 -0
  93. package/script/tl/0_tl_raw_writer.js +64 -0
  94. package/script/tl/1_tl_object.js +156 -0
  95. package/script/tl/2_types.js +49824 -0
  96. package/script/tl/3_functions.js +20413 -0
  97. package/script/tl/3_tl_object_deserializer.js +76 -0
  98. package/script/tl/3_tl_reader.js +20 -0
  99. package/script/tl/3_tl_writer.js +11 -0
  100. package/script/tl/4_rpc_result.js +31 -0
  101. package/script/tl/5_message.js +58 -0
  102. package/script/tl/6_message_container.js +39 -0
  103. package/script/transport/transport.js +36 -0
  104. package/script/transport/transport_intermediate.js +60 -0
  105. package/script/transport/transport_provider.js +27 -0
  106. package/script/types.js +2 -0
  107. package/script/utilities/0_bigint.js +67 -0
  108. package/script/utilities/0_buffer.js +38 -0
  109. package/script/utilities/0_crypto.js +39 -0
  110. package/script/utilities/0_hash.js +35 -0
  111. package/script/utilities/1_auth.js +56 -0
  112. package/script/utilities/1_message.js +102 -0
  113. package/script/utilities/1_obfuscation.js +60 -0
  114. package/types/_dnt.shims.d.ts +10 -0
  115. package/types/client/client.d.ts +19 -0
  116. package/types/client/client_abstract.d.ts +20 -0
  117. package/types/client/client_plain.d.ts +10 -0
  118. package/types/connection/connection.d.ts +7 -0
  119. package/types/connection/connection_web_socket.d.ts +13 -0
  120. package/types/constants.d.ts +2 -0
  121. package/types/deps/deno.land/std@0.186.0/fmt/colors.d.ts +270 -0
  122. package/types/deps/deno.land/std@0.186.0/testing/_diff.d.ts +26 -0
  123. package/types/deps/deno.land/std@0.186.0/testing/_format.d.ts +1 -0
  124. package/types/deps/deno.land/std@0.186.0/testing/asserts.d.ts +284 -0
  125. package/types/deps/deno.land/x/crc32@v0.2.0/mod.d.ts +15 -0
  126. package/types/deps/deno.land/x/tgcrypto@0.1.1/mod.d.ts +47 -0
  127. package/types/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.d.ts +2 -0
  128. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.d.ts +16 -0
  129. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.d.ts +1 -0
  130. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.d.ts +29 -0
  131. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.d.ts +23 -0
  132. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.d.ts +2 -0
  133. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.d.ts +1 -0
  134. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.d.ts +2 -0
  135. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.d.ts +78 -0
  136. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.d.ts +12 -0
  137. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.d.ts +1 -0
  138. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.d.ts +47 -0
  139. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.d.ts +1 -0
  140. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.d.ts +12 -0
  141. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.d.ts +30 -0
  142. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.d.ts +5 -0
  143. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.d.ts +14 -0
  144. package/types/deps.d.ts +4 -0
  145. package/types/mod.d.ts +4 -0
  146. package/types/tl/0_tl_raw_reader.d.ts +13 -0
  147. package/types/tl/0_tl_raw_writer.d.ts +13 -0
  148. package/types/tl/1_tl_object.d.ts +36 -0
  149. package/types/tl/2_types.d.ts +14815 -0
  150. package/types/tl/3_functions.d.ts +6122 -0
  151. package/types/tl/3_tl_object_deserializer.d.ts +3 -0
  152. package/types/tl/3_tl_reader.d.ts +4 -0
  153. package/types/tl/3_tl_writer.d.ts +5 -0
  154. package/types/tl/4_rpc_result.d.ts +8 -0
  155. package/types/tl/5_message.d.ts +11 -0
  156. package/types/tl/6_message_container.d.ts +9 -0
  157. package/types/transport/transport.d.ts +15 -0
  158. package/types/transport/transport_intermediate.d.ts +11 -0
  159. package/types/transport/transport_provider.d.ts +12 -0
  160. package/types/types.d.ts +1 -0
  161. package/types/utilities/0_bigint.d.ts +4 -0
  162. package/types/utilities/0_buffer.d.ts +2 -0
  163. package/types/utilities/0_crypto.d.ts +8 -0
  164. package/types/utilities/0_hash.d.ts +2 -0
  165. package/types/utilities/1_auth.d.ts +1 -0
  166. package/types/utilities/1_message.d.ts +10 -0
  167. package/types/utilities/1_obfuscation.d.ts +6 -0
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ZStream {
4
+ constructor() {
5
+ /* next input byte */
6
+ Object.defineProperty(this, "input", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: null
11
+ }); // JS specific, because we have no pointers
12
+ Object.defineProperty(this, "next_in", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: 0
17
+ });
18
+ /* number of bytes available at input */
19
+ Object.defineProperty(this, "avail_in", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: 0
24
+ });
25
+ /* total number of input bytes read so far */
26
+ Object.defineProperty(this, "total_in", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: 0
31
+ });
32
+ /* next output byte should be put there */
33
+ Object.defineProperty(this, "output", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: null
38
+ }); // JS specific, because we have no pointers
39
+ Object.defineProperty(this, "next_out", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: 0
44
+ });
45
+ /* remaining free space at output */
46
+ Object.defineProperty(this, "avail_out", {
47
+ enumerable: true,
48
+ configurable: true,
49
+ writable: true,
50
+ value: 0
51
+ });
52
+ /* total number of bytes output so far */
53
+ Object.defineProperty(this, "total_out", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: 0
58
+ });
59
+ /* last error message, NULL if no error */
60
+ Object.defineProperty(this, "msg", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: "" /*Z_NULL*/
65
+ });
66
+ /* not visible by applications */
67
+ Object.defineProperty(this, "state", {
68
+ enumerable: true,
69
+ configurable: true,
70
+ writable: true,
71
+ value: null
72
+ });
73
+ /* best guess about the data type: binary or text */
74
+ Object.defineProperty(this, "data_type", {
75
+ enumerable: true,
76
+ configurable: true,
77
+ writable: true,
78
+ value: 2 /*Z_UNKNOWN*/
79
+ });
80
+ /* adler32 value of the uncompressed data */
81
+ Object.defineProperty(this, "adler", {
82
+ enumerable: true,
83
+ configurable: true,
84
+ writable: true,
85
+ value: 0
86
+ });
87
+ }
88
+ }
89
+ exports.default = ZStream;
package/script/deps.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Mutex = exports.gzip = exports.gunzip = exports.initTgCrypto = exports.ige256Encrypt = exports.ige256Decrypt = exports.factorize = exports.ctr256Encrypt = exports.ctr256Decrypt = void 0;
18
+ __exportStar(require("./deps/deno.land/std@0.186.0/testing/asserts.js"), exports);
19
+ var mod_js_1 = require("./deps/deno.land/x/tgcrypto@0.1.1/mod.js");
20
+ Object.defineProperty(exports, "ctr256Decrypt", { enumerable: true, get: function () { return mod_js_1.ctr256Decrypt; } });
21
+ Object.defineProperty(exports, "ctr256Encrypt", { enumerable: true, get: function () { return mod_js_1.ctr256Encrypt; } });
22
+ Object.defineProperty(exports, "factorize", { enumerable: true, get: function () { return mod_js_1.factorize; } });
23
+ Object.defineProperty(exports, "ige256Decrypt", { enumerable: true, get: function () { return mod_js_1.ige256Decrypt; } });
24
+ Object.defineProperty(exports, "ige256Encrypt", { enumerable: true, get: function () { return mod_js_1.ige256Encrypt; } });
25
+ Object.defineProperty(exports, "initTgCrypto", { enumerable: true, get: function () { return mod_js_1.init; } });
26
+ var gzip_js_1 = require("./deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js");
27
+ Object.defineProperty(exports, "gunzip", { enumerable: true, get: function () { return gzip_js_1.gunzip; } });
28
+ Object.defineProperty(exports, "gzip", { enumerable: true, get: function () { return gzip_js_1.gzip; } });
29
+ var async_mutex_1 = require("async-mutex");
30
+ Object.defineProperty(exports, "Mutex", { enumerable: true, get: function () { return async_mutex_1.Mutex; } });
package/script/mod.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Client = exports.ClientPlain = exports.functions = exports.types = void 0;
27
+ exports.types = __importStar(require("./tl/2_types.js"));
28
+ exports.functions = __importStar(require("./tl/3_functions.js"));
29
+ var client_plain_js_1 = require("./client/client_plain.js");
30
+ Object.defineProperty(exports, "ClientPlain", { enumerable: true, get: function () { return client_plain_js_1.ClientPlain; } });
31
+ var client_js_1 = require("./client/client.js");
32
+ Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_js_1.Client; } });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TLRawReader = void 0;
4
+ const _0_bigint_js_1 = require("../utilities/0_bigint.js");
5
+ class TLRawReader {
6
+ constructor(_buffer) {
7
+ Object.defineProperty(this, "_buffer", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: _buffer
12
+ });
13
+ }
14
+ get buffer() {
15
+ return this._buffer;
16
+ }
17
+ read(count) {
18
+ if (this._buffer.length < count) {
19
+ throw new Error("No data remaining");
20
+ }
21
+ const buffer = this._buffer.slice(0, count);
22
+ this._buffer = this._buffer.slice(count);
23
+ return buffer;
24
+ }
25
+ readInt24(signed = true) {
26
+ const buffer = this.read(24 / 8);
27
+ return Number((0, _0_bigint_js_1.bigIntFromBuffer)(buffer, true, signed));
28
+ }
29
+ readInt32(signed = true) {
30
+ const buffer = this.read(32 / 8);
31
+ return Number((0, _0_bigint_js_1.bigIntFromBuffer)(buffer, true, signed));
32
+ }
33
+ readInt64(signed = true) {
34
+ const buffer = this.read(64 / 8);
35
+ return (0, _0_bigint_js_1.bigIntFromBuffer)(buffer, true, signed);
36
+ }
37
+ readInt128(signed = true) {
38
+ const buffer = this.read(128 / 8);
39
+ return (0, _0_bigint_js_1.bigIntFromBuffer)(buffer, true, signed);
40
+ }
41
+ readInt256(signed = true) {
42
+ const buffer = this.read(256 / 8);
43
+ return (0, _0_bigint_js_1.bigIntFromBuffer)(buffer, true, signed);
44
+ }
45
+ readBytes() {
46
+ let L = this.read(1)[0];
47
+ let padding;
48
+ if (L > 253) {
49
+ L = this.readInt24();
50
+ padding = L % 4;
51
+ }
52
+ else {
53
+ padding = (L + 1) % 4;
54
+ }
55
+ const bytes = this.read(L);
56
+ if (padding > 0) {
57
+ padding = 4 - padding;
58
+ this.read(padding);
59
+ }
60
+ return bytes;
61
+ }
62
+ readString() {
63
+ return new TextDecoder().decode(this.readBytes());
64
+ }
65
+ }
66
+ exports.TLRawReader = TLRawReader;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TLRawWriter = void 0;
4
+ const _0_buffer_js_1 = require("../utilities/0_buffer.js");
5
+ class TLRawWriter {
6
+ constructor() {
7
+ Object.defineProperty(this, "_buffer", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: new Uint8Array()
12
+ });
13
+ }
14
+ get buffer() {
15
+ return this._buffer;
16
+ }
17
+ write(buffer) {
18
+ this._buffer = (0, _0_buffer_js_1.concat)(this._buffer, buffer);
19
+ return this;
20
+ }
21
+ writeInt24(int, signed = true) {
22
+ this.write((0, _0_buffer_js_1.bufferFromBigInt)(int, 24 / 7, true, signed));
23
+ return this;
24
+ }
25
+ writeInt32(int, signed = true) {
26
+ this.write((0, _0_buffer_js_1.bufferFromBigInt)(int, 32 / 8, true, signed));
27
+ return this;
28
+ }
29
+ writeInt64(int, signed = true) {
30
+ this.write((0, _0_buffer_js_1.bufferFromBigInt)(int, 64 / 8, true, signed));
31
+ return this;
32
+ }
33
+ writeInt128(int, signed = true) {
34
+ this.write((0, _0_buffer_js_1.bufferFromBigInt)(int, 128 / 8, true, signed));
35
+ return this;
36
+ }
37
+ writeInt256(int, signed = true) {
38
+ this.write((0, _0_buffer_js_1.bufferFromBigInt)(int, 256 / 8, true, signed));
39
+ return this;
40
+ }
41
+ writeBytes(bytes) {
42
+ let padding;
43
+ if (bytes.length > 253) {
44
+ this.write(new Uint8Array([254]));
45
+ this.writeInt24(bytes.length);
46
+ padding = bytes.length % 4;
47
+ }
48
+ else {
49
+ this.write(new Uint8Array([bytes.length]));
50
+ padding = (bytes.length + 1) % 4;
51
+ }
52
+ this.write(bytes);
53
+ if (padding > 0) {
54
+ padding = 4 - padding;
55
+ this.write(new Uint8Array(padding));
56
+ }
57
+ return this;
58
+ }
59
+ writeString(string) {
60
+ this.writeBytes(new TextEncoder().encode(string));
61
+ return this;
62
+ }
63
+ }
64
+ exports.TLRawWriter = TLRawWriter;
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTLObjectConstructor = exports.TLObject = exports.analyzeOptionalParam = exports.isOptionalParam = exports.length = exports.paramDesc = exports.params = exports.id = exports.flags = void 0;
4
+ const deps_js_1 = require("../deps.js");
5
+ const _0_tl_raw_writer_js_1 = require("./0_tl_raw_writer.js");
6
+ exports.flags = Symbol("flags");
7
+ exports.id = Symbol("id");
8
+ exports.params = Symbol("params");
9
+ exports.paramDesc = Symbol("paramDesc");
10
+ exports.length = Symbol("length");
11
+ function isOptionalParam(ntype) {
12
+ return ntype.includes("?");
13
+ }
14
+ exports.isOptionalParam = isOptionalParam;
15
+ function analyzeOptionalParam(ntype) {
16
+ if (!isOptionalParam(ntype)) {
17
+ throw new Error("Parameter not optional");
18
+ }
19
+ const flagField = ntype.split(".")[0];
20
+ (0, deps_js_1.assertEquals)(typeof flagField, "string");
21
+ const bitIndex = Number(ntype.split("?")[0].split(".")[1]);
22
+ (0, deps_js_1.assertFalse)(isNaN(bitIndex));
23
+ return { flagField, bitIndex };
24
+ }
25
+ exports.analyzeOptionalParam = analyzeOptionalParam;
26
+ function serializeSingleParam(writer, value, type, ntype) {
27
+ if (isTLObjectConstructor(type)) {
28
+ if ((type.name == "TypeX" && value instanceof TLObject) ||
29
+ value instanceof type) {
30
+ writer.write(value.serialize());
31
+ return;
32
+ }
33
+ else {
34
+ throw new Error("a");
35
+ }
36
+ }
37
+ if (type == Uint8Array) {
38
+ if ((value instanceof Uint8Array)) {
39
+ writer.writeBytes(value);
40
+ }
41
+ else {
42
+ throw new Error("Expected Uint8Array");
43
+ }
44
+ }
45
+ switch (type) {
46
+ case "bigint":
47
+ if (typeof value === "bigint") {
48
+ if (ntype == "int128") {
49
+ writer.writeInt128(value);
50
+ }
51
+ else if (ntype === "int256") {
52
+ writer.writeInt256(value);
53
+ }
54
+ else {
55
+ writer.writeInt64(value);
56
+ }
57
+ }
58
+ else {
59
+ throw new Error("Expected bigint");
60
+ }
61
+ break;
62
+ case "boolean":
63
+ if (typeof value === "boolean") {
64
+ if (value) {
65
+ writer.writeInt32(0x997275B5);
66
+ }
67
+ else {
68
+ writer.writeInt32(0xBC799737);
69
+ }
70
+ }
71
+ else {
72
+ throw new Error("Expected boolean");
73
+ }
74
+ break;
75
+ case "number":
76
+ if (typeof value === "number") {
77
+ writer.writeInt32(value);
78
+ }
79
+ else {
80
+ throw new Error("Expected number");
81
+ }
82
+ break;
83
+ case "string":
84
+ if (typeof value === "string") {
85
+ writer.writeString(value);
86
+ }
87
+ else if (value instanceof Uint8Array) {
88
+ writer.writeBytes(value);
89
+ }
90
+ else {
91
+ throw new Error("Expected string or Uint8Array");
92
+ }
93
+ break;
94
+ case "true":
95
+ if (value === true) {
96
+ writer.writeInt32(0x997275B5);
97
+ }
98
+ else {
99
+ throw new Error("Expected true");
100
+ }
101
+ }
102
+ }
103
+ class TLObject {
104
+ static get [exports.paramDesc]() {
105
+ // unimpl
106
+ return [];
107
+ }
108
+ get [exports.length]() {
109
+ return this.serialize().byteLength;
110
+ }
111
+ serialize() {
112
+ const writer = new _0_tl_raw_writer_js_1.TLRawWriter();
113
+ writer.writeInt32(this[exports.id], false);
114
+ for (const [value, type, ntype] of this[exports.params]) {
115
+ if (isOptionalParam(ntype) && value == null) {
116
+ continue;
117
+ }
118
+ if (type == exports.flags) {
119
+ let flags = 0;
120
+ const flagField_ = value;
121
+ for (const [value, _, ntype] of this[exports.params]) {
122
+ if (isOptionalParam(ntype)) {
123
+ const { flagField, bitIndex } = analyzeOptionalParam(ntype);
124
+ if (flagField == flagField_) {
125
+ if (value != null) {
126
+ flags |= 1 << bitIndex;
127
+ }
128
+ }
129
+ }
130
+ }
131
+ writer.writeInt32(flags);
132
+ continue;
133
+ }
134
+ if (type instanceof Array) {
135
+ const itemsType = type[0];
136
+ if (!Array.isArray(value)) {
137
+ throw new Error("Expected array");
138
+ }
139
+ writer.writeInt32(0x1CB5C415); // vector constructor
140
+ writer.writeInt32(value.length);
141
+ for (const item of value) {
142
+ serializeSingleParam(writer, item, itemsType, ntype);
143
+ }
144
+ continue;
145
+ }
146
+ serializeSingleParam(writer, value, type, ntype);
147
+ }
148
+ return writer.buffer;
149
+ }
150
+ }
151
+ exports.TLObject = TLObject;
152
+ function isTLObjectConstructor(t) {
153
+ // deno-lint-ignore no-explicit-any
154
+ return t[exports.paramDesc] instanceof Array;
155
+ }
156
+ exports.isTLObjectConstructor = isTLObjectConstructor;