@d0v3riz/baileys 6.7.12 → 6.7.17
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 +1 -1
- package/README.md +35 -1267
- package/WAProto/index.d.ts +16106 -2739
- package/WAProto/index.js +128593 -73944
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +3 -3
- package/lib/Defaults/index.d.ts +51 -53
- package/lib/Defaults/index.js +105 -106
- package/lib/Signal/libsignal.d.ts +3 -3
- package/lib/Signal/libsignal.js +161 -152
- package/lib/Socket/Client/index.d.ts +2 -2
- package/lib/Socket/Client/index.js +18 -18
- package/lib/Socket/Client/types.d.ts +15 -17
- package/lib/Socket/Client/types.js +13 -13
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.js +62 -62
- package/lib/Socket/business.d.ts +146 -148
- package/lib/Socket/business.js +260 -260
- package/lib/Socket/chats.d.ts +85 -84
- package/lib/Socket/chats.js +880 -846
- package/lib/Socket/groups.d.ts +124 -123
- package/lib/Socket/groups.js +314 -314
- package/lib/Socket/index.d.ts +146 -148
- package/lib/Socket/index.js +10 -10
- package/lib/Socket/messages-recv.d.ts +135 -135
- package/lib/Socket/messages-recv.js +920 -913
- package/lib/Socket/messages-send.d.ts +130 -129
- package/lib/Socket/messages-send.js +683 -673
- package/lib/Socket/socket.d.ts +42 -45
- package/lib/Socket/socket.js +622 -622
- package/lib/Socket/usync.d.ts +36 -38
- package/lib/Socket/usync.js +70 -70
- package/lib/Types/Auth.d.ts +103 -105
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +13 -13
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +112 -107
- package/lib/Types/Chat.js +4 -4
- package/lib/Types/Contact.d.ts +19 -19
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +172 -172
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +56 -56
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +46 -46
- package/lib/Types/Label.js +27 -27
- package/lib/Types/LabelAssociation.d.ts +29 -29
- package/lib/Types/LabelAssociation.js +9 -9
- package/lib/Types/Message.d.ts +269 -273
- package/lib/Types/Message.js +7 -9
- package/lib/Types/Product.d.ts +78 -78
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +57 -57
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +121 -118
- package/lib/Types/Socket.js +2 -2
- package/lib/Types/State.d.ts +27 -27
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.d.ts +25 -25
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +63 -63
- package/lib/Types/index.js +41 -41
- package/lib/Utils/auth-utils.d.ts +18 -18
- package/lib/Utils/auth-utils.js +200 -200
- package/lib/Utils/baileys-event-stream.d.ts +16 -16
- package/lib/Utils/baileys-event-stream.js +63 -63
- package/lib/Utils/business.d.ts +22 -22
- package/lib/Utils/business.js +234 -234
- package/lib/Utils/chat-utils.d.ts +70 -72
- package/lib/Utils/chat-utils.js +745 -745
- package/lib/Utils/crypto.d.ts +40 -42
- package/lib/Utils/crypto.js +193 -153
- package/lib/Utils/decode-wa-message.d.ts +36 -36
- package/lib/Utils/decode-wa-message.js +205 -205
- package/lib/Utils/event-buffer.d.ts +35 -35
- package/lib/Utils/event-buffer.js +520 -520
- package/lib/Utils/generics.d.ts +90 -94
- package/lib/Utils/generics.js +398 -421
- package/lib/Utils/history.d.ts +19 -19
- package/lib/Utils/history.js +94 -94
- package/lib/Utils/index.d.ts +17 -17
- package/lib/Utils/index.js +33 -33
- package/lib/Utils/link-preview.d.ts +21 -21
- package/lib/Utils/link-preview.js +126 -116
- package/lib/Utils/logger.d.ts +11 -4
- package/lib/Utils/logger.js +7 -7
- package/lib/Utils/lt-hash.d.ts +12 -12
- package/lib/Utils/lt-hash.js +51 -51
- package/lib/Utils/make-mutex.d.ts +7 -7
- package/lib/Utils/make-mutex.js +44 -44
- package/lib/Utils/messages-media.d.ts +104 -108
- package/lib/Utils/messages-media.js +677 -667
- package/lib/Utils/messages.d.ts +75 -78
- package/lib/Utils/messages.js +765 -762
- package/lib/Utils/noise-handler.d.ts +19 -21
- package/lib/Utils/noise-handler.js +150 -150
- package/lib/Utils/process-message.d.ts +41 -42
- package/lib/Utils/process-message.js +382 -371
- package/lib/Utils/signal.d.ts +33 -33
- package/lib/Utils/signal.js +153 -153
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -12
- package/lib/Utils/use-multi-file-auth-state.js +125 -94
- package/lib/Utils/validate-connection.d.ts +10 -10
- package/lib/Utils/validate-connection.js +175 -175
- package/lib/WABinary/constants.d.ts +27 -27
- package/lib/WABinary/constants.js +40 -40
- package/lib/WABinary/decode.d.ts +6 -8
- package/lib/WABinary/decode.js +264 -254
- package/lib/WABinary/encode.d.ts +2 -4
- package/lib/WABinary/encode.js +252 -234
- package/lib/WABinary/generic-utils.d.ts +14 -16
- package/lib/WABinary/generic-utils.js +110 -110
- package/lib/WABinary/index.d.ts +5 -5
- package/lib/WABinary/index.js +21 -21
- package/lib/WABinary/jid-utils.d.ts +33 -31
- package/lib/WABinary/jid-utils.js +66 -62
- package/lib/WABinary/types.d.ts +18 -18
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +8 -18
- package/lib/WAM/BinaryInfo.js +13 -13
- package/lib/WAM/constants.d.ts +39 -39
- package/lib/WAM/constants.js +15350 -15350
- package/lib/WAM/encode.d.ts +2 -4
- package/lib/WAM/encode.js +155 -155
- package/lib/WAM/index.d.ts +3 -3
- package/lib/WAM/index.js +19 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -32
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -57
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -30
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -42
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -4
- package/lib/WAUSync/Protocols/index.js +20 -20
- package/lib/WAUSync/USyncQuery.d.ts +28 -26
- package/lib/WAUSync/USyncQuery.js +89 -79
- package/lib/WAUSync/USyncUser.d.ts +12 -10
- package/lib/WAUSync/USyncUser.js +26 -22
- package/lib/WAUSync/index.d.ts +3 -3
- package/lib/WAUSync/index.js +19 -19
- package/lib/index.d.ts +11 -12
- package/lib/index.js +30 -31
- package/package.json +27 -35
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -3344
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/index.js +0 -10
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-in-memory-store.js +0 -420
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/make-ordered-dictionary.js +0 -81
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Store/object-repository.js +0 -27
package/lib/Utils/crypto.d.ts
CHANGED
|
@@ -1,42 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export declare function
|
|
27
|
-
|
|
28
|
-
export declare function
|
|
29
|
-
/** decrypt AES 256 CBC
|
|
30
|
-
export declare function
|
|
31
|
-
|
|
32
|
-
export declare function
|
|
33
|
-
export declare function
|
|
34
|
-
export declare function
|
|
35
|
-
export declare function
|
|
36
|
-
export declare function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}): Buffer;
|
|
42
|
-
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>;
|
|
1
|
+
import { KeyPair } from '../Types';
|
|
2
|
+
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
3
|
+
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
|
|
4
|
+
export declare const Curve: {
|
|
5
|
+
generateKeyPair: () => KeyPair;
|
|
6
|
+
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer<any>;
|
|
7
|
+
sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
|
|
8
|
+
verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) => {
|
|
11
|
+
keyPair: KeyPair;
|
|
12
|
+
signature: any;
|
|
13
|
+
keyId: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* encrypt AES 256 GCM;
|
|
17
|
+
* where the tag tag is suffixed to the ciphertext
|
|
18
|
+
* */
|
|
19
|
+
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer<ArrayBuffer>;
|
|
20
|
+
/**
|
|
21
|
+
* decrypt AES 256 GCM;
|
|
22
|
+
* where the auth tag is suffixed to the ciphertext
|
|
23
|
+
* */
|
|
24
|
+
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer<ArrayBuffer>;
|
|
25
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer<ArrayBuffer>;
|
|
26
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer<ArrayBuffer>;
|
|
27
|
+
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
28
|
+
export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer<ArrayBuffer>;
|
|
29
|
+
/** decrypt AES 256 CBC */
|
|
30
|
+
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer<ArrayBuffer>;
|
|
31
|
+
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer<ArrayBuffer>;
|
|
32
|
+
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer<ArrayBuffer>;
|
|
33
|
+
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer<ArrayBufferLike>;
|
|
34
|
+
export declare function sha256(buffer: Buffer): Buffer<ArrayBufferLike>;
|
|
35
|
+
export declare function md5(buffer: Buffer): Buffer<ArrayBufferLike>;
|
|
36
|
+
export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
|
|
37
|
+
salt?: Buffer;
|
|
38
|
+
info?: string;
|
|
39
|
+
}): Promise<Buffer>;
|
|
40
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>;
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -1,153 +1,193 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
exports.
|
|
41
|
-
exports.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
function
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
|
37
|
+
exports.aesEncryptGCM = aesEncryptGCM;
|
|
38
|
+
exports.aesDecryptGCM = aesDecryptGCM;
|
|
39
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
|
40
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
|
41
|
+
exports.aesDecrypt = aesDecrypt;
|
|
42
|
+
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
43
|
+
exports.aesEncrypt = aesEncrypt;
|
|
44
|
+
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
45
|
+
exports.hmacSign = hmacSign;
|
|
46
|
+
exports.sha256 = sha256;
|
|
47
|
+
exports.md5 = md5;
|
|
48
|
+
exports.hkdf = hkdf;
|
|
49
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
50
|
+
const crypto_1 = require("crypto");
|
|
51
|
+
const libsignal = __importStar(require("libsignal"));
|
|
52
|
+
const Defaults_1 = require("../Defaults");
|
|
53
|
+
// insure browser & node compatibility
|
|
54
|
+
const { subtle } = globalThis.crypto;
|
|
55
|
+
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
56
|
+
const generateSignalPubKey = (pubKey) => (pubKey.length === 33
|
|
57
|
+
? pubKey
|
|
58
|
+
: Buffer.concat([Defaults_1.KEY_BUNDLE_TYPE, pubKey]));
|
|
59
|
+
exports.generateSignalPubKey = generateSignalPubKey;
|
|
60
|
+
exports.Curve = {
|
|
61
|
+
generateKeyPair: () => {
|
|
62
|
+
const { pubKey, privKey } = libsignal.curve.generateKeyPair();
|
|
63
|
+
return {
|
|
64
|
+
private: Buffer.from(privKey),
|
|
65
|
+
// remove version byte
|
|
66
|
+
public: Buffer.from(pubKey.slice(1))
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
sharedKey: (privateKey, publicKey) => {
|
|
70
|
+
const shared = libsignal.curve.calculateAgreement((0, exports.generateSignalPubKey)(publicKey), privateKey);
|
|
71
|
+
return Buffer.from(shared);
|
|
72
|
+
},
|
|
73
|
+
sign: (privateKey, buf) => (libsignal.curve.calculateSignature(privateKey, buf)),
|
|
74
|
+
verify: (pubKey, message, signature) => {
|
|
75
|
+
try {
|
|
76
|
+
libsignal.curve.verifySignature((0, exports.generateSignalPubKey)(pubKey), message, signature);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const signedKeyPair = (identityKeyPair, keyId) => {
|
|
85
|
+
const preKey = exports.Curve.generateKeyPair();
|
|
86
|
+
const pubKey = (0, exports.generateSignalPubKey)(preKey.public);
|
|
87
|
+
const signature = exports.Curve.sign(identityKeyPair.private, pubKey);
|
|
88
|
+
return { keyPair: preKey, signature, keyId };
|
|
89
|
+
};
|
|
90
|
+
exports.signedKeyPair = signedKeyPair;
|
|
91
|
+
const GCM_TAG_LENGTH = 128 >> 3;
|
|
92
|
+
/**
|
|
93
|
+
* encrypt AES 256 GCM;
|
|
94
|
+
* where the tag tag is suffixed to the ciphertext
|
|
95
|
+
* */
|
|
96
|
+
function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
97
|
+
const cipher = (0, crypto_1.createCipheriv)('aes-256-gcm', key, iv);
|
|
98
|
+
cipher.setAAD(additionalData);
|
|
99
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* decrypt AES 256 GCM;
|
|
103
|
+
* where the auth tag is suffixed to the ciphertext
|
|
104
|
+
* */
|
|
105
|
+
function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
106
|
+
const decipher = (0, crypto_1.createDecipheriv)('aes-256-gcm', key, iv);
|
|
107
|
+
// decrypt additional adata
|
|
108
|
+
const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
|
|
109
|
+
const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
|
|
110
|
+
// set additional data
|
|
111
|
+
decipher.setAAD(additionalData);
|
|
112
|
+
decipher.setAuthTag(tag);
|
|
113
|
+
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
114
|
+
}
|
|
115
|
+
function aesEncryptCTR(plaintext, key, iv) {
|
|
116
|
+
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
|
117
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
118
|
+
}
|
|
119
|
+
function aesDecryptCTR(ciphertext, key, iv) {
|
|
120
|
+
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
|
121
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
122
|
+
}
|
|
123
|
+
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
124
|
+
function aesDecrypt(buffer, key) {
|
|
125
|
+
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
|
126
|
+
}
|
|
127
|
+
/** decrypt AES 256 CBC */
|
|
128
|
+
function aesDecryptWithIV(buffer, key, IV) {
|
|
129
|
+
const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
|
|
130
|
+
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
131
|
+
}
|
|
132
|
+
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
133
|
+
function aesEncrypt(buffer, key) {
|
|
134
|
+
const IV = (0, crypto_1.randomBytes)(16);
|
|
135
|
+
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
136
|
+
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
137
|
+
}
|
|
138
|
+
// encrypt AES 256 CBC with a given IV
|
|
139
|
+
function aesEncrypWithIV(buffer, key, IV) {
|
|
140
|
+
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
141
|
+
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
142
|
+
}
|
|
143
|
+
// sign HMAC using SHA 256
|
|
144
|
+
function hmacSign(buffer, key, variant = 'sha256') {
|
|
145
|
+
return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
|
|
146
|
+
}
|
|
147
|
+
function sha256(buffer) {
|
|
148
|
+
return (0, crypto_1.createHash)('sha256').update(buffer).digest();
|
|
149
|
+
}
|
|
150
|
+
function md5(buffer) {
|
|
151
|
+
return (0, crypto_1.createHash)('md5').update(buffer).digest();
|
|
152
|
+
}
|
|
153
|
+
// HKDF key expansion
|
|
154
|
+
async function hkdf(buffer, expandedLength, info) {
|
|
155
|
+
// Ensure we have a Uint8Array for the key material
|
|
156
|
+
const inputKeyMaterial = buffer instanceof Uint8Array
|
|
157
|
+
? buffer
|
|
158
|
+
: new Uint8Array(buffer);
|
|
159
|
+
// Set default values if not provided
|
|
160
|
+
const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
|
|
161
|
+
const infoBytes = info.info
|
|
162
|
+
? new TextEncoder().encode(info.info)
|
|
163
|
+
: new Uint8Array(0);
|
|
164
|
+
// Import the input key material
|
|
165
|
+
const importedKey = await subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits']);
|
|
166
|
+
// Derive bits using HKDF
|
|
167
|
+
const derivedBits = await subtle.deriveBits({
|
|
168
|
+
name: 'HKDF',
|
|
169
|
+
hash: 'SHA-256',
|
|
170
|
+
salt: salt,
|
|
171
|
+
info: infoBytes
|
|
172
|
+
}, importedKey, expandedLength * 8 // Convert bytes to bits
|
|
173
|
+
);
|
|
174
|
+
return Buffer.from(derivedBits);
|
|
175
|
+
}
|
|
176
|
+
async function derivePairingCodeKey(pairingCode, salt) {
|
|
177
|
+
// Convert inputs to formats Web Crypto API can work with
|
|
178
|
+
const encoder = new TextEncoder();
|
|
179
|
+
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
180
|
+
const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt);
|
|
181
|
+
// Import the pairing code as key material
|
|
182
|
+
const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, ['deriveBits']);
|
|
183
|
+
// Derive bits using PBKDF2 with the same parameters
|
|
184
|
+
// 2 << 16 = 131,072 iterations
|
|
185
|
+
const derivedBits = await subtle.deriveBits({
|
|
186
|
+
name: 'PBKDF2',
|
|
187
|
+
salt: saltBuffer,
|
|
188
|
+
iterations: 2 << 16,
|
|
189
|
+
hash: 'SHA-256'
|
|
190
|
+
}, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
|
|
191
|
+
);
|
|
192
|
+
return Buffer.from(derivedBits);
|
|
193
|
+
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
|
|
6
|
-
export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
|
|
7
|
-
export declare const NACK_REASONS: {
|
|
8
|
-
ParsingError: number;
|
|
9
|
-
UnrecognizedStanza: number;
|
|
10
|
-
UnrecognizedStanzaClass: number;
|
|
11
|
-
UnrecognizedStanzaType: number;
|
|
12
|
-
InvalidProtobuf: number;
|
|
13
|
-
InvalidHostedCompanionStanza: number;
|
|
14
|
-
MissingMessageSecret: number;
|
|
15
|
-
SignalErrorOldCounter: number;
|
|
16
|
-
MessageDeletedOnPeer: number;
|
|
17
|
-
UnhandledError: number;
|
|
18
|
-
UnsupportedAdminRevoke: number;
|
|
19
|
-
UnsupportedLIDGroup: number;
|
|
20
|
-
DBOperationFailed: number;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Decode the received node as a message.
|
|
24
|
-
* @note this will only parse the message, not decrypt it
|
|
25
|
-
*/
|
|
26
|
-
export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
|
|
27
|
-
fullMessage: proto.IWebMessageInfo;
|
|
28
|
-
author: string;
|
|
29
|
-
sender: string;
|
|
30
|
-
};
|
|
31
|
-
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger:
|
|
32
|
-
fullMessage: proto.IWebMessageInfo;
|
|
33
|
-
category: string;
|
|
34
|
-
author: string;
|
|
35
|
-
decrypt(): Promise<void>;
|
|
36
|
-
};
|
|
1
|
+
import { proto } from '../../WAProto';
|
|
2
|
+
import { SignalRepository } from '../Types';
|
|
3
|
+
import { BinaryNode } from '../WABinary';
|
|
4
|
+
import { ILogger } from './logger';
|
|
5
|
+
export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
|
|
6
|
+
export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
|
|
7
|
+
export declare const NACK_REASONS: {
|
|
8
|
+
ParsingError: number;
|
|
9
|
+
UnrecognizedStanza: number;
|
|
10
|
+
UnrecognizedStanzaClass: number;
|
|
11
|
+
UnrecognizedStanzaType: number;
|
|
12
|
+
InvalidProtobuf: number;
|
|
13
|
+
InvalidHostedCompanionStanza: number;
|
|
14
|
+
MissingMessageSecret: number;
|
|
15
|
+
SignalErrorOldCounter: number;
|
|
16
|
+
MessageDeletedOnPeer: number;
|
|
17
|
+
UnhandledError: number;
|
|
18
|
+
UnsupportedAdminRevoke: number;
|
|
19
|
+
UnsupportedLIDGroup: number;
|
|
20
|
+
DBOperationFailed: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Decode the received node as a message.
|
|
24
|
+
* @note this will only parse the message, not decrypt it
|
|
25
|
+
*/
|
|
26
|
+
export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
|
|
27
|
+
fullMessage: proto.IWebMessageInfo;
|
|
28
|
+
author: string;
|
|
29
|
+
sender: string;
|
|
30
|
+
};
|
|
31
|
+
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger) => {
|
|
32
|
+
fullMessage: proto.IWebMessageInfo;
|
|
33
|
+
category: string;
|
|
34
|
+
author: string;
|
|
35
|
+
decrypt(): Promise<void>;
|
|
36
|
+
};
|