@neelegirl/baileys 2.1.9 → 2.2.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/README.md +75 -1617
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +18 -31
- package/lib/Signal/libsignal.d.ts +3 -8
- package/lib/Signal/libsignal.js +79 -279
- package/lib/Socket/chats.js +2 -3
- package/lib/Socket/socket.js +3 -3
- package/lib/Types/Auth.d.ts +2 -15
- package/lib/Types/Contact.d.ts +1 -2
- package/lib/Types/Events.d.ts +1 -4
- package/lib/Types/Message.d.ts +5 -1
- package/lib/Types/Signal.d.ts +1 -16
- package/lib/Types/Socket.d.ts +4 -10
- package/lib/Utils/decode-wa-message.d.ts +4 -4
- package/lib/Utils/decode-wa-message.js +36 -10
- package/lib/Utils/generics.d.ts +4 -3
- package/lib/Utils/generics.js +8 -6
- package/lib/Utils/history.d.ts +4 -11
- package/lib/Utils/history.js +38 -77
- package/lib/Utils/index.d.ts +1 -4
- package/lib/Utils/index.js +1 -2
- package/lib/Utils/message-retry-manager.js +4 -4
- package/lib/Utils/process-message.d.ts +2 -3
- package/lib/Utils/process-message.js +2 -28
- package/lib/WABinary/jid-utils.d.ts +4 -21
- package/lib/WABinary/jid-utils.js +8 -62
- package/package.json +45 -26
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/fix-imports.js +0 -81
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Signal/lid-mapping.js +0 -278
- package/lib/Utils/browser-utils.d.ts +0 -1
- package/lib/Utils/browser-utils.js +0 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
{"version":[2,3000,1032141294]}
|
package/lib/Defaults/index.d.ts
CHANGED
|
@@ -1,28 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import { proto } from '../../WAProto'
|
|
2
2
|
import type { MediaType, SocketConfig } from '../Types'
|
|
3
3
|
|
|
4
4
|
export declare const UNAUTHORIZED_CODES: number[]
|
|
5
5
|
|
|
6
6
|
export declare const PHONENUMBER_MCC: Record<string, number>
|
|
7
7
|
|
|
8
|
-
export declare const DEFAULT_ORIGIN:
|
|
8
|
+
export declare const DEFAULT_ORIGIN: "https://web.whatsapp.com"
|
|
9
9
|
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
|
|
13
|
-
export declare const DEF_CALLBACK_PREFIX: 'CB:'
|
|
14
|
-
export declare const DEF_TAG_PREFIX: 'TAG:'
|
|
15
|
-
export declare const PHONE_CONNECTION_CB: 'CB:Pong'
|
|
16
|
-
|
|
17
|
-
export declare const WA_ADV_ACCOUNT_SIG_PREFIX: Buffer
|
|
18
|
-
export declare const WA_ADV_DEVICE_SIG_PREFIX: Buffer
|
|
19
|
-
export declare const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX: Buffer
|
|
20
|
-
export declare const WA_ADV_HOSTED_DEVICE_SIG_PREFIX: Buffer
|
|
10
|
+
export declare const DEF_CALLBACK_PREFIX: "CB:"
|
|
11
|
+
export declare const DEF_TAG_PREFIX: "TAG:"
|
|
12
|
+
export declare const PHONE_CONNECTION_CB: "CB:Pong"
|
|
21
13
|
|
|
22
14
|
export declare const WA_DEFAULT_EPHEMERAL: number
|
|
23
|
-
export declare const STATUS_EXPIRY_SECONDS: number
|
|
24
15
|
|
|
25
|
-
export declare const NOISE_MODE:
|
|
16
|
+
export declare const NOISE_MODE: "Noise_XX_25519_AESGCM_SHA256\0\0\0\0"
|
|
26
17
|
|
|
27
18
|
export declare const DICT_VERSION: 3
|
|
28
19
|
|
|
@@ -33,8 +24,6 @@ export declare const URL_REGEX: RegExp
|
|
|
33
24
|
|
|
34
25
|
export declare const WA_CERT_DETAILS: {
|
|
35
26
|
SERIAL: number
|
|
36
|
-
ISSUER: string
|
|
37
|
-
PUBLIC_KEY: Buffer
|
|
38
27
|
}
|
|
39
28
|
|
|
40
29
|
export declare const PROCESSABLE_HISTORY_TYPES: proto.Message.HistorySyncNotification.HistorySyncType[]
|
|
@@ -46,16 +35,15 @@ export declare const MEDIA_PATH_MAP: {
|
|
|
46
35
|
}
|
|
47
36
|
|
|
48
37
|
export declare const MEDIA_HKDF_KEY_MAPPING: {
|
|
49
|
-
audio: string
|
|
50
|
-
document: string
|
|
51
|
-
gif: string
|
|
52
|
-
image: string
|
|
53
|
-
ppic: string
|
|
54
|
-
product: string
|
|
55
|
-
ptt: string
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
'sticker-pack': string
|
|
38
|
+
'audio': string
|
|
39
|
+
'document': string
|
|
40
|
+
'gif': string
|
|
41
|
+
'image': string
|
|
42
|
+
'ppic': string
|
|
43
|
+
'product': string
|
|
44
|
+
'ptt': string
|
|
45
|
+
'sticker': string
|
|
46
|
+
'video': string
|
|
59
47
|
'thumbnail-document': string
|
|
60
48
|
'thumbnail-image': string
|
|
61
49
|
'thumbnail-video': string
|
|
@@ -64,18 +52,17 @@ export declare const MEDIA_HKDF_KEY_MAPPING: {
|
|
|
64
52
|
'md-app-state': string
|
|
65
53
|
'product-catalog-image': string
|
|
66
54
|
'payment-bg-image': string
|
|
67
|
-
ptv: string
|
|
68
|
-
'biz-cover-photo': string
|
|
55
|
+
'ptv': string
|
|
69
56
|
}
|
|
70
57
|
|
|
71
58
|
export declare const MEDIA_KEYS: (keyof typeof MEDIA_HKDF_KEY_MAPPING)[]
|
|
72
59
|
|
|
73
60
|
export declare const MIN_PREKEY_COUNT: 5
|
|
74
|
-
export declare const INITIAL_PREKEY_COUNT:
|
|
61
|
+
export declare const INITIAL_PREKEY_COUNT: 30
|
|
75
62
|
|
|
76
63
|
export declare const DEFAULT_CACHE_TTLS: {
|
|
77
64
|
SIGNAL_STORE: number
|
|
78
65
|
MSG_RETRY: number
|
|
79
66
|
CALL_OFFER: number
|
|
80
67
|
USER_DEVICES: number
|
|
81
|
-
}
|
|
68
|
+
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type { ILogger } from '../Utils/logger'
|
|
1
|
+
import { SignalAuthState } from '../Types'
|
|
2
|
+
import { SignalRepository } from '../Types/Signal'
|
|
4
3
|
|
|
5
|
-
export declare function makeLibSignalRepository(
|
|
6
|
-
auth: SignalAuthState,
|
|
7
|
-
logger: ILogger,
|
|
8
|
-
pnToLIDFunc?: (jids: string[]) => Promise<LIDMapping[] | undefined>
|
|
9
|
-
): SignalRepositoryWithLIDStore
|
|
4
|
+
export declare function makeLibSignalRepository(auth: SignalAuthState): SignalRepository
|
package/lib/Signal/libsignal.js
CHANGED
|
@@ -1,323 +1,123 @@
|
|
|
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
|
+
}
|
|
3
28
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
29
|
|
|
5
|
-
const libsignal = require("@neelegirl/libsignal")
|
|
6
|
-
const { PreKeyWhisperMessage } = require("@neelegirl/libsignal/src/protobufs")
|
|
7
|
-
const LRUCacheModule = require("lru-cache")
|
|
8
|
-
const LRUCache = LRUCacheModule.LRUCache || LRUCacheModule
|
|
30
|
+
const libsignal = __importStar(require("@neelegirl/libsignal"))
|
|
9
31
|
const WASignalGroup_1 = require("./WASignalGroup")
|
|
10
|
-
const lid_mapping_1 = require("./lid-mapping")
|
|
11
32
|
const Utils_1 = require("../Utils")
|
|
12
33
|
const WABinary_1 = require("../WABinary")
|
|
13
34
|
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return undefined
|
|
18
|
-
}
|
|
19
|
-
const version = ciphertext[0]
|
|
20
|
-
if ((version & 0xf) !== 3) {
|
|
21
|
-
return undefined
|
|
22
|
-
}
|
|
23
|
-
const preKeyProto = PreKeyWhisperMessage.decode(ciphertext.slice(1))
|
|
24
|
-
if (preKeyProto.identityKey?.length === 33) {
|
|
25
|
-
return new Uint8Array(preKeyProto.identityKey)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch (_error) { }
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function makeLibSignalRepository(auth, logger, pnToLIDFunc) {
|
|
32
|
-
const parsedKeys = auth.keys
|
|
33
|
-
const lidMapping = new lid_mapping_1.LIDMappingStore(parsedKeys, logger, pnToLIDFunc)
|
|
34
|
-
const storage = signalStorage(auth, lidMapping)
|
|
35
|
-
const migratedSessionCache = new LRUCache({
|
|
36
|
-
ttl: 3 * 24 * 60 * 60 * 1000,
|
|
37
|
-
ttlAutopurge: true,
|
|
38
|
-
updateAgeOnGet: true
|
|
39
|
-
})
|
|
40
|
-
const repository = {
|
|
35
|
+
function makeLibSignalRepository(auth) {
|
|
36
|
+
const storage = signalStorage(auth)
|
|
37
|
+
return {
|
|
41
38
|
decryptGroupMessage({ group, authorJid, msg }) {
|
|
42
39
|
const senderName = jidToSignalSenderKeyName(group, authorJid)
|
|
43
40
|
const cipher = new WASignalGroup_1.GroupCipher(storage, senderName)
|
|
44
|
-
return
|
|
45
|
-
return cipher.decrypt(msg)
|
|
46
|
-
}, group)
|
|
41
|
+
return cipher.decrypt(msg)
|
|
47
42
|
},
|
|
48
43
|
async processSenderKeyDistributionMessage({ item, authorJid }) {
|
|
49
|
-
if (!item.groupId) {
|
|
50
|
-
throw new Error('group ID is required for sender key distribution message')
|
|
51
|
-
}
|
|
52
44
|
const builder = new WASignalGroup_1.GroupSessionBuilder(storage)
|
|
53
45
|
const senderName = jidToSignalSenderKeyName(item.groupId, authorJid)
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
item.axolotlSenderKeyDistributionMessage
|
|
61
|
-
)
|
|
62
|
-
return parsedKeys.transaction(async () => {
|
|
63
|
-
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr])
|
|
64
|
-
if (!senderKey) {
|
|
65
|
-
await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord())
|
|
66
|
-
}
|
|
67
|
-
await builder.process(senderName, senderMsg)
|
|
68
|
-
}, item.groupId)
|
|
46
|
+
const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage)
|
|
47
|
+
const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName])
|
|
48
|
+
if (!senderKey) {
|
|
49
|
+
await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord())
|
|
50
|
+
}
|
|
51
|
+
await builder.process(senderName, senderMsg)
|
|
69
52
|
},
|
|
70
53
|
async decryptMessage({ jid, type, ciphertext }) {
|
|
71
54
|
const addr = jidToSignalProtocolAddress(jid)
|
|
72
55
|
const session = new libsignal.SessionCipher(storage, addr)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
56
|
+
let result
|
|
57
|
+
switch (type) {
|
|
58
|
+
case 'pkmsg':
|
|
59
|
+
result = await session.decryptPreKeyWhisperMessage(ciphertext)
|
|
60
|
+
break
|
|
61
|
+
case 'msg':
|
|
62
|
+
result = await session.decryptWhisperMessage(ciphertext)
|
|
63
|
+
break
|
|
82
64
|
}
|
|
83
|
-
return
|
|
84
|
-
switch (type) {
|
|
85
|
-
case 'pkmsg':
|
|
86
|
-
return session.decryptPreKeyWhisperMessage(ciphertext)
|
|
87
|
-
case 'msg':
|
|
88
|
-
default:
|
|
89
|
-
return session.decryptWhisperMessage(ciphertext)
|
|
90
|
-
}
|
|
91
|
-
}, jid)
|
|
65
|
+
return result
|
|
92
66
|
},
|
|
93
67
|
async encryptMessage({ jid, data }) {
|
|
94
68
|
const addr = jidToSignalProtocolAddress(jid)
|
|
95
69
|
const cipher = new libsignal.SessionCipher(storage, addr)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
type,
|
|
101
|
-
ciphertext: Buffer.from(body, 'binary')
|
|
102
|
-
}
|
|
103
|
-
}, jid)
|
|
70
|
+
const { type: sigType, body } = await cipher.encrypt(data)
|
|
71
|
+
const type = sigType === 3 ? 'pkmsg' : 'msg'
|
|
72
|
+
return { type, ciphertext: Buffer.from(body, 'binary') }
|
|
104
73
|
},
|
|
105
74
|
async encryptGroupMessage({ group, meId, data }) {
|
|
106
75
|
const senderName = jidToSignalSenderKeyName(group, meId)
|
|
107
76
|
const builder = new WASignalGroup_1.GroupSessionBuilder(storage)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
77
|
+
const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName])
|
|
78
|
+
if (!senderKey) {
|
|
79
|
+
await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord())
|
|
80
|
+
}
|
|
81
|
+
const senderKeyDistributionMessage = await builder.create(senderName)
|
|
82
|
+
const session = new WASignalGroup_1.GroupCipher(storage, senderName)
|
|
83
|
+
const ciphertext = await session.encrypt(data)
|
|
84
|
+
return {
|
|
85
|
+
ciphertext,
|
|
86
|
+
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
|
|
87
|
+
}
|
|
117
88
|
},
|
|
118
89
|
async injectE2ESession({ jid, session }) {
|
|
119
|
-
logger?.trace?.({ jid }, 'injecting E2EE session')
|
|
120
90
|
const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid))
|
|
121
|
-
|
|
122
|
-
await cipher.initOutgoing(session)
|
|
123
|
-
}, jid)
|
|
91
|
+
await cipher.initOutgoing(session)
|
|
124
92
|
},
|
|
125
93
|
jidToSignalProtocolAddress(jid) {
|
|
126
94
|
return jidToSignalProtocolAddress(jid).toString()
|
|
127
95
|
},
|
|
128
|
-
lidMapping,
|
|
129
|
-
async validateSession(jid) {
|
|
130
|
-
try {
|
|
131
|
-
const addr = jidToSignalProtocolAddress(jid)
|
|
132
|
-
const session = await storage.loadSession(addr.toString())
|
|
133
|
-
if (!session) {
|
|
134
|
-
return { exists: false, reason: 'no session' }
|
|
135
|
-
}
|
|
136
|
-
if (!session.haveOpenSession()) {
|
|
137
|
-
return { exists: false, reason: 'no open session' }
|
|
138
|
-
}
|
|
139
|
-
return { exists: true }
|
|
140
|
-
}
|
|
141
|
-
catch (_error) {
|
|
142
|
-
return { exists: false, reason: 'validation error' }
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
async deleteSession(jids) {
|
|
146
|
-
if (!jids?.length) {
|
|
147
|
-
return
|
|
148
|
-
}
|
|
149
|
-
const sessionUpdates = {}
|
|
150
|
-
for (const jid of jids) {
|
|
151
|
-
const addr = jidToSignalProtocolAddress(jid)
|
|
152
|
-
sessionUpdates[addr.toString()] = null
|
|
153
|
-
}
|
|
154
|
-
await parsedKeys.transaction(async () => {
|
|
155
|
-
await auth.keys.set({ session: sessionUpdates })
|
|
156
|
-
}, `delete-${jids.length}-sessions`)
|
|
157
|
-
},
|
|
158
|
-
async migrateSession(fromJid, toJid) {
|
|
159
|
-
if (!fromJid || (!(0, WABinary_1.isLidUser)(toJid) && !(0, WABinary_1.isHostedLidUser)(toJid))) {
|
|
160
|
-
return { migrated: 0, skipped: 0, total: 0 }
|
|
161
|
-
}
|
|
162
|
-
if (!(0, WABinary_1.isPnUser)(fromJid) && !(0, WABinary_1.isHostedPnUser)(fromJid)) {
|
|
163
|
-
return { migrated: 0, skipped: 0, total: 1 }
|
|
164
|
-
}
|
|
165
|
-
const fromDecoded = (0, WABinary_1.jidDecode)(fromJid)
|
|
166
|
-
const user = fromDecoded?.user
|
|
167
|
-
if (!user) {
|
|
168
|
-
return { migrated: 0, skipped: 0, total: 0 }
|
|
169
|
-
}
|
|
170
|
-
const { [user]: userDevices } = await parsedKeys.get('device-list', [user])
|
|
171
|
-
if (!userDevices?.length) {
|
|
172
|
-
return { migrated: 0, skipped: 0, total: 0 }
|
|
173
|
-
}
|
|
174
|
-
const fromDeviceStr = (fromDecoded?.device || 0).toString()
|
|
175
|
-
if (!userDevices.includes(fromDeviceStr)) {
|
|
176
|
-
userDevices.push(fromDeviceStr)
|
|
177
|
-
}
|
|
178
|
-
const uncachedDeviceJids = userDevices
|
|
179
|
-
.map(device => {
|
|
180
|
-
const deviceNum = parseInt(device, 10)
|
|
181
|
-
const normalizedDevice = Number.isNaN(deviceNum) ? 0 : deviceNum
|
|
182
|
-
return `${user}${normalizedDevice ? `:${normalizedDevice}` : ''}@${normalizedDevice === 99 ? 'hosted' : 's.whatsapp.net'}`
|
|
183
|
-
})
|
|
184
|
-
.filter(jid => !migratedSessionCache.has(jidToSignalProtocolAddress(jid).toString()))
|
|
185
|
-
const deviceSessionKeys = uncachedDeviceJids.map(jid => jidToSignalProtocolAddress(jid).toString())
|
|
186
|
-
const existingSessions = deviceSessionKeys.length
|
|
187
|
-
? await parsedKeys.get('session', deviceSessionKeys)
|
|
188
|
-
: {}
|
|
189
|
-
const deviceJids = uncachedDeviceJids.filter(jid => existingSessions[jidToSignalProtocolAddress(jid).toString()])
|
|
190
|
-
return parsedKeys.transaction(async () => {
|
|
191
|
-
const migrationOps = deviceJids.map(jid => {
|
|
192
|
-
const lidWithDevice = (0, WABinary_1.transferDevice)(jid, toJid)
|
|
193
|
-
const fromDecoded = (0, WABinary_1.jidDecode)(jid)
|
|
194
|
-
return {
|
|
195
|
-
fromJid: jid,
|
|
196
|
-
toJid: lidWithDevice,
|
|
197
|
-
pnUser: fromDecoded?.user,
|
|
198
|
-
deviceId: fromDecoded?.device || 0,
|
|
199
|
-
fromAddr: jidToSignalProtocolAddress(jid),
|
|
200
|
-
toAddr: jidToSignalProtocolAddress(lidWithDevice)
|
|
201
|
-
}
|
|
202
|
-
})
|
|
203
|
-
const totalOps = migrationOps.length
|
|
204
|
-
let migratedCount = 0
|
|
205
|
-
const pnAddrStrings = [...new Set(migrationOps.map(op => op.fromAddr.toString()))]
|
|
206
|
-
const pnSessions = pnAddrStrings.length
|
|
207
|
-
? await parsedKeys.get('session', pnAddrStrings)
|
|
208
|
-
: {}
|
|
209
|
-
const sessionUpdates = {}
|
|
210
|
-
for (const op of migrationOps) {
|
|
211
|
-
const pnAddrStr = op.fromAddr.toString()
|
|
212
|
-
const lidAddrStr = op.toAddr.toString()
|
|
213
|
-
const pnSession = pnSessions[pnAddrStr]
|
|
214
|
-
if (!pnSession) {
|
|
215
|
-
continue
|
|
216
|
-
}
|
|
217
|
-
const fromSession = libsignal.SessionRecord.deserialize(pnSession)
|
|
218
|
-
if (!fromSession.haveOpenSession()) {
|
|
219
|
-
continue
|
|
220
|
-
}
|
|
221
|
-
sessionUpdates[lidAddrStr] = fromSession.serialize()
|
|
222
|
-
sessionUpdates[pnAddrStr] = null
|
|
223
|
-
migratedCount += 1
|
|
224
|
-
}
|
|
225
|
-
if (Object.keys(sessionUpdates).length) {
|
|
226
|
-
await parsedKeys.set({ session: sessionUpdates })
|
|
227
|
-
for (const op of migrationOps) {
|
|
228
|
-
if (sessionUpdates[op.toAddr.toString()] && op.pnUser) {
|
|
229
|
-
migratedSessionCache.set(op.fromAddr.toString(), true)
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return {
|
|
234
|
-
migrated: migratedCount,
|
|
235
|
-
skipped: totalOps - migratedCount,
|
|
236
|
-
total: totalOps
|
|
237
|
-
}
|
|
238
|
-
}, `migrate-${deviceJids.length}-sessions-${(0, WABinary_1.jidDecode)(toJid)?.user || 'unknown'}`)
|
|
239
|
-
}
|
|
240
96
|
}
|
|
241
|
-
return repository
|
|
242
97
|
}
|
|
243
98
|
|
|
244
99
|
const jidToSignalProtocolAddress = (jid) => {
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
if (!user) {
|
|
248
|
-
throw new Error(`JID decoded but user is empty: ${jid}`)
|
|
249
|
-
}
|
|
250
|
-
const signalUser = domainType !== WABinary_1.WAJIDDomains.WHATSAPP ? `${user}_${domainType}` : user
|
|
251
|
-
const finalDevice = device || 0
|
|
252
|
-
if (device === 99 && server !== 'hosted' && server !== 'hosted.lid') {
|
|
253
|
-
throw new Error(`unexpected non-hosted device 99 JID: ${jid}`)
|
|
254
|
-
}
|
|
255
|
-
return new libsignal.ProtocolAddress(signalUser, finalDevice)
|
|
100
|
+
const { user, device } = WABinary_1.jidDecode(jid)
|
|
101
|
+
return new libsignal.ProtocolAddress(user, device || 0)
|
|
256
102
|
}
|
|
257
103
|
|
|
258
104
|
const jidToSignalSenderKeyName = (group, user) => {
|
|
259
|
-
return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user))
|
|
105
|
+
return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString()
|
|
260
106
|
}
|
|
261
107
|
|
|
262
|
-
function signalStorage({ creds, keys }
|
|
263
|
-
const resolveLIDSignalAddress = async (id) => {
|
|
264
|
-
if (id.includes('.')) {
|
|
265
|
-
const [deviceId, device] = id.split('.')
|
|
266
|
-
const [user, domainType_] = deviceId.split('_')
|
|
267
|
-
const domainType = parseInt(domainType_ || '0', 10)
|
|
268
|
-
if (domainType === WABinary_1.WAJIDDomains.LID || domainType === WABinary_1.WAJIDDomains.HOSTED_LID) {
|
|
269
|
-
return id
|
|
270
|
-
}
|
|
271
|
-
const pnJid = `${user}${device !== '0' ? `:${device}` : ''}@${domainType === WABinary_1.WAJIDDomains.HOSTED ? 'hosted' : 's.whatsapp.net'}`
|
|
272
|
-
const lidForPN = await lidMapping.getLIDForPN(pnJid)
|
|
273
|
-
if (lidForPN) {
|
|
274
|
-
return jidToSignalProtocolAddress(lidForPN).toString()
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return id
|
|
278
|
-
}
|
|
108
|
+
function signalStorage({ creds, keys }) {
|
|
279
109
|
return {
|
|
280
110
|
loadSession: async (id) => {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (sess) {
|
|
285
|
-
return libsignal.SessionRecord.deserialize(sess)
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
catch (_error) {
|
|
289
|
-
return null
|
|
111
|
+
const { [id]: sess } = await keys.get('session', [id])
|
|
112
|
+
if (sess) {
|
|
113
|
+
return libsignal.SessionRecord.deserialize(sess)
|
|
290
114
|
}
|
|
291
|
-
return null
|
|
292
115
|
},
|
|
293
116
|
storeSession: async (id, session) => {
|
|
294
|
-
|
|
295
|
-
await keys.set({ session: { [wireJid]: session.serialize() } })
|
|
117
|
+
await keys.set({ 'session': { [id]: session.serialize() } })
|
|
296
118
|
},
|
|
297
|
-
isTrustedIdentity: () =>
|
|
298
|
-
|
|
299
|
-
const wireJid = await resolveLIDSignalAddress(id)
|
|
300
|
-
const { [wireJid]: key } = await keys.get('identity-key', [wireJid])
|
|
301
|
-
return key || undefined
|
|
302
|
-
},
|
|
303
|
-
saveIdentity: async (id, identityKey) => {
|
|
304
|
-
const wireJid = await resolveLIDSignalAddress(id)
|
|
305
|
-
const { [wireJid]: existingKey } = await keys.get('identity-key', [wireJid])
|
|
306
|
-
const keysMatch = existingKey
|
|
307
|
-
&& existingKey.length === identityKey.length
|
|
308
|
-
&& existingKey.every((byte, i) => byte === identityKey[i])
|
|
309
|
-
if (existingKey && !keysMatch) {
|
|
310
|
-
await keys.set({
|
|
311
|
-
session: { [wireJid]: null },
|
|
312
|
-
'identity-key': { [wireJid]: identityKey }
|
|
313
|
-
})
|
|
314
|
-
return true
|
|
315
|
-
}
|
|
316
|
-
if (!existingKey) {
|
|
317
|
-
await keys.set({ 'identity-key': { [wireJid]: identityKey } })
|
|
318
|
-
return true
|
|
319
|
-
}
|
|
320
|
-
return false
|
|
119
|
+
isTrustedIdentity: () => {
|
|
120
|
+
return true
|
|
321
121
|
},
|
|
322
122
|
loadPreKey: async (id) => {
|
|
323
123
|
const keyId = id.toString()
|
|
@@ -337,26 +137,26 @@ function signalStorage({ creds, keys }, lidMapping) {
|
|
|
337
137
|
pubKey: Buffer.from(key.keyPair.public)
|
|
338
138
|
}
|
|
339
139
|
},
|
|
340
|
-
loadSenderKey: async (
|
|
341
|
-
const keyId = senderKeyName.toString()
|
|
140
|
+
loadSenderKey: async (keyId) => {
|
|
342
141
|
const { [keyId]: key } = await keys.get('sender-key', [keyId])
|
|
343
|
-
|
|
142
|
+
if (key) {
|
|
143
|
+
return new WASignalGroup_1.SenderKeyRecord(key)
|
|
144
|
+
}
|
|
344
145
|
},
|
|
345
|
-
storeSenderKey: async (
|
|
346
|
-
const keyId = senderKeyName.toString()
|
|
146
|
+
storeSenderKey: async (keyId, key) => {
|
|
347
147
|
await keys.set({ 'sender-key': { [keyId]: key.serialize() } })
|
|
348
148
|
},
|
|
349
|
-
getOurRegistrationId: () => creds.registrationId,
|
|
149
|
+
getOurRegistrationId: () => (creds.registrationId),
|
|
350
150
|
getOurIdentity: () => {
|
|
351
151
|
const { signedIdentityKey } = creds
|
|
352
152
|
return {
|
|
353
153
|
privKey: Buffer.from(signedIdentityKey.private),
|
|
354
|
-
pubKey:
|
|
154
|
+
pubKey: Utils_1.generateSignalPubKey(signedIdentityKey.public),
|
|
355
155
|
}
|
|
356
156
|
}
|
|
357
157
|
}
|
|
358
158
|
}
|
|
359
159
|
|
|
360
160
|
module.exports = {
|
|
361
|
-
|
|
362
|
-
}
|
|
161
|
+
makeLibSignalRepository
|
|
162
|
+
}
|
package/lib/Socket/chats.js
CHANGED
|
@@ -21,7 +21,7 @@ const MAX_SYNC_ATTEMPTS = 2
|
|
|
21
21
|
const makeChatsSocket = (config) => {
|
|
22
22
|
const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config
|
|
23
23
|
const Neele = usync_1.makeUSyncSocket(config)
|
|
24
|
-
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, groupFetchAllParticipating
|
|
24
|
+
const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, groupFetchAllParticipating } = Neele
|
|
25
25
|
|
|
26
26
|
let privacySettings
|
|
27
27
|
let syncState = Types_1.SyncState.Connecting
|
|
@@ -1000,7 +1000,6 @@ const makeChatsSocket = (config) => {
|
|
|
1000
1000
|
logger,
|
|
1001
1001
|
options: config.options,
|
|
1002
1002
|
getMessage: config.getMessage,
|
|
1003
|
-
signalRepository,
|
|
1004
1003
|
})
|
|
1005
1004
|
])
|
|
1006
1005
|
|
|
@@ -1131,4 +1130,4 @@ const makeChatsSocket = (config) => {
|
|
|
1131
1130
|
|
|
1132
1131
|
module.exports = {
|
|
1133
1132
|
makeChatsSocket
|
|
1134
|
-
}
|
|
1133
|
+
}
|
package/lib/Socket/socket.js
CHANGED
|
@@ -793,7 +793,7 @@ const makeSocket = (config) => {
|
|
|
793
793
|
try {
|
|
794
794
|
const myPN = authState.creds.me.id
|
|
795
795
|
// Store our own LID-PN mapping
|
|
796
|
-
await signalRepository
|
|
796
|
+
await signalRepository?.lidMapping?.storeLIDPNMappings?.([{ lid: myLID, pn: myPN }])
|
|
797
797
|
// Create device list for our own user (needed for bulk migration)
|
|
798
798
|
const { user, device } = WABinary_1.jidDecode(myPN)
|
|
799
799
|
await authState.keys.set({
|
|
@@ -802,7 +802,7 @@ const makeSocket = (config) => {
|
|
|
802
802
|
}
|
|
803
803
|
})
|
|
804
804
|
// migrate our own session
|
|
805
|
-
await signalRepository
|
|
805
|
+
await signalRepository?.migrateSession?.(myPN, myLID)
|
|
806
806
|
logger.info({ myPN, myLID }, 'Own LID session created successfully')
|
|
807
807
|
}
|
|
808
808
|
catch (error) {
|
|
@@ -944,4 +944,4 @@ function mapWebSocketError(handler) {
|
|
|
944
944
|
|
|
945
945
|
module.exports = {
|
|
946
946
|
makeSocket
|
|
947
|
-
}
|
|
947
|
+
}
|
package/lib/Types/Auth.d.ts
CHANGED
|
@@ -24,11 +24,6 @@ export type SignalIdentity = {
|
|
|
24
24
|
identifierKey: Uint8Array
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export type LIDMapping = {
|
|
28
|
-
pn: string
|
|
29
|
-
lid: string
|
|
30
|
-
}
|
|
31
|
-
|
|
32
27
|
export type LTHashState = {
|
|
33
28
|
version: number
|
|
34
29
|
hash: Buffer
|
|
@@ -72,7 +67,6 @@ export type AuthenticationCreds = SignalCreds & {
|
|
|
72
67
|
pairingCode: string | undefined
|
|
73
68
|
lastPropHash: string | undefined
|
|
74
69
|
routingInfo: Buffer | undefined
|
|
75
|
-
additionalData?: any | undefined
|
|
76
70
|
}
|
|
77
71
|
|
|
78
72
|
export type SignalDataTypeMap = {
|
|
@@ -84,13 +78,6 @@ export type SignalDataTypeMap = {
|
|
|
84
78
|
}
|
|
85
79
|
'app-state-sync-key': proto.Message.IAppStateSyncKeyData
|
|
86
80
|
'app-state-sync-version': LTHashState
|
|
87
|
-
'lid-mapping': string
|
|
88
|
-
'device-list': string[]
|
|
89
|
-
'tctoken': {
|
|
90
|
-
token: Buffer
|
|
91
|
-
timestamp?: string
|
|
92
|
-
}
|
|
93
|
-
'identity-key': Uint8Array
|
|
94
81
|
}
|
|
95
82
|
|
|
96
83
|
export type SignalDataSet = {
|
|
@@ -112,7 +99,7 @@ export type SignalKeyStore = {
|
|
|
112
99
|
|
|
113
100
|
export type SignalKeyStoreWithTransaction = SignalKeyStore & {
|
|
114
101
|
isInTransaction: () => boolean
|
|
115
|
-
transaction<T>(exec: () => Promise<T
|
|
102
|
+
transaction<T>(exec: () => Promise<T>): Promise<T>
|
|
116
103
|
}
|
|
117
104
|
|
|
118
105
|
export type TransactionCapabilityOptions = {
|
|
@@ -130,4 +117,4 @@ export type AuthenticationState = {
|
|
|
130
117
|
keys: SignalKeyStore
|
|
131
118
|
}
|
|
132
119
|
|
|
133
|
-
export {}
|
|
120
|
+
export {}
|
package/lib/Types/Contact.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export interface Contact {
|
|
|
2
2
|
id: string
|
|
3
3
|
lid?: string
|
|
4
4
|
jid?: string
|
|
5
|
-
phoneNumber?: string
|
|
6
5
|
/** name of the contact, you have saved on your WA */
|
|
7
6
|
name?: string
|
|
8
7
|
/** name of the contact, the contact has set on their own on WA */
|
|
@@ -18,4 +17,4 @@ export interface Contact {
|
|
|
18
17
|
*/
|
|
19
18
|
imgUrl?: string | null
|
|
20
19
|
status?: string
|
|
21
|
-
}
|
|
20
|
+
}
|