@heavstaltech/baileys 2.3.4 → 3.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +226 -53
- package/WAProto/index.js +14270 -302
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +118 -79
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
- package/lib/Signal/libsignal.js +51 -29
- package/lib/Socket/business.d.ts +43 -42
- package/lib/Socket/chats.d.ts +222 -36
- package/lib/Socket/chats.js +186 -153
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +7 -7
- package/lib/Socket/groups.js +37 -35
- package/lib/Socket/index.d.ts +52 -51
- package/lib/Socket/index.js +1 -0
- package/lib/Socket/messages-recv.d.ts +37 -34
- package/lib/Socket/messages-recv.js +175 -37
- package/lib/Socket/messages-send.d.ts +12 -18
- package/lib/Socket/messages-send.js +396 -574
- package/lib/Socket/newsletter.d.ts +28 -26
- package/lib/Socket/newsletter.js +140 -25
- package/lib/Socket/registration.d.ts +52 -49
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.d.ts +0 -1
- package/lib/Socket/socket.js +47 -198
- package/lib/Socket/usync.d.ts +10 -11
- package/lib/Store/make-cache-manager-store.d.ts +1 -2
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Store/make-in-memory-store.js +1 -5
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -12
- package/lib/Types/Events.d.ts +2 -17
- package/lib/Types/GroupMetadata.d.ts +2 -3
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +10 -170
- package/lib/Types/Newsletter.d.ts +97 -86
- package/lib/Types/Newsletter.js +38 -32
- package/lib/Types/Socket.d.ts +2 -7
- package/lib/Types/index.d.ts +0 -9
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +14 -35
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +12 -11
- package/lib/Utils/chat-utils.js +36 -52
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +26 -74
- package/lib/Utils/decode-wa-message.d.ts +0 -17
- package/lib/Utils/decode-wa-message.js +17 -53
- package/lib/Utils/event-buffer.js +7 -10
- package/lib/Utils/generics.d.ts +17 -13
- package/lib/Utils/generics.js +79 -58
- package/lib/Utils/history.d.ts +2 -6
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/logger.d.ts +3 -1
- package/lib/Utils/lt-hash.js +12 -12
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +28 -25
- package/lib/Utils/messages-media.js +201 -103
- package/lib/Utils/messages.js +36 -473
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/noise-handler.js +14 -19
- package/lib/Utils/process-message.d.ts +5 -5
- package/lib/Utils/process-message.js +23 -75
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +26 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +66 -242
- package/lib/Utils/validate-connection.d.ts +1 -1
- package/lib/Utils/validate-connection.js +88 -64
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.js +11 -23
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +147 -134
- package/lib/WABinary/generic-utils.d.ts +5 -2
- package/lib/WABinary/generic-utils.js +125 -37
- package/lib/WABinary/jid-utils.d.ts +1 -1
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +12 -0
- package/package.json +102 -98
- package/WAProto/index.d.ts +0 -50383
- 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/Utils/use-single-file-auth-state.d.ts +0 -12
- package/lib/Utils/use-single-file-auth-state.js +0 -75
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
const SenderChainKey = require('./sender_chain_key');
|
|
2
|
-
const SenderMessageKey = require('./sender_message_key');
|
|
3
|
-
|
|
4
|
-
const protobufs = require('./protobufs');
|
|
5
|
-
|
|
6
|
-
class SenderKeyState {
|
|
7
|
-
MAX_MESSAGE_KEYS = 2000;
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
id = null,
|
|
11
|
-
iteration = null,
|
|
12
|
-
chainKey = null,
|
|
13
|
-
signatureKeyPair = null,
|
|
14
|
-
signatureKeyPublic = null,
|
|
15
|
-
signatureKeyPrivate = null,
|
|
16
|
-
senderKeyStateStructure = null
|
|
17
|
-
) {
|
|
18
|
-
if (senderKeyStateStructure) {
|
|
19
|
-
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
20
|
-
} else {
|
|
21
|
-
if (signatureKeyPair) {
|
|
22
|
-
signatureKeyPublic = signatureKeyPair.public;
|
|
23
|
-
signatureKeyPrivate = signatureKeyPair.private;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
|
|
27
|
-
this.senderKeyStateStructure = protobufs.SenderKeyStateStructure.create();
|
|
28
|
-
const senderChainKeyStructure = protobufs.SenderChainKey.create();
|
|
29
|
-
senderChainKeyStructure.iteration = iteration;
|
|
30
|
-
senderChainKeyStructure.seed = chainKey;
|
|
31
|
-
this.senderKeyStateStructure.senderChainKey = senderChainKeyStructure;
|
|
32
|
-
|
|
33
|
-
const signingKeyStructure = protobufs.SenderSigningKey.create();
|
|
34
|
-
signingKeyStructure.public =
|
|
35
|
-
typeof signatureKeyPublic === 'string' ?
|
|
36
|
-
Buffer.from(signatureKeyPublic, 'base64') :
|
|
37
|
-
signatureKeyPublic;
|
|
38
|
-
if (signatureKeyPrivate) {
|
|
39
|
-
signingKeyStructure.private =
|
|
40
|
-
typeof signatureKeyPrivate === 'string' ?
|
|
41
|
-
Buffer.from(signatureKeyPrivate, 'base64') :
|
|
42
|
-
signatureKeyPrivate;
|
|
43
|
-
}
|
|
44
|
-
this.senderKeyStateStructure.senderKeyId = id;
|
|
45
|
-
this.senderChainKey = senderChainKeyStructure;
|
|
46
|
-
this.senderKeyStateStructure.senderSigningKey = signingKeyStructure;
|
|
47
|
-
}
|
|
48
|
-
this.senderKeyStateStructure.senderMessageKeys =
|
|
49
|
-
this.senderKeyStateStructure.senderMessageKeys || [];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
SenderKeyState(senderKeyStateStructure) {
|
|
53
|
-
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
getKeyId() {
|
|
57
|
-
return this.senderKeyStateStructure.senderKeyId;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
getSenderChainKey() {
|
|
61
|
-
return new SenderChainKey(
|
|
62
|
-
this.senderKeyStateStructure.senderChainKey.iteration,
|
|
63
|
-
this.senderKeyStateStructure.senderChainKey.seed
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setSenderChainKey(chainKey) {
|
|
68
|
-
const senderChainKeyStructure = protobufs.SenderChainKey.create({
|
|
69
|
-
iteration: chainKey.getIteration(),
|
|
70
|
-
seed: chainKey.getSeed(),
|
|
71
|
-
});
|
|
72
|
-
this.senderKeyStateStructure.senderChainKey = senderChainKeyStructure;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
getSigningKeyPublic() {
|
|
76
|
-
return typeof this.senderKeyStateStructure.senderSigningKey.public === 'string' ?
|
|
77
|
-
Buffer.from(this.senderKeyStateStructure.senderSigningKey.public, 'base64') :
|
|
78
|
-
this.senderKeyStateStructure.senderSigningKey.public;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
getSigningKeyPrivate() {
|
|
82
|
-
return typeof this.senderKeyStateStructure.senderSigningKey.private === 'string' ?
|
|
83
|
-
Buffer.from(this.senderKeyStateStructure.senderSigningKey.private, 'base64') :
|
|
84
|
-
this.senderKeyStateStructure.senderSigningKey.private;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
hasSenderMessageKey(iteration) {
|
|
88
|
-
const list = this.senderKeyStateStructure.senderMessageKeys;
|
|
89
|
-
for (let o = 0; o < list.length; o++) {
|
|
90
|
-
const senderMessageKey = list[o];
|
|
91
|
-
if (senderMessageKey.iteration === iteration) return true;
|
|
92
|
-
}
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
addSenderMessageKey(senderMessageKey) {
|
|
97
|
-
const senderMessageKeyStructure = protobufs.SenderKeyStateStructure.create({
|
|
98
|
-
iteration: senderMessageKey.getIteration(),
|
|
99
|
-
seed: senderMessageKey.getSeed(),
|
|
100
|
-
});
|
|
101
|
-
this.senderKeyStateStructure.senderMessageKeys.push(senderMessageKeyStructure);
|
|
102
|
-
|
|
103
|
-
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
104
|
-
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
removeSenderMessageKey(iteration) {
|
|
109
|
-
let result = null;
|
|
110
|
-
|
|
111
|
-
this.senderKeyStateStructure.senderMessageKeys = this.senderKeyStateStructure.senderMessageKeys.filter(
|
|
112
|
-
senderMessageKey => {
|
|
113
|
-
if (senderMessageKey.iteration === iteration) result = senderMessageKey;
|
|
114
|
-
return senderMessageKey.iteration !== iteration;
|
|
115
|
-
}
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
if (result != null) {
|
|
119
|
-
return new SenderMessageKey(result.iteration, result.seed);
|
|
120
|
-
}
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
getStructure() {
|
|
125
|
-
return this.senderKeyStateStructure;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
module.exports = SenderKeyState;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Logger } from 'pino';
|
|
2
|
-
import type { AuthenticationState } from '../Types';
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated use multi file auth state instead please
|
|
5
|
-
* stores the full authentication state in a single JSON file
|
|
6
|
-
*
|
|
7
|
-
* DO NOT USE IN A PROD ENVIRONMENT, only meant to serve as an example
|
|
8
|
-
* */
|
|
9
|
-
export declare const useSingleFileAuthState: (filename: string, logger?: Logger) => {
|
|
10
|
-
state: AuthenticationState;
|
|
11
|
-
saveState: () => void;
|
|
12
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useSingleFileAuthState = void 0;
|
|
4
|
-
const WAProto_1 = require("../../WAProto");
|
|
5
|
-
const auth_utils_1 = require("./auth-utils");
|
|
6
|
-
const generics_1 = require("./generics");
|
|
7
|
-
// useless key map only there to maintain backwards compatibility
|
|
8
|
-
// do not use in your own systems please
|
|
9
|
-
const KEY_MAP = {
|
|
10
|
-
'pre-key': 'preKeys',
|
|
11
|
-
'session': 'sessions',
|
|
12
|
-
'sender-key': 'senderKeys',
|
|
13
|
-
'app-state-sync-key': 'appStateSyncKeys',
|
|
14
|
-
'app-state-sync-version': 'appStateVersions',
|
|
15
|
-
'sender-key-memory': 'senderKeyMemory'
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* @deprecated use multi file auth state instead please
|
|
19
|
-
* stores the full authentication state in a single JSON file
|
|
20
|
-
*
|
|
21
|
-
* DO NOT USE IN A PROD ENVIRONMENT, only meant to serve as an example
|
|
22
|
-
* */
|
|
23
|
-
const useSingleFileAuthState = (filename, logger) => {
|
|
24
|
-
// require fs here so that in case "fs" is not available -- the app does not crash
|
|
25
|
-
const { readFileSync, writeFileSync, existsSync } = require('fs');
|
|
26
|
-
let creds;
|
|
27
|
-
let keys = {};
|
|
28
|
-
// save the authentication state to a file
|
|
29
|
-
const saveState = () => {
|
|
30
|
-
logger && logger.trace('saving auth state');
|
|
31
|
-
writeFileSync(filename,
|
|
32
|
-
// BufferJSON replacer utility saves buffers nicely
|
|
33
|
-
JSON.stringify({ creds, keys }, generics_1.BufferJSON.replacer, 2));
|
|
34
|
-
};
|
|
35
|
-
if (existsSync(filename)) {
|
|
36
|
-
const result = JSON.parse(readFileSync(filename, { encoding: 'utf-8' }), generics_1.BufferJSON.reviver);
|
|
37
|
-
creds = result.creds;
|
|
38
|
-
keys = result.keys;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
creds = (0, auth_utils_1.initAuthCreds)();
|
|
42
|
-
keys = {};
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
state: {
|
|
46
|
-
creds,
|
|
47
|
-
keys: {
|
|
48
|
-
get: (type, ids) => {
|
|
49
|
-
const key = KEY_MAP[type];
|
|
50
|
-
return ids.reduce((dict, id) => {
|
|
51
|
-
var _a;
|
|
52
|
-
let value = (_a = keys[key]) === null || _a === void 0 ? void 0 : _a[id];
|
|
53
|
-
if (value) {
|
|
54
|
-
if (type === 'app-state-sync-key') {
|
|
55
|
-
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
56
|
-
}
|
|
57
|
-
dict[id] = value;
|
|
58
|
-
}
|
|
59
|
-
return dict;
|
|
60
|
-
}, {});
|
|
61
|
-
},
|
|
62
|
-
set: (data) => {
|
|
63
|
-
for (const _key in data) {
|
|
64
|
-
const key = KEY_MAP[_key];
|
|
65
|
-
keys[key] = keys[key] || {};
|
|
66
|
-
Object.assign(keys[key], data[_key]);
|
|
67
|
-
}
|
|
68
|
-
saveState();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
saveState
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
exports.useSingleFileAuthState = useSingleFileAuthState;
|