@rennzsync/baileys 10.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.id.md +261 -0
- package/README.md +359 -0
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +5479 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +97691 -0
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +129 -0
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/group_cipher.js +81 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.js +428 -0
- package/lib/Signal/lid-mapping.js +276 -0
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +1198 -0
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +347 -0
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +12 -0
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +1772 -0
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +1196 -0
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +181 -0
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +970 -0
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Store/index.js +8 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +70 -0
- package/lib/Store/make-in-memory-store.js +417 -0
- package/lib/Store/make-ordered-dictionary.js +69 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Mex.d.ts.map +1 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Mex.js.map +1 -0
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +26 -0
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +302 -0
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +872 -0
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +118 -0
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +317 -0
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +622 -0
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +393 -0
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +134 -0
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +27 -0
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +8 -0
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/media-processor.js +173 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +811 -0
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +973 -0
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +630 -0
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/rich-carousel.js +205 -0
- package/lib/Utils/rich-classic.js +124 -0
- package/lib/Utils/rich-webui.js +133 -0
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +201 -0
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +164 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/use-sqlite-auth-state.js +162 -0
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +210 -0
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +220 -0
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +182 -0
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +96 -0
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +98 -0
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +31 -0
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12 -0
- package/lib/index.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Defaults/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAE9C,OAAO,KAAK,EAAuB,YAAY,EAAa,MAAM,UAAU,CAAA;AAM5E,eAAO,MAAM,kBAAkB,UAAkB,CAAA;AAEjD,eAAO,MAAM,cAAc,6BAA6B,CAAA;AACxD,eAAO,MAAM,iBAAiB,qCAAqC,CAAA;AACnE,eAAO,MAAM,iBAAiB,qCAAqC,CAAA;AACnE,eAAO,MAAM,mBAAmB,QAAQ,CAAA;AACxC,eAAO,MAAM,cAAc,SAAS,CAAA;AACpC,eAAO,MAAM,mBAAmB,YAAY,CAAA;AAE5C,eAAO,MAAM,yBAAyB,qBAAsB,CAAA;AAC5D,eAAO,MAAM,wBAAwB,qBAAsB,CAAA;AAC3D,eAAO,MAAM,gCAAgC,qBAAsB,CAAA;AACnE,eAAO,MAAM,+BAA+B,qBAAsB,CAAA;AAElE,eAAO,MAAM,oBAAoB,QAAmB,CAAA;AAEpD,iEAAiE;AACjE,eAAO,MAAM,qBAAqB,QAAe,CAAA;AAEjD,2EAA2E;AAC3E,eAAO,MAAM,2BAA2B,QAAoB,CAAA;AAE5D,eAAO,MAAM,UAAU,yCAAyC,CAAA;AAChE,eAAO,MAAM,YAAY,IAAI,CAAA;AAC7B,eAAO,MAAM,eAAe,qBAAmB,CAAA;AAC/C,eAAO,MAAM,eAAe,qBAAyC,CAAA;AACrE,yGAAyG;AACzG,eAAO,MAAM,SAAS,QAAwF,CAAA;AAE9G,eAAO,MAAM,eAAe;;;;CAI3B,CAAA;AAED,eAAO,MAAM,yBAAyB,qCAQrC,CAAA;AAED,eAAO,MAAM,kBAAkB;;;;;CAK9B,CAAA;AAED,eAAO,MAAM,yBAAyB,EAAE,YAmCvC,CAAA;AAED,eAAO,MAAM,cAAc,EAAE;KAAG,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,MAAM;CAWvD,CAAA;AAED,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;CAoBlC,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,sBAAsB,CAAA;AAE3D,eAAO,MAAM,UAAU,EAAkC,SAAS,EAAE,CAAA;AAEpE,yHAAyH;AACzH,eAAO,MAAM,8BAA8B,SAAU,CAAA;AAErD,eAAO,MAAM,gBAAgB,IAAI,CAAA;AAEjC,eAAO,MAAM,oBAAoB,MAAM,CAAA;AAEvC,eAAO,MAAM,cAAc,QAAQ,CAAA;AAEnC,eAAO,MAAM,MAAM;;;;;CAKlB,CAAA"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { makeLibSignalRepository } from '../Signal/libsignal.js';
|
|
3
|
+
import { Browsers } from '../Utils/browser-utils.js';
|
|
4
|
+
import logger from '../Utils/logger.js';
|
|
5
|
+
const version = [2, 3000, 1043857760];
|
|
6
|
+
export const UNAUTHORIZED_CODES = [401, 403, 419];
|
|
7
|
+
export const DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
8
|
+
export const CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
|
|
9
|
+
export const CALL_AUDIO_PREFIX = 'https://call.whatsapp.com/voice/';
|
|
10
|
+
export const DEF_CALLBACK_PREFIX = 'CB:';
|
|
11
|
+
export const DEF_TAG_PREFIX = 'TAG:';
|
|
12
|
+
export const PHONE_CONNECTION_CB = 'CB:Pong';
|
|
13
|
+
export const WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0]);
|
|
14
|
+
export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]);
|
|
15
|
+
export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]);
|
|
16
|
+
export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]);
|
|
17
|
+
export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
|
|
18
|
+
/** Status messages older than 24 hours are considered expired */
|
|
19
|
+
export const STATUS_EXPIRY_SECONDS = 24 * 60 * 60;
|
|
20
|
+
/** WA Web enforces a 14-day maximum age for placeholder resend requests */
|
|
21
|
+
export const PLACEHOLDER_MAX_AGE_SECONDS = 14 * 24 * 60 * 60;
|
|
22
|
+
export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
|
|
23
|
+
export const DICT_VERSION = 3;
|
|
24
|
+
export const KEY_BUNDLE_TYPE = Buffer.from([5]);
|
|
25
|
+
export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]); // last is "DICT_VERSION"
|
|
26
|
+
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
27
|
+
export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
|
|
28
|
+
export const WA_CERT_DETAILS = {
|
|
29
|
+
SERIAL: 0,
|
|
30
|
+
ISSUER: 'WhatsAppLongTerm1',
|
|
31
|
+
PUBLIC_KEY: Buffer.from('142375574d0a587166aae71ebe516437c4a28b73e3695c6ce1f7f9545da8ee6b', 'hex')
|
|
32
|
+
};
|
|
33
|
+
export const PROCESSABLE_HISTORY_TYPES = [
|
|
34
|
+
proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
35
|
+
proto.HistorySync.HistorySyncType.PUSH_NAME,
|
|
36
|
+
proto.HistorySync.HistorySyncType.RECENT,
|
|
37
|
+
proto.HistorySync.HistorySyncType.FULL,
|
|
38
|
+
proto.HistorySync.HistorySyncType.ON_DEMAND,
|
|
39
|
+
proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
|
|
40
|
+
proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3
|
|
41
|
+
];
|
|
42
|
+
export const DEFAULT_CACHE_TTLS = {
|
|
43
|
+
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
44
|
+
MSG_RETRY: 10 * 60, // 10 minutes — cukup untuk retry; RAM-friendly
|
|
45
|
+
CALL_OFFER: 5 * 60, // 5 minutes
|
|
46
|
+
USER_DEVICES: 5 * 60 // 5 minutes
|
|
47
|
+
};
|
|
48
|
+
export const DEFAULT_CONNECTION_CONFIG = {
|
|
49
|
+
version: version,
|
|
50
|
+
browser: Browsers.macOS('Chrome'),
|
|
51
|
+
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
52
|
+
connectTimeoutMs: 20000,
|
|
53
|
+
keepAliveIntervalMs: 30000,
|
|
54
|
+
logger: logger.child({ class: 'baileys' }),
|
|
55
|
+
emitOwnEvents: true,
|
|
56
|
+
defaultQueryTimeoutMs: 60000,
|
|
57
|
+
customUploadHosts: [],
|
|
58
|
+
retryRequestDelayMs: 250,
|
|
59
|
+
maxMsgRetryCount: 5,
|
|
60
|
+
fireInitQueries: true,
|
|
61
|
+
auth: undefined,
|
|
62
|
+
markOnlineOnConnect: true,
|
|
63
|
+
syncFullHistory: false,
|
|
64
|
+
patchMessageBeforeSending: msg => msg,
|
|
65
|
+
shouldSyncHistoryMessage: ({ syncType }) => {
|
|
66
|
+
return syncType !== proto.HistorySync.HistorySyncType.FULL;
|
|
67
|
+
},
|
|
68
|
+
shouldIgnoreJid: () => false,
|
|
69
|
+
linkPreviewImageThumbnailWidth: 192,
|
|
70
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
71
|
+
generateHighQualityLinkPreview: false,
|
|
72
|
+
enableAutoSessionRecreation: true,
|
|
73
|
+
enableRecentMessageCache: false,
|
|
74
|
+
options: {},
|
|
75
|
+
appStateMacVerification: {
|
|
76
|
+
patch: false,
|
|
77
|
+
snapshot: false
|
|
78
|
+
},
|
|
79
|
+
countryCode: 'US',
|
|
80
|
+
getMessage: async () => undefined,
|
|
81
|
+
cachedGroupMetadata: async () => undefined,
|
|
82
|
+
makeSignalRepository: makeLibSignalRepository
|
|
83
|
+
};
|
|
84
|
+
export const MEDIA_PATH_MAP = {
|
|
85
|
+
image: '/mms/image',
|
|
86
|
+
video: '/mms/video',
|
|
87
|
+
document: '/mms/document',
|
|
88
|
+
audio: '/mms/audio',
|
|
89
|
+
sticker: '/mms/image',
|
|
90
|
+
'thumbnail-link': '/mms/image',
|
|
91
|
+
'product-catalog-image': '/product/image',
|
|
92
|
+
'md-app-state': '',
|
|
93
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
94
|
+
'biz-cover-photo': '/pps/biz-cover-photo'
|
|
95
|
+
};
|
|
96
|
+
export const MEDIA_HKDF_KEY_MAPPING = {
|
|
97
|
+
audio: 'Audio',
|
|
98
|
+
document: 'Document',
|
|
99
|
+
gif: 'Video',
|
|
100
|
+
image: 'Image',
|
|
101
|
+
ppic: '',
|
|
102
|
+
product: 'Image',
|
|
103
|
+
ptt: 'Audio',
|
|
104
|
+
sticker: 'Image',
|
|
105
|
+
video: 'Video',
|
|
106
|
+
'thumbnail-document': 'Document Thumbnail',
|
|
107
|
+
'thumbnail-image': 'Image Thumbnail',
|
|
108
|
+
'thumbnail-video': 'Video Thumbnail',
|
|
109
|
+
'thumbnail-link': 'Link Thumbnail',
|
|
110
|
+
'md-msg-hist': 'History',
|
|
111
|
+
'md-app-state': 'App State',
|
|
112
|
+
'product-catalog-image': '',
|
|
113
|
+
'payment-bg-image': 'Payment Background',
|
|
114
|
+
ptv: 'Video',
|
|
115
|
+
'biz-cover-photo': 'Image'
|
|
116
|
+
};
|
|
117
|
+
export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP);
|
|
118
|
+
/** 120s timeout for history sync stall detection, same as WA Web's handleChunkProgress / restartPausedTimer (g = 120) */
|
|
119
|
+
export const HISTORY_SYNC_PAUSED_TIMEOUT_MS = 120000;
|
|
120
|
+
export const MIN_PREKEY_COUNT = 5;
|
|
121
|
+
export const INITIAL_PREKEY_COUNT = 812;
|
|
122
|
+
export const UPLOAD_TIMEOUT = 30000; // 30 seconds
|
|
123
|
+
export const TimeMs = {
|
|
124
|
+
Minute: 60 * 1000,
|
|
125
|
+
Hour: 60 * 60 * 1000,
|
|
126
|
+
Day: 24 * 60 * 60 * 1000,
|
|
127
|
+
Week: 7 * 24 * 60 * 60 * 1000
|
|
128
|
+
};
|
|
129
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Defaults/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;AAE7D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,MAAM,MAAM,iBAAiB,CAAA;AAEpC,MAAM,OAAO,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAA;AAErC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAEjD,MAAM,CAAC,MAAM,cAAc,GAAG,0BAA0B,CAAA;AACxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,kCAAkC,CAAA;AACnE,MAAM,CAAC,MAAM,iBAAiB,GAAG,kCAAkC,CAAA;AACnE,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAA;AACxC,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAA;AACpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAA;AAE5C,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAC5D,MAAM,CAAC,MAA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AAW;IAC3B,uBAAuB,EAAE,EAAE;IAC3B,kBAAkB,EAAE,oBAAoB;IACxC,GAAG,EAAE,OAAO;IACZ,iBAAiB,EAAE,OAAO;CAC1B,CAAA;AAID,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAgB,CAAA;AAEpE,yHAAyH;AACzH,MAAM,CAAC,MAAM,8BAA8B,GAAG,MAAO,CAAA;AAErD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAA;AAEjC,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAA;AAEvC,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAA,CAAC,aAAa;AAEjD,MAAM,CAAC,MAAM,MAAM,GAAG;IACrB,MAAM,EAAE,EAAE,GAAG,IAAI;IACjB,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACpB,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IACxB,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;CAC7B,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class CiphertextMessage {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.UNSUPPORTED_VERSION = 1;
|
|
4
|
+
this.CURRENT_VERSION = 3;
|
|
5
|
+
this.WHISPER_TYPE = 2;
|
|
6
|
+
this.PREKEY_TYPE = 3;
|
|
7
|
+
this.SENDERKEY_TYPE = 4;
|
|
8
|
+
this.SENDERKEY_DISTRIBUTION_TYPE = 5;
|
|
9
|
+
this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as keyhelper from './keyhelper.js';
|
|
2
|
+
import { SenderKeyDistributionMessage } from './sender-key-distribution-message.js';
|
|
3
|
+
import { SenderKeyName } from './sender-key-name.js';
|
|
4
|
+
import { SenderKeyRecord } from './sender-key-record.js';
|
|
5
|
+
export class GroupSessionBuilder {
|
|
6
|
+
constructor(senderKeyStore) {
|
|
7
|
+
this.senderKeyStore = senderKeyStore;
|
|
8
|
+
}
|
|
9
|
+
async process(senderKeyName, senderKeyDistributionMessage) {
|
|
10
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
|
|
11
|
+
senderKeyRecord.addSenderKeyState(senderKeyDistributionMessage.getId(), senderKeyDistributionMessage.getIteration(), senderKeyDistributionMessage.getChainKey(), senderKeyDistributionMessage.getSignatureKey());
|
|
12
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
13
|
+
}
|
|
14
|
+
async create(senderKeyName) {
|
|
15
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
|
|
16
|
+
if (senderKeyRecord.isEmpty()) {
|
|
17
|
+
const keyId = keyhelper.generateSenderKeyId();
|
|
18
|
+
const senderKey = keyhelper.generateSenderKey();
|
|
19
|
+
const signingKey = keyhelper.generateSenderSigningKey();
|
|
20
|
+
senderKeyRecord.setSenderKeyState(keyId, 0, senderKey, signingKey);
|
|
21
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
22
|
+
}
|
|
23
|
+
const state = senderKeyRecord.getSenderKeyState();
|
|
24
|
+
if (!state) {
|
|
25
|
+
throw new Error('No session state available');
|
|
26
|
+
}
|
|
27
|
+
return new SenderKeyDistributionMessage(state.getKeyId(), state.getSenderChainKey().getIteration(), state.getSenderChainKey().getSeed(), state.getSigningKeyPublic());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { decrypt, encrypt } from 'libsignal/src/crypto';
|
|
2
|
+
import { SenderKeyMessage } from './sender-key-message.js';
|
|
3
|
+
import { SenderKeyName } from './sender-key-name.js';
|
|
4
|
+
import { SenderKeyRecord } from './sender-key-record.js';
|
|
5
|
+
import { SenderKeyState } from './sender-key-state.js';
|
|
6
|
+
export class GroupCipher {
|
|
7
|
+
constructor(senderKeyStore, senderKeyName) {
|
|
8
|
+
this.senderKeyStore = senderKeyStore;
|
|
9
|
+
this.senderKeyName = senderKeyName;
|
|
10
|
+
}
|
|
11
|
+
async encrypt(paddedPlaintext) {
|
|
12
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
|
|
13
|
+
if (!record) {
|
|
14
|
+
throw new Error('No SenderKeyRecord found for encryption');
|
|
15
|
+
}
|
|
16
|
+
const senderKeyState = record.getSenderKeyState();
|
|
17
|
+
if (!senderKeyState) {
|
|
18
|
+
throw new Error('No session to encrypt message');
|
|
19
|
+
}
|
|
20
|
+
const iteration = senderKeyState.getSenderChainKey().getIteration();
|
|
21
|
+
const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1);
|
|
22
|
+
const ciphertext = await this.getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext);
|
|
23
|
+
const senderKeyMessage = new SenderKeyMessage(senderKeyState.getKeyId(), senderKey.getIteration(), ciphertext, senderKeyState.getSigningKeyPrivate());
|
|
24
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
|
|
25
|
+
return senderKeyMessage.serialize();
|
|
26
|
+
}
|
|
27
|
+
async decrypt(senderKeyMessageBytes) {
|
|
28
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
|
|
29
|
+
if (!record) {
|
|
30
|
+
throw new Error('No SenderKeyRecord found for decryption');
|
|
31
|
+
}
|
|
32
|
+
const senderKeyMessage = new SenderKeyMessage(null, null, null, null, senderKeyMessageBytes);
|
|
33
|
+
const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());
|
|
34
|
+
if (!senderKeyState) {
|
|
35
|
+
throw new Error('No session found to decrypt message');
|
|
36
|
+
}
|
|
37
|
+
senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic());
|
|
38
|
+
const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration());
|
|
39
|
+
const plaintext = await this.getPlainText(senderKey.getIv(), senderKey.getCipherKey(), senderKeyMessage.getCipherText());
|
|
40
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
|
|
41
|
+
return plaintext;
|
|
42
|
+
}
|
|
43
|
+
getSenderKey(senderKeyState, iteration) {
|
|
44
|
+
let senderChainKey = senderKeyState.getSenderChainKey();
|
|
45
|
+
if (senderChainKey.getIteration() > iteration) {
|
|
46
|
+
if (senderKeyState.hasSenderMessageKey(iteration)) {
|
|
47
|
+
const messageKey = senderKeyState.removeSenderMessageKey(iteration);
|
|
48
|
+
if (!messageKey) {
|
|
49
|
+
throw new Error('No sender message key found for iteration');
|
|
50
|
+
}
|
|
51
|
+
return messageKey;
|
|
52
|
+
}
|
|
53
|
+
throw new Error(`Received message with old counter: ${senderChainKey.getIteration()}, ${iteration}`);
|
|
54
|
+
}
|
|
55
|
+
if (iteration - senderChainKey.getIteration() > 2000) {
|
|
56
|
+
throw new Error('Over 2000 messages into the future!');
|
|
57
|
+
}
|
|
58
|
+
while (senderChainKey.getIteration() < iteration) {
|
|
59
|
+
senderKeyState.addSenderMessageKey(senderChainKey.getSenderMessageKey());
|
|
60
|
+
senderChainKey = senderChainKey.getNext();
|
|
61
|
+
}
|
|
62
|
+
senderKeyState.setSenderChainKey(senderChainKey.getNext());
|
|
63
|
+
return senderChainKey.getSenderMessageKey();
|
|
64
|
+
}
|
|
65
|
+
async getPlainText(iv, key, ciphertext) {
|
|
66
|
+
try {
|
|
67
|
+
return decrypt(key, ciphertext, iv);
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
throw new Error('InvalidMessageException');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async getCipherText(iv, key, plaintext) {
|
|
74
|
+
try {
|
|
75
|
+
return encrypt(key, plaintext, iv);
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
throw new Error('InvalidMessageException');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { GroupSessionBuilder } from './group-session-builder.js';
|
|
2
|
+
export { SenderKeyDistributionMessage } from './sender-key-distribution-message.js';
|
|
3
|
+
export { SenderKeyRecord } from './sender-key-record.js';
|
|
4
|
+
export { SenderKeyName } from './sender-key-name.js';
|
|
5
|
+
export { GroupCipher } from './group_cipher.js';
|
|
6
|
+
export { SenderKeyState } from './sender-key-state.js';
|
|
7
|
+
export { SenderKeyMessage } from './sender-key-message.js';
|
|
8
|
+
export { SenderMessageKey } from './sender-message-key.js';
|
|
9
|
+
export { SenderChainKey } from './sender-chain-key.js';
|
|
10
|
+
export { CiphertextMessage } from './ciphertext-message.js';
|
|
11
|
+
export * as keyhelper from './keyhelper.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as nodeCrypto from 'crypto';
|
|
2
|
+
import { generateKeyPair } from 'libsignal/src/curve';
|
|
3
|
+
export function generateSenderKey() {
|
|
4
|
+
return nodeCrypto.randomBytes(32);
|
|
5
|
+
}
|
|
6
|
+
export function generateSenderKeyId() {
|
|
7
|
+
return nodeCrypto.randomInt(2147483647);
|
|
8
|
+
}
|
|
9
|
+
export function generateSenderSigningKey(key) {
|
|
10
|
+
if (!key) {
|
|
11
|
+
key = generateKeyPair();
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
public: Buffer.from(key.pubKey),
|
|
15
|
+
private: Buffer.from(key.privKey)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { calculateMAC } from 'libsignal/src/crypto';
|
|
2
|
+
import { SenderMessageKey } from './sender-message-key.js';
|
|
3
|
+
export class SenderChainKey {
|
|
4
|
+
constructor(iteration, chainKey) {
|
|
5
|
+
this.MESSAGE_KEY_SEED = Buffer.from([0x01]);
|
|
6
|
+
this.CHAIN_KEY_SEED = Buffer.from([0x02]);
|
|
7
|
+
this.iteration = iteration;
|
|
8
|
+
this.chainKey = Buffer.from(chainKey);
|
|
9
|
+
}
|
|
10
|
+
getIteration() {
|
|
11
|
+
return this.iteration;
|
|
12
|
+
}
|
|
13
|
+
getSenderMessageKey() {
|
|
14
|
+
return new SenderMessageKey(this.iteration, this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey));
|
|
15
|
+
}
|
|
16
|
+
getNext() {
|
|
17
|
+
return new SenderChainKey(this.iteration + 1, this.getDerivative(this.CHAIN_KEY_SEED, this.chainKey));
|
|
18
|
+
}
|
|
19
|
+
getSeed() {
|
|
20
|
+
return this.chainKey;
|
|
21
|
+
}
|
|
22
|
+
getDerivative(seed, key) {
|
|
23
|
+
return calculateMAC(key, seed);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { proto } from '../../../WAProto/index.js';
|
|
2
|
+
import { CiphertextMessage } from './ciphertext-message.js';
|
|
3
|
+
export class SenderKeyDistributionMessage extends CiphertextMessage {
|
|
4
|
+
constructor(id, iteration, chainKey, signatureKey, serialized) {
|
|
5
|
+
super();
|
|
6
|
+
if (serialized) {
|
|
7
|
+
try {
|
|
8
|
+
const message = serialized.slice(1);
|
|
9
|
+
const distributionMessage = proto.SenderKeyDistributionMessage.decode(message).toJSON();
|
|
10
|
+
this.serialized = serialized;
|
|
11
|
+
this.id = distributionMessage.id;
|
|
12
|
+
this.iteration = distributionMessage.iteration;
|
|
13
|
+
this.chainKey =
|
|
14
|
+
typeof distributionMessage.chainKey === 'string'
|
|
15
|
+
? Buffer.from(distributionMessage.chainKey, 'base64')
|
|
16
|
+
: distributionMessage.chainKey;
|
|
17
|
+
this.signatureKey =
|
|
18
|
+
typeof distributionMessage.signingKey === 'string'
|
|
19
|
+
? Buffer.from(distributionMessage.signingKey, 'base64')
|
|
20
|
+
: distributionMessage.signingKey;
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
throw new Error(String(e));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const version = this.intsToByteHighAndLow(this.CURRENT_VERSION, this.CURRENT_VERSION);
|
|
28
|
+
this.id = id;
|
|
29
|
+
this.iteration = iteration;
|
|
30
|
+
this.chainKey = chainKey;
|
|
31
|
+
this.signatureKey = signatureKey;
|
|
32
|
+
const message = proto.SenderKeyDistributionMessage.encode(proto.SenderKeyDistributionMessage.create({
|
|
33
|
+
id,
|
|
34
|
+
iteration,
|
|
35
|
+
chainKey,
|
|
36
|
+
signingKey: this.signatureKey
|
|
37
|
+
})).finish();
|
|
38
|
+
this.serialized = Buffer.concat([Buffer.from([version]), message]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
intsToByteHighAndLow(highValue, lowValue) {
|
|
42
|
+
return (((highValue << 4) | lowValue) & 0xff) % 256;
|
|
43
|
+
}
|
|
44
|
+
serialize() {
|
|
45
|
+
return this.serialized;
|
|
46
|
+
}
|
|
47
|
+
getType() {
|
|
48
|
+
return this.SENDERKEY_DISTRIBUTION_TYPE;
|
|
49
|
+
}
|
|
50
|
+
getIteration() {
|
|
51
|
+
return this.iteration;
|
|
52
|
+
}
|
|
53
|
+
getChainKey() {
|
|
54
|
+
return this.chainKey;
|
|
55
|
+
}
|
|
56
|
+
getSignatureKey() {
|
|
57
|
+
return this.signatureKey;
|
|
58
|
+
}
|
|
59
|
+
getId() {
|
|
60
|
+
return this.id;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { calculateSignature, verifySignature } from 'libsignal/src/curve';
|
|
2
|
+
import { proto } from '../../../WAProto/index.js';
|
|
3
|
+
import { CiphertextMessage } from './ciphertext-message.js';
|
|
4
|
+
export class SenderKeyMessage extends CiphertextMessage {
|
|
5
|
+
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
6
|
+
super();
|
|
7
|
+
this.SIGNATURE_LENGTH = 64;
|
|
8
|
+
if (serialized) {
|
|
9
|
+
const version = serialized[0];
|
|
10
|
+
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
|
|
11
|
+
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
12
|
+
const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON();
|
|
13
|
+
this.serialized = serialized;
|
|
14
|
+
this.messageVersion = (version & 0xff) >> 4;
|
|
15
|
+
this.keyId = senderKeyMessage.id;
|
|
16
|
+
this.iteration = senderKeyMessage.iteration;
|
|
17
|
+
this.ciphertext =
|
|
18
|
+
typeof senderKeyMessage.ciphertext === 'string'
|
|
19
|
+
? Buffer.from(senderKeyMessage.ciphertext, 'base64')
|
|
20
|
+
: senderKeyMessage.ciphertext;
|
|
21
|
+
this.signature = signature;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256;
|
|
25
|
+
const ciphertextBuffer = Buffer.from(ciphertext);
|
|
26
|
+
const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
|
|
27
|
+
id: keyId,
|
|
28
|
+
iteration: iteration,
|
|
29
|
+
ciphertext: ciphertextBuffer
|
|
30
|
+
})).finish();
|
|
31
|
+
const signature = this.getSignature(signatureKey, Buffer.concat([Buffer.from([version]), message]));
|
|
32
|
+
this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)]);
|
|
33
|
+
this.messageVersion = this.CURRENT_VERSION;
|
|
34
|
+
this.keyId = keyId;
|
|
35
|
+
this.iteration = iteration;
|
|
36
|
+
this.ciphertext = ciphertextBuffer;
|
|
37
|
+
this.signature = signature;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
getKeyId() {
|
|
41
|
+
return this.keyId;
|
|
42
|
+
}
|
|
43
|
+
getIteration() {
|
|
44
|
+
return this.iteration;
|
|
45
|
+
}
|
|
46
|
+
getCipherText() {
|
|
47
|
+
return this.ciphertext;
|
|
48
|
+
}
|
|
49
|
+
verifySignature(signatureKey) {
|
|
50
|
+
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
|
|
51
|
+
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
52
|
+
const res = verifySignature(signatureKey, part1, part2);
|
|
53
|
+
if (!res)
|
|
54
|
+
throw new Error('Invalid signature!');
|
|
55
|
+
}
|
|
56
|
+
getSignature(signatureKey, serialized) {
|
|
57
|
+
return Buffer.from(calculateSignature(signatureKey, serialized));
|
|
58
|
+
}
|
|
59
|
+
serialize() {
|
|
60
|
+
return this.serialized;
|
|
61
|
+
}
|
|
62
|
+
getType() {
|
|
63
|
+
return 4;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function isNull(str) {
|
|
2
|
+
return str === null || str === '';
|
|
3
|
+
}
|
|
4
|
+
function intValue(num) {
|
|
5
|
+
const MAX_VALUE = 0x7fffffff;
|
|
6
|
+
const MIN_VALUE = -0x80000000;
|
|
7
|
+
if (num > MAX_VALUE || num < MIN_VALUE) {
|
|
8
|
+
return num & 0xffffffff;
|
|
9
|
+
}
|
|
10
|
+
return num;
|
|
11
|
+
}
|
|
12
|
+
function hashCode(strKey) {
|
|
13
|
+
let hash = 0;
|
|
14
|
+
if (!isNull(strKey)) {
|
|
15
|
+
for (let i = 0; i < strKey.length; i++) {
|
|
16
|
+
hash = hash * 31 + strKey.charCodeAt(i);
|
|
17
|
+
hash = intValue(hash);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return hash;
|
|
21
|
+
}
|
|
22
|
+
export class SenderKeyName {
|
|
23
|
+
constructor(groupId, sender) {
|
|
24
|
+
this.groupId = groupId;
|
|
25
|
+
this.sender = sender;
|
|
26
|
+
}
|
|
27
|
+
getGroupId() {
|
|
28
|
+
return this.groupId;
|
|
29
|
+
}
|
|
30
|
+
getSender() {
|
|
31
|
+
return this.sender;
|
|
32
|
+
}
|
|
33
|
+
serialize() {
|
|
34
|
+
return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`;
|
|
35
|
+
}
|
|
36
|
+
toString() {
|
|
37
|
+
return this.serialize();
|
|
38
|
+
}
|
|
39
|
+
equals(other) {
|
|
40
|
+
if (other === null)
|
|
41
|
+
return false;
|
|
42
|
+
return this.groupId === other.groupId && this.sender.toString() === other.sender.toString();
|
|
43
|
+
}
|
|
44
|
+
hashCode() {
|
|
45
|
+
return hashCode(this.groupId) ^ hashCode(this.sender.toString());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BufferJSON } from '../../Utils/generics.js';
|
|
2
|
+
import { SenderKeyState } from './sender-key-state.js';
|
|
3
|
+
export class SenderKeyRecord {
|
|
4
|
+
constructor(serialized) {
|
|
5
|
+
this.MAX_STATES = 5;
|
|
6
|
+
this.senderKeyStates = [];
|
|
7
|
+
if (serialized) {
|
|
8
|
+
for (const structure of serialized) {
|
|
9
|
+
this.senderKeyStates.push(new SenderKeyState(null, null, null, null, null, null, structure));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
isEmpty() {
|
|
14
|
+
return this.senderKeyStates.length === 0;
|
|
15
|
+
}
|
|
16
|
+
getSenderKeyState(keyId) {
|
|
17
|
+
if (keyId === undefined && this.senderKeyStates.length) {
|
|
18
|
+
return this.senderKeyStates[this.senderKeyStates.length - 1];
|
|
19
|
+
}
|
|
20
|
+
return this.senderKeyStates.find(state => state.getKeyId() === keyId);
|
|
21
|
+
}
|
|
22
|
+
addSenderKeyState(id, iteration, chainKey, signatureKey) {
|
|
23
|
+
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, null, signatureKey));
|
|
24
|
+
if (this.senderKeyStates.length > this.MAX_STATES) {
|
|
25
|
+
this.senderKeyStates.shift();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
setSenderKeyState(id, iteration, chainKey, keyPair) {
|
|
29
|
+
this.senderKeyStates.length = 0;
|
|
30
|
+
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, keyPair));
|
|
31
|
+
}
|
|
32
|
+
serialize() {
|
|
33
|
+
return this.senderKeyStates.map(state => state.getStructure());
|
|
34
|
+
}
|
|
35
|
+
static deserialize(data) {
|
|
36
|
+
const str = Buffer.from(data).toString('utf-8');
|
|
37
|
+
const parsed = JSON.parse(str, BufferJSON.reviver);
|
|
38
|
+
return new SenderKeyRecord(parsed);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { SenderChainKey } from './sender-chain-key.js';
|
|
2
|
+
import { SenderMessageKey } from './sender-message-key.js';
|
|
3
|
+
export class SenderKeyState {
|
|
4
|
+
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
5
|
+
this.MAX_MESSAGE_KEYS = 2000;
|
|
6
|
+
if (senderKeyStateStructure) {
|
|
7
|
+
this.senderKeyStateStructure = {
|
|
8
|
+
...senderKeyStateStructure,
|
|
9
|
+
senderMessageKeys: Array.isArray(senderKeyStateStructure.senderMessageKeys)
|
|
10
|
+
? senderKeyStateStructure.senderMessageKeys
|
|
11
|
+
: []
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
if (signatureKeyPair) {
|
|
16
|
+
signatureKeyPublic = signatureKeyPair.public;
|
|
17
|
+
signatureKeyPrivate = signatureKeyPair.private;
|
|
18
|
+
}
|
|
19
|
+
this.senderKeyStateStructure = {
|
|
20
|
+
senderKeyId: id || 0,
|
|
21
|
+
senderChainKey: {
|
|
22
|
+
iteration: iteration || 0,
|
|
23
|
+
seed: Buffer.from(chainKey || [])
|
|
24
|
+
},
|
|
25
|
+
senderSigningKey: {
|
|
26
|
+
public: Buffer.from(signatureKeyPublic || []),
|
|
27
|
+
private: Buffer.from(signatureKeyPrivate || [])
|
|
28
|
+
},
|
|
29
|
+
senderMessageKeys: []
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
getKeyId() {
|
|
34
|
+
return this.senderKeyStateStructure.senderKeyId;
|
|
35
|
+
}
|
|
36
|
+
getSenderChainKey() {
|
|
37
|
+
return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
|
|
38
|
+
}
|
|
39
|
+
setSenderChainKey(chainKey) {
|
|
40
|
+
this.senderKeyStateStructure.senderChainKey = {
|
|
41
|
+
iteration: chainKey.getIteration(),
|
|
42
|
+
seed: chainKey.getSeed()
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
getSigningKeyPublic() {
|
|
46
|
+
const publicKey = Buffer.from(this.senderKeyStateStructure.senderSigningKey.public);
|
|
47
|
+
if (publicKey.length === 32) {
|
|
48
|
+
const fixed = Buffer.alloc(33);
|
|
49
|
+
fixed[0] = 0x05;
|
|
50
|
+
publicKey.copy(fixed, 1);
|
|
51
|
+
return fixed;
|
|
52
|
+
}
|
|
53
|
+
return publicKey;
|
|
54
|
+
}
|
|
55
|
+
getSigningKeyPrivate() {
|
|
56
|
+
const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
|
|
57
|
+
return Buffer.from(privateKey || []);
|
|
58
|
+
}
|
|
59
|
+
hasSenderMessageKey(iteration) {
|
|
60
|
+
return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration);
|
|
61
|
+
}
|
|
62
|
+
addSenderMessageKey(senderMessageKey) {
|
|
63
|
+
this.senderKeyStateStructure.senderMessageKeys.push({
|
|
64
|
+
iteration: senderMessageKey.getIteration(),
|
|
65
|
+
seed: senderMessageKey.getSeed()
|
|
66
|
+
});
|
|
67
|
+
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
68
|
+
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
removeSenderMessageKey(iteration) {
|
|
72
|
+
const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration);
|
|
73
|
+
if (index !== -1) {
|
|
74
|
+
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
|
|
75
|
+
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
|
|
76
|
+
return new SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
getStructure() {
|
|
81
|
+
return this.senderKeyStateStructure;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { deriveSecrets } from 'libsignal/src/crypto';
|
|
2
|
+
export class SenderMessageKey {
|
|
3
|
+
constructor(iteration, seed) {
|
|
4
|
+
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
5
|
+
const keys = new Uint8Array(32);
|
|
6
|
+
keys.set(new Uint8Array(derivative[0].slice(16)));
|
|
7
|
+
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
8
|
+
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
9
|
+
this.cipherKey = Buffer.from(keys.buffer);
|
|
10
|
+
this.iteration = iteration;
|
|
11
|
+
this.seed = seed;
|
|
12
|
+
}
|
|
13
|
+
getIteration() {
|
|
14
|
+
return this.iteration;
|
|
15
|
+
}
|
|
16
|
+
getIv() {
|
|
17
|
+
return this.iv;
|
|
18
|
+
}
|
|
19
|
+
getCipherKey() {
|
|
20
|
+
return this.cipherKey;
|
|
21
|
+
}
|
|
22
|
+
getSeed() {
|
|
23
|
+
return this.seed;
|
|
24
|
+
}
|
|
25
|
+
}
|