@celestial-community/baileys 0.0.1-security → 1.0.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.
Potentially problematic release.
This version of @celestial-community/baileys might be problematic. Click here for more details.
- package/WAProto/index.js +138933 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +7 -0
- package/lib/Defaults/index.js +157 -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 +94 -0
- package/lib/Signal/Group/group_cipher.js +118 -0
- package/lib/Signal/Group/index.js +138 -0
- package/lib/Signal/Group/keyhelper.js +75 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +39 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
- package/lib/Signal/Group/sender-key-message.js +76 -0
- package/lib/Signal/Group/sender-key-name.js +50 -0
- package/lib/Signal/Group/sender-key-record.js +65 -0
- package/lib/Signal/Group/sender-key-state.js +114 -0
- package/lib/Signal/Group/sender-message-key.js +33 -0
- package/lib/Signal/libsignal.js +204 -0
- package/lib/Signal/lid-mapping.js +267 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +32 -0
- package/lib/Socket/Client/mobile-socket-client.js +82 -0
- package/lib/Socket/Client/web-socket-client.js +89 -0
- package/lib/Socket/Denzy-ZeroDay.js +805 -0
- package/lib/Socket/business.js +279 -0
- package/lib/Socket/chats.js +1169 -0
- package/lib/Socket/community.d.ts +120 -0
- package/lib/Socket/community.js +388 -0
- package/lib/Socket/graphql.js +1122 -0
- package/lib/Socket/groups.js +345 -0
- package/lib/Socket/index.js +22 -0
- package/lib/Socket/interop.js +265 -0
- package/lib/Socket/lid-mapping.js +111 -0
- package/lib/Socket/messages-recv.js +1385 -0
- package/lib/Socket/messages-send.js +956 -0
- package/lib/Socket/mex.js +69 -0
- package/lib/Socket/newsletter.js +424 -0
- package/lib/Socket/privacy.js +229 -0
- package/lib/Socket/registration.js +190 -0
- package/lib/Socket/socket.js +783 -0
- package/lib/Socket/username.d.ts +185 -0
- package/lib/Socket/username.js +168 -0
- package/lib/Socket/usync.js +80 -0
- package/lib/Store/index.js +14 -0
- package/lib/Store/keyed-db.js +158 -0
- package/lib/Store/make-cache-manager-store.js +88 -0
- package/lib/Store/make-in-memory-store.js +484 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -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 +14 -0
- package/lib/Types/MexUpdates.js +19 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/RichType.js +30 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +58 -0
- package/lib/Utils/anti-ban.js +339 -0
- package/lib/Utils/anti-delete.d.ts +158 -0
- package/lib/Utils/anti-delete.js +293 -0
- package/lib/Utils/antiban-presets.js +91 -0
- package/lib/Utils/antiban-profiles.js +43 -0
- package/lib/Utils/auth-utils.js +210 -0
- package/lib/Utils/baileys-event-stream.js +66 -0
- package/lib/Utils/browser-utils.js +52 -0
- package/lib/Utils/business.js +261 -0
- package/lib/Utils/chat-control.d.ts +113 -0
- package/lib/Utils/chat-control.js +230 -0
- package/lib/Utils/chat-utils.js +922 -0
- package/lib/Utils/companion-reg-client-utils.js +37 -0
- package/lib/Utils/contact-graph-warmer.js +208 -0
- package/lib/Utils/crypto.js +196 -0
- package/lib/Utils/decode-wa-message.js +208 -0
- package/lib/Utils/delivery-tracker.js +110 -0
- package/lib/Utils/device-fingerprint.js +135 -0
- package/lib/Utils/event-buffer.js +531 -0
- package/lib/Utils/generics.js +571 -0
- package/lib/Utils/group-operation-guard.js +147 -0
- package/lib/Utils/health-monitor.js +207 -0
- package/lib/Utils/history.js +122 -0
- package/lib/Utils/human-entropy.js +226 -0
- package/lib/Utils/identity-change-handler.js +72 -0
- package/lib/Utils/index.js +83 -0
- package/lib/Utils/interactive-message.d.ts +139 -0
- package/lib/Utils/interactive-message.js +273 -0
- package/lib/Utils/legitimacy-signal-injector.js +180 -0
- package/lib/Utils/link-preview.js +106 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.js +9 -0
- package/lib/Utils/lt-hash.js +54 -0
- package/lib/Utils/make-mutex.js +41 -0
- package/lib/Utils/message-composer.d.ts +106 -0
- package/lib/Utils/message-composer.js +721 -0
- package/lib/Utils/message-retry-manager.d.ts +88 -0
- package/lib/Utils/message-retry-manager.js +160 -0
- package/lib/Utils/message-search.d.ts +52 -0
- package/lib/Utils/message-search.js +226 -0
- package/lib/Utils/messages-media.js +899 -0
- package/lib/Utils/messages.js +2698 -0
- package/lib/Utils/noise-handler.js +175 -0
- package/lib/Utils/offline-node-processor.js +45 -0
- package/lib/Utils/pre-key-manager.js +131 -0
- package/lib/Utils/presence-choreographer.js +438 -0
- package/lib/Utils/process-message.js +423 -0
- package/lib/Utils/rate-limiter.js +232 -0
- package/lib/Utils/reconnect-throttle.js +157 -0
- package/lib/Utils/reply-ratio-guard.js +137 -0
- package/lib/Utils/reporting-utils.js +307 -0
- package/lib/Utils/retry-reason-tracker.js +140 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +400 -0
- package/lib/Utils/rich-response-utils.js +461 -0
- package/lib/Utils/scheduling.d.ts +135 -0
- package/lib/Utils/scheduling.js +246 -0
- package/lib/Utils/session-fingerprint.js +226 -0
- package/lib/Utils/session-stability.js +224 -0
- package/lib/Utils/signal.js +188 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/state-manager.js +91 -0
- package/lib/Utils/status-posting.d.ts +81 -0
- package/lib/Utils/status-posting.js +187 -0
- package/lib/Utils/stealth-connect.js +124 -0
- package/lib/Utils/sync-action-utils.js +55 -0
- package/lib/Utils/tc-token-utils.js +171 -0
- package/lib/Utils/templates.d.ts +54 -0
- package/lib/Utils/templates.js +244 -0
- package/lib/Utils/timelock-guard.js +162 -0
- package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
- package/lib/Utils/use-mongo-file-auth-state.js +81 -0
- package/lib/Utils/use-multi-file-auth-state.js +125 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-single-file-auth-state.js +86 -0
- package/lib/Utils/use-sqlite-auth-state.js +187 -0
- package/lib/Utils/vCard.d.ts +71 -0
- package/lib/Utils/vCard.js +196 -0
- package/lib/Utils/validate-connection.js +253 -0
- package/lib/Utils/warmup.js +154 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +270 -0
- package/lib/WABinary/encode.js +279 -0
- package/lib/WABinary/generic-utils.js +223 -0
- package/lib/WABinary/index.js +34 -0
- package/lib/WABinary/jid-utils.js +84 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15254 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.js +32 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +71 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +58 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +34 -0
- package/lib/WAUSync/USyncQuery.js +99 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/USyncUsernameProtocol.js +37 -0
- package/lib/WAUSync/index.js +32 -0
- package/lib/index.js +59 -0
- package/package.json +105 -5
- package/README.md +0 -5
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const major = parseInt(process.versions.node.split('.')[0], 10)
|
|
2
|
+
|
|
3
|
+
if (major < 20) {
|
|
4
|
+
console.error(
|
|
5
|
+
`\n❌ This package requires Node.js 20+ to run reliably.\n` +
|
|
6
|
+
` You are using Node.js ${process.versions.node}.\n` +
|
|
7
|
+
` Please upgrade to Node.js 20+ to proceed.\n`
|
|
8
|
+
)
|
|
9
|
+
process.exit(1)
|
|
10
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
var __importDefault =
|
|
2
|
+
(this && this.__importDefault) ||
|
|
3
|
+
function (a) {
|
|
4
|
+
return a && a.__esModule ? a : { default: a }
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, '__esModule', { value: !0 })
|
|
8
|
+
|
|
9
|
+
exports.DEFAULT_CACHE_TTLS =
|
|
10
|
+
exports.INITIAL_PREKEY_COUNT =
|
|
11
|
+
exports.MIN_PREKEY_COUNT =
|
|
12
|
+
exports.MEDIA_KEYS =
|
|
13
|
+
exports.MEDIA_HKDF_KEY_MAPPING =
|
|
14
|
+
exports.MEDIA_PATH_MAP =
|
|
15
|
+
exports.DEFAULT_CONNECTION_CONFIG =
|
|
16
|
+
exports.PROCESSABLE_HISTORY_TYPES =
|
|
17
|
+
exports.WA_CERT_DETAILS =
|
|
18
|
+
exports.URL_REGEX =
|
|
19
|
+
exports.NOISE_WA_HEADER =
|
|
20
|
+
exports.KEY_BUNDLE_TYPE =
|
|
21
|
+
exports.DICT_VERSION =
|
|
22
|
+
exports.NOISE_MODE =
|
|
23
|
+
exports.WA_DEFAULT_EPHEMERAL =
|
|
24
|
+
exports.PHONE_CONNECTION_CB =
|
|
25
|
+
exports.DEF_TAG_PREFIX =
|
|
26
|
+
exports.DEF_CALLBACK_PREFIX =
|
|
27
|
+
exports.DEFAULT_ORIGIN =
|
|
28
|
+
exports.UNAUTHORIZED_CODES =
|
|
29
|
+
void 0
|
|
30
|
+
|
|
31
|
+
const crypto_1 = require('crypto')
|
|
32
|
+
const WAProto_1 = require('../../WAProto'),
|
|
33
|
+
libsignal_1 = require('../Signal/libsignal'),
|
|
34
|
+
Utils_1 = require('../Utils'),
|
|
35
|
+
logger_1 = __importDefault(require('../Utils/logger')),
|
|
36
|
+
baileys_version_json_1 = require('./baileys-version.json'),
|
|
37
|
+
phonenumber_mcc_json_1 = __importDefault(require('./phonenumber-mcc.json'))
|
|
38
|
+
|
|
39
|
+
exports.UNAUTHORIZED_CODES = [401, 403, 419]
|
|
40
|
+
exports.version = [2, 3000, 1027934701]
|
|
41
|
+
exports.PHONENUMBER_MCC = phonenumber_mcc_json_1.default
|
|
42
|
+
exports.DEFAULT_ORIGIN = 'https://web.whatsapp.com'
|
|
43
|
+
exports.MOBILE_ENDPOINT = 'g.whatsapp.net'
|
|
44
|
+
exports.MOBILE_PORT = 443
|
|
45
|
+
exports.DEF_CALLBACK_PREFIX = 'CB:'
|
|
46
|
+
exports.DEF_TAG_PREFIX = 'TAG:'
|
|
47
|
+
exports.PHONE_CONNECTION_CB = 'CB:Pong'
|
|
48
|
+
exports.WA_DEFAULT_EPHEMERAL = 604800
|
|
49
|
+
const WA_VERSION = '2.25.23.24'
|
|
50
|
+
const WA_VERSION_HASH = (0, crypto_1.createHash)('md5').update(WA_VERSION).digest('hex')
|
|
51
|
+
exports.MOBILE_TOKEN = Buffer.from('0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM' + WA_VERSION_HASH)
|
|
52
|
+
exports.MOBILE_REGISTRATION_ENDPOINT = 'https://v.whatsapp.net/v2'
|
|
53
|
+
exports.MOBILE_USERAGENT = `WhatsApp/${WA_VERSION} iOS/17.5.1 Device/Apple-iPhone_13`
|
|
54
|
+
exports.REGISTRATION_PUBLIC_KEY = Buffer.from([
|
|
55
|
+
5, 142, 140, 15, 116, 195, 235, 197, 215, 166, 134, 92, 108, 60, 132, 56, 86, 176, 97, 33, 204,
|
|
56
|
+
232, 234, 119, 77, 34, 251, 111, 18, 37, 18, 48, 45
|
|
57
|
+
])
|
|
58
|
+
exports.NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\x00\x00\x00\x00'
|
|
59
|
+
exports.DICT_VERSION = 2
|
|
60
|
+
exports.KEY_BUNDLE_TYPE = Buffer.from([5])
|
|
61
|
+
exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION])
|
|
62
|
+
exports.PROTOCOL_VERSION = [5, 2]
|
|
63
|
+
exports.MOBILE_NOISE_HEADER = Buffer.concat([
|
|
64
|
+
Buffer.from('WA'),
|
|
65
|
+
Buffer.from(exports.PROTOCOL_VERSION)
|
|
66
|
+
])
|
|
67
|
+
|
|
68
|
+
exports.URL_REGEX =
|
|
69
|
+
/https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g
|
|
70
|
+
exports.WA_CERT_DETAILS = { SERIAL: 0 }
|
|
71
|
+
|
|
72
|
+
exports.PROCESSABLE_HISTORY_TYPES = [
|
|
73
|
+
WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
74
|
+
WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME,
|
|
75
|
+
WAProto_1.proto.HistorySync.HistorySyncType.RECENT,
|
|
76
|
+
WAProto_1.proto.HistorySync.HistorySyncType.FULL,
|
|
77
|
+
WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND,
|
|
78
|
+
WAProto_1.proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
|
|
79
|
+
WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
83
|
+
// LID <-> PN helpers are lazy (only run when called). true = also learn mappings passively from existing events
|
|
84
|
+
enableLidMapping: false,
|
|
85
|
+
version: baileys_version_json_1.version,
|
|
86
|
+
browser: ['Chrome (Linux)', '', 'Chrome'],
|
|
87
|
+
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
88
|
+
connectTimeoutMs: 2e4,
|
|
89
|
+
keepAliveIntervalMs: 3e4,
|
|
90
|
+
logger: logger_1.default.child({ class: 'baileys' }),
|
|
91
|
+
printQRInTerminal: !1,
|
|
92
|
+
emitOwnEvents: !0,
|
|
93
|
+
defaultQueryTimeoutMs: 6e4,
|
|
94
|
+
customUploadHosts: [],
|
|
95
|
+
retryRequestDelayMs: 250,
|
|
96
|
+
maxMsgRetryCount: 5,
|
|
97
|
+
fireInitQueries: !0,
|
|
98
|
+
auth: void 0,
|
|
99
|
+
markOnlineOnConnect: !0,
|
|
100
|
+
syncFullHistory: !1,
|
|
101
|
+
patchMessageBeforeSending: (a) => a,
|
|
102
|
+
shouldSyncHistoryMessage: () => !0,
|
|
103
|
+
shouldIgnoreJid: () => !1,
|
|
104
|
+
linkPreviewImageThumbnailWidth: 192,
|
|
105
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3e3 },
|
|
106
|
+
generateHighQualityLinkPreview: !1,
|
|
107
|
+
options: {},
|
|
108
|
+
appStateMacVerification: { patch: !1, snapshot: !1 },
|
|
109
|
+
countryCode: 'US',
|
|
110
|
+
getMessage: async () => {},
|
|
111
|
+
cachedGroupMetadata: async () => {},
|
|
112
|
+
makeSignalRepository: libsignal_1.makeLibSignalRepository
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
exports.MEDIA_PATH_MAP = {
|
|
116
|
+
image: '/mms/image',
|
|
117
|
+
video: '/mms/video',
|
|
118
|
+
document: '/mms/document',
|
|
119
|
+
audio: '/mms/audio',
|
|
120
|
+
sticker: '/mms/image',
|
|
121
|
+
'thumbnail-link': '/mms/image',
|
|
122
|
+
'product-catalog-image': '/product/image',
|
|
123
|
+
'md-app-state': '',
|
|
124
|
+
'md-msg-hist': '/mms/md-app-state'
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
128
|
+
audio: 'Audio',
|
|
129
|
+
document: 'Document',
|
|
130
|
+
gif: 'Video',
|
|
131
|
+
image: 'Image',
|
|
132
|
+
ppic: '',
|
|
133
|
+
product: 'Image',
|
|
134
|
+
ptt: 'Audio',
|
|
135
|
+
sticker: 'Image',
|
|
136
|
+
video: 'Video',
|
|
137
|
+
'thumbnail-document': 'Document Thumbnail',
|
|
138
|
+
'thumbnail-image': 'Image Thumbnail',
|
|
139
|
+
'thumbnail-video': 'Video Thumbnail',
|
|
140
|
+
'thumbnail-link': 'Link Thumbnail',
|
|
141
|
+
'md-msg-hist': 'History',
|
|
142
|
+
'md-app-state': 'App State',
|
|
143
|
+
'product-catalog-image': '',
|
|
144
|
+
'payment-bg-image': 'Payment Background',
|
|
145
|
+
ptv: 'Video'
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP)
|
|
149
|
+
exports.MIN_PREKEY_COUNT = 5
|
|
150
|
+
exports.INITIAL_PREKEY_COUNT = 30
|
|
151
|
+
|
|
152
|
+
exports.DEFAULT_CACHE_TTLS = {
|
|
153
|
+
SIGNAL_STORE: 300,
|
|
154
|
+
MSG_RETRY: 3600,
|
|
155
|
+
CALL_OFFER: 300,
|
|
156
|
+
USER_DEVICES: 300
|
|
157
|
+
}
|
|
@@ -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,94 @@
|
|
|
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)
|
|
40
|
+
if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k
|
|
41
|
+
return ar
|
|
42
|
+
}
|
|
43
|
+
return ownKeys(o)
|
|
44
|
+
}
|
|
45
|
+
return function (mod) {
|
|
46
|
+
if (mod && mod.__esModule) return mod
|
|
47
|
+
var result = {}
|
|
48
|
+
if (mod != null)
|
|
49
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++)
|
|
50
|
+
if (k[i] !== 'default') __createBinding(result, mod, k[i])
|
|
51
|
+
__setModuleDefault(result, mod)
|
|
52
|
+
return result
|
|
53
|
+
}
|
|
54
|
+
})()
|
|
55
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
56
|
+
exports.GroupSessionBuilder = void 0
|
|
57
|
+
const keyhelper = __importStar(require('./keyhelper'))
|
|
58
|
+
const sender_key_distribution_message_1 = require('./sender-key-distribution-message')
|
|
59
|
+
class GroupSessionBuilder {
|
|
60
|
+
constructor(senderKeyStore) {
|
|
61
|
+
this.senderKeyStore = senderKeyStore
|
|
62
|
+
}
|
|
63
|
+
async process(senderKeyName, senderKeyDistributionMessage) {
|
|
64
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName)
|
|
65
|
+
senderKeyRecord.addSenderKeyState(
|
|
66
|
+
senderKeyDistributionMessage.getId(),
|
|
67
|
+
senderKeyDistributionMessage.getIteration(),
|
|
68
|
+
senderKeyDistributionMessage.getChainKey(),
|
|
69
|
+
senderKeyDistributionMessage.getSignatureKey()
|
|
70
|
+
)
|
|
71
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord)
|
|
72
|
+
}
|
|
73
|
+
async create(senderKeyName) {
|
|
74
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName)
|
|
75
|
+
if (senderKeyRecord.isEmpty()) {
|
|
76
|
+
const keyId = keyhelper.generateSenderKeyId()
|
|
77
|
+
const senderKey = keyhelper.generateSenderKey()
|
|
78
|
+
const signingKey = keyhelper.generateSenderSigningKey()
|
|
79
|
+
senderKeyRecord.setSenderKeyState(keyId, 0, senderKey, signingKey)
|
|
80
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord)
|
|
81
|
+
}
|
|
82
|
+
const state = senderKeyRecord.getSenderKeyState()
|
|
83
|
+
if (!state) {
|
|
84
|
+
throw new Error('No session state available')
|
|
85
|
+
}
|
|
86
|
+
return new sender_key_distribution_message_1.SenderKeyDistributionMessage(
|
|
87
|
+
state.getKeyId(),
|
|
88
|
+
state.getSenderChainKey().getIteration(),
|
|
89
|
+
state.getSenderChainKey().getSeed(),
|
|
90
|
+
state.getSigningKeyPublic()
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.GroupSessionBuilder = GroupSessionBuilder
|
|
@@ -0,0 +1,118 @@
|
|
|
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.GroupCipher = void 0
|
|
9
|
+
const crypto_1 = require('libsignal/src/crypto')
|
|
10
|
+
const queue_job_1 = __importDefault(require('./queue-job'))
|
|
11
|
+
const sender_key_message_1 = require('./sender-key-message')
|
|
12
|
+
class GroupCipher {
|
|
13
|
+
constructor(senderKeyStore, senderKeyName) {
|
|
14
|
+
this.senderKeyStore = senderKeyStore
|
|
15
|
+
this.senderKeyName = senderKeyName
|
|
16
|
+
}
|
|
17
|
+
queueJob(awaitable) {
|
|
18
|
+
return (0, queue_job_1.default)(this.senderKeyName.toString(), awaitable)
|
|
19
|
+
}
|
|
20
|
+
async encrypt(paddedPlaintext) {
|
|
21
|
+
return await this.queueJob(async () => {
|
|
22
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName)
|
|
23
|
+
if (!record) {
|
|
24
|
+
throw new Error('No SenderKeyRecord found for encryption')
|
|
25
|
+
}
|
|
26
|
+
const senderKeyState = record.getSenderKeyState()
|
|
27
|
+
if (!senderKeyState) {
|
|
28
|
+
throw new Error('No session to encrypt message')
|
|
29
|
+
}
|
|
30
|
+
const iteration = senderKeyState.getSenderChainKey().getIteration()
|
|
31
|
+
const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1)
|
|
32
|
+
const ciphertext = await this.getCipherText(
|
|
33
|
+
senderKey.getIv(),
|
|
34
|
+
senderKey.getCipherKey(),
|
|
35
|
+
paddedPlaintext
|
|
36
|
+
)
|
|
37
|
+
const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(
|
|
38
|
+
senderKeyState.getKeyId(),
|
|
39
|
+
senderKey.getIteration(),
|
|
40
|
+
ciphertext,
|
|
41
|
+
senderKeyState.getSigningKeyPrivate()
|
|
42
|
+
)
|
|
43
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record)
|
|
44
|
+
return senderKeyMessage.serialize()
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
async decrypt(senderKeyMessageBytes) {
|
|
48
|
+
return await this.queueJob(async () => {
|
|
49
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName)
|
|
50
|
+
if (!record) {
|
|
51
|
+
throw new Error('No SenderKeyRecord found for decryption')
|
|
52
|
+
}
|
|
53
|
+
const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(
|
|
54
|
+
null,
|
|
55
|
+
null,
|
|
56
|
+
null,
|
|
57
|
+
null,
|
|
58
|
+
senderKeyMessageBytes
|
|
59
|
+
)
|
|
60
|
+
const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId())
|
|
61
|
+
if (!senderKeyState) {
|
|
62
|
+
throw new Error('No session found to decrypt message')
|
|
63
|
+
}
|
|
64
|
+
senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic())
|
|
65
|
+
const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration())
|
|
66
|
+
const plaintext = await this.getPlainText(
|
|
67
|
+
senderKey.getIv(),
|
|
68
|
+
senderKey.getCipherKey(),
|
|
69
|
+
senderKeyMessage.getCipherText()
|
|
70
|
+
)
|
|
71
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record)
|
|
72
|
+
return plaintext
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
getSenderKey(senderKeyState, iteration) {
|
|
76
|
+
let senderChainKey = senderKeyState.getSenderChainKey()
|
|
77
|
+
if (senderChainKey.getIteration() > iteration) {
|
|
78
|
+
if (senderKeyState.hasSenderMessageKey(iteration)) {
|
|
79
|
+
const messageKey = senderKeyState.removeSenderMessageKey(iteration)
|
|
80
|
+
if (!messageKey) {
|
|
81
|
+
throw new Error('No sender message key found for iteration')
|
|
82
|
+
}
|
|
83
|
+
return messageKey
|
|
84
|
+
}
|
|
85
|
+
throw new Error(
|
|
86
|
+
`Received message with old counter: ${senderChainKey.getIteration()}, ${iteration}`
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
if (iteration - senderChainKey.getIteration() > 2000) {
|
|
90
|
+
throw new Error('Over 2000 messages into the future!')
|
|
91
|
+
}
|
|
92
|
+
while (senderChainKey.getIteration() < iteration) {
|
|
93
|
+
senderKeyState.addSenderMessageKey(senderChainKey.getSenderMessageKey())
|
|
94
|
+
senderChainKey = senderChainKey.getNext()
|
|
95
|
+
}
|
|
96
|
+
senderKeyState.setSenderChainKey(senderChainKey.getNext())
|
|
97
|
+
return senderChainKey.getSenderMessageKey()
|
|
98
|
+
}
|
|
99
|
+
async getPlainText(iv, key, ciphertext) {
|
|
100
|
+
try {
|
|
101
|
+
return (0, crypto_1.decrypt)(key, ciphertext, iv)
|
|
102
|
+
} catch (e) {
|
|
103
|
+
throw new Error('InvalidMessageException')
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async getCipherText(iv, key, plaintext) {
|
|
107
|
+
try {
|
|
108
|
+
const ivBuffer = typeof iv === 'string' ? Buffer.from(iv, 'base64') : iv
|
|
109
|
+
const keyBuffer = typeof key === 'string' ? Buffer.from(key, 'base64') : key
|
|
110
|
+
const plaintextBuffer =
|
|
111
|
+
typeof plaintext === 'string' ? Buffer.from(plaintext) : plaintext
|
|
112
|
+
return (0, crypto_1.encrypt)(keyBuffer, plaintextBuffer, ivBuffer)
|
|
113
|
+
} catch (e) {
|
|
114
|
+
throw new Error('InvalidMessageException')
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.GroupCipher = GroupCipher
|