@badzz88/baileys 8.5.6 → 8.5.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/README.md +337 -1055
- package/WAProto/WAProto.proto +28 -1189
- package/WAProto/fix-imports.js +79 -69
- package/WAProto/index.d.ts +71491 -15254
- package/WAProto/index.js +126436 -19814
- package/engine-requirements.js +8 -15
- package/lib/Defaults/index.js +130 -0
- package/{src → lib}/Signal/Group/ciphertext-message.js +2 -5
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/{src → lib}/Signal/Group/group_cipher.js +11 -11
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/{src → lib}/Signal/Group/sender-chain-key.js +6 -9
- package/{src → lib}/Signal/Group/sender-key-distribution-message.js +6 -9
- package/{src → lib}/Signal/Group/sender-key-message.js +9 -12
- package/{src → lib}/Signal/Group/sender-key-name.js +2 -5
- package/{src → lib}/Signal/Group/sender-key-record.js +8 -11
- package/{src → lib}/Signal/Group/sender-key-state.js +6 -9
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/{src → lib}/Signal/libsignal.js +131 -155
- package/{src → lib}/Signal/lid-mapping.js +27 -23
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.js +11 -0
- package/{src → lib}/Socket/Client/websocket.js +11 -18
- package/{src → lib}/Socket/business.js +35 -67
- package/{src → lib}/Socket/chats.js +294 -550
- package/{src → lib}/Socket/communities.js +82 -114
- package/lib/Socket/graphql.js +716 -0
- package/lib/Socket/groups.js +374 -0
- package/lib/Socket/index.js +18 -0
- package/lib/Socket/interop.js +463 -0
- package/{src → lib}/Socket/luxu.js +120 -82
- package/lib/Socket/messages-recv.js +1916 -0
- package/lib/Socket/messages-send.js +1436 -0
- package/lib/Socket/mex.js +54 -0
- package/lib/Socket/newsletter.js +757 -0
- package/lib/Socket/privacy.js +318 -0
- package/{src → lib}/Socket/socket.js +356 -244
- package/lib/Socket/username.js +236 -0
- package/lib/Store/index.js +10 -0
- package/{src → lib}/Store/keyed-db.js +11 -21
- package/lib/Store/make-cache-manager-store.js +85 -0
- package/lib/Store/make-in-memory-store.js +244 -0
- package/{src → lib}/Store/make-ordered-dictionary.js +19 -25
- package/{src → lib}/Store/object-repository.js +11 -5
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Mex.js +111 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +26 -0
- package/{src → lib}/Utils/auth-utils.js +91 -43
- package/lib/Utils/browser-utils.js +48 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/chat-utils.js +872 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/crypto.js +118 -0
- package/lib/Utils/decode-wa-message.js +350 -0
- package/{src → lib}/Utils/event-buffer.js +81 -39
- package/lib/Utils/generics.js +403 -0
- package/lib/Utils/history.js +134 -0
- package/{src → lib}/Utils/identity-change-handler.js +9 -11
- package/lib/Utils/index.js +23 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.js +8 -0
- package/{src → lib}/Utils/make-mutex.js +7 -10
- package/lib/Utils/message-composer.js +273 -0
- package/{src → lib}/Utils/message-retry-manager.js +76 -28
- package/lib/Utils/messages-media.js +870 -0
- package/lib/Utils/messages.js +1337 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/{src → lib}/Utils/offline-node-processor.js +10 -4
- package/{src → lib}/Utils/pre-key-manager.js +27 -11
- package/lib/Utils/process-message.js +630 -0
- package/{src → lib}/Utils/reporting-utils.js +12 -15
- package/lib/Utils/signal.js +201 -0
- package/{src → lib}/Utils/stanza-ack.js +12 -4
- package/lib/Utils/sticker.js +110 -0
- package/{src → lib}/Utils/sync-action-utils.js +14 -10
- package/{src → lib}/Utils/tc-token-utils.js +48 -43
- package/{src → lib}/Utils/use-multi-file-auth-state.js +35 -25
- package/lib/Utils/validate-connection.js +203 -0
- package/{src → lib}/WABinary/constants.js +9 -12
- package/{src → lib}/WABinary/decode.js +38 -118
- package/{src → lib}/WABinary/encode.js +6 -11
- package/lib/WABinary/generic-utils.js +204 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.js +98 -0
- package/lib/WABinary/types.js +2 -0
- package/{src → lib}/WAM/BinaryInfo.js +2 -5
- package/{src → lib}/WAM/constants.js +4 -16635
- package/{src → lib}/WAM/encode.js +18 -17
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +58 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
- package/lib/WAUSync/Protocols/index.js +12 -0
- package/lib/WAUSync/USyncQuery.js +151 -0
- package/lib/WAUSync/USyncUser.js +56 -0
- package/lib/WAUSync/index.js +3 -0
- package/{src → lib}/index.js +16 -51
- package/package.json +129 -99
- package/LICENSE +0 -21
- package/src/Defaults/index.js +0 -186
- package/src/Defaults/phonenumber-mcc.json +0 -223
- package/src/Signal/Group/group-session-builder.js +0 -86
- package/src/Signal/Group/index.js +0 -140
- package/src/Signal/Group/keyhelper.js +0 -77
- package/src/Signal/Group/sender-message-key.js +0 -29
- package/src/Socket/Client/index.js +0 -31
- package/src/Socket/Client/types.js +0 -13
- package/src/Socket/aigroups.js +0 -221
- package/src/Socket/graphql.js +0 -523
- package/src/Socket/groups.js +0 -516
- package/src/Socket/index.js +0 -31
- package/src/Socket/interactive-handler.js +0 -527
- package/src/Socket/interop.js +0 -339
- package/src/Socket/managed-account.js +0 -98
- package/src/Socket/messages-recv.js +0 -2685
- package/src/Socket/messages-send.js +0 -2047
- package/src/Socket/mex.js +0 -57
- package/src/Socket/newsletter.js +0 -455
- package/src/Socket/privacy.js +0 -125
- package/src/Socket/registration.js +0 -236
- package/src/Socket/text-router.js +0 -65
- package/src/Socket/username.js +0 -130
- package/src/Store/index.js +0 -33
- package/src/Store/make-cache-manager-store.js +0 -84
- package/src/Store/make-in-memory-store.js +0 -551
- package/src/Types/Auth.js +0 -31
- package/src/Types/Bussines.js +0 -2
- package/src/Types/Call.js +0 -2
- package/src/Types/Chat.js +0 -4
- package/src/Types/Contact.js +0 -2
- package/src/Types/Events.js +0 -2
- package/src/Types/GroupMetadata.js +0 -2
- package/src/Types/Label.js +0 -26
- package/src/Types/LabelAssociation.js +0 -8
- package/src/Types/Message.js +0 -93
- package/src/Types/Mex.js +0 -112
- package/src/Types/Newsletter.js +0 -109
- package/src/Types/Product.js +0 -2
- package/src/Types/Signal.js +0 -2
- package/src/Types/Socket.js +0 -2
- package/src/Types/State.js +0 -62
- package/src/Types/USync.js +0 -2
- package/src/Types/index.js +0 -56
- package/src/Utils/browser-utils.js +0 -112
- package/src/Utils/business.js +0 -240
- package/src/Utils/chat-utils.js +0 -1230
- package/src/Utils/command-loader.d.ts +0 -27
- package/src/Utils/command-loader.js +0 -89
- package/src/Utils/companion-reg-client-utils.js +0 -40
- package/src/Utils/consumer-application.js +0 -105
- package/src/Utils/crypto.js +0 -118
- package/src/Utils/curve25519-js.js +0 -242
- package/src/Utils/decode-wa-message.js +0 -529
- package/src/Utils/generics.js +0 -483
- package/src/Utils/group-history.js +0 -44
- package/src/Utils/history.js +0 -232
- package/src/Utils/index.js +0 -58
- package/src/Utils/jid-display-normalization.js +0 -195
- package/src/Utils/link-preview.js +0 -135
- package/src/Utils/logger.js +0 -8
- package/src/Utils/lt-hash.js +0 -25
- package/src/Utils/message-composer.js +0 -471
- package/src/Utils/messages-media.js +0 -843
- package/src/Utils/messages.js +0 -2817
- package/src/Utils/meta-ai-msmsg.js +0 -222
- package/src/Utils/native-bridge.js +0 -68
- package/src/Utils/noise-handler.js +0 -169
- package/src/Utils/process-message.js +0 -950
- package/src/Utils/session-pool.d.ts +0 -14
- package/src/Utils/session-pool.js +0 -70
- package/src/Utils/signal.js +0 -217
- package/src/Utils/sticker.d.ts +0 -13
- package/src/Utils/sticker.js +0 -123
- package/src/Utils/validate-connection.js +0 -209
- package/src/Utils/view-once-cache.d.ts +0 -12
- package/src/Utils/view-once-cache.js +0 -63
- package/src/Utils/voip-rekey.js +0 -22
- package/src/WABinary/generic-utils.js +0 -238
- package/src/WABinary/index.js +0 -34
- package/src/WABinary/jid-utils.js +0 -351
- package/src/WABinary/types.js +0 -2
- package/src/WAM/index.js +0 -32
- package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -53
- package/src/WAUSync/Protocols/USyncBusinessProtocol.js +0 -44
- package/src/WAUSync/Protocols/USyncContactProtocol.js +0 -55
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +0 -55
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -31
- package/src/WAUSync/Protocols/USyncFeatureProtocol.js +0 -54
- package/src/WAUSync/Protocols/USyncLIDProtocol.js +0 -32
- package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -473
- package/src/WAUSync/Protocols/USyncPictureProtocol.js +0 -34
- package/src/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
- package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
- package/src/WAUSync/Protocols/index.js +0 -40
- package/src/WAUSync/USyncQuery.js +0 -126
- package/src/WAUSync/USyncUser.js +0 -50
- package/src/WAUSync/index.js +0 -32
- package/src/antiban.js +0 -4152
package/engine-requirements.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
const major = parseInt(process.versions.node.split(
|
|
2
|
-
if (major < 20) {
|
|
3
|
-
console.error(`
|
|
4
|
-
━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
5
|
-
🚫 Unsupported Node.js Version
|
|
6
|
-
|
|
7
|
-
• Current : v${process.versions.node}
|
|
8
|
-
• Required : v20.0.0+
|
|
1
|
+
const major = parseInt(process.versions.node.split('.')[0], 10);
|
|
9
2
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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);
|
|
17
10
|
}
|
|
@@ -0,0 +1,130 @@
|
|
|
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: 60 * 60, // 1 hour
|
|
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
|
+
aiLabel: true,
|
|
64
|
+
syncFullHistory: true,
|
|
65
|
+
patchMessageBeforeSending: msg => msg,
|
|
66
|
+
shouldSyncHistoryMessage: ({ syncType }) => {
|
|
67
|
+
return syncType !== proto.HistorySync.HistorySyncType.FULL;
|
|
68
|
+
},
|
|
69
|
+
shouldIgnoreJid: () => false,
|
|
70
|
+
linkPreviewImageThumbnailWidth: 192,
|
|
71
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
72
|
+
generateHighQualityLinkPreview: false,
|
|
73
|
+
enableAutoSessionRecreation: true,
|
|
74
|
+
enableRecentMessageCache: true,
|
|
75
|
+
options: {},
|
|
76
|
+
appStateMacVerification: {
|
|
77
|
+
patch: false,
|
|
78
|
+
snapshot: false
|
|
79
|
+
},
|
|
80
|
+
countryCode: 'US',
|
|
81
|
+
getMessage: async () => undefined,
|
|
82
|
+
cachedGroupMetadata: async () => undefined,
|
|
83
|
+
makeSignalRepository: makeLibSignalRepository
|
|
84
|
+
};
|
|
85
|
+
export const MEDIA_PATH_MAP = {
|
|
86
|
+
image: '/mms/image',
|
|
87
|
+
video: '/mms/video',
|
|
88
|
+
document: '/mms/document',
|
|
89
|
+
audio: '/mms/audio',
|
|
90
|
+
sticker: '/mms/image',
|
|
91
|
+
'thumbnail-link': '/mms/image',
|
|
92
|
+
'product-catalog-image': '/product/image',
|
|
93
|
+
'md-app-state': '',
|
|
94
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
95
|
+
'biz-cover-photo': '/pps/biz-cover-photo'
|
|
96
|
+
};
|
|
97
|
+
export const MEDIA_HKDF_KEY_MAPPING = {
|
|
98
|
+
audio: 'Audio',
|
|
99
|
+
document: 'Document',
|
|
100
|
+
gif: 'Video',
|
|
101
|
+
image: 'Image',
|
|
102
|
+
ppic: '',
|
|
103
|
+
product: 'Image',
|
|
104
|
+
ptt: 'Audio',
|
|
105
|
+
sticker: 'Image',
|
|
106
|
+
video: 'Video',
|
|
107
|
+
'thumbnail-document': 'Document Thumbnail',
|
|
108
|
+
'thumbnail-image': 'Image Thumbnail',
|
|
109
|
+
'thumbnail-video': 'Video Thumbnail',
|
|
110
|
+
'thumbnail-link': 'Link Thumbnail',
|
|
111
|
+
'md-msg-hist': 'History',
|
|
112
|
+
'md-app-state': 'App State',
|
|
113
|
+
'product-catalog-image': '',
|
|
114
|
+
'payment-bg-image': 'Payment Background',
|
|
115
|
+
ptv: 'Video',
|
|
116
|
+
'biz-cover-photo': 'Image'
|
|
117
|
+
};
|
|
118
|
+
export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP);
|
|
119
|
+
/** 120s timeout for history sync stall detection, same as WA Web's handleChunkProgress / restartPausedTimer (g = 120) */
|
|
120
|
+
export const HISTORY_SYNC_PAUSED_TIMEOUT_MS = 120000;
|
|
121
|
+
export const MIN_PREKEY_COUNT = 5;
|
|
122
|
+
export const INITIAL_PREKEY_COUNT = 812;
|
|
123
|
+
export const UPLOAD_TIMEOUT = 30000; // 30 seconds
|
|
124
|
+
export const TimeMs = {
|
|
125
|
+
Minute: 60 * 1000,
|
|
126
|
+
Hour: 60 * 60 * 1000,
|
|
127
|
+
Day: 24 * 60 * 60 * 1000,
|
|
128
|
+
Week: 7 * 24 * 60 * 60 * 1000
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.CiphertextMessage = void 0;
|
|
4
|
-
class CiphertextMessage {
|
|
1
|
+
export class CiphertextMessage {
|
|
5
2
|
constructor() {
|
|
6
3
|
this.UNSUPPORTED_VERSION = 1;
|
|
7
4
|
this.CURRENT_VERSION = 3;
|
|
@@ -12,4 +9,4 @@ class CiphertextMessage {
|
|
|
12
9
|
this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
|
|
13
10
|
}
|
|
14
11
|
}
|
|
15
|
-
|
|
12
|
+
//# sourceMappingURL=ciphertext-message.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|
|
30
|
+
//# sourceMappingURL=group-session-builder.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class GroupCipher {
|
|
1
|
+
import { decrypt, encrypt } from 'libsignal/src/crypto.js';
|
|
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
7
|
constructor(senderKeyStore, senderKeyName) {
|
|
8
8
|
this.senderKeyStore = senderKeyStore;
|
|
9
9
|
this.senderKeyName = senderKeyName;
|
|
@@ -20,7 +20,7 @@ class GroupCipher {
|
|
|
20
20
|
const iteration = senderKeyState.getSenderChainKey().getIteration();
|
|
21
21
|
const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1);
|
|
22
22
|
const ciphertext = await this.getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext);
|
|
23
|
-
const senderKeyMessage = new
|
|
23
|
+
const senderKeyMessage = new SenderKeyMessage(senderKeyState.getKeyId(), senderKey.getIteration(), ciphertext, senderKeyState.getSigningKeyPrivate());
|
|
24
24
|
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
|
|
25
25
|
return senderKeyMessage.serialize();
|
|
26
26
|
}
|
|
@@ -29,7 +29,7 @@ class GroupCipher {
|
|
|
29
29
|
if (!record) {
|
|
30
30
|
throw new Error('No SenderKeyRecord found for decryption');
|
|
31
31
|
}
|
|
32
|
-
const senderKeyMessage = new
|
|
32
|
+
const senderKeyMessage = new SenderKeyMessage(null, null, null, null, senderKeyMessageBytes);
|
|
33
33
|
const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());
|
|
34
34
|
if (!senderKeyState) {
|
|
35
35
|
throw new Error('No session found to decrypt message');
|
|
@@ -64,7 +64,7 @@ class GroupCipher {
|
|
|
64
64
|
}
|
|
65
65
|
async getPlainText(iv, key, ciphertext) {
|
|
66
66
|
try {
|
|
67
|
-
return
|
|
67
|
+
return decrypt(key, ciphertext, iv);
|
|
68
68
|
}
|
|
69
69
|
catch (e) {
|
|
70
70
|
throw new Error('InvalidMessageException');
|
|
@@ -72,11 +72,11 @@ class GroupCipher {
|
|
|
72
72
|
}
|
|
73
73
|
async getCipherText(iv, key, plaintext) {
|
|
74
74
|
try {
|
|
75
|
-
return
|
|
75
|
+
return encrypt(key, plaintext, iv);
|
|
76
76
|
}
|
|
77
77
|
catch (e) {
|
|
78
78
|
throw new Error('InvalidMessageException');
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
//# sourceMappingURL=group_cipher.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
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';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as nodeCrypto from 'crypto';
|
|
2
|
+
import { generateKeyPair } from 'libsignal/src/curve.js';
|
|
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
|
+
}
|
|
18
|
+
//# sourceMappingURL=keyhelper.js.map
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const Crypto_1 = require('../../Utils/crypto');
|
|
5
|
-
const sender_message_key_1 = require('./sender-message-key');
|
|
6
|
-
class SenderChainKey {
|
|
1
|
+
import { calculateMAC } from 'libsignal/src/crypto.js';
|
|
2
|
+
import { SenderMessageKey } from './sender-message-key.js';
|
|
3
|
+
export class SenderChainKey {
|
|
7
4
|
constructor(iteration, chainKey) {
|
|
8
5
|
this.MESSAGE_KEY_SEED = Buffer.from([0x01]);
|
|
9
6
|
this.CHAIN_KEY_SEED = Buffer.from([0x02]);
|
|
@@ -14,7 +11,7 @@ class SenderChainKey {
|
|
|
14
11
|
return this.iteration;
|
|
15
12
|
}
|
|
16
13
|
getSenderMessageKey() {
|
|
17
|
-
return new
|
|
14
|
+
return new SenderMessageKey(this.iteration, this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey));
|
|
18
15
|
}
|
|
19
16
|
getNext() {
|
|
20
17
|
return new SenderChainKey(this.iteration + 1, this.getDerivative(this.CHAIN_KEY_SEED, this.chainKey));
|
|
@@ -23,7 +20,7 @@ class SenderChainKey {
|
|
|
23
20
|
return this.chainKey;
|
|
24
21
|
}
|
|
25
22
|
getDerivative(seed, key) {
|
|
26
|
-
return
|
|
23
|
+
return calculateMAC(key, seed);
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
|
-
|
|
26
|
+
//# sourceMappingURL=sender-chain-key.js.map
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const index_js_1 = require('../../../WAProto/index.js');
|
|
5
|
-
const ciphertext_message_1 = require('./ciphertext-message');
|
|
6
|
-
class SenderKeyDistributionMessage extends ciphertext_message_1.CiphertextMessage {
|
|
1
|
+
import { proto } from '../../../WAProto/index.js';
|
|
2
|
+
import { CiphertextMessage } from './ciphertext-message.js';
|
|
3
|
+
export class SenderKeyDistributionMessage extends CiphertextMessage {
|
|
7
4
|
constructor(id, iteration, chainKey, signatureKey, serialized) {
|
|
8
5
|
super();
|
|
9
6
|
if (serialized) {
|
|
10
7
|
try {
|
|
11
8
|
const message = serialized.slice(1);
|
|
12
|
-
const distributionMessage =
|
|
9
|
+
const distributionMessage = proto.SenderKeyDistributionMessage.decode(message).toJSON();
|
|
13
10
|
this.serialized = serialized;
|
|
14
11
|
this.id = distributionMessage.id;
|
|
15
12
|
this.iteration = distributionMessage.iteration;
|
|
@@ -32,7 +29,7 @@ class SenderKeyDistributionMessage extends ciphertext_message_1.CiphertextMessag
|
|
|
32
29
|
this.iteration = iteration;
|
|
33
30
|
this.chainKey = chainKey;
|
|
34
31
|
this.signatureKey = signatureKey;
|
|
35
|
-
const message =
|
|
32
|
+
const message = proto.SenderKeyDistributionMessage.encode(proto.SenderKeyDistributionMessage.create({
|
|
36
33
|
id,
|
|
37
34
|
iteration,
|
|
38
35
|
chainKey,
|
|
@@ -63,4 +60,4 @@ class SenderKeyDistributionMessage extends ciphertext_message_1.CiphertextMessag
|
|
|
63
60
|
return this.id;
|
|
64
61
|
}
|
|
65
62
|
}
|
|
66
|
-
|
|
63
|
+
//# sourceMappingURL=sender-key-distribution-message.js.map
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const index_js_1 = require('../../../WAProto/index.js');
|
|
6
|
-
const ciphertext_message_1 = require('./ciphertext-message');
|
|
7
|
-
class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
1
|
+
import { calculateSignature, verifySignature } from 'libsignal/src/curve.js';
|
|
2
|
+
import { proto } from '../../../WAProto/index.js';
|
|
3
|
+
import { CiphertextMessage } from './ciphertext-message.js';
|
|
4
|
+
export class SenderKeyMessage extends CiphertextMessage {
|
|
8
5
|
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
9
6
|
super();
|
|
10
7
|
this.SIGNATURE_LENGTH = 64;
|
|
@@ -12,7 +9,7 @@ class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
|
12
9
|
const version = serialized[0];
|
|
13
10
|
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
|
|
14
11
|
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
15
|
-
const senderKeyMessage =
|
|
12
|
+
const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON();
|
|
16
13
|
this.serialized = serialized;
|
|
17
14
|
this.messageVersion = (version & 0xff) >> 4;
|
|
18
15
|
this.keyId = senderKeyMessage.id;
|
|
@@ -26,7 +23,7 @@ class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
|
26
23
|
else {
|
|
27
24
|
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256;
|
|
28
25
|
const ciphertextBuffer = Buffer.from(ciphertext);
|
|
29
|
-
const message =
|
|
26
|
+
const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
|
|
30
27
|
id: keyId,
|
|
31
28
|
iteration: iteration,
|
|
32
29
|
ciphertext: ciphertextBuffer
|
|
@@ -52,12 +49,12 @@ class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
|
52
49
|
verifySignature(signatureKey) {
|
|
53
50
|
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
|
|
54
51
|
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
55
|
-
const res =
|
|
52
|
+
const res = verifySignature(signatureKey, part1, part2);
|
|
56
53
|
if (!res)
|
|
57
54
|
throw new Error('Invalid signature!');
|
|
58
55
|
}
|
|
59
56
|
getSignature(signatureKey, serialized) {
|
|
60
|
-
return Buffer.from(
|
|
57
|
+
return Buffer.from(calculateSignature(signatureKey, serialized));
|
|
61
58
|
}
|
|
62
59
|
serialize() {
|
|
63
60
|
return this.serialized;
|
|
@@ -66,4 +63,4 @@ class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
|
66
63
|
return 4;
|
|
67
64
|
}
|
|
68
65
|
}
|
|
69
|
-
|
|
66
|
+
//# sourceMappingURL=sender-key-message.js.map
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.SenderKeyName = void 0;
|
|
4
1
|
function isNull(str) {
|
|
5
2
|
return str === null || str === '';
|
|
6
3
|
}
|
|
@@ -22,7 +19,7 @@ function hashCode(strKey) {
|
|
|
22
19
|
}
|
|
23
20
|
return hash;
|
|
24
21
|
}
|
|
25
|
-
class SenderKeyName {
|
|
22
|
+
export class SenderKeyName {
|
|
26
23
|
constructor(groupId, sender) {
|
|
27
24
|
this.groupId = groupId;
|
|
28
25
|
this.sender = sender;
|
|
@@ -48,4 +45,4 @@ class SenderKeyName {
|
|
|
48
45
|
return hashCode(this.groupId) ^ hashCode(this.sender.toString());
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
|
-
|
|
48
|
+
//# sourceMappingURL=sender-key-name.js.map
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const generics_1 = require('../../Utils/generics');
|
|
5
|
-
const sender_key_state_1 = require('./sender-key-state');
|
|
6
|
-
class SenderKeyRecord {
|
|
1
|
+
import { BufferJSON } from '../../Utils/generics.js';
|
|
2
|
+
import { SenderKeyState } from './sender-key-state.js';
|
|
3
|
+
export class SenderKeyRecord {
|
|
7
4
|
constructor(serialized) {
|
|
8
5
|
this.MAX_STATES = 5;
|
|
9
6
|
this.senderKeyStates = [];
|
|
10
7
|
if (serialized) {
|
|
11
8
|
for (const structure of serialized) {
|
|
12
|
-
this.senderKeyStates.push(new
|
|
9
|
+
this.senderKeyStates.push(new SenderKeyState(null, null, null, null, null, null, structure));
|
|
13
10
|
}
|
|
14
11
|
}
|
|
15
12
|
}
|
|
@@ -23,22 +20,22 @@ class SenderKeyRecord {
|
|
|
23
20
|
return this.senderKeyStates.find(state => state.getKeyId() === keyId);
|
|
24
21
|
}
|
|
25
22
|
addSenderKeyState(id, iteration, chainKey, signatureKey) {
|
|
26
|
-
this.senderKeyStates.push(new
|
|
23
|
+
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, null, signatureKey));
|
|
27
24
|
if (this.senderKeyStates.length > this.MAX_STATES) {
|
|
28
25
|
this.senderKeyStates.shift();
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
28
|
setSenderKeyState(id, iteration, chainKey, keyPair) {
|
|
32
29
|
this.senderKeyStates.length = 0;
|
|
33
|
-
this.senderKeyStates.push(new
|
|
30
|
+
this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, keyPair));
|
|
34
31
|
}
|
|
35
32
|
serialize() {
|
|
36
33
|
return this.senderKeyStates.map(state => state.getStructure());
|
|
37
34
|
}
|
|
38
35
|
static deserialize(data) {
|
|
39
36
|
const str = Buffer.from(data).toString('utf-8');
|
|
40
|
-
const parsed = JSON.parse(str,
|
|
37
|
+
const parsed = JSON.parse(str, BufferJSON.reviver);
|
|
41
38
|
return new SenderKeyRecord(parsed);
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
|
-
|
|
41
|
+
//# sourceMappingURL=sender-key-record.js.map
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const sender_chain_key_1 = require('./sender-chain-key');
|
|
5
|
-
const sender_message_key_1 = require('./sender-message-key');
|
|
6
|
-
class SenderKeyState {
|
|
1
|
+
import { SenderChainKey } from './sender-chain-key.js';
|
|
2
|
+
import { SenderMessageKey } from './sender-message-key.js';
|
|
3
|
+
export class SenderKeyState {
|
|
7
4
|
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
8
5
|
this.MAX_MESSAGE_KEYS = 2000;
|
|
9
6
|
if (senderKeyStateStructure) {
|
|
@@ -37,7 +34,7 @@ class SenderKeyState {
|
|
|
37
34
|
return this.senderKeyStateStructure.senderKeyId;
|
|
38
35
|
}
|
|
39
36
|
getSenderChainKey() {
|
|
40
|
-
return new
|
|
37
|
+
return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
|
|
41
38
|
}
|
|
42
39
|
setSenderChainKey(chainKey) {
|
|
43
40
|
this.senderKeyStateStructure.senderChainKey = {
|
|
@@ -76,7 +73,7 @@ class SenderKeyState {
|
|
|
76
73
|
if (index !== -1) {
|
|
77
74
|
const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
|
|
78
75
|
this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
|
|
79
|
-
return new
|
|
76
|
+
return new SenderMessageKey(messageKey.iteration, messageKey.seed);
|
|
80
77
|
}
|
|
81
78
|
return null;
|
|
82
79
|
}
|
|
@@ -84,4 +81,4 @@ class SenderKeyState {
|
|
|
84
81
|
return this.senderKeyStateStructure;
|
|
85
82
|
}
|
|
86
83
|
}
|
|
87
|
-
|
|
84
|
+
//# sourceMappingURL=sender-key-state.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { deriveSecrets } from 'libsignal/src/crypto.js';
|
|
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
|
+
}
|
|
26
|
+
//# sourceMappingURL=sender-message-key.js.map
|