@sixcore/baileys 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/index.js +14270 -302
- package/jessica.js +91 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +117 -79
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
- package/lib/Signal/libsignal.js +51 -29
- package/lib/Socket/business.d.ts +43 -42
- package/lib/Socket/chats.d.ts +222 -36
- package/lib/Socket/chats.js +173 -153
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +7 -7
- package/lib/Socket/groups.js +37 -35
- package/lib/Socket/index.d.ts +52 -51
- package/lib/Socket/index.js +1 -0
- package/lib/Socket/messages-recv.d.ts +37 -34
- package/lib/Socket/messages-recv.js +175 -37
- package/lib/Socket/messages-send.d.ts +12 -18
- package/lib/Socket/messages-send.js +396 -574
- package/lib/Socket/newsletter.d.ts +28 -26
- package/lib/Socket/newsletter.js +132 -121
- package/lib/Socket/registration.d.ts +52 -49
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.d.ts +0 -1
- package/lib/Socket/socket.js +49 -27
- package/lib/Socket/usync.d.ts +10 -11
- package/lib/Store/make-cache-manager-store.d.ts +1 -2
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Store/make-in-memory-store.js +1 -5
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -12
- package/lib/Types/Events.d.ts +2 -17
- package/lib/Types/GroupMetadata.d.ts +2 -3
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +10 -170
- package/lib/Types/Newsletter.d.ts +97 -86
- package/lib/Types/Newsletter.js +38 -32
- package/lib/Types/Socket.d.ts +2 -7
- package/lib/Types/index.d.ts +0 -9
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +14 -35
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +12 -11
- package/lib/Utils/chat-utils.js +36 -52
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +26 -74
- package/lib/Utils/decode-wa-message.d.ts +0 -17
- package/lib/Utils/decode-wa-message.js +17 -53
- package/lib/Utils/event-buffer.js +7 -10
- package/lib/Utils/generics.d.ts +17 -13
- package/lib/Utils/generics.js +79 -58
- package/lib/Utils/history.d.ts +2 -6
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/logger.d.ts +3 -1
- package/lib/Utils/lt-hash.js +12 -12
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +28 -25
- package/lib/Utils/messages-media.js +733 -557
- package/lib/Utils/messages.js +68 -473
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/noise-handler.js +14 -19
- package/lib/Utils/process-message.d.ts +5 -5
- package/lib/Utils/process-message.js +23 -75
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +26 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +66 -242
- package/lib/Utils/validate-connection.d.ts +1 -1
- package/lib/Utils/validate-connection.js +88 -64
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.js +11 -23
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +147 -134
- package/lib/WABinary/generic-utils.d.ts +5 -2
- package/lib/WABinary/generic-utils.js +125 -37
- package/lib/WABinary/jid-utils.d.ts +1 -1
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +64 -1
- package/package.json +113 -51
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -4357
- package/WAProto/index.d.ts +0 -50383
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/generate-proto.sh +0 -1
- package/WASignalGroup/group.proto +0 -42
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
- package/lib/Utils/use-single-file-auth-state.js +0 -75
- package/src/Defaults/baileys-version.json +0 -3
- package/src/Defaults/index.ts +0 -133
- package/src/Signal/Group/ciphertext-message.ts +0 -9
- package/src/Signal/Group/group-session-builder.ts +0 -56
- package/src/Signal/Group/group_cipher.ts +0 -117
- package/src/Signal/Group/index.ts +0 -11
- package/src/Signal/Group/keyhelper.ts +0 -28
- package/src/Signal/Group/sender-chain-key.ts +0 -34
- package/src/Signal/Group/sender-key-distribution-message.ts +0 -95
- package/src/Signal/Group/sender-key-message.ts +0 -96
- package/src/Signal/Group/sender-key-name.ts +0 -66
- package/src/Signal/Group/sender-key-record.ts +0 -69
- package/src/Signal/Group/sender-key-state.ts +0 -134
- package/src/Signal/Group/sender-message-key.ts +0 -36
- package/src/Signal/libsignal.ts +0 -447
- package/src/Signal/lid-mapping.ts +0 -209
- package/src/Socket/Client/index.ts +0 -2
- package/src/Socket/Client/types.ts +0 -22
- package/src/Socket/Client/websocket.ts +0 -56
- package/src/Socket/business.ts +0 -421
- package/src/Socket/chats.ts +0 -1223
- package/src/Socket/communities.ts +0 -477
- package/src/Socket/groups.ts +0 -361
- package/src/Socket/index.ts +0 -22
- package/src/Socket/messages-recv.ts +0 -1563
- package/src/Socket/messages-send.ts +0 -1210
- package/src/Socket/mex.ts +0 -58
- package/src/Socket/newsletter.ts +0 -229
- package/src/Socket/socket.ts +0 -1072
- package/src/Types/Auth.ts +0 -115
- package/src/Types/Bussines.ts +0 -20
- package/src/Types/Call.ts +0 -14
- package/src/Types/Chat.ts +0 -138
- package/src/Types/Contact.ts +0 -24
- package/src/Types/Events.ts +0 -132
- package/src/Types/GroupMetadata.ts +0 -70
- package/src/Types/Label.ts +0 -48
- package/src/Types/LabelAssociation.ts +0 -35
- package/src/Types/Message.ts +0 -424
- package/src/Types/Newsletter.ts +0 -98
- package/src/Types/Product.ts +0 -85
- package/src/Types/Signal.ts +0 -76
- package/src/Types/Socket.ts +0 -150
- package/src/Types/State.ts +0 -43
- package/src/Types/USync.ts +0 -27
- package/src/Types/globals.d.ts +0 -8
- package/src/Types/index.ts +0 -67
- package/src/Utils/auth-utils.ts +0 -331
- package/src/Utils/browser-utils.ts +0 -31
- package/src/Utils/business.ts +0 -286
- package/src/Utils/chat-utils.ts +0 -933
- package/src/Utils/crypto.ts +0 -184
- package/src/Utils/decode-wa-message.ts +0 -355
- package/src/Utils/event-buffer.ts +0 -662
- package/src/Utils/generics.ts +0 -470
- package/src/Utils/history.ts +0 -114
- package/src/Utils/index.ts +0 -18
- package/src/Utils/link-preview.ts +0 -111
- package/src/Utils/logger.ts +0 -13
- package/src/Utils/lt-hash.ts +0 -65
- package/src/Utils/make-mutex.ts +0 -45
- package/src/Utils/message-retry-manager.ts +0 -229
- package/src/Utils/messages-media.ts +0 -820
- package/src/Utils/messages.ts +0 -1137
- package/src/Utils/noise-handler.ts +0 -192
- package/src/Utils/pre-key-manager.ts +0 -126
- package/src/Utils/process-message.ts +0 -622
- package/src/Utils/signal.ts +0 -214
- package/src/Utils/use-multi-file-auth-state.ts +0 -136
- package/src/Utils/validate-connection.ts +0 -253
- package/src/WABinary/constants.ts +0 -1305
- package/src/WABinary/decode.ts +0 -281
- package/src/WABinary/encode.ts +0 -253
- package/src/WABinary/generic-utils.ts +0 -127
- package/src/WABinary/index.ts +0 -5
- package/src/WABinary/jid-utils.ts +0 -128
- package/src/WABinary/types.ts +0 -17
- package/src/WAM/BinaryInfo.ts +0 -12
- package/src/WAM/constants.ts +0 -22889
- package/src/WAM/encode.ts +0 -169
- package/src/WAM/index.ts +0 -3
- package/src/WAUSync/Protocols/USyncContactProtocol.ts +0 -32
- package/src/WAUSync/Protocols/USyncDeviceProtocol.ts +0 -78
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.ts +0 -35
- package/src/WAUSync/Protocols/USyncStatusProtocol.ts +0 -44
- package/src/WAUSync/Protocols/UsyncBotProfileProtocol.ts +0 -76
- package/src/WAUSync/Protocols/UsyncLIDProtocol.ts +0 -33
- package/src/WAUSync/Protocols/index.ts +0 -4
- package/src/WAUSync/USyncQuery.ts +0 -133
- package/src/WAUSync/USyncUser.ts +0 -32
- package/src/WAUSync/index.ts +0 -3
- package/src/index.ts +0 -13
package/src/WAM/encode.ts
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { BinaryInfo } from './BinaryInfo'
|
|
2
|
-
import {
|
|
3
|
-
FLAG_BYTE,
|
|
4
|
-
FLAG_EVENT,
|
|
5
|
-
FLAG_EXTENDED,
|
|
6
|
-
FLAG_FIELD,
|
|
7
|
-
FLAG_GLOBAL,
|
|
8
|
-
type Value,
|
|
9
|
-
WEB_EVENTS,
|
|
10
|
-
WEB_GLOBALS
|
|
11
|
-
} from './constants'
|
|
12
|
-
|
|
13
|
-
const getHeaderBitLength = (key: number) => (key < 256 ? 2 : 3)
|
|
14
|
-
|
|
15
|
-
export const encodeWAM = (binaryInfo: BinaryInfo) => {
|
|
16
|
-
binaryInfo.buffer = []
|
|
17
|
-
|
|
18
|
-
encodeWAMHeader(binaryInfo)
|
|
19
|
-
encodeEvents(binaryInfo)
|
|
20
|
-
|
|
21
|
-
const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b)
|
|
22
|
-
const buffer = Buffer.alloc(totalSize)
|
|
23
|
-
let offset = 0
|
|
24
|
-
for (const buffer_ of binaryInfo.buffer) {
|
|
25
|
-
buffer_.copy(buffer, offset)
|
|
26
|
-
offset += buffer_.length
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return buffer
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function encodeWAMHeader(binaryInfo: BinaryInfo) {
|
|
33
|
-
const headerBuffer = Buffer.alloc(8) // starting buffer
|
|
34
|
-
headerBuffer.write('WAM', 0, 'utf8')
|
|
35
|
-
headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3)
|
|
36
|
-
headerBuffer.writeUInt8(1, 4) //random flag
|
|
37
|
-
headerBuffer.writeUInt16BE(binaryInfo.sequence, 5)
|
|
38
|
-
headerBuffer.writeUInt8(0, 7) // regular channel
|
|
39
|
-
|
|
40
|
-
binaryInfo.buffer.push(headerBuffer)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function encodeGlobalAttributes(binaryInfo: BinaryInfo, globals: { [key: string]: Value }) {
|
|
44
|
-
for (const [key, _value] of Object.entries(globals)) {
|
|
45
|
-
const id = WEB_GLOBALS.find(a => a?.name === key)!.id
|
|
46
|
-
let value = _value
|
|
47
|
-
if (typeof value === 'boolean') {
|
|
48
|
-
value = value ? 1 : 0
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL))
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function encodeEvents(binaryInfo: BinaryInfo) {
|
|
56
|
-
for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0]!)) {
|
|
57
|
-
encodeGlobalAttributes(binaryInfo, globals)
|
|
58
|
-
const event = WEB_EVENTS.find(a => a.name === name)!
|
|
59
|
-
|
|
60
|
-
const props_ = Object.entries(props)
|
|
61
|
-
|
|
62
|
-
let extended = false
|
|
63
|
-
|
|
64
|
-
for (const [, value] of props_) {
|
|
65
|
-
extended ||= value !== null
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED
|
|
69
|
-
binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag))
|
|
70
|
-
|
|
71
|
-
for (let i = 0; i < props_.length; i++) {
|
|
72
|
-
const [key, _value] = props_[i]!
|
|
73
|
-
const id = event.props[key]?.[0]
|
|
74
|
-
extended = i < props_.length - 1
|
|
75
|
-
let value = _value
|
|
76
|
-
if (typeof value === 'boolean') {
|
|
77
|
-
value = value ? 1 : 0
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED
|
|
81
|
-
binaryInfo.buffer.push(serializeData(id!, value, fieldFlag))
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function serializeData(key: number, value: Value, flag: number): Buffer {
|
|
87
|
-
const bufferLength = getHeaderBitLength(key)
|
|
88
|
-
let buffer: Buffer
|
|
89
|
-
let offset = 0
|
|
90
|
-
if (value === null) {
|
|
91
|
-
if (flag === FLAG_GLOBAL) {
|
|
92
|
-
buffer = Buffer.alloc(bufferLength)
|
|
93
|
-
offset = serializeHeader(buffer, offset, key, flag)
|
|
94
|
-
return buffer
|
|
95
|
-
}
|
|
96
|
-
} else if (typeof value === 'number' && Number.isInteger(value)) {
|
|
97
|
-
// is number
|
|
98
|
-
if (value === 0 || value === 1) {
|
|
99
|
-
buffer = Buffer.alloc(bufferLength)
|
|
100
|
-
offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4))
|
|
101
|
-
return buffer
|
|
102
|
-
} else if (-128 <= value && value < 128) {
|
|
103
|
-
buffer = Buffer.alloc(bufferLength + 1)
|
|
104
|
-
offset = serializeHeader(buffer, offset, key, flag | (3 << 4))
|
|
105
|
-
buffer.writeInt8(value, offset)
|
|
106
|
-
return buffer
|
|
107
|
-
} else if (-32768 <= value && value < 32768) {
|
|
108
|
-
buffer = Buffer.alloc(bufferLength + 2)
|
|
109
|
-
offset = serializeHeader(buffer, offset, key, flag | (4 << 4))
|
|
110
|
-
buffer.writeInt16LE(value, offset)
|
|
111
|
-
return buffer
|
|
112
|
-
} else if (-2147483648 <= value && value < 2147483648) {
|
|
113
|
-
buffer = Buffer.alloc(bufferLength + 4)
|
|
114
|
-
offset = serializeHeader(buffer, offset, key, flag | (5 << 4))
|
|
115
|
-
buffer.writeInt32LE(value, offset)
|
|
116
|
-
return buffer
|
|
117
|
-
} else {
|
|
118
|
-
buffer = Buffer.alloc(bufferLength + 8)
|
|
119
|
-
offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
|
|
120
|
-
buffer.writeDoubleLE(value, offset)
|
|
121
|
-
return buffer
|
|
122
|
-
}
|
|
123
|
-
} else if (typeof value === 'number') {
|
|
124
|
-
// is float
|
|
125
|
-
buffer = Buffer.alloc(bufferLength + 8)
|
|
126
|
-
offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
|
|
127
|
-
buffer.writeDoubleLE(value, offset)
|
|
128
|
-
return buffer
|
|
129
|
-
} else if (typeof value === 'string') {
|
|
130
|
-
// is string
|
|
131
|
-
const utf8Bytes = Buffer.byteLength(value, 'utf8')
|
|
132
|
-
if (utf8Bytes < 256) {
|
|
133
|
-
buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes)
|
|
134
|
-
offset = serializeHeader(buffer, offset, key, flag | (8 << 4))
|
|
135
|
-
buffer.writeUint8(utf8Bytes, offset++)
|
|
136
|
-
} else if (utf8Bytes < 65536) {
|
|
137
|
-
buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes)
|
|
138
|
-
offset = serializeHeader(buffer, offset, key, flag | (9 << 4))
|
|
139
|
-
buffer.writeUInt16LE(utf8Bytes, offset)
|
|
140
|
-
offset += 2
|
|
141
|
-
} else {
|
|
142
|
-
buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes)
|
|
143
|
-
offset = serializeHeader(buffer, offset, key, flag | (10 << 4))
|
|
144
|
-
buffer.writeUInt32LE(utf8Bytes, offset)
|
|
145
|
-
offset += 4
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
buffer.write(value, offset, 'utf8')
|
|
149
|
-
return buffer
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
throw 'missing'
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function serializeHeader(buffer: Buffer, offset: number, key: number, flag: number) {
|
|
156
|
-
if (key < 256) {
|
|
157
|
-
buffer.writeUInt8(flag, offset)
|
|
158
|
-
offset += 1
|
|
159
|
-
buffer.writeUInt8(key, offset)
|
|
160
|
-
offset += 1
|
|
161
|
-
} else {
|
|
162
|
-
buffer.writeUInt8(flag | FLAG_BYTE, offset)
|
|
163
|
-
offset += 1
|
|
164
|
-
buffer.writeUInt16LE(key, offset)
|
|
165
|
-
offset += 2
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return offset
|
|
169
|
-
}
|
package/src/WAM/index.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { USyncQueryProtocol } from '../../Types/USync'
|
|
2
|
-
import { assertNodeErrorFree, type BinaryNode } from '../../WABinary'
|
|
3
|
-
import { USyncUser } from '../USyncUser'
|
|
4
|
-
|
|
5
|
-
export class USyncContactProtocol implements USyncQueryProtocol {
|
|
6
|
-
name = 'contact'
|
|
7
|
-
|
|
8
|
-
getQueryElement(): BinaryNode {
|
|
9
|
-
return {
|
|
10
|
-
tag: 'contact',
|
|
11
|
-
attrs: {}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
getUserElement(user: USyncUser): BinaryNode {
|
|
16
|
-
//TODO: Implement type / username fields (not yet supported)
|
|
17
|
-
return {
|
|
18
|
-
tag: 'contact',
|
|
19
|
-
attrs: {},
|
|
20
|
-
content: user.phone
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
parser(node: BinaryNode): boolean {
|
|
25
|
-
if (node.tag === 'contact') {
|
|
26
|
-
assertNodeErrorFree(node)
|
|
27
|
-
return node?.attrs?.type === 'in'
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return false
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { USyncQueryProtocol } from '../../Types/USync'
|
|
2
|
-
import { assertNodeErrorFree, type BinaryNode, getBinaryNodeChild } from '../../WABinary'
|
|
3
|
-
//import { USyncUser } from '../USyncUser'
|
|
4
|
-
|
|
5
|
-
export type KeyIndexData = {
|
|
6
|
-
timestamp: number
|
|
7
|
-
signedKeyIndex?: Uint8Array
|
|
8
|
-
expectedTimestamp?: number
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type DeviceListData = {
|
|
12
|
-
id: number
|
|
13
|
-
keyIndex?: number
|
|
14
|
-
isHosted?: boolean
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type ParsedDeviceInfo = {
|
|
18
|
-
deviceList?: DeviceListData[]
|
|
19
|
-
keyIndex?: KeyIndexData
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class USyncDeviceProtocol implements USyncQueryProtocol {
|
|
23
|
-
name = 'devices'
|
|
24
|
-
|
|
25
|
-
getQueryElement(): BinaryNode {
|
|
26
|
-
return {
|
|
27
|
-
tag: 'devices',
|
|
28
|
-
attrs: {
|
|
29
|
-
version: '2'
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getUserElement(/* user: USyncUser */): BinaryNode | null {
|
|
35
|
-
//TODO: Implement device phashing, ts and expectedTs
|
|
36
|
-
//TODO: if all are not present, return null <- current behavior
|
|
37
|
-
//TODO: otherwise return a node w tag 'devices' w those as attrs
|
|
38
|
-
return null
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
parser(node: BinaryNode): ParsedDeviceInfo {
|
|
42
|
-
const deviceList: DeviceListData[] = []
|
|
43
|
-
let keyIndex: KeyIndexData | undefined = undefined
|
|
44
|
-
|
|
45
|
-
if (node.tag === 'devices') {
|
|
46
|
-
assertNodeErrorFree(node)
|
|
47
|
-
const deviceListNode = getBinaryNodeChild(node, 'device-list')
|
|
48
|
-
const keyIndexNode = getBinaryNodeChild(node, 'key-index-list')
|
|
49
|
-
|
|
50
|
-
if (Array.isArray(deviceListNode?.content)) {
|
|
51
|
-
for (const { tag, attrs } of deviceListNode.content) {
|
|
52
|
-
const id = +attrs.id!
|
|
53
|
-
const keyIndex = +attrs['key-index']!
|
|
54
|
-
if (tag === 'device') {
|
|
55
|
-
deviceList.push({
|
|
56
|
-
id,
|
|
57
|
-
keyIndex,
|
|
58
|
-
isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (keyIndexNode?.tag === 'key-index-list') {
|
|
65
|
-
keyIndex = {
|
|
66
|
-
timestamp: +keyIndexNode.attrs['ts']!,
|
|
67
|
-
signedKeyIndex: keyIndexNode?.content as Uint8Array,
|
|
68
|
-
expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
deviceList,
|
|
75
|
-
keyIndex
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { USyncQueryProtocol } from '../../Types/USync'
|
|
2
|
-
import { assertNodeErrorFree, type BinaryNode } from '../../WABinary'
|
|
3
|
-
|
|
4
|
-
export type DisappearingModeData = {
|
|
5
|
-
duration: number
|
|
6
|
-
setAt?: Date
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class USyncDisappearingModeProtocol implements USyncQueryProtocol {
|
|
10
|
-
name = 'disappearing_mode'
|
|
11
|
-
|
|
12
|
-
getQueryElement(): BinaryNode {
|
|
13
|
-
return {
|
|
14
|
-
tag: 'disappearing_mode',
|
|
15
|
-
attrs: {}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
getUserElement(): null {
|
|
20
|
-
return null
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
parser(node: BinaryNode): DisappearingModeData | undefined {
|
|
24
|
-
if (node.tag === 'disappearing_mode') {
|
|
25
|
-
assertNodeErrorFree(node)
|
|
26
|
-
const duration: number = +node?.attrs.duration!
|
|
27
|
-
const setAt = new Date(+(node?.attrs.t || 0) * 1000)
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
duration,
|
|
31
|
-
setAt
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { USyncQueryProtocol } from '../../Types/USync'
|
|
2
|
-
import { assertNodeErrorFree, type BinaryNode } from '../../WABinary'
|
|
3
|
-
|
|
4
|
-
export type StatusData = {
|
|
5
|
-
status?: string | null
|
|
6
|
-
setAt?: Date
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class USyncStatusProtocol implements USyncQueryProtocol {
|
|
10
|
-
name = 'status'
|
|
11
|
-
|
|
12
|
-
getQueryElement(): BinaryNode {
|
|
13
|
-
return {
|
|
14
|
-
tag: 'status',
|
|
15
|
-
attrs: {}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
getUserElement(): null {
|
|
20
|
-
return null
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
parser(node: BinaryNode): StatusData | undefined {
|
|
24
|
-
if (node.tag === 'status') {
|
|
25
|
-
assertNodeErrorFree(node)
|
|
26
|
-
let status: string | null = node?.content?.toString() ?? null
|
|
27
|
-
const setAt = new Date(+(node?.attrs.t || 0) * 1000)
|
|
28
|
-
if (!status) {
|
|
29
|
-
if (node.attrs?.code && +node.attrs.code === 401) {
|
|
30
|
-
status = ''
|
|
31
|
-
} else {
|
|
32
|
-
status = null
|
|
33
|
-
}
|
|
34
|
-
} else if (typeof status === 'string' && status.length === 0) {
|
|
35
|
-
status = null
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
status,
|
|
40
|
-
setAt
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { USyncQueryProtocol } from '../../Types/USync'
|
|
2
|
-
import { type BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString } from '../../WABinary'
|
|
3
|
-
import { USyncUser } from '../USyncUser'
|
|
4
|
-
|
|
5
|
-
export type BotProfileCommand = {
|
|
6
|
-
name: string
|
|
7
|
-
description: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type BotProfileInfo = {
|
|
11
|
-
jid: string
|
|
12
|
-
name: string
|
|
13
|
-
attributes: string
|
|
14
|
-
description: string
|
|
15
|
-
category: string
|
|
16
|
-
isDefault: boolean
|
|
17
|
-
prompts: string[]
|
|
18
|
-
personaId: string
|
|
19
|
-
commands: BotProfileCommand[]
|
|
20
|
-
commandsDescription: string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class USyncBotProfileProtocol implements USyncQueryProtocol {
|
|
24
|
-
name = 'bot'
|
|
25
|
-
|
|
26
|
-
getQueryElement(): BinaryNode {
|
|
27
|
-
return {
|
|
28
|
-
tag: 'bot',
|
|
29
|
-
attrs: {},
|
|
30
|
-
content: [{ tag: 'profile', attrs: { v: '1' } }]
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getUserElement(user: USyncUser): BinaryNode {
|
|
35
|
-
return {
|
|
36
|
-
tag: 'bot',
|
|
37
|
-
attrs: {},
|
|
38
|
-
content: [{ tag: 'profile', attrs: { persona_id: user.personaId! } }]
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
parser(node: BinaryNode): BotProfileInfo {
|
|
43
|
-
const botNode = getBinaryNodeChild(node, 'bot')
|
|
44
|
-
const profile = getBinaryNodeChild(botNode, 'profile')
|
|
45
|
-
|
|
46
|
-
const commandsNode = getBinaryNodeChild(profile, 'commands')
|
|
47
|
-
const promptsNode = getBinaryNodeChild(profile, 'prompts')
|
|
48
|
-
|
|
49
|
-
const commands: BotProfileCommand[] = []
|
|
50
|
-
const prompts: string[] = []
|
|
51
|
-
|
|
52
|
-
for (const command of getBinaryNodeChildren(commandsNode, 'command')) {
|
|
53
|
-
commands.push({
|
|
54
|
-
name: getBinaryNodeChildString(command, 'name')!,
|
|
55
|
-
description: getBinaryNodeChildString(command, 'description')!
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
for (const prompt of getBinaryNodeChildren(promptsNode, 'prompt')) {
|
|
60
|
-
prompts.push(`${getBinaryNodeChildString(prompt, 'emoji')!} ${getBinaryNodeChildString(prompt, 'text')!}`)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
isDefault: !!getBinaryNodeChild(profile, 'default'),
|
|
65
|
-
jid: node.attrs.jid!,
|
|
66
|
-
name: getBinaryNodeChildString(profile, 'name')!,
|
|
67
|
-
attributes: getBinaryNodeChildString(profile, 'attributes')!,
|
|
68
|
-
description: getBinaryNodeChildString(profile, 'description')!,
|
|
69
|
-
category: getBinaryNodeChildString(profile, 'category')!,
|
|
70
|
-
personaId: profile!.attrs['persona_id']!,
|
|
71
|
-
commandsDescription: getBinaryNodeChildString(commandsNode, 'description')!,
|
|
72
|
-
commands,
|
|
73
|
-
prompts
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { USyncQueryProtocol } from '../../Types/USync'
|
|
2
|
-
import type { BinaryNode } from '../../WABinary'
|
|
3
|
-
import type { USyncUser } from '../USyncUser'
|
|
4
|
-
|
|
5
|
-
export class USyncLIDProtocol implements USyncQueryProtocol {
|
|
6
|
-
name = 'lid'
|
|
7
|
-
|
|
8
|
-
getQueryElement(): BinaryNode {
|
|
9
|
-
return {
|
|
10
|
-
tag: 'lid',
|
|
11
|
-
attrs: {}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
getUserElement(user: USyncUser): BinaryNode | null {
|
|
16
|
-
if (user.lid) {
|
|
17
|
-
return {
|
|
18
|
-
tag: 'lid',
|
|
19
|
-
attrs: { jid: user.lid }
|
|
20
|
-
}
|
|
21
|
-
} else {
|
|
22
|
-
return null
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
parser(node: BinaryNode): string | null {
|
|
27
|
-
if (node.tag === 'lid') {
|
|
28
|
-
return node.attrs.val!
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return null
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import type { USyncQueryProtocol } from '../Types/USync'
|
|
2
|
-
import { type BinaryNode, getBinaryNodeChild } from '../WABinary'
|
|
3
|
-
import { USyncBotProfileProtocol } from './Protocols/UsyncBotProfileProtocol'
|
|
4
|
-
import { USyncLIDProtocol } from './Protocols/UsyncLIDProtocol'
|
|
5
|
-
import {
|
|
6
|
-
USyncContactProtocol,
|
|
7
|
-
USyncDeviceProtocol,
|
|
8
|
-
USyncDisappearingModeProtocol,
|
|
9
|
-
USyncStatusProtocol
|
|
10
|
-
} from './Protocols'
|
|
11
|
-
import { USyncUser } from './USyncUser'
|
|
12
|
-
|
|
13
|
-
export type USyncQueryResultList = { [protocol: string]: unknown; id: string }
|
|
14
|
-
|
|
15
|
-
export type USyncQueryResult = {
|
|
16
|
-
list: USyncQueryResultList[]
|
|
17
|
-
sideList: USyncQueryResultList[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class USyncQuery {
|
|
21
|
-
protocols: USyncQueryProtocol[]
|
|
22
|
-
users: USyncUser[]
|
|
23
|
-
context: string
|
|
24
|
-
mode: string
|
|
25
|
-
|
|
26
|
-
constructor() {
|
|
27
|
-
this.protocols = []
|
|
28
|
-
this.users = []
|
|
29
|
-
this.context = 'interactive'
|
|
30
|
-
this.mode = 'query'
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
withMode(mode: string) {
|
|
34
|
-
this.mode = mode
|
|
35
|
-
return this
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
withContext(context: string) {
|
|
39
|
-
this.context = context
|
|
40
|
-
return this
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
withUser(user: USyncUser) {
|
|
44
|
-
this.users.push(user)
|
|
45
|
-
return this
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
parseUSyncQueryResult(result: BinaryNode | undefined): USyncQueryResult | undefined {
|
|
49
|
-
if (!result || result.attrs.type !== 'result') {
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const protocolMap = Object.fromEntries(
|
|
54
|
-
this.protocols.map(protocol => {
|
|
55
|
-
return [protocol.name, protocol.parser]
|
|
56
|
-
})
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
const queryResult: USyncQueryResult = {
|
|
60
|
-
// TODO: implement errors etc.
|
|
61
|
-
list: [],
|
|
62
|
-
sideList: []
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const usyncNode = getBinaryNodeChild(result, 'usync')
|
|
66
|
-
|
|
67
|
-
//TODO: implement error backoff, refresh etc.
|
|
68
|
-
//TODO: see if there are any errors in the result node
|
|
69
|
-
//const resultNode = getBinaryNodeChild(usyncNode, 'result')
|
|
70
|
-
|
|
71
|
-
const listNode = usyncNode ? getBinaryNodeChild(usyncNode, 'list') : undefined
|
|
72
|
-
|
|
73
|
-
if (listNode?.content && Array.isArray(listNode.content)) {
|
|
74
|
-
queryResult.list = listNode.content.reduce((acc: USyncQueryResultList[], node) => {
|
|
75
|
-
const id = node?.attrs.jid
|
|
76
|
-
if (id) {
|
|
77
|
-
const data = Array.isArray(node?.content)
|
|
78
|
-
? Object.fromEntries(
|
|
79
|
-
node.content
|
|
80
|
-
.map(content => {
|
|
81
|
-
const protocol = content.tag
|
|
82
|
-
const parser = protocolMap[protocol]
|
|
83
|
-
if (parser) {
|
|
84
|
-
return [protocol, parser(content)]
|
|
85
|
-
} else {
|
|
86
|
-
return [protocol, null]
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
.filter(([, b]) => b !== null) as [string, unknown][]
|
|
90
|
-
)
|
|
91
|
-
: {}
|
|
92
|
-
acc.push({ ...data, id })
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return acc
|
|
96
|
-
}, [])
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
//TODO: implement side list
|
|
100
|
-
//const sideListNode = getBinaryNodeChild(usyncNode, 'side_list')
|
|
101
|
-
return queryResult
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
withDeviceProtocol() {
|
|
105
|
-
this.protocols.push(new USyncDeviceProtocol())
|
|
106
|
-
return this
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
withContactProtocol() {
|
|
110
|
-
this.protocols.push(new USyncContactProtocol())
|
|
111
|
-
return this
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
withStatusProtocol() {
|
|
115
|
-
this.protocols.push(new USyncStatusProtocol())
|
|
116
|
-
return this
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
withDisappearingModeProtocol() {
|
|
120
|
-
this.protocols.push(new USyncDisappearingModeProtocol())
|
|
121
|
-
return this
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
withBotProfileProtocol() {
|
|
125
|
-
this.protocols.push(new USyncBotProfileProtocol())
|
|
126
|
-
return this
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
withLIDProtocol() {
|
|
130
|
-
this.protocols.push(new USyncLIDProtocol())
|
|
131
|
-
return this
|
|
132
|
-
}
|
|
133
|
-
}
|
package/src/WAUSync/USyncUser.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export class USyncUser {
|
|
2
|
-
id?: string
|
|
3
|
-
lid?: string
|
|
4
|
-
phone?: string
|
|
5
|
-
type?: string
|
|
6
|
-
personaId?: string
|
|
7
|
-
|
|
8
|
-
withId(id: string) {
|
|
9
|
-
this.id = id
|
|
10
|
-
return this
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
withLid(lid: string) {
|
|
14
|
-
this.lid = lid
|
|
15
|
-
return this
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
withPhone(phone: string) {
|
|
19
|
-
this.phone = phone
|
|
20
|
-
return this
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
withType(type: string) {
|
|
24
|
-
this.type = type
|
|
25
|
-
return this
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
withPersonaId(personaId: string) {
|
|
29
|
-
this.personaId = personaId
|
|
30
|
-
return this
|
|
31
|
-
}
|
|
32
|
-
}
|
package/src/WAUSync/index.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import makeWASocket from './Socket/index'
|
|
2
|
-
|
|
3
|
-
export * from '../WAProto/index.js'
|
|
4
|
-
export * from './Utils/index'
|
|
5
|
-
export * from './Types/index'
|
|
6
|
-
export * from './Defaults/index'
|
|
7
|
-
export * from './WABinary/index'
|
|
8
|
-
export * from './WAM/index'
|
|
9
|
-
export * from './WAUSync/index'
|
|
10
|
-
|
|
11
|
-
export type WASocket = ReturnType<typeof makeWASocket>
|
|
12
|
-
export { makeWASocket }
|
|
13
|
-
export default makeWASocket
|