@mtkruto/node 0.153.0 → 0.154.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.
- package/esm/4_constants.d.ts +1 -0
- package/esm/4_constants.d.ts.map +1 -1
- package/esm/4_constants.js +1 -0
- package/esm/client/1_client_plain.d.ts +1 -1
- package/esm/client/1_client_plain.d.ts.map +1 -1
- package/esm/client/1_client_plain.js +25 -13
- package/esm/client/2_client_encrypted.d.ts +6 -3
- package/esm/client/2_client_encrypted.d.ts.map +1 -1
- package/esm/client/2_client_encrypted.js +155 -48
- package/esm/client/2_network_statistics_manager.d.ts.map +1 -1
- package/esm/client/2_network_statistics_manager.js +3 -2
- package/esm/client/2_update_manager.d.ts.map +1 -1
- package/esm/client/2_update_manager.js +6 -1
- package/esm/client/6_client.d.ts +2 -0
- package/esm/client/6_client.d.ts.map +1 -1
- package/esm/client/6_client.js +4 -1
- package/esm/session/0_session_state.d.ts +1 -0
- package/esm/session/0_session_state.d.ts.map +1 -1
- package/esm/session/0_session_state.js +8 -4
- package/esm/session/1_session.d.ts +1 -0
- package/esm/session/1_session.d.ts.map +1 -1
- package/esm/session/1_session.js +3 -0
- package/esm/session/2_session_encrypted.d.ts +11 -6
- package/esm/session/2_session_encrypted.d.ts.map +1 -1
- package/esm/session/2_session_encrypted.js +18 -10
- package/package.json +1 -1
- package/script/4_constants.d.ts +1 -0
- package/script/4_constants.d.ts.map +1 -1
- package/script/4_constants.js +2 -1
- package/script/client/1_client_plain.d.ts +1 -1
- package/script/client/1_client_plain.d.ts.map +1 -1
- package/script/client/1_client_plain.js +24 -12
- package/script/client/2_client_encrypted.d.ts +6 -3
- package/script/client/2_client_encrypted.d.ts.map +1 -1
- package/script/client/2_client_encrypted.js +156 -49
- package/script/client/2_network_statistics_manager.d.ts.map +1 -1
- package/script/client/2_network_statistics_manager.js +3 -2
- package/script/client/2_update_manager.d.ts.map +1 -1
- package/script/client/2_update_manager.js +6 -1
- package/script/client/6_client.d.ts +2 -0
- package/script/client/6_client.d.ts.map +1 -1
- package/script/client/6_client.js +4 -1
- package/script/session/0_session_state.d.ts +1 -0
- package/script/session/0_session_state.d.ts.map +1 -1
- package/script/session/0_session_state.js +8 -4
- package/script/session/1_session.d.ts +1 -0
- package/script/session/1_session.d.ts.map +1 -1
- package/script/session/1_session.js +3 -0
- package/script/session/2_session_encrypted.d.ts +11 -6
- package/script/session/2_session_encrypted.d.ts.map +1 -1
- package/script/session/2_session_encrypted.js +18 -10
|
@@ -27,16 +27,20 @@ class SessionState {
|
|
|
27
27
|
#seqNo = 0;
|
|
28
28
|
#messageId = 0n;
|
|
29
29
|
nextMessageId() {
|
|
30
|
+
return this.#messageId = this.previewNextMessageId();
|
|
31
|
+
}
|
|
32
|
+
previewNextMessageId() {
|
|
30
33
|
const now = (0, _1_utilities_js_1.toUnixTimestamp)(new Date()) + this.timeDifference;
|
|
31
34
|
const nanoseconds = Math.floor((now - Math.floor(now)) * 1e9);
|
|
32
35
|
const newMessageId = (BigInt(Math.floor(now)) << 32n) || (BigInt(nanoseconds) << 2n);
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
let messageId = this.#messageId;
|
|
37
|
+
if (messageId >= newMessageId) {
|
|
38
|
+
messageId += 4n;
|
|
35
39
|
}
|
|
36
40
|
else {
|
|
37
|
-
|
|
41
|
+
messageId = newMessageId;
|
|
38
42
|
}
|
|
39
|
-
return
|
|
43
|
+
return messageId;
|
|
40
44
|
}
|
|
41
45
|
nextSeqNo(contentRelated) {
|
|
42
46
|
let seqNo = this.#seqNo * 2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1_session.d.ts","sourceRoot":"","sources":["../../src/session/1_session.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAoD,MAAM,mBAAmB,CAAC;AACt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AAwE;IACxE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,8BAAsB,OAAO;;IAG3B,SAAS,CAAC,KAAK,EAAE,YAAY,CAAsB;IACnD,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC;gBAMvC,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,aAAa;IAc1C,IAAI,uBAAuB,CAAC,uBAAuB,EAAE,UAAU,CAAC,oBAAoB,CAAC,EAEpF;IAED,IAAI,kBAAkB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,SAAS,EAExE;IAED,IAAI,EAAE,IAAI,EAAE,CAEX;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,UAAU,CAAC,UAAU,EAAE,MAAM,EAEhC;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IA6BD,IAAI,WAAW,IAAI,OAAO,CAEzB;IAGK,OAAO;cAeG,kBAAkB;IAIlC,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED,UAAU;IAOV,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAEhD,oBAAoB,IAAI,MAAM;CAG/B"}
|
|
@@ -17,23 +17,28 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
+
import { TransportError } from "../0_errors.js";
|
|
21
|
+
import { type MaybePromise } from "../1_utilities.js";
|
|
20
22
|
import { Mtproto } from "../2_tl.js";
|
|
21
23
|
import type { DC } from "../3_transport.js";
|
|
22
24
|
import { Session, type SessionParams } from "./1_session.js";
|
|
23
25
|
export interface Handlers {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
onTransportError?: (transportError: TransportError) => MaybePromise<void>;
|
|
27
|
+
onUpdate?: (body: Uint8Array) => MaybePromise<void>;
|
|
28
|
+
onNewServerSalt?: (serverSalt: bigint) => MaybePromise<void>;
|
|
29
|
+
onMessageFailed?: (id: bigint, reason: unknown) => MaybePromise<void>;
|
|
30
|
+
onPong?: (pong: Mtproto.pong) => MaybePromise<void>;
|
|
31
|
+
onRpcError?: (id: bigint, error: Mtproto.rpc_error) => MaybePromise<void>;
|
|
32
|
+
onRpcResult?: (id: bigint, result: Uint8Array) => MaybePromise<void>;
|
|
30
33
|
}
|
|
31
34
|
export declare class SessionEncrypted extends Session implements Session {
|
|
32
35
|
#private;
|
|
33
36
|
handlers: Handlers;
|
|
34
37
|
constructor(dc: DC, params?: SessionParams);
|
|
35
38
|
setAuthKey(key: Uint8Array<ArrayBuffer>): Promise<void>;
|
|
39
|
+
get id(): bigint;
|
|
36
40
|
get authKey(): Uint8Array<ArrayBuffer>;
|
|
41
|
+
get authKeyId(): bigint;
|
|
37
42
|
connect(): Promise<void>;
|
|
38
43
|
disconnect(): void;
|
|
39
44
|
send(body: Uint8Array<ArrayBuffer>): Promise<bigint>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"2_session_encrypted.d.ts","sourceRoot":"","sources":["../../src/session/2_session_encrypted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;
|
|
1
|
+
{"version":3,"file":"2_session_encrypted.d.ts","sourceRoot":"","sources":["../../src/session/2_session_encrypted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAmB,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAA+E,KAAK,YAAY,EAAsC,MAAM,mBAAmB,CAAC;AACvK,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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essionEncrypted extends _1_session_js_1.Session {
|
|
|
61
61
|
this.#authKeyId = (0, _1_utilities_js_1.intFromBytes)(hash.slice(-8));
|
|
62
62
|
this.#authKey = key;
|
|
63
63
|
}
|
|
64
|
+
get id() {
|
|
65
|
+
return this.#id;
|
|
66
|
+
}
|
|
64
67
|
get authKey() {
|
|
65
68
|
return this.#authKey;
|
|
66
69
|
}
|
|
70
|
+
get authKeyId() {
|
|
71
|
+
return this.#authKeyId;
|
|
72
|
+
}
|
|
67
73
|
async connect() {
|
|
68
74
|
if (!this.isConnected) {
|
|
69
75
|
this.#rejectAllPending(new _0_errors_js_1.ConnectionError("The connection was closed."));
|
|
@@ -82,6 +88,8 @@ class SessionEncrypted extends _1_session_js_1.Session {
|
|
|
82
88
|
super.disconnect();
|
|
83
89
|
this.state.reset();
|
|
84
90
|
this.#id = (0, _1_utilities_js_1.getRandomId)();
|
|
91
|
+
this.#receiveLoop.abort();
|
|
92
|
+
this.#sendLoop.abort();
|
|
85
93
|
this.#pingLoop.abort();
|
|
86
94
|
this.#awakeSendLoop?.();
|
|
87
95
|
this.#rejectAllPending(new _0_errors_js_1.ConnectionError("The connection was disconnected."));
|
|
@@ -140,11 +148,11 @@ class SessionEncrypted extends _1_session_js_1.Session {
|
|
|
140
148
|
return;
|
|
141
149
|
}
|
|
142
150
|
// message was not sent by us
|
|
143
|
-
this.handlers.onMessageFailed?.(id, reason);
|
|
151
|
+
(0, _1_utilities_js_1.drop)(this.handlers.onMessageFailed?.(id, reason));
|
|
144
152
|
}
|
|
145
153
|
#setServerSalt(newServerSalt) {
|
|
146
154
|
this.state.serverSalt = newServerSalt;
|
|
147
|
-
this.handlers.onNewServerSalt?.(newServerSalt);
|
|
155
|
+
(0, _1_utilities_js_1.drop)(this.handlers.onNewServerSalt?.(newServerSalt));
|
|
148
156
|
}
|
|
149
157
|
async send(body) {
|
|
150
158
|
if (!this.isDisconnected && !this.isConnected) {
|
|
@@ -304,11 +312,11 @@ class SessionEncrypted extends _1_session_js_1.Session {
|
|
|
304
312
|
if (!this.isConnected) {
|
|
305
313
|
this.#LreceiveLoop.debug("aborting as not connected");
|
|
306
314
|
loop.abort();
|
|
307
|
-
return;
|
|
308
315
|
}
|
|
309
|
-
else {
|
|
310
|
-
|
|
316
|
+
else if (err instanceof _0_errors_js_1.TransportError) {
|
|
317
|
+
await this.handlers.onTransportError?.(err);
|
|
311
318
|
}
|
|
319
|
+
return;
|
|
312
320
|
}
|
|
313
321
|
try {
|
|
314
322
|
if (message.body instanceof Uint8Array) {
|
|
@@ -334,13 +342,13 @@ class SessionEncrypted extends _1_session_js_1.Session {
|
|
|
334
342
|
id = reader.readInt32(false);
|
|
335
343
|
}
|
|
336
344
|
if (id === RPC_RESULT) {
|
|
337
|
-
this.#onRpcResult(msgId, reader.buffer, logger);
|
|
345
|
+
await this.#onRpcResult(msgId, reader.buffer, logger);
|
|
338
346
|
return;
|
|
339
347
|
}
|
|
340
348
|
if (!_2_tl_js_1.Mtproto.schema.identifierToName[id]) {
|
|
341
349
|
logger.debug("identified body as a non-MTProto constructor");
|
|
342
350
|
reader.unreadInt32();
|
|
343
|
-
this.handlers.onUpdate?.(reader.buffer);
|
|
351
|
+
await this.handlers.onUpdate?.(reader.buffer);
|
|
344
352
|
return;
|
|
345
353
|
}
|
|
346
354
|
let type;
|
|
@@ -393,10 +401,10 @@ class SessionEncrypted extends _1_session_js_1.Session {
|
|
|
393
401
|
if (id === RPC_ERROR) {
|
|
394
402
|
logger.debug("received rpc_error from message", msgId);
|
|
395
403
|
const error = await _2_tl_js_1.Mtproto.deserializeType("rpc_error", reader);
|
|
396
|
-
this.handlers.onRpcError?.(reqMsgId, error);
|
|
404
|
+
await this.handlers.onRpcError?.(reqMsgId, error);
|
|
397
405
|
}
|
|
398
406
|
else {
|
|
399
|
-
this.handlers.onRpcResult?.(reqMsgId, reader.buffer);
|
|
407
|
+
await this.handlers.onRpcResult?.(reqMsgId, reader.buffer);
|
|
400
408
|
}
|
|
401
409
|
}
|
|
402
410
|
#onMsgDetailedInfo(msgDetailedInfo, logger) {
|
|
@@ -448,7 +456,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
|
|
|
448
456
|
}
|
|
449
457
|
else {
|
|
450
458
|
// pong is not ours
|
|
451
|
-
this.handlers.onPong?.(pong);
|
|
459
|
+
(0, _1_utilities_js_1.drop)(this.handlers.onPong?.(pong));
|
|
452
460
|
}
|
|
453
461
|
}
|
|
454
462
|
#onNewSessionCreated(msgId, newSessionCreated) {
|