@d0v3riz/baileys 6.3.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/README.md +956 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +2845 -0
- package/WAProto/index.d.ts +32006 -0
- package/WAProto/index.js +87184 -0
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +106 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/readme.md +6 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +54 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/WASignalGroup/sender_message_key.js +39 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +284 -0
- package/lib/Defaults/index.js +115 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +151 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +16 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +19 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +124 -0
- package/lib/Socket/business.js +259 -0
- package/lib/Socket/chats.d.ts +74 -0
- package/lib/Socket/chats.js +838 -0
- package/lib/Socket/groups.d.ts +105 -0
- package/lib/Socket/groups.js +291 -0
- package/lib/Socket/index.d.ts +126 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.d.ts +112 -0
- package/lib/Socket/messages-recv.js +641 -0
- package/lib/Socket/messages-send.d.ts +110 -0
- package/lib/Socket/messages-send.js +648 -0
- package/lib/Socket/registration.d.ts +211 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +42 -0
- package/lib/Socket/socket.js +527 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +117 -0
- package/lib/Store/make-in-memory-store.js +435 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +106 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.d.ts +12 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +102 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.d.ts +18 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +152 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +42 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.d.ts +245 -0
- package/lib/Types/Message.js +9 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +106 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/index.d.ts +54 -0
- package/lib/Types/index.js +39 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +202 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/chat-utils.js +710 -0
- package/lib/Utils/crypto.d.ts +38 -0
- package/lib/Utils/crypto.js +137 -0
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/decode-wa-message.js +160 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +514 -0
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +368 -0
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/history.js +91 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +33 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +116 -0
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/messages-media.d.ts +101 -0
- package/lib/Utils/messages-media.js +632 -0
- package/lib/Utils/messages.d.ts +75 -0
- package/lib/Utils/messages.js +738 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +142 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +297 -0
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/signal.js +151 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-multi-file-auth-state.js +80 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +188 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/constants.js +40 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +252 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +228 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +110 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.d.ts +27 -0
- package/lib/WABinary/jid-utils.js +56 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +27 -0
- package/package.json +100 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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 __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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.makeLibSignalRepository = void 0;
|
|
27
|
+
const libsignal = __importStar(require("libsignal"));
|
|
28
|
+
const WASignalGroup_1 = require("../../WASignalGroup");
|
|
29
|
+
const Utils_1 = require("../Utils");
|
|
30
|
+
function makeLibSignalRepository(auth) {
|
|
31
|
+
const storage = signalStorage(auth);
|
|
32
|
+
return {
|
|
33
|
+
decryptGroupMessage({ group, authorJid, msg }) {
|
|
34
|
+
const senderName = jidToSignalSenderKeyName(group, authorJid);
|
|
35
|
+
const cipher = new WASignalGroup_1.GroupCipher(storage, senderName);
|
|
36
|
+
return cipher.decrypt(msg);
|
|
37
|
+
},
|
|
38
|
+
async processSenderKeyDistributionMessage({ item, authorJid }) {
|
|
39
|
+
const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
|
|
40
|
+
const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
|
|
41
|
+
const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
|
|
42
|
+
const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
|
|
43
|
+
if (!senderKey) {
|
|
44
|
+
await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
|
|
45
|
+
}
|
|
46
|
+
await builder.process(senderName, senderMsg);
|
|
47
|
+
},
|
|
48
|
+
async decryptMessage({ jid, type, ciphertext }) {
|
|
49
|
+
const addr = jidToSignalProtocolAddress(jid);
|
|
50
|
+
const session = new libsignal.SessionCipher(storage, addr);
|
|
51
|
+
let result;
|
|
52
|
+
switch (type) {
|
|
53
|
+
case 'pkmsg':
|
|
54
|
+
result = await session.decryptPreKeyWhisperMessage(ciphertext);
|
|
55
|
+
break;
|
|
56
|
+
case 'msg':
|
|
57
|
+
result = await session.decryptWhisperMessage(ciphertext);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
},
|
|
62
|
+
async encryptMessage({ jid, data }) {
|
|
63
|
+
const addr = jidToSignalProtocolAddress(jid);
|
|
64
|
+
const cipher = new libsignal.SessionCipher(storage, addr);
|
|
65
|
+
const { type: sigType, body } = await cipher.encrypt(data);
|
|
66
|
+
const type = sigType === 3 ? 'pkmsg' : 'msg';
|
|
67
|
+
return { type, ciphertext: Buffer.from(body, 'binary') };
|
|
68
|
+
},
|
|
69
|
+
async encryptGroupMessage({ group, meId, data }) {
|
|
70
|
+
const senderName = jidToSignalSenderKeyName(group, meId);
|
|
71
|
+
const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
|
|
72
|
+
const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
|
|
73
|
+
if (!senderKey) {
|
|
74
|
+
await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
|
|
75
|
+
}
|
|
76
|
+
const senderKeyDistributionMessage = await builder.create(senderName);
|
|
77
|
+
const session = new WASignalGroup_1.GroupCipher(storage, senderName);
|
|
78
|
+
const ciphertext = await session.encrypt(data);
|
|
79
|
+
return {
|
|
80
|
+
ciphertext,
|
|
81
|
+
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
async injectE2ESession({ jid, session }) {
|
|
85
|
+
const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid));
|
|
86
|
+
await cipher.initOutgoing(session);
|
|
87
|
+
},
|
|
88
|
+
jidToSignalProtocolAddress(jid) {
|
|
89
|
+
return jidToSignalProtocolAddress(jid).toString();
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
exports.makeLibSignalRepository = makeLibSignalRepository;
|
|
94
|
+
const jidToSignalAddress = (jid) => jid.split('@')[0];
|
|
95
|
+
const jidToSignalProtocolAddress = (jid) => {
|
|
96
|
+
return new libsignal.ProtocolAddress(jidToSignalAddress(jid), 0);
|
|
97
|
+
};
|
|
98
|
+
const jidToSignalSenderKeyName = (group, user) => {
|
|
99
|
+
return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString();
|
|
100
|
+
};
|
|
101
|
+
function signalStorage({ creds, keys }) {
|
|
102
|
+
return {
|
|
103
|
+
loadSession: async (id) => {
|
|
104
|
+
const { [id]: sess } = await keys.get('session', [id]);
|
|
105
|
+
if (sess) {
|
|
106
|
+
return libsignal.SessionRecord.deserialize(sess);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
storeSession: async (id, session) => {
|
|
110
|
+
await keys.set({ 'session': { [id]: session.serialize() } });
|
|
111
|
+
},
|
|
112
|
+
isTrustedIdentity: () => {
|
|
113
|
+
return true;
|
|
114
|
+
},
|
|
115
|
+
loadPreKey: async (id) => {
|
|
116
|
+
const keyId = id.toString();
|
|
117
|
+
const { [keyId]: key } = await keys.get('pre-key', [keyId]);
|
|
118
|
+
if (key) {
|
|
119
|
+
return {
|
|
120
|
+
privKey: Buffer.from(key.private),
|
|
121
|
+
pubKey: Buffer.from(key.public)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
removePreKey: (id) => keys.set({ 'pre-key': { [id]: null } }),
|
|
126
|
+
loadSignedPreKey: () => {
|
|
127
|
+
const key = creds.signedPreKey;
|
|
128
|
+
return {
|
|
129
|
+
privKey: Buffer.from(key.keyPair.private),
|
|
130
|
+
pubKey: Buffer.from(key.keyPair.public)
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
loadSenderKey: async (keyId) => {
|
|
134
|
+
const { [keyId]: key } = await keys.get('sender-key', [keyId]);
|
|
135
|
+
if (key) {
|
|
136
|
+
return new WASignalGroup_1.SenderKeyRecord(key);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
storeSenderKey: async (keyId, key) => {
|
|
140
|
+
await keys.set({ 'sender-key': { [keyId]: key.serialize() } });
|
|
141
|
+
},
|
|
142
|
+
getOurRegistrationId: () => (creds.registrationId),
|
|
143
|
+
getOurIdentity: () => {
|
|
144
|
+
const { signedIdentityKey } = creds;
|
|
145
|
+
return {
|
|
146
|
+
privKey: Buffer.from(signedIdentityKey.private),
|
|
147
|
+
pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { URL } from 'url';
|
|
4
|
+
import { SocketConfig } from '../../Types';
|
|
5
|
+
export declare abstract class AbstractSocketClient extends EventEmitter {
|
|
6
|
+
url: URL;
|
|
7
|
+
config: SocketConfig;
|
|
8
|
+
abstract get isOpen(): boolean;
|
|
9
|
+
abstract get isClosed(): boolean;
|
|
10
|
+
abstract get isClosing(): boolean;
|
|
11
|
+
abstract get isConnecting(): boolean;
|
|
12
|
+
constructor(url: URL, config: SocketConfig);
|
|
13
|
+
abstract connect(): Promise<void>;
|
|
14
|
+
abstract close(): Promise<void>;
|
|
15
|
+
abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractSocketClient = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
class AbstractSocketClient extends events_1.EventEmitter {
|
|
6
|
+
constructor(url, config) {
|
|
7
|
+
super();
|
|
8
|
+
this.url = url;
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.setMaxListeners(0);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.AbstractSocketClient = AbstractSocketClient;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Socket } from 'net';
|
|
3
|
+
import { AbstractSocketClient } from './abstract-socket-client';
|
|
4
|
+
export declare class MobileSocketClient extends AbstractSocketClient {
|
|
5
|
+
protected socket: Socket | null;
|
|
6
|
+
get isOpen(): boolean;
|
|
7
|
+
get isClosed(): boolean;
|
|
8
|
+
get isClosing(): boolean;
|
|
9
|
+
get isConnecting(): boolean;
|
|
10
|
+
connect(): Promise<void>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MobileSocketClient = void 0;
|
|
4
|
+
const net_1 = require("net");
|
|
5
|
+
const abstract_socket_client_1 = require("./abstract-socket-client");
|
|
6
|
+
class MobileSocketClient extends abstract_socket_client_1.AbstractSocketClient {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.socket = null;
|
|
10
|
+
}
|
|
11
|
+
get isOpen() {
|
|
12
|
+
var _a;
|
|
13
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'open';
|
|
14
|
+
}
|
|
15
|
+
get isClosed() {
|
|
16
|
+
var _a;
|
|
17
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
|
|
18
|
+
}
|
|
19
|
+
get isClosing() {
|
|
20
|
+
var _a;
|
|
21
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
|
|
22
|
+
}
|
|
23
|
+
get isConnecting() {
|
|
24
|
+
var _a;
|
|
25
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'opening';
|
|
26
|
+
}
|
|
27
|
+
async connect() {
|
|
28
|
+
var _a;
|
|
29
|
+
if (this.socket) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (this.config.agent) {
|
|
33
|
+
throw new Error('There are not support for proxy agent for mobile connection');
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.socket = (0, net_1.connect)({
|
|
37
|
+
host: this.url.hostname,
|
|
38
|
+
port: Number(this.url.port) || 443
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
this.socket.setMaxListeners(0);
|
|
42
|
+
const events = ['close', 'connect', 'data', 'drain', 'end', 'error', 'lookup', 'ready', 'timeout'];
|
|
43
|
+
for (const event of events) {
|
|
44
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.on(event, (...args) => this.emit(event, ...args));
|
|
45
|
+
}
|
|
46
|
+
this.socket.on('data', (...args) => this.emit('message', ...args));
|
|
47
|
+
this.socket.on('ready', (...args) => this.emit('open', ...args));
|
|
48
|
+
}
|
|
49
|
+
async close() {
|
|
50
|
+
if (!this.socket) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
return new Promise(resolve => {
|
|
54
|
+
this.socket.end(resolve);
|
|
55
|
+
this.socket = null;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
send(str, cb) {
|
|
59
|
+
if (this.socket === null) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return this.socket.write(str, undefined, cb);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.MobileSocketClient = MobileSocketClient;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import WebSocket from 'ws';
|
|
2
|
+
import { AbstractSocketClient } from './abstract-socket-client';
|
|
3
|
+
export declare class WebSocketClient extends AbstractSocketClient {
|
|
4
|
+
protected socket: WebSocket | null;
|
|
5
|
+
get isOpen(): boolean;
|
|
6
|
+
get isClosed(): boolean;
|
|
7
|
+
get isClosing(): boolean;
|
|
8
|
+
get isConnecting(): boolean;
|
|
9
|
+
connect(): Promise<void>;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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.WebSocketClient = void 0;
|
|
7
|
+
const ws_1 = __importDefault(require("ws"));
|
|
8
|
+
const Defaults_1 = require("../../Defaults");
|
|
9
|
+
const abstract_socket_client_1 = require("./abstract-socket-client");
|
|
10
|
+
class WebSocketClient extends abstract_socket_client_1.AbstractSocketClient {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.socket = null;
|
|
14
|
+
}
|
|
15
|
+
get isOpen() {
|
|
16
|
+
var _a;
|
|
17
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN;
|
|
18
|
+
}
|
|
19
|
+
get isClosed() {
|
|
20
|
+
var _a;
|
|
21
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSED;
|
|
22
|
+
}
|
|
23
|
+
get isClosing() {
|
|
24
|
+
var _a;
|
|
25
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING;
|
|
26
|
+
}
|
|
27
|
+
get isConnecting() {
|
|
28
|
+
var _a;
|
|
29
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CONNECTING;
|
|
30
|
+
}
|
|
31
|
+
async connect() {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
if (this.socket) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.socket = new ws_1.default(this.url, {
|
|
37
|
+
origin: Defaults_1.DEFAULT_ORIGIN,
|
|
38
|
+
headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
|
|
39
|
+
handshakeTimeout: this.config.connectTimeoutMs,
|
|
40
|
+
timeout: this.config.connectTimeoutMs,
|
|
41
|
+
agent: this.config.agent,
|
|
42
|
+
});
|
|
43
|
+
this.socket.setMaxListeners(0);
|
|
44
|
+
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
|
45
|
+
for (const event of events) {
|
|
46
|
+
(_b = this.socket) === null || _b === void 0 ? void 0 : _b.on(event, (...args) => this.emit(event, ...args));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async close() {
|
|
50
|
+
if (!this.socket) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.socket.close();
|
|
54
|
+
this.socket = null;
|
|
55
|
+
}
|
|
56
|
+
send(str, cb) {
|
|
57
|
+
var _a;
|
|
58
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
|
|
59
|
+
return Boolean(this.socket);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.WebSocketClient = WebSocketClient;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { GetCatalogOptions, ProductCreate, ProductUpdate, SocketConfig } from '../Types';
|
|
3
|
+
import { BinaryNode } from '../WABinary';
|
|
4
|
+
export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
5
|
+
getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
|
|
6
|
+
getCatalog: ({ jid, limit, cursor }: GetCatalogOptions) => Promise<{
|
|
7
|
+
products: import("../Types").Product[];
|
|
8
|
+
nextPageCursor: string | undefined;
|
|
9
|
+
}>;
|
|
10
|
+
getCollections: (jid?: string | undefined, limit?: number) => Promise<{
|
|
11
|
+
collections: import("../Types").CatalogCollection[];
|
|
12
|
+
}>;
|
|
13
|
+
productCreate: (create: ProductCreate) => Promise<import("../Types").Product>;
|
|
14
|
+
productDelete: (productIds: string[]) => Promise<{
|
|
15
|
+
deleted: number;
|
|
16
|
+
}>;
|
|
17
|
+
productUpdate: (productId: string, update: ProductUpdate) => Promise<import("../Types").Product>;
|
|
18
|
+
sendMessageAck: ({ tag, attrs }: BinaryNode) => Promise<void>;
|
|
19
|
+
sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
|
|
20
|
+
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
21
|
+
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
|
22
|
+
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
23
|
+
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
24
|
+
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
25
|
+
sendReceipts: (keys: import("../Types").WAProto.IMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
26
|
+
readMessages: (keys: import("../Types").WAProto.IMessageKey[]) => Promise<void>;
|
|
27
|
+
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
|
|
28
|
+
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
29
|
+
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
30
|
+
[_: string]: string;
|
|
31
|
+
}>;
|
|
32
|
+
updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
|
|
33
|
+
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
|
|
34
|
+
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
35
|
+
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
36
|
+
groupLeave: (id: string) => Promise<void>;
|
|
37
|
+
groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
|
|
38
|
+
groupRequestParticipantsList: (jid: string) => Promise<{
|
|
39
|
+
[key: string]: string;
|
|
40
|
+
}[]>;
|
|
41
|
+
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "reject" | "approve") => Promise<{
|
|
42
|
+
status: string;
|
|
43
|
+
jid: string;
|
|
44
|
+
}[]>;
|
|
45
|
+
groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
|
|
46
|
+
status: string;
|
|
47
|
+
jid: string;
|
|
48
|
+
}[]>;
|
|
49
|
+
groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
|
|
50
|
+
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
51
|
+
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
52
|
+
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
53
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
|
|
54
|
+
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
55
|
+
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
56
|
+
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
57
|
+
groupFetchAllParticipating: () => Promise<{
|
|
58
|
+
[_: string]: import("../Types").GroupMetadata;
|
|
59
|
+
}>;
|
|
60
|
+
processingMutex: {
|
|
61
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
|
62
|
+
};
|
|
63
|
+
upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
|
|
64
|
+
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
|
65
|
+
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
|
|
66
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
|
|
67
|
+
profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
|
|
68
|
+
onWhatsApp: (...jids: string[]) => Promise<{
|
|
69
|
+
exists: boolean;
|
|
70
|
+
jid: string;
|
|
71
|
+
}[]>;
|
|
72
|
+
fetchBlocklist: () => Promise<string[]>;
|
|
73
|
+
fetchStatus: (jid: string) => Promise<{
|
|
74
|
+
status: string | undefined;
|
|
75
|
+
setAt: Date;
|
|
76
|
+
} | undefined>;
|
|
77
|
+
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
|
78
|
+
removeProfilePicture: (jid: string) => Promise<void>;
|
|
79
|
+
updateProfileStatus: (status: string) => Promise<void>;
|
|
80
|
+
updateProfileName: (name: string) => Promise<void>;
|
|
81
|
+
updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
|
|
82
|
+
updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
83
|
+
updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
|
|
84
|
+
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
85
|
+
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
86
|
+
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
|
87
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
88
|
+
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
89
|
+
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
|
|
90
|
+
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
91
|
+
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
92
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
|
|
93
|
+
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
94
|
+
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
95
|
+
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
96
|
+
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
97
|
+
type: "md";
|
|
98
|
+
ws: import("./Client").MobileSocketClient | import("./Client").WebSocketClient;
|
|
99
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
100
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
101
|
+
buffer(): void;
|
|
102
|
+
createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
|
|
103
|
+
flush(force?: boolean | undefined): boolean;
|
|
104
|
+
isBuffering(): boolean;
|
|
105
|
+
};
|
|
106
|
+
authState: {
|
|
107
|
+
creds: import("../Types").AuthenticationCreds;
|
|
108
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
|
109
|
+
};
|
|
110
|
+
signalRepository: import("../Types").SignalRepository;
|
|
111
|
+
user: import("../Types").Contact | undefined;
|
|
112
|
+
generateMessageTag: () => string;
|
|
113
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
|
|
114
|
+
waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
|
|
115
|
+
waitForSocketOpen: () => Promise<void>;
|
|
116
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
117
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
118
|
+
logout: (msg?: string | undefined) => Promise<void>;
|
|
119
|
+
end: (error: Error | undefined) => void;
|
|
120
|
+
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
121
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
|
122
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
123
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
124
|
+
};
|