@pontalabs/baileys 1.0.6 → 1.0.7
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 +1 -1
- package/README.md +839 -267
- package/WAProto/GenerateStatics.sh +4 -3
- package/WAProto/WAProto.proto +511 -1215
- package/WAProto/index.d.ts +55 -14017
- package/WAProto/index.js +29 -97689
- package/lib/Defaults/index.d.ts +74 -72
- package/lib/Defaults/index.js +108 -94
- package/lib/Signal/Group/ciphertext-message.d.ts +7 -8
- package/lib/Signal/Group/ciphertext-message.js +16 -9
- package/lib/Signal/Group/group-session-builder.d.ts +13 -11
- package/lib/Signal/Group/group-session-builder.js +61 -19
- package/lib/Signal/Group/group_cipher.d.ts +16 -14
- package/lib/Signal/Group/group_cipher.js +70 -41
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +61 -12
- package/lib/Signal/Group/keyhelper.d.ts +14 -9
- package/lib/Signal/Group/keyhelper.js +58 -10
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -13
- package/lib/Signal/Group/sender-chain-key.js +34 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +36 -28
- package/lib/Signal/Group/sender-key-message.d.ts +18 -18
- package/lib/Signal/Group/sender-key-message.js +45 -38
- package/lib/Signal/Group/sender-key-name.d.ts +15 -14
- package/lib/Signal/Group/sender-key-name.js +31 -20
- package/lib/Signal/Group/sender-key-record.d.ts +25 -24
- package/lib/Signal/Group/sender-key-record.js +35 -18
- package/lib/Signal/Group/sender-key-state.d.ts +34 -29
- package/lib/Signal/Group/sender-key-state.js +100 -37
- package/lib/Signal/Group/sender-message-key.d.ts +10 -11
- package/lib/Signal/Group/sender-message-key.js +22 -15
- package/lib/Signal/libsignal.d.ts +8 -5
- package/lib/Signal/libsignal.js +142 -288
- package/lib/Signal/lid-mapping.d.ts +28 -23
- package/lib/Signal/lid-mapping.js +184 -277
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +22 -3
- package/lib/Socket/Client/types.d.ts +15 -15
- package/lib/Socket/Client/types.js +15 -8
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.js +37 -29
- package/lib/Socket/business.d.ts +178 -208
- package/lib/Socket/business.js +127 -91
- package/lib/Socket/chats.d.ts +93 -120
- package/lib/Socket/chats.js +652 -727
- package/lib/Socket/community.js +10 -2
- package/lib/Socket/groups.d.ts +111 -143
- package/lib/Socket/groups.js +186 -165
- package/lib/Socket/index.d.ts +183 -252
- package/lib/Socket/index.js +18 -38
- package/lib/Socket/messages-recv.d.ts +167 -196
- package/lib/Socket/messages-recv.js +1567 -1443
- package/lib/Socket/messages-send.d.ts +158 -192
- package/lib/Socket/messages-send.js +1208 -1102
- package/lib/Socket/newsletter.d.ts +138 -163
- package/lib/Socket/newsletter.js +249 -153
- package/lib/Socket/socket.d.ts +36 -50
- package/lib/Socket/socket.js +820 -749
- package/lib/Store/index.d.ts +4 -4
- package/lib/Store/index.js +24 -4
- package/lib/Store/make-in-memory-store.d.ts +104 -44
- package/lib/Store/make-in-memory-store.js +213 -199
- package/lib/Store/make-ordered-dictionary.d.ts +12 -13
- package/lib/Store/make-ordered-dictionary.js +45 -38
- package/lib/Store/object-repository.d.ts +10 -11
- package/lib/Store/object-repository.js +16 -9
- package/lib/Types/Auth.d.ts +97 -93
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -2
- package/lib/Types/Call.d.ts +13 -14
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.d.ts +97 -78
- package/lib/Types/Chat.js +9 -8
- package/lib/Types/Contact.d.ts +9 -12
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.d.ts +176 -206
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.d.ts +48 -53
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.d.ts +14 -13
- package/lib/Types/Label.js +30 -24
- package/lib/Types/LabelAssociation.d.ts +20 -15
- package/lib/Types/LabelAssociation.js +12 -6
- package/lib/Types/Message.d.ts +412 -248
- package/lib/Types/Message.js +19 -17
- package/lib/Types/Product.d.ts +71 -58
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.d.ts +82 -71
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.d.ts +81 -76
- package/lib/Types/Socket.js +3 -3
- package/lib/Types/State.d.ts +19 -75
- package/lib/Types/State.js +14 -56
- package/lib/Types/USync.d.ts +8 -8
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.d.ts +62 -47
- package/lib/Types/index.js +50 -26
- package/lib/Utils/auth-utils.d.ts +10 -13
- package/lib/Utils/auth-utils.js +472 -213
- package/lib/Utils/business.d.ts +20 -14
- package/lib/Utils/business.js +134 -110
- package/lib/Utils/chat-utils.d.ts +70 -88
- package/lib/Utils/chat-utils.js +403 -466
- package/lib/Utils/crypto.d.ts +46 -27
- package/lib/Utils/crypto.js +188 -117
- package/lib/Utils/decode-wa-message.d.ts +45 -58
- package/lib/Utils/decode-wa-message.js +311 -212
- package/lib/Utils/event-buffer.d.ts +17 -14
- package/lib/Utils/event-buffer.js +296 -321
- package/lib/Utils/generics.d.ts +92 -66
- package/lib/Utils/generics.js +436 -270
- package/lib/Utils/history.d.ts +23 -24
- package/lib/Utils/history.js +76 -106
- package/lib/Utils/index.d.ts +21 -24
- package/lib/Utils/index.js +41 -24
- package/lib/Utils/link-preview.d.ts +14 -12
- package/lib/Utils/link-preview.js +75 -40
- package/lib/Utils/logger.d.ts +11 -10
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +14 -8
- package/lib/Utils/lt-hash.js +53 -3
- package/lib/Utils/make-mutex.d.ts +7 -7
- package/lib/Utils/make-mutex.js +44 -28
- package/lib/Utils/message-retry-manager.d.ts +88 -115
- package/lib/Utils/message-retry-manager.js +160 -265
- package/lib/Utils/messages-media.d.ts +107 -105
- package/lib/Utils/messages-media.js +619 -548
- package/lib/Utils/messages.d.ts +66 -52
- package/lib/Utils/messages.js +1558 -1730
- package/lib/Utils/noise-handler.d.ts +18 -18
- package/lib/Utils/noise-handler.js +130 -176
- package/lib/Utils/process-message.d.ts +32 -43
- package/lib/Utils/process-message.js +282 -484
- package/lib/Utils/rich-message-utils.js +724 -1220
- package/lib/Utils/signal.d.ts +32 -37
- package/lib/Utils/signal.js +105 -140
- package/lib/Utils/use-multi-file-auth-state.d.ts +5 -5
- package/lib/Utils/use-multi-file-auth-state.js +120 -70
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -11
- package/lib/Utils/use-single-file-auth-state.js +66 -92
- package/lib/Utils/validate-connection.d.ts +13 -11
- package/lib/Utils/validate-connection.js +113 -128
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +1292 -1451
- package/lib/WABinary/decode.d.ts +9 -7
- package/lib/WABinary/decode.js +189 -163
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +155 -110
- package/lib/WABinary/generic-utils.d.ts +27 -14
- package/lib/WABinary/generic-utils.js +105 -177
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +25 -6
- package/lib/WABinary/jid-utils.d.ts +54 -41
- package/lib/WABinary/jid-utils.js +152 -83
- package/lib/WABinary/types.d.ts +13 -10
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.d.ts +15 -8
- package/lib/WAM/BinaryInfo.js +14 -7
- package/lib/WAM/constants.d.ts +37 -30
- package/lib/WAM/constants.js +11983 -19465
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +109 -95
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +23 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +21 -37
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -19
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +26 -18
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +24 -16
- package/lib/WAUSync/Protocols/index.d.ts +6 -6
- package/lib/WAUSync/Protocols/index.js +26 -6
- package/lib/WAUSync/USyncQuery.d.ts +28 -27
- package/lib/WAUSync/USyncQuery.js +62 -68
- package/lib/WAUSync/USyncUser.d.ts +10 -15
- package/lib/WAUSync/USyncUser.js +19 -20
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +23 -4
- package/lib/index.d.ts +12 -11
- package/lib/index.js +39 -12
- package/package.json +42 -86
- package/engine-requirements.js +0 -10
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { proto } from '../../WAProto
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { proto } from '../../WAProto'
|
|
2
|
+
import { KeyPair } from '../Types'
|
|
3
|
+
import { BinaryNode } from '../WABinary'
|
|
4
|
+
import { ILogger } from './logger'
|
|
5
|
+
|
|
5
6
|
export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
|
|
6
|
-
keyPair: KeyPair
|
|
7
|
-
NOISE_HEADER: Uint8Array
|
|
8
|
-
logger: ILogger
|
|
9
|
-
routingInfo?: Buffer | undefined
|
|
7
|
+
keyPair: KeyPair
|
|
8
|
+
NOISE_HEADER: Uint8Array
|
|
9
|
+
logger: ILogger
|
|
10
|
+
routingInfo?: Buffer | undefined
|
|
10
11
|
}) => {
|
|
11
|
-
encrypt: (plaintext: Uint8Array) =>
|
|
12
|
-
decrypt: (ciphertext: Uint8Array) =>
|
|
13
|
-
authenticate: (data: Uint8Array) => void
|
|
14
|
-
mixIntoKey: (data: Uint8Array) => void
|
|
15
|
-
finishInit: () => Promise<void
|
|
16
|
-
processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) =>
|
|
17
|
-
encodeFrame: (data: Buffer | Uint8Array) => Buffer
|
|
18
|
-
decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => Promise<void
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=noise-handler.d.ts.map
|
|
12
|
+
encrypt: (plaintext: Uint8Array) => Buffer
|
|
13
|
+
decrypt: (ciphertext: Uint8Array) => Buffer
|
|
14
|
+
authenticate: (data: Uint8Array) => void
|
|
15
|
+
mixIntoKey: (data: Uint8Array) => Promise<void>
|
|
16
|
+
finishInit: () => Promise<void>
|
|
17
|
+
processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Promise<Buffer>
|
|
18
|
+
encodeFrame: (data: Buffer | Uint8Array) => Buffer
|
|
19
|
+
decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => Promise<void>
|
|
20
|
+
}
|
|
@@ -1,201 +1,155 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const boom_1 = require("@hapi/boom")
|
|
6
|
+
const WAProto_1 = require("../../WAProto")
|
|
7
|
+
const Defaults_1 = require("../Defaults")
|
|
8
|
+
const WABinary_1 = require("../WABinary")
|
|
9
|
+
const crypto_1 = require("./crypto")
|
|
10
|
+
|
|
8
11
|
const generateIV = (counter) => {
|
|
9
|
-
const iv = new ArrayBuffer(
|
|
10
|
-
new DataView(iv).setUint32(8, counter)
|
|
11
|
-
return new Uint8Array(iv)
|
|
12
|
-
};
|
|
13
|
-
class TransportState {
|
|
14
|
-
constructor(encKey, decKey) {
|
|
15
|
-
this.encKey = encKey;
|
|
16
|
-
this.decKey = decKey;
|
|
17
|
-
this.readCounter = 0;
|
|
18
|
-
this.writeCounter = 0;
|
|
19
|
-
this.iv = new Uint8Array(IV_LENGTH);
|
|
20
|
-
}
|
|
21
|
-
encrypt(plaintext) {
|
|
22
|
-
const c = this.writeCounter++;
|
|
23
|
-
this.iv[8] = (c >>> 24) & 0xff;
|
|
24
|
-
this.iv[9] = (c >>> 16) & 0xff;
|
|
25
|
-
this.iv[10] = (c >>> 8) & 0xff;
|
|
26
|
-
this.iv[11] = c & 0xff;
|
|
27
|
-
return aesEncryptGCM(plaintext, this.encKey, this.iv, EMPTY_BUFFER);
|
|
28
|
-
}
|
|
29
|
-
decrypt(ciphertext) {
|
|
30
|
-
const c = this.readCounter++;
|
|
31
|
-
this.iv[8] = (c >>> 24) & 0xff;
|
|
32
|
-
this.iv[9] = (c >>> 16) & 0xff;
|
|
33
|
-
this.iv[10] = (c >>> 8) & 0xff;
|
|
34
|
-
this.iv[11] = c & 0xff;
|
|
35
|
-
return aesDecryptGCM(ciphertext, this.decKey, this.iv, EMPTY_BUFFER);
|
|
36
|
-
}
|
|
12
|
+
const iv = new ArrayBuffer(12)
|
|
13
|
+
new DataView(iv).setUint32(8, counter)
|
|
14
|
+
return new Uint8Array(iv)
|
|
37
15
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
let hash = data.byteLength === 32 ? data : sha256(data);
|
|
42
|
-
let salt = hash;
|
|
43
|
-
let encKey = hash;
|
|
44
|
-
let decKey = hash;
|
|
45
|
-
let counter = 0;
|
|
46
|
-
let sentIntro = false;
|
|
47
|
-
let inBytes = Buffer.alloc(0);
|
|
48
|
-
let transport = null;
|
|
49
|
-
let isWaitingForTransport = false;
|
|
50
|
-
let pendingOnFrame = null;
|
|
51
|
-
let introHeader;
|
|
52
|
-
if (routingInfo) {
|
|
53
|
-
introHeader = Buffer.alloc(7 + routingInfo.byteLength + NOISE_HEADER.length);
|
|
54
|
-
introHeader.write('ED', 0, 'utf8');
|
|
55
|
-
introHeader.writeUint8(0, 2);
|
|
56
|
-
introHeader.writeUint8(1, 3);
|
|
57
|
-
introHeader.writeUint8(routingInfo.byteLength >> 16, 4);
|
|
58
|
-
introHeader.writeUint16BE(routingInfo.byteLength & 65535, 5);
|
|
59
|
-
introHeader.set(routingInfo, 7);
|
|
60
|
-
introHeader.set(NOISE_HEADER, 7 + routingInfo.byteLength);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
introHeader = Buffer.from(NOISE_HEADER);
|
|
64
|
-
}
|
|
16
|
+
|
|
17
|
+
const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }) => {
|
|
18
|
+
logger = logger.child({ class: 'ns' })
|
|
65
19
|
const authenticate = (data) => {
|
|
66
|
-
if (!
|
|
67
|
-
hash = sha256(Buffer.concat([hash, data]))
|
|
20
|
+
if (!isFinished) {
|
|
21
|
+
hash = crypto_1.sha256(Buffer.concat([hash, data]))
|
|
68
22
|
}
|
|
69
|
-
}
|
|
23
|
+
}
|
|
70
24
|
const encrypt = (plaintext) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return result;
|
|
77
|
-
};
|
|
25
|
+
const result = crypto_1.aesEncryptGCM(plaintext, encKey, generateIV(writeCounter), hash)
|
|
26
|
+
writeCounter += 1
|
|
27
|
+
authenticate(result)
|
|
28
|
+
return result
|
|
29
|
+
}
|
|
78
30
|
const decrypt = (ciphertext) => {
|
|
79
|
-
|
|
80
|
-
|
|
31
|
+
// before the handshake is finished, we use the same counter
|
|
32
|
+
// after handshake, the counters are different
|
|
33
|
+
const iv = generateIV(isFinished ? readCounter : writeCounter)
|
|
34
|
+
const result = crypto_1.aesDecryptGCM(ciphertext, decKey, iv, hash)
|
|
35
|
+
if (isFinished) {
|
|
36
|
+
readCounter += 1
|
|
81
37
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return result;
|
|
85
|
-
};
|
|
86
|
-
const localHKDF = (data) => {
|
|
87
|
-
const key = hkdf(Buffer.from(data), 64, { salt, info: '' });
|
|
88
|
-
return [key.subarray(0, 32), key.subarray(32)];
|
|
89
|
-
};
|
|
90
|
-
const mixIntoKey = (data) => {
|
|
91
|
-
const [write, read] = localHKDF(data);
|
|
92
|
-
salt = write;
|
|
93
|
-
encKey = read;
|
|
94
|
-
decKey = read;
|
|
95
|
-
counter = 0;
|
|
96
|
-
};
|
|
97
|
-
const finishInit = async () => {
|
|
98
|
-
isWaitingForTransport = true;
|
|
99
|
-
const [write, read] = localHKDF(new Uint8Array(0));
|
|
100
|
-
transport = new TransportState(write, read);
|
|
101
|
-
isWaitingForTransport = false;
|
|
102
|
-
logger.trace('Noise handler transitioned to Transport state');
|
|
103
|
-
if (pendingOnFrame) {
|
|
104
|
-
logger.trace({ length: inBytes.length }, 'Flushing buffered frames after transport ready');
|
|
105
|
-
await processData(pendingOnFrame);
|
|
106
|
-
pendingOnFrame = null;
|
|
38
|
+
else {
|
|
39
|
+
writeCounter += 1
|
|
107
40
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
41
|
+
authenticate(ciphertext)
|
|
42
|
+
return result
|
|
43
|
+
}
|
|
44
|
+
const localHKDF = async (data) => {
|
|
45
|
+
const key = await crypto_1.hkdf(Buffer.from(data), 64, { salt, info: '' })
|
|
46
|
+
return [key.slice(0, 32), key.slice(32)]
|
|
47
|
+
}
|
|
48
|
+
const mixIntoKey = async (data) => {
|
|
49
|
+
const [write, read] = await localHKDF(data)
|
|
50
|
+
salt = write
|
|
51
|
+
encKey = read
|
|
52
|
+
decKey = read
|
|
53
|
+
readCounter = 0
|
|
54
|
+
writeCounter = 0
|
|
55
|
+
}
|
|
56
|
+
const finishInit = async () => {
|
|
57
|
+
const [write, read] = await localHKDF(new Uint8Array(0))
|
|
58
|
+
encKey = write
|
|
59
|
+
decKey = read
|
|
60
|
+
hash = Buffer.from([])
|
|
61
|
+
readCounter = 0
|
|
62
|
+
writeCounter = 0
|
|
63
|
+
isFinished = true
|
|
64
|
+
}
|
|
65
|
+
const data = Buffer.from(Defaults_1.NOISE_MODE)
|
|
66
|
+
let hash = data.byteLength === 32 ? data : crypto_1.sha256(data)
|
|
67
|
+
let salt = hash
|
|
68
|
+
let encKey = hash
|
|
69
|
+
let decKey = hash
|
|
70
|
+
let readCounter = 0
|
|
71
|
+
let writeCounter = 0
|
|
72
|
+
let isFinished = false
|
|
73
|
+
let sentIntro = false
|
|
74
|
+
let inBytes = Buffer.alloc(0)
|
|
75
|
+
authenticate(NOISE_HEADER)
|
|
76
|
+
authenticate(publicKey)
|
|
131
77
|
return {
|
|
132
78
|
encrypt,
|
|
133
79
|
decrypt,
|
|
134
80
|
authenticate,
|
|
135
81
|
mixIntoKey,
|
|
136
82
|
finishInit,
|
|
137
|
-
processHandshake: ({ serverHello }, noiseKey) => {
|
|
138
|
-
authenticate(serverHello.ephemeral)
|
|
139
|
-
mixIntoKey(Curve.sharedKey(privateKey, serverHello.ephemeral))
|
|
140
|
-
const decStaticContent = decrypt(serverHello.static)
|
|
141
|
-
mixIntoKey(Curve.sharedKey(privateKey, decStaticContent))
|
|
142
|
-
const certDecoded = decrypt(serverHello.payload)
|
|
143
|
-
const { intermediate: certIntermediate
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
throw new Boom('
|
|
147
|
-
}
|
|
148
|
-
if (!certIntermediate?.details || !certIntermediate?.signature) {
|
|
149
|
-
throw new Boom('invalid noise intermediate certificate', { statusCode: 400 });
|
|
150
|
-
}
|
|
151
|
-
const details = proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
|
|
152
|
-
const { issuerSerial } = details;
|
|
153
|
-
const verify = Curve.verify(details.key, leaf.details, leaf.signature);
|
|
154
|
-
const verifyIntermediate = Curve.verify(WA_CERT_DETAILS.PUBLIC_KEY, certIntermediate.details, certIntermediate.signature);
|
|
155
|
-
if (!verify) {
|
|
156
|
-
throw new Boom('noise certificate signature invalid', { statusCode: 400 });
|
|
157
|
-
}
|
|
158
|
-
if (!verifyIntermediate) {
|
|
159
|
-
throw new Boom('noise intermediate certificate signature invalid', { statusCode: 400 });
|
|
160
|
-
}
|
|
161
|
-
if (issuerSerial !== WA_CERT_DETAILS.SERIAL) {
|
|
162
|
-
throw new Boom('certification match failed', { statusCode: 400 });
|
|
83
|
+
processHandshake: async ({ serverHello }, noiseKey) => {
|
|
84
|
+
authenticate(serverHello.ephemeral)
|
|
85
|
+
await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, serverHello.ephemeral))
|
|
86
|
+
const decStaticContent = decrypt(serverHello.static)
|
|
87
|
+
await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, decStaticContent))
|
|
88
|
+
const certDecoded = decrypt(serverHello.payload)
|
|
89
|
+
const { intermediate: certIntermediate } = WAProto_1.proto.CertChain.decode(certDecoded)
|
|
90
|
+
const { issuerSerial } = WAProto_1.proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details)
|
|
91
|
+
if (issuerSerial !== Defaults_1.WA_CERT_DETAILS.SERIAL) {
|
|
92
|
+
throw new boom_1.Boom('certification match failed', { statusCode: 400 })
|
|
163
93
|
}
|
|
164
|
-
const keyEnc = encrypt(noiseKey.public)
|
|
165
|
-
mixIntoKey(Curve.sharedKey(noiseKey.private, serverHello.ephemeral))
|
|
166
|
-
return keyEnc
|
|
94
|
+
const keyEnc = encrypt(noiseKey.public)
|
|
95
|
+
await mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral))
|
|
96
|
+
return keyEnc
|
|
167
97
|
},
|
|
168
98
|
encodeFrame: (data) => {
|
|
169
|
-
if (
|
|
170
|
-
data =
|
|
99
|
+
if (isFinished) {
|
|
100
|
+
data = encrypt(data)
|
|
171
101
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
102
|
+
let header
|
|
103
|
+
if (routingInfo) {
|
|
104
|
+
header = Buffer.alloc(7)
|
|
105
|
+
header.write('ED', 0, 'utf8')
|
|
106
|
+
header.writeUint8(0, 2)
|
|
107
|
+
header.writeUint8(1, 3)
|
|
108
|
+
header.writeUint8(routingInfo.byteLength >> 16, 4)
|
|
109
|
+
header.writeUint16BE(routingInfo.byteLength & 65535, 5)
|
|
110
|
+
header = Buffer.concat([header, routingInfo, NOISE_HEADER])
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
header = Buffer.from(NOISE_HEADER)
|
|
114
|
+
}
|
|
115
|
+
const introSize = sentIntro ? 0 : header.length
|
|
116
|
+
const frame = Buffer.alloc(introSize + 3 + data.byteLength)
|
|
175
117
|
if (!sentIntro) {
|
|
176
|
-
frame.set(
|
|
177
|
-
sentIntro = true
|
|
118
|
+
frame.set(header)
|
|
119
|
+
sentIntro = true
|
|
178
120
|
}
|
|
179
|
-
frame
|
|
180
|
-
frame
|
|
181
|
-
frame
|
|
182
|
-
frame
|
|
183
|
-
return frame;
|
|
121
|
+
frame.writeUInt8(data.byteLength >> 16, introSize)
|
|
122
|
+
frame.writeUInt16BE(65535 & data.byteLength, introSize + 1)
|
|
123
|
+
frame.set(data, introSize + 3)
|
|
124
|
+
return frame
|
|
184
125
|
},
|
|
185
126
|
decodeFrame: async (newData, onFrame) => {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
127
|
+
// the binary protocol uses its own framing mechanism
|
|
128
|
+
// on top of the WS frames
|
|
129
|
+
// so we get this data and separate out the frames
|
|
130
|
+
const getBytesSize = () => {
|
|
131
|
+
if (inBytes.length >= 3) {
|
|
132
|
+
return (inBytes.readUInt8() << 16) | inBytes.readUInt16BE(1)
|
|
133
|
+
}
|
|
190
134
|
}
|
|
191
|
-
|
|
192
|
-
|
|
135
|
+
inBytes = Buffer.concat([inBytes, newData])
|
|
136
|
+
logger.trace(`recv ${newData.length} bytes, total recv ${inBytes.length} bytes`)
|
|
137
|
+
let size = getBytesSize()
|
|
138
|
+
while (size && inBytes.length >= size + 3) {
|
|
139
|
+
let frame = inBytes.slice(3, size + 3)
|
|
140
|
+
inBytes = inBytes.slice(size + 3)
|
|
141
|
+
if (isFinished) {
|
|
142
|
+
const result = decrypt(frame)
|
|
143
|
+
frame = await WABinary_1.decodeBinaryNode(result)
|
|
144
|
+
}
|
|
145
|
+
logger.trace({ msg: frame?.attrs?.id }, 'recv frame')
|
|
146
|
+
onFrame(frame)
|
|
147
|
+
size = getBytesSize()
|
|
193
148
|
}
|
|
194
|
-
else {
|
|
195
|
-
inBytes = Buffer.concat([inBytes, newData]);
|
|
196
|
-
}
|
|
197
|
-
await processData(onFrame);
|
|
198
149
|
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
module.exports = {
|
|
154
|
+
makeNoiseHandler
|
|
155
|
+
}
|
|
@@ -1,60 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { AxiosRequestConfig } from 'axios'
|
|
2
|
+
import { proto } from '../../WAProto'
|
|
3
|
+
import { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction, SocketConfig } from '../Types'
|
|
4
|
+
import { ILogger } from './logger'
|
|
5
|
+
|
|
4
6
|
type ProcessMessageContext = {
|
|
5
|
-
shouldProcessHistoryMsg: boolean
|
|
6
|
-
placeholderResendCache?: CacheStore
|
|
7
|
-
creds: AuthenticationCreds
|
|
8
|
-
keyStore: SignalKeyStoreWithTransaction
|
|
9
|
-
ev: BaileysEventEmitter
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
shouldProcessHistoryMsg: boolean
|
|
8
|
+
placeholderResendCache?: CacheStore
|
|
9
|
+
creds: AuthenticationCreds
|
|
10
|
+
keyStore: SignalKeyStoreWithTransaction
|
|
11
|
+
ev: BaileysEventEmitter
|
|
12
|
+
getMessage: SocketConfig['getMessage']
|
|
13
|
+
logger?: ILogger
|
|
14
|
+
options: AxiosRequestConfig<{}>
|
|
15
|
+
}
|
|
16
|
+
|
|
15
17
|
/** Cleans a received message to further processing */
|
|
16
|
-
export declare const cleanMessage: (message:
|
|
17
|
-
|
|
18
|
-
export declare const
|
|
18
|
+
export declare const cleanMessage: (message: proto.IWebMessageInfo, meId: string) => void
|
|
19
|
+
|
|
20
|
+
export declare const isRealMessage: (message: proto.IWebMessageInfo, meId: string) => boolean | undefined
|
|
21
|
+
|
|
22
|
+
export declare const shouldIncrementChatUnread: (message: proto.IWebMessageInfo) => boolean
|
|
23
|
+
|
|
19
24
|
/**
|
|
20
25
|
* Get the ID of the chat from the given key.
|
|
21
26
|
* Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
|
|
22
27
|
*/
|
|
23
|
-
export declare const getChatId: ({ remoteJid, participant, fromMe }:
|
|
28
|
+
export declare const getChatId: ({ remoteJid, participant, fromMe }: proto.IMessageKey) => string
|
|
29
|
+
|
|
24
30
|
type PollContext = {
|
|
25
31
|
/** normalised jid of the person that created the poll */
|
|
26
|
-
pollCreatorJid: string
|
|
32
|
+
pollCreatorJid: string
|
|
27
33
|
/** ID of the poll creation message */
|
|
28
|
-
pollMsgId: string
|
|
34
|
+
pollMsgId: string
|
|
29
35
|
/** poll creation message enc key */
|
|
30
|
-
pollEncKey: Uint8Array
|
|
36
|
+
pollEncKey: Uint8Array
|
|
31
37
|
/** jid of the person that voted */
|
|
32
|
-
voterJid: string
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** normalised jid of the person that created the event */
|
|
36
|
-
eventCreatorJid: string;
|
|
37
|
-
/** ID of the event creation message */
|
|
38
|
-
eventMsgId: string;
|
|
39
|
-
/** event creation message enc key */
|
|
40
|
-
eventEncKey: Uint8Array;
|
|
41
|
-
/** jid of the person that responded */
|
|
42
|
-
responderJid: string;
|
|
43
|
-
};
|
|
38
|
+
voterJid: string
|
|
39
|
+
}
|
|
40
|
+
|
|
44
41
|
/**
|
|
45
42
|
* Decrypt a poll vote
|
|
46
43
|
* @param vote encrypted vote
|
|
47
44
|
* @param ctx additional info about the poll required for decryption
|
|
48
45
|
* @returns list of SHA256 options
|
|
49
46
|
*/
|
|
50
|
-
export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }: PollContext): proto.Message.PollVoteMessage
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* @param response encrypted event response
|
|
54
|
-
* @param ctx additional info about the event required for decryption
|
|
55
|
-
* @returns event response message
|
|
56
|
-
*/
|
|
57
|
-
export declare function decryptEventResponse({ encPayload, encIv }: proto.Message.IPollEncValue, { eventCreatorJid, eventMsgId, eventEncKey, responderJid }: EventContext): proto.Message.EventResponseMessage;
|
|
58
|
-
declare const processMessage: (message: WAMessage, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
|
|
59
|
-
export default processMessage;
|
|
60
|
-
//# sourceMappingURL=process-message.d.ts.map
|
|
47
|
+
export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage
|
|
48
|
+
|
|
49
|
+
export declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>
|