@nexustechpro/baileys 2.0.2 → 2.0.6

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.
Files changed (108) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +924 -1299
  3. package/WAProto/index.js +22 -18
  4. package/lib/Defaults/baileys-version.json +6 -2
  5. package/lib/Defaults/index.js +173 -172
  6. package/lib/Signal/libsignal.js +395 -292
  7. package/lib/Signal/lid-mapping.js +264 -171
  8. package/lib/Socket/Client/index.js +2 -2
  9. package/lib/Socket/Client/types.js +10 -10
  10. package/lib/Socket/Client/websocket.js +45 -310
  11. package/lib/Socket/business.js +375 -375
  12. package/lib/Socket/chats.js +916 -963
  13. package/lib/Socket/communities.js +430 -430
  14. package/lib/Socket/groups.js +342 -342
  15. package/lib/Socket/index.js +21 -22
  16. package/lib/Socket/messages-recv.js +963 -743
  17. package/lib/Socket/messages-send.js +273 -321
  18. package/lib/Socket/mex.js +50 -50
  19. package/lib/Socket/newsletter.js +148 -148
  20. package/lib/Socket/nexus-handler.js +296 -247
  21. package/lib/Socket/registration.js +50 -33
  22. package/lib/Socket/socket.js +872 -1201
  23. package/lib/Store/index.js +5 -5
  24. package/lib/Store/make-cache-manager-store.js +81 -81
  25. package/lib/Store/make-in-memory-store.js +416 -416
  26. package/lib/Store/make-ordered-dictionary.js +81 -81
  27. package/lib/Store/object-repository.js +30 -30
  28. package/lib/Types/Auth.js +1 -1
  29. package/lib/Types/Bussines.js +1 -1
  30. package/lib/Types/Call.js +1 -1
  31. package/lib/Types/Chat.js +7 -7
  32. package/lib/Types/Contact.js +1 -1
  33. package/lib/Types/Events.js +1 -1
  34. package/lib/Types/GroupMetadata.js +1 -1
  35. package/lib/Types/Label.js +24 -24
  36. package/lib/Types/LabelAssociation.js +6 -6
  37. package/lib/Types/Message.js +10 -10
  38. package/lib/Types/Newsletter.js +37 -29
  39. package/lib/Types/Product.js +1 -1
  40. package/lib/Types/Signal.js +1 -1
  41. package/lib/Types/Socket.js +2 -2
  42. package/lib/Types/State.js +55 -12
  43. package/lib/Types/USync.js +1 -1
  44. package/lib/Types/index.js +25 -25
  45. package/lib/Utils/auth-utils.js +264 -256
  46. package/lib/Utils/baileys-event-stream.js +55 -55
  47. package/lib/Utils/browser-utils.js +27 -27
  48. package/lib/Utils/business.js +228 -230
  49. package/lib/Utils/chat-utils.js +726 -764
  50. package/lib/Utils/companion-reg-client-utils.js +34 -0
  51. package/lib/Utils/crypto.js +109 -135
  52. package/lib/Utils/decode-wa-message.js +342 -314
  53. package/lib/Utils/event-buffer.js +547 -547
  54. package/lib/Utils/generics.js +295 -297
  55. package/lib/Utils/history.js +91 -83
  56. package/lib/Utils/index.js +25 -20
  57. package/lib/Utils/key-store.js +17 -0
  58. package/lib/Utils/link-preview.js +107 -98
  59. package/lib/Utils/logger.js +2 -2
  60. package/lib/Utils/lt-hash.js +47 -47
  61. package/lib/Utils/make-mutex.js +39 -39
  62. package/lib/Utils/message-retry-manager.js +148 -148
  63. package/lib/Utils/messages-media.js +579 -535
  64. package/lib/Utils/messages.js +821 -706
  65. package/lib/Utils/noise-handler.js +255 -255
  66. package/lib/Utils/pre-key-manager.js +105 -105
  67. package/lib/Utils/process-message.js +430 -412
  68. package/lib/Utils/reporting-utils.js +155 -0
  69. package/lib/Utils/signal.js +191 -159
  70. package/lib/Utils/sync-action-utils.js +33 -0
  71. package/lib/Utils/tc-token-utils.js +162 -0
  72. package/lib/Utils/use-multi-file-auth-state.js +120 -120
  73. package/lib/Utils/validate-connection.js +194 -194
  74. package/lib/WABinary/constants.js +1306 -1300
  75. package/lib/WABinary/decode.js +237 -237
  76. package/lib/WABinary/encode.js +232 -232
  77. package/lib/WABinary/generic-utils.js +252 -211
  78. package/lib/WABinary/index.js +6 -5
  79. package/lib/WABinary/jid-utils.js +279 -95
  80. package/lib/WABinary/types.js +1 -1
  81. package/lib/WAM/BinaryInfo.js +9 -9
  82. package/lib/WAM/constants.js +22852 -22852
  83. package/lib/WAM/encode.js +149 -149
  84. package/lib/WAM/index.js +3 -3
  85. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -28
  86. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -53
  87. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -26
  88. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -37
  89. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
  90. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -28
  91. package/lib/WAUSync/Protocols/index.js +4 -4
  92. package/lib/WAUSync/USyncQuery.js +93 -93
  93. package/lib/WAUSync/USyncUser.js +22 -22
  94. package/lib/WAUSync/index.js +3 -3
  95. package/lib/index.js +65 -66
  96. package/package.json +172 -143
  97. package/lib/Signal/Group/ciphertext-message.js +0 -12
  98. package/lib/Signal/Group/group-session-builder.js +0 -30
  99. package/lib/Signal/Group/group_cipher.js +0 -100
  100. package/lib/Signal/Group/index.js +0 -12
  101. package/lib/Signal/Group/keyhelper.js +0 -18
  102. package/lib/Signal/Group/sender-chain-key.js +0 -26
  103. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  104. package/lib/Signal/Group/sender-key-message.js +0 -66
  105. package/lib/Signal/Group/sender-key-name.js +0 -48
  106. package/lib/Signal/Group/sender-key-record.js +0 -41
  107. package/lib/Signal/Group/sender-key-state.js +0 -84
  108. package/lib/Signal/Group/sender-message-key.js +0 -26
package/package.json CHANGED
@@ -1,144 +1,173 @@
1
- {
2
- "$schema": "https://json.schemastore.org/package.json",
3
- "name": "@nexustechpro/baileys",
4
- "type": "module",
5
- "version": "2.0.2",
6
- "description": "Advanced WhatsApp Web API client with interactive messages, product catalogs, carousels, events, payments, and polls.",
7
- "keywords": [
8
- "whatsapp",
9
- "whatsapp-api",
10
- "whatsapp-web",
11
- "whatsapp-bot",
12
- "automation",
13
- "websocket",
14
- "baileys-mod",
15
- "wabot",
16
- "js-whatsapp",
17
- "baileys",
18
- "multimedia-messaging",
19
- "multidevice",
20
- "nexustech",
21
- "nexus",
22
- "nexustechpro",
23
- "advanced-messaging",
24
- "nexusbaileys",
25
- "nexusbot",
26
- "interactive-messages",
27
- "buttons",
28
- "carousels",
29
- "products",
30
- "events",
31
- "payments",
32
- "multi-device"
33
- ],
34
- "homepage": "https://github.com/nexustechpro2/baileys/",
35
- "repository": {
36
- "url": "git+ssh://git@github.com/nexustechpro2/baileys.git"
37
- },
38
- "license": "MIT",
39
- "author": "nexustechpro2",
40
- "main": "lib/index.js",
41
- "types": "lib/index.d.ts",
42
- "scripts": {
43
- "build:all": "tsc && typedoc",
44
- "build:docs": "typedoc",
45
- "build:tsc": "tsc",
46
- "generate:license": "npx license",
47
- "changelog:last": "conventional-changelog -p angular -r 2",
48
- "changelog:preview": "conventional-changelog -p angular -u",
49
- "changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
50
- "example": "node --inspect -r ts-node/register Example/example.ts",
51
- "gen:protobuf": "sh WAProto/GenerateStatics.sh",
52
- "lint": "eslint src --ext .js,.ts,.jsx,.tsx",
53
- "lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
54
- "prepack": "echo 'NexusTechPro WhatsApp Library'",
55
- "prepare": "echo 'NexusTechPro WhatsApp Library'",
56
- "preinstall": "node ./engine-requirements.js",
57
- "release": "release-it",
58
- "test": "jest"
59
- },
60
- "files": [
61
- "lib/**/*.js",
62
- "lib/**/*.json",
63
- "lib/**/*.d.ts",
64
- "lib/**/*.map",
65
- "WAProto/**/*.js",
66
- "WAProto/**/*.json",
67
- "WAProto/**/*.d.ts",
68
- "WAProto/**/*.sh",
69
- "engine-requirements.js"
70
- ],
71
- "dependencies": {
72
- "@cacheable/node-cache": "^1.4.0",
73
- "@hapi/boom": "^9.1.3",
74
- "async-mutex": "^0.5.0",
75
- "axios": "^1.6.0",
76
- "cache-manager": "latest",
77
- "chalk": "^4.1.2",
78
- "fflate": "^0.8.2",
79
- "gradient-string": "^2.0.2",
80
- "libsignal": "npm:@rexxhayanasi/elaina-libsignal",
81
- "lru-cache": "^11.1.0",
82
- "music-metadata": "^11.7.0",
83
- "p-queue": "^9.0.0",
84
- "pino": "^9.6",
85
- "protobufjs": "^7.2.4",
86
- "sharp": "^0.32.0",
87
- "whatsapp-rust-bridge": "^0.5.2",
88
- "ws": "^8.13.0",
89
- "yarn": "^1.22.22"
90
- },
91
- "devDependencies": {
92
- "@eslint/eslintrc": "^3.3.1",
93
- "@eslint/js": "^9.31.0",
94
- "@types/jest": "^30.0.0",
95
- "@types/node": "^20.9.0",
96
- "@types/ws": "^8.0.0",
97
- "@typescript-eslint/eslint-plugin": "^8",
98
- "@typescript-eslint/parser": "^8",
99
- "@whiskeysockets/eslint-config": "^1.0.0",
100
- "conventional-changelog": "^7.1.1",
101
- "conventional-changelog-angular": "^8.0.0",
102
- "esbuild-register": "^3.6.0",
103
- "eslint": "^9",
104
- "eslint-config-prettier": "^10.1.2",
105
- "eslint-plugin-prettier": "^5.4.0",
106
- "jest": "^30.0.5",
107
- "jimp": "^1.6.0",
108
- "jiti": "^2.4.2",
109
- "json": "^11.0.0",
110
- "link-preview-js": "^4.0.0",
111
- "lru-cache": "^11.1.0",
112
- "open": "^8.4.2",
113
- "pino-pretty": "^13.1.1",
114
- "prettier": "^3.5.3",
115
- "protobufjs-cli": "^1.1.3",
116
- "release-it": "^15.10.3",
117
- "ts-jest": "^29.4.0",
118
- "tsc-esm-fix": "^3.1.2",
119
- "tsx": "^4.20.3",
120
- "typedoc": "^0.27.9",
121
- "typedoc-plugin-markdown": "4.4.2",
122
- "typescript": "^5.8.2"
123
- },
124
- "peerDependencies": {
125
- "audio-decode": "^2.1.3",
126
- "jimp": "^1.6.0",
127
- "link-preview-js": "^3.0.0"
128
- },
129
- "peerDependenciesMeta": {
130
- "audio-decode": {
131
- "optional": true
132
- },
133
- "jimp": {
134
- "optional": true
135
- },
136
- "link-preview-js": {
137
- "optional": true
138
- }
139
- },
140
- "packageManager": "yarn@4.9.2",
141
- "engines": {
142
- "node": ">=20.0.0"
143
- }
1
+ {
2
+ "$schema": "https://json.schemastore.org/package.json",
3
+ "name": "@nexustechpro/baileys",
4
+ "type": "module",
5
+ "version": "2.0.6",
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
+ "ffmpeg-static": "^5.2.0",
109
+ "gradient-string": "^2.0.2",
110
+ "libphonenumber-js": "^1.13.3",
111
+ "link-preview-js": "latest",
112
+ "lru-cache": "^11.1.0",
113
+ "music-metadata": "^11.7.0",
114
+ "p-queue": "^9.0.0",
115
+ "pino": "^9.6",
116
+ "protobufjs": "latest",
117
+ "sharp": "^0.32.0",
118
+ "uuid": "latest",
119
+ "whatsapp-rust-bridge": "latest",
120
+ "ws": "latest",
121
+ "yarn": "^1.22.22"
122
+ },
123
+ "devDependencies": {
124
+ "@eslint/eslintrc": "^3.3.1",
125
+ "@eslint/js": "^9.31.0",
126
+ "@types/jest": "^30.0.0",
127
+ "@types/node": "^20.9.0",
128
+ "@types/ws": "^8.0.0",
129
+ "@typescript-eslint/eslint-plugin": "^8",
130
+ "@typescript-eslint/parser": "^8",
131
+ "@whiskeysockets/eslint-config": "^1.0.0",
132
+ "conventional-changelog": "^7.1.1",
133
+ "conventional-changelog-angular": "^8.0.0",
134
+ "esbuild-register": "^3.6.0",
135
+ "eslint": "^9",
136
+ "eslint-config-prettier": "^10.1.2",
137
+ "eslint-plugin-prettier": "^5.4.0",
138
+ "jest": "^30.0.5",
139
+ "jimp": "^1.6.0",
140
+ "jiti": "^2.4.2",
141
+ "json": "^11.0.0",
142
+ "link-preview-js": "^3.0.4",
143
+ "lru-cache": "^11.1.0",
144
+ "open": "^8.4.2",
145
+ "pino-pretty": "^13.1.1",
146
+ "prettier": "^3.5.3",
147
+ "protobufjs-cli": "^1.1.3",
148
+ "release-it": "^15.10.3",
149
+ "ts-jest": "^29.4.0",
150
+ "tsc-esm-fix": "^3.1.2",
151
+ "tsx": "^4.20.3",
152
+ "typedoc": "^0.27.9",
153
+ "typedoc-plugin-markdown": "4.4.2",
154
+ "typescript": "^5.8.2"
155
+ },
156
+ "peerDependencies": {
157
+ "audio-decode": "^2.1.3",
158
+ "jimp": "^1.6.0",
159
+ "link-preview-js": "^3.0.4"
160
+ },
161
+ "peerDependenciesMeta": {
162
+ "audio-decode": {
163
+ "optional": true
164
+ },
165
+ "jimp": {
166
+ "optional": true
167
+ }
168
+ },
169
+ "packageManager": "yarn@4.9.2",
170
+ "engines": {
171
+ "node": ">=20.0.0"
172
+ }
144
173
  }
@@ -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