@armatofik/tgsnake-core 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 (171) hide show
  1. package/COPYING +674 -0
  2. package/COPYING.lesser +165 -0
  3. package/README.md +88 -0
  4. package/lib/package.json +46 -0
  5. package/lib/src/Logger.d.ts +3 -0
  6. package/lib/src/Logger.js +9 -0
  7. package/lib/src/Queue.d.ts +19 -0
  8. package/lib/src/Queue.js +52 -0
  9. package/lib/src/Timeout.d.ts +9 -0
  10. package/lib/src/Timeout.js +44 -0
  11. package/lib/src/Version.node.d.ts +4 -0
  12. package/lib/src/Version.node.js +26 -0
  13. package/lib/src/client/Auth.d.ts +40 -0
  14. package/lib/src/client/Auth.js +317 -0
  15. package/lib/src/client/Client.d.ts +83 -0
  16. package/lib/src/client/Client.js +461 -0
  17. package/lib/src/client/Session.d.ts +9 -0
  18. package/lib/src/client/Session.js +132 -0
  19. package/lib/src/client/index.d.ts +3 -0
  20. package/lib/src/client/index.js +39 -0
  21. package/lib/src/connection/TCP/TCPAbridged.d.ts +9 -0
  22. package/lib/src/connection/TCP/TCPAbridged.js +47 -0
  23. package/lib/src/connection/TCP/TCPAbridgedO.d.ts +12 -0
  24. package/lib/src/connection/TCP/TCPAbridgedO.js +140 -0
  25. package/lib/src/connection/TCP/TCPFull.d.ts +10 -0
  26. package/lib/src/connection/TCP/TCPFull.js +43 -0
  27. package/lib/src/connection/TCP/TCPIntermediate.d.ts +9 -0
  28. package/lib/src/connection/TCP/TCPIntermediate.js +31 -0
  29. package/lib/src/connection/TCP/TCPIntermediateO.d.ts +12 -0
  30. package/lib/src/connection/TCP/TCPIntermediateO.js +123 -0
  31. package/lib/src/connection/TCP/TCPPaddedIntermediate.d.ts +9 -0
  32. package/lib/src/connection/TCP/TCPPaddedIntermediate.js +38 -0
  33. package/lib/src/connection/TCP/index.d.ts +7 -0
  34. package/lib/src/connection/TCP/index.js +17 -0
  35. package/lib/src/connection/TCP/tcp.d.ts +17 -0
  36. package/lib/src/connection/TCP/tcp.js +98 -0
  37. package/lib/src/connection/WebSocket.d.ts +21 -0
  38. package/lib/src/connection/WebSocket.js +279 -0
  39. package/lib/src/connection/connection.d.ts +53 -0
  40. package/lib/src/connection/connection.js +189 -0
  41. package/lib/src/connection/index.d.ts +4 -0
  42. package/lib/src/connection/index.js +41 -0
  43. package/lib/src/crypto/Aes.d.ts +10 -0
  44. package/lib/src/crypto/Aes.js +135 -0
  45. package/lib/src/crypto/Mtproto.d.ts +5 -0
  46. package/lib/src/crypto/Mtproto.js +123 -0
  47. package/lib/src/crypto/Password.d.ts +5 -0
  48. package/lib/src/crypto/Password.js +92 -0
  49. package/lib/src/crypto/Prime.d.ts +4 -0
  50. package/lib/src/crypto/Prime.js +64 -0
  51. package/lib/src/crypto/RSA.d.ts +7 -0
  52. package/lib/src/crypto/RSA.js +99 -0
  53. package/lib/src/crypto/SecretChat.d.ts +5 -0
  54. package/lib/src/crypto/SecretChat.js +136 -0
  55. package/lib/src/crypto/index.d.ts +6 -0
  56. package/lib/src/crypto/index.js +42 -0
  57. package/lib/src/errors/Base.d.ts +9 -0
  58. package/lib/src/errors/Base.js +50 -0
  59. package/lib/src/errors/Client.d.ts +21 -0
  60. package/lib/src/errors/Client.js +29 -0
  61. package/lib/src/errors/File.d.ts +13 -0
  62. package/lib/src/errors/File.js +30 -0
  63. package/lib/src/errors/RpcError.d.ts +22 -0
  64. package/lib/src/errors/RpcError.js +120 -0
  65. package/lib/src/errors/SecretChat.d.ts +13 -0
  66. package/lib/src/errors/SecretChat.js +30 -0
  67. package/lib/src/errors/WebSocket.d.ts +13 -0
  68. package/lib/src/errors/WebSocket.js +30 -0
  69. package/lib/src/errors/exceptions/All.d.ts +774 -0
  70. package/lib/src/errors/exceptions/All.js +778 -0
  71. package/lib/src/errors/exceptions/BadRequest400.d.ts +2345 -0
  72. package/lib/src/errors/exceptions/BadRequest400.js +2945 -0
  73. package/lib/src/errors/exceptions/Flood420.d.ts +37 -0
  74. package/lib/src/errors/exceptions/Flood420.js +49 -0
  75. package/lib/src/errors/exceptions/Forbidden403.d.ts +205 -0
  76. package/lib/src/errors/exceptions/Forbidden403.js +260 -0
  77. package/lib/src/errors/exceptions/InternalServerError500.d.ts +221 -0
  78. package/lib/src/errors/exceptions/InternalServerError500.js +280 -0
  79. package/lib/src/errors/exceptions/NotAcceptable406.d.ts +117 -0
  80. package/lib/src/errors/exceptions/NotAcceptable406.js +149 -0
  81. package/lib/src/errors/exceptions/NotFound404.d.ts +9 -0
  82. package/lib/src/errors/exceptions/NotFound404.js +14 -0
  83. package/lib/src/errors/exceptions/SeeOther303.d.ts +25 -0
  84. package/lib/src/errors/exceptions/SeeOther303.js +34 -0
  85. package/lib/src/errors/exceptions/ServiceUnavailable503.d.ts +17 -0
  86. package/lib/src/errors/exceptions/ServiceUnavailable503.js +24 -0
  87. package/lib/src/errors/exceptions/Unauthorized401.d.ts +41 -0
  88. package/lib/src/errors/exceptions/Unauthorized401.js +54 -0
  89. package/lib/src/errors/exceptions/index.d.ts +10 -0
  90. package/lib/src/errors/exceptions/index.js +48 -0
  91. package/lib/src/errors/index.d.ts +31 -0
  92. package/lib/src/errors/index.js +111 -0
  93. package/lib/src/file/Download.d.ts +11 -0
  94. package/lib/src/file/Download.js +118 -0
  95. package/lib/src/file/File.d.ts +20 -0
  96. package/lib/src/file/File.js +82 -0
  97. package/lib/src/file/Upload.d.ts +19 -0
  98. package/lib/src/file/Upload.js +250 -0
  99. package/lib/src/file/index.d.ts +3 -0
  100. package/lib/src/file/index.js +11 -0
  101. package/lib/src/helpers.d.ts +34 -0
  102. package/lib/src/helpers.js +358 -0
  103. package/lib/src/index.d.ts +16 -0
  104. package/lib/src/index.js +56 -0
  105. package/lib/src/platform.node.d.ts +36 -0
  106. package/lib/src/platform.node.js +109 -0
  107. package/lib/src/raw/All.d.ts +2400 -0
  108. package/lib/src/raw/All.js +2403 -0
  109. package/lib/src/raw/Raw.d.ts +29195 -0
  110. package/lib/src/raw/Raw.js +97277 -0
  111. package/lib/src/raw/core/BytesIO.d.ts +33 -0
  112. package/lib/src/raw/core/BytesIO.js +145 -0
  113. package/lib/src/raw/core/GzipPacked.d.ts +10 -0
  114. package/lib/src/raw/core/GzipPacked.js +60 -0
  115. package/lib/src/raw/core/Message.d.ts +13 -0
  116. package/lib/src/raw/core/Message.js +81 -0
  117. package/lib/src/raw/core/MsgContainer.d.ts +11 -0
  118. package/lib/src/raw/core/MsgContainer.js +69 -0
  119. package/lib/src/raw/core/TLObject.d.ts +19 -0
  120. package/lib/src/raw/core/TLObject.js +108 -0
  121. package/lib/src/raw/core/UpdateSecretChat.d.ts +40 -0
  122. package/lib/src/raw/core/UpdateSecretChat.js +88 -0
  123. package/lib/src/raw/core/index.d.ts +8 -0
  124. package/lib/src/raw/core/index.js +52 -0
  125. package/lib/src/raw/core/primitive/Bool.d.ts +20 -0
  126. package/lib/src/raw/core/primitive/Bool.js +41 -0
  127. package/lib/src/raw/core/primitive/Bytes.d.ts +7 -0
  128. package/lib/src/raw/core/primitive/Bytes.js +41 -0
  129. package/lib/src/raw/core/primitive/Double.d.ts +7 -0
  130. package/lib/src/raw/core/primitive/Double.js +24 -0
  131. package/lib/src/raw/core/primitive/Float.d.ts +7 -0
  132. package/lib/src/raw/core/primitive/Float.js +24 -0
  133. package/lib/src/raw/core/primitive/Int.d.ts +23 -0
  134. package/lib/src/raw/core/primitive/Int.js +122 -0
  135. package/lib/src/raw/core/primitive/String.d.ts +7 -0
  136. package/lib/src/raw/core/primitive/String.js +15 -0
  137. package/lib/src/raw/core/primitive/Vector.d.ts +9 -0
  138. package/lib/src/raw/core/primitive/Vector.js +50 -0
  139. package/lib/src/raw/core/primitive/index.d.ts +7 -0
  140. package/lib/src/raw/core/primitive/index.js +22 -0
  141. package/lib/src/raw/index.d.ts +3 -0
  142. package/lib/src/raw/index.js +17 -0
  143. package/lib/src/session/Auth.d.ts +15 -0
  144. package/lib/src/session/Auth.js +254 -0
  145. package/lib/src/session/Session.d.ts +58 -0
  146. package/lib/src/session/Session.js +571 -0
  147. package/lib/src/session/index.d.ts +7 -0
  148. package/lib/src/session/index.js +49 -0
  149. package/lib/src/session/internals/DataCenter.d.ts +42 -0
  150. package/lib/src/session/internals/DataCenter.js +80 -0
  151. package/lib/src/session/internals/MsgFactory.d.ts +3 -0
  152. package/lib/src/session/internals/MsgFactory.js +23 -0
  153. package/lib/src/session/internals/MsgId.d.ts +9 -0
  154. package/lib/src/session/internals/MsgId.js +24 -0
  155. package/lib/src/session/internals/SeqNo.d.ts +6 -0
  156. package/lib/src/session/internals/SeqNo.js +18 -0
  157. package/lib/src/session/secretChats/SecretChat.d.ts +29 -0
  158. package/lib/src/session/secretChats/SecretChat.js +527 -0
  159. package/lib/src/session/secretChats/index.d.ts +1 -0
  160. package/lib/src/session/secretChats/index.js +5 -0
  161. package/lib/src/storage/Abstract.d.ts +68 -0
  162. package/lib/src/storage/Abstract.js +6 -0
  163. package/lib/src/storage/SecretChat.d.ts +42 -0
  164. package/lib/src/storage/SecretChat.js +99 -0
  165. package/lib/src/storage/Session.d.ts +63 -0
  166. package/lib/src/storage/Session.js +245 -0
  167. package/lib/src/storage/StringSession.d.ts +4 -0
  168. package/lib/src/storage/StringSession.js +77 -0
  169. package/lib/src/storage/index.d.ts +4 -0
  170. package/lib/src/storage/index.js +12 -0
  171. package/package.json +46 -0
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DCProdMediaIPV6 = exports.DCProdIPV6 = exports.DCTestIPV6 = exports.DCProdMedia = exports.WebDC = exports.DCProd = exports.DCTest = void 0;
4
+ exports.DataCenter = DataCenter;
5
+ const platform_node_js_1 = require("../../platform.node.js");
6
+ exports.DCTest = {
7
+ 1: '149.154.175.10',
8
+ 2: '149.154.167.40',
9
+ 3: '149.154.175.117',
10
+ };
11
+ exports.DCProd = {
12
+ 1: '149.154.175.53',
13
+ 2: '149.154.167.51',
14
+ 3: '149.154.175.100',
15
+ 4: '149.154.167.91',
16
+ 5: '91.108.56.130',
17
+ 203: '91.105.192.100',
18
+ };
19
+ exports.WebDC = {
20
+ 1: 'pluto.web.telegram.org',
21
+ 2: 'venus.web.telegram.org',
22
+ 3: 'aurora.web.telegram.org',
23
+ 4: 'vesta.web.telegram.org',
24
+ 5: 'flora.web.telegram.org',
25
+ };
26
+ exports.DCProdMedia = {
27
+ 2: '149.154.167.151',
28
+ 4: '149.154.164.250',
29
+ };
30
+ exports.DCTestIPV6 = {
31
+ 1: '2001:b28:f23d:f001::e',
32
+ 2: '2001:67c:4e8:f002::e',
33
+ 3: '2001:b28:f23d:f003::e',
34
+ };
35
+ exports.DCProdIPV6 = {
36
+ 1: '2001:b28:f23d:f001::a',
37
+ 2: '2001:67c:4e8:f002::a',
38
+ 3: '2001:b28:f23d:f003::a',
39
+ 4: '2001:67c:4e8:f004::a',
40
+ 5: '2001:b28:f23f:f005::a',
41
+ 203: '2a0a:f280:0203:000a:5000:0000:0000:0100',
42
+ };
43
+ exports.DCProdMediaIPV6 = {
44
+ 2: '2001:067c:04e8:f002:0000:0000:0000:000b',
45
+ 4: '2001:067c:04e8:f004:0000:0000:0000:000b',
46
+ };
47
+ function DataCenter(dcId, testMode, ipv6, media) {
48
+ if (platform_node_js_1.isBrowser) {
49
+ return [
50
+ `${exports.WebDC[dcId]}:$PORT/apiws${testMode ? '_test' : ''}`,
51
+ 443,
52
+ ];
53
+ }
54
+ else {
55
+ if (testMode) {
56
+ return [
57
+ ipv6 ? exports.DCTestIPV6[dcId] : exports.DCTest[dcId],
58
+ 80,
59
+ ];
60
+ }
61
+ else {
62
+ if (media) {
63
+ return [
64
+ ipv6
65
+ ? (exports.DCProdMediaIPV6[dcId] ??
66
+ exports.DCProdIPV6[dcId])
67
+ : (exports.DCProdMedia[dcId] ??
68
+ exports.DCProd[dcId]),
69
+ 443,
70
+ ];
71
+ }
72
+ else {
73
+ return [
74
+ ipv6 ? exports.DCProdIPV6[dcId] : exports.DCProd[dcId],
75
+ 443,
76
+ ];
77
+ }
78
+ }
79
+ }
80
+ }
@@ -0,0 +1,3 @@
1
+ import { MsgId } from './MsgId.js';
2
+ import { Message, TLObject } from '../../raw/index.js';
3
+ export declare function MsgFactory(): (body: TLObject, msgId: MsgId) => Message;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MsgFactory = MsgFactory;
4
+ const SeqNo_js_1 = require("./SeqNo.js");
5
+ const index_js_1 = require("../../raw/index.js");
6
+ const platform_node_js_1 = require("../../platform.node.js");
7
+ function MsgFactory() {
8
+ const seqNo = new SeqNo_js_1.SeqNo();
9
+ const notRelatedContent = (content) => {
10
+ if (content instanceof index_js_1.Raw.Ping)
11
+ return true;
12
+ if (content instanceof index_js_1.Raw.HttpWait)
13
+ return true;
14
+ if (content instanceof index_js_1.Raw.MsgsAck)
15
+ return true;
16
+ if (content instanceof index_js_1.MsgContainer)
17
+ return true;
18
+ return false;
19
+ };
20
+ return (body, msgId) => {
21
+ return new index_js_1.Message(body, BigInt(msgId.getMsgId()), seqNo.getSeqNo(!notRelatedContent(body)), platform_node_js_1.Buffer.byteLength(body.write()));
22
+ };
23
+ }
@@ -0,0 +1,9 @@
1
+ export declare class MsgId {
2
+ referenceClock: bigint;
3
+ lastTime: bigint;
4
+ msgIdOffset: bigint;
5
+ serverTime: bigint;
6
+ constructor();
7
+ getMsgId(): bigint;
8
+ setServerTime(serverTime: bigint): void;
9
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MsgId = void 0;
4
+ class MsgId {
5
+ referenceClock = BigInt(0);
6
+ lastTime = BigInt(0);
7
+ msgIdOffset = BigInt(0);
8
+ serverTime = BigInt(0);
9
+ constructor() { }
10
+ getMsgId() {
11
+ const now = BigInt(Math.floor(Date.now() / 1000)) - this.referenceClock + this.serverTime;
12
+ this.msgIdOffset = now === this.lastTime ? this.msgIdOffset + BigInt(4) : BigInt(0);
13
+ const msgId = now * BigInt(2 ** 32) + this.msgIdOffset;
14
+ this.lastTime = now;
15
+ return msgId;
16
+ }
17
+ setServerTime(serverTime) {
18
+ if (!this.serverTime) {
19
+ this.referenceClock = BigInt(Math.floor(Date.now() / 1000));
20
+ this.serverTime = serverTime;
21
+ }
22
+ }
23
+ }
24
+ exports.MsgId = MsgId;
@@ -0,0 +1,6 @@
1
+ export declare class SeqNo {
2
+ contentRMsgSend: number;
3
+ seqNo: number;
4
+ constructor();
5
+ getSeqNo(isContentRelated: boolean): number;
6
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SeqNo = void 0;
4
+ class SeqNo {
5
+ contentRMsgSend;
6
+ seqNo;
7
+ constructor() {
8
+ this.contentRMsgSend = 0;
9
+ this.seqNo = 0;
10
+ }
11
+ getSeqNo(isContentRelated) {
12
+ this.seqNo = this.contentRMsgSend * 2 + (isContentRelated ? 1 : 0);
13
+ if (isContentRelated)
14
+ this.contentRMsgSend += 1;
15
+ return this.seqNo;
16
+ }
17
+ }
18
+ exports.SeqNo = SeqNo;
@@ -0,0 +1,29 @@
1
+ import { Raw } from '../../raw/index.js';
2
+ import { type AbstractSession } from '../../storage/index.js';
3
+ import { Buffer } from '../../platform.node.js';
4
+ import type { Client } from '../../client/Client.js';
5
+ export declare class SecretChat {
6
+ private _storage;
7
+ private _client;
8
+ private _dhConfig;
9
+ private _mutex;
10
+ private _tempAuthKey;
11
+ private _waiting;
12
+ constructor(storage: AbstractSession, client: Client);
13
+ private reqDHConfig;
14
+ start(userId: bigint | string): Promise<Raw.TypeEncryptedChat>;
15
+ accept(request: Raw.EncryptedChatRequested): Promise<Raw.TypeEncryptedChat>;
16
+ finish(chat: Raw.EncryptedChat): Promise<Raw.messages.TypeSentEncryptedMessage | undefined>;
17
+ notifyLayer(chatId: number): Promise<Raw.messages.TypeSentEncryptedMessage | undefined>;
18
+ destroy(chatId: number): Promise<boolean>;
19
+ rekeying(chatId: number): Promise<Raw.messages.TypeSentEncryptedMessage>;
20
+ acceptRekeying(chatId: number, action: Raw.DecryptedMessageActionRequestKey20): Promise<Raw.messages.TypeSentEncryptedMessage | undefined>;
21
+ commitRekeying(chatId: number, action: Raw.DecryptedMessageActionAcceptKey20): Promise<Raw.messages.TypeSentEncryptedMessage | undefined>;
22
+ finalRekeying(chatId: number, action: Raw.DecryptedMessageActionCommitKey20): Promise<Raw.messages.TypeSentEncryptedMessage | undefined>;
23
+ decrypt(message: Raw.TypeEncryptedMessage): Promise<any>;
24
+ encrypt(chatId: number, message: Raw.TypeDecryptedMessage): Promise<Buffer<ArrayBufferLike>>;
25
+ toJSON(): {
26
+ [key: string]: any;
27
+ };
28
+ toString(): string;
29
+ }