kage-baileys 3.0.6 → 3.2.3
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/Example/connection.cjs +4 -0
- package/README.MD +4726 -48
- package/WAProto/WAProto.proto +3395 -415
- package/WAProto/compat.cjs +12 -0
- package/WAProto/index.d.ts +47104 -19888
- package/WAProto/index.js +131979 -57361
- package/lib/Addon/http-error.js +43 -0
- package/lib/Addon/index.js +32 -0
- package/lib/Addon/keyed-db.js +250 -0
- package/lib/Addon/link-preview.js +82 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/connection.js +110 -0
- package/lib/Defaults/constants.js +156 -0
- package/lib/Defaults/history.js +46 -0
- package/lib/Defaults/index.js +230 -0
- package/lib/Defaults/media.js +104 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/prefix.js +44 -0
- package/lib/Extensions/business-advanced.js +382 -0
- package/lib/Extensions/business.js +159 -0
- package/lib/Extensions/chats-advanced.js +1106 -0
- package/lib/Extensions/chats.js +349 -0
- package/lib/Extensions/communities-advanced.js +430 -0
- package/lib/Extensions/community.js +94 -0
- package/lib/Extensions/groups-advanced.js +343 -0
- package/lib/Extensions/index.js +30 -0
- package/lib/Extensions/messages-recv-advanced.js +1690 -0
- package/lib/Extensions/messages-send-advanced.js +622 -0
- package/lib/Extensions/messages-send.js +1380 -0
- package/lib/Extensions/newsletter-advanced.js +228 -0
- package/lib/Extensions/newsletter.js +72 -0
- package/lib/Extensions/socket.js +389 -0
- package/lib/Modded/message_builder.js +2084 -4
- package/lib/Signal/Group/ciphertext-message.js +54 -0
- package/lib/Signal/Group/group-session-builder.js +124 -0
- package/lib/Signal/Group/group_cipher.js +216 -0
- package/lib/Signal/Group/index.js +124 -0
- package/lib/Signal/Group/keyhelper.js +108 -0
- package/lib/Signal/Group/sender-chain-key.js +83 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +157 -0
- package/lib/Signal/Group/sender-key-message.js +166 -0
- package/lib/Signal/Group/sender-key-name.js +130 -0
- package/lib/Signal/Group/sender-key-record.js +113 -0
- package/lib/Signal/Group/sender-key-state.js +208 -0
- package/lib/Signal/Group/sender-message-key.js +82 -0
- package/lib/Signal/libsignal.js +935 -0
- package/lib/Signal/lid-mapping.js +545 -1
- package/lib/Socket/Client/index.js +60 -0
- package/lib/Socket/Client/types.js +51 -0
- package/lib/Socket/Client/websocket.js +152 -0
- package/lib/Socket/business.js +831 -0
- package/lib/Socket/chats.js +2535 -49
- package/lib/Socket/communities.js +450 -1
- package/lib/Socket/community.js +1022 -0
- package/lib/Socket/dugong.js +1 -1
- package/lib/Socket/groups.js +747 -0
- package/lib/Socket/index.js +60 -2
- package/lib/Socket/messages-recv.js +3450 -5
- package/lib/Socket/messages-send.js +3123 -0
- package/lib/Socket/mex.js +126 -1
- package/lib/Socket/newsletter.js +465 -0
- package/lib/Socket/socket.js +2217 -1
- package/lib/Store/index.js +79 -0
- package/lib/Store/make-cache-manager-store.js +186 -0
- package/lib/Store/make-in-memory-store.js +878 -0
- package/lib/Store/make-ordered-dictionary.js +187 -0
- package/lib/Store/object-repository.js +78 -0
- package/lib/Types/Auth.js +25 -0
- package/lib/Types/Bussines.js +25 -1
- package/lib/Types/Call.js +25 -0
- package/lib/Types/Chat.js +39 -0
- package/lib/Types/Contact.js +25 -0
- package/lib/Types/Events.js +25 -0
- package/lib/Types/GroupMetadata.js +25 -0
- package/lib/Types/Label.js +76 -0
- package/lib/Types/LabelAssociation.js +40 -0
- package/lib/Types/Message.js +57 -0
- package/lib/Types/Mex.js +56 -1
- package/lib/Types/MexUpdates.js +46 -0
- package/lib/Types/Newsletter.js +56 -0
- package/lib/Types/Product.js +25 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/Signal.js +25 -0
- package/lib/Types/Socket.js +25 -0
- package/lib/Types/State.js +92 -0
- package/lib/Types/USync.js +25 -0
- package/lib/Types/index.js +133 -0
- package/lib/Utils/auth-utils.js +703 -0
- package/lib/Utils/automation-tools.js +51 -16
- package/lib/Utils/baileys-event-stream.js +146 -0
- package/lib/Utils/browser-utils.js +95 -0
- package/lib/Utils/business.js +525 -0
- package/lib/Utils/chat-utils.js +1861 -0
- package/lib/Utils/companion-reg-client-utils.js +55 -1
- package/lib/Utils/crypto.js +355 -0
- package/lib/Utils/decode-wa-message.js +709 -0
- package/lib/Utils/event-buffer.js +1323 -8
- package/lib/Utils/generics.js +945 -1
- package/lib/Utils/history.js +266 -0
- package/lib/Utils/identity-change-handler.js +62 -1
- package/lib/Utils/index.js +114 -0
- package/lib/Utils/link-preview.js +179 -0
- package/lib/Utils/logger.js +42 -0
- package/lib/Utils/lt-hash.js +73 -0
- package/lib/Utils/make-mutex.js +104 -0
- package/lib/Utils/message-inspector.js +110 -0
- package/lib/Utils/message-retry-manager.js +507 -2
- package/lib/Utils/messages-media.js +1931 -1
- package/lib/Utils/messages.js +3748 -0
- package/lib/Utils/noise-handler.js +423 -0
- package/lib/Utils/offline-node-processor.js +53 -1
- package/lib/Utils/pre-key-manager.js +255 -1
- package/lib/Utils/process-message.js +1592 -0
- package/lib/Utils/reporting-utils.js +272 -1
- package/lib/Utils/rich-message-utils.js +377 -0
- package/lib/Utils/rich-messages.js +1 -1
- package/lib/Utils/signal.js +437 -0
- package/lib/Utils/stanza-ack.js +51 -1
- package/lib/Utils/status-refresh.js +37 -0
- package/lib/Utils/status-tools.js +4 -2
- package/lib/Utils/sync-action-utils.js +63 -1
- package/lib/Utils/tc-token-utils.js +185 -1
- package/lib/Utils/terminal-banner.js +31 -0
- package/lib/Utils/use-multi-file-auth-state.js +271 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.js +142 -0
- package/lib/Utils/validate-connection.js +497 -1
- package/lib/Utils/view-once-compat.js +13 -5
- package/lib/VoIP/audio-feeder.js +150 -0
- package/lib/VoIP/index.js +289 -0
- package/lib/VoIP/relay-transport.js +608 -0
- package/lib/VoIP/signaling.js +583 -0
- package/lib/VoIP/types.js +30 -0
- package/lib/VoIP/wasm-engine.js +1261 -2
- package/lib/VoIP/worker-bootstrap.js +1090 -2
- package/lib/WABinary/constants.js +2805 -0
- package/lib/WABinary/decode.js +649 -2
- package/lib/WABinary/encode.js +564 -2
- package/lib/WABinary/generic-utils.js +401 -0
- package/lib/WABinary/index.js +82 -0
- package/lib/WABinary/jid-utils.js +290 -0
- package/lib/WABinary/types.js +25 -0
- package/lib/WAM/BinaryInfo.js +50 -0
- package/lib/WAM/constants.js +45747 -0
- package/lib/WAM/encode.js +393 -0
- package/lib/WAM/index.js +78 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +135 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +110 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +142 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +85 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +69 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +107 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +38 -1
- package/lib/WAUSync/Protocols/index.js +83 -0
- package/lib/WAUSync/USyncQuery.js +241 -2
- package/lib/WAUSync/USyncUser.js +86 -0
- package/lib/WAUSync/index.js +78 -0
- package/lib/assets/wasm/loader.js +1875 -1
- package/lib/assets/wasm/worker-modules.js +11047 -1
- package/lib/index.d.ts +126 -0
- package/lib/index.js +53 -21
- package/lib/index.mjs +437 -0
- package/licenses/upstream-MIT.txt +22 -0
- package/maintenance/api-coverage.json +1642 -0
- package/maintenance/archivos-sha256.json +207 -0
- package/maintenance/consumer-validation.log +3 -0
- package/maintenance/dependency-audit.json +4 -4
- package/maintenance/extension-inventory.json +57 -0
- package/maintenance/protocol-update.json +1101 -0
- package/maintenance/protocol-wire-audit.json +4 -0
- package/maintenance/reference-socket-surface.json +209 -0
- package/maintenance/resumen-validacion.json +50 -0
- package/maintenance/validation.log +2725 -0
- package/maintenance/verification.json +566 -0
- package/package.json +107 -9
- package/scripts/check-imports.cjs +10 -0
- package/scripts/check-package.cjs +40 -0
- package/scripts/check-syntax.cjs +1 -1
- package/scripts/generate-protobuf.cjs +6 -1
- package/scripts/generate-public-types.cjs +9 -0
- package/scripts/kage-base64-fix.cjs +45 -0
- package/scripts/maintenance.cjs +10 -0
- package/test/advanced.test.cjs +24 -0
- package/test/base64-fix.test.cjs +49 -0
- package/test/maintenance.test.cjs +1 -1
- package/test/npm-publication.test.cjs +141 -0
- package/test/recepcion-reparada.test.cjs +98 -0
- package/test/resilience-binary.test.cjs +69 -0
- package/test/resilience-transport.test.cjs +34 -0
- package/test/types.test.ts +5 -0
- package/test/upgrade.test.cjs +104 -0
- package/tsconfig.json +20 -0
- package/WAProto/p.html +0 -1
- package/lib/KageExtra/Modded/message_builder.js +0 -2330
- package/lib/KageExtra/VoIP/audio-feeder.js +0 -136
- package/lib/KageExtra/VoIP/index.js +0 -282
- package/lib/KageExtra/VoIP/relay-transport.js +0 -559
- package/lib/KageExtra/VoIP/signaling.js +0 -603
- package/lib/KageExtra/VoIP/types.js +0 -17
- package/lib/KageExtra/VoIP/wasm-engine.js +0 -1214
- package/lib/KageExtra/VoIP/worker-bootstrap.js +0 -1042
- package/lib/KageExtra/assets/wasm/loader.js +0 -5
- package/lib/KageExtra/assets/wasm/whatsapp.wasm +0 -0
- package/lib/KageExtra/assets/wasm/worker-modules.js +0 -273
- package/lib/KageExtra/index.js +0 -3
- package/lib/KageExtra/package.json +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
- package/maintenance/revision-full-check.txt +0 -1097
- package/maintenance/revision-library-tests.tap +0 -1088
- package/maintenance/revision-protobuf.txt +0 -5
- package/maintenance/revision-syntax.txt +0 -5
- package/maintenance/schema-coverage.json +0 -23
- package/maintenance/schema-merge.json +0 -30
- package/maintenance/validation-node20.txt +0 -191
- package/maintenance/validation-node22.txt +0 -237
|
@@ -32,4 +32,58 @@ const BROWSER_TO_COMPANION_WEB_CLIENT = {
|
|
|
32
32
|
return ('https://wa.me/settings/linked_devices#' +
|
|
33
33
|
[ref, noiseKeyB64, identityKeyB64, advB64, exports.getCompanionPlatformId.call(void 0, browser)].join(','));
|
|
34
34
|
}; exports.buildPairingQRData = buildPairingQRData;
|
|
35
|
-
//#
|
|
35
|
+
//#
|
|
36
|
+
// Kage: funciones avanzadas.
|
|
37
|
+
const __kageModule165 = (() => {
|
|
38
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
39
|
+
"use strict";
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.buildPairingQRData = exports.getCompanionPlatformId = exports.getCompanionWebClientType = exports.CompanionWebClientType = void 0;
|
|
42
|
+
(function (CompanionWebClientType) {
|
|
43
|
+
CompanionWebClientType[CompanionWebClientType["UNKNOWN"] = 0] = "UNKNOWN";
|
|
44
|
+
CompanionWebClientType[CompanionWebClientType["CHROME"] = 1] = "CHROME";
|
|
45
|
+
CompanionWebClientType[CompanionWebClientType["EDGE"] = 2] = "EDGE";
|
|
46
|
+
CompanionWebClientType[CompanionWebClientType["FIREFOX"] = 3] = "FIREFOX";
|
|
47
|
+
CompanionWebClientType[CompanionWebClientType["IE"] = 4] = "IE";
|
|
48
|
+
CompanionWebClientType[CompanionWebClientType["OPERA"] = 5] = "OPERA";
|
|
49
|
+
CompanionWebClientType[CompanionWebClientType["SAFARI"] = 6] = "SAFARI";
|
|
50
|
+
CompanionWebClientType[CompanionWebClientType["ELECTRON"] = 7] = "ELECTRON";
|
|
51
|
+
CompanionWebClientType[CompanionWebClientType["UWP"] = 8] = "UWP";
|
|
52
|
+
CompanionWebClientType[CompanionWebClientType["OTHER_WEB_CLIENT"] = 9] = "OTHER_WEB_CLIENT";
|
|
53
|
+
})(exports.CompanionWebClientType || (exports.CompanionWebClientType = {}));
|
|
54
|
+
const BROWSER_TO_COMPANION_WEB_CLIENT = {
|
|
55
|
+
Chrome: exports.CompanionWebClientType.CHROME,
|
|
56
|
+
Edge: exports.CompanionWebClientType.EDGE,
|
|
57
|
+
Firefox: exports.CompanionWebClientType.FIREFOX,
|
|
58
|
+
IE: exports.CompanionWebClientType.IE,
|
|
59
|
+
Opera: exports.CompanionWebClientType.OPERA,
|
|
60
|
+
Safari: exports.CompanionWebClientType.SAFARI
|
|
61
|
+
};
|
|
62
|
+
const getCompanionWebClientType = ([os, browserName]) => {
|
|
63
|
+
if (browserName === 'Desktop') {
|
|
64
|
+
return os === 'Windows' ? exports.CompanionWebClientType.UWP : exports.CompanionWebClientType.ELECTRON;
|
|
65
|
+
}
|
|
66
|
+
return BROWSER_TO_COMPANION_WEB_CLIENT[browserName] || exports.CompanionWebClientType.OTHER_WEB_CLIENT;
|
|
67
|
+
};
|
|
68
|
+
exports.getCompanionWebClientType = getCompanionWebClientType;
|
|
69
|
+
const getCompanionPlatformId = (browser) => {
|
|
70
|
+
return (0, exports.getCompanionWebClientType)(browser).toString();
|
|
71
|
+
};
|
|
72
|
+
exports.getCompanionPlatformId = getCompanionPlatformId;
|
|
73
|
+
const buildPairingQRData = (ref, noiseKeyB64, identityKeyB64, advB64, browser) => {
|
|
74
|
+
return 'https://wa.me/settings/linked_devices#' + [
|
|
75
|
+
ref,
|
|
76
|
+
noiseKeyB64,
|
|
77
|
+
identityKeyB64,
|
|
78
|
+
advB64,
|
|
79
|
+
(0, exports.getCompanionPlatformId)(browser)
|
|
80
|
+
].join(',');
|
|
81
|
+
};
|
|
82
|
+
exports.buildPairingQRData = buildPairingQRData;
|
|
83
|
+
|
|
84
|
+
return module.exports;
|
|
85
|
+
})();
|
|
86
|
+
for (const key of Object.keys(__kageModule165)) {
|
|
87
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule165[key]});
|
|
88
|
+
}
|
|
89
|
+
Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule165, configurable:true});
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -191,3 +191,358 @@ async function derivePairingCodeKey(pairingCode, salt) {
|
|
|
191
191
|
);
|
|
192
192
|
return Buffer.from(derivedBits);
|
|
193
193
|
}
|
|
194
|
+
|
|
195
|
+
// Kage: compatibilidad de API.
|
|
196
|
+
const __kageModule62 = (() => {
|
|
197
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
198
|
+
"use strict"
|
|
199
|
+
|
|
200
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
201
|
+
|
|
202
|
+
const {
|
|
203
|
+
createCipheriv,
|
|
204
|
+
createDecipheriv,
|
|
205
|
+
createHash,
|
|
206
|
+
createHmac,
|
|
207
|
+
randomBytes
|
|
208
|
+
} = require("crypto")
|
|
209
|
+
const { curve } = require("@itsukichan/libsignal-node")
|
|
210
|
+
const { KEY_BUNDLE_TYPE } = require("../Defaults/constants")
|
|
211
|
+
|
|
212
|
+
const generateSignalPubKey = (pubKey) => (
|
|
213
|
+
pubKey.length === 33 ? pubKey : Buffer.concat([KEY_BUNDLE_TYPE, pubKey])
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
const Curve = {
|
|
217
|
+
generateKeyPair: () => {
|
|
218
|
+
const { pubKey, privKey } = curve.generateKeyPair()
|
|
219
|
+
return {
|
|
220
|
+
private: Buffer.from(privKey),
|
|
221
|
+
public: Buffer.from(pubKey.slice(1))
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
sharedKey: (privateKey, publicKey) => {
|
|
225
|
+
const shared = curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey)
|
|
226
|
+
return Buffer.from(shared)
|
|
227
|
+
},
|
|
228
|
+
sign: (privateKey, buf) => curve.calculateSignature(privateKey, buf),
|
|
229
|
+
verify: (pubKey, message, signature) => {
|
|
230
|
+
try {
|
|
231
|
+
curve.verifySignature(generateSignalPubKey(pubKey), message, signature)
|
|
232
|
+
return true
|
|
233
|
+
} catch {
|
|
234
|
+
return false
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const signedKeyPair = (identityKeyPair, keyId) => {
|
|
240
|
+
const preKey = Curve.generateKeyPair()
|
|
241
|
+
const pubKey = generateSignalPubKey(preKey.public)
|
|
242
|
+
const signature = Curve.sign(identityKeyPair.private, pubKey)
|
|
243
|
+
return { keyPair: preKey, signature, keyId }
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const GCM_TAG_LENGTH = 128 >> 3
|
|
247
|
+
|
|
248
|
+
function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
249
|
+
const cipher = createCipheriv('aes-256-gcm', key, iv)
|
|
250
|
+
cipher.setAAD(additionalData)
|
|
251
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()])
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
255
|
+
const decipher = createDecipheriv('aes-256-gcm', key, iv)
|
|
256
|
+
const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH)
|
|
257
|
+
const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH)
|
|
258
|
+
if (additionalData) decipher.setAAD(additionalData)
|
|
259
|
+
decipher.setAuthTag(tag)
|
|
260
|
+
return Buffer.concat([decipher.update(enc), decipher.final()])
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function aesEncryptCTR(plaintext, key, iv) {
|
|
264
|
+
const cipher = createCipheriv('aes-256-ctr', key, iv)
|
|
265
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final()])
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function aesDecryptCTR(ciphertext, key, iv) {
|
|
269
|
+
const decipher = createDecipheriv('aes-256-ctr', key, iv)
|
|
270
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()])
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function aesDecrypt(buffer, key) {
|
|
274
|
+
return aesDecryptWithIV(buffer.slice(16), key, buffer.slice(0, 16))
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function aesDecryptWithIV(buffer, key, IV) {
|
|
278
|
+
const aes = createDecipheriv('aes-256-cbc', key, IV)
|
|
279
|
+
return Buffer.concat([aes.update(buffer), aes.final()])
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function aesEncrypt(buffer, key) {
|
|
283
|
+
const IV = randomBytes(16)
|
|
284
|
+
const aes = createCipheriv('aes-256-cbc', key, IV)
|
|
285
|
+
return Buffer.concat([IV, aes.update(buffer), aes.final()])
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function aesEncrypWithIV(buffer, key, IV) {
|
|
289
|
+
const aes = createCipheriv('aes-256-cbc', key, IV)
|
|
290
|
+
return Buffer.concat([aes.update(buffer), aes.final()])
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function hmacSign(buffer, key, variant = 'sha256') {
|
|
294
|
+
return createHmac(variant, key).update(buffer).digest()
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function sha256(buffer) {
|
|
298
|
+
return createHash('sha256').update(buffer).digest()
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function md5(buffer) {
|
|
302
|
+
return createHash('md5').update(buffer).digest()
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async function hkdf(buffer, expandedLength, info) {
|
|
306
|
+
// Normalize to a Uint8Array whose underlying buffer is a regular ArrayBuffer (not ArrayBufferLike)
|
|
307
|
+
// Cloning via new Uint8Array(...) guarantees the generic parameter is ArrayBuffer which satisfies WebCrypto types.
|
|
308
|
+
const inputKeyMaterial = new Uint8Array(buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer))
|
|
309
|
+
|
|
310
|
+
// Set default values if not provided
|
|
311
|
+
const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0)
|
|
312
|
+
const infoBytes = info.info ? new TextEncoder().encode(info.info) : new Uint8Array(0)
|
|
313
|
+
|
|
314
|
+
// Import the input key material (cast to BufferSource to appease TS DOM typings)
|
|
315
|
+
const importedKey = await crypto.subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, [
|
|
316
|
+
'deriveBits'
|
|
317
|
+
])
|
|
318
|
+
|
|
319
|
+
const derivedBits = await crypto.subtle.deriveBits({
|
|
320
|
+
name: 'HKDF',
|
|
321
|
+
hash: 'SHA-256',
|
|
322
|
+
salt,
|
|
323
|
+
info: infoBytes
|
|
324
|
+
}, importedKey, expandedLength * 8)
|
|
325
|
+
|
|
326
|
+
return Buffer.from(derivedBits)
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
async function derivePairingCodeKey(pairingCode, salt) {
|
|
330
|
+
const encoder = new TextEncoder()
|
|
331
|
+
const pairingCodeBuffer = encoder.encode(pairingCode)
|
|
332
|
+
const saltBuffer = new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt))
|
|
333
|
+
|
|
334
|
+
// Import the pairing code as key material
|
|
335
|
+
const keyMaterial = await crypto.subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, [
|
|
336
|
+
'deriveBits'
|
|
337
|
+
])
|
|
338
|
+
|
|
339
|
+
const derivedBits = await crypto.subtle.deriveBits({
|
|
340
|
+
name: 'PBKDF2',
|
|
341
|
+
salt: saltBuffer,
|
|
342
|
+
iterations: 2 << 16,
|
|
343
|
+
hash: 'SHA-256'
|
|
344
|
+
}, keyMaterial, 32 * 8)
|
|
345
|
+
|
|
346
|
+
return Buffer.from(derivedBits)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
module.exports = {
|
|
350
|
+
generateSignalPubKey,
|
|
351
|
+
Curve,
|
|
352
|
+
signedKeyPair,
|
|
353
|
+
aesEncryptGCM,
|
|
354
|
+
aesDecryptGCM,
|
|
355
|
+
aesEncryptCTR,
|
|
356
|
+
aesDecryptCTR,
|
|
357
|
+
aesDecrypt,
|
|
358
|
+
aesDecryptWithIV,
|
|
359
|
+
aesEncrypt,
|
|
360
|
+
aesEncrypWithIV,
|
|
361
|
+
hmacSign,
|
|
362
|
+
sha256,
|
|
363
|
+
md5,
|
|
364
|
+
hkdf,
|
|
365
|
+
derivePairingCodeKey
|
|
366
|
+
}
|
|
367
|
+
return module.exports;
|
|
368
|
+
})();
|
|
369
|
+
for (const key of Object.keys(__kageModule62)) {
|
|
370
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule62[key]});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Kage: funciones avanzadas.
|
|
374
|
+
const __kageModule166 = (() => {
|
|
375
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
376
|
+
"use strict";
|
|
377
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
378
|
+
if (k2 === undefined) k2 = k;
|
|
379
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
380
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
381
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
382
|
+
}
|
|
383
|
+
Object.defineProperty(o, k2, desc);
|
|
384
|
+
}) : (function(o, m, k, k2) {
|
|
385
|
+
if (k2 === undefined) k2 = k;
|
|
386
|
+
o[k2] = m[k];
|
|
387
|
+
}));
|
|
388
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
389
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
390
|
+
}) : function(o, v) {
|
|
391
|
+
o["default"] = v;
|
|
392
|
+
});
|
|
393
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
394
|
+
var ownKeys = function(o) {
|
|
395
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
396
|
+
var ar = [];
|
|
397
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
398
|
+
return ar;
|
|
399
|
+
};
|
|
400
|
+
return ownKeys(o);
|
|
401
|
+
};
|
|
402
|
+
return function (mod) {
|
|
403
|
+
if (mod && mod.__esModule) return mod;
|
|
404
|
+
var result = {};
|
|
405
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
406
|
+
__setModuleDefault(result, mod);
|
|
407
|
+
return result;
|
|
408
|
+
};
|
|
409
|
+
})();
|
|
410
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
411
|
+
exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
|
412
|
+
exports.aesEncryptGCM = aesEncryptGCM;
|
|
413
|
+
exports.aesDecryptGCM = aesDecryptGCM;
|
|
414
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
|
415
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
|
416
|
+
exports.aesDecrypt = aesDecrypt;
|
|
417
|
+
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
418
|
+
exports.aesEncrypt = aesEncrypt;
|
|
419
|
+
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
420
|
+
exports.hmacSign = hmacSign;
|
|
421
|
+
exports.sha256 = sha256;
|
|
422
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
423
|
+
const node_crypto_1 = require("node:crypto");
|
|
424
|
+
const curve = __importStar(require("libsignal/src/curve.js"));
|
|
425
|
+
const index_js_1 = require("../Defaults/index.js");
|
|
426
|
+
const { md5, hkdf } = require('./crypto.js');
|
|
427
|
+
// insure browser & node compatibility
|
|
428
|
+
const { subtle } = globalThis.crypto;
|
|
429
|
+
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
430
|
+
const generateSignalPubKey = (pubKey) => pubKey.length === 33 ? pubKey : Buffer.concat([index_js_1.KEY_BUNDLE_TYPE, pubKey]);
|
|
431
|
+
exports.generateSignalPubKey = generateSignalPubKey;
|
|
432
|
+
exports.Curve = {
|
|
433
|
+
generateKeyPair: () => {
|
|
434
|
+
const { pubKey, privKey } = curve.generateKeyPair();
|
|
435
|
+
return {
|
|
436
|
+
private: Buffer.from(privKey),
|
|
437
|
+
// remove version byte
|
|
438
|
+
public: Buffer.from(pubKey.slice(1))
|
|
439
|
+
};
|
|
440
|
+
},
|
|
441
|
+
sharedKey: (privateKey, publicKey) => {
|
|
442
|
+
const shared = curve.calculateAgreement((0, exports.generateSignalPubKey)(publicKey), privateKey);
|
|
443
|
+
return Buffer.from(shared);
|
|
444
|
+
},
|
|
445
|
+
sign: (privateKey, buf) => curve.calculateSignature(privateKey, buf),
|
|
446
|
+
verify: (pubKey, message, signature) => {
|
|
447
|
+
try {
|
|
448
|
+
curve.verifySignature((0, exports.generateSignalPubKey)(pubKey), message, signature);
|
|
449
|
+
return true;
|
|
450
|
+
}
|
|
451
|
+
catch (error) {
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
const signedKeyPair = (identityKeyPair, keyId) => {
|
|
457
|
+
const preKey = exports.Curve.generateKeyPair();
|
|
458
|
+
const pubKey = (0, exports.generateSignalPubKey)(preKey.public);
|
|
459
|
+
const signature = exports.Curve.sign(identityKeyPair.private, pubKey);
|
|
460
|
+
return { keyPair: preKey, signature, keyId };
|
|
461
|
+
};
|
|
462
|
+
exports.signedKeyPair = signedKeyPair;
|
|
463
|
+
const GCM_TAG_LENGTH = 128 >> 3;
|
|
464
|
+
/**
|
|
465
|
+
* encrypt AES 256 GCM;
|
|
466
|
+
* where the tag tag is suffixed to the ciphertext
|
|
467
|
+
* */
|
|
468
|
+
function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
469
|
+
const cipher = (0, node_crypto_1.createCipheriv)('aes-256-gcm', key, iv);
|
|
470
|
+
cipher.setAAD(additionalData);
|
|
471
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* decrypt AES 256 GCM;
|
|
475
|
+
* where the auth tag is suffixed to the ciphertext
|
|
476
|
+
* */
|
|
477
|
+
function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
478
|
+
const decipher = (0, node_crypto_1.createDecipheriv)('aes-256-gcm', key, iv);
|
|
479
|
+
// decrypt additional adata
|
|
480
|
+
const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
|
|
481
|
+
const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
|
|
482
|
+
// set additional data
|
|
483
|
+
decipher.setAAD(additionalData);
|
|
484
|
+
decipher.setAuthTag(tag);
|
|
485
|
+
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
486
|
+
}
|
|
487
|
+
function aesEncryptCTR(plaintext, key, iv) {
|
|
488
|
+
const cipher = (0, node_crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
|
489
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
490
|
+
}
|
|
491
|
+
function aesDecryptCTR(ciphertext, key, iv) {
|
|
492
|
+
const decipher = (0, node_crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
|
493
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
494
|
+
}
|
|
495
|
+
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
496
|
+
function aesDecrypt(buffer, key) {
|
|
497
|
+
return aesDecryptWithIV(buffer.subarray(16), key, buffer.subarray(0, 16));
|
|
498
|
+
}
|
|
499
|
+
/** decrypt AES 256 CBC */
|
|
500
|
+
function aesDecryptWithIV(buffer, key, IV) {
|
|
501
|
+
const aes = (0, node_crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
|
|
502
|
+
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
503
|
+
}
|
|
504
|
+
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
505
|
+
function aesEncrypt(buffer, key) {
|
|
506
|
+
const IV = (0, node_crypto_1.randomBytes)(16);
|
|
507
|
+
const aes = (0, node_crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
508
|
+
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
509
|
+
}
|
|
510
|
+
// encrypt AES 256 CBC with a given IV
|
|
511
|
+
function aesEncrypWithIV(buffer, key, IV) {
|
|
512
|
+
const aes = (0, node_crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
513
|
+
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
514
|
+
}
|
|
515
|
+
// sign HMAC using SHA 256
|
|
516
|
+
function hmacSign(buffer, key, variant = 'sha256') {
|
|
517
|
+
return (0, node_crypto_1.createHmac)(variant, key).update(buffer).digest();
|
|
518
|
+
}
|
|
519
|
+
function sha256(buffer) {
|
|
520
|
+
return (0, node_crypto_1.createHash)('sha256').update(buffer).digest();
|
|
521
|
+
}
|
|
522
|
+
async function derivePairingCodeKey(pairingCode, salt) {
|
|
523
|
+
// Convert inputs to formats Web Crypto API can work with
|
|
524
|
+
const encoder = new TextEncoder();
|
|
525
|
+
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
526
|
+
const saltBuffer = new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt));
|
|
527
|
+
// Import the pairing code as key material
|
|
528
|
+
const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, [
|
|
529
|
+
'deriveBits'
|
|
530
|
+
]);
|
|
531
|
+
// Derive bits using PBKDF2 with the same parameters
|
|
532
|
+
// 2 << 16 = 131,072 iterations
|
|
533
|
+
const derivedBits = await subtle.deriveBits({
|
|
534
|
+
name: 'PBKDF2',
|
|
535
|
+
salt: saltBuffer,
|
|
536
|
+
iterations: 2 << 16,
|
|
537
|
+
hash: 'SHA-256'
|
|
538
|
+
}, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
|
|
539
|
+
);
|
|
540
|
+
return Buffer.from(derivedBits);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return module.exports;
|
|
544
|
+
})();
|
|
545
|
+
for (const key of Object.keys(__kageModule166)) {
|
|
546
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule166[key]});
|
|
547
|
+
}
|
|
548
|
+
Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule166, configurable:true});
|