amiudmodz 6.2.2 → 6.2.5

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 (115) hide show
  1. package/lib/Defaults/index.d.ts +8 -0
  2. package/lib/Defaults/index.d.ts.map +1 -1
  3. package/lib/Defaults/index.js +26 -10
  4. package/lib/Defaults/index.js.map +1 -1
  5. package/lib/Signal/lid-mapping.d.ts +3 -3
  6. package/lib/Signal/lid-mapping.d.ts.map +1 -1
  7. package/lib/Signal/lid-mapping.js +21 -14
  8. package/lib/Signal/lid-mapping.js.map +1 -1
  9. package/lib/Socket/business.d.ts +19 -12
  10. package/lib/Socket/business.d.ts.map +1 -1
  11. package/lib/Socket/chats.d.ts +2 -5
  12. package/lib/Socket/chats.d.ts.map +1 -1
  13. package/lib/Socket/chats.js +29 -11
  14. package/lib/Socket/chats.js.map +1 -1
  15. package/lib/Socket/communities.d.ts +19 -12
  16. package/lib/Socket/communities.d.ts.map +1 -1
  17. package/lib/Socket/groups.d.ts +1 -4
  18. package/lib/Socket/groups.d.ts.map +1 -1
  19. package/lib/Socket/index.d.ts +2 -277
  20. package/lib/Socket/index.d.ts.map +1 -1
  21. package/lib/Socket/index.js +30 -1
  22. package/lib/Socket/index.js.map +1 -1
  23. package/lib/Socket/messages-recv.d.ts +19 -12
  24. package/lib/Socket/messages-recv.d.ts.map +1 -1
  25. package/lib/Socket/messages-recv.js +117 -28
  26. package/lib/Socket/messages-recv.js.map +1 -1
  27. package/lib/Socket/messages-send.d.ts +18 -11
  28. package/lib/Socket/messages-send.d.ts.map +1 -1
  29. package/lib/Socket/messages-send.js +362 -250
  30. package/lib/Socket/messages-send.js.map +1 -1
  31. package/lib/Socket/mex.d.ts +1 -1
  32. package/lib/Socket/mex.d.ts.map +1 -1
  33. package/lib/Socket/mex.js +4 -4
  34. package/lib/Socket/mex.js.map +1 -1
  35. package/lib/Socket/newsletter.d.ts +6 -7
  36. package/lib/Socket/newsletter.d.ts.map +1 -1
  37. package/lib/Socket/newsletter.js +74 -26
  38. package/lib/Socket/newsletter.js.map +1 -1
  39. package/lib/Socket/socket.d.ts.map +1 -1
  40. package/lib/Socket/socket.js +7 -26
  41. package/lib/Socket/socket.js.map +1 -1
  42. package/lib/Types/Auth.d.ts +10 -0
  43. package/lib/Types/Auth.d.ts.map +1 -1
  44. package/lib/Types/Events.d.ts +2 -1
  45. package/lib/Types/Events.d.ts.map +1 -1
  46. package/lib/Types/Message.d.ts +59 -10
  47. package/lib/Types/Message.d.ts.map +1 -1
  48. package/lib/Types/Message.js +6 -0
  49. package/lib/Types/Message.js.map +1 -1
  50. package/lib/Types/Mex.d.ts +2 -0
  51. package/lib/Types/Mex.d.ts.map +1 -1
  52. package/lib/Types/Mex.js +2 -0
  53. package/lib/Types/Mex.js.map +1 -1
  54. package/lib/Types/Socket.d.ts +18 -0
  55. package/lib/Types/Socket.d.ts.map +1 -1
  56. package/lib/Types/State.d.ts +10 -0
  57. package/lib/Types/State.d.ts.map +1 -1
  58. package/lib/Types/State.js.map +1 -1
  59. package/lib/Types/index.d.ts +1 -1
  60. package/lib/Types/index.d.ts.map +1 -1
  61. package/lib/Types/index.js +1 -0
  62. package/lib/Types/index.js.map +1 -1
  63. package/lib/Utils/MessageBuilder.d.ts +11 -10
  64. package/lib/Utils/MessageBuilder.d.ts.map +1 -1
  65. package/lib/Utils/MessageBuilder.js +14 -3
  66. package/lib/Utils/MessageBuilder.js.map +1 -1
  67. package/lib/Utils/auth-utils.d.ts.map +1 -1
  68. package/lib/Utils/auth-utils.js +23 -8
  69. package/lib/Utils/auth-utils.js.map +1 -1
  70. package/lib/Utils/browser-utils.js +4 -4
  71. package/lib/Utils/browser-utils.js.map +1 -1
  72. package/lib/Utils/decode-wa-message.d.ts.map +1 -1
  73. package/lib/Utils/decode-wa-message.js +9 -5
  74. package/lib/Utils/decode-wa-message.js.map +1 -1
  75. package/lib/Utils/generics.d.ts.map +1 -1
  76. package/lib/Utils/generics.js +8 -5
  77. package/lib/Utils/generics.js.map +1 -1
  78. package/lib/Utils/index.d.ts +6 -1
  79. package/lib/Utils/index.d.ts.map +1 -1
  80. package/lib/Utils/index.js +6 -1
  81. package/lib/Utils/index.js.map +1 -1
  82. package/lib/Utils/messages-media.d.ts +12 -18
  83. package/lib/Utils/messages-media.d.ts.map +1 -1
  84. package/lib/Utils/messages-media.js +163 -65
  85. package/lib/Utils/messages-media.js.map +1 -1
  86. package/lib/Utils/messages.d.ts +26 -71
  87. package/lib/Utils/messages.d.ts.map +1 -1
  88. package/lib/Utils/messages.js +1198 -328
  89. package/lib/Utils/messages.js.map +1 -1
  90. package/lib/Utils/tc-token-utils.d.ts.map +1 -1
  91. package/lib/Utils/tc-token-utils.js +2 -3
  92. package/lib/Utils/tc-token-utils.js.map +1 -1
  93. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -1
  94. package/lib/Utils/use-multi-file-auth-state.js +30 -1
  95. package/lib/Utils/use-multi-file-auth-state.js.map +1 -1
  96. package/lib/Utils/use-sqlite-auth-state.js +12 -12
  97. package/lib/Utils/validate-connection.d.ts.map +1 -1
  98. package/lib/Utils/validate-connection.js +5 -11
  99. package/lib/Utils/validate-connection.js.map +1 -1
  100. package/lib/WABinary/constants.d.ts +8 -0
  101. package/lib/WABinary/constants.d.ts.map +1 -1
  102. package/lib/WABinary/constants.js +72 -0
  103. package/lib/WABinary/constants.js.map +1 -1
  104. package/lib/WABinary/generic-utils.d.ts +1 -0
  105. package/lib/WABinary/generic-utils.d.ts.map +1 -1
  106. package/lib/WABinary/generic-utils.js +100 -1
  107. package/lib/WABinary/generic-utils.js.map +1 -1
  108. package/lib/WABinary/jid-utils.d.ts.map +1 -1
  109. package/lib/WABinary/jid-utils.js +45 -6
  110. package/lib/WABinary/jid-utils.js.map +1 -1
  111. package/lib/index.d.ts +1 -0
  112. package/lib/index.d.ts.map +1 -1
  113. package/lib/index.js +1 -0
  114. package/lib/index.js.map +1 -1
  115. package/package.json +1 -1
@@ -1,12 +1,41 @@
1
1
  import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
2
2
  import { makeCommunitiesSocket } from './communities.js';
3
+ import { wrapSocket } from 'baileys-antiban';
3
4
  // export the last socket layer
4
5
  const makeWASocket = (config) => {
5
6
  const newConfig = {
6
7
  ...DEFAULT_CONNECTION_CONFIG,
7
8
  ...config
8
9
  };
9
- return makeCommunitiesSocket(newConfig);
10
+ const sock = makeCommunitiesSocket(newConfig);
11
+ // Lazy initialization & helpers for VoIP Voice & Video Calling
12
+ let voipClient = null;
13
+ const getVoipClient = async () => {
14
+ if (!voipClient) {
15
+ // @ts-ignore
16
+ const { VoipClient } = await import('../../VoIP/index.js');
17
+ voipClient = new VoipClient(newConfig);
18
+ await voipClient.connectWithSocket(sock);
19
+ }
20
+ return voipClient;
21
+ };
22
+ const call = async (number, opts = {}) => {
23
+ const client = await getVoipClient();
24
+ return client.call(number, opts);
25
+ };
26
+ call.voice = async (number, opts = {}) => {
27
+ return call(number, { ...opts, type: 'voice', isVideo: false });
28
+ };
29
+ call.video = async (number, opts = {}) => {
30
+ return call(number, { ...opts, type: 'video', isVideo: true });
31
+ };
32
+ call.getVoipClient = getVoipClient;
33
+ const extendedSock = Object.assign(sock, { call });
34
+ if (config.antiban !== false) {
35
+ const antibanConfig = typeof config.antiban === 'object' ? config.antiban : undefined;
36
+ return wrapSocket(extendedSock, antibanConfig);
37
+ }
38
+ return extendedSock;
10
39
  };
11
40
  export default makeWASocket;
12
41
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Socket/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAErD,+BAA+B;AAC/B,MAAM,YAAY,GAAG,CAAC,MAA8B,EAAE,EAAE;IACvD,MAAM,SAAS,GAAG;QACjB,GAAG,yBAAyB;Q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M,EAAE,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAA;IAChE,CAAC,CAAA;IAED,IAAI,CAAC,KAAK,GAAG,KAAK,EAAE,MAAc,EAAE,OAAsD,EAAE,EAAE,EAAE;QAC/F,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;IAC/D,CAAC,CAAA;IAED,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IAElC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IAElD,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;QAC9B,MAAM,aAAa,GAAG,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAA;QACrF,OAAO,UAAU,CAAC,YAAmB,EAAE,aAAa,CAAQ,CAAA;IAC7D,CAAC;IAED,OAAO,YAAY,CAAA;AACpB,CAAC,CAAA;AAED,eAAe,YAAY,CAAA"}
@@ -6,7 +6,7 @@ import type { MessageReceiptType, MessageRelayOptions, NewChatMessageCapInfo, So
6
6
  import { type BinaryNode, type JidWithDevice } from '../WABinary/index.js';
7
7
  export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
8
8
  sendMessageAck: (node: BinaryNode, errorCode?: number) => Promise<void>;
9
- sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
9
+ sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean, decryptionError?: string) => Promise<void>;
10
10
  rejectCall: (callId: string, callFrom: string) => Promise<void>;
11
11
  fetchMessageHistory: (count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
12
12
  requestPlaceholderResend: (messageKey: WAMessageKey, msgData?: Partial<WAMessage>) => Promise<string | undefined>;
@@ -17,7 +17,9 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
17
17
  };
18
18
  issuePrivacyTokens: (jids: string[], timestamp?: number) => Promise<any>;
19
19
  assertSessions: (jids: string[], force?: boolean) => Promise<boolean>;
20
- relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
20
+ relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList, addBizAttributes }: MessageRelayOptions & {
21
+ addBizAttributes?: boolean;
22
+ }) => Promise<string>;
21
23
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
22
24
  sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
23
25
  readMessages: (keys: WAMessageKey[]) => Promise<void>;
@@ -37,12 +39,8 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
37
39
  })[]>;
38
40
  updateMemberLabel: (jid: string, memberLabel: string) => Promise<string>;
39
41
  updateMediaMessage: (message: WAMessage) => Promise<WAMessage>;
40
- sendMessage: (jid: string, content: import("../Types/index.js").AnyMessageContent, options?: import("../Types/index.js").MiscMessageGenerationOptions) => Promise<WAMessage | undefined>;
41
- sendChStatus: (jid: string, content: import("../Types/index.js").AnyMessageContent, options?: import("../Types/index.js").MiscMessageGenerationOptions) => Promise<WAMessage>;
42
- sendGroupStatus: (groupJid: string, content: import("../Types/index.js").AnyMessageContent, options?: MessageRelayOptions) => Promise<any>;
43
- sendChannelStatus: (channelJid: string, content: import("../Types/index.js").AnyMessageContent, options?: MessageRelayOptions) => Promise<any>;
44
42
  menurich: (jid: string, options: {
45
- title?: string;
43
+ title: string;
46
44
  subtitle?: string;
47
45
  imageUrl?: string;
48
46
  menus?: {
@@ -58,11 +56,23 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
58
56
  url: string;
59
57
  }[];
60
58
  }) => Promise<string>;
59
+ sendHtmlGame: (jid: string, htmlPayload: string, options?: {
60
+ title?: string;
61
+ subtitle?: string;
62
+ trustedSources?: string[];
63
+ responseId?: string;
64
+ botResponseId?: string;
65
+ botJid?: string;
66
+ signature?: string;
67
+ certificateChain?: string[];
68
+ }) => Promise<string>;
69
+ sendMessage: (jid: string, content: import("../Types/index.js").AnyMessageContent, options?: import("../Types/index.js").MiscMessageGenerationOptions) => Promise<WAMessage | undefined>;
61
70
  newsletterCreate: (name: string, description?: string) => Promise<import("../Types/index.js").NewsletterMetadata>;
62
71
  newsletterUpdate: (jid: string, updates: import("../Types/index.js").NewsletterUpdate) => Promise<unknown>;
63
72
  newsletterSubscribers: (jid: string) => Promise<{
64
73
  subscribers: number;
65
74
  }>;
75
+ newsletterSubscribed: () => Promise<unknown>;
66
76
  newsletterMetadata: (type: "invite" | "jid", key: string) => Promise<import("../Types/index.js").NewsletterMetadata | null>;
67
77
  newsletterFollow: (jid: string) => Promise<unknown>;
68
78
  newsletterUnfollow: (jid: string) => Promise<unknown>;
@@ -73,7 +83,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
73
83
  newsletterUpdatePicture: (jid: string, content: import("../Types/index.js").WAMediaUpload) => Promise<unknown>;
74
84
  newsletterRemovePicture: (jid: string) => Promise<unknown>;
75
85
  newsletterReactMessage: (jid: string, serverId: string, reaction?: string) => Promise<void>;
76
- newsletterFetchMessages: (jid: string, count: number, since: number, after: number) => Promise<any>;
86
+ newsletterFetchMessages: (type: "jid" | "key", key: string, count: number, after?: number, before?: number) => Promise<proto.IWebMessageInfo[]>;
77
87
  subscribeNewsletterUpdates: (jid: string) => Promise<{
78
88
  duration: string;
79
89
  } | null>;
@@ -164,16 +174,13 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
164
174
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
165
175
  addOrEditContact: (jid: string, contact: proto.SyncActionValue.IContactAction) => Promise<void>;
166
176
  removeContact: (jid: string) => Promise<void>;
177
+ saveContact: (name: string, phoneNumber: string) => Promise<void>;
167
178
  placeholderResendCache: import("../Types/index.js").CacheStore;
168
179
  addLabel: (jid: string, labels: import("../Types/Label.js").LabelActionBody) => Promise<void>;
169
180
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
170
181
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
171
182
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
172
183
  removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
173
- star: (jid: string, messages: {
174
- id: string;
175
- fromMe?: boolean;
176
- }[], star: boolean) => Promise<void>;
177
184
  addOrEditQuickReply: (quickReply: import("../Types/Bussines.js").QuickReplyAction) => Promise<void>;
178
185
  removeQuickReply: (timestamp: string) => Promise<void>;
179
186
  type: "md";
@@ -1 +1 @@
1
- {"version":3,"file":"messages-recv.d.ts","sourceRoot":"","sources":["../../src/Socket/messages-recv.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEjC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAQ9C,OAAO,KAAK,EAEX,kBAAkB,EAClB,mBAAmB,EAEnB,qBAAqB,EACrB,YAAY,EAEZ,SAAS,EACT,YAAY,EAEZ,MAAM,UAAU,CAAA;AA4CjB,OAAO,EAEN,KAAK,UAAU,EAef,KAAK,aAAa,EAElB,MAAM,aAAa,CAAA;AAuBpB,eAAO,MAAM,sBAAsB,GAAI,QAAQ,YAAY;2BAobtB,UAAU,cAAc,MAAM;6BA4B5B,UAAU;yBAtBd,MAAM,YAAY,MAAM;iCAnYlD,MAAM,gBACC,YA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AS,CAAC,KAC1B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;;;;;;;;;wBA2W3B,CAAC;;;;;;;;;;;;;;;;;;;;;;;gBAyoBkB,CAAC;gBACjB,CAAC;aAAmB,CAAC;;;;;qBAAyE,CAAC;;;mBACpE,CAAC;;;;;;aAkN1B,CAAC;gBAEL,CAAC;sBAA4B,CAAC;kBAA0B,CAAC;qBACzD,CAAC;cAAoB,CAAC;iBACR,CAAC;wBAA8B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0DAp1C7C,GAAG,0BACO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2pElB,CAAA"}
@@ -10,9 +10,10 @@ import { makeMutex } from '../Utils/make-mutex.js';
10
10
  import { makeOfflineNodeProcessor } from '../Utils/offline-node-processor.js';
11
11
  import { buildAckStanza } from '../Utils/stanza-ack.js';
12
12
  import { buildMergedTcTokenIndexWrite, isTcTokenExpired, readTcTokenIndex, resolveIssuanceJid, resolveTcTokenJid, storeTcTokensFromIqResult, TC_TOKEN_INDEX_KEY } from '../Utils/tc-token-utils.js';
13
- import { areJidsSameUser, binaryNodeToString, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildString, getBinaryNodeChildUInt, isJidGroup, isJidNewsletter, isJidStatusBroadcast, isLidUser, isPnUser, jidDecode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
13
+ import { areJidsSameUser, binaryNodeToString, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildString, getBinaryNodeChildUInt, isHostedLidUser, isJidGroup, isJidNewsletter, isJidStatusBroadcast, isLidUser, isPnUser, jidDecode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
14
14
  import { extractGroupMetadata } from './groups.js';
15
15
  import { makeMessagesSocket } from './messages-send.js';
16
+ import { makeShortcakeFlow } from '../Utils/shortcake.js';
16
17
  const ENFORCEMENT_TYPE_VALUES = new Set(Object.values(ReachoutTimelockEnforcementType));
17
18
  function isValidEnforcementType(value) {
18
19
  return typeof value === 'string' && ENFORCEMENT_TYPE_VALUES.has(value);
@@ -24,6 +25,19 @@ export const makeMessagesRecvSocket = (config) => {
24
25
  const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
25
26
  /** this mutex ensures that each retryRequest will wait for the previous one to finish */
26
27
  const retryMutex = makeMutex();
28
+ /** Shortcake passkey flow - only active when signPasskeyAssertion is provided */
29
+ const shortcakeFlow = config.signPasskeyAssertion
30
+ ? makeShortcakeFlow({
31
+ logger: logger.child({ mod: 'shortcake' }),
32
+ query,
33
+ signAssertion: config.signPasskeyAssertion,
34
+ getCreds: () => authState.creds,
35
+ updateCreds: patch => ev.emit('creds.update', patch),
36
+ deviceType: undefined, // default: CHROME
37
+ emitVerificationCode: code => logger.info({ code }, 'shortcake verification code'),
38
+ emitPrologueSent: () => ev.emit('connection.update', { passkeyRequired: { hasSigner: true } })
39
+ })
40
+ : null;
27
41
  const msgRetryCache = config.msgRetryCounterCache ||
28
42
  new NodeCache({
29
43
  stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
@@ -384,7 +398,7 @@ export const makeMessagesRecvSocket = (config) => {
384
398
  };
385
399
  await query(stanza);
386
400
  };
387
- const sendRetryRequest = async (node, forceIncludeKeys = false) => {
401
+ const sendRetryRequest = async (node, forceIncludeKeys = false, decryptionError) => {
388
402
  const { fullMessage } = decodeMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '');
389
403
  const { key: msgKey } = fullMessage;
390
404
  const msgId = msgKey.id;
@@ -420,23 +434,34 @@ export const makeMessagesRecvSocket = (config) => {
420
434
  // Check if we should recreate the session
421
435
  let shouldRecreateSession = false;
422
436
  let recreateReason = '';
423
- if (enableAutoSessionRecreation && messageRetryManager && retryCount > 1) {
424
- try {
425
- // Check if we have a session with this JID
426
- const sessionId = signalRepository.jidToSignalProtocolAddress(fromJid);
427
- const hasSession = await signalRepository.validateSession(fromJid);
428
- const result = messageRetryManager.shouldRecreateSession(fromJid, hasSession.exists);
429
- shouldRecreateSession = result.recreate;
430
- recreateReason = result.reason;
431
- if (shouldRecreateSession) {
432
- logger.debug({ fromJid, retryCount, reason: recreateReason }, 'recreating session for retry');
433
- // Delete existing session to force recreation
434
- await authState.keys.set({ session: { [sessionId]: null } });
435
- forceIncludeKeys = true;
437
+ const isSessionCorrupted = !!(decryptionError && (decryptionError.toLowerCase().includes('session') ||
438
+ decryptionError.toLowerCase().includes('key') ||
439
+ decryptionError.toLowerCase().includes('signature') ||
440
+ decryptionError.toLowerCase().includes('mac') ||
441
+ decryptionError.toLowerCase().includes('decrypt')));
442
+ if (enableAutoSessionRecreation) {
443
+ if (retryCount > 1 || isSessionCorrupted) {
444
+ try {
445
+ // Check if we have a session with this JID
446
+ const sessionId = signalRepository.jidToSignalProtocolAddress(fromJid);
447
+ const hasSession = await signalRepository.validateSession(fromJid);
448
+ const result = messageRetryManager
449
+ ? messageRetryManager.shouldRecreateSession(fromJid, hasSession.exists)
450
+ : { recreate: true, reason: 'No messageRetryManager' };
451
+ shouldRecreateSession = result.recreate || isSessionCorrupted;
452
+ recreateReason = isSessionCorrupted
453
+ ? `proactive session repair on decryption error: ${decryptionError}`
454
+ : result.reason;
455
+ if (shouldRecreateSession) {
456
+ logger.debug({ fromJid, retryCount, reason: recreateReason }, 'recreating session for retry');
457
+ // Delete existing session to force recreation
458
+ await authState.keys.set({ session: { [sessionId]: null } });
459
+ forceIncludeKeys = true;
460
+ }
461
+ }
462
+ catch (error) {
463
+ logger.warn({ error, fromJid }, 'failed to check session recreation');
436
464
  }
437
- }
438
- catch (error) {
439
- logger.warn({ error, fromJid }, 'failed to check session recreation');
440
465
  }
441
466
  }
442
467
  if (retryCount <= 2) {
@@ -824,6 +849,30 @@ export const makeMessagesRecvSocket = (config) => {
824
849
  logger.error({ error, node }, 'failed to handle devices notification');
825
850
  }
826
851
  break;
852
+ case 'passkey_prologue_request':
853
+ if (shortcakeFlow) {
854
+ try {
855
+ await shortcakeFlow.handleIncomingNotification(node);
856
+ }
857
+ catch (error) {
858
+ logger.error({ error }, 'error in shortcake passkey prologue');
859
+ }
860
+ }
861
+ else {
862
+ logger.warn('server requested passkey but signPasskeyAssertion is not configured');
863
+ ev.emit('connection.update', { passkeyRequired: { hasSigner: false } });
864
+ }
865
+ break;
866
+ case 'crsc_continuation':
867
+ if (shortcakeFlow) {
868
+ try {
869
+ await shortcakeFlow.handleIncomingNotification(node);
870
+ }
871
+ catch (error) {
872
+ logger.error({ error }, 'error in shortcake crsc_continuation');
873
+ }
874
+ }
875
+ break;
827
876
  case 'server_sync':
828
877
  const update = getBinaryNodeChild(node, 'collection');
829
878
  if (update) {
@@ -880,9 +929,18 @@ export const makeMessagesRecvSocket = (config) => {
880
929
  break;
881
930
  case 'link_code_companion_reg':
882
931
  const linkCodeCompanionReg = getBinaryNodeChild(node, 'link_code_companion_reg');
883
- const ref = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_ref'));
884
- const primaryIdentityPublicKey = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'primary_identity_pub'));
885
- const primaryEphemeralPublicKeyWrapped = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
932
+ const refBuffer = getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_ref');
933
+ const primaryIdentityPublicKeyBuffer = getBinaryNodeChildBuffer(linkCodeCompanionReg, 'primary_identity_pub');
934
+ const primaryEphemeralPublicKeyWrappedBuffer = getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub');
935
+ if (refBuffer === undefined ||
936
+ primaryIdentityPublicKeyBuffer === undefined ||
937
+ primaryEphemeralPublicKeyWrappedBuffer === undefined) {
938
+ logger.debug({ id: node.attrs.id, type: node.attrs.type }, 'skipping empty link code companion registration');
939
+ break;
940
+ }
941
+ const ref = toRequiredBuffer(refBuffer);
942
+ const primaryIdentityPublicKey = toRequiredBuffer(primaryIdentityPublicKeyBuffer);
943
+ const primaryEphemeralPublicKeyWrapped = toRequiredBuffer(primaryEphemeralPublicKeyWrappedBuffer);
886
944
  const codePairingPublicKey = await decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
887
945
  const companionSharedKey = Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
888
946
  const random = randomBytes(32);
@@ -1265,12 +1323,6 @@ export const makeMessagesRecvSocket = (config) => {
1265
1323
  };
1266
1324
  const handleMessage = async (node) => {
1267
1325
  const encNode = getBinaryNodeChild(node, 'enc');
1268
- // TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
1269
- if (encNode?.attrs.type === 'msmsg') {
1270
- logger.debug({ key: node.attrs.key }, 'ignored msmsg');
1271
- await sendMessageAck(node, NACK_REASONS.MissingMessageSecret);
1272
- return;
1273
- }
1274
1326
  let acked = false;
1275
1327
  try {
1276
1328
  const { fullMessage: msg, category, author, decrypt } = decryptMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
@@ -1376,7 +1428,7 @@ export const makeMessagesRecvSocket = (config) => {
1376
1428
  return;
1377
1429
  }
1378
1430
  const encNode = getBinaryNodeChild(node, 'enc');
1379
- await sendRetryRequest(node, !encNode);
1431
+ await sendRetryRequest(node, !encNode, msg.messageStubParameters?.[0]);
1380
1432
  if (retryRequestDelayMs) {
1381
1433
  await delay(retryRequestDelayMs);
1382
1434
  }
@@ -1491,8 +1543,45 @@ export const makeMessagesRecvSocket = (config) => {
1491
1543
  await sendMessageAck(node).catch(ackErr => logger.error({ ackErr }, 'failed to ack call'));
1492
1544
  }
1493
1545
  };
1546
+ const handleLidRefreshAck = async (attrs) => {
1547
+ // NOTE: Yes, it is a string right from the WhatsApp x_x
1548
+ const refreshLidTrue = 'true';
1549
+ if (!config.enableLidMigrationSafety || attrs['refresh_lid'] !== refreshLidTrue)
1550
+ return;
1551
+ const oldLid = attrs.from || attrs.remoteJid;
1552
+ if (!oldLid || (!isLidUser(oldLid) && !isHostedLidUser(oldLid))) {
1553
+ logger.warn({ attrs }, `received 'refresh_lid' ack without a LID sender`);
1554
+ return;
1555
+ }
1556
+ let pn;
1557
+ let newLid;
1558
+ try {
1559
+ pn = (await signalRepository.lidMapping.getPNForLID(oldLid)) || undefined;
1560
+ if (pn && config.refreshMappingOnLidMigration) {
1561
+ const refreshedLid = await signalRepository.lidMapping.getLIDForPN(pn, { force: true });
1562
+ if (refreshedLid && !areJidsSameUser(refreshedLid, oldLid)) {
1563
+ newLid = refreshedLid;
1564
+ await signalRepository
1565
+ .migrateSession(pn, newLid)
1566
+ .catch(err => logger.warn({ err, pn, oldLid, newLid }, `failed to migrate Signal session after 'refresh_lid' ack`));
1567
+ }
1568
+ }
1569
+ }
1570
+ catch (err) {
1571
+ logger.warn({ err, oldLid }, `failed to refresh LID mapping after 'refresh_lid' ack`);
1572
+ }
1573
+ const migration = {
1574
+ oldLid,
1575
+ reason: 'ack-refresh-lid',
1576
+ pn,
1577
+ newLid,
1578
+ messageId: attrs.id,
1579
+ };
1580
+ ev.emit('lid-migration.update', migration);
1581
+ };
1494
1582
  const handleBadAck = async ({ attrs }) => {
1495
1583
  const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id };
1584
+ await handleLidRefreshAck(attrs);
1496
1585
  // WARNING: REFRAIN FROM ENABLING THIS FOR NOW. IT WILL CAUSE A LOOP
1497
1586
  // // current hypothesis is that if pash is sent in the ack
1498
1587
  // // it means -- the message hasn't reached all devices yet