@ubedsockets/baileys 1.6.6 → 1.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/GenerateStatics.sh +4 -3
- package/WAProto/WAProto.proto +511 -1215
- package/WAProto/index.js +131318 -59331
- package/lib/Defaults/index.js +92 -76
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.js +51 -37
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.js +44 -7
- package/lib/Signal/Group/sender-chain-key.js +15 -7
- package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
- package/lib/Signal/Group/sender-key-message.js +12 -9
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.js +21 -9
- package/lib/Signal/Group/sender-key-state.js +42 -27
- package/lib/Signal/Group/sender-message-key.js +7 -4
- package/lib/Signal/libsignal.js +90 -347
- package/lib/Socket/Client/index.js +18 -3
- package/lib/Socket/Client/types.js +6 -4
- package/lib/Socket/Client/websocket.js +78 -21
- package/lib/Socket/business.js +43 -162
- package/lib/Socket/chats.js +249 -571
- package/lib/Socket/groups.js +99 -114
- package/lib/Socket/index.js +9 -11
- package/lib/Socket/messages-recv.js +559 -1277
- package/lib/Socket/messages-send.js +669 -674
- package/lib/Socket/newsletter.js +286 -149
- package/lib/Socket/socket.js +235 -548
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.js +7 -11
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +2 -56
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.js +136 -239
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.js +238 -380
- package/lib/Utils/crypto.js +127 -56
- package/lib/Utils/decode-wa-message.js +63 -173
- package/lib/Utils/event-buffer.js +70 -174
- package/lib/Utils/generics.js +207 -159
- package/lib/Utils/history.js +53 -93
- package/lib/Utils/index.js +33 -22
- package/lib/Utils/link-preview.js +58 -17
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.js +46 -3
- package/lib/Utils/make-mutex.js +34 -24
- package/lib/Utils/messages-media.js +744 -483
- package/lib/Utils/messages.js +621 -411
- package/lib/Utils/noise-handler.js +99 -149
- package/lib/Utils/process-message.js +150 -459
- package/lib/Utils/signal.js +73 -112
- package/lib/Utils/use-multi-file-auth-state.js +27 -23
- package/lib/Utils/validate-connection.js +104 -74
- package/lib/WABinary/constants.js +11 -9
- package/lib/WABinary/decode.js +52 -49
- package/lib/WABinary/encode.js +49 -19
- package/lib/WABinary/generic-utils.js +43 -46
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.js +45 -72
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.js +11958 -19461
- package/lib/WAM/encode.js +22 -17
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +13 -33
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
- package/lib/WAUSync/Protocols/index.js +20 -6
- package/lib/WAUSync/USyncQuery.js +35 -44
- package/lib/WAUSync/USyncUser.js +5 -10
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +70 -11
- package/package.json +60 -100
- package/engine-requirements.js +0 -10
package/lib/Defaults/index.js
CHANGED
|
@@ -1,57 +1,77 @@
|
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_CACHE_TTLS =
|
|
7
|
+
exports.MIN_UPLOAD_INTERVAL =
|
|
8
|
+
exports.UPLOAD_TIMEOUT =
|
|
9
|
+
exports.INITIAL_PREKEY_COUNT =
|
|
10
|
+
exports.MIN_PREKEY_COUNT =
|
|
11
|
+
exports.MEDIA_KEYS =
|
|
12
|
+
exports.MEDIA_HKDF_KEY_MAPPING =
|
|
13
|
+
exports.MEDIA_PATH_MAP =
|
|
14
|
+
exports.DEFAULT_CONNECTION_CONFIG =
|
|
15
|
+
exports.PROCESSABLE_HISTORY_TYPES =
|
|
16
|
+
exports.WA_CERT_DETAILS =
|
|
17
|
+
exports.URL_REGEX =
|
|
18
|
+
exports.NOISE_WA_HEADER =
|
|
19
|
+
exports.KEY_BUNDLE_TYPE =
|
|
20
|
+
exports.DICT_VERSION =
|
|
21
|
+
exports.NOISE_MODE =
|
|
22
|
+
exports.WA_DEFAULT_EPHEMERAL =
|
|
23
|
+
exports.PHONE_CONNECTION_CB =
|
|
24
|
+
exports.DEF_TAG_PREFIX =
|
|
25
|
+
exports.DEF_CALLBACK_PREFIX =
|
|
26
|
+
exports.CALL_AUDIO_PREFIX =
|
|
27
|
+
exports.CALL_VIDEO_PREFIX =
|
|
28
|
+
exports.DEFAULT_ORIGIN =
|
|
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.UNAUTHORIZED_CODES = void 0;
|
|
34
|
+
|
|
35
|
+
const WAProto_1 = require("../../WAProto");
|
|
36
|
+
const libsignal_1 = require("../Signal/libsignal");
|
|
37
|
+
const Utils_1 = require("../Utils");
|
|
38
|
+
const logger_1 = __importDefault(require("../Utils/logger"));
|
|
39
|
+
const version = [2, 3000, 1027934701];
|
|
40
|
+
exports.UNAUTHORIZED_CODES = [401, 403, 419];
|
|
41
|
+
exports.DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
42
|
+
exports.CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
|
|
43
|
+
exports.CALL_AUDIO_PREFIX = 'https://call.whatsapp.com/voice/';
|
|
44
|
+
exports.DEF_CALLBACK_PREFIX = 'CB:';
|
|
45
|
+
exports.DEF_TAG_PREFIX = 'TAG:';
|
|
46
|
+
exports.PHONE_CONNECTION_CB = 'CB:Pong';
|
|
47
|
+
exports.WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0]);
|
|
48
|
+
exports.WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]);
|
|
49
|
+
exports.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]);
|
|
50
|
+
exports.WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]);
|
|
51
|
+
exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
|
|
52
|
+
exports.NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
|
|
53
|
+
exports.DICT_VERSION = 3;
|
|
54
|
+
exports.KEY_BUNDLE_TYPE = Buffer.from([5]);
|
|
55
|
+
exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]);
|
|
56
|
+
exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
|
|
57
|
+
exports.WA_CERT_DETAILS = {
|
|
29
58
|
SERIAL: 0,
|
|
30
|
-
ISSUER: 'WhatsAppLongTerm1',
|
|
31
|
-
PUBLIC_KEY: Buffer.from('142375574d0a587166aae71ebe516437c4a28b73e3695c6ce1f7f9545da8ee6b', 'hex')
|
|
32
59
|
};
|
|
33
|
-
|
|
34
|
-
proto.
|
|
35
|
-
proto.
|
|
36
|
-
proto.
|
|
37
|
-
proto.
|
|
38
|
-
proto.
|
|
39
|
-
proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
|
|
40
|
-
proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3
|
|
60
|
+
exports.PROCESSABLE_HISTORY_TYPES = [
|
|
61
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
62
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
|
|
63
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
|
|
64
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
|
|
65
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND,
|
|
41
66
|
];
|
|
42
|
-
|
|
43
|
-
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
44
|
-
MSG_RETRY: 60 * 60, // 1 hour
|
|
45
|
-
CALL_OFFER: 5 * 60, // 5 minutes
|
|
46
|
-
USER_DEVICES: 5 * 60 // 5 minutes
|
|
47
|
-
};
|
|
48
|
-
export const DEFAULT_CONNECTION_CONFIG = {
|
|
67
|
+
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
49
68
|
version: version,
|
|
50
|
-
browser: Browsers.
|
|
69
|
+
browser: Utils_1.Browsers.ubuntu('Chrome'),
|
|
51
70
|
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
52
71
|
connectTimeoutMs: 20000,
|
|
53
72
|
keepAliveIntervalMs: 30000,
|
|
54
|
-
logger:
|
|
73
|
+
logger: logger_1.default.child({ class: 'baileys' }),
|
|
74
|
+
printQRInTerminal: false,
|
|
55
75
|
emitOwnEvents: true,
|
|
56
76
|
defaultQueryTimeoutMs: 60000,
|
|
57
77
|
customUploadHosts: [],
|
|
@@ -62,9 +82,7 @@ export const DEFAULT_CONNECTION_CONFIG = {
|
|
|
62
82
|
markOnlineOnConnect: true,
|
|
63
83
|
syncFullHistory: true,
|
|
64
84
|
patchMessageBeforeSending: msg => msg,
|
|
65
|
-
shouldSyncHistoryMessage: (
|
|
66
|
-
return syncType !== proto.HistorySync.HistorySyncType.FULL;
|
|
67
|
-
},
|
|
85
|
+
shouldSyncHistoryMessage: () => true,
|
|
68
86
|
shouldIgnoreJid: () => false,
|
|
69
87
|
linkPreviewImageThumbnailWidth: 192,
|
|
70
88
|
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
@@ -74,14 +92,14 @@ export const DEFAULT_CONNECTION_CONFIG = {
|
|
|
74
92
|
options: {},
|
|
75
93
|
appStateMacVerification: {
|
|
76
94
|
patch: false,
|
|
77
|
-
snapshot: false
|
|
95
|
+
snapshot: false,
|
|
78
96
|
},
|
|
79
97
|
countryCode: 'US',
|
|
80
98
|
getMessage: async () => undefined,
|
|
81
99
|
cachedGroupMetadata: async () => undefined,
|
|
82
|
-
makeSignalRepository: makeLibSignalRepository
|
|
100
|
+
makeSignalRepository: libsignal_1.makeLibSignalRepository
|
|
83
101
|
};
|
|
84
|
-
|
|
102
|
+
exports.MEDIA_PATH_MAP = {
|
|
85
103
|
image: '/mms/image',
|
|
86
104
|
video: '/mms/video',
|
|
87
105
|
document: '/mms/document',
|
|
@@ -93,16 +111,16 @@ export const MEDIA_PATH_MAP = {
|
|
|
93
111
|
'md-msg-hist': '/mms/md-app-state',
|
|
94
112
|
'biz-cover-photo': '/pps/biz-cover-photo'
|
|
95
113
|
};
|
|
96
|
-
|
|
97
|
-
audio: 'Audio',
|
|
98
|
-
document: 'Document',
|
|
99
|
-
gif: 'Video',
|
|
100
|
-
image: 'Image',
|
|
101
|
-
ppic: '',
|
|
102
|
-
product: 'Image',
|
|
103
|
-
ptt: 'Audio',
|
|
104
|
-
sticker: 'Image',
|
|
105
|
-
video: 'Video',
|
|
114
|
+
exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
115
|
+
'audio': 'Audio',
|
|
116
|
+
'document': 'Document',
|
|
117
|
+
'gif': 'Video',
|
|
118
|
+
'image': 'Image',
|
|
119
|
+
'ppic': '',
|
|
120
|
+
'product': 'Image',
|
|
121
|
+
'ptt': 'Audio',
|
|
122
|
+
'sticker': 'Image',
|
|
123
|
+
'video': 'Video',
|
|
106
124
|
'thumbnail-document': 'Document Thumbnail',
|
|
107
125
|
'thumbnail-image': 'Image Thumbnail',
|
|
108
126
|
'thumbnail-video': 'Video Thumbnail',
|
|
@@ -111,19 +129,17 @@ export const MEDIA_HKDF_KEY_MAPPING = {
|
|
|
111
129
|
'md-app-state': 'App State',
|
|
112
130
|
'product-catalog-image': '',
|
|
113
131
|
'payment-bg-image': 'Payment Background',
|
|
114
|
-
ptv: 'Video',
|
|
132
|
+
'ptv': 'Video',
|
|
115
133
|
'biz-cover-photo': 'Image'
|
|
116
134
|
};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
Week: 7 * 24 * 60 * 60 * 1000
|
|
135
|
+
exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
|
|
136
|
+
exports.MIN_PREKEY_COUNT = 5;
|
|
137
|
+
exports.INITIAL_PREKEY_COUNT = 812;
|
|
138
|
+
exports.UPLOAD_TIMEOUT = 30000;
|
|
139
|
+
exports.MIN_UPLOAD_INTERVAL = 5000;
|
|
140
|
+
exports.DEFAULT_CACHE_TTLS = {
|
|
141
|
+
SIGNAL_STORE: 5 * 60,
|
|
142
|
+
MSG_RETRY: 60 * 60,
|
|
143
|
+
CALL_OFFER: 5 * 60,
|
|
144
|
+
USER_DEVICES: 5 * 60,
|
|
128
145
|
};
|
|
129
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CiphertextMessage = void 0;
|
|
4
|
+
class CiphertextMessage {
|
|
2
5
|
constructor() {
|
|
3
6
|
this.UNSUPPORTED_VERSION = 1;
|
|
4
7
|
this.CURRENT_VERSION = 3;
|
|
@@ -9,4 +12,4 @@ export class CiphertextMessage {
|
|
|
9
12
|
this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
|
-
|
|
15
|
+
exports.CiphertextMessage = CiphertextMessage;
|
|
@@ -1,8 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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.GroupSessionBuilder = void 0;
|
|
37
|
+
const keyhelper = __importStar(require("./keyhelper"));
|
|
38
|
+
const sender_key_distribution_message_1 = require("./sender-key-distribution-message");
|
|
39
|
+
class GroupSessionBuilder {
|
|
6
40
|
constructor(senderKeyStore) {
|
|
7
41
|
this.senderKeyStore = senderKeyStore;
|
|
8
42
|
}
|
|
@@ -24,7 +58,7 @@ export class GroupSessionBuilder {
|
|
|
24
58
|
if (!state) {
|
|
25
59
|
throw new Error('No session state available');
|
|
26
60
|
}
|
|
27
|
-
return new SenderKeyDistributionMessage(state.getKeyId(), state.getSenderChainKey().getIteration(), state.getSenderChainKey().getSeed(), state.getSigningKeyPublic());
|
|
61
|
+
return new sender_key_distribution_message_1.SenderKeyDistributionMessage(state.getKeyId(), state.getSenderChainKey().getIteration(), state.getSenderChainKey().getSeed(), state.getSigningKeyPublic());
|
|
28
62
|
}
|
|
29
63
|
}
|
|
30
|
-
|
|
64
|
+
exports.GroupSessionBuilder = GroupSessionBuilder;
|
|
@@ -1,44 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GroupCipher = void 0;
|
|
7
|
+
const crypto_1 = require("libsignal/src/crypto");
|
|
8
|
+
const queue_job_1 = __importDefault(require("./queue-job"));
|
|
9
|
+
const sender_key_message_1 = require("./sender-key-message");
|
|
10
|
+
class GroupCipher {
|
|
7
11
|
constructor(senderKeyStore, senderKeyName) {
|
|
8
12
|
this.senderKeyStore = senderKeyStore;
|
|
9
13
|
this.senderKeyName = senderKeyName;
|
|
10
14
|
}
|
|
15
|
+
queueJob(awaitable) {
|
|
16
|
+
return (0, queue_job_1.default)(this.senderKeyName.toString(), awaitable);
|
|
17
|
+
}
|
|
11
18
|
async encrypt(paddedPlaintext) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
return await this.queueJob(async () => {
|
|
20
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
|
|
21
|
+
if (!record) {
|
|
22
|
+
throw new Error('No SenderKeyRecord found for encryption');
|
|
23
|
+
}
|
|
24
|
+
const senderKeyState = record.getSenderKeyState();
|
|
25
|
+
if (!senderKeyState) {
|
|
26
|
+
throw new Error('No session to encrypt message');
|
|
27
|
+
}
|
|
28
|
+
const iteration = senderKeyState.getSenderChainKey().getIteration();
|
|
29
|
+
const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1);
|
|
30
|
+
const ciphertext = await this.getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext);
|
|
31
|
+
const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(senderKeyState.getKeyId(), senderKey.getIteration(), ciphertext, senderKeyState.getSigningKeyPrivate());
|
|
32
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
|
|
33
|
+
return senderKeyMessage.serialize();
|
|
34
|
+
});
|
|
26
35
|
}
|
|
27
36
|
async decrypt(senderKeyMessageBytes) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
return await this.queueJob(async () => {
|
|
38
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
|
|
39
|
+
if (!record) {
|
|
40
|
+
throw new Error('No SenderKeyRecord found for decryption');
|
|
41
|
+
}
|
|
42
|
+
const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(null, null, null, null, senderKeyMessageBytes);
|
|
43
|
+
const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());
|
|
44
|
+
if (!senderKeyState) {
|
|
45
|
+
throw new Error('No session found to decrypt message');
|
|
46
|
+
}
|
|
47
|
+
senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic());
|
|
48
|
+
const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration());
|
|
49
|
+
const plaintext = await this.getPlainText(senderKey.getIv(), senderKey.getCipherKey(), senderKeyMessage.getCipherText());
|
|
50
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
|
|
51
|
+
return plaintext;
|
|
52
|
+
});
|
|
42
53
|
}
|
|
43
54
|
getSenderKey(senderKeyState, iteration) {
|
|
44
55
|
let senderChainKey = senderKeyState.getSenderChainKey();
|
|
@@ -64,7 +75,7 @@ export class GroupCipher {
|
|
|
64
75
|
}
|
|
65
76
|
async getPlainText(iv, key, ciphertext) {
|
|
66
77
|
try {
|
|
67
|
-
return decrypt(key, ciphertext, iv);
|
|
78
|
+
return (0, crypto_1.decrypt)(key, ciphertext, iv);
|
|
68
79
|
}
|
|
69
80
|
catch (e) {
|
|
70
81
|
throw new Error('InvalidMessageException');
|
|
@@ -72,11 +83,14 @@ export class GroupCipher {
|
|
|
72
83
|
}
|
|
73
84
|
async getCipherText(iv, key, plaintext) {
|
|
74
85
|
try {
|
|
75
|
-
|
|
86
|
+
const ivBuffer = typeof iv === 'string' ? Buffer.from(iv, 'base64') : iv;
|
|
87
|
+
const keyBuffer = typeof key === 'string' ? Buffer.from(key, 'base64') : key;
|
|
88
|
+
const plaintextBuffer = typeof plaintext === 'string' ? Buffer.from(plaintext) : plaintext;
|
|
89
|
+
return (0, crypto_1.encrypt)(keyBuffer, plaintextBuffer, ivBuffer);
|
|
76
90
|
}
|
|
77
91
|
catch (e) {
|
|
78
92
|
throw new Error('InvalidMessageException');
|
|
79
93
|
}
|
|
80
94
|
}
|
|
81
95
|
}
|
|
82
|
-
|
|
96
|
+
exports.GroupCipher = GroupCipher;
|
|
@@ -1,12 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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.keyhelper = exports.CiphertextMessage = exports.SenderChainKey = exports.SenderMessageKey = exports.SenderKeyMessage = exports.SenderKeyState = exports.GroupCipher = exports.SenderKeyName = exports.SenderKeyRecord = exports.SenderKeyDistributionMessage = exports.GroupSessionBuilder = void 0;
|
|
37
|
+
var group_session_builder_1 = require("./group-session-builder");
|
|
38
|
+
Object.defineProperty(exports, "GroupSessionBuilder", { enumerable: true, get: function () { return group_session_builder_1.GroupSessionBuilder; } });
|
|
39
|
+
var sender_key_distribution_message_1 = require("./sender-key-distribution-message");
|
|
40
|
+
Object.defineProperty(exports, "SenderKeyDistributionMessage", { enumerable: true, get: function () { return sender_key_distribution_message_1.SenderKeyDistributionMessage; } });
|
|
41
|
+
var sender_key_record_1 = require("./sender-key-record");
|
|
42
|
+
Object.defineProperty(exports, "SenderKeyRecord", { enumerable: true, get: function () { return sender_key_record_1.SenderKeyRecord; } });
|
|
43
|
+
var sender_key_name_1 = require("./sender-key-name");
|
|
44
|
+
Object.defineProperty(exports, "SenderKeyName", { enumerable: true, get: function () { return sender_key_name_1.SenderKeyName; } });
|
|
45
|
+
var group_cipher_1 = require("./group_cipher");
|
|
46
|
+
Object.defineProperty(exports, "GroupCipher", { enumerable: true, get: function () { return group_cipher_1.GroupCipher; } });
|
|
47
|
+
var sender_key_state_1 = require("./sender-key-state");
|
|
48
|
+
Object.defineProperty(exports, "SenderKeyState", { enumerable: true, get: function () { return sender_key_state_1.SenderKeyState; } });
|
|
49
|
+
var sender_key_message_1 = require("./sender-key-message");
|
|
50
|
+
Object.defineProperty(exports, "SenderKeyMessage", { enumerable: true, get: function () { return sender_key_message_1.SenderKeyMessage; } });
|
|
51
|
+
var sender_message_key_1 = require("./sender-message-key");
|
|
52
|
+
Object.defineProperty(exports, "SenderMessageKey", { enumerable: true, get: function () { return sender_message_key_1.SenderMessageKey; } });
|
|
53
|
+
var sender_chain_key_1 = require("./sender-chain-key");
|
|
54
|
+
Object.defineProperty(exports, "SenderChainKey", { enumerable: true, get: function () { return sender_chain_key_1.SenderChainKey; } });
|
|
55
|
+
var ciphertext_message_1 = require("./ciphertext-message");
|
|
56
|
+
Object.defineProperty(exports, "CiphertextMessage", { enumerable: true, get: function () { return ciphertext_message_1.CiphertextMessage; } });
|
|
57
|
+
exports.keyhelper = __importStar(require("./keyhelper"));
|
|
@@ -1,18 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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.generateSenderKey = generateSenderKey;
|
|
37
|
+
exports.generateSenderKeyId = generateSenderKeyId;
|
|
38
|
+
exports.generateSenderSigningKey = generateSenderSigningKey;
|
|
39
|
+
const nodeCrypto = __importStar(require("crypto"));
|
|
40
|
+
const curve_1 = require("libsignal/src/curve");
|
|
41
|
+
function generateSenderKey() {
|
|
4
42
|
return nodeCrypto.randomBytes(32);
|
|
5
43
|
}
|
|
6
|
-
|
|
44
|
+
function generateSenderKeyId() {
|
|
7
45
|
return nodeCrypto.randomInt(2147483647);
|
|
8
46
|
}
|
|
9
|
-
|
|
47
|
+
function generateSenderSigningKey(key) {
|
|
10
48
|
if (!key) {
|
|
11
|
-
key = generateKeyPair();
|
|
49
|
+
key = (0, curve_1.generateKeyPair)();
|
|
12
50
|
}
|
|
13
51
|
return {
|
|
14
52
|
public: Buffer.from(key.pubKey),
|
|
15
53
|
private: Buffer.from(key.privKey)
|
|
16
54
|
};
|
|
17
55
|
}
|
|
18
|
-
//# sourceMappingURL=keyhelper.js.map
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderChainKey = void 0;
|
|
4
|
+
const crypto_1 = require("libsignal/src/crypto");
|
|
5
|
+
const sender_message_key_1 = require("./sender-message-key");
|
|
6
|
+
class SenderChainKey {
|
|
4
7
|
constructor(iteration, chainKey) {
|
|
5
8
|
this.MESSAGE_KEY_SEED = Buffer.from([0x01]);
|
|
6
9
|
this.CHAIN_KEY_SEED = Buffer.from([0x02]);
|
|
7
10
|
this.iteration = iteration;
|
|
8
|
-
|
|
11
|
+
if (chainKey instanceof Buffer) {
|
|
12
|
+
this.chainKey = chainKey;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
this.chainKey = Buffer.from(chainKey || []);
|
|
16
|
+
}
|
|
9
17
|
}
|
|
10
18
|
getIteration() {
|
|
11
19
|
return this.iteration;
|
|
12
20
|
}
|
|
13
21
|
getSenderMessageKey() {
|
|
14
|
-
return new SenderMessageKey(this.iteration, this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey));
|
|
22
|
+
return new sender_message_key_1.SenderMessageKey(this.iteration, this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey));
|
|
15
23
|
}
|
|
16
24
|
getNext() {
|
|
17
25
|
return new SenderChainKey(this.iteration + 1, this.getDerivative(this.CHAIN_KEY_SEED, this.chainKey));
|
|
@@ -20,7 +28,7 @@ export class SenderChainKey {
|
|
|
20
28
|
return this.chainKey;
|
|
21
29
|
}
|
|
22
30
|
getDerivative(seed, key) {
|
|
23
|
-
return calculateMAC(key, seed);
|
|
31
|
+
return (0, crypto_1.calculateMAC)(key, seed);
|
|
24
32
|
}
|
|
25
33
|
}
|
|
26
|
-
|
|
34
|
+
exports.SenderChainKey = SenderChainKey;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderKeyDistributionMessage = void 0;
|
|
4
|
+
const WAProto_1 = require("../../../WAProto");
|
|
5
|
+
const ciphertext_message_1 = require("./ciphertext-message");
|
|
6
|
+
class SenderKeyDistributionMessage extends ciphertext_message_1.CiphertextMessage {
|
|
4
7
|
constructor(id, iteration, chainKey, signatureKey, serialized) {
|
|
5
8
|
super();
|
|
6
9
|
if (serialized) {
|
|
7
10
|
try {
|
|
8
11
|
const message = serialized.slice(1);
|
|
9
|
-
const distributionMessage = proto.SenderKeyDistributionMessage.decode(message).toJSON();
|
|
12
|
+
const distributionMessage = WAProto_1.proto.SenderKeyDistributionMessage.decode(message).toJSON();
|
|
10
13
|
this.serialized = serialized;
|
|
11
14
|
this.id = distributionMessage.id;
|
|
12
15
|
this.iteration = distributionMessage.iteration;
|
|
@@ -29,7 +32,7 @@ export class SenderKeyDistributionMessage extends CiphertextMessage {
|
|
|
29
32
|
this.iteration = iteration;
|
|
30
33
|
this.chainKey = chainKey;
|
|
31
34
|
this.signatureKey = signatureKey;
|
|
32
|
-
const message = proto.SenderKeyDistributionMessage.encode(proto.SenderKeyDistributionMessage.create({
|
|
35
|
+
const message = WAProto_1.proto.SenderKeyDistributionMessage.encode(WAProto_1.proto.SenderKeyDistributionMessage.create({
|
|
33
36
|
id,
|
|
34
37
|
iteration,
|
|
35
38
|
chainKey,
|
|
@@ -51,13 +54,13 @@ export class SenderKeyDistributionMessage extends CiphertextMessage {
|
|
|
51
54
|
return this.iteration;
|
|
52
55
|
}
|
|
53
56
|
getChainKey() {
|
|
54
|
-
return this.chainKey;
|
|
57
|
+
return typeof this.chainKey === 'string' ? Buffer.from(this.chainKey, 'base64') : this.chainKey;
|
|
55
58
|
}
|
|
56
59
|
getSignatureKey() {
|
|
57
|
-
return this.signatureKey;
|
|
60
|
+
return typeof this.signatureKey === 'string' ? Buffer.from(this.signatureKey, 'base64') : this.signatureKey;
|
|
58
61
|
}
|
|
59
62
|
getId() {
|
|
60
63
|
return this.id;
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
|
-
|
|
66
|
+
exports.SenderKeyDistributionMessage = SenderKeyDistributionMessage;
|