@nerxa/socketon 0.0.0-stage → 1.21.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/EXPERIMENTAL.md +350 -0
- package/LICENSE +24 -0
- package/README.md +6317 -2
- package/WAProto/index.d.ts +17301 -0
- package/WAProto/index.js +125088 -0
- package/engine-requirements.js +14 -0
- package/package.json +100 -4
- package/src/Defaults/index.d.ts +152 -0
- package/src/Defaults/index.js +164 -0
- package/src/MessageBuilder/bot-signature.d.ts +22 -0
- package/src/MessageBuilder/bot-signature.js +122 -0
- package/src/MessageBuilder/extras.d.ts +449 -0
- package/src/MessageBuilder/extras.js +1356 -0
- package/src/MessageBuilder/index.d.ts +210 -0
- package/src/MessageBuilder/index.js +3594 -0
- package/src/MessageBuilder/metaai.d.ts +438 -0
- package/src/MessageBuilder/metaai.js +890 -0
- package/src/Signal/Group/ciphertext-message.d.ts +9 -0
- package/src/Signal/Group/ciphertext-message.js +11 -0
- package/src/Signal/Group/group-session-builder.d.ts +7 -0
- package/src/Signal/Group/group-session-builder.js +27 -0
- package/src/Signal/Group/group_cipher.d.ts +11 -0
- package/src/Signal/Group/group_cipher.js +78 -0
- package/src/Signal/Group/index.d.ts +11 -0
- package/src/Signal/Group/index.js +11 -0
- package/src/Signal/Group/keyhelper.d.ts +6 -0
- package/src/Signal/Group/keyhelper.js +17 -0
- package/src/Signal/Group/sender-chain-key.d.ts +13 -0
- package/src/Signal/Group/sender-chain-key.js +25 -0
- package/src/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/src/Signal/Group/sender-key-distribution-message.js +62 -0
- package/src/Signal/Group/sender-key-message.d.ts +18 -0
- package/src/Signal/Group/sender-key-message.js +65 -0
- package/src/Signal/Group/sender-key-name.d.ts +11 -0
- package/src/Signal/Group/sender-key-name.js +47 -0
- package/src/Signal/Group/sender-key-record.d.ts +12 -0
- package/src/Signal/Group/sender-key-record.js +40 -0
- package/src/Signal/Group/sender-key-state.d.ts +16 -0
- package/src/Signal/Group/sender-key-state.js +83 -0
- package/src/Signal/Group/sender-message-key.d.ts +11 -0
- package/src/Signal/Group/sender-message-key.js +25 -0
- package/src/Signal/libsignal.d.ts +54 -0
- package/src/Signal/libsignal.js +427 -0
- package/src/Signal/lid-mapping.d.ts +20 -0
- package/src/Signal/lid-mapping.js +274 -0
- package/src/Socket/Client/index.d.ts +2 -0
- package/src/Socket/Client/index.js +3 -0
- package/src/Socket/Client/tcp.js +177 -0
- package/src/Socket/Client/types.d.ts +5 -0
- package/src/Socket/Client/types.js +9 -0
- package/src/Socket/Client/websocket.d.ts +12 -0
- package/src/Socket/Client/websocket.js +53 -0
- package/src/Socket/business.d.ts +431 -0
- package/src/Socket/business.js +379 -0
- package/src/Socket/chats.d.ts +247 -0
- package/src/Socket/chats.js +1484 -0
- package/src/Socket/communities.d.ts +598 -0
- package/src/Socket/communities.js +421 -0
- package/src/Socket/email.js +145 -0
- package/src/Socket/groups.d.ts +298 -0
- package/src/Socket/groups.js +339 -0
- package/src/Socket/index.d.ts +581 -0
- package/src/Socket/index.js +37 -0
- package/src/Socket/messages-recv.d.ts +370 -0
- package/src/Socket/messages-recv.js +1864 -0
- package/src/Socket/messages-send.d.ts +390 -0
- package/src/Socket/messages-send.js +1574 -0
- package/src/Socket/mex.d.ts +1 -0
- package/src/Socket/mex.js +44 -0
- package/src/Socket/mobile-builders.js +72 -0
- package/src/Socket/mobile.js +424 -0
- package/src/Socket/newsletter.d.ts +468 -0
- package/src/Socket/newsletter.js +671 -0
- package/src/Socket/socket.d.ts +77 -0
- package/src/Socket/socket.js +1106 -0
- package/src/Store/index.d.ts +3 -0
- package/src/Store/index.js +3 -0
- package/src/Store/make-in-memory-store.d.ts +62 -0
- package/src/Store/make-in-memory-store.js +396 -0
- package/src/Store/make-ordered-dictionary.d.ts +12 -0
- package/src/Store/make-ordered-dictionary.js +78 -0
- package/src/Store/object-repository.d.ts +10 -0
- package/src/Store/object-repository.js +23 -0
- package/src/Types/Auth.d.ts +1 -0
- package/src/Types/Auth.js +1 -0
- package/src/Types/Bussines.d.ts +1 -0
- package/src/Types/Bussines.js +1 -0
- package/src/Types/Call.d.ts +1 -0
- package/src/Types/Call.js +1 -0
- package/src/Types/Chat.d.ts +2 -0
- package/src/Types/Chat.js +24 -0
- package/src/Types/Contact.d.ts +1 -0
- package/src/Types/Contact.js +1 -0
- package/src/Types/Events.d.ts +1 -0
- package/src/Types/Events.js +0 -0
- package/src/Types/GroupMetadata.d.ts +5 -0
- package/src/Types/GroupMetadata.js +6 -0
- package/src/Types/Label.d.ts +2 -0
- package/src/Types/Label.js +24 -0
- package/src/Types/LabelAssociation.d.ts +2 -0
- package/src/Types/LabelAssociation.js +6 -0
- package/src/Types/Message.d.ts +13 -0
- package/src/Types/Message.js +23 -0
- package/src/Types/Mex.d.ts +2 -0
- package/src/Types/Mex.js +95 -0
- package/src/Types/Product.d.ts +1 -0
- package/src/Types/Product.js +1 -0
- package/src/Types/Signal.d.ts +1 -0
- package/src/Types/Signal.js +0 -0
- package/src/Types/Socket.d.ts +1 -0
- package/src/Types/Socket.js +0 -0
- package/src/Types/State.d.ts +5 -0
- package/src/Types/State.js +54 -0
- package/src/Types/USync.d.ts +1 -0
- package/src/Types/USync.js +0 -0
- package/src/Types/index.d.ts +13 -0
- package/src/Types/index.js +25 -0
- package/src/Utils/auth-store.d.ts +29 -0
- package/src/Utils/auth-store.js +76 -0
- package/src/Utils/auth-utils.d.ts +58 -0
- package/src/Utils/auth-utils.js +273 -0
- package/src/Utils/browser-utils.d.ts +9 -0
- package/src/Utils/browser-utils.js +28 -0
- package/src/Utils/business.d.ts +49 -0
- package/src/Utils/business.js +226 -0
- package/src/Utils/chat-utils.d.ts +408 -0
- package/src/Utils/chat-utils.js +846 -0
- package/src/Utils/companion-reg-client-utils.d.ts +4 -0
- package/src/Utils/companion-reg-client-utils.js +39 -0
- package/src/Utils/crypto.d.ts +39 -0
- package/src/Utils/crypto.js +110 -0
- package/src/Utils/decode-wa-message.d.ts +99 -0
- package/src/Utils/decode-wa-message.js +373 -0
- package/src/Utils/event-buffer.d.ts +22 -0
- package/src/Utils/event-buffer.js +624 -0
- package/src/Utils/generics.d.ts +63 -0
- package/src/Utils/generics.js +375 -0
- package/src/Utils/group-metadata-cache.d.ts +4 -0
- package/src/Utils/group-metadata-cache.js +25 -0
- package/src/Utils/history.d.ts +75 -0
- package/src/Utils/history.js +131 -0
- package/src/Utils/html-app.d.ts +19 -0
- package/src/Utils/html-app.js +96 -0
- package/src/Utils/html-multiplayer.d.ts +10 -0
- package/src/Utils/html-multiplayer.js +94 -0
- package/src/Utils/identity-change-handler.d.ts +13 -0
- package/src/Utils/identity-change-handler.js +48 -0
- package/src/Utils/index.d.ts +44 -0
- package/src/Utils/index.js +44 -0
- package/src/Utils/link-preview-metadata.d.ts +47 -0
- package/src/Utils/link-preview-metadata.js +88 -0
- package/src/Utils/link-preview.d.ts +12 -0
- package/src/Utils/link-preview.js +79 -0
- package/src/Utils/logger.d.ts +2 -0
- package/src/Utils/logger.js +2 -0
- package/src/Utils/lt-hash.d.ts +6 -0
- package/src/Utils/lt-hash.js +3 -0
- package/src/Utils/make-mutex.d.ts +6 -0
- package/src/Utils/make-mutex.js +32 -0
- package/src/Utils/message-retry-manager.d.ts +79 -0
- package/src/Utils/message-retry-manager.js +255 -0
- package/src/Utils/messages-media.d.ts +136 -0
- package/src/Utils/messages-media.js +814 -0
- package/src/Utils/messages.d.ts +62 -0
- package/src/Utils/messages.js +2223 -0
- package/src/Utils/mobile-companion-crypto.js +191 -0
- package/src/Utils/modern-messages.d.ts +150 -0
- package/src/Utils/modern-messages.js +496 -0
- package/src/Utils/native-flow.d.ts +11 -0
- package/src/Utils/native-flow.js +115 -0
- package/src/Utils/newsletter-status.d.ts +158 -0
- package/src/Utils/newsletter-status.js +651 -0
- package/src/Utils/noise-handler.d.ts +20 -0
- package/src/Utils/noise-handler.js +200 -0
- package/src/Utils/offline-node-processor.d.ts +9 -0
- package/src/Utils/offline-node-processor.js +33 -0
- package/src/Utils/optional-media.d.ts +3 -0
- package/src/Utils/optional-media.js +45 -0
- package/src/Utils/payment-messages.d.ts +66 -0
- package/src/Utils/payment-messages.js +160 -0
- package/src/Utils/pre-key-manager.d.ts +25 -0
- package/src/Utils/pre-key-manager.js +95 -0
- package/src/Utils/process-message.d.ts +60 -0
- package/src/Utils/process-message.js +688 -0
- package/src/Utils/reporting-utils.d.ts +12 -0
- package/src/Utils/reporting-utils.js +256 -0
- package/src/Utils/scheduled-message.d.ts +51 -0
- package/src/Utils/scheduled-message.js +112 -0
- package/src/Utils/sender-key-memory.d.ts +19 -0
- package/src/Utils/sender-key-memory.js +51 -0
- package/src/Utils/signal.d.ts +82 -0
- package/src/Utils/signal.js +193 -0
- package/src/Utils/stanza-ack.d.ts +16 -0
- package/src/Utils/stanza-ack.js +30 -0
- package/src/Utils/status-stickers.d.ts +127 -0
- package/src/Utils/status-stickers.js +260 -0
- package/src/Utils/sync-action-utils.d.ts +2 -0
- package/src/Utils/sync-action-utils.js +44 -0
- package/src/Utils/tc-token-utils.d.ts +29 -0
- package/src/Utils/tc-token-utils.js +155 -0
- package/src/Utils/ttl-cache.d.ts +28 -0
- package/src/Utils/ttl-cache.js +120 -0
- package/src/Utils/use-mongo-auth-state.d.ts +21 -0
- package/src/Utils/use-mongo-auth-state.js +67 -0
- package/src/Utils/use-multi-file-auth-state.d.ts +11 -0
- package/src/Utils/use-multi-file-auth-state.js +106 -0
- package/src/Utils/use-mysql-auth-state.d.ts +19 -0
- package/src/Utils/use-mysql-auth-state.js +79 -0
- package/src/Utils/use-postgres-auth-state.d.ts +19 -0
- package/src/Utils/use-postgres-auth-state.js +79 -0
- package/src/Utils/use-redis-auth-state.d.ts +19 -0
- package/src/Utils/use-redis-auth-state.js +89 -0
- package/src/Utils/use-single-file-auth-state.d.ts +10 -0
- package/src/Utils/use-single-file-auth-state.js +108 -0
- package/src/Utils/use-sqlite-auth-state.d.ts +12 -0
- package/src/Utils/use-sqlite-auth-state.js +120 -0
- package/src/Utils/useNekoDBAuth.d.ts +19 -0
- package/src/Utils/useNekoDBAuth.js +111 -0
- package/src/Utils/username.d.ts +12 -0
- package/src/Utils/username.js +58 -0
- package/src/Utils/validate-connection.d.ts +43 -0
- package/src/Utils/validate-connection.js +277 -0
- package/src/Utils/voice-recognition.d.ts +53 -0
- package/src/Utils/voice-recognition.js +219 -0
- package/src/Voip/audio-feeder.d.ts +24 -0
- package/src/Voip/audio-feeder.js +268 -0
- package/src/Voip/index.d.ts +88 -0
- package/src/Voip/index.js +936 -0
- package/src/Voip/relay-transport.d.ts +5 -0
- package/src/Voip/relay-transport.js +824 -0
- package/src/Voip/signaling.d.ts +11 -0
- package/src/Voip/signaling.js +1099 -0
- package/src/Voip/types.d.ts +2 -0
- package/src/Voip/types.js +12 -0
- package/src/Voip/video-feeder.d.ts +24 -0
- package/src/Voip/video-feeder.js +268 -0
- package/src/Voip/wasm-engine.d.ts +26 -0
- package/src/Voip/wasm-engine.js +1307 -0
- package/src/Voip/worker-bootstrap.js +1023 -0
- package/src/WABinary/constants.d.ts +22 -0
- package/src/WABinary/constants.js +1300 -0
- package/src/WABinary/decode.d.ts +9 -0
- package/src/WABinary/decode.js +261 -0
- package/src/WABinary/encode.d.ts +2 -0
- package/src/WABinary/encode.js +219 -0
- package/src/WABinary/generic-utils.d.ts +76 -0
- package/src/WABinary/generic-utils.js +214 -0
- package/src/WABinary/index.d.ts +5 -0
- package/src/WABinary/index.js +5 -0
- package/src/WABinary/jid-utils.d.ts +30 -0
- package/src/WABinary/jid-utils.js +97 -0
- package/src/WABinary/types.d.ts +1 -0
- package/src/WABinary/types.js +0 -0
- package/src/WAM/BinaryInfo.d.ts +7 -0
- package/src/WAM/BinaryInfo.js +9 -0
- package/src/WAM/constants.d.ts +34926 -0
- package/src/WAM/constants.js +22852 -0
- package/src/WAM/encode.d.ts +1 -0
- package/src/WAM/encode.js +148 -0
- package/src/WAM/index.d.ts +3 -0
- package/src/WAM/index.js +3 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.js +50 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +51 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/src/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
- package/src/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/src/WAUSync/Protocols/UsyncBotProfileProtocol.js +49 -0
- package/src/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/src/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/src/WAUSync/Protocols/index.d.ts +5 -0
- package/src/WAUSync/Protocols/index.js +5 -0
- package/src/WAUSync/USyncQuery.d.ts +20 -0
- package/src/WAUSync/USyncQuery.js +93 -0
- package/src/WAUSync/USyncUser.d.ts +16 -0
- package/src/WAUSync/USyncUser.js +30 -0
- package/src/WAUSync/index.d.ts +3 -0
- package/src/WAUSync/index.js +3 -0
- package/src/assets/wasm/README.md +76 -0
- package/src/assets/wasm/loader.js +5 -0
- package/src/assets/wasm/whatsapp.wasm +0 -0
- package/src/assets/wasm/worker-modules.js +273 -0
- package/src/index.d.ts +43 -0
- package/src/index.js +48 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { pbkdf2Sync, randomBytes } from 'crypto';
|
|
2
|
+
import { hkdfSync } from 'crypto';
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
import { deflate } from 'zlib';
|
|
5
|
+
const deflateAsync = promisify(deflate);
|
|
6
|
+
|
|
7
|
+
import { Curve, aesEncryptCTR, aesDecryptCTR, hmacSign } from './crypto.js';
|
|
8
|
+
import { proto } from '../../WAProto/index.js';
|
|
9
|
+
|
|
10
|
+
const EMPTY = Buffer.alloc(0);
|
|
11
|
+
const PEM_HKDF_INFO = Buffer.from('Canonical Ent Companion Nonce Encrypt');
|
|
12
|
+
const PBKDF2_ITERATIONS = 131072;
|
|
13
|
+
const PAIRING_AES_KEY_BYTES = 32;
|
|
14
|
+
const ADV_PREFIX_ACCOUNT_SIGNATURE = Buffer.from([6, 0]);
|
|
15
|
+
const ADV_PREFIX_ACCOUNT_KEY_INDEX = Buffer.from([6, 2]);
|
|
16
|
+
|
|
17
|
+
const toRawPubKey = (pub) => {
|
|
18
|
+
const b = Buffer.from(pub);
|
|
19
|
+
return b.length === 33 ? b.slice(1) : b;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const decodeBase64Url = (input, label) => {
|
|
23
|
+
let s = String(input).replace(/-/g, '+').replace(/_/g, '/');
|
|
24
|
+
while (s.length % 4) s += '=';
|
|
25
|
+
try {
|
|
26
|
+
return Buffer.from(s, 'base64');
|
|
27
|
+
} catch (e) {
|
|
28
|
+
throw new Error(`${label}: invalid base64url`);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const parseCompanionQr = (qr) => {
|
|
33
|
+
const parts = String(qr).split(',');
|
|
34
|
+
if (parts.length < 5) throw new Error(`companion qr must have at least 5 parts, got ${parts.length}`);
|
|
35
|
+
const platform = parts[parts.length - 1];
|
|
36
|
+
const advSecretB64 = parts[parts.length - 2];
|
|
37
|
+
const identityPubB64 = parts[parts.length - 3];
|
|
38
|
+
const noisePubB64 = parts[parts.length - 4];
|
|
39
|
+
const ref = parts.slice(0, parts.length - 4).join(',');
|
|
40
|
+
return {
|
|
41
|
+
ref,
|
|
42
|
+
noisePublicKey: decodeBase64Url(noisePubB64, 'noisePublicKey'),
|
|
43
|
+
identityPublicKey: decodeBase64Url(identityPubB64, 'identityPublicKey'),
|
|
44
|
+
advSecretKey: decodeBase64Url(advSecretB64, 'advSecretKey'),
|
|
45
|
+
platform
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const buildSignedKeyIndexList = async (input) => {
|
|
50
|
+
const details = proto.ADVKeyIndexList.encode({
|
|
51
|
+
rawId: input.rawId,
|
|
52
|
+
timestamp: input.timestampSeconds,
|
|
53
|
+
currentIndex: input.currentIndex,
|
|
54
|
+
validIndexes: [...input.validIndexes]
|
|
55
|
+
}).finish();
|
|
56
|
+
const accountSignature = await signKeyIndexList(details, input.accountIdentityKeyPair);
|
|
57
|
+
return proto.ADVSignedKeyIndexList.encode({ details, accountSignature }).finish();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const signKeyIndexList = async (keyIndexListDetails, accountIdentityKeyPair, isHosted = false) => {
|
|
61
|
+
const prefix = isHosted ? Buffer.from([6, 7]) : ADV_PREFIX_ACCOUNT_KEY_INDEX;
|
|
62
|
+
const message = Buffer.concat([prefix, Buffer.from(keyIndexListDetails)]);
|
|
63
|
+
return Curve.sign(accountIdentityKeyPair.private, message);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const generateDeviceIdentityAccountSignature = async (details, companionIdentityPublicKey, accountIdentityKeyPair, isHosted = false) => {
|
|
67
|
+
const prefix = isHosted ? Buffer.from([6, 5]) : ADV_PREFIX_ACCOUNT_SIGNATURE;
|
|
68
|
+
const message = Buffer.concat([prefix, Buffer.from(details), toRawPubKey(companionIdentityPublicKey)]);
|
|
69
|
+
return Curve.sign(accountIdentityKeyPair.private, message);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const computeAdvIdentityHmac = (secretKey, details) => {
|
|
73
|
+
return hmacSign(Buffer.from(details), Buffer.from(secretKey));
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const buildSignedCompanionIdentity = async (input) => {
|
|
77
|
+
const accountSignatureKey = toRawPubKey(input.accountIdentityKeyPair.pubKey);
|
|
78
|
+
const details = proto.ADVDeviceIdentity.encode({
|
|
79
|
+
rawId: input.rawId,
|
|
80
|
+
timestamp: input.timestampSeconds,
|
|
81
|
+
keyIndex: input.keyIndex
|
|
82
|
+
}).finish();
|
|
83
|
+
const accountSignature = await generateDeviceIdentityAccountSignature(
|
|
84
|
+
details,
|
|
85
|
+
input.companionIdentityPublicKey,
|
|
86
|
+
input.accountIdentityKeyPair
|
|
87
|
+
);
|
|
88
|
+
const signedIdentity = proto.ADVSignedDeviceIdentity.encode({
|
|
89
|
+
details,
|
|
90
|
+
accountSignatureKey,
|
|
91
|
+
accountSignature
|
|
92
|
+
}).finish();
|
|
93
|
+
const hmac = computeAdvIdentityHmac(input.advSecretKey, signedIdentity);
|
|
94
|
+
const deviceIdentityBytes = proto.ADVSignedDeviceIdentityHMAC.encode({
|
|
95
|
+
details: signedIdentity,
|
|
96
|
+
hmac
|
|
97
|
+
}).finish();
|
|
98
|
+
const keyIndexListBytes = await buildSignedKeyIndexList({
|
|
99
|
+
accountIdentityKeyPair: input.accountIdentityKeyPair,
|
|
100
|
+
rawId: input.rawId,
|
|
101
|
+
currentIndex: input.keyIndex,
|
|
102
|
+
timestampSeconds: input.timestampSeconds,
|
|
103
|
+
validIndexes: input.validIndexes
|
|
104
|
+
});
|
|
105
|
+
return { deviceIdentityBytes, keyIndexListBytes };
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const derivePemKey = (advSecretKey, companionNoisePublicKey) => {
|
|
109
|
+
return Buffer.from(hkdfSync('sha256', Buffer.from(advSecretKey), Buffer.from(companionNoisePublicKey), PEM_HKDF_INFO, 32));
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const preparePrimaryHello = async (args) => {
|
|
113
|
+
if (args.wrappedCompanionEphemeralPub.length < 48) {
|
|
114
|
+
throw new Error(`wrapped companion ephemeral pub too short`);
|
|
115
|
+
}
|
|
116
|
+
const codeBytes = Buffer.from(args.pairingCode, 'utf8');
|
|
117
|
+
const salt = args.wrappedCompanionEphemeralPub.subarray(0, 32);
|
|
118
|
+
const counter = args.wrappedCompanionEphemeralPub.subarray(32, 48);
|
|
119
|
+
const companionCipherKey = pbkdf2Sync(codeBytes, Buffer.from(salt), PBKDF2_ITERATIONS, PAIRING_AES_KEY_BYTES, 'sha256');
|
|
120
|
+
const companionEphemeralPub = aesDecryptCTR(
|
|
121
|
+
args.wrappedCompanionEphemeralPub.subarray(48),
|
|
122
|
+
companionCipherKey,
|
|
123
|
+
counter
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const primaryEphemeralKeyPair = Curve.generateKeyPair();
|
|
127
|
+
const salt2 = randomBytes(32);
|
|
128
|
+
const counter2 = randomBytes(16);
|
|
129
|
+
const primaryCipherKey = pbkdf2Sync(codeBytes, salt2, PBKDF2_ITERATIONS, PAIRING_AES_KEY_BYTES, 'sha256');
|
|
130
|
+
const encrypted = aesEncryptCTR(primaryEphemeralKeyPair.public, primaryCipherKey, counter2);
|
|
131
|
+
const sharedEphemeral = Curve.sharedKey(primaryEphemeralKeyPair.private, companionEphemeralPub);
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
primaryEphemeralKeyPair,
|
|
135
|
+
wrappedPrimaryEphemeralPub: Buffer.concat([salt2, counter2, encrypted]),
|
|
136
|
+
sharedEphemeral
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const buildHistorySyncBootstrapMessage = async (input = {}) => {
|
|
141
|
+
const historySync = {
|
|
142
|
+
syncType: proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
143
|
+
chunkOrder: 0,
|
|
144
|
+
progress: 100,
|
|
145
|
+
conversations: input.conversations ? [...input.conversations] : [],
|
|
146
|
+
pushnames: input.pushnames ? [...input.pushnames] : [],
|
|
147
|
+
phoneNumberToLidMappings: (input.phoneNumberToLidMappings || []).map((m) => ({ pnJid: m.pnJid, lidJid: m.lidJid })),
|
|
148
|
+
...(input.companionMetaNonce !== undefined ? { companionMetaNonce: input.companionMetaNonce } : {})
|
|
149
|
+
};
|
|
150
|
+
const serialized = proto.HistorySync.encode(historySync).finish();
|
|
151
|
+
const compressed = await deflateAsync(serialized, { level: 1 });
|
|
152
|
+
const payload = new Uint8Array(compressed);
|
|
153
|
+
const message = {
|
|
154
|
+
type: proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION,
|
|
155
|
+
historySyncNotification: {
|
|
156
|
+
syncType: proto.Message.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
157
|
+
chunkOrder: 0,
|
|
158
|
+
progress: 100,
|
|
159
|
+
initialHistBootstrapInlinePayload: payload
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
return { message, payloadBytes: payload.byteLength };
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export const completePrimaryHandshake = async (args) => {
|
|
166
|
+
const info = Buffer.from('link_code_pairing_key_bundle_encryption_key');
|
|
167
|
+
const key = Buffer.from(hkdfSync('sha256', Buffer.from(args.sharedEphemeral), args.wrappedKeyBundle.subarray(0, 32), info, 32));
|
|
168
|
+
const plaintextBundle = aesDecryptGCM(
|
|
169
|
+
args.wrappedKeyBundle.subarray(44),
|
|
170
|
+
key,
|
|
171
|
+
args.wrappedKeyBundle.subarray(32, 44),
|
|
172
|
+
Buffer.alloc(0)
|
|
173
|
+
);
|
|
174
|
+
const bundleCompanionIdentity = plaintextBundle.subarray(0, 32);
|
|
175
|
+
const bundlePrimaryIdentity = plaintextBundle.subarray(32, 64);
|
|
176
|
+
const bundleSecret = plaintextBundle.subarray(64);
|
|
177
|
+
|
|
178
|
+
const rawCompanionIdentity = toRawPubKey(args.companionIdentityPub);
|
|
179
|
+
const rawPrimaryIdentity = toRawPubKey(args.primaryIdentityKeyPair.pubKey);
|
|
180
|
+
if (Buffer.compare(Buffer.from(bundlePrimaryIdentity), rawPrimaryIdentity) !== 0) {
|
|
181
|
+
throw new Error('link-code bundle primary identity mismatch');
|
|
182
|
+
}
|
|
183
|
+
if (Buffer.compare(Buffer.from(bundleCompanionIdentity), rawCompanionIdentity) !== 0) {
|
|
184
|
+
throw new Error('link-code bundle companion identity mismatch');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const sharedIdentity = Curve.sharedKey(args.primaryIdentityKeyPair.private, rawCompanionIdentity);
|
|
188
|
+
const advSecret = Buffer.from(hkdfSync('sha256', Buffer.concat([Buffer.from(args.sharedEphemeral), Buffer.from(sharedIdentity), Buffer.from(bundleSecret)]), EMPTY, Buffer.from('adv_secret'), 32));
|
|
189
|
+
// Wait zapo uses concatBytes([sharedEphemeral, sharedIdentity, bundleSecret]) as ikm, salt null, info ADV_SECRET. Need exact info string. Baileys messages-recv uses 'adv_secret'. Good.
|
|
190
|
+
return advSecret;
|
|
191
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js'
|
|
2
|
+
|
|
3
|
+
export declare function makeQuestionMessage(input: {
|
|
4
|
+
text: string
|
|
5
|
+
contextInfo?: proto.IContextInfo
|
|
6
|
+
}): proto.IMessage
|
|
7
|
+
|
|
8
|
+
export declare function makeQuestionResponseMessage(input: {
|
|
9
|
+
key: proto.IMessageKey
|
|
10
|
+
text?: string
|
|
11
|
+
}): proto.IMessage
|
|
12
|
+
|
|
13
|
+
export declare function makeQuestionReplyMessage(input: {
|
|
14
|
+
text: string
|
|
15
|
+
serverQuestionId: number | string
|
|
16
|
+
quotedQuestion?: proto.IMessage
|
|
17
|
+
quotedResponse?: proto.IMessage
|
|
18
|
+
contextInfo?: proto.IContextInfo
|
|
19
|
+
}): proto.IMessage
|
|
20
|
+
|
|
21
|
+
export declare function makeStatusQuestionAnswerMessage(input: {
|
|
22
|
+
key: proto.IMessageKey
|
|
23
|
+
text?: string
|
|
24
|
+
}): proto.IMessage
|
|
25
|
+
|
|
26
|
+
export declare function makeStatusQuotedMessage(input: {
|
|
27
|
+
type?: number | string
|
|
28
|
+
text?: string
|
|
29
|
+
thumbnail?: Uint8Array
|
|
30
|
+
originalStatusId: proto.IMessageKey
|
|
31
|
+
}): proto.IMessage
|
|
32
|
+
|
|
33
|
+
export declare function makeStatusStickerInteractionMessage(input: {
|
|
34
|
+
key: proto.IMessageKey
|
|
35
|
+
stickerKey: string
|
|
36
|
+
type?: number | string
|
|
37
|
+
}): proto.IMessage
|
|
38
|
+
|
|
39
|
+
export declare function makeStatusNotificationMessage(input: {
|
|
40
|
+
responseMessageKey: proto.IMessageKey
|
|
41
|
+
originalMessageKey: proto.IMessageKey
|
|
42
|
+
type?: number | string
|
|
43
|
+
}): proto.IMessage
|
|
44
|
+
|
|
45
|
+
export declare function makeNewsletterAdminInviteMessage(input: {
|
|
46
|
+
newsletterJid: string
|
|
47
|
+
newsletterName?: string
|
|
48
|
+
jpegThumbnail?: Uint8Array
|
|
49
|
+
caption?: string
|
|
50
|
+
inviteExpiration?: number
|
|
51
|
+
contextInfo?: proto.IContextInfo
|
|
52
|
+
}): proto.IMessage
|
|
53
|
+
|
|
54
|
+
export declare function makeNewsletterFollowerInviteMessage(input: {
|
|
55
|
+
newsletterJid: string
|
|
56
|
+
newsletterName?: string
|
|
57
|
+
jpegThumbnail?: Uint8Array
|
|
58
|
+
caption?: string
|
|
59
|
+
contextInfo?: proto.IContextInfo
|
|
60
|
+
}): proto.IMessage
|
|
61
|
+
|
|
62
|
+
export declare function makePollAddOptionMessage(input: {
|
|
63
|
+
pollCreationMessageKey: proto.IMessageKey
|
|
64
|
+
option?: string | proto.Message.PollCreationMessage.IOption
|
|
65
|
+
addOption?: proto.Message.PollCreationMessage.IOption
|
|
66
|
+
metadata?: proto.Message.IPollUpdateMessageMetadata
|
|
67
|
+
}): proto.IMessage
|
|
68
|
+
|
|
69
|
+
export declare function makeCommentMessage(input: {
|
|
70
|
+
message?: proto.IMessage
|
|
71
|
+
content?: Record<string, any>
|
|
72
|
+
targetMessageKey: proto.IMessageKey
|
|
73
|
+
}): proto.IMessage
|
|
74
|
+
|
|
75
|
+
export declare function makeEventInviteMessage(input: {
|
|
76
|
+
eventId: string
|
|
77
|
+
eventTitle?: string
|
|
78
|
+
jpegThumbnail?: Uint8Array
|
|
79
|
+
startTime?: number | Date
|
|
80
|
+
caption?: string
|
|
81
|
+
isCanceled?: boolean
|
|
82
|
+
endTime?: number | Date
|
|
83
|
+
callLink?: string
|
|
84
|
+
contextInfo?: proto.IContextInfo
|
|
85
|
+
}): proto.IMessage
|
|
86
|
+
|
|
87
|
+
export declare function makeScheduledCallCreationMessage(input: {
|
|
88
|
+
scheduledTimestampMs: number | Date
|
|
89
|
+
callType?: number | string
|
|
90
|
+
title?: string
|
|
91
|
+
}): proto.IMessage
|
|
92
|
+
|
|
93
|
+
export declare function makeScheduledCallEditMessage(input: {
|
|
94
|
+
key: proto.IMessageKey
|
|
95
|
+
editType?: number | string
|
|
96
|
+
}): proto.IMessage
|
|
97
|
+
|
|
98
|
+
export declare function makeGroupStatusReactionMessage(input: {
|
|
99
|
+
key: proto.IMessageKey
|
|
100
|
+
text?: string
|
|
101
|
+
groupingKey?: string
|
|
102
|
+
senderTimestampMs?: number
|
|
103
|
+
}): proto.IMessage
|
|
104
|
+
|
|
105
|
+
export declare function makeNewsletterStatusAttribution(input: {
|
|
106
|
+
newsletterJid: string
|
|
107
|
+
messageId: string | number
|
|
108
|
+
duration?: number
|
|
109
|
+
hasMultipleReshares?: boolean
|
|
110
|
+
actionUrl?: string
|
|
111
|
+
}): proto.IStatusAttribution
|
|
112
|
+
|
|
113
|
+
export declare function makeGroupStatusAttribution(input: {
|
|
114
|
+
authorJid: string
|
|
115
|
+
actionUrl?: string
|
|
116
|
+
}): proto.IStatusAttribution
|
|
117
|
+
|
|
118
|
+
export declare const STATUS_AUDIENCE_DEFAULT_LIST_NAME: string
|
|
119
|
+
export declare const STATUS_AUDIENCE_DEFAULT_EMOJI: string
|
|
120
|
+
|
|
121
|
+
export declare function makeStatusAudienceMetadata(input: string | {
|
|
122
|
+
listName?: string
|
|
123
|
+
listEmoji?: string
|
|
124
|
+
audienceType?: number | string
|
|
125
|
+
}): proto.ContextInfo.IStatusAudienceMetadata
|
|
126
|
+
|
|
127
|
+
export declare const STATUS_NOTIFICATION_TYPES: Readonly<Record<string, number>>
|
|
128
|
+
|
|
129
|
+
export declare function makeMessageAssociation(input: {
|
|
130
|
+
parentMessageKey?: proto.IMessageKey
|
|
131
|
+
key?: proto.IMessageKey
|
|
132
|
+
associationType?: number | string
|
|
133
|
+
type?: number | string
|
|
134
|
+
messageIndex?: number
|
|
135
|
+
}): proto.IMessageAssociation
|
|
136
|
+
|
|
137
|
+
export declare function makeStatusAddYoursAssociation(input: proto.IMessageKey | {
|
|
138
|
+
key?: proto.IMessageKey
|
|
139
|
+
parentMessageKey?: proto.IMessageKey
|
|
140
|
+
type?: number | string
|
|
141
|
+
associationType?: number | string
|
|
142
|
+
messageIndex?: number
|
|
143
|
+
}): proto.IMessageAssociation
|
|
144
|
+
|
|
145
|
+
export declare function makeStatusMentionMessage(input: {
|
|
146
|
+
key: proto.IMessageKey
|
|
147
|
+
group?: boolean
|
|
148
|
+
}): any
|
|
149
|
+
|
|
150
|
+
export declare function prepareModernMessageContent(content: any): any
|