@synacwave/baileys 0.0.0-stage → 0.4.2
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/ATTRIBUTION.md +14 -0
- package/CHANGELOG.md +47 -0
- package/LICENSE +23 -0
- package/README.md +299 -2
- package/WAProto/index.d.ts +15942 -0
- package/WAProto/index.js +115911 -0
- package/engine-requirements.js +13 -0
- package/lib/Defaults/index.d.ts +145 -0
- package/lib/Defaults/index.js +155 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.d.ts +8 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.d.ts +11 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.d.ts +7 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-name.d.ts +12 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.d.ts +13 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-state.d.ts +17 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/libsignal.d.ts +55 -0
- package/lib/Signal/libsignal.js +431 -0
- package/lib/Signal/lid-mapping.d.ts +21 -0
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.d.ts +6 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/business.d.ts +395 -0
- package/lib/Socket/business.js +380 -0
- package/lib/Socket/chats.d.ts +144 -0
- package/lib/Socket/chats.js +1219 -0
- package/lib/Socket/communities.d.ts +562 -0
- package/lib/Socket/communities.js +432 -0
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.js +348 -0
- package/lib/Socket/index.d.ts +531 -0
- package/lib/Socket/index.js +13 -0
- package/lib/Socket/messages-recv.d.ts +334 -0
- package/lib/Socket/messages-recv.js +1772 -0
- package/lib/Socket/messages-send.d.ts +330 -0
- package/lib/Socket/messages-send.js +1372 -0
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.d.ts +283 -0
- package/lib/Socket/newsletter.js +226 -0
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.js +970 -0
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +4 -0
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +421 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +79 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +24 -0
- package/lib/Types/Auth.d.ts +2 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.d.ts +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +2 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Contact.d.ts +2 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +3 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.d.ts +3 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.d.ts +12 -0
- package/lib/Types/Message.js +18 -0
- package/lib/Types/Mex.d.ts +3 -0
- package/lib/Types/Mex.js +39 -0
- package/lib/Types/Product.d.ts +2 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/RichType.d.ts +3 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/Signal.d.ts +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +6 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/USync.d.ts +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +14 -0
- package/lib/Types/index.js +26 -0
- package/lib/Utils/api-wrappers.d.ts +70 -0
- package/lib/Utils/api-wrappers.js +248 -0
- package/lib/Utils/auth-utils.d.ts +58 -0
- package/lib/Utils/auth-utils.js +306 -0
- package/lib/Utils/browser-utils.d.ts +10 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.d.ts +50 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/chat-utils.d.ts +409 -0
- package/lib/Utils/chat-utils.js +886 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +5 -0
- package/lib/Utils/companion-reg-client-utils.js +40 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +118 -0
- package/lib/Utils/decode-wa-message.d.ts +84 -0
- package/lib/Utils/decode-wa-message.js +317 -0
- package/lib/Utils/event-buffer.d.ts +13 -0
- package/lib/Utils/event-buffer.js +622 -0
- package/lib/Utils/generics.d.ts +64 -0
- package/lib/Utils/generics.js +395 -0
- package/lib/Utils/history.d.ts +76 -0
- package/lib/Utils/history.js +134 -0
- package/lib/Utils/identity-change-handler.d.ts +14 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.d.ts +28 -0
- package/lib/Utils/index.js +30 -0
- package/lib/Utils/link-preview.d.ts +13 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.d.ts +3 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.d.ts +7 -0
- package/lib/Utils/lt-hash.js +8 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/message-retry-manager.d.ts +80 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/messages-media.d.ts +137 -0
- package/lib/Utils/messages-media.js +843 -0
- package/lib/Utils/messages.d.ts +46 -0
- package/lib/Utils/messages.js +1848 -0
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/offline-node-processor.d.ts +10 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +26 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.d.ts +84 -0
- package/lib/Utils/process-message.js +749 -0
- package/lib/Utils/reporting-utils.d.ts +13 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/rich-message-utils.d.ts +49 -0
- package/lib/Utils/rich-message-utils.js +363 -0
- package/lib/Utils/signal.d.ts +83 -0
- package/lib/Utils/signal.js +201 -0
- package/lib/Utils/stanza-ack.d.ts +17 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/status-utils.js +178 -0
- package/lib/Utils/sticker-reaction.js +104 -0
- package/lib/Utils/synacwave.d.ts +111 -0
- package/lib/Utils/synacwave.js +564 -0
- package/lib/Utils/sync-action-utils.d.ts +3 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.d.ts +30 -0
- package/lib/Utils/tc-token-utils.js +164 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +109 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +109 -0
- package/lib/Utils/validate-connection.d.ts +44 -0
- package/lib/Utils/validate-connection.js +210 -0
- package/lib/Utils/view-once-text.d.ts +32 -0
- package/lib/Utils/view-once-text.js +213 -0
- package/lib/WABinary/constants.d.ts +62 -0
- package/lib/WABinary/constants.js +1467 -0
- package/lib/WABinary/decode.d.ts +10 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +220 -0
- package/lib/WABinary/generic-utils.d.ts +77 -0
- package/lib/WABinary/generic-utils.js +226 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.d.ts +29 -0
- package/lib/WABinary/jid-utils.js +96 -0
- package/lib/WABinary/types.d.ts +2 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.d.ts +34927 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/lib/WAUSync/USyncQuery.d.ts +21 -0
- package/lib/WAUSync/USyncQuery.js +98 -0
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.js +31 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +12 -0
- package/package.json +118 -5
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export function createSignalIdentity(wid: any, accountSignatureKey: any): {
|
|
2
|
+
identifier: {
|
|
3
|
+
name: any;
|
|
4
|
+
deviceId: number;
|
|
5
|
+
};
|
|
6
|
+
identifierKey: any;
|
|
7
|
+
};
|
|
8
|
+
export function getPreKeys({ get }: {
|
|
9
|
+
get: any;
|
|
10
|
+
}, min: any, limit: any): Promise<any>;
|
|
11
|
+
export function generateOrGetPreKeys(creds: any, range: any): {
|
|
12
|
+
newPreKeys: {};
|
|
13
|
+
lastPreKeyId: number;
|
|
14
|
+
preKeysRange: any[];
|
|
15
|
+
};
|
|
16
|
+
export function xmppSignedPreKey(key: any): {
|
|
17
|
+
tag: string;
|
|
18
|
+
attrs: {};
|
|
19
|
+
content: {
|
|
20
|
+
tag: string;
|
|
21
|
+
attrs: {};
|
|
22
|
+
content: any;
|
|
23
|
+
}[];
|
|
24
|
+
};
|
|
25
|
+
export function xmppPreKey(pair: any, id: any): {
|
|
26
|
+
tag: string;
|
|
27
|
+
attrs: {};
|
|
28
|
+
content: {
|
|
29
|
+
tag: string;
|
|
30
|
+
attrs: {};
|
|
31
|
+
content: any;
|
|
32
|
+
}[];
|
|
33
|
+
};
|
|
34
|
+
export function extractE2ESessionFromRetryReceipt(receipt: any): {
|
|
35
|
+
registrationId: number | undefined;
|
|
36
|
+
identityKey: any;
|
|
37
|
+
signedPreKey: {
|
|
38
|
+
keyId: number | undefined;
|
|
39
|
+
publicKey: any;
|
|
40
|
+
signature: any;
|
|
41
|
+
};
|
|
42
|
+
preKey: {
|
|
43
|
+
keyId: number | undefined;
|
|
44
|
+
publicKey: any;
|
|
45
|
+
} | undefined;
|
|
46
|
+
} | null;
|
|
47
|
+
export function parseAndInjectE2ESessions(node: any, repository: any): Promise<void>;
|
|
48
|
+
export function extractDeviceJids(result: any, myJid: any, myLid: any, excludeZeroDevices: any): {
|
|
49
|
+
user: any;
|
|
50
|
+
device: any;
|
|
51
|
+
domainType: any;
|
|
52
|
+
server: any;
|
|
53
|
+
}[];
|
|
54
|
+
export function getNextPreKeys({ creds, keys }: {
|
|
55
|
+
creds: any;
|
|
56
|
+
keys: any;
|
|
57
|
+
}, count: any): Promise<{
|
|
58
|
+
update: {
|
|
59
|
+
nextPreKeyId: number;
|
|
60
|
+
firstUnuploadedPreKeyId: number;
|
|
61
|
+
};
|
|
62
|
+
preKeys: any;
|
|
63
|
+
}>;
|
|
64
|
+
export function getNextPreKeysNode(state: any, count: any): Promise<{
|
|
65
|
+
update: {
|
|
66
|
+
nextPreKeyId: number;
|
|
67
|
+
firstUnuploadedPreKeyId: number;
|
|
68
|
+
};
|
|
69
|
+
node: {
|
|
70
|
+
tag: string;
|
|
71
|
+
attrs: {
|
|
72
|
+
xmlns: string;
|
|
73
|
+
type: string;
|
|
74
|
+
to: string;
|
|
75
|
+
};
|
|
76
|
+
content: {
|
|
77
|
+
tag: string;
|
|
78
|
+
attrs: {};
|
|
79
|
+
content: any;
|
|
80
|
+
}[];
|
|
81
|
+
};
|
|
82
|
+
}>;
|
|
83
|
+
//# sourceMappingURL=signal.d.ts.map
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { KEY_BUNDLE_TYPE } from '../Defaults/index.js';
|
|
2
|
+
import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildUInt, getServerFromDomainType, jidDecode, S_WHATSAPP_NET, WAJIDDomains } from '../WABinary/index.js';
|
|
3
|
+
import { Curve, generateSignalPubKey } from './crypto.js';
|
|
4
|
+
import { encodeBigEndian } from './generics.js';
|
|
5
|
+
function chunk(array, size) {
|
|
6
|
+
const chunks = [];
|
|
7
|
+
for (let i = 0; i < array.length; i += size) {
|
|
8
|
+
chunks.push(array.slice(i, i + size));
|
|
9
|
+
}
|
|
10
|
+
return chunks;
|
|
11
|
+
}
|
|
12
|
+
export const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
13
|
+
return {
|
|
14
|
+
identifier: { name: wid, deviceId: 0 },
|
|
15
|
+
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const getPreKeys = async ({ get }, min, limit) => {
|
|
19
|
+
const idList = [];
|
|
20
|
+
for (let id = min; id < limit; id++) {
|
|
21
|
+
idList.push(id.toString());
|
|
22
|
+
}
|
|
23
|
+
return get('pre-key', idList);
|
|
24
|
+
};
|
|
25
|
+
export const generateOrGetPreKeys = (creds, range) => {
|
|
26
|
+
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
27
|
+
const remaining = range - avaliable;
|
|
28
|
+
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
29
|
+
const newPreKeys = {};
|
|
30
|
+
if (remaining > 0) {
|
|
31
|
+
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
32
|
+
newPreKeys[i] = Curve.generateKeyPair();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
newPreKeys,
|
|
37
|
+
lastPreKeyId,
|
|
38
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export const xmppSignedPreKey = (key) => ({
|
|
42
|
+
tag: 'skey',
|
|
43
|
+
attrs: {},
|
|
44
|
+
content: [
|
|
45
|
+
{ tag: 'id', attrs: {}, content: encodeBigEndian(key.keyId, 3) },
|
|
46
|
+
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
47
|
+
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
48
|
+
]
|
|
49
|
+
});
|
|
50
|
+
export const xmppPreKey = (pair, id) => ({
|
|
51
|
+
tag: 'key',
|
|
52
|
+
attrs: {},
|
|
53
|
+
content: [
|
|
54
|
+
{ tag: 'id', attrs: {}, content: encodeBigEndian(id, 3) },
|
|
55
|
+
{ tag: 'value', attrs: {}, content: pair.public }
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
const isValidUInt = (n) => typeof n === 'number' && Number.isInteger(n);
|
|
59
|
+
export const extractE2ESessionFromRetryReceipt = (receipt) => {
|
|
60
|
+
const keysNode = getBinaryNodeChild(receipt, 'keys');
|
|
61
|
+
if (!keysNode)
|
|
62
|
+
return null;
|
|
63
|
+
const typeBuf = getBinaryNodeChildBuffer(keysNode, 'type');
|
|
64
|
+
if (!typeBuf || typeBuf.length !== 1 || typeBuf[0] !== KEY_BUNDLE_TYPE[0])
|
|
65
|
+
return null;
|
|
66
|
+
const identity = getBinaryNodeChildBuffer(keysNode, 'identity');
|
|
67
|
+
const skey = getBinaryNodeChild(keysNode, 'skey');
|
|
68
|
+
if (!identity || identity.length !== 32 || !skey)
|
|
69
|
+
return null;
|
|
70
|
+
const registrationId = getBinaryNodeChildUInt(receipt, 'registration', 4);
|
|
71
|
+
if (!isValidUInt(registrationId))
|
|
72
|
+
return null;
|
|
73
|
+
const signedPubKey = getBinaryNodeChildBuffer(skey, 'value');
|
|
74
|
+
const signedSig = getBinaryNodeChildBuffer(skey, 'signature');
|
|
75
|
+
const signedKeyId = getBinaryNodeChildUInt(skey, 'id', 3);
|
|
76
|
+
if (!signedPubKey || signedPubKey.length !== 32 || !signedSig || !isValidUInt(signedKeyId)) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const preKeyNode = getBinaryNodeChild(keysNode, 'key');
|
|
80
|
+
let preKey;
|
|
81
|
+
if (preKeyNode) {
|
|
82
|
+
const preKeyPub = getBinaryNodeChildBuffer(preKeyNode, 'value');
|
|
83
|
+
const preKeyId = getBinaryNodeChildUInt(preKeyNode, 'id', 3);
|
|
84
|
+
if (!preKeyPub || preKeyPub.length !== 32 || !isValidUInt(preKeyId)) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
preKey = { keyId: preKeyId, publicKey: generateSignalPubKey(preKeyPub) };
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
registrationId,
|
|
91
|
+
identityKey: generateSignalPubKey(identity),
|
|
92
|
+
signedPreKey: {
|
|
93
|
+
keyId: signedKeyId,
|
|
94
|
+
publicKey: generateSignalPubKey(signedPubKey),
|
|
95
|
+
signature: signedSig
|
|
96
|
+
},
|
|
97
|
+
preKey
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
export const parseAndInjectE2ESessions = async (node, repository) => {
|
|
101
|
+
const extractKey = (key) => key
|
|
102
|
+
? {
|
|
103
|
+
keyId: getBinaryNodeChildUInt(key, 'id', 3),
|
|
104
|
+
publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')),
|
|
105
|
+
signature: getBinaryNodeChildBuffer(key, 'signature')
|
|
106
|
+
}
|
|
107
|
+
: undefined;
|
|
108
|
+
const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user');
|
|
109
|
+
for (const node of nodes) {
|
|
110
|
+
assertNodeErrorFree(node);
|
|
111
|
+
}
|
|
112
|
+
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
113
|
+
// So Promise.all doesn't really help here,
|
|
114
|
+
// but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
|
|
115
|
+
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
116
|
+
// It's rare case when you need to E2E sessions for so many users, but it's possible
|
|
117
|
+
const chunkSize = 100;
|
|
118
|
+
const chunks = chunk(nodes, chunkSize);
|
|
119
|
+
for (const nodesChunk of chunks) {
|
|
120
|
+
for (const node of nodesChunk) {
|
|
121
|
+
const signedKey = getBinaryNodeChild(node, 'skey');
|
|
122
|
+
const key = getBinaryNodeChild(node, 'key');
|
|
123
|
+
const identity = getBinaryNodeChildBuffer(node, 'identity');
|
|
124
|
+
const jid = node.attrs.jid;
|
|
125
|
+
const registrationId = getBinaryNodeChildUInt(node, 'registration', 4);
|
|
126
|
+
await repository.injectE2ESession({
|
|
127
|
+
jid,
|
|
128
|
+
session: {
|
|
129
|
+
registrationId: registrationId,
|
|
130
|
+
identityKey: generateSignalPubKey(identity),
|
|
131
|
+
signedPreKey: extractKey(signedKey),
|
|
132
|
+
preKey: extractKey(key)
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
export const extractDeviceJids = (result, myJid, myLid, excludeZeroDevices) => {
|
|
139
|
+
const { user: myUser, device: myDevice } = jidDecode(myJid);
|
|
140
|
+
const extracted = [];
|
|
141
|
+
for (const userResult of result) {
|
|
142
|
+
const { devices, id } = userResult;
|
|
143
|
+
const decoded = jidDecode(id), { user, server } = decoded;
|
|
144
|
+
let { domainType } = decoded;
|
|
145
|
+
const deviceList = devices?.deviceList;
|
|
146
|
+
if (!Array.isArray(deviceList))
|
|
147
|
+
continue;
|
|
148
|
+
for (const { id: device, keyIndex, isHosted } of deviceList) {
|
|
149
|
+
if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
150
|
+
((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device
|
|
151
|
+
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
152
|
+
) {
|
|
153
|
+
if (isHosted) {
|
|
154
|
+
domainType = domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED;
|
|
155
|
+
}
|
|
156
|
+
extracted.push({
|
|
157
|
+
user,
|
|
158
|
+
device,
|
|
159
|
+
domainType,
|
|
160
|
+
server: getServerFromDomainType(server, domainType)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return extracted;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* get the next N keys for upload or processing
|
|
169
|
+
* @param count number of pre-keys to get or generate
|
|
170
|
+
*/
|
|
171
|
+
export const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
172
|
+
const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count);
|
|
173
|
+
const update = {
|
|
174
|
+
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
175
|
+
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
176
|
+
};
|
|
177
|
+
await keys.set({ 'pre-key': newPreKeys });
|
|
178
|
+
const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
179
|
+
return { update, preKeys };
|
|
180
|
+
};
|
|
181
|
+
export const getNextPreKeysNode = async (state, count) => {
|
|
182
|
+
const { creds } = state;
|
|
183
|
+
const { update, preKeys } = await getNextPreKeys(state, count);
|
|
184
|
+
const node = {
|
|
185
|
+
tag: 'iq',
|
|
186
|
+
attrs: {
|
|
187
|
+
xmlns: 'encrypt',
|
|
188
|
+
type: 'set',
|
|
189
|
+
to: S_WHATSAPP_NET
|
|
190
|
+
},
|
|
191
|
+
content: [
|
|
192
|
+
{ tag: 'registration', attrs: {}, content: encodeBigEndian(creds.registrationId) },
|
|
193
|
+
{ tag: 'type', attrs: {}, content: KEY_BUNDLE_TYPE },
|
|
194
|
+
{ tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
|
|
195
|
+
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
|
|
196
|
+
xmppSignedPreKey(creds.signedPreKey)
|
|
197
|
+
]
|
|
198
|
+
};
|
|
199
|
+
return { update, node };
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=signal.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds an ACK stanza for a received node.
|
|
3
|
+
* Pure function -- no I/O, no side effects.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors WhatsApp Web's ACK construction:
|
|
6
|
+
* - WAWebHandleMsgSendAck.sendAck / sendNack
|
|
7
|
+
* - WAWebCreateNackFromStanza.createNackFromStanza
|
|
8
|
+
*/
|
|
9
|
+
export function buildAckStanza(node: any, errorCode: any, meId: any): {
|
|
10
|
+
tag: string;
|
|
11
|
+
attrs: {
|
|
12
|
+
id: any;
|
|
13
|
+
to: any;
|
|
14
|
+
class: any;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=stanza-ack.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds an ACK stanza for a received node.
|
|
3
|
+
* Pure function -- no I/O, no side effects.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors WhatsApp Web's ACK construction:
|
|
6
|
+
* - WAWebHandleMsgSendAck.sendAck / sendNack
|
|
7
|
+
* - WAWebCreateNackFromStanza.createNackFromStanza
|
|
8
|
+
*/
|
|
9
|
+
export function buildAckStanza(node, errorCode, meId) {
|
|
10
|
+
const { tag, attrs } = node;
|
|
11
|
+
const stanza = {
|
|
12
|
+
tag: 'ack',
|
|
13
|
+
attrs: {
|
|
14
|
+
id: attrs.id,
|
|
15
|
+
to: attrs.from,
|
|
16
|
+
class: tag
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
if (errorCode) {
|
|
20
|
+
stanza.attrs.error = errorCode.toString();
|
|
21
|
+
}
|
|
22
|
+
if (attrs.participant) {
|
|
23
|
+
stanza.attrs.participant = attrs.participant;
|
|
24
|
+
}
|
|
25
|
+
if (attrs.recipient) {
|
|
26
|
+
stanza.attrs.recipient = attrs.recipient;
|
|
27
|
+
}
|
|
28
|
+
// WA Web always includes type when present: `n.type || DROP_ATTR`
|
|
29
|
+
if (attrs.type) {
|
|
30
|
+
stanza.attrs.type = attrs.type;
|
|
31
|
+
}
|
|
32
|
+
// WA Web WAWebHandleMsgSendAck.sendAck/sendNack always include `from` for message-class ACKs
|
|
33
|
+
if (tag === 'message' && meId) {
|
|
34
|
+
stanza.attrs.from = meId;
|
|
35
|
+
}
|
|
36
|
+
return stanza;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=stanza-ack.js.map
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { jidNormalizedUser } from '../WABinary/index.js';
|
|
2
|
+
import { generateMessageIDV2 } from './generics.js';
|
|
3
|
+
import { generateWAMessageFromContent, prepareWAMessageMedia } from './messages.js';
|
|
4
|
+
|
|
5
|
+
export const STATUS_RING_PALETTE = {
|
|
6
|
+
red: '#E53935',
|
|
7
|
+
pink: '#E91E8C',
|
|
8
|
+
blue: '#2196F3',
|
|
9
|
+
yellow: '#F4C20D',
|
|
10
|
+
purple: '#9C27B0',
|
|
11
|
+
green: '#43A047',
|
|
12
|
+
orange: '#FB8C00',
|
|
13
|
+
cyan: '#00ACC1'
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const STATUS_COLOR_ALIASES = {
|
|
17
|
+
magenta: 'pink',
|
|
18
|
+
violet: 'purple',
|
|
19
|
+
gold: 'yellow'
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const DEFAULT_RING_NAME = 'Synacwave';
|
|
23
|
+
const DEFAULT_RING_EMOJI = '🪼';
|
|
24
|
+
const DEFAULT_RING_COLOR = 'purple';
|
|
25
|
+
|
|
26
|
+
export function normaliseStatusColor(value) {
|
|
27
|
+
const key = String(value || '').trim().toLowerCase();
|
|
28
|
+
if (!key) return null;
|
|
29
|
+
if (STATUS_RING_PALETTE[key]) return key;
|
|
30
|
+
if (STATUS_COLOR_ALIASES[key]) return STATUS_COLOR_ALIASES[key];
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function buildStatusAudienceMetadata(options = {}) {
|
|
35
|
+
const ringColor = normaliseStatusColor(options.ringColor) || DEFAULT_RING_COLOR;
|
|
36
|
+
return {
|
|
37
|
+
audienceType: options.audienceType ?? 2,
|
|
38
|
+
listName: options.ringName || options.listName || DEFAULT_RING_NAME,
|
|
39
|
+
listEmoji: options.ringEmoji || options.listEmoji || DEFAULT_RING_EMOJI,
|
|
40
|
+
ringColor,
|
|
41
|
+
ringColorHex: STATUS_RING_PALETTE[ringColor] || STATUS_RING_PALETTE[DEFAULT_RING_COLOR]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function buildGroupStatusContextInfo(options = {}) {
|
|
46
|
+
const audience = buildStatusAudienceMetadata(options);
|
|
47
|
+
const ctx = {
|
|
48
|
+
isGroupStatus: true,
|
|
49
|
+
statusSourceType: options.statusSourceType ?? 4,
|
|
50
|
+
pairedMediaType: options.pairedMediaType ?? 0,
|
|
51
|
+
statusAttributions: options.statusAttributions || [{ type: 6 }],
|
|
52
|
+
statusAudienceMetadata: audience
|
|
53
|
+
};
|
|
54
|
+
if (options.forwardedNewsletterMessageInfo) {
|
|
55
|
+
ctx.isForwarded = true;
|
|
56
|
+
ctx.forwardingScore = options.forwardingScore ?? 999;
|
|
57
|
+
ctx.forwardedNewsletterMessageInfo = options.forwardedNewsletterMessageInfo;
|
|
58
|
+
}
|
|
59
|
+
if (options.mentionedJid) ctx.mentionedJid = options.mentionedJid;
|
|
60
|
+
if (options.quotedMessage) ctx.quotedMessage = options.quotedMessage;
|
|
61
|
+
return ctx;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function mergeStatusContextInfo(existing, options = {}) {
|
|
65
|
+
const base = existing && typeof existing === 'object' ? { ...existing } : {};
|
|
66
|
+
const built = buildGroupStatusContextInfo(options);
|
|
67
|
+
return {
|
|
68
|
+
...base,
|
|
69
|
+
...built,
|
|
70
|
+
...(base.externalAdReply ? { externalAdReply: base.externalAdReply } : {}),
|
|
71
|
+
...(base.quotedMessage ? { quotedMessage: base.quotedMessage } : {}),
|
|
72
|
+
...(base.mentionedJid ? { mentionedJid: base.mentionedJid } : {})
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function parseArgb(value, fallback = 0xff23313a) {
|
|
77
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value >>> 0;
|
|
78
|
+
if (typeof value === 'string') {
|
|
79
|
+
const hex = value.replace(/^#/, '');
|
|
80
|
+
if (/^[0-9a-fA-F]{6}$/.test(hex)) return (0xff000000 | parseInt(hex, 16)) >>> 0;
|
|
81
|
+
if (/^[0-9a-fA-F]{8}$/.test(hex)) return parseInt(hex, 16) >>> 0;
|
|
82
|
+
}
|
|
83
|
+
return fallback >>> 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function buildGroupStatusMessage(sock, groupJid, content = {}, options = {}) {
|
|
87
|
+
if (!groupJid || !String(groupJid).endsWith('@g.us')) {
|
|
88
|
+
throw new TypeError('groupJid must be a group JID ending with @g.us');
|
|
89
|
+
}
|
|
90
|
+
const senderJid = jidNormalizedUser(sock.user?.id);
|
|
91
|
+
const contextInfo = mergeStatusContextInfo(content.contextInfo, options);
|
|
92
|
+
const backgroundArgb = parseArgb(content.backgroundColor || content.backgroundArgb || options.backgroundColor);
|
|
93
|
+
const font = content.font ?? options.font ?? 1;
|
|
94
|
+
|
|
95
|
+
let inner;
|
|
96
|
+
if (content.image || content.video || content.audio || content.sticker) {
|
|
97
|
+
const upload = sock.waUploadToServer;
|
|
98
|
+
let mediaInput = {};
|
|
99
|
+
let key = 'imageMessage';
|
|
100
|
+
if (content.image) {
|
|
101
|
+
mediaInput = { image: content.image, caption: content.caption };
|
|
102
|
+
key = 'imageMessage';
|
|
103
|
+
} else if (content.video) {
|
|
104
|
+
mediaInput = { video: content.video, caption: content.caption };
|
|
105
|
+
key = 'videoMessage';
|
|
106
|
+
} else if (content.audio) {
|
|
107
|
+
mediaInput = {
|
|
108
|
+
audio: content.audio,
|
|
109
|
+
mimetype: content.mimetype || 'audio/ogg; codecs=opus',
|
|
110
|
+
ptt: content.ptt !== false
|
|
111
|
+
};
|
|
112
|
+
key = 'audioMessage';
|
|
113
|
+
} else if (content.sticker) {
|
|
114
|
+
mediaInput = { sticker: content.sticker };
|
|
115
|
+
key = 'stickerMessage';
|
|
116
|
+
}
|
|
117
|
+
const prepared = await prepareWAMessageMedia(mediaInput, {
|
|
118
|
+
upload,
|
|
119
|
+
logger: sock.logger,
|
|
120
|
+
mediaUploadTimeoutMs: options.mediaUploadTimeoutMs
|
|
121
|
+
});
|
|
122
|
+
const mediaMsg = prepared[key];
|
|
123
|
+
if (mediaMsg) {
|
|
124
|
+
mediaMsg.contextInfo = contextInfo;
|
|
125
|
+
if (key === 'audioMessage') mediaMsg.backgroundArgb = backgroundArgb;
|
|
126
|
+
}
|
|
127
|
+
inner = prepared;
|
|
128
|
+
} else {
|
|
129
|
+
const text = content.text || content.caption || '';
|
|
130
|
+
if (!text) throw new TypeError('Group status needs text or media content');
|
|
131
|
+
inner = {
|
|
132
|
+
extendedTextMessage: {
|
|
133
|
+
text,
|
|
134
|
+
font,
|
|
135
|
+
backgroundArgb,
|
|
136
|
+
contextInfo
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const messageContent = { groupStatusMessageV2: { message: inner } };
|
|
142
|
+
const generated = generateWAMessageFromContent(groupJid, messageContent, {
|
|
143
|
+
userJid: senderJid,
|
|
144
|
+
messageId: options.messageId || generateMessageIDV2(sock.user?.id)
|
|
145
|
+
});
|
|
146
|
+
return generated;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function sendGroupStatusMessage(sock, groupJid, content = {}, options = {}) {
|
|
150
|
+
const generated = await buildGroupStatusMessage(sock, groupJid, content, options);
|
|
151
|
+
await sock.relayMessage(groupJid, generated.message, { messageId: generated.key.id });
|
|
152
|
+
return generated;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export async function sendGroupStatusMessageClosefriends(sock, groupJid, content = {}, options = {}) {
|
|
156
|
+
return sendGroupStatusMessage(sock, groupJid, content, {
|
|
157
|
+
...options,
|
|
158
|
+
ringName: options.ringName || 'Close Friends',
|
|
159
|
+
ringEmoji: options.ringEmoji || '💜',
|
|
160
|
+
ringColor: options.ringColor || 'purple',
|
|
161
|
+
audienceType: options.audienceType ?? 2
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function sendStatus(sock, content = {}, options = {}) {
|
|
166
|
+
const statusJidList = options.statusJidList || content.statusJidList;
|
|
167
|
+
if (!Array.isArray(statusJidList) || statusJidList.length === 0) {
|
|
168
|
+
throw new TypeError('sendStatus requires options.statusJidList (array of contact JIDs)');
|
|
169
|
+
}
|
|
170
|
+
const payload = { ...content };
|
|
171
|
+
delete payload.statusJidList;
|
|
172
|
+
return sock.sendMessage('status@broadcast', payload, {
|
|
173
|
+
...options,
|
|
174
|
+
statusJidList,
|
|
175
|
+
backgroundColor: options.backgroundColor || content.backgroundColor,
|
|
176
|
+
font: options.font ?? content.font
|
|
177
|
+
});
|
|
178
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const ASSOCIATION_TYPE_STICKER_REACTION = 11;
|
|
2
|
+
|
|
3
|
+
function asBuffer(value) {
|
|
4
|
+
if (Buffer.isBuffer(value)) return value;
|
|
5
|
+
if (value instanceof Uint8Array) return Buffer.from(value);
|
|
6
|
+
if (value && value.type === 'Buffer' && Array.isArray(value.data)) return Buffer.from(value.data);
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function reviveBuffers(value) {
|
|
11
|
+
if (Buffer.isBuffer(value) || value instanceof Uint8Array) return value;
|
|
12
|
+
if (!value || typeof value !== 'object') return value;
|
|
13
|
+
if (value.type === 'Buffer' && Array.isArray(value.data)) return Buffer.from(value.data);
|
|
14
|
+
if (Array.isArray(value)) return value.map(reviveBuffers);
|
|
15
|
+
const out = {};
|
|
16
|
+
for (const key of Object.keys(value)) out[key] = reviveBuffers(value[key]);
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function extractStickerMessage(source) {
|
|
21
|
+
if (!source) return null;
|
|
22
|
+
const message = source.message || source;
|
|
23
|
+
return (
|
|
24
|
+
message.stickerMessage ||
|
|
25
|
+
message.lottieStickerMessage ||
|
|
26
|
+
source.stickerMessage ||
|
|
27
|
+
source.lottieStickerMessage ||
|
|
28
|
+
(source.mtype === 'stickerMessage' || source.mtype === 'lottieStickerMessage' ? source : null)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function buildStickerReactionPayload(parentMessageKey, stickerMessage) {
|
|
33
|
+
if (!parentMessageKey || typeof parentMessageKey !== 'object' || !parentMessageKey.id) {
|
|
34
|
+
throw new TypeError('parentMessageKey with an id is required');
|
|
35
|
+
}
|
|
36
|
+
if (!stickerMessage || typeof stickerMessage !== 'object') {
|
|
37
|
+
throw new TypeError('stickerMessage is required');
|
|
38
|
+
}
|
|
39
|
+
const sticker = reviveBuffers(stickerMessage);
|
|
40
|
+
const isLottie = sticker.isLottie === true || sticker.mimetype === 'application/was';
|
|
41
|
+
const payload = {
|
|
42
|
+
messageContextInfo: {
|
|
43
|
+
messageAssociation: {
|
|
44
|
+
associationType: ASSOCIATION_TYPE_STICKER_REACTION,
|
|
45
|
+
parentMessageKey: {
|
|
46
|
+
remoteJid: parentMessageKey.remoteJid,
|
|
47
|
+
fromMe: !!parentMessageKey.fromMe,
|
|
48
|
+
id: parentMessageKey.id,
|
|
49
|
+
...(parentMessageKey.participant ? { participant: parentMessageKey.participant } : {}),
|
|
50
|
+
...(parentMessageKey.participantPn ? { participantPn: parentMessageKey.participantPn } : {}),
|
|
51
|
+
...(parentMessageKey.participantAlt ? { participantAlt: parentMessageKey.participantAlt } : {})
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
if (isLottie) {
|
|
57
|
+
payload.lottieStickerMessage = { ...sticker };
|
|
58
|
+
} else {
|
|
59
|
+
payload.stickerMessage = { ...sticker };
|
|
60
|
+
}
|
|
61
|
+
return payload;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function sendStickerReaction(sock, jid, parentMessageKey, sticker, options = {}) {
|
|
65
|
+
if (!sock || typeof sock.relayMessage !== 'function') {
|
|
66
|
+
throw new TypeError('socket must support relayMessage');
|
|
67
|
+
}
|
|
68
|
+
if (!jid) throw new TypeError('destination jid is required');
|
|
69
|
+
const stickerMessage = extractStickerMessage(sticker) || sticker;
|
|
70
|
+
const payload = buildStickerReactionPayload(parentMessageKey, stickerMessage);
|
|
71
|
+
const count = Math.max(1, Math.min(Number(options.count) || 1, 10));
|
|
72
|
+
const delayMs = Number(options.delayMs) || 250;
|
|
73
|
+
const results = [];
|
|
74
|
+
for (let i = 0; i < count; i += 1) {
|
|
75
|
+
const id = await sock.relayMessage(jid, payload, {
|
|
76
|
+
messageId: options.messageId,
|
|
77
|
+
...(options.additionalAttributes ? { additionalAttributes: options.additionalAttributes } : {})
|
|
78
|
+
});
|
|
79
|
+
results.push(id);
|
|
80
|
+
if (i + 1 < count && delayMs > 0) {
|
|
81
|
+
await new Promise(r => setTimeout(r, delayMs));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return count === 1 ? results[0] : results;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function isStickerReactionMessage(message, referenceSticker) {
|
|
88
|
+
const sticker = extractStickerMessage(message);
|
|
89
|
+
if (!sticker) return false;
|
|
90
|
+
const association = message?.messageContextInfo?.messageAssociation
|
|
91
|
+
|| message?.message?.messageContextInfo?.messageAssociation;
|
|
92
|
+
if (association && association.associationType === ASSOCIATION_TYPE_STICKER_REACTION) return true;
|
|
93
|
+
if (!referenceSticker) return false;
|
|
94
|
+
const ref = extractStickerMessage(referenceSticker) || referenceSticker;
|
|
95
|
+
if (ref.fileSha256 && (sticker.fileSha256 === ref.fileSha256 || asBuffer(sticker.fileSha256)?.equals(asBuffer(ref.fileSha256) || Buffer.alloc(0)))) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
if (ref.fileEncSha256 && (sticker.fileEncSha256 === ref.fileEncSha256 || asBuffer(sticker.fileEncSha256)?.equals(asBuffer(ref.fileEncSha256) || Buffer.alloc(0)))) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
return sticker.mimetype === 'application/was' && sticker.isLottie === true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { ASSOCIATION_TYPE_STICKER_REACTION };
|