nrx-bails 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1541 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +2 -0
- package/WAProto/index.js +169661 -0
- package/lib/Defaults/index.d.ts +113 -0
- package/lib/Defaults/index.js +156 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/ye-bail-version.json +3 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +41 -0
- package/lib/Signal/Group/group-session-builder.d.ts +8 -0
- package/lib/Signal/Group/group-session-builder.js +90 -0
- package/lib/Signal/Group/group_cipher.d.ts +12 -0
- package/lib/Signal/Group/group_cipher.js +122 -0
- package/lib/Signal/Group/index.d.ts +22 -0
- package/lib/Signal/Group/index.js +83 -0
- package/lib/Signal/Group/keyhelper.d.ts +7 -0
- package/lib/Signal/Group/keyhelper.js +81 -0
- package/lib/Signal/Group/queue-job.d.ts +3 -0
- package/lib/Signal/Group/queue-job.js +83 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +60 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +92 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +95 -0
- package/lib/Signal/Group/sender-key-name.d.ts +12 -0
- package/lib/Signal/Group/sender-key-name.js +77 -0
- package/lib/Signal/Group/sender-key-record.d.ts +13 -0
- package/lib/Signal/Group/sender-key-record.js +79 -0
- package/lib/Signal/Group/sender-key-state.d.ts +17 -0
- package/lib/Signal/Group/sender-key-state.js +125 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +55 -0
- package/lib/Signal/libsignal.d.ts +37 -0
- package/lib/Signal/libsignal.js +200 -0
- package/lib/Socket/Client/index.d.ts +1 -0
- package/lib/Socket/Client/index.js +44 -0
- package/lib/Socket/Client/types.d.ts +7 -0
- package/lib/Socket/Client/types.js +39 -0
- package/lib/Socket/Client/websocket.d.ts +19 -0
- package/lib/Socket/Client/websocket.js +137 -0
- package/lib/Socket/business.d.ts +329 -0
- package/lib/Socket/business.js +286 -0
- package/lib/Socket/chats.d.ts +84 -0
- package/lib/Socket/chats.js +1022 -0
- package/lib/Socket/groups.d.ts +216 -0
- package/lib/Socket/groups.js +358 -0
- package/lib/Socket/index.d.ts +330 -0
- package/lib/Socket/index.js +36 -0
- package/lib/Socket/messages-recv.d.ts +271 -0
- package/lib/Socket/messages-recv.js +1079 -0
- package/lib/Socket/messages-send.d.ts +258 -0
- package/lib/Socket/messages-send.js +1190 -0
- package/lib/Socket/newsletter.d.ts +253 -0
- package/lib/Socket/newsletter.js +362 -0
- package/lib/Socket/registration.d.ts +361 -0
- package/lib/Socket/registration.js +179 -0
- package/lib/Socket/socket.d.ts +33 -0
- package/lib/Socket/socket.js +699 -0
- package/lib/Socket/usync.d.ts +27 -0
- package/lib/Socket/usync.js +96 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +36 -0
- package/lib/Store/make-cache-manager-auth-state.d.ts +16 -0
- package/lib/Store/make-cache-manager-auth-state.js +118 -0
- package/lib/Store/make-in-memory-store.d.ts +64 -0
- package/lib/Store/make-in-memory-store.js +465 -0
- package/lib/Store/make-ordered-dictionary.d.ts +14 -0
- package/lib/Store/make-ordered-dictionary.js +107 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +53 -0
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Auth.js +28 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.js +28 -0
- package/lib/Types/Chat.d.ts +2 -0
- package/lib/Types/Chat.js +30 -0
- package/lib/Types/Contact.d.ts +1 -0
- package/lib/Types/Contact.js +28 -0
- package/lib/Types/Events.d.ts +1 -0
- package/lib/Types/Events.js +28 -0
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/GroupMetadata.js +28 -0
- package/lib/Types/Label.d.ts +2 -0
- package/lib/Types/Label.js +53 -0
- package/lib/Types/LabelAssociation.d.ts +2 -0
- package/lib/Types/LabelAssociation.js +35 -0
- package/lib/Types/Message.d.ts +2 -0
- package/lib/Types/Message.js +33 -0
- package/lib/Types/Newsletter.d.ts +4 -0
- package/lib/Types/Newsletter.js +62 -0
- package/lib/Types/Product.d.ts +1 -0
- package/lib/Types/Product.js +28 -0
- package/lib/Types/Signal.d.ts +1 -0
- package/lib/Types/Signal.js +28 -0
- package/lib/Types/Socket.d.ts +1 -0
- package/lib/Types/Socket.js +28 -0
- package/lib/Types/State.d.ts +1 -0
- package/lib/Types/State.js +28 -0
- package/lib/Types/USync.d.ts +1 -0
- package/lib/Types/USync.js +28 -0
- package/lib/Types/index.d.ts +2 -0
- package/lib/Types/index.js +68 -0
- package/lib/Utils/auth-utils.d.ts +63 -0
- package/lib/Utils/auth-utils.js +248 -0
- package/lib/Utils/browser-utils.d.ts +3 -0
- package/lib/Utils/browser-utils.js +61 -0
- package/lib/Utils/business.d.ts +53 -0
- package/lib/Utils/business.js +260 -0
- package/lib/Utils/chat-utils.d.ts +253 -0
- package/lib/Utils/chat-utils.js +756 -0
- package/lib/Utils/crypto.d.ts +43 -0
- package/lib/Utils/crypto.js +219 -0
- package/lib/Utils/decode-wa-message.d.ts +61 -0
- package/lib/Utils/decode-wa-message.js +233 -0
- package/lib/Utils/event-buffer.d.ts +17 -0
- package/lib/Utils/event-buffer.js +544 -0
- package/lib/Utils/generics.d.ts +89 -0
- package/lib/Utils/generics.js +471 -0
- package/lib/Utils/history.d.ts +59 -0
- package/lib/Utils/history.js +120 -0
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +61 -0
- package/lib/Utils/link-preview.d.ts +19 -0
- package/lib/Utils/link-preview.js +152 -0
- package/lib/Utils/logger.d.ts +3 -0
- package/lib/Utils/logger.js +33 -0
- package/lib/Utils/lt-hash.d.ts +13 -0
- package/lib/Utils/lt-hash.js +77 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +69 -0
- package/lib/Utils/message-retry-manager.d.ts +34 -0
- package/lib/Utils/message-retry-manager.js +154 -0
- package/lib/Utils/messages-media.d.ts +137 -0
- package/lib/Utils/messages-media.js +1024 -0
- package/lib/Utils/messages.d.ts +66 -0
- package/lib/Utils/messages.js +1407 -0
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +176 -0
- package/lib/Utils/pre-key-manager.d.ts +13 -0
- package/lib/Utils/pre-key-manager.js +93 -0
- package/lib/Utils/process-message.d.ts +40 -0
- package/lib/Utils/process-message.js +430 -0
- package/lib/Utils/signal.d.ts +72 -0
- package/lib/Utils/signal.js +179 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +18 -0
- package/lib/Utils/use-multi-file-auth-state.js +151 -0
- package/lib/Utils/validate-connection.d.ts +43 -0
- package/lib/Utils/validate-connection.js +255 -0
- package/lib/Utils/ye-bail-event-stream.d.ts +16 -0
- package/lib/Utils/ye-bail-event-stream.js +89 -0
- package/lib/WABinary/constants.d.ts +23 -0
- package/lib/WABinary/constants.js +1328 -0
- package/lib/WABinary/decode.d.ts +10 -0
- package/lib/WABinary/decode.js +291 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +276 -0
- package/lib/WABinary/generic-utils.d.ts +16 -0
- package/lib/WABinary/generic-utils.js +155 -0
- package/lib/WABinary/index.d.ts +1 -0
- package/lib/WABinary/index.js +47 -0
- package/lib/WABinary/jid-utils.d.ts +34 -0
- package/lib/WABinary/jid-utils.js +111 -0
- package/lib/WABinary/types.d.ts +1 -0
- package/lib/WABinary/types.js +28 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +39 -0
- package/lib/WAM/constants.d.ts +35374 -0
- package/lib/WAM/constants.js +15376 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +181 -0
- package/lib/WAM/index.d.ts +1 -0
- package/lib/WAM/index.js +45 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +58 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +83 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +56 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +68 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +79 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +50 -0
- package/lib/WAUSync/Protocols/index.d.ts +1 -0
- package/lib/WAUSync/Protocols/index.js +46 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +115 -0
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/USyncUser.js +52 -0
- package/lib/WAUSync/index.d.ts +1 -0
- package/lib/WAUSync/index.js +45 -0
- package/lib/index.js +81 -0
- package/package.json +113 -0
- package/requirements.js +32 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
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 function useMultiFileAuthState(folder: any): Promise<{
|
|
10
|
+
state: {
|
|
11
|
+
creds: any;
|
|
12
|
+
keys: {
|
|
13
|
+
get: (type: any, ids: any) => Promise<{}>;
|
|
14
|
+
set: (data: any) => Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
saveCreds: () => Promise<any>;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ╔═══════════════════════════════════════════════════════════╗
|
|
3
|
+
* ║ NEROX - WhatsApp API Library ║
|
|
4
|
+
* ║ Premium Edition ║
|
|
5
|
+
* ╚═══════════════════════════════════════════════════════════╝
|
|
6
|
+
*
|
|
7
|
+
* @package nerox-bails
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author NEROX Development Team
|
|
10
|
+
* @copyright Copyright (c) 2025 NEROX. All rights reserved.
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
15
|
+
* to deal in the Software without restriction, including without limitation
|
|
16
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
18
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included
|
|
21
|
+
* in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
24
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
*/
|
|
27
|
+
"use strict";
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.useMultiFileAuthState = void 0;
|
|
30
|
+
const async_mutex_1 = require("async-mutex");
|
|
31
|
+
const promises_1 = require("fs/promises");
|
|
32
|
+
const path_1 = require("path");
|
|
33
|
+
const WAProto_1 = require("../../WAProto");
|
|
34
|
+
const auth_utils_1 = require("./auth-utils");
|
|
35
|
+
const generics_1 = require("./generics");
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const fileLocks = new Map();
|
|
41
|
+
|
|
42
|
+
const getFileLock = (path) => {
|
|
43
|
+
let mutex = fileLocks.get(path);
|
|
44
|
+
if (!mutex) {
|
|
45
|
+
mutex = new async_mutex_1.Mutex();
|
|
46
|
+
fileLocks.set(path, mutex);
|
|
47
|
+
}
|
|
48
|
+
return mutex;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* stores the full authentication state in a single folder.
|
|
52
|
+
* Far more efficient than singlefileauthstate
|
|
53
|
+
*
|
|
54
|
+
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
55
|
+
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
56
|
+
* */
|
|
57
|
+
const useMultiFileAuthState = async (folder) => {
|
|
58
|
+
|
|
59
|
+
const writeData = async (data, file) => {
|
|
60
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
61
|
+
const mutex = getFileLock(filePath);
|
|
62
|
+
return mutex.acquire().then(async (release) => {
|
|
63
|
+
try {
|
|
64
|
+
await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
release();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const readData = async (file) => {
|
|
72
|
+
try {
|
|
73
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
74
|
+
const mutex = getFileLock(filePath);
|
|
75
|
+
return await mutex.acquire().then(async (release) => {
|
|
76
|
+
try {
|
|
77
|
+
const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
|
|
78
|
+
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
release();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const removeData = async (file) => {
|
|
90
|
+
try {
|
|
91
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
92
|
+
const mutex = getFileLock(filePath);
|
|
93
|
+
return mutex.acquire().then(async (release) => {
|
|
94
|
+
try {
|
|
95
|
+
await (0, promises_1.unlink)(filePath);
|
|
96
|
+
}
|
|
97
|
+
catch (_a) {
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
release();
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
catch (_a) {
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
|
|
108
|
+
if (folderInfo) {
|
|
109
|
+
if (!folderInfo.isDirectory()) {
|
|
110
|
+
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
await (0, promises_1.mkdir)(folder, { recursive: true });
|
|
115
|
+
}
|
|
116
|
+
const fixFileName = (file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '-')) ?? file; };
|
|
117
|
+
const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
|
|
118
|
+
return {
|
|
119
|
+
state: {
|
|
120
|
+
creds,
|
|
121
|
+
keys: {
|
|
122
|
+
get: async (type, ids) => {
|
|
123
|
+
const data = {};
|
|
124
|
+
await Promise.all(ids.map(async (id) => {
|
|
125
|
+
let value = await readData(`${type}-${id}.json`);
|
|
126
|
+
if (type === 'app-state-sync-key' && value) {
|
|
127
|
+
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
128
|
+
}
|
|
129
|
+
data[id] = value;
|
|
130
|
+
}));
|
|
131
|
+
return data;
|
|
132
|
+
},
|
|
133
|
+
set: async (data) => {
|
|
134
|
+
const tasks = [];
|
|
135
|
+
for (const category in data) {
|
|
136
|
+
for (const id in data[category]) {
|
|
137
|
+
const value = data[category][id];
|
|
138
|
+
const file = `${category}-${id}.json`;
|
|
139
|
+
tasks.push(value ? writeData(value, file) : removeData(file));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
await Promise.all(tasks);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
saveCreds: async () => {
|
|
147
|
+
return writeData(creds, 'creds.json');
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
exports.useMultiFileAuthState = useMultiFileAuthState;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
2
|
+
export function generateLoginNode(userJid: any, config: any): any;
|
|
3
|
+
export function generateRegistrationNode({ registrationId, signedPreKey, signedIdentityKey }: {
|
|
4
|
+
registrationId: any;
|
|
5
|
+
signedPreKey: any;
|
|
6
|
+
signedIdentityKey: any;
|
|
7
|
+
}, config: any): any;
|
|
8
|
+
export function configureSuccessfulPairing(stanza: any, { advSecretKey, signedIdentityKey, signalIdentities }: {
|
|
9
|
+
advSecretKey: any;
|
|
10
|
+
signedIdentityKey: any;
|
|
11
|
+
signalIdentities: any;
|
|
12
|
+
}): {
|
|
13
|
+
creds: {
|
|
14
|
+
account: any;
|
|
15
|
+
me: {
|
|
16
|
+
id: any;
|
|
17
|
+
name: any;
|
|
18
|
+
lid: any;
|
|
19
|
+
};
|
|
20
|
+
signalIdentities: any[];
|
|
21
|
+
platform: any;
|
|
22
|
+
};
|
|
23
|
+
reply: {
|
|
24
|
+
tag: string;
|
|
25
|
+
attrs: {
|
|
26
|
+
to: any;
|
|
27
|
+
type: string;
|
|
28
|
+
id: any;
|
|
29
|
+
};
|
|
30
|
+
content: {
|
|
31
|
+
tag: string;
|
|
32
|
+
attrs: {};
|
|
33
|
+
content: {
|
|
34
|
+
tag: string;
|
|
35
|
+
attrs: {
|
|
36
|
+
'key-index': any;
|
|
37
|
+
};
|
|
38
|
+
content: any;
|
|
39
|
+
}[];
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export function encodeSignedDeviceIdentity(account: any, includeSignatureKey: any): any;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ╔═══════════════════════════════════════════════════════════╗
|
|
3
|
+
* ║ NEROX - WhatsApp API Library ║
|
|
4
|
+
* ║ Premium Edition ║
|
|
5
|
+
* ╚═══════════════════════════════════════════════════════════╝
|
|
6
|
+
*
|
|
7
|
+
* @package nerox-bails
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author NEROX Development Team
|
|
10
|
+
* @copyright Copyright (c) 2025 NEROX. All rights reserved.
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
15
|
+
* to deal in the Software without restriction, including without limitation
|
|
16
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
18
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included
|
|
21
|
+
* in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
24
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
*/
|
|
27
|
+
"use strict";
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
|
|
30
|
+
const boom_1 = require("@hapi/boom");
|
|
31
|
+
const crypto_1 = require("crypto");
|
|
32
|
+
const WAProto_1 = require("../../WAProto");
|
|
33
|
+
const Defaults_1 = require("../Defaults");
|
|
34
|
+
const WABinary_1 = require("../WABinary");
|
|
35
|
+
const crypto_2 = require("./crypto");
|
|
36
|
+
const generics_1 = require("./generics");
|
|
37
|
+
const signal_1 = require("./signal");
|
|
38
|
+
|
|
39
|
+
const getUserAgent = (config) => {
|
|
40
|
+
return {
|
|
41
|
+
appVersion: {
|
|
42
|
+
primary: config.version[0],
|
|
43
|
+
secondary: config.version[1],
|
|
44
|
+
tertiary: config.version[2],
|
|
45
|
+
},
|
|
46
|
+
platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
|
|
47
|
+
releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
48
|
+
osVersion: '0.1',
|
|
49
|
+
device: 'Desktop',
|
|
50
|
+
osBuildNumber: '0.1',
|
|
51
|
+
localeLanguageIso6391: 'en',
|
|
52
|
+
mnc: '000',
|
|
53
|
+
mcc: '000',
|
|
54
|
+
localeCountryIso31661Alpha2: config.countryCode || 'US'
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const PLATFORM_MAP = {
|
|
59
|
+
'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
60
|
+
'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const getWebInfo = (config) => {
|
|
64
|
+
let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
65
|
+
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
|
|
66
|
+
webSubPlatform = PLATFORM_MAP[config.browser[0]];
|
|
67
|
+
}
|
|
68
|
+
return { webSubPlatform };
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const getClientPayload = (config) => {
|
|
72
|
+
const payload = {
|
|
73
|
+
connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
74
|
+
connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
75
|
+
userAgent: getUserAgent(config),
|
|
76
|
+
};
|
|
77
|
+
payload.webInfo = getWebInfo(config);
|
|
78
|
+
return payload;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const generateLoginNode = (userJid, config) => {
|
|
82
|
+
const { user, device } = (0, WABinary_1.jidDecode)(userJid);
|
|
83
|
+
const payload = {
|
|
84
|
+
...getClientPayload(config),
|
|
85
|
+
passive: true,
|
|
86
|
+
pull: true,
|
|
87
|
+
username: +user,
|
|
88
|
+
device: device,
|
|
89
|
+
lidDbMigrated: false
|
|
90
|
+
};
|
|
91
|
+
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
92
|
+
};
|
|
93
|
+
exports.generateLoginNode = generateLoginNode;
|
|
94
|
+
|
|
95
|
+
const getPlatformType = (platform) => {
|
|
96
|
+
const platformType = platform.toUpperCase();
|
|
97
|
+
return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.CHROME;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
101
|
+
const appVersionBuf = (0, crypto_1.createHash)('md5')
|
|
102
|
+
.update(config.version.join('.'))
|
|
103
|
+
.digest();
|
|
104
|
+
|
|
105
|
+
const companion = {
|
|
106
|
+
os: config.browser[0],
|
|
107
|
+
platformType: getPlatformType(config.browser[1]),
|
|
108
|
+
requireFullSync: config.syncFullHistory,
|
|
109
|
+
historySyncConfig: {
|
|
110
|
+
storageQuotaMb: 10240,
|
|
111
|
+
inlineInitialPayloadInE2EeMsg: true,
|
|
112
|
+
recentSyncDaysLimit: undefined,
|
|
113
|
+
supportCallLogHistory: false,
|
|
114
|
+
supportBotUserAgentChatHistory: true,
|
|
115
|
+
supportCagReactionsAndPolls: true,
|
|
116
|
+
supportBizHostedMsg: true,
|
|
117
|
+
supportRecentSyncChunkMessageCountTuning: true,
|
|
118
|
+
supportHostedGroupMsg: true,
|
|
119
|
+
supportFbidBotChatHistory: true,
|
|
120
|
+
supportAddOnHistorySyncMigration: undefined,
|
|
121
|
+
supportMessageAssociation: true,
|
|
122
|
+
supportGroupHistory: false,
|
|
123
|
+
onDemandReady: undefined,
|
|
124
|
+
supportGuestChat: undefined
|
|
125
|
+
},
|
|
126
|
+
version: {
|
|
127
|
+
primary: 10,
|
|
128
|
+
secondary: 15,
|
|
129
|
+
tertiary: 7
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
|
|
134
|
+
|
|
135
|
+
const registerPayload = {
|
|
136
|
+
...getClientPayload(config),
|
|
137
|
+
passive: false,
|
|
138
|
+
pull: false,
|
|
139
|
+
devicePairingData: {
|
|
140
|
+
buildHash: appVersionBuf,
|
|
141
|
+
deviceProps: companionProto,
|
|
142
|
+
eRegid: (0, generics_1.encodeBigEndian)(registrationId),
|
|
143
|
+
eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
|
|
144
|
+
eIdent: signedIdentityKey.public,
|
|
145
|
+
eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
|
|
146
|
+
eSkeyVal: signedPreKey.keyPair.public,
|
|
147
|
+
eSkeySig: signedPreKey.signature,
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
|
|
151
|
+
};
|
|
152
|
+
exports.generateRegistrationNode = generateRegistrationNode;
|
|
153
|
+
|
|
154
|
+
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
155
|
+
const msgId = stanza.attrs.id;
|
|
156
|
+
const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
|
|
157
|
+
const deviceIdentityNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
|
|
158
|
+
const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
|
|
159
|
+
const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
|
|
160
|
+
const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
|
|
161
|
+
|
|
162
|
+
if (!deviceIdentityNode || !deviceNode) {
|
|
163
|
+
throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const bizName = businessNode?.attrs.name;
|
|
167
|
+
const jid = deviceNode.attrs.jid;
|
|
168
|
+
const lid = deviceNode.attrs.lid;
|
|
169
|
+
|
|
170
|
+
const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
171
|
+
|
|
172
|
+
let hmacPrefix = Buffer.from([]);
|
|
173
|
+
if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
|
|
174
|
+
hmacPrefix = Buffer.from([0x06, 0x05]);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
178
|
+
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
179
|
+
throw new boom_1.Boom('Invalid account signature');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
|
|
183
|
+
const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
|
|
184
|
+
|
|
185
|
+
const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(deviceDetails);
|
|
186
|
+
|
|
187
|
+
const accountSignaturePrefix = deviceIdentity.deviceType === WAProto_1.proto.ADVEncryptionType.HOSTED
|
|
188
|
+
? Buffer.from([0x06, 0x05])
|
|
189
|
+
: Buffer.from([0x06, 0x00]);
|
|
190
|
+
const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
|
|
191
|
+
|
|
192
|
+
if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
193
|
+
throw new boom_1.Boom('Failed to verify account signature');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const deviceMsg = Buffer.concat([
|
|
197
|
+
Buffer.from([0x06, 0x01]),
|
|
198
|
+
deviceDetails,
|
|
199
|
+
signedIdentityKey.public,
|
|
200
|
+
accountSignatureKey
|
|
201
|
+
]);
|
|
202
|
+
account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
203
|
+
|
|
204
|
+
const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
|
|
205
|
+
const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
|
|
206
|
+
|
|
207
|
+
const reply = {
|
|
208
|
+
tag: 'iq',
|
|
209
|
+
attrs: {
|
|
210
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
211
|
+
type: 'result',
|
|
212
|
+
id: msgId,
|
|
213
|
+
},
|
|
214
|
+
content: [
|
|
215
|
+
{
|
|
216
|
+
tag: 'pair-device-sign',
|
|
217
|
+
attrs: {},
|
|
218
|
+
content: [
|
|
219
|
+
{
|
|
220
|
+
tag: 'device-identity',
|
|
221
|
+
attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
|
|
222
|
+
content: accountEnc
|
|
223
|
+
}
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
]
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const authUpdate = {
|
|
230
|
+
account,
|
|
231
|
+
me: { id: jid, name: bizName, lid },
|
|
232
|
+
signalIdentities: [
|
|
233
|
+
...(signalIdentities || []),
|
|
234
|
+
identity
|
|
235
|
+
],
|
|
236
|
+
platform: platformNode?.attrs.name
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
creds: authUpdate,
|
|
241
|
+
reply
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
exports.configureSuccessfulPairing = configureSuccessfulPairing;
|
|
245
|
+
|
|
246
|
+
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
247
|
+
account = { ...account };
|
|
248
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
249
|
+
account.accountSignatureKey = null;
|
|
250
|
+
}
|
|
251
|
+
return WAProto_1.proto.ADVSignedDeviceIdentity
|
|
252
|
+
.encode(account)
|
|
253
|
+
.finish();
|
|
254
|
+
};
|
|
255
|
+
exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Captures events from a ye-bail event emitter & stores them in a file
|
|
4
|
+
* @param ev The event emitter to read events from
|
|
5
|
+
* @param filename File to save to
|
|
6
|
+
*/
|
|
7
|
+
export function captureEventStream(ev: any, filename: any): void;
|
|
8
|
+
/**
|
|
9
|
+
* Read event file and emit events from there
|
|
10
|
+
* @param filename filename containing event data
|
|
11
|
+
* @param delayIntervalMs delay between each event emit
|
|
12
|
+
*/
|
|
13
|
+
export function readAndEmitEventStream(filename: any, delayIntervalMs?: number): {
|
|
14
|
+
ev: any;
|
|
15
|
+
task: Promise<void>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ╔═══════════════════════════════════════════════════════════╗
|
|
3
|
+
* ║ NEROX - WhatsApp API Library ║
|
|
4
|
+
* ║ Premium Edition ║
|
|
5
|
+
* ╚═══════════════════════════════════════════════════════════╝
|
|
6
|
+
*
|
|
7
|
+
* @package nerox-bails
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author NEROX Development Team
|
|
10
|
+
* @copyright Copyright (c) 2025 NEROX. All rights reserved.
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
15
|
+
* to deal in the Software without restriction, including without limitation
|
|
16
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
18
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included
|
|
21
|
+
* in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
24
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
*/
|
|
27
|
+
"use strict";
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.readAndEmitEventStream = exports.captureEventStream = void 0;
|
|
33
|
+
const events_1 = __importDefault(require("events"));
|
|
34
|
+
const fs_1 = require("fs");
|
|
35
|
+
const promises_1 = require("fs/promises");
|
|
36
|
+
const readline_1 = require("readline");
|
|
37
|
+
const generics_1 = require("./generics");
|
|
38
|
+
const make_mutex_1 = require("./make-mutex");
|
|
39
|
+
/**
|
|
40
|
+
* Captures events from a ye-bail event emitter & stores them in a file
|
|
41
|
+
* @param ev The event emitter to read events from
|
|
42
|
+
* @param filename File to save to
|
|
43
|
+
*/
|
|
44
|
+
const captureEventStream = (ev, filename) => {
|
|
45
|
+
const oldEmit = ev.emit;
|
|
46
|
+
|
|
47
|
+
const writeMutex = (0, make_mutex_1.makeMutex)();
|
|
48
|
+
|
|
49
|
+
ev.emit = function (...args) {
|
|
50
|
+
const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n';
|
|
51
|
+
const result = oldEmit.apply(ev, args);
|
|
52
|
+
writeMutex.mutex(async () => {
|
|
53
|
+
await (0, promises_1.writeFile)(filename, content, { flag: 'a' });
|
|
54
|
+
});
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
exports.captureEventStream = captureEventStream;
|
|
59
|
+
/**
|
|
60
|
+
* Read event file and emit events from there
|
|
61
|
+
* @param filename filename containing event data
|
|
62
|
+
* @param delayIntervalMs delay between each event emit
|
|
63
|
+
*/
|
|
64
|
+
const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
65
|
+
const ev = new events_1.default();
|
|
66
|
+
const fireEvents = async () => {
|
|
67
|
+
|
|
68
|
+
const fileStream = (0, fs_1.createReadStream)(filename);
|
|
69
|
+
const rl = (0, readline_1.createInterface)({
|
|
70
|
+
input: fileStream,
|
|
71
|
+
crlfDelay: Infinity
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
for await (const line of rl) {
|
|
76
|
+
if (line) {
|
|
77
|
+
const { event, data } = JSON.parse(line);
|
|
78
|
+
ev.emit(event, data);
|
|
79
|
+
delayIntervalMs && await (0, generics_1.delay)(delayIntervalMs);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
fileStream.close();
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
ev,
|
|
86
|
+
task: fireEvents()
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
exports.readAndEmitEventStream = readAndEmitEventStream;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
2
|
+
export namespace TAGS {
|
|
3
|
+
let LIST_EMPTY: number;
|
|
4
|
+
let DICTIONARY_0: number;
|
|
5
|
+
let DICTIONARY_1: number;
|
|
6
|
+
let DICTIONARY_2: number;
|
|
7
|
+
let DICTIONARY_3: number;
|
|
8
|
+
let INTEROP_JID: number;
|
|
9
|
+
let FB_JID: number;
|
|
10
|
+
let AD_JID: number;
|
|
11
|
+
let LIST_8: number;
|
|
12
|
+
let LIST_16: number;
|
|
13
|
+
let JID_PAIR: number;
|
|
14
|
+
let HEX_8: number;
|
|
15
|
+
let BINARY_8: number;
|
|
16
|
+
let BINARY_20: number;
|
|
17
|
+
let BINARY_32: number;
|
|
18
|
+
let NIBBLE_8: number;
|
|
19
|
+
let PACKED_MAX: number;
|
|
20
|
+
}
|
|
21
|
+
export const DOUBLE_BYTE_TOKENS: string[][];
|
|
22
|
+
export const SINGLE_BYTE_TOKENS: string[];
|
|
23
|
+
export const TOKEN_MAP: {};
|