@jkt48connect-corp/baileys 7.2.6 → 7.2.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 (102) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +838 -94
  3. package/WAProto/WAProto.proto +969 -88
  4. package/WAProto/index.d.ts +13199 -1260
  5. package/WAProto/index.js +124901 -74525
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.d.ts +7 -8
  8. package/lib/Defaults/index.js +5 -3
  9. package/lib/Defaults/phonenumber-mcc.json +221 -221
  10. package/lib/Signal/libsignal.js +18 -9
  11. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -2
  12. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -1
  13. package/lib/Socket/business.d.ts +40 -40
  14. package/lib/Socket/chats.d.ts +13 -14
  15. package/lib/Socket/groups.d.ts +20 -21
  16. package/lib/Socket/groups.js +1 -1
  17. package/lib/Socket/index.d.ts +49 -49
  18. package/lib/Socket/messages-recv.d.ts +39 -39
  19. package/lib/Socket/messages-recv.js +310 -151
  20. package/lib/Socket/messages-send.d.ts +33 -31
  21. package/lib/Socket/messages-send.js +269 -36
  22. package/lib/Socket/newsletter.d.ts +24 -25
  23. package/lib/Socket/newsletter.js +3 -3
  24. package/lib/Socket/registration.d.ts +49 -52
  25. package/lib/Socket/registration.js +7 -7
  26. package/lib/Socket/socket.d.ts +6 -7
  27. package/lib/Socket/socket.js +7 -3
  28. package/lib/Store/make-cache-manager-store.d.ts +1 -0
  29. package/lib/Store/make-in-memory-store.d.ts +3 -4
  30. package/lib/Store/make-in-memory-store.js +13 -11
  31. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  32. package/lib/Types/Auth.d.ts +0 -1
  33. package/lib/Types/Call.d.ts +1 -1
  34. package/lib/Types/Chat.d.ts +12 -7
  35. package/lib/Types/Events.d.ts +17 -2
  36. package/lib/Types/GroupMetadata.d.ts +3 -1
  37. package/lib/Types/Label.d.ts +11 -0
  38. package/lib/Types/Label.js +1 -1
  39. package/lib/Types/LabelAssociation.js +1 -1
  40. package/lib/Types/Message.d.ts +164 -13
  41. package/lib/Types/Newsletter.js +3 -3
  42. package/lib/Types/Socket.d.ts +7 -2
  43. package/lib/Types/index.d.ts +9 -0
  44. package/lib/Types/index.js +1 -1
  45. package/lib/Utils/auth-utils.js +3 -3
  46. package/lib/Utils/business.d.ts +1 -1
  47. package/lib/Utils/business.js +2 -2
  48. package/lib/Utils/chat-utils.d.ts +11 -12
  49. package/lib/Utils/chat-utils.js +41 -20
  50. package/lib/Utils/crypto.d.ts +15 -16
  51. package/lib/Utils/crypto.js +35 -23
  52. package/lib/Utils/decode-wa-message.d.ts +17 -0
  53. package/lib/Utils/decode-wa-message.js +43 -15
  54. package/lib/Utils/generics.d.ts +10 -19
  55. package/lib/Utils/generics.js +32 -16
  56. package/lib/Utils/history.d.ts +6 -2
  57. package/lib/Utils/history.js +3 -0
  58. package/lib/Utils/index.d.ts +0 -1
  59. package/lib/Utils/index.js +0 -1
  60. package/lib/Utils/logger.d.ts +1 -3
  61. package/lib/Utils/make-mutex.d.ts +2 -2
  62. package/lib/Utils/messages-media.d.ts +25 -28
  63. package/lib/Utils/messages-media.js +38 -47
  64. package/lib/Utils/messages.d.ts +5 -8
  65. package/lib/Utils/messages.js +430 -12
  66. package/lib/Utils/noise-handler.d.ts +4 -5
  67. package/lib/Utils/process-message.js +2 -2
  68. package/lib/Utils/use-multi-file-auth-state.js +17 -3
  69. package/lib/Utils/validate-connection.d.ts +2 -2
  70. package/lib/Utils/validate-connection.js +12 -23
  71. package/lib/WABinary/decode.d.ts +1 -2
  72. package/lib/WABinary/decode.js +17 -7
  73. package/lib/WABinary/encode.d.ts +1 -2
  74. package/lib/WABinary/encode.js +33 -17
  75. package/lib/WABinary/generic-utils.d.ts +2 -3
  76. package/lib/WABinary/generic-utils.js +2 -2
  77. package/lib/WABinary/jid-utils.d.ts +1 -1
  78. package/lib/WAM/BinaryInfo.d.ts +2 -11
  79. package/lib/WAM/encode.d.ts +1 -2
  80. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  81. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  82. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  83. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  84. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  85. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  86. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  87. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  88. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  89. package/lib/WAUSync/Protocols/index.js +20 -0
  90. package/lib/WAUSync/USyncQuery.d.ts +26 -0
  91. package/lib/WAUSync/USyncQuery.js +79 -0
  92. package/lib/WAUSync/USyncUser.d.ts +10 -0
  93. package/lib/WAUSync/USyncUser.js +22 -0
  94. package/lib/WAUSync/index.d.ts +3 -0
  95. package/lib/WAUSync/index.js +19 -0
  96. package/lib/index.js +4 -1
  97. package/package.json +15 -10
  98. package/lib/Socket/community.d.ts +0 -219
  99. package/lib/Socket/community.js +0 -354
  100. package/lib/Utils/use-single-file-auth-statev2.d.ts +0 -12
  101. package/lib/Utils/use-single-file-auth-statev2.js +0 -75
  102. package/lib/index.d.ts +0 -11
@@ -10,30 +10,21 @@ const crypto_2 = require("./crypto");
10
10
  const generics_1 = require("./generics");
11
11
  const signal_1 = require("./signal");
12
12
  const getUserAgent = (config) => {
13
- var _a, _b;
14
- const osVersion = config.mobile ? '15.3.1' : '0.1';
15
- const version = config.mobile ? [2, 24, 6] : config.version;
16
- const device = config.mobile ? 'iPhone_7' : 'Desktop';
17
- const manufacturer = config.mobile ? 'Apple' : '';
18
- const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
19
- const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
20
13
  return {
21
14
  appVersion: {
22
- primary: version[0],
23
- secondary: version[1],
24
- tertiary: version[2],
15
+ primary: config.version[0],
16
+ secondary: config.version[1],
17
+ tertiary: config.version[2],
25
18
  },
26
- platform,
19
+ platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
27
20
  releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
28
- mcc: ((_a = config.auth.creds.registration) === null || _a === void 0 ? void 0 : _a.phoneNumberMobileCountryCode) || '000',
29
- mnc: ((_b = config.auth.creds.registration) === null || _b === void 0 ? void 0 : _b.phoneNumberMobileNetworkCode) || '000',
30
- osVersion: osVersion,
31
- manufacturer,
32
- device,
33
- osBuildNumber: osVersion,
21
+ osVersion: '0.1',
22
+ device: 'Desktop',
23
+ osBuildNumber: '0.1',
34
24
  localeLanguageIso6391: 'en',
35
- localeCountryIso31661Alpha2: 'US',
36
- ...phoneId
25
+ mnc: '000',
26
+ mcc: '000',
27
+ localeCountryIso31661Alpha2: config.countryCode,
37
28
  };
38
29
  };
39
30
  const PLATFORM_MAP = {
@@ -53,9 +44,7 @@ const getClientPayload = (config) => {
53
44
  connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
54
45
  userAgent: getUserAgent(config),
55
46
  };
56
- if (!config.mobile) {
57
- payload.webInfo = getWebInfo(config);
58
- }
47
+ payload.webInfo = getWebInfo(config);
59
48
  return payload;
60
49
  };
61
50
  const generateMobileNode = (config) => {
@@ -72,7 +61,7 @@ const generateMobileNode = (config) => {
72
61
  appCached: false,
73
62
  dnsMethod: WAProto_1.proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
74
63
  },
75
- passive: false,
64
+ passive: false, // XMPP heartbeat setting (false: server actively pings) (true: client actively pings)
76
65
  pushName: 'test',
77
66
  username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
78
67
  };
@@ -1,7 +1,6 @@
1
- /// <reference types="node" />
2
1
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
3
2
  export declare const decompressingIfRequired: (buffer: Buffer) => Buffer;
4
- export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, 'DOUBLE_BYTE_TOKENS' | 'SINGLE_BYTE_TOKENS' | 'TAGS'>, indexRef?: {
3
+ export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, "DOUBLE_BYTE_TOKENS" | "SINGLE_BYTE_TOKENS" | "TAGS">, indexRef?: {
5
4
  index: number;
6
5
  }) => BinaryNode;
7
6
  export declare const decodeBinaryNode: (buff: Buffer) => BinaryNode;
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
27
37
  const zlib_1 = require("zlib");
@@ -1,3 +1,2 @@
1
- /// <reference types="node" />
2
1
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
3
- export declare const encodeBinaryNode: ({ tag, attrs, content }: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) => Buffer;
2
+ export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, "TAGS" | "TOKEN_MAP">, buffer?: number[]) => Buffer;
@@ -15,18 +15,33 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.encodeBinaryNode = void 0;
27
37
  const constants = __importStar(require("./constants"));
28
38
  const jid_utils_1 = require("./jid-utils");
29
- const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0]) => {
39
+ const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
40
+ const encoded = encodeBinaryNodeInner(node, opts, buffer);
41
+ return Buffer.from(encoded);
42
+ };
43
+ exports.encodeBinaryNode = encodeBinaryNode;
44
+ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
30
45
  const { TAGS, TOKEN_MAP } = opts;
31
46
  const pushByte = (value) => buffer.push(value & 0xff);
32
47
  const pushInt = (value, n, littleEndian = false) => {
@@ -35,7 +50,11 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
35
50
  buffer.push((value >> (curShift * 8)) & 0xff);
36
51
  }
37
52
  };
38
- const pushBytes = (bytes) => (bytes.forEach(b => buffer.push(b)));
53
+ const pushBytes = (bytes) => {
54
+ for (const b of bytes) {
55
+ buffer.push(b);
56
+ }
57
+ };
39
58
  const pushInt16 = (value) => {
40
59
  pushBytes([(value >> 8) & 0xff, value & 0xff]);
41
60
  };
@@ -137,8 +156,7 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
137
156
  if (str.length > TAGS.PACKED_MAX) {
138
157
  return false;
139
158
  }
140
- for (let i = 0; i < str.length; i++) {
141
- const char = str[i];
159
+ for (const char of str) {
142
160
  const isInNibbleRange = char >= '0' && char <= '9';
143
161
  if (!isInNibbleRange && char !== '-' && char !== '.') {
144
162
  return false;
@@ -150,10 +168,9 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
150
168
  if (str.length > TAGS.PACKED_MAX) {
151
169
  return false;
152
170
  }
153
- for (let i = 0; i < str.length; i++) {
154
- const char = str[i];
171
+ for (const char of str) {
155
172
  const isInNibbleRange = char >= '0' && char <= '9';
156
- if (!isInNibbleRange && !(char >= 'A' && char <= 'F') && !(char >= 'a' && char <= 'f')) {
173
+ if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
157
174
  return false;
158
175
  }
159
176
  }
@@ -214,7 +231,7 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
214
231
  else if (Array.isArray(content)) {
215
232
  writeListStart(content.length);
216
233
  for (const item of content) {
217
- (0, exports.encodeBinaryNode)(item, opts, buffer);
234
+ encodeBinaryNodeInner(item, opts, buffer);
218
235
  }
219
236
  }
220
237
  else if (typeof content === 'undefined') {
@@ -223,6 +240,5 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
223
240
  else {
224
241
  throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
225
242
  }
226
- return Buffer.from(buffer);
243
+ return buffer;
227
244
  };
228
- exports.encodeBinaryNode = encodeBinaryNode;
@@ -1,11 +1,10 @@
1
- /// <reference types="node" />
2
1
  import { proto } from '../../WAProto';
3
2
  import { BinaryNode } from './types';
4
3
  export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
5
4
  export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
6
5
  export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
7
- export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array | Buffer | undefined;
8
- export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
6
+ export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => string | Uint8Array<ArrayBufferLike> | BinaryNode[] | undefined;
7
+ export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => any;
9
8
  export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
10
9
  export declare const assertNodeErrorFree: (node: BinaryNode) => void;
11
10
  export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: string) => {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.binaryNodeToString = exports.getBinaryNodeMessages = exports.reduceBinaryNodeToDictionary = exports.assertNodeErrorFree = exports.getBinaryNodeChildUInt = exports.getBinaryNodeChildString = exports.getBinaryNodeChildBuffer = exports.getBinaryNodeChild = exports.getAllBinaryNodeChildren = exports.getBinaryNodeChildren = void 0;
3
+ exports.getBinaryNodeMessages = exports.reduceBinaryNodeToDictionary = exports.assertNodeErrorFree = exports.getBinaryNodeChildUInt = exports.getBinaryNodeChildString = exports.getBinaryNodeChildBuffer = exports.getBinaryNodeChild = exports.getAllBinaryNodeChildren = exports.getBinaryNodeChildren = void 0;
4
+ exports.binaryNodeToString = binaryNodeToString;
4
5
  const boom_1 = require("@hapi/boom");
5
6
  const WAProto_1 = require("../../WAProto");
6
7
  // some extra useful utilities
@@ -107,4 +108,3 @@ function binaryNodeToString(node, i = 0) {
107
108
  const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
108
109
  return tag + content;
109
110
  }
110
- exports.binaryNodeToString = binaryNodeToString;
@@ -25,7 +25,7 @@ export declare const isJidBroadcast: (jid: string | undefined) => boolean | unde
25
25
  /** is the jid a group */
26
26
  export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
27
27
  /** is the jid the status broadcast */
28
- export declare const isJidStatusBroadcast: (jid: string) => boolean;
28
+ export declare const isJidStatusBroadcast: (jid: string) => jid is "status@broadcast";
29
29
  /** is the jid the newsletter */
30
30
  export declare const isJidNewsLetter: (jid: string | undefined) => boolean | undefined;
31
31
  export declare const jidNormalizedUser: (jid: string | undefined) => string;
@@ -1,17 +1,8 @@
1
- /// <reference types="node" />
1
+ import { EventInputType } from './constants';
2
2
  export declare class BinaryInfo {
3
3
  protocolVersion: number;
4
4
  sequence: number;
5
- events: {
6
- [x: string]: {
7
- props: {
8
- [x: string]: any;
9
- };
10
- globals: {
11
- [x: string]: any;
12
- };
13
- };
14
- }[];
5
+ events: EventInputType[];
15
6
  buffer: Buffer[];
16
7
  constructor(options?: Partial<BinaryInfo>);
17
8
  }
@@ -1,3 +1,2 @@
1
- /// <reference types="node" />
2
1
  import { BinaryInfo } from './BinaryInfo';
3
- export declare const encodeWAM: (binaryInfo: BinaryInfo) => Buffer;
2
+ export declare const encodeWAM: (binaryInfo: BinaryInfo) => any;
@@ -0,0 +1,9 @@
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
+ import { USyncUser } from '../USyncUser';
4
+ export declare class USyncContactProtocol implements USyncQueryProtocol {
5
+ name: string;
6
+ getQueryElement(): BinaryNode;
7
+ getUserElement(user: USyncUser): BinaryNode;
8
+ parser(node: BinaryNode): boolean;
9
+ }
@@ -0,0 +1,32 @@
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 ((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.type) === 'in';
28
+ }
29
+ return false;
30
+ }
31
+ }
32
+ exports.USyncContactProtocol = USyncContactProtocol;
@@ -0,0 +1,22 @@
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
+ export type KeyIndexData = {
4
+ timestamp: number;
5
+ signedKeyIndex?: Uint8Array;
6
+ expectedTimestamp?: number;
7
+ };
8
+ export type DeviceListData = {
9
+ id: number;
10
+ keyIndex?: number;
11
+ isHosted?: boolean;
12
+ };
13
+ export type ParsedDeviceInfo = {
14
+ deviceList?: DeviceListData[];
15
+ keyIndex?: KeyIndexData;
16
+ };
17
+ export declare class USyncDeviceProtocol implements USyncQueryProtocol {
18
+ name: string;
19
+ getQueryElement(): BinaryNode;
20
+ getUserElement(): BinaryNode | null;
21
+ parser(node: BinaryNode): ParsedDeviceInfo;
22
+ }
@@ -0,0 +1,57 @@
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 (Array.isArray(deviceListNode === null || deviceListNode === void 0 ? void 0 : deviceListNode.content)) {
31
+ for (const { tag, attrs } of deviceListNode.content) {
32
+ const id = +attrs.id;
33
+ const keyIndex = +attrs['key-index'];
34
+ if (tag === 'device') {
35
+ deviceList.push({
36
+ id,
37
+ keyIndex,
38
+ isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
39
+ });
40
+ }
41
+ }
42
+ }
43
+ if ((keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.tag) === 'key-index-list') {
44
+ keyIndex = {
45
+ timestamp: +keyIndexNode.attrs['ts'],
46
+ signedKeyIndex: keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.content,
47
+ expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
48
+ };
49
+ }
50
+ }
51
+ return {
52
+ deviceList,
53
+ keyIndex
54
+ };
55
+ }
56
+ }
57
+ exports.USyncDeviceProtocol = USyncDeviceProtocol;
@@ -0,0 +1,12 @@
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
+ export type DisappearingModeData = {
4
+ duration: number;
5
+ setAt?: Date;
6
+ };
7
+ export declare class USyncDisappearingModeProtocol implements USyncQueryProtocol {
8
+ name: string;
9
+ getQueryElement(): BinaryNode;
10
+ getUserElement(): null;
11
+ parser(node: BinaryNode): DisappearingModeData | undefined;
12
+ }
@@ -0,0 +1,30 @@
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(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
23
+ return {
24
+ duration,
25
+ setAt,
26
+ };
27
+ }
28
+ }
29
+ }
30
+ exports.USyncDisappearingModeProtocol = USyncDisappearingModeProtocol;
@@ -0,0 +1,12 @@
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
+ export type StatusData = {
4
+ status?: string | null;
5
+ setAt?: Date;
6
+ };
7
+ export declare class USyncStatusProtocol implements USyncQueryProtocol {
8
+ name: string;
9
+ getQueryElement(): BinaryNode;
10
+ getUserElement(): null;
11
+ parser(node: BinaryNode): StatusData | undefined;
12
+ }
@@ -0,0 +1,42 @@
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;
20
+ if (node.tag === 'status') {
21
+ (0, WABinary_1.assertNodeErrorFree)(node);
22
+ let status = node === null || node === void 0 ? void 0 : node.content.toString();
23
+ const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
24
+ if (!status) {
25
+ if (+((_a = node.attrs) === null || _a === void 0 ? void 0 : _a.code) === 401) {
26
+ status = '';
27
+ }
28
+ else {
29
+ status = null;
30
+ }
31
+ }
32
+ else if (typeof status === 'string' && status.length === 0) {
33
+ status = null;
34
+ }
35
+ return {
36
+ status,
37
+ setAt,
38
+ };
39
+ }
40
+ }
41
+ }
42
+ exports.USyncStatusProtocol = USyncStatusProtocol;
@@ -0,0 +1,4 @@
1
+ export * from './USyncDeviceProtocol';
2
+ export * from './USyncContactProtocol';
3
+ export * from './USyncStatusProtocol';
4
+ export * from './USyncDisappearingModeProtocol';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./USyncDeviceProtocol"), exports);
18
+ __exportStar(require("./USyncContactProtocol"), exports);
19
+ __exportStar(require("./USyncStatusProtocol"), exports);
20
+ __exportStar(require("./USyncDisappearingModeProtocol"), exports);
@@ -0,0 +1,26 @@
1
+ import { USyncQueryProtocol } from '../Types/USync';
2
+ import { BinaryNode } from '../WABinary';
3
+ import { USyncUser } from './USyncUser';
4
+ export type USyncQueryResultList = {
5
+ [protocol: string]: unknown;
6
+ id: string;
7
+ };
8
+ export type USyncQueryResult = {
9
+ list: USyncQueryResultList[];
10
+ sideList: USyncQueryResultList[];
11
+ };
12
+ export declare class USyncQuery {
13
+ protocols: USyncQueryProtocol[];
14
+ users: USyncUser[];
15
+ context: string;
16
+ mode: string;
17
+ constructor();
18
+ withMode(mode: string): this;
19
+ withContext(context: string): this;
20
+ withUser(user: USyncUser): this;
21
+ parseUSyncQueryResult(result: BinaryNode): USyncQueryResult | undefined;
22
+ withDeviceProtocol(): this;
23
+ withContactProtocol(): this;
24
+ withStatusProtocol(): this;
25
+ withDisappearingModeProtocol(): this;
26
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncQuery = void 0;
4
+ const WABinary_1 = require("../WABinary");
5
+ const Protocols_1 = require("./Protocols");
6
+ 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 = (0, WABinary_1.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 = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
42
+ if (Array.isArray(listNode === null || listNode === void 0 ? void 0 : listNode.content) && typeof listNode !== 'undefined') {
43
+ queryResult.list = listNode.content.map((node) => {
44
+ const id = node === null || node === void 0 ? void 0 : node.attrs.jid;
45
+ const data = Array.isArray(node === null || node === void 0 ? void 0 : node.content) ? Object.fromEntries(node.content.map((content) => {
46
+ const protocol = content.tag;
47
+ const parser = protocolMap[protocol];
48
+ if (parser) {
49
+ return [protocol, parser(content)];
50
+ }
51
+ else {
52
+ return [protocol, null];
53
+ }
54
+ }).filter(([, b]) => b !== null)) : {};
55
+ return { ...data, id };
56
+ });
57
+ }
58
+ //TODO: implement side list
59
+ //const sideListNode = getBinaryNodeChild(usyncNode, 'side_list')
60
+ return queryResult;
61
+ }
62
+ withDeviceProtocol() {
63
+ this.protocols.push(new Protocols_1.USyncDeviceProtocol());
64
+ return this;
65
+ }
66
+ withContactProtocol() {
67
+ this.protocols.push(new Protocols_1.USyncContactProtocol());
68
+ return this;
69
+ }
70
+ withStatusProtocol() {
71
+ this.protocols.push(new Protocols_1.USyncStatusProtocol());
72
+ return this;
73
+ }
74
+ withDisappearingModeProtocol() {
75
+ this.protocols.push(new Protocols_1.USyncDisappearingModeProtocol());
76
+ return this;
77
+ }
78
+ }
79
+ exports.USyncQuery = USyncQuery;
@@ -0,0 +1,10 @@
1
+ export declare class USyncUser {
2
+ id: string;
3
+ lid: string;
4
+ phone: string;
5
+ type: string;
6
+ withId(id: string): this;
7
+ withLid(lid: string): this;
8
+ withPhone(phone: string): this;
9
+ withType(type: string): this;
10
+ }