queenjusmy-baileys 3.0.8
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 +466 -0
- package/WAProto/index.js +169661 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Defaults/index.js +147 -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 +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +29 -0
- package/lib/Signal/Group/tmp +1 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +174 -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 +171 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.d.ts +267 -0
- package/lib/Socket/chats.js +970 -0
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +317 -0
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/index.js +11 -0
- package/lib/Socket/luxu.d.ts +268 -0
- package/lib/Socket/luxu.js +591 -0
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +1110 -0
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/messages-send.js +913 -0
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +326 -0
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/socket.js +665 -0
- package/lib/Socket/usync.d.ts +36 -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 +13 -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 +427 -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 +110 -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 +102 -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 +157 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +55 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +35 -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 +273 -0
- package/lib/Types/Message.js +9 -0
- package/lib/Types/Newsletter.d.ts +103 -0
- package/lib/Types/Newsletter.js +38 -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 +111 -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 +57 -0
- package/lib/Types/index.js +42 -0
- package/lib/Types/tmp +1 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +206 -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 +71 -0
- package/lib/Utils/chat-utils.js +729 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +151 -0
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/decode-wa-message.js +198 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +514 -0
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +423 -0
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/history.js +96 -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 +4 -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 +116 -0
- package/lib/Utils/messages-media.js +819 -0
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +816 -0
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +155 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +321 -0
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/signal.js +153 -0
- package/lib/Utils/tmp +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +119 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +229 -0
- package/lib/WABinary/constants.d.ts +30 -0
- package/lib/WABinary/constants.js +40 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +252 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +265 -0
- package/lib/WABinary/generic-utils.d.ts +17 -0
- package/lib/WABinary/generic-utils.js +198 -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/tmp +1 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +17 -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 +3 -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/WAM/tmp +1 -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/Protocols/tmp +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +89 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +39 -0
- package/lib/temp +1 -0
- package/package.json +106 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const major = parseInt(process.versions.node.split('.')[0], 10);
|
|
2
|
+
|
|
3
|
+
if (major < 20) {
|
|
4
|
+
console.error(
|
|
5
|
+
`\n❌ This package requires Node.js 20+ to run reliably.\n` +
|
|
6
|
+
` You are using Node.js ${process.versions.node}.\n` +
|
|
7
|
+
` Please upgrade to Node.js 20+ to proceed.\n`
|
|
8
|
+
);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { proto } from '../../WAProto';
|
|
4
|
+
import type { MediaType, SocketConfig } from '../Types';
|
|
5
|
+
export declare const UNAUTHORIZED_CODES: number[];
|
|
6
|
+
export declare const DEFAULT_ORIGIN = "https://web.whatsapp.com";
|
|
7
|
+
export declare const DEF_CALLBACK_PREFIX = "CB:";
|
|
8
|
+
export declare const DEF_TAG_PREFIX = "TAG:";
|
|
9
|
+
export declare const PHONE_CONNECTION_CB = "CB:Pong";
|
|
10
|
+
export declare const WA_DEFAULT_EPHEMERAL: number;
|
|
11
|
+
export declare const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
|
|
12
|
+
export declare const DICT_VERSION = 2;
|
|
13
|
+
export declare const KEY_BUNDLE_TYPE: Buffer;
|
|
14
|
+
export declare const NOISE_WA_HEADER: Buffer;
|
|
15
|
+
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
16
|
+
export declare const URL_REGEX: RegExp;
|
|
17
|
+
export declare const WA_CERT_DETAILS: {
|
|
18
|
+
SERIAL: number;
|
|
19
|
+
};
|
|
20
|
+
export declare const PROCESSABLE_HISTORY_TYPES: proto.Message.HistorySyncNotification.HistorySyncType[];
|
|
21
|
+
export declare const DEFAULT_CONNECTION_CONFIG: SocketConfig;
|
|
22
|
+
export declare const MEDIA_PATH_MAP: {
|
|
23
|
+
[T in MediaType]?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare const MEDIA_HKDF_KEY_MAPPING: {
|
|
26
|
+
audio: string;
|
|
27
|
+
document: string;
|
|
28
|
+
gif: string;
|
|
29
|
+
image: string;
|
|
30
|
+
ppic: string;
|
|
31
|
+
product: string;
|
|
32
|
+
ptt: string;
|
|
33
|
+
sticker: string;
|
|
34
|
+
video: string;
|
|
35
|
+
'thumbnail-document': string;
|
|
36
|
+
'thumbnail-image': string;
|
|
37
|
+
'thumbnail-video': string;
|
|
38
|
+
'thumbnail-link': string;
|
|
39
|
+
'md-msg-hist': string;
|
|
40
|
+
'md-app-state': string;
|
|
41
|
+
'product-catalog-image': string;
|
|
42
|
+
'payment-bg-image': string;
|
|
43
|
+
ptv: string;
|
|
44
|
+
};
|
|
45
|
+
export declare const MEDIA_KEYS: ("ppic" | "product" | "image" | "video" | "sticker" | "audio" | "gif" | "ptt" | "thumbnail-document" | "thumbnail-image" | "thumbnail-link" | "thumbnail-video" | "md-app-state" | "md-msg-hist" | "document" | "product-catalog-image" | "payment-bg-image" | "ptv")[];
|
|
46
|
+
export declare const MIN_PREKEY_COUNT = 5;
|
|
47
|
+
export declare const INITIAL_PREKEY_COUNT = 30;
|
|
48
|
+
export declare const DEFAULT_CACHE_TTLS: {
|
|
49
|
+
SIGNAL_STORE: number;
|
|
50
|
+
MSG_RETRY: number;
|
|
51
|
+
CALL_OFFER: number;
|
|
52
|
+
USER_DEVICES: number;
|
|
53
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
var __importDefault = this && this.__importDefault || function (a) {
|
|
2
|
+
return a && a.__esModule ? a : { "default": a }
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
6
|
+
|
|
7
|
+
exports.DEFAULT_CACHE_TTLS =
|
|
8
|
+
exports.INITIAL_PREKEY_COUNT =
|
|
9
|
+
exports.MIN_PREKEY_COUNT =
|
|
10
|
+
exports.MEDIA_KEYS =
|
|
11
|
+
exports.MEDIA_HKDF_KEY_MAPPING =
|
|
12
|
+
exports.MEDIA_PATH_MAP =
|
|
13
|
+
exports.DEFAULT_CONNECTION_CONFIG =
|
|
14
|
+
exports.PROCESSABLE_HISTORY_TYPES =
|
|
15
|
+
exports.WA_CERT_DETAILS =
|
|
16
|
+
exports.URL_REGEX =
|
|
17
|
+
exports.NOISE_WA_HEADER =
|
|
18
|
+
exports.KEY_BUNDLE_TYPE =
|
|
19
|
+
exports.DICT_VERSION =
|
|
20
|
+
exports.NOISE_MODE =
|
|
21
|
+
exports.WA_DEFAULT_EPHEMERAL =
|
|
22
|
+
exports.PHONE_CONNECTION_CB =
|
|
23
|
+
exports.DEF_TAG_PREFIX =
|
|
24
|
+
exports.DEF_CALLBACK_PREFIX =
|
|
25
|
+
exports.DEFAULT_ORIGIN =
|
|
26
|
+
exports.UNAUTHORIZED_CODES =
|
|
27
|
+
void 0;
|
|
28
|
+
|
|
29
|
+
const crypto_1 = require("crypto");
|
|
30
|
+
const WAProto_1 = require("../../WAProto"),
|
|
31
|
+
libsignal_1 = require("../Signal/libsignal"),
|
|
32
|
+
Utils_1 = require("../Utils"),
|
|
33
|
+
logger_1 = __importDefault(require("../Utils/logger")),
|
|
34
|
+
baileys_version_json_1 = require("./baileys-version.json"),
|
|
35
|
+
phonenumber_mcc_json_1 = __importDefault(require("./phonenumber-mcc.json"));
|
|
36
|
+
|
|
37
|
+
exports.UNAUTHORIZED_CODES = [401, 403, 419];
|
|
38
|
+
exports.version = [2, 3000, 1027934701];
|
|
39
|
+
exports.PHONENUMBER_MCC = phonenumber_mcc_json_1.default;
|
|
40
|
+
exports.DEFAULT_ORIGIN = "https://web.whatsapp.com";
|
|
41
|
+
exports.MOBILE_ENDPOINT = 'g.whatsapp.net';
|
|
42
|
+
exports.MOBILE_PORT = 443;
|
|
43
|
+
exports.DEF_CALLBACK_PREFIX = "CB:";
|
|
44
|
+
exports.DEF_TAG_PREFIX = "TAG:";
|
|
45
|
+
exports.PHONE_CONNECTION_CB = "CB:Pong";
|
|
46
|
+
exports.WA_DEFAULT_EPHEMERAL = 604800;
|
|
47
|
+
const WA_VERSION = '2.25.23.24';
|
|
48
|
+
const WA_VERSION_HASH = (0, crypto_1.createHash)('md5').update(WA_VERSION).digest('hex');
|
|
49
|
+
exports.MOBILE_TOKEN = Buffer.from('0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM' + WA_VERSION_HASH);
|
|
50
|
+
exports.MOBILE_REGISTRATION_ENDPOINT = 'https://v.whatsapp.net/v2';
|
|
51
|
+
exports.MOBILE_USERAGENT = `WhatsApp/${WA_VERSION} iOS/17.5.1 Device/Apple-iPhone_13`;
|
|
52
|
+
exports.REGISTRATION_PUBLIC_KEY = Buffer.from([
|
|
53
|
+
5, 142, 140, 15, 116, 195, 235, 197, 215, 166, 134, 92, 108, 60, 132, 56, 86, 176, 97, 33, 204, 232, 234, 119, 77,
|
|
54
|
+
34, 251, 111, 18, 37, 18, 48, 45,
|
|
55
|
+
]);
|
|
56
|
+
exports.NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\x00\x00\x00\x00";
|
|
57
|
+
exports.DICT_VERSION = 2;
|
|
58
|
+
exports.KEY_BUNDLE_TYPE = Buffer.from([5]);
|
|
59
|
+
exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]);
|
|
60
|
+
exports.PROTOCOL_VERSION = [5, 2];
|
|
61
|
+
exports.MOBILE_NOISE_HEADER = Buffer.concat([Buffer.from('WA'), Buffer.from(exports.PROTOCOL_VERSION)]);
|
|
62
|
+
|
|
63
|
+
exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
|
|
64
|
+
exports.WA_CERT_DETAILS = { SERIAL: 0 };
|
|
65
|
+
|
|
66
|
+
exports.PROCESSABLE_HISTORY_TYPES = [
|
|
67
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
68
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
|
|
69
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
|
|
70
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
|
|
71
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
75
|
+
version: baileys_version_json_1.version,
|
|
76
|
+
browser: Utils_1.Browsers("Chrome"),
|
|
77
|
+
waWebSocketUrl: "wss://web.whatsapp.com/ws/chat",
|
|
78
|
+
connectTimeoutMs: 2E4,
|
|
79
|
+
keepAliveIntervalMs: 3E4,
|
|
80
|
+
logger: logger_1.default.child({ class: "baileys" }),
|
|
81
|
+
printQRInTerminal: !1,
|
|
82
|
+
emitOwnEvents: !0,
|
|
83
|
+
defaultQueryTimeoutMs: 6E4,
|
|
84
|
+
customUploadHosts: [],
|
|
85
|
+
retryRequestDelayMs: 250,
|
|
86
|
+
maxMsgRetryCount: 5,
|
|
87
|
+
fireInitQueries: !0,
|
|
88
|
+
auth: void 0,
|
|
89
|
+
markOnlineOnConnect: !0,
|
|
90
|
+
syncFullHistory: !1,
|
|
91
|
+
patchMessageBeforeSending: a => a,
|
|
92
|
+
shouldSyncHistoryMessage: () => !0,
|
|
93
|
+
shouldIgnoreJid: () => !1,
|
|
94
|
+
linkPreviewImageThumbnailWidth: 192,
|
|
95
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3E3 },
|
|
96
|
+
generateHighQualityLinkPreview: !1,
|
|
97
|
+
options: {},
|
|
98
|
+
appStateMacVerification: { patch: !1, snapshot: !1 },
|
|
99
|
+
countryCode: "US",
|
|
100
|
+
getMessage: async () => { },
|
|
101
|
+
cachedGroupMetadata: async () => { },
|
|
102
|
+
makeSignalRepository: libsignal_1.makeLibSignalRepository
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
exports.MEDIA_PATH_MAP = {
|
|
106
|
+
image: "/mms/image",
|
|
107
|
+
video: "/mms/video",
|
|
108
|
+
document: "/mms/document",
|
|
109
|
+
audio: "/mms/audio",
|
|
110
|
+
sticker: "/mms/image",
|
|
111
|
+
"thumbnail-link": "/mms/image",
|
|
112
|
+
"product-catalog-image": "/product/image",
|
|
113
|
+
"md-app-state": "",
|
|
114
|
+
"md-msg-hist": "/mms/md-app-state"
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
118
|
+
audio: "Audio",
|
|
119
|
+
document: "Document",
|
|
120
|
+
gif: "Video",
|
|
121
|
+
image: "Image",
|
|
122
|
+
ppic: "",
|
|
123
|
+
product: "Image",
|
|
124
|
+
ptt: "Audio",
|
|
125
|
+
sticker: "Image",
|
|
126
|
+
video: "Video",
|
|
127
|
+
"thumbnail-document": "Document Thumbnail",
|
|
128
|
+
"thumbnail-image": "Image Thumbnail",
|
|
129
|
+
"thumbnail-video": "Video Thumbnail",
|
|
130
|
+
"thumbnail-link": "Link Thumbnail",
|
|
131
|
+
"md-msg-hist": "History",
|
|
132
|
+
"md-app-state": "App State",
|
|
133
|
+
"product-catalog-image": "",
|
|
134
|
+
"payment-bg-image": "Payment Background",
|
|
135
|
+
ptv: "Video"
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
|
|
139
|
+
exports.MIN_PREKEY_COUNT = 5;
|
|
140
|
+
exports.INITIAL_PREKEY_COUNT = 30;
|
|
141
|
+
|
|
142
|
+
exports.DEFAULT_CACHE_TTLS = {
|
|
143
|
+
SIGNAL_STORE: 300,
|
|
144
|
+
MSG_RETRY: 3600,
|
|
145
|
+
CALL_OFFER: 300,
|
|
146
|
+
USER_DEVICES: 300
|
|
147
|
+
};
|
|
@@ -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,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CiphertextMessage = void 0;
|
|
4
|
+
class CiphertextMessage {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.UNSUPPORTED_VERSION = 1;
|
|
7
|
+
this.CURRENT_VERSION = 3;
|
|
8
|
+
this.WHISPER_TYPE = 2;
|
|
9
|
+
this.PREKEY_TYPE = 3;
|
|
10
|
+
this.SENDERKEY_TYPE = 4;
|
|
11
|
+
this.SENDERKEY_DISTRIBUTION_TYPE = 5;
|
|
12
|
+
this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.CiphertextMessage = CiphertextMessage;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SenderKeyDistributionMessage } from './sender-key-distribution-message';
|
|
2
|
+
import { SenderKeyName } from './sender-key-name';
|
|
3
|
+
import { SenderKeyRecord } from './sender-key-record';
|
|
4
|
+
interface SenderKeyStore {
|
|
5
|
+
loadSenderKey(senderKeyName: SenderKeyName): Promise<SenderKeyRecord>;
|
|
6
|
+
storeSenderKey(senderKeyName: SenderKeyName, record: SenderKeyRecord): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare class GroupSessionBuilder {
|
|
9
|
+
private readonly senderKeyStore;
|
|
10
|
+
constructor(senderKeyStore: SenderKeyStore);
|
|
11
|
+
process(senderKeyName: SenderKeyName, senderKeyDistributionMessage: SenderKeyDistributionMessage): Promise<void>;
|
|
12
|
+
create(senderKeyName: SenderKeyName): Promise<SenderKeyDistributionMessage>;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
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.GroupSessionBuilder = void 0;
|
|
37
|
+
const keyhelper = __importStar(require("./keyhelper"));
|
|
38
|
+
const sender_key_distribution_message_1 = require("./sender-key-distribution-message");
|
|
39
|
+
class GroupSessionBuilder {
|
|
40
|
+
constructor(senderKeyStore) {
|
|
41
|
+
this.senderKeyStore = senderKeyStore;
|
|
42
|
+
}
|
|
43
|
+
async process(senderKeyName, senderKeyDistributionMessage) {
|
|
44
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
|
|
45
|
+
senderKeyRecord.addSenderKeyState(senderKeyDistributionMessage.getId(), senderKeyDistributionMessage.getIteration(), senderKeyDistributionMessage.getChainKey(), senderKeyDistributionMessage.getSignatureKey());
|
|
46
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
47
|
+
}
|
|
48
|
+
async create(senderKeyName) {
|
|
49
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
|
|
50
|
+
if (senderKeyRecord.isEmpty()) {
|
|
51
|
+
const keyId = keyhelper.generateSenderKeyId();
|
|
52
|
+
const senderKey = keyhelper.generateSenderKey();
|
|
53
|
+
const signingKey = keyhelper.generateSenderSigningKey();
|
|
54
|
+
senderKeyRecord.setSenderKeyState(keyId, 0, senderKey, signingKey);
|
|
55
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
56
|
+
}
|
|
57
|
+
const state = senderKeyRecord.getSenderKeyState();
|
|
58
|
+
if (!state) {
|
|
59
|
+
throw new Error('No session state available');
|
|
60
|
+
}
|
|
61
|
+
return new sender_key_distribution_message_1.SenderKeyDistributionMessage(state.getKeyId(), state.getSenderChainKey().getIteration(), state.getSenderChainKey().getSeed(), state.getSigningKeyPublic());
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.GroupSessionBuilder = GroupSessionBuilder;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SenderKeyName } from './sender-key-name';
|
|
2
|
+
import { SenderKeyRecord } from './sender-key-record';
|
|
3
|
+
export interface SenderKeyStore {
|
|
4
|
+
loadSenderKey(senderKeyName: SenderKeyName): Promise<SenderKeyRecord>;
|
|
5
|
+
storeSenderKey(senderKeyName: SenderKeyName, record: SenderKeyRecord): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export declare class GroupCipher {
|
|
8
|
+
private readonly senderKeyStore;
|
|
9
|
+
private readonly senderKeyName;
|
|
10
|
+
constructor(senderKeyStore: SenderKeyStore, senderKeyName: SenderKeyName);
|
|
11
|
+
private queueJob;
|
|
12
|
+
encrypt(paddedPlaintext: Uint8Array | string): Promise<Uint8Array>;
|
|
13
|
+
decrypt(senderKeyMessageBytes: Uint8Array): Promise<Uint8Array>;
|
|
14
|
+
private getSenderKey;
|
|
15
|
+
private getPlainText;
|
|
16
|
+
private getCipherText;
|
|
17
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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.GroupCipher = void 0;
|
|
7
|
+
const crypto_1 = require("libsignal/src/crypto");
|
|
8
|
+
const queue_job_1 = __importDefault(require("./queue-job"));
|
|
9
|
+
const sender_key_message_1 = require("./sender-key-message");
|
|
10
|
+
class GroupCipher {
|
|
11
|
+
constructor(senderKeyStore, senderKeyName) {
|
|
12
|
+
this.senderKeyStore = senderKeyStore;
|
|
13
|
+
this.senderKeyName = senderKeyName;
|
|
14
|
+
}
|
|
15
|
+
queueJob(awaitable) {
|
|
16
|
+
return (0, queue_job_1.default)(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 (0, 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 (0, crypto_1.encrypt)(keyBuffer, plaintextBuffer, ivBuffer);
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
throw new Error('InvalidMessageException');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.GroupCipher = GroupCipher;
|
|
@@ -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';
|