whatsapp-nodejs 0.0.1-security → 0.0.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.
Potentially problematic release.
This version of whatsapp-nodejs might be problematic. Click here for more details.
- package/.eslintignore +2 -0
- package/.eslintrc.js +59 -0
- package/.prettierrc +11 -0
- package/README.md +51 -3
- package/package.json +97 -3
- package/proto/ClientHello.proto +167 -0
- package/proto/HandshakeMessage.proto +26 -0
- package/proto/Message.proto +795 -0
- package/proto/SessionStructure.proto +113 -0
- package/proto/WhisperTextProtocol.proto +29 -0
- package/src/SocketClient.js +241 -0
- package/src/SocketManager.js +130 -0
- package/src/WASocketClient.js +170 -0
- package/src/Whatsapp.js +169 -0
- package/src/WhatsappServer.js +17 -0
- package/src/bin/decoder.js +1 -0
- package/src/bin/dict.js +1 -0
- package/src/bin/dict1.js +1 -0
- package/src/bin/dict2.js +1 -0
- package/src/bin/encoder.js +1 -0
- package/src/config.js +71 -0
- package/src/db.js +44 -0
- package/src/index.js +7 -0
- package/src/lib/SocketProxy.js +225 -0
- package/src/lib/libsignal-protocol.js +14 -0
- package/src/lib/utils.js +123 -0
- package/src/logger.js +79 -0
- package/src/packet/ProtocolEntity.js +39 -0
- package/src/packet/ProtocolTreeNode.js +202 -0
- package/src/protobuf/pb.js +32415 -0
- package/src/protocol/CipherState.js +48 -0
- package/src/protocol/FallbackPatternModifier.js +48 -0
- package/src/protocol/ForwarderHandshakeState.js +56 -0
- package/src/protocol/HandShake.js +273 -0
- package/src/protocol/HandshakePattern.js +62 -0
- package/src/protocol/HandshakeState.js +223 -0
- package/src/protocol/PKCS7.js +89 -0
- package/src/protocol/SwitchableHandshakeState.js +64 -0
- package/src/protocol/WASymmetricState.js +116 -0
- package/src/protocol/crypto.js +112 -0
- package/src/protocol/handshakepatterns/HandshakePattern.js +62 -0
- package/src/protocol/handshakepatterns/IKHandshakePattern.js +17 -0
- package/src/protocol/handshakepatterns/XXHandshakePattern.js +9 -0
- package/src/schema/account.js +65 -0
- package/src/schema/axolotl.js +8 -0
- package/src/schema/business.js +15 -0
- package/src/schema/common.js +26 -0
- package/src/schema/dayreport.js +21 -0
- package/src/schema/identify.js +49 -0
- package/src/schema/message.js +44 -0
- package/src/schema/prekey.js +51 -0
- package/src/schema/recvmessage.js +33 -0
- package/src/schema/senderkey.js +20 -0
- package/src/schema/session.js +22 -0
- package/src/schema/signedprekeys.js +56 -0
- package/test/WASocketClient.test.js +23 -0
- package/test/handshake.test.js +38 -0
- package/test/logger.test.js +17 -0
- package/test/whatsapp.test.js +17 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
mobile: {
|
|
3
|
+
type: String,
|
|
4
|
+
index: true,
|
|
5
|
+
},
|
|
6
|
+
to: {
|
|
7
|
+
type: String,
|
|
8
|
+
name: '接收者',
|
|
9
|
+
index: true,
|
|
10
|
+
},
|
|
11
|
+
mediaType: {
|
|
12
|
+
type: String,
|
|
13
|
+
default: 'text',
|
|
14
|
+
},
|
|
15
|
+
from: {
|
|
16
|
+
type: String,
|
|
17
|
+
index: true,
|
|
18
|
+
},
|
|
19
|
+
id: {
|
|
20
|
+
type: String,
|
|
21
|
+
name: '消息 id',
|
|
22
|
+
index: true,
|
|
23
|
+
},
|
|
24
|
+
attrs: {
|
|
25
|
+
type: Object,
|
|
26
|
+
},
|
|
27
|
+
record: {
|
|
28
|
+
type: String,
|
|
29
|
+
name: '消息内容',
|
|
30
|
+
},
|
|
31
|
+
timestamp: {
|
|
32
|
+
type: Number,
|
|
33
|
+
},
|
|
34
|
+
isRead: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
default: false,
|
|
37
|
+
index: true,
|
|
38
|
+
},
|
|
39
|
+
retry: {
|
|
40
|
+
type: Number,
|
|
41
|
+
name: '重试次数',
|
|
42
|
+
default: 0,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
mobile: {
|
|
3
|
+
type: String,
|
|
4
|
+
index: true,
|
|
5
|
+
},
|
|
6
|
+
keyId: {
|
|
7
|
+
type: Number,
|
|
8
|
+
index: true,
|
|
9
|
+
},
|
|
10
|
+
sent_to_server: {
|
|
11
|
+
type: Boolean,
|
|
12
|
+
default: false,
|
|
13
|
+
},
|
|
14
|
+
preKey: {
|
|
15
|
+
type: Object,
|
|
16
|
+
set: val => {
|
|
17
|
+
const { keyPair } = val;
|
|
18
|
+
return {
|
|
19
|
+
...val,
|
|
20
|
+
keyPair: {
|
|
21
|
+
pubKey: Buffer.from(keyPair.pubKey),
|
|
22
|
+
privKey: Buffer.from(keyPair.privKey),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
get: val => {
|
|
27
|
+
const { keyPair } = val;
|
|
28
|
+
const identityKeyPair = {
|
|
29
|
+
pubKey: new ArrayBuffer(keyPair.pubKey.buffer.length),
|
|
30
|
+
privKey: new ArrayBuffer(keyPair.privKey.buffer.length),
|
|
31
|
+
};
|
|
32
|
+
const pubKey = new Uint8Array(identityKeyPair.pubKey);
|
|
33
|
+
const privKey = new Uint8Array(identityKeyPair.privKey);
|
|
34
|
+
for (let i = 0; i < keyPair.pubKey.buffer.length; i++) {
|
|
35
|
+
const item = keyPair.pubKey.buffer[i];
|
|
36
|
+
pubKey[i] = item;
|
|
37
|
+
}
|
|
38
|
+
for (let i = 0; i < keyPair.privKey.buffer.length; i++) {
|
|
39
|
+
const item = keyPair.privKey.buffer[i];
|
|
40
|
+
privKey[i] = item;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
...val,
|
|
44
|
+
keyPair: identityKeyPair,
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
timestamp: {
|
|
49
|
+
type: Number,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
mobile: {
|
|
3
|
+
type: String,
|
|
4
|
+
index: true,
|
|
5
|
+
},
|
|
6
|
+
isRead: {
|
|
7
|
+
type: Boolean,
|
|
8
|
+
index: true,
|
|
9
|
+
default: false,
|
|
10
|
+
},
|
|
11
|
+
jid: {
|
|
12
|
+
type: String,
|
|
13
|
+
name: '来自',
|
|
14
|
+
index: true,
|
|
15
|
+
},
|
|
16
|
+
gid: {
|
|
17
|
+
type: String,
|
|
18
|
+
name: '群 id',
|
|
19
|
+
default: '',
|
|
20
|
+
},
|
|
21
|
+
id: {
|
|
22
|
+
type: String,
|
|
23
|
+
name: '消息 id',
|
|
24
|
+
index: true,
|
|
25
|
+
},
|
|
26
|
+
message: {
|
|
27
|
+
type: Object,
|
|
28
|
+
},
|
|
29
|
+
t: {
|
|
30
|
+
title: '接收消息时间',
|
|
31
|
+
type: Number,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
mobile: {
|
|
3
|
+
type: String,
|
|
4
|
+
index: true,
|
|
5
|
+
},
|
|
6
|
+
groupId: {
|
|
7
|
+
type: String,
|
|
8
|
+
index: true,
|
|
9
|
+
},
|
|
10
|
+
senderId: {
|
|
11
|
+
type: String,
|
|
12
|
+
index: true,
|
|
13
|
+
},
|
|
14
|
+
record: {
|
|
15
|
+
type: String,
|
|
16
|
+
},
|
|
17
|
+
timestamp: {
|
|
18
|
+
type: Number,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
mobile: {
|
|
3
|
+
type: String,
|
|
4
|
+
index: true,
|
|
5
|
+
},
|
|
6
|
+
address: {
|
|
7
|
+
type: String,
|
|
8
|
+
index: true,
|
|
9
|
+
},
|
|
10
|
+
jid: {
|
|
11
|
+
type: Number,
|
|
12
|
+
},
|
|
13
|
+
deviceId: {
|
|
14
|
+
type: String,
|
|
15
|
+
},
|
|
16
|
+
record: {
|
|
17
|
+
type: String,
|
|
18
|
+
},
|
|
19
|
+
timestamp: {
|
|
20
|
+
type: Number,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
mobile: {
|
|
3
|
+
type: String,
|
|
4
|
+
index: true,
|
|
5
|
+
},
|
|
6
|
+
keyId: {
|
|
7
|
+
type: Number,
|
|
8
|
+
},
|
|
9
|
+
preKey: {
|
|
10
|
+
type: Object,
|
|
11
|
+
set: val => {
|
|
12
|
+
const { keyPair } = val;
|
|
13
|
+
return {
|
|
14
|
+
...val,
|
|
15
|
+
keyPair: {
|
|
16
|
+
pubKey: Buffer.from(keyPair.pubKey),
|
|
17
|
+
privKey: Buffer.from(keyPair.privKey),
|
|
18
|
+
},
|
|
19
|
+
signature: Buffer.from(val.signature),
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
get: val => {
|
|
23
|
+
const { keyPair } = val;
|
|
24
|
+
const identityKeyPair = {
|
|
25
|
+
pubKey: new ArrayBuffer(keyPair.pubKey.buffer.length),
|
|
26
|
+
privKey: new ArrayBuffer(keyPair.privKey.buffer.length),
|
|
27
|
+
};
|
|
28
|
+
const signature = new ArrayBuffer(val.signature.buffer.length);
|
|
29
|
+
|
|
30
|
+
const pubKey = new Uint8Array(identityKeyPair.pubKey);
|
|
31
|
+
const privKey = new Uint8Array(identityKeyPair.privKey);
|
|
32
|
+
const sign = new Uint8Array(signature);
|
|
33
|
+
|
|
34
|
+
for (let i = 0; i < keyPair.pubKey.buffer.length; i++) {
|
|
35
|
+
const item = keyPair.pubKey.buffer[i];
|
|
36
|
+
pubKey[i] = item;
|
|
37
|
+
}
|
|
38
|
+
for (let i = 0; i < keyPair.privKey.buffer.length; i++) {
|
|
39
|
+
const item = keyPair.privKey.buffer[i];
|
|
40
|
+
privKey[i] = item;
|
|
41
|
+
}
|
|
42
|
+
for (let i = 0; i < val.signature.buffer.length; i++) {
|
|
43
|
+
const item = val.signature.buffer[i];
|
|
44
|
+
sign[i] = item;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
...val,
|
|
48
|
+
keyPair: identityKeyPair,
|
|
49
|
+
signature,
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
timestamp: {
|
|
54
|
+
type: Number,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const logger = require('../src/logger');
|
|
2
|
+
const WASocketClient = require('../src/WASocketClient');
|
|
3
|
+
|
|
4
|
+
const main = async () => {
|
|
5
|
+
//
|
|
6
|
+
|
|
7
|
+
const waSocketClient = new WASocketClient({
|
|
8
|
+
proxy: {
|
|
9
|
+
host: 'localhost',
|
|
10
|
+
port: 1080,
|
|
11
|
+
},
|
|
12
|
+
mobile: '233244040964',
|
|
13
|
+
socketName: 'Socket_1',
|
|
14
|
+
endpoint: {
|
|
15
|
+
host: 'e1.whatsapp.net',
|
|
16
|
+
port: 443,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await waSocketClient.init();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
main();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const logger = require('../src/logger');
|
|
2
|
+
const WASocketClient = require('../src/WASocketClient');
|
|
3
|
+
|
|
4
|
+
const HandShake = require('../src/protocol/HandShake');
|
|
5
|
+
const db = require('../src/db');
|
|
6
|
+
const libsignal = require('../src/lib/libsignal-protocol');
|
|
7
|
+
const config = require('../src/config');
|
|
8
|
+
|
|
9
|
+
const main = async () => {
|
|
10
|
+
//
|
|
11
|
+
libsignal.curve = (await libsignal.default()).Curve;
|
|
12
|
+
await db.init();
|
|
13
|
+
const waSocketClient = new WASocketClient({
|
|
14
|
+
proxy: {
|
|
15
|
+
host: '127.0.0.1',
|
|
16
|
+
port: 1086,
|
|
17
|
+
type: 'socks5',
|
|
18
|
+
},
|
|
19
|
+
mobile: '233244040964',
|
|
20
|
+
socketName: 'Socket_1',
|
|
21
|
+
endpoint: config.getEndPoint(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await waSocketClient.init();
|
|
25
|
+
|
|
26
|
+
const account = await db.findAccount(233244040964);
|
|
27
|
+
console.log('account', account);
|
|
28
|
+
|
|
29
|
+
const handShake = new HandShake(waSocketClient);
|
|
30
|
+
|
|
31
|
+
await handShake.start(account, account.serverStaticPublic);
|
|
32
|
+
|
|
33
|
+
handShake.waSocketClient.on('data', data => {
|
|
34
|
+
// console.log('data', data);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
main();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const logger = require('../src/logger');
|
|
2
|
+
|
|
3
|
+
console.log('log,info');
|
|
4
|
+
console.trace('trace');
|
|
5
|
+
console.debug('debug');
|
|
6
|
+
console.log('log');
|
|
7
|
+
console.info('info');
|
|
8
|
+
console.warn('warn');
|
|
9
|
+
console.error('error');
|
|
10
|
+
console.fatal('fatal');
|
|
11
|
+
|
|
12
|
+
// const e = new Error('失败');
|
|
13
|
+
// console.error(e, e.message, e.stack);
|
|
14
|
+
|
|
15
|
+
const childLogger = logger.child({ reqId: '1' }, false);
|
|
16
|
+
|
|
17
|
+
childLogger.info('hi', 'a');
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const Whatsapp = require('../src/whatsapp');
|
|
2
|
+
|
|
3
|
+
const main = async () => {
|
|
4
|
+
const whatsapp = new Whatsapp();
|
|
5
|
+
await whatsapp.init({
|
|
6
|
+
mobile: '233244040964',
|
|
7
|
+
proxy: {
|
|
8
|
+
host: '127.0.0.1',
|
|
9
|
+
port: 1080,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const res = await whatsapp.login();
|
|
14
|
+
console.log('res', res);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
main();
|