diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 25ab73d..e6a7e26 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -1,8 +1,7 @@ -import { encodeSyncdPatch, decodePatches, extractSyncdPatches, chatModificationToAppPatch } from "../Utils/chat-utils"; import { SocketConfig, WAPresence, PresenceData, Chat, WAPatchCreate, WAMediaUpload, ChatMutation, WAPatchName, LTHashState, ChatModification, Contact } from "../Types"; import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidNormalizedUser, S_WHATSAPP_NET } from "../WABinary"; import { proto } from '../../WAProto' -import { generateProfilePicture, toNumber } from "../Utils"; +import { generateProfilePicture, toNumber, encodeSyncdPatch, decodePatches, extractSyncdPatches, chatModificationToAppPatch } from "../Utils"; import { makeMessagesRecvSocket } from "./messages-recv"; export const makeChatsSocket = (config: SocketConfig) => { diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 323778a..7cdd863 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -1,10 +1,8 @@ import { SocketConfig, WAMessageStubType, ParticipantAction, Chat, GroupMetadata } from "../Types" -import { decodeMessageStanza, encodeBigEndian, toNumber } from "../Utils" +import { decodeMessageStanza, encodeBigEndian, toNumber, downloadHistory, generateSignalPubKey, xmppPreKey, xmppSignedPreKey } from "../Utils" import { BinaryNode, jidDecode, jidEncode, isJidStatusBroadcast, areJidsSameUser, getBinaryNodeChildren, jidNormalizedUser } from '../WABinary' -import { downloadHistory } from '../Utils/history' import { proto } from "../../WAProto" -import { generateSignalPubKey, xmppPreKey, xmppSignedPreKey } from "../Utils/signal" import { KEY_BUNDLE_TYPE } from "../Defaults" import { makeMessagesSocket } from "./messages-send" diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 642407a..76454a5 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -1,12 +1,11 @@ -import { SocketConfig, MediaConnInfo, AnyMessageContent, MiscMessageGenerationOptions, WAMediaUploadFunction, MessageRelayOptions } from "../Types" -import { encodeWAMessage, generateMessageID, generateWAMessage } from "../Utils" -import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET, BinaryNodeAttributes } from '../WABinary' -import { proto } from "../../WAProto" -import { encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, jidToSignalProtocolAddress, parseAndInjectE2ESession } from "../Utils/signal" -import { WA_DEFAULT_EPHEMERAL, DEFAULT_ORIGIN, MEDIA_PATH_MAP } from "../Defaults" import got from "got" import { Boom } from "@hapi/boom" +import { SocketConfig, MediaConnInfo, AnyMessageContent, MiscMessageGenerationOptions, WAMediaUploadFunction, MessageRelayOptions } from "../Types" +import { encodeWAMessage, generateMessageID, generateWAMessage, encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, jidToSignalProtocolAddress, parseAndInjectE2ESession } from "../Utils" +import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET, BinaryNodeAttributes } from '../WABinary' +import { proto } from "../../WAProto" +import { WA_DEFAULT_EPHEMERAL, DEFAULT_ORIGIN, MEDIA_PATH_MAP } from "../Defaults" import { makeGroupsSocket } from "./groups" export const makeMessagesSocket = (config: SocketConfig) => { diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index 80488b8..02ef48e 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -5,12 +5,9 @@ import WebSocket from "ws" import { randomBytes } from 'crypto' import { proto } from '../../WAProto' import { DisconnectReason, SocketConfig, BaileysEventEmitter, ConnectionState } from "../Types" -import { Curve, initAuthState, generateRegistrationNode, configureSuccessfulPairing, generateLoginNode, encodeBigEndian, promiseTimeout } from "../Utils" +import { Curve, initAuthState, generateRegistrationNode, configureSuccessfulPairing, generateLoginNode, encodeBigEndian, promiseTimeout, generateOrGetPreKeys, xmppSignedPreKey, xmppPreKey, getPreKeys, makeNoiseHandler } from "../Utils" import { DEFAULT_ORIGIN, DEF_TAG_PREFIX, DEF_CALLBACK_PREFIX, KEY_BUNDLE_TYPE } from "../Defaults" import { assertNodeErrorFree, BinaryNode, encodeBinaryNode, S_WHATSAPP_NET } from '../WABinary' -import noiseHandler from '../Utils/noise-handler' -import { generateOrGetPreKeys, xmppSignedPreKey, xmppPreKey, getPreKeys } from '../Utils/signal' - /** * Connects to WA servers and performs: * - simple queries (no retry mechanism, wait for connection establishment) @@ -45,7 +42,7 @@ export const makeSocket = ({ /** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */ const ephemeralKeyPair = Curve.generateKeyPair() /** WA noise protocol wrapper */ - const noise = noiseHandler(ephemeralKeyPair) + const noise = makeNoiseHandler(ephemeralKeyPair) const authState = initialAuthState || initAuthState() const { creds } = authState const ev = new EventEmitter() as BaileysEventEmitter diff --git a/src/Utils/chat-utils.ts b/src/Utils/chat-utils.ts index 95ac3ca..71ddbc1 100644 --- a/src/Utils/chat-utils.ts +++ b/src/Utils/chat-utils.ts @@ -2,7 +2,7 @@ import { Boom } from '@hapi/boom' import { aesDecrypt, hmacSign, aesEncrypt, hkdf } from "./crypto" import { AuthenticationState, WAPatchCreate, ChatMutation, WAPatchName, LTHashState, ChatModification } from "../Types" import { proto } from '../../WAProto' -import { LT_HASH_ANTI_TAMPERING } from '../WABinary/LTHash' +import { LT_HASH_ANTI_TAMPERING } from './lt-hash' import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren } from '../WABinary' import { toNumber } from './generics' diff --git a/src/Utils/index.ts b/src/Utils/index.ts index 8ea6ea7..640c9f2 100644 --- a/src/Utils/index.ts +++ b/src/Utils/index.ts @@ -3,4 +3,9 @@ export * from './generics' export * from './messages' export * from './messages-media' export * from './validate-connection' -export * from './crypto' \ No newline at end of file +export * from './crypto' +export * from './signal' +export * from './noise-handler' +export * from './history' +export * from './chat-utils' +export * from './lt-hash' \ No newline at end of file diff --git a/src/WABinary/LTHash.ts b/src/Utils/lt-hash.ts similarity index 79% rename from src/WABinary/LTHash.ts rename to src/Utils/lt-hash.ts index 85ea166..0eeaaa4 100644 --- a/src/WABinary/LTHash.ts +++ b/src/Utils/lt-hash.ts @@ -1,4 +1,10 @@ -import { hkdf } from '../Utils' +import { hkdf } from './crypto' + +/** + * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data + * over a series of mutations. You can add/remove mutations and it'll return a hash equal to + * if the same series of mutations was made sequentially. + */ const o = 128; diff --git a/src/Utils/noise-handler.ts b/src/Utils/noise-handler.ts index 4f60c03..28039cf 100644 --- a/src/Utils/noise-handler.ts +++ b/src/Utils/noise-handler.ts @@ -14,7 +14,7 @@ const generateIV = (counter: number) => { return new Uint8Array(iv) } -export default ({ public: publicKey, private: privateKey }: KeyPair) => { +export const makeNoiseHandler = ({ public: publicKey, private: privateKey }: KeyPair) => { const authenticate = (data: Uint8Array) => { if(!isFinished) { diff --git a/src/WABinary/index.ts b/src/WABinary/index.ts index bcb8016..74bc259 100644 --- a/src/WABinary/index.ts +++ b/src/WABinary/index.ts @@ -1,5 +1,5 @@ import { DICTIONARIES_MAP, SINGLE_BYTE_TOKEN, SINGLE_BYTE_TOKEN_MAP, DICTIONARIES } from '../../WABinary/Constants'; -import { jidDecode, jidEncode } from './JidUtils'; +import { jidDecode, jidEncode } from './jid-utils'; import { Binary, numUtf8Bytes } from '../../WABinary/Binary'; import { Boom } from '@hapi/boom'; @@ -301,5 +301,5 @@ export const assertNodeErrorFree = (node: BinaryNode) => { } } -export * from './JidUtils' +export * from './jid-utils' export { Binary } from '../../WABinary/Binary' \ No newline at end of file diff --git a/src/WABinary/JidUtils.ts b/src/WABinary/jid-utils.ts similarity index 100% rename from src/WABinary/JidUtils.ts rename to src/WABinary/jid-utils.ts