@nexustechpro/baileys 2.0.1 → 2.0.5
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 +924 -1299
- package/lib/Defaults/baileys-version.json +6 -2
- package/lib/Defaults/index.js +172 -172
- package/lib/Signal/libsignal.js +380 -292
- package/lib/Signal/lid-mapping.js +264 -171
- package/lib/Socket/Client/index.js +2 -2
- package/lib/Socket/Client/types.js +10 -10
- package/lib/Socket/Client/websocket.js +45 -310
- package/lib/Socket/business.js +375 -375
- package/lib/Socket/chats.js +909 -963
- package/lib/Socket/communities.js +430 -430
- package/lib/Socket/groups.js +342 -342
- package/lib/Socket/index.js +22 -22
- package/lib/Socket/messages-recv.js +777 -743
- package/lib/Socket/messages-send.js +667 -393
- package/lib/Socket/mex.js +50 -50
- package/lib/Socket/newsletter.js +148 -148
- package/lib/Socket/nexus-handler.js +75 -261
- package/lib/Socket/socket.js +709 -1201
- package/lib/Store/index.js +5 -5
- package/lib/Store/make-cache-manager-store.js +81 -81
- package/lib/Store/make-in-memory-store.js +416 -416
- package/lib/Store/make-ordered-dictionary.js +81 -81
- package/lib/Store/object-repository.js +30 -30
- package/lib/Types/Auth.js +1 -1
- package/lib/Types/Bussines.js +1 -1
- package/lib/Types/Call.js +1 -1
- package/lib/Types/Chat.js +7 -7
- package/lib/Types/Contact.js +1 -1
- package/lib/Types/Events.js +1 -1
- package/lib/Types/GroupMetadata.js +1 -1
- package/lib/Types/Label.js +24 -24
- package/lib/Types/LabelAssociation.js +6 -6
- package/lib/Types/Message.js +10 -10
- package/lib/Types/Newsletter.js +28 -28
- package/lib/Types/Product.js +1 -1
- package/lib/Types/Signal.js +1 -1
- package/lib/Types/Socket.js +2 -2
- package/lib/Types/State.js +12 -12
- package/lib/Types/USync.js +1 -1
- package/lib/Types/index.js +25 -25
- package/lib/Utils/auth-utils.js +264 -256
- package/lib/Utils/baileys-event-stream.js +55 -55
- package/lib/Utils/browser-utils.js +27 -27
- package/lib/Utils/business.js +228 -230
- package/lib/Utils/chat-utils.js +694 -764
- package/lib/Utils/crypto.js +109 -135
- package/lib/Utils/decode-wa-message.js +310 -314
- package/lib/Utils/event-buffer.js +547 -547
- package/lib/Utils/generics.js +297 -297
- package/lib/Utils/history.js +91 -83
- package/lib/Utils/index.js +21 -20
- package/lib/Utils/key-store.js +17 -0
- package/lib/Utils/link-preview.js +97 -88
- package/lib/Utils/logger.js +2 -2
- package/lib/Utils/lt-hash.js +47 -47
- package/lib/Utils/make-mutex.js +39 -39
- package/lib/Utils/message-retry-manager.js +148 -148
- package/lib/Utils/messages-media.js +534 -532
- package/lib/Utils/messages.js +705 -705
- package/lib/Utils/noise-handler.js +255 -255
- package/lib/Utils/pre-key-manager.js +105 -105
- package/lib/Utils/process-message.js +412 -412
- package/lib/Utils/signal.js +160 -158
- package/lib/Utils/use-multi-file-auth-state.js +120 -120
- package/lib/Utils/validate-connection.js +194 -194
- package/lib/WABinary/constants.js +1300 -1300
- package/lib/WABinary/decode.js +237 -237
- package/lib/WABinary/encode.js +232 -232
- package/lib/WABinary/generic-utils.js +252 -211
- package/lib/WABinary/index.js +5 -5
- package/lib/WABinary/jid-utils.js +279 -95
- package/lib/WABinary/types.js +1 -1
- package/lib/WAM/BinaryInfo.js +9 -9
- package/lib/WAM/constants.js +22852 -22852
- package/lib/WAM/encode.js +149 -149
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -28
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -26
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -37
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -28
- package/lib/WAUSync/Protocols/index.js +4 -4
- package/lib/WAUSync/USyncQuery.js +93 -93
- package/lib/WAUSync/USyncUser.js +22 -22
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.js +66 -66
- package/package.json +171 -144
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -100
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -18
- package/lib/Signal/Group/sender-chain-key.js +0 -26
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -66
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -41
- package/lib/Signal/Group/sender-key-state.js +0 -84
- package/lib/Signal/Group/sender-message-key.js +0 -26
package/package.json
CHANGED
|
@@ -1,144 +1,171 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"name": "@nexustechpro/baileys",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"version": "2.0.
|
|
6
|
-
"description": "Advanced WhatsApp Web API
|
|
7
|
-
"keywords": [
|
|
8
|
-
"whatsapp",
|
|
9
|
-
"whatsapp-api",
|
|
10
|
-
"whatsapp-web",
|
|
11
|
-
"whatsapp-bot",
|
|
12
|
-
"automation",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"pino
|
|
114
|
-
"
|
|
115
|
-
"protobufjs
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
"
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
"
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
"
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
"
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
"
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
"
|
|
143
|
-
|
|
144
|
-
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"name": "@nexustechpro/baileys",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "2.0.5",
|
|
6
|
+
"description": "Advanced WhatsApp Web API built on Baileys — interactive messages, buttons, carousels, products, events, payments, polls, albums, sticker packs and more.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"whatsapp",
|
|
9
|
+
"whatsapp-api",
|
|
10
|
+
"whatsapp-web",
|
|
11
|
+
"whatsapp-bot",
|
|
12
|
+
"whatsapp-automation",
|
|
13
|
+
"whatsapp-web-api",
|
|
14
|
+
"whatsapp-client",
|
|
15
|
+
"whatsapp-multidevice",
|
|
16
|
+
"whatsapp-business",
|
|
17
|
+
"whatsapp-interactive",
|
|
18
|
+
"whatsapp-buttons",
|
|
19
|
+
"whatsapp-carousel",
|
|
20
|
+
"whatsapp-sticker",
|
|
21
|
+
"whatsapp-media",
|
|
22
|
+
"whatsapp-group",
|
|
23
|
+
"whatsapp-newsletter",
|
|
24
|
+
"whatsapp-channel",
|
|
25
|
+
"whatsapp-status",
|
|
26
|
+
"whatsapp-pairing",
|
|
27
|
+
"baileys",
|
|
28
|
+
"baileys-mod",
|
|
29
|
+
"baileys-fork",
|
|
30
|
+
"baileys-advanced",
|
|
31
|
+
"whiskeysockets",
|
|
32
|
+
"wa-api",
|
|
33
|
+
"wa-bot",
|
|
34
|
+
"wa-web",
|
|
35
|
+
"nexus",
|
|
36
|
+
"nexusbot",
|
|
37
|
+
"nexustechpro",
|
|
38
|
+
"automation",
|
|
39
|
+
"bot",
|
|
40
|
+
"chatbot",
|
|
41
|
+
"messaging",
|
|
42
|
+
"websocket",
|
|
43
|
+
"multi-device",
|
|
44
|
+
"multidevice",
|
|
45
|
+
"interactive-messages",
|
|
46
|
+
"buttons",
|
|
47
|
+
"carousels",
|
|
48
|
+
"products",
|
|
49
|
+
"events",
|
|
50
|
+
"payments",
|
|
51
|
+
"polls",
|
|
52
|
+
"album",
|
|
53
|
+
"sticker-pack",
|
|
54
|
+
"nodejs",
|
|
55
|
+
"typescript",
|
|
56
|
+
"javascript",
|
|
57
|
+
"esm"
|
|
58
|
+
],
|
|
59
|
+
"homepage": "https://github.com/nexustechpro2/baileys/",
|
|
60
|
+
"bugs": {
|
|
61
|
+
"url": "https://github.com/nexustechpro2/baileys/issues"
|
|
62
|
+
},
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "git+https://github.com/nexustechpro2/baileys.git"
|
|
66
|
+
},
|
|
67
|
+
"license": "MIT",
|
|
68
|
+
"author": "nexustechpro2",
|
|
69
|
+
"main": "lib/index.js",
|
|
70
|
+
"types": "lib/index.d.ts",
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build:all": "tsc && typedoc",
|
|
73
|
+
"build:docs": "typedoc",
|
|
74
|
+
"build:tsc": "tsc",
|
|
75
|
+
"generate:license": "npx license",
|
|
76
|
+
"changelog:last": "conventional-changelog -p angular -r 2",
|
|
77
|
+
"changelog:preview": "conventional-changelog -p angular -u",
|
|
78
|
+
"changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
|
|
79
|
+
"example": "node --inspect -r ts-node/register Example/example.ts",
|
|
80
|
+
"gen:protobuf": "sh WAProto/GenerateStatics.sh",
|
|
81
|
+
"lint": "eslint src --ext .js,.ts,.jsx,.tsx",
|
|
82
|
+
"lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
|
|
83
|
+
"prepack": "echo 'NexusTechPro WhatsApp Library'",
|
|
84
|
+
"prepare": "echo 'NexusTechPro WhatsApp Library'",
|
|
85
|
+
"preinstall": "node ./engine-requirements.js",
|
|
86
|
+
"release": "release-it",
|
|
87
|
+
"test": "jest"
|
|
88
|
+
},
|
|
89
|
+
"files": [
|
|
90
|
+
"lib/**/*.js",
|
|
91
|
+
"lib/**/*.json",
|
|
92
|
+
"lib/**/*.d.ts",
|
|
93
|
+
"lib/**/*.map",
|
|
94
|
+
"WAProto/**/*.js",
|
|
95
|
+
"WAProto/**/*.json",
|
|
96
|
+
"WAProto/**/*.d.ts",
|
|
97
|
+
"WAProto/**/*.sh",
|
|
98
|
+
"engine-requirements.js"
|
|
99
|
+
],
|
|
100
|
+
"dependencies": {
|
|
101
|
+
"@cacheable/node-cache": "^1.4.0",
|
|
102
|
+
"@hapi/boom": "^9.1.3",
|
|
103
|
+
"async-mutex": "^0.5.0",
|
|
104
|
+
"axios": "^1.6.0",
|
|
105
|
+
"cache-manager": "latest",
|
|
106
|
+
"chalk": "^4.1.2",
|
|
107
|
+
"fflate": "^0.8.2",
|
|
108
|
+
"gradient-string": "^2.0.2",
|
|
109
|
+
"link-preview-js": "^3.0.4",
|
|
110
|
+
"lru-cache": "^11.1.0",
|
|
111
|
+
"music-metadata": "^11.7.0",
|
|
112
|
+
"p-queue": "^9.0.0",
|
|
113
|
+
"pino": "^9.6",
|
|
114
|
+
"uuid": "latest",
|
|
115
|
+
"protobufjs": "latest",
|
|
116
|
+
"sharp": "^0.32.0",
|
|
117
|
+
"whatsapp-rust-bridge": "latest",
|
|
118
|
+
"ws": "latest",
|
|
119
|
+
"yarn": "^1.22.22"
|
|
120
|
+
},
|
|
121
|
+
"devDependencies": {
|
|
122
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
123
|
+
"@eslint/js": "^9.31.0",
|
|
124
|
+
"@types/jest": "^30.0.0",
|
|
125
|
+
"@types/node": "^20.9.0",
|
|
126
|
+
"@types/ws": "^8.0.0",
|
|
127
|
+
"@typescript-eslint/eslint-plugin": "^8",
|
|
128
|
+
"@typescript-eslint/parser": "^8",
|
|
129
|
+
"@whiskeysockets/eslint-config": "^1.0.0",
|
|
130
|
+
"conventional-changelog": "^7.1.1",
|
|
131
|
+
"conventional-changelog-angular": "^8.0.0",
|
|
132
|
+
"esbuild-register": "^3.6.0",
|
|
133
|
+
"eslint": "^9",
|
|
134
|
+
"eslint-config-prettier": "^10.1.2",
|
|
135
|
+
"eslint-plugin-prettier": "^5.4.0",
|
|
136
|
+
"jest": "^30.0.5",
|
|
137
|
+
"jimp": "^1.6.0",
|
|
138
|
+
"jiti": "^2.4.2",
|
|
139
|
+
"json": "^11.0.0",
|
|
140
|
+
"link-preview-js": "^3.0.4",
|
|
141
|
+
"lru-cache": "^11.1.0",
|
|
142
|
+
"open": "^8.4.2",
|
|
143
|
+
"pino-pretty": "^13.1.1",
|
|
144
|
+
"prettier": "^3.5.3",
|
|
145
|
+
"protobufjs-cli": "^1.1.3",
|
|
146
|
+
"release-it": "^15.10.3",
|
|
147
|
+
"ts-jest": "^29.4.0",
|
|
148
|
+
"tsc-esm-fix": "^3.1.2",
|
|
149
|
+
"tsx": "^4.20.3",
|
|
150
|
+
"typedoc": "^0.27.9",
|
|
151
|
+
"typedoc-plugin-markdown": "4.4.2",
|
|
152
|
+
"typescript": "^5.8.2"
|
|
153
|
+
},
|
|
154
|
+
"peerDependencies": {
|
|
155
|
+
"audio-decode": "^2.1.3",
|
|
156
|
+
"jimp": "^1.6.0",
|
|
157
|
+
"link-preview-js": "^3.0.4"
|
|
158
|
+
},
|
|
159
|
+
"peerDependenciesMeta": {
|
|
160
|
+
"audio-decode": {
|
|
161
|
+
"optional": true
|
|
162
|
+
},
|
|
163
|
+
"jimp": {
|
|
164
|
+
"optional": true
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
"packageManager": "yarn@4.9.2",
|
|
168
|
+
"engines": {
|
|
169
|
+
"node": ">=20.0.0"
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export class CiphertextMessage {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.UNSUPPORTED_VERSION = 1;
|
|
4
|
-
this.CURRENT_VERSION = 3;
|
|
5
|
-
this.WHISPER_TYPE = 2;
|
|
6
|
-
this.PREKEY_TYPE = 3;
|
|
7
|
-
this.SENDERKEY_TYPE = 4;
|
|
8
|
-
this.SENDERKEY_DISTRIBUTION_TYPE = 5;
|
|
9
|
-
this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=ciphertext-message.js.map
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as keyhelper from './keyhelper.js';
|
|
2
|
-
import { SenderKeyDistributionMessage } from './sender-key-distribution-message.js';
|
|
3
|
-
import { SenderKeyName } from './sender-key-name.js';
|
|
4
|
-
import { SenderKeyRecord } from './sender-key-record.js';
|
|
5
|
-
export class GroupSessionBuilder {
|
|
6
|
-
constructor(senderKeyStore) {
|
|
7
|
-
this.senderKeyStore = senderKeyStore;
|
|
8
|
-
}
|
|
9
|
-
async process(senderKeyName, senderKeyDistributionMessage) {
|
|
10
|
-
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
|
|
11
|
-
senderKeyRecord.addSenderKeyState(senderKeyDistributionMessage.getId(), senderKeyDistributionMessage.getIteration(), senderKeyDistributionMessage.getChainKey(), senderKeyDistributionMessage.getSignatureKey());
|
|
12
|
-
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
13
|
-
}
|
|
14
|
-
async create(senderKeyName) {
|
|
15
|
-
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
|
|
16
|
-
if (senderKeyRecord.isEmpty()) {
|
|
17
|
-
const keyId = keyhelper.generateSenderKeyId();
|
|
18
|
-
const senderKey = keyhelper.generateSenderKey();
|
|
19
|
-
const signingKey = keyhelper.generateSenderSigningKey();
|
|
20
|
-
senderKeyRecord.setSenderKeyState(keyId, 0, senderKey, signingKey);
|
|
21
|
-
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
22
|
-
}
|
|
23
|
-
const state = senderKeyRecord.getSenderKeyState();
|
|
24
|
-
if (!state) {
|
|
25
|
-
throw new Error('No session state available');
|
|
26
|
-
}
|
|
27
|
-
return new SenderKeyDistributionMessage(state.getKeyId(), state.getSenderChainKey().getIteration(), state.getSenderChainKey().getSeed(), state.getSigningKeyPublic());
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=group-session-builder.js.map
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { decrypt, encrypt } from 'libsignal/src/crypto.js'
|
|
2
|
-
import { SenderKeyMessage } from './sender-key-message.js'
|
|
3
|
-
import { SenderKeyName } from './sender-key-name.js'
|
|
4
|
-
import { SenderKeyRecord } from './sender-key-record.js'
|
|
5
|
-
import { SenderKeyState } from './sender-key-state.js'
|
|
6
|
-
|
|
7
|
-
export class GroupCipher {
|
|
8
|
-
constructor(senderKeyStore, senderKeyName) {
|
|
9
|
-
this.senderKeyStore = senderKeyStore
|
|
10
|
-
this.senderKeyName = senderKeyName
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async encrypt(paddedPlaintext) {
|
|
14
|
-
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName)
|
|
15
|
-
if (!record) throw new Error('No SenderKeyRecord found')
|
|
16
|
-
const state = record.getSenderKeyState()
|
|
17
|
-
if (!state) throw new Error('No session to encrypt')
|
|
18
|
-
const iteration = state.getSenderChainKey().getIteration()
|
|
19
|
-
const senderKey = this.getSenderKey(state, iteration === 0 ? 0 : iteration + 1)
|
|
20
|
-
const ciphertext = await this.getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext)
|
|
21
|
-
const msg = new SenderKeyMessage(state.getKeyId(), senderKey.getIteration(), ciphertext, state.getSigningKeyPrivate())
|
|
22
|
-
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record)
|
|
23
|
-
return msg.serialize()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async decrypt(senderKeyMessageBytes) {
|
|
27
|
-
let record = await this.senderKeyStore.loadSenderKey(this.senderKeyName)
|
|
28
|
-
if (!record) throw new Error('No SenderKeyRecord - requesting new session')
|
|
29
|
-
|
|
30
|
-
const msg = new SenderKeyMessage(null, null, null, null, senderKeyMessageBytes)
|
|
31
|
-
let state = record.getSenderKeyState(msg.getKeyId())
|
|
32
|
-
|
|
33
|
-
if (!state) {
|
|
34
|
-
const allStates = record.getSenderKeyStates?.() || []
|
|
35
|
-
if (allStates.length > 0) {
|
|
36
|
-
state = allStates[allStates.length - 1]
|
|
37
|
-
} else {
|
|
38
|
-
throw new Error(`No session found - keyId: ${msg.getKeyId()}`)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
msg.verifySignature(state.getSigningKeyPublic())
|
|
44
|
-
} catch (e) {
|
|
45
|
-
throw new Error('Signature verification failed')
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const senderKey = this.getSenderKey(state, msg.getIteration())
|
|
49
|
-
const plaintext = await this.getPlainText(senderKey.getIv(), senderKey.getCipherKey(), msg.getCipherText())
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record)
|
|
53
|
-
} catch (e) {
|
|
54
|
-
// Non-critical: decryption succeeded
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return plaintext
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
getSenderKey(state, iteration) {
|
|
61
|
-
let chainKey = state.getSenderChainKey()
|
|
62
|
-
|
|
63
|
-
if (chainKey.getIteration() > iteration) {
|
|
64
|
-
if (state.hasSenderMessageKey(iteration)) {
|
|
65
|
-
const key = state.removeSenderMessageKey(iteration)
|
|
66
|
-
if (!key) throw new Error('No sender message key')
|
|
67
|
-
return key
|
|
68
|
-
}
|
|
69
|
-
throw new Error(`Old counter: ${chainKey.getIteration()} vs ${iteration}`)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (iteration - chainKey.getIteration() > 2000) throw new Error('Over 2000 messages ahead')
|
|
73
|
-
|
|
74
|
-
while (chainKey.getIteration() < iteration) {
|
|
75
|
-
state.addSenderMessageKey(chainKey.getSenderMessageKey())
|
|
76
|
-
chainKey = chainKey.getNext()
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
state.setSenderChainKey(chainKey.getNext())
|
|
80
|
-
return chainKey.getSenderMessageKey()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async getPlainText(iv, key, ciphertext) {
|
|
84
|
-
try {
|
|
85
|
-
return decrypt(key, ciphertext, iv)
|
|
86
|
-
} catch (e) {
|
|
87
|
-
throw new Error('InvalidMessageException')
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async getCipherText(iv, key, plaintext) {
|
|
92
|
-
try {
|
|
93
|
-
return encrypt(key, plaintext, iv)
|
|
94
|
-
} catch (e) {
|
|
95
|
-
throw new Error('InvalidMessageException')
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export default GroupCipher
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { GroupSessionBuilder } from './group-session-builder.js';
|
|
2
|
-
export { SenderKeyDistributionMessage } from './sender-key-distribution-message.js';
|
|
3
|
-
export { SenderKeyRecord } from './sender-key-record.js';
|
|
4
|
-
export { SenderKeyName } from './sender-key-name.js';
|
|
5
|
-
export { GroupCipher } from './group_cipher.js';
|
|
6
|
-
export { SenderKeyState } from './sender-key-state.js';
|
|
7
|
-
export { SenderKeyMessage } from './sender-key-message.js';
|
|
8
|
-
export { SenderMessageKey } from './sender-message-key.js';
|
|
9
|
-
export { SenderChainKey } from './sender-chain-key.js';
|
|
10
|
-
export { CiphertextMessage } from './ciphertext-message.js';
|
|
11
|
-
export * as keyhelper from './keyhelper.js';
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as nodeCrypto from 'crypto';
|
|
2
|
-
import { generateKeyPair } from 'libsignal/src/curve.js';
|
|
3
|
-
export function generateSenderKey() {
|
|
4
|
-
return nodeCrypto.randomBytes(32);
|
|
5
|
-
}
|
|
6
|
-
export function generateSenderKeyId() {
|
|
7
|
-
return nodeCrypto.randomInt(2147483647);
|
|
8
|
-
}
|
|
9
|
-
export function generateSenderSigningKey(key) {
|
|
10
|
-
if (!key) {
|
|
11
|
-
key = generateKeyPair();
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
14
|
-
public: Buffer.from(key.pubKey),
|
|
15
|
-
private: Buffer.from(key.privKey)
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=keyhelper.js.map
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { calculateMAC } from 'libsignal/src/crypto.js';
|
|
2
|
-
import { SenderMessageKey } from './sender-message-key.js';
|
|
3
|
-
export class SenderChainKey {
|
|
4
|
-
constructor(iteration, chainKey) {
|
|
5
|
-
this.MESSAGE_KEY_SEED = Buffer.from([0x01]);
|
|
6
|
-
this.CHAIN_KEY_SEED = Buffer.from([0x02]);
|
|
7
|
-
this.iteration = iteration;
|
|
8
|
-
this.chainKey = Buffer.from(chainKey);
|
|
9
|
-
}
|
|
10
|
-
getIteration() {
|
|
11
|
-
return this.iteration;
|
|
12
|
-
}
|
|
13
|
-
getSenderMessageKey() {
|
|
14
|
-
return new SenderMessageKey(this.iteration, this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey));
|
|
15
|
-
}
|
|
16
|
-
getNext() {
|
|
17
|
-
return new SenderChainKey(this.iteration + 1, this.getDerivative(this.CHAIN_KEY_SEED, this.chainKey));
|
|
18
|
-
}
|
|
19
|
-
getSeed() {
|
|
20
|
-
return this.chainKey;
|
|
21
|
-
}
|
|
22
|
-
getDerivative(seed, key) {
|
|
23
|
-
return calculateMAC(key, seed);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=sender-chain-key.js.map
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { proto } from '../../../WAProto/index.js';
|
|
2
|
-
import { CiphertextMessage } from './ciphertext-message.js';
|
|
3
|
-
export class SenderKeyDistributionMessage extends CiphertextMessage {
|
|
4
|
-
constructor(id, iteration, chainKey, signatureKey, serialized) {
|
|
5
|
-
super();
|
|
6
|
-
if (serialized) {
|
|
7
|
-
try {
|
|
8
|
-
const message = serialized.slice(1);
|
|
9
|
-
const distributionMessage = proto.SenderKeyDistributionMessage.decode(message).toJSON();
|
|
10
|
-
this.serialized = serialized;
|
|
11
|
-
this.id = distributionMessage.id;
|
|
12
|
-
this.iteration = distributionMessage.iteration;
|
|
13
|
-
this.chainKey =
|
|
14
|
-
typeof distributionMessage.chainKey === 'string'
|
|
15
|
-
? Buffer.from(distributionMessage.chainKey, 'base64')
|
|
16
|
-
: distributionMessage.chainKey;
|
|
17
|
-
this.signatureKey =
|
|
18
|
-
typeof distributionMessage.signingKey === 'string'
|
|
19
|
-
? Buffer.from(distributionMessage.signingKey, 'base64')
|
|
20
|
-
: distributionMessage.signingKey;
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
throw new Error(String(e));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
const version = this.intsToByteHighAndLow(this.CURRENT_VERSION, this.CURRENT_VERSION);
|
|
28
|
-
this.id = id;
|
|
29
|
-
this.iteration = iteration;
|
|
30
|
-
this.chainKey = chainKey;
|
|
31
|
-
this.signatureKey = signatureKey;
|
|
32
|
-
const message = proto.SenderKeyDistributionMessage.encode(proto.SenderKeyDistributionMessage.create({
|
|
33
|
-
id,
|
|
34
|
-
iteration,
|
|
35
|
-
chainKey,
|
|
36
|
-
signingKey: this.signatureKey
|
|
37
|
-
})).finish();
|
|
38
|
-
this.serialized = Buffer.concat([Buffer.from([version]), message]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
intsToByteHighAndLow(highValue, lowValue) {
|
|
42
|
-
return (((highValue << 4) | lowValue) & 0xff) % 256;
|
|
43
|
-
}
|
|
44
|
-
serialize() {
|
|
45
|
-
return this.serialized;
|
|
46
|
-
}
|
|
47
|
-
getType() {
|
|
48
|
-
return this.SENDERKEY_DISTRIBUTION_TYPE;
|
|
49
|
-
}
|
|
50
|
-
getIteration() {
|
|
51
|
-
return this.iteration;
|
|
52
|
-
}
|
|
53
|
-
getChainKey() {
|
|
54
|
-
return this.chainKey;
|
|
55
|
-
}
|
|
56
|
-
getSignatureKey() {
|
|
57
|
-
return this.signatureKey;
|
|
58
|
-
}
|
|
59
|
-
getId() {
|
|
60
|
-
return this.id;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=sender-key-distribution-message.js.map
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { calculateSignature, verifySignature } from 'libsignal/src/curve.js';
|
|
2
|
-
import { proto } from '../../../WAProto/index.js';
|
|
3
|
-
import { CiphertextMessage } from './ciphertext-message.js';
|
|
4
|
-
export class SenderKeyMessage extends CiphertextMessage {
|
|
5
|
-
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
6
|
-
super();
|
|
7
|
-
this.SIGNATURE_LENGTH = 64;
|
|
8
|
-
if (serialized) {
|
|
9
|
-
const version = serialized[0];
|
|
10
|
-
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
|
|
11
|
-
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
12
|
-
const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON();
|
|
13
|
-
this.serialized = serialized;
|
|
14
|
-
this.messageVersion = (version & 0xff) >> 4;
|
|
15
|
-
this.keyId = senderKeyMessage.id;
|
|
16
|
-
this.iteration = senderKeyMessage.iteration;
|
|
17
|
-
this.ciphertext =
|
|
18
|
-
typeof senderKeyMessage.ciphertext === 'string'
|
|
19
|
-
? Buffer.from(senderKeyMessage.ciphertext, 'base64')
|
|
20
|
-
: senderKeyMessage.ciphertext;
|
|
21
|
-
this.signature = signature;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256;
|
|
25
|
-
const ciphertextBuffer = Buffer.from(ciphertext);
|
|
26
|
-
const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
|
|
27
|
-
id: keyId,
|
|
28
|
-
iteration: iteration,
|
|
29
|
-
ciphertext: ciphertextBuffer
|
|
30
|
-
})).finish();
|
|
31
|
-
const signature = this.getSignature(signatureKey, Buffer.concat([Buffer.from([version]), message]));
|
|
32
|
-
this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)]);
|
|
33
|
-
this.messageVersion = this.CURRENT_VERSION;
|
|
34
|
-
this.keyId = keyId;
|
|
35
|
-
this.iteration = iteration;
|
|
36
|
-
this.ciphertext = ciphertextBuffer;
|
|
37
|
-
this.signature = signature;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
getKeyId() {
|
|
41
|
-
return this.keyId;
|
|
42
|
-
}
|
|
43
|
-
getIteration() {
|
|
44
|
-
return this.iteration;
|
|
45
|
-
}
|
|
46
|
-
getCipherText() {
|
|
47
|
-
return this.ciphertext;
|
|
48
|
-
}
|
|
49
|
-
verifySignature(signatureKey) {
|
|
50
|
-
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
|
|
51
|
-
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
52
|
-
const res = verifySignature(signatureKey, part1, part2);
|
|
53
|
-
if (!res)
|
|
54
|
-
throw new Error('Invalid signature!');
|
|
55
|
-
}
|
|
56
|
-
getSignature(signatureKey, serialized) {
|
|
57
|
-
return Buffer.from(calculateSignature(signatureKey, serialized));
|
|
58
|
-
}
|
|
59
|
-
serialize() {
|
|
60
|
-
return this.serialized;
|
|
61
|
-
}
|
|
62
|
-
getType() {
|
|
63
|
-
return 4;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=sender-key-message.js.map
|