dcodeindra-baileyspro 2.3.9
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 +2534 -0
- package/WAProto/Adv/Adv.d.ts +518 -0
- package/WAProto/Adv/Adv.js +1734 -0
- package/WAProto/Adv/Adv.proto +36 -0
- package/WAProto/BotMetadata/BotMetadata.d.ts +5745 -0
- package/WAProto/BotMetadata/BotMetadata.js +16291 -0
- package/WAProto/BotMetadata/BotMetadata.proto +463 -0
- package/WAProto/Cert/Cert.d.ts +497 -0
- package/WAProto/Cert/Cert.js +1503 -0
- package/WAProto/Cert/Cert.proto +28 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +391 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.js +1155 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.proto +7 -0
- package/WAProto/CompanionReg/CompanionReg.d.ts +1055 -0
- package/WAProto/CompanionReg/CompanionReg.js +3532 -0
- package/WAProto/CompanionReg/CompanionReg.proto +89 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +187 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.js +520 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +14 -0
- package/WAProto/E2E/E2E.d.ts +28417 -0
- package/WAProto/E2E/E2E.js +98438 -0
- package/WAProto/E2E/E2E.proto +2289 -0
- package/WAProto/Ephemeral/Ephemeral.d.ts +95 -0
- package/WAProto/Ephemeral/Ephemeral.js +269 -0
- package/WAProto/Ephemeral/Ephemeral.proto +6 -0
- package/WAProto/HistorySync/HistorySync.d.ts +40728 -0
- package/WAProto/HistorySync/HistorySync.js +142980 -0
- package/WAProto/HistorySync/HistorySync.proto +207 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +189 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +585 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +11 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +461 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +1559 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +37 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +29294 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +101732 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +76 -0
- package/WAProto/MmsRetry/MmsRetry.d.ts +200 -0
- package/WAProto/MmsRetry/MmsRetry.js +586 -0
- package/WAProto/MmsRetry/MmsRetry.proto +17 -0
- package/WAProto/Protocol/Protocol.d.ts +218 -0
- package/WAProto/Protocol/Protocol.js +701 -0
- package/WAProto/Protocol/Protocol.proto +20 -0
- package/WAProto/Reporting/Reporting.d.ts +301 -0
- package/WAProto/Reporting/Reporting.js +989 -0
- package/WAProto/Reporting/Reporting.proto +19 -0
- package/WAProto/ServerSync/ServerSync.d.ts +1050 -0
- package/WAProto/ServerSync/ServerSync.js +3176 -0
- package/WAProto/ServerSync/ServerSync.proto +59 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +1507 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +4756 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +88 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +617 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1940 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +38 -0
- package/WAProto/StatusAttributions/StatusAttributions.d.ts +636 -0
- package/WAProto/StatusAttributions/StatusAttributions.js +2037 -0
- package/WAProto/StatusAttributions/StatusAttributions.proto +61 -0
- package/WAProto/SyncAction/SyncAction.d.ts +7227 -0
- package/WAProto/SyncAction/SyncAction.js +22271 -0
- package/WAProto/SyncAction/SyncAction.proto +423 -0
- package/WAProto/UserPassword/UserPassword.d.ts +298 -0
- package/WAProto/UserPassword/UserPassword.js +898 -0
- package/WAProto/UserPassword/UserPassword.proto +27 -0
- package/WAProto/VnameCert/VnameCert.d.ts +658 -0
- package/WAProto/VnameCert/VnameCert.js +2225 -0
- package/WAProto/VnameCert/VnameCert.proto +60 -0
- package/WAProto/Wa6/Wa6.d.ts +1613 -0
- package/WAProto/Wa6/Wa6.js +6299 -0
- package/WAProto/Wa6/Wa6.proto +229 -0
- package/WAProto/Web/Web.d.ts +31718 -0
- package/WAProto/Web/Web.js +113402 -0
- package/WAProto/Web/Web.proto +545 -0
- package/WAProto/index.d.ts +49 -0
- package/WAProto/index.js +28 -0
- package/WASignalGroup/GroupProtocol.js +1771 -0
- package/WASignalGroup/ciphertext_message.js +10 -0
- package/WASignalGroup/group_cipher.js +103 -0
- package/WASignalGroup/group_session_builder.js +39 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +17 -0
- package/WASignalGroup/protobufs.js +2 -0
- package/WASignalGroup/queue_job.js +64 -0
- package/WASignalGroup/sender_chain_key.js +38 -0
- package/WASignalGroup/sender_key_distribution_message.js +68 -0
- package/WASignalGroup/sender_key_message.js +79 -0
- package/WASignalGroup/sender_key_name.js +59 -0
- package/WASignalGroup/sender_key_record.js +47 -0
- package/WASignalGroup/sender_key_state.js +110 -0
- package/WASignalGroup/sender_message_key.js +30 -0
- package/check-node-version.js +10 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +51 -0
- package/lib/Defaults/index.js +108 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +19 -0
- package/lib/Signal/Group/group-session-builder.d.ts +17 -0
- package/lib/Signal/Group/group-session-builder.js +72 -0
- package/lib/Signal/Group/group_cipher.d.ts +19 -0
- package/lib/Signal/Group/group_cipher.js +99 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +61 -0
- package/lib/Signal/Group/keyhelper.d.ts +16 -0
- package/lib/Signal/Group/keyhelper.js +66 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +64 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +39 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +73 -0
- package/lib/Signal/Group/sender-key-name.d.ts +19 -0
- package/lib/Signal/Group/sender-key-name.js +59 -0
- package/lib/Signal/Group/sender-key-record.d.ts +32 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-record.ts +77 -0
- package/lib/Signal/Group/sender-key-state.d.ts +44 -0
- package/lib/Signal/Group/sender-key-state.js +104 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +33 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +153 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +18 -0
- package/lib/Socket/Client/types.d.ts +15 -0
- package/lib/Socket/Client/types.js +14 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +57 -0
- package/lib/Socket/business.d.ts +181 -0
- package/lib/Socket/business.js +259 -0
- package/lib/Socket/chats.d.ts +95 -0
- package/lib/Socket/chats.js +906 -0
- package/lib/Socket/community.d.ts +131 -0
- package/lib/Socket/community.js +369 -0
- package/lib/Socket/groups.d.ts +122 -0
- package/lib/Socket/groups.js +360 -0
- package/lib/Socket/index.d.ts +183 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.d.ts +170 -0
- package/lib/Socket/messages-recv.js +1074 -0
- package/lib/Socket/messages-send.d.ts +161 -0
- package/lib/Socket/messages-send.js +982 -0
- package/lib/Socket/newsletter.d.ts +140 -0
- package/lib/Socket/newsletter.js +242 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/socket.js +749 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +71 -0
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +20 -0
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +77 -0
- package/lib/Store/make-in-memory-store.d.ts +117 -0
- package/lib/Store/make-in-memory-store.js +420 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +83 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +28 -0
- package/lib/Types/Auth.d.ts +103 -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 +115 -0
- package/lib/Types/Chat.js +6 -0
- package/lib/Types/Contact.d.ts +35 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +208 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +81 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +46 -0
- package/lib/Types/Label.js +28 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +10 -0
- package/lib/Types/Message.d.ts +480 -0
- package/lib/Types/Message.js +9 -0
- package/lib/Types/MexUpdates.d.ts +9 -0
- package/lib/Types/MexUpdates.js +18 -0
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Newsletter.js +33 -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 +70 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +198 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +64 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +243 -0
- package/lib/Utils/chat-utils.d.ts +72 -0
- package/lib/Utils/chat-utils.js +762 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +150 -0
- package/lib/Utils/decode-wa-message.d.ts +252 -0
- package/lib/Utils/decode-wa-message.js +232 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +539 -0
- package/lib/Utils/generics.d.ts +96 -0
- package/lib/Utils/generics.js +553 -0
- package/lib/Utils/history.d.ts +29 -0
- package/lib/Utils/history.js +109 -0
- package/lib/Utils/index.d.ts +19 -0
- package/lib/Utils/index.js +35 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +112 -0
- package/lib/Utils/logger.d.ts +11 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +53 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +45 -0
- package/lib/Utils/messages-media.d.ts +104 -0
- package/lib/Utils/messages-media.js +751 -0
- package/lib/Utils/messages.d.ts +80 -0
- package/lib/Utils/messages.js +1741 -0
- package/lib/Utils/noise-handler.d.ts +19 -0
- package/lib/Utils/noise-handler.js +150 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +391 -0
- package/lib/Utils/signal.d.ts +33 -0
- package/lib/Utils/signal.js +154 -0
- package/lib/Utils/use-mongo-file-auth-state.d.ts +5 -0
- package/lib/Utils/use-mongo-file-auth-state.js +75 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-multi-file-auth-state.js +123 -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 +10 -0
- package/lib/Utils/validate-connection.js +174 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/constants.js +45 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/decode.js +255 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +243 -0
- package/lib/WABinary/generic-utils.d.ts +16 -0
- package/lib/WABinary/generic-utils.js +125 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.d.ts +34 -0
- package/lib/WABinary/jid-utils.js +73 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +16 -0
- package/lib/WAM/BinaryInfo.js +14 -0
- package/lib/WAM/constants.d.ts +39 -0
- package/lib/WAM/constants.js +15362 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +156 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +60 -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 +58 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +22 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +88 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +27 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +45 -0
- package/package.json +63 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { proto } from '../../WAProto'
|
|
2
|
+
import type { MediaType, SocketConfig } from '../Types'
|
|
3
|
+
export declare const UNAUTHORIZED_CODES: number[]
|
|
4
|
+
export declare const PHONENUMBER_MCC: Record<string, number>
|
|
5
|
+
export declare const DEFAULT_ORIGIN: "https://web.whatsapp.com"
|
|
6
|
+
export declare const DEF_CALLBACK_PREFIX: "CB:"
|
|
7
|
+
export declare const DEF_TAG_PREFIX: "TAG:"
|
|
8
|
+
export declare const PHONE_CONNECTION_CB: "CB:Pong"
|
|
9
|
+
export declare const WA_DEFAULT_EPHEMERAL: number
|
|
10
|
+
export declare const NOISE_MODE: "Noise_XX_25519_AESGCM_SHA256\0\0\0\0"
|
|
11
|
+
export declare const DICT_VERSION: 2
|
|
12
|
+
export declare const KEY_BUNDLE_TYPE: Buffer
|
|
13
|
+
export declare const NOISE_WA_HEADER: Buffer
|
|
14
|
+
export declare const URL_REGEX: RegExp
|
|
15
|
+
export declare const WA_CERT_DETAILS: {
|
|
16
|
+
SERIAL: number
|
|
17
|
+
}
|
|
18
|
+
export declare const PROCESSABLE_HISTORY_TYPES: proto.Message.HistorySyncNotification.HistorySyncType[]
|
|
19
|
+
export declare const DEFAULT_CONNECTION_CONFIG: SocketConfig
|
|
20
|
+
export declare const MEDIA_PATH_MAP: {
|
|
21
|
+
[T in MediaType]?: string
|
|
22
|
+
}
|
|
23
|
+
export declare const MEDIA_HKDF_KEY_MAPPING: {
|
|
24
|
+
'audio': string
|
|
25
|
+
'document': string
|
|
26
|
+
'gif': string
|
|
27
|
+
'image': string
|
|
28
|
+
'ppic': string
|
|
29
|
+
'product': string
|
|
30
|
+
'ptt': string
|
|
31
|
+
'sticker': string
|
|
32
|
+
'video': string
|
|
33
|
+
'thumbnail-document': string
|
|
34
|
+
'thumbnail-image': string
|
|
35
|
+
'thumbnail-video': string
|
|
36
|
+
'thumbnail-link': string
|
|
37
|
+
'md-msg-hist': string
|
|
38
|
+
'md-app-state': string
|
|
39
|
+
'product-catalog-image': string
|
|
40
|
+
'payment-bg-image': string
|
|
41
|
+
'ptv': string
|
|
42
|
+
}
|
|
43
|
+
export declare const MEDIA_KEYS: (keyof typeof MEDIA_HKDF_KEY_MAPPING)[]
|
|
44
|
+
export declare const MIN_PREKEY_COUNT: 5
|
|
45
|
+
export declare const INITIAL_PREKEY_COUNT: 30
|
|
46
|
+
export declare const DEFAULT_CACHE_TTLS: {
|
|
47
|
+
SIGNAL_STORE: number
|
|
48
|
+
MSG_RETRY: number
|
|
49
|
+
CALL_OFFER: number
|
|
50
|
+
USER_DEVICES: number
|
|
51
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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.DEFAULT_CACHE_TTLS = exports.INITIAL_PREKEY_COUNT = exports.MIN_PREKEY_COUNT = exports.MEDIA_KEYS = exports.MEDIA_HKDF_KEY_MAPPING = exports.MEDIA_PATH_MAP = exports.DEFAULT_CONNECTION_CONFIG = exports.PROCESSABLE_HISTORY_TYPES = exports.WA_CERT_DETAILS = exports.URL_REGEX = exports.NOISE_WA_HEADER = exports.KEY_BUNDLE_TYPE = exports.DICT_VERSION = exports.NOISE_MODE = exports.WA_DEFAULT_EPHEMERAL = exports.PHONE_CONNECTION_CB = exports.DEF_TAG_PREFIX = exports.DEF_CALLBACK_PREFIX = exports.DEFAULT_ORIGIN = exports.UNAUTHORIZED_CODES = null
|
|
7
|
+
const WAProto_1 = require("../../WAProto");
|
|
8
|
+
const libsignal_1 = require("../Signal/libsignal");
|
|
9
|
+
const Utils_1 = require("../Utils");
|
|
10
|
+
const logger_1 = __importDefault(require("../Utils/logger"));
|
|
11
|
+
const baileys_version_json_1 = require("./baileys-version.json");
|
|
12
|
+
const phonenumber_mcc_json_1 = __importDefault(require("./phonenumber-mcc.json"))
|
|
13
|
+
exports.UNAUTHORIZED_CODES = [401, 403, 419]
|
|
14
|
+
exports.PHONENUMBER_MCC = phonenumber_mcc_json_1.default
|
|
15
|
+
exports.DEFAULT_ORIGIN = 'https://web.whatsapp.com'
|
|
16
|
+
exports.DEF_CALLBACK_PREFIX = 'CB:'
|
|
17
|
+
exports.DEF_TAG_PREFIX = 'TAG:'
|
|
18
|
+
exports.PHONE_CONNECTION_CB = 'CB:Pong'
|
|
19
|
+
exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60
|
|
20
|
+
exports.NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0'
|
|
21
|
+
exports.DICT_VERSION = 2
|
|
22
|
+
exports.KEY_BUNDLE_TYPE = Buffer.from([5])
|
|
23
|
+
exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]) // last is "DICT_VERSION"
|
|
24
|
+
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
25
|
+
exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g
|
|
26
|
+
exports.WA_CERT_DETAILS = {
|
|
27
|
+
SERIAL: 0,
|
|
28
|
+
}
|
|
29
|
+
exports.PROCESSABLE_HISTORY_TYPES = [
|
|
30
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
31
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
|
|
32
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
|
|
33
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
|
|
34
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND,
|
|
35
|
+
]
|
|
36
|
+
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
37
|
+
version: baileys_version_json_1.version,
|
|
38
|
+
browser: Utils_1.Browsers.ubuntu('Chrome'),
|
|
39
|
+
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
40
|
+
connectTimeoutMs: 20000,
|
|
41
|
+
keepAliveIntervalMs: 30000,
|
|
42
|
+
logger: logger_1.default.child({ class: 'baileys' }),
|
|
43
|
+
printQRInTerminal: false,
|
|
44
|
+
emitOwnEvents: true,
|
|
45
|
+
defaultQueryTimeoutMs: 60000,
|
|
46
|
+
customUploadHosts: [],
|
|
47
|
+
retryRequestDelayMs: 250,
|
|
48
|
+
maxMsgRetryCount: 5,
|
|
49
|
+
fireInitQueries: true,
|
|
50
|
+
auth: undefined,
|
|
51
|
+
markOnlineOnConnect: true,
|
|
52
|
+
syncFullHistory: false,
|
|
53
|
+
patchMessageBeforeSending: msg => msg,
|
|
54
|
+
shouldSyncHistoryMessage: () => true,
|
|
55
|
+
shouldIgnoreJid: () => false,
|
|
56
|
+
linkPreviewImageThumbnailWidth: 192,
|
|
57
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
58
|
+
generateHighQualityLinkPreview: false,
|
|
59
|
+
options: {},
|
|
60
|
+
appStateMacVerification: {
|
|
61
|
+
patch: false,
|
|
62
|
+
snapshot: false,
|
|
63
|
+
},
|
|
64
|
+
countryCode: 'US',
|
|
65
|
+
getMessage: async () => undefined,
|
|
66
|
+
cachedGroupMetadata: async () => undefined,
|
|
67
|
+
makeSignalRepository: libsignal_1.makeLibSignalRepository
|
|
68
|
+
}
|
|
69
|
+
exports.MEDIA_PATH_MAP = {
|
|
70
|
+
image: '/mms/image',
|
|
71
|
+
video: '/mms/video',
|
|
72
|
+
document: '/mms/document',
|
|
73
|
+
audio: '/mms/audio',
|
|
74
|
+
sticker: '/mms/image',
|
|
75
|
+
'thumbnail-link': '/mms/image',
|
|
76
|
+
'product-catalog-image': '/product/image',
|
|
77
|
+
'md-app-state': '',
|
|
78
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
79
|
+
}
|
|
80
|
+
exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
81
|
+
'audio': 'Audio',
|
|
82
|
+
'document': 'Document',
|
|
83
|
+
'gif': 'Video',
|
|
84
|
+
'image': 'Image',
|
|
85
|
+
'ppic': '',
|
|
86
|
+
'product': 'Image',
|
|
87
|
+
'ptt': 'Audio',
|
|
88
|
+
'sticker': 'Image',
|
|
89
|
+
'video': 'Video',
|
|
90
|
+
'thumbnail-document': 'Document Thumbnail',
|
|
91
|
+
'thumbnail-image': 'Image Thumbnail',
|
|
92
|
+
'thumbnail-video': 'Video Thumbnail',
|
|
93
|
+
'thumbnail-link': 'Link Thumbnail',
|
|
94
|
+
'md-msg-hist': 'History',
|
|
95
|
+
'md-app-state': 'App State',
|
|
96
|
+
'product-catalog-image': '',
|
|
97
|
+
'payment-bg-image': 'Payment Background',
|
|
98
|
+
'ptv': 'Video'
|
|
99
|
+
}
|
|
100
|
+
exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP)
|
|
101
|
+
exports.MIN_PREKEY_COUNT = 5
|
|
102
|
+
exports.INITIAL_PREKEY_COUNT = 30
|
|
103
|
+
exports.DEFAULT_CACHE_TTLS = {
|
|
104
|
+
SIGNAL_STORE: 5 * 60,
|
|
105
|
+
MSG_RETRY: 60 * 60,
|
|
106
|
+
CALL_OFFER: 5 * 60,
|
|
107
|
+
USER_DEVICES: 5 * 60, // 5 minutes
|
|
108
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
{
|
|
2
|
+
"93": 412,
|
|
3
|
+
"355": 276,
|
|
4
|
+
"213": 603,
|
|
5
|
+
"1-684": 544,
|
|
6
|
+
"376": 213,
|
|
7
|
+
"244": 631,
|
|
8
|
+
"1-264": 365,
|
|
9
|
+
"1-268": 344,
|
|
10
|
+
"54": 722,
|
|
11
|
+
"374": 283,
|
|
12
|
+
"297": 363,
|
|
13
|
+
"61": 505,
|
|
14
|
+
"43": 232,
|
|
15
|
+
"994": 400,
|
|
16
|
+
"1-242": 364,
|
|
17
|
+
"973": 426,
|
|
18
|
+
"880": 470,
|
|
19
|
+
"1-246": 342,
|
|
20
|
+
"375": 257,
|
|
21
|
+
"32": 206,
|
|
22
|
+
"501": 702,
|
|
23
|
+
"229": 616,
|
|
24
|
+
"1-441": 350,
|
|
25
|
+
"975": 402,
|
|
26
|
+
"591": 736,
|
|
27
|
+
"387": 218,
|
|
28
|
+
"267": 652,
|
|
29
|
+
"55": 724,
|
|
30
|
+
"1-284": 348,
|
|
31
|
+
"673": 528,
|
|
32
|
+
"359": 284,
|
|
33
|
+
"226": 613,
|
|
34
|
+
"257": 642,
|
|
35
|
+
"855": 456,
|
|
36
|
+
"237": 624,
|
|
37
|
+
"238": 625,
|
|
38
|
+
"1-345": 346,
|
|
39
|
+
"236": 623,
|
|
40
|
+
"235": 622,
|
|
41
|
+
"56": 730,
|
|
42
|
+
"86": 454,
|
|
43
|
+
"57": 732,
|
|
44
|
+
"269": 654,
|
|
45
|
+
"682": 548,
|
|
46
|
+
"506": 712,
|
|
47
|
+
"385": 219,
|
|
48
|
+
"53": 368,
|
|
49
|
+
"357": 280,
|
|
50
|
+
"420": 230,
|
|
51
|
+
"243": 630,
|
|
52
|
+
"45": 238,
|
|
53
|
+
"253": 638,
|
|
54
|
+
"1-767": 366,
|
|
55
|
+
"1-809": 370,
|
|
56
|
+
"1-849": 370,
|
|
57
|
+
"1-829": 370,
|
|
58
|
+
"593": 740,
|
|
59
|
+
"20": 602,
|
|
60
|
+
"503": 706,
|
|
61
|
+
"240": 627,
|
|
62
|
+
"291": 657,
|
|
63
|
+
"372": 248,
|
|
64
|
+
"251": 636,
|
|
65
|
+
"500": 750,
|
|
66
|
+
"298": 288,
|
|
67
|
+
"679": 542,
|
|
68
|
+
"358": 244,
|
|
69
|
+
"33": 208,
|
|
70
|
+
"689": 547,
|
|
71
|
+
"241": 628,
|
|
72
|
+
"220": 607,
|
|
73
|
+
"995": 282,
|
|
74
|
+
"49": 262,
|
|
75
|
+
"233": 620,
|
|
76
|
+
"350": 266,
|
|
77
|
+
"30": 202,
|
|
78
|
+
"299": 290,
|
|
79
|
+
"1-473": 352,
|
|
80
|
+
"1-671": 535,
|
|
81
|
+
"502": 704,
|
|
82
|
+
"224": 537,
|
|
83
|
+
"592": 738,
|
|
84
|
+
"509": 372,
|
|
85
|
+
"504": 708,
|
|
86
|
+
"852": 454,
|
|
87
|
+
"36": 216,
|
|
88
|
+
"354": 274,
|
|
89
|
+
"91": 404,
|
|
90
|
+
"62": 510,
|
|
91
|
+
"98": 432,
|
|
92
|
+
"964": 418,
|
|
93
|
+
"353": 234,
|
|
94
|
+
"972": 425,
|
|
95
|
+
"39": 222,
|
|
96
|
+
"225": 612,
|
|
97
|
+
"1-876": 338,
|
|
98
|
+
"81": 440,
|
|
99
|
+
"962": 416,
|
|
100
|
+
"254": 639,
|
|
101
|
+
"686": 545,
|
|
102
|
+
"383": 221,
|
|
103
|
+
"965": 419,
|
|
104
|
+
"371": 247,
|
|
105
|
+
"961": 415,
|
|
106
|
+
"266": 651,
|
|
107
|
+
"231": 618,
|
|
108
|
+
"218": 606,
|
|
109
|
+
"423": 295,
|
|
110
|
+
"370": 246,
|
|
111
|
+
"352": 270,
|
|
112
|
+
"389": 294,
|
|
113
|
+
"261": 646,
|
|
114
|
+
"265": 650,
|
|
115
|
+
"60": 502,
|
|
116
|
+
"960": 472,
|
|
117
|
+
"223": 610,
|
|
118
|
+
"356": 278,
|
|
119
|
+
"692": 551,
|
|
120
|
+
"222": 609,
|
|
121
|
+
"230": 617,
|
|
122
|
+
"52": 334,
|
|
123
|
+
"691": 550,
|
|
124
|
+
"373": 259,
|
|
125
|
+
"377": 212,
|
|
126
|
+
"976": 428,
|
|
127
|
+
"382": 297,
|
|
128
|
+
"1-664": 354,
|
|
129
|
+
"212": 604,
|
|
130
|
+
"258": 643,
|
|
131
|
+
"95": 414,
|
|
132
|
+
"264": 649,
|
|
133
|
+
"674": 536,
|
|
134
|
+
"977": 429,
|
|
135
|
+
"31": 204,
|
|
136
|
+
"687": 546,
|
|
137
|
+
"64": 530,
|
|
138
|
+
"505": 710,
|
|
139
|
+
"227": 614,
|
|
140
|
+
"234": 621,
|
|
141
|
+
"683": 555,
|
|
142
|
+
"1-670": 534,
|
|
143
|
+
"47": 242,
|
|
144
|
+
"968": 226,
|
|
145
|
+
"92": 410,
|
|
146
|
+
"680": 552,
|
|
147
|
+
"970": 423,
|
|
148
|
+
"507": 714,
|
|
149
|
+
"675": 537,
|
|
150
|
+
"595": 744,
|
|
151
|
+
"51": 716,
|
|
152
|
+
"63": 515,
|
|
153
|
+
"48": 260,
|
|
154
|
+
"351": 268,
|
|
155
|
+
"1-787, 1-939": 330,
|
|
156
|
+
"974": 427,
|
|
157
|
+
"242": 630,
|
|
158
|
+
"40": 226,
|
|
159
|
+
"7": 250,
|
|
160
|
+
"250": 635,
|
|
161
|
+
"290": 658,
|
|
162
|
+
"1-869": 356,
|
|
163
|
+
"1-758": 358,
|
|
164
|
+
"508": 308,
|
|
165
|
+
"1-784": 360,
|
|
166
|
+
"685": 544,
|
|
167
|
+
"378": 292,
|
|
168
|
+
"239": 626,
|
|
169
|
+
"966": 420,
|
|
170
|
+
"221": 608,
|
|
171
|
+
"381": 220,
|
|
172
|
+
"248": 633,
|
|
173
|
+
"232": 619,
|
|
174
|
+
"65": 525,
|
|
175
|
+
"386": 293,
|
|
176
|
+
"677": 540,
|
|
177
|
+
"27": 655,
|
|
178
|
+
"211": 659,
|
|
179
|
+
"34": 214,
|
|
180
|
+
"94": 413,
|
|
181
|
+
"249": 634,
|
|
182
|
+
"597": 746,
|
|
183
|
+
"268": 653,
|
|
184
|
+
"46": 240,
|
|
185
|
+
"41": 228,
|
|
186
|
+
"963": 417,
|
|
187
|
+
"886": 466,
|
|
188
|
+
"992": 436,
|
|
189
|
+
"255": 640,
|
|
190
|
+
"66": 520,
|
|
191
|
+
"228": 615,
|
|
192
|
+
"690": 554,
|
|
193
|
+
"676": 539,
|
|
194
|
+
"1-868": 374,
|
|
195
|
+
"216": 605,
|
|
196
|
+
"90": 286,
|
|
197
|
+
"993": 438,
|
|
198
|
+
"1-649": 376,
|
|
199
|
+
"688": 553,
|
|
200
|
+
"1-340": 332,
|
|
201
|
+
"256": 641,
|
|
202
|
+
"380": 255,
|
|
203
|
+
"971": 424,
|
|
204
|
+
"44": 234,
|
|
205
|
+
"1": 310,
|
|
206
|
+
"598": 748,
|
|
207
|
+
"998": 434,
|
|
208
|
+
"678": 541,
|
|
209
|
+
"379": 225,
|
|
210
|
+
"58": 734,
|
|
211
|
+
"681": 543,
|
|
212
|
+
"967": 421,
|
|
213
|
+
"260": 645,
|
|
214
|
+
"263": 648,
|
|
215
|
+
"670": 514,
|
|
216
|
+
"245": 632,
|
|
217
|
+
"856": 457,
|
|
218
|
+
"599": 362,
|
|
219
|
+
"850": 467,
|
|
220
|
+
"262": 647,
|
|
221
|
+
"82": 450,
|
|
222
|
+
"84": 452
|
|
223
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class CiphertextMessage {
|
|
2
|
+
readonly UNSUPPORTED_VERSION: number
|
|
3
|
+
readonly CURRENT_VERSION: number
|
|
4
|
+
readonly WHISPER_TYPE: number
|
|
5
|
+
readonly PREKEY_TYPE: number
|
|
6
|
+
readonly SENDERKEY_TYPE: number
|
|
7
|
+
readonly SENDERKEY_DISTRIBUTION_TYPE: number
|
|
8
|
+
readonly ENCRYPTED_MESSAGE_OVERHEAD: number
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
class CiphertextMessage {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.UNSUPPORTED_VERSION = 1
|
|
8
|
+
this.CURRENT_VERSION = 3
|
|
9
|
+
this.WHISPER_TYPE = 2
|
|
10
|
+
this.PREKEY_TYPE = 3
|
|
11
|
+
this.SENDERKEY_TYPE = 4
|
|
12
|
+
this.SENDERKEY_DISTRIBUTION_TYPE = 5
|
|
13
|
+
this.ENCRYPTED_MESSAGE_OVERHEAD = 53
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
CiphertextMessage
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SenderKeyDistributionMessage } from './sender-key-distribution-message'
|
|
2
|
+
import { SenderKeyName } from './sender-key-name'
|
|
3
|
+
import { SenderKeyRecord } from './sender-key-record'
|
|
4
|
+
|
|
5
|
+
interface SenderKeyStore {
|
|
6
|
+
loadSenderKey(senderKeyName: SenderKeyName): Promise<SenderKeyRecord>
|
|
7
|
+
storeSenderKey(senderKeyName: SenderKeyName, record: SenderKeyRecord): Promise<void>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export declare class GroupSessionBuilder {
|
|
11
|
+
private readonly senderKeyStore
|
|
12
|
+
constructor(senderKeyStore: SenderKeyStore)
|
|
13
|
+
process(senderKeyName: SenderKeyName, senderKeyDistributionMessage: SenderKeyDistributionMessage): Promise<void>
|
|
14
|
+
create(senderKeyName: SenderKeyName): Promise<SenderKeyDistributionMessage>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc)
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k
|
|
12
|
+
o[k2] = m[k]
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = []
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k
|
|
26
|
+
return ar
|
|
27
|
+
}
|
|
28
|
+
return ownKeys(o)
|
|
29
|
+
}
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod
|
|
32
|
+
var result = {}
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i])
|
|
34
|
+
__setModuleDefault(result, mod)
|
|
35
|
+
return result
|
|
36
|
+
}
|
|
37
|
+
})()
|
|
38
|
+
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
40
|
+
|
|
41
|
+
const keyhelper = __importStar(require("./keyhelper"))
|
|
42
|
+
const sender_key_distribution_message_1 = require("./sender-key-distribution-message")
|
|
43
|
+
|
|
44
|
+
class GroupSessionBuilder {
|
|
45
|
+
constructor(senderKeyStore) {
|
|
46
|
+
this.senderKeyStore = senderKeyStore
|
|
47
|
+
}
|
|
48
|
+
async process(senderKeyName, senderKeyDistributionMessage) {
|
|
49
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName)
|
|
50
|
+
senderKeyRecord.addSenderKeyState(senderKeyDistributionMessage.getId(), senderKeyDistributionMessage.getIteration(), senderKeyDistributionMessage.getChainKey(), senderKeyDistributionMessage.getSignatureKey())
|
|
51
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord)
|
|
52
|
+
}
|
|
53
|
+
async create(senderKeyName) {
|
|
54
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName)
|
|
55
|
+
if (senderKeyRecord.isEmpty()) {
|
|
56
|
+
const keyId = keyhelper.generateSenderKeyId()
|
|
57
|
+
const senderKey = keyhelper.generateSenderKey()
|
|
58
|
+
const signingKey = keyhelper.generateSenderSigningKey()
|
|
59
|
+
senderKeyRecord.setSenderKeyState(keyId, 0, senderKey, signingKey)
|
|
60
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord)
|
|
61
|
+
}
|
|
62
|
+
const state = senderKeyRecord.getSenderKeyState()
|
|
63
|
+
if (!state) {
|
|
64
|
+
throw new Error('No session state available')
|
|
65
|
+
}
|
|
66
|
+
return new sender_key_distribution_message_1.SenderKeyDistributionMessage(state.getKeyId(), state.getSenderChainKey().getIteration(), state.getSenderChainKey().getSeed(), state.getSigningKeyPublic())
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
GroupSessionBuilder
|
|
72
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SenderKeyName } from './sender-key-name'
|
|
2
|
+
import { SenderKeyRecord } from './sender-key-record'
|
|
3
|
+
|
|
4
|
+
export interface SenderKeyStore {
|
|
5
|
+
loadSenderKey(senderKeyName: SenderKeyName): Promise<SenderKeyRecord>
|
|
6
|
+
storeSenderKey(senderKeyName: SenderKeyName, record: SenderKeyRecord): Promise<void>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export declare class GroupCipher {
|
|
10
|
+
private readonly senderKeyStore
|
|
11
|
+
private readonly senderKeyName
|
|
12
|
+
constructor(senderKeyStore: SenderKeyStore, senderKeyName: SenderKeyName)
|
|
13
|
+
private queueJob
|
|
14
|
+
encrypt(paddedPlaintext: Uint8Array | string): Promise<Uint8Array>
|
|
15
|
+
decrypt(senderKeyMessageBytes: Uint8Array): Promise<Uint8Array>
|
|
16
|
+
private getSenderKey
|
|
17
|
+
private getPlainText
|
|
18
|
+
private getCipherText
|
|
19
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const crypto_1 = require("@itsukichan/libsignal-node/src/crypto")
|
|
6
|
+
|
|
7
|
+
const queue_job_1 = require("./queue-job")
|
|
8
|
+
const sender_key_message_1 = require("./sender-key-message")
|
|
9
|
+
|
|
10
|
+
class GroupCipher {
|
|
11
|
+
constructor(senderKeyStore, senderKeyName) {
|
|
12
|
+
this.senderKeyStore = senderKeyStore
|
|
13
|
+
this.senderKeyName = senderKeyName
|
|
14
|
+
}
|
|
15
|
+
queueJob(awaitable) {
|
|
16
|
+
return queue_job_1.queueJob(this.senderKeyName.toString(), awaitable)
|
|
17
|
+
}
|
|
18
|
+
async encrypt(paddedPlaintext) {
|
|
19
|
+
return await this.queueJob(async () => {
|
|
20
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName)
|
|
21
|
+
if (!record) {
|
|
22
|
+
throw new Error('No SenderKeyRecord found for encryption')
|
|
23
|
+
}
|
|
24
|
+
const senderKeyState = record.getSenderKeyState()
|
|
25
|
+
if (!senderKeyState) {
|
|
26
|
+
throw new Error('No session to encrypt message')
|
|
27
|
+
}
|
|
28
|
+
const iteration = senderKeyState.getSenderChainKey().getIteration()
|
|
29
|
+
const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1)
|
|
30
|
+
const ciphertext = await this.getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext)
|
|
31
|
+
const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(senderKeyState.getKeyId(), senderKey.getIteration(), ciphertext, senderKeyState.getSigningKeyPrivate())
|
|
32
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record)
|
|
33
|
+
return senderKeyMessage.serialize()
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
async decrypt(senderKeyMessageBytes) {
|
|
37
|
+
return await this.queueJob(async () => {
|
|
38
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName)
|
|
39
|
+
if (!record) {
|
|
40
|
+
throw new Error('No SenderKeyRecord found for decryption')
|
|
41
|
+
}
|
|
42
|
+
const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(null, null, null, null, senderKeyMessageBytes)
|
|
43
|
+
const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId())
|
|
44
|
+
if (!senderKeyState) {
|
|
45
|
+
throw new Error('No session found to decrypt message')
|
|
46
|
+
}
|
|
47
|
+
senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic())
|
|
48
|
+
const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration())
|
|
49
|
+
const plaintext = await this.getPlainText(senderKey.getIv(), senderKey.getCipherKey(), senderKeyMessage.getCipherText())
|
|
50
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record)
|
|
51
|
+
return plaintext
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
getSenderKey(senderKeyState, iteration) {
|
|
55
|
+
let senderChainKey = senderKeyState.getSenderChainKey()
|
|
56
|
+
if (senderChainKey.getIteration() > iteration) {
|
|
57
|
+
if (senderKeyState.hasSenderMessageKey(iteration)) {
|
|
58
|
+
const messageKey = senderKeyState.removeSenderMessageKey(iteration)
|
|
59
|
+
if (!messageKey) {
|
|
60
|
+
throw new Error('No sender message key found for iteration')
|
|
61
|
+
}
|
|
62
|
+
return messageKey
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`Received message with old counter: ${senderChainKey.getIteration()}, ${iteration}`)
|
|
65
|
+
}
|
|
66
|
+
if (iteration - senderChainKey.getIteration() > 2000) {
|
|
67
|
+
throw new Error('Over 2000 messages into the future!')
|
|
68
|
+
}
|
|
69
|
+
while (senderChainKey.getIteration() < iteration) {
|
|
70
|
+
senderKeyState.addSenderMessageKey(senderChainKey.getSenderMessageKey())
|
|
71
|
+
senderChainKey = senderChainKey.getNext()
|
|
72
|
+
}
|
|
73
|
+
senderKeyState.setSenderChainKey(senderChainKey.getNext())
|
|
74
|
+
return senderChainKey.getSenderMessageKey()
|
|
75
|
+
}
|
|
76
|
+
async getPlainText(iv, key, ciphertext) {
|
|
77
|
+
try {
|
|
78
|
+
return crypto_1.decrypt(key, ciphertext, iv)
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
throw new Error('InvalidMessageException')
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async getCipherText(iv, key, plaintext) {
|
|
85
|
+
try {
|
|
86
|
+
const ivBuffer = typeof iv === 'string' ? Buffer.from(iv, 'base64') : iv
|
|
87
|
+
const keyBuffer = typeof key === 'string' ? Buffer.from(key, 'base64') : key
|
|
88
|
+
const plaintextBuffer = typeof plaintext === 'string' ? Buffer.from(plaintext) : plaintext
|
|
89
|
+
return crypto_1.encrypt(keyBuffer, plaintextBuffer, ivBuffer)
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
throw new Error('InvalidMessageException')
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
module.exports = {
|
|
98
|
+
GroupCipher
|
|
99
|
+
}
|
|
@@ -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'
|