@mtcute/core 0.21.1 → 0.22.2

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 (143) hide show
  1. package/client.cjs +13 -8
  2. package/client.js +13 -8
  3. package/highlevel/client.d.cts +27 -49
  4. package/highlevel/client.d.ts +27 -49
  5. package/highlevel/methods/auth/sign-in-qr.cjs +4 -4
  6. package/highlevel/methods/files/download-iterable.cjs +25 -0
  7. package/highlevel/methods/files/download-iterable.js +25 -0
  8. package/highlevel/methods/files/upload-file.js +1 -1
  9. package/highlevel/methods/messages/forward-messages.cjs +2 -1
  10. package/highlevel/methods/messages/forward-messages.d.cts +6 -0
  11. package/highlevel/methods/messages/forward-messages.d.ts +6 -0
  12. package/highlevel/methods/messages/forward-messages.js +2 -1
  13. package/highlevel/methods/messages/get-web-page-preview.cjs +22 -0
  14. package/highlevel/methods/messages/get-web-page-preview.d.cts +9 -0
  15. package/highlevel/methods/messages/get-web-page-preview.d.ts +9 -0
  16. package/highlevel/methods/messages/get-web-page-preview.js +17 -0
  17. package/highlevel/methods/messages/send-common.d.cts +5 -0
  18. package/highlevel/methods/messages/send-common.d.ts +5 -0
  19. package/highlevel/methods/messages/send-media-group.cjs +2 -1
  20. package/highlevel/methods/messages/send-media-group.js +2 -1
  21. package/highlevel/methods/messages/send-media.cjs +2 -1
  22. package/highlevel/methods/messages/send-media.js +2 -1
  23. package/highlevel/methods/messages/send-text.cjs +2 -1
  24. package/highlevel/methods/messages/send-text.js +2 -1
  25. package/highlevel/methods/premium/pin-star-gift.cjs +24 -0
  26. package/highlevel/methods/premium/pin-star-gift.d.cts +13 -0
  27. package/highlevel/methods/premium/pin-star-gift.d.ts +13 -0
  28. package/highlevel/methods/premium/pin-star-gift.js +19 -0
  29. package/highlevel/methods/{premium/get-star-gifts.cjs → users/get-peer-settings.cjs} +10 -6
  30. package/highlevel/methods/users/get-peer-settings.d.cts +4 -0
  31. package/highlevel/methods/users/get-peer-settings.d.ts +4 -0
  32. package/highlevel/methods/users/get-peer-settings.js +14 -0
  33. package/highlevel/methods/users/resolve-peer.cjs +16 -31
  34. package/highlevel/methods/users/resolve-peer.js +7 -22
  35. package/highlevel/methods.d.cts +3 -2
  36. package/highlevel/methods.d.ts +3 -2
  37. package/highlevel/storage/repository/peers.d.cts +2 -3
  38. package/highlevel/storage/repository/peers.d.ts +2 -3
  39. package/highlevel/storage/service/peers.cjs +10 -4
  40. package/highlevel/storage/service/peers.d.cts +1 -0
  41. package/highlevel/storage/service/peers.d.ts +1 -0
  42. package/highlevel/storage/service/peers.js +10 -4
  43. package/highlevel/types/bots/keyboards/factories.cjs +4 -4
  44. package/highlevel/types/media/document.cjs +1 -1
  45. package/highlevel/types/media/document.js +1 -1
  46. package/highlevel/types/media/web-page.cjs +40 -3
  47. package/highlevel/types/media/web-page.d.cts +23 -1
  48. package/highlevel/types/media/web-page.d.ts +23 -1
  49. package/highlevel/types/media/web-page.js +41 -4
  50. package/highlevel/types/messages/message-media.cjs +1 -1
  51. package/highlevel/types/messages/message-media.d.cts +2 -2
  52. package/highlevel/types/messages/message-media.d.ts +2 -2
  53. package/highlevel/types/messages/message-media.js +2 -2
  54. package/highlevel/types/messages/message.cjs +4 -0
  55. package/highlevel/types/messages/message.d.cts +2 -0
  56. package/highlevel/types/messages/message.d.ts +2 -0
  57. package/highlevel/types/messages/message.js +4 -0
  58. package/highlevel/types/peers/chat-event/actions.cjs +5 -0
  59. package/highlevel/types/peers/chat-event/actions.js +5 -0
  60. package/highlevel/types/peers/chat.cjs +4 -2
  61. package/highlevel/types/peers/chat.d.cts +2 -2
  62. package/highlevel/types/peers/chat.d.ts +2 -2
  63. package/highlevel/types/peers/chat.js +4 -2
  64. package/highlevel/types/peers/full-chat.cjs +4 -0
  65. package/highlevel/types/peers/full-chat.d.cts +2 -0
  66. package/highlevel/types/peers/full-chat.d.ts +2 -0
  67. package/highlevel/types/peers/full-chat.js +4 -0
  68. package/highlevel/types/peers/index.d.cts +1 -0
  69. package/highlevel/types/peers/index.d.ts +1 -0
  70. package/highlevel/types/peers/peer-settings.cjs +101 -0
  71. package/highlevel/types/peers/peer-settings.d.cts +84 -0
  72. package/highlevel/types/peers/peer-settings.d.ts +84 -0
  73. package/highlevel/types/peers/peer-settings.js +96 -0
  74. package/highlevel/types/peers/user.cjs +4 -0
  75. package/highlevel/types/peers/user.d.cts +2 -0
  76. package/highlevel/types/peers/user.d.ts +2 -0
  77. package/highlevel/types/peers/user.js +4 -0
  78. package/highlevel/types/premium/saved-star-gift.cjs +4 -1
  79. package/highlevel/types/premium/saved-star-gift.d.cts +2 -3
  80. package/highlevel/types/premium/saved-star-gift.d.ts +2 -3
  81. package/highlevel/types/premium/saved-star-gift.js +5 -2
  82. package/highlevel/types/premium/stars-transaction.cjs +14 -0
  83. package/highlevel/types/premium/stars-transaction.d.cts +14 -0
  84. package/highlevel/types/premium/stars-transaction.d.ts +14 -0
  85. package/highlevel/types/premium/stars-transaction.js +14 -0
  86. package/highlevel/types/stories/story-viewer.cjs +1 -1
  87. package/highlevel/types/stories/story-viewer.js +1 -1
  88. package/highlevel/types/updates/history-read-update.cjs +1 -0
  89. package/highlevel/types/updates/history-read-update.js +1 -0
  90. package/highlevel/updates/manager.js +2 -2
  91. package/highlevel/utils/file-utils.js +1 -1
  92. package/highlevel/utils/inline-utils.cjs +5 -5
  93. package/highlevel/utils/inline-utils.js +1 -1
  94. package/highlevel/worker/storage.cjs +2 -0
  95. package/highlevel/worker/storage.d.cts +1 -0
  96. package/highlevel/worker/storage.d.ts +1 -0
  97. package/highlevel/worker/storage.js +2 -0
  98. package/index.cjs +3 -1
  99. package/index.js +5 -3
  100. package/methods.cjs +6 -4
  101. package/methods.js +6 -4
  102. package/network/authorization.js +2 -2
  103. package/network/network-manager.cjs +1 -1
  104. package/network/network-manager.js +1 -1
  105. package/network/persistent-connection.cjs +6 -4
  106. package/network/persistent-connection.js +6 -4
  107. package/network/session-connection.cjs +14 -7
  108. package/network/session-connection.d.cts +1 -1
  109. package/network/session-connection.d.ts +1 -1
  110. package/network/session-connection.js +15 -8
  111. package/package.json +4 -4
  112. package/storage/memory/repository/peers.cjs +2 -2
  113. package/storage/memory/repository/peers.d.cts +1 -1
  114. package/storage/memory/repository/peers.d.ts +1 -1
  115. package/storage/memory/repository/peers.js +2 -2
  116. package/storage/sqlite/repository/peers.cjs +3 -5
  117. package/storage/sqlite/repository/peers.d.cts +1 -2
  118. package/storage/sqlite/repository/peers.d.ts +1 -2
  119. package/storage/sqlite/repository/peers.js +3 -5
  120. package/utils/binary/asn1-parser.js +1 -1
  121. package/utils/binary/compat.cjs +150 -0
  122. package/utils/binary/compat.d.cts +13 -0
  123. package/utils/binary/compat.d.ts +13 -0
  124. package/utils/binary/compat.js +145 -0
  125. package/utils/binary/compat.test.d.cts +1 -0
  126. package/utils/binary/compat.test.d.ts +1 -0
  127. package/utils/binary/serialization.cjs +59 -0
  128. package/utils/binary/serialization.d.cts +10 -0
  129. package/utils/binary/serialization.d.ts +10 -0
  130. package/utils/binary/serialization.js +54 -0
  131. package/utils/index.d.cts +2 -0
  132. package/utils/index.d.ts +2 -0
  133. package/utils/long-utils.js +1 -1
  134. package/utils/peer-utils.js +1 -1
  135. package/utils.cjs +8 -0
  136. package/utils.js +8 -0
  137. package/highlevel/methods/premium/get-star-gifts.d.cts +0 -23
  138. package/highlevel/methods/premium/get-star-gifts.d.ts +0 -23
  139. package/highlevel/methods/premium/get-star-gifts.js +0 -10
  140. package/highlevel/methods/premium/iter-star-gifts.cjs +0 -29
  141. package/highlevel/methods/premium/iter-star-gifts.d.cts +0 -26
  142. package/highlevel/methods/premium/iter-star-gifts.d.ts +0 -26
  143. package/highlevel/methods/premium/iter-star-gifts.js +0 -24
package/index.js CHANGED
@@ -33,7 +33,7 @@ import { Thumbnail } from "./highlevel/types/media/thumbnail.js";
33
33
  import { Venue } from "./highlevel/types/media/venue.js";
34
34
  import { Video } from "./highlevel/types/media/video.js";
35
35
  import { Voice } from "./highlevel/types/media/voice.js";
36
- import { WebPage } from "./highlevel/types/media/web-page.js";
36
+ import { WebPage, WebPageMedia } from "./highlevel/types/media/web-page.js";
37
37
  import { Dialog } from "./highlevel/types/messages/dialog.js";
38
38
  import { DraftMessage } from "./highlevel/types/messages/draft-message.js";
39
39
  import { FactCheck } from "./highlevel/types/messages/fact-check.js";
@@ -70,6 +70,7 @@ import { ChatlistPreview } from "./highlevel/types/peers/chatlist-preview.js";
70
70
  import { ForumTopic } from "./highlevel/types/peers/forum-topic.js";
71
71
  import { FullChat } from "./highlevel/types/peers/full-chat.js";
72
72
  import { FullUser } from "./highlevel/types/peers/full-user.js";
73
+ import { PeerSettings } from "./highlevel/types/peers/peer-settings.js";
73
74
  import { parsePeer } from "./highlevel/types/peers/peer.js";
74
75
  import { PeersIndex } from "./highlevel/types/peers/peers-index.js";
75
76
  import { User } from "./highlevel/types/peers/user.js";
@@ -82,7 +83,7 @@ import { BusinessConnection } from "./highlevel/types/premium/business-connectio
82
83
  import { BusinessIntro } from "./highlevel/types/premium/business-intro.js";
83
84
  import { BusinessLocation } from "./highlevel/types/premium/business-location.js";
84
85
  import { BusinessWorkHours, businessWorkHoursDaysToRaw } from "./highlevel/types/premium/business-work-hours.js";
85
- import { SavedStarGift, UserStarGift } from "./highlevel/types/premium/saved-star-gift.js";
86
+ import { SavedStarGift } from "./highlevel/types/premium/saved-star-gift.js";
86
87
  import { StarGiftUnique, StarGiftUniqueAttribute, StarGiftUniqueBackdrop, StarGiftUniqueOriginalDetails } from "./highlevel/types/premium/stars-gift-unique.js";
87
88
  import { StarGift } from "./highlevel/types/premium/stars-gift.js";
88
89
  import { StarsStatus } from "./highlevel/types/premium/stars-status.js";
@@ -242,6 +243,7 @@ export {
242
243
  PaidMedia,
243
244
  PaidPeerReaction,
244
245
  PeerReaction,
246
+ PeerSettings,
245
247
  PeerStories,
246
248
  PeersIndex,
247
249
  Photo,
@@ -291,7 +293,6 @@ export {
291
293
  TransportError,
292
294
  UpdatesManager,
293
295
  User,
294
- UserStarGift,
295
296
  UserStatusUpdate,
296
297
  UserTypingUpdate,
297
298
  Venue,
@@ -299,6 +300,7 @@ export {
299
300
  Voice,
300
301
  WebDocument,
301
302
  WebPage,
303
+ WebPageMedia,
302
304
  WebviewResult,
303
305
  _actionFromTl,
304
306
  _messageActionFromTl,
package/methods.cjs CHANGED
@@ -148,6 +148,7 @@ const getMessages = require("./highlevel/methods/messages/get-messages.cjs");
148
148
  const getReactionUsers = require("./highlevel/methods/messages/get-reaction-users.cjs");
149
149
  const getReplyTo = require("./highlevel/methods/messages/get-reply-to.cjs");
150
150
  const getScheduledMessages = require("./highlevel/methods/messages/get-scheduled-messages.cjs");
151
+ const getWebPagePreview = require("./highlevel/methods/messages/get-web-page-preview.cjs");
151
152
  const iterHistory = require("./highlevel/methods/messages/iter-history.cjs");
152
153
  const iterReactionUsers = require("./highlevel/methods/messages/iter-reaction-users.cjs");
153
154
  const iterSearchGlobal = require("./highlevel/methods/messages/iter-search-global.cjs");
@@ -199,13 +200,12 @@ const getSavedStarGiftsById = require("./highlevel/methods/premium/get-saved-sta
199
200
  const getSavedStarGifts = require("./highlevel/methods/premium/get-saved-star-gifts.cjs");
200
201
  const getStarGiftOptions = require("./highlevel/methods/premium/get-star-gift-options.cjs");
201
202
  const getStarGiftWithdrawalUrl = require("./highlevel/methods/premium/get-star-gift-withdrawal-url.cjs");
202
- const getStarGifts = require("./highlevel/methods/premium/get-star-gifts.cjs");
203
203
  const getStarsTransactions = require("./highlevel/methods/premium/get-stars-transactions.cjs");
204
204
  const getUniqueStarGift = require("./highlevel/methods/premium/get-unique-star-gift.cjs");
205
205
  const iterBoosters = require("./highlevel/methods/premium/iter-boosters.cjs");
206
206
  const iterSavedStarGifts = require("./highlevel/methods/premium/iter-saved-star-gifts.cjs");
207
- const iterStarGifts = require("./highlevel/methods/premium/iter-star-gifts.cjs");
208
207
  const iterStarsTransactions = require("./highlevel/methods/premium/iter-stars-transactions.cjs");
208
+ const pinStarGift = require("./highlevel/methods/premium/pin-star-gift.cjs");
209
209
  const sendStarGift = require("./highlevel/methods/premium/send-star-gift.cjs");
210
210
  const setBusinessIntro = require("./highlevel/methods/premium/set-business-intro.cjs");
211
211
  const setBusinessWorkHours = require("./highlevel/methods/premium/set-business-work-hours.cjs");
@@ -249,6 +249,7 @@ const getCommonChats = require("./highlevel/methods/users/get-common-chats.cjs")
249
249
  const getGlobalTtl = require("./highlevel/methods/users/get-global-ttl.cjs");
250
250
  const getMe = require("./highlevel/methods/users/get-me.cjs");
251
251
  const getMyUsername = require("./highlevel/methods/users/get-my-username.cjs");
252
+ const getPeerSettings = require("./highlevel/methods/users/get-peer-settings.cjs");
252
253
  const getProfilePhoto = require("./highlevel/methods/users/get-profile-photo.cjs");
253
254
  const getProfilePhotos = require("./highlevel/methods/users/get-profile-photos.cjs");
254
255
  const getUsers = require("./highlevel/methods/users/get-users.cjs");
@@ -414,6 +415,7 @@ exports.getMessages = getMessages.getMessages;
414
415
  exports.getReactionUsers = getReactionUsers.getReactionUsers;
415
416
  exports.getReplyTo = getReplyTo.getReplyTo;
416
417
  exports.getScheduledMessages = getScheduledMessages.getScheduledMessages;
418
+ exports.getWebPagePreview = getWebPagePreview.getWebPagePreview;
417
419
  exports.iterHistory = iterHistory.iterHistory;
418
420
  exports.iterReactionUsers = iterReactionUsers.iterReactionUsers;
419
421
  exports.iterSearchGlobal = iterSearchGlobal.iterSearchGlobal;
@@ -477,13 +479,12 @@ exports.getSavedStarGiftsById = getSavedStarGiftsById.getSavedStarGiftsById;
477
479
  exports.getSavedStarGifts = getSavedStarGifts.getSavedStarGifts;
478
480
  exports.getStarGiftOptions = getStarGiftOptions.getStarGiftOptions;
479
481
  exports.getStarGiftWithdrawalUrl = getStarGiftWithdrawalUrl.getStarGiftWithdrawalUrl;
480
- exports.getStarGifts = getStarGifts.getStarGifts;
481
482
  exports.getStarsTransactions = getStarsTransactions.getStarsTransactions;
482
483
  exports.getUniqueStarGift = getUniqueStarGift.getUniqueStarGift;
483
484
  exports.iterBoosters = iterBoosters.iterBoosters;
484
485
  exports.iterSavedStarGifts = iterSavedStarGifts.iterSavedStarGifts;
485
- exports.iterStarGifts = iterStarGifts.iterStarGifts;
486
486
  exports.iterStarsTransactions = iterStarsTransactions.iterStarsTransactions;
487
+ exports.togglePinnedStarGifts = pinStarGift.togglePinnedStarGifts;
487
488
  exports.sendStarGift = sendStarGift.sendStarGift;
488
489
  exports.setBusinessIntro = setBusinessIntro.setBusinessIntro;
489
490
  exports.setBusinessWorkHours = setBusinessWorkHours.setBusinessWorkHours;
@@ -529,6 +530,7 @@ exports.getCommonChats = getCommonChats.getCommonChats;
529
530
  exports.getGlobalTtl = getGlobalTtl.getGlobalTtl;
530
531
  exports.getMe = getMe.getMe;
531
532
  exports.getMyUsername = getMyUsername.getMyUsername;
533
+ exports.getPeerSettings = getPeerSettings.getPeerSettings;
532
534
  exports.getProfilePhoto = getProfilePhoto.getProfilePhoto;
533
535
  exports.getProfilePhotos = getProfilePhotos.getProfilePhotos;
534
536
  exports.getUsers = getUsers.getUsers;
package/methods.js CHANGED
@@ -141,6 +141,7 @@ import { getMessages } from "./highlevel/methods/messages/get-messages.js";
141
141
  import { getReactionUsers } from "./highlevel/methods/messages/get-reaction-users.js";
142
142
  import { getReplyTo } from "./highlevel/methods/messages/get-reply-to.js";
143
143
  import { getScheduledMessages } from "./highlevel/methods/messages/get-scheduled-messages.js";
144
+ import { getWebPagePreview } from "./highlevel/methods/messages/get-web-page-preview.js";
144
145
  import { iterHistory } from "./highlevel/methods/messages/iter-history.js";
145
146
  import { iterReactionUsers } from "./highlevel/methods/messages/iter-reaction-users.js";
146
147
  import { iterSearchGlobal } from "./highlevel/methods/messages/iter-search-global.js";
@@ -192,13 +193,12 @@ import { getSavedStarGiftsById } from "./highlevel/methods/premium/get-saved-sta
192
193
  import { getSavedStarGifts } from "./highlevel/methods/premium/get-saved-star-gifts.js";
193
194
  import { getStarGiftOptions } from "./highlevel/methods/premium/get-star-gift-options.js";
194
195
  import { getStarGiftWithdrawalUrl } from "./highlevel/methods/premium/get-star-gift-withdrawal-url.js";
195
- import { getStarGifts } from "./highlevel/methods/premium/get-star-gifts.js";
196
196
  import { getStarsTransactions } from "./highlevel/methods/premium/get-stars-transactions.js";
197
197
  import { getUniqueStarGift } from "./highlevel/methods/premium/get-unique-star-gift.js";
198
198
  import { iterBoosters } from "./highlevel/methods/premium/iter-boosters.js";
199
199
  import { iterSavedStarGifts } from "./highlevel/methods/premium/iter-saved-star-gifts.js";
200
- import { iterStarGifts } from "./highlevel/methods/premium/iter-star-gifts.js";
201
200
  import { iterStarsTransactions } from "./highlevel/methods/premium/iter-stars-transactions.js";
201
+ import { togglePinnedStarGifts } from "./highlevel/methods/premium/pin-star-gift.js";
202
202
  import { sendStarGift } from "./highlevel/methods/premium/send-star-gift.js";
203
203
  import { setBusinessIntro } from "./highlevel/methods/premium/set-business-intro.js";
204
204
  import { setBusinessWorkHours } from "./highlevel/methods/premium/set-business-work-hours.js";
@@ -242,6 +242,7 @@ import { getCommonChats } from "./highlevel/methods/users/get-common-chats.js";
242
242
  import { getGlobalTtl } from "./highlevel/methods/users/get-global-ttl.js";
243
243
  import { getMe } from "./highlevel/methods/users/get-me.js";
244
244
  import { getMyUsername } from "./highlevel/methods/users/get-my-username.js";
245
+ import { getPeerSettings } from "./highlevel/methods/users/get-peer-settings.js";
245
246
  import { getProfilePhoto } from "./highlevel/methods/users/get-profile-photo.js";
246
247
  import { getProfilePhotos } from "./highlevel/methods/users/get-profile-photos.js";
247
248
  import { getUsers } from "./highlevel/methods/users/get-users.js";
@@ -382,6 +383,7 @@ export {
382
383
  getPasswordHint,
383
384
  getPeer,
384
385
  getPeerDialogs,
386
+ getPeerSettings,
385
387
  getPeerStories,
386
388
  getPrimaryInviteLink,
387
389
  getProfilePhoto,
@@ -395,7 +397,6 @@ export {
395
397
  getSimilarChannels,
396
398
  getStarGiftOptions,
397
399
  getStarGiftWithdrawalUrl,
398
- getStarGifts,
399
400
  getStarsTransactions,
400
401
  getStickerSet,
401
402
  getStoriesById,
@@ -405,6 +406,7 @@ export {
405
406
  getUniqueStarGift,
406
407
  getUser,
407
408
  getUsers,
409
+ getWebPagePreview,
408
410
  hideAllJoinRequests,
409
411
  hideJoinRequest,
410
412
  hideMyStoriesViews,
@@ -429,7 +431,6 @@ export {
429
431
  iterSearchGlobal,
430
432
  iterSearchHashtag,
431
433
  iterSearchMessages,
432
- iterStarGifts,
433
434
  iterStarsTransactions,
434
435
  iterStoryViewers,
435
436
  joinChat,
@@ -528,6 +529,7 @@ export {
528
529
  toggleJoinRequests,
529
530
  toggleJoinToSend,
530
531
  togglePeerStoriesArchived,
532
+ togglePinnedStarGifts,
531
533
  toggleStoriesPinned,
532
534
  transferStarGift,
533
535
  translateMessage,
@@ -1,12 +1,12 @@
1
1
  import { typed, bigint, u8 } from "@fuman/utils";
2
2
  import { mtp } from "@mtcute/tl";
3
- import { TlSerializationCounter, TlBinaryWriter, TlBinaryReader } from "@mtcute/tl-runtime";
3
+ import { TlBinaryWriter, TlBinaryReader, TlSerializationCounter } from "@mtcute/tl-runtime";
4
4
  import Long from "long";
5
5
  import { findKeyByFingerprints } from "../utils/crypto/keys.js";
6
6
  import { millerRabin } from "../utils/crypto/miller-rabin.js";
7
7
  import { generateKeyAndIvFromNonce } from "../utils/crypto/mtproto.js";
8
8
  import { mtpAssertTypeIs } from "../utils/type-assertions.js";
9
- import { MtSecurityError, MtArgumentError, MtTypeAssertionError } from "../types/errors.js";
9
+ import { MtSecurityError, MtTypeAssertionError, MtArgumentError } from "../types/errors.js";
10
10
  const DH_SAFETY_RANGE = 2n ** (2048n - 64n);
11
11
  const KNOWN_DH_PRIME = 0xC71CAEB9C6B1C9048E6C522F70F13F73980D40238E3E21C14934D037563D930F48198A0AA7C14058229493D22530F4DBFA336F6E0AC925139543AED44CCE7C3720FD51F69458705AC68CD4FE6B6B13ABDC9746512969328454F18FAF8C595F642477FE96BB2A941D5BCD1D4AC8CC49880708FA9B378E3C4F3A9060BEE67CF9A4A4A695811051907E162753B56B0F6B410DBA74D8A84B2A14B3144E0EF1284754FD17ED950D5965B4B9DD46582DB1178D169C6BC465B0D6FF9CA3928FEF5B9AE4E418FC15E83EBEA0F87FA9FF5EED70050DED2849F47BF959D956850CE929851F0D8115F635B105EE2E4E15D04B2454BF6F4FADF034B10403119CD8E3B92FCC5Bn;
12
12
  const TWO_POW_2047 = 2n ** 2047n;
@@ -220,7 +220,7 @@ class NetworkManager {
220
220
  _: "initConnection",
221
221
  deviceModel,
222
222
  systemVersion: "1.0",
223
- appVersion: "0.21.1",
223
+ appVersion: "0.22.2",
224
224
  systemLangCode: "en",
225
225
  langPack: "",
226
226
  // "langPacks are for official apps only"
@@ -213,7 +213,7 @@ class NetworkManager {
213
213
  _: "initConnection",
214
214
  deviceModel,
215
215
  systemVersion: "1.0",
216
- appVersion: "0.21.1",
216
+ appVersion: "0.22.2",
217
217
  systemLangCode: "en",
218
218
  langPack: "",
219
219
  // "langPacks are for official apps only"
@@ -172,10 +172,12 @@ class PersistentConnection {
172
172
  try {
173
173
  await this._writer.write(data);
174
174
  } catch (e) {
175
- this.log.warn("encountered an error while sending, reconnecting: %e", e);
176
- this._writer = void 0;
177
- this._fuman.reconnect(true);
178
- this._sendOnceConnected.push(data);
175
+ if (!(e instanceof net.ConnectionClosedError)) {
176
+ this.log.warn("encountered an error while sending, reconnecting: %e", e);
177
+ this._writer = void 0;
178
+ this._fuman.reconnect(true);
179
+ this._sendOnceConnected.push(data);
180
+ }
179
181
  }
180
182
  } else {
181
183
  this._sendOnceConnected.push(data);
@@ -165,10 +165,12 @@ class PersistentConnection {
165
165
  try {
166
166
  await this._writer.write(data);
167
167
  } catch (e) {
168
- this.log.warn("encountered an error while sending, reconnecting: %e", e);
169
- this._writer = void 0;
170
- this._fuman.reconnect(true);
171
- this._sendOnceConnected.push(data);
168
+ if (!(e instanceof ConnectionClosedError)) {
169
+ this.log.warn("encountered an error while sending, reconnecting: %e", e);
170
+ this._writer = void 0;
171
+ this._fuman.reconnect(true);
172
+ this._sendOnceConnected.push(data);
173
+ }
172
174
  }
173
175
  } else {
174
176
  this._sendOnceConnected.push(data);
@@ -88,7 +88,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
88
88
  this._session._authKeyTemp.reset();
89
89
  utils.timers.clearTimeout(this._pfsUpdateTimeout);
90
90
  }
91
- this._resetSession();
91
+ this._resetSession("use pfs changed");
92
92
  }
93
93
  onClosed() {
94
94
  Object.values(this._pendingWaitForUnencrypted).forEach(([prom, timeout]) => {
@@ -168,13 +168,13 @@ class SessionConnection extends persistentConnection.PersistentConnection {
168
168
  if (!this._triedReconnectingOn404) {
169
169
  this.log.warn("transport error 404. trying to reconnect");
170
170
  this._triedReconnectingOn404 = true;
171
- this._resetSession();
171
+ this._resetSession("-404 reconnect");
172
172
  return;
173
173
  }
174
174
  this.log.warn("transport error 404, reauthorizing");
175
175
  this.onError.emit(error);
176
176
  this._session.resetAuthKey();
177
- this._resetSession();
177
+ this._resetSession("-404 reconnect + reauth");
178
178
  this.onKeyChange.emit(null);
179
179
  return;
180
180
  }
@@ -370,6 +370,11 @@ class SessionConnection extends persistentConnection.PersistentConnection {
370
370
  try {
371
371
  this._session.decryptMessage(data, this._handleRawMessage);
372
372
  } catch (err) {
373
+ if (err instanceof tlRuntime.TlUnknownObjectError) {
374
+ this.log.warn("received unknown object %s, reconnecting...", err.objectId.toString(16));
375
+ this._resetSession("unknown object");
376
+ return;
377
+ }
373
378
  this.log.error("failed to decrypt message: %s\ndata: %h", err, data);
374
379
  }
375
380
  }
@@ -655,6 +660,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
655
660
  case "bind":
656
661
  case "cancel":
657
662
  break;
663
+ // do nothing, wait for the result
658
664
  default:
659
665
  if (!inContainer) {
660
666
  this.log.warn("received unexpected ack for %s query %l", msg._, msgId);
@@ -788,7 +794,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
788
794
  msg.badMsgId,
789
795
  msg.errorCode
790
796
  );
791
- this._resetSession();
797
+ this._resetSession("bad_msg_notification");
792
798
  break;
793
799
  }
794
800
  }
@@ -847,6 +853,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
847
853
  );
848
854
  return this._onMessageFailed(msgId, "message info state = 0, ans_id = 0");
849
855
  }
856
+ // fallthrough
850
857
  case 4:
851
858
  this._onMessageAcked(msgId);
852
859
  break;
@@ -916,10 +923,10 @@ class SessionConnection extends persistentConnection.PersistentConnection {
916
923
  this._flushTimer.emitWhenIdle();
917
924
  }
918
925
  }
919
- _resetSession() {
926
+ _resetSession(reason = "session reset") {
920
927
  this._queuedDestroySession.push(this._session._sessionId);
921
928
  this._session.resetState(true);
922
- this._onAllFailed("session reset");
929
+ this._onAllFailed(reason);
923
930
  this.reconnect();
924
931
  this._flushTimer.reset();
925
932
  }
@@ -1144,7 +1151,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
1144
1151
  if (now - this._session.lastPingTime > this._pingInterval) {
1145
1152
  if (!this._session.lastPingMsgId.isZero()) {
1146
1153
  this.log.warn("didn't receive pong for previous ping (msg_id = %l). are we offline?", this._session.lastPingMsgId);
1147
- this._resetSession();
1154
+ this._resetSession("ping timeout");
1148
1155
  return;
1149
1156
  }
1150
1157
  pingId = longUtils.randomLong();
@@ -82,7 +82,7 @@ export declare class SessionConnection extends PersistentConnection {
82
82
  private _onFutureSalts;
83
83
  private _onDestroySessionResult;
84
84
  private _enqueueRpc;
85
- _resetSession(): void;
85
+ _resetSession(reason?: string): void;
86
86
  private _sendAck;
87
87
  sendRpc<T extends tl.RpcMethod>(request: T, timeout?: number, abortSignal?: AbortSignal, chainId?: string | number): Promise<tl.RpcCallReturn[T['_']]>;
88
88
  notifyNetworkChanged(online: boolean): void;
@@ -82,7 +82,7 @@ export declare class SessionConnection extends PersistentConnection {
82
82
  private _onFutureSalts;
83
83
  private _onDestroySessionResult;
84
84
  private _enqueueRpc;
85
- _resetSession(): void;
85
+ _resetSession(reason?: string): void;
86
86
  private _sendAck;
87
87
  sendRpc<T extends tl.RpcMethod>(request: T, timeout?: number, abortSignal?: AbortSignal, chainId?: string | number): Promise<tl.RpcCallReturn[T['_']]>;
88
88
  notifyNetworkChanged(online: boolean): void;
@@ -1,6 +1,6 @@
1
1
  import { Emitter, timers, u8, Deferred } from "@fuman/utils";
2
2
  import { tl } from "@mtcute/tl";
3
- import { TlBinaryWriter, TlSerializationCounter, TlBinaryReader } from "@mtcute/tl-runtime";
3
+ import { TlBinaryWriter, TlSerializationCounter, TlUnknownObjectError, TlBinaryReader } from "@mtcute/tl-runtime";
4
4
  import Long from "long";
5
5
  import { createAesIgeForMessageOld } from "../utils/crypto/mtproto.js";
6
6
  import { EarlyTimer } from "../utils/early-timer.js";
@@ -81,7 +81,7 @@ class SessionConnection extends PersistentConnection {
81
81
  this._session._authKeyTemp.reset();
82
82
  timers.clearTimeout(this._pfsUpdateTimeout);
83
83
  }
84
- this._resetSession();
84
+ this._resetSession("use pfs changed");
85
85
  }
86
86
  onClosed() {
87
87
  Object.values(this._pendingWaitForUnencrypted).forEach(([prom, timeout]) => {
@@ -161,13 +161,13 @@ class SessionConnection extends PersistentConnection {
161
161
  if (!this._triedReconnectingOn404) {
162
162
  this.log.warn("transport error 404. trying to reconnect");
163
163
  this._triedReconnectingOn404 = true;
164
- this._resetSession();
164
+ this._resetSession("-404 reconnect");
165
165
  return;
166
166
  }
167
167
  this.log.warn("transport error 404, reauthorizing");
168
168
  this.onError.emit(error);
169
169
  this._session.resetAuthKey();
170
- this._resetSession();
170
+ this._resetSession("-404 reconnect + reauth");
171
171
  this.onKeyChange.emit(null);
172
172
  return;
173
173
  }
@@ -363,6 +363,11 @@ class SessionConnection extends PersistentConnection {
363
363
  try {
364
364
  this._session.decryptMessage(data, this._handleRawMessage);
365
365
  } catch (err) {
366
+ if (err instanceof TlUnknownObjectError) {
367
+ this.log.warn("received unknown object %s, reconnecting...", err.objectId.toString(16));
368
+ this._resetSession("unknown object");
369
+ return;
370
+ }
366
371
  this.log.error("failed to decrypt message: %s\ndata: %h", err, data);
367
372
  }
368
373
  }
@@ -648,6 +653,7 @@ class SessionConnection extends PersistentConnection {
648
653
  case "bind":
649
654
  case "cancel":
650
655
  break;
656
+ // do nothing, wait for the result
651
657
  default:
652
658
  if (!inContainer) {
653
659
  this.log.warn("received unexpected ack for %s query %l", msg._, msgId);
@@ -781,7 +787,7 @@ class SessionConnection extends PersistentConnection {
781
787
  msg.badMsgId,
782
788
  msg.errorCode
783
789
  );
784
- this._resetSession();
790
+ this._resetSession("bad_msg_notification");
785
791
  break;
786
792
  }
787
793
  }
@@ -840,6 +846,7 @@ class SessionConnection extends PersistentConnection {
840
846
  );
841
847
  return this._onMessageFailed(msgId, "message info state = 0, ans_id = 0");
842
848
  }
849
+ // fallthrough
843
850
  case 4:
844
851
  this._onMessageAcked(msgId);
845
852
  break;
@@ -909,10 +916,10 @@ class SessionConnection extends PersistentConnection {
909
916
  this._flushTimer.emitWhenIdle();
910
917
  }
911
918
  }
912
- _resetSession() {
919
+ _resetSession(reason = "session reset") {
913
920
  this._queuedDestroySession.push(this._session._sessionId);
914
921
  this._session.resetState(true);
915
- this._onAllFailed("session reset");
922
+ this._onAllFailed(reason);
916
923
  this.reconnect();
917
924
  this._flushTimer.reset();
918
925
  }
@@ -1137,7 +1144,7 @@ class SessionConnection extends PersistentConnection {
1137
1144
  if (now - this._session.lastPingTime > this._pingInterval) {
1138
1145
  if (!this._session.lastPingMsgId.isZero()) {
1139
1146
  this.log.warn("didn't receive pong for previous ping (msg_id = %l). are we offline?", this._session.lastPingMsgId);
1140
- this._resetSession();
1147
+ this._resetSession("ping timeout");
1141
1148
  return;
1142
1149
  }
1143
1150
  pingId = randomLong();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mtcute/core",
3
3
  "type": "module",
4
- "version": "0.21.1",
4
+ "version": "0.22.2",
5
5
  "description": "Type-safe library for MTProto (Telegram API)",
6
6
  "license": "MIT",
7
7
  "scripts": {},
@@ -9,9 +9,9 @@
9
9
  "@fuman/io": "0.0.8",
10
10
  "@fuman/net": "0.0.9",
11
11
  "@fuman/utils": "0.0.4",
12
- "@mtcute/file-id": "^0.19.0",
13
- "@mtcute/tl": "^199.0.0",
14
- "@mtcute/tl-runtime": "^0.19.0",
12
+ "@mtcute/file-id": "^0.22.0",
13
+ "@mtcute/tl": "^200.0.0",
14
+ "@mtcute/tl-runtime": "^0.22.0",
15
15
  "@types/events": "3.0.0",
16
16
  "long": "5.2.3"
17
17
  },
@@ -33,9 +33,9 @@ class MemoryPeersRepository {
33
33
  if (peer.phone) this.state.phoneIndex.set(peer.phone, peer.id);
34
34
  this.state.entities.set(peer.id, peer);
35
35
  }
36
- getById(id, allowMin) {
36
+ getById(id) {
37
37
  const ent = this.state.entities.get(id);
38
- if (!ent || ent.isMin && !allowMin) return null;
38
+ if (!ent) return null;
39
39
  return ent;
40
40
  }
41
41
  getByUsername(username) {
@@ -10,7 +10,7 @@ export declare class MemoryPeersRepository implements IPeersRepository {
10
10
  readonly state: PeersState;
11
11
  constructor(_driver: MemoryStorageDriver);
12
12
  store(peer: IPeersRepository.PeerInfo): void;
13
- getById(id: number, allowMin: boolean): IPeersRepository.PeerInfo | null;
13
+ getById(id: number): IPeersRepository.PeerInfo | null;
14
14
  getByUsername(username: string): IPeersRepository.PeerInfo | null;
15
15
  getByPhone(phone: string): IPeersRepository.PeerInfo | null;
16
16
  deleteAll(): void;
@@ -10,7 +10,7 @@ export declare class MemoryPeersRepository implements IPeersRepository {
10
10
  readonly state: PeersState;
11
11
  constructor(_driver: MemoryStorageDriver);
12
12
  store(peer: IPeersRepository.PeerInfo): void;
13
- getById(id: number, allowMin: boolean): IPeersRepository.PeerInfo | null;
13
+ getById(id: number): IPeersRepository.PeerInfo | null;
14
14
  getByUsername(username: string): IPeersRepository.PeerInfo | null;
15
15
  getByPhone(phone: string): IPeersRepository.PeerInfo | null;
16
16
  deleteAll(): void;
@@ -26,9 +26,9 @@ class MemoryPeersRepository {
26
26
  if (peer.phone) this.state.phoneIndex.set(peer.phone, peer.id);
27
27
  this.state.entities.set(peer.id, peer);
28
28
  }
29
- getById(id, allowMin) {
29
+ getById(id) {
30
30
  const ent = this.state.entities.get(id);
31
- if (!ent || ent.isMin && !allowMin) return null;
31
+ if (!ent) return null;
32
32
  return ent;
33
33
  }
34
34
  getByUsername(username) {
@@ -42,8 +42,7 @@ class SqlitePeersRepository {
42
42
  this._store = db.prepare(
43
43
  "insert or replace into peers (id, hash, isMin, usernames, updated, phone, complete) values (?, ?, ?, ?, ?, ?, ?)"
44
44
  );
45
- this._getById = db.prepare("select * from peers where id = ? and isMin = false");
46
- this._getByIdAllowMin = db.prepare("select * from peers where id = ?");
45
+ this._getById = db.prepare("select * from peers where id = ?");
47
46
  this._getByUsername = db.prepare(
48
47
  "select * from peers where exists (select 1 from json_each(usernames) where value = ?) and isMin = false"
49
48
  );
@@ -73,10 +72,9 @@ class SqlitePeersRepository {
73
72
  ]);
74
73
  }
75
74
  _getById;
76
- _getByIdAllowMin;
77
- getById(id, allowMin) {
75
+ getById(id) {
78
76
  this._ensureLoaded();
79
- const row = (allowMin ? this._getByIdAllowMin : this._getById).get(id);
77
+ const row = this._getById.get(id);
80
78
  if (!row) return null;
81
79
  return mapPeerDto(row);
82
80
  }
@@ -8,8 +8,7 @@ export declare class SqlitePeersRepository implements IPeersRepository {
8
8
  private _store;
9
9
  store(peer: IPeersRepository.PeerInfo): void;
10
10
  private _getById;
11
- private _getByIdAllowMin;
12
- getById(id: number, allowMin: boolean): IPeersRepository.PeerInfo | null;
11
+ getById(id: number): IPeersRepository.PeerInfo | null;
13
12
  private _getByUsername;
14
13
  getByUsername(username: string): IPeersRepository.PeerInfo | null;
15
14
  private _getByPhone;
@@ -8,8 +8,7 @@ export declare class SqlitePeersRepository implements IPeersRepository {
8
8
  private _store;
9
9
  store(peer: IPeersRepository.PeerInfo): void;
10
10
  private _getById;
11
- private _getByIdAllowMin;
12
- getById(id: number, allowMin: boolean): IPeersRepository.PeerInfo | null;
11
+ getById(id: number): IPeersRepository.PeerInfo | null;
13
12
  private _getByUsername;
14
13
  getByUsername(username: string): IPeersRepository.PeerInfo | null;
15
14
  private _getByPhone;
@@ -35,8 +35,7 @@ class SqlitePeersRepository {
35
35
  this._store = db.prepare(
36
36
  "insert or replace into peers (id, hash, isMin, usernames, updated, phone, complete) values (?, ?, ?, ?, ?, ?, ?)"
37
37
  );
38
- this._getById = db.prepare("select * from peers where id = ? and isMin = false");
39
- this._getByIdAllowMin = db.prepare("select * from peers where id = ?");
38
+ this._getById = db.prepare("select * from peers where id = ?");
40
39
  this._getByUsername = db.prepare(
41
40
  "select * from peers where exists (select 1 from json_each(usernames) where value = ?) and isMin = false"
42
41
  );
@@ -66,10 +65,9 @@ class SqlitePeersRepository {
66
65
  ]);
67
66
  }
68
67
  _getById;
69
- _getByIdAllowMin;
70
- getById(id, allowMin) {
68
+ getById(id) {
71
69
  this._ensureLoaded();
72
- const row = (allowMin ? this._getByIdAllowMin : this._getById).get(id);
70
+ const row = this._getById.get(id);
73
71
  if (!row) return null;
74
72
  return mapPeerDto(row);
75
73
  }
@@ -1,4 +1,4 @@
1
- import { hex, base64 } from "@fuman/utils";
1
+ import { base64, hex } from "@fuman/utils";
2
2
  function parsePemContents(pem) {
3
3
  return base64.decode(pem.replace(/^-----(?:BEGIN|END)(?: RSA)? PUBLIC KEY-----$|\n/gm, ""));
4
4
  }