diff --git a/Example/example.ts b/Example/example.ts index 28aa66e7..8e8aeb1b 100644 --- a/Example/example.ts +++ b/Example/example.ts @@ -6,6 +6,7 @@ const logger = MAIN_LOGGER.child({ }) logger.level = 'trace' const useStore = !process.argv.includes('--no-store') +const doReplies = !process.argv.includes('--no-reply') // the store maintains the data of the WA connection in memory // can be written out to a file & read from it @@ -59,7 +60,7 @@ const startSock = async() => { console.log(JSON.stringify(m, undefined, 2)) const msg = m.messages[0] - if(!msg.key.fromMe && m.type === 'notify') { + if(!msg.key.fromMe && m.type === 'notify' && doReplies) { console.log('replying to', m.messages[0].key.remoteJid) await sock!.sendReadReceipt(msg.key.remoteJid, msg.key.participant, [msg.key.id]) await sendMessageWTyping({ text: 'Hello there!' }, msg.key.remoteJid) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 31776cf9..9ea410b7 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -546,7 +546,6 @@ export const makeChatsSocket = (config: SocketConfig) => { to: S_WHATSAPP_NET, xmlns: 'abt', type: 'get', - id: generateMessageTag(), }, content: [ { tag: 'props', attrs: { protocol: '1' } } @@ -573,7 +572,6 @@ export const makeChatsSocket = (config: SocketConfig) => { to: S_WHATSAPP_NET, xmlns: 'w', type: 'get', - id: generateMessageTag(), }, content: [ { tag: 'props', attrs: { } } diff --git a/src/Utils/noise-handler.ts b/src/Utils/noise-handler.ts index 4213cd3d..0251b08e 100644 --- a/src/Utils/noise-handler.ts +++ b/src/Utils/noise-handler.ts @@ -17,7 +17,7 @@ export const makeNoiseHandler = ({ public: publicKey, private: privateKey }: Key const authenticate = (data: Uint8Array) => { if(!isFinished) { - hash = sha256(Buffer.from(Binary.build(hash, data).readByteArray())) + hash = sha256(Buffer.concat([hash, data])) } } @@ -83,7 +83,7 @@ export const makeNoiseHandler = ({ public: publicKey, private: privateKey }: Key isFinished = true } - const data = Binary.build(NOISE_MODE).readBuffer() + const data = Buffer.from(NOISE_MODE) let hash = Buffer.from(data.byteLength === 32 ? data : sha256(Buffer.from(data))) let salt = hash let encKey = hash diff --git a/src/Utils/validate-connection.ts b/src/Utils/validate-connection.ts index 42c7f561..fd17be4d 100644 --- a/src/Utils/validate-connection.ts +++ b/src/Utils/validate-connection.ts @@ -3,7 +3,7 @@ import { createHash } from 'crypto' import { proto } from '../../WAProto' import { KEY_BUNDLE_TYPE } from '../Defaults' import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types' -import { Binary, BinaryNode, getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../WABinary' +import { BinaryNode, getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../WABinary' import { Curve, hmacSign } from './crypto' import { encodeBigEndian } from './generics' import { createSignalIdentity } from './signal' @@ -124,18 +124,26 @@ export const configureSuccessfulPairing = ( const account = proto.ADVSignedDeviceIdentity.decode(details) const { accountSignatureKey, accountSignature } = account - const accountMsg = Binary.build(new Uint8Array([6, 0]), account.details, signedIdentityKey.public).readByteArray() + const accountMsg = Buffer.concat([ + Buffer.from([6, 0]), + account.details, + signedIdentityKey.public + ]) if(!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) { throw new Boom('Failed to verify account signature') } + const deviceMsg = Buffer.concat([ + new Uint8Array([6, 1]), + account.details, + signedIdentityKey.public, + account.accountSignatureKey + ]) + account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg) + const identity = createSignalIdentity(jid, accountSignatureKey) const deviceIdentity = proto.ADVDeviceIdentity.decode(account.details) - const keyIndex = deviceIdentity.keyIndex - - const deviceMsg = Binary.build(new Uint8Array([6, 1]), account.details, signedIdentityKey.public, account.accountSignatureKey).readByteArray() - account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg) delete account.accountSignatureKey const accountEnc = proto.ADVSignedDeviceIdentity.encode(account).finish()