@d0v3riz/baileys 6.7.21 → 6.7.22
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/WAProto/GenerateStatics.sh +2 -3
- package/WAProto/index.js +4138 -4136
- package/lib/Defaults/index.d.ts +2 -3
- package/lib/Defaults/index.js +40 -36
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.d.ts +3 -4
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.d.ts +2 -3
- package/lib/Signal/Group/group_cipher.js +16 -14
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.d.ts +1 -2
- package/lib/Signal/Group/keyhelper.js +44 -8
- package/lib/Signal/Group/queue-job.d.ts +0 -2
- package/lib/Signal/Group/queue-job.js +5 -5
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -2
- package/lib/Signal/Group/sender-chain-key.js +9 -7
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +9 -6
- package/lib/Signal/Group/sender-key-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-message.js +12 -10
- package/lib/Signal/Group/sender-key-name.d.ts +0 -1
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.d.ts +1 -2
- package/lib/Signal/Group/sender-key-record.js +12 -9
- package/lib/Signal/Group/sender-key-state.d.ts +2 -3
- package/lib/Signal/Group/sender-key-state.js +9 -6
- package/lib/Signal/Group/sender-message-key.d.ts +0 -1
- package/lib/Signal/Group/sender-message-key.js +7 -5
- package/lib/Signal/libsignal.d.ts +2 -3
- package/lib/Signal/libsignal.js +55 -22
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +18 -3
- package/lib/Socket/Client/types.d.ts +1 -2
- package/lib/Socket/Client/types.js +6 -4
- package/lib/Socket/Client/websocket.d.ts +1 -2
- package/lib/Socket/Client/websocket.js +26 -14
- package/lib/Socket/business.d.ts +64 -66
- package/lib/Socket/business.js +37 -32
- package/lib/Socket/chats.d.ts +19 -21
- package/lib/Socket/chats.js +141 -176
- package/lib/Socket/groups.d.ts +35 -37
- package/lib/Socket/groups.js +63 -56
- package/lib/Socket/index.d.ts +70 -102
- package/lib/Socket/index.js +9 -16
- package/lib/Socket/messages-recv.d.ts +49 -51
- package/lib/Socket/messages-recv.js +173 -180
- package/lib/Socket/messages-send.d.ts +46 -48
- package/lib/Socket/messages-send.js +84 -75
- package/lib/Socket/mex.d.ts +1 -2
- package/lib/Socket/mex.js +16 -12
- package/lib/Socket/newsletter.d.ts +44 -46
- package/lib/Socket/newsletter.js +27 -23
- package/lib/Socket/socket.d.ts +12 -13
- package/lib/Socket/socket.js +115 -135
- package/lib/Socket/usync.d.ts +14 -15
- package/lib/Socket/usync.js +11 -9
- package/lib/Types/Auth.d.ts +3 -4
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +0 -1
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +7 -10
- package/lib/Types/Chat.js +4 -2
- package/lib/Types/Contact.d.ts +0 -1
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +10 -11
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +2 -3
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -1
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.d.ts +7 -9
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.d.ts +0 -1
- package/lib/Types/Newsletter.js +7 -5
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +1 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +7 -8
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -14
- package/lib/Types/State.js +2 -13
- package/lib/Types/USync.d.ts +2 -3
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +14 -15
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.d.ts +2 -3
- package/lib/Utils/auth-utils.js +34 -25
- package/lib/Utils/baileys-event-stream.d.ts +1 -2
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.d.ts +2 -3
- package/lib/Utils/business.js +70 -61
- package/lib/Utils/chat-utils.d.ts +7 -8
- package/lib/Utils/chat-utils.js +137 -130
- package/lib/Utils/crypto.d.ts +1 -2
- package/lib/Utils/crypto.js +86 -37
- package/lib/Utils/decode-wa-message.d.ts +4 -5
- package/lib/Utils/decode-wa-message.js +44 -38
- package/lib/Utils/event-buffer.d.ts +4 -4
- package/lib/Utils/event-buffer.js +50 -37
- package/lib/Utils/generics.d.ts +8 -9
- package/lib/Utils/generics.js +114 -87
- package/lib/Utils/history.d.ts +3 -4
- package/lib/Utils/history.js +40 -32
- package/lib/Utils/index.d.ts +17 -18
- package/lib/Utils/index.js +33 -18
- package/lib/Utils/link-preview.d.ts +3 -4
- package/lib/Utils/link-preview.js +47 -10
- package/lib/Utils/logger.d.ts +6 -8
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +8 -9
- package/lib/Utils/lt-hash.js +26 -23
- package/lib/Utils/make-mutex.d.ts +0 -1
- package/lib/Utils/make-mutex.js +9 -5
- package/lib/Utils/messages-media.d.ts +10 -11
- package/lib/Utils/messages-media.js +203 -141
- package/lib/Utils/messages.d.ts +6 -7
- package/lib/Utils/messages.js +199 -190
- package/lib/Utils/noise-handler.d.ts +4 -5
- package/lib/Utils/noise-handler.js +26 -22
- package/lib/Utils/process-message.d.ts +4 -5
- package/lib/Utils/process-message.js +104 -95
- package/lib/Utils/signal.d.ts +4 -5
- package/lib/Utils/signal.js +52 -47
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
- package/lib/Utils/use-multi-file-auth-state.js +26 -23
- package/lib/Utils/validate-connection.d.ts +3 -4
- package/lib/Utils/validate-connection.js +58 -52
- package/lib/WABinary/constants.d.ts +0 -1
- package/lib/WABinary/constants.js +11 -9
- package/lib/WABinary/decode.d.ts +1 -2
- package/lib/WABinary/decode.js +51 -13
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +41 -5
- package/lib/WABinary/generic-utils.d.ts +3 -4
- package/lib/WABinary/generic-utils.js +38 -30
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +0 -1
- package/lib/WABinary/jid-utils.js +35 -21
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +1 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +0 -1
- package/lib/WAM/constants.js +6 -4
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAM/encode.js +14 -12
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -6
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -6
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +11 -7
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +21 -19
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +5 -2
- package/lib/WAUSync/Protocols/index.d.ts +4 -5
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.d.ts +3 -4
- package/lib/WAUSync/USyncQuery.js +20 -18
- package/lib/WAUSync/USyncUser.d.ts +5 -6
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.d.ts +8 -9
- package/lib/index.js +30 -11
- package/package.json +26 -26
- package/WAProto/fix-imports.js +0 -29
- package/lib/Defaults/index.d.ts.map +0 -1
- package/lib/Defaults/index.js.map +0 -1
- package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
- package/lib/Signal/Group/ciphertext-message.js.map +0 -1
- package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
- package/lib/Signal/Group/group-session-builder.js.map +0 -1
- package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
- package/lib/Signal/Group/group_cipher.js.map +0 -1
- package/lib/Signal/Group/index.d.ts.map +0 -1
- package/lib/Signal/Group/index.js.map +0 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
- package/lib/Signal/Group/keyhelper.js.map +0 -1
- package/lib/Signal/Group/queue-job.d.ts.map +0 -1
- package/lib/Signal/Group/queue-job.js.map +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-chain-key.js.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-name.js.map +0 -1
- package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-record.js.map +0 -1
- package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-state.js.map +0 -1
- package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-message-key.js.map +0 -1
- package/lib/Signal/libsignal.d.ts.map +0 -1
- package/lib/Signal/libsignal.js.map +0 -1
- package/lib/Socket/Client/index.d.ts.map +0 -1
- package/lib/Socket/Client/index.js.map +0 -1
- package/lib/Socket/Client/types.d.ts.map +0 -1
- package/lib/Socket/Client/types.js.map +0 -1
- package/lib/Socket/Client/websocket.d.ts.map +0 -1
- package/lib/Socket/Client/websocket.js.map +0 -1
- package/lib/Socket/business.d.ts.map +0 -1
- package/lib/Socket/business.js.map +0 -1
- package/lib/Socket/chats.d.ts.map +0 -1
- package/lib/Socket/chats.js.map +0 -1
- package/lib/Socket/communities.d.ts +0 -219
- package/lib/Socket/communities.d.ts.map +0 -1
- package/lib/Socket/communities.js +0 -351
- package/lib/Socket/communities.js.map +0 -1
- package/lib/Socket/groups.d.ts.map +0 -1
- package/lib/Socket/groups.js.map +0 -1
- package/lib/Socket/index.d.ts.map +0 -1
- package/lib/Socket/index.js.map +0 -1
- package/lib/Socket/messages-recv.d.ts.map +0 -1
- package/lib/Socket/messages-recv.js.map +0 -1
- package/lib/Socket/messages-send.d.ts.map +0 -1
- package/lib/Socket/messages-send.js.map +0 -1
- package/lib/Socket/mex.d.ts.map +0 -1
- package/lib/Socket/mex.js.map +0 -1
- package/lib/Socket/newsletter.d.ts.map +0 -1
- package/lib/Socket/newsletter.js.map +0 -1
- package/lib/Socket/socket.d.ts.map +0 -1
- package/lib/Socket/socket.js.map +0 -1
- package/lib/Socket/usync.d.ts.map +0 -1
- package/lib/Socket/usync.js.map +0 -1
- package/lib/Types/Auth.d.ts.map +0 -1
- package/lib/Types/Auth.js.map +0 -1
- package/lib/Types/Call.d.ts.map +0 -1
- package/lib/Types/Call.js.map +0 -1
- package/lib/Types/Chat.d.ts.map +0 -1
- package/lib/Types/Chat.js.map +0 -1
- package/lib/Types/Contact.d.ts.map +0 -1
- package/lib/Types/Contact.js.map +0 -1
- package/lib/Types/Events.d.ts.map +0 -1
- package/lib/Types/Events.js.map +0 -1
- package/lib/Types/GroupMetadata.d.ts.map +0 -1
- package/lib/Types/GroupMetadata.js.map +0 -1
- package/lib/Types/Label.d.ts.map +0 -1
- package/lib/Types/Label.js.map +0 -1
- package/lib/Types/LabelAssociation.d.ts.map +0 -1
- package/lib/Types/LabelAssociation.js.map +0 -1
- package/lib/Types/Message.d.ts.map +0 -1
- package/lib/Types/Message.js.map +0 -1
- package/lib/Types/Newsletter.d.ts.map +0 -1
- package/lib/Types/Newsletter.js.map +0 -1
- package/lib/Types/Product.d.ts.map +0 -1
- package/lib/Types/Product.js.map +0 -1
- package/lib/Types/Signal.d.ts.map +0 -1
- package/lib/Types/Signal.js.map +0 -1
- package/lib/Types/Socket.d.ts.map +0 -1
- package/lib/Types/Socket.js.map +0 -1
- package/lib/Types/State.d.ts.map +0 -1
- package/lib/Types/State.js.map +0 -1
- package/lib/Types/USync.d.ts.map +0 -1
- package/lib/Types/USync.js.map +0 -1
- package/lib/Types/index.d.ts.map +0 -1
- package/lib/Types/index.js.map +0 -1
- package/lib/Utils/auth-utils.d.ts.map +0 -1
- package/lib/Utils/auth-utils.js.map +0 -1
- package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
- package/lib/Utils/baileys-event-stream.js.map +0 -1
- package/lib/Utils/business.d.ts.map +0 -1
- package/lib/Utils/business.js.map +0 -1
- package/lib/Utils/chat-utils.d.ts.map +0 -1
- package/lib/Utils/chat-utils.js.map +0 -1
- package/lib/Utils/crypto.d.ts.map +0 -1
- package/lib/Utils/crypto.js.map +0 -1
- package/lib/Utils/decode-wa-message.d.ts.map +0 -1
- package/lib/Utils/decode-wa-message.js.map +0 -1
- package/lib/Utils/event-buffer.d.ts.map +0 -1
- package/lib/Utils/event-buffer.js.map +0 -1
- package/lib/Utils/generics.d.ts.map +0 -1
- package/lib/Utils/generics.js.map +0 -1
- package/lib/Utils/history.d.ts.map +0 -1
- package/lib/Utils/history.js.map +0 -1
- package/lib/Utils/index.d.ts.map +0 -1
- package/lib/Utils/index.js.map +0 -1
- package/lib/Utils/link-preview.d.ts.map +0 -1
- package/lib/Utils/link-preview.js.map +0 -1
- package/lib/Utils/logger.d.ts.map +0 -1
- package/lib/Utils/logger.js.map +0 -1
- package/lib/Utils/lt-hash.d.ts.map +0 -1
- package/lib/Utils/lt-hash.js.map +0 -1
- package/lib/Utils/make-mutex.d.ts.map +0 -1
- package/lib/Utils/make-mutex.js.map +0 -1
- package/lib/Utils/messages-media.d.ts.map +0 -1
- package/lib/Utils/messages-media.js.map +0 -1
- package/lib/Utils/messages.d.ts.map +0 -1
- package/lib/Utils/messages.js.map +0 -1
- package/lib/Utils/noise-handler.d.ts.map +0 -1
- package/lib/Utils/noise-handler.js.map +0 -1
- package/lib/Utils/process-message.d.ts.map +0 -1
- package/lib/Utils/process-message.js.map +0 -1
- package/lib/Utils/signal.d.ts.map +0 -1
- package/lib/Utils/signal.js.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
- package/lib/Utils/validate-connection.d.ts.map +0 -1
- package/lib/Utils/validate-connection.js.map +0 -1
- package/lib/WABinary/constants.d.ts.map +0 -1
- package/lib/WABinary/constants.js.map +0 -1
- package/lib/WABinary/decode.d.ts.map +0 -1
- package/lib/WABinary/decode.js.map +0 -1
- package/lib/WABinary/encode.d.ts.map +0 -1
- package/lib/WABinary/encode.js.map +0 -1
- package/lib/WABinary/generic-utils.d.ts.map +0 -1
- package/lib/WABinary/generic-utils.js.map +0 -1
- package/lib/WABinary/index.d.ts.map +0 -1
- package/lib/WABinary/index.js.map +0 -1
- package/lib/WABinary/jid-utils.d.ts.map +0 -1
- package/lib/WABinary/jid-utils.js.map +0 -1
- package/lib/WABinary/types.d.ts.map +0 -1
- package/lib/WABinary/types.js.map +0 -1
- package/lib/WAM/BinaryInfo.d.ts.map +0 -1
- package/lib/WAM/BinaryInfo.js.map +0 -1
- package/lib/WAM/constants.d.ts.map +0 -1
- package/lib/WAM/constants.js.map +0 -1
- package/lib/WAM/encode.d.ts.map +0 -1
- package/lib/WAM/encode.js.map +0 -1
- package/lib/WAM/index.d.ts.map +0 -1
- package/lib/WAM/index.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/index.js.map +0 -1
- package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
- package/lib/WAUSync/USyncQuery.js.map +0 -1
- package/lib/WAUSync/USyncUser.d.ts.map +0 -1
- package/lib/WAUSync/USyncUser.js.map +0 -1
- package/lib/WAUSync/index.d.ts.map +0 -1
- package/lib/WAUSync/index.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderKeyMessage = void 0;
|
|
4
|
+
const curve_1 = require("libsignal/src/curve");
|
|
5
|
+
const WAProto_1 = require("../../../WAProto");
|
|
6
|
+
const ciphertext_message_1 = require("./ciphertext-message");
|
|
7
|
+
class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
6
8
|
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
7
9
|
super();
|
|
8
10
|
this.SIGNATURE_LENGTH = 64;
|
|
@@ -10,7 +12,7 @@ export class SenderKeyMessage extends CiphertextMessage {
|
|
|
10
12
|
const version = serialized[0];
|
|
11
13
|
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
|
|
12
14
|
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
13
|
-
const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON();
|
|
15
|
+
const senderKeyMessage = WAProto_1.proto.SenderKeyMessage.decode(message).toJSON();
|
|
14
16
|
this.serialized = serialized;
|
|
15
17
|
this.messageVersion = (version & 0xff) >> 4;
|
|
16
18
|
this.keyId = senderKeyMessage.id;
|
|
@@ -24,7 +26,7 @@ export class SenderKeyMessage extends CiphertextMessage {
|
|
|
24
26
|
else {
|
|
25
27
|
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256;
|
|
26
28
|
const ciphertextBuffer = Buffer.from(ciphertext);
|
|
27
|
-
const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
|
|
29
|
+
const message = WAProto_1.proto.SenderKeyMessage.encode(WAProto_1.proto.SenderKeyMessage.create({
|
|
28
30
|
id: keyId,
|
|
29
31
|
iteration: iteration,
|
|
30
32
|
ciphertext: ciphertextBuffer
|
|
@@ -50,12 +52,12 @@ export class SenderKeyMessage extends CiphertextMessage {
|
|
|
50
52
|
verifySignature(signatureKey) {
|
|
51
53
|
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
|
|
52
54
|
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
53
|
-
const res = verifySignature(signatureKey, part1, part2);
|
|
55
|
+
const res = (0, curve_1.verifySignature)(signatureKey, part1, part2);
|
|
54
56
|
if (!res)
|
|
55
57
|
throw new Error('Invalid signature!');
|
|
56
58
|
}
|
|
57
59
|
getSignature(signatureKey, serialized) {
|
|
58
|
-
return Buffer.from(calculateSignature(signatureKey, serialized));
|
|
60
|
+
return Buffer.from((0, curve_1.calculateSignature)(signatureKey, serialized));
|
|
59
61
|
}
|
|
60
62
|
serialize() {
|
|
61
63
|
return this.serialized;
|
|
@@ -64,4 +66,4 @@ export class SenderKeyMessage extends CiphertextMessage {
|
|
|
64
66
|
return 4;
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
|
-
|
|
69
|
+
exports.SenderKeyMessage = SenderKeyMessage;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderKeyName = void 0;
|
|
1
4
|
function isNull(str) {
|
|
2
5
|
return str === null || str === '';
|
|
3
6
|
}
|
|
@@ -19,7 +22,7 @@ function hashCode(strKey) {
|
|
|
19
22
|
}
|
|
20
23
|
return hash;
|
|
21
24
|
}
|
|
22
|
-
|
|
25
|
+
class SenderKeyName {
|
|
23
26
|
constructor(groupId, sender) {
|
|
24
27
|
this.groupId = groupId;
|
|
25
28
|
this.sender = sender;
|
|
@@ -45,4 +48,4 @@ export class SenderKeyName {
|
|
|
45
48
|
return hashCode(this.groupId) ^ hashCode(this.sender.toString());
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
|
-
|
|
51
|
+
exports.SenderKeyName = SenderKeyName;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SenderKeyState } from './sender-key-state
|
|
1
|
+
import { SenderKeyState } from './sender-key-state';
|
|
2
2
|
export interface SenderKeyStateStructure {
|
|
3
3
|
senderKeyId: number;
|
|
4
4
|
senderChainKey: {
|
|
@@ -28,4 +28,3 @@ export declare class SenderKeyRecord {
|
|
|
28
28
|
serialize(): SenderKeyStateStructure[];
|
|
29
29
|
static deserialize(data: Uint8Array | string | SenderKeyStateStructure[]): SenderKeyRecord;
|
|
30
30
|
}
|
|
31
|
-
//# sourceMappingURL=sender-key-record.d.ts.map
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderKeyRecord = void 0;
|
|
4
|
+
const generics_1 = require("../../Utils/generics");
|
|
5
|
+
const sender_key_state_1 = require("./sender-key-state");
|
|
6
|
+
class SenderKeyRecord {
|
|
4
7
|
constructor(serialized) {
|
|
5
8
|
this.MAX_STATES = 5;
|
|
6
9
|
this.senderKeyStates = [];
|
|
7
10
|
if (serialized) {
|
|
8
11
|
for (const structure of serialized) {
|
|
9
|
-
this.senderKeyStates.push(new SenderKeyState(null, null, null, null, null, null, structure));
|
|
12
|
+
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(null, null, null, null, null, null, structure));
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
15
|
}
|
|
@@ -20,14 +23,14 @@ export class SenderKeyRecord {
|
|
|
20
23
|
return this.senderKeyStates.find(state => state.getKeyId() === keyId);
|
|
21
24
|
}
|
|
22
25
|
addSenderKeyState(id, iteration, chainKey, signatureKey) {
|
|
23
|
-
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, null, signatureKey));
|
|
26
|
+
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, null, signatureKey));
|
|
24
27
|
if (this.senderKeyStates.length > this.MAX_STATES) {
|
|
25
28
|
this.senderKeyStates.shift();
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
setSenderKeyState(id, iteration, chainKey, keyPair) {
|
|
29
32
|
this.senderKeyStates.length = 0;
|
|
30
|
-
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, keyPair));
|
|
33
|
+
this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, keyPair));
|
|
31
34
|
}
|
|
32
35
|
serialize() {
|
|
33
36
|
return this.senderKeyStates.map(state => state.getStructure());
|
|
@@ -35,11 +38,11 @@ export class SenderKeyRecord {
|
|
|
35
38
|
static deserialize(data) {
|
|
36
39
|
let parsed;
|
|
37
40
|
if (typeof data === 'string') {
|
|
38
|
-
parsed = JSON.parse(data, BufferJSON.reviver);
|
|
41
|
+
parsed = JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
39
42
|
}
|
|
40
43
|
else if (data instanceof Uint8Array) {
|
|
41
44
|
const str = Buffer.from(data).toString('utf-8');
|
|
42
|
-
parsed = JSON.parse(str, BufferJSON.reviver);
|
|
45
|
+
parsed = JSON.parse(str, generics_1.BufferJSON.reviver);
|
|
43
46
|
}
|
|
44
47
|
else {
|
|
45
48
|
parsed = data;
|
|
@@ -47,4 +50,4 @@ export class SenderKeyRecord {
|
|
|
47
50
|
return new SenderKeyRecord(parsed);
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
|
-
|
|
53
|
+
exports.SenderKeyRecord = SenderKeyRecord;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SenderChainKey } from './sender-chain-key
|
|
2
|
-
import { SenderMessageKey } from './sender-message-key
|
|
1
|
+
import { SenderChainKey } from './sender-chain-key';
|
|
2
|
+
import { SenderMessageKey } from './sender-message-key';
|
|
3
3
|
interface SenderChainKeyStructure {
|
|
4
4
|
iteration: number;
|
|
5
5
|
seed: Uint8Array;
|
|
@@ -36,4 +36,3 @@ export declare class SenderKeyState {
|
|
|
36
36
|
getStructure(): SenderKeyStateStructure;
|
|
37
37
|
}
|
|
38
38
|
export {};
|
|
39
|
-
//# sourceMappingURL=sender-key-state.d.ts.map
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderKeyState = void 0;
|
|
4
|
+
const sender_chain_key_1 = require("./sender-chain-key");
|
|
5
|
+
const sender_message_key_1 = require("./sender-message-key");
|
|
6
|
+
class SenderKeyState {
|
|
4
7
|
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
5
8
|
this.MAX_MESSAGE_KEYS = 2000;
|
|
6
9
|
if (senderKeyStateStructure) {
|
|
@@ -37,7 +40,7 @@ export class SenderKeyState {
|
|
|
37
40
|
return this.senderKeyStateStructure.senderKeyId;
|
|
38
41
|
}
|
|
39
42
|
getSenderChainKey() {
|
|
40
|
-
return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
|
|
43
|
+
return new sender_chain_key_1.SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
|
|
41
44
|
}
|
|
42
45
|
setSenderChainKey(chainKey) {
|
|
43
46
|
this.senderKeyStateStructure.senderChainKey = {
|
|
@@ -85,7 +88,7 @@ export class SenderKeyState {
|
|
|
85
88
|
if (index !== -1) {
|
|
86
89
|
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
|
|
87
90
|
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
|
|
88
|
-
return new SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
91
|
+
return new sender_message_key_1.SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
89
92
|
}
|
|
90
93
|
return null;
|
|
91
94
|
}
|
|
@@ -93,4 +96,4 @@ export class SenderKeyState {
|
|
|
93
96
|
return this.senderKeyStateStructure;
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
|
-
|
|
99
|
+
exports.SenderKeyState = SenderKeyState;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderMessageKey = void 0;
|
|
4
|
+
const crypto_1 = require("libsignal/src/crypto");
|
|
5
|
+
class SenderMessageKey {
|
|
4
6
|
constructor(iteration, seed) {
|
|
5
|
-
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
7
|
+
const derivative = (0, crypto_1.deriveSecrets)(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
6
8
|
const keys = new Uint8Array(32);
|
|
7
9
|
keys.set(new Uint8Array(derivative[0].slice(16)));
|
|
8
10
|
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
@@ -24,4 +26,4 @@ export class SenderMessageKey {
|
|
|
24
26
|
return this.seed;
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
|
-
|
|
29
|
+
exports.SenderMessageKey = SenderMessageKey;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { SignalAuthState } from '../Types';
|
|
2
|
+
import { SignalRepository } from '../Types/Signal';
|
|
3
3
|
export declare function makeLibSignalRepository(auth: SignalAuthState): SignalRepository;
|
|
4
|
-
//# sourceMappingURL=libsignal.d.ts.map
|
package/lib/Signal/libsignal.js
CHANGED
|
@@ -1,29 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.makeLibSignalRepository = makeLibSignalRepository;
|
|
37
|
+
const libsignal = __importStar(require("libsignal"));
|
|
38
|
+
const Utils_1 = require("../Utils");
|
|
39
|
+
const WABinary_1 = require("../WABinary");
|
|
40
|
+
const sender_key_name_1 = require("./Group/sender-key-name");
|
|
41
|
+
const sender_key_record_1 = require("./Group/sender-key-record");
|
|
42
|
+
const Group_1 = require("./Group");
|
|
43
|
+
function makeLibSignalRepository(auth) {
|
|
9
44
|
const storage = signalStorage(auth);
|
|
10
45
|
return {
|
|
11
46
|
decryptGroupMessage({ group, authorJid, msg }) {
|
|
12
47
|
const senderName = jidToSignalSenderKeyName(group, authorJid);
|
|
13
|
-
const cipher = new GroupCipher(storage, senderName);
|
|
48
|
+
const cipher = new Group_1.GroupCipher(storage, senderName);
|
|
14
49
|
return cipher.decrypt(msg);
|
|
15
50
|
},
|
|
16
51
|
async processSenderKeyDistributionMessage({ item, authorJid }) {
|
|
17
|
-
const builder = new GroupSessionBuilder(storage);
|
|
52
|
+
const builder = new Group_1.GroupSessionBuilder(storage);
|
|
18
53
|
if (!item.groupId) {
|
|
19
54
|
throw new Error('Group ID is required for sender key distribution message');
|
|
20
55
|
}
|
|
21
56
|
const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
|
|
22
|
-
const senderMsg = new SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
|
|
57
|
+
const senderMsg = new Group_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
|
|
23
58
|
const senderNameStr = senderName.toString();
|
|
24
59
|
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
25
60
|
if (!senderKey) {
|
|
26
|
-
await storage.storeSenderKey(senderName, new SenderKeyRecord());
|
|
61
|
+
await storage.storeSenderKey(senderName, new sender_key_record_1.SenderKeyRecord());
|
|
27
62
|
}
|
|
28
63
|
await builder.process(senderName, senderMsg);
|
|
29
64
|
},
|
|
@@ -52,14 +87,14 @@ export function makeLibSignalRepository(auth) {
|
|
|
52
87
|
},
|
|
53
88
|
async encryptGroupMessage({ group, meId, data }) {
|
|
54
89
|
const senderName = jidToSignalSenderKeyName(group, meId);
|
|
55
|
-
const builder = new GroupSessionBuilder(storage);
|
|
90
|
+
const builder = new Group_1.GroupSessionBuilder(storage);
|
|
56
91
|
const senderNameStr = senderName.toString();
|
|
57
92
|
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
58
93
|
if (!senderKey) {
|
|
59
|
-
await storage.storeSenderKey(senderName, new SenderKeyRecord());
|
|
94
|
+
await storage.storeSenderKey(senderName, new sender_key_record_1.SenderKeyRecord());
|
|
60
95
|
}
|
|
61
96
|
const senderKeyDistributionMessage = await builder.create(senderName);
|
|
62
|
-
const session = new GroupCipher(storage, senderName);
|
|
97
|
+
const session = new Group_1.GroupCipher(storage, senderName);
|
|
63
98
|
const ciphertext = await session.encrypt(data);
|
|
64
99
|
return {
|
|
65
100
|
ciphertext,
|
|
@@ -76,11 +111,11 @@ export function makeLibSignalRepository(auth) {
|
|
|
76
111
|
};
|
|
77
112
|
}
|
|
78
113
|
const jidToSignalProtocolAddress = (jid) => {
|
|
79
|
-
const { user, device } = jidDecode(jid);
|
|
114
|
+
const { user, device } = (0, WABinary_1.jidDecode)(jid);
|
|
80
115
|
return new libsignal.ProtocolAddress(user, device || 0);
|
|
81
116
|
};
|
|
82
117
|
const jidToSignalSenderKeyName = (group, user) => {
|
|
83
|
-
return new SenderKeyName(group, jidToSignalProtocolAddress(user));
|
|
118
|
+
return new sender_key_name_1.SenderKeyName(group, jidToSignalProtocolAddress(user));
|
|
84
119
|
};
|
|
85
120
|
function signalStorage({ creds, keys }) {
|
|
86
121
|
return {
|
|
@@ -90,7 +125,6 @@ function signalStorage({ creds, keys }) {
|
|
|
90
125
|
return libsignal.SessionRecord.deserialize(sess);
|
|
91
126
|
}
|
|
92
127
|
},
|
|
93
|
-
// TODO: Replace with libsignal.SessionRecord when type exports are added to libsignal
|
|
94
128
|
storeSession: async (id, session) => {
|
|
95
129
|
await keys.set({ session: { [id]: session.serialize() } });
|
|
96
130
|
},
|
|
@@ -119,9 +153,9 @@ function signalStorage({ creds, keys }) {
|
|
|
119
153
|
const keyId = senderKeyName.toString();
|
|
120
154
|
const { [keyId]: key } = await keys.get('sender-key', [keyId]);
|
|
121
155
|
if (key) {
|
|
122
|
-
return SenderKeyRecord.deserialize(key);
|
|
156
|
+
return sender_key_record_1.SenderKeyRecord.deserialize(key);
|
|
123
157
|
}
|
|
124
|
-
return new SenderKeyRecord();
|
|
158
|
+
return new sender_key_record_1.SenderKeyRecord();
|
|
125
159
|
},
|
|
126
160
|
storeSenderKey: async (senderKeyName, key) => {
|
|
127
161
|
const keyId = senderKeyName.toString();
|
|
@@ -133,9 +167,8 @@ function signalStorage({ creds, keys }) {
|
|
|
133
167
|
const { signedIdentityKey } = creds;
|
|
134
168
|
return {
|
|
135
169
|
privKey: Buffer.from(signedIdentityKey.private),
|
|
136
|
-
pubKey: generateSignalPubKey(signedIdentityKey.public)
|
|
170
|
+
pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public)
|
|
137
171
|
};
|
|
138
172
|
}
|
|
139
173
|
};
|
|
140
174
|
}
|
|
141
|
-
//# sourceMappingURL=libsignal.js.map
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from './types
|
|
2
|
-
export * from './websocket
|
|
3
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './websocket';
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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("./types"), exports);
|
|
18
|
+
__exportStar(require("./websocket"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import { URL } from 'url';
|
|
3
|
-
import
|
|
3
|
+
import { SocketConfig } from '../../Types';
|
|
4
4
|
export declare abstract class AbstractSocketClient extends EventEmitter {
|
|
5
5
|
url: URL;
|
|
6
6
|
config: SocketConfig;
|
|
@@ -13,4 +13,3 @@ export declare abstract class AbstractSocketClient extends EventEmitter {
|
|
|
13
13
|
abstract close(): Promise<void>;
|
|
14
14
|
abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
|
|
15
15
|
}
|
|
16
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractSocketClient = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
class AbstractSocketClient extends events_1.EventEmitter {
|
|
4
6
|
constructor(url, config) {
|
|
5
7
|
super();
|
|
6
8
|
this.url = url;
|
|
@@ -8,4 +10,4 @@ export class AbstractSocketClient extends EventEmitter {
|
|
|
8
10
|
this.setMaxListeners(0);
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
|
-
|
|
13
|
+
exports.AbstractSocketClient = AbstractSocketClient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import WebSocket from '@d0v3riz/ws';
|
|
2
|
-
import { AbstractSocketClient } from './types
|
|
2
|
+
import { AbstractSocketClient } from './types';
|
|
3
3
|
export declare class WebSocketClient extends AbstractSocketClient {
|
|
4
4
|
protected socket: WebSocket | null;
|
|
5
5
|
get isOpen(): boolean;
|
|
@@ -10,4 +10,3 @@ export declare class WebSocketClient extends AbstractSocketClient {
|
|
|
10
10
|
close(): Promise<void>;
|
|
11
11
|
send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean;
|
|
12
12
|
}
|
|
13
|
-
//# sourceMappingURL=websocket.d.ts.map
|
|
@@ -1,30 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WebSocketClient = void 0;
|
|
7
|
+
const ws_1 = __importDefault(require("@d0v3riz/ws"));
|
|
8
|
+
const Defaults_1 = require("../../Defaults");
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
class WebSocketClient extends types_1.AbstractSocketClient {
|
|
5
11
|
constructor() {
|
|
6
12
|
super(...arguments);
|
|
7
13
|
this.socket = null;
|
|
8
14
|
}
|
|
9
15
|
get isOpen() {
|
|
10
|
-
|
|
16
|
+
var _a;
|
|
17
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN;
|
|
11
18
|
}
|
|
12
19
|
get isClosed() {
|
|
13
|
-
|
|
20
|
+
var _a;
|
|
21
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSED;
|
|
14
22
|
}
|
|
15
23
|
get isClosing() {
|
|
16
|
-
|
|
24
|
+
var _a;
|
|
25
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING;
|
|
17
26
|
}
|
|
18
27
|
get isConnecting() {
|
|
19
|
-
|
|
28
|
+
var _a;
|
|
29
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CONNECTING;
|
|
20
30
|
}
|
|
21
31
|
async connect() {
|
|
32
|
+
var _a, _b;
|
|
22
33
|
if (this.socket) {
|
|
23
34
|
return;
|
|
24
35
|
}
|
|
25
|
-
this.socket = new
|
|
26
|
-
origin: DEFAULT_ORIGIN,
|
|
27
|
-
headers: this.config.options
|
|
36
|
+
this.socket = new ws_1.default(this.url, {
|
|
37
|
+
origin: Defaults_1.DEFAULT_ORIGIN,
|
|
38
|
+
headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
|
|
28
39
|
handshakeTimeout: this.config.connectTimeoutMs,
|
|
29
40
|
timeout: this.config.connectTimeoutMs,
|
|
30
41
|
agent: this.config.agent
|
|
@@ -32,7 +43,7 @@ export class WebSocketClient extends AbstractSocketClient {
|
|
|
32
43
|
this.socket.setMaxListeners(0);
|
|
33
44
|
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
|
34
45
|
for (const event of events) {
|
|
35
|
-
this.socket
|
|
46
|
+
(_b = this.socket) === null || _b === void 0 ? void 0 : _b.on(event, (...args) => this.emit(event, ...args));
|
|
36
47
|
}
|
|
37
48
|
}
|
|
38
49
|
async close() {
|
|
@@ -43,8 +54,9 @@ export class WebSocketClient extends AbstractSocketClient {
|
|
|
43
54
|
this.socket = null;
|
|
44
55
|
}
|
|
45
56
|
send(str, cb) {
|
|
46
|
-
|
|
57
|
+
var _a;
|
|
58
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
|
|
47
59
|
return Boolean(this.socket);
|
|
48
60
|
}
|
|
49
61
|
}
|
|
50
|
-
|
|
62
|
+
exports.WebSocketClient = WebSocketClient;
|