@d0v3riz/baileys 6.3.0 → 6.4.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 +6 -5
- package/WAProto/WAProto.proto +58 -24
- package/WAProto/index.d.ts +649 -410
- package/WAProto/index.js +1632 -985
- package/WASignalGroup/group_cipher.js +38 -24
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_key_record.js +4 -2
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +1 -1
- package/lib/Socket/Client/abstract-socket-client.d.ts +1 -0
- package/lib/Socket/business.d.ts +5 -3
- package/lib/Socket/chats.d.ts +6 -5
- package/lib/Socket/groups.d.ts +4 -2
- package/lib/Socket/groups.js +1 -1
- package/lib/Socket/index.d.ts +9 -7
- package/lib/Socket/messages-recv.d.ts +6 -3
- package/lib/Socket/messages-recv.js +79 -3
- package/lib/Socket/messages-send.d.ts +4 -2
- package/lib/Socket/messages-send.js +17 -8
- package/lib/Socket/registration.d.ts +6 -4
- package/lib/Socket/socket.d.ts +4 -3
- package/lib/Socket/socket.js +69 -9
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Types/Auth.d.ts +19 -17
- package/lib/Types/Call.d.ts +2 -2
- package/lib/Types/Chat.d.ts +13 -13
- package/lib/Types/Events.d.ts +3 -3
- package/lib/Types/GroupMetadata.d.ts +4 -2
- package/lib/Types/LabelAssociation.d.ts +2 -2
- package/lib/Types/Message.d.ts +57 -45
- package/lib/Types/Product.d.ts +14 -14
- package/lib/Types/Signal.d.ts +10 -10
- package/lib/Types/Socket.d.ts +5 -4
- package/lib/Types/State.d.ts +2 -2
- package/lib/Types/index.d.ts +5 -5
- package/lib/Utils/auth-utils.js +3 -1
- package/lib/Utils/chat-utils.d.ts +4 -4
- package/lib/Utils/crypto.d.ts +3 -0
- package/lib/Utils/crypto.js +15 -1
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +3 -3
- package/lib/Utils/generics.d.ts +7 -6
- package/lib/Utils/generics.js +25 -27
- package/lib/Utils/link-preview.d.ts +1 -1
- package/lib/Utils/link-preview.js +1 -24
- package/lib/Utils/make-mutex.d.ts +1 -1
- package/lib/Utils/messages-media.d.ts +9 -3
- package/lib/Utils/messages-media.js +54 -6
- package/lib/Utils/messages.d.ts +6 -5
- package/lib/Utils/messages.js +37 -7
- package/lib/Utils/process-message.d.ts +2 -2
- package/lib/Utils/validate-connection.js +1 -2
- package/lib/WABinary/jid-utils.d.ts +4 -4
- package/lib/WABinary/types.d.ts +4 -4
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -0
- package/package.json +6 -5
package/lib/Types/Message.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
2
4
|
import { AxiosRequestConfig } from 'axios';
|
|
3
5
|
import type { Logger } from 'pino';
|
|
4
6
|
import type { Readable } from 'stream';
|
|
@@ -8,31 +10,31 @@ import { MEDIA_HKDF_KEY_MAPPING } from '../Defaults';
|
|
|
8
10
|
import type { GroupMetadata } from './GroupMetadata';
|
|
9
11
|
import { CacheStore } from './Socket';
|
|
10
12
|
export { proto as WAProto };
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
13
|
+
export type WAMessage = proto.IWebMessageInfo;
|
|
14
|
+
export type WAMessageContent = proto.IMessage;
|
|
15
|
+
export type WAContactMessage = proto.Message.IContactMessage;
|
|
16
|
+
export type WAContactsArrayMessage = proto.Message.IContactsArrayMessage;
|
|
17
|
+
export type WAMessageKey = proto.IMessageKey;
|
|
18
|
+
export type WATextMessage = proto.Message.IExtendedTextMessage;
|
|
19
|
+
export type WAContextInfo = proto.IContextInfo;
|
|
20
|
+
export type WALocationMessage = proto.Message.ILocationMessage;
|
|
21
|
+
export type WAGenericMediaMessage = proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
|
|
20
22
|
export import WAMessageStubType = proto.WebMessageInfo.StubType;
|
|
21
23
|
export import WAMessageStatus = proto.WebMessageInfo.Status;
|
|
22
|
-
export
|
|
24
|
+
export type WAMediaUpload = Buffer | {
|
|
23
25
|
url: URL | string;
|
|
24
26
|
} | {
|
|
25
27
|
stream: Readable;
|
|
26
28
|
};
|
|
27
29
|
/** Set of message types that are supported by the library */
|
|
28
|
-
export
|
|
29
|
-
export
|
|
30
|
+
export type MessageType = keyof proto.Message;
|
|
31
|
+
export type DownloadableMessage = {
|
|
30
32
|
mediaKey?: Uint8Array | null;
|
|
31
33
|
directPath?: string | null;
|
|
32
34
|
url?: string | null;
|
|
33
35
|
};
|
|
34
|
-
export
|
|
35
|
-
export
|
|
36
|
+
export type MessageReceiptType = 'read' | 'read-self' | 'hist_sync' | 'peer_msg' | 'sender' | 'inactive' | 'played' | undefined;
|
|
37
|
+
export type MediaConnInfo = {
|
|
36
38
|
auth: string;
|
|
37
39
|
ttl: number;
|
|
38
40
|
hosts: {
|
|
@@ -50,30 +52,30 @@ export interface WAUrlInfo {
|
|
|
50
52
|
highQualityThumbnail?: proto.Message.IImageMessage;
|
|
51
53
|
originalThumbnailUrl?: string;
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
type Mentionable = {
|
|
54
56
|
/** list of jids that are mentioned in the accompanying text */
|
|
55
57
|
mentions?: string[];
|
|
56
58
|
};
|
|
57
|
-
|
|
59
|
+
type Contextable = {
|
|
58
60
|
/** add contextInfo to the message */
|
|
59
61
|
contextInfo?: proto.IContextInfo;
|
|
60
62
|
};
|
|
61
|
-
|
|
63
|
+
type ViewOnce = {
|
|
62
64
|
viewOnce?: boolean;
|
|
63
65
|
};
|
|
64
|
-
|
|
66
|
+
type Buttonable = {
|
|
65
67
|
/** add buttons to the message */
|
|
66
68
|
buttons?: proto.Message.ButtonsMessage.IButton[];
|
|
67
69
|
};
|
|
68
|
-
|
|
70
|
+
type Templatable = {
|
|
69
71
|
/** add buttons to the message (conflicts with normal buttons)*/
|
|
70
72
|
templateButtons?: proto.IHydratedTemplateButton[];
|
|
71
73
|
footer?: string;
|
|
72
74
|
};
|
|
73
|
-
|
|
75
|
+
type Editable = {
|
|
74
76
|
edit?: WAMessageKey;
|
|
75
77
|
};
|
|
76
|
-
|
|
78
|
+
type Listable = {
|
|
77
79
|
/** Sections of the List */
|
|
78
80
|
sections?: proto.Message.ListMessage.ISection[];
|
|
79
81
|
/** Title of a List Message only */
|
|
@@ -81,19 +83,19 @@ declare type Listable = {
|
|
|
81
83
|
/** Text of the bnutton on the list (required) */
|
|
82
84
|
buttonText?: string;
|
|
83
85
|
};
|
|
84
|
-
|
|
86
|
+
type WithDimensions = {
|
|
85
87
|
width?: number;
|
|
86
88
|
height?: number;
|
|
87
89
|
};
|
|
88
|
-
export
|
|
90
|
+
export type PollMessageOptions = {
|
|
89
91
|
name: string;
|
|
90
92
|
selectableCount?: number;
|
|
91
93
|
values: string[];
|
|
92
94
|
/** 32 byte message secret to encrypt poll selections */
|
|
93
95
|
messageSecret?: Uint8Array;
|
|
94
96
|
};
|
|
95
|
-
export
|
|
96
|
-
export
|
|
97
|
+
export type MediaType = keyof typeof MEDIA_HKDF_KEY_MAPPING;
|
|
98
|
+
export type AnyMediaMessageContent = (({
|
|
97
99
|
image: WAMediaUpload;
|
|
98
100
|
caption?: string;
|
|
99
101
|
jpegThumbnail?: string;
|
|
@@ -119,15 +121,15 @@ export declare type AnyMediaMessageContent = (({
|
|
|
119
121
|
} & Contextable & Buttonable & Templatable)) & {
|
|
120
122
|
mimetype?: string;
|
|
121
123
|
} & Editable;
|
|
122
|
-
export
|
|
124
|
+
export type ButtonReplyInfo = {
|
|
123
125
|
displayText: string;
|
|
124
126
|
id: string;
|
|
125
127
|
index: number;
|
|
126
128
|
};
|
|
127
|
-
export
|
|
129
|
+
export type WASendableProduct = Omit<proto.Message.ProductMessage.IProductSnapshot, 'productImage'> & {
|
|
128
130
|
productImage: WAMediaUpload;
|
|
129
131
|
};
|
|
130
|
-
export
|
|
132
|
+
export type AnyRegularMessageContent = (({
|
|
131
133
|
text: string;
|
|
132
134
|
linkPreview?: WAUrlInfo | null;
|
|
133
135
|
} & Mentionable & Contextable & Buttonable & Templatable & Listable & Editable) | AnyMediaMessageContent | ({
|
|
@@ -152,7 +154,7 @@ export declare type AnyRegularMessageContent = (({
|
|
|
152
154
|
body?: string;
|
|
153
155
|
footer?: string;
|
|
154
156
|
}) & ViewOnce;
|
|
155
|
-
export
|
|
157
|
+
export type AnyMessageContent = AnyRegularMessageContent | {
|
|
156
158
|
forward: WAMessage;
|
|
157
159
|
force?: boolean;
|
|
158
160
|
} | {
|
|
@@ -161,14 +163,14 @@ export declare type AnyMessageContent = AnyRegularMessageContent | {
|
|
|
161
163
|
} | {
|
|
162
164
|
disappearingMessagesInChat: boolean | number;
|
|
163
165
|
};
|
|
164
|
-
export
|
|
165
|
-
|
|
166
|
+
export type GroupMetadataParticipants = Pick<GroupMetadata, 'participants'>;
|
|
167
|
+
type MinimalRelayOptions = {
|
|
166
168
|
/** override the message ID with a custom provided string */
|
|
167
169
|
messageId?: string;
|
|
168
170
|
/** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
|
|
169
171
|
cachedGroupMetadata?: (jid: string) => Promise<GroupMetadataParticipants | undefined>;
|
|
170
172
|
};
|
|
171
|
-
export
|
|
173
|
+
export type MessageRelayOptions = MinimalRelayOptions & {
|
|
172
174
|
/** only send to a specific participant; used when a message decryption fails for a single user */
|
|
173
175
|
participant?: {
|
|
174
176
|
jid: string;
|
|
@@ -180,8 +182,10 @@ export declare type MessageRelayOptions = MinimalRelayOptions & {
|
|
|
180
182
|
};
|
|
181
183
|
/** should we use the devices cache, or fetch afresh from the server; default assumed to be "true" */
|
|
182
184
|
useUserDevicesCache?: boolean;
|
|
185
|
+
/** jid list of participants for status@broadcast */
|
|
186
|
+
statusJidList?: string[];
|
|
183
187
|
};
|
|
184
|
-
export
|
|
188
|
+
export type MiscMessageGenerationOptions = MinimalRelayOptions & {
|
|
185
189
|
/** optional, if you want to manually set the timestamp of the message */
|
|
186
190
|
timestamp?: Date;
|
|
187
191
|
/** the message you want to quote */
|
|
@@ -192,11 +196,17 @@ export declare type MiscMessageGenerationOptions = MinimalRelayOptions & {
|
|
|
192
196
|
ephemeralExpiration?: number | string;
|
|
193
197
|
/** timeout for media upload to WA server */
|
|
194
198
|
mediaUploadTimeoutMs?: number;
|
|
199
|
+
/** jid list of participants for status@broadcast */
|
|
200
|
+
statusJidList?: string[];
|
|
201
|
+
/** backgroundcolor for status */
|
|
202
|
+
backgroundColor?: string;
|
|
203
|
+
/** font type for status */
|
|
204
|
+
font?: number;
|
|
195
205
|
};
|
|
196
|
-
export
|
|
206
|
+
export type MessageGenerationOptionsFromContent = MiscMessageGenerationOptions & {
|
|
197
207
|
userJid: string;
|
|
198
208
|
};
|
|
199
|
-
export
|
|
209
|
+
export type WAMediaUploadFunction = (readStream: Readable, opts: {
|
|
200
210
|
fileEncSha256B64: string;
|
|
201
211
|
mediaType: MediaType;
|
|
202
212
|
timeoutMs?: number;
|
|
@@ -204,7 +214,7 @@ export declare type WAMediaUploadFunction = (readStream: Readable, opts: {
|
|
|
204
214
|
mediaUrl: string;
|
|
205
215
|
directPath: string;
|
|
206
216
|
}>;
|
|
207
|
-
export
|
|
217
|
+
export type MediaGenerationOptions = {
|
|
208
218
|
logger?: Logger;
|
|
209
219
|
mediaTypeOverride?: MediaType;
|
|
210
220
|
upload: WAMediaUploadFunction;
|
|
@@ -212,34 +222,36 @@ export declare type MediaGenerationOptions = {
|
|
|
212
222
|
mediaCache?: CacheStore;
|
|
213
223
|
mediaUploadTimeoutMs?: number;
|
|
214
224
|
options?: AxiosRequestConfig;
|
|
225
|
+
backgroundColor?: string;
|
|
226
|
+
font?: number;
|
|
215
227
|
};
|
|
216
|
-
export
|
|
228
|
+
export type MessageContentGenerationOptions = MediaGenerationOptions & {
|
|
217
229
|
getUrlInfo?: (text: string) => Promise<WAUrlInfo | undefined>;
|
|
218
230
|
};
|
|
219
|
-
export
|
|
231
|
+
export type MessageGenerationOptions = MessageContentGenerationOptions & MessageGenerationOptionsFromContent;
|
|
220
232
|
/**
|
|
221
233
|
* Type of message upsert
|
|
222
234
|
* 1. notify => notify the user, this message was just received
|
|
223
235
|
* 2. append => append the message to the chat history, no notification required
|
|
224
236
|
*/
|
|
225
|
-
export
|
|
226
|
-
export
|
|
227
|
-
export
|
|
237
|
+
export type MessageUpsertType = 'append' | 'notify';
|
|
238
|
+
export type MessageUserReceipt = proto.IUserReceipt;
|
|
239
|
+
export type WAMessageUpdate = {
|
|
228
240
|
update: Partial<WAMessage>;
|
|
229
241
|
key: proto.IMessageKey;
|
|
230
242
|
};
|
|
231
|
-
export
|
|
243
|
+
export type WAMessageCursor = {
|
|
232
244
|
before: WAMessageKey | undefined;
|
|
233
245
|
} | {
|
|
234
246
|
after: WAMessageKey | undefined;
|
|
235
247
|
};
|
|
236
|
-
export
|
|
248
|
+
export type MessageUserReceiptUpdate = {
|
|
237
249
|
key: proto.IMessageKey;
|
|
238
250
|
receipt: MessageUserReceipt;
|
|
239
251
|
};
|
|
240
|
-
export
|
|
252
|
+
export type MediaDecryptionKeyInfo = {
|
|
241
253
|
iv: Buffer;
|
|
242
254
|
cipherKey: Buffer;
|
|
243
255
|
macKey?: Buffer;
|
|
244
256
|
};
|
|
245
|
-
export
|
|
257
|
+
export type MinimalMessage = Pick<proto.IWebMessageInfo, 'key' | 'messageTimestamp'>;
|
package/lib/Types/Product.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WAMediaUpload } from './Message';
|
|
2
|
-
export
|
|
2
|
+
export type CatalogResult = {
|
|
3
3
|
data: {
|
|
4
4
|
paging: {
|
|
5
5
|
cursors: {
|
|
@@ -10,23 +10,23 @@ export declare type CatalogResult = {
|
|
|
10
10
|
data: any[];
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type ProductCreateResult = {
|
|
14
14
|
data: {
|
|
15
15
|
product: {};
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
export
|
|
18
|
+
export type CatalogStatus = {
|
|
19
19
|
status: string;
|
|
20
20
|
canAppeal: boolean;
|
|
21
21
|
};
|
|
22
|
-
export
|
|
22
|
+
export type CatalogCollection = {
|
|
23
23
|
id: string;
|
|
24
24
|
name: string;
|
|
25
25
|
products: Product[];
|
|
26
26
|
status: CatalogStatus;
|
|
27
27
|
};
|
|
28
|
-
export
|
|
29
|
-
export
|
|
28
|
+
export type ProductAvailability = 'in stock';
|
|
29
|
+
export type ProductBase = {
|
|
30
30
|
name: string;
|
|
31
31
|
retailerId?: string;
|
|
32
32
|
url?: string;
|
|
@@ -35,14 +35,14 @@ export declare type ProductBase = {
|
|
|
35
35
|
currency: string;
|
|
36
36
|
isHidden?: boolean;
|
|
37
37
|
};
|
|
38
|
-
export
|
|
38
|
+
export type ProductCreate = ProductBase & {
|
|
39
39
|
/** ISO country code for product origin. Set to undefined for no country */
|
|
40
40
|
originCountryCode: string | undefined;
|
|
41
41
|
/** images of the product */
|
|
42
42
|
images: WAMediaUpload[];
|
|
43
43
|
};
|
|
44
|
-
export
|
|
45
|
-
export
|
|
44
|
+
export type ProductUpdate = Omit<ProductCreate, 'originCountryCode'>;
|
|
45
|
+
export type Product = ProductBase & {
|
|
46
46
|
id: string;
|
|
47
47
|
imageUrls: {
|
|
48
48
|
[_: string]: string;
|
|
@@ -52,11 +52,11 @@ export declare type Product = ProductBase & {
|
|
|
52
52
|
};
|
|
53
53
|
availability: ProductAvailability;
|
|
54
54
|
};
|
|
55
|
-
export
|
|
55
|
+
export type OrderPrice = {
|
|
56
56
|
currency: string;
|
|
57
57
|
total: number;
|
|
58
58
|
};
|
|
59
|
-
export
|
|
59
|
+
export type OrderProduct = {
|
|
60
60
|
id: string;
|
|
61
61
|
imageUrl: string;
|
|
62
62
|
name: string;
|
|
@@ -64,12 +64,12 @@ export declare type OrderProduct = {
|
|
|
64
64
|
currency: string;
|
|
65
65
|
price: number;
|
|
66
66
|
};
|
|
67
|
-
export
|
|
67
|
+
export type OrderDetails = {
|
|
68
68
|
price: OrderPrice;
|
|
69
69
|
products: OrderProduct[];
|
|
70
70
|
};
|
|
71
|
-
export
|
|
72
|
-
export
|
|
71
|
+
export type CatalogCursor = string;
|
|
72
|
+
export type GetCatalogOptions = {
|
|
73
73
|
/** cursor to start from */
|
|
74
74
|
cursor?: CatalogCursor;
|
|
75
75
|
/** number of products to fetch */
|
package/lib/Types/Signal.d.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
import { proto } from '../../WAProto';
|
|
2
|
-
|
|
2
|
+
type DecryptGroupSignalOpts = {
|
|
3
3
|
group: string;
|
|
4
4
|
authorJid: string;
|
|
5
5
|
msg: Uint8Array;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
type ProcessSenderKeyDistributionMessageOpts = {
|
|
8
8
|
item: proto.Message.ISenderKeyDistributionMessage;
|
|
9
9
|
authorJid: string;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
type DecryptSignalProtoOpts = {
|
|
12
12
|
jid: string;
|
|
13
13
|
type: 'pkmsg' | 'msg';
|
|
14
14
|
ciphertext: Uint8Array;
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
type EncryptMessageOpts = {
|
|
17
17
|
jid: string;
|
|
18
18
|
data: Uint8Array;
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
type EncryptGroupMessageOpts = {
|
|
21
21
|
group: string;
|
|
22
22
|
data: Uint8Array;
|
|
23
23
|
meId: string;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
type PreKey = {
|
|
26
26
|
keyId: number;
|
|
27
27
|
publicKey: Uint8Array;
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
type SignedPreKey = PreKey & {
|
|
30
30
|
signature: Uint8Array;
|
|
31
31
|
};
|
|
32
|
-
|
|
32
|
+
type E2ESession = {
|
|
33
33
|
registrationId: number;
|
|
34
34
|
identityKey: Uint8Array;
|
|
35
35
|
signedPreKey: SignedPreKey;
|
|
36
36
|
preKey: PreKey;
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
type E2ESessionOpts = {
|
|
39
39
|
jid: string;
|
|
40
40
|
session: E2ESession;
|
|
41
41
|
};
|
|
42
|
-
export
|
|
42
|
+
export type SignalRepository = {
|
|
43
43
|
decryptGroupMessage(opts: DecryptGroupSignalOpts): Promise<Uint8Array>;
|
|
44
44
|
processSenderKeyDistributionMessage(opts: ProcessSenderKeyDistributionMessageOpts): Promise<void>;
|
|
45
45
|
decryptMessage(opts: DecryptSignalProtoOpts): Promise<Uint8Array>;
|
package/lib/Types/Socket.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { AxiosRequestConfig } from 'axios';
|
|
3
4
|
import type { Agent } from 'https';
|
|
4
5
|
import type { Logger } from 'pino';
|
|
@@ -7,9 +8,9 @@ import { proto } from '../../WAProto';
|
|
|
7
8
|
import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth';
|
|
8
9
|
import { MediaConnInfo } from './Message';
|
|
9
10
|
import { SignalRepository } from './Signal';
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
11
|
+
export type WAVersion = [number, number, number];
|
|
12
|
+
export type WABrowserDescription = [string, string, string];
|
|
13
|
+
export type CacheStore = {
|
|
13
14
|
/** get a cached key and change the stats */
|
|
14
15
|
get<T>(key: string): T | undefined;
|
|
15
16
|
/** set a key in the cache */
|
|
@@ -19,7 +20,7 @@ export declare type CacheStore = {
|
|
|
19
20
|
/** flush all data */
|
|
20
21
|
flushAll(): void;
|
|
21
22
|
};
|
|
22
|
-
export
|
|
23
|
+
export type SocketConfig = {
|
|
23
24
|
/** the WS url to connect to WA */
|
|
24
25
|
waWebSocketUrl: string | URL;
|
|
25
26
|
/** Fails the connection if the socket times out in this interval */
|
package/lib/Types/State.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Contact } from './Contact';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type WAConnectionState = 'open' | 'connecting' | 'close';
|
|
3
|
+
export type ConnectionState = {
|
|
4
4
|
/** connection is now open, connecting or closed */
|
|
5
5
|
connection: WAConnectionState;
|
|
6
6
|
/** the error that caused the connection to close */
|
package/lib/Types/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export * from './Call';
|
|
|
11
11
|
export * from './Signal';
|
|
12
12
|
import { AuthenticationState } from './Auth';
|
|
13
13
|
import { SocketConfig } from './Socket';
|
|
14
|
-
export
|
|
14
|
+
export type UserFacingSocketConfig = Partial<SocketConfig> & {
|
|
15
15
|
auth: AuthenticationState;
|
|
16
16
|
};
|
|
17
17
|
export declare enum DisconnectReason {
|
|
@@ -24,18 +24,18 @@ export declare enum DisconnectReason {
|
|
|
24
24
|
restartRequired = 515,
|
|
25
25
|
multideviceMismatch = 411
|
|
26
26
|
}
|
|
27
|
-
export
|
|
27
|
+
export type WAInitResponse = {
|
|
28
28
|
ref: string;
|
|
29
29
|
ttl: number;
|
|
30
30
|
status: 200;
|
|
31
31
|
};
|
|
32
|
-
export
|
|
32
|
+
export type WABusinessHoursConfig = {
|
|
33
33
|
day_of_week: string;
|
|
34
34
|
mode: string;
|
|
35
35
|
open_time?: number;
|
|
36
36
|
close_time?: number;
|
|
37
37
|
};
|
|
38
|
-
export
|
|
38
|
+
export type WABusinessProfile = {
|
|
39
39
|
description: string;
|
|
40
40
|
email: string | undefined;
|
|
41
41
|
business_hours: {
|
|
@@ -48,7 +48,7 @@ export declare type WABusinessProfile = {
|
|
|
48
48
|
wid?: string;
|
|
49
49
|
address?: string;
|
|
50
50
|
};
|
|
51
|
-
export
|
|
51
|
+
export type CurveKeyPair = {
|
|
52
52
|
private: Uint8Array;
|
|
53
53
|
public: Uint8Array;
|
|
54
54
|
};
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -179,6 +179,7 @@ const initAuthCreds = () => {
|
|
|
179
179
|
const identityKey = crypto_2.Curve.generateKeyPair();
|
|
180
180
|
return {
|
|
181
181
|
noiseKey: crypto_2.Curve.generateKeyPair(),
|
|
182
|
+
pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
|
|
182
183
|
signedIdentityKey: identityKey,
|
|
183
184
|
signedPreKey: (0, crypto_2.signedKeyPair)(identityKey, 1),
|
|
184
185
|
registrationId: (0, generics_1.generateRegistrationId)(),
|
|
@@ -196,7 +197,8 @@ const initAuthCreds = () => {
|
|
|
196
197
|
identityId: (0, crypto_1.randomBytes)(20),
|
|
197
198
|
registered: false,
|
|
198
199
|
backupToken: (0, crypto_1.randomBytes)(20),
|
|
199
|
-
registration: {}
|
|
200
|
+
registration: {},
|
|
201
|
+
pairingCode: undefined,
|
|
200
202
|
};
|
|
201
203
|
};
|
|
202
204
|
exports.initAuthCreds = initAuthCreds;
|
|
@@ -4,8 +4,8 @@ import type { Logger } from 'pino';
|
|
|
4
4
|
import { proto } from '../../WAProto';
|
|
5
5
|
import { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LTHashState, WAPatchCreate, WAPatchName } from '../Types';
|
|
6
6
|
import { BinaryNode } from '../WABinary';
|
|
7
|
-
|
|
8
|
-
export
|
|
7
|
+
type FetchAppStateSyncKey = (keyId: string) => Promise<proto.Message.IAppStateSyncKeyData | null | undefined>;
|
|
8
|
+
export type ChatMutationMap = {
|
|
9
9
|
[index: string]: ChatMutation;
|
|
10
10
|
};
|
|
11
11
|
export declare const newLTHashState: () => LTHashState;
|
|
@@ -62,10 +62,10 @@ export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.IS
|
|
|
62
62
|
state: LTHashState;
|
|
63
63
|
mutationMap: ChatMutationMap;
|
|
64
64
|
}>;
|
|
65
|
-
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number
|
|
65
|
+
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
|
|
66
66
|
state: LTHashState;
|
|
67
67
|
mutationMap: ChatMutationMap;
|
|
68
68
|
}>;
|
|
69
69
|
export declare const chatModificationToAppPatch: (mod: ChatModification, jid: string) => WAPatchCreate;
|
|
70
|
-
export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions
|
|
70
|
+
export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions, logger?: Logger) => void;
|
|
71
71
|
export {};
|
package/lib/Utils/crypto.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv
|
|
|
23
23
|
* where the auth tag is suffixed to the ciphertext
|
|
24
24
|
* */
|
|
25
25
|
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
|
|
26
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
|
|
27
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
|
|
26
28
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
27
29
|
export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer;
|
|
28
30
|
/** decrypt AES 256 CBC */
|
|
@@ -36,3 +38,4 @@ export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number
|
|
|
36
38
|
salt?: Buffer;
|
|
37
39
|
info?: string;
|
|
38
40
|
}): Buffer;
|
|
41
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Buffer;
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.hkdf = exports.md5 = exports.sha256 = exports.hmacSign = exports.aesEncrypWithIV = exports.aesEncrypt = exports.aesDecryptWithIV = exports.aesDecrypt = exports.aesDecryptGCM = exports.aesEncryptGCM = exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
|
29
|
+
exports.derivePairingCodeKey = exports.hkdf = exports.md5 = exports.sha256 = exports.hmacSign = exports.aesEncrypWithIV = exports.aesEncrypt = exports.aesDecryptWithIV = exports.aesDecrypt = exports.aesDecryptCTR = exports.aesEncryptCTR = exports.aesDecryptGCM = exports.aesEncryptGCM = exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
|
30
30
|
const crypto_1 = require("crypto");
|
|
31
31
|
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
|
32
32
|
const libsignal = __importStar(require("libsignal"));
|
|
@@ -93,6 +93,16 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
|
93
93
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
94
94
|
}
|
|
95
95
|
exports.aesDecryptGCM = aesDecryptGCM;
|
|
96
|
+
function aesEncryptCTR(plaintext, key, iv) {
|
|
97
|
+
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
|
98
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
99
|
+
}
|
|
100
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
|
101
|
+
function aesDecryptCTR(ciphertext, key, iv) {
|
|
102
|
+
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
|
103
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
104
|
+
}
|
|
105
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
|
96
106
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
97
107
|
function aesDecrypt(buffer, key) {
|
|
98
108
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
|
@@ -135,3 +145,7 @@ function hkdf(buffer, expandedLength, info) {
|
|
|
135
145
|
return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
|
|
136
146
|
}
|
|
137
147
|
exports.hkdf = hkdf;
|
|
148
|
+
function derivePairingCodeKey(pairingCode, salt) {
|
|
149
|
+
return (0, crypto_1.pbkdf2Sync)(pairingCode, salt, 2 << 16, 32, 'sha256');
|
|
150
|
+
}
|
|
151
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
@@ -7,8 +7,8 @@ import { BaileysEventEmitter, BaileysEventMap } from '../Types';
|
|
|
7
7
|
* this can make processing events extremely efficient -- since everything
|
|
8
8
|
* can be done in a single transaction
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
type BaileysEventData = Partial<BaileysEventMap>;
|
|
11
|
+
type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|
12
12
|
/** Use to process events in a batch */
|
|
13
13
|
process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void);
|
|
14
14
|
/**
|
|
@@ -156,7 +156,7 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
156
156
|
for (const contact of eventData.contacts) {
|
|
157
157
|
const existingContact = data.historySets.contacts[contact.id];
|
|
158
158
|
if (existingContact) {
|
|
159
|
-
Object.assign(existingContact, (0, generics_1.
|
|
159
|
+
Object.assign(existingContact, (0, generics_1.trimUndefined)(contact));
|
|
160
160
|
}
|
|
161
161
|
else {
|
|
162
162
|
const historyContactId = `c:${contact.id}`;
|
|
@@ -256,14 +256,14 @@ function append(data, historyCache, event, eventData, logger) {
|
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
if (upsert) {
|
|
259
|
-
upsert = Object.assign(upsert, (0, generics_1.
|
|
259
|
+
upsert = Object.assign(upsert, (0, generics_1.trimUndefined)(contact));
|
|
260
260
|
}
|
|
261
261
|
else {
|
|
262
262
|
upsert = contact;
|
|
263
263
|
data.contactUpserts[contact.id] = upsert;
|
|
264
264
|
}
|
|
265
265
|
if (data.contactUpdates[contact.id]) {
|
|
266
|
-
upsert = Object.assign(data.contactUpdates[contact.id], (0, generics_1.
|
|
266
|
+
upsert = Object.assign(data.contactUpdates[contact.id], (0, generics_1.trimUndefined)(contact));
|
|
267
267
|
delete data.contactUpdates[contact.id];
|
|
268
268
|
}
|
|
269
269
|
}
|
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -24,9 +24,9 @@ export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
|
|
24
24
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
|
25
25
|
/** unix timestamp of a date in seconds */
|
|
26
26
|
export declare const unixTimestampSeconds: (date?: Date) => number;
|
|
27
|
-
export
|
|
28
|
-
export declare const debouncedTimeout: (intervalMs?: number, task?: (
|
|
29
|
-
start: (newIntervalMs?: number
|
|
27
|
+
export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>;
|
|
28
|
+
export declare const debouncedTimeout: (intervalMs?: number, task?: () => void) => {
|
|
29
|
+
start: (newIntervalMs?: number, newTask?: () => void) => void;
|
|
30
30
|
cancel: () => void;
|
|
31
31
|
setTask: (newTask: () => void) => () => void;
|
|
32
32
|
setInterval: (newInterval: number) => number;
|
|
@@ -38,8 +38,8 @@ export declare const delayCancellable: (ms: number) => {
|
|
|
38
38
|
};
|
|
39
39
|
export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
|
|
40
40
|
export declare const generateMessageID: () => string;
|
|
41
|
-
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number
|
|
42
|
-
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number
|
|
41
|
+
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
42
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
|
43
43
|
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
|
44
44
|
/**
|
|
45
45
|
* utility that fetches latest baileys version from the master branch.
|
|
@@ -89,4 +89,5 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
|
89
89
|
* @param platform AuthenticationCreds.platform
|
|
90
90
|
*/
|
|
91
91
|
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
|
92
|
-
export declare function
|
|
92
|
+
export declare function trimUndefined(obj: any): any;
|
|
93
|
+
export declare function bytesToCrockford(buffer: Buffer): string;
|