sroosh 1.0.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 (250) hide show
  1. package/CryptoFile-BROWSER.d.ts +2 -0
  2. package/CryptoFile-BROWSER.js +23 -0
  3. package/CryptoFile.d.ts +2 -0
  4. package/CryptoFile.js +23 -0
  5. package/Helpers.d.ts +151 -0
  6. package/Helpers.js +480 -0
  7. package/Password.d.ts +15 -0
  8. package/Password.js +271 -0
  9. package/README.md +105 -0
  10. package/Utils.d.ts +228 -0
  11. package/Utils.js +1248 -0
  12. package/Version.d.ts +1 -0
  13. package/Version.js +4 -0
  14. package/client/2fa.d.ts +48 -0
  15. package/client/2fa.js +109 -0
  16. package/client/TelegramClient.d.ts +1042 -0
  17. package/client/TelegramClient.js +1244 -0
  18. package/client/account.d.ts +0 -0
  19. package/client/account.js +1 -0
  20. package/client/auth.d.ts +93 -0
  21. package/client/auth.js +363 -0
  22. package/client/bots.d.ts +6 -0
  23. package/client/bots.js +24 -0
  24. package/client/buttons.d.ts +4 -0
  25. package/client/buttons.js +87 -0
  26. package/client/chats.d.ts +46 -0
  27. package/client/chats.js +350 -0
  28. package/client/dialogs.d.ts +52 -0
  29. package/client/dialogs.js +174 -0
  30. package/client/downloads.d.ts +157 -0
  31. package/client/downloads.js +598 -0
  32. package/client/fs-BROWSER.d.ts +10 -0
  33. package/client/fs-BROWSER.js +13 -0
  34. package/client/fs.d.ts +1 -0
  35. package/client/fs.js +13 -0
  36. package/client/index.d.ts +15 -0
  37. package/client/index.js +50 -0
  38. package/client/messageParse.d.ts +17 -0
  39. package/client/messageParse.js +191 -0
  40. package/client/messages.d.ts +259 -0
  41. package/client/messages.js +804 -0
  42. package/client/os-BROWSER.d.ts +5 -0
  43. package/client/os-BROWSER.js +10 -0
  44. package/client/os.d.ts +2 -0
  45. package/client/os.js +23 -0
  46. package/client/path-BROWSER.d.ts +7 -0
  47. package/client/path-BROWSER.js +8 -0
  48. package/client/path.d.ts +2 -0
  49. package/client/path.js +7 -0
  50. package/client/telegramBaseClient.d.ts +239 -0
  51. package/client/telegramBaseClient.js +369 -0
  52. package/client/updates.d.ts +31 -0
  53. package/client/updates.js +254 -0
  54. package/client/uploads.d.ts +137 -0
  55. package/client/uploads.js +514 -0
  56. package/client/users.d.ts +29 -0
  57. package/client/users.js +491 -0
  58. package/crypto/AuthKey.d.ts +20 -0
  59. package/crypto/AuthKey.js +76 -0
  60. package/crypto/CTR.d.ts +6 -0
  61. package/crypto/CTR.js +35 -0
  62. package/crypto/Factorizator.d.ts +19 -0
  63. package/crypto/Factorizator.js +74 -0
  64. package/crypto/IGE.d.ts +18 -0
  65. package/crypto/IGE.js +34 -0
  66. package/crypto/RSA.d.ts +15 -0
  67. package/crypto/RSA.js +150 -0
  68. package/crypto/converters.d.ts +19 -0
  69. package/crypto/converters.js +52 -0
  70. package/crypto/crypto.d.ts +27 -0
  71. package/crypto/crypto.js +117 -0
  72. package/crypto/words.d.ts +6 -0
  73. package/crypto/words.js +48 -0
  74. package/entityCache.d.ts +7 -0
  75. package/entityCache.js +79 -0
  76. package/errors/Common.d.ts +72 -0
  77. package/errors/Common.js +122 -0
  78. package/errors/RPCBaseErrors.d.ts +84 -0
  79. package/errors/RPCBaseErrors.js +134 -0
  80. package/errors/RPCErrorList.d.ts +37 -0
  81. package/errors/RPCErrorList.js +117 -0
  82. package/errors/index.d.ts +11 -0
  83. package/errors/index.js +29 -0
  84. package/events/Album.d.ts +36 -0
  85. package/events/Album.js +104 -0
  86. package/events/CallbackQuery.d.ts +74 -0
  87. package/events/CallbackQuery.js +193 -0
  88. package/events/DeletedMessage.d.ts +45 -0
  89. package/events/DeletedMessage.js +63 -0
  90. package/events/EditedMessage.d.ts +30 -0
  91. package/events/EditedMessage.js +41 -0
  92. package/events/NewMessage.d.ts +89 -0
  93. package/events/NewMessage.js +182 -0
  94. package/events/Raw.d.ts +29 -0
  95. package/events/Raw.js +43 -0
  96. package/events/common.d.ts +66 -0
  97. package/events/common.js +141 -0
  98. package/events/index.d.ts +2 -0
  99. package/events/index.js +8 -0
  100. package/extensions/AsyncQueue.d.ts +10 -0
  101. package/extensions/AsyncQueue.js +32 -0
  102. package/extensions/BinaryReader.d.ts +100 -0
  103. package/extensions/BinaryReader.js +242 -0
  104. package/extensions/BinaryWriter.d.ts +7 -0
  105. package/extensions/BinaryWriter.js +15 -0
  106. package/extensions/Deferred.d.ts +8 -0
  107. package/extensions/Deferred.js +16 -0
  108. package/extensions/Logger.d.ts +58 -0
  109. package/extensions/Logger.js +127 -0
  110. package/extensions/MessagePacker.d.ts +22 -0
  111. package/extensions/MessagePacker.js +154 -0
  112. package/extensions/PendingState.d.ts +12 -0
  113. package/extensions/PendingState.js +29 -0
  114. package/extensions/PromisedNetSockets-BROWSER.d.ts +8 -0
  115. package/extensions/PromisedNetSockets-BROWSER.js +12 -0
  116. package/extensions/PromisedNetSockets.d.ts +25 -0
  117. package/extensions/PromisedNetSockets.js +178 -0
  118. package/extensions/PromisedWebSockets.d.ts +19 -0
  119. package/extensions/PromisedWebSockets.js +134 -0
  120. package/extensions/html.d.ts +5 -0
  121. package/extensions/html.js +213 -0
  122. package/extensions/index.d.ts +7 -0
  123. package/extensions/index.js +17 -0
  124. package/extensions/markdown.d.ts +5 -0
  125. package/extensions/markdown.js +76 -0
  126. package/extensions/markdownv2.d.ts +5 -0
  127. package/extensions/markdownv2.js +51 -0
  128. package/extensions/net-BROWSER.d.ts +8 -0
  129. package/extensions/net-BROWSER.js +11 -0
  130. package/extensions/net.d.ts +1 -0
  131. package/extensions/net.js +13 -0
  132. package/extensions/socks-BROWSER.d.ts +3 -0
  133. package/extensions/socks-BROWSER.js +6 -0
  134. package/extensions/socks.d.ts +1 -0
  135. package/extensions/socks.js +13 -0
  136. package/index.d.ts +14 -0
  137. package/index.js +48 -0
  138. package/inspect-BROWSER.d.ts +3 -0
  139. package/inspect-BROWSER.js +6 -0
  140. package/inspect.d.ts +1 -0
  141. package/inspect.js +5 -0
  142. package/network/Authenticator.d.ts +12 -0
  143. package/network/Authenticator.js +193 -0
  144. package/network/MTProtoPlainSender.d.ts +19 -0
  145. package/network/MTProtoPlainSender.js +74 -0
  146. package/network/MTProtoSender.d.ts +291 -0
  147. package/network/MTProtoSender.js +854 -0
  148. package/network/MTProtoState.d.ts +103 -0
  149. package/network/MTProtoState.js +267 -0
  150. package/network/RequestState.d.ts +19 -0
  151. package/network/RequestState.js +35 -0
  152. package/network/connection/Connection.d.ts +71 -0
  153. package/network/connection/Connection.js +157 -0
  154. package/network/connection/ConnectionWebSocket.d.ts +19 -0
  155. package/network/connection/ConnectionWebSocket.js +77 -0
  156. package/network/connection/CustomIntermediatePacketCodec.d.ts +8 -0
  157. package/network/connection/CustomIntermediatePacketCodec.js +25 -0
  158. package/network/connection/CustomPromisedWebSockets.d.ts +22 -0
  159. package/network/connection/CustomPromisedWebSockets.js +170 -0
  160. package/network/connection/ObfuscatedIO.d.ts +12 -0
  161. package/network/connection/ObfuscatedIO.js +64 -0
  162. package/network/connection/TCPAbridged.d.ts +20 -0
  163. package/network/connection/TCPAbridged.js +58 -0
  164. package/network/connection/TCPFull.d.ts +17 -0
  165. package/network/connection/TCPFull.js +61 -0
  166. package/network/connection/TCPMTProxy.d.ts +50 -0
  167. package/network/connection/TCPMTProxy.js +121 -0
  168. package/network/connection/TCPObfuscated.d.ts +18 -0
  169. package/network/connection/TCPObfuscated.js +79 -0
  170. package/network/connection/index.d.ts +5 -0
  171. package/network/connection/index.js +13 -0
  172. package/network/index.d.ts +11 -0
  173. package/network/index.js +24 -0
  174. package/package.json +73 -0
  175. package/platform.d.ts +3 -0
  176. package/platform.js +6 -0
  177. package/requestIter.d.ts +24 -0
  178. package/requestIter.js +107 -0
  179. package/sessions/Abstract.d.ts +103 -0
  180. package/sessions/Abstract.js +6 -0
  181. package/sessions/CacheApiSession.d.ts +18 -0
  182. package/sessions/CacheApiSession.js +99 -0
  183. package/sessions/Memory.d.ts +38 -0
  184. package/sessions/Memory.js +272 -0
  185. package/sessions/StoreSession.d.ts +14 -0
  186. package/sessions/StoreSession.js +77 -0
  187. package/sessions/StringSession.d.ts +33 -0
  188. package/sessions/StringSession.js +116 -0
  189. package/sessions/index.d.ts +4 -0
  190. package/sessions/index.js +13 -0
  191. package/sessions/localStorage-BROWSER.d.ts +3 -0
  192. package/sessions/localStorage-BROWSER.js +9 -0
  193. package/sessions/localStorage.d.ts +1 -0
  194. package/sessions/localStorage.js +4 -0
  195. package/tl/AllTLObjects.d.ts +3 -0
  196. package/tl/AllTLObjects.js +17 -0
  197. package/tl/MTProtoRequest.d.ts +19 -0
  198. package/tl/MTProtoRequest.js +38 -0
  199. package/tl/api.d.ts +2 -0
  200. package/tl/api.js +507 -0
  201. package/tl/apiTl.d.ts +2 -0
  202. package/tl/apiTl.js +1638 -0
  203. package/tl/core/GZIPPacked.d.ts +16 -0
  204. package/tl/core/GZIPPacked.js +51 -0
  205. package/tl/core/MessageContainer.d.ts +12 -0
  206. package/tl/core/MessageContainer.js +42 -0
  207. package/tl/core/RPCResult.d.ts +15 -0
  208. package/tl/core/RPCResult.js +32 -0
  209. package/tl/core/TLMessage.d.ts +10 -0
  210. package/tl/core/TLMessage.js +14 -0
  211. package/tl/core/index.d.ts +6 -0
  212. package/tl/core/index.js +16 -0
  213. package/tl/custom/button.d.ts +25 -0
  214. package/tl/custom/button.js +78 -0
  215. package/tl/custom/chatGetter.d.ts +30 -0
  216. package/tl/custom/chatGetter.js +114 -0
  217. package/tl/custom/dialog.d.ts +31 -0
  218. package/tl/custom/dialog.js +40 -0
  219. package/tl/custom/draft.d.ts +22 -0
  220. package/tl/custom/draft.js +48 -0
  221. package/tl/custom/file.d.ts +22 -0
  222. package/tl/custom/file.js +68 -0
  223. package/tl/custom/forward.d.ts +16 -0
  224. package/tl/custom/forward.js +47 -0
  225. package/tl/custom/index.d.ts +1 -0
  226. package/tl/custom/index.js +5 -0
  227. package/tl/custom/inlineResult.d.ts +33 -0
  228. package/tl/custom/inlineResult.js +87 -0
  229. package/tl/custom/inlineResults.d.ts +21 -0
  230. package/tl/custom/inlineResults.js +26 -0
  231. package/tl/custom/message.d.ts +428 -0
  232. package/tl/custom/message.js +702 -0
  233. package/tl/custom/messageButton.d.ts +55 -0
  234. package/tl/custom/messageButton.js +152 -0
  235. package/tl/custom/senderGetter.d.ts +29 -0
  236. package/tl/custom/senderGetter.js +55 -0
  237. package/tl/generateModule.d.ts +1 -0
  238. package/tl/generateModule.js +17 -0
  239. package/tl/generationHelpers.d.ts +12 -0
  240. package/tl/generationHelpers.js +289 -0
  241. package/tl/index.d.ts +3 -0
  242. package/tl/index.js +10 -0
  243. package/tl/patched/index.d.ts +2 -0
  244. package/tl/patched/index.js +77 -0
  245. package/tl/schemaTl.d.ts +2 -0
  246. package/tl/schemaTl.js +64 -0
  247. package/tl/types-generator/generate.d.ts +1 -0
  248. package/tl/types-generator/generate.js +84 -0
  249. package/tl/types-generator/template.d.ts +6 -0
  250. package/tl/types-generator/template.js +257 -0
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionTCPMTProxyAbridged = exports.TCPMTProxy = void 0;
4
+ const Connection_1 = require("./Connection");
5
+ const TCPAbridged_1 = require("./TCPAbridged");
6
+ const Helpers_1 = require("../../Helpers");
7
+ const CTR_1 = require("../../crypto/CTR");
8
+ class MTProxyIO {
9
+ constructor(connection) {
10
+ this.header = undefined;
11
+ this.connection = connection.socket;
12
+ this._packetClass =
13
+ connection.PacketCodecClass;
14
+ this._secret = connection._secret;
15
+ this._dcId = connection._dcId;
16
+ }
17
+ async initHeader() {
18
+ let secret = this._secret;
19
+ const isDD = secret.length == 17 && secret[0] == 0xdd;
20
+ secret = isDD ? secret.slice(1) : secret;
21
+ if (secret.length != 16) {
22
+ throw new Error("MTProxy secret must be a hex-string representing 16 bytes");
23
+ }
24
+ const keywords = [
25
+ Buffer.from("50567247", "hex"),
26
+ Buffer.from("474554", "hex"),
27
+ Buffer.from("504f5354", "hex"),
28
+ Buffer.from("eeeeeeee", "hex"),
29
+ ];
30
+ let random;
31
+ // eslint-disable-next-line no-constant-condition
32
+ while (true) {
33
+ random = (0, Helpers_1.generateRandomBytes)(64);
34
+ if (random[0] !== 0xef &&
35
+ !random.slice(4, 8).equals(Buffer.alloc(4))) {
36
+ let ok = true;
37
+ for (const key of keywords) {
38
+ if (key.equals(random.slice(0, 4))) {
39
+ ok = false;
40
+ break;
41
+ }
42
+ }
43
+ if (ok) {
44
+ break;
45
+ }
46
+ }
47
+ }
48
+ random = random.toJSON().data;
49
+ const randomReversed = Buffer.from(random.slice(8, 56)).reverse();
50
+ // Encryption has "continuous buffer" enabled
51
+ const encryptKey = await (0, Helpers_1.sha256)(Buffer.concat([Buffer.from(random.slice(8, 40)), secret]));
52
+ const encryptIv = Buffer.from(random.slice(40, 56));
53
+ const decryptKey = await (0, Helpers_1.sha256)(Buffer.concat([Buffer.from(randomReversed.slice(0, 32)), secret]));
54
+ const decryptIv = Buffer.from(randomReversed.slice(32, 48));
55
+ const encryptor = new CTR_1.CTR(encryptKey, encryptIv);
56
+ const decryptor = new CTR_1.CTR(decryptKey, decryptIv);
57
+ random = Buffer.concat([
58
+ Buffer.from(random.slice(0, 56)),
59
+ this._packetClass.obfuscateTag,
60
+ Buffer.from(random.slice(60)),
61
+ ]);
62
+ const dcIdBytes = Buffer.alloc(2);
63
+ dcIdBytes.writeInt8(this._dcId, 0);
64
+ random = Buffer.concat([
65
+ Buffer.from(random.slice(0, 60)),
66
+ dcIdBytes,
67
+ Buffer.from(random.slice(62)),
68
+ ]);
69
+ random = Buffer.concat([
70
+ Buffer.from(random.slice(0, 56)),
71
+ Buffer.from(encryptor.encrypt(random).slice(56, 64)),
72
+ Buffer.from(random.slice(64)),
73
+ ]);
74
+ this.header = random;
75
+ this._encrypt = encryptor;
76
+ this._decrypt = decryptor;
77
+ }
78
+ async read(n) {
79
+ const data = await this.connection.readExactly(n);
80
+ return this._decrypt.encrypt(data);
81
+ }
82
+ write(data) {
83
+ this.connection.write(this._encrypt.encrypt(data));
84
+ }
85
+ }
86
+ class TCPMTProxy extends Connection_1.ObfuscatedConnection {
87
+ constructor({ ip, port, dcId, loggers, proxy, socket, testServers, }) {
88
+ super({
89
+ ip: proxy.ip,
90
+ port: proxy.port,
91
+ dcId: dcId,
92
+ loggers: loggers,
93
+ socket: socket,
94
+ proxy: proxy,
95
+ testServers: testServers,
96
+ });
97
+ this.ObfuscatedIO = MTProxyIO;
98
+ if (!("MTProxy" in proxy)) {
99
+ throw new Error("This connection only supports MPTProxies");
100
+ }
101
+ if (!proxy.secret) {
102
+ throw new Error("You need to provide the secret for the MTProxy");
103
+ }
104
+ if (proxy.secret && proxy.secret.match(/^[0-9a-f]+$/i)) {
105
+ // probably hex
106
+ this._secret = Buffer.from(proxy.secret, "hex");
107
+ }
108
+ else {
109
+ // probably b64
110
+ this._secret = Buffer.from(proxy.secret, "base64");
111
+ }
112
+ }
113
+ }
114
+ exports.TCPMTProxy = TCPMTProxy;
115
+ class ConnectionTCPMTProxyAbridged extends TCPMTProxy {
116
+ constructor() {
117
+ super(...arguments);
118
+ this.PacketCodecClass = TCPAbridged_1.AbridgedPacketCodec;
119
+ }
120
+ }
121
+ exports.ConnectionTCPMTProxyAbridged = ConnectionTCPMTProxyAbridged;
@@ -0,0 +1,18 @@
1
+ /// <reference types="node" />
2
+ import { ObfuscatedConnection } from "./Connection";
3
+ import { AbridgedPacketCodec } from "./TCPAbridged";
4
+ export declare class ObfuscatedIO {
5
+ header?: Buffer;
6
+ private connection;
7
+ private _encrypt?;
8
+ private _decrypt?;
9
+ private _packetClass;
10
+ constructor(connection: ConnectionTCPObfuscated);
11
+ initHeader(): Promise<void>;
12
+ read(n: number): Promise<Buffer>;
13
+ write(data: Buffer): void;
14
+ }
15
+ export declare class ConnectionTCPObfuscated extends ObfuscatedConnection {
16
+ ObfuscatedIO: typeof ObfuscatedIO;
17
+ PacketCodecClass: typeof AbridgedPacketCodec;
18
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionTCPObfuscated = exports.ObfuscatedIO = void 0;
4
+ const Helpers_1 = require("../../Helpers");
5
+ const Connection_1 = require("./Connection");
6
+ const TCPAbridged_1 = require("./TCPAbridged");
7
+ const CTR_1 = require("../../crypto/CTR");
8
+ class ObfuscatedIO {
9
+ constructor(connection) {
10
+ this.header = undefined;
11
+ this.connection = connection.socket;
12
+ this._packetClass = connection.PacketCodecClass;
13
+ }
14
+ async initHeader() {
15
+ // Obfuscated messages secrets cannot start with any of these
16
+ const keywords = [
17
+ Buffer.from("50567247", "hex"),
18
+ Buffer.from("474554", "hex"),
19
+ Buffer.from("504f5354", "hex"),
20
+ Buffer.from("eeeeeeee", "hex"),
21
+ ];
22
+ let random;
23
+ // eslint-disable-next-line no-constant-condition
24
+ while (true) {
25
+ random = (0, Helpers_1.generateRandomBytes)(64);
26
+ if (random[0] !== 0xef &&
27
+ !random.slice(4, 8).equals(Buffer.alloc(4))) {
28
+ let ok = true;
29
+ for (const key of keywords) {
30
+ if (key.equals(random.slice(0, 4))) {
31
+ ok = false;
32
+ break;
33
+ }
34
+ }
35
+ if (ok) {
36
+ break;
37
+ }
38
+ }
39
+ }
40
+ random = random.toJSON().data;
41
+ const randomReversed = Buffer.from(random.slice(8, 56)).reverse();
42
+ // Encryption has "continuous buffer" enabled
43
+ const encryptKey = Buffer.from(random.slice(8, 40));
44
+ const encryptIv = Buffer.from(random.slice(40, 56));
45
+ const decryptKey = Buffer.from(randomReversed.slice(0, 32));
46
+ const decryptIv = Buffer.from(randomReversed.slice(32, 48));
47
+ const encryptor = new CTR_1.CTR(encryptKey, encryptIv);
48
+ const decryptor = new CTR_1.CTR(decryptKey, decryptIv);
49
+ random = Buffer.concat([
50
+ Buffer.from(random.slice(0, 56)),
51
+ this._packetClass.obfuscateTag,
52
+ Buffer.from(random.slice(60)),
53
+ ]);
54
+ random = Buffer.concat([
55
+ Buffer.from(random.slice(0, 56)),
56
+ Buffer.from(encryptor.encrypt(random).slice(56, 64)),
57
+ Buffer.from(random.slice(64)),
58
+ ]);
59
+ this.header = random;
60
+ this._encrypt = encryptor;
61
+ this._decrypt = decryptor;
62
+ }
63
+ async read(n) {
64
+ const data = await this.connection.readExactly(n);
65
+ return this._decrypt.encrypt(data);
66
+ }
67
+ write(data) {
68
+ this.connection.write(this._encrypt.encrypt(data));
69
+ }
70
+ }
71
+ exports.ObfuscatedIO = ObfuscatedIO;
72
+ class ConnectionTCPObfuscated extends Connection_1.ObfuscatedConnection {
73
+ constructor() {
74
+ super(...arguments);
75
+ this.ObfuscatedIO = ObfuscatedIO;
76
+ this.PacketCodecClass = TCPAbridged_1.AbridgedPacketCodec;
77
+ }
78
+ }
79
+ exports.ConnectionTCPObfuscated = ConnectionTCPObfuscated;
@@ -0,0 +1,5 @@
1
+ export { Connection } from "./Connection";
2
+ export { ConnectionTCPFull } from "./TCPFull";
3
+ export { ConnectionTCPAbridged } from "./TCPAbridged";
4
+ export { ConnectionTCPObfuscated } from "./TCPObfuscated";
5
+ export { ConnectionWebSocket } from "./ConnectionWebSocket";
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionWebSocket = exports.ConnectionTCPObfuscated = exports.ConnectionTCPAbridged = exports.ConnectionTCPFull = exports.Connection = void 0;
4
+ var Connection_1 = require("./Connection");
5
+ Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return Connection_1.Connection; } });
6
+ var TCPFull_1 = require("./TCPFull");
7
+ Object.defineProperty(exports, "ConnectionTCPFull", { enumerable: true, get: function () { return TCPFull_1.ConnectionTCPFull; } });
8
+ var TCPAbridged_1 = require("./TCPAbridged");
9
+ Object.defineProperty(exports, "ConnectionTCPAbridged", { enumerable: true, get: function () { return TCPAbridged_1.ConnectionTCPAbridged; } });
10
+ var TCPObfuscated_1 = require("./TCPObfuscated");
11
+ Object.defineProperty(exports, "ConnectionTCPObfuscated", { enumerable: true, get: function () { return TCPObfuscated_1.ConnectionTCPObfuscated; } });
12
+ var ConnectionWebSocket_1 = require("./ConnectionWebSocket");
13
+ Object.defineProperty(exports, "ConnectionWebSocket", { enumerable: true, get: function () { return ConnectionWebSocket_1.ConnectionWebSocket; } });
@@ -0,0 +1,11 @@
1
+ export { MTProtoPlainSender } from "./MTProtoPlainSender";
2
+ export { doAuthentication } from "./Authenticator";
3
+ export { MTProtoSender } from "./MTProtoSender";
4
+ export declare class UpdateConnectionState {
5
+ static disconnected: number;
6
+ static connected: number;
7
+ static broken: number;
8
+ state: number;
9
+ constructor(state: number);
10
+ }
11
+ export { Connection, ConnectionTCPFull, ConnectionTCPAbridged, ConnectionTCPObfuscated, ConnectionWebSocket } from "./connection";
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionWebSocket = exports.ConnectionTCPObfuscated = exports.ConnectionTCPAbridged = exports.ConnectionTCPFull = exports.Connection = exports.UpdateConnectionState = exports.MTProtoSender = exports.doAuthentication = exports.MTProtoPlainSender = void 0;
4
+ var MTProtoPlainSender_1 = require("./MTProtoPlainSender");
5
+ Object.defineProperty(exports, "MTProtoPlainSender", { enumerable: true, get: function () { return MTProtoPlainSender_1.MTProtoPlainSender; } });
6
+ var Authenticator_1 = require("./Authenticator");
7
+ Object.defineProperty(exports, "doAuthentication", { enumerable: true, get: function () { return Authenticator_1.doAuthentication; } });
8
+ var MTProtoSender_1 = require("./MTProtoSender");
9
+ Object.defineProperty(exports, "MTProtoSender", { enumerable: true, get: function () { return MTProtoSender_1.MTProtoSender; } });
10
+ class UpdateConnectionState {
11
+ constructor(state) {
12
+ this.state = state;
13
+ }
14
+ }
15
+ exports.UpdateConnectionState = UpdateConnectionState;
16
+ UpdateConnectionState.disconnected = -1;
17
+ UpdateConnectionState.connected = 1;
18
+ UpdateConnectionState.broken = 0;
19
+ var connection_1 = require("./connection");
20
+ Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return connection_1.Connection; } });
21
+ Object.defineProperty(exports, "ConnectionTCPFull", { enumerable: true, get: function () { return connection_1.ConnectionTCPFull; } });
22
+ Object.defineProperty(exports, "ConnectionTCPAbridged", { enumerable: true, get: function () { return connection_1.ConnectionTCPAbridged; } });
23
+ Object.defineProperty(exports, "ConnectionTCPObfuscated", { enumerable: true, get: function () { return connection_1.ConnectionTCPObfuscated; } });
24
+ Object.defineProperty(exports, "ConnectionWebSocket", { enumerable: true, get: function () { return connection_1.ConnectionWebSocket; } });
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "sroosh",
3
+ "version": "1.0.0",
4
+ "description": "NodeJS/Browser MTProto API Sroosh client library,",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "scripts": {
8
+ "test": "jest"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/gram-js/gramjs.git"
13
+ },
14
+ "browser": {
15
+ "fs": false
16
+ },
17
+ "license": "MIT",
18
+ "bugs": {
19
+ "url": "https://github.com/gram-js/gramjs/issues"
20
+ },
21
+ "keywords": [
22
+ "telegram",
23
+ "mtproto",
24
+ "userbot",
25
+ "api"
26
+ ],
27
+ "homepage": "https://github.com/gram-js/gramjs#readme",
28
+ "optionalDependencies": {
29
+ "bufferutil": "^4.0.3",
30
+ "utf-8-validate": "^5.0.5"
31
+ },
32
+ "devDependencies": {
33
+ "@babel/core": "^7.12.13",
34
+ "@babel/plugin-proposal-class-properties": "^7.12.13",
35
+ "@babel/preset-env": "^7.12.16",
36
+ "@types/jest": "^29.5.1",
37
+ "@types/mime": "^2.0.3",
38
+ "@types/node": "^15.12.0",
39
+ "@types/node-localstorage": "^1.3.0",
40
+ "@types/pako": "^1.0.1",
41
+ "@types/websocket": "^1.0.4",
42
+ "babel-loader": "^8.2.2",
43
+ "jest": "^29.5.0",
44
+ "os-browserify": "^0.3.0",
45
+ "prettier": "2.3.1",
46
+ "process": "^0.11.10",
47
+ "ts-jest": "^29.1.0",
48
+ "ts-loader": "^8.0.16",
49
+ "ts-node": "^9.1.1",
50
+ "typedoc": "^0.22.18",
51
+ "typedoc-plugin-missing-exports": "^0.22.6",
52
+ "typescript": "^4.2.4",
53
+ "util": "^0.12.4",
54
+ "webpack": "^5.69.0",
55
+ "webpack-cli": "^4.9.2"
56
+ },
57
+ "dependencies": {
58
+ "@cryptography/aes": "^0.1.1",
59
+ "async-mutex": "^0.3.0",
60
+ "big-integer": "^1.6.48",
61
+ "buffer": "^6.0.3",
62
+ "htmlparser2": "^6.1.0",
63
+ "mime": "^3.0.0",
64
+ "pako": "^2.0.3",
65
+ "path-browserify": "^1.0.1",
66
+ "real-cancellable-promise": "^1.1.1",
67
+ "store2": "^2.13.0",
68
+ "ts-custom-error": "^3.2.0",
69
+ "websocket": "^1.0.34",
70
+ "node-localstorage": "^2.2.1",
71
+ "socks": "^2.6.2"
72
+ }
73
+ }
package/platform.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare const isDeno: boolean;
2
+ export declare const isBrowser: boolean;
3
+ export declare const isNode: boolean;
package/platform.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNode = exports.isBrowser = exports.isDeno = void 0;
4
+ exports.isDeno = "Deno" in globalThis;
5
+ exports.isBrowser = !exports.isDeno && typeof window !== "undefined";
6
+ exports.isNode = !exports.isBrowser;
@@ -0,0 +1,24 @@
1
+ import type { TelegramClient } from "./client/TelegramClient";
2
+ import { helpers } from "./";
3
+ interface BaseRequestIterInterface {
4
+ reverse?: boolean;
5
+ waitTime?: number;
6
+ }
7
+ export declare class RequestIter implements AsyncIterable<any> {
8
+ client: TelegramClient;
9
+ reverse: boolean | undefined;
10
+ waitTime: number | undefined;
11
+ protected readonly limit: number;
12
+ protected left: number;
13
+ protected buffer: Array<any> | undefined;
14
+ private index;
15
+ protected total: number | undefined;
16
+ private lastLoad;
17
+ kwargs: {};
18
+ constructor(client: TelegramClient, limit?: number, params?: BaseRequestIterInterface, args?: {});
19
+ _init(kwargs: any): Promise<boolean | void>;
20
+ [Symbol.asyncIterator](): AsyncIterator<any, any, undefined>;
21
+ collect(): Promise<helpers.TotalList<unknown>>;
22
+ _loadNextChunk(): Promise<boolean | undefined>;
23
+ }
24
+ export {};
package/requestIter.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
3
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4
+ var m = o[Symbol.asyncIterator], i;
5
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
6
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
7
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.RequestIter = void 0;
11
+ const Helpers_1 = require("./Helpers");
12
+ const _1 = require("./");
13
+ class RequestIter {
14
+ constructor(client, limit, params = {}, args = {}) {
15
+ this.client = client;
16
+ this.reverse = params.reverse;
17
+ this.waitTime = params.waitTime;
18
+ this.limit = Math.max(!limit ? Number.MAX_SAFE_INTEGER : limit, 0);
19
+ this.left = this.limit;
20
+ this.buffer = undefined;
21
+ this.kwargs = args;
22
+ this.index = 0;
23
+ this.total = undefined;
24
+ this.lastLoad = 0;
25
+ }
26
+ async _init(kwargs) {
27
+ // for overload
28
+ }
29
+ [Symbol.asyncIterator]() {
30
+ this.buffer = undefined;
31
+ this.index = 0;
32
+ this.lastLoad = 0;
33
+ this.left = this.limit;
34
+ return {
35
+ next: async () => {
36
+ if (this.buffer == undefined) {
37
+ this.buffer = [];
38
+ if (await this._init(this.kwargs)) {
39
+ this.left = this.buffer.length;
40
+ }
41
+ }
42
+ if (this.left <= 0) {
43
+ return {
44
+ value: undefined,
45
+ done: true,
46
+ };
47
+ }
48
+ if (this.index == this.buffer.length) {
49
+ if (this.waitTime) {
50
+ await (0, Helpers_1.sleep)(this.waitTime -
51
+ (new Date().getTime() / 1000 - this.lastLoad));
52
+ }
53
+ this.lastLoad = new Date().getTime() / 1000;
54
+ this.index = 0;
55
+ this.buffer = [];
56
+ const nextChunk = await this._loadNextChunk();
57
+ if (nextChunk === false) {
58
+ // we exit;
59
+ return {
60
+ value: undefined,
61
+ done: true,
62
+ };
63
+ }
64
+ if (nextChunk) {
65
+ this.left = this.buffer.length;
66
+ }
67
+ }
68
+ if (!this.buffer || !this.buffer.length) {
69
+ return {
70
+ value: undefined,
71
+ done: true,
72
+ };
73
+ }
74
+ const result = this.buffer[this.index];
75
+ this.left -= 1;
76
+ this.index += 1;
77
+ return {
78
+ value: result,
79
+ done: false,
80
+ };
81
+ },
82
+ };
83
+ }
84
+ async collect() {
85
+ var e_1, _a;
86
+ const result = new _1.helpers.TotalList();
87
+ try {
88
+ for (var _b = __asyncValues(this), _c; _c = await _b.next(), !_c.done;) {
89
+ const message = _c.value;
90
+ result.push(message);
91
+ }
92
+ }
93
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
94
+ finally {
95
+ try {
96
+ if (_c && !_c.done && (_a = _b.return)) await _a.call(_b);
97
+ }
98
+ finally { if (e_1) throw e_1.error; }
99
+ }
100
+ result.total = this.total;
101
+ return result;
102
+ }
103
+ async _loadNextChunk() {
104
+ throw new Error("Not Implemented");
105
+ }
106
+ }
107
+ exports.RequestIter = RequestIter;
@@ -0,0 +1,103 @@
1
+ import type { AuthKey } from "../crypto/AuthKey";
2
+ import type { EntityLike } from "../define";
3
+ import { Api } from "../tl";
4
+ export declare abstract class Session {
5
+ /**
6
+ * Creates a clone of this session file
7
+ * @param toInstance {Session|null}
8
+ * @returns {Session}
9
+ */
10
+ /**
11
+ * Sets the information of the data center address and port that
12
+ * the library should connect to, as well as the data center ID,
13
+ * which is currently unused.
14
+ * @param dcId {number}
15
+ * @param serverAddress {string}
16
+ * @param port {number}
17
+ */
18
+ abstract setDC(dcId: number, serverAddress: string, port: number): void;
19
+ /**
20
+ * Returns the currently-used data center ID.
21
+ */
22
+ abstract get dcId(): number;
23
+ /**
24
+ * Returns the server address where the library should connect to.
25
+ */
26
+ abstract get serverAddress(): string;
27
+ /**
28
+ * Returns the port to which the library should connect to.
29
+ */
30
+ abstract get port(): number;
31
+ /**
32
+ * Returns an ``AuthKey`` instance associated with the saved
33
+ * data center, or `undefined` if a new one should be generated.
34
+ */
35
+ abstract get authKey(): AuthKey | undefined;
36
+ /**
37
+ * Sets the ``AuthKey`` to be used for the saved data center.
38
+ * @param value
39
+ */
40
+ abstract set authKey(value: AuthKey | undefined);
41
+ /**
42
+ * Called before using the session
43
+ */
44
+ abstract load(): Promise<void>;
45
+ /**
46
+ * sets auth key for a dc
47
+ */
48
+ abstract setAuthKey(authKey?: AuthKey, dcId?: number): void;
49
+ /**
50
+ * gets auth key for a dc
51
+ */
52
+ abstract getAuthKey(dcId?: number): AuthKey | undefined;
53
+ /**
54
+ * Turns the given key into an ``InputPeer`` (e.g. ``InputPeerUser``).
55
+ * The library uses this method whenever an ``InputPeer`` is needed
56
+ * to suit several purposes (e.g. user only provided its ID or wishes
57
+ * to use a cached username to avoid extra RPC).
58
+ */
59
+ abstract getInputEntity(key: EntityLike): Api.TypeInputPeer;
60
+ /**
61
+ * Returns an ID of the takeout process initialized for this session,
62
+ * or `None` if there's no were any unfinished takeout requests.
63
+ */
64
+ /**
65
+ * Sets the ID of the unfinished takeout process for this session.
66
+ * @param value
67
+ */
68
+ /**
69
+ * Returns the ``UpdateState`` associated with the given `entity_id`.
70
+ * If the `entity_id` is 0, it should return the ``UpdateState`` for
71
+ * no specific channel (the "general" state). If no state is known
72
+ * it should ``return None``.
73
+ * @param entityId
74
+ */
75
+ /**
76
+ * Sets the given ``UpdateState`` for the specified `entity_id`, which
77
+ * should be 0 if the ``UpdateState`` is the "general" state (and not
78
+ * for any specific channel).
79
+ * @param entityId
80
+ * @param state
81
+ */
82
+ /**
83
+ * Called on client disconnection. Should be used to
84
+ * free any used resources. Can be left empty if none.
85
+ */
86
+ abstract close(): void;
87
+ /**
88
+ * called whenever important properties change. It should
89
+ * make persist the relevant session information to disk.
90
+ */
91
+ abstract save(): void;
92
+ /**
93
+ * Called upon client.log_out(). Should delete the stored
94
+ * information from disk since it's not valid anymore.
95
+ */
96
+ abstract delete(): void;
97
+ /**
98
+ * Processes the input ``TLObject`` or ``list`` and saves
99
+ * whatever information is relevant (e.g., ID or access hash).
100
+ * @param tlo
101
+ */
102
+ abstract processEntities(tlo: any): void;
103
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Session = void 0;
4
+ class Session {
5
+ }
6
+ exports.Session = Session;
@@ -0,0 +1,18 @@
1
+ export = CacheApi;
2
+ declare class CacheApi {
3
+ constructor(sessionId: any);
4
+ _storageKey: any;
5
+ _authKeys: {};
6
+ load(): Promise<void>;
7
+ setDC(dcId: any, serverAddress: any, port: any, skipUpdateStorage?: boolean): void;
8
+ _dcId: any;
9
+ _serverAddress: any;
10
+ _port: any;
11
+ save(): Promise<any>;
12
+ set authKey(arg: void);
13
+ get authKey(): void;
14
+ getAuthKey(dcId?: any): any;
15
+ setAuthKey(authKey: any, dcId?: any): void;
16
+ _updateStorage(): Promise<void>;
17
+ delete(): Promise<void>;
18
+ }