@sixcore/baileys 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +606 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4357 -0
- package/WAProto/index.d.ts +50383 -0
- package/WAProto/index.js +155693 -0
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/generate-proto.sh +1 -0
- package/WASignalGroup/group.proto +42 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/WASignalGroup/sender_message_key.js +39 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Defaults/index.js +108 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +152 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +19 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +170 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.d.ts +81 -0
- package/lib/Socket/chats.js +950 -0
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +315 -0
- package/lib/Socket/index.d.ts +172 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.d.ts +158 -0
- package/lib/Socket/messages-recv.js +972 -0
- package/lib/Socket/messages-send.d.ts +155 -0
- package/lib/Socket/messages-send.js +1087 -0
- package/lib/Socket/newsletter.d.ts +132 -0
- package/lib/Socket/newsletter.js +236 -0
- package/lib/Socket/registration.d.ts +264 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +44 -0
- package/lib/Socket/socket.js +643 -0
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +431 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +109 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +107 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +172 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +56 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +46 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.d.ts +433 -0
- package/lib/Types/Message.js +9 -0
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Newsletter.js +32 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +116 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +227 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +745 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +199 -0
- package/lib/Utils/decode-wa-message.d.ts +36 -0
- package/lib/Utils/decode-wa-message.js +234 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +517 -0
- package/lib/Utils/generics.d.ts +88 -0
- package/lib/Utils/generics.js +402 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/history.js +94 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +33 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +93 -0
- package/lib/Utils/logger.d.ts +2 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/messages-media.d.ts +113 -0
- package/lib/Utils/messages-media.js +643 -0
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +1221 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +160 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +373 -0
- package/lib/Utils/signal.d.ts +33 -0
- package/lib/Utils/signal.js +159 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-multi-file-auth-state.js +295 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-single-file-auth-state.js +75 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +205 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/constants.js +40 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/decode.js +264 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +252 -0
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/generic-utils.js +110 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/jid-utils.js +62 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +89 -0
- package/lib/WAUSync/USyncUser.d.ts +10 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.js +31 -0
- package/package.json +51 -0
- package/src/Defaults/baileys-version.json +3 -0
- package/src/Defaults/index.ts +133 -0
- package/src/Signal/Group/ciphertext-message.ts +9 -0
- package/src/Signal/Group/group-session-builder.ts +56 -0
- package/src/Signal/Group/group_cipher.ts +117 -0
- package/src/Signal/Group/index.ts +11 -0
- package/src/Signal/Group/keyhelper.ts +28 -0
- package/src/Signal/Group/sender-chain-key.ts +34 -0
- package/src/Signal/Group/sender-key-distribution-message.ts +95 -0
- package/src/Signal/Group/sender-key-message.ts +96 -0
- package/src/Signal/Group/sender-key-name.ts +66 -0
- package/src/Signal/Group/sender-key-record.ts +69 -0
- package/src/Signal/Group/sender-key-state.ts +134 -0
- package/src/Signal/Group/sender-message-key.ts +36 -0
- package/src/Signal/libsignal.ts +447 -0
- package/src/Signal/lid-mapping.ts +209 -0
- package/src/Socket/Client/index.ts +2 -0
- package/src/Socket/Client/types.ts +22 -0
- package/src/Socket/Client/websocket.ts +56 -0
- package/src/Socket/business.ts +421 -0
- package/src/Socket/chats.ts +1223 -0
- package/src/Socket/communities.ts +477 -0
- package/src/Socket/groups.ts +361 -0
- package/src/Socket/index.ts +22 -0
- package/src/Socket/messages-recv.ts +1563 -0
- package/src/Socket/messages-send.ts +1210 -0
- package/src/Socket/mex.ts +58 -0
- package/src/Socket/newsletter.ts +229 -0
- package/src/Socket/socket.ts +1072 -0
- package/src/Types/Auth.ts +115 -0
- package/src/Types/Bussines.ts +20 -0
- package/src/Types/Call.ts +14 -0
- package/src/Types/Chat.ts +138 -0
- package/src/Types/Contact.ts +24 -0
- package/src/Types/Events.ts +132 -0
- package/src/Types/GroupMetadata.ts +70 -0
- package/src/Types/Label.ts +48 -0
- package/src/Types/LabelAssociation.ts +35 -0
- package/src/Types/Message.ts +424 -0
- package/src/Types/Newsletter.ts +98 -0
- package/src/Types/Product.ts +85 -0
- package/src/Types/Signal.ts +76 -0
- package/src/Types/Socket.ts +150 -0
- package/src/Types/State.ts +43 -0
- package/src/Types/USync.ts +27 -0
- package/src/Types/globals.d.ts +8 -0
- package/src/Types/index.ts +67 -0
- package/src/Utils/auth-utils.ts +331 -0
- package/src/Utils/browser-utils.ts +31 -0
- package/src/Utils/business.ts +286 -0
- package/src/Utils/chat-utils.ts +933 -0
- package/src/Utils/crypto.ts +184 -0
- package/src/Utils/decode-wa-message.ts +355 -0
- package/src/Utils/event-buffer.ts +662 -0
- package/src/Utils/generics.ts +470 -0
- package/src/Utils/history.ts +114 -0
- package/src/Utils/index.ts +18 -0
- package/src/Utils/link-preview.ts +111 -0
- package/src/Utils/logger.ts +13 -0
- package/src/Utils/lt-hash.ts +65 -0
- package/src/Utils/make-mutex.ts +45 -0
- package/src/Utils/message-retry-manager.ts +229 -0
- package/src/Utils/messages-media.ts +820 -0
- package/src/Utils/messages.ts +1137 -0
- package/src/Utils/noise-handler.ts +192 -0
- package/src/Utils/pre-key-manager.ts +126 -0
- package/src/Utils/process-message.ts +622 -0
- package/src/Utils/signal.ts +214 -0
- package/src/Utils/use-multi-file-auth-state.ts +136 -0
- package/src/Utils/validate-connection.ts +253 -0
- package/src/WABinary/constants.ts +1305 -0
- package/src/WABinary/decode.ts +281 -0
- package/src/WABinary/encode.ts +253 -0
- package/src/WABinary/generic-utils.ts +127 -0
- package/src/WABinary/index.ts +5 -0
- package/src/WABinary/jid-utils.ts +128 -0
- package/src/WABinary/types.ts +17 -0
- package/src/WAM/BinaryInfo.ts +12 -0
- package/src/WAM/constants.ts +22889 -0
- package/src/WAM/encode.ts +169 -0
- package/src/WAM/index.ts +3 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.ts +32 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.ts +78 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.ts +35 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.ts +44 -0
- package/src/WAUSync/Protocols/UsyncBotProfileProtocol.ts +76 -0
- package/src/WAUSync/Protocols/UsyncLIDProtocol.ts +33 -0
- package/src/WAUSync/Protocols/index.ts +4 -0
- package/src/WAUSync/USyncQuery.ts +133 -0
- package/src/WAUSync/USyncUser.ts +32 -0
- package/src/WAUSync/index.ts +3 -0
- package/src/index.ts +13 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.USyncUser = void 0;
|
|
4
|
+
class USyncUser {
|
|
5
|
+
withId(id) {
|
|
6
|
+
this.id = id;
|
|
7
|
+
return this;
|
|
8
|
+
}
|
|
9
|
+
withLid(lid) {
|
|
10
|
+
this.lid = lid;
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
withPhone(phone) {
|
|
14
|
+
this.phone = phone;
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
withType(type) {
|
|
18
|
+
this.type = type;
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
withPersonaId(personaId) {
|
|
22
|
+
this.personaId = personaId;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.USyncUser = USyncUser;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Protocols"), exports);
|
|
18
|
+
__exportStar(require("./USyncQuery"), exports);
|
|
19
|
+
__exportStar(require("./USyncUser"), exports);
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.makeWASocket = void 0;
|
|
21
|
+
const Socket_1 = __importDefault(require("./Socket"));
|
|
22
|
+
exports.makeWASocket = Socket_1.default;
|
|
23
|
+
__exportStar(require("../WAProto"), exports);
|
|
24
|
+
__exportStar(require("./Utils"), exports);
|
|
25
|
+
__exportStar(require("./Types"), exports);
|
|
26
|
+
__exportStar(require("./Store"), exports);
|
|
27
|
+
__exportStar(require("./Defaults"), exports);
|
|
28
|
+
__exportStar(require("./WABinary"), exports);
|
|
29
|
+
__exportStar(require("./WAM"), exports);
|
|
30
|
+
__exportStar(require("./WAUSync"), exports);
|
|
31
|
+
exports.default = Socket_1.default;
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sixcore/baileys",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Baileys core adaptado para @sixcore/baileys",
|
|
5
|
+
"main": "lib/WAUSync/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./lib/WAUSync/index.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/Ytsixx/lena-baileys.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/Ytsixx/lena-baileys/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/Ytsixx/lena-baileys",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"baileys",
|
|
19
|
+
"whatsapp",
|
|
20
|
+
"core",
|
|
21
|
+
"lena"
|
|
22
|
+
],
|
|
23
|
+
"author": "Sixx",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@cacheable/node-cache": "^2.0.1",
|
|
27
|
+
"@hapi/boom": "^10.0.1",
|
|
28
|
+
"async-lock": "^1.4.1",
|
|
29
|
+
"async-mutex": "^0.5.0",
|
|
30
|
+
"cache-manager": "^7.2.8",
|
|
31
|
+
"libsignal": "^2.0.1",
|
|
32
|
+
"libsignal-protocol": "^1.3.15",
|
|
33
|
+
"long": "^5.3.2",
|
|
34
|
+
"lru-cache": "^11.2.6",
|
|
35
|
+
"music-metadata": "^11.12.1",
|
|
36
|
+
"p-queue": "^9.1.0",
|
|
37
|
+
"pino": "^9.14.0",
|
|
38
|
+
"protobufjs": "^8.0.0",
|
|
39
|
+
"uuid": "^13.0.0",
|
|
40
|
+
"ws": "^8.19.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"axios": "^1.13.5",
|
|
44
|
+
"node-cache": "^5.1.2",
|
|
45
|
+
"node-fetch": "^3.3.2",
|
|
46
|
+
"qrcode-terminal": "^0.12.0"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"test": "node test.js"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js'
|
|
2
|
+
import { makeLibSignalRepository } from '../Signal/libsignal'
|
|
3
|
+
import type { AuthenticationState, SocketConfig, WAVersion } from '../Types'
|
|
4
|
+
import { Browsers } from '../Utils/browser-utils'
|
|
5
|
+
import logger from '../Utils/logger'
|
|
6
|
+
|
|
7
|
+
const version = [2, 3000, 1027934701]
|
|
8
|
+
|
|
9
|
+
export const UNAUTHORIZED_CODES = [401, 403, 419]
|
|
10
|
+
|
|
11
|
+
export const DEFAULT_ORIGIN = 'https://web.whatsapp.com'
|
|
12
|
+
export const CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/'
|
|
13
|
+
export const CALL_AUDIO_PREFIX = 'https://call.whatsapp.com/voice/'
|
|
14
|
+
export const DEF_CALLBACK_PREFIX = 'CB:'
|
|
15
|
+
export const DEF_TAG_PREFIX = 'TAG:'
|
|
16
|
+
export const PHONE_CONNECTION_CB = 'CB:Pong'
|
|
17
|
+
|
|
18
|
+
export const WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0])
|
|
19
|
+
export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1])
|
|
20
|
+
export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5])
|
|
21
|
+
export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6])
|
|
22
|
+
|
|
23
|
+
export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60
|
|
24
|
+
|
|
25
|
+
export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0'
|
|
26
|
+
export const DICT_VERSION = 3
|
|
27
|
+
export const KEY_BUNDLE_TYPE = Buffer.from([5])
|
|
28
|
+
export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]) // last is "DICT_VERSION"
|
|
29
|
+
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
30
|
+
export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g
|
|
31
|
+
|
|
32
|
+
// TODO: Add WA root CA
|
|
33
|
+
export const WA_CERT_DETAILS = {
|
|
34
|
+
SERIAL: 0
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const PROCESSABLE_HISTORY_TYPES = [
|
|
38
|
+
proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
39
|
+
proto.HistorySync.HistorySyncType.PUSH_NAME,
|
|
40
|
+
proto.HistorySync.HistorySyncType.RECENT,
|
|
41
|
+
proto.HistorySync.HistorySyncType.FULL,
|
|
42
|
+
proto.HistorySync.HistorySyncType.ON_DEMAND,
|
|
43
|
+
proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
|
|
44
|
+
proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
|
|
48
|
+
version: version as WAVersion,
|
|
49
|
+
browser: Browsers.macOS('Chrome'),
|
|
50
|
+
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
51
|
+
connectTimeoutMs: 20_000,
|
|
52
|
+
keepAliveIntervalMs: 30_000,
|
|
53
|
+
logger: logger.child({ class: 'baileys' }),
|
|
54
|
+
emitOwnEvents: true,
|
|
55
|
+
defaultQueryTimeoutMs: 60_000,
|
|
56
|
+
customUploadHosts: [],
|
|
57
|
+
retryRequestDelayMs: 250,
|
|
58
|
+
maxMsgRetryCount: 5,
|
|
59
|
+
fireInitQueries: true,
|
|
60
|
+
auth: undefined as unknown as AuthenticationState,
|
|
61
|
+
markOnlineOnConnect: true,
|
|
62
|
+
syncFullHistory: true,
|
|
63
|
+
patchMessageBeforeSending: msg => msg,
|
|
64
|
+
shouldSyncHistoryMessage: () => true,
|
|
65
|
+
shouldIgnoreJid: () => false,
|
|
66
|
+
linkPreviewImageThumbnailWidth: 192,
|
|
67
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
68
|
+
generateHighQualityLinkPreview: false,
|
|
69
|
+
enableAutoSessionRecreation: true,
|
|
70
|
+
enableRecentMessageCache: true,
|
|
71
|
+
options: {},
|
|
72
|
+
appStateMacVerification: {
|
|
73
|
+
patch: false,
|
|
74
|
+
snapshot: false
|
|
75
|
+
},
|
|
76
|
+
countryCode: 'US',
|
|
77
|
+
getMessage: async () => undefined,
|
|
78
|
+
cachedGroupMetadata: async () => undefined,
|
|
79
|
+
makeSignalRepository: makeLibSignalRepository
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const MEDIA_PATH_MAP: { [T in MediaType]?: string } = {
|
|
83
|
+
image: '/mms/image',
|
|
84
|
+
video: '/mms/video',
|
|
85
|
+
document: '/mms/document',
|
|
86
|
+
audio: '/mms/audio',
|
|
87
|
+
sticker: '/mms/image',
|
|
88
|
+
'thumbnail-link': '/mms/image',
|
|
89
|
+
'product-catalog-image': '/product/image',
|
|
90
|
+
'md-app-state': '',
|
|
91
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
92
|
+
'biz-cover-photo': '/pps/biz-cover-photo'
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const MEDIA_HKDF_KEY_MAPPING = {
|
|
96
|
+
audio: 'Audio',
|
|
97
|
+
document: 'Document',
|
|
98
|
+
gif: 'Video',
|
|
99
|
+
image: 'Image',
|
|
100
|
+
ppic: '',
|
|
101
|
+
product: 'Image',
|
|
102
|
+
ptt: 'Audio',
|
|
103
|
+
sticker: 'Image',
|
|
104
|
+
video: 'Video',
|
|
105
|
+
'thumbnail-document': 'Document Thumbnail',
|
|
106
|
+
'thumbnail-image': 'Image Thumbnail',
|
|
107
|
+
'thumbnail-video': 'Video Thumbnail',
|
|
108
|
+
'thumbnail-link': 'Link Thumbnail',
|
|
109
|
+
'md-msg-hist': 'History',
|
|
110
|
+
'md-app-state': 'App State',
|
|
111
|
+
'product-catalog-image': '',
|
|
112
|
+
'payment-bg-image': 'Payment Background',
|
|
113
|
+
ptv: 'Video',
|
|
114
|
+
'biz-cover-photo': 'Image'
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export type MediaType = keyof typeof MEDIA_HKDF_KEY_MAPPING
|
|
118
|
+
|
|
119
|
+
export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP) as MediaType[]
|
|
120
|
+
|
|
121
|
+
export const MIN_PREKEY_COUNT = 5
|
|
122
|
+
|
|
123
|
+
export const INITIAL_PREKEY_COUNT = 812
|
|
124
|
+
|
|
125
|
+
export const UPLOAD_TIMEOUT = 30000 // 30 seconds
|
|
126
|
+
export const MIN_UPLOAD_INTERVAL = 5000 // 5 seconds minimum between uploads
|
|
127
|
+
|
|
128
|
+
export const DEFAULT_CACHE_TTLS = {
|
|
129
|
+
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
130
|
+
MSG_RETRY: 60 * 60, // 1 hour
|
|
131
|
+
CALL_OFFER: 5 * 60, // 5 minutes
|
|
132
|
+
USER_DEVICES: 5 * 60 // 5 minutes
|
|
133
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export class CiphertextMessage {
|
|
2
|
+
readonly UNSUPPORTED_VERSION: number = 1
|
|
3
|
+
readonly CURRENT_VERSION: number = 3
|
|
4
|
+
readonly WHISPER_TYPE: number = 2
|
|
5
|
+
readonly PREKEY_TYPE: number = 3
|
|
6
|
+
readonly SENDERKEY_TYPE: number = 4
|
|
7
|
+
readonly SENDERKEY_DISTRIBUTION_TYPE: number = 5
|
|
8
|
+
readonly ENCRYPTED_MESSAGE_OVERHEAD: number = 53
|
|
9
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as keyhelper from './keyhelper'
|
|
2
|
+
import { SenderKeyDistributionMessage } from './sender-key-distribution-message'
|
|
3
|
+
import { SenderKeyName } from './sender-key-name'
|
|
4
|
+
import { SenderKeyRecord } from './sender-key-record'
|
|
5
|
+
|
|
6
|
+
interface SenderKeyStore {
|
|
7
|
+
loadSenderKey(senderKeyName: SenderKeyName): Promise<SenderKeyRecord>
|
|
8
|
+
storeSenderKey(senderKeyName: SenderKeyName, record: SenderKeyRecord): Promise<void>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class GroupSessionBuilder {
|
|
12
|
+
private readonly senderKeyStore: SenderKeyStore
|
|
13
|
+
|
|
14
|
+
constructor(senderKeyStore: SenderKeyStore) {
|
|
15
|
+
this.senderKeyStore = senderKeyStore
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public async process(
|
|
19
|
+
senderKeyName: SenderKeyName,
|
|
20
|
+
senderKeyDistributionMessage: SenderKeyDistributionMessage
|
|
21
|
+
): Promise<void> {
|
|
22
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName)
|
|
23
|
+
senderKeyRecord.addSenderKeyState(
|
|
24
|
+
senderKeyDistributionMessage.getId(),
|
|
25
|
+
senderKeyDistributionMessage.getIteration(),
|
|
26
|
+
senderKeyDistributionMessage.getChainKey(),
|
|
27
|
+
senderKeyDistributionMessage.getSignatureKey()
|
|
28
|
+
)
|
|
29
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public async create(senderKeyName: SenderKeyName): Promise<SenderKeyDistributionMessage> {
|
|
33
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName)
|
|
34
|
+
|
|
35
|
+
if (senderKeyRecord.isEmpty()) {
|
|
36
|
+
const keyId = keyhelper.generateSenderKeyId()
|
|
37
|
+
const senderKey = keyhelper.generateSenderKey()
|
|
38
|
+
const signingKey = keyhelper.generateSenderSigningKey()
|
|
39
|
+
|
|
40
|
+
senderKeyRecord.setSenderKeyState(keyId, 0, senderKey, signingKey)
|
|
41
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const state = senderKeyRecord.getSenderKeyState()
|
|
45
|
+
if (!state) {
|
|
46
|
+
throw new Error('No session state available')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return new SenderKeyDistributionMessage(
|
|
50
|
+
state.getKeyId(),
|
|
51
|
+
state.getSenderChainKey().getIteration(),
|
|
52
|
+
state.getSenderChainKey().getSeed(),
|
|
53
|
+
state.getSigningKeyPublic()
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { decrypt, encrypt } from 'libsignal/src/crypto'
|
|
2
|
+
import { SenderKeyMessage } from './sender-key-message'
|
|
3
|
+
import { SenderKeyName } from './sender-key-name'
|
|
4
|
+
import { SenderKeyRecord } from './sender-key-record'
|
|
5
|
+
import { SenderKeyState } from './sender-key-state'
|
|
6
|
+
|
|
7
|
+
export interface SenderKeyStore {
|
|
8
|
+
loadSenderKey(senderKeyName: SenderKeyName): Promise<SenderKeyRecord>
|
|
9
|
+
|
|
10
|
+
storeSenderKey(senderKeyName: SenderKeyName, record: SenderKeyRecord): Promise<void>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class GroupCipher {
|
|
14
|
+
private readonly senderKeyStore: SenderKeyStore
|
|
15
|
+
private readonly senderKeyName: SenderKeyName
|
|
16
|
+
|
|
17
|
+
constructor(senderKeyStore: SenderKeyStore, senderKeyName: SenderKeyName) {
|
|
18
|
+
this.senderKeyStore = senderKeyStore
|
|
19
|
+
this.senderKeyName = senderKeyName
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public async encrypt(paddedPlaintext: Uint8Array): Promise<Uint8Array> {
|
|
23
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName)
|
|
24
|
+
if (!record) {
|
|
25
|
+
throw new Error('No SenderKeyRecord found for encryption')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const senderKeyState = record.getSenderKeyState()
|
|
29
|
+
if (!senderKeyState) {
|
|
30
|
+
throw new Error('No session to encrypt message')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const iteration = senderKeyState.getSenderChainKey().getIteration()
|
|
34
|
+
const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1)
|
|
35
|
+
|
|
36
|
+
const ciphertext = await this.getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext)
|
|
37
|
+
|
|
38
|
+
const senderKeyMessage = new SenderKeyMessage(
|
|
39
|
+
senderKeyState.getKeyId(),
|
|
40
|
+
senderKey.getIteration(),
|
|
41
|
+
ciphertext,
|
|
42
|
+
senderKeyState.getSigningKeyPrivate()
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record)
|
|
46
|
+
return senderKeyMessage.serialize()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public async decrypt(senderKeyMessageBytes: Uint8Array): Promise<Uint8Array> {
|
|
50
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName)
|
|
51
|
+
if (!record) {
|
|
52
|
+
throw new Error('No SenderKeyRecord found for decryption')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const senderKeyMessage = new SenderKeyMessage(null, null, null, null, senderKeyMessageBytes)
|
|
56
|
+
const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId())
|
|
57
|
+
if (!senderKeyState) {
|
|
58
|
+
throw new Error('No session found to decrypt message')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic())
|
|
62
|
+
const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration())
|
|
63
|
+
|
|
64
|
+
const plaintext = await this.getPlainText(
|
|
65
|
+
senderKey.getIv(),
|
|
66
|
+
senderKey.getCipherKey(),
|
|
67
|
+
senderKeyMessage.getCipherText()
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record)
|
|
71
|
+
return plaintext
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private getSenderKey(senderKeyState: SenderKeyState, iteration: number) {
|
|
75
|
+
let senderChainKey = senderKeyState.getSenderChainKey()
|
|
76
|
+
if (senderChainKey.getIteration() > iteration) {
|
|
77
|
+
if (senderKeyState.hasSenderMessageKey(iteration)) {
|
|
78
|
+
const messageKey = senderKeyState.removeSenderMessageKey(iteration)
|
|
79
|
+
if (!messageKey) {
|
|
80
|
+
throw new Error('No sender message key found for iteration')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return messageKey
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
throw new Error(`Received message with old counter: ${senderChainKey.getIteration()}, ${iteration}`)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (iteration - senderChainKey.getIteration() > 2000) {
|
|
90
|
+
throw new Error('Over 2000 messages into the future!')
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
while (senderChainKey.getIteration() < iteration) {
|
|
94
|
+
senderKeyState.addSenderMessageKey(senderChainKey.getSenderMessageKey())
|
|
95
|
+
senderChainKey = senderChainKey.getNext()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
senderKeyState.setSenderChainKey(senderChainKey.getNext())
|
|
99
|
+
return senderChainKey.getSenderMessageKey()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private async getPlainText(iv: Uint8Array, key: Uint8Array, ciphertext: Uint8Array): Promise<Uint8Array> {
|
|
103
|
+
try {
|
|
104
|
+
return decrypt(key, ciphertext, iv)
|
|
105
|
+
} catch (e) {
|
|
106
|
+
throw new Error('InvalidMessageException')
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private async getCipherText(iv: Uint8Array, key: Uint8Array, plaintext: Uint8Array): Promise<Buffer> {
|
|
111
|
+
try {
|
|
112
|
+
return encrypt(key, plaintext, iv)
|
|
113
|
+
} catch (e) {
|
|
114
|
+
throw new Error('InvalidMessageException')
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { GroupSessionBuilder } from './group-session-builder'
|
|
2
|
+
export { SenderKeyDistributionMessage } from './sender-key-distribution-message'
|
|
3
|
+
export { SenderKeyRecord } from './sender-key-record'
|
|
4
|
+
export { SenderKeyName } from './sender-key-name'
|
|
5
|
+
export { GroupCipher } from './group_cipher'
|
|
6
|
+
export { SenderKeyState } from './sender-key-state'
|
|
7
|
+
export { SenderKeyMessage } from './sender-key-message'
|
|
8
|
+
export { SenderMessageKey } from './sender-message-key'
|
|
9
|
+
export { SenderChainKey } from './sender-chain-key'
|
|
10
|
+
export { CiphertextMessage } from './ciphertext-message'
|
|
11
|
+
export * as keyhelper from './keyhelper'
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as nodeCrypto from 'crypto'
|
|
2
|
+
import { generateKeyPair } from 'libsignal/src/curve'
|
|
3
|
+
|
|
4
|
+
type KeyPairType = ReturnType<typeof generateKeyPair>
|
|
5
|
+
|
|
6
|
+
export function generateSenderKey(): Buffer {
|
|
7
|
+
return nodeCrypto.randomBytes(32)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function generateSenderKeyId(): number {
|
|
11
|
+
return nodeCrypto.randomInt(2147483647)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SigningKeyPair {
|
|
15
|
+
public: Buffer
|
|
16
|
+
private: Buffer
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function generateSenderSigningKey(key?: KeyPairType): SigningKeyPair {
|
|
20
|
+
if (!key) {
|
|
21
|
+
key = generateKeyPair()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
public: Buffer.from(key.pubKey),
|
|
26
|
+
private: Buffer.from(key.privKey)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { calculateMAC } from 'libsignal/src/crypto'
|
|
2
|
+
import { SenderMessageKey } from './sender-message-key'
|
|
3
|
+
|
|
4
|
+
export class SenderChainKey {
|
|
5
|
+
private readonly MESSAGE_KEY_SEED: Uint8Array = Buffer.from([0x01])
|
|
6
|
+
private readonly CHAIN_KEY_SEED: Uint8Array = Buffer.from([0x02])
|
|
7
|
+
private readonly iteration: number
|
|
8
|
+
private readonly chainKey: Buffer
|
|
9
|
+
|
|
10
|
+
constructor(iteration: number, chainKey: Uint8Array | Buffer) {
|
|
11
|
+
this.iteration = iteration
|
|
12
|
+
this.chainKey = Buffer.from(chainKey)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public getIteration(): number {
|
|
16
|
+
return this.iteration
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public getSenderMessageKey(): SenderMessageKey {
|
|
20
|
+
return new SenderMessageKey(this.iteration, this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public getNext(): SenderChainKey {
|
|
24
|
+
return new SenderChainKey(this.iteration + 1, this.getDerivative(this.CHAIN_KEY_SEED, this.chainKey))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public getSeed(): Uint8Array {
|
|
28
|
+
return this.chainKey
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private getDerivative(seed: Uint8Array, key: Buffer): Uint8Array {
|
|
32
|
+
return calculateMAC(key, seed)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { proto } from '../../../WAProto/index.js'
|
|
2
|
+
import { CiphertextMessage } from './ciphertext-message'
|
|
3
|
+
|
|
4
|
+
interface SenderKeyDistributionMessageStructure {
|
|
5
|
+
id: number
|
|
6
|
+
iteration: number
|
|
7
|
+
chainKey: string | Uint8Array
|
|
8
|
+
signingKey: string | Uint8Array
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class SenderKeyDistributionMessage extends CiphertextMessage {
|
|
12
|
+
private readonly id: number
|
|
13
|
+
private readonly iteration: number
|
|
14
|
+
private readonly chainKey: Uint8Array
|
|
15
|
+
private readonly signatureKey: Uint8Array
|
|
16
|
+
private readonly serialized: Uint8Array
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
id?: number | null,
|
|
20
|
+
iteration?: number | null,
|
|
21
|
+
chainKey?: Uint8Array | null,
|
|
22
|
+
signatureKey?: Uint8Array | null,
|
|
23
|
+
serialized?: Uint8Array | null
|
|
24
|
+
) {
|
|
25
|
+
super()
|
|
26
|
+
|
|
27
|
+
if (serialized) {
|
|
28
|
+
try {
|
|
29
|
+
const message = serialized.slice(1)
|
|
30
|
+
const distributionMessage = proto.SenderKeyDistributionMessage.decode(
|
|
31
|
+
message
|
|
32
|
+
).toJSON() as SenderKeyDistributionMessageStructure
|
|
33
|
+
|
|
34
|
+
this.serialized = serialized
|
|
35
|
+
this.id = distributionMessage.id
|
|
36
|
+
this.iteration = distributionMessage.iteration
|
|
37
|
+
this.chainKey =
|
|
38
|
+
typeof distributionMessage.chainKey === 'string'
|
|
39
|
+
? Buffer.from(distributionMessage.chainKey, 'base64')
|
|
40
|
+
: distributionMessage.chainKey
|
|
41
|
+
this.signatureKey =
|
|
42
|
+
typeof distributionMessage.signingKey === 'string'
|
|
43
|
+
? Buffer.from(distributionMessage.signingKey, 'base64')
|
|
44
|
+
: distributionMessage.signingKey
|
|
45
|
+
} catch (e) {
|
|
46
|
+
throw new Error(String(e))
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
const version = this.intsToByteHighAndLow(this.CURRENT_VERSION, this.CURRENT_VERSION)
|
|
50
|
+
this.id = id!
|
|
51
|
+
this.iteration = iteration!
|
|
52
|
+
this.chainKey = chainKey!
|
|
53
|
+
this.signatureKey = signatureKey!
|
|
54
|
+
|
|
55
|
+
const message = proto.SenderKeyDistributionMessage.encode(
|
|
56
|
+
proto.SenderKeyDistributionMessage.create({
|
|
57
|
+
id,
|
|
58
|
+
iteration,
|
|
59
|
+
chainKey,
|
|
60
|
+
signingKey: this.signatureKey
|
|
61
|
+
})
|
|
62
|
+
).finish()
|
|
63
|
+
|
|
64
|
+
this.serialized = Buffer.concat([Buffer.from([version]), message])
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private intsToByteHighAndLow(highValue: number, lowValue: number): number {
|
|
69
|
+
return (((highValue << 4) | lowValue) & 0xff) % 256
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public serialize(): Uint8Array {
|
|
73
|
+
return this.serialized
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public getType(): number {
|
|
77
|
+
return this.SENDERKEY_DISTRIBUTION_TYPE
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public getIteration(): number {
|
|
81
|
+
return this.iteration
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public getChainKey(): Uint8Array {
|
|
85
|
+
return this.chainKey
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public getSignatureKey(): Uint8Array {
|
|
89
|
+
return this.signatureKey
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public getId(): number {
|
|
93
|
+
return this.id
|
|
94
|
+
}
|
|
95
|
+
}
|