@ryuhan/baileys 1.0.1 → 1.0.4

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 (115) hide show
  1. package/LICENSE +1 -1
  2. package/{README.md → README.MD} +16 -30
  3. package/lib/Defaults/index.js +50 -35
  4. package/lib/Defaults/ryuhan-version.json +3 -0
  5. package/lib/Socket/chats.js +147 -87
  6. package/lib/Socket/messages-recv.js +127 -43
  7. package/lib/Socket/socket.js +17 -4
  8. package/lib/Store/make-in-memory-store.js +1 -1
  9. package/lib/Utils/browser-utils.js +35 -0
  10. package/lib/Utils/event-buffer.js +2 -2
  11. package/lib/Utils/generics.js +36 -10
  12. package/lib/Utils/identity-change-handler.js +52 -0
  13. package/lib/Utils/index.js +4 -1
  14. package/lib/Utils/message-retry-manager.js +135 -0
  15. package/lib/Utils/process-message.js +17 -7
  16. package/lib/Utils/{baileys-event-stream.js → ryuhan-event-stream.js} +1 -1
  17. package/lib/Utils/use-multi-file-auth-state.js +0 -2
  18. package/lib/Utils/validate-connection.js +77 -21
  19. package/lib/index.js +30 -2
  20. package/package.json +11 -10
  21. package/WAProto/index.d.ts +0 -55057
  22. package/WAProto/index.ts.ts +0 -53473
  23. package/WAProto/p.html +0 -1
  24. package/lib/Defaults/baileys-version.json +0 -3
  25. package/lib/Defaults/index.d.ts +0 -51
  26. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  27. package/lib/Signal/Group/group-session-builder.d.ts +0 -14
  28. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  29. package/lib/Signal/Group/index.d.ts +0 -11
  30. package/lib/Signal/Group/keyhelper.d.ts +0 -10
  31. package/lib/Signal/Group/queue-job.d.ts +0 -1
  32. package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
  33. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
  34. package/lib/Signal/Group/sender-key-message.d.ts +0 -18
  35. package/lib/Signal/Group/sender-key-name.d.ts +0 -17
  36. package/lib/Signal/Group/sender-key-record.d.ts +0 -30
  37. package/lib/Signal/Group/sender-key-state.d.ts +0 -38
  38. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  39. package/lib/Signal/libsignal.d.ts +0 -3
  40. package/lib/Socket/Client/index.d.ts +0 -2
  41. package/lib/Socket/Client/types.d.ts +0 -16
  42. package/lib/Socket/Client/websocket.d.ts +0 -13
  43. package/lib/Socket/business.d.ts +0 -172
  44. package/lib/Socket/chats.d.ts +0 -82
  45. package/lib/Socket/groups.d.ts +0 -124
  46. package/lib/Socket/index.d.ts +0 -172
  47. package/lib/Socket/messages-recv.d.ts +0 -161
  48. package/lib/Socket/messages-send.d.ts +0 -151
  49. package/lib/Socket/newsletter.d.ts +0 -136
  50. package/lib/Socket/socket.d.ts +0 -43
  51. package/lib/Socket/usync.d.ts +0 -36
  52. package/lib/Store/index.d.ts +0 -2
  53. package/lib/Store/make-in-memory-store.d.ts +0 -118
  54. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  55. package/lib/Store/object-repository.d.ts +0 -10
  56. package/lib/Types/Auth.d.ts +0 -103
  57. package/lib/Types/Call.d.ts +0 -13
  58. package/lib/Types/Chat.d.ts +0 -109
  59. package/lib/Types/Contact.d.ts +0 -23
  60. package/lib/Types/Events.d.ts +0 -199
  61. package/lib/Types/GroupMetadata.d.ts +0 -64
  62. package/lib/Types/Label.d.ts +0 -35
  63. package/lib/Types/LabelAssociation.d.ts +0 -29
  64. package/lib/Types/Message.d.ts +0 -400
  65. package/lib/Types/Newsletter.d.ts +0 -79
  66. package/lib/Types/Product.d.ts +0 -78
  67. package/lib/Types/Signal.d.ts +0 -57
  68. package/lib/Types/Socket.d.ts +0 -119
  69. package/lib/Types/State.d.ts +0 -27
  70. package/lib/Types/USync.d.ts +0 -25
  71. package/lib/Types/index.d.ts +0 -64
  72. package/lib/Utils/auth-utils.d.ts +0 -18
  73. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  74. package/lib/Utils/business.d.ts +0 -22
  75. package/lib/Utils/chat-utils.d.ts +0 -70
  76. package/lib/Utils/crypto.d.ts +0 -40
  77. package/lib/Utils/decode-wa-message.d.ts +0 -35
  78. package/lib/Utils/event-buffer.d.ts +0 -35
  79. package/lib/Utils/generics.d.ts +0 -89
  80. package/lib/Utils/history.d.ts +0 -19
  81. package/lib/Utils/index.d.ts +0 -17
  82. package/lib/Utils/link-preview.d.ts +0 -21
  83. package/lib/Utils/logger.d.ts +0 -11
  84. package/lib/Utils/lt-hash.d.ts +0 -12
  85. package/lib/Utils/make-mutex.d.ts +0 -7
  86. package/lib/Utils/messages-media.d.ts +0 -120
  87. package/lib/Utils/messages.d.ts +0 -80
  88. package/lib/Utils/noise-handler.d.ts +0 -19
  89. package/lib/Utils/process-message.d.ts +0 -42
  90. package/lib/Utils/signal.d.ts +0 -33
  91. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
  92. package/lib/Utils/validate-connection.d.ts +0 -10
  93. package/lib/WABinary/constants.d.ts +0 -27
  94. package/lib/WABinary/decode.d.ts +0 -6
  95. package/lib/WABinary/encode.d.ts +0 -2
  96. package/lib/WABinary/generic-utils.d.ts +0 -14
  97. package/lib/WABinary/index.d.ts +0 -5
  98. package/lib/WABinary/jid-utils.d.ts +0 -37
  99. package/lib/WABinary/jid-utils.js.bak +0 -83
  100. package/lib/WABinary/types.d.ts +0 -18
  101. package/lib/WAM/BinaryInfo.d.ts +0 -8
  102. package/lib/WAM/constants.d.ts +0 -38
  103. package/lib/WAM/encode.d.ts +0 -2
  104. package/lib/WAM/index.d.ts +0 -3
  105. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  106. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  107. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  108. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  109. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  110. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  111. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  112. package/lib/WAUSync/USyncQuery.d.ts +0 -28
  113. package/lib/WAUSync/USyncUser.d.ts +0 -12
  114. package/lib/WAUSync/index.d.ts +0 -3
  115. package/lib/index.d.ts +0 -16
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageRetryManager = void 0;
4
+ exports.createMessageRetryManager = createMessageRetryManager;
5
+
6
+ const lru_cache_1 = require("lru-cache");
7
+
8
+ const RECENT_MESSAGES_SIZE = 512;
9
+
10
+ const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000;
11
+
12
+ const PHONE_REQUEST_DELAY = 3000;
13
+
14
+ function createMessageRetryManager(options) {
15
+ const { logger, maxRetries, phoneRequestDelayMs } = options;
16
+ return new MessageRetryManager(logger, maxRetries, phoneRequestDelayMs);
17
+ }
18
+
19
+ class MessageRetryManager {
20
+ constructor(logger, maxMsgRetryCount, phoneRequestDelayMs = PHONE_REQUEST_DELAY) {
21
+ this.logger = logger;
22
+ this.maxMsgRetryCount = maxMsgRetryCount;
23
+ this.phoneRequestDelayMs = phoneRequestDelayMs;
24
+ this._recentMessagesMap = new lru_cache_1.LRUCache({
25
+ max: RECENT_MESSAGES_SIZE
26
+ });
27
+ this._sessionRecreateHistory = new lru_cache_1.LRUCache({
28
+ ttl: RECREATE_SESSION_TIMEOUT * 2,
29
+ ttlAutopurge: true
30
+ });
31
+ this._retryCounters = new lru_cache_1.LRUCache({
32
+ ttl: 15 * 60 * 1000,
33
+ ttlAutopurge: true,
34
+ updateAgeOnGet: true
35
+ });
36
+ this._pendingPhoneRequests = {};
37
+ this.statistics = {
38
+ totalRetries: 0,
39
+ successfulRetries: 0,
40
+ failedRetries: 0,
41
+ mediaRetries: 0,
42
+ sessionRecreations: 0,
43
+ phoneRequests: 0
44
+ };
45
+ }
46
+ addRecentMessage(to, id, message) {
47
+ const key = { to, id };
48
+ const keyStr = this._keyToString(key);
49
+ this._recentMessagesMap.set(keyStr, {
50
+ message,
51
+ timestamp: Date.now()
52
+ });
53
+ this.logger.debug(`Added message to retry cache: ${to}/${id}`);
54
+ }
55
+ getRecentMessage(to, id) {
56
+ const key = { to, id };
57
+ const keyStr = this._keyToString(key);
58
+ return this._recentMessagesMap.get(keyStr);
59
+ }
60
+ shouldRecreateSession(jid, hasSession) {
61
+ if (!hasSession) {
62
+ this._sessionRecreateHistory.set(jid, Date.now());
63
+ this.statistics.sessionRecreations++;
64
+ return {
65
+ reason: "we don't have a Signal session with them",
66
+ recreate: true
67
+ };
68
+ }
69
+ const retryCount = this._retryCounters.get(jid) || 0;
70
+ if (retryCount < 2) {
71
+ return { reason: '', recreate: false };
72
+ }
73
+ const now = Date.now();
74
+ const prevTime = this._sessionRecreateHistory.get(jid);
75
+ if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
76
+ this._sessionRecreateHistory.set(jid, now);
77
+ this.statistics.sessionRecreations++;
78
+ return {
79
+ reason: 'retry count > 1 and over an hour since last recreation',
80
+ recreate: true
81
+ };
82
+ }
83
+ return { reason: '', recreate: false };
84
+ }
85
+ incrementRetryCount(messageId) {
86
+ this._retryCounters.set(messageId, (this._retryCounters.get(messageId) || 0) + 1);
87
+ this.statistics.totalRetries++;
88
+ return this._retryCounters.get(messageId);
89
+ }
90
+ getRetryCount(messageId) {
91
+ return this._retryCounters.get(messageId) || 0;
92
+ }
93
+ hasExceededMaxRetries(messageId) {
94
+ return this.getRetryCount(messageId) >= this.maxMsgRetryCount;
95
+ }
96
+ markRetrySuccess(messageId) {
97
+ this.statistics.successfulRetries++;
98
+ this._retryCounters.delete(messageId);
99
+ this._cancelPendingPhoneRequest(messageId);
100
+ }
101
+ markRetryFailed(messageId) {
102
+ this.statistics.failedRetries++;
103
+ this._retryCounters.delete(messageId);
104
+ }
105
+ schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
106
+ this._cancelPendingPhoneRequest(messageId);
107
+ this._pendingPhoneRequests[messageId] = setTimeout(() => {
108
+ delete this._pendingPhoneRequests[messageId];
109
+ this.statistics.phoneRequests++;
110
+ callback();
111
+ }, delay);
112
+ this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
113
+ }
114
+ cancelPendingPhoneRequest(messageId) {
115
+ const timeout = this._pendingPhoneRequests[messageId];
116
+ if (timeout) {
117
+ clearTimeout(timeout);
118
+ delete this._pendingPhoneRequests[messageId];
119
+ this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
120
+ }
121
+ }
122
+ _keyToString(key) {
123
+ return `${key.to}:${key.id}`;
124
+ }
125
+ _cancelPendingPhoneRequest(messageId) {
126
+ const timeout = this._pendingPhoneRequests[messageId];
127
+ if (timeout) {
128
+ clearTimeout(timeout);
129
+ delete this._pendingPhoneRequests[messageId];
130
+ this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
131
+ }
132
+ }
133
+ }
134
+
135
+ exports.MessageRetryManager = MessageRetryManager;
@@ -19,16 +19,24 @@ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
19
19
  Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD
20
20
  ]);
21
21
  /** Cleans a received message to further processing */
22
- const cleanMessage = (message, meId) => {
22
+ const cleanMessage = (message, meId, meLid) => {
23
23
  // ensure remoteJid and participant doesn't have device or agent in it
24
24
  // normalize JIDs but catch errors to avoid throwing on invalid LIDs/JIDs
25
- try {
26
- message.key.remoteJid = (0, WABinary_1.jidNormalizedUser)(message.key.remoteJid);
25
+ if ((0, WABinary_1.isHostedLidUser)(message.key.remoteJid) || (0, WABinary_1.isHostedPnUser)(message.key.remoteJid)) {
26
+ message.key.remoteJid = (0, WABinary_1.jidEncode)((0, WABinary_1.jidDecode)(message.key === null || message.key === void 0 ? void 0 : message.key.remoteJid) === null || (0, WABinary_1.jidDecode)(message.key === null || message.key === void 0 ? void 0 : message.key.remoteJid) === void 0 ? void 0 : (0, WABinary_1.jidDecode)(message.key === null || message.key === void 0 ? void 0 : message.key.remoteJid).user, (0, WABinary_1.isHostedPnUser)(message.key.remoteJid) ? 's.whatsapp.net' : 'lid');
27
27
  }
28
- catch (_e) {
29
- // if normalization fails, retain original remoteJid
28
+ else {
29
+ try {
30
+ message.key.remoteJid = (0, WABinary_1.jidNormalizedUser)(message.key.remoteJid);
31
+ }
32
+ catch (_e) {
33
+ // if normalization fails, retain original remoteJid
34
+ }
35
+ }
36
+ if ((0, WABinary_1.isHostedLidUser)(message.key.participant) || (0, WABinary_1.isHostedPnUser)(message.key.participant)) {
37
+ message.key.participant = (0, WABinary_1.jidEncode)((0, WABinary_1.jidDecode)(message.key.participant) === null || (0, WABinary_1.jidDecode)(message.key.participant) === void 0 ? void 0 : (0, WABinary_1.jidDecode)(message.key.participant).user, (0, WABinary_1.isHostedPnUser)(message.key.participant) ? 's.whatsapp.net' : 'lid');
30
38
  }
31
- if (message.key.participant) {
39
+ else if (message.key.participant) {
32
40
  try {
33
41
  message.key.participant = (0, WABinary_1.jidNormalizedUser)(message.key.participant);
34
42
  }
@@ -51,11 +59,13 @@ const cleanMessage = (message, meId) => {
51
59
  // if the sender believed the message being reacted to is not from them
52
60
  // we've to correct the key to be from them, or some other participant
53
61
  msgKey.fromMe = !msgKey.fromMe
54
- ? (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId)
62
+ ? (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId) ||
63
+ (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meLid)
55
64
  // if the message being reacted to, was from them
56
65
  // fromMe automatically becomes false
57
66
  : false;
58
67
  // set the remoteJid to being the same as the chat the message came from
68
+ // TODO: investigate inconsistencies
59
69
  msgKey.remoteJid = message.key.remoteJid;
60
70
  // set participant of the message
61
71
  msgKey.participant = msgKey.participant || message.key.participant;
@@ -11,7 +11,7 @@ const readline_1 = require("readline");
11
11
  const generics_1 = require("./generics");
12
12
  const make_mutex_1 = require("./make-mutex");
13
13
  /**
14
- * Captures events from a baileys event emitter & stores them in a file
14
+ * Captures events from a ryuhan event emitter & stores them in a file
15
15
  * @param ev The event emitter to read events from
16
16
  * @param filename File to save to
17
17
  */
@@ -8,8 +8,6 @@ const WAProto_1 = require("../../WAProto");
8
8
  const auth_utils_1 = require("./auth-utils");
9
9
  const generics_1 = require("./generics");
10
10
  // We need to lock files due to the fact that we are using async functions to read and write files
11
- // https://github.com/WhiskeySockets/Baileys/issues/794
12
- // https://github.com/nodejs/node/issues/26338
13
11
  // Use a Map to store mutexes for each file path
14
12
  const fileLocks = new Map();
15
13
  // Get or create a mutex for a specific file path
@@ -9,6 +9,7 @@ const WABinary_1 = require("../WABinary");
9
9
  const crypto_2 = require("./crypto");
10
10
  const generics_1 = require("./generics");
11
11
  const signal_1 = require("./signal");
12
+
12
13
  const getUserAgent = (config) => {
13
14
  return {
14
15
  appVersion: {
@@ -22,20 +23,25 @@ const getUserAgent = (config) => {
22
23
  device: 'Desktop',
23
24
  osBuildNumber: '0.1',
24
25
  localeLanguageIso6391: 'en',
25
- localeCountryIso31661Alpha2: 'US'
26
+ mnc: '000',
27
+ mcc: '000',
28
+ localeCountryIso31661Alpha2: config.countryCode || 'US'
26
29
  };
27
30
  };
31
+
28
32
  const PLATFORM_MAP = {
29
33
  'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
30
34
  'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
31
35
  };
36
+
32
37
  const getWebInfo = (config) => {
33
38
  let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
34
- if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
39
+ if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
35
40
  webSubPlatform = PLATFORM_MAP[config.browser[0]];
36
41
  }
37
42
  return { webSubPlatform };
38
43
  };
44
+
39
45
  const getClientPayload = (config) => {
40
46
  const payload = {
41
47
  connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
@@ -45,34 +51,61 @@ const getClientPayload = (config) => {
45
51
  payload.webInfo = getWebInfo(config);
46
52
  return payload;
47
53
  };
54
+
48
55
  const generateLoginNode = (userJid, config) => {
49
56
  const { user, device } = (0, WABinary_1.jidDecode)(userJid);
50
57
  const payload = {
51
58
  ...getClientPayload(config),
52
- passive: false,
59
+ passive: true,
53
60
  pull: true,
54
61
  username: +user,
55
62
  device: device,
63
+ lidDbMigrated: false
56
64
  };
57
65
  return WAProto_1.proto.ClientPayload.fromObject(payload);
58
66
  };
59
67
  exports.generateLoginNode = generateLoginNode;
68
+
60
69
  const getPlatformType = (platform) => {
61
70
  const platformType = platform.toUpperCase();
62
- return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.DESKTOP;
71
+ return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.CHROME;
63
72
  };
73
+
64
74
  const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
65
- // the app version needs to be md5 hashed
66
- // and passed in
67
75
  const appVersionBuf = (0, crypto_1.createHash)('md5')
68
- .update(config.version.join('.')) // join as string
76
+ .update(config.version.join('.'))
69
77
  .digest();
78
+
70
79
  const companion = {
71
80
  os: config.browser[0],
72
81
  platformType: getPlatformType(config.browser[1]),
73
82
  requireFullSync: config.syncFullHistory,
83
+ historySyncConfig: {
84
+ storageQuotaMb: 10240,
85
+ inlineInitialPayloadInE2EeMsg: true,
86
+ recentSyncDaysLimit: undefined,
87
+ supportCallLogHistory: false,
88
+ supportBotUserAgentChatHistory: true,
89
+ supportCagReactionsAndPolls: true,
90
+ supportBizHostedMsg: true,
91
+ supportRecentSyncChunkMessageCountTuning: true,
92
+ supportHostedGroupMsg: true,
93
+ supportFbidBotChatHistory: true,
94
+ supportAddOnHistorySyncMigration: undefined,
95
+ supportMessageAssociation: true,
96
+ supportGroupHistory: false,
97
+ onDemandReady: undefined,
98
+ supportGuestChat: undefined
99
+ },
100
+ version: {
101
+ primary: 10,
102
+ secondary: 15,
103
+ tertiary: 7
104
+ }
74
105
  };
106
+
75
107
  const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
108
+
76
109
  const registerPayload = {
77
110
  ...getClientPayload(config),
78
111
  passive: false,
@@ -91,6 +124,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
91
124
  return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
92
125
  };
93
126
  exports.generateRegistrationNode = generateRegistrationNode;
127
+
94
128
  const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
95
129
  const msgId = stanza.attrs.id;
96
130
  const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
@@ -98,30 +132,52 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
98
132
  const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
99
133
  const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
100
134
  const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
135
+
101
136
  if (!deviceIdentityNode || !deviceNode) {
102
137
  throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
103
138
  }
104
- const bizName = businessNode === null || businessNode === void 0 ? void 0 : businessNode.attrs.name;
139
+
140
+ const bizName = businessNode?.attrs.name;
105
141
  const jid = deviceNode.attrs.jid;
142
+ const lid = deviceNode.attrs.lid;
143
+
106
144
  const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
107
- const isHostedAccount = accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED;
108
- const hmacPrefix = isHostedAccount ? Buffer.from([6, 5]) : Buffer.alloc(0);
145
+
146
+ let hmacPrefix = Buffer.from([]);
147
+ if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
148
+ hmacPrefix = Buffer.from([0x06, 0x05]);
149
+ }
150
+
109
151
  const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
110
152
  if (Buffer.compare(hmac, advSign) !== 0) {
111
153
  throw new boom_1.Boom('Invalid account signature');
112
154
  }
155
+
113
156
  const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
114
157
  const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
115
- const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails, signedIdentityKey.public]);
158
+
159
+ const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(deviceDetails);
160
+
161
+ const accountSignaturePrefix = deviceIdentity.deviceType === WAProto_1.proto.ADVEncryptionType.HOSTED
162
+ ? Buffer.from([0x06, 0x05])
163
+ : Buffer.from([0x06, 0x00]);
164
+ const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
165
+
116
166
  if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
117
167
  throw new boom_1.Boom('Failed to verify account signature');
118
168
  }
119
- const devicePrefix = isHostedAccount ? Buffer.from([6, 6]) : Buffer.from([6, 1]);
120
- const deviceMsg = Buffer.concat([devicePrefix, deviceDetails, signedIdentityKey.public, accountSignatureKey]);
169
+
170
+ const deviceMsg = Buffer.concat([
171
+ Buffer.from([0x06, 0x01]),
172
+ deviceDetails,
173
+ signedIdentityKey.public,
174
+ accountSignatureKey
175
+ ]);
121
176
  account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
177
+
122
178
  const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
123
179
  const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
124
- const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(account.details);
180
+
125
181
  const reply = {
126
182
  tag: 'iq',
127
183
  attrs: {
@@ -143,31 +199,31 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
143
199
  }
144
200
  ]
145
201
  };
202
+
146
203
  const authUpdate = {
147
204
  account,
148
- me: { id: jid, name: bizName },
205
+ me: { id: jid, name: bizName, lid },
149
206
  signalIdentities: [
150
207
  ...(signalIdentities || []),
151
208
  identity
152
209
  ],
153
- platform: platformNode === null || platformNode === void 0 ? void 0 : platformNode.attrs.name
210
+ platform: platformNode?.attrs.name
154
211
  };
212
+
155
213
  return {
156
214
  creds: authUpdate,
157
215
  reply
158
216
  };
159
217
  };
160
218
  exports.configureSuccessfulPairing = configureSuccessfulPairing;
219
+
161
220
  const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
162
- var _a;
163
221
  account = { ...account };
164
- // set to null if we are not to include the signature key
165
- // or if we are including the signature key but it is empty
166
- if (!includeSignatureKey || !((_a = account.accountSignatureKey) === null || _a === void 0 ? void 0 : _a.length)) {
222
+ if (!includeSignatureKey || !account.accountSignatureKey?.length) {
167
223
  account.accountSignatureKey = null;
168
224
  }
169
225
  return WAProto_1.proto.ADVSignedDeviceIdentity
170
226
  .encode(account)
171
227
  .finish();
172
228
  };
173
- exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
229
+ exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
package/lib/index.js CHANGED
@@ -4,10 +4,38 @@ const chalk = require("chalk");
4
4
  const gradient = require("gradient-string");
5
5
 
6
6
  console.log();
7
+
8
+ const rimuru =
9
+ chalk.bold.blue("Ri") +
10
+ chalk.bold.cyan("mu") +
11
+ chalk.bold.magenta("ru");
12
+
13
+ console.log(chalk.bold("╔══════════════════════════════╗"));
14
+ console.log(chalk.bold("║ ") + rimuru + chalk.bold(" ║"));
15
+ console.log(chalk.bold("╚══════════════════════════════╝"));
16
+
17
+ console.log();
18
+
19
+ const devWatermark = gradient(["cyan", "magenta"])(
20
+ " Github: github.com/ryuhandev "
21
+ );
22
+
23
+ console.log(
24
+ chalk.bold(
25
+ chalk.bgBlack("╭────────────────────────────────────────╮")
26
+ )
27
+ );
7
28
  console.log(
8
- chalk.bold.hex('#FFA500')('TENSURA INTERACTIVE ') + chalk.bold.cyan('Baileys')
29
+ chalk.bold(
30
+ chalk.bgBlack("│") + devWatermark + chalk.bold(chalk.bgBlack("│"))
31
+ )
9
32
  );
10
- console.log(gradient(['magenta', 'cyan'])('> Rimuru Baileys By Ryuhan. <'));
33
+ console.log(
34
+ chalk.bold(
35
+ chalk.bgBlack("╰────────────────────────────────────────╯")
36
+ )
37
+ );
38
+
11
39
  console.log();
12
40
 
13
41
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
package/package.json CHANGED
@@ -1,24 +1,25 @@
1
1
  {
2
2
  "name": "@ryuhan/baileys",
3
- "version": "1.0.1",
4
- "description": "Tensura Interactive Project",
3
+ "version": "1.0.4",
4
+ "description": "Rimuru Baileys - Fixed & Enhanced Version",
5
5
  "keywords": [
6
6
  "baileys",
7
- "ryuhan",
8
7
  "whatsapp",
9
8
  "whatsapp-api",
10
9
  "whatsapp-web",
11
10
  "whatsapp-bot",
12
- "automation",
13
- "multi-device"
11
+ "tensura",
12
+ "rimuru",
13
+ "multi-device",
14
+ "ryuhan"
14
15
  ],
15
- "homepage": "https://github.com/ryuhandev/rimuru-baileys",
16
+ "homepage": "https://www.npmjs.com/package/@ryuhan/baileys",
16
17
  "repository": {
17
18
  "type": "git",
18
19
  "url": "https://github.com/ryuhandev/rimuru-baileys.git"
19
20
  },
20
21
  "license": "MIT",
21
- "author": "ryuhan",
22
+ "author": "ryuhan <ryuhandev@users.noreply.github.com>",
22
23
  "main": "lib/index.js",
23
24
  "types": "lib/index.d.ts",
24
25
  "files": [
@@ -37,8 +38,8 @@
37
38
  "gen:protobuf": "sh WAProto/GenerateStatics.sh",
38
39
  "lint": "eslint src --ext .js,.ts,.jsx,.tsx",
39
40
  "lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
40
- "prepack": "echo 'Ryuhan Baileys'",
41
- "prepare": "echo 'Ryuhan Baileys'",
41
+ "prepack": "echo 'Tensura Interactive WhatsApp Library by Ryuhan'",
42
+ "prepare": "echo 'Tensura Interactive Library by Ryuhan'",
42
43
  "preinstall": "node ./engine-requirements.js",
43
44
  "release": "release-it",
44
45
  "test": "jest"
@@ -54,7 +55,7 @@
54
55
  "cache-manager": "^5.7.6",
55
56
  "cheerio": "^1.0.0-rc.10",
56
57
  "libphonenumber-js": "^1.10.20",
57
- "libsignal": "github:NaufalYupra/libsignal-node",
58
+ "libsignal": "github:ryuhandev/libsignal-node",
58
59
  "lodash": "^4.17.21",
59
60
  "music-metadata": "^7.12.3",
60
61
  "pino": "^9.6",