@prototypevip/baileys 0.0.1

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 (118) hide show
  1. package/LICENSE +23 -0
  2. package/WAProto/index.js +131118 -0
  3. package/engine-requirements.js +1 -0
  4. package/lib/Defaults/index.js +187 -0
  5. package/lib/Signal/Group/ciphertext-message.js +11 -0
  6. package/lib/Signal/Group/group-session-builder.js +41 -0
  7. package/lib/Signal/Group/group_cipher.js +108 -0
  8. package/lib/Signal/Group/index.js +11 -0
  9. package/lib/Signal/Group/keyhelper.js +14 -0
  10. package/lib/Signal/Group/sender-chain-key.js +31 -0
  11. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  12. package/lib/Signal/Group/sender-key-message.js +79 -0
  13. package/lib/Signal/Group/sender-key-name.js +49 -0
  14. package/lib/Signal/Group/sender-key-record.js +46 -0
  15. package/lib/Signal/Group/sender-key-state.js +104 -0
  16. package/lib/Signal/Group/sender-message-key.js +29 -0
  17. package/lib/Signal/libsignal.js +532 -0
  18. package/lib/Signal/lid-mapping.js +312 -0
  19. package/lib/Socket/Client/index.js +2 -0
  20. package/lib/Socket/Client/types.js +10 -0
  21. package/lib/Socket/Client/websocket.js +64 -0
  22. package/lib/Socket/business.js +293 -0
  23. package/lib/Socket/chats.js +1124 -0
  24. package/lib/Socket/communities.js +528 -0
  25. package/lib/Socket/groups.js +465 -0
  26. package/lib/Socket/index.js +14 -0
  27. package/lib/Socket/messages-recv.js +2325 -0
  28. package/lib/Socket/messages-send.js +1746 -0
  29. package/lib/Socket/mex.js +55 -0
  30. package/lib/Socket/newsletter.js +317 -0
  31. package/lib/Socket/socket.js +1185 -0
  32. package/lib/Store/cache-factory.js +20 -0
  33. package/lib/Store/index.js +5 -0
  34. package/lib/Store/make-in-memory-store.js +523 -0
  35. package/lib/Store/make-ordered-dictionary.js +203 -0
  36. package/lib/Store/object-repository.js +23 -0
  37. package/lib/Store/prototype-store.js +958 -0
  38. package/lib/Types/Auth.js +1 -0
  39. package/lib/Types/Bussines.js +1 -0
  40. package/lib/Types/Call.js +1 -0
  41. package/lib/Types/Chat.js +7 -0
  42. package/lib/Types/Contact.js +1 -0
  43. package/lib/Types/Events.js +1 -0
  44. package/lib/Types/GroupMetadata.js +1 -0
  45. package/lib/Types/Label.js +24 -0
  46. package/lib/Types/LabelAssociation.js +6 -0
  47. package/lib/Types/Message.js +18 -0
  48. package/lib/Types/Mex.js +37 -0
  49. package/lib/Types/Newsletter.js +36 -0
  50. package/lib/Types/Product.js +1 -0
  51. package/lib/Types/RichType.js +25 -0
  52. package/lib/Types/Signal.js +1 -0
  53. package/lib/Types/Socket.js +2 -0
  54. package/lib/Types/State.js +78 -0
  55. package/lib/Types/USync.js +1 -0
  56. package/lib/Types/index.js +33 -0
  57. package/lib/Utils/auth-utils.js +303 -0
  58. package/lib/Utils/browser-utils.js +32 -0
  59. package/lib/Utils/business.js +245 -0
  60. package/lib/Utils/chat-utils.js +971 -0
  61. package/lib/Utils/companion-reg-client-utils.js +54 -0
  62. package/lib/Utils/constants.js +24 -0
  63. package/lib/Utils/crypto.js +133 -0
  64. package/lib/Utils/cstoken-utils.js +41 -0
  65. package/lib/Utils/decode-wa-message.js +406 -0
  66. package/lib/Utils/event-buffer.js +616 -0
  67. package/lib/Utils/generics.js +438 -0
  68. package/lib/Utils/history.js +147 -0
  69. package/lib/Utils/identity-change-handler.js +63 -0
  70. package/lib/Utils/index.js +29 -0
  71. package/lib/Utils/interactive-message-handler.js +478 -0
  72. package/lib/Utils/link-preview.js +91 -0
  73. package/lib/Utils/logger.js +2 -0
  74. package/lib/Utils/lt-hash.js +6 -0
  75. package/lib/Utils/make-mutex.js +31 -0
  76. package/lib/Utils/message-retry-manager.js +291 -0
  77. package/lib/Utils/messages-media.js +881 -0
  78. package/lib/Utils/messages.js +1434 -0
  79. package/lib/Utils/noise-handler.js +229 -0
  80. package/lib/Utils/normalize-message-identity.js +73 -0
  81. package/lib/Utils/offline-node-processor.js +50 -0
  82. package/lib/Utils/pre-key-manager.js +119 -0
  83. package/lib/Utils/process-message.js +648 -0
  84. package/lib/Utils/reporting-utils.js +355 -0
  85. package/lib/Utils/rich-message-utils.js +264 -0
  86. package/lib/Utils/signal.js +233 -0
  87. package/lib/Utils/stanza-ack.js +33 -0
  88. package/lib/Utils/sticker-utils.js +221 -0
  89. package/lib/Utils/sync-action-utils.js +53 -0
  90. package/lib/Utils/tc-token-utils.js +182 -0
  91. package/lib/Utils/use-multi-file-auth-state.js +118 -0
  92. package/lib/Utils/use-prototype-auth-state.js +217 -0
  93. package/lib/Utils/use-single-file-auth-state.js +94 -0
  94. package/lib/Utils/validate-connection.js +235 -0
  95. package/lib/WABinary/constants.js +1468 -0
  96. package/lib/WABinary/decode.js +258 -0
  97. package/lib/WABinary/encode.js +219 -0
  98. package/lib/WABinary/generic-utils.js +202 -0
  99. package/lib/WABinary/index.js +5 -0
  100. package/lib/WABinary/jid-utils.js +94 -0
  101. package/lib/WABinary/types.js +1 -0
  102. package/lib/WAM/BinaryInfo.js +9 -0
  103. package/lib/WAM/constants.js +20669 -0
  104. package/lib/WAM/encode.js +151 -0
  105. package/lib/WAM/index.js +3 -0
  106. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -0
  107. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +59 -0
  108. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -0
  109. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +29 -0
  110. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  111. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +59 -0
  112. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +21 -0
  113. package/lib/WAUSync/Protocols/index.js +4 -0
  114. package/lib/WAUSync/USyncQuery.js +133 -0
  115. package/lib/WAUSync/USyncUser.js +22 -0
  116. package/lib/WAUSync/index.js +3 -0
  117. package/lib/index.js +12 -0
  118. package/package.json +78 -0
@@ -0,0 +1,151 @@
1
+ import { BinaryInfo } from "./BinaryInfo.js";
2
+ import {
3
+ FLAG_BYTE,
4
+ FLAG_EVENT,
5
+ FLAG_EXTENDED,
6
+ FLAG_FIELD,
7
+ FLAG_GLOBAL,
8
+ WEB_EVENTS,
9
+ WEB_GLOBALS,
10
+ } from "./constants.js";
11
+ const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
12
+ export const encodeWAM = (binaryInfo) => {
13
+ binaryInfo.buffer = [];
14
+ encodeWAMHeader(binaryInfo);
15
+ encodeEvents(binaryInfo);
16
+ const totalSize = binaryInfo.buffer
17
+ .map((a) => a.length)
18
+ .reduce((a, b) => a + b);
19
+ const buffer = Buffer.alloc(totalSize);
20
+ let offset = 0;
21
+ for (const buffer_ of binaryInfo.buffer) {
22
+ buffer_.copy(buffer, offset);
23
+ offset += buffer_.length;
24
+ }
25
+ return buffer;
26
+ };
27
+ function encodeWAMHeader(binaryInfo) {
28
+ const headerBuffer = Buffer.alloc(8); // starting buffer
29
+ headerBuffer.write("WAM", 0, "utf8");
30
+ headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3);
31
+ headerBuffer.writeUInt8(1, 4); //random flag
32
+ headerBuffer.writeUInt16BE(binaryInfo.sequence, 5);
33
+ headerBuffer.writeUInt8(0, 7); // regular channel
34
+ binaryInfo.buffer.push(headerBuffer);
35
+ }
36
+ function encodeGlobalAttributes(binaryInfo, globals) {
37
+ for (const [key, _value] of Object.entries(globals)) {
38
+ const id = WEB_GLOBALS.find((a) => a?.name === key).id;
39
+ let value = _value;
40
+ if (typeof value === "boolean") {
41
+ value = value ? 1 : 0;
42
+ }
43
+ binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
44
+ }
45
+ }
46
+ function encodeEvents(binaryInfo) {
47
+ for (const [name, { props, globals }] of binaryInfo.events.map(
48
+ (a) => Object.entries(a)[0],
49
+ )) {
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
+ } else if (typeof value === "number" && Number.isInteger(value)) {
83
+ // is number
84
+ if (value === 0 || value === 1) {
85
+ buffer = Buffer.alloc(bufferLength);
86
+ offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4));
87
+ return buffer;
88
+ } else if (-128 <= value && value < 128) {
89
+ buffer = Buffer.alloc(bufferLength + 1);
90
+ offset = serializeHeader(buffer, offset, key, flag | (3 << 4));
91
+ buffer.writeInt8(value, offset);
92
+ return buffer;
93
+ } else if (-32768 <= value && value < 32768) {
94
+ buffer = Buffer.alloc(bufferLength + 2);
95
+ offset = serializeHeader(buffer, offset, key, flag | (4 << 4));
96
+ buffer.writeInt16LE(value, offset);
97
+ return buffer;
98
+ } else if (-2147483648 <= value && value < 2147483648) {
99
+ buffer = Buffer.alloc(bufferLength + 4);
100
+ offset = serializeHeader(buffer, offset, key, flag | (5 << 4));
101
+ buffer.writeInt32LE(value, offset);
102
+ return buffer;
103
+ } else {
104
+ buffer = Buffer.alloc(bufferLength + 8);
105
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
106
+ buffer.writeDoubleLE(value, offset);
107
+ return buffer;
108
+ }
109
+ } else if (typeof value === "number") {
110
+ // is float
111
+ buffer = Buffer.alloc(bufferLength + 8);
112
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
113
+ buffer.writeDoubleLE(value, offset);
114
+ return buffer;
115
+ } else if (typeof value === "string") {
116
+ // is string
117
+ const utf8Bytes = Buffer.byteLength(value, "utf8");
118
+ if (utf8Bytes < 256) {
119
+ buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
120
+ offset = serializeHeader(buffer, offset, key, flag | (8 << 4));
121
+ buffer.writeUint8(utf8Bytes, offset++);
122
+ } else if (utf8Bytes < 65536) {
123
+ buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes);
124
+ offset = serializeHeader(buffer, offset, key, flag | (9 << 4));
125
+ buffer.writeUInt16LE(utf8Bytes, offset);
126
+ offset += 2;
127
+ } else {
128
+ buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes);
129
+ offset = serializeHeader(buffer, offset, key, flag | (10 << 4));
130
+ buffer.writeUInt32LE(utf8Bytes, offset);
131
+ offset += 4;
132
+ }
133
+ buffer.write(value, offset, "utf8");
134
+ return buffer;
135
+ }
136
+ throw "missing";
137
+ }
138
+ function serializeHeader(buffer, offset, key, flag) {
139
+ if (key < 256) {
140
+ buffer.writeUInt8(flag, offset);
141
+ offset += 1;
142
+ buffer.writeUInt8(key, offset);
143
+ offset += 1;
144
+ } else {
145
+ buffer.writeUInt8(flag | FLAG_BYTE, offset);
146
+ offset += 1;
147
+ buffer.writeUInt16LE(key, offset);
148
+ offset += 2;
149
+ }
150
+ return offset;
151
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./constants.js";
2
+ export * from "./encode.js";
3
+ export * from "./BinaryInfo.js";
@@ -0,0 +1,28 @@
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 { tag: "contact", attrs: {} };
9
+ }
10
+ getUserElement(user) {
11
+ const attrs = {};
12
+ if (user.type) {
13
+ attrs.type = user.type;
14
+ }
15
+ return {
16
+ tag: "contact",
17
+ attrs: attrs,
18
+ content: user.username || user.phone,
19
+ };
20
+ }
21
+ parser(node) {
22
+ if (node.tag === "contact") {
23
+ assertNodeErrorFree(node);
24
+ return node?.attrs?.type === "in";
25
+ }
26
+ return false;
27
+ }
28
+ }
@@ -0,0 +1,59 @@
1
+ import {
2
+ assertNodeErrorFree,
3
+ getBinaryNodeChild,
4
+ } from "../../WABinary/index.js";
5
+ export class USyncDeviceProtocol {
6
+ constructor() {
7
+ this.name = "devices";
8
+ }
9
+ getQueryElement() {
10
+ return { tag: "devices", attrs: { version: "2" } };
11
+ }
12
+ getUserElement(user) {
13
+ const attrs = {};
14
+ if (user.phashing) {
15
+ attrs.phashing = user.phashing;
16
+ }
17
+ if (user.ts) {
18
+ attrs.ts = user.ts;
19
+ }
20
+ if (user.expectedTs) {
21
+ attrs.expected_ts = user.expectedTs;
22
+ }
23
+ return Object.keys(attrs).length > 0
24
+ ? { tag: "devices", attrs: attrs }
25
+ : null;
26
+ }
27
+ parser(node) {
28
+ const deviceList = [];
29
+ let keyIndex = undefined;
30
+ if (node.tag === "devices") {
31
+ assertNodeErrorFree(node);
32
+ const deviceListNode = getBinaryNodeChild(node, "device-list");
33
+ const keyIndexNode = getBinaryNodeChild(node, "key-index-list");
34
+ if (Array.isArray(deviceListNode?.content)) {
35
+ for (const { tag, attrs } of deviceListNode.content) {
36
+ const id = +attrs.id;
37
+ const keyIndex = +attrs["key-index"];
38
+ if (tag === "device") {
39
+ deviceList.push({
40
+ id: id,
41
+ keyIndex: keyIndex,
42
+ isHosted: !!(attrs["is_hosted"] && attrs["is_hosted"] === "true"),
43
+ });
44
+ }
45
+ }
46
+ }
47
+ if (keyIndexNode?.tag === "key-index-list") {
48
+ keyIndex = {
49
+ timestamp: +keyIndexNode.attrs["ts"],
50
+ signedKeyIndex: keyIndexNode?.content,
51
+ expectedTimestamp: keyIndexNode.attrs["expected_ts"]
52
+ ? +keyIndexNode.attrs["expected_ts"]
53
+ : undefined,
54
+ };
55
+ }
56
+ }
57
+ return { deviceList: deviceList, keyIndex: keyIndex };
58
+ }
59
+ }
@@ -0,0 +1,20 @@
1
+ import { assertNodeErrorFree } from "../../WABinary/index.js";
2
+ export class USyncDisappearingModeProtocol {
3
+ constructor() {
4
+ this.name = "disappearing_mode";
5
+ }
6
+ getQueryElement() {
7
+ return { tag: "disappearing_mode", attrs: {} };
8
+ }
9
+ getUserElement() {
10
+ return null;
11
+ }
12
+ parser(node) {
13
+ if (node.tag === "disappearing_mode") {
14
+ assertNodeErrorFree(node);
15
+ const duration = +node?.attrs.duration;
16
+ const setAt = new Date(+(node?.attrs.t || 0) * 1e3);
17
+ return { duration: duration, setAt: setAt };
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,29 @@
1
+ import { assertNodeErrorFree } from "../../WABinary/index.js";
2
+ export class USyncStatusProtocol {
3
+ constructor() {
4
+ this.name = "status";
5
+ }
6
+ getQueryElement() {
7
+ return { tag: "status", attrs: {} };
8
+ }
9
+ getUserElement() {
10
+ return null;
11
+ }
12
+ parser(node) {
13
+ if (node.tag === "status") {
14
+ assertNodeErrorFree(node);
15
+ let status = node?.content?.toString() ?? null;
16
+ const setAt = new Date(+(node?.attrs.t || 0) * 1e3);
17
+ if (!status) {
18
+ if (node.attrs?.code && +node.attrs.code === 401) {
19
+ status = "";
20
+ } else {
21
+ status = null;
22
+ }
23
+ } else if (typeof status === "string" && status.length === 0) {
24
+ status = null;
25
+ }
26
+ return { status: status, setAt: setAt };
27
+ }
28
+ }
29
+ }
@@ -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,59 @@
1
+ import {
2
+ getBinaryNodeChild,
3
+ getBinaryNodeChildren,
4
+ getBinaryNodeChildString,
5
+ } from "../../WABinary/index.js";
6
+ import { USyncUser } from "../USyncUser.js";
7
+ export class USyncBotProfileProtocol {
8
+ constructor() {
9
+ this.name = "bot";
10
+ }
11
+ getQueryElement() {
12
+ return {
13
+ tag: "bot",
14
+ attrs: {},
15
+ content: [{ tag: "profile", attrs: { v: "1" } }],
16
+ };
17
+ }
18
+ getUserElement(user) {
19
+ return {
20
+ tag: "bot",
21
+ attrs: {},
22
+ content: [{ tag: "profile", attrs: { persona_id: user.personaId } }],
23
+ };
24
+ }
25
+ parser(node) {
26
+ const botNode = getBinaryNodeChild(node, "bot");
27
+ const profile = getBinaryNodeChild(botNode, "profile");
28
+ const commandsNode = getBinaryNodeChild(profile, "commands");
29
+ const promptsNode = getBinaryNodeChild(profile, "prompts");
30
+ const commands = [];
31
+ const prompts = [];
32
+ for (const command of getBinaryNodeChildren(commandsNode, "command")) {
33
+ commands.push({
34
+ name: getBinaryNodeChildString(command, "name"),
35
+ description: getBinaryNodeChildString(command, "description"),
36
+ });
37
+ }
38
+ for (const prompt of getBinaryNodeChildren(promptsNode, "prompt")) {
39
+ prompts.push(
40
+ `${getBinaryNodeChildString(prompt, "emoji")} ${getBinaryNodeChildString(prompt, "text")}`,
41
+ );
42
+ }
43
+ return {
44
+ isDefault: !!getBinaryNodeChild(profile, "default"),
45
+ jid: node.attrs.jid,
46
+ name: getBinaryNodeChildString(profile, "name"),
47
+ attributes: getBinaryNodeChildString(profile, "attributes"),
48
+ description: getBinaryNodeChildString(profile, "description"),
49
+ category: getBinaryNodeChildString(profile, "category"),
50
+ personaId: profile.attrs["persona_id"],
51
+ commandsDescription: getBinaryNodeChildString(
52
+ commandsNode,
53
+ "description",
54
+ ),
55
+ commands: commands,
56
+ prompts: prompts,
57
+ };
58
+ }
59
+ }
@@ -0,0 +1,21 @@
1
+ export class USyncLIDProtocol {
2
+ constructor() {
3
+ this.name = "lid";
4
+ }
5
+ getQueryElement() {
6
+ return { tag: "lid", attrs: {} };
7
+ }
8
+ getUserElement(user) {
9
+ if (user.lid) {
10
+ return { tag: "lid", attrs: { jid: user.lid } };
11
+ } else {
12
+ return null;
13
+ }
14
+ }
15
+ parser(node) {
16
+ if (node.tag === "lid") {
17
+ return node.attrs.val;
18
+ }
19
+ return null;
20
+ }
21
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./USyncDeviceProtocol.js";
2
+ export * from "./USyncContactProtocol.js";
3
+ export * from "./USyncStatusProtocol.js";
4
+ export * from "./USyncDisappearingModeProtocol.js";
@@ -0,0 +1,133 @@
1
+ import { getBinaryNodeChild } from "../WABinary/index.js";
2
+ import { USyncBotProfileProtocol } from "./Protocols/UsyncBotProfileProtocol.js";
3
+ import { USyncLIDProtocol } from "./Protocols/UsyncLIDProtocol.js";
4
+ import {
5
+ USyncContactProtocol,
6
+ USyncDeviceProtocol,
7
+ USyncDisappearingModeProtocol,
8
+ USyncStatusProtocol,
9
+ } from "./Protocols/index.js";
10
+ import { USyncUser } from "./USyncUser.js";
11
+ export class USyncQuery {
12
+ constructor() {
13
+ this.protocols = [];
14
+ this.users = [];
15
+ this.context = "interactive";
16
+ this.mode = "query";
17
+ }
18
+ withMode(mode) {
19
+ this.mode = mode;
20
+ return this;
21
+ }
22
+ withContext(context) {
23
+ this.context = context;
24
+ return this;
25
+ }
26
+ withUser(user) {
27
+ this.users.push(user);
28
+ return this;
29
+ }
30
+ parseUSyncQueryResult(result) {
31
+ if (!result || result.attrs.type !== "result") {
32
+ return;
33
+ }
34
+ const protocolMap = Object.fromEntries(
35
+ this.protocols.map((protocol) => {
36
+ return [protocol.name, protocol.parser];
37
+ }),
38
+ );
39
+ const queryResult = {
40
+ errors: [],
41
+ list: [],
42
+ sideList: [],
43
+ };
44
+ const usyncNode = getBinaryNodeChild(result, "usync");
45
+ const errorNode = getBinaryNodeChild(usyncNode, "error");
46
+ if (errorNode) {
47
+ queryResult.errors.push({
48
+ code: +errorNode.attrs.code,
49
+ text: errorNode.attrs.text,
50
+ });
51
+ }
52
+
53
+ const listNode = usyncNode
54
+ ? getBinaryNodeChild(usyncNode, "list")
55
+ : undefined;
56
+ if (listNode?.content && Array.isArray(listNode.content)) {
57
+ queryResult.list = listNode.content.reduce((acc, node) => {
58
+ const id = node?.attrs.jid;
59
+ if (id) {
60
+ const data = Array.isArray(node?.content)
61
+ ? Object.fromEntries(
62
+ node.content
63
+ .map((content) => {
64
+ const protocol = content.tag;
65
+ const parser = protocolMap[protocol];
66
+ if (parser) {
67
+ return [protocol, parser(content)];
68
+ } else {
69
+ return [protocol, null];
70
+ }
71
+ })
72
+ .filter(([, b]) => b !== null),
73
+ )
74
+ : {};
75
+ acc.push({ ...data, id: id });
76
+ }
77
+ return acc;
78
+ }, []);
79
+ }
80
+ const sideListNode = usyncNode
81
+ ? getBinaryNodeChild(usyncNode, "side_list")
82
+ : undefined;
83
+ if (sideListNode?.content && Array.isArray(sideListNode.content)) {
84
+ queryResult.sideList = sideListNode.content.reduce((acc, node) => {
85
+ const id = node?.attrs.jid;
86
+ if (id) {
87
+ const data = Array.isArray(node?.content)
88
+ ? Object.fromEntries(
89
+ node.content
90
+ .map((content) => {
91
+ const protocol = content.tag;
92
+ const parser = protocolMap[protocol];
93
+ if (parser) {
94
+ return [protocol, parser(content)];
95
+ } else {
96
+ return [protocol, null];
97
+ }
98
+ })
99
+ .filter(([, b]) => b !== null),
100
+ )
101
+ : {};
102
+ acc.push({ ...data, id: id });
103
+ }
104
+ return acc;
105
+ }, []);
106
+ }
107
+ return queryResult;
108
+ }
109
+ withDeviceProtocol() {
110
+ this.protocols.push(new USyncDeviceProtocol());
111
+ return this;
112
+ }
113
+ withContactProtocol() {
114
+ this.protocols.push(new USyncContactProtocol());
115
+ return this;
116
+ }
117
+ withStatusProtocol() {
118
+ this.protocols.push(new USyncStatusProtocol());
119
+ return this;
120
+ }
121
+ withDisappearingModeProtocol() {
122
+ this.protocols.push(new USyncDisappearingModeProtocol());
123
+ return this;
124
+ }
125
+ withBotProfileProtocol() {
126
+ this.protocols.push(new USyncBotProfileProtocol());
127
+ return this;
128
+ }
129
+ withLIDProtocol() {
130
+ this.protocols.push(new USyncLIDProtocol());
131
+ return this;
132
+ }
133
+ }
@@ -0,0 +1,22 @@
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
+ withType(type) {
15
+ this.type = type;
16
+ return this;
17
+ }
18
+ withPersonaId(personaId) {
19
+ this.personaId = personaId;
20
+ return this;
21
+ }
22
+ }
@@ -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,12 @@
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 "./Store/index.js";
7
+ export * from "./WABinary/index.js";
8
+ export * from "./WAM/index.js";
9
+ export * from "./WAUSync/index.js";
10
+ export * from "./Store/cache-factory.js";
11
+ export { makeWASocket };
12
+ export default makeWASocket;
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@prototypevip/baileys",
3
+ "version": "0.0.1",
4
+ "description": "A simple fork of Baileys for WhatsApp automation",
5
+ "main": "lib/index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "preinstall": "node ./engine-requirements.js"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "engines": {
14
+ "node": ">=20.0.0"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/GSK-F/baileys.git"
19
+ },
20
+ "files": [
21
+ "lib/**/*",
22
+ "WAProto/**/*",
23
+ "engine-requirements.js"
24
+ ],
25
+ "keywords": [
26
+ "automation",
27
+ "baileys",
28
+ "baileys-fork",
29
+ "baileys-mod",
30
+ "js-whatsapp",
31
+ "multi-device",
32
+ "whatsapp",
33
+ "whatsapp-api",
34
+ "whatsapp-bot",
35
+ "whatsapp-chat",
36
+ "whatsapp-group",
37
+ "whatsapp-web"
38
+ ],
39
+ "homepage": "https://github.com/GSK-F/baileys",
40
+ "author": "The Prototype",
41
+ "license": "MIT",
42
+ "dependencies": {
43
+ "@adiwajshing/keyed-db": "^0.2.4",
44
+ "@cacheable/node-cache": "^1.4.0",
45
+ "@hapi/boom": "^9.1.3",
46
+ "async-mutex": "^0.5.0",
47
+ "fflate": "^0.8.2",
48
+ "libsignal": "github:WhiskeySockets/libsignal-wasm#master",
49
+ "lru-cache": "^11.2.6",
50
+ "music-metadata": "^11.7.0",
51
+ "p-queue": "^9.1.0",
52
+ "pino": "^9.6.0",
53
+ "protobufjs": "^7.5.4",
54
+ "whatsapp-rust-bridge": "0.5.3",
55
+ "ws": "^8.19.0"
56
+ },
57
+ "peerDependencies": {
58
+ "@napi-rs/image": "~1.12.0",
59
+ "audio-decode": "^2.2.3",
60
+ "jimp": "*",
61
+ "link-preview-js": "^3.0.0",
62
+ "sharp": "*"
63
+ },
64
+ "peerDependenciesMeta": {
65
+ "@napi-rs/image": {
66
+ "optional": true
67
+ },
68
+ "audio-decode": {
69
+ "optional": true
70
+ },
71
+ "jimp": {
72
+ "optional": true
73
+ },
74
+ "link-preview-js": {
75
+ "optional": true
76
+ }
77
+ }
78
+ }