@baileys-md/baileys 10.1.0 → 11.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/LICENSE +1 -1
- package/README.md +1303 -2
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.js +13516 -4182
- package/lib/Defaults/baileys-version.js +1 -0
- package/lib/Defaults/index.js +51 -72
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.js +94 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +19 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +32 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.js +67 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.js +50 -0
- package/lib/Signal/Group/sender-key-state.js +96 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +4 -16
- package/lib/Signal/libsignal.js +41 -61
- package/lib/Socket/Client/index.js +3 -19
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +50 -0
- package/lib/Socket/business.js +37 -42
- package/lib/Socket/chats.js +194 -187
- package/lib/Socket/communities.js +351 -0
- package/lib/Socket/groups.js +87 -90
- package/lib/Socket/index.js +7 -8
- package/lib/Socket/messages-recv.js +360 -335
- package/lib/Socket/messages-send.js +156 -279
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.js +144 -213
- package/lib/Socket/socket.js +128 -161
- package/lib/Socket/usync.js +19 -26
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +3 -5
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.js +30 -17
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +15 -31
- package/lib/Utils/auth-utils.js +31 -47
- package/lib/Utils/baileys-event-stream.js +15 -22
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/chat-utils.js +200 -195
- package/lib/Utils/crypto.js +70 -85
- package/lib/Utils/decode-wa-message.js +47 -51
- package/lib/Utils/event-buffer.js +36 -46
- package/lib/Utils/generics.js +116 -188
- package/lib/Utils/history.js +37 -46
- package/lib/Utils/index.js +19 -33
- package/lib/Utils/link-preview.js +14 -55
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/lt-hash.js +23 -26
- package/lib/{Store → Utils}/make-in-memory-store.js +19 -27
- package/lib/Utils/make-mutex.js +7 -10
- package/lib/{Store → Utils}/make-ordered-dictionary.js +1 -3
- package/lib/Utils/messages-media.js +236 -368
- package/lib/Utils/messages.js +278 -510
- package/lib/Utils/noise-handler.js +22 -31
- package/lib/{Store → Utils}/object-repository.js +1 -4
- package/lib/Utils/process-message.js +144 -148
- package/lib/Utils/signal.js +71 -64
- package/lib/Utils/use-multi-file-auth-state.js +112 -84
- package/lib/Utils/validate-connection.js +72 -115
- package/lib/WABinary/constants.js +1281 -20
- package/lib/WABinary/decode.js +15 -52
- package/lib/WABinary/encode.js +14 -48
- package/lib/WABinary/generic-utils.js +31 -39
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/jid-utils.js +23 -40
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/constants.js +2257 -2366
- package/lib/WAM/encode.js +17 -21
- package/lib/WAM/index.js +4 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -6
- package/lib/WAUSync/Protocols/index.js +5 -20
- package/lib/WAUSync/USyncQuery.js +34 -32
- package/lib/WAUSync/USyncUser.js +2 -5
- package/lib/WAUSync/index.js +4 -19
- package/lib/index.js +11 -33
- package/package.json +25 -54
- 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/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/registration.js +0 -166
- package/lib/Store/index.js +0 -8
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-mongo-store.js +0 -567
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { SenderChainKey } from './sender-chain-key.js';
|
|
2
|
+
import { SenderMessageKey } from './sender-message-key.js';
|
|
3
|
+
export class SenderKeyState {
|
|
4
|
+
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
5
|
+
this.MAX_MESSAGE_KEYS = 2000;
|
|
6
|
+
if (senderKeyStateStructure) {
|
|
7
|
+
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
if (signatureKeyPair) {
|
|
11
|
+
signatureKeyPublic = signatureKeyPair.public;
|
|
12
|
+
signatureKeyPrivate = signatureKeyPair.private;
|
|
13
|
+
}
|
|
14
|
+
chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
|
|
15
|
+
const senderChainKeyStructure = {
|
|
16
|
+
iteration: iteration || 0,
|
|
17
|
+
seed: chainKey || Buffer.alloc(0)
|
|
18
|
+
};
|
|
19
|
+
const signingKeyStructure = {
|
|
20
|
+
public: typeof signatureKeyPublic === 'string'
|
|
21
|
+
? Buffer.from(signatureKeyPublic, 'base64')
|
|
22
|
+
: signatureKeyPublic || Buffer.alloc(0)
|
|
23
|
+
};
|
|
24
|
+
if (signatureKeyPrivate) {
|
|
25
|
+
signingKeyStructure.private =
|
|
26
|
+
typeof signatureKeyPrivate === 'string' ? Buffer.from(signatureKeyPrivate, 'base64') : signatureKeyPrivate;
|
|
27
|
+
}
|
|
28
|
+
this.senderKeyStateStructure = {
|
|
29
|
+
senderKeyId: id || 0,
|
|
30
|
+
senderChainKey: senderChainKeyStructure,
|
|
31
|
+
senderSigningKey: signingKeyStructure,
|
|
32
|
+
senderMessageKeys: []
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
getKeyId() {
|
|
37
|
+
return this.senderKeyStateStructure.senderKeyId;
|
|
38
|
+
}
|
|
39
|
+
getSenderChainKey() {
|
|
40
|
+
return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
|
|
41
|
+
}
|
|
42
|
+
setSenderChainKey(chainKey) {
|
|
43
|
+
this.senderKeyStateStructure.senderChainKey = {
|
|
44
|
+
iteration: chainKey.getIteration(),
|
|
45
|
+
seed: chainKey.getSeed()
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
getSigningKeyPublic() {
|
|
49
|
+
const publicKey = this.senderKeyStateStructure.senderSigningKey.public;
|
|
50
|
+
if (publicKey instanceof Buffer) {
|
|
51
|
+
return publicKey;
|
|
52
|
+
}
|
|
53
|
+
else if (typeof publicKey === 'string') {
|
|
54
|
+
return Buffer.from(publicKey, 'base64');
|
|
55
|
+
}
|
|
56
|
+
return Buffer.from(publicKey || []);
|
|
57
|
+
}
|
|
58
|
+
getSigningKeyPrivate() {
|
|
59
|
+
const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
|
|
60
|
+
if (!privateKey) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
if (privateKey instanceof Buffer) {
|
|
64
|
+
return privateKey;
|
|
65
|
+
}
|
|
66
|
+
else if (typeof privateKey === 'string') {
|
|
67
|
+
return Buffer.from(privateKey, 'base64');
|
|
68
|
+
}
|
|
69
|
+
return Buffer.from(privateKey || []);
|
|
70
|
+
}
|
|
71
|
+
hasSenderMessageKey(iteration) {
|
|
72
|
+
return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration);
|
|
73
|
+
}
|
|
74
|
+
addSenderMessageKey(senderMessageKey) {
|
|
75
|
+
this.senderKeyStateStructure.senderMessageKeys.push({
|
|
76
|
+
iteration: senderMessageKey.getIteration(),
|
|
77
|
+
seed: senderMessageKey.getSeed()
|
|
78
|
+
});
|
|
79
|
+
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
80
|
+
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
removeSenderMessageKey(iteration) {
|
|
84
|
+
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration);
|
|
85
|
+
if (index !== -1) {
|
|
86
|
+
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
|
|
87
|
+
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
|
|
88
|
+
return new SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
getStructure() {
|
|
93
|
+
return this.senderKeyStateStructure;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=sender-key-state.js.map
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
iv = Buffer.alloc(0);
|
|
6
|
-
|
|
7
|
-
cipherKey = Buffer.alloc(0);
|
|
8
|
-
|
|
9
|
-
seed = Buffer.alloc(0);
|
|
10
|
-
|
|
1
|
+
/* @ts-ignore */
|
|
2
|
+
import { deriveSecrets } from 'libsignal/src/crypto.js';
|
|
3
|
+
export class SenderMessageKey {
|
|
11
4
|
constructor(iteration, seed) {
|
|
12
5
|
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
13
6
|
const keys = new Uint8Array(32);
|
|
@@ -15,25 +8,20 @@ class SenderMessageKey {
|
|
|
15
8
|
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
16
9
|
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
17
10
|
this.cipherKey = Buffer.from(keys.buffer);
|
|
18
|
-
|
|
19
11
|
this.iteration = iteration;
|
|
20
12
|
this.seed = seed;
|
|
21
13
|
}
|
|
22
|
-
|
|
23
14
|
getIteration() {
|
|
24
15
|
return this.iteration;
|
|
25
16
|
}
|
|
26
|
-
|
|
27
17
|
getIv() {
|
|
28
18
|
return this.iv;
|
|
29
19
|
}
|
|
30
|
-
|
|
31
20
|
getCipherKey() {
|
|
32
21
|
return this.cipherKey;
|
|
33
22
|
}
|
|
34
|
-
|
|
35
23
|
getSeed() {
|
|
36
24
|
return this.seed;
|
|
37
25
|
}
|
|
38
26
|
}
|
|
39
|
-
|
|
27
|
+
//# sourceMappingURL=sender-message-key.js.map
|
package/lib/Signal/libsignal.js
CHANGED
|
@@ -1,58 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.makeLibSignalRepository = makeLibSignalRepository;
|
|
37
|
-
const libsignal = __importStar(require("libsignal"));
|
|
38
|
-
const WASignalGroup_1 = require("../../WASignalGroup");
|
|
39
|
-
const Utils_1 = require("../Utils");
|
|
40
|
-
const WABinary_1 = require("../WABinary");
|
|
41
|
-
function makeLibSignalRepository(auth) {
|
|
1
|
+
/* @ts-ignore */
|
|
2
|
+
import * as libsignal from 'libsignal';
|
|
3
|
+
import { generateSignalPubKey } from '../Utils/index.js';
|
|
4
|
+
import { jidDecode } from '../WABinary/index.js';
|
|
5
|
+
import { SenderKeyName } from './Group/sender-key-name.js';
|
|
6
|
+
import { SenderKeyRecord } from './Group/sender-key-record.js';
|
|
7
|
+
import { GroupCipher, GroupSessionBuilder, SenderKeyDistributionMessage } from './Group/index.js';
|
|
8
|
+
export function makeLibSignalRepository(auth) {
|
|
42
9
|
const storage = signalStorage(auth);
|
|
43
10
|
return {
|
|
44
11
|
decryptGroupMessage({ group, authorJid, msg }) {
|
|
45
12
|
const senderName = jidToSignalSenderKeyName(group, authorJid);
|
|
46
|
-
const cipher = new
|
|
13
|
+
const cipher = new GroupCipher(storage, senderName);
|
|
47
14
|
return cipher.decrypt(msg);
|
|
48
15
|
},
|
|
49
16
|
async processSenderKeyDistributionMessage({ item, authorJid }) {
|
|
50
|
-
const builder = new
|
|
17
|
+
const builder = new GroupSessionBuilder(storage);
|
|
18
|
+
if (!item.groupId) {
|
|
19
|
+
throw new Error('Group ID is required for sender key distribution message');
|
|
20
|
+
}
|
|
51
21
|
const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
|
|
52
|
-
const senderMsg = new
|
|
53
|
-
const
|
|
22
|
+
const senderMsg = new SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
|
|
23
|
+
const senderNameStr = senderName.toString();
|
|
24
|
+
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
54
25
|
if (!senderKey) {
|
|
55
|
-
await storage.storeSenderKey(senderName, new
|
|
26
|
+
await storage.storeSenderKey(senderName, new SenderKeyRecord());
|
|
56
27
|
}
|
|
57
28
|
await builder.process(senderName, senderMsg);
|
|
58
29
|
},
|
|
@@ -67,6 +38,8 @@ function makeLibSignalRepository(auth) {
|
|
|
67
38
|
case 'msg':
|
|
68
39
|
result = await session.decryptWhisperMessage(ciphertext);
|
|
69
40
|
break;
|
|
41
|
+
default:
|
|
42
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
70
43
|
}
|
|
71
44
|
return result;
|
|
72
45
|
},
|
|
@@ -79,17 +52,18 @@ function makeLibSignalRepository(auth) {
|
|
|
79
52
|
},
|
|
80
53
|
async encryptGroupMessage({ group, meId, data }) {
|
|
81
54
|
const senderName = jidToSignalSenderKeyName(group, meId);
|
|
82
|
-
const builder = new
|
|
83
|
-
const
|
|
55
|
+
const builder = new GroupSessionBuilder(storage);
|
|
56
|
+
const senderNameStr = senderName.toString();
|
|
57
|
+
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
84
58
|
if (!senderKey) {
|
|
85
|
-
await storage.storeSenderKey(senderName, new
|
|
59
|
+
await storage.storeSenderKey(senderName, new SenderKeyRecord());
|
|
86
60
|
}
|
|
87
61
|
const senderKeyDistributionMessage = await builder.create(senderName);
|
|
88
|
-
const session = new
|
|
62
|
+
const session = new GroupCipher(storage, senderName);
|
|
89
63
|
const ciphertext = await session.encrypt(data);
|
|
90
64
|
return {
|
|
91
65
|
ciphertext,
|
|
92
|
-
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize()
|
|
66
|
+
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize()
|
|
93
67
|
};
|
|
94
68
|
},
|
|
95
69
|
async injectE2ESession({ jid, session }) {
|
|
@@ -98,15 +72,15 @@ function makeLibSignalRepository(auth) {
|
|
|
98
72
|
},
|
|
99
73
|
jidToSignalProtocolAddress(jid) {
|
|
100
74
|
return jidToSignalProtocolAddress(jid).toString();
|
|
101
|
-
}
|
|
75
|
+
}
|
|
102
76
|
};
|
|
103
77
|
}
|
|
104
78
|
const jidToSignalProtocolAddress = (jid) => {
|
|
105
|
-
const { user, device } =
|
|
79
|
+
const { user, device } = jidDecode(jid);
|
|
106
80
|
return new libsignal.ProtocolAddress(user, device || 0);
|
|
107
81
|
};
|
|
108
82
|
const jidToSignalSenderKeyName = (group, user) => {
|
|
109
|
-
return new
|
|
83
|
+
return new SenderKeyName(group, jidToSignalProtocolAddress(user));
|
|
110
84
|
};
|
|
111
85
|
function signalStorage({ creds, keys }) {
|
|
112
86
|
return {
|
|
@@ -116,8 +90,9 @@ function signalStorage({ creds, keys }) {
|
|
|
116
90
|
return libsignal.SessionRecord.deserialize(sess);
|
|
117
91
|
}
|
|
118
92
|
},
|
|
93
|
+
// TODO: Replace with libsignal.SessionRecord when type exports are added to libsignal
|
|
119
94
|
storeSession: async (id, session) => {
|
|
120
|
-
await keys.set({
|
|
95
|
+
await keys.set({ session: { [id]: session.serialize() } });
|
|
121
96
|
},
|
|
122
97
|
isTrustedIdentity: () => {
|
|
123
98
|
return true;
|
|
@@ -140,22 +115,27 @@ function signalStorage({ creds, keys }) {
|
|
|
140
115
|
pubKey: Buffer.from(key.keyPair.public)
|
|
141
116
|
};
|
|
142
117
|
},
|
|
143
|
-
loadSenderKey: async (
|
|
118
|
+
loadSenderKey: async (senderKeyName) => {
|
|
119
|
+
const keyId = senderKeyName.toString();
|
|
144
120
|
const { [keyId]: key } = await keys.get('sender-key', [keyId]);
|
|
145
121
|
if (key) {
|
|
146
|
-
return
|
|
122
|
+
return SenderKeyRecord.deserialize(key);
|
|
147
123
|
}
|
|
124
|
+
return new SenderKeyRecord();
|
|
148
125
|
},
|
|
149
|
-
storeSenderKey: async (
|
|
150
|
-
|
|
126
|
+
storeSenderKey: async (senderKeyName, key) => {
|
|
127
|
+
const keyId = senderKeyName.toString();
|
|
128
|
+
const serialized = JSON.stringify(key.serialize());
|
|
129
|
+
await keys.set({ 'sender-key': { [keyId]: Buffer.from(serialized, 'utf-8') } });
|
|
151
130
|
},
|
|
152
|
-
getOurRegistrationId: () =>
|
|
131
|
+
getOurRegistrationId: () => creds.registrationId,
|
|
153
132
|
getOurIdentity: () => {
|
|
154
133
|
const { signedIdentityKey } = creds;
|
|
155
134
|
return {
|
|
156
135
|
privKey: Buffer.from(signedIdentityKey.private),
|
|
157
|
-
pubKey:
|
|
136
|
+
pubKey: generateSignalPubKey(signedIdentityKey.public)
|
|
158
137
|
};
|
|
159
138
|
}
|
|
160
139
|
};
|
|
161
140
|
}
|
|
141
|
+
//# sourceMappingURL=libsignal.js.map
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./abstract-socket-client"), exports);
|
|
18
|
-
__exportStar(require("./mobile-socket-client"), exports);
|
|
19
|
-
__exportStar(require("./web-socket-client"), exports);
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './websocket.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { URL } from 'url';
|
|
3
|
+
export class AbstractSocketClient extends EventEmitter {
|
|
4
|
+
constructor(url, config) {
|
|
5
|
+
super();
|
|
6
|
+
this.url = url;
|
|
7
|
+
this.config = config;
|
|
8
|
+
this.setMaxListeners(0);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import WebSocket from 'ws';
|
|
2
|
+
import { DEFAULT_ORIGIN } from '../../Defaults/index.js';
|
|
3
|
+
import { AbstractSocketClient } from './types.js';
|
|
4
|
+
export class WebSocketClient extends AbstractSocketClient {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.socket = null;
|
|
8
|
+
}
|
|
9
|
+
get isOpen() {
|
|
10
|
+
return this.socket?.readyState === WebSocket.OPEN;
|
|
11
|
+
}
|
|
12
|
+
get isClosed() {
|
|
13
|
+
return this.socket === null || this.socket?.readyState === WebSocket.CLOSED;
|
|
14
|
+
}
|
|
15
|
+
get isClosing() {
|
|
16
|
+
return this.socket === null || this.socket?.readyState === WebSocket.CLOSING;
|
|
17
|
+
}
|
|
18
|
+
get isConnecting() {
|
|
19
|
+
return this.socket?.readyState === WebSocket.CONNECTING;
|
|
20
|
+
}
|
|
21
|
+
async connect() {
|
|
22
|
+
if (this.socket) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.socket = new WebSocket(this.url, {
|
|
26
|
+
origin: DEFAULT_ORIGIN,
|
|
27
|
+
headers: this.config.options?.headers,
|
|
28
|
+
handshakeTimeout: this.config.connectTimeoutMs,
|
|
29
|
+
timeout: this.config.connectTimeoutMs,
|
|
30
|
+
agent: this.config.agent
|
|
31
|
+
});
|
|
32
|
+
this.socket.setMaxListeners(0);
|
|
33
|
+
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
|
34
|
+
for (const event of events) {
|
|
35
|
+
this.socket?.on(event, (...args) => this.emit(event, ...args));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async close() {
|
|
39
|
+
if (!this.socket) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this.socket.close();
|
|
43
|
+
this.socket = null;
|
|
44
|
+
}
|
|
45
|
+
send(str, cb) {
|
|
46
|
+
this.socket?.send(str, cb);
|
|
47
|
+
return Boolean(this.socket);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=websocket.js.map
|
package/lib/Socket/business.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const messages_recv_1 = require("./messages-recv");
|
|
8
|
-
const makeBusinessSocket = (config) => {
|
|
9
|
-
const sock = (0, messages_recv_1.makeMessagesRecvSocket)(config);
|
|
1
|
+
import { parseCatalogNode, parseCollectionsNode, parseOrderDetailsNode, parseProductNode, toProductNode, uploadingNecessaryImagesOfProduct } from '../Utils/business.js';
|
|
2
|
+
import { jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
3
|
+
import { getBinaryNodeChild } from '../WABinary/generic-utils.js';
|
|
4
|
+
import { makeMessagesRecvSocket } from './messages-recv.js';
|
|
5
|
+
export const makeBusinessSocket = (config) => {
|
|
6
|
+
const sock = makeMessagesRecvSocket(config);
|
|
10
7
|
const { authState, query, waUploadToServer } = sock;
|
|
11
8
|
const getCatalog = async ({ jid, limit, cursor }) => {
|
|
12
|
-
|
|
13
|
-
jid = jid
|
|
14
|
-
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
9
|
+
jid = jid || authState.creds.me?.id;
|
|
10
|
+
jid = jidNormalizedUser(jid);
|
|
15
11
|
const queryParamNodes = [
|
|
16
12
|
{
|
|
17
13
|
tag: 'limit',
|
|
@@ -27,7 +23,7 @@ const makeBusinessSocket = (config) => {
|
|
|
27
23
|
tag: 'height',
|
|
28
24
|
attrs: {},
|
|
29
25
|
content: Buffer.from('100')
|
|
30
|
-
}
|
|
26
|
+
}
|
|
31
27
|
];
|
|
32
28
|
if (cursor) {
|
|
33
29
|
queryParamNodes.push({
|
|
@@ -39,7 +35,7 @@ const makeBusinessSocket = (config) => {
|
|
|
39
35
|
const result = await query({
|
|
40
36
|
tag: 'iq',
|
|
41
37
|
attrs: {
|
|
42
|
-
to:
|
|
38
|
+
to: S_WHATSAPP_NET,
|
|
43
39
|
type: 'get',
|
|
44
40
|
xmlns: 'w:biz:catalog'
|
|
45
41
|
},
|
|
@@ -48,31 +44,30 @@ const makeBusinessSocket = (config) => {
|
|
|
48
44
|
tag: 'product_catalog',
|
|
49
45
|
attrs: {
|
|
50
46
|
jid,
|
|
51
|
-
|
|
47
|
+
allow_shop_source: 'true'
|
|
52
48
|
},
|
|
53
49
|
content: queryParamNodes
|
|
54
50
|
}
|
|
55
51
|
]
|
|
56
52
|
});
|
|
57
|
-
return
|
|
53
|
+
return parseCatalogNode(result);
|
|
58
54
|
};
|
|
59
55
|
const getCollections = async (jid, limit = 51) => {
|
|
60
|
-
|
|
61
|
-
jid = jid
|
|
62
|
-
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
56
|
+
jid = jid || authState.creds.me?.id;
|
|
57
|
+
jid = jidNormalizedUser(jid);
|
|
63
58
|
const result = await query({
|
|
64
59
|
tag: 'iq',
|
|
65
60
|
attrs: {
|
|
66
|
-
to:
|
|
61
|
+
to: S_WHATSAPP_NET,
|
|
67
62
|
type: 'get',
|
|
68
63
|
xmlns: 'w:biz:catalog',
|
|
69
|
-
|
|
64
|
+
smax_id: '35'
|
|
70
65
|
},
|
|
71
66
|
content: [
|
|
72
67
|
{
|
|
73
68
|
tag: 'collections',
|
|
74
69
|
attrs: {
|
|
75
|
-
|
|
70
|
+
biz_jid: jid
|
|
76
71
|
},
|
|
77
72
|
content: [
|
|
78
73
|
{
|
|
@@ -99,16 +94,16 @@ const makeBusinessSocket = (config) => {
|
|
|
99
94
|
}
|
|
100
95
|
]
|
|
101
96
|
});
|
|
102
|
-
return
|
|
97
|
+
return parseCollectionsNode(result);
|
|
103
98
|
};
|
|
104
99
|
const getOrderDetails = async (orderId, tokenBase64) => {
|
|
105
100
|
const result = await query({
|
|
106
101
|
tag: 'iq',
|
|
107
102
|
attrs: {
|
|
108
|
-
to:
|
|
103
|
+
to: S_WHATSAPP_NET,
|
|
109
104
|
type: 'get',
|
|
110
105
|
xmlns: 'fb:thrift_iq',
|
|
111
|
-
|
|
106
|
+
smax_id: '5'
|
|
112
107
|
},
|
|
113
108
|
content: [
|
|
114
109
|
{
|
|
@@ -143,15 +138,15 @@ const makeBusinessSocket = (config) => {
|
|
|
143
138
|
}
|
|
144
139
|
]
|
|
145
140
|
});
|
|
146
|
-
return
|
|
141
|
+
return parseOrderDetailsNode(result);
|
|
147
142
|
};
|
|
148
143
|
const productUpdate = async (productId, update) => {
|
|
149
|
-
update = await
|
|
150
|
-
const editNode =
|
|
144
|
+
update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer);
|
|
145
|
+
const editNode = toProductNode(productId, update);
|
|
151
146
|
const result = await query({
|
|
152
147
|
tag: 'iq',
|
|
153
148
|
attrs: {
|
|
154
|
-
to:
|
|
149
|
+
to: S_WHATSAPP_NET,
|
|
155
150
|
type: 'set',
|
|
156
151
|
xmlns: 'w:biz:catalog'
|
|
157
152
|
},
|
|
@@ -175,19 +170,19 @@ const makeBusinessSocket = (config) => {
|
|
|
175
170
|
}
|
|
176
171
|
]
|
|
177
172
|
});
|
|
178
|
-
const productCatalogEditNode =
|
|
179
|
-
const productNode =
|
|
180
|
-
return
|
|
173
|
+
const productCatalogEditNode = getBinaryNodeChild(result, 'product_catalog_edit');
|
|
174
|
+
const productNode = getBinaryNodeChild(productCatalogEditNode, 'product');
|
|
175
|
+
return parseProductNode(productNode);
|
|
181
176
|
};
|
|
182
177
|
const productCreate = async (create) => {
|
|
183
178
|
// ensure isHidden is defined
|
|
184
179
|
create.isHidden = !!create.isHidden;
|
|
185
|
-
create = await
|
|
186
|
-
const createNode =
|
|
180
|
+
create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
|
|
181
|
+
const createNode = toProductNode(undefined, create);
|
|
187
182
|
const result = await query({
|
|
188
183
|
tag: 'iq',
|
|
189
184
|
attrs: {
|
|
190
|
-
to:
|
|
185
|
+
to: S_WHATSAPP_NET,
|
|
191
186
|
type: 'set',
|
|
192
187
|
xmlns: 'w:biz:catalog'
|
|
193
188
|
},
|
|
@@ -211,15 +206,15 @@ const makeBusinessSocket = (config) => {
|
|
|
211
206
|
}
|
|
212
207
|
]
|
|
213
208
|
});
|
|
214
|
-
const productCatalogAddNode =
|
|
215
|
-
const productNode =
|
|
216
|
-
return
|
|
209
|
+
const productCatalogAddNode = getBinaryNodeChild(result, 'product_catalog_add');
|
|
210
|
+
const productNode = getBinaryNodeChild(productCatalogAddNode, 'product');
|
|
211
|
+
return parseProductNode(productNode);
|
|
217
212
|
};
|
|
218
213
|
const productDelete = async (productIds) => {
|
|
219
214
|
const result = await query({
|
|
220
215
|
tag: 'iq',
|
|
221
216
|
attrs: {
|
|
222
|
-
to:
|
|
217
|
+
to: S_WHATSAPP_NET,
|
|
223
218
|
type: 'set',
|
|
224
219
|
xmlns: 'w:biz:catalog'
|
|
225
220
|
},
|
|
@@ -241,9 +236,9 @@ const makeBusinessSocket = (config) => {
|
|
|
241
236
|
}
|
|
242
237
|
]
|
|
243
238
|
});
|
|
244
|
-
const productCatalogDelNode =
|
|
239
|
+
const productCatalogDelNode = getBinaryNodeChild(result, 'product_catalog_delete');
|
|
245
240
|
return {
|
|
246
|
-
deleted: +(
|
|
241
|
+
deleted: +(productCatalogDelNode?.attrs.deleted_count || 0)
|
|
247
242
|
};
|
|
248
243
|
};
|
|
249
244
|
return {
|
|
@@ -257,4 +252,4 @@ const makeBusinessSocket = (config) => {
|
|
|
257
252
|
productUpdate
|
|
258
253
|
};
|
|
259
254
|
};
|
|
260
|
-
|
|
255
|
+
//# sourceMappingURL=business.js.map
|