@kanaraa/baileys 3.1.8

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.
Files changed (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1426 -0
  3. package/WAProto/GenerateStatics.sh +3 -0
  4. package/WAProto/WAProto.proto +5479 -0
  5. package/WAProto/fix-imports.js +85 -0
  6. package/WAProto/index.js +97691 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/index.js +128 -0
  9. package/lib/Signal/Group/ciphertext-message.js +11 -0
  10. package/lib/Signal/Group/group-session-builder.js +29 -0
  11. package/lib/Signal/Group/group_cipher.js +81 -0
  12. package/lib/Signal/Group/index.js +11 -0
  13. package/lib/Signal/Group/keyhelper.js +17 -0
  14. package/lib/Signal/Group/sender-chain-key.js +25 -0
  15. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  16. package/lib/Signal/Group/sender-key-message.js +65 -0
  17. package/lib/Signal/Group/sender-key-name.js +47 -0
  18. package/lib/Signal/Group/sender-key-record.js +40 -0
  19. package/lib/Signal/Group/sender-key-state.js +83 -0
  20. package/lib/Signal/Group/sender-message-key.js +25 -0
  21. package/lib/Signal/libsignal.js +430 -0
  22. package/lib/Signal/lid-mapping.js +276 -0
  23. package/lib/Socket/Client/index.js +2 -0
  24. package/lib/Socket/Client/types.js +10 -0
  25. package/lib/Socket/Client/websocket.js +53 -0
  26. package/lib/Socket/business.js +378 -0
  27. package/lib/Socket/chats.js +1192 -0
  28. package/lib/Socket/communities.js +430 -0
  29. package/lib/Socket/groups.js +346 -0
  30. package/lib/Socket/index.js +11 -0
  31. package/lib/Socket/messages-recv.js +1785 -0
  32. package/lib/Socket/messages-send.js +1174 -0
  33. package/lib/Socket/mex.js +41 -0
  34. package/lib/Socket/newsletter.js +180 -0
  35. package/lib/Socket/socket.js +966 -0
  36. package/lib/Types/Auth.js +1 -0
  37. package/lib/Types/Bussines.js +1 -0
  38. package/lib/Types/Call.js +1 -0
  39. package/lib/Types/Chat.js +7 -0
  40. package/lib/Types/Contact.js +1 -0
  41. package/lib/Types/Events.js +1 -0
  42. package/lib/Types/GroupMetadata.js +1 -0
  43. package/lib/Types/Label.js +24 -0
  44. package/lib/Types/LabelAssociation.js +6 -0
  45. package/lib/Types/Message.js +10 -0
  46. package/lib/Types/Mex.js +36 -0
  47. package/lib/Types/Product.js +1 -0
  48. package/lib/Types/Signal.js +1 -0
  49. package/lib/Types/Socket.js +2 -0
  50. package/lib/Types/State.js +55 -0
  51. package/lib/Types/USync.js +1 -0
  52. package/lib/Types/index.js +25 -0
  53. package/lib/Utils/auth-utils.js +301 -0
  54. package/lib/Utils/browser-utils.js +27 -0
  55. package/lib/Utils/business.js +230 -0
  56. package/lib/Utils/chat-utils.js +871 -0
  57. package/lib/Utils/companion-reg-client-utils.js +34 -0
  58. package/lib/Utils/crypto.js +117 -0
  59. package/lib/Utils/decode-wa-message.js +316 -0
  60. package/lib/Utils/event-buffer.js +621 -0
  61. package/lib/Utils/generics.js +392 -0
  62. package/lib/Utils/history.js +133 -0
  63. package/lib/Utils/identity-change-handler.js +49 -0
  64. package/lib/Utils/index.js +22 -0
  65. package/lib/Utils/interactive-send.js +136 -0
  66. package/lib/Utils/link-preview.js +84 -0
  67. package/lib/Utils/logger.js +2 -0
  68. package/lib/Utils/lt-hash.js +7 -0
  69. package/lib/Utils/make-mutex.js +32 -0
  70. package/lib/Utils/message-retry-manager.js +264 -0
  71. package/lib/Utils/messages-media.js +787 -0
  72. package/lib/Utils/messages.js +2306 -0
  73. package/lib/Utils/noise-handler.js +200 -0
  74. package/lib/Utils/offline-node-processor.js +39 -0
  75. package/lib/Utils/pre-key-manager.js +105 -0
  76. package/lib/Utils/process-message.js +629 -0
  77. package/lib/Utils/reporting-utils.js +257 -0
  78. package/lib/Utils/signal.js +200 -0
  79. package/lib/Utils/stanza-ack.js +37 -0
  80. package/lib/Utils/sync-action-utils.js +48 -0
  81. package/lib/Utils/tc-token-utils.js +162 -0
  82. package/lib/Utils/use-multi-file-auth-state.js +120 -0
  83. package/lib/Utils/validate-connection.js +202 -0
  84. package/lib/WABinary/constants.js +1300 -0
  85. package/lib/WABinary/decode.js +261 -0
  86. package/lib/WABinary/encode.js +219 -0
  87. package/lib/WABinary/generic-utils.js +112 -0
  88. package/lib/WABinary/index.js +5 -0
  89. package/lib/WABinary/jid-utils.js +95 -0
  90. package/lib/WABinary/types.js +1 -0
  91. package/lib/WAM/BinaryInfo.js +9 -0
  92. package/lib/WAM/constants.js +22852 -0
  93. package/lib/WAM/encode.js +149 -0
  94. package/lib/WAM/index.js +3 -0
  95. package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
  96. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  97. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  98. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  99. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  100. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  101. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  102. package/lib/WAUSync/Protocols/index.js +5 -0
  103. package/lib/WAUSync/USyncQuery.js +97 -0
  104. package/lib/WAUSync/USyncUser.js +30 -0
  105. package/lib/WAUSync/index.js +3 -0
  106. package/lib/index.js +10 -0
  107. package/package.json +75 -0
@@ -0,0 +1,149 @@
1
+ import { BinaryInfo } from './BinaryInfo.js';
2
+ import { FLAG_BYTE, FLAG_EVENT, FLAG_EXTENDED, FLAG_FIELD, FLAG_GLOBAL, WEB_EVENTS, WEB_GLOBALS } from './constants.js';
3
+ const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
4
+ export const encodeWAM = (binaryInfo) => {
5
+ binaryInfo.buffer = [];
6
+ encodeWAMHeader(binaryInfo);
7
+ encodeEvents(binaryInfo);
8
+ const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b);
9
+ const buffer = Buffer.alloc(totalSize);
10
+ let offset = 0;
11
+ for (const buffer_ of binaryInfo.buffer) {
12
+ buffer_.copy(buffer, offset);
13
+ offset += buffer_.length;
14
+ }
15
+ return buffer;
16
+ };
17
+ function encodeWAMHeader(binaryInfo) {
18
+ const headerBuffer = Buffer.alloc(8); // starting buffer
19
+ headerBuffer.write('WAM', 0, 'utf8');
20
+ headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3);
21
+ headerBuffer.writeUInt8(1, 4); //random flag
22
+ headerBuffer.writeUInt16BE(binaryInfo.sequence, 5);
23
+ headerBuffer.writeUInt8(0, 7); // regular channel
24
+ binaryInfo.buffer.push(headerBuffer);
25
+ }
26
+ function encodeGlobalAttributes(binaryInfo, globals) {
27
+ for (const [key, _value] of Object.entries(globals)) {
28
+ const id = WEB_GLOBALS.find(a => a?.name === key).id;
29
+ let value = _value;
30
+ if (typeof value === 'boolean') {
31
+ value = value ? 1 : 0;
32
+ }
33
+ binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
34
+ }
35
+ }
36
+ function encodeEvents(binaryInfo) {
37
+ for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0])) {
38
+ encodeGlobalAttributes(binaryInfo, globals);
39
+ const event = WEB_EVENTS.find(a => a.name === name);
40
+ const props_ = Object.entries(props);
41
+ let extended = false;
42
+ for (const [, value] of props_) {
43
+ extended || (extended = value !== null);
44
+ }
45
+ const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED;
46
+ binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
47
+ for (let i = 0; i < props_.length; i++) {
48
+ const [key, _value] = props_[i];
49
+ const id = event.props[key]?.[0];
50
+ extended = i < props_.length - 1;
51
+ let value = _value;
52
+ if (typeof value === 'boolean') {
53
+ value = value ? 1 : 0;
54
+ }
55
+ const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED;
56
+ binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
57
+ }
58
+ }
59
+ }
60
+ function serializeData(key, value, flag) {
61
+ const bufferLength = getHeaderBitLength(key);
62
+ let buffer;
63
+ let offset = 0;
64
+ if (value === null) {
65
+ if (flag === FLAG_GLOBAL) {
66
+ buffer = Buffer.alloc(bufferLength);
67
+ offset = serializeHeader(buffer, offset, key, flag);
68
+ return buffer;
69
+ }
70
+ }
71
+ else if (typeof value === 'number' && Number.isInteger(value)) {
72
+ // is number
73
+ if (value === 0 || value === 1) {
74
+ buffer = Buffer.alloc(bufferLength);
75
+ offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4));
76
+ return buffer;
77
+ }
78
+ else if (-128 <= value && value < 128) {
79
+ buffer = Buffer.alloc(bufferLength + 1);
80
+ offset = serializeHeader(buffer, offset, key, flag | (3 << 4));
81
+ buffer.writeInt8(value, offset);
82
+ return buffer;
83
+ }
84
+ else if (-32768 <= value && value < 32768) {
85
+ buffer = Buffer.alloc(bufferLength + 2);
86
+ offset = serializeHeader(buffer, offset, key, flag | (4 << 4));
87
+ buffer.writeInt16LE(value, offset);
88
+ return buffer;
89
+ }
90
+ else if (-2147483648 <= value && value < 2147483648) {
91
+ buffer = Buffer.alloc(bufferLength + 4);
92
+ offset = serializeHeader(buffer, offset, key, flag | (5 << 4));
93
+ buffer.writeInt32LE(value, offset);
94
+ return buffer;
95
+ }
96
+ else {
97
+ buffer = Buffer.alloc(bufferLength + 8);
98
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
99
+ buffer.writeDoubleLE(value, offset);
100
+ return buffer;
101
+ }
102
+ }
103
+ else if (typeof value === 'number') {
104
+ // is float
105
+ buffer = Buffer.alloc(bufferLength + 8);
106
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
107
+ buffer.writeDoubleLE(value, offset);
108
+ return buffer;
109
+ }
110
+ else if (typeof value === 'string') {
111
+ // is string
112
+ const utf8Bytes = Buffer.byteLength(value, 'utf8');
113
+ if (utf8Bytes < 256) {
114
+ buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
115
+ offset = serializeHeader(buffer, offset, key, flag | (8 << 4));
116
+ buffer.writeUint8(utf8Bytes, offset++);
117
+ }
118
+ else if (utf8Bytes < 65536) {
119
+ buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes);
120
+ offset = serializeHeader(buffer, offset, key, flag | (9 << 4));
121
+ buffer.writeUInt16LE(utf8Bytes, offset);
122
+ offset += 2;
123
+ }
124
+ else {
125
+ buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes);
126
+ offset = serializeHeader(buffer, offset, key, flag | (10 << 4));
127
+ buffer.writeUInt32LE(utf8Bytes, offset);
128
+ offset += 4;
129
+ }
130
+ buffer.write(value, offset, 'utf8');
131
+ return buffer;
132
+ }
133
+ throw 'missing';
134
+ }
135
+ function serializeHeader(buffer, offset, key, flag) {
136
+ if (key < 256) {
137
+ buffer.writeUInt8(flag, offset);
138
+ offset += 1;
139
+ buffer.writeUInt8(key, offset);
140
+ offset += 1;
141
+ }
142
+ else {
143
+ buffer.writeUInt8(flag | FLAG_BYTE, offset);
144
+ offset += 1;
145
+ buffer.writeUInt16LE(key, offset);
146
+ offset += 2;
147
+ }
148
+ return offset;
149
+ }
@@ -0,0 +1,3 @@
1
+ export * from './constants.js';
2
+ export * from './encode.js';
3
+ export * from './BinaryInfo.js';
@@ -0,0 +1,51 @@
1
+ import { assertNodeErrorFree } from '../../WABinary/index.js';
2
+ import { USyncUser } from '../USyncUser.js';
3
+ export class USyncContactProtocol {
4
+ constructor() {
5
+ this.name = 'contact';
6
+ }
7
+ getQueryElement() {
8
+ return {
9
+ tag: 'contact',
10
+ attrs: {}
11
+ };
12
+ }
13
+ getUserElement(user) {
14
+ if (user.phone) {
15
+ return {
16
+ tag: 'contact',
17
+ attrs: {},
18
+ content: user.phone
19
+ };
20
+ }
21
+ if (user.username) {
22
+ return {
23
+ tag: 'contact',
24
+ attrs: {
25
+ username: user.username,
26
+ ...(user.usernameKey ? { pin: user.usernameKey } : {}),
27
+ ...(user.lid ? { lid: user.lid } : {})
28
+ }
29
+ };
30
+ }
31
+ if (user.type) {
32
+ return {
33
+ tag: 'contact',
34
+ attrs: {
35
+ type: user.type
36
+ }
37
+ };
38
+ }
39
+ return {
40
+ tag: 'contact',
41
+ attrs: {}
42
+ };
43
+ }
44
+ parser(node) {
45
+ if (node.tag === 'contact') {
46
+ assertNodeErrorFree(node);
47
+ return node?.attrs?.type === 'in';
48
+ }
49
+ return false;
50
+ }
51
+ }
@@ -0,0 +1,53 @@
1
+ import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js';
2
+ export class USyncDeviceProtocol {
3
+ constructor() {
4
+ this.name = 'devices';
5
+ }
6
+ getQueryElement() {
7
+ return {
8
+ tag: 'devices',
9
+ attrs: {
10
+ version: '2'
11
+ }
12
+ };
13
+ }
14
+ getUserElement( /* user: USyncUser */) {
15
+ //TODO: Implement device phashing, ts and expectedTs
16
+ //TODO: if all are not present, return null <- current behavior
17
+ //TODO: otherwise return a node w tag 'devices' w those as attrs
18
+ return null;
19
+ }
20
+ parser(node) {
21
+ const deviceList = [];
22
+ let keyIndex = undefined;
23
+ if (node.tag === 'devices') {
24
+ assertNodeErrorFree(node);
25
+ const deviceListNode = getBinaryNodeChild(node, 'device-list');
26
+ const keyIndexNode = getBinaryNodeChild(node, 'key-index-list');
27
+ if (Array.isArray(deviceListNode?.content)) {
28
+ for (const { tag, attrs } of deviceListNode.content) {
29
+ const id = +attrs.id;
30
+ const keyIndex = +attrs['key-index'];
31
+ if (tag === 'device') {
32
+ deviceList.push({
33
+ id,
34
+ keyIndex,
35
+ isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
36
+ });
37
+ }
38
+ }
39
+ }
40
+ if (keyIndexNode?.tag === 'key-index-list') {
41
+ keyIndex = {
42
+ timestamp: +keyIndexNode.attrs['ts'],
43
+ signedKeyIndex: keyIndexNode?.content,
44
+ expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
45
+ };
46
+ }
47
+ }
48
+ return {
49
+ deviceList,
50
+ keyIndex
51
+ };
52
+ }
53
+ }
@@ -0,0 +1,26 @@
1
+ import { assertNodeErrorFree } from '../../WABinary/index.js';
2
+ export class USyncDisappearingModeProtocol {
3
+ constructor() {
4
+ this.name = 'disappearing_mode';
5
+ }
6
+ getQueryElement() {
7
+ return {
8
+ tag: 'disappearing_mode',
9
+ attrs: {}
10
+ };
11
+ }
12
+ getUserElement() {
13
+ return null;
14
+ }
15
+ parser(node) {
16
+ if (node.tag === 'disappearing_mode') {
17
+ assertNodeErrorFree(node);
18
+ const duration = +node?.attrs.duration;
19
+ const setAt = new Date(+(node?.attrs.t || 0) * 1000);
20
+ return {
21
+ duration,
22
+ setAt
23
+ };
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,37 @@
1
+ import { assertNodeErrorFree } from '../../WABinary/index.js';
2
+ export class USyncStatusProtocol {
3
+ constructor() {
4
+ this.name = 'status';
5
+ }
6
+ getQueryElement() {
7
+ return {
8
+ tag: 'status',
9
+ attrs: {}
10
+ };
11
+ }
12
+ getUserElement() {
13
+ return null;
14
+ }
15
+ parser(node) {
16
+ if (node.tag === 'status') {
17
+ assertNodeErrorFree(node);
18
+ let status = node?.content?.toString() ?? null;
19
+ const setAt = new Date(+(node?.attrs.t || 0) * 1000);
20
+ if (!status) {
21
+ if (node.attrs?.code && +node.attrs.code === 401) {
22
+ status = '';
23
+ }
24
+ else {
25
+ status = null;
26
+ }
27
+ }
28
+ else if (typeof status === 'string' && status.length === 0) {
29
+ status = null;
30
+ }
31
+ return {
32
+ status,
33
+ setAt
34
+ };
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,24 @@
1
+ import { assertNodeErrorFree } from '../../WABinary/index.js';
2
+ import { USyncUser } from '../USyncUser.js';
3
+ export class USyncUsernameProtocol {
4
+ constructor() {
5
+ this.name = 'username';
6
+ }
7
+ getQueryElement() {
8
+ return {
9
+ tag: 'username',
10
+ attrs: {}
11
+ };
12
+ }
13
+ getUserElement(user) {
14
+ void user;
15
+ return null;
16
+ }
17
+ parser(node) {
18
+ if (node.tag === 'username') {
19
+ assertNodeErrorFree(node);
20
+ return typeof node.content === 'string' ? node.content : null;
21
+ }
22
+ return null;
23
+ }
24
+ }
@@ -0,0 +1,50 @@
1
+ import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString } from '../../WABinary/index.js';
2
+ import { USyncUser } from '../USyncUser.js';
3
+ export class USyncBotProfileProtocol {
4
+ constructor() {
5
+ this.name = 'bot';
6
+ }
7
+ getQueryElement() {
8
+ return {
9
+ tag: 'bot',
10
+ attrs: {},
11
+ content: [{ tag: 'profile', attrs: { v: '1' } }]
12
+ };
13
+ }
14
+ getUserElement(user) {
15
+ return {
16
+ tag: 'bot',
17
+ attrs: {},
18
+ content: [{ tag: 'profile', attrs: { persona_id: user.personaId } }]
19
+ };
20
+ }
21
+ parser(node) {
22
+ const botNode = getBinaryNodeChild(node, 'bot');
23
+ const profile = getBinaryNodeChild(botNode, 'profile');
24
+ const commandsNode = getBinaryNodeChild(profile, 'commands');
25
+ const promptsNode = getBinaryNodeChild(profile, 'prompts');
26
+ const commands = [];
27
+ const prompts = [];
28
+ for (const command of getBinaryNodeChildren(commandsNode, 'command')) {
29
+ commands.push({
30
+ name: getBinaryNodeChildString(command, 'name'),
31
+ description: getBinaryNodeChildString(command, 'description')
32
+ });
33
+ }
34
+ for (const prompt of getBinaryNodeChildren(promptsNode, 'prompt')) {
35
+ prompts.push(`${getBinaryNodeChildString(prompt, 'emoji')} ${getBinaryNodeChildString(prompt, 'text')}`);
36
+ }
37
+ return {
38
+ isDefault: !!getBinaryNodeChild(profile, 'default'),
39
+ jid: node.attrs.jid,
40
+ name: getBinaryNodeChildString(profile, 'name'),
41
+ attributes: getBinaryNodeChildString(profile, 'attributes'),
42
+ description: getBinaryNodeChildString(profile, 'description'),
43
+ category: getBinaryNodeChildString(profile, 'category'),
44
+ personaId: profile.attrs['persona_id'],
45
+ commandsDescription: getBinaryNodeChildString(commandsNode, 'description'),
46
+ commands,
47
+ prompts
48
+ };
49
+ }
50
+ }
@@ -0,0 +1,28 @@
1
+ export class USyncLIDProtocol {
2
+ constructor() {
3
+ this.name = 'lid';
4
+ }
5
+ getQueryElement() {
6
+ return {
7
+ tag: 'lid',
8
+ attrs: {}
9
+ };
10
+ }
11
+ getUserElement(user) {
12
+ if (user.lid) {
13
+ return {
14
+ tag: 'lid',
15
+ attrs: { jid: user.lid }
16
+ };
17
+ }
18
+ else {
19
+ return null;
20
+ }
21
+ }
22
+ parser(node) {
23
+ if (node.tag === 'lid') {
24
+ return node.attrs.val;
25
+ }
26
+ return null;
27
+ }
28
+ }
@@ -0,0 +1,5 @@
1
+ export * from './USyncDeviceProtocol.js';
2
+ export * from './USyncContactProtocol.js';
3
+ export * from './USyncStatusProtocol.js';
4
+ export * from './USyncDisappearingModeProtocol.js';
5
+ export * from './USyncUsernameProtocol.js';
@@ -0,0 +1,97 @@
1
+ import { getBinaryNodeChild } from '../WABinary/index.js';
2
+ import { USyncBotProfileProtocol } from './Protocols/UsyncBotProfileProtocol.js';
3
+ import { USyncLIDProtocol } from './Protocols/UsyncLIDProtocol.js';
4
+ import { USyncContactProtocol, USyncDeviceProtocol, USyncDisappearingModeProtocol, USyncStatusProtocol, USyncUsernameProtocol } from './Protocols/index.js';
5
+ import { USyncUser } from './USyncUser.js';
6
+ export class USyncQuery {
7
+ constructor() {
8
+ this.protocols = [];
9
+ this.users = [];
10
+ this.context = 'interactive';
11
+ this.mode = 'query';
12
+ }
13
+ withMode(mode) {
14
+ this.mode = mode;
15
+ return this;
16
+ }
17
+ withContext(context) {
18
+ this.context = context;
19
+ return this;
20
+ }
21
+ withUser(user) {
22
+ this.users.push(user);
23
+ return this;
24
+ }
25
+ parseUSyncQueryResult(result) {
26
+ if (result?.attrs.type !== 'result') {
27
+ return;
28
+ }
29
+ const protocolMap = Object.fromEntries(this.protocols.map(protocol => {
30
+ return [protocol.name, protocol.parser];
31
+ }));
32
+ const queryResult = {
33
+ // TODO: implement errors etc.
34
+ list: [],
35
+ sideList: []
36
+ };
37
+ const usyncNode = getBinaryNodeChild(result, 'usync');
38
+ //TODO: implement error backoff, refresh etc.
39
+ //TODO: see if there are any errors in the result node
40
+ //const resultNode = getBinaryNodeChild(usyncNode, 'result')
41
+ const listNode = usyncNode ? getBinaryNodeChild(usyncNode, 'list') : undefined;
42
+ if (listNode?.content && Array.isArray(listNode.content)) {
43
+ queryResult.list = listNode.content.reduce((acc, node) => {
44
+ const id = node?.attrs.jid;
45
+ if (id) {
46
+ const data = Array.isArray(node?.content)
47
+ ? Object.fromEntries(node.content
48
+ .map(content => {
49
+ const protocol = content.tag;
50
+ const parser = protocolMap[protocol];
51
+ if (parser) {
52
+ return [protocol, parser(content)];
53
+ }
54
+ else {
55
+ return [protocol, null];
56
+ }
57
+ })
58
+ .filter(([, b]) => b !== null))
59
+ : {};
60
+ acc.push({ ...data, id });
61
+ }
62
+ return acc;
63
+ }, []);
64
+ }
65
+ //TODO: implement side list
66
+ //const sideListNode = getBinaryNodeChild(usyncNode, 'side_list')
67
+ return queryResult;
68
+ }
69
+ withDeviceProtocol() {
70
+ this.protocols.push(new USyncDeviceProtocol());
71
+ return this;
72
+ }
73
+ withContactProtocol() {
74
+ this.protocols.push(new USyncContactProtocol());
75
+ return this;
76
+ }
77
+ withStatusProtocol() {
78
+ this.protocols.push(new USyncStatusProtocol());
79
+ return this;
80
+ }
81
+ withDisappearingModeProtocol() {
82
+ this.protocols.push(new USyncDisappearingModeProtocol());
83
+ return this;
84
+ }
85
+ withBotProfileProtocol() {
86
+ this.protocols.push(new USyncBotProfileProtocol());
87
+ return this;
88
+ }
89
+ withLIDProtocol() {
90
+ this.protocols.push(new USyncLIDProtocol());
91
+ return this;
92
+ }
93
+ withUsernameProtocol() {
94
+ this.protocols.push(new USyncUsernameProtocol());
95
+ return this;
96
+ }
97
+ }
@@ -0,0 +1,30 @@
1
+ export class USyncUser {
2
+ withId(id) {
3
+ this.id = id;
4
+ return this;
5
+ }
6
+ withLid(lid) {
7
+ this.lid = lid;
8
+ return this;
9
+ }
10
+ withPhone(phone) {
11
+ this.phone = phone;
12
+ return this;
13
+ }
14
+ withUsername(username) {
15
+ this.username = username;
16
+ return this;
17
+ }
18
+ withUsernameKey(usernameKey) {
19
+ this.usernameKey = usernameKey;
20
+ return this;
21
+ }
22
+ withType(type) {
23
+ this.type = type;
24
+ return this;
25
+ }
26
+ withPersonaId(personaId) {
27
+ this.personaId = personaId;
28
+ return this;
29
+ }
30
+ }
@@ -0,0 +1,3 @@
1
+ export * from './Protocols/index.js';
2
+ export * from './USyncQuery.js';
3
+ export * from './USyncUser.js';
package/lib/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import makeWASocket from './Socket/index.js';
2
+ export * from '../WAProto/index.js';
3
+ export * from './Utils/index.js';
4
+ export * from './Types/index.js';
5
+ export * from './Defaults/index.js';
6
+ export * from './WABinary/index.js';
7
+ export * from './WAM/index.js';
8
+ export * from './WAUSync/index.js';
9
+ export { makeWASocket };
10
+ export default makeWASocket;
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@kanaraa/baileys",
3
+ "type": "module",
4
+ "version": "3.1.8",
5
+ "description": "Modded Baileys v7, Rebuilt on top of official @whiskeysockets/baileys 7.0.0-rc13, with the interactive & rich-message content types (buttons, lists, carousel, cards, shop/collection, native flow, AI rich response, sticker packs, admin invite, payments, etc.).",
6
+ "keywords": [
7
+ "whatsapp",
8
+ "whatsapp-api",
9
+ "whatsapp-web",
10
+ "baileys",
11
+ "baileys-fork",
12
+ "interactive-messages",
13
+ "rich-response"
14
+ ],
15
+ "homepage": "https://github.com/kanaraa/GaraSigmaBet",
16
+ "license": "MIT",
17
+ "author": "kanaraa",
18
+ "main": "lib/index.js",
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "files": [
23
+ "lib/**/*",
24
+ "WAProto/**/*",
25
+ "engine-requirements.js"
26
+ ],
27
+ "scripts": {
28
+ "format": "prettier --write \"lib/**/*.js\""
29
+ },
30
+ "dependencies": {
31
+ "@cacheable/node-cache": "^1.4.0",
32
+ "@hapi/boom": "^9.1.3",
33
+ "async-mutex": "^0.5.0",
34
+ "libsignal": "^6.0.0",
35
+ "lru-cache": "^11.1.0",
36
+ "music-metadata": "^11.12.3",
37
+ "p-queue": "^9.0.0",
38
+ "pino": "^9.6",
39
+ "protobufjs": "^7.5.6",
40
+ "whatsapp-rust-bridge": "0.5.4",
41
+ "ws": "^8.13.0"
42
+ },
43
+ "peerDependencies": {
44
+ "adm-zip": "^0.5.10",
45
+ "audio-decode": "^2.1.3",
46
+ "fluent-ffmpeg": "^2.1.2",
47
+ "jimp": "^1.6.1",
48
+ "link-preview-js": "^3.0.0",
49
+ "sharp": "*"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "adm-zip": {
53
+ "optional": true
54
+ },
55
+ "audio-decode": {
56
+ "optional": true
57
+ },
58
+ "fluent-ffmpeg": {
59
+ "optional": true
60
+ },
61
+ "jimp": {
62
+ "optional": true
63
+ },
64
+ "link-preview-js": {
65
+ "optional": true
66
+ },
67
+ "sharp": {
68
+ "optional": true
69
+ }
70
+ },
71
+ "engines": {
72
+ "node": ">=20.0.0"
73
+ },
74
+ "acknowledgements": "Core rebuilt on the official Baileys library by WhiskeySockets (https://github.com/WhiskeySockets/Baileys), MIT license. This is an unofficial community fork, not published or endorsed by WhiskeySockets."
75
+ }