vialeys 0.0.1 → 0.0.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/README.md +11 -5
- package/WAProto/AICommon/AICommon.js +13991 -9169
- package/WAProto/AICommon/AICommon.proto +110 -3
- package/WAProto/CompanionReg/CompanionReg.js +114 -0
- package/WAProto/CompanionReg/CompanionReg.proto +3 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.js +652 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +19 -0
- package/WAProto/E2E/E2E.js +77193 -51248
- package/WAProto/E2E/E2E.proto +68 -12
- package/WAProto/HistorySync/HistorySync.js +3375 -178
- package/WAProto/HistorySync/HistorySync.proto +3 -3
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +98 -49
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +2 -2
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +75226 -48422
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +6 -0
- package/WAProto/StatusAttributions/StatusAttributions.js +21 -0
- package/WAProto/StatusAttributions/StatusAttributions.proto +3 -0
- package/WAProto/SyncAction/SyncAction.js +9423 -2023
- package/WAProto/SyncAction/SyncAction.proto +208 -15
- package/WAProto/Wa6/Wa6.js +83 -0
- package/WAProto/Wa6/Wa6.proto +3 -0
- package/WAProto/Web/Web.js +92664 -63403
- package/WAProto/Web/Web.proto +31 -13
- package/engine-requirements.js +9 -7
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/connection.js +51 -0
- package/lib/Defaults/constants.js +62 -0
- package/lib/Defaults/history.js +17 -0
- package/lib/Defaults/index.js +36 -142
- package/lib/Defaults/media.js +48 -0
- package/lib/Defaults/prefix.js +18 -0
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +9 -6
- package/lib/Signal/Group/index.js +39 -53
- package/lib/Signal/Group/keyhelper.js +8 -41
- package/lib/Signal/Group/sender-chain-key.js +4 -4
- package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
- package/lib/Signal/Group/sender-key-message.js +12 -8
- package/lib/Signal/Group/sender-key-state.js +4 -4
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.js +45 -69
- package/lib/Signal/lid-mapping.js +15 -11
- package/lib/Socket/Client/types.js +2 -2
- package/lib/Socket/Client/websocket.js +16 -14
- package/lib/Socket/business.js +41 -32
- package/lib/Socket/chats.js +123 -98
- package/lib/Socket/community.js +50 -40
- package/lib/Socket/groups.js +59 -47
- package/lib/Socket/index.js +4 -4
- package/lib/Socket/messages-recv.js +226 -171
- package/lib/Socket/messages-send.js +187 -143
- package/lib/Socket/newsletter.js +61 -47
- package/lib/Socket/socket.js +133 -90
- package/lib/Socket/usync.js +6 -6
- package/lib/Store/index.js +27 -11
- package/lib/Store/make-cache-manager-store.js +14 -15
- package/lib/Store/make-in-memory-store.js +28 -24
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +6 -6
- package/lib/Types/MexUpdates.js +5 -4
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +28 -12
- package/lib/Utils/auth-utils.js +28 -26
- package/lib/Utils/baileys-event-stream.js +68 -69
- package/lib/Utils/business.js +63 -53
- package/lib/Utils/chat-utils.js +81 -71
- package/lib/Utils/crypto.js +25 -45
- package/lib/Utils/decode-wa-message.js +319 -311
- package/lib/Utils/event-buffer.js +21 -22
- package/lib/Utils/generics.js +103 -73
- package/lib/Utils/history.js +21 -21
- package/lib/Utils/index.js +27 -13
- package/lib/Utils/link-preview.js +7 -30
- package/lib/Utils/logger.js +5 -5
- package/lib/Utils/lt-hash.js +3 -3
- package/lib/Utils/message-retry-manager.js +4 -4
- package/lib/Utils/messages-media.js +104 -109
- package/lib/Utils/messages.js +203 -171
- package/lib/Utils/noise-handler.js +28 -19
- package/lib/Utils/process-message.js +370 -136
- package/lib/Utils/signal.js +36 -25
- package/lib/Utils/use-multi-file-auth-state.js +18 -22
- package/lib/Utils/validate-connection.js +52 -45
- package/lib/WABinary/decode.js +6 -32
- package/lib/WABinary/encode.js +3 -29
- package/lib/WABinary/generic-utils.js +4 -4
- package/lib/WABinary/index.js +27 -11
- package/lib/WAM/encode.js +16 -8
- package/lib/WAM/index.js +27 -11
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/index.js +27 -11
- package/lib/WAUSync/USyncQuery.js +17 -10
- package/lib/WAUSync/index.js +27 -11
- package/lib/index.js +62 -37
- package/package.json +1 -1
- package/WAProto/index.d.ts +0 -55
- package/lib/index.d.ts +0 -13
package/lib/Utils/signal.js
CHANGED
|
@@ -2,16 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const { chunk } = require("lodash")
|
|
6
|
+
const { KEY_BUNDLE_TYPE } = require("../Defaults/constants")
|
|
7
|
+
const {
|
|
8
|
+
S_WHATSAPP_NET,
|
|
9
|
+
getBinaryNodeChild,
|
|
10
|
+
getBinaryNodeChildren,
|
|
11
|
+
getBinaryNodeChildUInt,
|
|
12
|
+
getBinaryNodeChildBuffer,
|
|
13
|
+
assertNodeErrorFree,
|
|
14
|
+
jidDecode
|
|
15
|
+
} = require("../WABinary")
|
|
16
|
+
const {
|
|
17
|
+
Curve,
|
|
18
|
+
generateSignalPubKey
|
|
19
|
+
} = require("./crypto")
|
|
20
|
+
const { encodeBigEndian } = require("./generics")
|
|
10
21
|
|
|
11
22
|
const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
12
23
|
return {
|
|
13
24
|
identifier: { name: wid, deviceId: 0 },
|
|
14
|
-
identifierKey:
|
|
25
|
+
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
15
26
|
}
|
|
16
27
|
}
|
|
17
28
|
|
|
@@ -30,7 +41,7 @@ const generateOrGetPreKeys = (creds, range) => {
|
|
|
30
41
|
const newPreKeys = {}
|
|
31
42
|
if (remaining > 0) {
|
|
32
43
|
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
33
|
-
newPreKeys[i] =
|
|
44
|
+
newPreKeys[i] = Curve.generateKeyPair()
|
|
34
45
|
}
|
|
35
46
|
}
|
|
36
47
|
return {
|
|
@@ -44,7 +55,7 @@ const xmppSignedPreKey = (key) => ({
|
|
|
44
55
|
tag: 'skey',
|
|
45
56
|
attrs: {},
|
|
46
57
|
content: [
|
|
47
|
-
{ tag: 'id', attrs: {}, content:
|
|
58
|
+
{ tag: 'id', attrs: {}, content: encodeBigEndian(key.keyId, 3) },
|
|
48
59
|
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
49
60
|
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
50
61
|
]
|
|
@@ -54,20 +65,20 @@ const xmppPreKey = (pair, id) => ({
|
|
|
54
65
|
tag: 'key',
|
|
55
66
|
attrs: {},
|
|
56
67
|
content: [
|
|
57
|
-
{ tag: 'id', attrs: {}, content:
|
|
68
|
+
{ tag: 'id', attrs: {}, content: encodeBigEndian(id, 3) },
|
|
58
69
|
{ tag: 'value', attrs: {}, content: pair.public }
|
|
59
70
|
]
|
|
60
71
|
})
|
|
61
72
|
|
|
62
73
|
const parseAndInjectE2ESessions = async (node, repository) => {
|
|
63
74
|
const extractKey = (key) => (key ? ({
|
|
64
|
-
keyId:
|
|
65
|
-
publicKey:
|
|
66
|
-
signature:
|
|
75
|
+
keyId: getBinaryNodeChildUInt(key, 'id', 3),
|
|
76
|
+
publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')),
|
|
77
|
+
signature: getBinaryNodeChildBuffer(key, 'signature')
|
|
67
78
|
}) : undefined)
|
|
68
|
-
const nodes =
|
|
79
|
+
const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user')
|
|
69
80
|
for (const node of nodes) {
|
|
70
|
-
|
|
81
|
+
assertNodeErrorFree(node)
|
|
71
82
|
}
|
|
72
83
|
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
73
84
|
// So Promise.all doesn't really help here,
|
|
@@ -75,19 +86,19 @@ const parseAndInjectE2ESessions = async (node, repository) => {
|
|
|
75
86
|
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
76
87
|
// It's rare case when you need to E2E sessions for so many users, but it's possible
|
|
77
88
|
const chunkSize = 100
|
|
78
|
-
const chunks =
|
|
89
|
+
const chunks = chunk(nodes, chunkSize)
|
|
79
90
|
for (const nodesChunk of chunks) {
|
|
80
91
|
await Promise.all(nodesChunk.map(async (node) => {
|
|
81
|
-
const signedKey =
|
|
82
|
-
const key =
|
|
83
|
-
const identity =
|
|
92
|
+
const signedKey = getBinaryNodeChild(node, 'skey')
|
|
93
|
+
const key = getBinaryNodeChild(node, 'key')
|
|
94
|
+
const identity = getBinaryNodeChildBuffer(node, 'identity')
|
|
84
95
|
const jid = node.attrs.jid
|
|
85
|
-
const registrationId =
|
|
96
|
+
const registrationId = getBinaryNodeChildUInt(node, 'registration', 4)
|
|
86
97
|
await repository.injectE2ESession({
|
|
87
98
|
jid,
|
|
88
99
|
session: {
|
|
89
100
|
registrationId: registrationId,
|
|
90
|
-
identityKey:
|
|
101
|
+
identityKey: generateSignalPubKey(identity),
|
|
91
102
|
signedPreKey: extractKey(signedKey),
|
|
92
103
|
preKey: extractKey(key)
|
|
93
104
|
}
|
|
@@ -97,11 +108,11 @@ const parseAndInjectE2ESessions = async (node, repository) => {
|
|
|
97
108
|
}
|
|
98
109
|
|
|
99
110
|
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
100
|
-
const { user: myUser, device: myDevice } =
|
|
111
|
+
const { user: myUser, device: myDevice } = jidDecode(myJid)
|
|
101
112
|
const extracted = []
|
|
102
113
|
for (const userResult of result) {
|
|
103
114
|
const { devices, id } = userResult
|
|
104
|
-
const { user } =
|
|
115
|
+
const { user } = jidDecode(id)
|
|
105
116
|
const deviceList = devices?.deviceList
|
|
106
117
|
if (Array.isArray(deviceList)) {
|
|
107
118
|
for (const { id: device, keyIndex } of deviceList) {
|
|
@@ -140,11 +151,11 @@ const getNextPreKeysNode = async (state, count) => {
|
|
|
140
151
|
attrs: {
|
|
141
152
|
xmlns: 'encrypt',
|
|
142
153
|
type: 'set',
|
|
143
|
-
to:
|
|
154
|
+
to: S_WHATSAPP_NET,
|
|
144
155
|
},
|
|
145
156
|
content: [
|
|
146
|
-
{ tag: 'registration', attrs: {}, content:
|
|
147
|
-
{ tag: 'type', attrs: {}, content:
|
|
157
|
+
{ tag: 'registration', attrs: {}, content: encodeBigEndian(creds.registrationId) },
|
|
158
|
+
{ tag: 'type', attrs: {}, content: KEY_BUNDLE_TYPE },
|
|
148
159
|
{ tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
|
|
149
160
|
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
|
|
150
161
|
xmppSignedPreKey(creds.signedPreKey)
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
5
|
-
}
|
|
6
|
-
|
|
7
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
8
4
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
5
|
+
const { Mutex } = require("async-mutex")
|
|
6
|
+
const { promises } = require("fs")
|
|
7
|
+
const { join } = require("path")
|
|
8
|
+
const { proto } = require("../../WAProto")
|
|
9
|
+
const { initAuthCreds } = require("./auth-utils")
|
|
10
|
+
const { BufferJSON } = require("./generics")
|
|
15
11
|
// We need to lock files due to the fact that we are using async functions to read and write files
|
|
16
12
|
// https://github.com/WhiskeySockets/Baileys/issues/794
|
|
17
13
|
// https://github.com/nodejs/node/issues/26338
|
|
@@ -22,7 +18,7 @@ const fileLocks = new Map()
|
|
|
22
18
|
const getFileLock = (path) => {
|
|
23
19
|
let mutex = fileLocks.get(path)
|
|
24
20
|
if (!mutex) {
|
|
25
|
-
mutex = new
|
|
21
|
+
mutex = new Mutex()
|
|
26
22
|
fileLocks.set(path, mutex)
|
|
27
23
|
}
|
|
28
24
|
|
|
@@ -39,11 +35,11 @@ const getFileLock = (path) => {
|
|
|
39
35
|
const useMultiFileAuthState = async (folder) => {
|
|
40
36
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
37
|
const writeData = async (data, file) => {
|
|
42
|
-
const filePath =
|
|
38
|
+
const filePath = join(folder, fixFileName(file))
|
|
43
39
|
const mutex = getFileLock(filePath)
|
|
44
40
|
return mutex.acquire().then(async (release) => {
|
|
45
41
|
try {
|
|
46
|
-
await
|
|
42
|
+
await promises.writeFile(filePath, JSON.stringify(data, BufferJSON.replacer))
|
|
47
43
|
} finally {
|
|
48
44
|
release()
|
|
49
45
|
}
|
|
@@ -51,47 +47,47 @@ const useMultiFileAuthState = async (folder) => {
|
|
|
51
47
|
}
|
|
52
48
|
const readData = async (file) => {
|
|
53
49
|
try {
|
|
54
|
-
const filePath =
|
|
50
|
+
const filePath = join(folder, fixFileName(file))
|
|
55
51
|
const mutex = getFileLock(filePath)
|
|
56
52
|
const data = await mutex.acquire().then(async (release) => {
|
|
57
53
|
try {
|
|
58
|
-
return await
|
|
54
|
+
return await promises.readFile(filePath, { encoding: 'utf-8' })
|
|
59
55
|
} finally {
|
|
60
56
|
release()
|
|
61
57
|
}
|
|
62
58
|
})
|
|
63
59
|
|
|
64
|
-
return JSON.parse(data,
|
|
60
|
+
return JSON.parse(data, BufferJSON.reviver)
|
|
65
61
|
} catch (error) {
|
|
66
62
|
return null
|
|
67
63
|
}
|
|
68
64
|
}
|
|
69
65
|
const removeData = async (file) => {
|
|
70
66
|
try {
|
|
71
|
-
const filePath =
|
|
67
|
+
const filePath = join(folder, fixFileName(file))
|
|
72
68
|
const mutex = getFileLock(filePath)
|
|
73
69
|
await mutex.acquire().then(async (release) => {
|
|
74
70
|
try {
|
|
75
|
-
await
|
|
71
|
+
await promises.unlink(filePath)
|
|
76
72
|
} finally {
|
|
77
73
|
release()
|
|
78
74
|
}
|
|
79
75
|
})
|
|
80
76
|
} catch {}
|
|
81
77
|
}
|
|
82
|
-
const folderInfo = await
|
|
78
|
+
const folderInfo = await promises.stat(folder).catch(() => { })
|
|
83
79
|
if (folderInfo) {
|
|
84
80
|
if (!folderInfo.isDirectory()) {
|
|
85
81
|
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`)
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
84
|
else {
|
|
89
|
-
await
|
|
85
|
+
await promises.mkdir(folder, { recursive: true })
|
|
90
86
|
}
|
|
91
87
|
const fixFileName = (file) => {
|
|
92
88
|
return file?.replace(/\//g, '__')?.replace(/:/g, '-')
|
|
93
89
|
}
|
|
94
|
-
const creds = await readData('creds.json') ||
|
|
90
|
+
const creds = await readData('creds.json') || initAuthCreds()
|
|
95
91
|
return {
|
|
96
92
|
state: {
|
|
97
93
|
creds,
|
|
@@ -101,7 +97,7 @@ const useMultiFileAuthState = async (folder) => {
|
|
|
101
97
|
await Promise.all(ids.map(async (id) => {
|
|
102
98
|
let value = await readData(`${type}-${id}.json`)
|
|
103
99
|
if (type === 'app-state-sync-key' && value) {
|
|
104
|
-
value =
|
|
100
|
+
value = proto.Message.AppStateSyncKeyData.fromObject(value)
|
|
105
101
|
}
|
|
106
102
|
data[id] = value
|
|
107
103
|
}))
|
|
@@ -2,14 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
const { Boom } = require("@hapi/boom")
|
|
6
|
+
const { createHash } = require("crypto")
|
|
7
|
+
const { proto } = require("../../WAProto")
|
|
8
|
+
const { KEY_BUNDLE_TYPE } = require("../Defaults/constants")
|
|
9
|
+
const {
|
|
10
|
+
jidDecode,
|
|
11
|
+
getBinaryNodeChild,
|
|
12
|
+
S_WHATSAPP_NET
|
|
13
|
+
} = require("../WABinary")
|
|
14
|
+
const {
|
|
15
|
+
Curve,
|
|
16
|
+
hmacSign
|
|
17
|
+
} = require("./crypto")
|
|
18
|
+
const { encodeBigEndian } = require("./generics")
|
|
19
|
+
const { createSignalIdentity } = require("./signal")
|
|
13
20
|
|
|
14
21
|
const getUserAgent = (config) => {
|
|
15
22
|
return {
|
|
@@ -18,8 +25,8 @@ const getUserAgent = (config) => {
|
|
|
18
25
|
secondary: config.version[1],
|
|
19
26
|
tertiary: config.version[2],
|
|
20
27
|
},
|
|
21
|
-
platform:
|
|
22
|
-
releaseChannel:
|
|
28
|
+
platform: proto.ClientPayload.UserAgent.Platform.WEB,
|
|
29
|
+
releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
23
30
|
osVersion: '0.1',
|
|
24
31
|
device: 'Desktop',
|
|
25
32
|
osBuildNumber: '0.1',
|
|
@@ -31,13 +38,13 @@ const getUserAgent = (config) => {
|
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
const PLATFORM_MAP = {
|
|
34
|
-
'Mac OS':
|
|
35
|
-
'Windows':
|
|
36
|
-
'Android':
|
|
41
|
+
'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
42
|
+
'Windows': proto.ClientPayload.WebInfo.WebSubPlatform.WIN32,
|
|
43
|
+
'Android': proto.ClientPayload.WebInfo.WebSubPlatform.WIN_HYBRID
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
const getWebInfo = (config) => {
|
|
40
|
-
let webSubPlatform =
|
|
47
|
+
let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER
|
|
41
48
|
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
|
|
42
49
|
webSubPlatform = PLATFORM_MAP[config.browser[0]]
|
|
43
50
|
}
|
|
@@ -46,8 +53,8 @@ const getWebInfo = (config) => {
|
|
|
46
53
|
|
|
47
54
|
const getClientPayload = (config) => {
|
|
48
55
|
const payload = {
|
|
49
|
-
connectType:
|
|
50
|
-
connectReason:
|
|
56
|
+
connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
57
|
+
connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
51
58
|
userAgent: getUserAgent(config),
|
|
52
59
|
}
|
|
53
60
|
payload.webInfo = getWebInfo(config)
|
|
@@ -55,7 +62,7 @@ const getClientPayload = (config) => {
|
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
const generateLoginNode = (userJid, config) => {
|
|
58
|
-
const { user, device } =
|
|
65
|
+
const { user, device } = jidDecode(userJid)
|
|
59
66
|
const payload = {
|
|
60
67
|
...getClientPayload(config),
|
|
61
68
|
passive: false,
|
|
@@ -63,18 +70,18 @@ const generateLoginNode = (userJid, config) => {
|
|
|
63
70
|
username: +user,
|
|
64
71
|
device: device,
|
|
65
72
|
}
|
|
66
|
-
return
|
|
73
|
+
return proto.ClientPayload.fromObject(payload)
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
const getPlatformType = (platform) => {
|
|
70
77
|
const platformType = platform.toUpperCase()
|
|
71
|
-
return
|
|
78
|
+
return proto.DeviceProps.PlatformType[platformType] || proto.DeviceProps.PlatformType.DESKTOP
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
75
82
|
// the app version needs to be md5 hashed
|
|
76
83
|
// and passed in
|
|
77
|
-
const appVersionBuf =
|
|
84
|
+
const appVersionBuf = createHash('md5')
|
|
78
85
|
.update(config.version.join('.')) // join as string
|
|
79
86
|
.digest()
|
|
80
87
|
|
|
@@ -106,7 +113,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
106
113
|
}
|
|
107
114
|
}
|
|
108
115
|
|
|
109
|
-
const companionProto =
|
|
116
|
+
const companionProto = proto.DeviceProps.encode(companion).finish()
|
|
110
117
|
|
|
111
118
|
const registerPayload = {
|
|
112
119
|
...getClientPayload(config),
|
|
@@ -115,55 +122,55 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
115
122
|
devicePairingData: {
|
|
116
123
|
buildHash: appVersionBuf,
|
|
117
124
|
deviceProps: companionProto,
|
|
118
|
-
eRegid:
|
|
119
|
-
eKeytype:
|
|
125
|
+
eRegid: encodeBigEndian(registrationId),
|
|
126
|
+
eKeytype: KEY_BUNDLE_TYPE,
|
|
120
127
|
eIdent: signedIdentityKey.public,
|
|
121
|
-
eSkeyId:
|
|
128
|
+
eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
|
|
122
129
|
eSkeyVal: signedPreKey.keyPair.public,
|
|
123
130
|
eSkeySig: signedPreKey.signature,
|
|
124
131
|
}
|
|
125
132
|
}
|
|
126
133
|
|
|
127
|
-
return
|
|
134
|
+
return proto.ClientPayload.fromObject(registerPayload)
|
|
128
135
|
}
|
|
129
136
|
|
|
130
137
|
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
131
138
|
const msgId = stanza.attrs.id
|
|
132
|
-
const pairSuccessNode =
|
|
133
|
-
const deviceIdentityNode =
|
|
134
|
-
const platformNode =
|
|
135
|
-
const deviceNode =
|
|
136
|
-
const businessNode =
|
|
139
|
+
const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success')
|
|
140
|
+
const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity')
|
|
141
|
+
const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform')
|
|
142
|
+
const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device')
|
|
143
|
+
const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz')
|
|
137
144
|
if (!deviceIdentityNode || !deviceNode) {
|
|
138
|
-
throw new
|
|
145
|
+
throw new Boom('Missing device-identity or device in pair success node', { data: stanza })
|
|
139
146
|
}
|
|
140
147
|
const bizName = businessNode?.attrs?.name
|
|
141
148
|
const jid = deviceNode.attrs.jid
|
|
142
149
|
const lid = deviceNode.attrs.lid
|
|
143
|
-
const { details, hmac, accountType } =
|
|
150
|
+
const { details, hmac, accountType } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content)
|
|
144
151
|
|
|
145
152
|
let hmacPrefix = Buffer.from([])
|
|
146
|
-
if (accountType !== undefined && accountType ===
|
|
153
|
+
if (accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED) {
|
|
147
154
|
hmacPrefix = Buffer.from([6, 5])
|
|
148
155
|
}
|
|
149
156
|
|
|
150
|
-
const advSign =
|
|
157
|
+
const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'))
|
|
151
158
|
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
152
|
-
throw new
|
|
159
|
+
throw new Boom('Invalid account signature')
|
|
153
160
|
}
|
|
154
161
|
|
|
155
|
-
const account =
|
|
162
|
+
const account = proto.ADVSignedDeviceIdentity.decode(details)
|
|
156
163
|
const { accountSignatureKey, accountSignature, details: deviceDetails } = account
|
|
157
164
|
|
|
158
|
-
const decodedDeviceIdentity =
|
|
165
|
+
const decodedDeviceIdentity = proto.ADVDeviceIdentity.decode(deviceDetails)
|
|
159
166
|
|
|
160
167
|
const accountSignaturePrefix =
|
|
161
|
-
decodedDeviceIdentity.deviceType ===
|
|
168
|
+
decodedDeviceIdentity.deviceType === proto.ADVEncryptionType.HOSTED
|
|
162
169
|
? Buffer.from([6, 5])
|
|
163
170
|
: Buffer.from([6, 0])
|
|
164
171
|
const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public])
|
|
165
|
-
if (!
|
|
166
|
-
throw new
|
|
172
|
+
if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
173
|
+
throw new Boom('Failed to verify account signature')
|
|
167
174
|
}
|
|
168
175
|
|
|
169
176
|
const deviceMsg = Buffer.concat([
|
|
@@ -172,14 +179,14 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
172
179
|
signedIdentityKey.public,
|
|
173
180
|
accountSignatureKey
|
|
174
181
|
])
|
|
175
|
-
account.deviceSignature =
|
|
176
|
-
const identity =
|
|
182
|
+
account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg)
|
|
183
|
+
const identity = createSignalIdentity(lid, accountSignatureKey)
|
|
177
184
|
const accountEnc = encodeSignedDeviceIdentity(account, false)
|
|
178
|
-
const deviceIdentityData =
|
|
185
|
+
const deviceIdentityData = proto.ADVDeviceIdentity.decode(account.details)
|
|
179
186
|
const reply = {
|
|
180
187
|
tag: 'iq',
|
|
181
188
|
attrs: {
|
|
182
|
-
to:
|
|
189
|
+
to: S_WHATSAPP_NET,
|
|
183
190
|
type: 'result',
|
|
184
191
|
id: msgId,
|
|
185
192
|
},
|
|
@@ -219,7 +226,7 @@ const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
|
219
226
|
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
220
227
|
account.accountSignatureKey = null
|
|
221
228
|
}
|
|
222
|
-
return
|
|
229
|
+
return proto.ADVSignedDeviceIdentity.encode(account).finish()
|
|
223
230
|
}
|
|
224
231
|
|
|
225
232
|
module.exports = {
|
package/lib/WABinary/decode.js
CHANGED
|
@@ -1,38 +1,12 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod
|
|
23
|
-
var result = {}
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
|
|
25
|
-
__setModuleDefault(result, mod)
|
|
26
|
-
return result
|
|
27
|
-
}
|
|
28
|
-
|
|
29
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
30
4
|
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const inflatePromise =
|
|
5
|
+
const { promisify } = require("util")
|
|
6
|
+
const { inflate } = require("zlib")
|
|
7
|
+
const { jidEncode } = require("./jid-utils")
|
|
8
|
+
const constants = require("./constants")
|
|
9
|
+
const inflatePromise = promisify(inflate)
|
|
36
10
|
|
|
37
11
|
const decompressingIfRequired = async (buffer) => {
|
|
38
12
|
if (2 & buffer.readUInt8()) {
|
|
@@ -168,7 +142,7 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
168
142
|
const agent = readByte()
|
|
169
143
|
const device = readByte()
|
|
170
144
|
const user = readString(readByte())
|
|
171
|
-
return
|
|
145
|
+
return jidEncode(user, agent === 0 ? 's.whatsapp.net' : 'lid', device)
|
|
172
146
|
}
|
|
173
147
|
|
|
174
148
|
const readString = (tag) => {
|
package/lib/WABinary/encode.js
CHANGED
|
@@ -1,35 +1,9 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod
|
|
23
|
-
var result = {}
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
|
|
25
|
-
__setModuleDefault(result, mod)
|
|
26
|
-
return result
|
|
27
|
-
}
|
|
28
|
-
|
|
29
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
30
4
|
|
|
31
|
-
const
|
|
32
|
-
const
|
|
5
|
+
const { jidDecode } = require("./jid-utils")
|
|
6
|
+
const constants = require("./constants")
|
|
33
7
|
|
|
34
8
|
const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
|
|
35
9
|
const encoded = encodeBinaryNodeInner(node, opts, buffer)
|
|
@@ -201,7 +175,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
201
175
|
writePackedBytes(str, 'hex')
|
|
202
176
|
}
|
|
203
177
|
else if (str) {
|
|
204
|
-
const decodedJid =
|
|
178
|
+
const decodedJid = jidDecode(str)
|
|
205
179
|
if (decodedJid) {
|
|
206
180
|
writeJid(decodedJid)
|
|
207
181
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const { Boom } = require("@hapi/boom")
|
|
6
|
+
const { proto } = require("../../WAProto")
|
|
7
7
|
|
|
8
8
|
// some extra useful utilities
|
|
9
9
|
const getBinaryNodeChildren = (node, childTag) => {
|
|
@@ -53,7 +53,7 @@ const getBinaryNodeChildUInt = (node, childTag, length) => {
|
|
|
53
53
|
const assertNodeErrorFree = (node) => {
|
|
54
54
|
const errNode = getBinaryNodeChild(node, 'error')
|
|
55
55
|
if (errNode) {
|
|
56
|
-
throw new
|
|
56
|
+
throw new Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code })
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -71,7 +71,7 @@ const getBinaryNodeMessages = ({ content }) => {
|
|
|
71
71
|
if (Array.isArray(content)) {
|
|
72
72
|
for (const item of content) {
|
|
73
73
|
if (item.tag === 'message') {
|
|
74
|
-
msgs.push(
|
|
74
|
+
msgs.push(proto.WebMessageInfo.decode(item.content))
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
package/lib/WABinary/index.js
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
let desc = Object.getOwnPropertyDescriptor(m, k)
|
|
7
|
+
|
|
6
8
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return m[k]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
8
15
|
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
Object.defineProperty(o, k2, desc)
|
|
18
|
+
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k
|
|
21
|
+
o[k2] = m[k]
|
|
22
|
+
}
|
|
23
|
+
))
|
|
24
|
+
|
|
25
|
+
const __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) {
|
|
27
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
28
|
+
__createBinding(exports, m, p)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
17
31
|
}
|
|
18
32
|
|
|
19
|
-
Object.defineProperty(exports, "__esModule", {
|
|
33
|
+
Object.defineProperty(exports, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
})
|
|
20
36
|
|
|
21
37
|
__exportStar(require("./encode"), exports)
|
|
22
38
|
__exportStar(require("./decode"), exports)
|