jagproject 26.3.23 → 26.3.26
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/WAProto/GenerateStatics.sh +3 -4
- package/WAProto/WAProto.proto +1215 -511
- package/WAProto/fix-imports.js +73 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +64857 -145167
- package/engine-requirements.js +4 -7
- package/lib/Defaults/index.d.ts +74 -0
- package/lib/Defaults/index.js +49 -35
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/wileys-version.json +2 -2
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +5 -3
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +35 -46
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +21 -21
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +2 -2
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +5 -10
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +8 -8
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +7 -16
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +25 -37
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +358 -54
- package/lib/Signal/lid-mapping.d.ts +19 -0
- package/lib/Signal/lid-mapping.js +274 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +2 -2
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +18 -30
- package/lib/Socket/business.d.ts +202 -0
- package/lib/Socket/business.js +160 -38
- package/lib/Socket/chats.d.ts +111 -0
- package/lib/Socket/chats.js +497 -314
- package/lib/Socket/communities.d.ts +258 -0
- package/lib/Socket/communities.js +438 -0
- package/lib/Socket/community.js +333 -0
- package/lib/Socket/groups.d.ts +150 -0
- package/lib/Socket/groups.js +229 -91
- package/lib/Socket/index.d.ts +245 -0
- package/lib/Socket/index.js +9 -6
- package/lib/Socket/messages-recv.d.ts +187 -0
- package/lib/Socket/messages-recv.js +1105 -501
- package/lib/Socket/messages-send.d.ts +183 -0
- package/lib/Socket/messages-send.js +1181 -501
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.d.ts +160 -0
- package/lib/Socket/newsletter.js +227 -200
- package/lib/Socket/socket.d.ts +55 -0
- package/lib/Socket/socket.js +507 -206
- package/lib/Socket/usync.js +6 -6
- package/lib/Store/index.js +17 -5
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.js +48 -89
- package/lib/Store/make-ordered-dictionary.js +1 -1
- package/lib/Types/Auth.d.ts +116 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Events.d.ts +237 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +1 -3
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +1 -3
- package/lib/Types/Message.d.ts +305 -0
- package/lib/Types/Message.js +9 -5
- package/lib/Types/MexUpdates.js +11 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.js +36 -11
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/State.js +12 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.js +14 -14
- package/lib/Utils/audioToBuffer.js +31 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/auth-utils.js +222 -123
- package/lib/Utils/baileys-event-stream.js +60 -0
- package/lib/Utils/bridge-runtime.d.ts +1 -0
- package/lib/Utils/bridge-runtime.js +14 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +38 -29
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +54 -48
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +284 -189
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +16 -41
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.js +128 -48
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/event-buffer.js +124 -62
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.js +154 -138
- package/lib/Utils/history.d.ts +22 -0
- package/lib/Utils/history.js +77 -34
- package/lib/Utils/identity-change-handler.d.ts +37 -0
- package/lib/Utils/identity-change-handler.js +54 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.js +32 -19
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +12 -17
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +2 -43
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +21 -27
- package/lib/Utils/message-retry-manager.d.ts +110 -0
- package/lib/Utils/message-retry-manager.js +143 -45
- package/lib/Utils/messages-media.d.ts +130 -0
- package/lib/Utils/messages-media.js +429 -502
- package/lib/Utils/messages-newsletter.d.ts +84 -0
- package/lib/Utils/messages-newsletter.js +295 -0
- package/lib/Utils/messages.d.ts +92 -0
- package/lib/Utils/messages.js +1025 -674
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +145 -91
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +112 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +316 -184
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +262 -0
- package/lib/Utils/resolve-jid.d.ts +43 -0
- package/lib/Utils/resolve-jid.js +95 -0
- package/lib/Utils/rust-bridge-shim.d.ts +22 -0
- package/lib/Utils/rust-bridge-shim.js +70 -0
- package/lib/Utils/serial-task-queue.js +29 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/signal.js +56 -39
- package/lib/Utils/streamToBuffer.js +17 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +52 -0
- package/lib/Utils/tc-token-utils.d.ts +12 -0
- package/lib/Utils/tc-token-utils.js +20 -0
- package/lib/Utils/use-mongo-file-auth-state.js +71 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +11 -12
- package/lib/Utils/use-single-file-auth-state.js +73 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +59 -82
- package/lib/Utils/wileys-event-stream.js +1 -61
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +39 -4
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +17 -11
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +46 -18
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +9 -5
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +67 -37
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +34 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +19183 -11678
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +15 -17
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -6
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -6
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -8
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +18 -17
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +6 -4
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncQuery.js +38 -30
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.d.ts +12 -0
- package/lib/index.js +3 -5
- package/package.json +7 -4
- package/LICENSE +0 -21
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import type { WAMessageContent, WAMessageKey } from '../Types/index.js';
|
|
3
|
+
import type { BinaryNode } from '../WABinary/index.js';
|
|
4
|
+
export type ReportingField = {
|
|
5
|
+
f: number;
|
|
6
|
+
m?: boolean;
|
|
7
|
+
s?: ReportingField[];
|
|
8
|
+
};
|
|
9
|
+
export declare const shouldIncludeReportingToken: (message: proto.IMessage) => boolean;
|
|
10
|
+
export declare const getMessageReportingToken: (msgProtobuf: Buffer, message: WAMessageContent, key: WAMessageKey) => Promise<BinaryNode | null>;
|
|
11
|
+
//# sourceMappingURL=reporting-utils.d.ts.map
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMessageReportingToken = exports.shouldIncludeReportingToken = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
6
|
+
const crypto_js_1 = require("./crypto.js");
|
|
7
|
+
const reportingFields = [
|
|
8
|
+
{ f: 1 },
|
|
9
|
+
{
|
|
10
|
+
f: 3,
|
|
11
|
+
s: [{ f: 2 }, { f: 3 }, { f: 8 }, { f: 11 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 25 }]
|
|
12
|
+
},
|
|
13
|
+
{ f: 4, s: [{ f: 1 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
|
|
14
|
+
{ f: 5, s: [{ f: 3 }, { f: 4 }, { f: 5 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
|
|
15
|
+
{ f: 6, s: [{ f: 1 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 30 }] },
|
|
16
|
+
{ f: 7, s: [{ f: 2 }, { f: 7 }, { f: 10 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
|
|
17
|
+
{ f: 8, s: [{ f: 2 }, { f: 7 }, { f: 9 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 21 }] },
|
|
18
|
+
{ f: 9, s: [{ f: 2 }, { f: 6 }, { f: 7 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
|
|
19
|
+
{ f: 12, s: [{ f: 1 }, { f: 2 }, { f: 14, m: true }, { f: 15 }] },
|
|
20
|
+
{ f: 18, s: [{ f: 6 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
|
|
21
|
+
{ f: 26, s: [{ f: 4 }, { f: 5 }, { f: 8 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
|
|
22
|
+
{ f: 28, s: [{ f: 1 }, { f: 2 }, { f: 4 }, { f: 5 }, { f: 6 }, { f: 7, s: [{ f: 21 }, { f: 22 }] }] },
|
|
23
|
+
{ f: 37, s: [{ f: 1, m: true }] },
|
|
24
|
+
{
|
|
25
|
+
f: 49,
|
|
26
|
+
s: [
|
|
27
|
+
{ f: 2 },
|
|
28
|
+
{ f: 3, s: [{ f: 1 }, { f: 2 }] },
|
|
29
|
+
{ f: 5, s: [{ f: 21 }, { f: 22 }] },
|
|
30
|
+
{ f: 8, s: [{ f: 1 }, { f: 2 }] }
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{ f: 53, s: [{ f: 1, m: true }] },
|
|
34
|
+
{ f: 55, s: [{ f: 1, m: true }] },
|
|
35
|
+
{ f: 58, s: [{ f: 1, m: true }] },
|
|
36
|
+
{ f: 59, s: [{ f: 1, m: true }] },
|
|
37
|
+
{
|
|
38
|
+
f: 60,
|
|
39
|
+
s: [
|
|
40
|
+
{ f: 2 },
|
|
41
|
+
{ f: 3, s: [{ f: 1 }, { f: 2 }] },
|
|
42
|
+
{ f: 5, s: [{ f: 21 }, { f: 22 }] },
|
|
43
|
+
{ f: 8, s: [{ f: 1 }, { f: 2 }] }
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
f: 64,
|
|
48
|
+
s: [
|
|
49
|
+
{ f: 2 },
|
|
50
|
+
{ f: 3, s: [{ f: 1 }, { f: 2 }] },
|
|
51
|
+
{ f: 5, s: [{ f: 21 }, { f: 22 }] },
|
|
52
|
+
{ f: 8, s: [{ f: 1 }, { f: 2 }] }
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
{ f: 66, s: [{ f: 2 }, { f: 6 }, { f: 7 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
|
|
56
|
+
{ f: 74, s: [{ f: 1, m: true }] },
|
|
57
|
+
{ f: 87, s: [{ f: 1, m: true }] },
|
|
58
|
+
{ f: 88, s: [{ f: 1 }, { f: 2, s: [{ f: 1 }] }, { f: 3, s: [{ f: 21 }, { f: 22 }] }] },
|
|
59
|
+
{ f: 92, s: [{ f: 1, m: true }] },
|
|
60
|
+
{ f: 93, s: [{ f: 1, m: true }] },
|
|
61
|
+
{ f: 94, s: [{ f: 1, m: true }] }
|
|
62
|
+
];
|
|
63
|
+
const compileReportingFields = (fields) => {
|
|
64
|
+
const map = new Map();
|
|
65
|
+
for (const f of fields) {
|
|
66
|
+
map.set(f.f, {
|
|
67
|
+
m: f.m,
|
|
68
|
+
children: f.s ? compileReportingFields(f.s) : undefined
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return map;
|
|
72
|
+
};
|
|
73
|
+
const compiledReportingFields = compileReportingFields(reportingFields);
|
|
74
|
+
const EMPTY_MAP = new Map();
|
|
75
|
+
const ENC_SECRET_REPORT_TOKEN = 'Report Token';
|
|
76
|
+
const WIRE = {
|
|
77
|
+
VARINT: 0,
|
|
78
|
+
FIXED64: 1,
|
|
79
|
+
BYTES: 2,
|
|
80
|
+
FIXED32: 5
|
|
81
|
+
};
|
|
82
|
+
const shouldIncludeReportingToken = (message) => !message.reactionMessage &&
|
|
83
|
+
!message.encReactionMessage &&
|
|
84
|
+
!message.encEventResponseMessage &&
|
|
85
|
+
!message.pollUpdateMessage;
|
|
86
|
+
exports.shouldIncludeReportingToken = shouldIncludeReportingToken;
|
|
87
|
+
const generateMsgSecretKey = (modificationType, origMsgId, origMsgSender, modificationSender, origMsgSecret) => {
|
|
88
|
+
const useCaseSecret = Buffer.concat([
|
|
89
|
+
Buffer.from(origMsgId, 'utf8'),
|
|
90
|
+
Buffer.from(origMsgSender, 'utf8'),
|
|
91
|
+
Buffer.from(modificationSender, 'utf8'),
|
|
92
|
+
Buffer.from(modificationType, 'utf8')
|
|
93
|
+
]);
|
|
94
|
+
return (0, crypto_js_1.hkdf)(origMsgSecret, 32, { info: useCaseSecret.toString('latin1') });
|
|
95
|
+
};
|
|
96
|
+
const extractReportingTokenContent = (data, cfg) => {
|
|
97
|
+
const out = [];
|
|
98
|
+
let i = 0;
|
|
99
|
+
while (i < data.length) {
|
|
100
|
+
const tag = decodeVarint(data, i);
|
|
101
|
+
if (!tag.ok) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const fieldNum = tag.value >> 3;
|
|
105
|
+
const wireType = tag.value & 0x7;
|
|
106
|
+
const fieldStart = i;
|
|
107
|
+
i += tag.bytes;
|
|
108
|
+
const fieldCfg = cfg.get(fieldNum);
|
|
109
|
+
const pushSlice = (end) => {
|
|
110
|
+
if (end > data.length) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
out.push({ num: fieldNum, bytes: data.subarray(fieldStart, end) });
|
|
114
|
+
i = end;
|
|
115
|
+
return true;
|
|
116
|
+
};
|
|
117
|
+
const skip = (end) => {
|
|
118
|
+
if (end > data.length) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
i = end;
|
|
122
|
+
return true;
|
|
123
|
+
};
|
|
124
|
+
if (wireType === WIRE.VARINT) {
|
|
125
|
+
const v = decodeVarint(data, i);
|
|
126
|
+
if (!v.ok) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const end = i + v.bytes;
|
|
130
|
+
if (!fieldCfg) {
|
|
131
|
+
if (!skip(end)) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (!pushSlice(end)) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (wireType === WIRE.FIXED64) {
|
|
142
|
+
const end = i + 8;
|
|
143
|
+
if (!fieldCfg) {
|
|
144
|
+
if (!skip(end)) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (!pushSlice(end)) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (wireType === WIRE.FIXED32) {
|
|
155
|
+
const end = i + 4;
|
|
156
|
+
if (!fieldCfg) {
|
|
157
|
+
if (!skip(end)) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (!pushSlice(end)) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (wireType === WIRE.BYTES) {
|
|
168
|
+
const len = decodeVarint(data, i);
|
|
169
|
+
if (!len.ok) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
const valStart = i + len.bytes;
|
|
173
|
+
const valEnd = valStart + len.value;
|
|
174
|
+
if (valEnd > data.length) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
if (!fieldCfg) {
|
|
178
|
+
i = valEnd;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (fieldCfg.m || fieldCfg.children) {
|
|
182
|
+
const sub = extractReportingTokenContent(data.subarray(valStart, valEnd), fieldCfg.children ?? EMPTY_MAP);
|
|
183
|
+
if (sub === null) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
if (sub.length > 0) {
|
|
187
|
+
const newTag = encodeVarint(tag.value);
|
|
188
|
+
const newLen = encodeVarint(sub.length);
|
|
189
|
+
out.push({
|
|
190
|
+
num: fieldNum,
|
|
191
|
+
bytes: Buffer.concat([newTag, newLen, sub])
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
i = valEnd;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
out.push({ num: fieldNum, bytes: data.subarray(fieldStart, valEnd) });
|
|
198
|
+
i = valEnd;
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
if (out.length === 0) {
|
|
204
|
+
return Buffer.alloc(0);
|
|
205
|
+
}
|
|
206
|
+
out.sort((a, b) => a.num - b.num);
|
|
207
|
+
return Buffer.concat(out.map(f => f.bytes));
|
|
208
|
+
};
|
|
209
|
+
const decodeVarint = (buffer, offset) => {
|
|
210
|
+
let value = 0;
|
|
211
|
+
let bytes = 0;
|
|
212
|
+
let shift = 0;
|
|
213
|
+
while (offset + bytes < buffer.length) {
|
|
214
|
+
const current = buffer[offset + bytes];
|
|
215
|
+
value |= (current & 0x7f) << shift;
|
|
216
|
+
bytes++;
|
|
217
|
+
if ((current & 0x80) === 0) {
|
|
218
|
+
return { value, bytes, ok: true };
|
|
219
|
+
}
|
|
220
|
+
shift += 7;
|
|
221
|
+
if (shift > 35) {
|
|
222
|
+
return { value: 0, bytes: 0, ok: false };
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return { value: 0, bytes: 0, ok: false };
|
|
226
|
+
};
|
|
227
|
+
const encodeVarint = (value) => {
|
|
228
|
+
const parts = [];
|
|
229
|
+
let remaining = value >>> 0;
|
|
230
|
+
while (remaining > 0x7f) {
|
|
231
|
+
parts.push((remaining & 0x7f) | 0x80);
|
|
232
|
+
remaining >>>= 7;
|
|
233
|
+
}
|
|
234
|
+
parts.push(remaining);
|
|
235
|
+
return Buffer.from(parts);
|
|
236
|
+
};
|
|
237
|
+
const getMessageReportingToken = async (msgProtobuf, message, key) => {
|
|
238
|
+
const msgSecret = message.messageContextInfo?.messageSecret;
|
|
239
|
+
if (!msgSecret || !key.id) {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
const from = key.fromMe ? key.remoteJid : key.participant || key.remoteJid;
|
|
243
|
+
const to = key.fromMe ? key.participant || key.remoteJid : key.remoteJid;
|
|
244
|
+
const reportingSecret = generateMsgSecretKey(ENC_SECRET_REPORT_TOKEN, key.id, from, to, msgSecret);
|
|
245
|
+
const content = extractReportingTokenContent(msgProtobuf, compiledReportingFields);
|
|
246
|
+
if (!content || content.length === 0) {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
const reportingToken = (0, crypto_1.createHmac)('sha256', reportingSecret).update(content).digest().subarray(0, 16);
|
|
250
|
+
return {
|
|
251
|
+
tag: 'reporting',
|
|
252
|
+
attrs: {},
|
|
253
|
+
content: [
|
|
254
|
+
{
|
|
255
|
+
tag: 'reporting_token',
|
|
256
|
+
attrs: { v: '2' },
|
|
257
|
+
content: reportingToken
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
exports.getMessageReportingToken = getMessageReportingToken;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { WASocket } from '../Types/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolve LID / mention JID / participant ID menjadi JID @s.whatsapp.net.
|
|
5
|
+
*
|
|
6
|
+
* @param conn WASocket instance
|
|
7
|
+
* @param m serialized message object (dari handler)
|
|
8
|
+
* @param target JID/LID eksplisit, opsional (override dari m)
|
|
9
|
+
* @returns JID @s.whatsapp.net atau null jika tidak bisa di-resolve
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const jid = await resolveJid(conn, m);
|
|
13
|
+
* if (!jid) return conn.sendMessage(m.chat, { text: 'Gagal resolve JID' });
|
|
14
|
+
* await conn.sendMessage(m.chat, { text: `JID: ${jid}` });
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Resolve dari mention pertama
|
|
18
|
+
* const jid = await resolveJid(conn, m, m.mentionedJid?.[0]);
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveJid(
|
|
21
|
+
conn: WASocket,
|
|
22
|
+
m: {
|
|
23
|
+
sender?: string;
|
|
24
|
+
jid?: string;
|
|
25
|
+
chat?: string;
|
|
26
|
+
isGroup?: boolean;
|
|
27
|
+
mentionedJid?: string[];
|
|
28
|
+
quoted?: { sender?: string; participant?: string };
|
|
29
|
+
},
|
|
30
|
+
target?: string | null
|
|
31
|
+
): Promise<string | null>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Resolve banyak JID/LID sekaligus.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const jids = await resolveJids(conn, m, m.mentionedJid);
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveJids(
|
|
40
|
+
conn: WASocket,
|
|
41
|
+
m: Parameters<typeof resolveJid>[1],
|
|
42
|
+
targets?: string[]
|
|
43
|
+
): Promise<(string | null)[]>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* resolve-jid.js
|
|
4
|
+
* Resolve LID / participant ID menjadi JID WhatsApp asli (@s.whatsapp.net).
|
|
5
|
+
*
|
|
6
|
+
* Berguna saat participant.jid di grup adalah format @lid,
|
|
7
|
+
* dan kamu butuh nomor WA aslinya.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.resolveJid = resolveJid;
|
|
11
|
+
exports.resolveJids = resolveJids;
|
|
12
|
+
const index_js_1 = require("../WABinary/index.js");
|
|
13
|
+
/**
|
|
14
|
+
* Resolve LID, mention JID, atau sender menjadi JID @s.whatsapp.net.
|
|
15
|
+
*
|
|
16
|
+
* @param {import('../Types').WASocket} conn
|
|
17
|
+
* @param {object} m — serialized message object
|
|
18
|
+
* @param {string} [target] — JID/LID eksplisit (opsional, override otomatis)
|
|
19
|
+
* @returns {Promise<string|null>}
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Di dalam handler:
|
|
23
|
+
* const jid = await resolveJid(conn, m);
|
|
24
|
+
* if (!jid) return conn.sendMessage(m.chat, { text: 'Tidak bisa resolve JID' });
|
|
25
|
+
* await conn.sendMessage(m.chat, { text: `JID: ${jid}` });
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Dengan target eksplisit (misalnya dari mention):
|
|
29
|
+
* const jid = await resolveJid(conn, m, m.mentionedJid?.[0]);
|
|
30
|
+
*/
|
|
31
|
+
async function resolveJid(conn, m, target) {
|
|
32
|
+
// Tentukan input — prioritas: target > mention > quoted sender > sender
|
|
33
|
+
const input = target ||
|
|
34
|
+
(m.mentionedJid && m.mentionedJid[0]) ||
|
|
35
|
+
(m.quoted && (m.quoted.sender || m.quoted.participant)) ||
|
|
36
|
+
m.sender ||
|
|
37
|
+
m.jid;
|
|
38
|
+
if (!input)
|
|
39
|
+
return null;
|
|
40
|
+
// Sudah berbentuk JID normal → langsung return
|
|
41
|
+
if (/@s\.whatsapp\.net$/.test(input)) {
|
|
42
|
+
return (0, index_js_1.jidNormalizedUser)(input);
|
|
43
|
+
}
|
|
44
|
+
// Jika bukan di grup, tidak bisa resolve LID via groupMetadata
|
|
45
|
+
if (!m.isGroup || !m.chat) {
|
|
46
|
+
// Coba normalise saja (untuk kasus user JID tanpa domain)
|
|
47
|
+
if (/^\d+$/.test(input.split('@')[0])) {
|
|
48
|
+
return `${input.split('@')[0]}@s.whatsapp.net`;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
let meta;
|
|
53
|
+
try {
|
|
54
|
+
meta = await conn.groupMetadata(m.chat);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
if (!meta || !Array.isArray(meta.participants))
|
|
60
|
+
return null;
|
|
61
|
+
// Cari match di participants: by jid, id, lid, atau user number
|
|
62
|
+
const inputUser = input.split('@')[0];
|
|
63
|
+
const participant = meta.participants.find(p => {
|
|
64
|
+
if (!p)
|
|
65
|
+
return false;
|
|
66
|
+
const pJid = p.jid || p.id || '';
|
|
67
|
+
const pLid = p.lid || '';
|
|
68
|
+
return (pJid === input ||
|
|
69
|
+
pLid === input ||
|
|
70
|
+
pJid.split('@')[0] === inputUser ||
|
|
71
|
+
pLid.split('@')[0] === inputUser);
|
|
72
|
+
});
|
|
73
|
+
if (participant) {
|
|
74
|
+
// Return JID yang sudah pasti @s.whatsapp.net
|
|
75
|
+
const resolved = participant.jid || participant.id;
|
|
76
|
+
if (resolved && /@s\.whatsapp\.net$/.test(resolved)) {
|
|
77
|
+
return (0, index_js_1.jidNormalizedUser)(resolved);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Resolve banyak JID/LID sekaligus.
|
|
84
|
+
*
|
|
85
|
+
* @param {import('../Types').WASocket} conn
|
|
86
|
+
* @param {object} m
|
|
87
|
+
* @param {string[]} targets
|
|
88
|
+
* @returns {Promise<(string|null)[]>}
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* const jids = await resolveJids(conn, m, m.mentionedJid);
|
|
92
|
+
*/
|
|
93
|
+
async function resolveJids(conn, m, targets = []) {
|
|
94
|
+
return Promise.all(targets.map(t => resolveJid(conn, m, t)));
|
|
95
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type HKDFOptions = {
|
|
2
|
+
salt?: Uint8Array | Buffer | string;
|
|
3
|
+
info?: Uint8Array | Buffer | string;
|
|
4
|
+
};
|
|
5
|
+
export declare function md5(data: Uint8Array | Buffer | string): Buffer;
|
|
6
|
+
export declare function hkdf(key: Uint8Array | Buffer | string, length: number, options?: HKDFOptions): Buffer;
|
|
7
|
+
export declare function expandAppStateKeys(keyData: Uint8Array | Buffer | string): {
|
|
8
|
+
indexKey: Buffer;
|
|
9
|
+
valueEncryptionKey: Buffer;
|
|
10
|
+
valueMacKey: Buffer;
|
|
11
|
+
snapshotMacKey: Buffer;
|
|
12
|
+
patchMacKey: Buffer;
|
|
13
|
+
};
|
|
14
|
+
export declare class LTHashAntiTampering {
|
|
15
|
+
private readonly info;
|
|
16
|
+
private readonly size;
|
|
17
|
+
constructor(info?: string | Uint8Array | Buffer, size?: number);
|
|
18
|
+
subtractThenAdd(base: Uint8Array | Buffer, subtract?: Array<Uint8Array | Buffer>, add?: Array<Uint8Array | Buffer>): Buffer;
|
|
19
|
+
subtractThenAddInPlace(base: Buffer, subtract?: Array<Uint8Array | Buffer>, add?: Array<Uint8Array | Buffer>): Buffer;
|
|
20
|
+
private multipleOp;
|
|
21
|
+
private performPointwiseWithOverflow;
|
|
22
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LTHashAntiTampering = void 0;
|
|
4
|
+
exports.md5 = md5;
|
|
5
|
+
exports.hkdf = hkdf;
|
|
6
|
+
exports.expandAppStateKeys = expandAppStateKeys;
|
|
7
|
+
const crypto_1 = require("crypto");
|
|
8
|
+
function toBuffer(input) {
|
|
9
|
+
if (Buffer.isBuffer(input)) return input;
|
|
10
|
+
if (input instanceof Uint8Array) return Buffer.from(input);
|
|
11
|
+
if (ArrayBuffer.isView(input)) return Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
|
12
|
+
if (input instanceof ArrayBuffer) return Buffer.from(input);
|
|
13
|
+
if (typeof input === "string") return Buffer.from(input);
|
|
14
|
+
return Buffer.from(input || []);
|
|
15
|
+
}
|
|
16
|
+
function normalizeHkdfOptions(options = {}) {
|
|
17
|
+
const salt = options.salt == null ? Buffer.alloc(0) : toBuffer(options.salt);
|
|
18
|
+
const info = options.info == null ? Buffer.alloc(0) : toBuffer(options.info);
|
|
19
|
+
return { salt, info };
|
|
20
|
+
}
|
|
21
|
+
function md5(data) {
|
|
22
|
+
return (0, crypto_1.createHash)("md5").update(toBuffer(data)).digest();
|
|
23
|
+
}
|
|
24
|
+
function hkdf(key, length, options = {}) {
|
|
25
|
+
const { salt, info } = normalizeHkdfOptions(options);
|
|
26
|
+
const out = crypto_1.hkdfSync("sha256", toBuffer(key), salt, info, length);
|
|
27
|
+
return Buffer.from(out);
|
|
28
|
+
}
|
|
29
|
+
function expandAppStateKeys(keyData) {
|
|
30
|
+
const expanded = hkdf(toBuffer(keyData), 160, { info: "WhatsApp Mutation Keys" });
|
|
31
|
+
return {
|
|
32
|
+
indexKey: expanded.subarray(0, 32),
|
|
33
|
+
valueEncryptionKey: expanded.subarray(32, 64),
|
|
34
|
+
valueMacKey: expanded.subarray(64, 96),
|
|
35
|
+
snapshotMacKey: expanded.subarray(96, 128),
|
|
36
|
+
patchMacKey: expanded.subarray(128, 160)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
class LTHashAntiTampering {
|
|
40
|
+
constructor(info = "WhatsApp Patch Integrity", size = 128) {
|
|
41
|
+
this.info = toBuffer(info);
|
|
42
|
+
this.size = size;
|
|
43
|
+
}
|
|
44
|
+
subtractThenAdd(base, subtract = [], add = []) {
|
|
45
|
+
const output = Buffer.from(toBuffer(base));
|
|
46
|
+
this.subtractThenAddInPlace(output, subtract, add);
|
|
47
|
+
return output;
|
|
48
|
+
}
|
|
49
|
+
subtractThenAddInPlace(base, subtract = [], add = []) {
|
|
50
|
+
this.multipleOp(base, subtract, true);
|
|
51
|
+
this.multipleOp(base, add, false);
|
|
52
|
+
return base;
|
|
53
|
+
}
|
|
54
|
+
multipleOp(base, items, subtract) {
|
|
55
|
+
for (const item of items || []) {
|
|
56
|
+
const expanded = hkdf(item, this.size, { info: this.info });
|
|
57
|
+
this.performPointwiseWithOverflow(base, expanded, subtract);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
performPointwiseWithOverflow(base, input, subtract) {
|
|
61
|
+
for (let i = 0; i < base.length; i += 2) {
|
|
62
|
+
const x = base.readUInt16LE(i);
|
|
63
|
+
const y = input.readUInt16LE(i);
|
|
64
|
+
const result = subtract ? (x - y + 0x10000) & 0xFFFF : (x + y) & 0xFFFF;
|
|
65
|
+
base.writeUInt16LE(result, i);
|
|
66
|
+
}
|
|
67
|
+
return base;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.LTHashAntiTampering = LTHashAntiTampering;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class SerialTaskQueue {
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
this.concurrency = Math.max(1, Number(options.concurrency || 1));
|
|
6
|
+
this.running = 0;
|
|
7
|
+
this.queue = [];
|
|
8
|
+
}
|
|
9
|
+
add(task) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
this.queue.push({ task, resolve, reject });
|
|
12
|
+
this._drain();
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
_drain() {
|
|
16
|
+
while (this.running < this.concurrency && this.queue.length) {
|
|
17
|
+
const item = this.queue.shift();
|
|
18
|
+
this.running += 1;
|
|
19
|
+
Promise.resolve()
|
|
20
|
+
.then(() => item.task())
|
|
21
|
+
.then(value => item.resolve(value), error => item.reject(error))
|
|
22
|
+
.finally(() => {
|
|
23
|
+
this.running -= 1;
|
|
24
|
+
this._drain();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.default = SerialTaskQueue;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { SignalRepositoryWithLIDStore } from '../Types/index.js';
|
|
2
|
+
import type { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth.js';
|
|
3
|
+
import { type BinaryNode, type FullJid } from '../WABinary/index.js';
|
|
4
|
+
import type { USyncQueryResultList } from '../WAUSync/index.js';
|
|
5
|
+
export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
|
|
6
|
+
export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
|
|
7
|
+
[id: string]: KeyPair;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: number) => {
|
|
10
|
+
newPreKeys: {
|
|
11
|
+
[id: number]: KeyPair;
|
|
12
|
+
};
|
|
13
|
+
lastPreKeyId: number;
|
|
14
|
+
preKeysRange: readonly [number, number];
|
|
15
|
+
};
|
|
16
|
+
export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
|
|
17
|
+
export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
|
|
18
|
+
export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepositoryWithLIDStore) => Promise<void>;
|
|
19
|
+
export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, myLid: string, excludeZeroDevices: boolean) => FullJid[];
|
|
20
|
+
/**
|
|
21
|
+
* get the next N keys for upload or processing
|
|
22
|
+
* @param count number of pre-keys to get or generate
|
|
23
|
+
*/
|
|
24
|
+
export declare const getNextPreKeys: ({ creds, keys }: AuthenticationState, count: number) => Promise<{
|
|
25
|
+
update: Partial<AuthenticationCreds>;
|
|
26
|
+
preKeys: {
|
|
27
|
+
[id: string]: KeyPair;
|
|
28
|
+
};
|
|
29
|
+
}>;
|
|
30
|
+
export declare const getNextPreKeysNode: (state: AuthenticationState, count: number) => Promise<{
|
|
31
|
+
update: Partial<AuthenticationCreds>;
|
|
32
|
+
node: BinaryNode;
|
|
33
|
+
}>;
|
|
34
|
+
//# sourceMappingURL=signal.d.ts.map
|