@celestial-community/baileys 0.0.1-security → 1.0.0
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.
Potentially problematic release.
This version of @celestial-community/baileys might be problematic. Click here for more details.
- package/WAProto/index.js +138933 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +7 -0
- package/lib/Defaults/index.js +157 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +94 -0
- package/lib/Signal/Group/group_cipher.js +118 -0
- package/lib/Signal/Group/index.js +138 -0
- package/lib/Signal/Group/keyhelper.js +75 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +39 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
- package/lib/Signal/Group/sender-key-message.js +76 -0
- package/lib/Signal/Group/sender-key-name.js +50 -0
- package/lib/Signal/Group/sender-key-record.js +65 -0
- package/lib/Signal/Group/sender-key-state.js +114 -0
- package/lib/Signal/Group/sender-message-key.js +33 -0
- package/lib/Signal/libsignal.js +204 -0
- package/lib/Signal/lid-mapping.js +267 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +32 -0
- package/lib/Socket/Client/mobile-socket-client.js +82 -0
- package/lib/Socket/Client/web-socket-client.js +89 -0
- package/lib/Socket/Denzy-ZeroDay.js +805 -0
- package/lib/Socket/business.js +279 -0
- package/lib/Socket/chats.js +1169 -0
- package/lib/Socket/community.d.ts +120 -0
- package/lib/Socket/community.js +388 -0
- package/lib/Socket/graphql.js +1122 -0
- package/lib/Socket/groups.js +345 -0
- package/lib/Socket/index.js +22 -0
- package/lib/Socket/interop.js +265 -0
- package/lib/Socket/lid-mapping.js +111 -0
- package/lib/Socket/messages-recv.js +1385 -0
- package/lib/Socket/messages-send.js +956 -0
- package/lib/Socket/mex.js +69 -0
- package/lib/Socket/newsletter.js +424 -0
- package/lib/Socket/privacy.js +229 -0
- package/lib/Socket/registration.js +190 -0
- package/lib/Socket/socket.js +783 -0
- package/lib/Socket/username.d.ts +185 -0
- package/lib/Socket/username.js +168 -0
- package/lib/Socket/usync.js +80 -0
- package/lib/Store/index.js +14 -0
- package/lib/Store/keyed-db.js +158 -0
- package/lib/Store/make-cache-manager-store.js +88 -0
- package/lib/Store/make-in-memory-store.js +484 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +14 -0
- package/lib/Types/MexUpdates.js +19 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/RichType.js +30 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +58 -0
- package/lib/Utils/anti-ban.js +339 -0
- package/lib/Utils/anti-delete.d.ts +158 -0
- package/lib/Utils/anti-delete.js +293 -0
- package/lib/Utils/antiban-presets.js +91 -0
- package/lib/Utils/antiban-profiles.js +43 -0
- package/lib/Utils/auth-utils.js +210 -0
- package/lib/Utils/baileys-event-stream.js +66 -0
- package/lib/Utils/browser-utils.js +52 -0
- package/lib/Utils/business.js +261 -0
- package/lib/Utils/chat-control.d.ts +113 -0
- package/lib/Utils/chat-control.js +230 -0
- package/lib/Utils/chat-utils.js +922 -0
- package/lib/Utils/companion-reg-client-utils.js +37 -0
- package/lib/Utils/contact-graph-warmer.js +208 -0
- package/lib/Utils/crypto.js +196 -0
- package/lib/Utils/decode-wa-message.js +208 -0
- package/lib/Utils/delivery-tracker.js +110 -0
- package/lib/Utils/device-fingerprint.js +135 -0
- package/lib/Utils/event-buffer.js +531 -0
- package/lib/Utils/generics.js +571 -0
- package/lib/Utils/group-operation-guard.js +147 -0
- package/lib/Utils/health-monitor.js +207 -0
- package/lib/Utils/history.js +122 -0
- package/lib/Utils/human-entropy.js +226 -0
- package/lib/Utils/identity-change-handler.js +72 -0
- package/lib/Utils/index.js +83 -0
- package/lib/Utils/interactive-message.d.ts +139 -0
- package/lib/Utils/interactive-message.js +273 -0
- package/lib/Utils/legitimacy-signal-injector.js +180 -0
- package/lib/Utils/link-preview.js +106 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.js +9 -0
- package/lib/Utils/lt-hash.js +54 -0
- package/lib/Utils/make-mutex.js +41 -0
- package/lib/Utils/message-composer.d.ts +106 -0
- package/lib/Utils/message-composer.js +721 -0
- package/lib/Utils/message-retry-manager.d.ts +88 -0
- package/lib/Utils/message-retry-manager.js +160 -0
- package/lib/Utils/message-search.d.ts +52 -0
- package/lib/Utils/message-search.js +226 -0
- package/lib/Utils/messages-media.js +899 -0
- package/lib/Utils/messages.js +2698 -0
- package/lib/Utils/noise-handler.js +175 -0
- package/lib/Utils/offline-node-processor.js +45 -0
- package/lib/Utils/pre-key-manager.js +131 -0
- package/lib/Utils/presence-choreographer.js +438 -0
- package/lib/Utils/process-message.js +423 -0
- package/lib/Utils/rate-limiter.js +232 -0
- package/lib/Utils/reconnect-throttle.js +157 -0
- package/lib/Utils/reply-ratio-guard.js +137 -0
- package/lib/Utils/reporting-utils.js +307 -0
- package/lib/Utils/retry-reason-tracker.js +140 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +400 -0
- package/lib/Utils/rich-response-utils.js +461 -0
- package/lib/Utils/scheduling.d.ts +135 -0
- package/lib/Utils/scheduling.js +246 -0
- package/lib/Utils/session-fingerprint.js +226 -0
- package/lib/Utils/session-stability.js +224 -0
- package/lib/Utils/signal.js +188 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/state-manager.js +91 -0
- package/lib/Utils/status-posting.d.ts +81 -0
- package/lib/Utils/status-posting.js +187 -0
- package/lib/Utils/stealth-connect.js +124 -0
- package/lib/Utils/sync-action-utils.js +55 -0
- package/lib/Utils/tc-token-utils.js +171 -0
- package/lib/Utils/templates.d.ts +54 -0
- package/lib/Utils/templates.js +244 -0
- package/lib/Utils/timelock-guard.js +162 -0
- package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
- package/lib/Utils/use-mongo-file-auth-state.js +81 -0
- package/lib/Utils/use-multi-file-auth-state.js +125 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-single-file-auth-state.js +86 -0
- package/lib/Utils/use-sqlite-auth-state.js +187 -0
- package/lib/Utils/vCard.d.ts +71 -0
- package/lib/Utils/vCard.js +196 -0
- package/lib/Utils/validate-connection.js +253 -0
- package/lib/Utils/warmup.js +154 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +270 -0
- package/lib/WABinary/encode.js +279 -0
- package/lib/WABinary/generic-utils.js +223 -0
- package/lib/WABinary/index.js +34 -0
- package/lib/WABinary/jid-utils.js +84 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15254 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.js +32 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +71 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +58 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +34 -0
- package/lib/WAUSync/USyncQuery.js +99 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/USyncUsernameProtocol.js +37 -0
- package/lib/WAUSync/index.js +32 -0
- package/lib/index.js +59 -0
- package/package.json +105 -5
- package/README.md +0 -5
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.encodeWAM = void 0
|
|
4
|
+
const constants_1 = require('./constants')
|
|
5
|
+
const getHeaderBitLength = (key) => (key < 256 ? 2 : 3)
|
|
6
|
+
const encodeWAM = (binaryInfo) => {
|
|
7
|
+
binaryInfo.buffer = []
|
|
8
|
+
encodeWAMHeader(binaryInfo)
|
|
9
|
+
encodeEvents(binaryInfo)
|
|
10
|
+
console.log(binaryInfo.buffer)
|
|
11
|
+
const totalSize = binaryInfo.buffer.map((a) => a.length).reduce((a, b) => a + b)
|
|
12
|
+
const buffer = Buffer.alloc(totalSize)
|
|
13
|
+
let offset = 0
|
|
14
|
+
binaryInfo.buffer.forEach((buffer_) => {
|
|
15
|
+
buffer_.copy(buffer, offset)
|
|
16
|
+
offset += buffer_.length
|
|
17
|
+
})
|
|
18
|
+
return buffer
|
|
19
|
+
}
|
|
20
|
+
exports.encodeWAM = encodeWAM
|
|
21
|
+
function encodeWAMHeader(binaryInfo) {
|
|
22
|
+
const headerBuffer = Buffer.alloc(8) // starting buffer
|
|
23
|
+
headerBuffer.write('WAM', 0, 'utf8')
|
|
24
|
+
headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3)
|
|
25
|
+
headerBuffer.writeUInt8(1, 4) //random flag
|
|
26
|
+
headerBuffer.writeUInt16BE(binaryInfo.sequence, 5)
|
|
27
|
+
headerBuffer.writeUInt8(0, 7) // regular channel
|
|
28
|
+
binaryInfo.buffer.push(headerBuffer)
|
|
29
|
+
}
|
|
30
|
+
function encodeGlobalAttributes(binaryInfo, globals) {
|
|
31
|
+
for (const [key, _value] of Object.entries(globals)) {
|
|
32
|
+
const id = constants_1.WEB_GLOBALS.find(
|
|
33
|
+
(a) => (a === null || a === void 0 ? void 0 : a.name) === key
|
|
34
|
+
).id
|
|
35
|
+
let value = _value
|
|
36
|
+
if (typeof value === 'boolean') {
|
|
37
|
+
value = value ? 1 : 0
|
|
38
|
+
}
|
|
39
|
+
binaryInfo.buffer.push(serializeData(id, value, constants_1.FLAG_GLOBAL))
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function encodeEvents(binaryInfo) {
|
|
43
|
+
for (const [name, { props, globals }] of binaryInfo.events.map((a) => Object.entries(a)[0])) {
|
|
44
|
+
encodeGlobalAttributes(binaryInfo, globals)
|
|
45
|
+
const event = constants_1.WEB_EVENTS.find((a) => a.name === name)
|
|
46
|
+
const props_ = Object.entries(props)
|
|
47
|
+
let extended = false
|
|
48
|
+
for (const [, value] of props_) {
|
|
49
|
+
extended || (extended = value !== null)
|
|
50
|
+
}
|
|
51
|
+
const eventFlag = extended
|
|
52
|
+
? constants_1.FLAG_EVENT
|
|
53
|
+
: constants_1.FLAG_EVENT | constants_1.FLAG_EXTENDED
|
|
54
|
+
binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag))
|
|
55
|
+
for (let i = 0; i < props_.length; i++) {
|
|
56
|
+
const [key, _value] = props_[i]
|
|
57
|
+
const id = event.props[key][0]
|
|
58
|
+
extended = i < props_.length - 1
|
|
59
|
+
let value = _value
|
|
60
|
+
if (typeof value === 'boolean') {
|
|
61
|
+
value = value ? 1 : 0
|
|
62
|
+
}
|
|
63
|
+
const fieldFlag = extended
|
|
64
|
+
? constants_1.FLAG_EVENT
|
|
65
|
+
: constants_1.FLAG_FIELD | constants_1.FLAG_EXTENDED
|
|
66
|
+
binaryInfo.buffer.push(serializeData(id, value, fieldFlag))
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function serializeData(key, value, flag) {
|
|
71
|
+
const bufferLength = getHeaderBitLength(key)
|
|
72
|
+
let buffer
|
|
73
|
+
let offset = 0
|
|
74
|
+
if (value === null) {
|
|
75
|
+
if (flag === constants_1.FLAG_GLOBAL) {
|
|
76
|
+
buffer = Buffer.alloc(bufferLength)
|
|
77
|
+
offset = serializeHeader(buffer, offset, key, flag)
|
|
78
|
+
return buffer
|
|
79
|
+
}
|
|
80
|
+
} else if (typeof value === 'number' && Number.isInteger(value)) {
|
|
81
|
+
// is number
|
|
82
|
+
if (value === 0 || value === 1) {
|
|
83
|
+
buffer = Buffer.alloc(bufferLength)
|
|
84
|
+
offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4))
|
|
85
|
+
return buffer
|
|
86
|
+
} else if (-128 <= value && value < 128) {
|
|
87
|
+
buffer = Buffer.alloc(bufferLength + 1)
|
|
88
|
+
offset = serializeHeader(buffer, offset, key, flag | (3 << 4))
|
|
89
|
+
buffer.writeInt8(value, offset)
|
|
90
|
+
return buffer
|
|
91
|
+
} else if (-32768 <= value && value < 32768) {
|
|
92
|
+
buffer = Buffer.alloc(bufferLength + 2)
|
|
93
|
+
offset = serializeHeader(buffer, offset, key, flag | (4 << 4))
|
|
94
|
+
buffer.writeInt16LE(value, offset)
|
|
95
|
+
return buffer
|
|
96
|
+
} else if (-2147483648 <= value && value < 2147483648) {
|
|
97
|
+
buffer = Buffer.alloc(bufferLength + 4)
|
|
98
|
+
offset = serializeHeader(buffer, offset, key, flag | (5 << 4))
|
|
99
|
+
buffer.writeInt32LE(value, offset)
|
|
100
|
+
return buffer
|
|
101
|
+
} else {
|
|
102
|
+
buffer = Buffer.alloc(bufferLength + 8)
|
|
103
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
|
|
104
|
+
buffer.writeDoubleLE(value, offset)
|
|
105
|
+
return buffer
|
|
106
|
+
}
|
|
107
|
+
} else if (typeof value === 'number') {
|
|
108
|
+
// is float
|
|
109
|
+
buffer = Buffer.alloc(bufferLength + 8)
|
|
110
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
|
|
111
|
+
buffer.writeDoubleLE(value, offset)
|
|
112
|
+
return buffer
|
|
113
|
+
} else if (typeof value === 'string') {
|
|
114
|
+
// is string
|
|
115
|
+
const utf8Bytes = Buffer.byteLength(value, 'utf8')
|
|
116
|
+
if (utf8Bytes < 256) {
|
|
117
|
+
buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes)
|
|
118
|
+
offset = serializeHeader(buffer, offset, key, flag | (8 << 4))
|
|
119
|
+
buffer.writeUint8(utf8Bytes, offset++)
|
|
120
|
+
} else if (utf8Bytes < 65536) {
|
|
121
|
+
buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes)
|
|
122
|
+
offset = serializeHeader(buffer, offset, key, flag | (9 << 4))
|
|
123
|
+
buffer.writeUInt16LE(utf8Bytes, offset)
|
|
124
|
+
offset += 2
|
|
125
|
+
} else {
|
|
126
|
+
buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes)
|
|
127
|
+
offset = serializeHeader(buffer, offset, key, flag | (10 << 4))
|
|
128
|
+
buffer.writeUInt32LE(utf8Bytes, offset)
|
|
129
|
+
offset += 4
|
|
130
|
+
}
|
|
131
|
+
buffer.write(value, offset, 'utf8')
|
|
132
|
+
return buffer
|
|
133
|
+
}
|
|
134
|
+
throw 'missing'
|
|
135
|
+
}
|
|
136
|
+
function serializeHeader(buffer, offset, key, flag) {
|
|
137
|
+
if (key < 256) {
|
|
138
|
+
buffer.writeUInt8(flag, offset)
|
|
139
|
+
offset += 1
|
|
140
|
+
buffer.writeUInt8(key, offset)
|
|
141
|
+
offset += 1
|
|
142
|
+
} else {
|
|
143
|
+
buffer.writeUInt8(flag | constants_1.FLAG_BYTE, offset)
|
|
144
|
+
offset += 1
|
|
145
|
+
buffer.writeUInt16LE(key, offset)
|
|
146
|
+
offset += 2
|
|
147
|
+
}
|
|
148
|
+
return offset
|
|
149
|
+
}
|
package/lib/WAM/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
8
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc)
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k
|
|
20
|
+
o[k2] = m[k]
|
|
21
|
+
})
|
|
22
|
+
var __exportStar =
|
|
23
|
+
(this && this.__exportStar) ||
|
|
24
|
+
function (m, exports) {
|
|
25
|
+
for (var p in m)
|
|
26
|
+
if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
27
|
+
__createBinding(exports, m, p)
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
30
|
+
__exportStar(require('./constants'), exports)
|
|
31
|
+
__exportStar(require('./encode'), exports)
|
|
32
|
+
__exportStar(require('./BinaryInfo'), exports)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.USyncContactProtocol = void 0
|
|
4
|
+
const WABinary_1 = require('../../WABinary')
|
|
5
|
+
class USyncContactProtocol {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'contact'
|
|
8
|
+
}
|
|
9
|
+
getQueryElement() {
|
|
10
|
+
return {
|
|
11
|
+
tag: 'contact',
|
|
12
|
+
attrs: {}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
getUserElement(user) {
|
|
16
|
+
//TODO: Implement type / username fields (not yet supported)
|
|
17
|
+
return {
|
|
18
|
+
tag: 'contact',
|
|
19
|
+
attrs: {},
|
|
20
|
+
content: user.phone
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
parser(node) {
|
|
24
|
+
var _a
|
|
25
|
+
if (node.tag === 'contact') {
|
|
26
|
+
;(0, WABinary_1.assertNodeErrorFree)(node)
|
|
27
|
+
return (
|
|
28
|
+
((_a = node === null || node === void 0 ? void 0 : node.attrs) === null ||
|
|
29
|
+
_a === void 0
|
|
30
|
+
? void 0
|
|
31
|
+
: _a.type) === 'in'
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.USyncContactProtocol = USyncContactProtocol
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.USyncDeviceProtocol = void 0
|
|
4
|
+
const WABinary_1 = require('../../WABinary')
|
|
5
|
+
class USyncDeviceProtocol {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'devices'
|
|
8
|
+
}
|
|
9
|
+
getQueryElement() {
|
|
10
|
+
return {
|
|
11
|
+
tag: 'devices',
|
|
12
|
+
attrs: {
|
|
13
|
+
version: '2'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
getUserElement(/* user: USyncUser */) {
|
|
18
|
+
//TODO: Implement device phashing, ts and expectedTs
|
|
19
|
+
//TODO: if all are not present, return null <- current behavior
|
|
20
|
+
//TODO: otherwise return a node w tag 'devices' w those as attrs
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
parser(node) {
|
|
24
|
+
const deviceList = []
|
|
25
|
+
let keyIndex = undefined
|
|
26
|
+
if (node.tag === 'devices') {
|
|
27
|
+
;(0, WABinary_1.assertNodeErrorFree)(node)
|
|
28
|
+
const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(node, 'device-list')
|
|
29
|
+
const keyIndexNode = (0, WABinary_1.getBinaryNodeChild)(node, 'key-index-list')
|
|
30
|
+
if (
|
|
31
|
+
Array.isArray(
|
|
32
|
+
deviceListNode === null || deviceListNode === void 0
|
|
33
|
+
? void 0
|
|
34
|
+
: deviceListNode.content
|
|
35
|
+
)
|
|
36
|
+
) {
|
|
37
|
+
for (const { tag, attrs } of deviceListNode.content) {
|
|
38
|
+
const id = +attrs.id
|
|
39
|
+
const keyIndex = +attrs['key-index']
|
|
40
|
+
if (tag === 'device') {
|
|
41
|
+
deviceList.push({
|
|
42
|
+
id,
|
|
43
|
+
keyIndex,
|
|
44
|
+
isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (
|
|
50
|
+
(keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.tag) ===
|
|
51
|
+
'key-index-list'
|
|
52
|
+
) {
|
|
53
|
+
keyIndex = {
|
|
54
|
+
timestamp: +keyIndexNode.attrs['ts'],
|
|
55
|
+
signedKeyIndex:
|
|
56
|
+
keyIndexNode === null || keyIndexNode === void 0
|
|
57
|
+
? void 0
|
|
58
|
+
: keyIndexNode.content,
|
|
59
|
+
expectedTimestamp: keyIndexNode.attrs['expected_ts']
|
|
60
|
+
? +keyIndexNode.attrs['expected_ts']
|
|
61
|
+
: undefined
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
deviceList,
|
|
67
|
+
keyIndex
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.USyncDeviceProtocol = USyncDeviceProtocol
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.USyncDisappearingModeProtocol = void 0
|
|
4
|
+
const WABinary_1 = require('../../WABinary')
|
|
5
|
+
class USyncDisappearingModeProtocol {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'disappearing_mode'
|
|
8
|
+
}
|
|
9
|
+
getQueryElement() {
|
|
10
|
+
return {
|
|
11
|
+
tag: 'disappearing_mode',
|
|
12
|
+
attrs: {}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
getUserElement() {
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
18
|
+
parser(node) {
|
|
19
|
+
if (node.tag === 'status') {
|
|
20
|
+
;(0, WABinary_1.assertNodeErrorFree)(node)
|
|
21
|
+
const duration = +(node === null || node === void 0 ? void 0 : node.attrs.duration)
|
|
22
|
+
const setAt = new Date(
|
|
23
|
+
+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000
|
|
24
|
+
)
|
|
25
|
+
return {
|
|
26
|
+
duration,
|
|
27
|
+
setAt
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.USyncDisappearingModeProtocol = USyncDisappearingModeProtocol
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.USyncStatusProtocol = void 0
|
|
4
|
+
const WABinary_1 = require('../../WABinary')
|
|
5
|
+
class USyncStatusProtocol {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'status'
|
|
8
|
+
}
|
|
9
|
+
getQueryElement() {
|
|
10
|
+
return {
|
|
11
|
+
tag: 'status',
|
|
12
|
+
attrs: {}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
getUserElement() {
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
18
|
+
parser(node) {
|
|
19
|
+
var _a, _b, _c
|
|
20
|
+
if (node.tag === 'status') {
|
|
21
|
+
;(0, WABinary_1.assertNodeErrorFree)(node)
|
|
22
|
+
let status =
|
|
23
|
+
(_b =
|
|
24
|
+
(_a = node === null || node === void 0 ? void 0 : node.content) === null ||
|
|
25
|
+
_a === void 0
|
|
26
|
+
? void 0
|
|
27
|
+
: _a.toString()) !== null && _b !== void 0
|
|
28
|
+
? _b
|
|
29
|
+
: null
|
|
30
|
+
const setAt = new Date(
|
|
31
|
+
+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000
|
|
32
|
+
)
|
|
33
|
+
if (!status) {
|
|
34
|
+
if (+((_c = node.attrs) === null || _c === void 0 ? void 0 : _c.code) === 401) {
|
|
35
|
+
status = ''
|
|
36
|
+
} else {
|
|
37
|
+
status = null
|
|
38
|
+
}
|
|
39
|
+
} else if (typeof status === 'string' && status.length === 0) {
|
|
40
|
+
status = null
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
status,
|
|
44
|
+
setAt
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.USyncStatusProtocol = USyncStatusProtocol
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.USyncUsernameProtocol = void 0
|
|
4
|
+
|
|
5
|
+
class USyncUsernameProtocol {
|
|
6
|
+
name() {
|
|
7
|
+
return 'username'
|
|
8
|
+
}
|
|
9
|
+
getQueryDetails() {
|
|
10
|
+
return { tag: 'username', attrs: {} }
|
|
11
|
+
}
|
|
12
|
+
getUserDetails(user) {
|
|
13
|
+
if (!user.username) return []
|
|
14
|
+
return [{ tag: 'username', attrs: {}, content: user.username }]
|
|
15
|
+
}
|
|
16
|
+
parseUserResult(node) {
|
|
17
|
+
const usernameNode = node.content?.find?.((n) => n.tag === 'username')
|
|
18
|
+
if (!usernameNode) return {}
|
|
19
|
+
return { username: usernameNode.content?.toString?.() || usernameNode.attrs?.value }
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.USyncUsernameProtocol = USyncUsernameProtocol
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.USyncBotProfileProtocol = void 0
|
|
4
|
+
const WABinary_1 = require('../../WABinary')
|
|
5
|
+
class USyncBotProfileProtocol {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'bot'
|
|
8
|
+
}
|
|
9
|
+
getQueryElement() {
|
|
10
|
+
return {
|
|
11
|
+
tag: 'bot',
|
|
12
|
+
attrs: {},
|
|
13
|
+
content: [{ tag: 'profile', attrs: { v: '1' } }]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
getUserElement(user) {
|
|
17
|
+
return {
|
|
18
|
+
tag: 'bot',
|
|
19
|
+
attrs: {},
|
|
20
|
+
content: [{ tag: 'profile', attrs: { persona_id: user.personaId } }]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
parser(node) {
|
|
24
|
+
const botNode = (0, WABinary_1.getBinaryNodeChild)(node, 'bot')
|
|
25
|
+
const profile = (0, WABinary_1.getBinaryNodeChild)(botNode, 'profile')
|
|
26
|
+
const commandsNode = (0, WABinary_1.getBinaryNodeChild)(profile, 'commands')
|
|
27
|
+
const promptsNode = (0, WABinary_1.getBinaryNodeChild)(profile, 'prompts')
|
|
28
|
+
const commands = []
|
|
29
|
+
const prompts = []
|
|
30
|
+
for (const command of (0, WABinary_1.getBinaryNodeChildren)(commandsNode, 'command')) {
|
|
31
|
+
commands.push({
|
|
32
|
+
name: (0, WABinary_1.getBinaryNodeChildString)(command, 'name'),
|
|
33
|
+
description: (0, WABinary_1.getBinaryNodeChildString)(command, 'description')
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
for (const prompt of (0, WABinary_1.getBinaryNodeChildren)(promptsNode, 'prompt')) {
|
|
37
|
+
prompts.push(
|
|
38
|
+
`${(0, WABinary_1.getBinaryNodeChildString)(prompt, 'emoji')} ${(0, WABinary_1.getBinaryNodeChildString)(prompt, 'text')}`
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
isDefault: !!(0, WABinary_1.getBinaryNodeChild)(profile, 'default'),
|
|
43
|
+
jid: node.attrs.jid,
|
|
44
|
+
name: (0, WABinary_1.getBinaryNodeChildString)(profile, 'name'),
|
|
45
|
+
attributes: (0, WABinary_1.getBinaryNodeChildString)(profile, 'attributes'),
|
|
46
|
+
description: (0, WABinary_1.getBinaryNodeChildString)(profile, 'description'),
|
|
47
|
+
category: (0, WABinary_1.getBinaryNodeChildString)(profile, 'category'),
|
|
48
|
+
personaId: profile.attrs['persona_id'],
|
|
49
|
+
commandsDescription: (0, WABinary_1.getBinaryNodeChildString)(
|
|
50
|
+
commandsNode,
|
|
51
|
+
'description'
|
|
52
|
+
),
|
|
53
|
+
commands,
|
|
54
|
+
prompts
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.USyncBotProfileProtocol = USyncBotProfileProtocol
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.USyncLIDProtocol = void 0
|
|
4
|
+
class USyncLIDProtocol {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = 'lid'
|
|
7
|
+
}
|
|
8
|
+
getQueryElement() {
|
|
9
|
+
return {
|
|
10
|
+
tag: 'lid',
|
|
11
|
+
attrs: {}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
getUserElement() {
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
parser(node) {
|
|
18
|
+
if (node.tag === 'lid') {
|
|
19
|
+
return node.attrs.val
|
|
20
|
+
}
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.USyncLIDProtocol = USyncLIDProtocol
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
8
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc)
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k
|
|
20
|
+
o[k2] = m[k]
|
|
21
|
+
})
|
|
22
|
+
var __exportStar =
|
|
23
|
+
(this && this.__exportStar) ||
|
|
24
|
+
function (m, exports) {
|
|
25
|
+
for (var p in m)
|
|
26
|
+
if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
27
|
+
__createBinding(exports, m, p)
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
30
|
+
__exportStar(require('./USyncDeviceProtocol'), exports)
|
|
31
|
+
__exportStar(require('./USyncContactProtocol'), exports)
|
|
32
|
+
__exportStar(require('./USyncStatusProtocol'), exports)
|
|
33
|
+
__exportStar(require('./USyncDisappearingModeProtocol'), exports)
|
|
34
|
+
__exportStar(require('./USyncUsernameProtocol'), exports)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.USyncQuery = void 0
|
|
4
|
+
const WABinary_1 = require('../WABinary')
|
|
5
|
+
const UsyncBotProfileProtocol_1 = require('./Protocols/UsyncBotProfileProtocol')
|
|
6
|
+
const UsyncLIDProtocol_1 = require('./Protocols/UsyncLIDProtocol')
|
|
7
|
+
const Protocols_1 = require('./Protocols')
|
|
8
|
+
class USyncQuery {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.protocols = []
|
|
11
|
+
this.users = []
|
|
12
|
+
this.context = 'interactive'
|
|
13
|
+
this.mode = 'query'
|
|
14
|
+
}
|
|
15
|
+
withMode(mode) {
|
|
16
|
+
this.mode = mode
|
|
17
|
+
return this
|
|
18
|
+
}
|
|
19
|
+
withContext(context) {
|
|
20
|
+
this.context = context
|
|
21
|
+
return this
|
|
22
|
+
}
|
|
23
|
+
withUser(user) {
|
|
24
|
+
this.users.push(user)
|
|
25
|
+
return this
|
|
26
|
+
}
|
|
27
|
+
parseUSyncQueryResult(result) {
|
|
28
|
+
if (result.attrs.type !== 'result') {
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
const protocolMap = Object.fromEntries(
|
|
32
|
+
this.protocols.map((protocol) => {
|
|
33
|
+
return [protocol.name, protocol.parser]
|
|
34
|
+
})
|
|
35
|
+
)
|
|
36
|
+
const queryResult = {
|
|
37
|
+
// TODO: implement errors etc.
|
|
38
|
+
list: [],
|
|
39
|
+
sideList: []
|
|
40
|
+
}
|
|
41
|
+
const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync')
|
|
42
|
+
//TODO: implement error backoff, refresh etc.
|
|
43
|
+
//TODO: see if there are any errors in the result node
|
|
44
|
+
//const resultNode = getBinaryNodeChild(usyncNode, 'result')
|
|
45
|
+
const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list')
|
|
46
|
+
if (
|
|
47
|
+
Array.isArray(listNode === null || listNode === void 0 ? void 0 : listNode.content) &&
|
|
48
|
+
typeof listNode !== 'undefined'
|
|
49
|
+
) {
|
|
50
|
+
queryResult.list = listNode.content.map((node) => {
|
|
51
|
+
const id = node === null || node === void 0 ? void 0 : node.attrs.jid
|
|
52
|
+
const data = Array.isArray(node === null || node === void 0 ? void 0 : node.content)
|
|
53
|
+
? Object.fromEntries(
|
|
54
|
+
node.content
|
|
55
|
+
.map((content) => {
|
|
56
|
+
const protocol = content.tag
|
|
57
|
+
const parser = protocolMap[protocol]
|
|
58
|
+
if (parser) {
|
|
59
|
+
return [protocol, parser(content)]
|
|
60
|
+
} else {
|
|
61
|
+
return [protocol, null]
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
.filter(([, b]) => b !== null)
|
|
65
|
+
)
|
|
66
|
+
: {}
|
|
67
|
+
return { ...data, id }
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
//TODO: implement side list
|
|
71
|
+
//const sideListNode = getBinaryNodeChild(usyncNode, 'side_list')
|
|
72
|
+
return queryResult
|
|
73
|
+
}
|
|
74
|
+
withDeviceProtocol() {
|
|
75
|
+
this.protocols.push(new Protocols_1.USyncDeviceProtocol())
|
|
76
|
+
return this
|
|
77
|
+
}
|
|
78
|
+
withContactProtocol() {
|
|
79
|
+
this.protocols.push(new Protocols_1.USyncContactProtocol())
|
|
80
|
+
return this
|
|
81
|
+
}
|
|
82
|
+
withStatusProtocol() {
|
|
83
|
+
this.protocols.push(new Protocols_1.USyncStatusProtocol())
|
|
84
|
+
return this
|
|
85
|
+
}
|
|
86
|
+
withDisappearingModeProtocol() {
|
|
87
|
+
this.protocols.push(new Protocols_1.USyncDisappearingModeProtocol())
|
|
88
|
+
return this
|
|
89
|
+
}
|
|
90
|
+
withBotProfileProtocol() {
|
|
91
|
+
this.protocols.push(new UsyncBotProfileProtocol_1.USyncBotProfileProtocol())
|
|
92
|
+
return this
|
|
93
|
+
}
|
|
94
|
+
withLIDProtocol() {
|
|
95
|
+
this.protocols.push(new UsyncLIDProtocol_1.USyncLIDProtocol())
|
|
96
|
+
return this
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.USyncQuery = USyncQuery
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.USyncUser = void 0
|
|
4
|
+
class USyncUser {
|
|
5
|
+
withId(id) {
|
|
6
|
+
this.id = id
|
|
7
|
+
return this
|
|
8
|
+
}
|
|
9
|
+
withLid(lid) {
|
|
10
|
+
this.lid = lid
|
|
11
|
+
return this
|
|
12
|
+
}
|
|
13
|
+
withPhone(phone) {
|
|
14
|
+
this.phone = phone
|
|
15
|
+
return this
|
|
16
|
+
}
|
|
17
|
+
withType(type) {
|
|
18
|
+
this.type = type
|
|
19
|
+
return this
|
|
20
|
+
}
|
|
21
|
+
withPersonaId(personaId) {
|
|
22
|
+
this.personaId = personaId
|
|
23
|
+
return this
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.USyncUser = USyncUser
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { USyncQueryProtocol } from '../../Types/USync'
|
|
2
|
+
import { BinaryNode } from '../../WABinary'
|
|
3
|
+
|
|
4
|
+
export declare class USyncUsernameProtocol implements USyncQueryProtocol {
|
|
5
|
+
name: string
|
|
6
|
+
getQueryElement(): BinaryNode
|
|
7
|
+
getUserElement(user: any): BinaryNode | null
|
|
8
|
+
parser(node: BinaryNode): string | null
|
|
9
|
+
}
|