gifted-baileys 1.5.5 → 1.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1642
- package/WAProto/WAProto.proto +969 -88
- package/WAProto/index.d.ts +13199 -1260
- package/WAProto/index.js +124901 -74525
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +284 -0
- package/{src → lib}/Defaults/index.js +7 -14
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +161 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/{src → lib}/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.d.ts +17 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +62 -0
- package/lib/Socket/business.d.ts +170 -0
- package/{src → lib}/Socket/business.js +28 -33
- package/lib/Socket/chats.d.ts +81 -0
- package/{src → lib}/Socket/chats.js +174 -176
- package/lib/Socket/groups.d.ts +115 -0
- package/{src → lib}/Socket/groups.js +80 -68
- package/lib/Socket/index.d.ts +172 -0
- package/{src → lib}/Socket/index.js +4 -1
- package/lib/Socket/messages-recv.d.ts +158 -0
- package/{src → lib}/Socket/messages-recv.js +378 -211
- package/lib/Socket/messages-send.d.ts +155 -0
- package/{src → lib}/Socket/messages-send.js +452 -177
- package/lib/Socket/newsletter.d.ts +132 -0
- package/{src → lib}/Socket/newsletter.js +107 -98
- package/lib/Socket/registration.d.ts +264 -0
- package/{src → lib}/Socket/registration.js +56 -48
- package/lib/Socket/socket.d.ts +44 -0
- package/{src → lib}/Socket/socket.js +77 -77
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/{src → lib}/Store/make-cache-manager-store.js +25 -34
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/{src → lib}/Store/make-in-memory-store.js +36 -32
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/{src → lib}/Store/object-repository.js +1 -1
- package/lib/Types/Auth.d.ts +109 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Chat.d.ts +107 -0
- package/{src/Types/Contact.ts → lib/Types/Contact.d.ts} +8 -9
- package/lib/Types/Events.d.ts +172 -0
- package/lib/Types/GroupMetadata.d.ts +56 -0
- package/lib/Types/Label.d.ts +46 -0
- package/{src/Types/LabelAssociation.ts → lib/Types/LabelAssociation.d.ts} +16 -22
- package/lib/Types/Message.d.ts +433 -0
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/{src/Types/Socket.ts → lib/Types/Socket.d.ts} +61 -68
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/{src → lib}/Utils/auth-utils.js +73 -90
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +22 -0
- package/{src → lib}/Utils/business.js +15 -43
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/{src → lib}/Utils/chat-utils.js +87 -94
- package/lib/Utils/crypto.d.ts +40 -0
- package/{src → lib}/Utils/crypto.js +4 -2
- package/lib/Utils/decode-wa-message.d.ts +36 -0
- package/lib/Utils/decode-wa-message.js +226 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/{src → lib}/Utils/event-buffer.js +4 -13
- package/lib/Utils/generics.d.ts +88 -0
- package/{src → lib}/Utils/generics.js +67 -86
- package/lib/Utils/history.d.ts +19 -0
- package/{src → lib}/Utils/history.js +13 -39
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/{src → lib}/Utils/link-preview.js +17 -54
- package/lib/Utils/logger.d.ts +2 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/{src → lib}/Utils/make-mutex.js +4 -13
- package/lib/Utils/messages-media.d.ts +113 -0
- package/{src → lib}/Utils/messages-media.js +193 -255
- package/lib/Utils/messages.d.ts +77 -0
- package/{src → lib}/Utils/messages.js +588 -118
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/{src → lib}/Utils/process-message.js +27 -30
- package/lib/Utils/signal.d.ts +33 -0
- package/{src → lib}/Utils/signal.js +25 -42
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/{src → lib}/Utils/use-multi-file-auth-state.js +27 -28
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/{src → lib}/Utils/validate-connection.js +40 -9
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/{src → lib}/WABinary/encode.js +16 -10
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -0
- package/lib/WAUSync/USyncQuery.js +79 -0
- package/lib/WAUSync/USyncUser.d.ts +10 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/{src → lib}/index.js +1 -0
- package/package.json +26 -8
- package/LICENSE +0 -21
- package/src/Defaults/baileys-version.json +0 -3
- package/src/Defaults/index.ts +0 -131
- package/src/Signal/libsignal.js +0 -180
- package/src/Signal/libsignal.ts +0 -141
- package/src/Socket/Client/abstract-socket-client.ts +0 -19
- package/src/Socket/Client/index.ts +0 -3
- package/src/Socket/Client/mobile-socket-client.js +0 -78
- package/src/Socket/Client/mobile-socket-client.ts +0 -66
- package/src/Socket/Client/web-socket-client.js +0 -75
- package/src/Socket/Client/web-socket-client.ts +0 -57
- package/src/Socket/business.ts +0 -281
- package/src/Socket/chats.ts +0 -1030
- package/src/Socket/groups.ts +0 -356
- package/src/Socket/index.ts +0 -13
- package/src/Socket/messages-recv.ts +0 -985
- package/src/Socket/messages-send.ts +0 -871
- package/src/Socket/newsletter.ts +0 -282
- package/src/Socket/registration.ts +0 -250
- package/src/Socket/socket.ts +0 -777
- package/src/Store/index.ts +0 -3
- package/src/Store/make-cache-manager-store.ts +0 -100
- package/src/Store/make-in-memory-store.ts +0 -475
- package/src/Store/make-ordered-dictionary.ts +0 -86
- package/src/Store/object-repository.ts +0 -32
- package/src/Tests/test.app-state-sync.js +0 -204
- package/src/Tests/test.app-state-sync.ts +0 -207
- package/src/Tests/test.event-buffer.js +0 -270
- package/src/Tests/test.event-buffer.ts +0 -319
- package/src/Tests/test.key-store.js +0 -76
- package/src/Tests/test.key-store.ts +0 -92
- package/src/Tests/test.libsignal.js +0 -141
- package/src/Tests/test.libsignal.ts +0 -186
- package/src/Tests/test.media-download.js +0 -93
- package/src/Tests/test.media-download.ts +0 -76
- package/src/Tests/test.messages.js +0 -33
- package/src/Tests/test.messages.ts +0 -37
- package/src/Tests/utils.js +0 -34
- package/src/Tests/utils.ts +0 -36
- package/src/Types/Auth.ts +0 -113
- package/src/Types/Call.ts +0 -15
- package/src/Types/Chat.ts +0 -106
- package/src/Types/Events.ts +0 -93
- package/src/Types/GroupMetadata.ts +0 -53
- package/src/Types/Label.ts +0 -36
- package/src/Types/Message.ts +0 -288
- package/src/Types/Newsletter.ts +0 -98
- package/src/Types/Product.ts +0 -85
- package/src/Types/Signal.ts +0 -68
- package/src/Types/State.ts +0 -29
- package/src/Types/index.ts +0 -59
- package/src/Utils/auth-utils.ts +0 -222
- package/src/Utils/baileys-event-stream.js +0 -92
- package/src/Utils/baileys-event-stream.ts +0 -66
- package/src/Utils/business.ts +0 -275
- package/src/Utils/chat-utils.ts +0 -860
- package/src/Utils/crypto.ts +0 -131
- package/src/Utils/decode-wa-message.js +0 -211
- package/src/Utils/decode-wa-message.ts +0 -228
- package/src/Utils/event-buffer.ts +0 -613
- package/src/Utils/generics.ts +0 -434
- package/src/Utils/history.ts +0 -112
- package/src/Utils/index.ts +0 -17
- package/src/Utils/link-preview.ts +0 -122
- package/src/Utils/logger.ts +0 -3
- package/src/Utils/lt-hash.ts +0 -61
- package/src/Utils/make-mutex.ts +0 -44
- package/src/Utils/messages-media.ts +0 -847
- package/src/Utils/messages.ts +0 -956
- package/src/Utils/noise-handler.ts +0 -197
- package/src/Utils/process-message.ts +0 -414
- package/src/Utils/signal.ts +0 -177
- package/src/Utils/use-multi-file-auth-state.ts +0 -90
- package/src/Utils/validate-connection.ts +0 -238
- package/src/WABinary/constants.ts +0 -42
- package/src/WABinary/decode.ts +0 -265
- package/src/WABinary/encode.ts +0 -236
- package/src/WABinary/generic-utils.ts +0 -121
- package/src/WABinary/index.ts +0 -5
- package/src/WABinary/jid-utils.ts +0 -68
- package/src/WABinary/types.ts +0 -17
- package/src/WAM/BinaryInfo.ts +0 -12
- package/src/WAM/constants.ts +0 -15382
- package/src/WAM/encode.ts +0 -174
- package/src/WAM/index.ts +0 -3
- package/src/gifted +0 -1
- package/src/index.ts +0 -13
- /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
- /package/{src → lib}/Socket/Client/abstract-socket-client.js +0 -0
- /package/{src → lib}/Store/index.js +0 -0
- /package/{src → lib}/Store/make-ordered-dictionary.js +0 -0
- /package/{src → lib}/Types/Auth.js +0 -0
- /package/{src → lib}/Types/Call.js +0 -0
- /package/{src → lib}/Types/Chat.js +0 -0
- /package/{src → lib}/Types/Contact.js +0 -0
- /package/{src → lib}/Types/Events.js +0 -0
- /package/{src → lib}/Types/GroupMetadata.js +0 -0
- /package/{src → lib}/Types/Label.js +0 -0
- /package/{src → lib}/Types/LabelAssociation.js +0 -0
- /package/{src → lib}/Types/Message.js +0 -0
- /package/{src → lib}/Types/Newsletter.js +0 -0
- /package/{src → lib}/Types/Product.js +0 -0
- /package/{src → lib}/Types/Signal.js +0 -0
- /package/{src → lib}/Types/Socket.js +0 -0
- /package/{src → lib}/Types/State.js +0 -0
- /package/{src/WABinary/types.js → lib/Types/USync.js} +0 -0
- /package/{src → lib}/Types/index.js +0 -0
- /package/{src → lib}/Utils/index.js +0 -0
- /package/{src → lib}/Utils/logger.js +0 -0
- /package/{src → lib}/Utils/lt-hash.js +0 -0
- /package/{src → lib}/Utils/noise-handler.js +0 -0
- /package/{src → lib}/WABinary/constants.js +0 -0
- /package/{src → lib}/WABinary/decode.js +0 -0
- /package/{src → lib}/WABinary/generic-utils.js +0 -0
- /package/{src → lib}/WABinary/index.js +0 -0
- /package/{src → lib}/WABinary/jid-utils.js +0 -0
- /package/{src → lib}/WAM/BinaryInfo.js +0 -0
- /package/{src → lib}/WAM/constants.js +0 -0
- /package/{src → lib}/WAM/encode.js +0 -0
- /package/{src → lib}/WAM/index.js +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Logger } from 'pino';
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
import { KeyPair } from '../Types';
|
|
4
|
+
import { BinaryNode } from '../WABinary';
|
|
5
|
+
export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }: {
|
|
6
|
+
keyPair: KeyPair;
|
|
7
|
+
NOISE_HEADER: Uint8Array;
|
|
8
|
+
mobile: boolean;
|
|
9
|
+
logger: Logger;
|
|
10
|
+
routingInfo?: Buffer | undefined;
|
|
11
|
+
}) => {
|
|
12
|
+
encrypt: (plaintext: Uint8Array) => any;
|
|
13
|
+
decrypt: (ciphertext: Uint8Array) => any;
|
|
14
|
+
authenticate: (data: Uint8Array) => void;
|
|
15
|
+
mixIntoKey: (data: Uint8Array) => void;
|
|
16
|
+
finishInit: () => void;
|
|
17
|
+
processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => any;
|
|
18
|
+
encodeFrame: (data: Buffer | Uint8Array) => any;
|
|
19
|
+
decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => void;
|
|
20
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import type { Logger } from 'pino';
|
|
3
|
+
import { proto } from '../../WAProto';
|
|
4
|
+
import { AuthenticationCreds, BaileysEventEmitter, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
|
|
5
|
+
type ProcessMessageContext = {
|
|
6
|
+
shouldProcessHistoryMsg: boolean;
|
|
7
|
+
creds: AuthenticationCreds;
|
|
8
|
+
keyStore: SignalKeyStoreWithTransaction;
|
|
9
|
+
ev: BaileysEventEmitter;
|
|
10
|
+
getMessage: SocketConfig['getMessage'];
|
|
11
|
+
logger?: Logger;
|
|
12
|
+
options: AxiosRequestConfig<{}>;
|
|
13
|
+
};
|
|
14
|
+
/** Cleans a received message to further processing */
|
|
15
|
+
export declare const cleanMessage: (message: proto.IWebMessageInfo, meId: string) => void;
|
|
16
|
+
export declare const isRealMessage: (message: proto.IWebMessageInfo, meId: string) => boolean | undefined;
|
|
17
|
+
export declare const shouldIncrementChatUnread: (message: proto.IWebMessageInfo) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Get the ID of the chat from the given key.
|
|
20
|
+
* Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
|
|
21
|
+
*/
|
|
22
|
+
export declare const getChatId: ({ remoteJid, participant, fromMe }: proto.IMessageKey) => string;
|
|
23
|
+
type PollContext = {
|
|
24
|
+
/** normalised jid of the person that created the poll */
|
|
25
|
+
pollCreatorJid: string;
|
|
26
|
+
/** ID of the poll creation message */
|
|
27
|
+
pollMsgId: string;
|
|
28
|
+
/** poll creation message enc key */
|
|
29
|
+
pollEncKey: Uint8Array;
|
|
30
|
+
/** jid of the person that voted */
|
|
31
|
+
voterJid: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Decrypt a poll vote
|
|
35
|
+
* @param vote encrypted vote
|
|
36
|
+
* @param ctx additional info about the poll required for decryption
|
|
37
|
+
* @returns list of SHA256 options
|
|
38
|
+
*/
|
|
39
|
+
export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage;
|
|
40
|
+
declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
|
|
41
|
+
export default processMessage;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
|
|
13
4
|
exports.decryptPollVote = decryptPollVote;
|
|
@@ -111,8 +102,8 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
|
|
|
111
102
|
return Buffer.from(txt);
|
|
112
103
|
}
|
|
113
104
|
}
|
|
114
|
-
const processMessage =
|
|
115
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k
|
|
105
|
+
const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }) => {
|
|
106
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
116
107
|
const meId = creds.me.id;
|
|
117
108
|
const { accountSettings } = creds;
|
|
118
109
|
const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
|
|
@@ -127,7 +118,7 @@ const processMessage = (message_1, _a) => __awaiter(void 0, [message_1, _a], voi
|
|
|
127
118
|
const content = (0, messages_1.normalizeMessageContent)(message.message);
|
|
128
119
|
// unarchive chat if it's a real message, or someone reacted to our message
|
|
129
120
|
// and we've the unarchive chats setting on
|
|
130
|
-
if ((isRealMsg || ((
|
|
121
|
+
if ((isRealMsg || ((_b = (_a = content === null || content === void 0 ? void 0 : content.reactionMessage) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.fromMe))
|
|
131
122
|
&& (accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats)) {
|
|
132
123
|
chat.archived = false;
|
|
133
124
|
chat.readOnly = false;
|
|
@@ -138,7 +129,7 @@ const processMessage = (message_1, _a) => __awaiter(void 0, [message_1, _a], voi
|
|
|
138
129
|
case WAProto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
|
|
139
130
|
const histNotification = protocolMsg.historySyncNotification;
|
|
140
131
|
const process = shouldProcessHistoryMsg;
|
|
141
|
-
const isLatest = !((
|
|
132
|
+
const isLatest = !((_c = creds.processedHistoryMessages) === null || _c === void 0 ? void 0 : _c.length);
|
|
142
133
|
logger === null || logger === void 0 ? void 0 : logger.info({
|
|
143
134
|
histNotification,
|
|
144
135
|
process,
|
|
@@ -152,24 +143,24 @@ const processMessage = (message_1, _a) => __awaiter(void 0, [message_1, _a], voi
|
|
|
152
143
|
{ key: message.key, messageTimestamp: message.messageTimestamp }
|
|
153
144
|
]
|
|
154
145
|
});
|
|
155
|
-
const data =
|
|
156
|
-
ev.emit('messaging-history.set',
|
|
146
|
+
const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
|
|
147
|
+
ev.emit('messaging-history.set', { ...data, isLatest });
|
|
157
148
|
}
|
|
158
149
|
break;
|
|
159
150
|
case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
|
|
160
151
|
const keys = protocolMsg.appStateSyncKeyShare.keys;
|
|
161
152
|
if (keys === null || keys === void 0 ? void 0 : keys.length) {
|
|
162
153
|
let newAppStateSyncKeyId = '';
|
|
163
|
-
|
|
154
|
+
await keyStore.transaction(async () => {
|
|
164
155
|
const newKeys = [];
|
|
165
156
|
for (const { keyData, keyId } of keys) {
|
|
166
157
|
const strKeyId = Buffer.from(keyId.keyId).toString('base64');
|
|
167
158
|
newKeys.push(strKeyId);
|
|
168
|
-
|
|
159
|
+
await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
|
|
169
160
|
newAppStateSyncKeyId = strKeyId;
|
|
170
161
|
}
|
|
171
162
|
logger === null || logger === void 0 ? void 0 : logger.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
|
|
172
|
-
})
|
|
163
|
+
});
|
|
173
164
|
ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
|
|
174
165
|
}
|
|
175
166
|
else {
|
|
@@ -179,7 +170,10 @@ const processMessage = (message_1, _a) => __awaiter(void 0, [message_1, _a], voi
|
|
|
179
170
|
case WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE:
|
|
180
171
|
ev.emit('messages.update', [
|
|
181
172
|
{
|
|
182
|
-
key:
|
|
173
|
+
key: {
|
|
174
|
+
...message.key,
|
|
175
|
+
id: protocolMsg.key.id
|
|
176
|
+
},
|
|
183
177
|
update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
|
|
184
178
|
}
|
|
185
179
|
]);
|
|
@@ -208,7 +202,10 @@ const processMessage = (message_1, _a) => __awaiter(void 0, [message_1, _a], voi
|
|
|
208
202
|
}
|
|
209
203
|
}
|
|
210
204
|
else if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
|
|
211
|
-
const reaction =
|
|
205
|
+
const reaction = {
|
|
206
|
+
...content.reactionMessage,
|
|
207
|
+
key: message.key,
|
|
208
|
+
};
|
|
212
209
|
ev.emit('messages.reaction', [{
|
|
213
210
|
reaction,
|
|
214
211
|
key: content.reactionMessage.key,
|
|
@@ -221,7 +218,7 @@ const processMessage = (message_1, _a) => __awaiter(void 0, [message_1, _a], voi
|
|
|
221
218
|
const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
|
|
222
219
|
const emitGroupUpdate = (update) => {
|
|
223
220
|
var _a;
|
|
224
|
-
ev.emit('groups.update', [
|
|
221
|
+
ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
|
|
225
222
|
};
|
|
226
223
|
const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
|
|
227
224
|
switch (message.messageStubType) {
|
|
@@ -252,28 +249,28 @@ const processMessage = (message_1, _a) => __awaiter(void 0, [message_1, _a], voi
|
|
|
252
249
|
emitParticipantsUpdate('promote');
|
|
253
250
|
break;
|
|
254
251
|
case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
|
|
255
|
-
const announceValue = (
|
|
252
|
+
const announceValue = (_d = message.messageStubParameters) === null || _d === void 0 ? void 0 : _d[0];
|
|
256
253
|
emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
|
|
257
254
|
break;
|
|
258
255
|
case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
|
|
259
|
-
const restrictValue = (
|
|
256
|
+
const restrictValue = (_e = message.messageStubParameters) === null || _e === void 0 ? void 0 : _e[0];
|
|
260
257
|
emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
|
|
261
258
|
break;
|
|
262
259
|
case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
|
263
|
-
const name = (
|
|
260
|
+
const name = (_f = message.messageStubParameters) === null || _f === void 0 ? void 0 : _f[0];
|
|
264
261
|
chat.name = name;
|
|
265
262
|
emitGroupUpdate({ subject: name });
|
|
266
263
|
break;
|
|
267
264
|
case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
|
|
268
|
-
const code = (
|
|
265
|
+
const code = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
|
|
269
266
|
emitGroupUpdate({ inviteCode: code });
|
|
270
267
|
break;
|
|
271
268
|
case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
|
|
272
|
-
const memberAddValue = (
|
|
269
|
+
const memberAddValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
|
|
273
270
|
emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
|
|
274
271
|
break;
|
|
275
272
|
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
|
|
276
|
-
const approvalMode = (
|
|
273
|
+
const approvalMode = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
|
|
277
274
|
emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
|
|
278
275
|
break;
|
|
279
276
|
}
|
|
@@ -281,12 +278,12 @@ const processMessage = (message_1, _a) => __awaiter(void 0, [message_1, _a], voi
|
|
|
281
278
|
else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
|
|
282
279
|
const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey;
|
|
283
280
|
// we need to fetch the poll creation message to get the poll enc key
|
|
284
|
-
const pollMsg =
|
|
281
|
+
const pollMsg = await getMessage(creationMsgKey);
|
|
285
282
|
if (pollMsg) {
|
|
286
283
|
const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
|
|
287
284
|
const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
|
|
288
285
|
const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
|
|
289
|
-
const pollEncKey = (
|
|
286
|
+
const pollEncKey = (_k = pollMsg.messageContextInfo) === null || _k === void 0 ? void 0 : _k.messageSecret;
|
|
290
287
|
try {
|
|
291
288
|
const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
|
|
292
289
|
pollEncKey,
|
|
@@ -320,5 +317,5 @@ const processMessage = (message_1, _a) => __awaiter(void 0, [message_1, _a], voi
|
|
|
320
317
|
if (Object.keys(chat).length > 1) {
|
|
321
318
|
ev.emit('chats.update', [chat]);
|
|
322
319
|
}
|
|
323
|
-
}
|
|
320
|
+
};
|
|
324
321
|
exports.default = processMessage;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SignalRepository } from '../Types';
|
|
2
|
+
import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth';
|
|
3
|
+
import { BinaryNode, JidWithDevice } from '../WABinary';
|
|
4
|
+
import { USyncQueryResultList } from '../WAUSync';
|
|
5
|
+
export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
|
|
6
|
+
export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
|
|
7
|
+
[id: string]: KeyPair;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: number) => {
|
|
10
|
+
newPreKeys: {
|
|
11
|
+
[id: number]: KeyPair;
|
|
12
|
+
};
|
|
13
|
+
lastPreKeyId: number;
|
|
14
|
+
preKeysRange: readonly [number, number];
|
|
15
|
+
};
|
|
16
|
+
export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
|
|
17
|
+
export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
|
|
18
|
+
export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>;
|
|
19
|
+
export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
|
|
20
|
+
/**
|
|
21
|
+
* get the next N keys for upload or processing
|
|
22
|
+
* @param count number of pre-keys to get or generate
|
|
23
|
+
*/
|
|
24
|
+
export declare const getNextPreKeys: ({ creds, keys }: AuthenticationState, count: number) => Promise<{
|
|
25
|
+
update: Partial<AuthenticationCreds>;
|
|
26
|
+
preKeys: {
|
|
27
|
+
[id: string]: KeyPair;
|
|
28
|
+
};
|
|
29
|
+
}>;
|
|
30
|
+
export declare const getNextPreKeysNode: (state: AuthenticationState, count: number) => Promise<{
|
|
31
|
+
update: Partial<AuthenticationCreds>;
|
|
32
|
+
node: BinaryNode;
|
|
33
|
+
}>;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
|
|
13
4
|
const Defaults_1 = require("../Defaults");
|
|
@@ -21,13 +12,13 @@ const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
|
21
12
|
};
|
|
22
13
|
};
|
|
23
14
|
exports.createSignalIdentity = createSignalIdentity;
|
|
24
|
-
const getPreKeys =
|
|
15
|
+
const getPreKeys = async ({ get }, min, limit) => {
|
|
25
16
|
const idList = [];
|
|
26
17
|
for (let id = min; id < limit; id++) {
|
|
27
18
|
idList.push(id.toString());
|
|
28
19
|
}
|
|
29
20
|
return get('pre-key', idList);
|
|
30
|
-
}
|
|
21
|
+
};
|
|
31
22
|
exports.getPreKeys = getPreKeys;
|
|
32
23
|
const generateOrGetPreKeys = (creds, range) => {
|
|
33
24
|
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
@@ -65,7 +56,7 @@ const xmppPreKey = (pair, id) => ({
|
|
|
65
56
|
]
|
|
66
57
|
});
|
|
67
58
|
exports.xmppPreKey = xmppPreKey;
|
|
68
|
-
const parseAndInjectE2ESessions = (node, repository) =>
|
|
59
|
+
const parseAndInjectE2ESessions = async (node, repository) => {
|
|
69
60
|
const extractKey = (key) => (key ? ({
|
|
70
61
|
keyId: (0, WABinary_1.getBinaryNodeChildUInt)(key, 'id', 3),
|
|
71
62
|
publicKey: (0, crypto_1.generateSignalPubKey)((0, WABinary_1.getBinaryNodeChildBuffer)(key, 'value')),
|
|
@@ -75,13 +66,13 @@ const parseAndInjectE2ESessions = (node, repository) => __awaiter(void 0, void 0
|
|
|
75
66
|
for (const node of nodes) {
|
|
76
67
|
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
77
68
|
}
|
|
78
|
-
|
|
69
|
+
await Promise.all(nodes.map(async (node) => {
|
|
79
70
|
const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
|
|
80
71
|
const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
|
|
81
72
|
const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
|
|
82
73
|
const jid = node.attrs.jid;
|
|
83
74
|
const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
|
|
84
|
-
|
|
75
|
+
await repository.injectE2ESession({
|
|
85
76
|
jid,
|
|
86
77
|
session: {
|
|
87
78
|
registrationId: registrationId,
|
|
@@ -90,31 +81,23 @@ const parseAndInjectE2ESessions = (node, repository) => __awaiter(void 0, void 0
|
|
|
90
81
|
preKey: extractKey(key)
|
|
91
82
|
}
|
|
92
83
|
});
|
|
93
|
-
}))
|
|
94
|
-
}
|
|
84
|
+
}));
|
|
85
|
+
};
|
|
95
86
|
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
96
87
|
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
97
|
-
var _a;
|
|
98
88
|
const { user: myUser, device: myDevice } = (0, WABinary_1.jidDecode)(myJid);
|
|
99
89
|
const extracted = [];
|
|
100
|
-
for (const
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
for
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
112
|
-
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
113
|
-
(device === 0 || !!attrs['key-index']) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
114
|
-
) {
|
|
115
|
-
extracted.push({ user, device });
|
|
116
|
-
}
|
|
117
|
-
}
|
|
90
|
+
for (const userResult of result) {
|
|
91
|
+
const { devices, id } = userResult;
|
|
92
|
+
const { user } = (0, WABinary_1.jidDecode)(id);
|
|
93
|
+
const deviceList = devices === null || devices === void 0 ? void 0 : devices.deviceList;
|
|
94
|
+
if (Array.isArray(deviceList)) {
|
|
95
|
+
for (const { id: device, keyIndex } of deviceList) {
|
|
96
|
+
if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
97
|
+
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
98
|
+
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
99
|
+
) {
|
|
100
|
+
extracted.push({ user, device });
|
|
118
101
|
}
|
|
119
102
|
}
|
|
120
103
|
}
|
|
@@ -126,20 +109,20 @@ exports.extractDeviceJids = extractDeviceJids;
|
|
|
126
109
|
* get the next N keys for upload or processing
|
|
127
110
|
* @param count number of pre-keys to get or generate
|
|
128
111
|
*/
|
|
129
|
-
const getNextPreKeys =
|
|
112
|
+
const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
130
113
|
const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
|
|
131
114
|
const update = {
|
|
132
115
|
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
133
116
|
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
134
117
|
};
|
|
135
|
-
|
|
136
|
-
const preKeys =
|
|
118
|
+
await keys.set({ 'pre-key': newPreKeys });
|
|
119
|
+
const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
137
120
|
return { update, preKeys };
|
|
138
|
-
}
|
|
121
|
+
};
|
|
139
122
|
exports.getNextPreKeys = getNextPreKeys;
|
|
140
|
-
const getNextPreKeysNode = (state, count) =>
|
|
123
|
+
const getNextPreKeysNode = async (state, count) => {
|
|
141
124
|
const { creds } = state;
|
|
142
|
-
const { update, preKeys } =
|
|
125
|
+
const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
|
|
143
126
|
const node = {
|
|
144
127
|
tag: 'iq',
|
|
145
128
|
attrs: {
|
|
@@ -156,5 +139,5 @@ const getNextPreKeysNode = (state, count) => __awaiter(void 0, void 0, void 0, f
|
|
|
156
139
|
]
|
|
157
140
|
};
|
|
158
141
|
return { update, node };
|
|
159
|
-
}
|
|
142
|
+
};
|
|
160
143
|
exports.getNextPreKeysNode = getNextPreKeysNode;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AuthenticationState } from '../Types';
|
|
2
|
+
/**
|
|
3
|
+
* stores the full authentication state in a single folder.
|
|
4
|
+
* Far more efficient than singlefileauthstate
|
|
5
|
+
*
|
|
6
|
+
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
7
|
+
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
8
|
+
* */
|
|
9
|
+
export declare const useMultiFileAuthState: (folder: string) => Promise<{
|
|
10
|
+
state: AuthenticationState;
|
|
11
|
+
saveCreds: () => Promise<void>;
|
|
12
|
+
}>;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
4
|
};
|
|
11
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
6
|
exports.useMultiFileAuthState = void 0;
|
|
@@ -15,6 +9,8 @@ const path_1 = require("path");
|
|
|
15
9
|
const WAProto_1 = require("../../WAProto");
|
|
16
10
|
const auth_utils_1 = require("./auth-utils");
|
|
17
11
|
const generics_1 = require("./generics");
|
|
12
|
+
const async_lock_1 = __importDefault(require("async-lock"));
|
|
13
|
+
const fileLock = new async_lock_1.default({ maxPending: Infinity });
|
|
18
14
|
/**
|
|
19
15
|
* stores the full authentication state in a single folder.
|
|
20
16
|
* Far more efficient than singlefileauthstate
|
|
@@ -22,53 +18,56 @@ const generics_1 = require("./generics");
|
|
|
22
18
|
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
23
19
|
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
24
20
|
* */
|
|
25
|
-
const useMultiFileAuthState = (folder) =>
|
|
21
|
+
const useMultiFileAuthState = async (folder) => {
|
|
26
22
|
const writeData = (data, file) => {
|
|
27
|
-
|
|
23
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
24
|
+
return fileLock.acquire(filePath, () => (0, promises_1.writeFile)((0, path_1.join)(filePath), JSON.stringify(data, generics_1.BufferJSON.replacer)));
|
|
28
25
|
};
|
|
29
|
-
const readData = (file) =>
|
|
26
|
+
const readData = async (file) => {
|
|
30
27
|
try {
|
|
31
|
-
const
|
|
28
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
29
|
+
const data = await fileLock.acquire(filePath, () => (0, promises_1.readFile)(filePath, { encoding: 'utf-8' }));
|
|
32
30
|
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
33
31
|
}
|
|
34
32
|
catch (error) {
|
|
35
33
|
return null;
|
|
36
34
|
}
|
|
37
|
-
}
|
|
38
|
-
const removeData = (file) =>
|
|
35
|
+
};
|
|
36
|
+
const removeData = async (file) => {
|
|
39
37
|
try {
|
|
40
|
-
|
|
38
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
39
|
+
await fileLock.acquire(filePath, () => (0, promises_1.unlink)(filePath));
|
|
41
40
|
}
|
|
42
41
|
catch (_a) {
|
|
43
42
|
}
|
|
44
|
-
}
|
|
45
|
-
const folderInfo =
|
|
43
|
+
};
|
|
44
|
+
const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
|
|
46
45
|
if (folderInfo) {
|
|
47
46
|
if (!folderInfo.isDirectory()) {
|
|
48
47
|
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
else {
|
|
52
|
-
|
|
51
|
+
await (0, promises_1.mkdir)(folder, { recursive: true });
|
|
53
52
|
}
|
|
54
53
|
const fixFileName = (file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-'); };
|
|
55
|
-
const creds =
|
|
54
|
+
const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
|
|
56
55
|
return {
|
|
57
56
|
state: {
|
|
58
57
|
creds,
|
|
59
58
|
keys: {
|
|
60
|
-
get: (type, ids) =>
|
|
59
|
+
get: async (type, ids) => {
|
|
61
60
|
const data = {};
|
|
62
|
-
|
|
63
|
-
let value =
|
|
61
|
+
await Promise.all(ids.map(async (id) => {
|
|
62
|
+
let value = await readData(`${type}-${id}.json`);
|
|
64
63
|
if (type === 'app-state-sync-key' && value) {
|
|
65
64
|
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
66
65
|
}
|
|
67
66
|
data[id] = value;
|
|
68
|
-
}))
|
|
67
|
+
}));
|
|
69
68
|
return data;
|
|
70
|
-
}
|
|
71
|
-
set: (data) =>
|
|
69
|
+
},
|
|
70
|
+
set: async (data) => {
|
|
72
71
|
const tasks = [];
|
|
73
72
|
for (const category in data) {
|
|
74
73
|
for (const id in data[category]) {
|
|
@@ -77,13 +76,13 @@ const useMultiFileAuthState = (folder) => __awaiter(void 0, void 0, void 0, func
|
|
|
77
76
|
tasks.push(value ? writeData(value, file) : removeData(file));
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
|
-
|
|
81
|
-
}
|
|
79
|
+
await Promise.all(tasks);
|
|
80
|
+
}
|
|
82
81
|
}
|
|
83
82
|
},
|
|
84
83
|
saveCreds: () => {
|
|
85
84
|
return writeData(creds, 'creds.json');
|
|
86
85
|
}
|
|
87
86
|
};
|
|
88
|
-
}
|
|
87
|
+
};
|
|
89
88
|
exports.useMultiFileAuthState = useMultiFileAuthState;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { proto } from '../../WAProto';
|
|
2
|
+
import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types';
|
|
3
|
+
import { BinaryNode } from '../WABinary';
|
|
4
|
+
export declare const generateMobileNode: (config: SocketConfig) => proto.IClientPayload;
|
|
5
|
+
export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
|
|
6
|
+
export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
|
|
7
|
+
export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
|
|
8
|
+
creds: Partial<AuthenticationCreds>;
|
|
9
|
+
reply: BinaryNode;
|
|
10
|
+
};
|
|
11
|
+
export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array;
|
|
@@ -17,12 +17,24 @@ const getUserAgent = (config) => {
|
|
|
17
17
|
const manufacturer = config.mobile ? 'Apple' : '';
|
|
18
18
|
const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
|
|
19
19
|
const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
|
|
20
|
-
return
|
|
20
|
+
return {
|
|
21
|
+
appVersion: {
|
|
21
22
|
primary: version[0],
|
|
22
23
|
secondary: version[1],
|
|
23
24
|
tertiary: version[2],
|
|
24
|
-
},
|
|
25
|
-
|
|
25
|
+
},
|
|
26
|
+
platform,
|
|
27
|
+
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,
|
|
34
|
+
localeLanguageIso6391: 'en',
|
|
35
|
+
localeCountryIso31661Alpha2: 'US',
|
|
36
|
+
...phoneId
|
|
37
|
+
};
|
|
26
38
|
};
|
|
27
39
|
const PLATFORM_MAP = {
|
|
28
40
|
'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
@@ -50,16 +62,31 @@ const generateMobileNode = (config) => {
|
|
|
50
62
|
if (!config.auth.creds) {
|
|
51
63
|
throw new boom_1.Boom('No registration data found', { data: config });
|
|
52
64
|
}
|
|
53
|
-
const payload =
|
|
65
|
+
const payload = {
|
|
66
|
+
...getClientPayload(config),
|
|
67
|
+
sessionId: Math.floor(Math.random() * 999999999 + 1),
|
|
68
|
+
shortConnect: true,
|
|
69
|
+
connectAttemptCount: 0,
|
|
70
|
+
device: 0,
|
|
71
|
+
dnsSource: {
|
|
54
72
|
appCached: false,
|
|
55
73
|
dnsMethod: WAProto_1.proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
|
|
56
|
-
},
|
|
74
|
+
},
|
|
75
|
+
passive: false,
|
|
76
|
+
pushName: 'test',
|
|
77
|
+
username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
|
|
78
|
+
};
|
|
57
79
|
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
58
80
|
};
|
|
59
81
|
exports.generateMobileNode = generateMobileNode;
|
|
60
82
|
const generateLoginNode = (userJid, config) => {
|
|
61
83
|
const { user, device } = (0, WABinary_1.jidDecode)(userJid);
|
|
62
|
-
const payload =
|
|
84
|
+
const payload = {
|
|
85
|
+
...getClientPayload(config),
|
|
86
|
+
passive: true,
|
|
87
|
+
username: +user,
|
|
88
|
+
device: device,
|
|
89
|
+
};
|
|
63
90
|
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
64
91
|
};
|
|
65
92
|
exports.generateLoginNode = generateLoginNode;
|
|
@@ -79,7 +106,10 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
79
106
|
requireFullSync: config.syncFullHistory,
|
|
80
107
|
};
|
|
81
108
|
const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
|
|
82
|
-
const registerPayload =
|
|
109
|
+
const registerPayload = {
|
|
110
|
+
...getClientPayload(config),
|
|
111
|
+
passive: false,
|
|
112
|
+
devicePairingData: {
|
|
83
113
|
buildHash: appVersionBuf,
|
|
84
114
|
deviceProps: companionProto,
|
|
85
115
|
eRegid: (0, generics_1.encodeBigEndian)(registrationId),
|
|
@@ -88,7 +118,8 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
88
118
|
eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
|
|
89
119
|
eSkeyVal: signedPreKey.keyPair.public,
|
|
90
120
|
eSkeySig: signedPreKey.signature,
|
|
91
|
-
}
|
|
121
|
+
},
|
|
122
|
+
};
|
|
92
123
|
return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
|
|
93
124
|
};
|
|
94
125
|
exports.generateRegistrationNode = generateRegistrationNode;
|
|
@@ -161,7 +192,7 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
161
192
|
exports.configureSuccessfulPairing = configureSuccessfulPairing;
|
|
162
193
|
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
163
194
|
var _a;
|
|
164
|
-
account =
|
|
195
|
+
account = { ...account };
|
|
165
196
|
// set to null if we are not to include the signature key
|
|
166
197
|
// or if we are including the signature key but it is empty
|
|
167
198
|
if (!includeSignatureKey || !((_a = account.accountSignatureKey) === null || _a === void 0 ? void 0 : _a.length)) {
|