diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index ea5681b..16dc5e7 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -2,7 +2,7 @@ import { proto } from '../../WAProto' import { KEY_BUNDLE_TYPE, MIN_PREKEY_COUNT } from '../Defaults' import { MessageReceiptType, MessageRelayOptions, MessageUserReceipt, SocketConfig, WACallEvent, WAMessageKey, WAMessageStubType, WAPatchName } from '../Types' -import { decodeMediaRetryNode, decodeMessageStanza, delay, encodeBigEndian, getCallStatusFromNode, getNextPreKeys, getStatusFromReceiptType, isHistoryMsg, unixTimestampSeconds, xmppPreKey, xmppSignedPreKey } from '../Utils' +import { decodeMediaRetryNode, decodeMessageStanza, delay, encodeBigEndian, encodeSignedDeviceIdentity, getCallStatusFromNode, getNextPreKeys, getStatusFromReceiptType, isHistoryMsg, unixTimestampSeconds, xmppPreKey, xmppSignedPreKey } from '../Utils' import { makeMutex } from '../Utils/make-mutex' import { cleanMessage } from '../Utils/process-message' import { areJidsSameUser, BinaryNode, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary' @@ -80,10 +80,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { const { account, signedPreKey, signedIdentityKey: identityKey } = authState.creds - const deviceIdentity = proto.ADVSignedDeviceIdentity.encode({ - ...account, - accountSignatureKey: undefined - }).finish() + const deviceIdentity = encodeSignedDeviceIdentity(account!, true) await authState.keys.transaction( async() => { const receipt: BinaryNode = { diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index f9dddc6..9c75460 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -4,7 +4,7 @@ import NodeCache from 'node-cache' import { proto } from '../../WAProto' import { WA_DEFAULT_EPHEMERAL } from '../Defaults' import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types' -import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeWAMessage, encryptMediaRetryRequest, encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, generateMessageID, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, jidToSignalProtocolAddress, parseAndInjectE2ESessions, patchMessageForMdIfRequired, unixTimestampSeconds } from '../Utils' +import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, generateMessageID, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, jidToSignalProtocolAddress, parseAndInjectE2ESessions, patchMessageForMdIfRequired, unixTimestampSeconds } from '../Utils' import { getUrlInfo } from '../Utils/link-preview' import { areJidsSameUser, BinaryNode, BinaryNodeAttributes, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidEncode, jidNormalizedUser, JidWithDevice, S_WHATSAPP_NET } from '../WABinary' import { makeGroupsSocket } from './groups' @@ -266,7 +266,9 @@ export const makeMessagesSocket = (config: SocketConfig) => { attrs: { v: '2', type, - ...extraAttrs || {} + // do not send extra params + // causes retries to fail for some reason now + // ...extraAttrs || {} }, content: ciphertext }] @@ -473,7 +475,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { (stanza.content as BinaryNode[]).push({ tag: 'device-identity', attrs: { }, - content: proto.ADVSignedDeviceIdentity.encode(authState.creds.account!).finish() + content: encodeSignedDeviceIdentity(authState.creds.account!, true) }) logger.debug({ jid }, 'adding device identity') diff --git a/src/Utils/validate-connection.ts b/src/Utils/validate-connection.ts index 77d499e..444634d 100644 --- a/src/Utils/validate-connection.ts +++ b/src/Utils/validate-connection.ts @@ -148,13 +148,7 @@ export const configureSuccessfulPairing = ( account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg) const identity = createSignalIdentity(jid, accountSignatureKey) - const accountEnc = proto.ADVSignedDeviceIdentity - .encode({ - ...account, - // do not provide the "accountSignatureKey" back - accountSignatureKey: undefined - }) - .finish() + const accountEnc = encodeSignedDeviceIdentity(account, false) const deviceIdentity = proto.ADVDeviceIdentity.decode(account.details) @@ -195,3 +189,20 @@ export const configureSuccessfulPairing = ( reply } } + +export const encodeSignedDeviceIdentity = ( + account: proto.IADVSignedDeviceIdentity, + includeSignatureKey: boolean +) => { + account = { ...account } + // set to null if we are not to include the signature key + // or if we are including the signature key but it is empty + if(!includeSignatureKey || !account.accountSignatureKey?.length) { + account.accountSignatureKey = null + } + + const accountEnc = proto.ADVSignedDeviceIdentity + .encode(account) + .finish() + return accountEnc +} \ No newline at end of file