mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
code cleanup
This commit is contained in:
@@ -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 { SocketConfig, WAPresence, PresenceData, Chat, WAPatchCreate, WAMediaUpload, ChatMutation, WAPatchName, LTHashState, ChatModification, Contact } from "../Types";
|
||||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidNormalizedUser, S_WHATSAPP_NET } from "../WABinary";
|
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidNormalizedUser, S_WHATSAPP_NET } from "../WABinary";
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { generateProfilePicture, toNumber } from "../Utils";
|
import { generateProfilePicture, toNumber, encodeSyncdPatch, decodePatches, extractSyncdPatches, chatModificationToAppPatch } from "../Utils";
|
||||||
import { makeMessagesRecvSocket } from "./messages-recv";
|
import { makeMessagesRecvSocket } from "./messages-recv";
|
||||||
|
|
||||||
export const makeChatsSocket = (config: SocketConfig) => {
|
export const makeChatsSocket = (config: SocketConfig) => {
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
|
|
||||||
import { SocketConfig, WAMessageStubType, ParticipantAction, Chat, GroupMetadata } from "../Types"
|
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 { BinaryNode, jidDecode, jidEncode, isJidStatusBroadcast, areJidsSameUser, getBinaryNodeChildren, jidNormalizedUser } from '../WABinary'
|
||||||
import { downloadHistory } from '../Utils/history'
|
|
||||||
import { proto } from "../../WAProto"
|
import { proto } from "../../WAProto"
|
||||||
import { generateSignalPubKey, xmppPreKey, xmppSignedPreKey } from "../Utils/signal"
|
|
||||||
import { KEY_BUNDLE_TYPE } from "../Defaults"
|
import { KEY_BUNDLE_TYPE } from "../Defaults"
|
||||||
import { makeMessagesSocket } from "./messages-send"
|
import { makeMessagesSocket } from "./messages-send"
|
||||||
|
|
||||||
|
|||||||
@@ -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 got from "got"
|
||||||
import { Boom } from "@hapi/boom"
|
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"
|
import { makeGroupsSocket } from "./groups"
|
||||||
|
|
||||||
export const makeMessagesSocket = (config: SocketConfig) => {
|
export const makeMessagesSocket = (config: SocketConfig) => {
|
||||||
|
|||||||
@@ -5,12 +5,9 @@ import WebSocket from "ws"
|
|||||||
import { randomBytes } from 'crypto'
|
import { randomBytes } from 'crypto'
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { DisconnectReason, SocketConfig, BaileysEventEmitter, ConnectionState } from "../Types"
|
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 { DEFAULT_ORIGIN, DEF_TAG_PREFIX, DEF_CALLBACK_PREFIX, KEY_BUNDLE_TYPE } from "../Defaults"
|
||||||
import { assertNodeErrorFree, BinaryNode, encodeBinaryNode, S_WHATSAPP_NET } from '../WABinary'
|
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:
|
* Connects to WA servers and performs:
|
||||||
* - simple queries (no retry mechanism, wait for connection establishment)
|
* - 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 */
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
||||||
const ephemeralKeyPair = Curve.generateKeyPair()
|
const ephemeralKeyPair = Curve.generateKeyPair()
|
||||||
/** WA noise protocol wrapper */
|
/** WA noise protocol wrapper */
|
||||||
const noise = noiseHandler(ephemeralKeyPair)
|
const noise = makeNoiseHandler(ephemeralKeyPair)
|
||||||
const authState = initialAuthState || initAuthState()
|
const authState = initialAuthState || initAuthState()
|
||||||
const { creds } = authState
|
const { creds } = authState
|
||||||
const ev = new EventEmitter() as BaileysEventEmitter
|
const ev = new EventEmitter() as BaileysEventEmitter
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Boom } from '@hapi/boom'
|
|||||||
import { aesDecrypt, hmacSign, aesEncrypt, hkdf } from "./crypto"
|
import { aesDecrypt, hmacSign, aesEncrypt, hkdf } from "./crypto"
|
||||||
import { AuthenticationState, WAPatchCreate, ChatMutation, WAPatchName, LTHashState, ChatModification } from "../Types"
|
import { AuthenticationState, WAPatchCreate, ChatMutation, WAPatchName, LTHashState, ChatModification } from "../Types"
|
||||||
import { proto } from '../../WAProto'
|
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 { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren } from '../WABinary'
|
||||||
import { toNumber } from './generics'
|
import { toNumber } from './generics'
|
||||||
|
|
||||||
|
|||||||
@@ -3,4 +3,9 @@ export * from './generics'
|
|||||||
export * from './messages'
|
export * from './messages'
|
||||||
export * from './messages-media'
|
export * from './messages-media'
|
||||||
export * from './validate-connection'
|
export * from './validate-connection'
|
||||||
export * from './crypto'
|
export * from './crypto'
|
||||||
|
export * from './signal'
|
||||||
|
export * from './noise-handler'
|
||||||
|
export * from './history'
|
||||||
|
export * from './chat-utils'
|
||||||
|
export * from './lt-hash'
|
||||||
@@ -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;
|
const o = 128;
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ const generateIV = (counter: number) => {
|
|||||||
return new Uint8Array(iv)
|
return new Uint8Array(iv)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ({ public: publicKey, private: privateKey }: KeyPair) => {
|
export const makeNoiseHandler = ({ public: publicKey, private: privateKey }: KeyPair) => {
|
||||||
|
|
||||||
const authenticate = (data: Uint8Array) => {
|
const authenticate = (data: Uint8Array) => {
|
||||||
if(!isFinished) {
|
if(!isFinished) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { DICTIONARIES_MAP, SINGLE_BYTE_TOKEN, SINGLE_BYTE_TOKEN_MAP, DICTIONARIES } from '../../WABinary/Constants';
|
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 { Binary, numUtf8Bytes } from '../../WABinary/Binary';
|
||||||
import { Boom } from '@hapi/boom';
|
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'
|
export { Binary } from '../../WABinary/Binary'
|
||||||
Reference in New Issue
Block a user