@bellaxchuu/flowred 0.8.6
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 +214 -0
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +6902 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.js +242946 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.js +190 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +92 -0
- package/lib/Signal/Group/group_cipher.js +89 -0
- package/lib/Signal/Group/index.js +136 -0
- package/lib/Signal/Group/keyhelper.js +73 -0
- package/lib/Signal/Group/sender-chain-key.js +32 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.js +50 -0
- package/lib/Signal/Group/sender-key-record.js +44 -0
- package/lib/Signal/Group/sender-key-state.js +97 -0
- package/lib/Signal/Group/sender-message-key.js +30 -0
- package/lib/Signal/libsignal.js +490 -0
- package/lib/Signal/lid-mapping.js +262 -0
- package/lib/Socket/Client/index.js +30 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +62 -0
- package/lib/Socket/aigroups.js +240 -0
- package/lib/Socket/business.js +422 -0
- package/lib/Socket/chats.js +1816 -0
- package/lib/Socket/communities.js +549 -0
- package/lib/Socket/graphql.js +656 -0
- package/lib/Socket/groups.js +764 -0
- package/lib/Socket/index.js +39 -0
- package/lib/Socket/interactive-handler.js +522 -0
- package/lib/Socket/interop.js +549 -0
- package/lib/Socket/luxu.js +387 -0
- package/lib/Socket/managed-account.js +183 -0
- package/lib/Socket/messages-recv.js +2440 -0
- package/lib/Socket/messages-send.js +1853 -0
- package/lib/Socket/mex.js +60 -0
- package/lib/Socket/newsletter.js +820 -0
- package/lib/Socket/privacy.js +449 -0
- package/lib/Socket/registration.js +427 -0
- package/lib/Socket/socket.js +1092 -0
- package/lib/Socket/text-router.js +83 -0
- package/lib/Socket/username.js +243 -0
- package/lib/Store/index.js +36 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +90 -0
- package/lib/Store/make-in-memory-store.js +604 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.js +29 -0
- package/lib/Types/Auth.js +38 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +4 -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 +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +95 -0
- package/lib/Types/Mex.js +112 -0
- package/lib/Types/Newsletter.js +121 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +70 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +55 -0
- package/lib/Utils/auth-utils.js +306 -0
- package/lib/Utils/browser-utils.js +114 -0
- package/lib/Utils/business.js +247 -0
- package/lib/Utils/chat-utils.js +1208 -0
- package/lib/Utils/command-loader.js +100 -0
- package/lib/Utils/companion-reg-client-utils.js +42 -0
- package/lib/Utils/consumer-application.js +107 -0
- package/lib/Utils/crypto.js +155 -0
- package/lib/Utils/curve25519-js.js +275 -0
- package/lib/Utils/decode-wa-message.js +560 -0
- package/lib/Utils/event-buffer.js +607 -0
- package/lib/Utils/generics.js +563 -0
- package/lib/Utils/group-history.js +60 -0
- package/lib/Utils/history.js +244 -0
- package/lib/Utils/identity-change-handler.js +52 -0
- package/lib/Utils/index.js +57 -0
- package/lib/Utils/jid-display-normalization.js +218 -0
- package/lib/Utils/link-preview.js +143 -0
- package/lib/Utils/logger.js +9 -0
- package/lib/Utils/lt-hash.js +39 -0
- package/lib/Utils/make-mutex.js +36 -0
- package/lib/Utils/message-composer.js +479 -0
- package/lib/Utils/message-retry-manager.js +270 -0
- package/lib/Utils/messages-media.js +896 -0
- package/lib/Utils/messages.js +2904 -0
- package/lib/Utils/meta-ai-msmsg.js +262 -0
- package/lib/Utils/native-bridge.js +82 -0
- package/lib/Utils/noise-handler.js +196 -0
- package/lib/Utils/offline-node-processor.js +42 -0
- package/lib/Utils/pre-key-manager.js +107 -0
- package/lib/Utils/process-message.js +1048 -0
- package/lib/Utils/reporting-utils.js +262 -0
- package/lib/Utils/session-pool.js +94 -0
- package/lib/Utils/signal.js +224 -0
- package/lib/Utils/stanza-ack.js +40 -0
- package/lib/Utils/sticker.js +145 -0
- package/lib/Utils/sync-action-utils.js +54 -0
- package/lib/Utils/tc-token-utils.js +161 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/validate-connection.js +219 -0
- package/lib/Utils/view-once-cache.js +79 -0
- package/lib/Utils/voip-rekey.js +22 -0
- package/lib/WABinary/constants.js +1304 -0
- package/lib/WABinary/decode.js +343 -0
- package/lib/WABinary/encode.js +228 -0
- package/lib/WABinary/generic-utils.js +240 -0
- package/lib/WABinary/index.js +33 -0
- package/lib/WABinary/jid-utils.js +361 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +39486 -0
- package/lib/WAM/encode.js +142 -0
- package/lib/WAM/index.js +31 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -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 +59 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -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 +39 -0
- package/lib/WAUSync/USyncQuery.js +133 -0
- package/lib/WAUSync/USyncUser.js +50 -0
- package/lib/WAUSync/index.js +31 -0
- package/lib/antiban.js +4637 -0
- package/lib/index.js +45 -0
- package/package.json +107 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const major = parseInt(process.versions.node.split('.')[0], 10);
|
|
2
|
+
|
|
3
|
+
if (major < 20) {
|
|
4
|
+
console.warn(
|
|
5
|
+
`\n⚠️ WARNING: This package recommends Node.js 20+ for optimal performance.\n` +
|
|
6
|
+
` You are using Node.js ${process.versions.node}.\n` +
|
|
7
|
+
` Consider upgrading to Node.js 20+ for better compatibility.\n`
|
|
8
|
+
);
|
|
9
|
+
// Don't exit - make it optional
|
|
10
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
var __importDefault =
|
|
3
|
+
(this && this.__importDefault) ||
|
|
4
|
+
function (mod) {
|
|
5
|
+
return mod && mod.__esModule ? mod : { default: mod }
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
8
|
+
exports.VERSION =
|
|
9
|
+
exports.TimeMs =
|
|
10
|
+
exports.DEFAULT_CACHE_TTLS =
|
|
11
|
+
exports.MIN_UPLOAD_INTERVAL =
|
|
12
|
+
exports.UPLOAD_TIMEOUT =
|
|
13
|
+
exports.INITIAL_PREKEY_COUNT =
|
|
14
|
+
exports.MIN_PREKEY_COUNT =
|
|
15
|
+
exports.MEDIA_KEYS =
|
|
16
|
+
exports.MEDIA_HKDF_KEY_MAPPING =
|
|
17
|
+
exports.MEDIA_PATH_MAP =
|
|
18
|
+
exports.DEFAULT_CONNECTION_CONFIG =
|
|
19
|
+
exports.PROCESSABLE_HISTORY_TYPES =
|
|
20
|
+
exports.WA_CERT_DETAILS =
|
|
21
|
+
exports.URL_REGEX =
|
|
22
|
+
exports.NOISE_WA_HEADER =
|
|
23
|
+
exports.KEY_BUNDLE_TYPE =
|
|
24
|
+
exports.DICT_VERSION =
|
|
25
|
+
exports.NOISE_MODE =
|
|
26
|
+
exports.PLACEHOLDER_MAX_AGE_SECONDS =
|
|
27
|
+
exports.STATUS_EXPIRY_SECONDS =
|
|
28
|
+
exports.WA_DEFAULT_EPHEMERAL =
|
|
29
|
+
exports.WA_ADV_HOSTED_DEVICE_SIG_PREFIX =
|
|
30
|
+
exports.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX =
|
|
31
|
+
exports.WA_ADV_DEVICE_SIG_PREFIX =
|
|
32
|
+
exports.WA_ADV_ACCOUNT_SIG_PREFIX =
|
|
33
|
+
exports.PHONE_CONNECTION_CB =
|
|
34
|
+
exports.DEF_TAG_PREFIX =
|
|
35
|
+
exports.DEF_CALLBACK_PREFIX =
|
|
36
|
+
exports.CALL_AUDIO_PREFIX =
|
|
37
|
+
exports.CALL_VIDEO_PREFIX =
|
|
38
|
+
exports.DEFAULT_ORIGIN =
|
|
39
|
+
exports.UNAUTHORIZED_CODES =
|
|
40
|
+
void 0
|
|
41
|
+
const index_js_1 = require('../../WAProto/index.js')
|
|
42
|
+
const libsignal_1 = require('../Signal/libsignal')
|
|
43
|
+
const browser_utils_1 = require('../Utils/browser-utils')
|
|
44
|
+
const logger_1 = __importDefault(require('../Utils/logger'))
|
|
45
|
+
const version = [2, 3000, 1041467552]
|
|
46
|
+
exports.VERSION = version
|
|
47
|
+
exports.UNAUTHORIZED_CODES = [401, 403, 419]
|
|
48
|
+
exports.DEFAULT_ORIGIN = 'https://web.whatsapp.com'
|
|
49
|
+
exports.CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/'
|
|
50
|
+
exports.CALL_AUDIO_PREFIX = 'https://call.whatsapp.com/voice/'
|
|
51
|
+
exports.DEF_CALLBACK_PREFIX = 'CB:'
|
|
52
|
+
exports.DEF_TAG_PREFIX = 'TAG:'
|
|
53
|
+
exports.PHONE_CONNECTION_CB = 'CB:Pong'
|
|
54
|
+
exports.WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0])
|
|
55
|
+
exports.WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1])
|
|
56
|
+
exports.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5])
|
|
57
|
+
exports.WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6])
|
|
58
|
+
exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60
|
|
59
|
+
/** Status messages older than 24 hours are considered expired */
|
|
60
|
+
exports.STATUS_EXPIRY_SECONDS = 24 * 60 * 60
|
|
61
|
+
/** WA Web enforces a 14-day maximum age for placeholder resend requests */
|
|
62
|
+
exports.PLACEHOLDER_MAX_AGE_SECONDS = 14 * 24 * 60 * 60
|
|
63
|
+
exports.NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0'
|
|
64
|
+
exports.DICT_VERSION = 3
|
|
65
|
+
exports.KEY_BUNDLE_TYPE = Buffer.from([5])
|
|
66
|
+
exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]) // last is "DICT_VERSION"
|
|
67
|
+
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
68
|
+
exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g
|
|
69
|
+
exports.WA_CERT_DETAILS = {
|
|
70
|
+
SERIAL: 0,
|
|
71
|
+
ISSUER: 'WhatsAppLongTerm1',
|
|
72
|
+
PUBLIC_KEY: Buffer.from('142375574d0a587166aae71ebe516437c4a28b73e3695c6ce1f7f9545da8ee6b', 'hex')
|
|
73
|
+
}
|
|
74
|
+
exports.HISTORY_SYNC_PAUSED_TIMEOUT_MS = 120000
|
|
75
|
+
exports.PROCESSABLE_HISTORY_TYPES = [
|
|
76
|
+
index_js_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
77
|
+
index_js_1.proto.HistorySync.HistorySyncType.PUSH_NAME,
|
|
78
|
+
index_js_1.proto.HistorySync.HistorySyncType.RECENT,
|
|
79
|
+
index_js_1.proto.HistorySync.HistorySyncType.FULL,
|
|
80
|
+
index_js_1.proto.HistorySync.HistorySyncType.ON_DEMAND,
|
|
81
|
+
index_js_1.proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
|
|
82
|
+
index_js_1.proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3
|
|
83
|
+
]
|
|
84
|
+
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
85
|
+
version: version,
|
|
86
|
+
browser: browser_utils_1.Browsers.windows('Firefox'),
|
|
87
|
+
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
88
|
+
connectTimeoutMs: 20000,
|
|
89
|
+
keepAliveIntervalMs: 30000,
|
|
90
|
+
aiLabel: true,
|
|
91
|
+
logger: logger_1.default.child({ class: 'baileys' }),
|
|
92
|
+
emitOwnEvents: true,
|
|
93
|
+
defaultQueryTimeoutMs: 60000,
|
|
94
|
+
customUploadHosts: [],
|
|
95
|
+
retryRequestDelayMs: 250,
|
|
96
|
+
maxMsgRetryCount: 5,
|
|
97
|
+
fireInitQueries: true,
|
|
98
|
+
auth: undefined,
|
|
99
|
+
markOnlineOnConnect: true,
|
|
100
|
+
syncFullHistory: false,
|
|
101
|
+
patchMessageBeforeSending: msg => msg,
|
|
102
|
+
shouldSyncHistoryMessage: ({ syncType }) => {
|
|
103
|
+
return syncType !== index_js_1.proto.HistorySync.HistorySyncType.FULL
|
|
104
|
+
},
|
|
105
|
+
shouldIgnoreJid: () => false,
|
|
106
|
+
masqueradeAsPrimary: false,
|
|
107
|
+
linkPreviewImageThumbnailWidth: 192,
|
|
108
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
109
|
+
generateHighQualityLinkPreview: false,
|
|
110
|
+
enableAutoSessionRecreation: true,
|
|
111
|
+
enableRecentMessageCache: true,
|
|
112
|
+
options: {},
|
|
113
|
+
appStateMacVerification: {
|
|
114
|
+
patch: false,
|
|
115
|
+
snapshot: false
|
|
116
|
+
},
|
|
117
|
+
countryCode: 'US',
|
|
118
|
+
getMessage: async () => undefined,
|
|
119
|
+
cachedGroupMetadata: async () => undefined,
|
|
120
|
+
makeSignalRepository: libsignal_1.makeLibSignalRepository,
|
|
121
|
+
maxConcurrentUploads: 3,
|
|
122
|
+
presenceUpdateIntervalMs: 5000,
|
|
123
|
+
groupMetadataCacheTTL: 30 * 60 * 1000,
|
|
124
|
+
useCachedGroupMetadata: false,
|
|
125
|
+
enableCallHistory: false,
|
|
126
|
+
reconnectOnNetworkChange: false
|
|
127
|
+
}
|
|
128
|
+
exports.MEDIA_PATH_MAP = {
|
|
129
|
+
image: '/mms/image',
|
|
130
|
+
video: '/mms/video',
|
|
131
|
+
document: '/mms/document',
|
|
132
|
+
audio: '/mms/audio',
|
|
133
|
+
sticker: '/mms/image',
|
|
134
|
+
'thumbnail-link': '/mms/image',
|
|
135
|
+
'thumbnail-image': '/mms/image',
|
|
136
|
+
'thumbnail-video': '/mms/video',
|
|
137
|
+
'thumbnail-document': '/mms/document',
|
|
138
|
+
'product-catalog-image': '/product/image',
|
|
139
|
+
'md-app-state': '',
|
|
140
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
141
|
+
'biz-cover-photo': '/pps/biz-cover-photo',
|
|
142
|
+
ptv: '/mms/video'
|
|
143
|
+
}
|
|
144
|
+
exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
145
|
+
audio: 'Audio',
|
|
146
|
+
document: 'Document',
|
|
147
|
+
gif: 'Video',
|
|
148
|
+
image: 'Image',
|
|
149
|
+
ppic: '',
|
|
150
|
+
product: 'Image',
|
|
151
|
+
ptt: 'Audio',
|
|
152
|
+
sticker: 'Image',
|
|
153
|
+
video: 'Video',
|
|
154
|
+
'thumbnail-document': 'Document Thumbnail',
|
|
155
|
+
'thumbnail-image': 'Image Thumbnail',
|
|
156
|
+
'thumbnail-video': 'Video Thumbnail',
|
|
157
|
+
'thumbnail-link': 'Link Thumbnail',
|
|
158
|
+
'md-msg-hist': 'History',
|
|
159
|
+
'md-app-state': 'App State',
|
|
160
|
+
'product-catalog-image': 'Product Catalog Image',
|
|
161
|
+
'payment-bg-image': 'Payment Background',
|
|
162
|
+
ptv: 'Video',
|
|
163
|
+
'biz-cover-photo': 'Image',
|
|
164
|
+
location: 'Location',
|
|
165
|
+
contact: 'Contact',
|
|
166
|
+
'voip-token': 'Voip Token'
|
|
167
|
+
}
|
|
168
|
+
exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP)
|
|
169
|
+
exports.MIN_PREKEY_COUNT = 5
|
|
170
|
+
exports.INITIAL_PREKEY_COUNT = 812
|
|
171
|
+
exports.UPLOAD_TIMEOUT = 30000 // 30 seconds
|
|
172
|
+
exports.MIN_UPLOAD_INTERVAL = 5000 // 5 seconds minimum between uploads
|
|
173
|
+
exports.DEFAULT_CACHE_TTLS = {
|
|
174
|
+
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
175
|
+
MSG_RETRY: 60 * 60, // 1 hour
|
|
176
|
+
CALL_OFFER: 5 * 60, // 5 minutes
|
|
177
|
+
USER_DEVICES: 5 * 60, // 5 minutes
|
|
178
|
+
GROUP_METADATA: 30 * 60, // 30 minutes
|
|
179
|
+
CALL_SESSION: 10 * 60, // 10 minutes
|
|
180
|
+
USYNC_RESULTS: 10 * 60, // 10 minutes
|
|
181
|
+
IDENTITY_PROOF: 60 * 60 // 1 hour
|
|
182
|
+
}
|
|
183
|
+
exports.TimeMs = {
|
|
184
|
+
Second: 1000,
|
|
185
|
+
Minute: 60 * 1000,
|
|
186
|
+
Hour: 60 * 60 * 1000,
|
|
187
|
+
Day: 24 * 60 * 60 * 1000,
|
|
188
|
+
Week: 7 * 24 * 60 * 60 * 1000,
|
|
189
|
+
Month: 30 * 24 * 60 * 60 * 1000
|
|
190
|
+
}
|
|
@@ -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,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,92 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
8
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc)
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k
|
|
20
|
+
o[k2] = m[k]
|
|
21
|
+
})
|
|
22
|
+
var __setModuleDefault =
|
|
23
|
+
(this && this.__setModuleDefault) ||
|
|
24
|
+
(Object.create
|
|
25
|
+
? function (o, v) {
|
|
26
|
+
Object.defineProperty(o, 'default', { enumerable: true, value: v })
|
|
27
|
+
}
|
|
28
|
+
: function (o, v) {
|
|
29
|
+
o['default'] = v
|
|
30
|
+
})
|
|
31
|
+
var __importStar =
|
|
32
|
+
(this && this.__importStar) ||
|
|
33
|
+
(function () {
|
|
34
|
+
var ownKeys = function (o) {
|
|
35
|
+
ownKeys =
|
|
36
|
+
Object.getOwnPropertyNames ||
|
|
37
|
+
function (o) {
|
|
38
|
+
var ar = []
|
|
39
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k
|
|
40
|
+
return ar
|
|
41
|
+
}
|
|
42
|
+
return ownKeys(o)
|
|
43
|
+
}
|
|
44
|
+
return function (mod) {
|
|
45
|
+
if (mod && mod.__esModule) return mod
|
|
46
|
+
var result = {}
|
|
47
|
+
if (mod != null)
|
|
48
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== 'default') __createBinding(result, mod, k[i])
|
|
49
|
+
__setModuleDefault(result, mod)
|
|
50
|
+
return result
|
|
51
|
+
}
|
|
52
|
+
})()
|
|
53
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
54
|
+
exports.GroupSessionBuilder = void 0
|
|
55
|
+
const keyhelper = __importStar(require('./keyhelper'))
|
|
56
|
+
const sender_key_distribution_message_1 = require('./sender-key-distribution-message')
|
|
57
|
+
class GroupSessionBuilder {
|
|
58
|
+
constructor(senderKeyStore) {
|
|
59
|
+
this.senderKeyStore = senderKeyStore
|
|
60
|
+
}
|
|
61
|
+
async process(senderKeyName, senderKeyDistributionMessage) {
|
|
62
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName)
|
|
63
|
+
senderKeyRecord.addSenderKeyState(
|
|
64
|
+
senderKeyDistributionMessage.getId(),
|
|
65
|
+
senderKeyDistributionMessage.getIteration(),
|
|
66
|
+
senderKeyDistributionMessage.getChainKey(),
|
|
67
|
+
senderKeyDistributionMessage.getSignatureKey()
|
|
68
|
+
)
|
|
69
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord)
|
|
70
|
+
}
|
|
71
|
+
async create(senderKeyName) {
|
|
72
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName)
|
|
73
|
+
if (senderKeyRecord.isEmpty()) {
|
|
74
|
+
const keyId = keyhelper.generateSenderKeyId()
|
|
75
|
+
const senderKey = keyhelper.generateSenderKey()
|
|
76
|
+
const signingKey = keyhelper.generateSenderSigningKey()
|
|
77
|
+
senderKeyRecord.setSenderKeyState(keyId, 0, senderKey, signingKey)
|
|
78
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord)
|
|
79
|
+
}
|
|
80
|
+
const state = senderKeyRecord.getSenderKeyState()
|
|
81
|
+
if (!state) {
|
|
82
|
+
throw new Error('No session state available')
|
|
83
|
+
}
|
|
84
|
+
return new sender_key_distribution_message_1.SenderKeyDistributionMessage(
|
|
85
|
+
state.getKeyId(),
|
|
86
|
+
state.getSenderChainKey().getIteration(),
|
|
87
|
+
state.getSenderChainKey().getSeed(),
|
|
88
|
+
state.getSigningKeyPublic()
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.GroupSessionBuilder = GroupSessionBuilder
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.GroupCipher = void 0
|
|
4
|
+
const Crypto_1 = require('../../Utils/crypto')
|
|
5
|
+
const sender_key_message_1 = require('./sender-key-message')
|
|
6
|
+
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 sender_key_message_1.SenderKeyMessage(
|
|
24
|
+
senderKeyState.getKeyId(),
|
|
25
|
+
senderKey.getIteration(),
|
|
26
|
+
ciphertext,
|
|
27
|
+
senderKeyState.getSigningKeyPrivate()
|
|
28
|
+
)
|
|
29
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record)
|
|
30
|
+
return senderKeyMessage.serialize()
|
|
31
|
+
}
|
|
32
|
+
async decrypt(senderKeyMessageBytes) {
|
|
33
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName)
|
|
34
|
+
if (!record) {
|
|
35
|
+
throw new Error('No SenderKeyRecord found for decryption')
|
|
36
|
+
}
|
|
37
|
+
const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(null, null, null, null, senderKeyMessageBytes)
|
|
38
|
+
const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId())
|
|
39
|
+
if (!senderKeyState) {
|
|
40
|
+
throw new Error('No session found to decrypt message')
|
|
41
|
+
}
|
|
42
|
+
senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic())
|
|
43
|
+
const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration())
|
|
44
|
+
const plaintext = await this.getPlainText(
|
|
45
|
+
senderKey.getIv(),
|
|
46
|
+
senderKey.getCipherKey(),
|
|
47
|
+
senderKeyMessage.getCipherText()
|
|
48
|
+
)
|
|
49
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record)
|
|
50
|
+
return plaintext
|
|
51
|
+
}
|
|
52
|
+
getSenderKey(senderKeyState, iteration) {
|
|
53
|
+
let senderChainKey = senderKeyState.getSenderChainKey()
|
|
54
|
+
if (senderChainKey.getIteration() > iteration) {
|
|
55
|
+
if (senderKeyState.hasSenderMessageKey(iteration)) {
|
|
56
|
+
const messageKey = senderKeyState.removeSenderMessageKey(iteration)
|
|
57
|
+
if (!messageKey) {
|
|
58
|
+
throw new Error('No sender message key found for iteration')
|
|
59
|
+
}
|
|
60
|
+
return messageKey
|
|
61
|
+
}
|
|
62
|
+
throw new Error(`Received message with old counter: ${senderChainKey.getIteration()}, ${iteration}`)
|
|
63
|
+
}
|
|
64
|
+
if (iteration - senderChainKey.getIteration() > 2000) {
|
|
65
|
+
throw new Error('Over 2000 messages into the future!')
|
|
66
|
+
}
|
|
67
|
+
while (senderChainKey.getIteration() < iteration) {
|
|
68
|
+
senderKeyState.addSenderMessageKey(senderChainKey.getSenderMessageKey())
|
|
69
|
+
senderChainKey = senderChainKey.getNext()
|
|
70
|
+
}
|
|
71
|
+
senderKeyState.setSenderChainKey(senderChainKey.getNext())
|
|
72
|
+
return senderChainKey.getSenderMessageKey()
|
|
73
|
+
}
|
|
74
|
+
async getPlainText(iv, key, ciphertext) {
|
|
75
|
+
try {
|
|
76
|
+
return Buffer.from(Crypto_1.aesDecryptWithIV(ciphertext, key, iv))
|
|
77
|
+
} catch (e) {
|
|
78
|
+
throw new Error('InvalidMessageException')
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async getCipherText(iv, key, plaintext) {
|
|
82
|
+
try {
|
|
83
|
+
return Buffer.from(Crypto_1.aesEncrypWithIV(plaintext, key, iv))
|
|
84
|
+
} catch (e) {
|
|
85
|
+
throw new Error('InvalidMessageException')
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.GroupCipher = GroupCipher
|