@queenanya/baileys 7.5.11 → 8.0.0
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/package.json +13 -97
- package/LICENSE +0 -21
- package/README.md +0 -931
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -3344
- package/WAProto/index.d.ts +0 -37016
- package/WAProto/index.js +0 -101044
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/WASignalGroup/sender_message_key.js +0 -39
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Defaults/index.js +0 -107
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Signal/libsignal.js +0 -152
- package/lib/Socket/Client/index.d.ts +0 -2
- package/lib/Socket/Client/index.js +0 -18
- package/lib/Socket/Client/types.d.ts +0 -17
- package/lib/Socket/Client/types.js +0 -13
- package/lib/Socket/Client/websocket.d.ts +0 -12
- package/lib/Socket/Client/websocket.js +0 -62
- package/lib/Socket/business.d.ts +0 -177
- package/lib/Socket/business.js +0 -260
- package/lib/Socket/chats.d.ts +0 -91
- package/lib/Socket/chats.js +0 -949
- package/lib/Socket/groups.d.ts +0 -131
- package/lib/Socket/groups.js +0 -314
- package/lib/Socket/index.d.ts +0 -177
- package/lib/Socket/index.js +0 -10
- package/lib/Socket/messages-recv.d.ts +0 -164
- package/lib/Socket/messages-recv.js +0 -918
- package/lib/Socket/messages-send.d.ts +0 -157
- package/lib/Socket/messages-send.js +0 -794
- package/lib/Socket/newsletter.d.ts +0 -143
- package/lib/Socket/newsletter.js +0 -249
- package/lib/Socket/socket.d.ts +0 -45
- package/lib/Socket/socket.js +0 -616
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/index.js +0 -10
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-in-memory-store.js +0 -420
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/make-ordered-dictionary.js +0 -81
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Store/object-repository.js +0 -27
- package/lib/Types/Auth.d.ts +0 -105
- package/lib/Types/Auth.js +0 -2
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Call.js +0 -2
- package/lib/Types/Chat.d.ts +0 -107
- package/lib/Types/Chat.js +0 -4
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Contact.js +0 -2
- package/lib/Types/Events.d.ts +0 -199
- package/lib/Types/Events.js +0 -2
- package/lib/Types/GroupMetadata.d.ts +0 -56
- package/lib/Types/GroupMetadata.js +0 -2
- package/lib/Types/Label.d.ts +0 -46
- package/lib/Types/Label.js +0 -27
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/LabelAssociation.js +0 -9
- package/lib/Types/Message.d.ts +0 -280
- package/lib/Types/Message.js +0 -9
- package/lib/Types/Newsletter.d.ts +0 -79
- package/lib/Types/Newsletter.js +0 -18
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Product.js +0 -2
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Signal.js +0 -2
- package/lib/Types/Socket.d.ts +0 -118
- package/lib/Types/Socket.js +0 -2
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/State.js +0 -2
- package/lib/Types/index.d.ts +0 -65
- package/lib/Types/index.js +0 -42
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/auth-utils.js +0 -200
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/baileys-event-stream.js +0 -63
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/business.js +0 -234
- package/lib/Utils/chat-utils.d.ts +0 -72
- package/lib/Utils/chat-utils.js +0 -745
- package/lib/Utils/crypto.d.ts +0 -42
- package/lib/Utils/crypto.js +0 -153
- package/lib/Utils/decode-wa-message.d.ts +0 -20
- package/lib/Utils/decode-wa-message.js +0 -218
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/event-buffer.js +0 -520
- package/lib/Utils/generics.d.ts +0 -119
- package/lib/Utils/generics.js +0 -467
- package/lib/Utils/history.d.ts +0 -19
- package/lib/Utils/history.js +0 -94
- package/lib/Utils/index.d.ts +0 -18
- package/lib/Utils/index.js +0 -34
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/link-preview.js +0 -116
- package/lib/Utils/logger.d.ts +0 -2
- package/lib/Utils/logger.js +0 -7
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/lt-hash.js +0 -51
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/make-mutex.js +0 -44
- package/lib/Utils/messages-media.d.ts +0 -131
- package/lib/Utils/messages-media.js +0 -786
- package/lib/Utils/messages.d.ts +0 -78
- package/lib/Utils/messages.js +0 -767
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/noise-handler.js +0 -150
- package/lib/Utils/process-message.d.ts +0 -42
- package/lib/Utils/process-message.js +0 -355
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/signal.js +0 -158
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
- package/lib/Utils/use-multi-file-auth-state.js +0 -94
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -5
- package/lib/Utils/use-single-file-auth-state.js +0 -66
- package/lib/Utils/validate-connection.d.ts +0 -10
- package/lib/Utils/validate-connection.js +0 -171
- package/lib/WABinary/constants.d.ts +0 -27
- package/lib/WABinary/constants.js +0 -40
- package/lib/WABinary/decode.d.ts +0 -8
- package/lib/WABinary/decode.js +0 -254
- package/lib/WABinary/encode.d.ts +0 -2
- package/lib/WABinary/encode.js +0 -230
- package/lib/WABinary/generic-utils.d.ts +0 -16
- package/lib/WABinary/generic-utils.js +0 -110
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/index.js +0 -21
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/jid-utils.js +0 -62
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WABinary/types.js +0 -2
- package/lib/WAM/BinaryInfo.d.ts +0 -18
- package/lib/WAM/BinaryInfo.js +0 -13
- package/lib/WAM/constants.d.ts +0 -39
- package/lib/WAM/constants.js +0 -15350
- package/lib/WAM/encode.d.ts +0 -4
- package/lib/WAM/encode.js +0 -155
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAM/index.js +0 -19
- package/lib/index.d.ts +0 -11
- package/lib/index.js +0 -30
package/lib/Utils/signal.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
|
|
4
|
-
const lodash_1 = require("lodash");
|
|
5
|
-
const Defaults_1 = require("../Defaults");
|
|
6
|
-
const WABinary_1 = require("../WABinary");
|
|
7
|
-
const crypto_1 = require("./crypto");
|
|
8
|
-
const generics_1 = require("./generics");
|
|
9
|
-
const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
10
|
-
return {
|
|
11
|
-
identifier: { name: wid, deviceId: 0 },
|
|
12
|
-
identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
exports.createSignalIdentity = createSignalIdentity;
|
|
16
|
-
const getPreKeys = async ({ get }, min, limit) => {
|
|
17
|
-
const idList = [];
|
|
18
|
-
for (let id = min; id < limit; id++) {
|
|
19
|
-
idList.push(id.toString());
|
|
20
|
-
}
|
|
21
|
-
return get('pre-key', idList);
|
|
22
|
-
};
|
|
23
|
-
exports.getPreKeys = getPreKeys;
|
|
24
|
-
const generateOrGetPreKeys = (creds, range) => {
|
|
25
|
-
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
26
|
-
const remaining = range - avaliable;
|
|
27
|
-
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
28
|
-
const newPreKeys = {};
|
|
29
|
-
if (remaining > 0) {
|
|
30
|
-
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
31
|
-
newPreKeys[i] = crypto_1.Curve.generateKeyPair();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
newPreKeys,
|
|
36
|
-
lastPreKeyId,
|
|
37
|
-
preKeysRange: [creds.firstUnuploadedPreKeyId, range],
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
exports.generateOrGetPreKeys = generateOrGetPreKeys;
|
|
41
|
-
const xmppSignedPreKey = (key) => ({
|
|
42
|
-
tag: 'skey',
|
|
43
|
-
attrs: {},
|
|
44
|
-
content: [
|
|
45
|
-
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
|
|
46
|
-
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
47
|
-
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
48
|
-
]
|
|
49
|
-
});
|
|
50
|
-
exports.xmppSignedPreKey = xmppSignedPreKey;
|
|
51
|
-
const xmppPreKey = (pair, id) => ({
|
|
52
|
-
tag: 'key',
|
|
53
|
-
attrs: {},
|
|
54
|
-
content: [
|
|
55
|
-
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
|
|
56
|
-
{ tag: 'value', attrs: {}, content: pair.public }
|
|
57
|
-
]
|
|
58
|
-
});
|
|
59
|
-
exports.xmppPreKey = xmppPreKey;
|
|
60
|
-
const parseAndInjectE2ESessions = async (node, repository) => {
|
|
61
|
-
const extractKey = (key) => (key ? ({
|
|
62
|
-
keyId: (0, WABinary_1.getBinaryNodeChildUInt)(key, 'id', 3),
|
|
63
|
-
publicKey: (0, crypto_1.generateSignalPubKey)((0, WABinary_1.getBinaryNodeChildBuffer)(key, 'value')),
|
|
64
|
-
signature: (0, WABinary_1.getBinaryNodeChildBuffer)(key, 'signature'),
|
|
65
|
-
}) : undefined);
|
|
66
|
-
const nodes = (0, WABinary_1.getBinaryNodeChildren)((0, WABinary_1.getBinaryNodeChild)(node, 'list'), 'user');
|
|
67
|
-
for (const node of nodes) {
|
|
68
|
-
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
69
|
-
}
|
|
70
|
-
const chunkSize = 100;
|
|
71
|
-
const chunks = (0, lodash_1.chunk)(nodes, chunkSize);
|
|
72
|
-
for (const nodesChunk of chunks) {
|
|
73
|
-
await Promise.all(nodesChunk.map(async (node) => {
|
|
74
|
-
const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
|
|
75
|
-
const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
|
|
76
|
-
const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
|
|
77
|
-
const jid = node.attrs.jid;
|
|
78
|
-
const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
|
|
79
|
-
await repository.injectE2ESession({
|
|
80
|
-
jid,
|
|
81
|
-
session: {
|
|
82
|
-
registrationId: registrationId,
|
|
83
|
-
identityKey: (0, crypto_1.generateSignalPubKey)(identity),
|
|
84
|
-
signedPreKey: extractKey(signedKey),
|
|
85
|
-
preKey: extractKey(key)
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}));
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
92
|
-
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
93
|
-
var _a;
|
|
94
|
-
const { user: myUser, device: myDevice } = (0, WABinary_1.jidDecode)(myJid);
|
|
95
|
-
const extracted = [];
|
|
96
|
-
for (const node of result.content) {
|
|
97
|
-
const list = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'list')) === null || _a === void 0 ? void 0 : _a.content;
|
|
98
|
-
if (list && Array.isArray(list)) {
|
|
99
|
-
for (const item of list) {
|
|
100
|
-
const { user } = (0, WABinary_1.jidDecode)(item.attrs.jid);
|
|
101
|
-
const devicesNode = (0, WABinary_1.getBinaryNodeChild)(item, 'devices');
|
|
102
|
-
const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(devicesNode, 'device-list');
|
|
103
|
-
if (Array.isArray(deviceListNode === null || deviceListNode === void 0 ? void 0 : deviceListNode.content)) {
|
|
104
|
-
//eslint-disable-next-line max-depth
|
|
105
|
-
for (const { tag, attrs } of deviceListNode.content) {
|
|
106
|
-
const device = +attrs.id;
|
|
107
|
-
//eslint-disable-next-line max-depth
|
|
108
|
-
if (tag === 'device' && // ensure the "device" tag
|
|
109
|
-
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
110
|
-
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
111
|
-
(device === 0 || !!attrs['key-index']) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
112
|
-
) {
|
|
113
|
-
extracted.push({ user, device });
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return extracted;
|
|
121
|
-
};
|
|
122
|
-
exports.extractDeviceJids = extractDeviceJids;
|
|
123
|
-
/**
|
|
124
|
-
* get the next N keys for upload or processing
|
|
125
|
-
* @param count number of pre-keys to get or generate
|
|
126
|
-
*/
|
|
127
|
-
const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
128
|
-
const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
|
|
129
|
-
const update = {
|
|
130
|
-
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
131
|
-
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
132
|
-
};
|
|
133
|
-
await keys.set({ 'pre-key': newPreKeys });
|
|
134
|
-
const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
135
|
-
return { update, preKeys };
|
|
136
|
-
};
|
|
137
|
-
exports.getNextPreKeys = getNextPreKeys;
|
|
138
|
-
const getNextPreKeysNode = async (state, count) => {
|
|
139
|
-
const { creds } = state;
|
|
140
|
-
const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
|
|
141
|
-
const node = {
|
|
142
|
-
tag: 'iq',
|
|
143
|
-
attrs: {
|
|
144
|
-
xmlns: 'encrypt',
|
|
145
|
-
type: 'set',
|
|
146
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
147
|
-
},
|
|
148
|
-
content: [
|
|
149
|
-
{ tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
|
|
150
|
-
{ tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
|
|
151
|
-
{ tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
|
|
152
|
-
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
|
|
153
|
-
(0, exports.xmppSignedPreKey)(creds.signedPreKey)
|
|
154
|
-
]
|
|
155
|
-
};
|
|
156
|
-
return { update, node };
|
|
157
|
-
};
|
|
158
|
-
exports.getNextPreKeysNode = getNextPreKeysNode;
|
|
@@ -1,12 +0,0 @@
|
|
|
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,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useMultiFileAuthState = void 0;
|
|
7
|
-
const async_lock_1 = __importDefault(require("async-lock"));
|
|
8
|
-
const promises_1 = require("fs/promises");
|
|
9
|
-
const path_1 = require("path");
|
|
10
|
-
const WAProto_1 = require("../../WAProto");
|
|
11
|
-
const auth_utils_1 = require("./auth-utils");
|
|
12
|
-
const generics_1 = require("./generics");
|
|
13
|
-
// We need to lock files due to the fact that we are using async functions to read and write files
|
|
14
|
-
// https://github.com/WhiskeySockets/Baileys/issues/794
|
|
15
|
-
// https://github.com/nodejs/node/issues/26338
|
|
16
|
-
// Default pending is 1000, set it to infinity
|
|
17
|
-
// https://github.com/rogierschouten/async-lock/issues/63
|
|
18
|
-
const fileLock = new async_lock_1.default({ maxPending: Infinity });
|
|
19
|
-
/**
|
|
20
|
-
* stores the full authentication state in a single folder.
|
|
21
|
-
* Far more efficient than singlefileauthstate
|
|
22
|
-
*
|
|
23
|
-
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
24
|
-
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
25
|
-
* */
|
|
26
|
-
const useMultiFileAuthState = async (folder) => {
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
-
const writeData = (data, file) => {
|
|
29
|
-
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
30
|
-
return fileLock.acquire(filePath, () => (0, promises_1.writeFile)((0, path_1.join)(filePath), JSON.stringify(data, generics_1.BufferJSON.replacer)));
|
|
31
|
-
};
|
|
32
|
-
const readData = async (file) => {
|
|
33
|
-
try {
|
|
34
|
-
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
35
|
-
const data = await fileLock.acquire(filePath, () => (0, promises_1.readFile)(filePath, { encoding: 'utf-8' }));
|
|
36
|
-
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const removeData = async (file) => {
|
|
43
|
-
try {
|
|
44
|
-
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
45
|
-
await fileLock.acquire(filePath, () => (0, promises_1.unlink)(filePath));
|
|
46
|
-
}
|
|
47
|
-
catch (_a) {
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
|
|
51
|
-
if (folderInfo) {
|
|
52
|
-
if (!folderInfo.isDirectory()) {
|
|
53
|
-
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
await (0, promises_1.mkdir)(folder, { recursive: true });
|
|
58
|
-
}
|
|
59
|
-
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, '-'); };
|
|
60
|
-
const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
|
|
61
|
-
return {
|
|
62
|
-
state: {
|
|
63
|
-
creds,
|
|
64
|
-
keys: {
|
|
65
|
-
get: async (type, ids) => {
|
|
66
|
-
const data = {};
|
|
67
|
-
await Promise.all(ids.map(async (id) => {
|
|
68
|
-
let value = await readData(`${type}-${id}.json`);
|
|
69
|
-
if (type === 'app-state-sync-key' && value) {
|
|
70
|
-
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
71
|
-
}
|
|
72
|
-
data[id] = value;
|
|
73
|
-
}));
|
|
74
|
-
return data;
|
|
75
|
-
},
|
|
76
|
-
set: async (data) => {
|
|
77
|
-
const tasks = [];
|
|
78
|
-
for (const category in data) {
|
|
79
|
-
for (const id in data[category]) {
|
|
80
|
-
const value = data[category][id];
|
|
81
|
-
const file = `${category}-${id}.json`;
|
|
82
|
-
tasks.push(value ? writeData(value, file) : removeData(file));
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
await Promise.all(tasks);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
saveCreds: () => {
|
|
90
|
-
return writeData(creds, 'creds.json');
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
exports.useMultiFileAuthState = useMultiFileAuthState;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useSingleFileAuthState = void 0;
|
|
7
|
-
const async_lock_1 = __importDefault(require("async-lock"));
|
|
8
|
-
const promises_1 = require("fs/promises");
|
|
9
|
-
const index_1 = require("../../WAProto/index");
|
|
10
|
-
const auth_utils_1 = require("./auth-utils");
|
|
11
|
-
const generics_1 = require("./generics");
|
|
12
|
-
const fileLock = new async_lock_1.default({ maxPending: Infinity });
|
|
13
|
-
const useSingleFileAuthState = async (filepath) => {
|
|
14
|
-
const filePath = filepath + '.json';
|
|
15
|
-
const writeData = (data) => {
|
|
16
|
-
return fileLock.acquire(filePath, () => (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer)));
|
|
17
|
-
};
|
|
18
|
-
const readData = async () => {
|
|
19
|
-
try {
|
|
20
|
-
const data = await fileLock.acquire(filePath, () => (0, promises_1.readFile)(filePath, { encoding: 'utf-8' }));
|
|
21
|
-
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const fileInfo = await (0, promises_1.stat)(filePath).catch(() => null);
|
|
28
|
-
if (fileInfo && !fileInfo.isFile()) {
|
|
29
|
-
throw new Error(`A non-file exists at ${filePath}, please delete it or specify a different path.`);
|
|
30
|
-
}
|
|
31
|
-
// Initialize with default credentials if the file is empty or doesn't exist
|
|
32
|
-
const { creds = (0, auth_utils_1.initAuthCreds)(), keys = {} } = await readData() || {};
|
|
33
|
-
return {
|
|
34
|
-
state: {
|
|
35
|
-
creds,
|
|
36
|
-
keys: {
|
|
37
|
-
get: async (type, ids) => {
|
|
38
|
-
const data = {};
|
|
39
|
-
for (const id of ids) {
|
|
40
|
-
const value = keys[`${type}-${id}`];
|
|
41
|
-
data[id] = type === 'app-state-sync-key' && value
|
|
42
|
-
? index_1.proto.Message.AppStateSyncKeyData.fromObject(value)
|
|
43
|
-
: value;
|
|
44
|
-
}
|
|
45
|
-
return data;
|
|
46
|
-
},
|
|
47
|
-
set: async (data) => {
|
|
48
|
-
for (const category in data) {
|
|
49
|
-
for (const id in data[category]) {
|
|
50
|
-
const value = data[category][id];
|
|
51
|
-
if (value) {
|
|
52
|
-
keys[`${category}-${id}`] = value;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
delete keys[`${category}-${id}`];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
await writeData({ creds, keys });
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
saveCreds: () => writeData({ creds, keys })
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
exports.useSingleFileAuthState = useSingleFileAuthState;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { proto } from '../../WAProto';
|
|
2
|
-
import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types';
|
|
3
|
-
import { BinaryNode } from '../WABinary';
|
|
4
|
-
export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
|
|
5
|
-
export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
|
|
6
|
-
export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
|
|
7
|
-
creds: Partial<AuthenticationCreds>;
|
|
8
|
-
reply: BinaryNode;
|
|
9
|
-
};
|
|
10
|
-
export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array;
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
|
|
4
|
-
const boom_1 = require("@hapi/boom");
|
|
5
|
-
const crypto_1 = require("crypto");
|
|
6
|
-
const WAProto_1 = require("../../WAProto");
|
|
7
|
-
const Defaults_1 = require("../Defaults");
|
|
8
|
-
const WABinary_1 = require("../WABinary");
|
|
9
|
-
const crypto_2 = require("./crypto");
|
|
10
|
-
const generics_1 = require("./generics");
|
|
11
|
-
const signal_1 = require("./signal");
|
|
12
|
-
const getUserAgent = (config) => {
|
|
13
|
-
return {
|
|
14
|
-
appVersion: {
|
|
15
|
-
primary: config.version[0],
|
|
16
|
-
secondary: config.version[1],
|
|
17
|
-
tertiary: config.version[2],
|
|
18
|
-
},
|
|
19
|
-
platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
|
|
20
|
-
releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
21
|
-
osVersion: '0.1',
|
|
22
|
-
device: 'Desktop',
|
|
23
|
-
osBuildNumber: '0.1',
|
|
24
|
-
localeLanguageIso6391: 'en',
|
|
25
|
-
localeCountryIso31661Alpha2: 'US'
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
const PLATFORM_MAP = {
|
|
29
|
-
'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
30
|
-
'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
31
|
-
};
|
|
32
|
-
const getWebInfo = (config) => {
|
|
33
|
-
let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
34
|
-
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
|
|
35
|
-
webSubPlatform = PLATFORM_MAP[config.browser[0]];
|
|
36
|
-
}
|
|
37
|
-
return { webSubPlatform };
|
|
38
|
-
};
|
|
39
|
-
const getClientPayload = (config) => {
|
|
40
|
-
const payload = {
|
|
41
|
-
connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
42
|
-
connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
43
|
-
userAgent: getUserAgent(config),
|
|
44
|
-
};
|
|
45
|
-
payload.webInfo = getWebInfo(config);
|
|
46
|
-
return payload;
|
|
47
|
-
};
|
|
48
|
-
const generateLoginNode = (userJid, config) => {
|
|
49
|
-
const { user, device } = (0, WABinary_1.jidDecode)(userJid);
|
|
50
|
-
const payload = {
|
|
51
|
-
...getClientPayload(config),
|
|
52
|
-
passive: true,
|
|
53
|
-
username: +user,
|
|
54
|
-
device: device,
|
|
55
|
-
};
|
|
56
|
-
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
57
|
-
};
|
|
58
|
-
exports.generateLoginNode = generateLoginNode;
|
|
59
|
-
const getPlatformType = (platform) => {
|
|
60
|
-
const platformType = platform.toUpperCase();
|
|
61
|
-
return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.DESKTOP;
|
|
62
|
-
};
|
|
63
|
-
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
64
|
-
// the app version needs to be md5 hashed
|
|
65
|
-
// and passed in
|
|
66
|
-
const appVersionBuf = (0, crypto_1.createHash)('md5')
|
|
67
|
-
.update(config.version.join('.')) // join as string
|
|
68
|
-
.digest();
|
|
69
|
-
const companion = {
|
|
70
|
-
os: config.browser[0],
|
|
71
|
-
platformType: getPlatformType(config.browser[1]),
|
|
72
|
-
requireFullSync: config.syncFullHistory,
|
|
73
|
-
};
|
|
74
|
-
const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
|
|
75
|
-
const registerPayload = {
|
|
76
|
-
...getClientPayload(config),
|
|
77
|
-
passive: false,
|
|
78
|
-
devicePairingData: {
|
|
79
|
-
buildHash: appVersionBuf,
|
|
80
|
-
deviceProps: companionProto,
|
|
81
|
-
eRegid: (0, generics_1.encodeBigEndian)(registrationId),
|
|
82
|
-
eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
|
|
83
|
-
eIdent: signedIdentityKey.public,
|
|
84
|
-
eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
|
|
85
|
-
eSkeyVal: signedPreKey.keyPair.public,
|
|
86
|
-
eSkeySig: signedPreKey.signature,
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
|
|
90
|
-
};
|
|
91
|
-
exports.generateRegistrationNode = generateRegistrationNode;
|
|
92
|
-
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
93
|
-
const msgId = stanza.attrs.id;
|
|
94
|
-
const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
|
|
95
|
-
const deviceIdentityNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
|
|
96
|
-
const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
|
|
97
|
-
const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
|
|
98
|
-
const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
|
|
99
|
-
if (!deviceIdentityNode || !deviceNode) {
|
|
100
|
-
throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
|
|
101
|
-
}
|
|
102
|
-
const bizName = businessNode === null || businessNode === void 0 ? void 0 : businessNode.attrs.name;
|
|
103
|
-
const jid = deviceNode.attrs.jid;
|
|
104
|
-
const { details, hmac } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
105
|
-
// check HMAC matches
|
|
106
|
-
const advSign = (0, crypto_2.hmacSign)(details, Buffer.from(advSecretKey, 'base64'));
|
|
107
|
-
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
108
|
-
throw new boom_1.Boom('Invalid account signature');
|
|
109
|
-
}
|
|
110
|
-
const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
|
|
111
|
-
const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
|
|
112
|
-
// verify the device signature matches
|
|
113
|
-
const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails, signedIdentityKey.public]);
|
|
114
|
-
if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
115
|
-
throw new boom_1.Boom('Failed to verify account signature');
|
|
116
|
-
}
|
|
117
|
-
// sign the details with our identity key
|
|
118
|
-
const deviceMsg = Buffer.concat([Buffer.from([6, 1]), deviceDetails, signedIdentityKey.public, accountSignatureKey]);
|
|
119
|
-
account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
120
|
-
const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
|
|
121
|
-
const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
|
|
122
|
-
const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(account.details);
|
|
123
|
-
const reply = {
|
|
124
|
-
tag: 'iq',
|
|
125
|
-
attrs: {
|
|
126
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
127
|
-
type: 'result',
|
|
128
|
-
id: msgId,
|
|
129
|
-
},
|
|
130
|
-
content: [
|
|
131
|
-
{
|
|
132
|
-
tag: 'pair-device-sign',
|
|
133
|
-
attrs: {},
|
|
134
|
-
content: [
|
|
135
|
-
{
|
|
136
|
-
tag: 'device-identity',
|
|
137
|
-
attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
|
|
138
|
-
content: accountEnc
|
|
139
|
-
}
|
|
140
|
-
]
|
|
141
|
-
}
|
|
142
|
-
]
|
|
143
|
-
};
|
|
144
|
-
const authUpdate = {
|
|
145
|
-
account,
|
|
146
|
-
me: { id: jid, name: bizName },
|
|
147
|
-
signalIdentities: [
|
|
148
|
-
...(signalIdentities || []),
|
|
149
|
-
identity
|
|
150
|
-
],
|
|
151
|
-
platform: platformNode === null || platformNode === void 0 ? void 0 : platformNode.attrs.name
|
|
152
|
-
};
|
|
153
|
-
return {
|
|
154
|
-
creds: authUpdate,
|
|
155
|
-
reply
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
exports.configureSuccessfulPairing = configureSuccessfulPairing;
|
|
159
|
-
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
160
|
-
var _a;
|
|
161
|
-
account = { ...account };
|
|
162
|
-
// set to null if we are not to include the signature key
|
|
163
|
-
// or if we are including the signature key but it is empty
|
|
164
|
-
if (!includeSignatureKey || !((_a = account.accountSignatureKey) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
165
|
-
account.accountSignatureKey = null;
|
|
166
|
-
}
|
|
167
|
-
return WAProto_1.proto.ADVSignedDeviceIdentity
|
|
168
|
-
.encode(account)
|
|
169
|
-
.finish();
|
|
170
|
-
};
|
|
171
|
-
exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export declare const TAGS: {
|
|
2
|
-
LIST_EMPTY: number;
|
|
3
|
-
DICTIONARY_0: number;
|
|
4
|
-
DICTIONARY_1: number;
|
|
5
|
-
DICTIONARY_2: number;
|
|
6
|
-
DICTIONARY_3: number;
|
|
7
|
-
AD_JID: number;
|
|
8
|
-
LIST_8: number;
|
|
9
|
-
LIST_16: number;
|
|
10
|
-
JID_PAIR: number;
|
|
11
|
-
HEX_8: number;
|
|
12
|
-
BINARY_8: number;
|
|
13
|
-
BINARY_20: number;
|
|
14
|
-
BINARY_32: number;
|
|
15
|
-
NIBBLE_8: number;
|
|
16
|
-
PACKED_MAX: number;
|
|
17
|
-
SINGLE_BYTE_MAX: number;
|
|
18
|
-
STREAM_END: number;
|
|
19
|
-
};
|
|
20
|
-
export declare const DOUBLE_BYTE_TOKENS: string[][];
|
|
21
|
-
export declare const SINGLE_BYTE_TOKENS: (string | null)[];
|
|
22
|
-
export declare const TOKEN_MAP: {
|
|
23
|
-
[token: string]: {
|
|
24
|
-
dict?: number;
|
|
25
|
-
index: number;
|
|
26
|
-
};
|
|
27
|
-
};
|