@x4r1s3/baileys 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +1262 -2
- package/SECURITY.md +47 -0
- package/WAProto/V +1 -0
- package/WAProto/WAProto.proto +8892 -0
- package/WAProto/index.d.ts +104128 -0
- package/WAProto/index.js +334920 -0
- package/assets/rolling-circle.svg +133 -0
- package/assets/x4r1s3-banner.svg +32 -0
- package/engine-requirements.js +27 -0
- package/lib/Builders/A2UI.js +245 -0
- package/lib/Builders/AIRich.js +179 -0
- package/lib/Builders/Button.js +108 -0
- package/lib/Builders/CFC.js +284 -0
- package/lib/Builders/Carousel.js +81 -0
- package/lib/Call/THIRD_PARTY_LICENSE.txt +21 -0
- package/lib/Call/audio-feeder.mjs +179 -0
- package/lib/Call/audio-recorder.mjs +250 -0
- package/lib/Call/fetch-wasm-resources.mjs +104 -0
- package/lib/Call/index.mjs +680 -0
- package/lib/Call/relay-transport.mjs +563 -0
- package/lib/Call/signaling.mjs +641 -0
- package/lib/Call/types.mjs +17 -0
- package/lib/Call/video-feeder.mjs +94 -0
- package/lib/Call/wasm-engine.mjs +1372 -0
- package/lib/Call/worker-bootstrap.mjs +1042 -0
- package/lib/Defaults/ban-checker.js +56 -0
- package/lib/Defaults/index.js +170 -0
- package/lib/Signal/Group/ciphertext-message.js +23 -0
- package/lib/Signal/Group/group-session-builder.js +41 -0
- package/lib/Signal/Group/group_cipher.js +93 -0
- package/lib/Signal/Group/index.js +23 -0
- package/lib/Signal/Group/keyhelper.js +29 -0
- package/lib/Signal/Group/sender-chain-key.js +37 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +74 -0
- package/lib/Signal/Group/sender-key-message.js +77 -0
- package/lib/Signal/Group/sender-key-name.js +59 -0
- package/lib/Signal/Group/sender-key-record.js +52 -0
- package/lib/Signal/Group/sender-key-state.js +95 -0
- package/lib/Signal/Group/sender-message-key.js +37 -0
- package/lib/Signal/libsignal.js +440 -0
- package/lib/Signal/lid-mapping.js +292 -0
- package/lib/Socket/Client/index.js +14 -0
- package/lib/Socket/Client/types.js +22 -0
- package/lib/Socket/Client/websocket.js +65 -0
- package/lib/Socket/aigroups.js +327 -0
- package/lib/Socket/ban-checker.js +165 -0
- package/lib/Socket/business.js +419 -0
- package/lib/Socket/chats.js +1921 -0
- package/lib/Socket/communities.js +443 -0
- package/lib/Socket/graphql.js +911 -0
- package/lib/Socket/groups.js +561 -0
- package/lib/Socket/index.js +49 -0
- package/lib/Socket/interactive-handler.js +612 -0
- package/lib/Socket/interop.js +575 -0
- package/lib/Socket/managed-account.js +220 -0
- package/lib/Socket/messages-recv.js +2191 -0
- package/lib/Socket/messages-send.js +4104 -0
- package/lib/Socket/mex.js +53 -0
- package/lib/Socket/newsletter.js +291 -0
- package/lib/Socket/privacy.js +458 -0
- package/lib/Socket/registration.js +440 -0
- package/lib/Socket/socket.js +1029 -0
- package/lib/Socket/status-actions.js +287 -0
- package/lib/Socket/username.js +241 -0
- package/lib/Store/index.js +16 -0
- package/lib/Store/make-cache-manager-store.js +101 -0
- package/lib/Store/make-in-memory-store.js +432 -0
- package/lib/Store/make-ordered-dictionary.js +90 -0
- package/lib/Store/object-repository.js +35 -0
- package/lib/Types/Auth.js +13 -0
- package/lib/Types/Bussines.js +13 -0
- package/lib/Types/Call.js +13 -0
- package/lib/Types/Chat.js +19 -0
- package/lib/Types/Contact.js +13 -0
- package/lib/Types/Events.js +13 -0
- package/lib/Types/GroupMetadata.js +13 -0
- package/lib/Types/Label.js +36 -0
- package/lib/Types/LabelAssociation.js +18 -0
- package/lib/Types/Message.js +30 -0
- package/lib/Types/Mex.js +53 -0
- package/lib/Types/Product.js +13 -0
- package/lib/Types/RichType.js +34 -0
- package/lib/Types/Signal.js +13 -0
- package/lib/Types/Socket.js +14 -0
- package/lib/Types/State.js +60 -0
- package/lib/Types/USync.js +13 -0
- package/lib/Types/index.js +37 -0
- package/lib/Utils/auth-utils.js +313 -0
- package/lib/Utils/ban-checker.js +48 -0
- package/lib/Utils/bot-capabilities.js +96 -0
- package/lib/Utils/bot-planning-replay.js +177 -0
- package/lib/Utils/browser-utils.js +40 -0
- package/lib/Utils/business.js +242 -0
- package/lib/Utils/c2582.js +147 -0
- package/lib/Utils/chat-utils.js +905 -0
- package/lib/Utils/companion-reg-client-utils.js +44 -0
- package/lib/Utils/consumer-application.js +114 -0
- package/lib/Utils/crypto.js +129 -0
- package/lib/Utils/decode-wa-message.js +496 -0
- package/lib/Utils/direct-chat-theme.js +164 -0
- package/lib/Utils/event-buffer.js +601 -0
- package/lib/Utils/experimental-proto.js +206 -0
- package/lib/Utils/games/miniapp.js +17 -0
- package/lib/Utils/games/slot-machine.js +270 -0
- package/lib/Utils/games/website-preview.js +306 -0
- package/lib/Utils/generics.js +402 -0
- package/lib/Utils/group-history.js +68 -0
- package/lib/Utils/group-wallpaper.js +168 -0
- package/lib/Utils/history.js +162 -0
- package/lib/Utils/identity-change-handler.js +60 -0
- package/lib/Utils/index.js +61 -0
- package/lib/Utils/jid-display-normalization.js +221 -0
- package/lib/Utils/link-preview.js +96 -0
- package/lib/Utils/logger.js +14 -0
- package/lib/Utils/lt-hash.js +19 -0
- package/lib/Utils/make-mutex.js +44 -0
- package/lib/Utils/message-composer.js +709 -0
- package/lib/Utils/message-inspect.js +79 -0
- package/lib/Utils/message-retry-manager.js +253 -0
- package/lib/Utils/message-security.js +167 -0
- package/lib/Utils/messages-media.js +1027 -0
- package/lib/Utils/messages.js +2467 -0
- package/lib/Utils/meta-ai-msmsg.js +215 -0
- package/lib/Utils/meta-compositing.js +239 -0
- package/lib/Utils/native-flow.js +158 -0
- package/lib/Utils/newsletter-live-update-utils.js +74 -0
- package/lib/Utils/newsletter-status-utils.js +152 -0
- package/lib/Utils/noise-handler.js +212 -0
- package/lib/Utils/offline-node-processor.js +51 -0
- package/lib/Utils/poll-manager.js +206 -0
- package/lib/Utils/portable-compat.js +12 -0
- package/lib/Utils/pre-key-manager.js +117 -0
- package/lib/Utils/process-message.js +610 -0
- package/lib/Utils/reporting-utils.js +269 -0
- package/lib/Utils/rich-message-utils.js +2841 -0
- package/lib/Utils/scheduled-message.js +107 -0
- package/lib/Utils/signal.js +212 -0
- package/lib/Utils/source-grep.js +57 -0
- package/lib/Utils/stanza-ack.js +49 -0
- package/lib/Utils/sticker-annotation.js +87 -0
- package/lib/Utils/sync-action-utils.js +59 -0
- package/lib/Utils/tc-token-utils.js +174 -0
- package/lib/Utils/use-multi-file-auth-state.js +132 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.js +120 -0
- package/lib/Utils/validate-connection.js +220 -0
- package/lib/Utils/view-once-utils.js +218 -0
- package/lib/Utils/voip-rekey.js +32 -0
- package/lib/Utils/website-preview.js +27 -0
- package/lib/Utils/welcome-flow.js +228 -0
- package/lib/Utils/x4r1s3.js +144 -0
- package/lib/WABinary/constants.js +1475 -0
- package/lib/WABinary/decode.js +273 -0
- package/lib/WABinary/encode.js +231 -0
- package/lib/WABinary/generic-utils.js +242 -0
- package/lib/WABinary/index.js +17 -0
- package/lib/WABinary/jid-utils.js +107 -0
- package/lib/WABinary/types.js +13 -0
- package/lib/WAM/BinaryInfo.js +21 -0
- package/lib/WAM/constants.js +22864 -0
- package/lib/WAM/encode.js +161 -0
- package/lib/WAM/index.js +15 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +108 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +68 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +65 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +82 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +40 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +46 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +36 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +40 -0
- package/lib/WAUSync/Protocols/index.js +24 -0
- package/lib/WAUSync/USyncQuery.js +213 -0
- package/lib/WAUSync/USyncUser.js +66 -0
- package/lib/WAUSync/index.js +15 -0
- package/lib/antiban.cjs +4726 -0
- package/lib/index.d.ts +1285 -0
- package/lib/index.js +30 -0
- package/package.json +125 -4
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/WAM/encode.js
|
|
5
|
+
* About: Encode module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: encodeWAM
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
import { BinaryInfo } from './BinaryInfo.js';
|
|
14
|
+
import { FLAG_BYTE, FLAG_EVENT, FLAG_EXTENDED, FLAG_FIELD, FLAG_GLOBAL, WEB_EVENTS, WEB_GLOBALS } from './constants.js';
|
|
15
|
+
const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
|
|
16
|
+
export const encodeWAM = (binaryInfo) => {
|
|
17
|
+
binaryInfo.buffer = [];
|
|
18
|
+
encodeWAMHeader(binaryInfo);
|
|
19
|
+
encodeEvents(binaryInfo);
|
|
20
|
+
const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b);
|
|
21
|
+
const buffer = Buffer.alloc(totalSize);
|
|
22
|
+
let offset = 0;
|
|
23
|
+
for (const buffer_ of binaryInfo.buffer) {
|
|
24
|
+
buffer_.copy(buffer, offset);
|
|
25
|
+
offset += buffer_.length;
|
|
26
|
+
}
|
|
27
|
+
return buffer;
|
|
28
|
+
};
|
|
29
|
+
function encodeWAMHeader(binaryInfo) {
|
|
30
|
+
const headerBuffer = Buffer.alloc(8); // starting buffer
|
|
31
|
+
headerBuffer.write('WAM', 0, 'utf8');
|
|
32
|
+
headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3);
|
|
33
|
+
headerBuffer.writeUInt8(1, 4); //random flag
|
|
34
|
+
headerBuffer.writeUInt16BE(binaryInfo.sequence, 5);
|
|
35
|
+
headerBuffer.writeUInt8(0, 7); // regular channel
|
|
36
|
+
binaryInfo.buffer.push(headerBuffer);
|
|
37
|
+
}
|
|
38
|
+
function encodeGlobalAttributes(binaryInfo, globals) {
|
|
39
|
+
for (const [key, _value] of Object.entries(globals)) {
|
|
40
|
+
const id = WEB_GLOBALS.find(a => a?.name === key).id;
|
|
41
|
+
let value = _value;
|
|
42
|
+
if (typeof value === 'boolean') {
|
|
43
|
+
value = value ? 1 : 0;
|
|
44
|
+
}
|
|
45
|
+
binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function encodeEvents(binaryInfo) {
|
|
49
|
+
for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0])) {
|
|
50
|
+
encodeGlobalAttributes(binaryInfo, globals);
|
|
51
|
+
const event = WEB_EVENTS.find(a => a.name === name);
|
|
52
|
+
const props_ = Object.entries(props);
|
|
53
|
+
let extended = false;
|
|
54
|
+
for (const [, value] of props_) {
|
|
55
|
+
extended || (extended = value !== null);
|
|
56
|
+
}
|
|
57
|
+
const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED;
|
|
58
|
+
binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
|
|
59
|
+
for (let i = 0; i < props_.length; i++) {
|
|
60
|
+
const [key, _value] = props_[i];
|
|
61
|
+
const id = event.props[key]?.[0];
|
|
62
|
+
extended = i < props_.length - 1;
|
|
63
|
+
let value = _value;
|
|
64
|
+
if (typeof value === 'boolean') {
|
|
65
|
+
value = value ? 1 : 0;
|
|
66
|
+
}
|
|
67
|
+
const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED;
|
|
68
|
+
binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function serializeData(key, value, flag) {
|
|
73
|
+
const bufferLength = getHeaderBitLength(key);
|
|
74
|
+
let buffer;
|
|
75
|
+
let offset = 0;
|
|
76
|
+
if (value === null) {
|
|
77
|
+
if (flag === FLAG_GLOBAL) {
|
|
78
|
+
buffer = Buffer.alloc(bufferLength);
|
|
79
|
+
offset = serializeHeader(buffer, offset, key, flag);
|
|
80
|
+
return buffer;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (typeof value === 'number' && Number.isInteger(value)) {
|
|
84
|
+
// is number
|
|
85
|
+
if (value === 0 || value === 1) {
|
|
86
|
+
buffer = Buffer.alloc(bufferLength);
|
|
87
|
+
offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4));
|
|
88
|
+
return buffer;
|
|
89
|
+
}
|
|
90
|
+
else if (-128 <= value && value < 128) {
|
|
91
|
+
buffer = Buffer.alloc(bufferLength + 1);
|
|
92
|
+
offset = serializeHeader(buffer, offset, key, flag | (3 << 4));
|
|
93
|
+
buffer.writeInt8(value, offset);
|
|
94
|
+
return buffer;
|
|
95
|
+
}
|
|
96
|
+
else if (-32768 <= value && value < 32768) {
|
|
97
|
+
buffer = Buffer.alloc(bufferLength + 2);
|
|
98
|
+
offset = serializeHeader(buffer, offset, key, flag | (4 << 4));
|
|
99
|
+
buffer.writeInt16LE(value, offset);
|
|
100
|
+
return buffer;
|
|
101
|
+
}
|
|
102
|
+
else if (-2147483648 <= value && value < 2147483648) {
|
|
103
|
+
buffer = Buffer.alloc(bufferLength + 4);
|
|
104
|
+
offset = serializeHeader(buffer, offset, key, flag | (5 << 4));
|
|
105
|
+
buffer.writeInt32LE(value, offset);
|
|
106
|
+
return buffer;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
buffer = Buffer.alloc(bufferLength + 8);
|
|
110
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
|
|
111
|
+
buffer.writeDoubleLE(value, offset);
|
|
112
|
+
return buffer;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (typeof value === 'number') {
|
|
116
|
+
// is float
|
|
117
|
+
buffer = Buffer.alloc(bufferLength + 8);
|
|
118
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
|
|
119
|
+
buffer.writeDoubleLE(value, offset);
|
|
120
|
+
return buffer;
|
|
121
|
+
}
|
|
122
|
+
else if (typeof value === 'string') {
|
|
123
|
+
// is string
|
|
124
|
+
const utf8Bytes = Buffer.byteLength(value, 'utf8');
|
|
125
|
+
if (utf8Bytes < 256) {
|
|
126
|
+
buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
|
|
127
|
+
offset = serializeHeader(buffer, offset, key, flag | (8 << 4));
|
|
128
|
+
buffer.writeUint8(utf8Bytes, offset++);
|
|
129
|
+
}
|
|
130
|
+
else if (utf8Bytes < 65536) {
|
|
131
|
+
buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes);
|
|
132
|
+
offset = serializeHeader(buffer, offset, key, flag | (9 << 4));
|
|
133
|
+
buffer.writeUInt16LE(utf8Bytes, offset);
|
|
134
|
+
offset += 2;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes);
|
|
138
|
+
offset = serializeHeader(buffer, offset, key, flag | (10 << 4));
|
|
139
|
+
buffer.writeUInt32LE(utf8Bytes, offset);
|
|
140
|
+
offset += 4;
|
|
141
|
+
}
|
|
142
|
+
buffer.write(value, offset, 'utf8');
|
|
143
|
+
return buffer;
|
|
144
|
+
}
|
|
145
|
+
throw 'missing';
|
|
146
|
+
}
|
|
147
|
+
function serializeHeader(buffer, offset, key, flag) {
|
|
148
|
+
if (key < 256) {
|
|
149
|
+
buffer.writeUInt8(flag, offset);
|
|
150
|
+
offset += 1;
|
|
151
|
+
buffer.writeUInt8(key, offset);
|
|
152
|
+
offset += 1;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
buffer.writeUInt8(flag | FLAG_BYTE, offset);
|
|
156
|
+
offset += 1;
|
|
157
|
+
buffer.writeUInt16LE(key, offset);
|
|
158
|
+
offset += 2;
|
|
159
|
+
}
|
|
160
|
+
return offset;
|
|
161
|
+
}
|
package/lib/WAM/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/WAM/index.js
|
|
5
|
+
* About: WAM module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: No public exports detected; module side effects or declarations are local.
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
export * from './constants.js';
|
|
14
|
+
export * from './encode.js';
|
|
15
|
+
export * from './BinaryInfo.js';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/WAUSync/Protocols/USyncBusinessProtocol.js
|
|
5
|
+
* About: USyncBusinessProtocol module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: USyncBusinessProtocol
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildren } from '../../WABinary/index.js';
|
|
14
|
+
export class USyncBusinessProtocol {
|
|
15
|
+
constructor(profileVersion = '2') {
|
|
16
|
+
this.name = 'business';
|
|
17
|
+
this.profileVersion = profileVersion;
|
|
18
|
+
}
|
|
19
|
+
getQueryElement() {
|
|
20
|
+
return {
|
|
21
|
+
tag: 'business',
|
|
22
|
+
attrs: {},
|
|
23
|
+
content: [
|
|
24
|
+
{ tag: 'verified_name', attrs: {} },
|
|
25
|
+
{ tag: 'profile', attrs: { v: this.profileVersion } }
|
|
26
|
+
]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
getUserElement(user) {
|
|
30
|
+
const children = [];
|
|
31
|
+
if (user.verifiedNameSerial) {
|
|
32
|
+
children.push({ tag: 'verified_name', attrs: { serial: user.verifiedNameSerial } });
|
|
33
|
+
}
|
|
34
|
+
if (user.businessProfileTag) {
|
|
35
|
+
children.push({ tag: 'profile', attrs: { tag: user.businessProfileTag } });
|
|
36
|
+
}
|
|
37
|
+
return children.length > 0 ? { tag: 'business', attrs: {}, content: children } : null;
|
|
38
|
+
}
|
|
39
|
+
parser(node) {
|
|
40
|
+
if (node.tag !== 'business') return null;
|
|
41
|
+
assertNodeErrorFree(node);
|
|
42
|
+
const verifiedNameNode = getBinaryNodeChild(node, 'verified_name');
|
|
43
|
+
const profileNode = getBinaryNodeChild(node, 'profile');
|
|
44
|
+
|
|
45
|
+
// Business hours: profile may contain a business_hours child with business_hours_config children
|
|
46
|
+
let businessHours = undefined;
|
|
47
|
+
if (profileNode) {
|
|
48
|
+
const businessHoursNode = getBinaryNodeChild(profileNode, 'business_hours');
|
|
49
|
+
if (businessHoursNode) {
|
|
50
|
+
const configs = getBinaryNodeChildren(businessHoursNode, 'business_hours_config');
|
|
51
|
+
businessHours = {
|
|
52
|
+
timezone: businessHoursNode.attrs?.timezone ?? null,
|
|
53
|
+
config: configs.map(({ attrs }) => ({
|
|
54
|
+
dayOfWeek: attrs?.day_of_week ?? null,
|
|
55
|
+
openTime: attrs?.open_time ?? null,
|
|
56
|
+
closeTime: attrs?.close_time ?? null,
|
|
57
|
+
mode: attrs?.mode ?? null
|
|
58
|
+
}))
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Business address from profile child node
|
|
64
|
+
const addressNode = profileNode ? getBinaryNodeChild(profileNode, 'address') : null;
|
|
65
|
+
const businessAddress = addressNode?.content
|
|
66
|
+
? Buffer.isBuffer(addressNode.content)
|
|
67
|
+
? addressNode.content.toString()
|
|
68
|
+
: String(addressNode.content)
|
|
69
|
+
: (profileNode?.attrs?.address ?? null);
|
|
70
|
+
|
|
71
|
+
// Catalog status from profile attrs
|
|
72
|
+
const catalogStatus = profileNode
|
|
73
|
+
? {
|
|
74
|
+
exists: profileNode.attrs?.catalog_exists === 'true' || profileNode.attrs?.catalog_exists === true,
|
|
75
|
+
sendAll: profileNode.attrs?.catalog_send_all === 'true' || profileNode.attrs?.catalog_send_all === true
|
|
76
|
+
}
|
|
77
|
+
: null;
|
|
78
|
+
|
|
79
|
+
// Cart flags from profile attrs
|
|
80
|
+
const cartEnabled =
|
|
81
|
+
profileNode?.attrs?.cart_enabled !== undefined
|
|
82
|
+
? profileNode.attrs.cart_enabled === 'true' || profileNode.attrs.cart_enabled === true
|
|
83
|
+
: null;
|
|
84
|
+
const webCartEnabled =
|
|
85
|
+
profileNode?.attrs?.web_cart_enabled !== undefined
|
|
86
|
+
? profileNode.attrs.web_cart_enabled === 'true' || profileNode.attrs.web_cart_enabled === true
|
|
87
|
+
: null;
|
|
88
|
+
const webCartOnOff = profileNode?.attrs?.web_cart_on_off ?? null;
|
|
89
|
+
|
|
90
|
+
// Commerce experience from profile attrs
|
|
91
|
+
const commerceExperience = profileNode?.attrs?.commerce_experience ?? null;
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
verifiedName: verifiedNameNode?.content ?? null,
|
|
95
|
+
verifiedLevel: verifiedNameNode?.attrs?.verified_level ?? null,
|
|
96
|
+
verifiedNameLevel: verifiedNameNode?.attrs?.verified_level ?? null,
|
|
97
|
+
profileTag: profileNode?.attrs?.tag ?? null,
|
|
98
|
+
pnJid: node.attrs?.pn_jid ?? null,
|
|
99
|
+
businessHours: businessHours ?? null,
|
|
100
|
+
businessAddress,
|
|
101
|
+
catalogStatus,
|
|
102
|
+
cartEnabled,
|
|
103
|
+
webCartEnabled,
|
|
104
|
+
webCartOnOff,
|
|
105
|
+
commerceExperience
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/WAUSync/Protocols/USyncContactProtocol.js
|
|
5
|
+
* About: USyncContactProtocol module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: USyncContactProtocol
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
14
|
+
export class USyncContactProtocol {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.name = 'contact';
|
|
17
|
+
}
|
|
18
|
+
getQueryElement() {
|
|
19
|
+
return {
|
|
20
|
+
tag: 'contact',
|
|
21
|
+
attrs: {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
getUserElement(user) {
|
|
25
|
+
if (user.phone) {
|
|
26
|
+
return {
|
|
27
|
+
tag: 'contact',
|
|
28
|
+
attrs: {},
|
|
29
|
+
content: user.phone
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (user.username) {
|
|
33
|
+
return {
|
|
34
|
+
tag: 'contact',
|
|
35
|
+
attrs: {
|
|
36
|
+
username: user.username,
|
|
37
|
+
...(user.usernameKey ? { pin: user.usernameKey } : {}),
|
|
38
|
+
...(user.lid ? { lid: user.lid } : {})
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (user.type) {
|
|
43
|
+
return {
|
|
44
|
+
tag: 'contact',
|
|
45
|
+
attrs: {
|
|
46
|
+
type: user.type
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
tag: 'contact',
|
|
52
|
+
attrs: {}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
parser(node) {
|
|
56
|
+
if (node.tag === 'contact') {
|
|
57
|
+
assertNodeErrorFree(node);
|
|
58
|
+
const inWA = node?.attrs?.type === 'in';
|
|
59
|
+
const restrictionType = node?.attrs?.stella_addressbook_restriction_type;
|
|
60
|
+
if (restrictionType !== undefined) {
|
|
61
|
+
// Return object with extra metadata when restriction type is present
|
|
62
|
+
return { inWA, stellaAddressbookRestrictionType: restrictionType };
|
|
63
|
+
}
|
|
64
|
+
return inWA;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/WAUSync/Protocols/USyncDeviceProtocol.js
|
|
5
|
+
* About: USyncDeviceProtocol module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: USyncDeviceProtocol
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js';
|
|
14
|
+
export class USyncDeviceProtocol {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.name = 'devices';
|
|
17
|
+
}
|
|
18
|
+
getQueryElement() {
|
|
19
|
+
return {
|
|
20
|
+
tag: 'devices',
|
|
21
|
+
attrs: {
|
|
22
|
+
version: '2'
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
getUserElement( /* user: USyncUser */) {
|
|
27
|
+
//TODO: Implement device phashing, ts and expectedTs
|
|
28
|
+
//TODO: if all are not present, return null <- current behavior
|
|
29
|
+
//TODO: otherwise return a node w tag 'devices' w those as attrs
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
parser(node) {
|
|
33
|
+
const deviceList = [];
|
|
34
|
+
let keyIndex = undefined;
|
|
35
|
+
if (node.tag === 'devices') {
|
|
36
|
+
assertNodeErrorFree(node);
|
|
37
|
+
const deviceListNode = getBinaryNodeChild(node, 'device-list');
|
|
38
|
+
const keyIndexNode = getBinaryNodeChild(node, 'key-index-list');
|
|
39
|
+
if (Array.isArray(deviceListNode?.content)) {
|
|
40
|
+
for (const { tag, attrs } of deviceListNode.content) {
|
|
41
|
+
const id = +attrs.id;
|
|
42
|
+
const keyIndex = +attrs['key-index'];
|
|
43
|
+
if (tag === 'device') {
|
|
44
|
+
deviceList.push({
|
|
45
|
+
id,
|
|
46
|
+
keyIndex,
|
|
47
|
+
isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (keyIndexNode?.tag === 'key-index-list') {
|
|
53
|
+
keyIndex = {
|
|
54
|
+
timestamp: +keyIndexNode.attrs['ts'],
|
|
55
|
+
signedKeyIndex: keyIndexNode?.content,
|
|
56
|
+
expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
deviceList,
|
|
62
|
+
keyIndex
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js
|
|
5
|
+
* About: USyncDisappearingModeProtocol module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: USyncDisappearingModeProtocol
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
14
|
+
export class USyncDisappearingModeProtocol {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.name = 'disappearing_mode';
|
|
17
|
+
}
|
|
18
|
+
getQueryElement() {
|
|
19
|
+
return {
|
|
20
|
+
tag: 'disappearing_mode',
|
|
21
|
+
attrs: {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
getUserElement() {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
parser(node) {
|
|
28
|
+
if (node.tag === 'disappearing_mode') {
|
|
29
|
+
assertNodeErrorFree(node);
|
|
30
|
+
const duration = +node?.attrs.duration;
|
|
31
|
+
const setAt = new Date(+(node?.attrs.t || 0) * 1000);
|
|
32
|
+
return {
|
|
33
|
+
duration,
|
|
34
|
+
setAt
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/WAUSync/Protocols/USyncFeatureProtocol.js
|
|
5
|
+
* About: USyncFeatureProtocol module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: USYNC_FEATURES, USyncFeatureProtocol
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
import { getBinaryNodeChild } from '../../WABinary/index.js';
|
|
14
|
+
// Device feature flags that can be queried, ported from WhatsApp Web's
|
|
15
|
+
// WAWebUsyncFeature module.
|
|
16
|
+
export const USYNC_FEATURES = [
|
|
17
|
+
'document',
|
|
18
|
+
'encrypt',
|
|
19
|
+
'encrypt_blist',
|
|
20
|
+
'encrypt_contact',
|
|
21
|
+
'encrypt_group_gen2',
|
|
22
|
+
'encrypt_image',
|
|
23
|
+
'encrypt_location',
|
|
24
|
+
'encrypt_url',
|
|
25
|
+
'encrypt_v2',
|
|
26
|
+
'voip',
|
|
27
|
+
'voip_legacy',
|
|
28
|
+
'multi_agent',
|
|
29
|
+
'bot_eligible'
|
|
30
|
+
];
|
|
31
|
+
export class USyncFeatureProtocol {
|
|
32
|
+
/**
|
|
33
|
+
* @param {string[]} [features] feature names to query (defaults to all known)
|
|
34
|
+
*/
|
|
35
|
+
constructor(features) {
|
|
36
|
+
this.name = 'feature';
|
|
37
|
+
this.features = features && features.length ? features : USYNC_FEATURES;
|
|
38
|
+
}
|
|
39
|
+
getQueryElement() {
|
|
40
|
+
return {
|
|
41
|
+
tag: 'feature',
|
|
42
|
+
attrs: {},
|
|
43
|
+
content: this.features.map(feature => ({ tag: feature, attrs: {} }))
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
getUserElement() {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
parser(node) {
|
|
50
|
+
if (node.tag !== 'feature') {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const errorNode = getBinaryNodeChild(node, 'error');
|
|
54
|
+
if (errorNode) {
|
|
55
|
+
return {
|
|
56
|
+
errorCode: errorNode.attrs?.code ? +errorNode.attrs.code : undefined,
|
|
57
|
+
errorText: errorNode.attrs?.text
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const CAMEL_MAP = {
|
|
61
|
+
encrypt_v2: 'encryptV2',
|
|
62
|
+
voip_legacy: 'voipLegacy',
|
|
63
|
+
multi_agent: 'multiAgent',
|
|
64
|
+
bot_eligible: 'botEligible',
|
|
65
|
+
encrypt_blist: 'encryptBlist',
|
|
66
|
+
encrypt_contact: 'encryptContact',
|
|
67
|
+
encrypt_group_gen2: 'encryptGroupGen2',
|
|
68
|
+
encrypt_image: 'encryptImage',
|
|
69
|
+
encrypt_location: 'encryptLocation',
|
|
70
|
+
encrypt_url: 'encryptUrl'
|
|
71
|
+
};
|
|
72
|
+
const features = {};
|
|
73
|
+
const children = Array.isArray(node.content) ? node.content : [];
|
|
74
|
+
for (const child of children) {
|
|
75
|
+
if (child?.attrs && child.attrs.value !== undefined) {
|
|
76
|
+
const key = CAMEL_MAP[child.tag] || child.tag;
|
|
77
|
+
features[key] = child.attrs.value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return features;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/WAUSync/Protocols/USyncPictureProtocol.js
|
|
5
|
+
* About: USyncPictureProtocol module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: USyncPictureProtocol
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
14
|
+
export class USyncPictureProtocol {
|
|
15
|
+
constructor(type = 'image') {
|
|
16
|
+
this.name = 'picture';
|
|
17
|
+
// "image" for full resolution, "preview" for thumbnail
|
|
18
|
+
this.type = type;
|
|
19
|
+
}
|
|
20
|
+
getQueryElement() {
|
|
21
|
+
return {
|
|
22
|
+
tag: 'picture',
|
|
23
|
+
attrs: { type: this.type }
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
getUserElement(user) {
|
|
27
|
+
const attrs = {};
|
|
28
|
+
if (user.pictureId != null) attrs.id = String(user.pictureId);
|
|
29
|
+
return Object.keys(attrs).length > 0 ? { tag: 'picture', attrs } : null;
|
|
30
|
+
}
|
|
31
|
+
parser(node) {
|
|
32
|
+
if (node.tag !== 'picture') return null;
|
|
33
|
+
assertNodeErrorFree(node);
|
|
34
|
+
const id = node.attrs?.id ?? null;
|
|
35
|
+
const directPath = node.attrs?.direct_path ?? null;
|
|
36
|
+
const hash = node.attrs?.hash ?? null;
|
|
37
|
+
if (!id && !directPath) return null;
|
|
38
|
+
return { id, directPath, hash };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/WAUSync/Protocols/USyncSidelistProtocol.js
|
|
5
|
+
* About: USyncSidelistProtocol module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: USyncSidelistProtocol
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
14
|
+
export class USyncSidelistProtocol {
|
|
15
|
+
constructor(useLidAddressing = true) {
|
|
16
|
+
this.name = 'sidelist';
|
|
17
|
+
// When true, sends addressing_mode="lid" — required for interop/LID-mode contacts
|
|
18
|
+
this.useLidAddressing = useLidAddressing;
|
|
19
|
+
}
|
|
20
|
+
getQueryElement() {
|
|
21
|
+
const attrs = {};
|
|
22
|
+
if (this.useLidAddressing) attrs.addressing_mode = 'lid';
|
|
23
|
+
return { tag: 'sidelist', attrs };
|
|
24
|
+
}
|
|
25
|
+
getUserElement(user) {
|
|
26
|
+
if (user.sidelistDelete) {
|
|
27
|
+
return { tag: 'sidelist', attrs: { type: 'delete' } };
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
parser(node) {
|
|
32
|
+
if (node.tag !== 'sidelist' && node.tag !== 'side_list') return null;
|
|
33
|
+
assertNodeErrorFree(node);
|
|
34
|
+
// Returns minimal parsed data; the full side_list is parsed in USyncQuery
|
|
35
|
+
return { type: node.attrs?.type ?? null };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/WAUSync/Protocols/USyncStatusProtocol.js
|
|
5
|
+
* About: USyncStatusProtocol module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: USyncStatusProtocol
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
14
|
+
export class USyncStatusProtocol {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.name = 'status';
|
|
17
|
+
}
|
|
18
|
+
getQueryElement() {
|
|
19
|
+
return {
|
|
20
|
+
tag: 'status',
|
|
21
|
+
attrs: {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
getUserElement() {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
parser(node) {
|
|
28
|
+
if (node.tag === 'status') {
|
|
29
|
+
assertNodeErrorFree(node);
|
|
30
|
+
let status = node?.content?.toString() ?? null;
|
|
31
|
+
const setAt = new Date(+(node?.attrs.t || 0) * 1000);
|
|
32
|
+
if (!status) {
|
|
33
|
+
if (node.attrs?.code && +node.attrs.code === 401) {
|
|
34
|
+
status = '';
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
status = null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (typeof status === 'string' && status.length === 0) {
|
|
41
|
+
status = null;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
status,
|
|
45
|
+
setAt
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|