mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
lint: stricter linting rules
This commit is contained in:
16
package.json
16
package.json
@@ -52,10 +52,18 @@
|
|||||||
"sharp": "^0.29.3"
|
"sharp": "^0.29.3"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@adiwajshing/keyed-db": { "optional": true },
|
"@adiwajshing/keyed-db": {
|
||||||
"jimp": { "optional": true },
|
"optional": true
|
||||||
"qrcode-terminal": { "optional": true },
|
},
|
||||||
"sharp": { "optional": true }
|
"jimp": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"qrcode-terminal": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"sharp": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib/*",
|
"lib/*",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export const DEF_CALLBACK_PREFIX = 'CB:'
|
|||||||
export const DEF_TAG_PREFIX = 'TAG:'
|
export const DEF_TAG_PREFIX = 'TAG:'
|
||||||
export const PHONE_CONNECTION_CB = 'CB:Pong'
|
export const PHONE_CONNECTION_CB = 'CB:Pong'
|
||||||
|
|
||||||
export const WA_DEFAULT_EPHEMERAL = 7*24*60*60
|
export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60
|
||||||
|
|
||||||
export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0'
|
export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0'
|
||||||
export const NOISE_WA_HEADER = new Uint8Array([87, 65, 5, 2]) // last is "DICT_VERSION"
|
export const NOISE_WA_HEADER = new Uint8Array([87, 65, 5, 2]) // last is "DICT_VERSION"
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ const makeChatsSocket = (config: LegacySocketConfig) => {
|
|||||||
}
|
}
|
||||||
} else if('clear' in modification) {
|
} else if('clear' in modification) {
|
||||||
chatAttrs.type = 'clear'
|
chatAttrs.type = 'clear'
|
||||||
chatAttrs.modify_tag = Math.round(Math.random()*1000000).toString()
|
chatAttrs.modify_tag = Math.round(Math.random() * 1000000).toString()
|
||||||
if(modification.clear !== 'all') {
|
if(modification.clear !== 'all') {
|
||||||
data = modification.clear.messages.map(({ id, fromMe }) => (
|
data = modification.clear.messages.map(({ id, fromMe }) => (
|
||||||
{
|
{
|
||||||
@@ -345,14 +345,14 @@ const makeChatsSocket = (config: LegacySocketConfig) => {
|
|||||||
}
|
}
|
||||||
))
|
))
|
||||||
} else if('markRead' in modification) {
|
} else if('markRead' in modification) {
|
||||||
const indexKey = modification.lastMessages[modification.lastMessages.length-1].key
|
const indexKey = modification.lastMessages[modification.lastMessages.length - 1].key
|
||||||
return chatRead(indexKey, modification.markRead ? 0 : -1)
|
return chatRead(indexKey, modification.markRead ? 0 : -1)
|
||||||
} else if('delete' in modification) {
|
} else if('delete' in modification) {
|
||||||
chatAttrs.type = 'delete'
|
chatAttrs.type = 'delete'
|
||||||
}
|
}
|
||||||
|
|
||||||
if('lastMessages' in modification) {
|
if('lastMessages' in modification) {
|
||||||
const indexKey = modification.lastMessages[modification.lastMessages.length-1].key
|
const indexKey = modification.lastMessages[modification.lastMessages.length - 1].key
|
||||||
if(indexKey) {
|
if(indexKey) {
|
||||||
chatAttrs.index = indexKey.id
|
chatAttrs.index = indexKey.id
|
||||||
chatAttrs.owner = indexKey.fromMe ? 'true' : 'false'
|
chatAttrs.owner = indexKey.fromMe ? 'true' : 'false'
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const makeMessagesSocket = (config: LegacySocketConfig) => {
|
|||||||
let mediaConn: Promise<MediaConnInfo>
|
let mediaConn: Promise<MediaConnInfo>
|
||||||
const refreshMediaConn = async(forceGet = false) => {
|
const refreshMediaConn = async(forceGet = false) => {
|
||||||
const media = await mediaConn
|
const media = await mediaConn
|
||||||
if(!media || forceGet || (new Date().getTime()-media.fetchDate.getTime()) > media.ttl*1000) {
|
if(!media || forceGet || (new Date().getTime() - media.fetchDate.getTime()) > media.ttl * 1000) {
|
||||||
mediaConn = (async() => {
|
mediaConn = (async() => {
|
||||||
const { media_conn } = await query({
|
const { media_conn } = await query({
|
||||||
json: ['query', 'mediaConn'],
|
json: ['query', 'mediaConn'],
|
||||||
@@ -540,7 +540,7 @@ const makeMessagesSocket = (config: LegacySocketConfig) => {
|
|||||||
tag: 'group',
|
tag: 'group',
|
||||||
attrs: { id: tag, jid, type: 'prop', author: userJid },
|
attrs: { id: tag, jid, type: 'prop', author: userJid },
|
||||||
content: [
|
content: [
|
||||||
{ tag: 'ephemeral', attrs: { value: value.toString() } }
|
{ tag: 'ephemeral', attrs: { value: value.toString() } }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export const makeSocket = ({
|
|||||||
const sendPromise = promisify(ws.send)
|
const sendPromise = promisify(ws.send)
|
||||||
/** generate message tag and increment epoch */
|
/** generate message tag and increment epoch */
|
||||||
const generateMessageTag = (longTag: boolean = false) => {
|
const generateMessageTag = (longTag: boolean = false) => {
|
||||||
const tag = `${longTag ? referenceDateSeconds : (referenceDateSeconds%1000)}.--${epoch}`
|
const tag = `${longTag ? referenceDateSeconds : (referenceDateSeconds % 1000)}.--${epoch}`
|
||||||
epoch += 1 // increment message count, it makes the 'epoch' field when sending binary messages
|
epoch += 1 // increment message count, it makes the 'epoch' field when sending binary messages
|
||||||
return tag
|
return tag
|
||||||
}
|
}
|
||||||
@@ -308,7 +308,7 @@ export const makeSocket = ({
|
|||||||
end(new Boom('WA server overloaded', { statusCode: 599, data: { query: json, response } }))
|
end(new Boom('WA server overloaded', { statusCode: 599, data: { query: json, response } }))
|
||||||
}
|
}
|
||||||
|
|
||||||
if(expect200 && Math.floor(responseStatusCode/100) !== 2) {
|
if(expect200 && Math.floor(responseStatusCode / 100) !== 2) {
|
||||||
const message = STATUS_CODES[responseStatusCode] || 'unknown'
|
const message = STATUS_CODES[responseStatusCode] || 'unknown'
|
||||||
throw new Boom(
|
throw new Boom(
|
||||||
`Unexpected status in '${Array.isArray(json) ? json[0] : (json?.tag || 'query')}': ${message}(${responseStatusCode})`,
|
`Unexpected status in '${Array.isArray(json) ? json[0] : (json?.tag || 'query')}': ${message}(${responseStatusCode})`,
|
||||||
@@ -330,7 +330,7 @@ export const makeSocket = ({
|
|||||||
check if it's been a suspicious amount of time since the server responded with our last seen
|
check if it's been a suspicious amount of time since the server responded with our last seen
|
||||||
it could be that the network is down
|
it could be that the network is down
|
||||||
*/
|
*/
|
||||||
if(diff > keepAliveIntervalMs+5000) {
|
if(diff > keepAliveIntervalMs + 5000) {
|
||||||
end(new Boom('Connection was lost', { statusCode: DisconnectReason.connectionLost }))
|
end(new Boom('Connection was lost', { statusCode: DisconnectReason.connectionLost }))
|
||||||
} else if(ws.readyState === ws.OPEN) {
|
} else if(ws.readyState === ws.OPEN) {
|
||||||
sendRawMessage('?,,') // if its all good, send a keep alive request
|
sendRawMessage('?,,') // if its all good, send a keep alive request
|
||||||
|
|||||||
@@ -546,7 +546,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
tag: 'collection',
|
tag: 'collection',
|
||||||
attrs: {
|
attrs: {
|
||||||
name,
|
name,
|
||||||
version: (state.version-1).toString(),
|
version: (state.version - 1).toString(),
|
||||||
return_snapshot: 'false'
|
return_snapshot: 'false'
|
||||||
},
|
},
|
||||||
content: [
|
content: [
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
msgRetryMap[msgId] = retryCount+1
|
msgRetryMap[msgId] = retryCount + 1
|
||||||
|
|
||||||
const isGroup = !!node.attrs.participant
|
const isGroup = !!node.attrs.participant
|
||||||
const { account, signedPreKey, signedIdentityKey: identityKey } = authState.creds
|
const { account, signedPreKey, signedIdentityKey: identityKey } = authState.creds
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
let mediaConn: Promise<MediaConnInfo>
|
let mediaConn: Promise<MediaConnInfo>
|
||||||
const refreshMediaConn = async(forceGet = false) => {
|
const refreshMediaConn = async(forceGet = false) => {
|
||||||
const media = await mediaConn
|
const media = await mediaConn
|
||||||
if(!media || forceGet || (new Date().getTime()-media.fetchDate.getTime()) > media.ttl*1000) {
|
if(!media || forceGet || (new Date().getTime() - media.fetchDate.getTime()) > media.ttl * 1000) {
|
||||||
mediaConn = (async() => {
|
mediaConn = (async() => {
|
||||||
const result = await query({
|
const result = await query({
|
||||||
tag: 'iq',
|
tag: 'iq',
|
||||||
|
|||||||
@@ -205,8 +205,8 @@ export const makeSocket = ({
|
|||||||
const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(authState.creds, range)
|
const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(authState.creds, range)
|
||||||
|
|
||||||
const update: Partial<AuthenticationCreds> = {
|
const update: Partial<AuthenticationCreds> = {
|
||||||
nextPreKeyId: Math.max(lastPreKeyId+1, creds.nextPreKeyId),
|
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
||||||
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId+1)
|
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
||||||
}
|
}
|
||||||
if(!creds.serverHasPreKeys) {
|
if(!creds.serverHasPreKeys) {
|
||||||
update.serverHasPreKeys = true
|
update.serverHasPreKeys = true
|
||||||
@@ -343,7 +343,7 @@ export const makeSocket = ({
|
|||||||
check if it's been a suspicious amount of time since the server responded with our last seen
|
check if it's been a suspicious amount of time since the server responded with our last seen
|
||||||
it could be that the network is down
|
it could be that the network is down
|
||||||
*/
|
*/
|
||||||
if(diff > keepAliveIntervalMs+5000) {
|
if(diff > keepAliveIntervalMs + 5000) {
|
||||||
end(new Boom('Connection was lost', { statusCode: DisconnectReason.connectionLost }))
|
end(new Boom('Connection was lost', { statusCode: DisconnectReason.connectionLost }))
|
||||||
} else if(ws.readyState === ws.OPEN) {
|
} else if(ws.readyState === ws.OPEN) {
|
||||||
// if its all good, send a keep alive request
|
// if its all good, send a keep alive request
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ type LegacyWASocket = ReturnType<typeof makeLegacySocket>
|
|||||||
type AnyWASocket = ReturnType<typeof makeMDSocket>
|
type AnyWASocket = ReturnType<typeof makeMDSocket>
|
||||||
|
|
||||||
export const waChatKey = (pin: boolean) => ({
|
export const waChatKey = (pin: boolean) => ({
|
||||||
key: (c: Chat) => (pin ? (c.pin ? '1' : '0') : '') + (c.archive ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') :'') + c.id,
|
key: (c: Chat) => (pin ? (c.pin ? '1' : '0') : '') + (c.archive ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
|
||||||
compare: (k1: string, k2: string) => k2.localeCompare (k1)
|
compare: (k1: string, k2: string) => k2.localeCompare (k1)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -286,7 +286,7 @@ export default (
|
|||||||
const cursor = { before: fMessage?.key || cursorKey }
|
const cursor = { before: fMessage?.key || cursorKey }
|
||||||
const extra = await retrieve (diff, cursor)
|
const extra = await retrieve (diff, cursor)
|
||||||
// add to DB
|
// add to DB
|
||||||
for(let i = extra.length-1; i >= 0;i--) {
|
for(let i = extra.length - 1; i >= 0;i--) {
|
||||||
list.upsert(extra[i], 'prepend')
|
list.upsert(extra[i], 'prepend')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ describe('Media Download Tests', () => {
|
|||||||
for(const { type, message, plaintext } of TEST_VECTORS) {
|
for(const { type, message, plaintext } of TEST_VECTORS) {
|
||||||
// check all edge cases
|
// check all edge cases
|
||||||
const ranges = [
|
const ranges = [
|
||||||
{ startByte: 51, endByte: plaintext.length-100 }, // random numbers
|
{ startByte: 51, endByte: plaintext.length - 100 }, // random numbers
|
||||||
{ startByte: 1024, endByte: 2038 }, // larger random multiples of 16
|
{ startByte: 1024, endByte: 2038 }, // larger random multiples of 16
|
||||||
{ startByte: 1, endByte: plaintext.length-1 } // borders
|
{ startByte: 1, endByte: plaintext.length - 1 } // borders
|
||||||
]
|
]
|
||||||
for(const range of ranges) {
|
for(const range of ranges) {
|
||||||
const readPipe = await downloadContentFromMessage(message, type, range)
|
const readPipe = await downloadContentFromMessage(message, type, range)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export type BaileysEventMap<T> = {
|
|||||||
/** delete chats with given ID */
|
/** delete chats with given ID */
|
||||||
'chats.delete': string[]
|
'chats.delete': string[]
|
||||||
/** presence of contact in a chat updated */
|
/** presence of contact in a chat updated */
|
||||||
'presence.update': { id: string, presences: { [participant: string]: PresenceData } }
|
'presence.update': { id: string, presences: { [participant: string]: PresenceData } }
|
||||||
|
|
||||||
'contacts.upsert': Contact[]
|
'contacts.upsert': Contact[]
|
||||||
'contacts.update': Partial<Contact>[]
|
'contacts.update': Partial<Contact>[]
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ export type AnyMessageContent = AnyRegularMessageContent | {
|
|||||||
force?: boolean
|
force?: boolean
|
||||||
} | {
|
} | {
|
||||||
delete: WAMessageKey
|
delete: WAMessageKey
|
||||||
} | {
|
} | {
|
||||||
disappearingMessagesInChat: boolean | number
|
disappearingMessagesInChat: boolean | number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,15 +53,15 @@ export type WABusinessHoursConfig = {
|
|||||||
export type WABusinessProfile = {
|
export type WABusinessProfile = {
|
||||||
description: string
|
description: string
|
||||||
email: string
|
email: string
|
||||||
business_hours: {
|
business_hours: {
|
||||||
timezone?: string
|
timezone?: string
|
||||||
config?: WABusinessHoursConfig[]
|
config?: WABusinessHoursConfig[]
|
||||||
business_config?: WABusinessHoursConfig[]
|
business_config?: WABusinessHoursConfig[]
|
||||||
}
|
}
|
||||||
website: string[]
|
website: string[]
|
||||||
categories: {
|
categories: {
|
||||||
id: string
|
id: string
|
||||||
localized_display_name: string
|
localized_display_name: string
|
||||||
}[]
|
}[]
|
||||||
wid?: string
|
wid?: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren } from '../WABina
|
|||||||
import { aesDecrypt, aesEncrypt, hkdf, hmacSign } from './crypto'
|
import { aesDecrypt, aesEncrypt, hkdf, hmacSign } from './crypto'
|
||||||
import { toNumber } from './generics'
|
import { toNumber } from './generics'
|
||||||
import { LT_HASH_ANTI_TAMPERING } from './lt-hash'
|
import { LT_HASH_ANTI_TAMPERING } from './lt-hash'
|
||||||
import { downloadContentFromMessage, } from './messages-media'
|
import { downloadContentFromMessage, } from './messages-media'
|
||||||
|
|
||||||
type FetchAppStateSyncKey = (keyId: string) => Promise<proto.IAppStateSyncKeyData> | proto.IAppStateSyncKeyData
|
type FetchAppStateSyncKey = (keyId: string) => Promise<proto.IAppStateSyncKeyData> | proto.IAppStateSyncKeyData
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ const generateMac = (operation: proto.SyncdMutation.SyncdMutationSyncdOperation,
|
|||||||
const keyData = getKeyData()
|
const keyData = getKeyData()
|
||||||
|
|
||||||
const last = Buffer.alloc(8) // 8 bytes
|
const last = Buffer.alloc(8) // 8 bytes
|
||||||
last.set([ keyData.length ], last.length-1)
|
last.set([ keyData.length ], last.length - 1)
|
||||||
|
|
||||||
const total = Buffer.concat([ keyData, data, last ])
|
const total = Buffer.concat([ keyData, data, last ])
|
||||||
const hmac = hmacSign(total, key, 'sha512')
|
const hmac = hmacSign(total, key, 'sha512')
|
||||||
@@ -313,7 +313,7 @@ export const extractSyncdPatches = async(result: BinaryNode) => {
|
|||||||
|
|
||||||
const syncd = proto.SyncdPatch.decode(content! as Uint8Array)
|
const syncd = proto.SyncdPatch.decode(content! as Uint8Array)
|
||||||
if(!syncd.version) {
|
if(!syncd.version) {
|
||||||
syncd.version = { version: +collectionNode.attrs.version+1 }
|
syncd.version = { version: +collectionNode.attrs.version + 1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
syncds.push(syncd)
|
syncds.push(syncd)
|
||||||
@@ -450,7 +450,7 @@ export const chatModificationToAppPatch = (
|
|||||||
throw new Boom('Expected last message to be not from me', { statusCode: 400 })
|
throw new Boom('Expected last message to be not from me', { statusCode: 400 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const lastMsg = lastMessages[lastMessages.length-1]
|
const lastMsg = lastMessages[lastMessages.length - 1]
|
||||||
if(lastMsg.key.fromMe) {
|
if(lastMsg.key.fromMe) {
|
||||||
throw new Boom('Expected last message in array to be not from me', { statusCode: 400 })
|
throw new Boom('Expected last message in array to be not from me', { statusCode: 400 })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ export function hkdf(buffer: Uint8Array, expandedLength: number, { info, salt }:
|
|||||||
|
|
||||||
const infoBuff = Buffer.from(info || [])
|
const infoBuff = Buffer.from(info || [])
|
||||||
|
|
||||||
for(var i=0; i<num_blocks; i++) {
|
for(var i = 0; i < num_blocks; i++) {
|
||||||
const hmac = createHmac(hashAlg, prk)
|
const hmac = createHmac(hashAlg, prk)
|
||||||
// XXX is there a more optimal way to build up buffers?
|
// XXX is there a more optimal way to build up buffers?
|
||||||
const input = Buffer.concat([
|
const input = Buffer.concat([
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ export const encodeInt = (e: number, t: number) => {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
export const encodeBigEndian = (e: number, t=4) => {
|
export const encodeBigEndian = (e: number, t = 4) => {
|
||||||
let r = e
|
let r = e
|
||||||
const a = new Uint8Array(t)
|
const a = new Uint8Array(t)
|
||||||
for(let i = t - 1; i >= 0; i--) {
|
for(let i = t - 1; i >= 0; i--) {
|
||||||
@@ -121,7 +121,7 @@ export function shallowChanges <T>(old: T, current: T, { lookForDeletedKeys }: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** unix timestamp of a date in seconds */
|
/** unix timestamp of a date in seconds */
|
||||||
export const unixTimestampSeconds = (date: Date = new Date()) => Math.floor(date.getTime()/1000)
|
export const unixTimestampSeconds = (date: Date = new Date()) => Math.floor(date.getTime() / 1000)
|
||||||
|
|
||||||
export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>
|
export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>
|
||||||
|
|
||||||
|
|||||||
@@ -12,18 +12,18 @@ export const newLegacyAuthCreds = () => ({
|
|||||||
export const decodeWAMessage = (
|
export const decodeWAMessage = (
|
||||||
message: Buffer | string,
|
message: Buffer | string,
|
||||||
auth: { macKey: Buffer, encKey: Buffer },
|
auth: { macKey: Buffer, encKey: Buffer },
|
||||||
fromMe: boolean=false
|
fromMe: boolean = false
|
||||||
) => {
|
) => {
|
||||||
let commaIndex = message.indexOf(',') // all whatsapp messages have a tag and a comma, followed by the actual message
|
let commaIndex = message.indexOf(',') // all whatsapp messages have a tag and a comma, followed by the actual message
|
||||||
if(commaIndex < 0) {
|
if(commaIndex < 0) {
|
||||||
throw new Boom('invalid message', { data: message })
|
throw new Boom('invalid message', { data: message })
|
||||||
} // if there was no comma, then this message must be not be valid
|
} // if there was no comma, then this message must be not be valid
|
||||||
|
|
||||||
if(message[commaIndex+1] === ',') {
|
if(message[commaIndex + 1] === ',') {
|
||||||
commaIndex += 1
|
commaIndex += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = message.slice(commaIndex+1, message.length)
|
let data = message.slice(commaIndex + 1, message.length)
|
||||||
|
|
||||||
// get the message tag.
|
// get the message tag.
|
||||||
// If a query was done, the server will respond with the same message tag we sent the query with
|
// If a query was done, the server will respond with the same message tag we sent the query with
|
||||||
|
|||||||
@@ -356,14 +356,14 @@ export const downloadContentFromMessage = async(
|
|||||||
if(startByte) {
|
if(startByte) {
|
||||||
const chunk = toSmallestChunkSize(startByte || 0)
|
const chunk = toSmallestChunkSize(startByte || 0)
|
||||||
if(chunk) {
|
if(chunk) {
|
||||||
startChunk = chunk-AES_CHUNK_SIZE
|
startChunk = chunk - AES_CHUNK_SIZE
|
||||||
bytesFetched = chunk
|
bytesFetched = chunk
|
||||||
|
|
||||||
firstBlockIsIV = true
|
firstBlockIsIV = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const endChunk = endByte ? toSmallestChunkSize(endByte || 0)+AES_CHUNK_SIZE : undefined
|
const endChunk = endByte ? toSmallestChunkSize(endByte || 0) + AES_CHUNK_SIZE : undefined
|
||||||
|
|
||||||
const headers: { [_: string]: string } = {
|
const headers: { [_: string]: string } = {
|
||||||
Origin: DEFAULT_ORIGIN,
|
Origin: DEFAULT_ORIGIN,
|
||||||
@@ -392,8 +392,8 @@ export const downloadContentFromMessage = async(
|
|||||||
|
|
||||||
const pushBytes = (bytes: Buffer, push: (bytes: Buffer) => void) => {
|
const pushBytes = (bytes: Buffer, push: (bytes: Buffer) => void) => {
|
||||||
if(startByte || endByte) {
|
if(startByte || endByte) {
|
||||||
const start = bytesFetched >= startByte ? undefined : Math.max(startByte-bytesFetched, 0)
|
const start = bytesFetched >= startByte ? undefined : Math.max(startByte - bytesFetched, 0)
|
||||||
const end = bytesFetched+bytes.length < endByte ? undefined : Math.max(endByte-bytesFetched, 0)
|
const end = bytesFetched + bytes.length < endByte ? undefined : Math.max(endByte - bytesFetched, 0)
|
||||||
|
|
||||||
push(bytes.slice(start, end))
|
push(bytes.slice(start, end))
|
||||||
|
|
||||||
@@ -568,7 +568,7 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger }: C
|
|||||||
result = error.response?.data
|
result = error.response?.data
|
||||||
}
|
}
|
||||||
|
|
||||||
const isLast = hostname === hosts[uploadInfo.hosts.length-1]?.hostname
|
const isLast = hostname === hosts[uploadInfo.hosts.length - 1]?.hostname
|
||||||
logger.warn({ trace: error.stack, uploadResult: result }, `Error in uploading to ${hostname} ${isLast ? '' : ', retrying...'}`)
|
logger.warn({ trace: error.stack, uploadResult: result }, `Error in uploading to ${hostname} ${isLast ? '' : ', retrying...'}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ export const makeNoiseHandler = ({ public: publicKey, private: privateKey }: Key
|
|||||||
const cipher = createDecipheriv('aes-256-gcm', decKey, iv)
|
const cipher = createDecipheriv('aes-256-gcm', decKey, iv)
|
||||||
// decrypt additional adata
|
// decrypt additional adata
|
||||||
const tagLength = 128 >> 3
|
const tagLength = 128 >> 3
|
||||||
const enc = ciphertext.slice(0, ciphertext.length-tagLength)
|
const enc = ciphertext.slice(0, ciphertext.length - tagLength)
|
||||||
const tag = ciphertext.slice(ciphertext.length-tagLength)
|
const tag = ciphertext.slice(ciphertext.length - tagLength)
|
||||||
// set additional data
|
// set additional data
|
||||||
cipher.setAAD(hash)
|
cipher.setAAD(hash)
|
||||||
cipher.setAuthTag(tag)
|
cipher.setAuthTag(tag)
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ const encode = ({ tag, attrs, content }: BinaryNode, buffer: number[] = []) => {
|
|||||||
|
|
||||||
const pushByte = (value: number) => buffer.push(value & 0xff)
|
const pushByte = (value: number) => buffer.push(value & 0xff)
|
||||||
|
|
||||||
const pushInt = (value: number, n: number, littleEndian=false) => {
|
const pushInt = (value: number, n: number, littleEndian = false) => {
|
||||||
for(let i = 0; i < n; i++) {
|
for(let i = 0; i < n; i++) {
|
||||||
const curShift = littleEndian ? i : n - 1 - i
|
const curShift = littleEndian ? i : n - 1 - i
|
||||||
buffer.push((value >> (curShift * 8)) & 0xff)
|
buffer.push((value >> (curShift * 8)) & 0xff)
|
||||||
@@ -341,7 +341,7 @@ const encode = ({ tag, attrs, content }: BinaryNode, buffer: number[] = []) => {
|
|||||||
typeof attrs[k] !== 'undefined' && attrs[k] !== null
|
typeof attrs[k] !== 'undefined' && attrs[k] !== null
|
||||||
))
|
))
|
||||||
|
|
||||||
writeListStart(2*validAttributes.length + 1 + (typeof content !== 'undefined' && content !== null ? 1 : 0))
|
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' && content !== null ? 1 : 0))
|
||||||
writeString(tag)
|
writeString(tag)
|
||||||
|
|
||||||
validAttributes.forEach((key) => {
|
validAttributes.forEach((key) => {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export const jidDecode = (jid: string) => {
|
|||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
const server = jid.slice(sepIdx+1)
|
const server = jid.slice(sepIdx + 1)
|
||||||
const userCombined = jid.slice(0, sepIdx)
|
const userCombined = jid.slice(0, sepIdx)
|
||||||
|
|
||||||
const [userAgent, device] = userCombined.split(':')
|
const [userAgent, device] = userCombined.split(':')
|
||||||
|
|||||||
46
yarn.lock
46
yarn.lock
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
"@adiwajshing/eslint-config@git+https://github.com/adiwajshing/eslint-config":
|
"@adiwajshing/eslint-config@git+https://github.com/adiwajshing/eslint-config":
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "git+https://github.com/adiwajshing/eslint-config#db16c7427bd6dcf8fba20e0aaa526724e46c83aa"
|
resolved "git+https://github.com/adiwajshing/eslint-config#ee2b90dba10bc161d85745be59217efa10bc1eb3"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@typescript-eslint/eslint-plugin" "^4.33.0"
|
"@typescript-eslint/eslint-plugin" "^4.33.0"
|
||||||
"@typescript-eslint/parser" "^4.33.0"
|
"@typescript-eslint/parser" "^4.33.0"
|
||||||
@@ -1800,14 +1800,14 @@ data-urls@^2.0.0:
|
|||||||
whatwg-mimetype "^2.3.0"
|
whatwg-mimetype "^2.3.0"
|
||||||
whatwg-url "^8.0.0"
|
whatwg-url "^8.0.0"
|
||||||
|
|
||||||
debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1:
|
debug@4, debug@^4.1.0, debug@^4.1.1:
|
||||||
version "4.3.2"
|
version "4.3.2"
|
||||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.2.tgz#f0a49c18ac8779e31d4a0c6029dfb76873c7428b"
|
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.2.tgz#f0a49c18ac8779e31d4a0c6029dfb76873c7428b"
|
||||||
integrity sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==
|
integrity sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==
|
||||||
dependencies:
|
dependencies:
|
||||||
ms "2.1.2"
|
ms "2.1.2"
|
||||||
|
|
||||||
debug@^4.0.1:
|
debug@^4.0.1, debug@^4.3.1:
|
||||||
version "4.3.3"
|
version "4.3.3"
|
||||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
|
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
|
||||||
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
|
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
|
||||||
@@ -2033,21 +2033,21 @@ escodegen@^2.0.0:
|
|||||||
source-map "~0.6.1"
|
source-map "~0.6.1"
|
||||||
|
|
||||||
eslint-plugin-react@^7.26.1:
|
eslint-plugin-react@^7.26.1:
|
||||||
version "7.28.0"
|
version "7.29.2"
|
||||||
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.28.0.tgz#8f3ff450677571a659ce76efc6d80b6a525adbdf"
|
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.29.2.tgz#2d4da69d30d0a736efd30890dc6826f3e91f3f7c"
|
||||||
integrity sha512-IOlFIRHzWfEQQKcAD4iyYDndHwTQiCMcJVJjxempf203jnNLUnW34AXLrV33+nEXoifJE2ZEGmcjKPL8957eSw==
|
integrity sha512-ypEBTKOy5liFQXZWMchJ3LN0JX1uPI6n7MN7OPHKacqXAxq5gYC30TdO7wqGYQyxD1OrzpobdHC3hDmlRWDg9w==
|
||||||
dependencies:
|
dependencies:
|
||||||
array-includes "^3.1.4"
|
array-includes "^3.1.4"
|
||||||
array.prototype.flatmap "^1.2.5"
|
array.prototype.flatmap "^1.2.5"
|
||||||
doctrine "^2.1.0"
|
doctrine "^2.1.0"
|
||||||
estraverse "^5.3.0"
|
estraverse "^5.3.0"
|
||||||
jsx-ast-utils "^2.4.1 || ^3.0.0"
|
jsx-ast-utils "^2.4.1 || ^3.0.0"
|
||||||
minimatch "^3.0.4"
|
minimatch "^3.1.2"
|
||||||
object.entries "^1.1.5"
|
object.entries "^1.1.5"
|
||||||
object.fromentries "^2.0.5"
|
object.fromentries "^2.0.5"
|
||||||
object.hasown "^1.1.0"
|
object.hasown "^1.1.0"
|
||||||
object.values "^1.1.5"
|
object.values "^1.1.5"
|
||||||
prop-types "^15.7.2"
|
prop-types "^15.8.1"
|
||||||
resolve "^2.0.0-next.3"
|
resolve "^2.0.0-next.3"
|
||||||
semver "^6.3.0"
|
semver "^6.3.0"
|
||||||
string.prototype.matchall "^4.0.6"
|
string.prototype.matchall "^4.0.6"
|
||||||
@@ -2180,16 +2180,11 @@ estraverse@^4.1.1:
|
|||||||
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.3.0.tgz#398ad3f3c5a24948be7725e83d11a7de28cdbd1d"
|
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.3.0.tgz#398ad3f3c5a24948be7725e83d11a7de28cdbd1d"
|
||||||
integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==
|
integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==
|
||||||
|
|
||||||
estraverse@^5.1.0, estraverse@^5.3.0:
|
estraverse@^5.1.0, estraverse@^5.2.0, estraverse@^5.3.0:
|
||||||
version "5.3.0"
|
version "5.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.3.0.tgz#2eea5290702f26ab8fe5370370ff86c965d21123"
|
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.3.0.tgz#2eea5290702f26ab8fe5370370ff86c965d21123"
|
||||||
integrity sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==
|
integrity sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==
|
||||||
|
|
||||||
estraverse@^5.2.0:
|
|
||||||
version "5.2.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.2.0.tgz#307df42547e6cc7324d3cf03c155d5cdb8c53880"
|
|
||||||
integrity sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==
|
|
||||||
|
|
||||||
esutils@^2.0.2:
|
esutils@^2.0.2:
|
||||||
version "2.0.3"
|
version "2.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
|
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
|
||||||
@@ -2680,9 +2675,9 @@ is-ci@^3.0.0:
|
|||||||
ci-info "^3.1.1"
|
ci-info "^3.1.1"
|
||||||
|
|
||||||
is-core-module@^2.2.0:
|
is-core-module@^2.2.0:
|
||||||
version "2.5.0"
|
version "2.8.1"
|
||||||
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.5.0.tgz#f754843617c70bfd29b7bd87327400cda5c18491"
|
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.8.1.tgz#f59fdfca701d5879d0a6b100a40aa1560ce27211"
|
||||||
integrity sha512-TXCMSDsEHMEEZ6eCA8rwRDbLu55MRGmrctljsBX/2v1d9/GzqHOxW5c5oPSgrUt2vBFXebu9rGqckXGPWOlYpg==
|
integrity sha512-SdNCUs284hr40hFTFP6l0IfZ/RSrMXF3qgoRHd3/79unUTvrFO/JoXwkGm+5J/Oe3E/b5GsnG330uUNgRpu1PA==
|
||||||
dependencies:
|
dependencies:
|
||||||
has "^1.0.3"
|
has "^1.0.3"
|
||||||
|
|
||||||
@@ -3544,10 +3539,10 @@ min-document@^2.19.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
dom-walk "^0.1.0"
|
dom-walk "^0.1.0"
|
||||||
|
|
||||||
minimatch@^3.0.4:
|
minimatch@^3.0.4, minimatch@^3.1.2:
|
||||||
version "3.0.4"
|
version "3.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
|
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
|
||||||
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
|
integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==
|
||||||
dependencies:
|
dependencies:
|
||||||
brace-expansion "^1.1.7"
|
brace-expansion "^1.1.7"
|
||||||
|
|
||||||
@@ -3873,11 +3868,16 @@ phin@^2.9.1:
|
|||||||
resolved "https://registry.yarnpkg.com/phin/-/phin-2.9.3.tgz#f9b6ac10a035636fb65dfc576aaaa17b8743125c"
|
resolved "https://registry.yarnpkg.com/phin/-/phin-2.9.3.tgz#f9b6ac10a035636fb65dfc576aaaa17b8743125c"
|
||||||
integrity sha512-CzFr90qM24ju5f88quFC/6qohjC144rehe5n6DH900lgXmUe86+xCKc10ev56gRKC4/BkHUoG4uSiQgBiIXwDA==
|
integrity sha512-CzFr90qM24ju5f88quFC/6qohjC144rehe5n6DH900lgXmUe86+xCKc10ev56gRKC4/BkHUoG4uSiQgBiIXwDA==
|
||||||
|
|
||||||
picomatch@^2.0.4, picomatch@^2.2.3:
|
picomatch@^2.0.4:
|
||||||
version "2.3.0"
|
version "2.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.0.tgz#f1f061de8f6a4bf022892e2d128234fb98302972"
|
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.0.tgz#f1f061de8f6a4bf022892e2d128234fb98302972"
|
||||||
integrity sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==
|
integrity sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==
|
||||||
|
|
||||||
|
picomatch@^2.2.3:
|
||||||
|
version "2.3.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
|
||||||
|
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
|
||||||
|
|
||||||
pino-abstract-transport@v0.5.0:
|
pino-abstract-transport@v0.5.0:
|
||||||
version "0.5.0"
|
version "0.5.0"
|
||||||
resolved "https://registry.yarnpkg.com/pino-abstract-transport/-/pino-abstract-transport-0.5.0.tgz#4b54348d8f73713bfd14e3dc44228739aa13d9c0"
|
resolved "https://registry.yarnpkg.com/pino-abstract-transport/-/pino-abstract-transport-0.5.0.tgz#4b54348d8f73713bfd14e3dc44228739aa13d9c0"
|
||||||
@@ -4010,7 +4010,7 @@ prompts@^2.0.1:
|
|||||||
kleur "^3.0.3"
|
kleur "^3.0.3"
|
||||||
sisteransi "^1.0.5"
|
sisteransi "^1.0.5"
|
||||||
|
|
||||||
prop-types@^15.7.2:
|
prop-types@^15.8.1:
|
||||||
version "15.8.1"
|
version "15.8.1"
|
||||||
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
|
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
|
||||||
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
|
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
|
||||||
|
|||||||
Reference in New Issue
Block a user