@dhilzzkz/baileys 0.0.0-stage → 0.1.1
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/LICENSE +23 -0
- package/NOTICE.md +37 -0
- package/README.md +2083 -2
- package/WAProto/index.d.ts +22220 -0
- package/WAProto/index.js +5 -0
- package/lib/Addon/http-error.d.ts +18 -0
- package/lib/Addon/http-error.js +40 -0
- package/lib/Addon/index.d.ts +3 -0
- package/lib/Addon/index.js +4 -0
- package/lib/Addon/keyed-db.d.ts +14 -0
- package/lib/Addon/keyed-db.js +241 -0
- package/lib/Addon/link-preview.d.ts +15 -0
- package/lib/Addon/link-preview.js +79 -0
- package/lib/Defaults/index.d.ts +188 -0
- package/lib/Defaults/index.js +185 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-cipher.d.ts +10 -0
- package/lib/Signal/Group/group-cipher.js +81 -0
- package/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/Protocol/crypto.d.ts +6 -0
- package/lib/Signal/Protocol/crypto.js +61 -0
- package/lib/Signal/Protocol/curve.d.ts +8 -0
- package/lib/Signal/Protocol/curve.js +61 -0
- package/lib/Signal/Protocol/index.d.ts +16 -0
- package/lib/Signal/Protocol/index.js +9 -0
- package/lib/Signal/Protocol/internals.d.ts +57 -0
- package/lib/Signal/Protocol/internals.js +155 -0
- package/lib/Signal/Protocol/session-builder.d.ts +40 -0
- package/lib/Signal/Protocol/session-builder.js +143 -0
- package/lib/Signal/Protocol/session-cipher.d.ts +26 -0
- package/lib/Signal/Protocol/session-cipher.js +301 -0
- package/lib/Signal/Protocol/session-record.d.ts +55 -0
- package/lib/Signal/Protocol/session-record.js +272 -0
- package/lib/Signal/libsignal.d.ts +54 -0
- package/lib/Signal/libsignal.js +426 -0
- package/lib/Signal/lid-mapping.d.ts +20 -0
- package/lib/Signal/lid-mapping.js +274 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.d.ts +5 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +119 -0
- package/lib/Socket/business.d.ts +387 -0
- package/lib/Socket/business.js +380 -0
- package/lib/Socket/chats.d.ts +144 -0
- package/lib/Socket/chats.js +1216 -0
- package/lib/Socket/communities.d.ts +554 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.js +347 -0
- package/lib/Socket/index.d.ts +522 -0
- package/lib/Socket/index.js +11 -0
- package/lib/Socket/messages-recv.d.ts +326 -0
- package/lib/Socket/messages-recv.js +1822 -0
- package/lib/Socket/messages-send.d.ts +321 -0
- package/lib/Socket/messages-send.js +1378 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.d.ts +283 -0
- package/lib/Socket/newsletter.js +225 -0
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.js +992 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +3 -0
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +418 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +23 -0
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Business.d.ts +1 -0
- package/lib/Types/Business.js +1 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +1 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.d.ts +1 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +1 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +2 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.d.ts +2 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.d.ts +11 -0
- package/lib/Types/Message.js +17 -0
- package/lib/Types/Mex.d.ts +2 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +1 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/RichType.d.ts +2 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +1 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +1 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +5 -0
- package/lib/Types/State.js +54 -0
- package/lib/Types/USync.d.ts +1 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +13 -0
- package/lib/Types/index.js +25 -0
- package/lib/Utils/Auth/auth-utils.d.ts +58 -0
- package/lib/Utils/Auth/auth-utils.js +316 -0
- package/lib/Utils/Auth/companion-reg-client-utils.d.ts +4 -0
- package/lib/Utils/Auth/companion-reg-client-utils.js +39 -0
- package/lib/Utils/Auth/pre-key-manager.d.ts +25 -0
- package/lib/Utils/Auth/pre-key-manager.js +105 -0
- package/lib/Utils/Auth/use-multi-file-auth-state.d.ts +10 -0
- package/lib/Utils/Auth/use-multi-file-auth-state.js +116 -0
- package/lib/Utils/Auth/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/Auth/use-single-file-auth-state.js +94 -0
- package/lib/Utils/Auth/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/Auth/use-sqlite-auth-state.js +109 -0
- package/lib/Utils/Auth/validate-connection.d.ts +44 -0
- package/lib/Utils/Auth/validate-connection.js +210 -0
- package/lib/Utils/Common/browser-utils.d.ts +9 -0
- package/lib/Utils/Common/browser-utils.js +28 -0
- package/lib/Utils/Common/generics.d.ts +63 -0
- package/lib/Utils/Common/generics.js +392 -0
- package/lib/Utils/Common/logger.d.ts +12 -0
- package/lib/Utils/Common/logger.js +12 -0
- package/lib/Utils/Common/make-mutex.d.ts +6 -0
- package/lib/Utils/Common/make-mutex.js +32 -0
- package/lib/Utils/Crypto/crypto.d.ts +39 -0
- package/lib/Utils/Crypto/crypto.js +117 -0
- package/lib/Utils/Crypto/lt-hash.d.ts +6 -0
- package/lib/Utils/Crypto/lt-hash.js +7 -0
- package/lib/Utils/Crypto/noise-handler.d.ts +20 -0
- package/lib/Utils/Crypto/noise-handler.js +200 -0
- package/lib/Utils/Crypto/signal.d.ts +82 -0
- package/lib/Utils/Crypto/signal.js +200 -0
- package/lib/Utils/Message/business.d.ts +49 -0
- package/lib/Utils/Message/business.js +230 -0
- package/lib/Utils/Message/decode-wa-message.d.ts +83 -0
- package/lib/Utils/Message/decode-wa-message.js +316 -0
- package/lib/Utils/Message/history.d.ts +75 -0
- package/lib/Utils/Message/history.js +133 -0
- package/lib/Utils/Message/link-preview.d.ts +13 -0
- package/lib/Utils/Message/link-preview.js +73 -0
- package/lib/Utils/Message/message-retry-manager.d.ts +79 -0
- package/lib/Utils/Message/message-retry-manager.js +259 -0
- package/lib/Utils/Message/messages-media.d.ts +134 -0
- package/lib/Utils/Message/messages-media.js +802 -0
- package/lib/Utils/Message/messages.d.ts +47 -0
- package/lib/Utils/Message/messages.js +1907 -0
- package/lib/Utils/Message/offline-node-processor.d.ts +10 -0
- package/lib/Utils/Message/offline-node-processor.js +40 -0
- package/lib/Utils/Message/process-message.d.ts +83 -0
- package/lib/Utils/Message/process-message.js +748 -0
- package/lib/Utils/Message/reporting-utils.d.ts +12 -0
- package/lib/Utils/Message/reporting-utils.js +257 -0
- package/lib/Utils/Message/rich-message-utils.d.ts +48 -0
- package/lib/Utils/Message/rich-message-utils.js +366 -0
- package/lib/Utils/Message/stanza-ack.d.ts +16 -0
- package/lib/Utils/Message/stanza-ack.js +37 -0
- package/lib/Utils/State/chat-utils.d.ts +408 -0
- package/lib/Utils/State/chat-utils.js +871 -0
- package/lib/Utils/State/event-buffer.d.ts +12 -0
- package/lib/Utils/State/event-buffer.js +621 -0
- package/lib/Utils/State/identity-change-handler.d.ts +13 -0
- package/lib/Utils/State/identity-change-handler.js +48 -0
- package/lib/Utils/State/sync-action-utils.d.ts +2 -0
- package/lib/Utils/State/sync-action-utils.js +48 -0
- package/lib/Utils/State/tc-token-utils.d.ts +29 -0
- package/lib/Utils/State/tc-token-utils.js +163 -0
- package/lib/Utils/index.d.ts +24 -0
- package/lib/Utils/index.js +24 -0
- package/lib/WABinary/constants.d.ts +61 -0
- package/lib/WABinary/constants.js +1466 -0
- package/lib/WABinary/decode.d.ts +9 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.d.ts +79 -0
- package/lib/WABinary/generic-utils.js +226 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.d.ts +28 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.d.ts +1 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +7 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.d.ts +34926 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +38 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +5 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +97 -0
- package/lib/WAUSync/USyncUser.d.ts +16 -0
- package/lib/WAUSync/USyncUser.js +30 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +11 -0
- package/package.json +120 -5
- package/scripts/engine-requirements.js +16 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { proto } from '../../../WAProto/index.js';
|
|
3
|
+
import { HttpError } from '../../Addon/index.js';
|
|
4
|
+
import { KEY_BUNDLE_TYPE, WA_ADV_ACCOUNT_SIG_PREFIX, WA_ADV_DEVICE_SIG_PREFIX, WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX } from '../../Defaults/index.js';
|
|
5
|
+
import { getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../../WABinary/index.js';
|
|
6
|
+
import { Curve, hmacSign } from '../Crypto/crypto.js';
|
|
7
|
+
import { encodeBigEndian } from '../Common/generics.js';
|
|
8
|
+
import { createSignalIdentity } from '../Crypto/signal.js';
|
|
9
|
+
const getUserAgent = (config) => {
|
|
10
|
+
return {
|
|
11
|
+
appVersion: {
|
|
12
|
+
primary: config.version[0],
|
|
13
|
+
secondary: config.version[1],
|
|
14
|
+
tertiary: config.version[2]
|
|
15
|
+
},
|
|
16
|
+
platform: config.browser[1].toLocaleLowerCase().includes('android')
|
|
17
|
+
? proto.ClientPayload.UserAgent.Platform.ANDROID
|
|
18
|
+
: proto.ClientPayload.UserAgent.Platform.WEB,
|
|
19
|
+
releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
20
|
+
osVersion: '0.1',
|
|
21
|
+
device: 'Desktop',
|
|
22
|
+
osBuildNumber: '0.1',
|
|
23
|
+
localeLanguageIso6391: 'en',
|
|
24
|
+
mnc: '000',
|
|
25
|
+
mcc: '000',
|
|
26
|
+
localeCountryIso31661Alpha2: config.countryCode
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const PLATFORM_MAP = {
|
|
30
|
+
'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
31
|
+
Windows: proto.ClientPayload.WebInfo.WebSubPlatform.WIN_HYBRID
|
|
32
|
+
};
|
|
33
|
+
const getWebInfo = (config) => {
|
|
34
|
+
let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
35
|
+
if (config.syncFullHistory &&
|
|
36
|
+
PLATFORM_MAP[config.browser[0]] &&
|
|
37
|
+
config.browser[1] === 'Desktop') {
|
|
38
|
+
webSubPlatform = PLATFORM_MAP[config.browser[0]];
|
|
39
|
+
}
|
|
40
|
+
return { webSubPlatform };
|
|
41
|
+
};
|
|
42
|
+
const getClientPayload = (config) => {
|
|
43
|
+
const payload = {
|
|
44
|
+
connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
45
|
+
connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
46
|
+
userAgent: getUserAgent(config)
|
|
47
|
+
};
|
|
48
|
+
if (!config.browser[1].toLocaleLowerCase().includes('android')) {
|
|
49
|
+
payload.webInfo = getWebInfo(config);
|
|
50
|
+
}
|
|
51
|
+
if (config.pushName) {
|
|
52
|
+
payload.pushName = config.pushName;
|
|
53
|
+
}
|
|
54
|
+
return payload;
|
|
55
|
+
};
|
|
56
|
+
export const generateLoginNode = (userJid, config) => {
|
|
57
|
+
const { user, device } = jidDecode(userJid);
|
|
58
|
+
const payload = {
|
|
59
|
+
...getClientPayload(config),
|
|
60
|
+
passive: true,
|
|
61
|
+
pull: true,
|
|
62
|
+
username: +user,
|
|
63
|
+
device: device,
|
|
64
|
+
// TODO: investigate (hard set as false atm)
|
|
65
|
+
lidDbMigrated: false
|
|
66
|
+
};
|
|
67
|
+
return proto.ClientPayload.fromObject(payload);
|
|
68
|
+
};
|
|
69
|
+
const getPlatformType = (platform) => {
|
|
70
|
+
const platformType = platform.toUpperCase();
|
|
71
|
+
if (platformType === 'ANDROID') {
|
|
72
|
+
return proto.DeviceProps.PlatformType.ANDROID_PHONE;
|
|
73
|
+
}
|
|
74
|
+
return (proto.DeviceProps.PlatformType[platformType] ||
|
|
75
|
+
proto.DeviceProps.PlatformType.CHROME);
|
|
76
|
+
};
|
|
77
|
+
export const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
78
|
+
// the app version needs to be md5 hashed
|
|
79
|
+
// and passed in
|
|
80
|
+
const appVersionBuf = createHash('md5')
|
|
81
|
+
.update(config.version.join('.')) // join as string
|
|
82
|
+
.digest();
|
|
83
|
+
const companion = {
|
|
84
|
+
os: config.browser[0],
|
|
85
|
+
platformType: getPlatformType(config.browser[1]),
|
|
86
|
+
requireFullSync: config.syncFullHistory,
|
|
87
|
+
historySyncConfig: {
|
|
88
|
+
storageQuotaMb: 10240,
|
|
89
|
+
inlineInitialPayloadInE2EeMsg: true,
|
|
90
|
+
recentSyncDaysLimit: undefined,
|
|
91
|
+
supportCallLogHistory: false,
|
|
92
|
+
supportBotUserAgentChatHistory: true,
|
|
93
|
+
supportCagReactionsAndPolls: true,
|
|
94
|
+
supportBizHostedMsg: true,
|
|
95
|
+
supportRecentSyncChunkMessageCountTuning: true,
|
|
96
|
+
supportHostedGroupMsg: true,
|
|
97
|
+
supportFbidBotChatHistory: true,
|
|
98
|
+
supportAddOnHistorySyncMigration: undefined,
|
|
99
|
+
supportMessageAssociation: true,
|
|
100
|
+
supportGroupHistory: false,
|
|
101
|
+
onDemandReady: undefined,
|
|
102
|
+
supportGuestChat: undefined
|
|
103
|
+
},
|
|
104
|
+
version: {
|
|
105
|
+
primary: 10,
|
|
106
|
+
secondary: 15,
|
|
107
|
+
tertiary: 7
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const companionProto = proto.DeviceProps.encode(companion).finish();
|
|
111
|
+
const registerPayload = {
|
|
112
|
+
...getClientPayload(config),
|
|
113
|
+
passive: false,
|
|
114
|
+
pull: false,
|
|
115
|
+
devicePairingData: {
|
|
116
|
+
buildHash: appVersionBuf,
|
|
117
|
+
deviceProps: companionProto,
|
|
118
|
+
eRegid: encodeBigEndian(registrationId),
|
|
119
|
+
eKeytype: KEY_BUNDLE_TYPE,
|
|
120
|
+
eIdent: signedIdentityKey.public,
|
|
121
|
+
eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
|
|
122
|
+
eSkeyVal: signedPreKey.keyPair.public,
|
|
123
|
+
eSkeySig: signedPreKey.signature
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
return proto.ClientPayload.fromObject(registerPayload);
|
|
127
|
+
};
|
|
128
|
+
export const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
129
|
+
const msgId = stanza.attrs.id;
|
|
130
|
+
const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success');
|
|
131
|
+
const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity');
|
|
132
|
+
const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform');
|
|
133
|
+
const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device');
|
|
134
|
+
const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz');
|
|
135
|
+
if (!deviceIdentityNode || !deviceNode) {
|
|
136
|
+
throw new HttpError('Missing device-identity or device in pair success node', { data: stanza });
|
|
137
|
+
}
|
|
138
|
+
const bizName = businessNode?.attrs.name;
|
|
139
|
+
const jid = deviceNode.attrs.jid;
|
|
140
|
+
const lid = deviceNode.attrs.lid;
|
|
141
|
+
const { details, hmac, accountType } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
142
|
+
let hmacPrefix = Buffer.from([]);
|
|
143
|
+
if (accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED) {
|
|
144
|
+
hmacPrefix = WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX;
|
|
145
|
+
}
|
|
146
|
+
const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
147
|
+
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
148
|
+
throw new HttpError('Invalid account signature');
|
|
149
|
+
}
|
|
150
|
+
const account = proto.ADVSignedDeviceIdentity.decode(details);
|
|
151
|
+
const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
|
|
152
|
+
const deviceIdentity = proto.ADVDeviceIdentity.decode(deviceDetails);
|
|
153
|
+
const accountSignaturePrefix = deviceIdentity.deviceType === proto.ADVEncryptionType.HOSTED
|
|
154
|
+
? WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
155
|
+
: WA_ADV_ACCOUNT_SIG_PREFIX;
|
|
156
|
+
const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
|
|
157
|
+
if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
158
|
+
throw new HttpError('Failed to verify account signature');
|
|
159
|
+
}
|
|
160
|
+
const deviceMsg = Buffer.concat([
|
|
161
|
+
WA_ADV_DEVICE_SIG_PREFIX,
|
|
162
|
+
deviceDetails,
|
|
163
|
+
signedIdentityKey.public,
|
|
164
|
+
accountSignatureKey
|
|
165
|
+
]);
|
|
166
|
+
account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
167
|
+
const identity = createSignalIdentity(lid, accountSignatureKey);
|
|
168
|
+
const accountEnc = encodeSignedDeviceIdentity(account, false);
|
|
169
|
+
const reply = {
|
|
170
|
+
tag: 'iq',
|
|
171
|
+
attrs: {
|
|
172
|
+
to: S_WHATSAPP_NET,
|
|
173
|
+
type: 'result',
|
|
174
|
+
id: msgId
|
|
175
|
+
},
|
|
176
|
+
content: [
|
|
177
|
+
{
|
|
178
|
+
tag: 'pair-device-sign',
|
|
179
|
+
attrs: {},
|
|
180
|
+
content: [
|
|
181
|
+
{
|
|
182
|
+
tag: 'device-identity',
|
|
183
|
+
attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
|
|
184
|
+
content: accountEnc
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
};
|
|
190
|
+
const authUpdate = {
|
|
191
|
+
account,
|
|
192
|
+
me: { id: jid, name: bizName, lid },
|
|
193
|
+
signalIdentities: [...(signalIdentities || []), identity],
|
|
194
|
+
platform: platformNode?.attrs.name,
|
|
195
|
+
registered: true
|
|
196
|
+
};
|
|
197
|
+
return {
|
|
198
|
+
creds: authUpdate,
|
|
199
|
+
reply
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
export const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
203
|
+
account = { ...account };
|
|
204
|
+
// set to null if we are not to include the signature key
|
|
205
|
+
// or if we are including the signature key but it is empty
|
|
206
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
207
|
+
account.accountSignatureKey = null;
|
|
208
|
+
}
|
|
209
|
+
return proto.ADVSignedDeviceIdentity.encode(account).finish();
|
|
210
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export namespace Browsers {
|
|
2
|
+
function ubuntu(browser: any): any[];
|
|
3
|
+
function macOS(browser: any): any[];
|
|
4
|
+
function baileys(browser: any): any[];
|
|
5
|
+
function windows(browser: any): any[];
|
|
6
|
+
function android(browser: any): any[];
|
|
7
|
+
function appropriate(browser: any): any[];
|
|
8
|
+
}
|
|
9
|
+
export function getPlatformId(browser: any): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { platform, release } from 'node:os';
|
|
2
|
+
import { proto } from '../../../WAProto/index.js';
|
|
3
|
+
const PLATFORM_MAP = {
|
|
4
|
+
aix: 'AIX',
|
|
5
|
+
darwin: 'Mac OS',
|
|
6
|
+
win32: 'Windows',
|
|
7
|
+
android: 'Android',
|
|
8
|
+
freebsd: 'FreeBSD',
|
|
9
|
+
openbsd: 'OpenBSD',
|
|
10
|
+
sunos: 'Solaris',
|
|
11
|
+
linux: undefined,
|
|
12
|
+
haiku: undefined,
|
|
13
|
+
cygwin: undefined,
|
|
14
|
+
netbsd: undefined
|
|
15
|
+
};
|
|
16
|
+
export const Browsers = {
|
|
17
|
+
ubuntu: browser => ['Ubuntu', browser, '22.04.4'],
|
|
18
|
+
macOS: browser => ['Mac OS', browser, '14.4.1'],
|
|
19
|
+
baileys: browser => ['Baileys', browser, '6.5.0'],
|
|
20
|
+
windows: browser => ['Windows', browser, '10.0.22631'],
|
|
21
|
+
android: browser => [browser, 'Android', ''],
|
|
22
|
+
/** The appropriate browser based on your OS & release */
|
|
23
|
+
appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', browser, release()]
|
|
24
|
+
};
|
|
25
|
+
export const getPlatformId = (browser) => {
|
|
26
|
+
const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
27
|
+
return platformType ? platformType.toString() : '1'; //chrome
|
|
28
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export function promiseTimeout(ms: any, promise: any): Promise<any>;
|
|
2
|
+
export function bindWaitForEvent(ev: any, event: any): (check: any, timeoutMs: any) => Promise<void>;
|
|
3
|
+
export function trimUndefined(obj: any): any;
|
|
4
|
+
export function bytesToCrockford(buffer: any): string;
|
|
5
|
+
export function encodeNewsletterMessage(message: any): Uint8Array<ArrayBufferLike>;
|
|
6
|
+
export namespace BufferJSON {
|
|
7
|
+
function replacer(k: any, value: any): any;
|
|
8
|
+
function reviver(_: any, value: any): any;
|
|
9
|
+
}
|
|
10
|
+
export function getKeyAuthor(key: any, meId?: string): any;
|
|
11
|
+
export function isStringNullOrEmpty(value: any): boolean;
|
|
12
|
+
export function writeRandomPadMax16(msg: any): any;
|
|
13
|
+
export function unpadRandomMax16(e: any): Uint8Array<any>;
|
|
14
|
+
export function generateParticipantHashV2(participants: any): string;
|
|
15
|
+
export function encodeWAMessage(message: any): any;
|
|
16
|
+
export function generateRegistrationId(): number;
|
|
17
|
+
export function encodeBigEndian(e: any, t?: number): Uint8Array<ArrayBuffer>;
|
|
18
|
+
export function toNumber(t: any): any;
|
|
19
|
+
export function unixTimestampSeconds(date?: Date): number;
|
|
20
|
+
export function debouncedTimeout(intervalMs: number | undefined, task: any): {
|
|
21
|
+
start: (newIntervalMs: any, newTask: any) => void;
|
|
22
|
+
cancel: () => void;
|
|
23
|
+
setTask: (newTask: any) => any;
|
|
24
|
+
setInterval: (newInterval: any) => any;
|
|
25
|
+
};
|
|
26
|
+
export function delay(ms: any): Promise<any>;
|
|
27
|
+
export function delayCancellable(ms: any): {
|
|
28
|
+
delay: Promise<any>;
|
|
29
|
+
cancel: () => void;
|
|
30
|
+
};
|
|
31
|
+
export function generateMessageIDV2(userId: any): string;
|
|
32
|
+
export function generateMessageID(): string;
|
|
33
|
+
export function bindWaitForConnectionUpdate(ev: any): (check: any, timeoutMs: any) => Promise<void>;
|
|
34
|
+
export function fetchLatestBaileysVersion(options?: {}): Promise<{
|
|
35
|
+
version: number[];
|
|
36
|
+
isLatest: boolean;
|
|
37
|
+
error?: undefined;
|
|
38
|
+
} | {
|
|
39
|
+
version: number[];
|
|
40
|
+
isLatest: boolean;
|
|
41
|
+
error: unknown;
|
|
42
|
+
}>;
|
|
43
|
+
export function fetchLatestWaWebVersion(options?: {}): Promise<{
|
|
44
|
+
version: number[];
|
|
45
|
+
isLatest: boolean;
|
|
46
|
+
error?: undefined;
|
|
47
|
+
} | {
|
|
48
|
+
version: number[];
|
|
49
|
+
isLatest: boolean;
|
|
50
|
+
error: unknown;
|
|
51
|
+
}>;
|
|
52
|
+
export function generateMdTagPrefix(): string;
|
|
53
|
+
export function getStatusFromReceiptType(type: any): any;
|
|
54
|
+
export function getErrorCodeFromStreamError(node: any): {
|
|
55
|
+
reason: any;
|
|
56
|
+
statusCode: number;
|
|
57
|
+
};
|
|
58
|
+
export function getCallStatusFromNode({ tag, attrs }: {
|
|
59
|
+
tag: any;
|
|
60
|
+
attrs: any;
|
|
61
|
+
}): string;
|
|
62
|
+
export function getCodeFromWSError(error: any): number;
|
|
63
|
+
export function isWABusinessPlatform(platform: any): boolean;
|